@@ -28,7 +28,7 @@ import {
2828 PresignTransactionOptions as BasePresignTransactionOptions ,
2929 Recipient ,
3030 SignTransactionOptions as BaseSignTransactionOptions ,
31- SuspiciousTransactionError ,
31+ TxIntentMismatchError ,
3232 TransactionParams ,
3333 TransactionPrebuild as BaseTransactionPrebuild ,
3434 TransactionRecipient ,
@@ -2768,6 +2768,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27682768 * @param {TransactionPrebuild } params.txPrebuild - prebuild object returned by server
27692769 * @param {Wallet } params.wallet - Wallet object to obtain keys to verify against
27702770 * @returns {boolean }
2771+ * @throws {TxIntentMismatchError } if transaction validation fails
27712772 */
27722773 async verifyTssTransaction ( params : VerifyEthTransactionOptions ) : Promise < boolean > {
27732774 const { txParams, txPrebuild, wallet } = params ;
@@ -2778,13 +2779,13 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27782779 ( txParams . type && [ 'acceleration' , 'fillNonce' , 'transferToken' , 'tokenApproval' ] . includes ( txParams . type ) )
27792780 )
27802781 ) {
2781- throw new SuspiciousTransactionError ( `missing txParams` ) ;
2782+ throw new TxIntentMismatchError ( `missing txParams` , '' , [ ] , '' ) ;
27822783 }
27832784 if ( ! wallet || ! txPrebuild ) {
2784- throw new SuspiciousTransactionError ( `missing params` ) ;
2785+ throw new TxIntentMismatchError ( `missing params` , '' , [ ] , '' ) ;
27852786 }
27862787 if ( txParams . hop && txParams . recipients && txParams . recipients . length > 1 ) {
2787- throw new SuspiciousTransactionError ( `tx cannot be both a batch and hop transaction` ) ;
2788+ throw new TxIntentMismatchError ( `tx cannot be both a batch and hop transaction` , '' , [ ] , '' ) ;
27882789 }
27892790
27902791 if ( txParams . type && [ 'transfer' ] . includes ( txParams . type ) ) {
@@ -2799,25 +2800,41 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27992800 const txJson = tx . toJson ( ) ;
28002801 if ( txJson . data === '0x' ) {
28012802 if ( expectedAmount !== txJson . value ) {
2802- throw new SuspiciousTransactionError (
2803- 'the transaction amount in txPrebuild does not match the value given by client'
2803+ throw new TxIntentMismatchError (
2804+ 'the transaction amount in txPrebuild does not match the value given by client' ,
2805+ '' ,
2806+ [ ] ,
2807+ ''
28042808 ) ;
28052809 }
28062810 if ( expectedDestination . toLowerCase ( ) !== txJson . to . toLowerCase ( ) ) {
2807- throw new SuspiciousTransactionError ( 'destination address does not match with the recipient address' ) ;
2811+ throw new TxIntentMismatchError (
2812+ 'destination address does not match with the recipient address' ,
2813+ '' ,
2814+ [ ] ,
2815+ ''
2816+ ) ;
28082817 }
28092818 } else if ( txJson . data . startsWith ( '0xa9059cbb' ) ) {
28102819 const [ recipientAddress , amount ] = getRawDecoded (
28112820 [ 'address' , 'uint256' ] ,
28122821 getBufferedByteCode ( '0xa9059cbb' , txJson . data )
28132822 ) ;
28142823 if ( expectedAmount !== amount . toString ( ) ) {
2815- throw new SuspiciousTransactionError (
2816- 'the transaction amount in txPrebuild does not match the value given by client'
2824+ throw new TxIntentMismatchError (
2825+ 'the transaction amount in txPrebuild does not match the value given by client' ,
2826+ '' ,
2827+ [ ] ,
2828+ ''
28172829 ) ;
28182830 }
28192831 if ( expectedDestination . toLowerCase ( ) !== addHexPrefix ( recipientAddress . toString ( ) ) . toLowerCase ( ) ) {
2820- throw new SuspiciousTransactionError ( 'destination address does not match with the recipient address' ) ;
2832+ throw new TxIntentMismatchError (
2833+ 'destination address does not match with the recipient address' ,
2834+ '' ,
2835+ [ ] ,
2836+ ''
2837+ ) ;
28212838 }
28222839 }
28232840 }
@@ -2834,6 +2851,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28342851 * @param {TransactionPrebuild } params.txPrebuild - prebuild object returned by server
28352852 * @param {Wallet } params.wallet - Wallet object to obtain keys to verify against
28362853 * @returns {boolean }
2854+ * @throws {TxIntentMismatchError } if transaction validation fails
28372855 */
28382856 async verifyTransaction ( params : VerifyEthTransactionOptions ) : Promise < boolean > {
28392857 const ethNetwork = this . getNetwork ( ) ;
@@ -2844,21 +2862,27 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28442862 }
28452863
28462864 if ( ! txParams ?. recipients || ! txPrebuild ?. recipients || ! wallet ) {
2847- throw new SuspiciousTransactionError ( `missing params` ) ;
2865+ throw new TxIntentMismatchError ( `missing params` , '' , [ ] , '' ) ;
28482866 }
28492867 if ( txParams . hop && txParams . recipients . length > 1 ) {
2850- throw new SuspiciousTransactionError ( `tx cannot be both a batch and hop transaction` ) ;
2868+ throw new TxIntentMismatchError ( `tx cannot be both a batch and hop transaction` , '' , [ ] , '' ) ;
28512869 }
28522870 if ( txPrebuild . recipients . length > 1 ) {
2853- throw new SuspiciousTransactionError (
2854- `${ this . getChain ( ) } doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.`
2871+ throw new TxIntentMismatchError (
2872+ `${ this . getChain ( ) } doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` ,
2873+ '' ,
2874+ [ ] ,
2875+ ''
28552876 ) ;
28562877 }
28572878 if ( txParams . hop && txPrebuild . hopTransaction ) {
28582879 // Check recipient amount for hop transaction
28592880 if ( txParams . recipients . length !== 1 ) {
2860- throw new SuspiciousTransactionError (
2861- `hop transaction only supports 1 recipient but ${ txParams . recipients . length } found`
2881+ throw new TxIntentMismatchError (
2882+ `hop transaction only supports 1 recipient but ${ txParams . recipients . length } found` ,
2883+ '' ,
2884+ [ ] ,
2885+ ''
28622886 ) ;
28632887 }
28642888
@@ -2869,7 +2893,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28692893 const expectedHopAddress = optionalDeps . ethUtil . stripHexPrefix ( decodedHopTx . getSenderAddress ( ) . toString ( ) ) ;
28702894 const actualHopAddress = optionalDeps . ethUtil . stripHexPrefix ( txPrebuild . recipients [ 0 ] . address ) ;
28712895 if ( expectedHopAddress . toLowerCase ( ) !== actualHopAddress . toLowerCase ( ) ) {
2872- throw new SuspiciousTransactionError ( 'recipient address of txPrebuild does not match hop address' ) ;
2896+ throw new TxIntentMismatchError ( 'recipient address of txPrebuild does not match hop address' , '' , [ ] , ' ') ;
28732897 }
28742898
28752899 // Convert TransactionRecipient array to Recipient array
@@ -2887,8 +2911,11 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28872911 if ( txParams . tokenName ) {
28882912 const expectedTotalAmount = new BigNumber ( 0 ) ;
28892913 if ( ! expectedTotalAmount . isEqualTo ( txPrebuild . recipients [ 0 ] . amount ) ) {
2890- throw new SuspiciousTransactionError (
2891- 'batch token transaction amount in txPrebuild should be zero for token transfers'
2914+ throw new TxIntentMismatchError (
2915+ 'batch token transaction amount in txPrebuild should be zero for token transfers' ,
2916+ '' ,
2917+ [ ] ,
2918+ ''
28922919 ) ;
28932920 }
28942921 } else {
@@ -2897,8 +2924,11 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28972924 expectedTotalAmount = expectedTotalAmount . plus ( txParams . recipients [ i ] . amount ) ;
28982925 }
28992926 if ( ! expectedTotalAmount . isEqualTo ( txPrebuild . recipients [ 0 ] . amount ) ) {
2900- throw new SuspiciousTransactionError (
2901- 'batch transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client'
2927+ throw new TxIntentMismatchError (
2928+ 'batch transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client' ,
2929+ '' ,
2930+ [ ] ,
2931+ ''
29022932 ) ;
29032933 }
29042934 }
@@ -2909,33 +2939,47 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
29092939 ! batcherContractAddress ||
29102940 batcherContractAddress . toLowerCase ( ) !== txPrebuild . recipients [ 0 ] . address . toLowerCase ( )
29112941 ) {
2912- throw new SuspiciousTransactionError ( 'recipient address of txPrebuild does not match batcher address' ) ;
2942+ throw new TxIntentMismatchError ( 'recipient address of txPrebuild does not match batcher address' , '' , [ ] , ' ') ;
29132943 }
29142944 } else {
29152945 // Check recipient address and amount for normal transaction
29162946 if ( txParams . recipients . length !== 1 ) {
2917- throw new SuspiciousTransactionError (
2918- `normal transaction only supports 1 recipient but ${ txParams . recipients . length } found`
2947+ throw new TxIntentMismatchError (
2948+ `normal transaction only supports 1 recipient but ${ txParams . recipients . length } found` ,
2949+ '' ,
2950+ [ ] ,
2951+ ''
29192952 ) ;
29202953 }
29212954 const expectedAmount = new BigNumber ( txParams . recipients [ 0 ] . amount ) ;
29222955 if ( ! expectedAmount . isEqualTo ( txPrebuild . recipients [ 0 ] . amount ) ) {
2923- throw new SuspiciousTransactionError (
2924- 'normal transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client'
2956+ throw new TxIntentMismatchError (
2957+ 'normal transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client' ,
2958+ '' ,
2959+ [ ] ,
2960+ ''
29252961 ) ;
29262962 }
29272963 if (
29282964 this . isETHAddress ( txParams . recipients [ 0 ] . address ) &&
29292965 txParams . recipients [ 0 ] . address !== txPrebuild . recipients [ 0 ] . address
29302966 ) {
2931- throw new SuspiciousTransactionError (
2932- 'destination address in normal txPrebuild does not match that in txParams supplied by client'
2967+ throw new TxIntentMismatchError (
2968+ 'destination address in normal txPrebuild does not match that in txParams supplied by client' ,
2969+ '' ,
2970+ [ ] ,
2971+ ''
29332972 ) ;
29342973 }
29352974 }
29362975 // Check coin is correct for all transaction types
29372976 if ( ! this . verifyCoin ( txPrebuild ) ) {
2938- throw new SuspiciousTransactionError ( `coin in txPrebuild did not match that in txParams supplied by client` ) ;
2977+ throw new TxIntentMismatchError (
2978+ `coin in txPrebuild did not match that in txParams supplied by client` ,
2979+ '' ,
2980+ [ ] ,
2981+ ''
2982+ ) ;
29392983 }
29402984 return true ;
29412985 }
0 commit comments