From 360cbe8d509ff8e9bc4dccda2f6a53523fd1cb6e Mon Sep 17 00:00:00 2001 From: himanshu Date: Tue, 23 Jan 2024 09:51:56 +0530 Subject: [PATCH] fix nonce race conditions and threshold check --- src/helpers/common.ts | 15 ++-- src/helpers/nodeUtils.ts | 39 ++++++----- test/aqua.test.ts | 54 ++++++++------- test/cyan.test.ts | 17 +++-- test/mainnet.test.ts | 35 +++++----- test/sapphire_devnet.test.ts | 130 +++++++++++++++-------------------- 6 files changed, 142 insertions(+), 148 deletions(-) diff --git a/src/helpers/common.ts b/src/helpers/common.ts index 855c195..7d0e07e 100644 --- a/src/helpers/common.ts +++ b/src/helpers/common.ts @@ -13,13 +13,14 @@ export const normalizeKeysResult = (result: VerifierLookupResponse) => { is_new_key: result.is_new_key, }; if (result && result.keys && result.keys.length > 0) { - finalResult.keys = result.keys.map((key) => { - return { - pub_key_X: key.pub_key_X, - pub_key_Y: key.pub_key_Y, - address: key.address, - }; - }); + const finalKey = result.keys[0]; + finalResult.keys = [ + { + pub_key_X: finalKey.pub_key_X, + pub_key_Y: finalKey.pub_key_Y, + address: finalKey.address, + }, + ]; } return finalResult; }; diff --git a/src/helpers/nodeUtils.ts b/src/helpers/nodeUtils.ts index a0fbaaa..330257b 100644 --- a/src/helpers/nodeUtils.ts +++ b/src/helpers/nodeUtils.ts @@ -60,15 +60,6 @@ export const GetPubKeyOrKeyAssign = async (params: { const result = await Some, KeyLookupResult>(lookupPromises, (lookupResults) => { const lookupPubKeys = lookupResults.filter((x1) => { if (x1 && !x1.error) { - if (!nonceResult) { - // currently only one node returns metadata nonce - // other nodes returns empty object - // pubNonce must be available to derive the public key - const pubNonceX = (x1.result?.keys[0].nonce_data as v2NonceResultType)?.pubNonce?.x; - if (pubNonceX) { - nonceResult = x1.result.keys[0].nonce_data; - } - } return x1; } return false; @@ -83,8 +74,7 @@ export const GetPubKeyOrKeyAssign = async (params: { ~~(endpoints.length / 2) + 1 ); - // nonceResult must exist except for extendedVerifierId and legacy networks along with keyResult - if ((keyResult && (nonceResult || extendedVerifierId || LEGACY_NETWORKS_ROUTE_MAP[network as TORUS_LEGACY_NETWORK_TYPE])) || errorResult) { + if (keyResult || errorResult) { if (keyResult) { lookupResults.forEach((x1) => { if (x1 && x1.result) { @@ -96,6 +86,16 @@ export const GetPubKeyOrKeyAssign = async (params: { const nodeIndex = parseInt(x1.result.node_index); if (nodeIndex) nodeIndexes.push(nodeIndex); } + // check for nonce result in response if not a extendedVerifierId and not a legacy network + if (!extendedVerifierId && !LEGACY_NETWORKS_ROUTE_MAP[network as TORUS_LEGACY_NETWORK_TYPE] && !nonceResult) { + // currently only one node returns metadata nonce + // other nodes returns empty object + // pubNonce must be available to derive the public key + const pubNonceX = (x1.result?.keys[0].nonce_data as v2NonceResultType)?.pubNonce?.x; + if (pubNonceX && currentNodePubKey === thresholdPubKey) { + nonceResult = x1.result.keys[0].nonce_data; + } + } } }); } @@ -321,12 +321,6 @@ export async function retrieveOrImportShare(params: { }); const pubkeys = shareResponses.map((x) => { if (x && x.result && x.result.keys[0].public_key) { - if (!thresholdNonceData && !verifierParams.extended_verifier_id) { - const pubNonce = (x.result.keys[0].nonce_data as v2NonceResultType)?.pubNonce?.x; - if (pubNonce) { - thresholdNonceData = x.result.keys[0].nonce_data; - } - } return x.result.keys[0].public_key; } return undefined; @@ -338,6 +332,17 @@ export async function retrieveOrImportShare(params: { throw new Error("invalid result from nodes, threshold number of public key results are not matching"); } + shareResponses.forEach((x) => { + const requiredShareResponse = x && x.result && x.result.keys[0].public_key && x.result.keys[0]; + if (requiredShareResponse && !thresholdNonceData && !verifierParams.extended_verifier_id) { + const currentPubKey = requiredShareResponse.public_key; + const pubNonce = (requiredShareResponse.nonce_data as v2NonceResultType)?.pubNonce?.x; + if (pubNonce && currentPubKey.X === thresholdPublicKey.X) { + thresholdNonceData = requiredShareResponse.nonce_data; + } + } + }); + // if both thresholdNonceData and extended_verifier_id are not available // then we need to throw other wise address would be incorrect. if (!thresholdNonceData && !verifierParams.extended_verifier_id && !LEGACY_NETWORKS_ROUTE_MAP[network as TORUS_LEGACY_NETWORK_TYPE]) { diff --git a/test/aqua.test.ts b/test/aqua.test.ts index 4358388..9d35806 100644 --- a/test/aqua.test.ts +++ b/test/aqua.test.ts @@ -55,8 +55,7 @@ describe("torus utils aqua", function () { const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result1 = (await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails)) as TorusPublicKey; - expect(result1.finalKeyData.evmAddress).to.equal("0x79F06350eF34Aeed4BE68e26954D405D573f1438"); - expect(result1.metadata.typeOfUser).to.equal("v1"); + expect(result1.metadata.typeOfUser).to.equal("v2"); expect(result1).eql({ oAuthKeyData: { evmAddress: "0xDfA967285AC699A70DA340F60d00DB19A272639d", @@ -64,15 +63,18 @@ describe("torus utils aqua", function () { Y: "f76933cbf5fe2916681075bb6cb4cde7d5f6b6ce290071b1b7106747d906457c", }, finalKeyData: { - evmAddress: "0xDfA967285AC699A70DA340F60d00DB19A272639d", - X: "4fc8db5d3fe164a3ab70fd6348721f2be848df2cc02fd2db316a154855a7aa7d", - Y: "f76933cbf5fe2916681075bb6cb4cde7d5f6b6ce290071b1b7106747d906457c", + evmAddress: "0x79F06350eF34Aeed4BE68e26954D405D573f1438", + X: "99df45abc8e6ee03d2f94df33be79e939eadfbed20c6b88492782fdc3ef1dfd3", + Y: "12bf3e54599a177fdb88f8b22419df7ddf1622e1d2344301edbe090890a72b16", }, metadata: { - pubNonce: undefined, + pubNonce: { + X: "dc5a031fd2e0b55dbaece314ea125bac9da5f0a916bf156ff36b5ad71380ea32", + Y: "affd749b98c209d2f9cf4dacb145d7897f82f1e2924a47b07874302ecc0b8ef1", + }, nonce: new BN(0), upgraded: false, - typeOfUser: "v1", + typeOfUser: "v2", }, nodesData: result1.nodesData, }); @@ -84,24 +86,26 @@ describe("torus utils aqua", function () { verifier: v2Verifier, verifierId: v2TestEmail, })) as TorusPublicKey; - expect(result2.finalKeyData.evmAddress).to.equal("0x5735dDC8d5125B23d77C3531aab3895A533584a3"); - expect(result2.metadata.typeOfUser).to.equal("v1"); + expect(result2.metadata.typeOfUser).to.equal("v2"); expect(result2).eql({ oAuthKeyData: { - evmAddress: "0x5735dDC8d5125B23d77C3531aab3895A533584a3", - X: "e1b419bc52b82e14b148c307f10479cfa464d20c947555fb4758c586eab12873", - Y: "75f47d7d5a271c0fcf51a790c1683a1cb3394b1d37d20e29c346ac249e3bfca2", + evmAddress: "0x4ea5260fF85678A2a326D08DF9C44d1f559a5828", + X: "0e6febe33a9d4eeb680cc6b63ff6237ad1971f27adcd7f104a3b1de18eda9337", + Y: "a5a915561f3543688e71281a850b9ee10b9690f305d9e79028dfc8359192b82d", }, finalKeyData: { - evmAddress: "0x5735dDC8d5125B23d77C3531aab3895A533584a3", - X: "e1b419bc52b82e14b148c307f10479cfa464d20c947555fb4758c586eab12873", - Y: "75f47d7d5a271c0fcf51a790c1683a1cb3394b1d37d20e29c346ac249e3bfca2", + evmAddress: "0xBc32f315515AdE7010cabC5Fd68c966657A570BD", + X: "4897f120584ee18a72b9a6bb92c3ef6e45fc5fdff70beae7dc9325bd01332022", + Y: "2066dbef2fcdded4573e3c04d1c04edd5d44662168e636ed9d0b0cbe2e67c968", }, metadata: { - pubNonce: undefined, + pubNonce: { + X: "1601cf4dc4362b219260663d5ec5119699fbca185d08b7acb2e36cad914340d5", + Y: "c2f7871f61ee71b4486ac9fb40ec759099800e737139dc5dfaaaed8c9d77c3c1", + }, nonce: new BN(0), upgraded: false, - typeOfUser: "v1", + typeOfUser: "v2", }, nodesData: result2.nodesData, }); @@ -112,8 +116,7 @@ describe("torus utils aqua", function () { verifier: v2Verifier, verifierId: v2nTestEmail, })) as TorusPublicKey; - expect(result3.finalKeyData.evmAddress).to.equal("0x4ce0D09C3989eb3cC9372cC27fa022D721D737dD"); - expect(result3.metadata.typeOfUser).to.equal("v1"); + expect(result3.metadata.typeOfUser).to.equal("v2"); expect(result3).eql({ oAuthKeyData: { evmAddress: "0x4ce0D09C3989eb3cC9372cC27fa022D721D737dD", @@ -121,15 +124,18 @@ describe("torus utils aqua", function () { Y: "b33b35148d72d357070f66372e07fec436001bdb15c098276b120b9ed64c1e5f", }, finalKeyData: { - evmAddress: "0x4ce0D09C3989eb3cC9372cC27fa022D721D737dD", - X: "e76d2f7fa2c0df324b4ab74629c3af47aa4609c35f1d2b6b90b77a47ab9a1281", - Y: "b33b35148d72d357070f66372e07fec436001bdb15c098276b120b9ed64c1e5f", + evmAddress: "0x5469C5aCB0F30929226AfF4622918DA8E1424a8D", + X: "c20fac685bb67169e92f1d5d8894d4eea18753c0ef3b7b1b2224233b2dfa3539", + Y: "c4f080b5c8d5c55c8eaba4bec70f668f36db4126f358b491d631fefea7c19d21", }, metadata: { - pubNonce: undefined, + pubNonce: { + X: "17b1ebce1fa874452a96d0c6d74c1445b78f16957c7decc5d2a202b0ce4662f5", + Y: "b5432cb593753e1b3ecf98b05dc03e57bc02c415e1b80a1ffc5a401ec1f0abd6", + }, nonce: new BN(0), upgraded: false, - typeOfUser: "v1", + typeOfUser: "v2", }, nodesData: result3.nodesData, }); diff --git a/test/cyan.test.ts b/test/cyan.test.ts index a972be0..5d3ec91 100644 --- a/test/cyan.test.ts +++ b/test/cyan.test.ts @@ -55,8 +55,8 @@ describe("torus utils cyan", function () { const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails); - expect(result1.finalKeyData.evmAddress).to.equal("0xA3767911A84bE6907f26C572bc89426dDdDB2825"); - expect(result1.metadata.typeOfUser).to.equal("v1"); + expect(result1.finalKeyData.evmAddress).to.equal("0x3507F0d192a44E436B8a6C32a37d57D022861b1a"); + expect(result1.metadata.typeOfUser).to.equal("v2"); expect(result1).eql({ oAuthKeyData: { evmAddress: "0xA3767911A84bE6907f26C572bc89426dDdDB2825", @@ -64,15 +64,18 @@ describe("torus utils cyan", function () { Y: "f026b4788e23523e0c8fcbf0bdcf1c1a62c9cde8f56170309607a7a52a19f7c1", }, finalKeyData: { - evmAddress: "0xA3767911A84bE6907f26C572bc89426dDdDB2825", - X: "2853f323437da98ce021d06854f4b292db433c0ad03b204ef223ac2583609a6a", - Y: "f026b4788e23523e0c8fcbf0bdcf1c1a62c9cde8f56170309607a7a52a19f7c1", + evmAddress: "0x3507F0d192a44E436B8a6C32a37d57D022861b1a", + X: "8aaadab9530cb157d0b0dfb7b27d1a3aaca45274563c22c92c77ee2191779051", + Y: "d57b89d9f62bb6609d8542c3057943805c8c72f6f27d39781b820f27d7210f12", }, metadata: { - pubNonce: undefined, + pubNonce: { + X: "5f2505155e2c1119ee8a76d0f3b22fccee45871d4aab3cb6209bdbc302b5abc2", + Y: "a20f30868759a6095697d5631483faa650f489b33c0e2958ad8dc29e707c0a99", + }, nonce: new BN(0), upgraded: false, - typeOfUser: "v1", + typeOfUser: "v2", }, nodesData: result1.nodesData, }); diff --git a/test/mainnet.test.ts b/test/mainnet.test.ts index 07ab1cc..1a94a19 100644 --- a/test/mainnet.test.ts +++ b/test/mainnet.test.ts @@ -55,8 +55,7 @@ describe("torus utils mainnet", function () { const verifierDetails = { verifier, verifierId: TORUS_TEST_EMAIL }; const { torusNodeEndpoints, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const result1 = await torus.getUserTypeAndAddress(torusNodeEndpoints, torusNodePub, verifierDetails); - expect(result1.finalKeyData.evmAddress).to.equal("0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A"); - expect(result1.metadata.typeOfUser).to.equal("v1"); + expect(result1.metadata.typeOfUser).to.equal("v2"); expect(result1).eql({ oAuthKeyData: { evmAddress: "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A", @@ -64,15 +63,18 @@ describe("torus utils mainnet", function () { Y: "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1", }, finalKeyData: { - evmAddress: "0x0C44AFBb5395a9e8d28DF18e1326aa0F16b9572A", - X: "3b5655d78978b6fd132562b5cb66b11bcd868bd2a9e16babe4a1ca50178e57d4", - Y: "15338510798d6b55db28c121d86babcce19eb9f1882f05fae8ee9b52ed09e8f1", + evmAddress: "0xb2e1c3119f8D8E73de7eaF7A535FB39A3Ae98C5E", + X: "072beda348a832aed06044a258cb6a8d428ec7c245c5da92db5da4f3ab433e55", + Y: "54ace0d3df2504fa29f17d424a36a0f92703899fad0afee93d010f6d84b310e5", }, metadata: { - pubNonce: undefined, + pubNonce: { + X: "eb22d93244acf7fcbeb6566da722bc9c8e5433cd28da25ca0650d9cb32806c39", + Y: "765541e214f067cfc44dcf41e582ae09b71c2e607a301cc8a45e1f316a6ba91c", + }, nonce: new BN(0), upgraded: false, - typeOfUser: "v1", + typeOfUser: "v2", }, nodesData: result1.nodesData, }); @@ -115,8 +117,7 @@ describe("torus utils mainnet", function () { verifier: v2Verifier, verifierId: v2nTestEmail, }); - expect(result3.finalKeyData.evmAddress).to.equal("0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53"); - expect(result3.metadata.typeOfUser).to.equal("v1"); + expect(result3.metadata.typeOfUser).to.equal("v2"); expect(result3).eql({ oAuthKeyData: { evmAddress: "0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53", @@ -124,15 +125,18 @@ describe("torus utils mainnet", function () { Y: "cb3937773bb819d60b780b6d4c2edcf27c0f7090ba1fc2ff42504a8138a8e2d7", }, finalKeyData: { - evmAddress: "0x61E52B6e488EC3dD6FDc0F5ed04a62Bb9c6BeF53", - X: "c01282dd68d2341031a1cff06f70d821cad45140f425f1c25055a8aa64959df8", - Y: "cb3937773bb819d60b780b6d4c2edcf27c0f7090ba1fc2ff42504a8138a8e2d7", + evmAddress: "0x40A4A04fDa1f29a3667152C8830112FBd6A77BDD", + X: "6779af3031d9e9eec6b4133b0ae13e367c83a614f92d2008e10c7f3b8e6723bc", + Y: "80edc4502abdfb220dd6e2fcfa2dbb058125dc95873e4bfa6877f9c26da7fdff", }, metadata: { - pubNonce: undefined, + pubNonce: { + X: "16214bf232167258fb5f98fa9d84968ffec3236aaf0994fc366940c4bc07a5b1", + Y: "475e8c09d2cc8f6c12a767f51c052b1bf8e8d3a2a2b6818d4b199dc283e80ac4", + }, nonce: new BN(0), upgraded: false, - typeOfUser: "v1", + typeOfUser: "v2", }, nodesData: result3.nodesData, }); @@ -159,9 +163,6 @@ describe("torus utils mainnet", function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL }; 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.oAuthKeyData.evmAddress).to.be.equal("0x90A926b698047b4A87265ba1E9D8b512E8489067"); - expect(result.finalKeyData.privKey).to.be.equal("0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44"); - expect(result.finalKeyData.evmAddress).to.be.equal("0x90A926b698047b4A87265ba1E9D8b512E8489067"); delete result.sessionData; expect(result).eql({ diff --git a/test/sapphire_devnet.test.ts b/test/sapphire_devnet.test.ts index bd05d64..41d8de4 100644 --- a/test/sapphire_devnet.test.ts +++ b/test/sapphire_devnet.test.ts @@ -9,8 +9,10 @@ import { keccak256 } from "../src"; import TorusUtils from "../src/torus"; import { generateIdToken, lookupVerifier } from "./helpers"; -const TORUS_TEST_EMAIL = "saasas@tr.us"; -const TORUS_IMPORT_EMAIL = "importeduser5@tor.us"; +const TORUS_TEST_EMAIL = "devnettestuser@tor.us"; +const TORUS_HASH_ENABLED_TEST_EMAIL = "saasas@tr.us"; + +const TORUS_IMPORT_EMAIL = "Sydnie.Lehner73@yahoo.com"; const TORUS_EXTENDED_VERIFIER_EMAIL = "testextenderverifierid@example.com"; @@ -201,22 +203,21 @@ describe("torus utils sapphire devnet", function () { const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); - expect(result.finalKeyData.evmAddress).to.equal("0x4924F91F5d6701dDd41042D94832bB17B76F316F"); expect(result).eql({ oAuthKeyData: { - evmAddress: "0xac997dE675Fb69FCb0F4115A23c0061A892A2772", - X: "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528", - Y: "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe", + evmAddress: "0x137B3607958562D03Eb3C6086392D1eFa01aA6aa", + X: "118a674da0c68f16a1123de9611ba655f4db1e336fe1b2d746028d65d22a3c6b", + Y: "8325432b3a3418d632b4fe93db094d6d83250eea60fe512897c0ad548737f8a5", }, finalKeyData: { - evmAddress: "0x4924F91F5d6701dDd41042D94832bB17B76F316F", - X: "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff", - Y: "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd", + evmAddress: "0x462A8BF111A55C9354425F875F89B22678c0Bc44", + X: "36e257717f746cdd52ba85f24f7c9040db8977d3b0354de70ed43689d24fa1b1", + Y: "58ec9768c2fe871b3e2a83cdbcf37ba6a88ad19ec2f6e16a66231732713fd507", }, metadata: { pubNonce: { - X: "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c", - Y: "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7", + X: "5d03a0df9b3db067d3363733df134598d42873bb4730298a53ee100975d703cc", + Y: "279434dcf0ff22f077877a70bcad1732412f853c96f02505547f7ca002b133ed", }, nonce: new BN("0"), upgraded: false, @@ -225,8 +226,7 @@ describe("torus utils sapphire devnet", function () { nodesData: result.nodesData, }); }); - // we are working on a new implementation for import sss keys, so skipping it for now. - it.skip("should fetch public address of imported user", async function () { + it("should fetch public address of imported user", async function () { const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_IMPORT_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; @@ -257,22 +257,21 @@ describe("torus utils sapphire devnet", function () { const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); - expect(result.finalKeyData.evmAddress).to.equal("0x4924F91F5d6701dDd41042D94832bB17B76F316F"); expect(result).eql({ oAuthKeyData: { - evmAddress: "0xac997dE675Fb69FCb0F4115A23c0061A892A2772", - X: "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528", - Y: "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe", + evmAddress: "0x137B3607958562D03Eb3C6086392D1eFa01aA6aa", + X: "118a674da0c68f16a1123de9611ba655f4db1e336fe1b2d746028d65d22a3c6b", + Y: "8325432b3a3418d632b4fe93db094d6d83250eea60fe512897c0ad548737f8a5", }, finalKeyData: { - evmAddress: "0x4924F91F5d6701dDd41042D94832bB17B76F316F", - X: "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff", - Y: "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd", + evmAddress: "0x462A8BF111A55C9354425F875F89B22678c0Bc44", + X: "36e257717f746cdd52ba85f24f7c9040db8977d3b0354de70ed43689d24fa1b1", + Y: "58ec9768c2fe871b3e2a83cdbcf37ba6a88ad19ec2f6e16a66231732713fd507", }, metadata: { pubNonce: { - X: "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c", - Y: "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7", + X: "5d03a0df9b3db067d3363733df134598d42873bb4730298a53ee100975d703cc", + Y: "279434dcf0ff22f077877a70bcad1732412f853c96f02505547f7ca002b133ed", }, nonce: new BN("0"), upgraded: false, @@ -283,7 +282,7 @@ describe("torus utils sapphire devnet", function () { }); it("should be able to key assign", async function () { - const email = faker.internet.email(); + const email = `${faker.internet.email()}`; const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: email }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; @@ -303,19 +302,18 @@ describe("torus utils sapphire devnet", function () { { verifier_id: TORUS_TEST_EMAIL }, token ); - expect(result.finalKeyData.privKey).to.be.equal("04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c"); expect(result).eql({ finalKeyData: { - evmAddress: "0x4924F91F5d6701dDd41042D94832bB17B76F316F", - X: "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff", - Y: "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd", - privKey: "04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c", + evmAddress: "0x462A8BF111A55C9354425F875F89B22678c0Bc44", + X: "36e257717f746cdd52ba85f24f7c9040db8977d3b0354de70ed43689d24fa1b1", + Y: "58ec9768c2fe871b3e2a83cdbcf37ba6a88ad19ec2f6e16a66231732713fd507", + privKey: "230dad9f42039569e891e6b066ff5258b14e9764ef5176d74aeb594d1a744203", }, oAuthKeyData: { - evmAddress: "0xac997dE675Fb69FCb0F4115A23c0061A892A2772", - X: "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528", - Y: "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe", - privKey: "cd7d1dc7aec71fd2ee284890d56ac34d375bbc15ff41a1d87d088170580b9b0f", + evmAddress: "0x137B3607958562D03Eb3C6086392D1eFa01aA6aa", + X: "118a674da0c68f16a1123de9611ba655f4db1e336fe1b2d746028d65d22a3c6b", + Y: "8325432b3a3418d632b4fe93db094d6d83250eea60fe512897c0ad548737f8a5", + privKey: "6b3c872a269aa8994a5acc8cdd70ea3d8d182d42f8af421c0c39ea124e9b66fa", }, sessionData: { sessionTokenData: result.sessionData.sessionTokenData, @@ -323,10 +321,10 @@ describe("torus utils sapphire devnet", function () { }, metadata: { pubNonce: { - X: "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c", - Y: "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7", + X: "5d03a0df9b3db067d3363733df134598d42873bb4730298a53ee100975d703cc", + Y: "279434dcf0ff22f077877a70bcad1732412f853c96f02505547f7ca002b133ed", }, - nonce: new BN("376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e", "hex"), + nonce: new BN("b7d126751b68ecd09e371a23898e6819dee54708a5ead4f6fe83cdc79c0f1c4a", "hex"), typeOfUser: "v2", upgraded: false, }, @@ -346,19 +344,18 @@ describe("torus utils sapphire devnet", function () { { verifier_id: TORUS_TEST_EMAIL }, token ); - expect(result.finalKeyData.privKey).to.be.equal("04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c"); expect(result).eql({ finalKeyData: { - evmAddress: "0x4924F91F5d6701dDd41042D94832bB17B76F316F", - X: "f3eaf63bf1fd645d4159832ccaad7f42457e287ac929363ba636eb7e87978bff", - Y: "f3b9d8dd91927a89ec45199ad697fe3fa01b8b836710143a0babb1a4eb35f1cd", - privKey: "04eb166ddcf59275a210c7289dca4a026f87a33fd2d6ed22f56efae7eab4052c", + evmAddress: "0x462A8BF111A55C9354425F875F89B22678c0Bc44", + X: "36e257717f746cdd52ba85f24f7c9040db8977d3b0354de70ed43689d24fa1b1", + Y: "58ec9768c2fe871b3e2a83cdbcf37ba6a88ad19ec2f6e16a66231732713fd507", + privKey: "230dad9f42039569e891e6b066ff5258b14e9764ef5176d74aeb594d1a744203", }, oAuthKeyData: { - evmAddress: "0xac997dE675Fb69FCb0F4115A23c0061A892A2772", - X: "9508a251dfc4146a132feb96111c136538f4fabd20fc488dbcaaf762261c1528", - Y: "f9128bc7403bab6d45415cad01dd0ba0924628cfb6bf51c17e77aa8ca43b3cfe", - privKey: "cd7d1dc7aec71fd2ee284890d56ac34d375bbc15ff41a1d87d088170580b9b0f", + evmAddress: "0x137B3607958562D03Eb3C6086392D1eFa01aA6aa", + X: "118a674da0c68f16a1123de9611ba655f4db1e336fe1b2d746028d65d22a3c6b", + Y: "8325432b3a3418d632b4fe93db094d6d83250eea60fe512897c0ad548737f8a5", + privKey: "6b3c872a269aa8994a5acc8cdd70ea3d8d182d42f8af421c0c39ea124e9b66fa", }, sessionData: { sessionTokenData: result.sessionData.sessionTokenData, @@ -366,19 +363,20 @@ describe("torus utils sapphire devnet", function () { }, metadata: { pubNonce: { - X: "78a88b99d960808543e75076529c913c1678bc7fafbb943f1ce58235fd2f4e0c", - Y: "6b451282135dfacd22561e0fb5bf21aea7b1f26f2442164b82b0e4c8f152f7a7", + X: "5d03a0df9b3db067d3363733df134598d42873bb4730298a53ee100975d703cc", + Y: "279434dcf0ff22f077877a70bcad1732412f853c96f02505547f7ca002b133ed", }, - nonce: new BN("376df8a62e2e72a2b3e87e97c85f86b3f2dac41082ddeb863838d80462deab5e", "hex"), + nonce: new BN("b7d126751b68ecd09e371a23898e6819dee54708a5ead4f6fe83cdc79c0f1c4a", "hex"), typeOfUser: "v2", upgraded: false, }, nodesData: result.nodesData, }); }); - it("should be able to import a key for a new user", async function () { + 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"); + const privKeyBuffer = generatePrivate(); const privHex = privKeyBuffer.toString("hex"); const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails({ verifier: TORUS_TEST_VERIFIER, verifierId: email }); @@ -393,27 +391,8 @@ describe("torus utils sapphire devnet", function () { privHex ); expect(result.finalKeyData.privKey).to.be.equal(privHex); - }); - it.skip("should be able to import a key for a existing user", async function () { - let verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_IMPORT_EMAIL }; - const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); - const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; - const token = generateIdToken(TORUS_IMPORT_EMAIL, "ES256"); - const privKeyBuffer = generatePrivate(); - const privHex = privKeyBuffer.toString("hex"); - const result1 = await torus.importPrivateKey( - torusNodeEndpoints, - nodeDetails.torusIndexes, - nodeDetails.torusNodePub, - TORUS_TEST_VERIFIER, - { verifier_id: TORUS_IMPORT_EMAIL }, - token, - privHex - ); - expect(result1.finalKeyData.privKey).to.be.equal(privHex); - verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_IMPORT_EMAIL }; - const result2 = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); - expect(result1.finalKeyData.evmAddress).to.be.equal(result2.finalKeyData.evmAddress); + const result1 = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, { verifier: TORUS_TEST_VERIFIER, verifierId: email }); + expect(result1.finalKeyData.evmAddress).to.be.equal(result.finalKeyData.evmAddress); }); it("should fetch pub address of tss verifier id", async function () { @@ -425,7 +404,6 @@ describe("torus utils sapphire devnet", function () { const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; const result = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails); - expect(result.finalKeyData.evmAddress).to.be.equal("0xBd6Bc8aDC5f2A0526078Fd2016C4335f64eD3a30"); expect(result).eql({ oAuthKeyData: { evmAddress: "0xBd6Bc8aDC5f2A0526078Fd2016C4335f64eD3a30", @@ -485,7 +463,7 @@ describe("torus utils sapphire devnet", function () { }); it("should fetch public address when verifierID hash enabled", async function () { - const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_TEST_EMAIL }; + 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, nodeDetails.torusNodePub, verifierDetails); @@ -516,7 +494,7 @@ describe("torus utils sapphire devnet", function () { // to do: update pub keys it.skip("should lookup return hash when verifierID hash enabled", async function () { - const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails({ verifier: HashEnabledVerifier, verifierId: TORUS_TEST_VERIFIER }); + const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails({ verifier: HashEnabledVerifier, verifierId: TORUS_HASH_ENABLED_TEST_EMAIL }); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; for (const endpoint of torusNodeEndpoints) { const pubKeyX = "21cd0ae3168d60402edb8bd65c58ff4b3e0217127d5bb5214f03f84a76f24d8a"; @@ -528,7 +506,7 @@ describe("torus utils sapphire devnet", function () { }); it("should fetch user type and public address when verifierID hash enabled", async function () { - const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_TEST_EMAIL }; + 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, nodeDetails.torusNodePub, verifierDetails); @@ -557,8 +535,8 @@ describe("torus utils sapphire devnet", function () { }); }); it("should be able to login when verifierID hash enabled", async function () { - const token = generateIdToken(TORUS_TEST_EMAIL, "ES256"); - const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_TEST_EMAIL }; + const token = generateIdToken(TORUS_HASH_ENABLED_TEST_EMAIL, "ES256"); + const verifierDetails = { verifier: HashEnabledVerifier, verifierId: TORUS_HASH_ENABLED_TEST_EMAIL }; const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails); const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints; @@ -566,7 +544,7 @@ describe("torus utils sapphire devnet", function () { torusNodeEndpoints, nodeDetails.torusIndexes, HashEnabledVerifier, - { verifier_id: TORUS_TEST_EMAIL }, + { verifier_id: TORUS_HASH_ENABLED_TEST_EMAIL }, token ); expect(result.finalKeyData.privKey).to.be.equal("066270dfa345d3d0415c8223e045f366b238b50870de7e9658e3c6608a7e2d32");