Skip to content

Commit

Permalink
feat: backward test tss pub, share
Browse files Browse the repository at this point in the history
  • Loading branch information
guru-web3 committed Feb 26, 2024
1 parent 127b3ba commit 30ed81f
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import test from "node:test";
import { UX_MODE_TYPE } from "@toruslabs/customauth";
import { keccak256 } from "@toruslabs/metadata-helpers";
import * as TssLib from "@toruslabs/tss-lib-node";
import { Web3AuthMPCCoreKit as OldCoreKit } from "@web3auth/mpc-core-kit";
import BN from "bn.js";
import { ec as EC } from "elliptic";

Expand Down Expand Up @@ -50,6 +51,15 @@ variable.forEach((testVariable) => {
storageKey: "memory",
manualSync,
});
const oldCoreKitInstance = new OldCoreKit({
web3AuthClientId: "torus-key-test",
web3AuthNetwork,
baseUrl: "http://localhost:3000",
uxMode,
tssLib: TssLib,
storageKey: "memory",
manualSync,
});

const testNameSuffix = JSON.stringify(testVariable);
test(`#Login Test with JWT + logout : ${testNameSuffix}`, async (t) => {
Expand Down Expand Up @@ -125,6 +135,45 @@ variable.forEach((testVariable) => {
assert.strictEqual(pubkey.y.toString("hex"), publicKeyPoint.y.toString("hex"));
});

await t.test("#After Login able to get same details with old and new sdk", async function () {
// mock login
const { idToken, parsedToken } = await mockLogin(email);
await coreKitInstance.init({ handleRedirectResult: false });
await coreKitInstance.loginWithJWT({
verifier: "torus-test-health",
verifierId: parsedToken.email,
idToken,
});

// get key details
await checkLogin(coreKitInstance);
const publicKeyPoint = coreKitInstance.getTssPublicKey();

const factorkey = coreKitInstance.getCurrentFactorKey();
const { tssShare } = await coreKitInstance.tKey.getTSSShare(new BN(factorkey.factorKey, "hex"), {
threshold: 0,
});

const { idToken: idToken2, parsedToken: parsedToken2 } = await mockLogin(email);
await oldCoreKitInstance.init({ handleRedirectResult: false });
await oldCoreKitInstance.loginWithJWT({
verifier: "torus-test-health",
verifierId: parsedToken2.email,
idToken: idToken2,
});
const publicKeyPoint2 = oldCoreKitInstance.getTssPublicKey();
// should get same tss pub key post and pre soft account implementation
assert.strictEqual(publicKeyPoint.x.toString("hex"), publicKeyPoint2.x.toString("hex"));
assert.strictEqual(publicKeyPoint.y.toString("hex"), publicKeyPoint2.y.toString("hex"));

const factorkey2 = oldCoreKitInstance.getCurrentFactorKey();
const { tssShare: oldTssShare } = await oldCoreKitInstance.tKey.getTSSShare(new BN(factorkey2.factorKey, "hex"), {
threshold: 0,
});
// should get tss share post and pre soft account implementation
assert.strictEqual(oldTssShare.toString("hex"), tssShare.toString("hex"));
});

await t.test("#Login and sign with different account/wallet index", async function () {
// mock login with random
const { idToken: idToken2, parsedToken: parsedToken2 } = await mockLogin();
Expand Down

0 comments on commit 30ed81f

Please sign in to comment.