toCompact method
Renders the signature in compact form.
Returns a buffer containing the ECDSA signature in compact format allowing for public key recovery. See the fromCompact() constructor
Implementation
List<int> toCompact() {
if (![0,1,2,3].contains(_i)) {
throw SignatureException('i must be equal to 0, 1, 2, or 3');
}
var val = _i! + 27 + 4;
if (!_compressed) {
val = val - 4;
}
var b1 = [val];
//This is a hack around the problem of having r-values or s-values of length 31. This causes invalid sigs
//see: https://github.com/twostack/dartsv/issues/35
var b2Padded= sprintf("%064s", [_r!.toRadixString(16)]).replaceAll(' ', '0');
var b2 = HEX.decode(b2Padded);
var b3Padded= sprintf("%064s", [_s!.toRadixString(16)]).replaceAll(' ', '0');
var b3 = HEX.decode(b3Padded);
return b1 + b2 + b3;
}