From 8d0b743638861c29ab4a5633ce0499e238359bd7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 20 Apr 2023 15:22:31 +1000 Subject: [PATCH] Add example usage of new _global API --- src/key.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/key.rs b/src/key.rs index 4593c873c..ee2165b45 100644 --- a/src/key.rs +++ b/src/key.rs @@ -466,6 +466,20 @@ impl PublicKey { } } + /// This is just a demo of the new _global API + pub fn _from_secret_key(sk: &SecretKey) -> PublicKey { + unsafe { + crate::context::_global::with_global_signing_context(|ctx| { + let mut pk = ffi::PublicKey::new(); + // We can assume the return value because it's not possible to construct + // an invalid `SecretKey` without transmute trickery or something. + let res = ffi::secp256k1_ec_pubkey_create(ctx, &mut pk, sk.as_c_ptr()); + debug_assert_eq!(res, 1); + PublicKey(pk) + }) + } + } + /// Creates a new public key from a [`SecretKey`] and the global [`SECP256K1`] context. #[inline] #[cfg(feature = "global-context")]