Skip to content

Commit

Permalink
Merge branch 'master' into fix/bs58
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed Aug 5, 2024
2 parents f2f11dc + 8cb3ed6 commit 1eea8b8
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@toruslabs/torus.js",
"version": "15.0.0-alpha.1",
"version": "15.0.0",
"description": "Handle communication with torus nodes",
"main": "dist/lib.cjs/index.js",
"module": "dist/lib.esm/index.js",
Expand Down
140 changes: 140 additions & 0 deletions test/sapphire_devnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,144 @@ describe("torus utils sapphire devnet", function () {
expect(result.metadata.nonce).to.not.equal(null);
expect(result.metadata.upgraded).to.equal(false);
});

it("should be able to login with different accounts and get different addresses for each", async function () {
const email1 = faker.internet.email();
const email2 = faker.internet.email();

const idToken1 = generateIdToken(email1, "ES256");
const idToken2 = generateIdToken(email2, "ES256");
const hashedIdToken1 = keccak256(Buffer.from(idToken1, "utf8"));
const hashedIdToken2 = keccak256(Buffer.from(idToken2, "utf8"));
const verifierDetails1 = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email1 };
const verifierDetails2 = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email2 };

const nodeDetails1 = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails1);
const nodeDetails2 = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails2);
const torusNodeEndpoints1 = nodeDetails1.torusNodeSSSEndpoints;
const torusNodeEndpoints2 = nodeDetails1.torusNodeSSSEndpoints;
const result1 = await torus.retrieveShares(
torusNodeEndpoints1,
nodeDetails1.torusIndexes,
TORUS_TEST_AGGREGATE_VERIFIER,
{
verify_params: [{ verifier_id: email1, idtoken: idToken1 }],
sub_verifier_ids: [TORUS_TEST_VERIFIER],
verifier_id: email1,
},
hashedIdToken1.substring(2),
nodeDetails1.torusNodePub
);
const result2 = await torus.retrieveShares(
torusNodeEndpoints2,
nodeDetails2.torusIndexes,
TORUS_TEST_AGGREGATE_VERIFIER,
{
verify_params: [{ verifier_id: email2, idtoken: idToken2 }],
sub_verifier_ids: [TORUS_TEST_VERIFIER],
verifier_id: email2,
},
hashedIdToken2.substring(2),
nodeDetails2.torusNodePub
);
expect(result1.metadata.serverTimeOffset).lessThan(20);

expect(result1.finalKeyData.walletAddress).to.not.equal(null);
expect(result1.finalKeyData.walletAddress).to.not.equal("");
expect(result1.oAuthKeyData.walletAddress).to.not.equal(null);
expect(result1.metadata.typeOfUser).to.equal("v2");
expect(result1.metadata.nonce).to.not.equal(null);
expect(result1.metadata.upgraded).to.equal(false);

expect(result2.metadata.serverTimeOffset).lessThan(20);

expect(result2.finalKeyData.walletAddress).to.not.equal(null);
expect(result2.finalKeyData.walletAddress).to.not.equal("");
expect(result2.oAuthKeyData.walletAddress).to.not.equal(null);
expect(result2.metadata.typeOfUser).to.equal("v2");
expect(result2.metadata.nonce).to.not.equal(null);
expect(result2.metadata.upgraded).to.equal(false);

expect(result2.finalKeyData.walletAddress).to.not.equal(result1.finalKeyData.walletAddress);
});

it("should be able to login with the same account repeatedly and get the same address", async function () {
const addresses = [];
const iterations = 5;
const email = faker.internet.email();
for (let i = 0; i <= iterations; i++) {
const idToken = generateIdToken(email, "ES256");
const hashedIdToken = keccak256(Buffer.from(idToken, "utf8"));
const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email };

const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints;
const result = await torus.retrieveShares(
torusNodeEndpoints,
nodeDetails.torusIndexes,
TORUS_TEST_AGGREGATE_VERIFIER,
{
verify_params: [{ verifier_id: email, idtoken: idToken }],
sub_verifier_ids: [TORUS_TEST_VERIFIER],
verifier_id: email,
},
hashedIdToken.substring(2),
nodeDetails.torusNodePub
);
expect(result.metadata.serverTimeOffset).lessThan(20);
delete result.metadata.serverTimeOffset;

expect(result.finalKeyData.walletAddress).to.not.equal(null);
expect(result.finalKeyData.walletAddress).to.not.equal("");
expect(result.oAuthKeyData.walletAddress).to.not.equal(null);
expect(result.metadata.typeOfUser).to.equal("v2");
expect(result.metadata.nonce).to.not.equal(null);
expect(result.metadata.upgraded).to.equal(false);

addresses.push(result.finalKeyData.walletAddress);
}
const set = new Set(addresses);
expect(set.size).to.equal(1);
});

it("should be able to login with a fixed set of different accounts repeatedly and get a constant set of addresses", async function () {
const addresses = [];
const iterations = 5;
for (let i = 0; i <= iterations; i++) {
const email = faker.internet.email();
for (let k = 0; k <= iterations; k++) {
const idToken = generateIdToken(email, "ES256");
const hashedIdToken = keccak256(Buffer.from(idToken, "utf8"));
const verifierDetails = { verifier: TORUS_TEST_AGGREGATE_VERIFIER, verifierId: email };

const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
const torusNodeEndpoints = nodeDetails.torusNodeSSSEndpoints;
const result = await torus.retrieveShares(
torusNodeEndpoints,
nodeDetails.torusIndexes,
TORUS_TEST_AGGREGATE_VERIFIER,
{
verify_params: [{ verifier_id: email, idtoken: idToken }],
sub_verifier_ids: [TORUS_TEST_VERIFIER],
verifier_id: email,
},
hashedIdToken.substring(2),
nodeDetails.torusNodePub
);
expect(result.metadata.serverTimeOffset).lessThan(20);
delete result.metadata.serverTimeOffset;

expect(result.finalKeyData.walletAddress).to.not.equal(null);
expect(result.finalKeyData.walletAddress).to.not.equal("");
expect(result.oAuthKeyData.walletAddress).to.not.equal(null);
expect(result.metadata.typeOfUser).to.equal("v2");
expect(result.metadata.nonce).to.not.equal(null);
expect(result.metadata.upgraded).to.equal(false);

addresses.push(result.finalKeyData.walletAddress);
}
}
const set = new Set(addresses);
expect(set.size).to.equal(6);
});
});

0 comments on commit 1eea8b8

Please sign in to comment.