16
16
17
17
use :: libsecp256k1;
18
18
pub use :: libsecp256k1:: Error ;
19
+ #[ cfg( not( feature = "wasm-deterministic" ) ) ]
20
+ use :: libsecp256k1:: { Error as LibSecp256k1Error , Message as LibSecp256k1Message } ;
19
21
use :: libsecp256k1:: {
20
- Error as LibSecp256k1Error , Message as LibSecp256k1Message , PublicKey as LibSecp256k1PublicKey ,
21
- RecoveryId as LibSecp256k1RecoveryId , SecretKey as LibSecp256k1PrivateKey ,
22
- Signature as LibSecp256k1Signature ,
22
+ PublicKey as LibSecp256k1PublicKey , RecoveryId as LibSecp256k1RecoveryId ,
23
+ SecretKey as LibSecp256k1PrivateKey , Signature as LibSecp256k1Signature ,
23
24
} ;
24
25
use serde:: de:: { Deserialize , Error as de_Error} ;
25
26
use serde:: Serialize ;
@@ -101,6 +102,7 @@ impl Secp256k1PublicKey {
101
102
Secp256k1PublicKey :: from_slice ( & data[ ..] ) . map_err ( |_e| "Invalid public key hex string" )
102
103
}
103
104
105
+ #[ cfg( not( feature = "wasm-deterministic" ) ) ]
104
106
pub fn from_private ( privk : & Secp256k1PrivateKey ) -> Secp256k1PublicKey {
105
107
let key = LibSecp256k1PublicKey :: from_secret_key ( & privk. key ) ;
106
108
Secp256k1PublicKey {
@@ -109,6 +111,7 @@ impl Secp256k1PublicKey {
109
111
}
110
112
}
111
113
114
+ #[ cfg( not( feature = "wasm-deterministic" ) ) ]
112
115
/// recover message and signature to public key (will be compressed)
113
116
pub fn recover_to_pubkey (
114
117
msg : & [ u8 ] ,
@@ -186,6 +189,7 @@ impl Secp256k1PrivateKey {
186
189
}
187
190
}
188
191
192
+ #[ cfg( not( feature = "wasm-deterministic" ) ) ]
189
193
pub fn secp256k1_recover (
190
194
message_arr : & [ u8 ] ,
191
195
serialized_signature : & [ u8 ] ,
@@ -197,6 +201,7 @@ pub fn secp256k1_recover(
197
201
Ok ( recovered_pub_key. serialize_compressed ( ) )
198
202
}
199
203
204
+ #[ cfg( not( feature = "wasm-deterministic" ) ) ]
200
205
pub fn secp256k1_verify (
201
206
message_arr : & [ u8 ] ,
202
207
serialized_signature : & [ u8 ] ,
@@ -300,6 +305,12 @@ impl PublicKey for Secp256k1PublicKey {
300
305
self . to_bytes ( )
301
306
}
302
307
308
+ #[ cfg( feature = "wasm-deterministic" ) ]
309
+ fn verify ( & self , _data_hash : & [ u8 ] , _sig : & MessageSignature ) -> Result < bool , & ' static str > {
310
+ Err ( "Not implemented for wasm-deterministic" )
311
+ }
312
+
313
+ #[ cfg( not( feature = "wasm-deterministic" ) ) ]
303
314
fn verify ( & self , data_hash : & [ u8 ] , sig : & MessageSignature ) -> Result < bool , & ' static str > {
304
315
let pub_key = Secp256k1PublicKey :: recover_to_pubkey ( data_hash, sig) ?;
305
316
Ok ( self . eq ( & pub_key) )
@@ -315,6 +326,12 @@ impl PrivateKey for Secp256k1PrivateKey {
315
326
bits
316
327
}
317
328
329
+ #[ cfg( feature = "wasm-deterministic" ) ]
330
+ fn sign ( & self , _data_hash : & [ u8 ] ) -> Result < MessageSignature , & ' static str > {
331
+ Err ( "Not implemented for wasm-deterministic" )
332
+ }
333
+
334
+ #[ cfg( not( feature = "wasm-deterministic" ) ) ]
318
335
fn sign ( & self , data_hash : & [ u8 ] ) -> Result < MessageSignature , & ' static str > {
319
336
let message = LibSecp256k1Message :: parse_slice ( data_hash)
320
337
. map_err ( |_e| "Invalid message: failed to decode data hash: must be a 32-byte hash" ) ?;
0 commit comments