Add hashDelegation function to @metamask/delegation-core #13
Merged
Conversation
81b4fee to
edda70a
Compare
…related constants.
edda70a to
905f873
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors and consolidates delegation hashing logic by introducing a new getDelegationHash function in delegation-core. It updates related tests and re-exports delegation constants in delegation-toolkit while renaming types for clarity.
- Updated import and export paths in delegation-toolkit and delegation-core.
- Introduced getDelegationHash and related helper functions in delegation-core.
- Renamed types (Delegation and Caveat → DelegationStruct and CaveatStruct) and removed duplicate constant definitions.
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/delegation-toolkit/test/experimental/delegationStorageTestData.ts | Updated import style for delegation functions and constants. |
| packages/delegation-toolkit/test/delegation.test.ts | Adjusted test imports and usage to match new delegation-core exports and type renamings. |
| packages/delegation-toolkit/src/index.ts | Re-ordered exports to remove duplicates and re-export delegation-core constants. |
| packages/delegation-toolkit/src/delegation.ts | Replaced local getDelegationHashOffchain with delegation-core’s getDelegationHash. |
| packages/delegation-toolkit/src/constants.ts | Removed duplicate constant definitions (ANY_DELEGATE) in favor of ANY_BENEFICIARY. |
| packages/delegation-toolkit/src/DelegationFramework/*/constants.ts | Updated exports to reference delegation-core instead of legacy constants. |
| packages/delegation-core/test/delegation.test.ts | Added extensive tests for getDelegationHash and updated type usage. |
| packages/delegation-core/src/types.ts | Renamed Delegation and Caveat types to DelegationStruct and CaveatStruct. |
| packages/delegation-core/src/index.ts | Updated re-exports to reflect new type names and added getDelegationHash export. |
| packages/delegation-core/src/delegation.ts | Added getDelegationHash with improved encoding and hashing logic using @noble/hashes. |
| packages/delegation-core/package.json | Added dependency on @noble/hashes for keccak256 implementation. |
Comments suppressed due to low confidence (3)
packages/delegation-core/src/types.ts:12
- [nitpick] Consider updating the type documentation to reflect the new naming convention from 'Caveat' to 'CaveatStruct' to improve clarity for future developers.
export type CaveatStruct<TBytes extends BytesLike = BytesLike> = {
packages/delegation-core/src/types.ts:28
- [nitpick] Consider updating the documentation to clarify the renaming from 'Delegation' to 'DelegationStruct', ensuring consistency in type usage across the codebase.
export type DelegationStruct<TBytes extends BytesLike = BytesLike> = {
packages/delegation-core/src/delegation.ts:237
- [nitpick] Consider adding a comment clarifying that the 'args' field is intentionally excluded from the caveat hash computation, as supported by the associated test cases.
function getCaveatsArrayHash(caveats: CaveatStruct[]): Uint8Array {
… validated against current version of @metamask/delegation-toolkit
getDelegationHash function to @metamask/delegation-core hashDelegation function to @metamask/delegation-core
hanzel98
reviewed
Jun 30, 2025
hanzel98
reviewed
Jun 30, 2025
hanzel98
previously approved these changes
Jun 30, 2025
- Updated description of ANY_BENEFICIARY to be more descriptive - Fixed incorrect definition of DELEGATION_TYPEHASH, which excluded the caveat suffix Co-authored-by: Hanzel Anchia Mena <33629234+hanzel98@users.noreply.github.com>
hanzel98
approved these changes
Jul 1, 2025
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
Adds a function
hashDelegationto @metamask/delegation-core, along with hash encoding constants. Consumes these within @metamask/delegation-toolkit.🔄 What Changed?
hashDelegationand related tests to @metamask/delegation-coreDELEGATION_TYPEHASH,CAVEAT_TYPEHASH, andANY_BENEFICIARY(that last one is only loosely related to the change) constants to @metamask/delegation-coregetDelegationHashOffchainto use delegation-core implementationANY_BENEFICIARY,DELEGATION_TYPEHASH,CAVEAT_TYPEHASH, andROOT_AUTHORITYfrom @metamask/delegation-core rather than re-defining them. RemovesANY_DELEGATEwhich is a duplicate ofANY_BENEFICIARY(and was exported from the API asANY_BENEFICIARY).🚀 Why?
Delegation hashing is required in snaps and extension, so moving this implementation into core allows these low level consumers access to this functionality, without adding @metamask/delegation-toolkit as a dependency.
🧪 How to Test?
New unit tests are added to @metamask/delegation-core covering the new functionality, in addition to the existing unit tests in @metamask/delegation-toolkit and integration tests in delegator-e2e.
List any breaking changes: