ETHSignature.fromBytes constructor
Creates an Ethereum signature from a byte representation.
Throws a MessageException if the provided bytes are invalid.
Implementation
factory ETHSignature.fromBytes(List<int> bytes) {
if (bytes.length != ETHSignerConst.ethSignatureLength &&
bytes.length !=
ETHSignerConst.ethSignatureLength +
ETHSignerConst.ethSignatureRecoveryIdLength) {
throw MessageException("Invalid signature bytes",
details: {"input": BytesUtils.tryToHexString(bytes)});
}
final rBytes = bytes.sublist(0, ETHSignerConst.secp256.curve.baselen);
final sBytes = bytes.sublist(ETHSignerConst.secp256.curve.baselen,
ETHSignerConst.secp256.curve.baselen * 2);
int v;
if (bytes.length == ETHSignerConst.ethSignatureLength) {
v = (sBytes[0] & 0x80) != 0 ? 28 : 27;
sBytes[0] &= 0x7f;
} else {
v = ETHSignatureUtils.getSignatureV(
bytes[ETHSignerConst.ethSignatureLength]);
}
final r = BigintUtils.fromBytes(rBytes);
final s = BigintUtils.fromBytes(sBytes);
return ETHSignature(r, s, v);
}