diff --git a/README.md b/README.md index 6d0b4a2..9bc2e4c 100644 --- a/README.md +++ b/README.md @@ -74,11 +74,11 @@ const fetchNodeDetails = new FetchNodeDetails(); const torus = new TorusUtils({ network: "mainnet", clientId: "YOUR_CLIENT_ID" }); // get your Client ID from Web3Auth Dashboard const verifier = "google"; const verifierId = "hello@tor.us"; -const { torusNodeEndpoints } = await fetchNodeDetails.getNodeDetails(); -const publicAddress = await torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId }); +const { torusNodeEndpoints, torusNodePub, torusIndexes } = await fetchNodeDetails.getNodeDetails(); +const publicAddress = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId }); const idToken = "YOUR_ID_TOKEN"; -const keyData = await torus.retrieveShares(torusNodeEndpoints, verifier, { verifier_id: verifierId }, idToken); +const keyData = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, verifier, { verifier_id: verifierId }, idToken); ``` ```js @@ -91,13 +91,15 @@ const verifier = "google"; // any verifier const verifierId = "hello@tor.us"; // any verifier id fetchNodeDetails .getNodeDetails() - .then(({ torusNodeEndpoints }) => torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId })) + .then(({ torusNodeEndpoints, torusNodePub }) => torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId })) .then((publicAddress) => console.log(publicAddress)); const idToken = "YOUR_ID_TOKEN"; fetchNodeDetails .getNodeDetails() - .then(({ torusNodeEndpoints }) => torus.retrieveShares(torusNodeEndpoints, verifier, { verifier_id: verifierId }, idToken)) + .then(({ torusNodeEndpoints, torusIndexes }) => + torus.retrieveShares(torusNodeEndpoints, torusIndexes, verifier, { verifier_id: verifierId }, idToken) + ) .then((keyData) => console.log(keyData)); ``` @@ -112,11 +114,11 @@ const verifier = "google"; // any verifier const verifierId = "hello@tor.us"; // any verifier id fetchNodeDetails .getNodeDetails() - .then(({ torusNodeEndpoints }) => torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId })) + .then(({ torusNodeEndpoints, torusNodePub }) => torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId })) .then((publicAddress) => console.log(publicAddress)); ``` ## Requirements - This package requires a peer dependency of `@babel/runtime` -- Node 20+ +- Node 16+ diff --git a/src/helpers/nodeUtils.ts b/src/helpers/nodeUtils.ts index 558cfa8..0d5ce28 100644 --- a/src/helpers/nodeUtils.ts +++ b/src/helpers/nodeUtils.ts @@ -36,6 +36,7 @@ export const GetPubKeyOrKeyAssign = async (params: { extendedVerifierId?: string; }): Promise => { const { endpoints, network, verifier, verifierId, extendedVerifierId } = params; + const minThreshold = ~~(endpoints.length / 2) + 1; const lookupPromises = endpoints.map((x) => post>( x, @@ -65,12 +66,12 @@ export const GetPubKeyOrKeyAssign = async (params: { const errorResult = thresholdSame( lookupPubKeys.map((x2) => x2 && x2.error), - ~~(endpoints.length / 2) + 1 + minThreshold ); const keyResult = thresholdSame( lookupPubKeys.map((x3) => x3 && normalizeKeysResult(x3.result)), - ~~(endpoints.length / 2) + 1 + minThreshold ); // check for nonce result in response if not a extendedVerifierId and not a legacy network @@ -138,6 +139,7 @@ export async function retrieveOrImportShare(params: { idToken: string; importedShares?: ImportedShare[]; extraParams: Record; + indexes: number[]; }): Promise { const { legacyMetadataHost, @@ -154,6 +156,7 @@ export async function retrieveOrImportShare(params: { extraParams, serverTimeOffset, } = params; + const minThreshold = ~~(endpoints.length / 2) + 1; await get( allowHost, { @@ -348,7 +351,7 @@ export async function retrieveOrImportShare(params: { return undefined; }); - const thresholdPublicKey = thresholdSame(pubkeys, ~~(endpoints.length / 2) + 1); + const thresholdPublicKey = thresholdSame(pubkeys, minThreshold); if (!thresholdPublicKey) { throw new Error("invalid result from nodes, threshold number of public key results are not matching"); @@ -373,7 +376,7 @@ export async function retrieveOrImportShare(params: { ); } - const thresholdReqCount = importedShares.length > 0 ? endpoints.length : ~~(endpoints.length / 2) + 1; + const thresholdReqCount = importedShares.length > 0 ? endpoints.length : minThreshold; // optimistically run lagrange interpolation once threshold number of shares have been received // this is matched against the user public key to ensure that shares are consistent // Note: no need of thresholdMetadataNonce for extended_verifier_id key @@ -464,9 +467,8 @@ export async function retrieveOrImportShare(params: { return false; }); - const minThresholdRequired = ~~(endpoints.length / 2) + 1; - if (!verifierParams.extended_verifier_id && validSigs.length < minThresholdRequired) { - throw new Error(`Insufficient number of signatures from nodes, required: ${minThresholdRequired}, found: ${validSigs.length}`); + if (!verifierParams.extended_verifier_id && validSigs.length < minThreshold) { + throw new Error(`Insufficient number of signatures from nodes, required: ${minThreshold}, found: ${validSigs.length}`); } const validTokens = sessionTokensResolved.filter((token) => { @@ -476,8 +478,8 @@ export async function retrieveOrImportShare(params: { return false; }); - if (!verifierParams.extended_verifier_id && validTokens.length < minThresholdRequired) { - throw new Error(`Insufficient number of session tokens from nodes, required: ${minThresholdRequired}, found: ${validTokens.length}`); + if (!verifierParams.extended_verifier_id && validTokens.length < minThreshold) { + throw new Error(`Insufficient number of session tokens from nodes, required: ${minThreshold}, found: ${validTokens.length}`); } sessionTokensResolved.forEach((x, index) => { if (!x) sessionTokenData.push(undefined); @@ -500,7 +502,7 @@ export async function retrieveOrImportShare(params: { [] as { index: BN; value: BN }[] ); // run lagrange interpolation on all subsets, faster in the optimistic scenario than berlekamp-welch due to early exit - const allCombis = kCombinations(decryptedShares.length, ~~(endpoints.length / 2) + 1); + const allCombis = kCombinations(decryptedShares.length, minThreshold); let privateKey: BN | null = null; for (let j = 0; j < allCombis.length; j += 1) { @@ -525,7 +527,7 @@ export async function retrieveOrImportShare(params: { if (privateKey === undefined || privateKey === null) { throw new Error("could not derive private key"); } - const thresholdIsNewKey = thresholdSame(isNewKeyResponses, ~~(endpoints.length / 2) + 1); + const thresholdIsNewKey = thresholdSame(isNewKeyResponses, minThreshold); // Convert each string timestamp to a number const serverOffsetTimes = serverTimeOffsetResponses.map((timestamp) => Number.parseInt(timestamp, 10)); diff --git a/src/torus.ts b/src/torus.ts index afaca46..c7a8b63 100644 --- a/src/torus.ts +++ b/src/torus.ts @@ -94,6 +94,7 @@ class Torus { async retrieveShares( endpoints: string[], + indexes: number[], verifier: string, verifierParams: VerifierParams, idToken: string, @@ -111,6 +112,7 @@ class Torus { verifier, verifierParams, idToken, + indexes, importedShares: [], extraParams: { ...extraParams, @@ -121,6 +123,7 @@ class Torus { async getPublicAddress( endpoints: string[], + torusNodePubs: INodePub[], { verifier, verifierId, extendedVerifierId }: { verifier: string; verifierId: string; extendedVerifierId?: string } ): Promise { return this.getNewPublicAddress(endpoints, { verifier, verifierId, extendedVerifierId }, this.enableOneKey); @@ -196,6 +199,7 @@ class Torus { verifier, verifierParams, idToken, + indexes: nodeIndexes, importedShares: sharesData, extraParams: { ...extraParams, @@ -210,6 +214,7 @@ class Torus { */ async getUserTypeAndAddress( endpoints: string[], + torusNodePubs: INodePub[], { verifier, verifierId, extendedVerifierId }: { verifier: string; verifierId: string; extendedVerifierId?: string } ): Promise { return this.getNewPublicAddress(endpoints, { verifier, verifierId, extendedVerifierId }, true) as Promise; diff --git a/test/aqua.test.ts b/test/aqua.test.ts index 9acfdd0..4fa4fde 100644 --- a/test/aqua.test.ts +++ b/test/aqua.test.ts @@ -27,8 +27,8 @@ describe("torus utils aqua", function () { it("should fetch public address", async function () { const verifier = "tkey-google-aqua"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0xDfA967285AC699A70DA340F60d00DB19A272639d"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -57,8 +57,8 @@ describe("torus utils aqua", function () { it("should fetch user type and public address", async function () { const verifier = "tkey-google-aqua"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result1 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, verifierDetails)) as TorusPublicKey; + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result1 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails)) as TorusPublicKey; expect(result1.metadata.typeOfUser).to.equal("v2"); expect(result1.metadata.serverTimeOffset).lessThan(20); delete result1.metadata.serverTimeOffset; @@ -89,7 +89,7 @@ describe("torus utils aqua", function () { const v2Verifier = "tkey-google-aqua"; // 1/1 user const v2TestEmail = "somev2user@gmail.com"; - const result2 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result2 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2TestEmail, })) as TorusPublicKey; @@ -122,7 +122,7 @@ describe("torus utils aqua", function () { // 2/n user const v2nTestEmail = "caspertorus@gmail.com"; - const result3 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result3 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2nTestEmail, })) as TorusPublicKey; @@ -158,8 +158,8 @@ describe("torus utils aqua", function () { const verifier = "tkey-google-aqua"; // any verifier const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(finalKeyData.evmAddress).to.not.equal(""); expect(finalKeyData.evmAddress).to.not.equal(null); expect(oAuthKeyData.evmAddress).to.not.equal(""); @@ -171,8 +171,8 @@ describe("torus utils aqua", function () { it("should be able to login", async function () { const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); expect(result.finalKeyData.privKey).to.be.equal("f726ce4ac79ae4475d72633c94769a8817aff35eebe2d4790aed7b5d8a84aa1d"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -200,9 +200,10 @@ describe("torus utils aqua", function () { const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result = await torus.retrieveShares( torusNodeEndpoints, + torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], diff --git a/test/celeste.test.ts b/test/celeste.test.ts index a0e7106..7623295 100644 --- a/test/celeste.test.ts +++ b/test/celeste.test.ts @@ -27,8 +27,8 @@ describe("torus utils celeste", function () { it("should fetch public address", async function () { const verifier = "tkey-google-celeste"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0xC3115b9d6FaB99739b23DA9dfcBA47A4Ec4Cd113"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -57,8 +57,8 @@ describe("torus utils celeste", function () { it("should fetch user type and public address", async function () { const verifier = "tkey-google-celeste"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result1.finalKeyData.evmAddress).to.equal("0xC3115b9d6FaB99739b23DA9dfcBA47A4Ec4Cd113"); expect(result1.metadata.typeOfUser).to.equal("v1"); expect(result1.metadata.serverTimeOffset).lessThan(20); @@ -87,7 +87,7 @@ describe("torus utils celeste", function () { const v2Verifier = "tkey-google-celeste"; // 1/1 user const v2TestEmail = "somev2user@gmail.com"; - const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2TestEmail, }); @@ -120,7 +120,7 @@ describe("torus utils celeste", function () { // 2/n user const v2nTestEmail = "caspertorus@gmail.com"; - const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2nTestEmail, }); @@ -156,8 +156,8 @@ describe("torus utils celeste", function () { const verifier = "tkey-google-celeste"; // any verifier const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const { finalKeyData, metadata, oAuthKeyData } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { finalKeyData, metadata, oAuthKeyData } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(finalKeyData.evmAddress).to.not.equal(""); expect(finalKeyData.evmAddress).to.not.equal(null); expect(oAuthKeyData.evmAddress).to.not.equal(""); @@ -169,8 +169,8 @@ describe("torus utils celeste", function () { it("should be able to login", async function () { const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); expect(result.finalKeyData.privKey).to.be.equal("0ae056aa938080c9e8bf6641261619e09fd510c91bb5aad14b0de9742085a914"); expect(result.metadata.serverTimeOffset).lessThan(20); @@ -199,9 +199,10 @@ describe("torus utils celeste", function () { const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result = await torus.retrieveShares( torusNodeEndpoints, + torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], diff --git a/test/cyan.test.ts b/test/cyan.test.ts index 531f1c3..f0c4792 100644 --- a/test/cyan.test.ts +++ b/test/cyan.test.ts @@ -27,8 +27,8 @@ describe("torus utils cyan", function () { it("should fetch public address", async function () { const verifier = "tkey-google-cyan"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0xA3767911A84bE6907f26C572bc89426dDdDB2825"); expect(result.metadata.serverTimeOffset).lessThan(20); @@ -58,8 +58,8 @@ describe("torus utils cyan", function () { it("should fetch user type and public address", async function () { const verifier = "tkey-google-cyan"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result1.finalKeyData.evmAddress).to.equal("0x3507F0d192a44E436B8a6C32a37d57D022861b1a"); expect(result1.metadata.typeOfUser).to.equal("v2"); expect(result1.metadata.serverTimeOffset).lessThan(20); @@ -91,7 +91,7 @@ describe("torus utils cyan", function () { const v2Verifier = "tkey-google-cyan"; // 1/1 user const v2TestEmail = "somev2user@gmail.com"; - const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2TestEmail, }); @@ -125,7 +125,7 @@ describe("torus utils cyan", function () { }); // 2/n user const v2nTestEmail = "caspertorus@gmail.com"; - const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2nTestEmail, }); @@ -161,8 +161,8 @@ describe("torus utils cyan", function () { const verifier = "tkey-google-cyan"; // any verifier const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(finalKeyData.evmAddress).to.not.equal(""); expect(finalKeyData.evmAddress).to.not.equal(null); expect(oAuthKeyData.evmAddress).to.not.equal(""); @@ -174,8 +174,8 @@ describe("torus utils cyan", function () { it("should be able to login", async function () { const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); delete result.sessionData; expect(result.metadata.serverTimeOffset).lessThan(20); @@ -204,9 +204,10 @@ describe("torus utils cyan", function () { const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result = await torus.retrieveShares( torusNodeEndpoints, + torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], diff --git a/test/index.html b/test/index.html index 7b59854..9a4d20c 100644 --- a/test/index.html +++ b/test/index.html @@ -10,11 +10,11 @@ const torus = new TorusUtils.default({ network: "mainnet", clientId: "test" }); const verifier = "google"; // any verifier const verifierId = `${Math.random().toString(36).substring(2)}@tor.us`; // any verifier id - fetchNodeDetails + ffetchNodeDetails .getNodeDetails({ verifier, verifierId }) - .then(function ({ torusNodeEndpoints }) { + .then(function ({ torusNodeEndpoints, torusNodePub }) { console.log(arguments); - return torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId }); + return torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId }); }) .then((publicAddress) => console.log(publicAddress)) .catch(console.error); diff --git a/test/index.js b/test/index.js index e80f5e9..75c254b 100644 --- a/test/index.js +++ b/test/index.js @@ -5,7 +5,7 @@ // const verifierId = "hello@tor.us"; // any verifier id // fetchNodeDetails // .getNodeDetails({ verifier, verifierId }) -// .then(({ torusNodeEndpoints }) => torus.getPublicAddress(torusNodeEndpoints, { verifier, verifierId })) +// .then(({ torusNodeEndpoints, torusNodePub }) => torus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier, verifierId })) // .then((publicAddress) => console.log(publicAddress)) // .catch(console.error); diff --git a/test/mainnet.test.ts b/test/mainnet.test.ts index ac5eaf1..2ee12b2 100644 --- a/test/mainnet.test.ts +++ b/test/mainnet.test.ts @@ -27,8 +27,8 @@ describe("torus utils mainnet", function () { it("should fetch public address", async function () { const verifier = "google"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A"); delete result.metadata.serverTimeOffset; @@ -56,8 +56,8 @@ describe("torus utils mainnet", function () { it("should fetch user type and public address", async function () { const verifier = "google"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result1.metadata.typeOfUser).to.equal("v2"); expect(result1.metadata.serverTimeOffset).lessThan(20); @@ -89,7 +89,7 @@ describe("torus utils mainnet", function () { const v2Verifier = "tkey-google"; // 1/1 user const v2TestEmail = "somev2user@gmail.com"; - const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result2 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2TestEmail, }); @@ -124,7 +124,7 @@ describe("torus utils mainnet", function () { // 2/n user const v2nTestEmail = "caspertorus@gmail.com"; - const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result3 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2nTestEmail, }); @@ -160,8 +160,8 @@ describe("torus utils mainnet", function () { // TorusUtils.enableLogging(true); const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(finalKeyData.evmAddress).to.not.equal(""); expect(finalKeyData.evmAddress).to.not.equal(null); expect(oAuthKeyData.evmAddress).to.not.equal(""); @@ -174,8 +174,8 @@ describe("torus utils mainnet", function () { it("should be able to login", async function () { const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); delete result.sessionData; expect(result.metadata.serverTimeOffset).lessThan(20); @@ -203,9 +203,10 @@ describe("torus utils mainnet", function () { const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result = await torus.retrieveShares( torusNodeEndpoints, + torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], diff --git a/test/onekey.test.ts b/test/onekey.test.ts index c517f66..3d91039 100644 --- a/test/onekey.test.ts +++ b/test/onekey.test.ts @@ -29,8 +29,8 @@ describe("torus onekey", function () { it("should still fetch v1 public address correctly", async function () { const verifier = "google-lrc"; // any verifier const verifierDetails = { verifier, verifierId: "himanshu@tor.us" }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const publicAddress = (await torus.getPublicAddress(torusNodeEndpoints, verifierDetails)) as TorusPublicKey; + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const publicAddress = (await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails)) as TorusPublicKey; expect(publicAddress.finalKeyData.evmAddress).to.be.equal("0x930abEDDCa6F9807EaE77A3aCc5c78f20B168Fd1"); expect(publicAddress.metadata.serverTimeOffset).lessThan(20); @@ -60,8 +60,14 @@ describe("torus onekey", function () { it("should still login v1 account correctly", async function () { const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const retrieveSharesResponse = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const retrieveSharesResponse = await torus.retrieveShares( + torusNodeEndpoints, + torusIndexes, + TORUS_TEST_VERIFIER, + { verifier_id: TORUS_TEST_EMAIL }, + token + ); expect(retrieveSharesResponse.metadata.serverTimeOffset).lessThan(20); delete retrieveSharesResponse.metadata.serverTimeOffset; @@ -101,9 +107,10 @@ describe("torus onekey", function () { const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const retrieveSharesResponse = await torus.retrieveShares( torusNodeEndpoints, + torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], @@ -151,8 +158,8 @@ describe("torus onekey", function () { const verifier = TORUS_TEST_VERIFIER; // any verifier const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const publicAddress = (await torus.getPublicAddress(torusNodeEndpoints, verifierDetails)) as TorusPublicKey; + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const publicAddress = (await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails)) as TorusPublicKey; expect(publicAddress.metadata.typeOfUser).to.equal("v2"); expect(publicAddress.metadata.upgraded).to.equal(false); expect(publicAddress.finalKeyData.evmAddress).to.not.equal(""); @@ -165,8 +172,8 @@ describe("torus onekey", function () { const email = faker.internet.email(); const token = generateIdToken(email, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: email }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: email }, token); expect(!result.metadata.nonce.eq(new BN("0"))); expect(result.metadata.typeOfUser).to.equal("v2"); expect(result.metadata.upgraded).to.equal(false); @@ -179,9 +186,10 @@ describe("torus onekey", function () { it("should still login v2 account correctly", async function () { const token = generateIdToken("Jonathan.Nolan@hotmail.com", "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: "Jonathan.Nolan@hotmail.com" }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const retrieveSharesResponse = await torus.retrieveShares( torusNodeEndpoints, + torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: "Jonathan.Nolan@hotmail.com" }, token diff --git a/test/sapphire_devnet.test.ts b/test/sapphire_devnet.test.ts index b6c811c..a2605b5 100644 --- a/test/sapphire_devnet.test.ts +++ b/test/sapphire_devnet.test.ts @@ -48,8 +48,8 @@ describe("torus utils sapphire devnet", function () { clientId: "YOUR_CLIENT_ID", enableOneKey: true, }); - const { torusNodeSSSEndpoints: torusNodeEndpoints } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const publicKeyData = await legacyTorus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeSSSEndpoints: torusNodeEndpoints, torusNodePub } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const publicKeyData = await legacyTorus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(publicKeyData.metadata.typeOfUser).to.equal("v1"); expect(publicKeyData.finalKeyData.evmAddress).to.equal("0x930abEDDCa6F9807EaE77A3aCc5c78f20B168Fd1"); delete publicKeyData.metadata.serverTimeOffset; @@ -88,8 +88,14 @@ describe("torus utils sapphire devnet", function () { network: TORUS_LEGACY_NETWORK.TESTNET, clientId: "YOUR_CLIENT_ID", }); - const { torusNodeSSSEndpoints: torusNodeEndpoints } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const retrieveSharesResponse = await legacyTorus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: email }, token); + const { torusNodeSSSEndpoints: torusNodeEndpoints, torusIndexes } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const retrieveSharesResponse = await legacyTorus.retrieveShares( + torusNodeEndpoints, + torusIndexes, + TORUS_TEST_VERIFIER, + { verifier_id: email }, + token + ); expect(retrieveSharesResponse.finalKeyData.privKey).to.be.equal("dca7f29d234dc71561efe1a874d872bf34f6528bc042fe35e57197eac1f14eb9"); delete retrieveSharesResponse.sessionData; delete retrieveSharesResponse.metadata.serverTimeOffset; @@ -132,9 +138,9 @@ describe("torus utils sapphire devnet", function () { clientId: "YOUR_CLIENT_ID", enableOneKey: true, }); - const { torusNodeSSSEndpoints: torusNodeEndpoints } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeSSSEndpoints: torusNodeEndpoints, torusNodePub } = await LEGACY_TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await legacyTorus.getPublicAddress(torusNodeEndpoints, { + const result = await legacyTorus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2TestEmail, }); @@ -168,7 +174,7 @@ describe("torus utils sapphire devnet", function () { // 2/n user const v2nTestEmail = "caspertorus@gmail.com"; - const data = await legacyTorus.getPublicAddress(torusNodeEndpoints, { + const data = await legacyTorus.getPublicAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2nTestEmail, }); @@ -205,7 +211,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -237,7 +243,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_IMPORT_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.not.equal(null); expect(result.finalKeyData.evmAddress).to.not.equal(""); expect(result.finalKeyData.evmAddress).to.not.equal(null); @@ -252,11 +258,11 @@ describe("torus utils sapphire devnet", function () { const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result1 = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result1 = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result1.metadata.serverTimeOffset).lessThan(20); delete result1.metadata.serverTimeOffset; - const result2 = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result2 = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result2.metadata.serverTimeOffset).lessThan(20); delete result2.metadata.serverTimeOffset; @@ -270,7 +276,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -303,7 +309,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: email }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.not.equal(""); expect(result.finalKeyData.evmAddress).to.not.equal(null); }); @@ -312,7 +318,13 @@ describe("torus utils sapphire devnet", 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; - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const result = await torus.retrieveShares( + torusNodeEndpoints, + nodeDetails.torusIndexes, + TORUS_TEST_VERIFIER, + { verifier_id: TORUS_TEST_EMAIL }, + token + ); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -351,7 +363,13 @@ describe("torus utils sapphire devnet", function () { 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 result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const result = await torus.retrieveShares( + torusNodeEndpoints, + nodeDetails.torusIndexes, + TORUS_TEST_VERIFIER, + { verifier_id: TORUS_TEST_EMAIL }, + token + ); delete result.metadata.serverTimeOffset; expect(result).eql({ @@ -394,7 +412,13 @@ describe("torus utils sapphire devnet", function () { const customSessionTime = 3600; TorusUtils.setSessionTime(customSessionTime); // 1hr - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + 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 })); @@ -424,7 +448,7 @@ describe("torus utils sapphire devnet", function () { privHex ); expect(result.finalKeyData.privKey).to.be.equal(privHex); - const result1 = await torus.getPublicAddress(torusNodeEndpoints, { verifier: TORUS_TEST_VERIFIER, verifierId: email }); + const result1 = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, { verifier: TORUS_TEST_VERIFIER, verifierId: email }); expect(result1.finalKeyData.evmAddress).to.be.equal(result.finalKeyData.evmAddress); }); @@ -436,7 +460,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: email, extendedVerifierId: tssVerifierId }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -469,7 +493,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: email, extendedVerifierId: tssVerifierId }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.not.equal(null); expect(result.oAuthKeyData.evmAddress).to.not.equal(null); expect(result.metadata.typeOfUser).to.equal("v2"); @@ -487,6 +511,7 @@ describe("torus utils sapphire devnet", function () { const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; const result = await torus.retrieveShares( torusNodeEndpoints, + nodeDetails.torusIndexes, TORUS_TEST_VERIFIER, { extended_verifier_id: tssVerifierId, verifier_id: email }, token @@ -502,7 +527,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_HASH_ENABLED_TEST_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0xF79b5ffA48463eba839ee9C97D61c6063a96DA03"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -548,7 +573,7 @@ describe("torus utils sapphire devnet", function () { const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_HASH_ENABLED_TEST_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0xF79b5ffA48463eba839ee9C97D61c6063a96DA03"); expect(result.metadata.serverTimeOffset).lessThan(20); @@ -584,7 +609,13 @@ describe("torus utils sapphire devnet", function () { const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.retrieveShares(torusNodeEndpoints, HashEnabledVerifier, { verifier_id: TORUS_HASH_ENABLED_TEST_EMAIL }, token); + const result = await torus.retrieveShares( + torusNodeEndpoints, + nodeDetails.torusIndexes, + HashEnabledVerifier, + { verifier_id: TORUS_HASH_ENABLED_TEST_EMAIL }, + token + ); delete result.metadata.serverTimeOffset; expect(result.finalKeyData.privKey).to.be.equal("066270dfa345d3d0415c8223e045f366b238b50870de7e9658e3c6608a7e2d32"); @@ -628,6 +659,7 @@ describe("torus utils sapphire devnet", function () { const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; const result = await torus.retrieveShares( torusNodeEndpoints, + nodeDetails.torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: email, idtoken: idToken }], diff --git a/test/sapphire_mainnet.test.ts b/test/sapphire_mainnet.test.ts index 895e188..559011b 100644 --- a/test/sapphire_mainnet.test.ts +++ b/test/sapphire_mainnet.test.ts @@ -31,8 +31,8 @@ describe("torus utils sapphire mainnet", function () { it("should fetch public address", async function () { const verifier = "tkey-google-sapphire-mainnet"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0x327b2742768B436d09153429E762FADB54413Ded"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -84,8 +84,8 @@ describe("torus utils sapphire mainnet", function () { const verifier = "tkey-google-sapphire-mainnet"; // any verifier const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(finalKeyData.evmAddress).to.not.equal(""); expect(finalKeyData.evmAddress).to.not.equal(null); expect(oAuthKeyData.evmAddress).to.not.equal(""); @@ -102,7 +102,7 @@ describe("torus utils sapphire mainnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: email, extendedVerifierId: tssVerifierId }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.not.equal(null); expect(result.oAuthKeyData.evmAddress).to.not.equal(null); expect(result.metadata.typeOfUser).to.equal("v2"); @@ -118,7 +118,7 @@ describe("torus utils sapphire mainnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: email, extendedVerifierId: tssVerifierId }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.be.equal("0x98EC5b049c5C0Dc818C69e95CF43534AEB80261A"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -154,6 +154,7 @@ describe("torus utils sapphire mainnet", function () { const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; const result = await torus.retrieveShares( torusNodeEndpoints, + nodeDetails.torusIndexes, TORUS_TEST_VERIFIER, { extended_verifier_id: tssVerifierId, verifier_id: email }, token @@ -169,7 +170,7 @@ describe("torus utils sapphire mainnet", function () { const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_TEST_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0xCb76F4C8cbAe524997787B57efeeD99f6D3BD5AB"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -202,7 +203,7 @@ describe("torus utils sapphire mainnet", function () { const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_TEST_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0xCb76F4C8cbAe524997787B57efeeD99f6D3BD5AB"); delete result.metadata.serverTimeOffset; @@ -236,7 +237,13 @@ describe("torus utils sapphire mainnet", function () { const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const result = await torus.retrieveShares(torusNodeEndpoints, HashEnabledVerifier, { verifier_id: TORUS_TEST_EMAIL }, token); + const result = await torus.retrieveShares( + torusNodeEndpoints, + nodeDetails.torusIndexes, + HashEnabledVerifier, + { verifier_id: TORUS_TEST_EMAIL }, + token + ); expect(result.finalKeyData.privKey).to.be.equal("13941ecd812b08d8a33a20bc975f0cd1c3f82de25b20c0c863ba5f21580b65f6"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -274,8 +281,8 @@ describe("torus utils sapphire mainnet", function () { it("should be able to login", async function () { const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); expect(result.finalKeyData.privKey).to.be.equal("dfb39b84e0c64b8c44605151bf8670ae6eda232056265434729b6a8a50fa3419"); expect(result.metadata.serverTimeOffset).lessThan(20); @@ -318,6 +325,7 @@ describe("torus utils sapphire mainnet", function () { const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; const result = await torus.retrieveShares( torusNodeEndpoints, + nodeDetails.torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: email, idtoken: idToken }], @@ -345,7 +353,13 @@ describe("torus utils sapphire mainnet", function () { const customSessionTime = 3600; TorusUtils.setSessionTime(customSessionTime); // 1hr - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + 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 })); diff --git a/test/testnet.test.ts b/test/testnet.test.ts index 6534fe2..719c67e 100644 --- a/test/testnet.test.ts +++ b/test/testnet.test.ts @@ -28,8 +28,8 @@ describe("torus utils migrated testnet on sapphire", function () { it("should fetch public address", async function () { const verifier = "google-lrc"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result.finalKeyData.evmAddress).to.equal("0x9bcBAde70546c0796c00323CD1b97fa0a425A506"); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -58,8 +58,8 @@ describe("torus utils migrated testnet on sapphire", function () { it("should fetch user type and public address", async function () { const verifier = "google-lrc"; // any verifier const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(result1.finalKeyData.evmAddress).to.equal("0xf5804f608C233b9cdA5952E46EB86C9037fd6842"); expect(result1.metadata.typeOfUser).to.equal("v2"); expect(result1.metadata.serverTimeOffset).lessThan(20); @@ -92,7 +92,7 @@ describe("torus utils migrated testnet on sapphire", function () { const v2Verifier = "tkey-google-lrc"; // 1/1 user const v2TestEmail = "somev2user@gmail.com"; - const result2 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result2 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2TestEmail, })) as TorusPublicKey; @@ -127,7 +127,7 @@ describe("torus utils migrated testnet on sapphire", function () { // 2/n user const v2nTestEmail = "caspertorus@gmail.com"; - const result3 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, { + const result3 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, { verifier: v2Verifier, verifierId: v2nTestEmail, })) as TorusPublicKey; @@ -163,8 +163,8 @@ describe("torus utils migrated testnet on sapphire", function () { const verifier = "google-lrc"; // any verifier const email = faker.internet.email(); const verifierDetails = { verifier, verifierId: email }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { finalKeyData, oAuthKeyData, metadata } = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(finalKeyData.evmAddress).to.not.equal(""); expect(finalKeyData.evmAddress).to.not.equal(null); expect(oAuthKeyData.evmAddress).to.not.equal(""); @@ -176,8 +176,8 @@ describe("torus utils migrated testnet on sapphire", function () { it("should be able to login", async function () { const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const result = await torus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const result = await torus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: TORUS_TEST_EMAIL }, token); expect(result.metadata.serverTimeOffset).lessThan(20); delete result.metadata.serverTimeOffset; @@ -208,9 +208,10 @@ describe("torus utils migrated testnet on sapphire", function () { const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256"); const hashedIdToken = keccak256(Buffer.from(idToken, "utf8")); const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: TORUS_TEST_EMAIL }; - const { torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result = await torus.retrieveShares( torusNodeEndpoints, + torusIndexes, TORUS_TEST_AGGREGATE_VERIFIER, { verify_params: [{ verifier_id: TORUS_TEST_EMAIL, idtoken: idToken }], @@ -259,9 +260,9 @@ describe("torus utils migrated testnet on sapphire", function () { enableOneKey: true, serverTimeOffset: -100, }); - const { torusNodeSSSEndpoints: torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const { torusNodeSSSEndpoints: torusNodeEndpoints, torusIndexes } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); try { - await legacyTorus.retrieveShares(torusNodeEndpoints, TORUS_TEST_VERIFIER, { verifier_id: email }, token); + await legacyTorus.retrieveShares(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: email }, token); fail("should not reach here"); } catch (err) { expect((err as { status: number }).status).to.equal(403); @@ -283,8 +284,8 @@ describe("torus utils migrated testnet on sapphire", function () { const email = "himanshu@tor.us"; const verifier = "google-lrc"; const verifierDetails = { verifier, verifierId: email }; - const { torusNodeSSSEndpoints: torusNodeEndpoints } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const response = await torus.getPublicAddress(torusNodeEndpoints, verifierDetails); + const { torusNodeSSSEndpoints: torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); + const response = await torus.getPublicAddress(torusNodeEndpoints, torusNodePub, verifierDetails); expect(response.metadata.typeOfUser).to.equal("v1"); clock.restore(); });