Skip to content

Commit

Permalink
Fixed TypedData payloads for JSON-restricted chainId field (#3868).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 5, 2023
1 parent 130204d commit 50b74b8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src.ts/hash/typed-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAddress } from "../address/index.js";
import { keccak256 } from "../crypto/index.js";
import { recoverAddress } from "../transaction/index.js";
import {
concat, defineProperties, getBigInt, getBytes, hexlify, isHexString, mask, toBeHex, toTwos, zeroPadValue,
concat, defineProperties, getBigInt, getBytes, hexlify, isHexString, mask, toBeHex, toQuantity, toTwos, zeroPadValue,
assertArgument
} from "../utils/index.js";

Expand Down Expand Up @@ -68,8 +68,11 @@ function checkString(key: string): (value: any) => string {
const domainChecks: Record<string, (value: any) => any> = {
name: checkString("name"),
version: checkString("version"),
chainId: function(value: any) {
return getBigInt(value, "domain.chainId");
chainId: function(_value: any) {
const value = getBigInt(_value, "domain.chainId");
assertArgument(value >= 0, "invalid chain ID", "domain.chainId", _value);
if (Number.isSafeInteger(value)) { return Number(value); }
return toQuantity(value);
},
verifyingContract: function(value: any) {
try {
Expand Down

0 comments on commit 50b74b8

Please sign in to comment.