Commit 1ab7749
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
- src
- actions
- caveatBuilder
- test
- actions
- caveatBuilder
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
| |||
0 commit comments