Skip to content

Commit

Permalink
add more tessts
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshuchawla009 committed Oct 4, 2024
1 parent 3a84281 commit 09a5c8d
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
46 changes: 46 additions & 0 deletions test/cyan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,52 @@ describe("torus utils cyan", function () {
});
});

it("should be able to login without commitments", async function () {
const token = generateIdToken(TORUS_TEST_EMAIL, "ES256");
const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL };
const { torusNodeEndpoints, torusIndexes, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
const result = await torus.retrieveShares(
getRetrieveSharesParams(
torusNodeEndpoints,
torusIndexes,
TORUS_TEST_VERIFIER,
{ verifier_id: TORUS_TEST_EMAIL },
token,
torusNodePub,
{},
true,
false
)
);
delete result.sessionData;
expect(result.metadata.serverTimeOffset).lessThan(20);

delete result.metadata.serverTimeOffset;

expect(result.finalKeyData.privKey).to.be.equal("5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8");
expect(result).eql({
finalKeyData: {
X: "e2ed6033951af2851d1bea98799e62fb1ff24b952c1faea17922684678ba42d1",
Y: "beef0efad88e81385952c0068ca48e8b9c2121be87cb0ddf18a68806db202359",
walletAddress: "0xC615aA03Dd8C9b2dc6F7c43cBDfF2c34bBa47Ec9",
privKey: "5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8",
},
oAuthKeyData: {
X: "e2ed6033951af2851d1bea98799e62fb1ff24b952c1faea17922684678ba42d1",
Y: "beef0efad88e81385952c0068ca48e8b9c2121be87cb0ddf18a68806db202359",
walletAddress: "0xC615aA03Dd8C9b2dc6F7c43cBDfF2c34bBa47Ec9",
privKey: "5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8",
},
postboxKeyData: {
X: "e2ed6033951af2851d1bea98799e62fb1ff24b952c1faea17922684678ba42d1",
Y: "beef0efad88e81385952c0068ca48e8b9c2121be87cb0ddf18a68806db202359",
privKey: "5db51619684b32a2ff2375b4c03459d936179dfba401cb1c176b621e8a2e4ac8",
},
metadata: { pubNonce: undefined, nonce: new BN(0), typeOfUser: "v1", upgraded: null },
nodesData: result.nodesData,
});
});

it("should be able to aggregate login", async function () {
const idToken = generateIdToken(TORUS_TEST_EMAIL, "ES256");
const hashedIdToken = keccak256(Buffer.from(idToken, "utf8"));
Expand Down
2 changes: 1 addition & 1 deletion test/sapphire_devnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TORUS_TEST_VERIFIER = "torus-test-health";
const TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate";
const HashEnabledVerifier = "torus-test-verifierid-hash";

describe.only("torus utils sapphire devnet", function () {
describe("torus utils sapphire devnet", function () {
let torus: TorusUtils;
let TORUS_NODE_MANAGER: NodeDetailManager;

Expand Down
87 changes: 87 additions & 0 deletions test/sapphire_mainnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,60 @@ describe("torus utils sapphire mainnet", function () {
});
});

it("should be able to login without commitments", async function () {
const token = generateIdToken(TORUS_TEST_EMAIL, "ES256");
const verifierDetails = { verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL };
const { torusNodeEndpoints, torusIndexes, torusNodePub } = await TORUS_NODE_MANAGER.getNodeDetails(verifierDetails);
const result = await torus.retrieveShares(
getRetrieveSharesParams(
torusNodeEndpoints,
torusIndexes,
TORUS_TEST_VERIFIER,
{ verifier_id: TORUS_TEST_EMAIL },
token,
torusNodePub,
{},
true,
false
)
);
expect(result.finalKeyData.privKey).to.be.equal("dfb39b84e0c64b8c44605151bf8670ae6eda232056265434729b6a8a50fa3419");
expect(result.metadata.serverTimeOffset).lessThan(20);

delete result.metadata.serverTimeOffset;

expect(result).eql({
finalKeyData: {
walletAddress: "0x70520A7F04868ACad901683699Fa32765C9F6871",
X: "adff099b5d3b1e238b43fba1643cfa486e8d9e8de22c1e6731d06a5303f9025b",
Y: "21060328e7889afd303acb63201b6493e3061057d1d81279931ab4a6cabf94d4",
privKey: "dfb39b84e0c64b8c44605151bf8670ae6eda232056265434729b6a8a50fa3419",
},
oAuthKeyData: {
walletAddress: "0x925c97404F1aBdf4A8085B93edC7B9F0CEB3C673",
X: "5cd8625fc01c7f7863a58c914a8c43b2833b3d0d5059350bab4acf6f4766a33d",
Y: "198a4989615c5c2c7fa4d49c076ea7765743d09816bb998acb9ff54f5db4a391",
privKey: "90a219ac78273e82e36eaa57c15f9070195e436644319d6b9aea422bb4d31906",
},
postboxKeyData: {
X: "5cd8625fc01c7f7863a58c914a8c43b2833b3d0d5059350bab4acf6f4766a33d",
Y: "198a4989615c5c2c7fa4d49c076ea7765743d09816bb998acb9ff54f5db4a391",
privKey: "90a219ac78273e82e36eaa57c15f9070195e436644319d6b9aea422bb4d31906",
},
sessionData: { sessionTokenData: result.sessionData.sessionTokenData, sessionAuthKey: result.sessionData.sessionAuthKey },
metadata: {
pubNonce: {
X: "ab4d287c263ab1bb83c37646d0279764e50fe4b0c34de4da113657866ddcf318",
Y: "ad35db2679dfad4b62d77cf753d7b98f73c902e5d101cc2c3c1209ece6d94382",
},
nonce: new BN("4f1181d8689f0d0960f1a6f9fe26e03e557bdfba11f4b6c8d7b1285e9c271b13", "hex"),
typeOfUser: "v2",
upgraded: false,
},
nodesData: result.nodesData,
});
});

it("should be able to aggregate login", async function () {
const email = faker.internet.email();
const idToken = generateIdToken(email, "ES256");
Expand Down Expand Up @@ -367,6 +421,39 @@ describe("torus utils sapphire mainnet", function () {
expect(result.metadata.upgraded).to.equal(false);
});

it("should be able to aggregate login without commitment", async function () {
const email = faker.internet.email();
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(
getRetrieveSharesParams(
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,
{},
true,
false
)
);
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);
});

it("should be able to update the `sessionTime` of the token signature data", async function () {
const email = faker.internet.email();
const token = generateIdToken(TORUS_TEST_EMAIL, "ES256");
Expand Down
2 changes: 1 addition & 1 deletion test/testnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TORUS_TEST_EMAIL = "archit1@tor.us";
const TORUS_TEST_VERIFIER = "torus-test-health";
const TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate";

describe.only("torus utils migrated testnet on sapphire", function () {
describe("torus utils migrated testnet on sapphire", function () {
let torus: TorusUtils;
let TORUS_NODE_MANAGER: NodeDetailManager;

Expand Down

0 comments on commit 09a5c8d

Please sign in to comment.