Skip to content

Commit

Permalink
More robust support for Signatures with less standard parameter values (
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent 10bc1d9 commit b3562ce
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src.ts/crypto/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "../utils/index.js";

import type {
BigNumberish, BytesLike
BigNumberish, BytesLike, Numeric
} from "../utils/index.js";


Expand Down Expand Up @@ -325,7 +325,7 @@ export class Signature {
assertError((getBytes(s)[0] & 0x80) == 0, "non-canonical s");

// Get v; by any means necessary (we check consistency below)
const { networkV, v } = (function(_v?: BigNumberish, yParityAndS?: string, yParity?: number): { networkV?: bigint, v: 27 | 28 } {
const { networkV, v } = (function(_v?: BigNumberish, yParityAndS?: string, yParity?: Numeric): { networkV?: bigint, v: 27 | 28 } {
if (_v != null) {
const v = getBigInt(_v);
return {
Expand All @@ -340,7 +340,7 @@ export class Signature {
}

if (yParity != null) {
switch (yParity) {
switch (getNumber(yParity, "sig.yParity")) {
case 0: return { v: 27 };
case 1: return { v: 28 };
}
Expand All @@ -354,8 +354,8 @@ export class Signature {
if (networkV) { result.#networkV = networkV; }

// If multiple of v, yParity, yParityAndS we given, check they match
assertError(!("yParity" in sig && sig.yParity !== result.yParity), "yParity mismatch");
assertError(!("yParityAndS" in sig && sig.yParityAndS !== result.yParityAndS), "yParityAndS mismatch");
assertError(sig.yParity == null || getNumber(sig.yParity, "sig.yParity") === result.yParity, "yParity mismatch");
assertError(sig.yParityAndS == null || sig.yParityAndS === result.yParityAndS, "yParityAndS mismatch");

return result;
}
Expand Down

0 comments on commit b3562ce

Please sign in to comment.