From 96544598f62766bbc983a00a9075d1b2299504f3 Mon Sep 17 00:00:00 2001 From: rajeshkumarrobert Date: Sun, 2 Jun 2024 16:24:14 +0530 Subject: [PATCH] Implement generateprofileID --- Scarb.toml | 1 + src/core/registry.cairo | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index a2e32df..05824a3 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -6,6 +6,7 @@ edition = "2023_11" [dependencies] starknet = "2.6.3" alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git" } +alexandria_bytes = { git = "https://github.com/keep-starknet-strange/alexandria.git" } [dev-dependencies] snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.23.0" } diff --git a/src/core/registry.cairo b/src/core/registry.cairo index 5d7c7cd..4ae23a7 100644 --- a/src/core/registry.cairo +++ b/src/core/registry.cairo @@ -25,7 +25,9 @@ pub trait IRegistry {} #[starknet::contract] pub mod Registry { - use starknet::ContractAddress; + use alexandria_encoding::sol_abi::encode::SolAbiEncodeTrait; +use starknet::ContractAddress; + use alexandria_bytes::{Bytes, BytesTrait}; // ========================== // === Storage Variables ==== @@ -125,7 +127,14 @@ pub mod Registry { // Solidity - https://github.com/celestiaorg/blobstream-contracts/blob/0b4bcf69d1ce96df000da7f95fba8c03aa15a45e/src/lib/tree/namespace/TreeHasher.sol#L33 // Cairo - https://github.com/keep-starknet-strange/blobstream-starknet/blob/b74777e5fb479e5b4aa5a1419135e0826343fc37/src/tree/namespace/hasher.cairo#L10 // More about it - https://github.com/keep-starknet-strange/alexandria/tree/main/src/encoding - + fn _generateProfileId(_nonce: u256, owner: ContractAddress) -> u256 { + let profileId = BytesTrait::new_empty() + .encode_packed(_nonce) + .encode_packed(owner) + .keccak(); + return profileId; + } + // Issue no. #18 Implement the functionality of _generateAnchor // Internal function to create a _generateAnchor // https://github.com/allo-protocol/allo-v2/blob/4dd0ea34a504a16ac90e80f49a5570b8be9b30e9/contracts/core/Registry.sol#L340