From ac02476ec758d25d857ec30156d4f34b42c469ae Mon Sep 17 00:00:00 2001 From: Archit Date: Thu, 3 Oct 2024 10:08:41 +0530 Subject: [PATCH 1/3] Removes fnd call --- examples/vue-app/package-lock.json | 19 +++++++++--------- package-lock.json | 21 ++------------------ package.json | 2 +- src/login.ts | 31 ++++++++---------------------- 4 files changed, 21 insertions(+), 52 deletions(-) diff --git a/examples/vue-app/package-lock.json b/examples/vue-app/package-lock.json index 6843026..eb5b28b 100644 --- a/examples/vue-app/package-lock.json +++ b/examples/vue-app/package-lock.json @@ -43,7 +43,7 @@ }, "../..": { "name": "@toruslabs/customauth", - "version": "20.1.1", + "version": "20.2.3", "license": "MIT", "dependencies": { "@chaitanyapotti/register-service-worker": "^1.7.4", @@ -51,28 +51,29 @@ "@toruslabs/constants": "^14.0.0", "@toruslabs/eccrypto": "^5.0.4", "@toruslabs/fetch-node-details": "^14.0.1", + "@toruslabs/fnd-base": "^14.0.0", "@toruslabs/http-helpers": "^7.0.0", "@toruslabs/metadata-helpers": "^6.0.0", - "@toruslabs/session-manager": "^2.0.0", - "@toruslabs/torus.js": "^15.0.2", + "@toruslabs/session-manager": "^3.1.0", + "@toruslabs/torus.js": "^15.0.4", "base64url": "^3.0.1", "bowser": "^2.11.0", "deepmerge": "^4.3.1", "eventemitter3": "^5.0.1", - "loglevel": "^1.9.1" + "loglevel": "^1.9.2" }, "devDependencies": { - "@sentry/types": "^8.23.0", + "@sentry/types": "^8.31.0", "@toruslabs/config": "^2.2.0", "@toruslabs/eslint-config-typescript": "^3.3.3", - "@toruslabs/torus-scripts": "^6.1.1", + "@toruslabs/torus-scripts": "^6.1.2", "eslint": "^8.57.0", - "husky": "^9.1.4", - "lint-staged": "^15.2.8", + "husky": "^9.1.6", + "lint-staged": "^15.2.10", "prettier": "^3.3.3", "rimraf": "^6.0.1", "typed-emitter": "^2.1.0", - "typescript": "^5.5.4" + "typescript": "^5.6.2" }, "engines": { "node": ">=18.x", diff --git a/package-lock.json b/package-lock.json index ce1e0a6..dd1d7f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@toruslabs/broadcast-channel": "^11.0.0", "@toruslabs/constants": "^14.0.0", "@toruslabs/eccrypto": "^5.0.4", - "@toruslabs/fetch-node-details": "^14.0.1", + "@toruslabs/fnd-base": "^14.0.0", "@toruslabs/http-helpers": "^7.0.0", "@toruslabs/metadata-helpers": "^6.0.0", "@toruslabs/session-manager": "^3.1.0", @@ -3258,28 +3258,11 @@ "typescript": "^5.x" } }, - "node_modules/@toruslabs/fetch-node-details": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/@toruslabs/fetch-node-details/-/fetch-node-details-14.0.1.tgz", - "integrity": "sha512-cV/X8d97W9kU/ibycV/4rfkDSjl+MIgwbKhsVqvgDtoE1mdjMSeCxJTfEDgjxqzUcVlHjcbeUpzCe8qa/Gvs6A==", - "dependencies": { - "@toruslabs/constants": "^14.0.0", - "@toruslabs/fnd-base": "^14.0.0", - "@toruslabs/http-helpers": "^7.0.0", - "loglevel": "^1.9.1" - }, - "engines": { - "node": ">=18.x", - "npm": ">=9.x" - }, - "peerDependencies": { - "@babel/runtime": "7.x" - } - }, "node_modules/@toruslabs/fnd-base": { "version": "14.0.0", "resolved": "https://registry.npmjs.org/@toruslabs/fnd-base/-/fnd-base-14.0.0.tgz", "integrity": "sha512-zaYrm/HHHU4Evj/Et1HrVT8hmMaUpVw3Rcx2Gvp1W5pWZybbdEVoa0uqIANYxcr/NH7PUIU3DoRbk+bXx0kkYg==", + "license": "MIT", "dependencies": { "@toruslabs/constants": "^14.0.0" }, diff --git a/package.json b/package.json index ed7ff0f..0175bd5 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@toruslabs/broadcast-channel": "^11.0.0", "@toruslabs/constants": "^14.0.0", "@toruslabs/eccrypto": "^5.0.4", - "@toruslabs/fetch-node-details": "^14.0.1", + "@toruslabs/fnd-base": "^14.0.0", "@toruslabs/http-helpers": "^7.0.0", "@toruslabs/metadata-helpers": "^6.0.0", "@toruslabs/session-manager": "^3.1.0", diff --git a/src/login.ts b/src/login.ts index 8806947..199a900 100644 --- a/src/login.ts +++ b/src/login.ts @@ -1,6 +1,6 @@ import { TORUS_NETWORK_TYPE } from "@toruslabs/constants"; -import { NodeDetailManager } from "@toruslabs/fetch-node-details"; -import { keccak256, Torus, TorusKey } from "@toruslabs/torus.js"; +import { fetchLocalConfig } from "@toruslabs/fnd-base"; +import { keccak256, type KeyType, Torus, TorusKey } from "@toruslabs/torus.js"; import createHandler from "./handlers/HandlerFactory"; import { @@ -41,12 +41,11 @@ class CustomAuth { useDkg?: boolean; web3AuthClientId: string; web3AuthNetwork: TORUS_NETWORK_TYPE; + keyType: KeyType; }; torus: Torus; - nodeDetailManager: NodeDetailManager; - storageHelper: StorageHelper; sentryHandler: SentryHandler; @@ -86,6 +85,7 @@ class CustomAuth { useDkg, web3AuthClientId, web3AuthNetwork: network, + keyType, }; const torus = new Torus({ network, @@ -97,7 +97,6 @@ class CustomAuth { }); Torus.setAPIKey(apiKey); this.torus = torus; - this.nodeDetailManager = new NodeDetailManager({ network }); if (enableLogging) log.enableAll(); else log.disableAll(); this.storageHelper = new StorageHelper(storageServerUrl); @@ -177,7 +176,6 @@ class CustomAuth { const torusKey = await this.getTorusKey( verifier, - userInfo.verifierId, { verifier_id: userInfo.verifierId }, loginParams.idToken || loginParams.accessToken, userInfo.extraVerifierParams @@ -262,28 +260,15 @@ class CustomAuth { aggregateIdTokenSeeds.sort(); const aggregateIdToken = keccak256(Buffer.from(aggregateIdTokenSeeds.join(String.fromCharCode(29)), "utf8")).slice(2); aggregateVerifierParams.verifier_id = aggregateVerifierId; - const torusKey = await this.getTorusKey(verifierIdentifier, aggregateVerifierId, aggregateVerifierParams, aggregateIdToken, extraVerifierParams); + const torusKey = await this.getTorusKey(verifierIdentifier, aggregateVerifierParams, aggregateIdToken, extraVerifierParams); return { ...torusKey, userInfo: userInfoArray.map((x, index) => ({ ...x, ...loginParamsArray[index] })), }; } - async getTorusKey( - verifier: string, - verifierId: string, - verifierParams: { verifier_id: string }, - idToken: string, - additionalParams?: ExtraParams - ): Promise { - const nodeDetails = await this.sentryHandler.startSpan( - { - name: SENTRY_TXNS.FETCH_NODE_DETAILS, - }, - async () => { - return this.nodeDetailManager.getNodeDetails({ verifier, verifierId }); - } - ); + async getTorusKey(verifier: string, verifierParams: { verifier_id: string }, idToken: string, additionalParams?: ExtraParams): Promise { + const nodeDetails = fetchLocalConfig(this.config.web3AuthNetwork, this.config.keyType); log.debug("torus-direct/getTorusKey", { torusNodeEndpoints: nodeDetails.torusNodeEndpoints }); @@ -329,7 +314,7 @@ class CustomAuth { aggregateIdTokenSeeds.sort(); const aggregateIdToken = keccak256(Buffer.from(aggregateIdTokenSeeds.join(String.fromCharCode(29)), "utf8")).slice(2); aggregateVerifierParams.verifier_id = verifierId; - return this.getTorusKey(verifier, verifierId, aggregateVerifierParams, aggregateIdToken, extraVerifierParams); + return this.getTorusKey(verifier, aggregateVerifierParams, aggregateIdToken, extraVerifierParams); } async getRedirectResult({ replaceUrl = true, clearLoginDetails = true }: RedirectResultParams = {}): Promise { From 32b25c6e168652c3fb52e37f2d52f54dbedde1cc Mon Sep 17 00:00:00 2001 From: Archit Date: Thu, 3 Oct 2024 12:29:57 +0530 Subject: [PATCH 2/3] allow passing of node details as a param in the constructor --- examples/vue-app/package-lock.json | 18 ++++++++++++++- examples/vue-app/package.json | 1 + examples/vue-app/src/App.vue | 13 ++++++++--- package-lock.json | 21 +++++++++++++++++- package.json | 2 +- src/handlers/interfaces.ts | 4 +++- src/login.ts | 35 +++++++++++++++++++++++++----- 7 files changed, 81 insertions(+), 13 deletions(-) diff --git a/examples/vue-app/package-lock.json b/examples/vue-app/package-lock.json index eb5b28b..70ccf52 100644 --- a/examples/vue-app/package-lock.json +++ b/examples/vue-app/package-lock.json @@ -11,6 +11,7 @@ "@toruslabs/broadcast-channel": "10.0.1", "@toruslabs/constants": "^14.0.0", "@toruslabs/customauth": "file:../../", + "@toruslabs/fnd-base": "^14.0.0", "@toruslabs/openlogin-starkkey": "^3.2.0", "@toruslabs/torus.js": "^15.0.2", "@toruslabs/vue-components": "^7.8.3", @@ -51,7 +52,6 @@ "@toruslabs/constants": "^14.0.0", "@toruslabs/eccrypto": "^5.0.4", "@toruslabs/fetch-node-details": "^14.0.1", - "@toruslabs/fnd-base": "^14.0.0", "@toruslabs/http-helpers": "^7.0.0", "@toruslabs/metadata-helpers": "^6.0.0", "@toruslabs/session-manager": "^3.1.0", @@ -13439,6 +13439,22 @@ "typescript": "^5.x" } }, + "node_modules/@toruslabs/fnd-base": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/@toruslabs/fnd-base/-/fnd-base-14.0.0.tgz", + "integrity": "sha512-zaYrm/HHHU4Evj/Et1HrVT8hmMaUpVw3Rcx2Gvp1W5pWZybbdEVoa0uqIANYxcr/NH7PUIU3DoRbk+bXx0kkYg==", + "license": "MIT", + "dependencies": { + "@toruslabs/constants": "^14.0.0" + }, + "engines": { + "node": ">=18.x", + "npm": ">=9.x" + }, + "peerDependencies": { + "@babel/runtime": "7.x" + } + }, "node_modules/@toruslabs/http-helpers": { "version": "6.1.1", "license": "MIT", diff --git a/examples/vue-app/package.json b/examples/vue-app/package.json index 4a6a5fe..df01202 100644 --- a/examples/vue-app/package.json +++ b/examples/vue-app/package.json @@ -13,6 +13,7 @@ "@toruslabs/broadcast-channel": "10.0.1", "@toruslabs/constants": "^14.0.0", "@toruslabs/customauth": "file:../../", + "@toruslabs/fnd-base": "^14.0.0", "@toruslabs/openlogin-starkkey": "^3.2.0", "@toruslabs/torus.js": "^15.0.2", "@toruslabs/vue-components": "^7.8.3", diff --git a/examples/vue-app/src/App.vue b/examples/vue-app/src/App.vue index b4418c7..e9124a4 100644 --- a/examples/vue-app/src/App.vue +++ b/examples/vue-app/src/App.vue @@ -182,8 +182,9 @@