Struct breez_sdk_liquid::bitcoin::util::key::Secp256k1

pub struct Secp256k1<C>
where C: Context,
{ /* private fields */ }
Expand description

The secp256k1 engine, used to execute all signature operations.

Implementations§

§

impl<C> Secp256k1<C>
where C: Context,

pub fn gen_new() -> Secp256k1<C>

Lets you create a context in a generic manner (sign/verify/all).

If rand-std feature is enabled, context will have been randomized using thread_rng. If rand-std feature is not enabled please consider randomizing the context as follows:

let mut ctx = Secp256k1::new();
// let seed = <32 bytes of random data>
ctx.seeded_randomize(&seed);
§

impl Secp256k1<All>

pub fn new() -> Secp256k1<All>

Creates a new Secp256k1 context with all capabilities.

If rand-std feature is enabled, context will have been randomized using thread_rng. If rand-std feature is not enabled please consider randomizing the context (see docs for Secp256k1::gen_new()).

§

impl Secp256k1<SignOnly>

pub fn signing_only() -> Secp256k1<SignOnly>

Creates a new Secp256k1 context that can only be used for signing.

If rand-std feature is enabled, context will have been randomized using thread_rng. If rand-std feature is not enabled please consider randomizing the context (see docs for Secp256k1::gen_new()).

§

impl Secp256k1<VerifyOnly>

pub fn verification_only() -> Secp256k1<VerifyOnly>

Creates a new Secp256k1 context that can only be used for verification.

If rand-std feature is enabled, context will have been randomized using thread_rng. If rand-std feature is not enabled please consider randomizing the context (see docs for Secp256k1::gen_new()).

§

impl<'buf, C> Secp256k1<C>
where C: Context + PreallocatedContext<'buf>,

