2
2
* @prettier
3
3
*/
4
4
import { CoinFamily } from '@bitgo/statics' ;
5
+ import isEqual from 'lodash/isEqual' ;
5
6
6
7
import {
7
8
DelegationOptions ,
@@ -381,6 +382,7 @@ export class StakingWallet implements IStakingWallet {
381
382
}
382
383
383
384
const explainedTransaction = await coin . explainTransaction ( result ) ;
385
+ const mismatchErrors : string [ ] = [ ] ;
384
386
385
387
if ( buildParams ?. recipients && buildParams . recipients . length > 0 ) {
386
388
const userRecipientMap = new Map (
@@ -389,9 +391,6 @@ export class StakingWallet implements IStakingWallet {
389
391
const platformRecipientMap = new Map (
390
392
( explainedTransaction ?. outputs ?? [ ] ) . map ( ( recipient ) => [ recipient . address . toLowerCase ( ) , recipient ] )
391
393
) ;
392
-
393
- const mismatchErrors : string [ ] = [ ] ;
394
-
395
394
for ( const [ address ] of platformRecipientMap ) {
396
395
if ( ! userRecipientMap . has ( address ) ) {
397
396
mismatchErrors . push ( `Unexpected recipient address found in built transaction: ${ address } ` ) ;
@@ -420,13 +419,60 @@ export class StakingWallet implements IStakingWallet {
420
419
) ;
421
420
}
422
421
}
423
- if ( mismatchErrors . length > 0 ) {
424
- const errorMessage = `Staking transaction validation failed before signing: ${ mismatchErrors . join ( '; ' ) } ` ;
425
- debug ( errorMessage ) ;
426
- throw new Error ( errorMessage ) ;
422
+ }
423
+
424
+ if ( buildParams ?. memo && ( explainedTransaction as any ) . memo !== buildParams . memo ) {
425
+ mismatchErrors . push (
426
+ `Memo mismatch. Expected: '${ JSON . stringify ( buildParams . memo ) } ', Got: '${ JSON . stringify (
427
+ ( explainedTransaction as any ) . memo
428
+ ) } '`
429
+ ) ;
430
+ }
431
+
432
+ if ( buildParams ?. gasLimit && String ( ( explainedTransaction as any ) . gasLimit ) !== String ( buildParams . gasLimit ) ) {
433
+ mismatchErrors . push (
434
+ `Gas Limit mismatch. Expected: ${ buildParams . gasLimit } , Got: ${ ( explainedTransaction as any ) . gasLimit } `
435
+ ) ;
436
+ }
437
+
438
+ if ( buildParams ?. type && ( explainedTransaction as any ) . type !== buildParams . type ) {
439
+ mismatchErrors . push (
440
+ `Transaction type mismatch. Expected: '${ buildParams . type } ', Got: '${ ( explainedTransaction as any ) . type } '`
441
+ ) ;
442
+ }
443
+
444
+ if ( buildParams ?. solInstructions ) {
445
+ if ( ! isEqual ( ( explainedTransaction as any ) . solInstructions , buildParams . solInstructions ) ) {
446
+ mismatchErrors . push (
447
+ `Solana instructions mismatch. Expected: ${ JSON . stringify (
448
+ buildParams . solInstructions
449
+ ) } , Got: ${ JSON . stringify ( ( explainedTransaction as any ) . solInstructions ) } `
450
+ ) ;
451
+ }
452
+ }
453
+
454
+ if ( buildParams ?. aptosCustomTransactionParams ) {
455
+ if (
456
+ ! isEqual ( ( explainedTransaction as any ) . aptosCustomTransactionParams , buildParams . aptosCustomTransactionParams )
457
+ ) {
458
+ mismatchErrors . push (
459
+ `Aptos custom transaction parameters mismatch. Expected: ${ JSON . stringify (
460
+ buildParams . aptosCustomTransactionParams
461
+ ) } , Got: ${ JSON . stringify ( ( explainedTransaction as any ) . aptosCustomTransactionParams ) } `
462
+ ) ;
427
463
}
428
- } else {
429
- debug ( `Cannot validate staking transaction ${ transaction . stakingRequestId } without specified build params` ) ;
464
+ }
465
+
466
+ if ( mismatchErrors . length > 0 ) {
467
+ const errorMessage = `Staking transaction validation failed before signing: ${ mismatchErrors . join ( '; ' ) } ` ;
468
+ debug ( errorMessage ) ;
469
+ throw new Error ( errorMessage ) ;
470
+ }
471
+
472
+ if ( ! buildParams ) {
473
+ debug (
474
+ `Cannot perform deep validation for staking transaction ${ transaction . stakingRequestId } without specified build params`
475
+ ) ;
430
476
}
431
477
}
432
478
}
0 commit comments