File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { arrayify , hexlify } from '@ethersproject/bytes' ;
2+ import { keccak256 } from '@ethersproject/keccak256' ;
13import { ChainId , NetworkType } from '@metamask/controller-utils' ;
24import {
35 type TransactionMeta ,
@@ -374,6 +376,13 @@ describe('src/utils.js', () => {
374376 utils . getTxHash ( '0x0302b75dfb9fd9eb34056af0' ) ;
375377 } ) . toThrow ( 'unsupported transaction type: 3' ) ;
376378 } ) ;
379+
380+ it ( 'computes hash for type 4 transaction' , ( ) => {
381+ const type4TxHex = '0x04deadbeef' ;
382+ const expectedHash = hexlify ( keccak256 ( arrayify ( type4TxHex ) ) ) ;
383+ const txHash = utils . getTxHash ( type4TxHex ) ;
384+ expect ( txHash ) . toBe ( expectedHash ) ;
385+ } ) ;
377386 } ) ;
378387
379388 describe ( 'getReturnTxHashAsap' , ( ) => {
Original file line number Diff line number Diff line change @@ -224,6 +224,10 @@ export const incrementNonceInHex = (nonceInHex: string): string => {
224224 return hexlify ( Number ( nonceInDec ) + 1 ) ;
225225} ;
226226
227+ const isType4Transaction = ( signedTxHex : string ) => {
228+ return typeof signedTxHex === 'string' && signedTxHex . startsWith ( '0x04' ) ;
229+ } ;
230+
227231export const getTxHash = ( signedTxHex : any ) => {
228232 if ( ! signedTxHex ) {
229233 return '' ;
@@ -232,7 +236,7 @@ export const getTxHash = (signedTxHex: any) => {
232236 const parsed = parse ( signedTxHex ) ;
233237 return parsed ?. hash ?? '' ;
234238 } catch ( error ) {
235- if ( typeof signedTxHex === 'string' && signedTxHex . startsWith ( '0x04' ) ) {
239+ if ( isType4Transaction ( signedTxHex ) ) {
236240 return hexlify ( keccak256 ( arrayify ( signedTxHex ) ) ) ;
237241 }
238242 throw error ;
You can’t perform that action at this time.
0 commit comments