Struct secp256k1::KeyPair[][src]

pub struct KeyPair(_);
Expand description

Opaque data structure that holds a keypair consisting of a secret and a public key.

Implementations

Formats the explicit byte value of the secret key kept inside the type as a little-endian hexadecimal string using the provided formatter.

This is the only method that outputs the actual secret key value, and, thus, should be used with extreme precaution.

Example
use secp256k1::ONE_KEY;
use secp256k1::KeyPair;
use secp256k1::Secp256k1;

let secp = Secp256k1::new();
let key = ONE_KEY;
let key = KeyPair::from_secret_key(&secp, key);

// Normal display hides value
assert_eq!(
    "KeyPair(#2518682f7819fb2d)",
    format!("{:?}", key)
);
// Here we explicitly display the secret value:
assert_eq!(
    "0000000000000000000000000000000000000000000000000000000000000001",
    format!("{}", key.display_secret())
);
assert_eq!(
    "DisplaySecret(\"0000000000000000000000000000000000000000000000000000000000000001\")",
    format!("{:?}", key.display_secret())
);

Obtains a raw const pointer suitable for use with FFI functions

Obtains a raw mutable pointer suitable for use with FFI functions

Creates a Schnorr KeyPair directly from generic Secp256k1 secret key

Panic

Panics if internal representation of the provided SecretKey does not hold correct secret key value obtained from Secp256k1 library previously, specifically when secret key value is out-of-range (0 or in excess of the group order).

Creates a Schnorr KeyPair directly from a secret key slice.

Errors

Error::InvalidSecretKey if the provided data has an incorrect length, exceeds Secp256k1 field p value or the corresponding public key is not even.

Creates a Schnorr KeyPair directly from a secret key string

Errors

Error::InvalidSecretKey if corresponding public key for the provided secret key is not even.

This is supported on crate feature rand only.

Generates a new random secret key.

Serialize the key pair as a secret key byte value

Tweak a keypair by adding the given tweak to the secret key and updating the public key accordingly.

Will return an error if the resulting key would be invalid or if the tweak was not a 32-byte length slice.

NB: Will not error if the tweaked public key has an odd value and can’t be used for BIP 340-342 purposes.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.