@@ -23,6 +23,7 @@ pub struct SpendingRequirementsReturn {
23
23
}
24
24
25
25
impl Ledger {
26
+ #[ tracing:: instrument( skip_all) ]
26
27
pub fn p2wpkh_check (
27
28
& self ,
28
29
tx : & Transaction ,
@@ -79,6 +80,7 @@ impl Ledger {
79
80
Ok ( ( ) )
80
81
}
81
82
83
+ #[ tracing:: instrument( skip_all) ]
82
84
pub fn p2wsh_check (
83
85
& self ,
84
86
tx : & Transaction ,
@@ -123,6 +125,7 @@ impl Ledger {
123
125
} )
124
126
}
125
127
128
+ #[ tracing:: instrument( skip_all) ]
126
129
pub fn p2tr_check (
127
130
& self ,
128
131
tx : & Transaction ,
@@ -153,24 +156,32 @@ impl Ledger {
153
156
if witness. len ( ) == 1 {
154
157
let signature = witness. pop ( ) . unwrap ( ) ;
155
158
let signature = bitcoin:: taproot:: Signature :: from_slice ( & signature) . unwrap ( ) ;
159
+ tracing:: trace!( "Signature {:?}" , signature) ;
156
160
157
161
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
160
166
. taproot_key_spend_signature_hash (
161
167
input_idx,
162
168
& match signature. sighash_type {
169
+ TapSighashType :: Default | TapSighashType :: All => Prevouts :: All ( txouts) ,
163
170
TapSighashType :: SinglePlusAnyoneCanPay => {
164
171
Prevouts :: One ( input_idx, txouts[ input_idx] . clone ( ) )
165
172
}
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
+ }
168
179
} ,
169
180
signature. sighash_type ,
170
181
)
171
182
. unwrap ( ) ;
172
183
173
- let msg = Message :: from ( h ) ;
184
+ let msg = Message :: from ( taproot_key_spend_signature_hash ) ;
174
185
175
186
return match x_only_public_key. verify ( & secp, & msg, & signature. signature ) {
176
187
Ok ( ( ) ) => Ok ( SpendingRequirementsReturn {
0 commit comments