Skip to content

Commit ce2cc90

Browse files
chore(abstract-utxo): deprecate signing override params
BTC-2286 TICKET: BTC-2286
1 parent 8710cc5 commit ce2cc90

File tree

4 files changed

+21
-54
lines changed

4 files changed

+21
-54
lines changed

modules/abstract-utxo/src/sign.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function signAndVerifyPsbt(
6464
signerKeychain: utxolib.BIP32Interface,
6565
{
6666
isLastSignature,
67+
/** deprecated */
6768
allowNonSegwitSigningWithoutPrevTx,
6869
}: { isLastSignature: boolean; allowNonSegwitSigningWithoutPrevTx?: boolean }
6970
): utxolib.bitgo.UtxoPsbt | utxolib.bitgo.UtxoTransaction<bigint> {
@@ -85,11 +86,7 @@ export function signAndVerifyPsbt(
8586
}
8687

8788
try {
88-
utxolib.bitgo.withUnsafeNonSegwit(
89-
psbt,
90-
() => psbt.signInputHD(inputIndex, signerKeychain),
91-
!!allowNonSegwitSigningWithoutPrevTx
92-
);
89+
psbt.signInputHD(inputIndex, signerKeychain);
9390
debug('Successfully signed input %d of %d', inputIndex + 1, psbt.data.inputs.length);
9491
} catch (e) {
9592
return new InputSigningError<bigint>(inputIndex, { id: outputId }, e);
@@ -111,13 +108,7 @@ export function signAndVerifyPsbt(
111108

112109
const outputId = outputIds[inputIndex];
113110
try {
114-
if (
115-
!utxolib.bitgo.withUnsafeNonSegwit(
116-
psbt,
117-
() => psbt.validateSignaturesOfInputHD(inputIndex, signerKeychain),
118-
!!allowNonSegwitSigningWithoutPrevTx
119-
)
120-
) {
111+
if (!psbt.validateSignaturesOfInputHD(inputIndex, signerKeychain)) {
121112
return new InputSigningError(inputIndex, { id: outputId }, new Error(`invalid signature`));
122113
}
123114
} catch (e) {

modules/abstract-utxo/src/transaction/fixedScript/signTransaction.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export async function signTransaction<TNumber extends number | bigint>(
2727
txInfo: { unspents?: utxolib.bitgo.Unspent<TNumber>[] } | undefined;
2828
isLastSignature: boolean;
2929
signingStep: 'signerNonce' | 'cosignerNonce' | 'signerSignature' | undefined;
30+
/** deprecated */
3031
allowNonSegwitSigningWithoutPrevTx: boolean;
3132
pubs: string[] | undefined;
3233
cosignerPub: string | undefined;
@@ -47,19 +48,11 @@ export async function signTransaction<TNumber extends number | bigint>(
4748
isLastSignature = params.isLastSignature;
4849
}
4950

50-
const setSignerMusigNonceWithOverride = (
51-
psbt: utxolib.bitgo.UtxoPsbt,
52-
signerKeychain: utxolib.BIP32Interface,
53-
nonSegwitOverride: boolean
54-
) => {
55-
utxolib.bitgo.withUnsafeNonSegwit(psbt, () => psbt.setAllInputsMusig2NonceHD(signerKeychain), nonSegwitOverride);
56-
};
57-
5851
if (tx instanceof bitgo.UtxoPsbt && isTxWithKeyPathSpendInput) {
5952
switch (params.signingStep) {
6053
case 'signerNonce':
6154
assert(signerKeychain);
62-
setSignerMusigNonceWithOverride(tx, signerKeychain, params.allowNonSegwitSigningWithoutPrevTx);
55+
tx.setAllInputsMusig2NonceHD(signerKeychain);
6356
PSBT_CACHE.set(tx.getUnsignedTx().getId(), tx);
6457
return { txHex: tx.toHex() };
6558
case 'cosignerNonce':
@@ -80,7 +73,7 @@ export async function signTransaction<TNumber extends number | bigint>(
8073
// this instance is not an external signer
8174
assert(params.walletId, 'walletId is required for MuSig2 bitgo nonce');
8275
assert(signerKeychain);
83-
setSignerMusigNonceWithOverride(tx, signerKeychain, params.allowNonSegwitSigningWithoutPrevTx);
76+
tx.setAllInputsMusig2NonceHD(signerKeychain);
8477
const response = await coin.signPsbt(tx.toHex(), params.walletId);
8578
tx.combine(bitgo.createPsbtFromHex(response.psbt, coin.network));
8679
break;
@@ -102,7 +95,6 @@ export async function signTransaction<TNumber extends number | bigint>(
10295
assert(signerKeychain);
10396
signedTransaction = signAndVerifyPsbt(tx, signerKeychain, {
10497
isLastSignature,
105-
allowNonSegwitSigningWithoutPrevTx: params.allowNonSegwitSigningWithoutPrevTx,
10698
});
10799
} else {
108100
if (tx.ins.length !== params.txInfo?.unspents?.length) {

modules/utxo-lib/src/testutil/psbt.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
UtxoPsbt,
2525
UtxoTransaction,
2626
verifySignatureWithUnspent,
27-
withUnsafeNonSegwit,
2827
} from '../bitgo';
2928
import { Network } from '../networks';
3029
import { mockReplayProtectionUnspent, mockWalletUnspent } from './mock';
@@ -115,32 +114,21 @@ export function signPsbtInput(
115114
params?: {
116115
signers?: { signerName: KeyName; cosignerName?: KeyName };
117116
deterministic?: boolean;
117+
// For backwards compatibility keep this here.
118118
skipNonWitnessUtxo?: boolean;
119119
}
120120
): void {
121-
function signPsbt(psbt: UtxoPsbt, signFunc: () => void, skipNonWitnessUtxo?: boolean) {
122-
if (skipNonWitnessUtxo) {
123-
withUnsafeNonSegwit(psbt, signFunc);
124-
} else {
125-
signFunc();
126-
}
127-
}
128-
129-
const { signers, deterministic, skipNonWitnessUtxo } = params ?? {};
121+
const { signers, deterministic } = params ?? {};
130122
const { signerName, cosignerName } = signers ? signers : getSigners(input.scriptType);
131123
if (sign === 'halfsigned') {
132124
if (input.scriptType === 'p2shP2pk') {
133-
signPsbt(psbt, () => psbt.signInput(inputIndex, rootWalletKeys[signerName]), skipNonWitnessUtxo);
125+
psbt.signInput(inputIndex, rootWalletKeys[signerName]);
134126
} else {
135-
signPsbt(psbt, () => psbt.signInputHD(inputIndex, rootWalletKeys[signerName]), skipNonWitnessUtxo);
127+
psbt.signInputHD(inputIndex, rootWalletKeys[signerName]);
136128
}
137129
}
138130
if (sign === 'fullsigned' && cosignerName && input.scriptType !== 'p2shP2pk') {
139-
signPsbt(
140-
psbt,
141-
() => psbt.signInputHD(inputIndex, rootWalletKeys[cosignerName], { deterministic }),
142-
skipNonWitnessUtxo
143-
);
131+
psbt.signInputHD(inputIndex, rootWalletKeys[cosignerName], { deterministic });
144132
}
145133
}
146134

@@ -156,12 +144,13 @@ export function signAllPsbtInputs(
156144
params?: {
157145
signers?: { signerName: KeyName; cosignerName?: KeyName };
158146
deterministic?: boolean;
147+
// For backwards compatibility keep this here.
159148
skipNonWitnessUtxo?: boolean;
160149
}
161150
): void {
162-
const { signers, deterministic, skipNonWitnessUtxo } = params ?? {};
151+
const { signers, deterministic } = params ?? {};
163152
inputs.forEach((input, inputIndex) => {
164-
signPsbtInput(psbt, input, inputIndex, rootWalletKeys, sign, { signers, deterministic, skipNonWitnessUtxo });
153+
signPsbtInput(psbt, input, inputIndex, rootWalletKeys, sign, { signers, deterministic });
165154
});
166155
}
167156

modules/utxo-lib/test/bitgo/psbt/Psbt.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
clonePsbtWithoutNonWitnessUtxo,
3333
deleteWitnessUtxoForNonSegwitInputs,
3434
getPsbtInputScriptType,
35-
withUnsafeNonSegwit,
3635
getTransactionAmountsFromPsbt,
3736
WalletUnspent,
3837
getDefaultSigHash,
@@ -289,18 +288,14 @@ function runBuildSignSendFlowTest(
289288
hex = psbtWithoutPrevTx.toHex();
290289

291290
psbtAtHsm = createPsbtFromHex(hex, network);
292-
withUnsafeNonSegwit(psbtAtHsm, () => {
293-
testutil.signAllPsbtInputs(psbtAtHsm, inputs, rootWalletKeys, 'fullsigned', {
294-
signers: {
295-
signerName: 'user',
296-
cosignerName: 'bitgo',
297-
},
298-
deterministic: true,
299-
});
300-
});
301-
withUnsafeNonSegwit(psbtAtHsm, () => {
302-
assertValidate(psbtAtHsm);
291+
testutil.signAllPsbtInputs(psbtAtHsm, inputs, rootWalletKeys, 'fullsigned', {
292+
signers: {
293+
signerName: 'user',
294+
cosignerName: 'bitgo',
295+
},
296+
deterministic: true,
303297
});
298+
assertValidate(psbtAtHsm);
304299
hexAtHsm = psbtAtHsm.toHex();
305300

306301
psbtFromHsm = createPsbtFromHex(hexAtHsm, network);

0 commit comments

Comments
 (0)