pub struct GlobalContext { /* private fields */ }
Expand description
Proxy struct for global SECP256K1
context.
Methods from Deref<Target = Secp256k1<All>>§
Sourcepub fn sign_ecdsa(&self, msg: &Message, sk: &SecretKey) -> Signature
pub fn sign_ecdsa(&self, msg: &Message, sk: &SecretKey) -> Signature
Constructs a signature for msg
using the secret key sk
and RFC6979 nonce
Requires a signing-capable context.
Sourcepub fn sign_ecdsa_with_noncedata(
&self,
msg: &Message,
sk: &SecretKey,
noncedata: &[u8; 32],
) -> Signature
pub fn sign_ecdsa_with_noncedata( &self, msg: &Message, sk: &SecretKey, noncedata: &[u8; 32], ) -> Signature
Constructs a signature for msg
using the secret key sk
and RFC6979 nonce
and includes 32 bytes of noncedata in the nonce generation via inclusion in
one of the hash operations during nonce generation. This is useful when multiple
signatures are needed for the same Message and SecretKey while still using RFC6979.
Requires a signing-capable context.
Sourcepub fn sign_ecdsa_grind_r(
&self,
msg: &Message,
sk: &SecretKey,
bytes_to_grind: usize,
) -> Signature
pub fn sign_ecdsa_grind_r( &self, msg: &Message, sk: &SecretKey, bytes_to_grind: usize, ) -> Signature
Constructs a signature for msg
using the secret key sk
, RFC6979 nonce
and “grinds” the nonce by passing extra entropy if necessary to produce
a signature that is less than 71 - bytes_to_grind
bytes. The number
of signing operation performed by this function is exponential in the
number of bytes grinded.
Requires a signing capable context.
Sourcepub fn sign_ecdsa_low_r(&self, msg: &Message, sk: &SecretKey) -> Signature
pub fn sign_ecdsa_low_r(&self, msg: &Message, sk: &SecretKey) -> Signature
Constructs a signature for msg
using the secret key sk
, RFC6979 nonce
and “grinds” the nonce by passing extra entropy if necessary to produce
a signature that is less than 71 bytes and compatible with the low r
signature implementation of bitcoin core. In average, this function
will perform two signing operations.
Requires a signing capable context.
Sourcepub fn verify_ecdsa(
&self,
msg: &Message,
sig: &Signature,
pk: &PublicKey,
) -> Result<(), Error>
pub fn verify_ecdsa( &self, msg: &Message, sig: &Signature, pk: &PublicKey, ) -> Result<(), Error>
Checks that sig
is a valid ECDSA signature for msg
using the public
key pubkey
. Returns Ok(())
on success. Note that this function cannot
be used for Bitcoin consensus checking since there may exist signatures
which OpenSSL would verify but not libsecp256k1, or vice-versa. Requires a
verify-capable context.
let message = Message::from_digest_slice(&[0xab; 32]).expect("32 bytes");
let sig = secp.sign_ecdsa(&message, &secret_key);
assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Ok(()));
let message = Message::from_digest_slice(&[0xcd; 32]).expect("32 bytes");
assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Err(Error::IncorrectSignature));
Sourcepub fn sign_schnorr(&self, msg: &[u8], keypair: &Keypair) -> Signature
pub fn sign_schnorr(&self, msg: &[u8], keypair: &Keypair) -> Signature
Creates a schnorr signature internally using the rand::rngs::ThreadRng
random number
generator to generate the auxiliary random data.
Sourcepub fn sign_schnorr_no_aux_rand(
&self,
msg: &[u8],
keypair: &Keypair,
) -> Signature
pub fn sign_schnorr_no_aux_rand( &self, msg: &[u8], keypair: &Keypair, ) -> Signature
Creates a schnorr signature without using any auxiliary random data.
Sourcepub fn sign_schnorr_with_aux_rand(
&self,
msg: &[u8],
keypair: &Keypair,
aux_rand: &[u8; 32],
) -> Signature
pub fn sign_schnorr_with_aux_rand( &self, msg: &[u8], keypair: &Keypair, aux_rand: &[u8; 32], ) -> Signature
Creates a schnorr signature using the given auxiliary random data.
Sourcepub fn sign_schnorr_with_rng<R>(
&self,
msg: &[u8],
keypair: &Keypair,
rng: &mut R,
) -> Signature
pub fn sign_schnorr_with_rng<R>( &self, msg: &[u8], keypair: &Keypair, rng: &mut R, ) -> Signature
Creates a schnorr signature using the given random number generator to generate the auxiliary random data.
Sourcepub fn verify_schnorr(
&self,
sig: &Signature,
msg: &[u8],
pubkey: &XOnlyPublicKey,
) -> Result<(), Error>
pub fn verify_schnorr( &self, sig: &Signature, msg: &[u8], pubkey: &XOnlyPublicKey, ) -> Result<(), Error>
Verifies a schnorr signature.
Sourcepub fn ctx(&self) -> NonNull<Context>
pub fn ctx(&self) -> NonNull<Context>
Getter for the raw pointer to the underlying secp256k1 context. This shouldn’t be needed with normal usage of the library. It enables extending the Secp256k1 with more cryptographic algorithms outside of this crate.
Sourcepub fn generate_keypair<R>(&self, rng: &mut R) -> (SecretKey, PublicKey)
pub fn generate_keypair<R>(&self, rng: &mut R) -> (SecretKey, PublicKey)
Generates a random keypair. Convenience function for SecretKey::new
and
PublicKey::from_secret_key
.
Trait Implementations§
Source§impl Clone for GlobalContext
impl Clone for GlobalContext
Source§fn clone(&self) -> GlobalContext
fn clone(&self) -> GlobalContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more