From 1342fb5b3f41f77e1b2cdcc0e0c02443e012c8c9 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 14 Dec 2021 17:14:39 -0400 Subject: [PATCH] Make async in preparation for future change --- utils/ECC/ECC.js | 6 +++--- utils/ECC/ECC.spec.js | 16 +++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/utils/ECC/ECC.js b/utils/ECC/ECC.js index 990eac62..2d8de174 100644 --- a/utils/ECC/ECC.js +++ b/utils/ECC/ECC.js @@ -47,9 +47,9 @@ const isEncryptedMessage = message => * Generates a new encryption key pair that will be used * when communicating with the deviceId specified * @param {string} deviceId - * @returns {Pair} + * @returns {Promise} */ -const generateKeyPair = deviceId => { +const generateKeyPair = async deviceId => { try { const existingKey = nodeKeyPairs.get(deviceId) @@ -107,7 +107,7 @@ const isAuthorizedDevice = ({ deviceId }) => devicePublicKeys.has(deviceId) const authorizeDevice = async ({ deviceId, publicKey }) => { const hostId = await Storage.get('encryption/hostId') devicePublicKeys.set(deviceId, convertBase64ToBuffer(publicKey)) - const keyPair = generateKeyPair(deviceId) + const keyPair = await generateKeyPair(deviceId) return { success: true, diff --git a/utils/ECC/ECC.spec.js b/utils/ECC/ECC.spec.js index e4fbb9f7..7252e7c0 100644 --- a/utils/ECC/ECC.spec.js +++ b/utils/ECC/ECC.spec.js @@ -22,18 +22,20 @@ const storageDirectory = Path.resolve(__dirname, `./.test-storage`) console.log(`Storage directory: ${storageDirectory}`) describe('generateKeyPair()', () => { - it('generates a keypair', () => { - const pair = generateKeyPair(uuid()) + it('generates a keypair', async () => { + expect.hasAssertions() + const pair = await generateKeyPair(uuid()) expect(pair.privateKey).toBeInstanceOf(Buffer) expect(typeof pair.privateKeyBase64 === 'string').toBeTruthy() expect(pair.publicKey).toBeInstanceOf(Buffer) expect(typeof pair.publicKeyBase64 === 'string').toBeTruthy() }) - it('returns the same pair for the same device', () => { + it('returns the same pair for the same device', async () => { + expect.hasAssertions() const id = uuid() - const pair = generateKeyPair(id) - const pairAgain = generateKeyPair(id) + const pair = await generateKeyPair(id) + const pairAgain = await generateKeyPair(id) expect(pairAgain).toStrictEqual(pair) }) @@ -46,7 +48,7 @@ describe('authorizeDevice()/isAuthorizedDevice()', () => { dir: storageDirectory }) const deviceId = uuid() - const pair = generateKeyPair(deviceId) + const pair = await generateKeyPair(deviceId) await authorizeDevice({ deviceId, publicKey: pair.publicKeyBase64 }) expect(isAuthorizedDevice({ deviceId })).toBeTruthy() }) @@ -96,7 +98,7 @@ describe('encryptMessage()/decryptMessage()', () => { expect.hasAssertions() const deviceId = uuid() - const pair = generateKeyPair(deviceId) + const pair = await generateKeyPair(deviceId) await authorizeDevice({ deviceId, publicKey: pair.publicKeyBase64 })