From e1f832bfa72368adc584fa7a500e2c129d42f27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Van=20Rompay?= Date: Fri, 24 Jan 2020 09:20:43 +0100 Subject: [PATCH] fix linting errors --- spec/unit/crypto/algorithms/olm.spec.js | 10 ++++-- src/client.js | 16 ++++++--- src/crypto/OlmDevice.js | 46 ++++++++++++++++--------- src/crypto/index.js | 4 +-- 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/spec/unit/crypto/algorithms/olm.spec.js b/spec/unit/crypto/algorithms/olm.spec.js index 2f173ae30..c9cb6d31d 100644 --- a/spec/unit/crypto/algorithms/olm.spec.js +++ b/spec/unit/crypto/algorithms/olm.spec.js @@ -88,7 +88,10 @@ describe("OlmDevice", function() { // At this moment only Alice (the “initiator” in setupSession) has a session expect(exported.sessions).toEqual([]); - const MESSAGE = "The olm or proteus is an aquatic salamander in the family Proteidae"; + const MESSAGE = ( + "The olm or proteus is an aquatic salamander" + + " in the family Proteidae" + ); const ciphertext = await aliceOlmDevice.encryptMessage( bobOlmDevice.deviceCurve25519Key, sessionId, @@ -109,7 +112,10 @@ describe("OlmDevice", function() { // this time we expect Bob to have a session to export expect(exportedAgain.sessions).toHaveLength(1); - const MESSAGE_2 = "In contrast to most amphibians, the olm is entirely aquatic"; + const MESSAGE_2 = ( + "In contrast to most amphibians," + + " the olm is entirely aquatic" + ); const ciphertext_2 = await aliceOlmDevice.encryptMessage( bobOlmDevice.deviceCurve25519Key, sessionId, diff --git a/src/client.js b/src/client.js index c429b53ab..a1401d4ce 100644 --- a/src/client.js +++ b/src/client.js @@ -97,7 +97,7 @@ function keyFromRecoverySession(session, decryptionKey) { * @param {string} opts.accessToken The access_token for this user. * * @param {string} opts.userId The user ID for this user. - * + * * @param {Object} opts.deviceToImport Device data exported with * (TODO link to export method) that must be imported to recreate this device. * Should only be useful for deviced with end-to-end crypto enabled. @@ -256,10 +256,18 @@ export function MatrixClient(opts) { if (opts.deviceToImport) { if (this.deviceId) { - logger.warn('not importing device because device ID is provided to constructor independently of exported data'); + logger.warn( + 'not importing device because' + + ' device ID is provided to constructor' + + ' independently of exported data', + ); } else if (this.credentials.userId) { - logger.warn('not importing device because user ID is provided to constructor independently of exported data'); - } else if (!(opts.deviceToImport.deviceId)){ + logger.warn( + 'not importing device because' + + ' user ID is provided to constructor' + + ' independently of exported data', + ); + } else if (!(opts.deviceToImport.deviceId)) { logger.warn('not importing device because no device ID in exported data'); } else { this.deviceId = opts.deviceToImport.deviceId; diff --git a/src/crypto/OlmDevice.js b/src/crypto/OlmDevice.js index 620cfd7ab..b6e29e6a5 100644 --- a/src/crypto/OlmDevice.js +++ b/src/crypto/OlmDevice.js @@ -115,7 +115,7 @@ export function OlmDevice(cryptoStore) { * found. * * Reads the device keys from the OlmAccount object. - * + * * @param {object} fromExportedDevice (Optional) data from exported device * that must be re-created. */ @@ -123,10 +123,15 @@ OlmDevice.prototype.init = async function(fromExportedDevice) { let e2eKeys; const account = new global.Olm.Account(); try { - if (fromExportedDevice){ + if (fromExportedDevice) { this._pickleKey = fromExportedDevice.pickleKey; } - await _initialiseAccount(fromExportedDevice, this._cryptoStore, this._pickleKey, account); + await _initialiseAccount( + fromExportedDevice, + this._cryptoStore, + this._pickleKey, + account, + ); e2eKeys = JSON.parse(account.identity_keys()); this._maxOneTimeKeys = account.max_number_of_one_time_keys(); @@ -157,22 +162,31 @@ async function _initialiseAccount(fromExportedDevice, cryptoStore, pickleKey, ac session: session.session, lastReceivedMessageTs: session.lastReceivedMessageTs, }; - cryptoStore.storeEndToEndSession(deviceKey, sessionId, sessionInfo, txn); + cryptoStore.storeEndToEndSession( + deviceKey, + sessionId, + sessionInfo, + txn, + ); }); }); account.unpickle(pickleKey, fromExportedDevice.pickledAccount); } else { - await cryptoStore.doTxn('readwrite', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { - cryptoStore.getAccount(txn, (pickledAccount) => { - if (pickledAccount !== null) { - account.unpickle(pickleKey, pickledAccount); - } else { - account.create(); - pickledAccount = account.pickle(pickleKey); - cryptoStore.storeAccount(txn, pickledAccount); - } - }); - }); + await cryptoStore.doTxn( + 'readwrite', + [IndexedDBCryptoStore.STORE_ACCOUNT], + (txn) => { + cryptoStore.getAccount(txn, (pickledAccount) => { + if (pickledAccount !== null) { + account.unpickle(pickleKey, pickledAccount); + } else { + account.create(); + pickledAccount = account.pickle(pickleKey); + cryptoStore.storeAccount(txn, pickledAccount); + } + }); + }, + ); } } @@ -224,7 +238,7 @@ OlmDevice.prototype._storeAccount = function(txn, account) { /** * Export data for re-creating the Olm device later. * TODO export data other than just account and (P2P) sessions. - * + * * @return {Promise} The exported data */ OlmDevice.prototype.export = async function() { diff --git a/src/crypto/index.js b/src/crypto/index.js index 46107dc8b..5c0ade885 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -228,7 +228,7 @@ utils.inherits(Crypto, EventEmitter); * Initialise the crypto module so that it is ready for use * * Returns a promise which resolves once the crypto module is ready for use. - * + * * @param {Object} kwargs keyword arguments. * @param {string} kwargs.exportedOlmDevice (Optional) data from exported device * that must be re-created. @@ -243,7 +243,7 @@ Crypto.prototype.init = async function(kwargs) { logger.log( exportedOlmDevice ? "Crypto: initialising Olm device from exported device..." - : "Crypto: initialising Olm device..." + : "Crypto: initialising Olm device...", ); await this._olmDevice.init(exportedOlmDevice); logger.log("Crypto: loading device list...");