Skip to content

Commit

Permalink
feat: use main_id feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Aug 18, 2023
1 parent 606eafb commit 3363456
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/naming/main.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 12 additions & 1 deletion src/tests/identity.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::array::SpanTrait;

#[starknet::contract]
mod Identity {
use starknet::ContractAddress;
Expand All @@ -20,6 +19,7 @@ mod Identity {
owner_by_id: LegacyMap<u128, ContractAddress>,
user_data: LegacyMap<(u128, felt252), felt252>,
verifier_data: LegacyMap<(u128, felt252, ContractAddress), felt252>,
main_id_by_addr: LegacyMap<ContractAddress, u128>,
}

#[constructor]
Expand All @@ -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 {
Expand Down Expand Up @@ -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
) {
Expand Down

0 comments on commit 3363456

Please sign in to comment.