Struct schnorrkel::keys::MiniSecretKey
source · [−]pub struct MiniSecretKey(_);
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
sourceimpl MiniSecretKey
impl MiniSecretKey
sourcepub const UNIFORM_MODE: ExpansionMode
pub const UNIFORM_MODE: ExpansionMode
Avoids importing ExpansionMode
sourcepub const ED25519_MODE: ExpansionMode
pub const ED25519_MODE: ExpansionMode
Avoids importing ExpansionMode
sourcepub fn expand(&self, mode: ExpansionMode) -> SecretKey
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);
sourcepub fn expand_to_keypair(&self, mode: ExpansionMode) -> Keypair
pub fn expand_to_keypair(&self, mode: ExpansionMode) -> Keypair
Derive the Keypair
corresponding to this MiniSecretKey
.
sourcepub fn expand_to_public(&self, mode: ExpansionMode) -> PublicKey
pub fn expand_to_public(&self, mode: ExpansionMode) -> PublicKey
Derive the PublicKey
corresponding to this MiniSecretKey
.
sourcepub fn from_bytes(bytes: &[u8]) -> SignatureResult<MiniSecretKey>
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.
sourcepub fn generate_with<R>(csprng: R) -> MiniSecretKey where
R: CryptoRng + RngCore,
pub fn generate_with<R>(csprng: R) -> MiniSecretKey where
R: CryptoRng + RngCore,
sourcepub fn generate() -> MiniSecretKey
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);
sourceimpl MiniSecretKey
impl MiniSecretKey
sourcepub fn hard_derive_mini_secret_key<B: AsRef<[u8]>>(
&self,
cc: Option<ChainCode>,
i: B,
mode: ExpansionMode
) -> (MiniSecretKey, ChainCode)
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 ChainCode
s or ExtendedKey
s types.
Yet, some existing BIP32 workflows might do these things,
due to BIP32’s de facto stnadardization 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 becuase
the secret key remains valid if the nonce is changed.
Trait Implementations
sourceimpl Clone for MiniSecretKey
impl Clone for MiniSecretKey
sourcefn clone(&self) -> MiniSecretKey
fn clone(&self) -> MiniSecretKey
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl ConstantTimeEq for MiniSecretKey
impl ConstantTimeEq for MiniSecretKey
sourceimpl Debug for MiniSecretKey
impl Debug for MiniSecretKey
sourceimpl<'d> Deserialize<'d> for MiniSecretKey
impl<'d> Deserialize<'d> for MiniSecretKey
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'d>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'d>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Drop for MiniSecretKey
impl Drop for MiniSecretKey
sourceimpl PartialEq<MiniSecretKey> for MiniSecretKey
impl PartialEq<MiniSecretKey> for MiniSecretKey
sourceimpl Serialize for MiniSecretKey
impl Serialize for MiniSecretKey
sourceimpl Zeroize for MiniSecretKey
impl Zeroize for MiniSecretKey
impl Eq for MiniSecretKey
Auto Trait Implementations
impl RefUnwindSafe for MiniSecretKey
impl Send for MiniSecretKey
impl Sync for MiniSecretKey
impl Unpin for MiniSecretKey
impl UnwindSafe for MiniSecretKey
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more