Skip to content

Commit 5be7bfc

Browse files
kcheng-bitgodavidkaplanbitgo
authored andcommitted
fix(abstract-utxo): fix isValidAddress by generating all addr formats
TICKET: BTC-1553
1 parent 2b6a07e commit 5be7bfc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,15 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
415415
throw new Error('deprecated');
416416
}
417417

418-
const formats = param && param.anyFormat ? undefined : ['default' as const];
418+
const formats = utxolib.addressFormat.addressFormats.filter((format) =>
419+
utxolib.addressFormat.isSupportedAddressFormat(format, this.network)
420+
);
419421
try {
420422
const script = utxolib.addressFormat.toOutputScriptTryFormats(address, this.network, formats);
421-
return address === utxolib.address.fromOutputScript(script, this.network);
423+
const genAddresses = formats.map((format) =>
424+
utxolib.addressFormat.fromOutputScriptWithFormat(script, format, this.network)
425+
);
426+
return genAddresses.includes(address);
422427
} catch (e) {
423428
return false;
424429
}

modules/bitgo/test/v2/unit/wallet.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ describe('V2 Wallet:', function () {
242242
});
243243
});
244244

245+
it('should verify bch cashaddr format as valid', async function () {
246+
const coin = bitgo.coin('tbch');
247+
const valid = coin.isValidAddress('bchtest:pzfkxv532t0q5zchck2mhmmf2y02cdejyssq5qrz7a');
248+
valid.should.be.True();
249+
});
250+
251+
it('should verify bch legacy format as valid', async function () {
252+
const coin = bitgo.coin('tbch');
253+
const valid = coin.isValidAddress('2N6gY9r9iuXQQzZiSyngWJeoUuL5mC1x4Ac');
254+
valid.should.be.True();
255+
});
256+
245257
describe('TETH Wallet Addresses', function () {
246258
let ethWallet;
247259

0 commit comments

Comments
 (0)