Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c243cd1
feat: import tss key + recover Tss Key
ieow Sep 27, 2023
55650dd
feat: add tests
ieow Sep 28, 2023
80b1b38
Merge branch 'feat/recoverTssKey+importTssKey' into feat/add-tests
ieow Sep 29, 2023
92f037a
fix: add test for importTssKey
ieow Oct 2, 2023
e382afc
feat: update tkey package
ieow Oct 3, 2023
ae1466d
fix: cleanup
ieow Oct 3, 2023
bec85a9
fix: add resetaccount to tests
ieow Oct 3, 2023
34894c1
Merge branch 'alpha' into feat/recoverTssKey+importTssKey
ieow Oct 3, 2023
e7d7e20
Merge branch 'master' into feat/recoverTssKey+importTssKey
ieow Oct 4, 2023
ad12001
fix: add unsafe prefix
ieow Oct 4, 2023
bbc81bb
Merge branch 'alpha' into feat/recoverTssKey+importTssKey
ieow Oct 10, 2023
468fa21
fix: update mockLogin
ieow Oct 11, 2023
ffb7887
fix: token generation
ieow Oct 11, 2023
bde9f43
fix: jsonwebtoken package
ieow Oct 11, 2023
ce21110
feat: enable tests
ieow Oct 11, 2023
eb68747
fix: tests
ieow Oct 12, 2023
1e695ed
Merge branch 'master' into feat/enable-tests
ieow Oct 13, 2023
46bc250
Merge branch 'master' into feat/enable-tests
ieow Oct 13, 2023
da43d26
update: enable nodejs
ieow Oct 20, 2023
5561ccc
fix: revert to private for BrowserStorage
ieow Oct 20, 2023
9e47618
feat: enable signing nodejs
ieow Oct 24, 2023
8fba501
feat: make public sign and getPublic function
ieow Oct 24, 2023
766a99d
fix: add checking for nodejs with tssLib
ieow Oct 24, 2023
6d101c4
fix: enable back tests
ieow Oct 26, 2023
fd6e97a
fix: remove unused pacakges
ieow Oct 26, 2023
32208be
fix: add signing test
ieow Oct 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
479 changes: 460 additions & 19 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"homepage": "https://github.com/Web3Auth/mpc-core-kit/tree/master#readme",
"license": "ISC",
"scripts": {
"test": "echo no tests available",
"test": "node --test -r esbuild-register tests/*.spec.ts ",
"dev": "torus-scripts start",
"build": "torus-scripts build",
"release": "torus-scripts release",
Expand Down Expand Up @@ -68,12 +68,14 @@
"@types/elliptic": "^6.4.14",
"@types/node": "^20.6.3",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@toruslabs/tss-lib-node" : "^1.1.3",
"chai": "^4.3.8",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"esbuild-register": "^3.5.0",
"eslint": "^8.49.0",
"husky": "^8.0.3",
"jsonwebtoken": "^9.0.2",
"lint-staged": "^14.0.1",
"mocha": "^10.2.0",
"node-fetch": "^3.3.2",
Expand Down
37 changes: 31 additions & 6 deletions src/helper/browserStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ import { FIELD_ELEMENT_HEX_LEN } from "../constants";
import { ICoreKit, IStorage, TkeyLocalStoreData } from "../interfaces";
import { storageAvailable } from "../utils";

export type SupportedStorageType = "local" | "session" | "memory" | IStorage;

export class MemoryStorage implements IStorage {
private _store: Record<string, string> = {};

getItem(key: string): string | null {
return this._store[key] || null;
}

setItem(key: string, value: string): void {
this._store[key] = value;
}

removeItem(key: string): void {
delete this._store[key];
}

clear(): void {
this._store = {};
}
}

export class BrowserStorage {
// eslint-disable-next-line no-use-before-define
private static instance: BrowserStorage;
Expand All @@ -24,14 +46,17 @@ export class BrowserStorage {
}
}

static getInstance(key: string, storageKey: "session" | "local" = "local"): BrowserStorage {
static getInstance(key: string, storageKey: SupportedStorageType = "local"): BrowserStorage {
if (!this.instance) {
let storage: Storage | undefined;
let storage: IStorage | undefined;
if (storageKey === "local" && storageAvailable("localStorage")) {
storage = localStorage;
}
if (storageKey === "session" && storageAvailable("sessionStorage")) {
} else if (storageKey === "session" && storageAvailable("sessionStorage")) {
storage = sessionStorage;
} else if (storageKey === "memory") {
storage = new MemoryStorage();
} else if (typeof storageKey === "object") {
storage = storageKey;
}

if (!storage) {
Expand Down Expand Up @@ -76,7 +101,7 @@ export class BrowserStorage {
}
}

export async function storeWebBrowserFactor(factorKey: BN, mpcCoreKit: ICoreKit, storageKey: "local" | "session" = "local"): Promise<void> {
export async function storeWebBrowserFactor(factorKey: BN, mpcCoreKit: ICoreKit, storageKey: SupportedStorageType = "local"): Promise<void> {
const metadata = mpcCoreKit.tKey.getMetadata();
const currentStorage = BrowserStorage.getInstance("mpc_corekit_store", storageKey);

Expand All @@ -89,7 +114,7 @@ export async function storeWebBrowserFactor(factorKey: BN, mpcCoreKit: ICoreKit,
);
}

export async function getWebBrowserFactor(mpcCoreKit: ICoreKit, storageKey: "local" | "session" = "local"): Promise<string | undefined> {
export async function getWebBrowserFactor(mpcCoreKit: ICoreKit, storageKey: SupportedStorageType = "local"): Promise<string | undefined> {
const metadata = mpcCoreKit.tKey.getMetadata();
const currentStorage = BrowserStorage.getInstance("mpc_corekit_store", storageKey);

Expand Down
14 changes: 12 additions & 2 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { CustomChainConfig, SafeEventEmitterProvider } from "@web3auth/base";
import BN from "bn.js";

import { FactorKeyTypeShareDescription, TssShareType, USER_PATH, WEB3AUTH_NETWORK } from "./constants";

export type CoreKitMode = UX_MODE_TYPE | "nodejs";
export interface IStorage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
Expand Down Expand Up @@ -277,7 +279,7 @@ export interface Web3AuthOptions {
*
* @defaultValue `'local'`
*/
storageKey?: "session" | "local";
storageKey?: "session" | "local" | "memory" | IStorage;

/**
* @defaultValue 86400
Expand All @@ -287,7 +289,7 @@ export interface Web3AuthOptions {
/**
* @defaultValue `'POPUP'`
*/
uxMode?: UX_MODE_TYPE;
uxMode?: CoreKitMode;

/**
* @defaultValue `false`
Expand Down Expand Up @@ -338,6 +340,14 @@ export interface Web3AuthOptions {
* Recommended for Non Custodial Flow.
*/
disableHashedFactorKey?: boolean;

/**
* @defaultValue `null`
* Overwrite tss-lib for nodejs.
* Required for nodejs mode.
* Do not use this option for non nodejs mode.
*/
tssLib?: unknown;
}

export type Web3AuthOptionsWithDefaults = Required<Web3AuthOptions>;
Expand Down
Loading