11import {
22 encodeDelegations as encodeDelegationsCore ,
33 decodeDelegations as decodeDelegationsCore ,
4+ getDelegationHash as getDelegationHashCore ,
5+ ANY_BENEFICIARY ,
6+ DELEGATION_TYPEHASH ,
7+ CAVEAT_TYPEHASH ,
8+ ROOT_AUTHORITY ,
49} from '@metamask/delegation-core' ;
5- import {
6- encodeAbiParameters ,
7- parseAbiParameters ,
8- keccak256 ,
9- hashMessage ,
10- toBytes ,
11- toHex ,
12- getAddress ,
13- } from 'viem' ;
10+ import { hashMessage , toBytes , toHex , getAddress } from 'viem' ;
1411import type {
1512 TypedData ,
1613 AbiParameter ,
@@ -23,13 +20,16 @@ import type {
2320} from 'viem' ;
2421
2522import { type Caveats , resolveCaveats } from './caveatBuilder' ;
26- import {
27- CAVEAT_ABI_TYPE_COMPONENTS ,
28- getCaveatArrayPacketHash ,
29- } from './caveats' ;
30- import { ROOT_AUTHORITY } from './constants' ;
23+ import { CAVEAT_ABI_TYPE_COMPONENTS } from './caveats' ;
3124import type { Delegation } from './types' ;
3225
26+ export {
27+ ANY_BENEFICIARY ,
28+ DELEGATION_TYPEHASH ,
29+ CAVEAT_TYPEHASH ,
30+ ROOT_AUTHORITY ,
31+ } ;
32+
3333/**
3434 * The ABI type components of a Delegation.
3535 */
@@ -141,21 +141,6 @@ export const decodePermissionContexts = (encoded: Hex[]): Delegation[][] => {
141141 return delegationChains ;
142142} ;
143143
144- /**
145- * To be used in the allowList field of a gas delegation so as not to restrict who can redeem the gas delegation.
146- */
147- export const ANY_BENEFICIARY = '0x0000000000000000000000000000000000000a11' ;
148-
149- /**
150- * To be used when generating a delegation hash to be signed
151- * NOTE: signature is omitted from the Delegation typehash
152- */
153- export const DELEGATION_TYPEHASH = keccak256 (
154- toHex (
155- 'Delegation(address delegate,address delegator,bytes32 authority,Caveat[] caveats,uint256 salt)Caveat(address enforcer,bytes terms)' ,
156- ) ,
157- ) ;
158-
159144/**
160145 * TypedData to be used when signing a Delegation. Delegation value for `signature` and Caveat values for `args` are omitted as they cannot be known at signing time.
161146 */
@@ -200,19 +185,7 @@ export const prepDelegationHashForPasskeySign = (delegationHash: Hex) => {
200185export const getDelegationHashOffchain = ( input : Delegation ) : Hex => {
201186 const delegationStruct = toDelegationStruct ( input ) ;
202187
203- const encoded = encodeAbiParameters (
204- parseAbiParameters ( 'bytes32, address, address, bytes32, bytes32, uint' ) ,
205- [
206- DELEGATION_TYPEHASH ,
207- delegationStruct . delegate ,
208- delegationStruct . delegator ,
209- delegationStruct . authority ,
210- getCaveatArrayPacketHash ( delegationStruct . caveats ) ,
211- delegationStruct . salt ,
212- ] ,
213- ) ;
214-
215- return keccak256 ( encoded ) ;
188+ return getDelegationHashCore ( delegationStruct ) ;
216189} ;
217190
218191type BaseCreateDelegationOptions = {
0 commit comments