diff --git a/src/naming/main.cairo b/src/naming/main.cairo index f8dcfc2..41ac8d4 100644 --- a/src/naming/main.cairo +++ b/src/naming/main.cairo @@ -142,10 +142,13 @@ mod Naming { if domain.len() != 0 && self.domain_to_address(domain.span()) == address { domain } else { - let id = self.domain_to_id(domain.span()); - let id_hashed_domain = IIdentityDispatcher { + let identity = IIdentityDispatcher { contract_address: self.starknetid_contract.read() - }.get_verifier_data(id, 'name', get_contract_address(), 0); + }; + let id = identity.get_main_id(address); + assert(id != 0, 'an id cannot be null'); + let id_hashed_domain = identity + .get_verifier_data(id, 'name', get_contract_address(), 0); let domain = self.unhash_domain(id_hashed_domain); assert( self.domain_to_address(domain.span()) == address, 'domain not pointing back' diff --git a/src/tests/identity.cairo b/src/tests/identity.cairo index 0ef4c5d..e43cdad 100644 --- a/src/tests/identity.cairo +++ b/src/tests/identity.cairo @@ -1,5 +1,4 @@ use core::array::SpanTrait; - #[starknet::contract] mod Identity { use starknet::ContractAddress; @@ -20,6 +19,7 @@ mod Identity { owner_by_id: LegacyMap, user_data: LegacyMap<(u128, felt252), felt252>, verifier_data: LegacyMap<(u128, felt252, ContractAddress), felt252>, + main_id_by_addr: LegacyMap, } #[constructor] @@ -32,6 +32,10 @@ mod Identity { self.owner_by_id.read(id) } + fn get_main_id(self: @ContractState, user: ContractAddress) -> u128 { + self.main_id_by_addr.read(user) + } + fn get_user_data( self: @ContractState, id: u128, field: felt252, domain: felt252 ) -> felt252 { @@ -71,6 +75,13 @@ mod Identity { } } + fn set_main_id(ref self: ContractState, id: u128) { + let caller = get_caller_address(); + assert(caller == self.owner_by_id.read(id), 'you don\'t own this id'); + self.main_id_by_addr.write(caller, id); + } + + fn set_user_data( ref self: ContractState, id: u128, field: felt252, data: felt252, domain: felt252 ) {