feat: add support for redelegating from permission contexts#217
Merged
Conversation
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>
Co-authored-by: jeffsmale90 <jeffsmale90@users.noreply.github.com>
- 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>
f6dbdd9 to
5cad4df
Compare
- 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
337d8e4 to
fba187e
Compare
…d redelegateOpenPermissionContext
mj-kiwi
reviewed
May 10, 2026
mj-kiwi
reviewed
May 10, 2026
mj-kiwi
reviewed
May 11, 2026
mj-kiwi
reviewed
May 11, 2026
… params: - parentDelegation may not be ROOT_AUTHORITY - resolveCaveats now accepts isScopeOptional rather than hasInheritance
6e6c2b7 to
3fa9795
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6273f37. Configure here.
mj-kiwi
approved these changes
May 11, 2026
jeffsmale90
added a commit
that referenced
this pull request
May 12, 2026
jeffsmale90
added a commit
that referenced
this pull request
May 12, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

📝 Description
This PR implements support for creating redelegations from existing permission contexts (e.g., ERC-7715 responses), significantly improving the developer experience when working with delegation chains.
Previously, developers had to manually decode permission contexts, extract the leaf delegation, sign a new delegation, and re-encode the chain. This PR streamlines that workflow with new APIs and improved type safety.
🔄 What Changed?
Core API Enhancements (
createDelegation/createOpenDelegation)Added
parentPermissionContextparameter tocreateDelegationandcreateOpenDelegationPermissionContext(either aDelegation[]or encodedHex)parentDelegationandscopeso the three options are mutually exclusive at the type levelMade
scopeoptional when a parent delegation/permission context existsresolveCaveatsnow takeshasInheritanceScope is required when the delegation has no inheritancewhen scope is missing on a root delegationNew Redelegation Actions
Two explicit, high-level convenience functions that handle the full redelegation workflow. They mirror the
createDelegation/createOpenDelegationsplit so callers always get the kind of delegation they expect — no optionaltoflag deciding the shape of the result.redelegatePermissionContext— creates a redelegation to a specific delegate (tois required).redelegatePermissionContextOpen— creates an open redelegation (delegate isANY_BENEFICIARY); does not acceptto.Both functions:
signDelegationdelegationand the encodedpermissionContextShared parameters:
account?— defaults toclient.accountenvironment— providesDelegationManagerand caveat enforcerspermissionContext— the context to redelegate fromchainId— chain id used for the EIP-712 signaturescope?— optional override; inherits from parent when omittedcaveats?— additional caveats to applysalt?— optional salt for uniquenessredelegatePermissionContextadditionally requires:to— the address of the new delegateClient Extension (
redelegatePermissionContextActions)signDelegationActions)redelegatePermissionContextandredelegatePermissionContextOpento the wallet client when.extend()-edchainIdfromclient.chain.idfor both actions (throwsChain ID is requiredif neither client chain norchainIdis provided)Type Safety
BaseCreateDelegationOptionstype uses a discriminated union so exactly one of the following is allowed:scope(root delegation, no parent)parentDelegation(with optionalscope)parentPermissionContext(with optionalscope)RedelegatePermissionContextParametersvsRedelegatePermissionContextOpenParameters), so the choice between specific and open is made at the call site rather than via an optional flag.🚀 Why?
Issue: #196
Before this PR, redelegating from an ERC-7715 response required manual orchestration:
Now, you can use the
parentPermissionContextparameter oncreateDelegation:Or, use the dedicated actions to redelegate directly: