-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e16439b
commit 89918ff
Showing
10 changed files
with
142 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod lockable; | |
pub mod permissionable; | ||
pub mod upgradeable; | ||
pub mod presets; | ||
pub mod signatory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod signatory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// ************************************************************************* | ||
// SIGNATORY COMPONENT | ||
// ************************************************************************* | ||
#[starknet::component] | ||
pub mod SignatoryComponent { | ||
// ************************************************************************* | ||
// IMPORTS | ||
// ************************************************************************* | ||
use starknet::{ | ||
get_caller_address, get_contract_address, ContractAddress | ||
}; | ||
use token_bound_accounts::components::account::account::AccountComponent; | ||
use token_bound_accounts::components::account::account::AccountComponent::InternalImpl; | ||
|
||
// ************************************************************************* | ||
// STORAGE | ||
// ************************************************************************* | ||
#[storage] | ||
pub struct Storage {} | ||
|
||
// ************************************************************************* | ||
// PRIVATE FUNCTIONS | ||
// ************************************************************************* | ||
#[generate_trait] | ||
pub impl Private< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
+Drop<TContractState>, | ||
impl Account: AccountComponent::HasComponent<TContractState> | ||
> of PrivateTrait<TContractState> { | ||
/// @notice implements a simple signer validation where only NFT owner is a valid signer. | ||
/// @param signer the address to be validated | ||
fn _base_signer_validation(self: @ComponentState<TContractState>, signer: ContractAddress) -> bool { | ||
let account = get_dep_component!(self, Account); | ||
let (contract_address, token_id, _) = account._get_token(); | ||
|
||
// get owner | ||
let owner = account | ||
._get_owner(contract_address, token_id); | ||
|
||
// validate | ||
if (signer == owner) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/// @notice implements a signer validation where both NFT owner and the root owner (for nested accounts) are valid signers. | ||
/// @param signer the address to be validated | ||
fn _base_and_root_signer_validation(self: @ComponentState<TContractState>, signer: ContractAddress) -> bool { | ||
let account = get_dep_component!(self, Account); | ||
let (contract_address, token_id, _) = account._get_token(); | ||
|
||
// get owner | ||
let owner = account | ||
._get_owner(contract_address, token_id); | ||
// get root owner | ||
let root_owner = account | ||
._get_root_owner(contract_address, token_id); | ||
|
||
// validate | ||
if (signer == owner) { | ||
return true; | ||
} | ||
else if(signer == root_owner) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
/// @notice implements a more complex signer validation where NFT owner, root owner, and permissioned addresses are valid signers. | ||
/// @param signer the address to be validated | ||
fn _permissioned_signer_validation(self: @ComponentState<TContractState>, signer: ContractAddress) -> bool { | ||
true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod IRegistry; | |
pub mod IUpgradeable; | ||
pub mod IExecutable; | ||
pub mod ILockable; | ||
pub mod ISignatory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// ************************************************************************* | ||
// SIGNER VALIDATION INTERFACE | ||
// ************************************************************************* | ||
use starknet::ContractAddress; | ||
|
||
#[starknet::interface] | ||
pub trait ISignatory<TContractState> { | ||
fn is_valid_signer(self: @TContractState, signer: ContractAddress) -> bool; | ||
} |