@@ -28,6 +28,7 @@ import {
2828 PresignTransactionOptions as BasePresignTransactionOptions ,
2929 Recipient ,
3030 SignTransactionOptions as BaseSignTransactionOptions ,
31+ SuspiciousTransactionError ,
3132 TransactionParams ,
3233 TransactionPrebuild as BaseTransactionPrebuild ,
3334 TransactionRecipient ,
@@ -2777,13 +2778,13 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27772778 ( txParams . type && [ 'acceleration' , 'fillNonce' , 'transferToken' , 'tokenApproval' ] . includes ( txParams . type ) )
27782779 )
27792780 ) {
2780- throw new Error ( `missing txParams` ) ;
2781+ throw new SuspiciousTransactionError ( `missing txParams` ) ;
27812782 }
27822783 if ( ! wallet || ! txPrebuild ) {
2783- throw new Error ( `missing params` ) ;
2784+ throw new SuspiciousTransactionError ( `missing params` ) ;
27842785 }
27852786 if ( txParams . hop && txParams . recipients && txParams . recipients . length > 1 ) {
2786- throw new Error ( `tx cannot be both a batch and hop transaction` ) ;
2787+ throw new SuspiciousTransactionError ( `tx cannot be both a batch and hop transaction` ) ;
27872788 }
27882789
27892790 if ( txParams . type && [ 'transfer' ] . includes ( txParams . type ) ) {
@@ -2798,21 +2799,25 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27982799 const txJson = tx . toJson ( ) ;
27992800 if ( txJson . data === '0x' ) {
28002801 if ( expectedAmount !== txJson . value ) {
2801- throw new Error ( 'the transaction amount in txPrebuild does not match the value given by client' ) ;
2802+ throw new SuspiciousTransactionError (
2803+ 'the transaction amount in txPrebuild does not match the value given by client'
2804+ ) ;
28022805 }
28032806 if ( expectedDestination . toLowerCase ( ) !== txJson . to . toLowerCase ( ) ) {
2804- throw new Error ( 'destination address does not match with the recipient address' ) ;
2807+ throw new SuspiciousTransactionError ( 'destination address does not match with the recipient address' ) ;
28052808 }
28062809 } else if ( txJson . data . startsWith ( '0xa9059cbb' ) ) {
28072810 const [ recipientAddress , amount ] = getRawDecoded (
28082811 [ 'address' , 'uint256' ] ,
28092812 getBufferedByteCode ( '0xa9059cbb' , txJson . data )
28102813 ) ;
28112814 if ( expectedAmount !== amount . toString ( ) ) {
2812- throw new Error ( 'the transaction amount in txPrebuild does not match the value given by client' ) ;
2815+ throw new SuspiciousTransactionError (
2816+ 'the transaction amount in txPrebuild does not match the value given by client'
2817+ ) ;
28132818 }
28142819 if ( expectedDestination . toLowerCase ( ) !== addHexPrefix ( recipientAddress . toString ( ) ) . toLowerCase ( ) ) {
2815- throw new Error ( 'destination address does not match with the recipient address' ) ;
2820+ throw new SuspiciousTransactionError ( 'destination address does not match with the recipient address' ) ;
28162821 }
28172822 }
28182823 }
@@ -2839,20 +2844,22 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28392844 }
28402845
28412846 if ( ! txParams ?. recipients || ! txPrebuild ?. recipients || ! wallet ) {
2842- throw new Error ( `missing params` ) ;
2847+ throw new SuspiciousTransactionError ( `missing params` ) ;
28432848 }
28442849 if ( txParams . hop && txParams . recipients . length > 1 ) {
2845- throw new Error ( `tx cannot be both a batch and hop transaction` ) ;
2850+ throw new SuspiciousTransactionError ( `tx cannot be both a batch and hop transaction` ) ;
28462851 }
28472852 if ( txPrebuild . recipients . length > 1 ) {
2848- throw new Error (
2853+ throw new SuspiciousTransactionError (
28492854 `${ this . getChain ( ) } doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.`
28502855 ) ;
28512856 }
28522857 if ( txParams . hop && txPrebuild . hopTransaction ) {
28532858 // Check recipient amount for hop transaction
28542859 if ( txParams . recipients . length !== 1 ) {
2855- throw new Error ( `hop transaction only supports 1 recipient but ${ txParams . recipients . length } found` ) ;
2860+ throw new SuspiciousTransactionError (
2861+ `hop transaction only supports 1 recipient but ${ txParams . recipients . length } found`
2862+ ) ;
28562863 }
28572864
28582865 // Check tx sends to hop address
@@ -2862,7 +2869,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28622869 const expectedHopAddress = optionalDeps . ethUtil . stripHexPrefix ( decodedHopTx . getSenderAddress ( ) . toString ( ) ) ;
28632870 const actualHopAddress = optionalDeps . ethUtil . stripHexPrefix ( txPrebuild . recipients [ 0 ] . address ) ;
28642871 if ( expectedHopAddress . toLowerCase ( ) !== actualHopAddress . toLowerCase ( ) ) {
2865- throw new Error ( 'recipient address of txPrebuild does not match hop address' ) ;
2872+ throw new SuspiciousTransactionError ( 'recipient address of txPrebuild does not match hop address' ) ;
28662873 }
28672874
28682875 // Convert TransactionRecipient array to Recipient array
@@ -2880,15 +2887,17 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28802887 if ( txParams . tokenName ) {
28812888 const expectedTotalAmount = new BigNumber ( 0 ) ;
28822889 if ( ! expectedTotalAmount . isEqualTo ( txPrebuild . recipients [ 0 ] . amount ) ) {
2883- throw new Error ( 'batch token transaction amount in txPrebuild should be zero for token transfers' ) ;
2890+ throw new SuspiciousTransactionError (
2891+ 'batch token transaction amount in txPrebuild should be zero for token transfers'
2892+ ) ;
28842893 }
28852894 } else {
28862895 let expectedTotalAmount = new BigNumber ( 0 ) ;
28872896 for ( let i = 0 ; i < txParams . recipients . length ; i ++ ) {
28882897 expectedTotalAmount = expectedTotalAmount . plus ( txParams . recipients [ i ] . amount ) ;
28892898 }
28902899 if ( ! expectedTotalAmount . isEqualTo ( txPrebuild . recipients [ 0 ] . amount ) ) {
2891- throw new Error (
2900+ throw new SuspiciousTransactionError (
28922901 'batch transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client'
28932902 ) ;
28942903 }
@@ -2900,29 +2909,33 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
29002909 ! batcherContractAddress ||
29012910 batcherContractAddress . toLowerCase ( ) !== txPrebuild . recipients [ 0 ] . address . toLowerCase ( )
29022911 ) {
2903- throw new Error ( 'recipient address of txPrebuild does not match batcher address' ) ;
2912+ throw new SuspiciousTransactionError ( 'recipient address of txPrebuild does not match batcher address' ) ;
29042913 }
29052914 } else {
29062915 // Check recipient address and amount for normal transaction
29072916 if ( txParams . recipients . length !== 1 ) {
2908- throw new Error ( `normal transaction only supports 1 recipient but ${ txParams . recipients . length } found` ) ;
2917+ throw new SuspiciousTransactionError (
2918+ `normal transaction only supports 1 recipient but ${ txParams . recipients . length } found`
2919+ ) ;
29092920 }
29102921 const expectedAmount = new BigNumber ( txParams . recipients [ 0 ] . amount ) ;
29112922 if ( ! expectedAmount . isEqualTo ( txPrebuild . recipients [ 0 ] . amount ) ) {
2912- throw new Error (
2923+ throw new SuspiciousTransactionError (
29132924 'normal transaction amount in txPrebuild received from BitGo servers does not match txParams supplied by client'
29142925 ) ;
29152926 }
29162927 if (
29172928 this . isETHAddress ( txParams . recipients [ 0 ] . address ) &&
29182929 txParams . recipients [ 0 ] . address !== txPrebuild . recipients [ 0 ] . address
29192930 ) {
2920- throw new Error ( 'destination address in normal txPrebuild does not match that in txParams supplied by client' ) ;
2931+ throw new SuspiciousTransactionError (
2932+ 'destination address in normal txPrebuild does not match that in txParams supplied by client'
2933+ ) ;
29212934 }
29222935 }
29232936 // Check coin is correct for all transaction types
29242937 if ( ! this . verifyCoin ( txPrebuild ) ) {
2925- throw new Error ( `coin in txPrebuild did not match that in txParams supplied by client` ) ;
2938+ throw new SuspiciousTransactionError ( `coin in txPrebuild did not match that in txParams supplied by client` ) ;
29262939 }
29272940 return true ;
29282941 }
0 commit comments