Skip to content

Commit 0257f73

Browse files
feat(utxo-core): accept scriptId instead of chain and index params
Replace chain and index parameters with a scriptId object in addBip322InputWithChainAndIndex function for better consistency with other API methods. BTC-2383 TICKET: BTC-2383
1 parent c4004ab commit 0257f73

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

modules/utxo-core/src/bip322/toSign.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,16 @@ export function addBip322InputWithChainAndIndex(
7979
psbt: Psbt,
8080
message: string,
8181
rootWalletKeys: bitgo.RootWalletKeys,
82-
chain: bitgo.ChainCode,
83-
index: number
82+
scriptId: bitgo.ScriptId
8483
): Psbt {
85-
if (isTaprootChain(chain)) {
84+
if (isTaprootChain(scriptId.chain)) {
8685
throw new Error('BIP322 is not supported for Taproot script types.');
8786
}
88-
const walletKeys = rootWalletKeys.deriveForChainAndIndex(chain, index);
89-
const output = bitgo.outputScripts.createOutputScript2of3(walletKeys.publicKeys, bitgo.scriptTypeForChain(chain));
87+
const walletKeys = rootWalletKeys.deriveForChainAndIndex(scriptId.chain, scriptId.index);
88+
const output = bitgo.outputScripts.createOutputScript2of3(
89+
walletKeys.publicKeys,
90+
bitgo.scriptTypeForChain(scriptId.chain)
91+
);
9092

9193
addBip322Input(psbt, message, {
9294
scriptPubKey: output.scriptPubKey,
@@ -97,7 +99,7 @@ export function addBip322InputWithChainAndIndex(
9799
const inputIndex = psbt.data.inputs.length - 1;
98100
psbt.updateInput(
99101
inputIndex,
100-
bitgo.getPsbtBip32DerivationOutputUpdate(rootWalletKeys, walletKeys, bitgo.scriptTypeForChain(chain))
102+
bitgo.getPsbtBip32DerivationOutputUpdate(rootWalletKeys, walletKeys, bitgo.scriptTypeForChain(scriptId.chain))
101103
);
102104

103105
return psbt;

modules/utxo-core/test/bip322/toSign.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('BIP322 toSign', function () {
5353
}
5454
const toSpendTx = bip322.buildToSpendTransactionFromChainAndIndex(rootWalletKeys, chain, index, message);
5555
const toSignPsbt = bip322.createBaseToSignPsbt(rootWalletKeys);
56-
bip322.addBip322InputWithChainAndIndex(toSignPsbt, message, rootWalletKeys, chain, index);
56+
bip322.addBip322InputWithChainAndIndex(toSignPsbt, message, rootWalletKeys, { chain, index });
5757

5858
// Can sign the PSBT with the keys
5959
// Should be able to use HD because we have the bip32Derivation information

0 commit comments

Comments
 (0)