Add support for legacy flat signatures with recid instead of normalized v.

This commit is contained in:
Richard Moore 2020-01-11 04:10:57 -05:00
parent 72b3bc9909
commit 245cd0e48e
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
1 changed files with 9 additions and 0 deletions

View File

@ -343,6 +343,15 @@ export function splitSignature(signature: SignatureLike): Signature {
// Compute recoveryParam from v
result.recoveryParam = 1 - (result.v % 2);
// Allow a recid to be used as the v
if (result.v < 27) {
if (result.v === 0 || result.v === 1) {
result.v += 27;
} else {
logger.throwArgumentError("signature invalid v byte", "signature", signature);
}
}
// Compute _vs from recoveryParam and s
if (result.recoveryParam) { bytes[32] |= 0x80; }
result._vs = hexlify(bytes.slice(32, 64))