@@ -19,6 +19,8 @@ extern crate miniscript;
19
19
20
20
use bitcoin:: consensus:: Decodable ;
21
21
use bitcoin:: secp256k1; // secp256k1 re-exported from rust-bitcoin
22
+ use bitcoin:: util:: sighash;
23
+ use miniscript:: interpreter:: KeySigPair ;
22
24
use std:: str:: FromStr ;
23
25
24
26
fn main ( ) {
@@ -83,7 +85,7 @@ fn main() {
83
85
0xa9 , 0x14 , 0x92 , 0x09 , 0xa8 , 0xf9 , 0x0c , 0x58 , 0x4b , 0xb5 , 0x97 , 0x4d , 0x58 , 0x68 , 0x72 ,
84
86
0x49 , 0xe5 , 0x32 , 0xde , 0x59 , 0xf4 , 0xbc , 0x87 ,
85
87
] ) ;
86
- let mut interpreter = miniscript:: Interpreter :: from_txdata (
88
+ let interpreter = miniscript:: Interpreter :: from_txdata (
87
89
& spk_input_1,
88
90
& transaction. input [ 0 ] . script_sig ,
89
91
& transaction. input [ 0 ] . witness ,
@@ -105,10 +107,14 @@ fn main() {
105
107
// the blockchain, standardness would've required they be
106
108
// either valid or 0-length.
107
109
println ! ( "\n Example one" ) ;
108
- for elem in interpreter. iter ( |_ , _| true ) {
110
+ for elem in interpreter. iter_assume_sigs ( ) {
109
111
// Don't bother checking signatures
110
112
match elem. expect ( "no evaluation error" ) {
111
- miniscript:: interpreter:: SatisfiedConstraint :: PublicKey { key, sig } => {
113
+ miniscript:: interpreter:: SatisfiedConstraint :: PublicKey { key_sig } => {
114
+ // Check that the signature is ecdsa sig
115
+ let ( key, sig) = key_sig
116
+ . as_ecdsa ( )
117
+ . expect ( "Expected Ecdsa sig, found schnorr sig" ) ;
112
118
println ! ( "Signed with {}: {}" , key, sig) ;
113
119
}
114
120
_ => { }
@@ -122,7 +128,7 @@ fn main() {
122
128
// from the MiniscriptKey which can supplied by `to_pk_ctx` parameter. For example,
123
129
// when calculating the script pubkey of a descriptor with xpubs, the secp context and
124
130
// child information maybe required.
125
- let mut interpreter = miniscript:: Interpreter :: from_txdata (
131
+ let interpreter = miniscript:: Interpreter :: from_txdata (
126
132
& spk_input_1,
127
133
& transaction. input [ 0 ] . script_sig ,
128
134
& transaction. input [ 0 ] . witness ,
@@ -131,21 +137,15 @@ fn main() {
131
137
)
132
138
. unwrap ( ) ;
133
139
134
- // We can set the amount passed to `sighash_verify` to 0 because this is a legacy
135
- // transaction and so the amount won't actually be checked by the signature
136
- let vfyfn = interpreter
137
- . sighash_verify ( & secp, & transaction, 0 , 0 )
138
- . expect ( "Can only fail in sighash single when corresponding output is not present" ) ;
139
- // Restrict to sighash_all just to demonstrate how to add additional filters
140
- // `&_` needed here because of https://github.com/rust-lang/rust/issues/79187
141
- let vfyfn = move |pk : & _ , bitcoinsig : miniscript:: bitcoin:: EcdsaSig | {
142
- bitcoinsig. hash_ty == bitcoin:: EcdsaSigHashType :: All && vfyfn ( pk, bitcoinsig)
143
- } ;
140
+ // We can set prevouts to be empty list because this is a legacy transaction
141
+ // and this information is not required for sighash computation.
142
+ let prevouts = sighash:: Prevouts :: All ( & [ ] ) ;
144
143
145
144
println ! ( "\n Example two" ) ;
146
- for elem in interpreter. iter ( vfyfn ) {
145
+ for elem in interpreter. iter ( & secp , & transaction , 0 , & prevouts ) {
147
146
match elem. expect ( "no evaluation error" ) {
148
- miniscript:: interpreter:: SatisfiedConstraint :: PublicKey { key, sig } => {
147
+ miniscript:: interpreter:: SatisfiedConstraint :: PublicKey { key_sig } => {
148
+ let ( key, sig) = key_sig. as_ecdsa ( ) . unwrap ( ) ;
149
149
println ! ( "Signed with {}: {}" , key, sig) ;
150
150
}
151
151
_ => { }
@@ -156,7 +156,7 @@ fn main() {
156
156
// what happens given an apparently invalid script
157
157
let secp = secp256k1:: Secp256k1 :: new ( ) ;
158
158
let message = secp256k1:: Message :: from_slice ( & [ 0x01 ; 32 ] [ ..] ) . expect ( "32-byte hash" ) ;
159
- let mut interpreter = miniscript:: Interpreter :: from_txdata (
159
+ let interpreter = miniscript:: Interpreter :: from_txdata (
160
160
& spk_input_1,
161
161
& transaction. input [ 0 ] . script_sig ,
162
162
& transaction. input [ 0 ] . witness ,
@@ -165,12 +165,13 @@ fn main() {
165
165
)
166
166
. unwrap ( ) ;
167
167
168
- let iter = interpreter. iter ( |pk, ecdsa_sig| {
168
+ let iter = interpreter. iter_custom ( Box :: new ( |key_sig : & KeySigPair | {
169
+ let ( pk, ecdsa_sig) = key_sig. as_ecdsa ( ) . expect ( "Ecdsa Sig" ) ;
169
170
ecdsa_sig. hash_ty == bitcoin:: EcdsaSigHashType :: All
170
171
&& secp
171
172
. verify_ecdsa ( & message, & ecdsa_sig. sig , & pk. inner )
172
173
. is_ok ( )
173
- } ) ;
174
+ } ) ) ;
174
175
println ! ( "\n Example three" ) ;
175
176
for elem in iter {
176
177
let error = elem. expect_err ( "evaluation error" ) ;
0 commit comments