Skip to content

Commit

Permalink
Add bigint support
Browse files Browse the repository at this point in the history
  • Loading branch information
nickreynolds committed Nov 30, 2021
1 parent e595dc3 commit 46a663e
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/getEthTypesFromInputDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,30 @@ export function getEthTypesFromInputDoc(input: object, primaryType: string = "Do
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
],
...obj};
...obj
};
return obj;
}

// Given an Input Document, generate Types according to type generation algorithm specified in EIP-712 spec:
// https://w3c-ccg.github.io/ethereum-eip712-signature-2021-spec/#ref-for-dfn-types-generation-algorithm-2
function getEthTypesFromInputDocHelper(input: object, primaryType: string): Map<string, TypedDataField[]> {


const output = new Map<string, TypedDataField[]>();
const types = new Array<TypedDataField>();

let canonicalizedInput = JSON.parse(canonicalize(input));

for (const property in canonicalizedInput) {
// console.log("property: ", property);
const val = canonicalizedInput[property];
const type = typeof val;
// console.log("typeof canonicalizedInput[property]: ", type);
if (type === "boolean") {
types.push({ name: property, type: "bool" })
} else if (type === "number") {
} else if (type === "number" || type === "bigint") {
types.push({ name: property, type: "uint256" })
} else if (type === "string") {
types.push({ name: property, type: "string" })
} else if (type === "object") {
if (Array.isArray(val)) {
console.log("is Array.");
if (val.length === 0) {
throw new Error("Array with length 0 found")
} else {
Expand All @@ -67,14 +63,12 @@ function getEthTypesFromInputDocHelper(input: object, primaryType: string): Map<
}
}
} else {
console.log("is Not Array.");
const recursiveOutput = getEthTypesFromInputDocHelper(val, primaryType);
const recursiveTypes = recursiveOutput.get(primaryType);
const propertyType = property.charAt(0).toUpperCase() + property.substring(1);
types.push({ name: property, type: propertyType });
output.set(propertyType, recursiveTypes!);
for (const key in recursiveOutput) {
console.log("recursiveOutput key: ", key);
if (key !== primaryType) {
output.set(key, recursiveOutput.get(key)!)
}
Expand Down

0 comments on commit 46a663e

Please sign in to comment.