Skip to content

Commit

Permalink
Revert "enable variable session time for mpcCoreKit"
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow authored Apr 17, 2024
1 parent 99e0553 commit d99216a
Show file tree
Hide file tree
Showing 9 changed files with 2,111 additions and 3,580 deletions.
6 changes: 3 additions & 3 deletions demo/redirect-flow-example/package-lock.json

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

2 changes: 1 addition & 1 deletion demo/redirect-flow-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/node": "^16.18.48",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@web3auth/mpc-core-kit": "file:../..",
"@web3auth/mpc-core-kit": "file://../../",
"browserify-zlib": "^0.2.0",
"copy-webpack-plugin": "^11.0.0",
"html-webpack-plugin": "^5.5.3",
Expand Down
3 changes: 1 addition & 2 deletions demo/redirect-flow-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const coreKitInstance = new Web3AuthMPCCoreKit(
web3AuthNetwork: selectedNetwork,
uxMode: 'redirect',
manualSync: true,
setupProviderOnInit: false,
// sessionTime: 3600, // <== can provide variable session time based on user subscribed plan
setupProviderOnInit: false
}
);

Expand Down
5,526 changes: 2,076 additions & 3,450 deletions package-lock.json

Large diffs are not rendered by default.

50 changes: 24 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,66 +42,64 @@
"@tkey-mpc/share-serialization": "^9.1.0",
"@tkey-mpc/storage-layer-torus": "^9.1.0",
"@toruslabs/constants": "^13.0.1",
"@toruslabs/customauth": "^18.1.0",
"@toruslabs/customauth": "^16.0.6",
"@toruslabs/eccrypto": "4.0.0",
"@toruslabs/fetch-node-details": "^13.1.1",
"@toruslabs/fetch-node-details": "^13.0.1",
"@toruslabs/fnd-base": "^13.1.1",
"@toruslabs/metadata-helpers": "^5.x",
"@toruslabs/openlogin-session-manager": "^3.0.0",
"@toruslabs/openlogin-utils": "^8.0.0",
"@toruslabs/torus.js": "12.2.0",
"@toruslabs/torus.js": "^12.1.0",
"@toruslabs/tss-client": "^2.1.0",
"@toruslabs/tss-lib": "^2.0.0",
"@web3auth-mpc/ethereum-provider": "^3.1.0",
"@web3auth/base": "^7.3.1",
"@web3auth/base-provider": "^7.3.1",
"@web3auth-mpc/ethereum-provider": "^2.3.0",
"@web3auth/base": "^7.0.1",
"@web3auth/base-provider": "^7.0.1",
"bn.js": "^5.2.1",
"bowser": "^2.11.0",
"elliptic": "^6.5.4"
},
"devDependencies": {
"@babel/register": "^7.23.7",
"@babel/register": "^7.22.15",
"@toruslabs/config": "^2.0.2",
"@toruslabs/eslint-config-typescript": "^3.1.0",
"@toruslabs/torus-scripts": "^5.2.0",
"@toruslabs/eslint-config-typescript": "^3.0.1",
"@toruslabs/torus-scripts": "^5.0.5",
"@toruslabs/tss-lib-node": "^1.1.3",
"@types/chai": "^4.3.11",
"@types/elliptic": "^6.4.18",
"@types/chai": "^4.3.6",
"@types/elliptic": "^6.4.14",
"@types/jsonwebtoken": "^9.0.5",
"@types/node": "^20.11.16",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"chai": "^5.0.3",
"@types/node": "^20.6.3",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"chai": "^4.3.8",
"cross-env": "^7.0.3",
"dotenv": "^16.4.1",
"dotenv": "^16.3.1",
"esbuild-register": "^3.5.0",
"eslint": "^8.56.0",
"husky": "^9.0.10",
"eslint": "^8.49.0",
"husky": "^8.0.3",
"jsonwebtoken": "^9.0.2",
"lint-staged": "^15.2.1",
"lint-staged": "^14.0.1",
"mocha": "^10.2.0",
"node-fetch": "^3.3.2",
"prettier": "^3.2.4",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"prettier": "^3.0.3",
"rimraf": "^5.0.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
"typescript": "^5.2.2"
},
"engines": {
"node": ">=20.x"
},
"overrides": {
"@toruslabs/customauth": "^18.1.0",
"@tkey-mpc/storage-layer-torus": {
"@toruslabs/http-helpers": "^6.0.0"
},
"@toruslabs/base-session-manager": {
"@toruslabs/http-helpers": "^6.0.0"
},
"@tkey-mpc/service-provider-torus": {
"@toruslabs/torus.js": "^12.2.0",
"@toruslabs/customauth": "^18.1.0"
"@toruslabs/customauth": {
"@toruslabs/http-helpers": "^6.0.0"
}
},
"lint-staged": {
Expand Down
2 changes: 0 additions & 2 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,6 @@ export interface Web3AuthOptions {
* Setup Provider after `login success` reconstruct.
*/
setupProviderOnInit?: boolean;

serverTimeOffset?: number;
}

export type Web3AuthOptionsWithDefaults = Required<Web3AuthOptions>;
Expand Down
13 changes: 5 additions & 8 deletions src/mpcCoreKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
if (typeof options.manualSync !== "boolean") options.manualSync = false;
if (!options.web3AuthNetwork) options.web3AuthNetwork = WEB3AUTH_NETWORK.MAINNET;
if (!options.sessionTime) options.sessionTime = 86400;
if (!options.serverTimeOffset) options.serverTimeOffset = 0;
if (!options.uxMode) options.uxMode = UX_MODE.REDIRECT;
if (!options.redirectPathName) options.redirectPathName = "redirect";
if (!options.baseUrl) options.baseUrl = isNodejsOrRN ? "https://localhost" : `${window?.location.origin}/serviceworker`;
Expand Down Expand Up @@ -263,7 +262,6 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
network: this.options.web3AuthNetwork,
redirectPathName: this.options.redirectPathName,
locationReplaceOnRedirect: true,
serverTimeOffset: this.options.serverTimeOffset,
},
nodeEndpoints: nodeDetails.torusNodeEndpoints,
nodePubKeys: nodeDetails.torusNodePub.map((i) => ({ x: i.X, y: i.Y })),
Expand Down Expand Up @@ -306,7 +304,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
} else if (params.rehydrate && this.sessionManager.sessionId) {
// swallowed, should not throw on rehydrate timed out session
const sessionResult = await this.sessionManager.authorizeSession().catch(async (err) => {
log.error("rehydrate session error", err);
log.info("rehydrate session error", err);
});

// try rehydrate session
Expand All @@ -315,12 +313,10 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
} else {
// feature gating on no session rehydration
await this.featureRequest();
TorusUtils.setSessionTime(this.options.sessionTime);
}
} else {
// feature gating if not redirect flow or session rehydration
await this.featureRequest();
TorusUtils.setSessionTime(this.options.sessionTime);
}

