Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix node indexes response for existing users #122

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions test/mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ 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 @@ -175,9 +177,8 @@ describe("torus utils mainnet", function () {
Y: "0ad1ffaecb2178b02a37c455975368be9b967ead1b281202cc8d48c77618bff1",
privKey: "0129494416ab5d5f674692b39fa49680e07d3aac01b9683ee7650e40805d4c44",
},
sessionData: { sessionTokenData: [], sessionAuthKey: "" },
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: { nodeIndexes: [] },
nodesData: { nodeIndexes: result.nodesData.nodeIndexes },
});
});

Expand Down
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