pub struct SecretKey(/* private fields */);Expand description
32-byte secp256k1 secret scalar.
Display and serde use lowercase hex. Debug deliberately hides the
secret bytes — this type never logs in plaintext.
§Example
use nula_core::SecretKey;
let sk = SecretKey::generate().unwrap();
let hex = sk.to_hex();
let restored = SecretKey::parse(&hex).unwrap();
assert_eq!(sk, restored);Implementations§
Source§impl SecretKey
impl SecretKey
Sourcepub fn from_byte_array(bytes: [u8; 32]) -> Result<Self, SecretKeyError>
pub fn from_byte_array(bytes: [u8; 32]) -> Result<Self, SecretKeyError>
Construct a SecretKey from a fixed-size byte array.
§Errors
Returns SecretKeyError::InvalidScalar if the bytes do not encode a
valid secp256k1 scalar (i.e. 0 or >= n).
Sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, SecretKeyError>
pub fn from_slice(bytes: &[u8]) -> Result<Self, SecretKeyError>
Construct a SecretKey from a byte slice.
§Errors
Returns SecretKeyError::InvalidLength when the slice is not 32
bytes long, or SecretKeyError::InvalidScalar when the bytes are
not a valid scalar.
Sourcepub fn parse<S>(input: S) -> Result<Self, SecretKeyError>
pub fn parse<S>(input: S) -> Result<Self, SecretKeyError>
Sourcepub fn generate() -> Result<Self, SecretKeyError>
pub fn generate() -> Result<Self, SecretKeyError>
Generate a fresh SecretKey using the operating system’s entropy.
§Errors
Returns SecretKeyError::Rng if the OS RNG fails, or
SecretKeyError::InvalidScalar in the cryptographically negligible
case where the random bytes happen to land on 0 or >= n.
Sourcepub fn to_byte_array(&self) -> [u8; 32]
pub fn to_byte_array(&self) -> [u8; 32]
Return the secret key as raw bytes.
Sourcepub const fn as_inner(&self) -> &SecretKey
pub const fn as_inner(&self) -> &SecretKey
Borrow the inner secp256k1::SecretKey.
Use this only at the boundary with the cryptography backend.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SecretKey
impl<'de> Deserialize<'de> for SecretKey
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for SecretKey
Source§impl FromBech32 for SecretKey
impl FromBech32 for SecretKey
Source§fn from_bech32(s: &str) -> Result<Self, FromBech32Error>
fn from_bech32(s: &str) -> Result<Self, FromBech32Error>
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 UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.