struct SecretKey [src]
An Ed25519 secret key.
Fields
bytes: [encoded_length]u8
Members
- encoded_length (Constant)
- fromBytes (Function)
- publicKeyBytes (Function)
- seed (Function)
- toBytes (Function)
Source
pub const SecretKey = struct {
/// Length (in bytes) of a raw secret key.
pub const encoded_length = 64;
bytes: [encoded_length]u8,
/// Return the seed used to generate this secret key.
pub fn seed(self: SecretKey) [KeyPair.seed_length]u8 {
return self.bytes[0..KeyPair.seed_length].*;
}
/// Return the raw public key bytes corresponding to this secret key.
pub fn publicKeyBytes(self: SecretKey) [PublicKey.encoded_length]u8 {
return self.bytes[KeyPair.seed_length..].*;
}
/// Create a secret key from raw bytes.
pub fn fromBytes(bytes: [encoded_length]u8) !SecretKey {
return SecretKey{ .bytes = bytes };
}
/// Return the secret key as raw bytes.
pub fn toBytes(sk: SecretKey) [encoded_length]u8 {
return sk.bytes;
}
// Return the clamped secret scalar and prefix for this secret key
fn scalarAndPrefix(self: SecretKey) struct { scalar: CompressedScalar, prefix: [32]u8 } {
var az: [Sha512.digest_length]u8 = undefined;
var h = Sha512.init(.{});
h.update(&self.seed());
h.final(&az);
var s = az[0..32].*;
Curve.scalar.clamp(&s);
return .{ .scalar = s, .prefix = az[32..].* };
}
}