Skip to content

Commit ec9165a

Browse files
fix(abstract-utxo): use param in isValidAddress
TICKET: BTC-1553
1 parent 5be7bfc commit ec9165a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

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

418-
const formats = utxolib.addressFormat.addressFormats.filter((format) =>
419-
utxolib.addressFormat.isSupportedAddressFormat(format, this.network)
420-
);
418+
// Default to anyFormat to true - if anyFormat is false then only check the default. Otherwise, check
419+
// all formats
420+
const anyFormat = (param as { anyFormat: boolean | undefined })?.anyFormat;
421+
const formats =
422+
anyFormat === undefined || anyFormat
423+
? utxolib.addressFormat.addressFormats.filter((format) =>
424+
utxolib.addressFormat.isSupportedAddressFormat(format, this.network)
425+
)
426+
: ['default' as const];
427+
421428
try {
429+
// To make sure that we are preserving `fromOutputScript(script, network) === address`, we need to do the
430+
// circular check below. An example of something that this protects against is uppercase Bech32.
422431
const script = utxolib.addressFormat.toOutputScriptTryFormats(address, this.network, formats);
423432
const genAddresses = formats.map((format) =>
424433
utxolib.addressFormat.fromOutputScriptWithFormat(script, format, this.network)

0 commit comments

Comments
 (0)