Skip to main content

KeyPair

Trait KeyPair 

Source
pub trait KeyPair: Signer {
    // Required methods
    fn generate() -> Result<Self, <Self as Signer>::Error>
       where Self: Sized;
    fn from_bytes(private_key: &[u8]) -> Result<Self, <Self as Signer>::Error>
       where Self: Sized;
    fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>;

    // Provided methods
    fn from_keypair_bytes(
        keypair: &[u8],
    ) -> Result<Self, <Self as Signer>::Error>
       where Self: Sized { ... }
    fn keypair_bytes(&self) -> Zeroizing<Vec<u8>> { ... }
}
Expand description

A type that represents a cryptographic key pair capable of signing.

Required Methods§

Source

fn generate() -> Result<Self, <Self as Signer>::Error>
where Self: Sized,

Generate a new random key pair using OS entropy (CSPRNG).

Source

fn from_bytes(private_key: &[u8]) -> Result<Self, <Self as Signer>::Error>
where Self: Sized,

Reconstruct a key pair from raw private key bytes (32 bytes).

Source

fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>

Export the private key as auto-zeroizing bytes. The returned Zeroizing<Vec<u8>> will scrub the memory on drop.

Provided Methods§

Source

fn from_keypair_bytes(keypair: &[u8]) -> Result<Self, <Self as Signer>::Error>
where Self: Sized,

Reconstruct a key pair from a 64-byte expanded keypair (seed ∥ pubkey). Default impl uses only the first 32 bytes (seed).

Source

fn keypair_bytes(&self) -> Zeroizing<Vec<u8>>

Export the full keypair as private_key ∥ public_key. Default: 32B seed + compressed pubkey.

Implementors§