pub fn preallocated_gen_new( buf: &'buf mut [AlignedType], ) -> Result<Secp256k1<C>, Error>

Lets you create a context with a preallocated buffer in a generic manner (sign/verify/all).

§

impl<'buf> Secp256k1<AllPreallocated<'buf>>

pub fn preallocated_new( buf: &'buf mut [AlignedType], ) -> Result<Secp256k1<AllPreallocated<'buf>>, Error>

Creates a new Secp256k1 context with all capabilities

pub fn preallocate_size() -> usize

Uses the ffi secp256k1_context_preallocated_size to check the memory size needed for a context.

pub unsafe fn from_raw_all( raw_ctx: *mut Context, ) -> ManuallyDrop<Secp256k1<AllPreallocated<'buf>>>

Create a context from a raw context.

§Safety

This is highly unsafe, due to the number of conditions that aren’t checked.

  • raw_ctx needs to be a valid Secp256k1 context pointer. that was generated by exactly the same code/version of the libsecp256k1 used here.
  • The capabilities (All/SignOnly/VerifyOnly) of the context must match the flags passed to libsecp256k1 when generating the context.
  • The user must handle the freeing of the context(using the correct functions) by himself.
  • Violating these may lead to Undefined Behavior.
§

impl<'buf> Secp256k1<SignOnlyPreallocated<'buf>>

pub fn preallocated_signing_only( buf: &'buf mut [AlignedType], ) -> Result<Secp256k1<SignOnlyPreallocated<'buf>>, Error>

Creates a new Secp256k1 context that can only be used for signing.

pub fn preallocate_signing_size() -> usize

Uses the ffi secp256k1_context_preallocated_size to check the memory size needed for the context.

pub unsafe fn from_raw_signining_only( raw_ctx: *mut Context, ) -> ManuallyDrop<Secp256k1<SignOnlyPreallocated<'buf>>>

Create a context from a raw context.

§Safety

This is highly unsafe, due to the number of conditions that aren’t checked.

  • raw_ctx needs to be a valid Secp256k1 context pointer. that was generated by exactly the same code/version of the libsecp256k1 used here.
  • The capabilities (All/SignOnly/VerifyOnly) of the context must match the flags passed to libsecp256k1 when generating the context.
  • The user must handle the freeing of the context(using the correct functions) by himself.
  • This list is not exhaustive, and any violation may lead to Undefined Behavior.
§

impl<'buf> Secp256k1<VerifyOnlyPreallocated<'buf>>

pub fn preallocated_verification_only( buf: &'buf mut [AlignedType], ) -> Result<Secp256k1<VerifyOnlyPreallocated<'buf>>, Error>

Creates a new Secp256k1 context that can only be used for verification

pub fn preallocate_verification_size() -> usize

Uses the ffi secp256k1_context_preallocated_size to check the memory size needed for the context.

pub unsafe fn from_raw_verification_only( raw_ctx: *mut Context, ) -> ManuallyDrop<Secp256k1<VerifyOnlyPreallocated<'buf>>>

Create a context from a raw context.

§Safety

This is highly unsafe, due to the number of conditions that aren’t checked.

  • raw_ctx needs to be a valid Secp256k1 context pointer. that was generated by exactly the same code/version of the libsecp256k1 used here.
  • The capabilities (All/SignOnly/VerifyOnly) of the context must match the flags passed to libsecp256k1 when generating the context.
  • The user must handle the freeing of the context(using the correct functions) by himself.
  • This list is not exhaustive, and any violation may lead to Undefined Behavior.
§

impl<C> Secp256k1<C>
where C: Signing,

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

👎Deprecated since 0.21.0: Use sign_ecdsa_recoverable instead.

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

pub fn sign_ecdsa_recoverable( &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 sign_ecdsa_recoverable_with_noncedata( &self, msg: &Message, sk: &SecretKey, noncedata: &[u8; 32], ) -> RecoverableSignature

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.

§

impl<C> Secp256k1<C>
where C: Verification,

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

👎Deprecated since 0.21.0: Use recover_ecdsa instead.

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

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

§

impl<C> Secp256k1<C>
where C: Signing,

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

👎Deprecated since 0.21.0: Use sign_ecdsa instead.

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

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.

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.

pub fn sign_grind_r( &self, msg: &Message, sk: &SecretKey, bytes_to_grind: usize, ) -> Signature

👎Deprecated since 0.21.0: Use sign_ecdsa_grind_r instead.

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.

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.

pub fn sign_low_r(&self, msg: &Message, sk: &SecretKey) -> Signature

👎Deprecated since 0.21.0: Use sign_ecdsa_low_r instead.

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 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.

§

impl<C> Secp256k1<C>
where C: Verification,

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

👎Deprecated since 0.21.0: Use verify_ecdsa instead

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));

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_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_slice(&[0xcd; 32]).expect("32 bytes");
assert_eq!(secp.verify_ecdsa(&message, &sig, &public_key), Err(Error::IncorrectSignature));
§

impl<C> Secp256k1<C>
where C: Signing,

pub fn schnorrsig_sign_no_aux_rand( &self, msg: &Message, keypair: &KeyPair, ) -> Signature

👎Deprecated since 0.21.0: Use sign_schnorr_no_aux_rand instead.

Create a schnorr signature without using any auxiliary random data.

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

👎Deprecated since 0.21.0: Use sign_schnorr_with_aux_rand instead.

Create a Schnorr signature using the given auxiliary random data.

pub fn sign_schnorr_with_aux_rand( &self, msg: &Message, keypair: &KeyPair, aux_rand: &[u8; 32], ) -> Signature

Create a Schnorr signature using the given auxiliary random data.

§

impl<C> Secp256k1<C>
where C: Verification,

pub fn schnorrsig_verify( &self, sig: &Signature, msg: &Message, pubkey: &XOnlyPublicKey, ) -> Result<(), Error>

👎Deprecated since 0.21.0: Use verify_schnorr instead.

Verify a Schnorr signature.

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

Verify a Schnorr signature.

§

impl<C> Secp256k1<C>
where C: 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 preallocate_size_gen() -> usize

Returns the required memory for a preallocated context buffer in a generic manner(sign/verify/all).

pub fn seeded_randomize(&mut self, seed: &[u8; 32])

(Re)randomizes the Secp256k1 context for extra sidechannel resistance given 32 bytes of cryptographically-secure random data; see comment in libsecp256k1 commit d2275795f by Gregory Maxwell.

Trait Implementations§

§

impl<C> Clone for Secp256k1<C>
where C: Context,

§

fn clone(&self) -> Secp256k1<C>

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
§

impl<C> Debug for Secp256k1<C>
where C: Context,

§

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

Formats the value using the given formatter. Read more
§

impl Default for Secp256k1<All>

§

fn default() -> Secp256k1<All>

Returns the “default value” for a type. Read more
§

impl<C> Drop for Secp256k1<C>
where C: Context,

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<C> PartialEq for Secp256k1<C>
where C: Context,

§

fn eq(&self, _other: &Secp256k1<C>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl<C> Eq for Secp256k1<C>
where C: Context,

§

impl<C> Send for Secp256k1<C>
where C: Context,

§

impl<C> Sync for Secp256k1<C>
where C: Context,

Auto Trait Implementations§

§

impl<C> Freeze for Secp256k1<C>

§

impl<C> RefUnwindSafe for Secp256k1<C>
where C: RefUnwindSafe,

§

impl<C> Unpin for Secp256k1<C>
where C: Unpin,

§

impl<C> UnwindSafe for Secp256k1<C>
where C: UnwindSafe,

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§

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

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T

§

impl<T> TaskRetFutTrait for T
where T: Send,