Skip to content

Commit add4e11

Browse files
committed
feat(sdk-coin-dot): improve dot tx verification
Ticket: WP-5728
1 parent c09e01d commit add4e11

File tree

1 file changed

+34
-14
lines changed
  • modules/sdk-coin-dot/src

1 file changed

+34
-14
lines changed

modules/sdk-coin-dot/src/dot.ts

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@ import {
2929
multisigTypes,
3030
AuditDecryptedKeyParams,
3131
verifyEddsaTssWalletAddress,
32+
TxIntentMismatchRecipientError,
3233
} from '@bitgo/sdk-core';
3334
import { 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';
3543
import '@polkadot/api-augment';
3644
import { ApiPromise, WsProvider } from '@polkadot/api';
3745
import { 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, verification, wallet } = params;
662+
const { txPrebuild, txParams, verification, wallet, reqId } = params;
655663
if (!txParams) {
656664
throw new Error('missing txParams');
657665
}
@@ -665,17 +673,21 @@ 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;
669677

670678
if (verification?.consolidationToBaseAddress) {
671679
// Verify funds are sent to wallet's base address for consolidation
672680
const baseAddress = wallet?.coinSpecific()?.baseAddress || wallet?.coinSpecific()?.rootAddress;
673681
if (!baseAddress) {
674682
throw new Error('Unable to determine base address for consolidation');
675683
}
676-
if (txBuilder._to !== baseAddress) {
677-
throw new Error(
678-
`Transaction destination address ${txBuilder._to} does not match wallet base address ${baseAddress}`
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'] }]
679691
);
680692
}
681693
return true;
@@ -691,17 +703,25 @@ export class Dot extends BaseCoin {
691703
);
692704
}
693705

694-
// validate recipient is same as txBuilder._to
695-
if (txParams.recipients[0].address !== txBuilder._to) {
696-
throw new Error(
697-
`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'] }]
698714
);
699715
}
700716

701-
// and amount is same as txBuilder._amount
702-
if (txParams.recipients[0].amount !== txBuilder._amount) {
703-
throw new Error(
704-
`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'] }]
705725
);
706726
}
707727
return true;

0 commit comments

Comments
 (0)