// if not redirect flow or session rehydration, ask for factor key to login
Expand Down Expand Up @@ -716,7 +712,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
throw new Error(`sessionAuth does not exist ${currentSession}`);
}

const signatures = await this.getSigningSignatures();
const signatures = await this.getSigningSignatures(msgHash.toString("hex"));
if (!signatures) {
throw new Error(`Signature does not exist ${signatures}`);
}
Expand Down Expand Up @@ -1036,6 +1032,7 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
if (!factorKeyMetadata || factorKeyMetadata.message === "KEY_NOT_FOUND" || factorKeyMetadata.message === "SHARE_DELETED") {
return false;
}
log.info("factorKeyMetadata", factorKeyMetadata);
return true;
}

Expand Down Expand Up @@ -1195,8 +1192,9 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
return sessionData.map((session) => JSON.stringify({ data: session.token, sig: session.signature }));
}

private async getSigningSignatures(): Promise<string[]> {
private async getSigningSignatures(data: string): Promise<string[]> {
if (!this.signatures) throw new Error("signatures not present");
log.info("data", data);
return this.signatures;
}

Expand All @@ -1213,7 +1211,6 @@ export class Web3AuthMPCCoreKit implements ICoreKit {
client_id: this.options.web3AuthClientId,
is_mpc_core_kit: "true",
enable_gating: "true",
session_time: this.options.sessionTime.toString(),
};
const url = new URL(`${accessUrl}/api/feature-access`);
url.search = new URLSearchParams(accessRequest).toString();
Expand Down
2 changes: 1 addition & 1 deletion tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type TestVariable = {
email: string;
};

const defaultTestEmail = "testEmailForLogin";
const defaultTestEmail = "testEmail1";
const variable: TestVariable[] = [
{ web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET, uxMode: "nodejs", email: defaultTestEmail },
// { web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET, uxMode: UX_MODE.REDIRECT, email: defaultTestEmail },
Expand Down
87 changes: 0 additions & 87 deletions tests/sessionTime.spec.ts

This file was deleted.

0 comments on commit d99216a

Please sign in to comment.