pub struct KeyPair {
pub public: PublicKey,
pub secret: SecretSeed,
}Expand description
Ed25519 keypair: seed plus the deterministically-derived public key.
Fields§
§public: PublicKey§secret: SecretSeedImplementations§
Source§impl KeyPair
impl KeyPair
Sourcepub fn generate() -> Result<Self, MkitError>
pub fn generate() -> Result<Self, MkitError>
Generate a fresh keypair using the system CSPRNG (getrandom).
§Zeroization
The local seed lives inside a Zeroizing wrapper that scrubs
the buffer at end of scope, so the only remaining copy is the
one inside the returned KeyPair (zeroized on drop via
SecretSeed’s ZeroizeOnDrop).
Sourcepub fn from_seed(seed: [u8; 32]) -> Self
pub fn from_seed(seed: [u8; 32]) -> Self
Reconstruct a keypair deterministically from a 32-byte seed. Pure function: same seed always yields the same public key.
This is a self-scrubbing convenience constructor: it zeroes
the seed argument it owns before returning (see the body), so
the moved-in buffer never lingers. It is kept as a public,
ergonomic entry point for callers that already hold a bare
[u8; 32] (e.g. test vectors, golden fixtures, and downstream /
WASM consumers that decode a seed from their own format).
§Zeroization
The contract this constructor guarantees: the [u8; 32] passed
by value into this function is scrubbed before return. What it
CANNOT do is reach back and scrub a Copy the caller left on
their own stack — [u8; 32]: Copy, so the argument is a moved
copy of whatever the caller held. Callers that keep sensitive
seed material on their own frame MUST therefore either:
- Prefer
KeyPair::from_seed_zeroizing, which takes aZeroizing-wrapped reference and never creates a Copy on the caller’s frame (this is what ALL internal mkit signing-path code uses —generate,load_key, the attest signer factory, and the WASM bindings), or - Wrap their seed in
Zeroizingthemselves, or seed.zeroize()the buffer after this call returns.
KeyPair::generate and load_key already use the
Zeroizing path internally; no production call site passes a
bare [u8; 32] here. The contract above is pinned by the
from_seed_scrubs_owned_param and
from_seed_zeroizing_matches_from_seed regression tests.
Sourcepub fn from_seed_zeroizing(seed: &Zeroizing<[u8; 32]>) -> Self
pub fn from_seed_zeroizing(seed: &Zeroizing<[u8; 32]>) -> Self
Reconstruct a keypair from a Zeroizing-wrapped 32-byte seed
without forcing the caller to keep a Copy of the raw bytes on
their own stack. This is the preferred constructor for
signing-path code that loads keys from disk (see load_key)
or generates them on the fly (see KeyPair::generate).
§Zeroization
Borrowing the seed means this function never creates a fresh
[u8; 32] Copy on the caller’s frame. The only memory copy
is the one owned by the returned KeyPair::secret field, which
zeroes on drop.
Trait Implementations§
impl Eq for KeyPair
impl StructuralPartialEq for KeyPair
Auto Trait Implementations§
impl Freeze for KeyPair
impl RefUnwindSafe for KeyPair
impl Send for KeyPair
impl Sync for KeyPair
impl Unpin for KeyPair
impl UnsafeUnpin for KeyPair
impl UnwindSafe for KeyPair
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
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§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more