diff --git a/package-lock.json b/package-lock.json index 2a089f6..73f847d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,8 +15,8 @@ "axios": "^1.6.2", "base64url": "^3.0.1", "buffer": "^6.0.3", - "eip-712": "^1.0.0", "ethers": "^5.7.0", + "ethers-eip712": "^0.2.0", "jwt-decode": "^4.0.0", "lodash": "^4.17.21" }, @@ -867,17 +867,6 @@ "@ethersproject/strings": "^5.7.0" } }, - "node_modules/@findeth/abi": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@findeth/abi/-/abi-0.3.1.tgz", - "integrity": "sha512-T9HUVEjEgM0MzVLY4gs52ffz5AlHeC3CSGFcEzL4ojKMVzMxa3na1GW/XCmunrhnWP2cDh4fE2MhqLxA0CHqTw==", - "dependencies": { - "keccak": "^3.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.14", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", @@ -991,17 +980,6 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, - "node_modules/@noble/hashes": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", - "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2442,19 +2420,6 @@ "node": ">=6.0.0" } }, - "node_modules/eip-712": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/eip-712/-/eip-712-1.0.0.tgz", - "integrity": "sha512-zVWGCUJQErhTpBH0mfYurP+t7wNdRizBq7PMAFj8M1Hq4/4QvKE7+FfXVcs7kL6b2ypbCnMgsimJQR1B2AfHpg==", - "dependencies": { - "@findeth/abi": "^0.3.0", - "@noble/hashes": "^1.0.0", - "superstruct": "^0.15.3" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/electron-to-chromium": { "version": "1.4.651", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.651.tgz", @@ -3209,6 +3174,14 @@ "@ethersproject/wordlists": "5.7.0" } }, + "node_modules/ethers-eip712": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/ethers-eip712/-/ethers-eip712-0.2.0.tgz", + "integrity": "sha512-fgS196gCIXeiLwhsWycJJuxI9nL/AoUPGSQ+yvd+8wdWR+43G+J1n69LmWVWvAON0M6qNaf2BF4/M159U8fujQ==", + "peerDependencies": { + "ethers": "^4.0.47 || ^5.0.8" + } + }, "node_modules/events": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", @@ -4369,20 +4342,6 @@ "node": ">=18" } }, - "node_modules/keccak": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.4.tgz", - "integrity": "sha512-3vKuW0jV8J3XNTzvfyicFR5qvxrSAGl7KIhvgOu5cmWwM7tZRj3fMbj/pfIf4be7aznbc+prBWGjywox/g2Y6Q==", - "hasInstallScript": true, - "dependencies": { - "node-addon-api": "^2.0.0", - "node-gyp-build": "^4.2.0", - "readable-stream": "^3.6.0" - }, - "engines": { - "node": ">=10.0.0" - } - }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -4735,21 +4694,6 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, - "node_modules/node-addon-api": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", - "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" - }, - "node_modules/node-gyp-build": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz", - "integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==", - "bin": { - "node-gyp-build": "bin.js", - "node-gyp-build-optional": "optional.js", - "node-gyp-build-test": "build-test.js" - } - }, "node_modules/node-releases": { "version": "2.0.14", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", @@ -5190,19 +5134,6 @@ "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", "dev": true }, - "node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -5396,6 +5327,7 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, "funding": [ { "type": "github", @@ -5611,14 +5543,6 @@ "node": ">=0.10.0" } }, - "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dependencies": { - "safe-buffer": "~5.2.0" - } - }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -5732,11 +5656,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/superstruct": { - "version": "0.15.5", - "resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.15.5.tgz", - "integrity": "sha512-4AOeU+P5UuE/4nOUkmcQdW5y7i9ndt1cQd/3iUe+LTz3RxESf/W/5lg4B74HbDMMv8PHnPnGCQFH45kBcrQYoQ==" - }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -6147,11 +6066,6 @@ "punycode": "^2.1.0" } }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" - }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/package.json b/package.json index daf0c54..b504761 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,12 @@ "name": "@klaytn/zkauth-sdk", "version": "0.1.0", "license": "MIT", - "description": "SDK for zkAuth", + "description": "SDK for zkAuth wallet", + "keywords": [ + "klaytn", + "zkAuth", + "zkAuth sdk" + ], "repository": { "type": "git", "url": "git+https://github.com/klaytn/zkauth-sdk" @@ -50,8 +55,8 @@ "axios": "^1.6.2", "base64url": "^3.0.1", "buffer": "^6.0.3", - "eip-712": "^1.0.0", "ethers": "^5.7.0", + "ethers-eip712": "^0.2.0", "jwt-decode": "^4.0.0", "lodash": "^4.17.21" }, diff --git a/src/authBuilder.ts b/src/authBuilder.ts index a92f0e6..a06abf1 100644 --- a/src/authBuilder.ts +++ b/src/authBuilder.ts @@ -1,7 +1,7 @@ import { Buffer } from "buffer"; -import { getStructHash, keccak256 } from "eip-712"; import { Contract, utils } from "ethers"; +import { TypedDataUtils } from "ethers-eip712"; import { jwtDecode } from "jwt-decode"; import { JwtWithNonce, calcSubHash } from "./jwt"; @@ -240,20 +240,6 @@ const fillInTypeData = (args: typeDataArgs) => { return typedData; }; -export const calcNonce = (args: typeDataArgs) => { - const typedData = fillInTypeData(args); - - const domainHash = getStructHash(typedData, "EIP712Domain", typedData.domain); - const message = getStructHash(typedData, typedData.primaryType, typedData.message); - - const nonce = utils.concat([Buffer.from("1901", "hex"), domainHash, message]); - const nonceA = keccak256(nonce); - - const nonceB = keccak256(Math.random().toString()); - - return utils.hexlify(utils.concat([nonceA, nonceB])); -}; - // @Note Crypto.subtle is only available in localhost or secure contexts (HTTPS). function getCrypto() { try { @@ -263,6 +249,17 @@ function getCrypto() { } } +export const calcNonce = (args: typeDataArgs) => { + const crypto = getCrypto(); + + const typedData = fillInTypeData(args); + + const nonceA = TypedDataUtils.encodeDigest(typedData); + const nonceB = utils.keccak256(crypto.getRandomValues(new Uint8Array(32))); + + return utils.hexlify(utils.concat([nonceA, nonceB])); +}; + export async function calcSalt(password: string, salt = "salt", iterations = 1e7) { const crypto = getCrypto(); const textEncoder = new TextEncoder(); diff --git a/tsconfig.json b/tsconfig.json index 7eba0cf..7d0db8e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,8 @@ "compilerOptions": { "target": "ES2020", "module": "nodenext", - "moduleResolution": "nodenext", "resolveJsonModule": true, - "isolatedModules": true, "declaration": true, "declarationMap": true, "sourceMap": true, diff --git a/webpack.config.js b/webpack.config.js index 7636af0..07e23f1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,19 +1,21 @@ -import { resolve as _resolve } from "path"; +const path = require("path"); -export const entry = "./src/index.ts"; -export const module = { - rules: [ - { - test: /\.ts$/, - use: "ts-loader", - exclude: /node_modules/, - }, - ], -}; -export const resolve = { - extensions: [".tsx", ".ts", ".js"], -}; -export const output = { - filename: "zkauth-sdk.bundle.js", - path: _resolve(__dirname, "dist"), +module.exports = { + entry: "./src/index.ts", + module: { + rules: [ + { + test: /\.ts$/, + use: "ts-loader", + exclude: /node_modules/, + }, + ], + }, + resolve: { + extensions: [".tsx", ".ts", ".js"], + }, + output: { + filename: "zkauth-sdk.bundle.js", + path: path.resolve(__dirname, "dist"), + }, };