From 46a663e3df0aa24a82df4710bc359886fab2ee95 Mon Sep 17 00:00:00 2001 From: nickreynolds Date: Tue, 30 Nov 2021 16:22:28 -0500 Subject: [PATCH] Add bigint support --- src/getEthTypesFromInputDoc.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/getEthTypesFromInputDoc.ts b/src/getEthTypesFromInputDoc.ts index 0a579a4..52202f4 100644 --- a/src/getEthTypesFromInputDoc.ts +++ b/src/getEthTypesFromInputDoc.ts @@ -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 { - - const output = new Map(); const types = new Array(); 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 { @@ -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)!) }