feat: add support for redelegating from permission contexts#217
Open
jeffsmale90 wants to merge 3 commits intomainfrom
Open
feat: add support for redelegating from permission contexts#217jeffsmale90 wants to merge 3 commits intomainfrom
jeffsmale90 wants to merge 3 commits intomainfrom
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>
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 ERC-7715 permission contexts, significantly improving the developer experience when working with delegation chains.
Previously, developers had to manually decode permission contexts, extract the leaf delegation, and rebuild the chain. This PR streamlines that workflow with new APIs and improved type safety.
🔄 What Changed?
Core API Enhancements
Added
parentPermissionContextparameter tocreateDelegationandcreateOpenDelegationPermissionContext(eitherDelegation[]or encodedHex)Made
scopeoptional when a parent delegation existsNew
redelegatePermissionContextActionHigh-level convenience function for complete redelegation workflow:
Supports both delegation types:
delegateparameterdelegate(usesANY_BENEFICIARY)Client extension pattern:
redelegatePermissionContextActions()signDelegationActions)chainIdfrom client when extendedType Safety Improvements
scope,parentDelegation, orparentPermissionContextcan be provided🚀 Why?
Issue: #196
When creating a redelegation from an ERC-7715 response, developers previously had to:
After this PR, developers can:
Or with the lower-level API:
🧪 How to Test?
Automated Tests
Automated tests added/updated
test/delegation.test.ts: Tests forparentPermissionContextparametertest/actions/redelegatePermissionContext.test.ts: Comprehensive action testsAll existing tests pass
Manual Testing
Test scenarios covered:
Redelegate with specific delegate
Create open redelegation
ANY_BENEFICIARYInherit scope from parent
Override parent scope
Client extension pattern
redelegatePermissionContextActions()📋 Checklist
🔗 Related Issues
Closes #196
📚 Additional Notes
Design Decisions
Why discriminated union for parent parameters?
parentDelegationandparentPermissionContextWhy make scope optional?
Why return both
delegationandpermissionContext?delegation: for inspection or further manipulationpermissionContext: ready to use in transactions immediatelyFuture Considerations
Examples
Full working examples are included in the JSDoc comments of the new functions.
Slack Thread