Make async in preparation for future change
This commit is contained in:
parent
ece11954a1
commit
1342fb5b3f
2 changed files with 12 additions and 10 deletions
|
|
@ -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<Pair>}
|
||||
*/
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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 })
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue