PrivateKey

Struct PrivateKey 

Source
pub struct PrivateKey { /* private fields */ }
Expand description

An Ed25519 secret key

Implementations§

Source§

impl PrivateKey

Source

pub const BYTES: usize = 32usize

The length in bytes of the raw private key

Source

pub fn generate() -> Self

Create a new random secret Ed25519 key

Source

pub fn generate_using_rng<R: CryptoRng + Rng>(rng: &mut R) -> Self

Create a new random secret Ed25519 key using specified RNG

Source

pub fn generate_from_seed(seed: &[u8]) -> Self

Generate a key using an input seed

§Warning

For security the seed should be at least 256 bits and randomly generated

Source

pub fn sign_message(&self, msg: &[u8]) -> [u8; 64]

Sign a message and return a signature

This is the non-prehashed variant of Ed25519

Source

pub fn public_key(&self) -> PublicKey

Return the public key associated with this secret key

Source

pub fn serialize_raw(&self) -> [u8; 32]

Serialize the Ed25519 secret key

This returns the 32-byte encoding of the seed value which is used to derive the secret scalar

Source

pub fn deserialize_raw(bytes: &[u8]) -> Result<Self, PrivateKeyDecodingError>

Deserialize an Ed25519 private key from raw format

This is just the plain 32 byte random seed from which the internal key material is derived

This corresponds with the format used by PrivateKey::serialize_raw

Source

pub fn deserialize_raw_32(bytes: &[u8; 32]) -> Self

Deserialize an Ed25519 private key from raw format

This is just the plain 32 byte random seed from which the internal key material is derived

This corresponds with the format used by PrivateKey::serialize_raw

Source

pub fn serialize_pkcs8(&self, format: PrivateKeyFormat) -> Vec<u8>

Serialize the Ed25519 secret key in PKCS8 format

The details of the formatting are specified using the argument

Source

pub fn deserialize_pkcs8(bytes: &[u8]) -> Result<Self, PrivateKeyDecodingError>

Deserialize an Ed25519 private key from PKCS8 format

Both v1 and v2 PKCS8 encodings are accepted. The only difference is that v2 includes the public key as well. This also accepts the buggy format used by ring 0.16.

This corresponds with the format used by PrivateKey::serialize_pkcs8

Source

pub fn serialize_pkcs8_pem(&self, format: PrivateKeyFormat) -> String

Serialize the Ed25519 secret key in PKCS8 v2 format with PEM encoding

The details of the formatting are specified using the argument

Source

pub fn deserialize_pkcs8_pem(pem: &str) -> Result<Self, PrivateKeyDecodingError>

Deserialize an Ed25519 private key from PKCS8 PEM format

Both v1 and v2 PKCS8 encodings are accepted

This corresponds with the format used by PrivateKey::serialize_pkcs8_pem

Source

pub fn derive_subkey( &self, derivation_path: &DerivationPath, ) -> (DerivedPrivateKey, [u8; 32])

Derive a private key from this private key using a derivation path

This is the same derivation system used by the Internet Computer when deriving subkeys for threshold Ed25519

Note that this function returns a DerivedPrivateKey rather than Self, and that DerivedPrivateKey can sign messages but cannot be serialized. This is due to the definition of Ed25519 private keys, which is incompatible with additive derivation.

Source

pub fn derive_subkey_with_chain_code( &self, derivation_path: &DerivationPath, chain_code: &[u8; 32], ) -> (DerivedPrivateKey, [u8; 32])

Derive a private key from this private key using a derivation path and chain code

This is the same derivation system used by the Internet Computer when deriving subkeys for threshold Ed25519

Note that this function returns a DerivedPrivateKey rather than Self, and that DerivedPrivateKey can sign messages but cannot be serialized. This is due to the definition of Ed25519 private keys, which is incompatible with additive derivation.

Trait Implementations§

Source§

impl Clone for PrivateKey

Source§

fn clone(&self) -> PrivateKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PrivateKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for PrivateKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl PartialEq for PrivateKey

Source§

fn eq(&self, other: &PrivateKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for PrivateKey

Source§

impl StructuralPartialEq for PrivateKey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V