Skip to content

Commit c09e01d

Browse files
committed
feat(sdk-coin-dot): enhance tx verification for consolidation to base address
Ticket: WP-5728
1 parent 62202a0 commit c09e01d

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ export class Dot extends BaseCoin {
651651
}
652652

653653
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
654-
const { txPrebuild, txParams } = params;
654+
const { txPrebuild, txParams, verification, wallet } = params;
655655
if (!txParams) {
656656
throw new Error('missing txParams');
657657
}
@@ -664,13 +664,27 @@ export class Dot extends BaseCoin {
664664
throw new Error('missing txHex in txPrebuild');
665665
}
666666

667+
const factory = this.getBuilder();
668+
const txBuilder = factory.from(txPrebuild.txHex) as any;
669+
670+
if (verification?.consolidationToBaseAddress) {
671+
// Verify funds are sent to wallet's base address for consolidation
672+
const baseAddress = wallet?.coinSpecific()?.baseAddress || wallet?.coinSpecific()?.rootAddress;
673+
if (!baseAddress) {
674+
throw new Error('Unable to determine base address for consolidation');
675+
}
676+
if (txBuilder._to !== baseAddress) {
677+
throw new Error(
678+
`Transaction destination address ${txBuilder._to} does not match wallet base address ${baseAddress}`
679+
);
680+
}
681+
return true;
682+
}
683+
667684
if (!txParams.recipients || txParams.recipients.length === 0) {
668685
throw new Error('missing recipients in txParams');
669686
}
670687

671-
const factory = this.getBuilder();
672-
const txBuilder = factory.from(txPrebuild.txHex) as any;
673-
674688
if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) {
675689
throw new Error(
676690
`${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.`

modules/sdk-coin-dot/test/unit/dot.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,53 @@ describe('DOT:', function () {
727727
const result = await basecoin.verifyTransaction({ txPrebuild, txParams });
728728
assert.strictEqual(result, true);
729729
});
730+
731+
it('should verify a valid consolidation transaction', async function () {
732+
const mockedWallet = {
733+
coinSpecific: () => ({
734+
baseAddress: '5CZh773vKGwKFCYUjGc31AwXCbf7TPkavdeuk2XoujJMjbBD',
735+
}),
736+
};
737+
const txPrebuild = {
738+
txHex:
739+
'0xa80a0300161b969b6b53ef81225feea3882284c778cd4a406d23215fcf492e83f75d42960b00204aa9d101eb600400000065900f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9a7b7420ee3e4fe2b88da0fc42b30897e18d56d8b56a1934211d9de730cf96de300',
740+
};
741+
742+
const result = await basecoin.verifyTransaction({
743+
txPrebuild,
744+
txParams: {},
745+
wallet: mockedWallet as any,
746+
verification: {
747+
consolidationToBaseAddress: true,
748+
},
749+
});
750+
assert.strictEqual(result, true);
751+
});
752+
753+
it('should reject a consolidation transaction with invalid destination address', async function () {
754+
const mockedWallet = {
755+
coinSpecific: () => ({
756+
baseAddress: '5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74',
757+
}),
758+
};
759+
const txPrebuild = {
760+
txHex:
761+
'0xa80a0300161b969b6b53ef81225feea3882284c778cd4a406d23215fcf492e83f75d42960b00204aa9d101eb600400000065900f001000000067f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9a7b7420ee3e4fe2b88da0fc42b30897e18d56d8b56a1934211d9de730cf96de300',
762+
};
763+
764+
await basecoin
765+
.verifyTransaction({
766+
txPrebuild,
767+
txParams: {},
768+
wallet: mockedWallet as any,
769+
verification: {
770+
consolidationToBaseAddress: true,
771+
},
772+
})
773+
.should.be.rejectedWith(
774+
'Transaction destination address 5CZh773vKGwKFCYUjGc31AwXCbf7TPkavdeuk2XoujJMjbBD does not match wallet base address 5DxD9nT16GQLrU6aB5pSS5VtxoZbVju3NHUCcawxZyZCTf74'
775+
);
776+
});
730777
});
731778

732779
describe('isWalletAddress', () => {

0 commit comments

Comments
 (0)