Skip to content

Create functionality for delegating account permissions#27

Closed
kadoso-noni wants to merge 2 commits intoChain-Library:mainfrom
kadoso-noni:account_delegation
Closed

Create functionality for delegating account permissions#27
kadoso-noni wants to merge 2 commits intoChain-Library:mainfrom
kadoso-noni:account_delegation

Conversation

@kadoso-noni
Copy link
Contributor

Account Delegation Smart Contract
Overview
This PR introduces the AccountDelegation smart contract, a comprehensive solution for managing permissions delegation on StarkNet. The contract enables account owners to delegate specific permissions to other addresses with fine-grained control over delegation lifetimes and usage limits.
Features
Permission Types
The contract supports multiple delegation scopes:

Transfer: Permission to transfer tokens
Sign: Permission to sign messages
Call: Permission to call specific contracts
Admin: Full administrative access

Delegation Controls
Each delegation can be configured with:

Expiration Time: Delegations automatically expire after a specified timestamp
Action Limits: Delegations can be limited to a specific number of uses
Active Status: Delegations can be revoked at any time

Flexible Ownership

Multiple owners can be registered
Only owners can create delegations
Each owner manages their own delegations independently

Technical Details
Storage Structure

delegations: Maps from owner address and permission type to delegation details
owners: Maps an address to a boolean indicating ownership status

Events

DelegationCreated: Emitted when a new delegation is created
DelegationRevoked: Emitted when a delegation is explicitly revoked
DelegationUsed: Emitted each time a delegation is used
DelegationExpired: Emitted when a delegation expires during use

Error Handling
Comprehensive error handling for all operations:

NotAuthorized: Caller lacks required permissions
DelegationExpired: Attempted to use an expired delegation
ActionLimitReached: Maximum number of actions already performed
DelegationNotActive: Delegation has been deactivated
InvalidDelegate: Invalid delegate address provided
InvalidExpiry: Invalid expiration time provided

Core Functionality Tests

Contract initialization
Owner management
Delegation creation with various parameters
Delegation revocation
Permission checking
Delegation usage tracking

Edge Cases

Unlimited delegations (no expiry, no action limit)
Multiple delegation types for the same delegate
Multiple owners creating independent delegations

Security Testing

Unauthorized access attempts
Zero address validation
Past expiry validation
Action limit enforcement
Expiration handling
Delegation status verification

Security Considerations

All ownership and delegation operations check caller permissions
Time-based expirations are enforced on delegation usage
Action limits are strictly enforced
Delegations are automatically deactivated when limits are reached
All state changes emit appropriate events

@Pvsaint
Copy link
Contributor

Pvsaint commented Apr 30, 2025

@kadoso-noni please resolve the conflicts

@Pvsaint Pvsaint closed this May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants