An ECDSA public key.
p: CurveLength (in bytes) of a compressed sec1-encoded key.
pub const compressed_sec1_encoded_length = 1 + Curve.Fe.encoded_lengthLength (in bytes) of a compressed sec1-encoded key.
pub const uncompressed_sec1_encoded_length = 1 + 2 * Curve.Fe.encoded_lengthpub fn fromSec1(sec1: []const u8) !PublicKeyCreate a public key from a SEC-1 representation.
sec1: []const u8pub fn toCompressedSec1(pk: PublicKey) [compressed_sec1_encoded_length]u8Encode the public key using the compressed SEC-1 format.
pk: PublicKeypub fn toCompressedSec1(pk: PublicKey) [compressed_sec1_encoded_length]u8 {
return pk.p.toCompressedSec1();
}pub fn toUncompressedSec1(pk: PublicKey) [uncompressed_sec1_encoded_length]u8Encoding the public key using the uncompressed SEC-1 format.
pk: PublicKeypub fn toUncompressedSec1(pk: PublicKey) [uncompressed_sec1_encoded_length]u8 {
return pk.p.toUncompressedSec1();
}pub const PublicKey = struct {
/// Length (in bytes) of a compressed sec1-encoded key.
pub const compressed_sec1_encoded_length = 1 + Curve.Fe.encoded_length;
/// Length (in bytes) of a compressed sec1-encoded key.
pub const uncompressed_sec1_encoded_length = 1 + 2 * Curve.Fe.encoded_length;
p: Curve,
/// Create a public key from a SEC-1 representation.
pub fn fromSec1(sec1: []const u8) !PublicKey {
return PublicKey{ .p = try Curve.fromSec1(sec1) };
}
/// Encode the public key using the compressed SEC-1 format.
pub fn toCompressedSec1(pk: PublicKey) [compressed_sec1_encoded_length]u8 {
return pk.p.toCompressedSec1();
}
/// Encoding the public key using the uncompressed SEC-1 format.
pub fn toUncompressedSec1(pk: PublicKey) [uncompressed_sec1_encoded_length]u8 {
return pk.p.toUncompressedSec1();
}
}