Skip to main content

SecretKey

Struct SecretKey 

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

A voter’s secret key.

Internally a Ristretto255 scalar; externally 32 bytes. Treat the encoded form with the same care as any other private key — it should never be transmitted off the voter’s device.

SecretKey is intentionally not Clone. Every copy of a secret scalar is one more memory region to keep track of and zeroise; if a caller really needs to duplicate one, they should re-decode it from the same byte representation and accept the duplication explicitly.

Implementations§

Source§

impl SecretKey

Source

pub fn public_key(&self) -> PublicKey

Derive the matching PublicKey.

Source

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

Encode the scalar as 32 little-endian bytes.

Source

pub fn from_bytes(bytes: &[u8; 32]) -> Result<Self>

Decode 32 bytes produced by SecretKey::to_bytes.

Returns Error::InvalidScalar if the bytes are not a canonical reduction modulo the group order.

Source

pub fn to_hex(&self) -> String

Hex-encode using lowercase digits (64 characters).

Source

pub fn from_hex(s: &str) -> Result<Self>

Decode from a 64-character hex string.

Source

pub fn is_valid_bytes(bytes: &[u8; 32]) -> bool

Check whether 32 raw bytes encode a usable secret key, without constructing one.

Applies the same checks as SecretKey::from_bytes: the bytes must be the canonical encoding of a scalar in [0, ℓ) and must not be the zero scalar.

Source

pub fn is_valid_hex(s: &str) -> bool

Check whether a hex string encodes a usable secret key, without constructing one.

Applies the same checks as SecretKey::from_hex: valid hex, exactly 32 decoded bytes, canonical non-zero scalar.

Source

pub fn to_prefixed(&self) -> String

Encode in the human-friendly prefixed format: sk_<hex>_<checksum>.

Same care applies as to SecretKey::to_hex: this is the full secret and must never leave the voter’s device.

Source

pub fn from_prefixed(s: &str) -> Result<Self>

Decode an sk_<hex>_<checksum> string produced by SecretKey::to_prefixed, verifying the tag and the checksum.

Source

pub fn is_valid_prefixed(s: &str) -> bool

Check whether a prefixed string encodes a usable secret key, without constructing one. Counterpart of SecretKey::is_valid_hex for the sk_<hex>_<checksum> format: the tag and checksum must be valid and the body must be a canonical non-zero scalar.

Trait Implementations§

Source§

impl Debug for SecretKey

Source§

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

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

impl Drop for SecretKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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