Struct Secp256k1

Source
pub struct Secp256k1 { /* private fields */ }
Expand description

The secp256k1 engine, used to execute all signature operations

Implementations§

Source§

impl Secp256k1

Source

pub fn sign_schnorr( &self, msg: &Message, sk: &SecretKey, ) -> Result<Signature, Error>

Create a Schnorr signature

Source

pub fn verify_schnorr( &self, msg: &Message, sig: &Signature, pk: &PublicKey, ) -> Result<(), Error>

Verify a Schnorr signature

Source

pub fn recover_schnorr( &self, msg: &Message, sig: &Signature, ) -> Result<PublicKey, Error>

Retrieves the public key for which sig is a valid signature for msg. Requires a verify-capable context.

Source§

impl Secp256k1

Source

pub fn new() -> Secp256k1

Creates a new Secp256k1 context

Source

pub fn with_caps(caps: ContextFlag) -> Secp256k1

Creates a new Secp256k1 context with the specified capabilities

Source

pub fn without_caps() -> Secp256k1

Creates a new Secp256k1 context with no capabilities (just de/serialization)

Source

pub fn randomize<R: Rng>(&mut self, rng: &mut R)

(Re)randomizes the Secp256k1 context for cheap sidechannel resistence; see comment in libsecp256k1 commit d2275795f by Gregory Maxwell

Source

pub fn generate_keypair<R: Rng>( &self, rng: &mut R, ) -> Result<(SecretKey, PublicKey), Error>

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.

Source

pub fn sign(&self, msg: &Message, sk: &SecretKey) -> Result<Signature, Error>

Constructs a signature for msg using the secret key sk and RFC6979 nonce Requires a signing-capable context.

Source

pub fn sign_recoverable( &self, msg: &Message, sk: &SecretKey, ) -> Result<RecoverableSignature, Error>

Constructs a signature for msg using the secret key sk and RFC6979 nonce Requires a signing-capable context.

Source

pub fn recover( &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.

Source

pub fn verify( &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(true) 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.

Trait Implementations§

Source§

impl Clone for Secp256k1

Source§

fn clone(&self) -> Secp256k1

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Secp256k1

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Drop for Secp256k1

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for Secp256k1

Source§

fn eq(&self, other: &Secp256k1) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Secp256k1

Source§

impl Send for Secp256k1

Source§

impl Sync for Secp256k1

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.