Skip to content

Commit 3693873

Browse files
committed
refactor: simplify
TICKET: WP-7114
1 parent a298876 commit 3693873

File tree

2 files changed

+5
-44
lines changed

2 files changed

+5
-44
lines changed

modules/abstract-substrate/src/abstractSubstrateCoin.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
AddressCoinSpecific,
32
AuditDecryptedKeyParams,
43
BaseCoin,
54
BitGoBase,
@@ -21,8 +20,8 @@ import {
2120
RecoveryTxRequest,
2221
SignedTransaction,
2322
TssVerifyAddressOptions,
23+
UnexpectedAddressError,
2424
verifyEddsaTssWalletAddress,
25-
VerifyAddressOptions,
2625
VerifyTransactionOptions,
2726
} from '@bitgo/sdk-core';
2827
import { CoinFamily, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
@@ -36,13 +35,6 @@ import { ApiPromise } from '@polkadot/api';
3635

3736
export const DEFAULT_SCAN_FACTOR = 20;
3837

39-
export interface SubstrateVerifyAddressOptions extends VerifyAddressOptions {
40-
index?: number | string;
41-
coinSpecific?: AddressCoinSpecific & {
42-
index?: number | string;
43-
};
44-
}
45-
4638
export class SubstrateCoin extends BaseCoin {
4739
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
4840
readonly MAX_VALIDITY_DURATION = 2400;
@@ -119,28 +111,15 @@ export class SubstrateCoin extends BaseCoin {
119111
}
120112

121113
/** @inheritDoc **/
122-
async isWalletAddress(params: SubstrateVerifyAddressOptions): Promise<boolean> {
123-
const { address, keychains } = params;
124-
125-
const index = Number(params.index ?? params.coinSpecific?.index);
126-
if (isNaN(index) || index < 0) {
127-
throw new Error('Invalid or missing index. index must be a non-negative number.');
128-
}
129-
130-
const tssParams: TssVerifyAddressOptions = {
131-
address,
132-
keychains: keychains as TssVerifyAddressOptions['keychains'],
133-
index,
134-
};
135-
114+
async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
136115
const isValid = await verifyEddsaTssWalletAddress(
137-
tssParams,
116+
params,
138117
(addr) => this.isValidAddress(addr),
139118
(pubKey) => this.getAddressFromPublicKey(pubKey)
140119
);
141120

142121
if (!isValid) {
143-
throw new Error(`Address verification failed: address ${address} is not a wallet address at index ${index}`);
122+
throw new UnexpectedAddressError();
144123
}
145124

146125
return true;

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('Tao:', function () {
7474
keychains,
7575
index: 0, // Wrong index for this address
7676
})
77-
.should.be.rejectedWith(/Address verification failed/);
77+
.should.be.rejectedWith(/address validation failure/);
7878
});
7979

8080
it('should throw for missing index', async function () {
@@ -117,24 +117,6 @@ describe('Tao:', function () {
117117
})
118118
.should.be.rejectedWith(/missing required param keychains/);
119119
});
120-
121-
it('should accept index from coinSpecific', async function () {
122-
const keychains = [
123-
{ commonKeychain: isWalletAddressTestData.commonKeychain },
124-
{ commonKeychain: isWalletAddressTestData.commonKeychain },
125-
{ commonKeychain: isWalletAddressTestData.commonKeychain },
126-
];
127-
128-
const result = await baseCoin.isWalletAddress({
129-
address: isWalletAddressTestData.receiveAddress,
130-
keychains,
131-
coinSpecific: {
132-
index: isWalletAddressTestData.receiveAddressIndex,
133-
},
134-
});
135-
136-
result.should.be.true();
137-
});
138120
});
139121

140122
describe.skip('Recover Transactions:', function () {

0 commit comments

Comments
 (0)