Skip to main content

KeyPair

Struct KeyPair 

Source
pub struct KeyPair {
    pub public: PublicKey,
    pub secret: SecretSeed,
}
Expand description

Ed25519 keypair: seed plus the deterministically-derived public key.

Fields§

§public: PublicKey§secret: SecretSeed

Implementations§

Source§

impl KeyPair

Source

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).

Source

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 a Zeroizing-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 Zeroizing themselves, 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.

Source

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.

Source

pub fn sign(&self, domain: &[u8], signing_bytes: &[u8]) -> Signature

Sign signing_bytes under the given domain. The actual Ed25519 input is BLAKE3(len_le16(domain) || domain || signing_bytes) — see SPEC §2.2.

Trait Implementations§

Source§

impl Debug for KeyPair

Source§

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

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

impl Eq for KeyPair

Source§

impl PartialEq for KeyPair

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for KeyPair

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more