diff --git a/src/interface/resolver.cairo b/src/interface/resolver.cairo index ef719c6..327cbee 100644 --- a/src/interface/resolver.cairo +++ b/src/interface/resolver.cairo @@ -5,4 +5,5 @@ trait IResolver { fn resolve( self: @TContractState, domain: Span, field: felt252, hint: Span ) -> felt252; + fn update_uri(ref self: TContractState, new_uri: Span); } diff --git a/src/resolver.cairo b/src/resolver.cairo index 261dbfe..b396d4f 100644 --- a/src/resolver.cairo +++ b/src/resolver.cairo @@ -7,11 +7,16 @@ mod Resolver { use ecdsa::check_ecdsa_signature; use resolver::interface::resolver::{IResolver, IResolverDispatcher, IResolverDispatcherTrait}; use storage_read::{main::storage_read_component, interface::IStorageRead}; + use openzeppelin::access::ownable::OwnableComponent; component!(path: storage_read_component, storage: storage_read, event: StorageReadEvent); + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] impl StorageReadImpl = storage_read_component::StorageRead; + #[abi(embed_v0)] + impl OwnableImpl = OwnableComponent::OwnableImpl; + impl OwnableInternalImpl = OwnableComponent::InternalImpl; #[storage] struct Storage { @@ -19,20 +24,34 @@ mod Resolver { uri: LegacyMap, #[substorage(v0)] storage_read: storage_read_component::Storage, + #[substorage(v0)] + ownable: OwnableComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { + StarknetIDOffChainResolverUpdate: StarknetIDOffChainResolverUpdate, #[flat] StorageReadEvent: storage_read_component::Event, + #[flat] + OwnableEvent: OwnableComponent::Event, + } + + #[derive(Drop, starknet::Event)] + struct StarknetIDOffChainResolverUpdate { + uri: Span, } #[constructor] - fn constructor(ref self: ContractState, _public_key: felt252, uri: Span) { + fn constructor( + ref self: ContractState, owner: ContractAddress, _public_key: felt252, uri: Span + ) { + self.ownable.initializer(owner); self.public_key.write(_public_key); self.store_uri(uri); + self.emit(StarknetIDOffChainResolverUpdate { uri }); } #[external(v0)] @@ -66,6 +85,12 @@ mod Resolver { return *hint.at(0); } + + fn update_uri(ref self: ContractState, new_uri: Span) { + self.ownable.assert_only_owner(); + self.store_uri(new_uri); + self.emit(StarknetIDOffChainResolverUpdate { uri: new_uri, }); + } } #[generate_trait] diff --git a/src/tests.cairo b/src/tests.cairo index 95a1975..115c495 100644 --- a/src/tests.cairo +++ b/src/tests.cairo @@ -1,2 +1,2 @@ mod utils; -mod resolver; \ No newline at end of file +mod resolver; diff --git a/src/tests/resolver/erc20.cairo b/src/tests/resolver/erc20.cairo index b22cdba..bce873b 100644 --- a/src/tests/resolver/erc20.cairo +++ b/src/tests/resolver/erc20.cairo @@ -29,4 +29,4 @@ mod ERC20 { #[flat] ERC20Event: ERC20Component::Event, } -} \ No newline at end of file +} diff --git a/src/tests/resolver/test_resolver.cairo b/src/tests/resolver/test_resolver.cairo index 5b904ce..c3707c2 100644 --- a/src/tests/resolver/test_resolver.cairo +++ b/src/tests/resolver/test_resolver.cairo @@ -10,7 +10,7 @@ use starknet::contract_address_const; use starknet::testing::{set_contract_address, set_block_timestamp}; use super::super::utils; -use openzeppelin::token::erc20::{ +use openzeppelin::token::erc20::{ interface::{IERC20Camel, IERC20CamelDispatcher, IERC20CamelDispatcherTrait} }; use super::erc20::ERC20; @@ -24,7 +24,9 @@ use naming::pricing::Pricing; use resolver::interface::resolver::{IResolver, IResolverDispatcher, IResolverDispatcherTrait}; use resolver::resolver::Resolver; -fn deploy() -> ( +fn deploy( + pub_key: felt252 +) -> ( IERC20CamelDispatcher, IPricingDispatcher, IIdentityDispatcher, @@ -47,12 +49,7 @@ fn deploy() -> ( ); let resolver = utils::deploy( - Resolver::TEST_CLASS_HASH, - array![ - 0x64018d8ea7829641419aff38ea79efd3eafedf3a5c1fe001d35339b889d48f4, - 1, - 'http://0.0.0.0:8090' - ] + Resolver::TEST_CLASS_HASH, array![admin, pub_key, 1, 'http://0.0.0.0:8090'] ); ( IERC20CamelDispatcher { contract_address: eth }, @@ -72,7 +69,9 @@ fn deploy() -> ( )] fn test_offchain_resolving_no_hint() { // setup - let (eth, pricing, identity, naming, resolver) = deploy(); + let (eth, pricing, identity, naming, resolver) = deploy( + 0x64018d8ea7829641419aff38ea79efd3eafedf3a5c1fe001d35339b889d48f4 + ); let caller = contract_address_const::<0x123>(); set_contract_address(caller); let id1: u128 = 1; @@ -101,7 +100,9 @@ fn test_offchain_resolving_no_hint() { #[available_gas(20000000000)] fn test_offchain_resolving_with_hint() { // setup - let (eth, pricing, identity, naming, resolver) = deploy(); + let (eth, pricing, identity, naming, resolver) = deploy( + 0x64018d8ea7829641419aff38ea79efd3eafedf3a5c1fe001d35339b889d48f4 + ); let caller = contract_address_const::<0x123>(); set_contract_address(caller); let id1: u128 = 1; @@ -149,7 +150,9 @@ fn test_offchain_resolving_with_hint() { #[should_panic(expected: ('Signature expired', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_offchain_resolving_with_hint_expired_sig() { // setup - let (eth, pricing, identity, naming, resolver) = deploy(); + let (eth, pricing, identity, naming, resolver) = deploy( + 0x64018d8ea7829641419aff38ea79efd3eafedf3a5c1fe001d35339b889d48f4 + ); let caller = contract_address_const::<0x123>(); set_contract_address(caller); let id1: u128 = 1; @@ -178,7 +181,12 @@ fn test_offchain_resolving_with_hint_expired_sig() { .resolve( array![999902, 1059716045].span(), 'starknet', - array![0x04a8173e2F008282aC9793FB929974Cc7CEd6cEb76c79A0A9e0D163e60d08b6f, 1, 2, max_validity] + array![ + 0x04a8173e2F008282aC9793FB929974Cc7CEd6cEb76c79A0A9e0D163e60d08b6f, + 1, + 2, + max_validity + ] .span() ); } @@ -188,7 +196,9 @@ fn test_offchain_resolving_with_hint_expired_sig() { #[should_panic(expected: ('Invalid signature', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_offchain_resolving_with_hint_invalid_sig() { // setup - let (eth, pricing, identity, naming, resolver) = deploy(); + let (eth, pricing, identity, naming, resolver) = deploy( + 0x64018d8ea7829641419aff38ea79efd3eafedf3a5c1fe001d35339b889d48f4 + ); let caller = contract_address_const::<0x123>(); set_contract_address(caller); let id1: u128 = 1;