@@ -29,9 +29,17 @@ import {
2929 multisigTypes ,
3030 AuditDecryptedKeyParams ,
3131 verifyEddsaTssWalletAddress ,
32+ TxIntentMismatchRecipientError ,
3233} from '@bitgo/sdk-core' ;
3334import { BaseCoin as StaticsBaseCoin , coins , PolkadotSpecNameType } from '@bitgo/statics' ;
34- import { Interface , KeyPair as DotKeyPair , Transaction , TransactionBuilderFactory , Utils } from './lib' ;
35+ import {
36+ Interface ,
37+ KeyPair as DotKeyPair ,
38+ NativeTransferBuilder ,
39+ Transaction ,
40+ TransactionBuilderFactory ,
41+ Utils ,
42+ } from './lib' ;
3543import '@polkadot/api-augment' ;
3644import { ApiPromise , WsProvider } from '@polkadot/api' ;
3745import { Material } from './lib/iface' ;
@@ -651,7 +659,7 @@ export class Dot extends BaseCoin {
651659 }
652660
653661 async verifyTransaction ( params : VerifyTransactionOptions ) : Promise < boolean > {
654- const { txPrebuild, txParams } = params ;
662+ const { txPrebuild, txParams, verification , wallet , reqId } = params ;
655663 if ( ! txParams ) {
656664 throw new Error ( 'missing txParams' ) ;
657665 }
@@ -665,7 +673,24 @@ export class Dot extends BaseCoin {
665673 }
666674
667675 const factory = this . getBuilder ( ) ;
668- const txBuilder = factory . from ( txPrebuild . txHex ) as any ;
676+ const txBuilder = factory . from ( txPrebuild . txHex ) as unknown as NativeTransferBuilder ;
677+
678+ if ( verification ?. consolidationToBaseAddress ) {
679+ // Verify funds are sent to wallet's base address for consolidation
680+ const baseAddress = wallet ?. coinSpecific ( ) ?. rootAddress || wallet ?. coinSpecific ( ) ?. baseAddress ;
681+ if ( ! baseAddress ) {
682+ throw new Error ( 'Unable to determine base address for consolidation' ) ;
683+ }
684+ if ( txBuilder [ '_to' ] !== baseAddress ) {
685+ throw new TxIntentMismatchRecipientError (
686+ `Transaction destination address ${ txBuilder [ '_to' ] } does not match wallet base address ${ baseAddress } ` ,
687+ reqId ,
688+ [ txParams ] ,
689+ txPrebuild . txHex ,
690+ [ { address : txBuilder [ '_to' ] , amount : txBuilder [ '_amount' ] } ]
691+ ) ;
692+ }
693+ }
669694
670695 if ( txParams . recipients !== undefined ) {
671696 if ( txParams . recipients . length === 0 ) {
@@ -678,17 +703,25 @@ export class Dot extends BaseCoin {
678703 ) ;
679704 }
680705
681- // validate recipient is same as txBuilder._to
682- if ( txParams . recipients [ 0 ] . address !== txBuilder . _to ) {
683- throw new Error (
684- `Recipient address ${ txParams . recipients [ 0 ] . address } does not match transaction destination address ${ txBuilder . _to } `
706+ // validate recipient is same as txBuilder['_to']
707+ if ( txParams . recipients [ 0 ] . address !== txBuilder [ '_to' ] ) {
708+ throw new TxIntentMismatchRecipientError (
709+ `Recipient address ${ txParams . recipients [ 0 ] . address } does not match transaction destination address ${ txBuilder [ '_to' ] } ` ,
710+ reqId ,
711+ [ txParams ] ,
712+ txPrebuild . txHex ,
713+ [ { address : txBuilder [ '_to' ] , amount : txBuilder [ '_amount' ] } ]
685714 ) ;
686715 }
687716
688- // and amount is same as txBuilder._amount
689- if ( txParams . recipients [ 0 ] . amount !== txBuilder . _amount ) {
690- throw new Error (
691- `Recipient amount ${ txParams . recipients [ 0 ] . amount } does not match transaction amount ${ txBuilder . _amount } `
717+ // validate amount is same as txBuilder['_amount']
718+ if ( txParams . recipients [ 0 ] . amount !== txBuilder [ '_amount' ] ) {
719+ throw new TxIntentMismatchRecipientError (
720+ `Recipient amount ${ txParams . recipients [ 0 ] . amount } does not match transaction amount ${ txBuilder [ '_amount' ] } ` ,
721+ reqId ,
722+ [ txParams ] ,
723+ txPrebuild . txHex ,
724+ [ { address : txBuilder [ '_to' ] , amount : txBuilder [ '_amount' ] } ]
692725 ) ;
693726 }
694727 }
0 commit comments