Skip to content

Commit 8d0b743

Browse files
committed
Add example usage of new _global API
1 parent 06d0f16 commit 8d0b743

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/key.rs

+14
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,20 @@ impl PublicKey {
466466
}
467467
}
468468

469+
/// This is just a demo of the new _global API
470+
pub fn _from_secret_key(sk: &SecretKey) -> PublicKey {
471+
unsafe {
472+
crate::context::_global::with_global_signing_context(|ctx| {
473+
let mut pk = ffi::PublicKey::new();
474+
// We can assume the return value because it's not possible to construct
475+
// an invalid `SecretKey` without transmute trickery or something.
476+
let res = ffi::secp256k1_ec_pubkey_create(ctx, &mut pk, sk.as_c_ptr());
477+
debug_assert_eq!(res, 1);
478+
PublicKey(pk)
479+
})
480+
}
481+
}
482+
469483
/// Creates a new public key from a [`SecretKey`] and the global [`SECP256K1`] context.
470484
#[inline]
471485
#[cfg(feature = "global-context")]

0 commit comments

Comments
 (0)