@@ -160,6 +160,7 @@ pub use secp256k1_sys as ffi;
160
160
#[ cfg( all( test, feature = "serde" ) ) ] extern crate serde_test;
161
161
#[ cfg( any( test, feature = "rand" ) ) ] use rand:: Rng ;
162
162
#[ cfg( any( test, feature = "std" ) ) ] extern crate core;
163
+ #[ cfg( feature = "global-context" ) ] #[ macro_use] extern crate lazy_static;
163
164
164
165
use core:: { fmt, ptr, str} ;
165
166
@@ -179,6 +180,12 @@ use core::marker::PhantomData;
179
180
use core:: ops:: Deref ;
180
181
use ffi:: CPtr ;
181
182
183
+ #[ cfg( feature = "global-context" ) ]
184
+ lazy_static ! {
185
+ /// A global, static context to avoid repeatedly creating contexts where one can't be passed
186
+ pub static ref SECP256K1 : Secp256k1 <All > = Secp256k1 :: new( ) ;
187
+ }
188
+
182
189
#[ cfg( feature = "bitcoin_hashes" ) ]
183
190
use bitcoin_hashes:: Hash ;
184
191
@@ -1138,6 +1145,24 @@ mod tests {
1138
1145
assert_tokens ( & sig. readable ( ) , & [ Token :: BorrowedStr ( SIG_STR ) ] ) ;
1139
1146
}
1140
1147
1148
+ #[ cfg( feature = "global-context" ) ]
1149
+ #[ test]
1150
+ fn test_global_context ( ) {
1151
+ use super :: SECP256K1 ;
1152
+
1153
+ let sk_data = hex ! ( "e6dd32f8761625f105c39a39f19370b3521d845a12456d60ce44debd0a362641" ) ;
1154
+ let sk = SecretKey :: from_slice ( & sk_data) . unwrap ( ) ;
1155
+ let msg_data = hex ! ( "a4965ca63b7d8562736ceec36dfa5a11bf426eb65be8ea3f7a49ae363032da0d" ) ;
1156
+ let msg = Message :: from_slice ( & msg_data) . unwrap ( ) ;
1157
+
1158
+ // Check usagfe as explicit parameter
1159
+ let pk = PublicKey :: from_secret_key ( & SECP256K1 , & sk) ;
1160
+
1161
+ // Check usage as self
1162
+ let sig = SECP256K1 . sign ( & msg, & sk) ;
1163
+ assert ! ( SECP256K1 . verify( & msg, & sig, & pk) . is_ok( ) ) ;
1164
+ }
1165
+
1141
1166
// For WASM, just run through our general tests in this file all at once.
1142
1167
#[ cfg( target_arch = "wasm32" ) ]
1143
1168
extern crate wasm_bindgen_test;
0 commit comments