Skip to content

Commit ff15ce7

Browse files
committed
psbt: Default to SIGHASH_ALL in case of no sighash set in rawsign cmd
1 parent 7897c93 commit ff15ce7

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/bin/hal/cmd/psbt.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use base64;
55
use clap;
66
use hex;
77

8+
use bitcoin::{EcdsaSighashType, PublicKey, Transaction};
89
use bitcoin::consensus::{deserialize, serialize};
910
use bitcoin::util::bip32;
1011
use bitcoin::util::psbt;
11-
use bitcoin::{PublicKey, Transaction};
1212
use miniscript::psbt::PsbtExt;
1313
use secp256k1;
1414

@@ -504,15 +504,18 @@ fn exec_rawsign<'a>(args: &clap::ArgMatches<'a>) {
504504
};
505505

506506
let sighashtype = psbt.inputs[i].sighash_type
507-
.need("error locating sighash type on the selected input")
508-
.ecdsa_hash_ty()
509-
.need("schnorr signatures are not yet supported");
510-
let mut btc_sig = secp_sig.serialize_der().as_ref().to_vec();
511-
btc_sig.push(sighashtype.to_u32() as u8);
507+
.map(|t| t.ecdsa_hash_ty().need("schnorr signatures are not yet supported"))
508+
.unwrap_or_else(|| {
509+
eprintln!("No sighash type set for input {}, so signing with SIGHASH_ALL", i+1);
510+
EcdsaSighashType::All
511+
});
512+
let sig = bitcoin::EcdsaSig {
513+
sig: secp_sig,
514+
hash_ty: sighashtype,
515+
};
512516

513517
// mutate the psbt
514-
psbt.inputs[i].partial_sigs.insert(pk, bitcoin::EcdsaSig::from_slice(&btc_sig)
515-
.need("failed to sign psbt"));
518+
psbt.inputs[i].partial_sigs.insert(pk, sig);
516519
let raw = serialize(&psbt);
517520
if let Some(path) = args.value_of("output") {
518521
let mut file = File::create(&path).need("failed to open output file");

0 commit comments

Comments
 (0)