Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Fix compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonLewis committed Feb 28, 2024
1 parent 4c59a71 commit 86bac9e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 132 deletions.
106 changes: 10 additions & 96 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
},
Expand Down
27 changes: 12 additions & 15 deletions src/authBuilder.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"compilerOptions": {
"target": "ES2020",
"module": "nodenext",

"moduleResolution": "nodenext",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
Expand Down
36 changes: 19 additions & 17 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -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"),
},
};

0 comments on commit 86bac9e

Please sign in to comment.