diff --git a/LICENSE b/LICENSE index 48ecf1f..cfc6993 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/package-lock.json b/package-lock.json index 2d9d5d7..fd00cf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@toruslabs/torus.js", - "version": "15.0.2", + "version": "15.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@toruslabs/torus.js", - "version": "15.0.2", + "version": "15.0.5", "license": "MIT", "dependencies": { "@toruslabs/bs58": "^1.0.0", diff --git a/package.json b/package.json index dad3a5e..c5d92a3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/helpers/metadataUtils.ts b/src/helpers/metadataUtils.ts index ed992c1..7a2384a 100644 --- a/src/helpers/metadataUtils.ts +++ b/src/helpers/metadataUtils.ts @@ -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(), @@ -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"), diff --git a/src/torus.ts b/src/torus.ts index e56bae1..11e54f3 100644 --- a/src/torus.ts +++ b/src/torus.ts @@ -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 { diff --git a/test/sapphire_devnet_ed25519.test.ts b/test/sapphire_devnet_ed25519.test.ts index 884a3be..164cfb6 100644 --- a/test/sapphire_devnet_ed25519.test.ts +++ b/test/sapphire_devnet_ed25519.test.ts @@ -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 });