-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Origin/ft signatory impl #47
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
89918ff
chore: add signatory component
Darlington02 981262f
chore: add permissionable component, update signatory comp.
Darlington02 860c2e2
chore: abstract `is_valid_signature` into Signatory
Darlington02 975bc01
chore: update signatory component
Darlington02 229d078
unit test for permissionable docs
mubarak23 07fdf5c
fix changes requested on the PR
mubarak23 e22110a
check for caller is the account owner
mubarak23 445f57c
unit test for signatory component
mubarak23 5ab435a
add check for caller address
mubarak23 87735f5
root owner and permissioned address signature test
mubarak23 a7f2d89
fix test functions base on review requested
mubarak23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,112 @@ | ||
// permissionable component | ||
// ************************************************************************* | ||
// PERMISSIONABLE COMPONENT | ||
// ************************************************************************* | ||
#[starknet::component] | ||
pub mod PermissionableComponent { | ||
// ************************************************************************* | ||
// IMPORTS | ||
// ************************************************************************* | ||
use starknet::storage::{Map, StorageMapReadAccess, StorageMapWriteAccess}; | ||
use starknet::{ContractAddress, get_caller_address, get_block_timestamp}; | ||
use token_bound_accounts::components::account::account::AccountComponent; | ||
use token_bound_accounts::interfaces::IAccount::{IAccount, IAccountDispatcherTrait}; | ||
use token_bound_accounts::components::account::account::AccountComponent::InternalImpl; | ||
use token_bound_accounts::interfaces::IPermissionable::{ | ||
IPermissionable, IPermissionableDispatcher, IPermissionableDispatcherTrait | ||
}; | ||
|
||
// ************************************************************************* | ||
// STORAGE | ||
// ************************************************************************* | ||
#[storage] | ||
pub struct Storage { | ||
permissions: Map< | ||
(ContractAddress, ContractAddress), bool | ||
> // <<owner, permissioned_address>, bool> | ||
} | ||
|
||
// ************************************************************************* | ||
// EVENTS | ||
// ************************************************************************* | ||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
pub enum Event { | ||
PermissionUpdated: PermissionUpdated | ||
} | ||
|
||
// @notice emitted when permissions are updated for an account | ||
// @param owner tokenbound account owner | ||
// @param permissioned_address address to be given/revoked permission | ||
// @param has_permission returns true if user has permission else false | ||
#[derive(Drop, starknet::Event)] | ||
pub struct PermissionUpdated { | ||
#[key] | ||
pub owner: ContractAddress, | ||
pub permissioned_address: ContractAddress, | ||
pub has_permission: bool, | ||
} | ||
|
||
// ************************************************************************* | ||
// ERRORS | ||
// ************************************************************************* | ||
pub mod Errors { | ||
pub const INVALID_LENGTH: felt252 = 'Account: invalid length'; | ||
pub const UNAUTHORIZED: felt252 = 'Account: unauthorized'; | ||
} | ||
|
||
|
||
// ************************************************************************* | ||
// EXTERNAL FUNCTIONS | ||
// ************************************************************************* | ||
#[embeddable_as(PermissionableImpl)] | ||
pub impl Permissionable< | ||
TContractState, | ||
+HasComponent<TContractState>, | ||
+Drop<TContractState>, | ||
impl Account: AccountComponent::HasComponent<TContractState> | ||
> of IPermissionable<ComponentState<TContractState>> { | ||
// @notice sets permission for an account | ||
// @permissioned_addresses array of addresses who's permission is to be updated | ||
// @param permssions permission value <true, false> | ||
fn set_permission( | ||
ref self: ComponentState<TContractState>, | ||
permissioned_addresses: Array<ContractAddress>, | ||
permissions: Array<bool> | ||
) { | ||
assert(permissioned_addresses.len() == permissions.len(), Errors::INVALID_LENGTH); | ||
|
||
let account_comp = get_dep_component!(@self, Account); | ||
let owner = account_comp.owner(); | ||
assert(owner == get_caller_address(), Errors::UNAUTHORIZED); | ||
|
||
let length = permissioned_addresses.len(); | ||
let mut index: u32 = 0; | ||
while index < length { | ||
self | ||
.permissions | ||
.write((owner, *permissioned_addresses[index]), *permissions[index]); | ||
self | ||
.emit( | ||
PermissionUpdated { | ||
owner: owner, | ||
permissioned_address: *permissioned_addresses[index], | ||
has_permission: *permissions[index] | ||
} | ||
); | ||
index += 1 | ||
} | ||
} | ||
|
||
// @notice returns if a user has permission or not | ||
// @param owner tokenbound account owner | ||
// @param permissioned_address address to check permission for | ||
fn has_permission( | ||
self: @ComponentState<TContractState>, | ||
owner: ContractAddress, | ||
permissioned_address: ContractAddress | ||
) -> bool { | ||
let permission = self.permissions.read((owner, permissioned_address)); | ||
permission | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was going over our implementation again and it just came to mind that we should enforce only the contract owner calling this function. else permissioned addresses might give permissions to random addresses on the owner's account.
So let's enforce an assert that checks that the caller is the account owner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you marked this as resolved, but it's still yet to be resolved. assert that only owner can call this function