Skip to content

Commit

Permalink
Merge pull request #123 from torusresearch/fix/node_index
Browse files Browse the repository at this point in the history
Fix/node index
  • Loading branch information
chaitanyapotti authored Oct 13, 2023
2 parents 77efd29 + 5a379fc commit 545b9c9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 31 deletions.
10 changes: 8 additions & 2 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ export const GetPubKeyOrKeyAssign = async (params: {
if (keyResult) {
lookupResults.forEach((x1) => {
if (x1 && x1.result) {
const nodeIndex = parseInt(x1.result.node_index);
if (nodeIndex) nodeIndexes.push(nodeIndex);
const currentNodePubKey = x1.result.keys[0].pub_key_X.toLowerCase();
const thresholdPubKey = keyResult.keys[0].pub_key_X.toLowerCase();
// push only those indexes for nodes who are returning pub key matching with threshold pub key.
// this check is important when different nodes have different keys assigned to a user.
if (currentNodePubKey === thresholdPubKey) {
const nodeIndex = parseInt(x1.result.node_index);
if (nodeIndex) nodeIndexes.push(nodeIndex);
}
}
});
}
Expand Down
35 changes: 17 additions & 18 deletions test/cyan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand Down Expand Up @@ -76,7 +76,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v1",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result1.nodesData.nodeIndexes },
});

const v2Verifier = "tkey-google-cyan";
Expand Down Expand Up @@ -108,7 +108,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result2.nodesData.nodeIndexes },
});
// 2/n user
const v2nTestEmail = "[email protected]";
Expand Down Expand Up @@ -138,7 +138,7 @@ describe("torus utils cyan", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result3.nodesData.nodeIndexes },
});
});

Expand All @@ -161,23 +161,23 @@ describe("torus utils cyan", 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.finalKeyData.privKey).to.be.equal("1e0c955d73e73558f46521da55cc66de7b8fcb56c5b24e851616849b6a1278c8");
delete result.sessionData;
expect(result.finalKeyData.privKey).to.be.equal("5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8");
expect(result).eql({
finalKeyData: {
evmAddress: "0x8AA6C8ddCD868873120aA265Fc63E3a2180375BA",
X: "35739417e3be1b1e56cdf8c509d8dee5412712514b18df1bc961ac6465a0c949",
Y: "887497602e62ced686eb99eaa0020b0c0d705cad96eafeec2dd1bbfb6a9d42c2",
privKey: "1e0c955d73e73558f46521da55cc66de7b8fcb56c5b24e851616849b6a1278c8",
X: "e2ed6033951af2851d1bea98799e62fb1ff24b952c1faea17922684678ba42d1",
Y: "beef0efad88e81385952c0068ca48e8b9c2121be87cb0ddf18a68806db202359",
evmAddress: "0xC615aA03Dd8C9b2dc6F7c43cBDfF2c34bBa47Ec9",
privKey: "5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8",
},
oAuthKeyData: {
evmAddress: "0x8AA6C8ddCD868873120aA265Fc63E3a2180375BA",
X: "35739417e3be1b1e56cdf8c509d8dee5412712514b18df1bc961ac6465a0c949",
Y: "887497602e62ced686eb99eaa0020b0c0d705cad96eafeec2dd1bbfb6a9d42c2",
privKey: "1e0c955d73e73558f46521da55cc66de7b8fcb56c5b24e851616849b6a1278c8",
X: "e2ed6033951af2851d1bea98799e62fb1ff24b952c1faea17922684678ba42d1",
Y: "beef0efad88e81385952c0068ca48e8b9c2121be87cb0ddf18a68806db202359",
evmAddress: "0xC615aA03Dd8C9b2dc6F7c43cBDfF2c34bBa47Ec9",
privKey: "5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8",
},
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand All @@ -197,7 +197,7 @@ describe("torus utils cyan", function () {
},
hashedIdToken.substring(2)
);

delete result.sessionData;
expect(result.oAuthKeyData.evmAddress).to.be.equal("0x34117FDFEFBf1ad2DFA6d4c43804E6C710a6fB04");
expect(result.finalKeyData.evmAddress).to.be.equal("0x34117FDFEFBf1ad2DFA6d4c43804E6C710a6fB04");
expect(result).eql({
Expand All @@ -213,9 +213,8 @@ describe("torus utils cyan", function () {
Y: "e557a5ee879632727f5979d6b9cea69d87e3dab54a8c1b6685d86dfbfcd785dd",
privKey: "45a5b62c4ff5490baa75d33bf4f03ba6c5b0095678b0f4055312eef7b780b7bf",
},
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});
});
6 changes: 4 additions & 2 deletions test/mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe("torus utils mainnet", function () {
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({
finalKeyData: {
evmAddress: "0x90A926b698047b4A87265ba1E9D8b512E8489067",
Expand All @@ -177,7 +178,7 @@ describe("torus utils mainnet", function () {
},
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand All @@ -199,6 +200,7 @@ describe("torus utils mainnet", function () {
);
expect(result.oAuthKeyData.evmAddress).to.be.equal("0x621a4d458cFd345dAE831D9E756F10cC40A50381");
expect(result.finalKeyData.evmAddress).to.be.equal("0x621a4d458cFd345dAE831D9E756F10cC40A50381");
delete result.sessionData;
expect(result).eql({
finalKeyData: {
evmAddress: "0x621a4d458cFd345dAE831D9E756F10cC40A50381",
Expand All @@ -214,7 +216,7 @@ describe("torus utils mainnet", function () {
},
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});
});
13 changes: 7 additions & 6 deletions test/sapphire_devnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ describe("torus utils sapphire", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});
it("should fetch public address of imported user", async function () {
// 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 () {
const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_IMPORT_EMAIL };
const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints;
Expand Down Expand Up @@ -281,7 +282,7 @@ describe("torus utils sapphire", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand Down Expand Up @@ -446,7 +447,7 @@ describe("torus utils sapphire", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});
it("should assign key to tss verifier id", async function () {
Expand Down Expand Up @@ -513,7 +514,7 @@ describe("torus utils sapphire", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand Down Expand Up @@ -556,7 +557,7 @@ describe("torus utils sapphire", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});
it("should be able to login when verifierID hash enabled", async function () {
Expand Down
6 changes: 3 additions & 3 deletions test/sapphire_mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe("torus utils sapphire mainnet", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand Down Expand Up @@ -207,7 +207,7 @@ describe("torus utils sapphire mainnet", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand Down Expand Up @@ -237,7 +237,7 @@ describe("torus utils sapphire mainnet", function () {
upgraded: false,
typeOfUser: "v2",
},
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});
it("should be able to login when verifierID hash enabled", async function () {
Expand Down

0 comments on commit 545b9c9

Please sign in to comment.