pub struct SecretKey { /* private fields */ }
Expand description
SecretKey
Implementations§
Source§impl SecretKey
impl SecretKey
Sourcepub fn to_secret_hex(&self) -> String
pub fn to_secret_hex(&self) -> String
Get secret key as hex
string
Sourcepub fn as_secret_bytes(&self) -> &[u8] ⓘ
pub fn as_secret_bytes(&self) -> &[u8] ⓘ
Get secret key as bytes
Sourcepub fn to_secret_bytes(&self) -> [u8; 32]
pub fn to_secret_bytes(&self) -> [u8; 32]
Get secret key as bytes
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Get public key
Methods from Deref<Target = SecretKey>§
Sourcepub fn display_secret(&self) -> DisplaySecret
pub fn display_secret(&self) -> DisplaySecret
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 caution.
§Examples
use secp256k1::SecretKey;
let key = SecretKey::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
// Normal debug hides value (`Display` is not implemented for `SecretKey`).
// E.g., `format!("{:?}", key)` prints "SecretKey(#2518682f7819fb2d)".
// Here we explicitly display the secret value:
assert_eq!(
"0000000000000000000000000000000000000000000000000000000000000001",
format!("{}", key.display_secret())
);
// Also, we can explicitly display with `Debug`:
assert_eq!(
format!("{:?}", key.display_secret()),
format!("DisplaySecret(\"{}\")", key.display_secret())
);
Sourcepub fn secret_bytes(&self) -> [u8; 32]
pub fn secret_bytes(&self) -> [u8; 32]
Returns the secret key as a byte value.
Sourcepub fn keypair<C>(&self, secp: &Secp256k1<C>) -> Keypairwhere
C: Signing,
pub fn keypair<C>(&self, secp: &Secp256k1<C>) -> Keypairwhere
C: Signing,
Returns the Keypair
for this SecretKey
.
This is equivalent to using Keypair::from_secret_key
.
Sourcepub fn public_key<C>(&self, secp: &Secp256k1<C>) -> PublicKeywhere
C: Signing,
pub fn public_key<C>(&self, secp: &Secp256k1<C>) -> PublicKeywhere
C: Signing,
Returns the PublicKey
for this SecretKey
.
This is equivalent to using PublicKey::from_secret_key
.
Sourcepub fn x_only_public_key<C>(
&self,
secp: &Secp256k1<C>,
) -> (XOnlyPublicKey, Parity)where
C: Signing,
pub fn x_only_public_key<C>(
&self,
secp: &Secp256k1<C>,
) -> (XOnlyPublicKey, Parity)where
C: Signing,
Returns the XOnlyPublicKey
(and it’s Parity
) for this SecretKey
.
This is equivalent to XOnlyPublicKey::from_keypair(self.keypair(secp))
.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SecretKey
impl<'de> Deserialize<'de> for SecretKey
Source§fn deserialize<D>(
deserializer: D,
) -> Result<SecretKey, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<SecretKey, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for SecretKey
impl Serialize for SecretKey
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for SecretKey
impl StructuralPartialEq for SecretKey
Auto Trait Implementations§
impl Freeze for SecretKey
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more