Skip to content

Commit

Permalink
Add example usage of new _global API
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharding committed Apr 20, 2023
1 parent c9bcdec commit ebfeb2b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit ebfeb2b

Please sign in to comment.