Skip to content

Commit 2ca5c72

Browse files
feat(sdk-coin-near): reapply consolidation validation
This commit modifies the NEAR consolidation verification flow by: 1. Obtaining the base address directly from wallet.coinSpecific().rootAddress 2. Updating the verifyConsolidationToBaseAddress method signature 3. Adding error handling for missing root address - Tested native and token consolidation on express TICKET: WP-3968
1 parent f49da78 commit 2ca5c72

File tree

4 files changed

+16
-36
lines changed

4 files changed

+16
-36
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as request from 'superagent';
1111
import { auditEddsaPrivateKey } from '@bitgo/sdk-lib-mpc';
1212
import {
1313
AuditDecryptedKeyParams,
14-
BaseAddress,
1514
BaseCoin,
1615
BaseTransaction,
1716
BitGoBase,
@@ -990,7 +989,7 @@ export class Near extends BaseCoin {
990989
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
991990
let totalAmount = new BigNumber(0);
992991
const coinConfig = coins.get(this.getChain());
993-
const { txPrebuild: txPrebuild, txParams: txParams } = params;
992+
const { txPrebuild: txPrebuild, txParams: txParams, wallet } = params;
994993
const transaction = new Transaction(coinConfig);
995994
const rawTx = txPrebuild.txHex;
996995
if (!rawTx) {
@@ -1043,7 +1042,10 @@ export class Near extends BaseCoin {
10431042
}
10441043

10451044
if (params.verification?.consolidationToBaseAddress) {
1046-
await this.verifyConsolidationToBaseAddress(params, explainedTx);
1045+
if (!wallet?.coinSpecific()?.rootAddress) {
1046+
throw new Error('Unable to determine base address for consolidation');
1047+
}
1048+
await this.verifyConsolidationToBaseAddress(explainedTx, wallet.coinSpecific()?.rootAddress as string);
10471049
}
10481050

10491051
return true;
@@ -1061,18 +1063,13 @@ export class Near extends BaseCoin {
10611063
auditEddsaPrivateKey(prv, publicKey ?? '');
10621064
}
10631065

1066+
// TODO: Verify token consolidation as well.
10641067
protected async verifyConsolidationToBaseAddress(
1065-
params: VerifyTransactionOptions,
1066-
explainedTx: TransactionExplanation
1068+
explainedTx: TransactionExplanation,
1069+
baseAddress: string
10671070
): Promise<void> {
1068-
const baseAddresses: BaseAddress[] | undefined = await params.wallet.addresses({ sort: -1, limit: 1 });
1069-
if (!baseAddresses || baseAddresses.length === 0) {
1070-
throw new Error('No base address found on wallet');
1071-
}
1072-
const baseAddress = baseAddresses[0];
1073-
10741071
for (const output of explainedTx.outputs) {
1075-
if (output.address !== baseAddress.address) {
1072+
if (output.address !== baseAddress) {
10761073
throw new Error('tx outputs does not match with expected address');
10771074
}
10781075
}

modules/sdk-coin-near/src/nep141Token.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class Nep141Token extends Near {
6666
}
6767

6868
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
69-
const { txPrebuild: txPrebuild, txParams: txParams } = params;
69+
const { txPrebuild: txPrebuild, txParams: txParams, wallet } = params;
7070
const rawTx = txPrebuild.txHex;
7171
let totalAmount = new BigNumber(0);
7272
if (!rawTx) {
@@ -106,7 +106,10 @@ export class Nep141Token extends Near {
106106
}
107107

108108
if (params.verification?.consolidationToBaseAddress) {
109-
await this.verifyConsolidationToBaseAddress(params, explainedTx);
109+
if (!wallet?.coinSpecific()?.rootAddress) {
110+
throw new Error('Unable to determine base address for consolidation');
111+
}
112+
await this.verifyConsolidationToBaseAddress(explainedTx, wallet.coinSpecific()?.rootAddress as string);
110113
}
111114

112115
return true;

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ describe('NEAR:', function () {
543543
'5b3424f91bf349930e34017700000000',
544544
],
545545
coinSpecific: {
546-
rootAddress: '3a1b77653ea1705ad297db7abe259953b4ad5d2ecc5b50bee9a486f785dd90db',
546+
rootAddress: 'a94e3970aec46bbb156931ca090ed75ff3aade4979ffef6d74c72d5a247ce94f',
547547
},
548548
multisigType: 'tss',
549549
};
@@ -593,16 +593,6 @@ describe('NEAR:', function () {
593593
consolidateId: '68ae77ec62346a69d0aee5a2dda69c8c',
594594
coin: 'tnear',
595595
};
596-
const bgUrl = common.Environments['mock'].uri;
597-
598-
nock(bgUrl)
599-
.get('/api/v2/tnear/wallet/62e156dbd641c000076bbabe04041a90/addresses?sort=-1&limit=1')
600-
.reply(200, [
601-
{
602-
address: 'a94e3970aec46bbb156931ca090ed75ff3aade4979ffef6d74c72d5a247ce94f',
603-
},
604-
]);
605-
606596
try {
607597
if (
608598
!(await basecoin.verifyTransaction({

modules/sdk-coin-near/test/unit/nep141Token.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe('Nep141Token', () => {
284284
'5b3424f91bf349930e34017700000000',
285285
],
286286
coinSpecific: {
287-
rootAddress: '3a1b77653ea1705ad297db7abe259953b4ad5d2ecc5b50bee9a486f785dd90db',
287+
rootAddress: 'a94e3970aec46bbb156931ca090ed75ff3aade4979ffef6d74c72d5a247ce94f',
288288
},
289289
multisigType: 'tss',
290290
};
@@ -335,16 +335,6 @@ describe('Nep141Token', () => {
335335
coin: 'tnear',
336336
token: 'tnear:usdc',
337337
};
338-
const bgUrl = common.Environments['mock'].uri;
339-
340-
nock(bgUrl)
341-
.get('/api/v2/tnear:tnep24dp/wallet/62e156dbd641c000076bbabe04041a90/addresses?sort=-1&limit=1')
342-
.reply(200, [
343-
{
344-
address: 'a94e3970aec46bbb156931ca090ed75ff3aade4979ffef6d74c72d5a247ce94f',
345-
},
346-
]);
347-
348338
try {
349339
if (
350340
!(await baseCoin.verifyTransaction({

0 commit comments

Comments
 (0)