Skip to content

Commit a7e4048

Browse files
committedJul 16, 2023
More robust support for Signatures with less standard parameter values (#3835, #4228).
1 parent 330c318 commit a7e4048

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

Diff for: ‎src.ts/crypto/signature.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "../utils/index.js";
88

99
import type {
10-
BigNumberish, BytesLike
10+
BigNumberish, BytesLike, Numeric
1111
} from "../utils/index.js";
1212

1313

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

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

342342
if (yParity != null) {
343-
switch (yParity) {
343+
switch (getNumber(yParity, "sig.yParity")) {
344344
case 0: return { v: 27 };
345345
case 1: return { v: 28 };
346346
}
@@ -354,8 +354,8 @@ export class Signature {
354354
if (networkV) { result.#networkV = networkV; }
355355

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

360360
return result;
361361
}

0 commit comments

Comments
 (0)
Please sign in to comment.