Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
99 changes: 80 additions & 19 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions 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 All @@ -32,7 +32,7 @@
],
"peerDependencies": {
"@babel/runtime": "^7.x",
"@toruslabs/metadata-helpers": "^4.x"
"@toruslabs/metadata-helpers": "^5.x"
},
"dependencies": {
"@tkey-mpc/chrome-storage": "^9.0.2",
Expand All @@ -50,8 +50,8 @@
"@toruslabs/metadata-helpers": "^5.x",
"@toruslabs/openlogin-session-manager": "^3.0.0",
"@toruslabs/torus.js": "^11.0.6",
"@toruslabs/tss-client": "^1.7.1",
"@toruslabs/tss-lib": "^1.7.1",
"@toruslabs/tss-client": "^2.0.0",
"@toruslabs/tss-lib": "^2.0.0",
"@web3auth-mpc/ethereum-provider": "^2.3.0",
"@web3auth/base": "^7.0.1",
"@web3auth/base-provider": "^7.0.1",
Expand All @@ -64,6 +64,7 @@
"@toruslabs/config": "^2.0.2",
"@toruslabs/eslint-config-typescript": "^3.0.1",
"@toruslabs/torus-scripts": "^5.0.5",
"@toruslabs/tss-lib-node": "^1.1.3",
"@types/chai": "^4.3.6",
"@types/elliptic": "^6.4.14",
"@types/node": "^20.6.3",
Expand Down
33 changes: 28 additions & 5 deletions src/helper/browserStorage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import BN from "bn.js";

import { FIELD_ELEMENT_HEX_LEN } from "../constants";
import { ICoreKit, IStorage, TkeyLocalStoreData } from "../interfaces";
import { ICoreKit, IStorage, SupportedStorageType, TkeyLocalStoreData } from "../interfaces";
import { storageAvailable } from "../utils";

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 +44,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
17 changes: 15 additions & 2 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ 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" | "react-native";

export interface IStorage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
}

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

export interface InitParams {
/**
* @defaultValue `true`
Expand Down Expand Up @@ -286,7 +291,7 @@ export interface Web3AuthOptions {
*
* @defaultValue `'local'`
*/
storageKey?: "session" | "local";
storageKey?: SupportedStorageType;

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

/**
* @defaultValue `false`
Expand Down Expand Up @@ -348,6 +353,14 @@ export interface Web3AuthOptions {
*/
disableHashedFactorKey?: boolean;

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

/**
* @defaultValue `Web3AuthOptions.web3AuthClientId`
* Overwrites the default value ( clientId ) used as nonce for hashing the hash factor key.
Expand Down
Loading