11import {
22 encodeDelegations as encodeDelegationsCore ,
33 decodeDelegations as decodeDelegationsCore ,
4+ getDelegationHash as getDelegationHashCore ,
5+ ANY_BENEFICIARY ,
6+ DELEGATION_TYPEHASH ,
7+ CAVEAT_TYPEHASH ,
48} from '@metamask/delegation-core' ;
5- import {
6- encodeAbiParameters ,
7- parseAbiParameters ,
8- keccak256 ,
9- hashMessage ,
10- toBytes ,
11- toHex ,
12- getAddress ,
13- } from 'viem' ;
9+ import { hashMessage , toBytes , toHex , getAddress } from 'viem' ;
1410import type {
1511 TypedData ,
1612 AbiParameter ,
@@ -23,13 +19,12 @@ import type {
2319} from 'viem' ;
2420
2521import { type Caveats , resolveCaveats } from './caveatBuilder' ;
26- import {
27- CAVEAT_ABI_TYPE_COMPONENTS ,
28- getCaveatArrayPacketHash ,
29- } from './caveats' ;
22+ import { CAVEAT_ABI_TYPE_COMPONENTS } from './caveats' ;
3023import { ROOT_AUTHORITY } from './constants' ;
3124import type { Delegation } from './types' ;
3225
26+ export { ANY_BENEFICIARY , DELEGATION_TYPEHASH , CAVEAT_TYPEHASH } ;
27+
3328/**
3429 * The ABI type components of a Delegation.
3530 */
@@ -141,21 +136,6 @@ export const decodePermissionContexts = (encoded: Hex[]): Delegation[][] => {
141136 return delegationChains ;
142137} ;
143138
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-
159139/**
160140 * 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.
161141 */
@@ -200,19 +180,7 @@ export const prepDelegationHashForPasskeySign = (delegationHash: Hex) => {
200180export const getDelegationHashOffchain = ( input : Delegation ) : Hex => {
201181 const delegationStruct = toDelegationStruct ( input ) ;
202182
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 ) ;
183+ return getDelegationHashCore ( delegationStruct ) ;
216184} ;
217185
218186type BaseCreateDelegationOptions = {
0 commit comments