Struct wallet::SECP256K1 [−][src]
Global Secp256k1 context object
Methods from Deref<Target = Secp256k1<All>>
pub fn schnorrsig_sign(&self, msg: &Message, keypair: &KeyPair) -> Signature
Create a schnorr signature internally using the ThreadRng random number generator to generate the auxiliary random data. Requires compilation with “rand-std” feature.
pub fn schnorrsig_sign_no_aux_rand(
&self,
msg: &Message,
keypair: &KeyPair
) -> Signature
&self,
msg: &Message,
keypair: &KeyPair
) -> Signature
Create a schnorr signature without using any auxiliary random data.
pub fn schnorrsig_sign_with_aux_rand(
&self,
msg: &Message,
keypair: &KeyPair,
aux_rand: &[u8; 32]
) -> Signature
&self,
msg: &Message,
keypair: &KeyPair,
aux_rand: &[u8; 32]
) -> Signature
Create a Schnorr signature using the given auxiliary random data.
pub fn schnorrsig_sign_with_rng<R>(
&self,
msg: &Message,
keypair: &KeyPair,
rng: &mut R
) -> Signature where
R: Rng + CryptoRng,
&self,
msg: &Message,
keypair: &KeyPair,
rng: &mut R
) -> Signature where
R: Rng + CryptoRng,
Create a schnorr signature using the given random number generator to generate the auxiliary random data. Requires compilation with “rand” feature.
pub fn schnorrsig_verify(
&self,
sig: &Signature,
msg: &Message,
pubkey: &PublicKey
) -> Result<(), Error>
&self,
sig: &Signature,
msg: &Message,
pubkey: &PublicKey
) -> Result<(), Error>
Verify a Schnorr signature.
pub fn generate_schnorrsig_keypair<R>(
&self,
rng: &mut R
) -> (KeyPair, PublicKey) where
R: Rng + ?Sized,
&self,
rng: &mut R
) -> (KeyPair, PublicKey) where
R: Rng + ?Sized,
Generates a random Schnorr KeyPair and its associated Schnorr PublicKey.
Convenience function for schnorrsig::KeyPair::new and
schnorrsig::PublicKey::from_keypair; call those functions directly for
batch key generation. Requires a signing-capable context. Requires compilation
with the “rand” feature.
pub fn sign_recoverable(
&self,
msg: &Message,
sk: &SecretKey
) -> RecoverableSignature
&self,
msg: &Message,
sk: &SecretKey
) -> RecoverableSignature
Constructs a signature for msg using the secret key sk and RFC6979 nonce
Requires a signing-capable context.
pub fn recover(
&self,
msg: &Message,
sig: &RecoverableSignature
) -> Result<PublicKey, Error>
&self,
msg: &Message,
sig: &RecoverableSignature
) -> Result<PublicKey, Error>
Determines the public key for which sig is a valid signature for
msg. Requires a verify-capable context.
pub fn ctx(&self) -> &*mut 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.
pub fn sign(&self, msg: &Message, sk: &SecretKey) -> Signature
Constructs a signature for msg using the secret key sk and RFC6979 nonce
Requires a signing-capable context.
pub fn sign_grind_r(
&self,
msg: &Message,
sk: &SecretKey,
bytes_to_grind: usize
) -> Signature
&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_grund bytes. The number
of signing operation performed by this function is exponential in the
number of bytes grinded.
Requires a signing capable context.
pub fn sign_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.
pub fn generate_keypair<R>(&self, rng: &mut R) -> (SecretKey, PublicKey) where
R: Rng + ?Sized,
R: Rng + ?Sized,
Generates a random keypair. Convenience function for key::SecretKey::new
and key::PublicKey::from_secret_key; call those functions directly for
batch key generation. Requires a signing-capable context. Requires compilation
with the “rand” feature.
pub fn verify(
&self,
msg: &Message,
sig: &Signature,
pk: &PublicKey
) -> Result<(), Error>
&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_slice(&[0xab; 32]).expect("32 bytes"); let sig = secp.sign(&message, &secret_key); assert_eq!(secp.verify(&message, &sig, &public_key), Ok(())); let message = Message::from_slice(&[0xcd; 32]).expect("32 bytes"); assert_eq!(secp.verify(&message, &sig, &public_key), Err(Error::IncorrectSignature));
Trait Implementations
impl Deref for SECP256K1[src]
type Target = Secp256k1<All>
The resulting type after dereferencing.
fn deref(&self) -> &Secp256k1<All>[src]
impl LazyStatic for SECP256K1[src]
fn initialize(lazy: &Self)[src]
Auto Trait Implementations
impl RefUnwindSafe for SECP256K1
impl Send for SECP256K1
impl Sync for SECP256K1
impl Unpin for SECP256K1
impl UnwindSafe for SECP256K1
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,