1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

All the linting

This commit is contained in:
David Baker
2019-02-05 13:03:27 +00:00
parent b3513dc8f8
commit 7f5584e4f5
4 changed files with 60 additions and 28 deletions

View File

@@ -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;

View File

@@ -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();

View File

@@ -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]: {

View File

@@ -72,9 +72,9 @@ export default class SskInfo {
isVerified() {
return this.verified == SskInfo.SskVerification.VERIFIED;
};
}
isUnverified() {
return this.verified == SskInfo.SskVerification.UNVERIFIED;
};
}
}