Skip to content

Commit

Permalink
fix node indexes response for existing users and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed Oct 13, 2023
1 parent 77efd29 commit 5fd70eb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 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
25 changes: 13 additions & 12 deletions test/cyan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,24 @@ 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 +198,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 @@ -215,7 +216,7 @@ describe("torus utils cyan", function () {
},
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 5fd70eb

Please sign in to comment.