Skip to content

Commit 7a22775

Browse files
committed
refactor: throw error on validation failure
TICKET: WP-7322
1 parent e39dbdb commit 7a22775

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
VerifyTransactionOptions,
5353
TssVerifyAddressOptions,
5454
verifyEddsaTssWalletAddress,
55+
UnexpectedAddressError,
5556
} from '@bitgo/sdk-core';
5657
import { auditEddsaPrivateKey, getDerivationPath } from '@bitgo/sdk-lib-mpc';
5758
import { BaseNetwork, CoinFamily, coins, SolCoin, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
@@ -603,11 +604,17 @@ export class Sol extends BaseCoin {
603604
}
604605

605606
async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
606-
return verifyEddsaTssWalletAddress(
607+
const result = await verifyEddsaTssWalletAddress(
607608
params,
608609
(address) => this.isValidAddress(address),
609610
(publicKey) => this.getAddressFromPublicKey(publicKey)
610611
);
612+
613+
if (!result) {
614+
throw new UnexpectedAddressError(`address validation failure: ${params.address} is not a wallet address`);
615+
}
616+
617+
return true;
611618
}
612619

613620
/**

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,26 +3443,28 @@ describe('SOL:', function () {
34433443
result.should.equal(true);
34443444
});
34453445

3446-
it('should return false for address with incorrect keychain', async function () {
3446+
it('should throw error for address with incorrect keychain', async function () {
34473447
const address = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY';
34483448
const wrongKeychain =
34493449
'0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
34503450
const index = '1';
34513451
const keychains = [{ id: '1', type: 'tss' as const, commonKeychain: wrongKeychain }];
34523452

3453-
const result = await basecoin.isWalletAddress({ keychains, address, index });
3454-
result.should.equal(false);
3453+
await assert.rejects(async () => await basecoin.isWalletAddress({ keychains, address, index }), {
3454+
message: `address validation failure: ${address} is not a wallet address`,
3455+
});
34553456
});
34563457

3457-
it('should return false for address with incorrect index', async function () {
3458+
it('should throw error for address with incorrect index', async function () {
34583459
const address = '7YAesfwPk41VChUgr65bm8FEep7ymWqLSW5rpYB5zZPY';
34593460
const commonKeychain =
34603461
'8ea32ecacfc83effbd2e2790ee44fa7c59b4d86c29a12f09fb613d8195f93f4e21875cad3b98adada40c040c54c3569467df41a020881a6184096378701862bd';
34613462
const wrongIndex = '999';
34623463
const keychains = [{ id: '1', type: 'tss' as const, commonKeychain }];
34633464

3464-
const result = await basecoin.isWalletAddress({ keychains, address, index: wrongIndex });
3465-
result.should.equal(false);
3465+
await assert.rejects(async () => await basecoin.isWalletAddress({ keychains, address, index: wrongIndex }), {
3466+
message: `address validation failure: ${address} is not a wallet address`,
3467+
});
34663468
});
34673469

34683470
it('should throw error for invalid address', async function () {

0 commit comments

Comments
 (0)