From d83523f7b68dcefa058a56040c9af8be5d7bbd80 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Mon, 26 Feb 2024 16:56:06 -0500 Subject: [PATCH] psbt: Use specified sighash or SIGHASH_DEFAULT when dummy signing When dummy signing for finalizing, use either the specificed sighash, or SIGHASH_DEFAULT, rather than always SIGHASH_ALL. For outputs, just use SIGHASH_DEFAULT. --- src/psbt.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/psbt.cpp b/src/psbt.cpp index 7024adfc803f86..c7a5ef8abdb1f2 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -368,7 +368,7 @@ void UpdatePSBTOutput(const SigningProvider& provider, PartiallySignedTransactio // Construct a would-be spend of this output, to update sigdata with. // Note that ProduceSignature is used to fill in metadata (not actual signatures), // so provider does not need to provide any private keys (it can be a HidingSigningProvider). - MutableTransactionSignatureCreator creator(tx, /*input_idx=*/0, out.nValue, SIGHASH_ALL); + MutableTransactionSignatureCreator creator(tx, /*input_idx=*/0, out.nValue, SIGHASH_DEFAULT); ProduceSignature(provider, creator, out.scriptPubKey, sigdata); // Put redeem_script, witness_script, key paths, into PSBTOutput. @@ -506,7 +506,8 @@ bool FinalizePSBT(PartiallySignedTransaction& psbtx) bool complete = true; const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx); for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) { - complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, SIGHASH_ALL, nullptr, true); + int sighash_type = psbtx.inputs.at(i).sighash_type.value_or(SIGHASH_DEFAULT); + complete &= SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, &txdata, sighash_type, nullptr, true); } return complete;