From bb6425e7dbf857355b115755dd9e46f195ea7478 Mon Sep 17 00:00:00 2001 From: Chaitanya Potti Date: Wed, 24 Jan 2024 23:08:53 +0800 Subject: [PATCH 1/6] don't publish src --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 6c18834..297f96b 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "prepare": "husky install" }, "files": [ - "dist", - "src" + "dist" ], "peerDependencies": { "@babel/runtime": "7.x" From c8954c9b17693c16875925d7691292689b98d043 Mon Sep 17 00:00:00 2001 From: Chaitanya Potti Date: Wed, 24 Jan 2024 23:09:37 +0800 Subject: [PATCH 2/6] Release 12.1.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b4a8069..5a38796 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@toruslabs/torus.js", - "version": "12.1.0", + "version": "12.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@toruslabs/torus.js", - "version": "12.1.0", + "version": "12.1.1", "license": "MIT", "dependencies": { "@toruslabs/constants": "^13.1.0", diff --git a/package.json b/package.json index 297f96b..0e293f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@toruslabs/torus.js", - "version": "12.1.0", + "version": "12.1.1", "description": "Handle communication with torus nodes", "main": "dist/torusUtils.cjs.js", "module": "dist/torusUtils.esm.js", From ed24b7dea15c5602098a2cd4a1fde62e8236c5ec Mon Sep 17 00:00:00 2001 From: Lwin Date: Tue, 30 Jan 2024 11:06:19 +0800 Subject: [PATCH 3/6] variable sessionTime for sessionTokenData --- package-lock.json | 31 ++++++++++++++++++++++---- package.json | 2 +- src/torus.ts | 16 +++++++++++-- test/sapphire_devnet.test.ts | 28 +++++++++++++++++++++++ test/sapphire_mainnet.test.ts | 28 +++++++++++++++++++++++ tsconfig.json | 42 ++++++++++++++++++++++++++++++++--- 6 files changed, 137 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5a38796..eae6f3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@toruslabs/constants": "^13.1.0", "@toruslabs/eccrypto": "^4.0.0", - "@toruslabs/http-helpers": "^5.0.0", + "@toruslabs/http-helpers": "^6.0.0", "bn.js": "^5.2.1", "elliptic": "^6.5.4", "ethereum-cryptography": "^2.1.2", @@ -2997,6 +2997,29 @@ "@babel/runtime": "7.x" } }, + "node_modules/@toruslabs/fetch-node-details/node_modules/@toruslabs/http-helpers": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@toruslabs/http-helpers/-/http-helpers-5.0.0.tgz", + "integrity": "sha512-GmezWz9JeF6YyhjLSm+9XDF4YaeICEckY0Jbo43i86SjhfJYgRWqEi63VSiNsaqc/z810Q0FQvEk1TnBRX2tgA==", + "dev": true, + "dependencies": { + "lodash.merge": "^4.6.2", + "loglevel": "^1.8.1" + }, + "engines": { + "node": ">=18.x", + "npm": ">=9.x" + }, + "peerDependencies": { + "@babel/runtime": "^7.x", + "@sentry/types": "^7.x" + }, + "peerDependenciesMeta": { + "@sentry/types": { + "optional": true + } + } + }, "node_modules/@toruslabs/fnd-base": { "version": "13.1.1", "resolved": "https://registry.npmjs.org/@toruslabs/fnd-base/-/fnd-base-13.1.1.tgz", @@ -3014,9 +3037,9 @@ } }, "node_modules/@toruslabs/http-helpers": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@toruslabs/http-helpers/-/http-helpers-5.0.0.tgz", - "integrity": "sha512-GmezWz9JeF6YyhjLSm+9XDF4YaeICEckY0Jbo43i86SjhfJYgRWqEi63VSiNsaqc/z810Q0FQvEk1TnBRX2tgA==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@toruslabs/http-helpers/-/http-helpers-6.0.0.tgz", + "integrity": "sha512-/KrISB9fGV2TM+5Z+0CGj24d/G08kqbB+kodO3nbwNcS0a55dpy+RiB0naF3H1gbEt4Ah5YH8qCDyAZ+zcR2FQ==", "dependencies": { "lodash.merge": "^4.6.2", "loglevel": "^1.8.1" diff --git a/package.json b/package.json index 0e293f2..f46ccb1 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "dependencies": { "@toruslabs/constants": "^13.1.0", "@toruslabs/eccrypto": "^4.0.0", - "@toruslabs/http-helpers": "^5.0.0", + "@toruslabs/http-helpers": "^6.0.0", "bn.js": "^5.2.1", "elliptic": "^6.5.4", "ethereum-cryptography": "^2.1.2", diff --git a/src/torus.ts b/src/torus.ts index 44a9156..ea916ad 100644 --- a/src/torus.ts +++ b/src/torus.ts @@ -54,6 +54,8 @@ import { Some } from "./some"; // Implement threshold logic wrappers around public APIs // of Torus nodes to handle malicious node responses class Torus { + private static sessionTime: number = 2480; // 2480s = 24 hour + public allowHost: string; public serverTimeOffset: number; @@ -104,6 +106,10 @@ class Torus { setEmbedHost(embedHost); } + static setSessionTime(sessionTime: number): void { + Torus.sessionTime = sessionTime; + } + static isGetOrSetNonceError(err: unknown): boolean { return err instanceof GetOrSetNonceError; } @@ -137,7 +143,10 @@ class Torus { verifierParams, idToken, importedShares: [], - extraParams, + extraParams: { + ...extraParams, + session_token_exp_second: Torus.sessionTime, + }, }); } @@ -222,7 +231,10 @@ class Torus { verifierParams, idToken, importedShares: sharesData, - extraParams, + extraParams: { + ...extraParams, + session_token_exp_second: Torus.sessionTime, + }, }); } diff --git a/test/sapphire_devnet.test.ts b/test/sapphire_devnet.test.ts index 41d8de4..24d6f7d 100644 --- a/test/sapphire_devnet.test.ts +++ b/test/sapphire_devnet.test.ts @@ -373,6 +373,34 @@ describe("torus utils sapphire devnet", function () { nodesData: result.nodesData, }); }); + + it("should be able to update the `sessionTime` of the token signature data", async function () { + const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); + + const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails({ verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }); + const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; + torusNodeEndpoints[1] = "https://example.com"; + + const customSessionTime = 3600; + TorusUtils.setSessionTime(customSessionTime); // 1hr + + const result = await torus.retrieveShares( + torusNodeEndpoints, + nodeDetails.torusIndexes, + TORUS_TEST_VERIFIER, + { verifier_id: TORUS_TEST_EMAIL }, + token + ); + + const signatures = result.sessionData.sessionTokenData.map((s) => ({ data: s.token, sig: s.signature })); + + const parsedSigsData = signatures.map((s) => JSON.parse(atob(s.data))); + parsedSigsData.forEach((ps) => { + const sessionTime = ps.exp - Math.floor(Date.now() / 1000); + expect(sessionTime).eql(customSessionTime); + }); + }); + it.skip("should be able to import a key for a new user", async function () { const email = faker.internet.email(); const token = generateIdToken(email, "ES256"); diff --git a/test/sapphire_mainnet.test.ts b/test/sapphire_mainnet.test.ts index 6410d65..db3f1c7 100644 --- a/test/sapphire_mainnet.test.ts +++ b/test/sapphire_mainnet.test.ts @@ -343,4 +343,32 @@ describe("torus utils sapphire mainnet", function () { expect(result.metadata.nonce).to.not.equal(null); expect(result.metadata.upgraded).to.equal(false); }); + + it("should be able to update the `sessionTime` of the token signature data", async function () { + const email = faker.internet.email(); + const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); + + const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails({ verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email }); + const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; + torusNodeEndpoints[1] = "https://example.com"; + + const customSessionTime = 3600; + TorusUtils.setSessionTime(customSessionTime); // 1hr + + const result = await torus.retrieveShares( + torusNodeEndpoints, + nodeDetails.torusIndexes, + TORUS_TEST_VERIFIER, + { verifier_id: TORUS_TEST_EMAIL }, + token + ); + + const signatures = result.sessionData.sessionTokenData.map((s) => ({ data: s.token, sig: s.signature })); + + const parsedSigsData = signatures.map((s) => JSON.parse(atob(s.data))); + parsedSigsData.forEach((ps) => { + const sessionTime = ps.exp - Math.floor(Date.now() / 1000); + expect(sessionTime).eql(customSessionTime); + }); + }); }); diff --git a/tsconfig.json b/tsconfig.json index 2951c72..22d236c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,41 @@ +// { +// "extends": "@toruslabs/config/tsconfig.default.json", +// "include": ["src", "test"], +// "compilerOptions": {}, +// "ts-node": { +// "compilerOptions": { +// "module": "CommonJS", +// "target": "ES2015", +// } +// } +// } + { - "extends": "@toruslabs/config/tsconfig.default.json", - "include": ["src", "test"], - "compilerOptions": {} + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "moduleResolution": "bundler", + "strict": true, + "module": "esnext", + "target": "esnext", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "sourceMap": true, + "esModuleInterop": true, + "noImplicitThis": true, + "declaration": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "isolatedModules": true, + "noImplicitAny": true, + "strictNullChecks": false, + "skipLibCheck": true + }, + "ts-node": { + "compilerOptions": { + "module": "CommonJS", + "target": "ES2015" + } + } } From f656a1bd41774041d52db5c1419f073093936ed6 Mon Sep 17 00:00:00 2001 From: Lwin Date: Tue, 30 Jan 2024 11:54:19 +0800 Subject: [PATCH 4/6] cleanup debug logs --- .vscode/settings.json | 2 +- tsconfig.json | 42 +++--------------------------------------- 2 files changed, 4 insertions(+), 40 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5b39903..81647c0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "cSpell.words": ["Mutex", "Mutexes", "toruslabs"] } diff --git a/tsconfig.json b/tsconfig.json index 22d236c..2951c72 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,41 +1,5 @@ -// { -// "extends": "@toruslabs/config/tsconfig.default.json", -// "include": ["src", "test"], -// "compilerOptions": {}, -// "ts-node": { -// "compilerOptions": { -// "module": "CommonJS", -// "target": "ES2015", -// } -// } -// } - { - "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { - "moduleResolution": "bundler", - "strict": true, - "module": "esnext", - "target": "esnext", - "lib": ["ES2022", "DOM", "DOM.Iterable"], - "sourceMap": true, - "esModuleInterop": true, - "noImplicitThis": true, - "declaration": true, - "allowSyntheticDefaultImports": true, - "resolveJsonModule": true, - "noUncheckedIndexedAccess": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "isolatedModules": true, - "noImplicitAny": true, - "strictNullChecks": false, - "skipLibCheck": true - }, - "ts-node": { - "compilerOptions": { - "module": "CommonJS", - "target": "ES2015" - } - } + "extends": "@toruslabs/config/tsconfig.default.json", + "include": ["src", "test"], + "compilerOptions": {} } From 4eaedca01db643c30e570baa7dac0a299663bd6c Mon Sep 17 00:00:00 2001 From: himanshu Date: Tue, 30 Jan 2024 13:09:18 +0530 Subject: [PATCH 5/6] fix mainnet test, as nonce is no more sent in public apis --- test/sapphire_mainnet.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/sapphire_mainnet.test.ts b/test/sapphire_mainnet.test.ts index 6410d65..9100d9b 100644 --- a/test/sapphire_mainnet.test.ts +++ b/test/sapphire_mainnet.test.ts @@ -16,7 +16,7 @@ const HashEnabledVerifier = "torus-test-verifierid-hash"; const TORUS_EXTENDED_VERIFIER_EMAIL = "testextenderverifierid@example.com"; const TORUS_IMPORT_EMAIL = "importeduser5@tor.us"; -describe("torus utils sapphire mainnet", function () { +describe.only("torus utils sapphire mainnet", function () { let torus: TorusUtils; let TORUS_NODE_MANAGER: NodeManager; @@ -50,7 +50,7 @@ describe("torus utils sapphire mainnet", function () { X: "56e803db7710adbfe0ecca35bc6a3ad27e966df142e157e76e492773c88e8433", Y: "f4168594c1126ca731756dd480f992ee73b0834ba4b787dd892a9211165f50a3", }, - nonce: new BN("f3ba568eeeaca5c285b25878a067fd85b1720b94f9099591d4274dc0a8cada9b", "hex"), + nonce: new BN("0", "hex"), upgraded: false, typeOfUser: "v2", }, @@ -203,7 +203,7 @@ describe("torus utils sapphire mainnet", function () { X: "498ed301af25a3b7136f478fa58677c79a6d6fe965bc13002a6f459b896313bd", Y: "d6feb9a1e0d6d0627fbb1ce75682bc09ab4cf0e2da4f0f7fcac0ba9d07596c8f", }, - nonce: new BN("3c2b6ba5b54ca0ba4ae978eb48429a84c47b7b3e526b35e7d46dd716887f52bf", "hex"), + nonce: new BN("0", "hex"), upgraded: false, typeOfUser: "v2", }, @@ -233,7 +233,7 @@ describe("torus utils sapphire mainnet", function () { X: "498ed301af25a3b7136f478fa58677c79a6d6fe965bc13002a6f459b896313bd", Y: "d6feb9a1e0d6d0627fbb1ce75682bc09ab4cf0e2da4f0f7fcac0ba9d07596c8f", }, - nonce: new BN("3c2b6ba5b54ca0ba4ae978eb48429a84c47b7b3e526b35e7d46dd716887f52bf", "hex"), + nonce: new BN("0", "hex"), upgraded: false, typeOfUser: "v2", }, From cdca52ab63bd46ff9493efb118e78703ed339182 Mon Sep 17 00:00:00 2001 From: Lwin Date: Tue, 30 Jan 2024 16:01:00 +0800 Subject: [PATCH 6/6] updated default session time --- src/torus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/torus.ts b/src/torus.ts index ea916ad..67cb8ad 100644 --- a/src/torus.ts +++ b/src/torus.ts @@ -54,7 +54,7 @@ import { Some } from "./some"; // Implement threshold logic wrappers around public APIs // of Torus nodes to handle malicious node responses class Torus { - private static sessionTime: number = 2480; // 2480s = 24 hour + private static sessionTime: number = 86400; // 86400 = 24 hour public allowHost: string;