18
18
19
19
use std:: { ptr, fmt, error} ;
20
20
21
- use secp256k1:: { self , Secp256k1 , Signing , Verification , Message , key} ;
21
+ use secp256k1:: { self , Secp256k1 , Signing , Verification , Message } ;
22
+ use secp256k1:: key:: { PublicKey , SecretKey } ;
22
23
23
24
use ffi;
24
25
use super :: ScratchSpace ;
@@ -112,24 +113,24 @@ impl From<ffi::SchnorrSignature> for Signature {
112
113
/// Schnorrsig signing trait
113
114
pub trait Sign {
114
115
/// Creates a Schnorr signature as defined by BIP-schnorr from a message and a secret key.
115
- fn schnorrsig_sign ( & self , msg : & Message , sk : & key :: SecretKey )
116
+ fn schnorrsig_sign ( & self , msg : & Message , sk : & SecretKey )
116
117
-> Signature ;
117
118
}
118
119
119
120
/// Schnorrsig verification trait
120
121
pub trait Verify {
121
122
/// Verifies a Schnorr signature as defined by BIP-schnorr
122
- fn schnorrsig_verify ( & self , msg : & Message , sig : & Signature , pk : & key :: PublicKey ) -> Result < ( ) , Error > ;
123
+ fn schnorrsig_verify ( & self , msg : & Message , sig : & Signature , pk : & PublicKey ) -> Result < ( ) , Error > ;
123
124
/// Takes slices of messages, Schnorr signatures and public keys and verifies them all at once.
124
125
/// That's faster than if they would have been verified one by one. Returns an Error if a
125
126
/// single Signature fails verification.
126
- fn schnorrsig_verify_batch ( & self , msgs : & [ Message ] , sigs : & [ Signature ] , pks : & [ key :: PublicKey ] ) -> Result < ( ) , Error > ;
127
+ fn schnorrsig_verify_batch ( & self , msgs : & [ Message ] , sigs : & [ Signature ] , pks : & [ PublicKey ] ) -> Result < ( ) , Error > ;
127
128
}
128
129
129
130
impl < C : Signing > Sign for Secp256k1 < C > {
130
131
/// Constructs a signature for `msg` using the secret key `sk` and BIP-schnorr nonce
131
132
/// Requires a signing-capable context.
132
- fn schnorrsig_sign ( & self , msg : & Message , sk : & key :: SecretKey )
133
+ fn schnorrsig_sign ( & self , msg : & Message , sk : & SecretKey )
133
134
-> Signature {
134
135
let mut ret = unsafe { ffi:: SchnorrSignature :: blank ( ) } ;
135
136
unsafe {
@@ -152,7 +153,7 @@ impl<C: Verification> Verify for Secp256k1<C> {
152
153
/// Checks that `sig` is a valid Schnorr signature for `msg` using the public key
153
154
/// `pubkey`. Returns `Ok(true)` on success.Requires a verify-capable context.
154
155
#[ inline]
155
- fn schnorrsig_verify ( & self , msg : & Message , sig : & Signature , pk : & key :: PublicKey ) -> Result < ( ) , Error > {
156
+ fn schnorrsig_verify ( & self , msg : & Message , sig : & Signature , pk : & PublicKey ) -> Result < ( ) , Error > {
156
157
unsafe {
157
158
if ffi:: secp256k1_schnorrsig_verify ( * self . ctx ( ) , sig. as_ptr ( ) , msg. as_ptr ( ) , pk. as_ptr ( ) ) == 0 {
158
159
Err ( Error :: IncorrectSignature )
@@ -162,7 +163,7 @@ impl<C: Verification> Verify for Secp256k1<C> {
162
163
}
163
164
}
164
165
165
- fn schnorrsig_verify_batch ( & self , msgs : & [ Message ] , sigs : & [ Signature ] , pks : & [ key :: PublicKey ] ) -> Result < ( ) , Error > {
166
+ fn schnorrsig_verify_batch ( & self , msgs : & [ Message ] , sigs : & [ Signature ] , pks : & [ PublicKey ] ) -> Result < ( ) , Error > {
166
167
if msgs. len ( ) != sigs. len ( ) || msgs. len ( ) != pks. len ( ) {
167
168
return Err ( Error :: ArgumentLength ) ;
168
169
}
@@ -182,10 +183,11 @@ impl<C: Verification> Verify for Secp256k1<C> {
182
183
if sigs. len ( ) >= 1 << 31 {
183
184
return Err ( Error :: TooManySignatures ) ;
184
185
}
186
+ let scratch_space = ScratchSpace :: new ( & self , 8192 ) ;
185
187
unsafe {
186
188
/* TODO: use proper scratch space api */
187
- let scratch_space = ScratchSpace :: new ( & self , 8192 ) ;
188
- let result = ffi :: secp256k1_schnorrsig_verify_batch ( * self . ctx ( ) , scratch_space. scratch_space ( ) ,
189
+ let result = ffi :: secp256k1_schnorrsig_verify_batch ( * self . ctx ( ) ,
190
+ scratch_space. scratch_space ( ) ,
189
191
sigptrs. as_ptr ( ) ,
190
192
msgptrs. as_ptr ( ) ,
191
193
pkptrs. as_ptr ( ) ,
0 commit comments