Skip to content

Commit 5c74b12

Browse files
committed
spending_reqs: Add 2 new sighash_type.
1 parent 205b56f commit 5c74b12

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/ledger/spending_requirements.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct SpendingRequirementsReturn {
2323
}
2424

2525
impl Ledger {
26+
#[tracing::instrument(skip_all)]
2627
pub fn p2wpkh_check(
2728
&self,
2829
tx: &Transaction,
@@ -79,6 +80,7 @@ impl Ledger {
7980
Ok(())
8081
}
8182

83+
#[tracing::instrument(skip_all)]
8284
pub fn p2wsh_check(
8385
&self,
8486
tx: &Transaction,
@@ -123,6 +125,7 @@ impl Ledger {
123125
})
124126
}
125127

128+
#[tracing::instrument(skip_all)]
126129
pub fn p2tr_check(
127130
&self,
128131
tx: &Transaction,
@@ -153,24 +156,32 @@ impl Ledger {
153156
if witness.len() == 1 {
154157
let signature = witness.pop().unwrap();
155158
let signature = bitcoin::taproot::Signature::from_slice(&signature).unwrap();
159+
tracing::trace!("Signature {:?}", signature);
156160

157161
let x_only_public_key = XOnlyPublicKey::from_slice(&sig_pub_key_bytes[2..]).unwrap();
158-
let mut sighashcache = SighashCache::new(tx.clone());
159-
let h = sighashcache
162+
tracing::trace!("X-only public key is {}", x_only_public_key);
163+
164+
let mut sighash_cache = SighashCache::new(tx);
165+
let taproot_key_spend_signature_hash = sighash_cache
160166
.taproot_key_spend_signature_hash(
161167
input_idx,
162168
&match signature.sighash_type {
169+
TapSighashType::Default | TapSighashType::All => Prevouts::All(txouts),
163170
TapSighashType::SinglePlusAnyoneCanPay => {
164171
Prevouts::One(input_idx, txouts[input_idx].clone())
165172
}
166-
// TODO: Implement others.
167-
_ => Prevouts::All(txouts),
173+
_ => {
174+
return Err(LedgerError::SpendingRequirements(format!(
175+
"Unimplemented sighash type {}",
176+
signature.sighash_type
177+
)))
178+
}
168179
},
169180
signature.sighash_type,
170181
)
171182
.unwrap();
172183

173-
let msg = Message::from(h);
184+
let msg = Message::from(taproot_key_spend_signature_hash);
174185

175186
return match x_only_public_key.verify(&secp, &msg, &signature.signature) {
176187
Ok(()) => Ok(SpendingRequirementsReturn {

0 commit comments

Comments
 (0)