Skip to content

Commit 6d6d9bf

Browse files
committed
btc: Make tx::sighash() work for transactions with witness
By stripping the witness first. This is necessary because the transactions is coerced into a PSBT to calculate its sighash, which requires that no witnesses are set.
1 parent c510b55 commit 6d6d9bf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/stdlib/btc.minsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn tr::script_witness($tr, $script, $stack=[]) = $stack + [ $script, tr::ctrl($t
4444

4545
// Simplified SigHash API given a Transaction and its UTXOs
4646
fn tx::sighash($tx, $vin, $utxos, $sighash_ty=SIGHASH_ALL) = psbt::sighash([
47-
"unsigned_tx": $tx,
47+
"unsigned_tx": tx::strip_witness($tx),
4848
"inputs": map($utxos, |$utxo| [
4949
"utxo": $utxo,
5050
"sighash_type": $sighash_ty, // set for all inputs but only matters for the $vin
@@ -53,7 +53,7 @@ fn tx::sighash($tx, $vin, $utxos, $sighash_ty=SIGHASH_ALL) = psbt::sighash([
5353

5454
// SigHash for Taproot spending through a script-path leaf
5555
fn tx::sighash::tr_leaf($tx, $vin, $script_leaf, $utxos, $sighash_ty=SIGHASH_ALL) = psbt::sighash([
56-
"unsigned_tx": $tx,
56+
"unsigned_tx": tx::strip_witness($tx),
5757
"inputs": map($utxos, |$utxo| [
5858
"utxo": $utxo,
5959
"sighash_type": $sighash_ty, // set for all inputs but only matters for the $vin

0 commit comments

Comments
 (0)