From 6fc0cfd9bab7230278bc25a2b95ad811aad11172 Mon Sep 17 00:00:00 2001 From: Thomas Marchand Date: Wed, 9 Aug 2023 12:00:57 +0100 Subject: [PATCH] feat: add resolve function --- Scarb.toml | 1 + src/interface.cairo | 4 +++- src/interface/identity.cairo | 20 ++++++++++++++++++++ src/interface/resolver.cairo | 6 ++++++ src/naming/main.cairo | 20 ++++++++++++++++++-- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/interface/identity.cairo create mode 100644 src/interface/resolver.cairo diff --git a/Scarb.toml b/Scarb.toml index def9f4f..3b1ec33 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -7,6 +7,7 @@ version = "0.1.0" [dependencies] starknet = "2.1.0" openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", branch = "cairo-2" } +identity = { git = "https://github.com/starknet-id/identity.git", branch = "master" } [[target.starknet-contract]] # Enable Sierra codegen. diff --git a/src/interface.cairo b/src/interface.cairo index 22c0ad0..0f4509c 100644 --- a/src/interface.cairo +++ b/src/interface.cairo @@ -1,2 +1,4 @@ +mod identity; +mod naming; +mod resolver; mod pricing; -mod naming; \ No newline at end of file diff --git a/src/interface/identity.cairo b/src/interface/identity.cairo new file mode 100644 index 0000000..8994d03 --- /dev/null +++ b/src/interface/identity.cairo @@ -0,0 +1,20 @@ +use starknet::ContractAddress; + +#[starknet::interface] +trait IIdentity { + fn get_user_data( + self: @TContractState, starknet_id: felt252, field: felt252, domain: felt252 + ) -> felt252; + + fn get_crosschecked_user_data( + self: @TContractState, starknet_id: felt252, field: felt252 + ) -> felt252; + + fn get_verifier_data( + self: @TContractState, starknet_id: felt252, field: felt252, domain: felt252 + ) -> felt252; + + fn get_crosschecked_verifier_data( + self: @TContractState, starknet_id: felt252, field: felt252 + ) -> felt252; +} diff --git a/src/interface/resolver.cairo b/src/interface/resolver.cairo new file mode 100644 index 0000000..37eaf01 --- /dev/null +++ b/src/interface/resolver.cairo @@ -0,0 +1,6 @@ +use starknet::ContractAddress; + +#[starknet::interface] +trait IResolver { + fn resolve(self: @TContractState, domain: Span, field: felt252) -> felt252; +} diff --git a/src/naming/main.cairo b/src/naming/main.cairo index eae3c58..f42ba83 100644 --- a/src/naming/main.cairo +++ b/src/naming/main.cairo @@ -8,7 +8,11 @@ mod Naming { use array::{ArrayTrait, SpanTrait}; use zeroable::Zeroable; use starknet::class_hash::ClassHash; - use naming::interface::naming::{INaming, INamingDispatcher, INamingDispatcherTrait}; + use naming::interface::{ + naming::{INaming, INamingDispatcher, INamingDispatcherTrait}, + resolver::{IResolver, IResolverDispatcher, IResolverDispatcherTrait}, + identity::{IIdentity, IIdentityDispatcher, IIdentityDispatcherTrait} + }; use integer::{u256_safe_divmod, u256_as_non_zero}; use core::pedersen; @@ -45,9 +49,21 @@ mod Naming { #[external(v0)] impl NamingImpl of INaming { + // This function allows to read the single felt target of any domain for a specific field + // For example, it allows to find the Bitcoin address of Alice.stark by calling + // naming.resolve(['alice'], 'bitcoin') fn resolve(self: @ContractState, domain: Array, field: felt252) -> felt252 { let (resolver, parent_start) = self.domain_to_resolver(@domain, 0); - 1 + if (resolver != ContractAddressZeroable::zero()) { + IResolverDispatcher { + contract_address: resolver + }.resolve(domain.span().slice(parent_start, domain.len() - parent_start), field) + } else { + let domain_data = self._domain_data.read(self.hash_domain(domain.span())); + IIdentityDispatcher { + contract_address: self.starknetid_contract.read() + }.get_crosschecked_user_data(domain_data.owner, field) + } } }