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
impl SecretKey
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Derive the matching PublicKey.
Sourcepub fn from_bytes(bytes: &[u8; 32]) -> Result<Self>
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.
Sourcepub fn is_valid_bytes(bytes: &[u8; 32]) -> bool
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.
Sourcepub fn is_valid_hex(s: &str) -> bool
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.
Sourcepub fn to_prefixed(&self) -> String
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.
Sourcepub fn from_prefixed(s: &str) -> Result<Self>
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.
Sourcepub fn is_valid_prefixed(s: &str) -> bool
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.