Skip to content

Commit 1ab7749

Browse files
feat: add support for redelegating from permission contexts (#217)
* feat: add support for redelegating from permission contexts This implements support for creating redelegations from ERC-7715 permission contexts, improving the developer experience when working with delegation chains. Key changes: 1. **Enhanced createDelegation/createOpenDelegation**: - Added parameter to accept PermissionContext directly - Made optional when a parent delegation exists (scope is inherited) - Supports both Delegation[] and encoded Hex formats 2. **New redelegatePermissionContext action**: - High-level convenience function for the complete redelegation workflow - Automatically extracts leaf delegation from permission context - Signs the new delegation and returns updated permission context - Supports both specific delegate and open delegation (ANY_BENEFICIARY) - Can be used standalone or as a client extension via redelegatePermissionContextActions 3. **Improved type safety**: - Uses discriminated unions to ensure only one parent source is provided - Prevents conflicting parentDelegation and parentPermissionContext parameters 4. **Comprehensive test coverage**: - Tests for parentPermissionContext with Delegation arrays and encoded Hex - Tests for scope inheritance when no scope is provided - Tests for scope override with explicit scope parameter - Tests for both standalone and client extension usage patterns Breaking changes: None. All existing APIs remain unchanged and backward compatible. Addresses: #196 Co-authored-by: jeffsmale90 <jeffsmale90@users.noreply.github.com> * fix: correct type annotation for tokenAddress in test Co-authored-by: jeffsmale90 <jeffsmale90@users.noreply.github.com> * fix: resolve linting issues - Fix import order in redelegatePermissionContext.ts and test files - Remove forbidden non-null assertion, use explicit check instead - Apply auto-formatting fixes Co-authored-by: jeffsmale90 <jeffsmale90@users.noreply.github.com> * Refine changes to createDelegation and createOpenDelegation - resolveParentDelegation accepts config rather than position arguments - simplifies hasParentDelegation in trackSmartAccountsKitFunctionCall - refactors tests to enforce strict hierarchy - adds a new test to ensure an empty permission context is rejected * Ensure that only delegations with inheritance may be created without a scope * Refine redelegatePermissionContext function * Add changelog entry * Split redelegatePermissionContext into redelegatePermissionContext and redelegateOpenPermissionContext * Allow insecure unrestricted delegation when signing a redelegation * Pass parentDelegation.delegate as the 'from' address instead of the signer's address * Tighten up requirements for createDelegation and createOpenDelegation params: - parentDelegation may not be ROOT_AUTHORITY - resolveCaveats now accepts isScopeOptional rather than hasInheritance * Refactor createDelegation and createOpenDelegation to use shared resolveDelegationArgs * If parent delegation is an opendelegation, from should be the signer * Fix incorrect checking of root_authority rather than any_delegate --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: jeffsmale90 <jeffsmale90@users.noreply.github.com>
1 parent dd5b564 commit 1ab7749

8 files changed

Lines changed: 1463 additions & 18 deletions

File tree

packages/smart-accounts-kit/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add utils and wallet actions for redelegating a `permissionContext`: ([#217](https://github.com/metamask/smart-accounts-kit/pull/217))
13+
1014
## [1.4.0]
1115

1216
### Added

packages/smart-accounts-kit/src/actions/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ export {
5050
type SignUserOperationReturnType,
5151
} from './signUserOperation';
5252

53+
// Redelegation actions
54+
export {
55+
redelegatePermissionContext,
56+
redelegatePermissionContextOpen,
57+
redelegatePermissionContextActions,
58+
type RedelegatePermissionContextParameters,
59+
type RedelegatePermissionContextOpenParameters,
60+
type RedelegatePermissionContextReturnType,
61+
} from './redelegatePermissionContext';
62+
5363
export {
5464
erc7715RequestExecutionPermissionsAction as requestExecutionPermissions,
5565
type MetaMaskExtensionClient,

0 commit comments

Comments
 (0)