Struct schnorrkel::keys::MiniSecretKey

source ·
pub struct MiniSecretKey(/* private fields */);
Expand description

An EdDSA-like “secret” key seed.

These are seeds from which we produce a real SecretKey, which EdDSA itself calls an extended secret key by hashing. We require homomorphic properties unavailable from these seeds, so we renamed these and reserve SecretKey for what EdDSA calls an extended secret key.

Implementations§

source§

impl MiniSecretKey

source

pub const UNIFORM_MODE: ExpansionMode = ExpansionMode::Uniform

Avoids importing ExpansionMode

source

pub const ED25519_MODE: ExpansionMode = ExpansionMode::Ed25519

Avoids importing ExpansionMode

source

pub fn expand(&self, mode: ExpansionMode) -> SecretKey

Derive the SecretKey corresponding to this MiniSecretKey.

We caution that mode must always be chosen consistently. We slightly prefer ExpansionMode::Uniform here, but both remain secure under almost all situations. There exists deployed code using ExpansionMode::Ed25519, so you might require that for compatability.

use rand::{Rng, rngs::OsRng};
use schnorrkel::{MiniSecretKey, SecretKey, ExpansionMode};

let mini_secret_key: MiniSecretKey = MiniSecretKey::generate_with(OsRng);
let secret_key: SecretKey = mini_secret_key.expand(ExpansionMode::Uniform);
source

pub fn expand_to_keypair(&self, mode: ExpansionMode) -> Keypair

Derive the Keypair corresponding to this MiniSecretKey.

source

pub fn expand_to_public(&self, mode: ExpansionMode) -> PublicKey

Derive the PublicKey corresponding to this MiniSecretKey.

source

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

Convert this secret key to a byte array.

source

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

View this secret key as a byte array.

source

pub fn from_bytes(bytes: &[u8]) -> SignatureResult<MiniSecretKey>

Construct a MiniSecretKey from a slice of bytes.

§Example
use schnorrkel::{MiniSecretKey, MINI_SECRET_KEY_LENGTH};

let secret_key_bytes: [u8; MINI_SECRET_KEY_LENGTH] = [
   157, 097, 177, 157, 239, 253, 090, 096,
   186, 132, 074, 244, 146, 236, 044, 196,
   068, 073, 197, 105, 123, 050, 105, 025,
   112, 059, 172, 003, 028, 174, 127, 096, ];

let secret_key: MiniSecretKey = MiniSecretKey::from_bytes(&secret_key_bytes).unwrap();
§Returns

A Result whose okay value is an EdDSA MiniSecretKey or whose error value is an SignatureError wrapping the internal error that occurred.

source

pub fn generate_with<R>(csprng: R) -> MiniSecretKey
where R: CryptoRng + RngCore,

Generate a MiniSecretKey from a csprng.

§Example
use rand::{Rng, rngs::OsRng};
use schnorrkel::{PublicKey, MiniSecretKey, Signature};

let secret_key: MiniSecretKey = MiniSecretKey::generate_with(OsRng);
§Input

A CSPRNG with a fill_bytes() method, e.g. rand_chacha::ChaChaRng

source

pub fn generate() -> MiniSecretKey

Generate a MiniSecretKey from rand’s thread_rng.

§Example
use schnorrkel::{PublicKey, MiniSecretKey, Signature};

let secret_key: MiniSecretKey = MiniSecretKey::generate();

Afterwards, you can generate the corresponding public key.


let public_key: PublicKey = secret_key.expand_to_public(ExpansionMode::Ed25519);
source§

impl MiniSecretKey

source

pub fn hard_derive_mini_secret_key<B: AsRef<[u8]>>( &self, cc: Option<ChainCode>, i: B, mode: ExpansionMode, ) -> (MiniSecretKey, ChainCode)

Vaguely BIP32-like “hard” derivation of a MiniSecretKey from a SecretKey

We do not envision any “good reasons” why these “hard” derivations should ever be used after the soft Derivation trait. We similarly do not believe hard derivations make any sense for ChainCodes or ExtendedKeys types. Yet, some existing BIP32 workflows might do these things, due to BIP32’s de facto standardization and poor design. In consequence, we provide this method to do “hard” derivations in a way that should work with all BIP32 workflows and any permissible mutations of SecretKey. This means only that we hash the SecretKey’s scalar, but not its nonce because the secret key remains valid if the nonce is changed.

Trait Implementations§

source§

impl Clone for MiniSecretKey

source§

fn clone(&self) -> MiniSecretKey

Returns a copy 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 ConstantTimeEq for MiniSecretKey

source§

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal. Read more
source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
source§

impl Debug for MiniSecretKey

source§

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

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

impl PartialEq for MiniSecretKey

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Zeroize for MiniSecretKey

source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
source§

impl Eq for MiniSecretKey

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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