diff --git a/.mocharc.yaml b/.mocharc.yaml deleted file mode 100644 index 089d356..0000000 --- a/.mocharc.yaml +++ /dev/null @@ -1,5 +0,0 @@ -import: "tsx" -exit: true -timeout: 0 -spec: "test/**/*.test.ts" -extension: "ts" diff --git a/package-lock.json b/package-lock.json index d57bdfe..853ac69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,14 @@ { "name": "@toruslabs/torus.js", - "version": "17.1.0", + "version": "17.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@toruslabs/torus.js", - "version": "17.1.0", + "version": "17.1.1", "license": "MIT", "dependencies": { - "@noble/curves": "^2.0.1", "@toruslabs/constants": "^16.0.0", "@toruslabs/eccrypto": "^7.0.0", "@toruslabs/http-helpers": "^9.0.0", @@ -90,7 +89,6 @@ "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -1670,7 +1668,6 @@ "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.6.tgz", "integrity": "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA==", "license": "MIT", - "peer": true, "engines": { "node": ">=6.9.0" } @@ -3054,7 +3051,6 @@ "integrity": "sha512-DhGl4xMVFGVIyMwswXeyzdL4uXD5OGILGX5N8Y+f6W7LhC1Ze2poSNrkF/fedpVDHEEZ+PHFW0vL14I+mm8K3Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@octokit/auth-token": "^6.0.0", "@octokit/graphql": "^9.0.3", @@ -4142,7 +4138,6 @@ "integrity": "sha512-DZ8VwRFUNzuqJ5khrvwMXHmvPe+zGayJhr2CDNiKB1WBE1ST8Djl00D0IC4vvNmHMdj6DlbYRIaFE7WHjlDl5w==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -4206,7 +4201,6 @@ "integrity": "sha512-klQbnPAAiGYFyI02+znpBRLyjL4/BrBd0nyWkdC0s/6xFLkXYQ8OoRrSkqacS1ddVxf/LDyODIKbQ5TgKAf/Fg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/types": "8.56.1", @@ -4866,7 +4860,6 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -5368,7 +5361,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -6533,7 +6525,6 @@ "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -6594,7 +6585,6 @@ "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==", "dev": true, "license": "MIT", - "peer": true, "bin": { "eslint-config-prettier": "bin/cli.js" }, @@ -6721,7 +6711,6 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", @@ -9270,7 +9259,6 @@ "integrity": "sha512-xrHS24IxaLrvuo613F719wvOIv9xPHFWQHuvGUBmPnCA/3MQxKI3b+r7n1jAoDHmsbC5bRhTZYR77invLAxVnw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/parser": "^7.28.5", "@babel/types": "^7.28.5", @@ -10240,7 +10228,6 @@ "integrity": "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==", "dev": true, "license": "MIT", - "peer": true, "bin": { "prettier": "bin/prettier.cjs" }, @@ -10722,7 +10709,6 @@ "integrity": "sha512-2oMpl67a3zCH9H79LeMcbDhXW/UmWG/y2zuqnF2jQq5uq9TbM9TVyXvA4+t+ne2IIkBdrLpAaRQAvo7YI/Yyeg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -11500,7 +11486,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -11769,7 +11754,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -11886,7 +11870,6 @@ "dev": true, "hasInstallScript": true, "license": "MIT", - "peer": true, "dependencies": { "napi-postinstall": "^0.3.0" }, @@ -12010,7 +11993,6 @@ "integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", @@ -12119,7 +12101,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -12133,7 +12114,6 @@ "integrity": "sha512-hOQuK7h0FGKgBAas7v0mSAsnvrIgAvWmRFjmzpJ7SwFHH3g1k2u37JtYwOwmEKhK6ZO3v9ggDBBm0La1LCK4uQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@vitest/expect": "4.0.18", "@vitest/mocker": "4.0.18", diff --git a/package.json b/package.json index 6353acd..14ee036 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@toruslabs/torus.js", - "version": "17.1.0", + "version": "17.1.1", "description": "Handle communication with torus nodes", "main": "dist/lib.cjs/index.js", "module": "dist/lib.esm/index.js", @@ -24,7 +24,6 @@ "@babel/runtime": "7.x" }, "dependencies": { - "@noble/curves": "^2.0.1", "@toruslabs/constants": "^16.0.0", "@toruslabs/eccrypto": "^7.0.0", "@toruslabs/http-helpers": "^9.0.0", diff --git a/src/helpers/common.ts b/src/helpers/common.ts index 8384895..f41c8cf 100644 --- a/src/helpers/common.ts +++ b/src/helpers/common.ts @@ -1,4 +1,3 @@ -import { bytesToHex as nobleBytesToHex, concatBytes as nobleConcatBytes, hexToBytes as nobleHexToBytes } from "@noble/curves/utils.js"; import { JRPCResponse } from "@toruslabs/constants"; import { Ecies } from "@toruslabs/eccrypto"; import { @@ -9,6 +8,7 @@ import { bytesToNumberBE, bytesToNumberLE, calculateMedian, + concatBytes, Curve, derivePubKey, generatePrivateKey, @@ -36,6 +36,7 @@ export { bytesToNumberBE, bytesToNumberLE, calculateMedian, + concatBytes, derivePubKey, generatePrivateKey, getEd25519, @@ -56,11 +57,6 @@ export type { Curve }; export const bytesToBase64 = mhBytesToBase64; export const base64ToBytes = mhBase64ToBytes; -export const concatBytes = nobleConcatBytes; - -// --------------------------------------------------------------------------- -// Torus-specific helpers (NOT migrated to metadata-helpers) -// --------------------------------------------------------------------------- export const normalizeKeysResult = (result: GetORSetKeyResponse) => { const finalResult: Pick = { @@ -97,13 +93,12 @@ export const normalizeLookUpResult = (result: VerifierLookupResponse) => { return finalResult; }; -/** ECIES params: bytes → hex. Uses noble bytesToHex so round-trip with encParamsHexToBuf (noble hexToBytes) is consistent. */ export function encParamsBufToHex(encParams: Ecies): EciesHex { return { - iv: nobleBytesToHex(encParams.iv), - ephemPublicKey: nobleBytesToHex(encParams.ephemPublicKey), - ciphertext: nobleBytesToHex(encParams.ciphertext), - mac: nobleBytesToHex(encParams.mac), + iv: bytesToHex(encParams.iv), + ephemPublicKey: bytesToHex(encParams.ephemPublicKey), + ciphertext: bytesToHex(encParams.ciphertext), + mac: bytesToHex(encParams.mac), mode: "AES256", }; } @@ -111,9 +106,9 @@ export function encParamsBufToHex(encParams: Ecies): EciesHex { /** ECIES params: hex → bytes. */ export function encParamsHexToBuf(eciesData: Omit): Omit { return { - ephemPublicKey: nobleHexToBytes(eciesData.ephemPublicKey), - iv: nobleHexToBytes(eciesData.iv), - mac: nobleHexToBytes(eciesData.mac), + ephemPublicKey: hexToBytes(eciesData.ephemPublicKey), + iv: hexToBytes(eciesData.iv), + mac: hexToBytes(eciesData.mac), }; } diff --git a/src/helpers/keyUtils.ts b/src/helpers/keyUtils.ts index 046f282..8c04a36 100644 --- a/src/helpers/keyUtils.ts +++ b/src/helpers/keyUtils.ts @@ -1,5 +1,3 @@ -import { mod } from "@noble/curves/abstract/modular.js"; -import { hexToBytes } from "@noble/curves/utils.js"; import { INodePub, KEY_TYPE } from "@toruslabs/constants"; import { Ecies, encrypt } from "@toruslabs/eccrypto"; import { @@ -20,8 +18,10 @@ import { getSecp256k1, getSecp256k1PublicKeyFromAffinePoint, getSecpKeyFromEd25519, + hexToBytes, keccak256, KeyType, + mod, toBigIntBE, utf8ToBytes, } from "@toruslabs/metadata-helpers"; diff --git a/src/helpers/metadataUtils.ts b/src/helpers/metadataUtils.ts index 11ad171..8b172dc 100644 --- a/src/helpers/metadataUtils.ts +++ b/src/helpers/metadataUtils.ts @@ -83,7 +83,7 @@ export function generateMetadataParams(ecCurve: Curve, serverTimeOffset: number, pub_key_X: pubKey.x.toString(16), // DO NOT PAD THIS. BACKEND DOESN'T pub_key_Y: pubKey.y.toString(16), // DO NOT PAD THIS. BACKEND DOESN'T set_data: setData, - signature: bytesToBase64(concatBytes(sig, hexToBytes("00"))), + signature: bytesToBase64(concatBytes([sig, hexToBytes("00")])), }; } @@ -137,7 +137,7 @@ export function generateNonceMetadataParams( pub_key_Y: bigintToHex(pubKey.y), set_data: setData, key_type: keyType, - signature: bytesToBase64(concatBytes(sig, hexToBytes("00"))), + signature: bytesToBase64(concatBytes([sig, hexToBytes("00")])), }; } @@ -249,7 +249,7 @@ export async function getOrSetSapphireMetadataNonce( pub_key_X: bigintToHex(pubKey.x), pub_key_Y: bigintToHex(pubKey.y), set_data: setData, - signature: bytesToBase64(concatBytes(sig, hexToBytes("00"))), + signature: bytesToBase64(concatBytes([sig, hexToBytes("00")])), }; } diff --git a/src/interfaces.ts b/src/interfaces.ts index f854040..499cef8 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,10 +1,9 @@ -import type { AffinePoint as AffinePointCurve } from "@noble/curves/abstract/curve.js"; import type { INodePub, TORUS_NETWORK_TYPE } from "@toruslabs/constants"; import { Ecies } from "@toruslabs/eccrypto"; +import { AffinePoint } from "@toruslabs/metadata-helpers"; import { TorusUtilsExtraParams } from "./TorusUtilsExtraParams"; - -export type AffinePoint = AffinePointCurve; +export type { AffinePoint }; export interface KeyIndex { index: string; diff --git a/test/configs/node.config.mts b/test/configs/node.config.mts index 93c8733..4cc2530 100644 --- a/test/configs/node.config.mts +++ b/test/configs/node.config.mts @@ -3,7 +3,7 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { reporters: "verbose", - testTimeout: 10000, + testTimeout: 60000, coverage: { reporter: ["text"], provider: "istanbul", diff --git a/test/onekey.test.ts b/test/onekey.test.ts index f6d1323..5f6da76 100644 --- a/test/onekey.test.ts +++ b/test/onekey.test.ts @@ -160,7 +160,7 @@ describe("torus onekey", () => { }); }); - it("should be able to key assign", { timeout: 15000 }, async () => { + it("should be able to key assign", async () => { const verifier = TORUS_TEST_VERIFIER; const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; diff --git a/test/sapphire_devnet.test.ts b/test/sapphire_devnet.test.ts index b850cb5..ae7c576 100644 --- a/test/sapphire_devnet.test.ts +++ b/test/sapphire_devnet.test.ts @@ -281,7 +281,7 @@ describe("torus utils sapphire devnet", () => { expect(result.metadata.upgraded).toBe(false); }); - it("should keep public address same", { timeout: 15000 }, async () => { + it("should keep public address same", async () => { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: faker.internet.email() }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; @@ -635,7 +635,7 @@ describe("torus utils sapphire devnet", () => { }); }); - it("should assign key to tss verifier id", { timeout: 15000 }, async () => { + it("should assign key to tss verifier id", async () => { const email = faker.internet.email(); const nonce = 0; const tssTag = "default"; @@ -843,7 +843,7 @@ describe("torus utils sapphire devnet", () => { expect(result.metadata.upgraded).toBe(false); }); - it("should be able to login with different accounts and get different addresses for each", { timeout: 15000 }, async () => { + it("should be able to login with different accounts and get different addresses for each", async () => { const email1 = faker.internet.email(); const email2 = faker.internet.email(); @@ -942,48 +942,44 @@ describe("torus utils sapphire devnet", () => { expect(set.size).toBe(1); }); - it( - "should be able to login with a fixed set of different accounts repeatedly and get a constant set of addresses", - { timeout: 60000 }, - async () => { - const addresses = []; - const iterations = 5; - for (let i = 0; i <= iterations; i++) { - const email = faker.internet.email(); - for (let k = 0; k <= iterations; k++) { - const idToken = generateIdToken(email, "ES256"); - const hashedIdToken = keccak256(utf8ToBytes(idToken)); - const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email }; - - const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.retrieveShares({ - endpoints: torusNodeEndpoints, - indexes: nodeDetails.torusIndexes, - verifier: TORUS_TEST_AGGREGATE_VERIFIER, - verifierParams: { - verify_params: [{ verifier_id: email, idtoken: idToken }], - sub_verifier_ids: [TORUS_TEST_VERIFIER], - verifier_id: email, - }, - idToken: hashedIdToken.substring(2), - nodePubkeys: nodeDetails.torusNodePub, - }); - expect(result.metadata.serverTimeOffset).toBeLessThan(20); - delete result.metadata.serverTimeOffset; - - expect(result.finalKeyData.walletAddress).not.toBe(null); - expect(result.finalKeyData.walletAddress).not.toBe(""); - expect(result.oAuthKeyData.walletAddress).not.toBe(null); - expect(result.metadata.typeOfUser).toBe("v2"); - expect(result.metadata.nonce).not.toBe(null); - expect(result.metadata.upgraded).toBe(false); - - addresses.push(result.finalKeyData.walletAddress); - } + it("should be able to login with a fixed set of different accounts repeatedly and get a constant set of addresses", async () => { + const addresses = []; + const iterations = 5; + for (let i = 0; i <= iterations; i++) { + const email = faker.internet.email(); + for (let k = 0; k <= iterations; k++) { + const idToken = generateIdToken(email, "ES256"); + const hashedIdToken = keccak256(utf8ToBytes(idToken)); + const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email }; + + const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; + const result = await torus.retrieveShares({ + endpoints: torusNodeEndpoints, + indexes: nodeDetails.torusIndexes, + verifier: TORUS_TEST_AGGREGATE_VERIFIER, + verifierParams: { + verify_params: [{ verifier_id: email, idtoken: idToken }], + sub_verifier_ids: [TORUS_TEST_VERIFIER], + verifier_id: email, + }, + idToken: hashedIdToken.substring(2), + nodePubkeys: nodeDetails.torusNodePub, + }); + expect(result.metadata.serverTimeOffset).toBeLessThan(20); + delete result.metadata.serverTimeOffset; + + expect(result.finalKeyData.walletAddress).not.toBe(null); + expect(result.finalKeyData.walletAddress).not.toBe(""); + expect(result.oAuthKeyData.walletAddress).not.toBe(null); + expect(result.metadata.typeOfUser).toBe("v2"); + expect(result.metadata.nonce).not.toBe(null); + expect(result.metadata.upgraded).toBe(false); + + addresses.push(result.finalKeyData.walletAddress); } - const set = new Set(addresses); - expect(set.size).toBe(6); } - ); + const set = new Set(addresses); + expect(set.size).toBe(6); + }); }); diff --git a/test/tssPubKey.test.ts b/test/tssPubKey.test.ts index df21e56..b956f1f 100644 --- a/test/tssPubKey.test.ts +++ b/test/tssPubKey.test.ts @@ -15,7 +15,7 @@ describe("setTssKey", () => { TORUS_NODE_MANAGER = new NodeDetailManager({ network: TORUS_SAPPHIRE_NETWORK.SAPPHIRE_DEVNET }); }); - it("should assign key to tss verifier id", { timeout: 15000 }, async () => { + it("should assign key to tss verifier id", async () => { const email = faker.internet.email(); const nonce = 0; const tssTag = "default";