Signature
Definition
This is uses a custom implemention of ecdsa signer using the Secp256k1
curve.
Zabi supports both normal signatures and compact ones.
const Signature = struct {
r: [Secp256k1.scalar.encoded_length]u8,
s: [Secp256k1.scalar.encoded_length]u8,
v: u2,
}
const CompactSignature = struct {
r: [Secp256k1.scalar.encoded_length]u8,
yParityWithS: [Secp256k1.scalar.encoded_length]u8,
}
Usage
These types have some methods that can be used to convert from one to the other and to convert to Bytes
or Hex
.
toCompact and fromCompact
Converts a Signature
to a CompactSignature
or vice versa.
signature.zig
const sig: CompactSignature = .{
.r = &[_]u8{0} ** 32,
.yParityWithS = &[_]u8{0} ** 32,
}
try Signature.fromCompact(sig);
// Result
// const sig: Signature = .{
// .r = &[_]u8{0} ** 32,
// .s = &[_]u8{0} ** 32,
// .v = 0
// }
toBytes
Converts a Signature
or CompactSignature
to a [65]u8
byte array.
signature.zig
const sig: Signature = .{
.r = &[_]u8{0} ** 32,
.s = &[_]u8{0} ** 32,
.v = 0
}
try sig.toBytes();
// Result
// [_]u8{0} ** 65
toHex
Converts a Signature
or CompactSignature
to a Hex
string.
signature.zig
const sig: Signature = .{
.r = &[_]u8{0} ** 32,
.s = &[_]u8{0} ** 32,
.v = 0
}
try sig.toHex();
// Result
// &[_]u8{0} ** 130