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.
rand
only.Generates a new random secret key.
Serialize the key pair as a secret key byte value
pub fn tweak_add_assign<C: Verification>(
&mut self,
secp: &Secp256k1<C>,
tweak: &[u8]
) -> Result<(), Error>
pub fn tweak_add_assign<C: Verification>(
&mut self,
secp: &Secp256k1<C>,
tweak: &[u8]
) -> Result<(), Error>
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
Auto Trait Implementations
impl RefUnwindSafe for KeyPair
impl UnwindSafe for KeyPair
Blanket Implementations
Mutably borrows from an owned value. Read more