Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshuchawla009 committed Oct 4, 2024
2 parents 5881a07 + 1fbbf07 commit b745055
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Torus
Copyright (c) 2020 Torus Labs Private Limited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
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.2",
"version": "15.0.5",
"description": "Handle communication with torus nodes",
"main": "dist/lib.cjs/index.js",
"module": "dist/lib.esm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const getSecpKeyFromEd25519 = (

const secpKeyPair = secp256k1Curve.keyFromPrivate(bufferKey);

if (bufferKey.length < 32) {
throw new Error(`Key length must be less than 32. got ${bufferKey.length}`);
if (bufferKey.length !== 32) {
throw new Error(`Key length must be equal to 32. got ${bufferKey.length}`);
}
return {
scalar: secpKeyPair.getPrivate(),
Expand Down Expand Up @@ -214,7 +214,7 @@ export const decryptSeedData = async (seedBase64: string, finalUserKey: BN) => {
const seedUtf8 = Buffer.from(seedBase64, "base64").toString("utf-8");
const seedJson = JSON.parse(seedUtf8) as EncryptedSeed;
const bufferMetadata = { ...encParamsHexToBuf(seedJson.metadata), mode: "AES256" };
const bufferKey = decryptionKey.scalar.toArrayLike(Buffer);
const bufferKey = decryptionKey.scalar.toArrayLike(Buffer, "be", 32);
const decText = await decrypt(bufferKey, {
...bufferMetadata,
ciphertext: Buffer.from(seedJson.enc_text, "hex"),
Expand Down
2 changes: 1 addition & 1 deletion src/torus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Torus {
if (useDkg === false && LEGACY_NETWORKS_ROUTE_MAP[this.network as TORUS_LEGACY_NETWORK_TYPE]) {
throw new Error(`useDkg cannot be false for legacy network; ${this.network}`);
}
shouldUseDkg = useDkg;
shouldUseDkg = this.keyType === KEY_TYPE.ED25519 ? false : useDkg;
} else if (this.keyType === KEY_TYPE.ED25519) {
shouldUseDkg = false;
} else {
Expand Down
24 changes: 24 additions & 0 deletions test/sapphire_devnet_ed25519.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,30 @@ describe("torus utils ed25519 sapphire devnet", function () {
expect(result.finalKeyData.X).eql(publicResult.finalKeyData.X);
});

it("should be able to login a new user with use dkg flag is true", async function () {
const email = `${faker.internet.email()}`;
const token = generateIdToken(email, "ES256");
const verifierDetails = { verifier: TORUS_TEST_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_VERIFIER,
{ verifier_id: email },
token,
nodeDetails.torusNodePub,
{},
true
)
);

const publicResult = await torus.getPublicAddress(torusNodeEndpoints, nodeDetails.torusNodePub, verifierDetails);

expect(result.finalKeyData.X).eql(publicResult.finalKeyData.X);
});

it("should be able to login even when node is down", async function () {
const token = generateIdToken(TORUS_TEST_EMAIL, "ES256");
const nodeDetails = await TORUS_NODE_MANAGER.getNodeDetails({ verifier: TORUS_TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL });
Expand Down

0 comments on commit b745055

Please sign in to comment.