Skip to content

Commit

Permalink
Allow null values for TypedData domain (#3623).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Mar 4, 2023
1 parent 287d94f commit a32af3a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src.ts/hash/typed-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const BN_1 = BigInt(1);
const BN_MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

export interface TypedDataDomain {
name?: string;
version?: string;
chainId?: BigNumberish;
verifyingContract?: string;
salt?: BytesLike;
name?: null | string;
version?: null | string;
chainId?: null | BigNumberish;
verifyingContract?: null | string;
salt?: null | BytesLike;
};

export interface TypedDataField {
Expand Down Expand Up @@ -355,6 +355,7 @@ export class TypedDataEncoder {
static hashDomain(domain: TypedDataDomain): string {
const domainFields: Array<TypedDataField> = [ ];
for (const name in domain) {
if ((<Record<string, any>>domain)[name] == null) { continue; }
const type = domainFieldTypes[name];
assertArgument(type, `invalid typed-data domain key: ${ JSON.stringify(name) }`, "domain", domain);
domainFields.push({ name, type });
Expand Down Expand Up @@ -384,6 +385,13 @@ export class TypedDataEncoder {
// Make a copy to isolate it from the object passed in
domain = Object.assign({ }, domain);

// Allow passing null to ignore value
for (const key in domain) {
if ((<Record<string, any>>domain)[key] == null) {
delete (<Record<string, any>>domain)[key];
}
}

// Look up all ENS names
const ensCache: Record<string, string> = { };

Expand Down

0 comments on commit a32af3a

Please sign in to comment.