Skip to content

Commit c29bc87

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): validate txFormat param on testnet networks
Validate that the txFormat parameter is one of the allowed values for testnet networks to prevent invalid inputs. Added new utility function and error class to handle validation. Issue: BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent 75da414 commit c29bc87

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ import ScriptType2Of3 = utxolib.bitgo.outputScripts.ScriptType2Of3;
8686

8787
type TxFormat = 'legacy' | 'psbt' | 'psbt-lite';
8888

89+
function isTxFormat(txFormat: unknown): txFormat is TxFormat {
90+
return txFormat === 'legacy' || txFormat === 'psbt' || txFormat === 'psbt-lite';
91+
}
92+
93+
class ErrorInvalidTxFormat extends Error {
94+
constructor(txFormat: unknown) {
95+
super(`Invalid txFormat: ${txFormat}. Must be one of: legacy, psbt, psbt-lite`);
96+
}
97+
}
98+
8999
type UtxoCustomSigningFunction<TNumber extends number | bigint> = {
90100
(params: {
91101
coin: IBaseCoin;
@@ -983,6 +993,12 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
983993
}
984994

985995
private getTxFormat(wallet: Wallet, requestedTxFormat: unknown): TxFormat | undefined {
996+
if (utxolib.isTestnet(this.network)) {
997+
if (requestedTxFormat !== undefined && !isTxFormat(requestedTxFormat)) {
998+
throw new ErrorInvalidTxFormat(requestedTxFormat);
999+
}
1000+
}
1001+
9861002
const walletFlagMusigKp = wallet.flag('musigKp') === 'true';
9871003
const isHotWallet = wallet.type() === 'hot';
9881004

0 commit comments

Comments
 (0)