Allow non-bytes32 values for r and s in Signature.

This commit is contained in:
Richard Moore 2022-12-30 16:32:17 -05:00
parent 2eb48231f1
commit a63f84cda7

@ -1,7 +1,7 @@
import { ZeroHash } from "../constants/index.js"; import { ZeroHash } from "../constants/index.js";
import { import {
concat, dataLength, getBigInt, getBytes, getNumber, hexlify, concat, dataLength, getBigInt, getBytes, getNumber, hexlify,
isHexString, toBeArray, isHexString, zeroPadValue,
assertArgument, assertPrivate assertArgument, assertPrivate
} from "../utils/index.js"; } from "../utils/index.js";
@ -42,6 +42,10 @@ export type SignatureLike = Signature | string | {
yParityAndS?: string; yParityAndS?: string;
}; };
function toUint256(value: BigNumberish): string {
return zeroPadValue(toBeArray(value), 32);
}
/** /**
* A Signature @TODO * A Signature @TODO
*/ */
@ -291,16 +295,13 @@ export class Signature {
if (sig instanceof Signature) { return sig.clone(); } if (sig instanceof Signature) { return sig.clone(); }
// Get r // Get r
const r = sig.r; const _r = sig.r;
assertError(r != null, "missing r"); assertError(_r != null, "missing r");
assertError(isHexString(r, 32), "invalid r"); const r = toUint256(_r);
// Get s; by any means necessary (we check consistency below) // Get s; by any means necessary (we check consistency below)
const s = (function(s?: string, yParityAndS?: string) { const s = (function(s?: string, yParityAndS?: string) {
if (s != null) { if (s != null) { return toUint256(s); }
assertError(isHexString(s, 32), "invalid s");
return s;
}
if (yParityAndS != null) { if (yParityAndS != null) {
assertError(isHexString(yParityAndS, 32), "invalid yParityAndS"); assertError(isHexString(yParityAndS, 32), "invalid yParityAndS");