From 7f5584e4f594fd459f295f105c955ab2d269b5b4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 5 Feb 2019 13:03:27 +0000 Subject: [PATCH] All the linting --- src/crypto/DeviceList.js | 13 ++++++-- src/crypto/PkSigning.js | 6 ++-- src/crypto/index.js | 65 +++++++++++++++++++++++++++------------- src/crypto/sskinfo.js | 4 +-- 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index 16b59bd1c..6cd83d3a3 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -917,13 +917,17 @@ async function _updateStoredSelfSigningKeyForUser( return; } if (!userResult || !userResult.usage.includes('self_signing')) { - logger.warn("Self-signing key for " + userId + " does not include 'self_signing' usage: ignoring"); + logger.warn( + "Self-signing key for " + userId + + " does not include 'self_signing' usage: ignoring", + ); return; } const keyCount = Object.keys(userResult.keys).length; if (keyCount !== 1) { logger.warn( - "Self-signing key block for " + userId + " has " + keyCount + " keys: expected exactly 1. Ignoring.", + "Self-signing key block for " + userId + " has " + + keyCount + " keys: expected exactly 1. Ignoring.", ); return; } @@ -937,7 +941,10 @@ async function _updateStoredSelfSigningKeyForUser( const newKey = userResult.keys[newKeyId]; if (oldKeyId !== newKeyId || oldKey !== newKey) { updated = true; - logger.info("New self-signing key detected for " + userId + ": " + newKeyId + ", was previously " + oldKeyId); + logger.info( + "New self-signing key detected for " + userId + + ": " + newKeyId + ", was previously " + oldKeyId, + ); userStore.user_id = userResult.user_id; userStore.usage = userResult.usage; diff --git a/src/crypto/PkSigning.js b/src/crypto/PkSigning.js index 483b13437..357039357 100644 --- a/src/crypto/PkSigning.js +++ b/src/crypto/PkSigning.js @@ -18,9 +18,9 @@ const anotherjson = require('another-json'); /** * Higher level wrapper around olm.PkSigning that signs JSON objects - * @param obj {Object} Object to sign - * @param seed {Uint8Array} The private key seed (32 bytes) - * @param userId {string} The user ID who owns the signing key + * @param {Object} obj Object to sign + * @param {Uint8Array} seed The private key seed (32 bytes) + * @param {string} userId The user ID who owns the signing key */ export function pkSign(obj, seed, userId) { const signing = new global.Olm.PkSigning(); diff --git a/src/crypto/index.js b/src/crypto/index.js index eac52a1ba..7e7837eca 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -286,27 +286,37 @@ Crypto.prototype.checkOwnSskTrust = async function() { // First, get the pubkey of the one we can see const seenSsk = this._deviceList.getStoredSskForUser(userId); if (!seenSsk) { - logger.error("Got SSK update event for user " + userId + " but no new SSK found!"); + logger.error( + "Got SSK update event for user " + userId + + " but no new SSK found!", + ); return; } const seenPubkey = seenSsk.getFingerprint(); // Now dig out the account keys and get the pubkey of the one in there let accountKeys = null; - await this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { - this._cryptoStore.getAccountKeys(txn, keys => { - accountKeys = keys; - }); - }); + await this._cryptoStore.doTxn( + 'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], + (txn) => { + this._cryptoStore.getAccountKeys(txn, keys => { + accountKeys = keys; + }); + }, + ); if (!accountKeys || !accountKeys.self_signing_key_seed) { - logger.info("Ignoring new self-signing key for us because we have no private part stored"); + logger.info( + "Ignoring new self-signing key for us because we have no private part stored", + ); return; } let signing; let localPubkey; try { signing = new global.Olm.PkSigning(); - localPubkey = signing.init_with_seed(Buffer.from(accountKeys.self_signing_key_seed, 'base64')); + localPubkey = signing.init_with_seed( + Buffer.from(accountKeys.self_signing_key_seed, 'base64'), + ); } finally { if (signing) signing.free(); signing = null; @@ -468,7 +478,8 @@ Crypto.prototype.isKeyBackupTrusted = async function(backupInfo) { ret.usable = ret.sigs.some((s) => { return ( s.valid && ( - (s.device && s.device.isVerified()) || (s.self_signing_key && s.self_signing_key.isVerified()) + (s.device && s.device.isVerified()) || + (s.self_signing_key && s.self_signing_key.isVerified()) ) ); }); @@ -568,15 +579,22 @@ Crypto.prototype.uploadDeviceKeys = function() { let accountKeys; return crypto._signObject(deviceKeys).then(() => { - return this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { - this._cryptoStore.getAccountKeys(txn, keys => { - accountKeys = keys; - }); - }); + return this._cryptoStore.doTxn( + 'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], + (txn) => { + this._cryptoStore.getAccountKeys(txn, keys => { + accountKeys = keys; + }); + }, + ); }).then(() => { if (accountKeys && accountKeys.self_signing_key_seed) { // if we have an SSK, sign the key with the SSK too - pkSign(deviceKeys, Buffer.from(accountKeys.self_signing_key_seed, 'base64'), userId); + pkSign( + deviceKeys, + Buffer.from(accountKeys.self_signing_key_seed, 'base64'), + userId, + ); } return crypto._baseApis.uploadKeysRequest({ @@ -608,15 +626,22 @@ Crypto.prototype.uploadDeviceKeySignatures = async function() { user_id: userId, }; let accountKeys; - await this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { - this._cryptoStore.getAccountKeys(txn, keys => { - accountKeys = keys; - }); + await this._cryptoStore.doTxn( + 'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], + (txn) => { + this._cryptoStore.getAccountKeys(txn, keys => { + accountKeys = keys; + }, + ); }); if (!accountKeys || !accountKeys.self_signing_key_seed) return false; // Sign this device with the SSK - pkSign(thisDeviceKey, Buffer.from(accountKeys.self_signing_key_seed, 'base64'), userId); + pkSign( + thisDeviceKey, + Buffer.from(accountKeys.self_signing_key_seed, 'base64'), + userId, + ); const content = { [userId]: { diff --git a/src/crypto/sskinfo.js b/src/crypto/sskinfo.js index 4ed63341d..1f578247f 100644 --- a/src/crypto/sskinfo.js +++ b/src/crypto/sskinfo.js @@ -72,9 +72,9 @@ export default class SskInfo { isVerified() { return this.verified == SskInfo.SskVerification.VERIFIED; - }; + } isUnverified() { return this.verified == SskInfo.SskVerification.UNVERIFIED; - }; + } }