Apply suggestions from SonarQube (#2340)
This commit is contained in:
committed by
GitHub
parent
b86630f0e3
commit
8be30acb11
@@ -47,7 +47,7 @@ describe("Browserify Test", function() {
|
||||
httpBackend.stop();
|
||||
});
|
||||
|
||||
it("Sync", async function() {
|
||||
it("Sync", function() {
|
||||
const event = utils.mkMembership({
|
||||
room: ROOM_ID,
|
||||
mship: "join",
|
||||
@@ -71,7 +71,7 @@ describe("Browserify Test", function() {
|
||||
};
|
||||
|
||||
httpBackend.when("GET", "/sync").respond(200, syncData);
|
||||
return await Promise.race([
|
||||
return Promise.race([
|
||||
httpBackend.flushAllExpected(),
|
||||
new Promise((_, reject) => {
|
||||
client.once("sync.unexpectedError", reject);
|
||||
|
||||
@@ -410,14 +410,14 @@ export class AutoDiscovery {
|
||||
* the following properties:
|
||||
* raw: The JSON object returned by the server.
|
||||
* action: One of SUCCESS, IGNORE, or FAIL_PROMPT.
|
||||
* reason: Relatively human readable description of what went wrong.
|
||||
* reason: Relatively human-readable description of what went wrong.
|
||||
* error: The actual Error, if one exists.
|
||||
* @param {string} url The URL to fetch a JSON object from.
|
||||
* @return {Promise<object>} Resolves to the returned state.
|
||||
* @private
|
||||
*/
|
||||
private static async fetchWellKnownObject(url: string): Promise<IWellKnownConfig> {
|
||||
return new Promise(function(resolve, reject) {
|
||||
private static fetchWellKnownObject(url: string): Promise<IWellKnownConfig> {
|
||||
return new Promise(function(resolve) {
|
||||
// eslint-disable-next-line
|
||||
const request = require("./matrix").getRequest();
|
||||
if (!request) throw new Error("No request library available");
|
||||
|
||||
+25
-32
@@ -1296,9 +1296,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* Get the current dehydrated device, if any
|
||||
* @return {Promise} A promise of an object containing the dehydrated device
|
||||
*/
|
||||
public async getDehydratedDevice(): Promise<IDehydratedDevice> {
|
||||
public getDehydratedDevice(): Promise<IDehydratedDevice> {
|
||||
try {
|
||||
return await this.http.authedRequest<IDehydratedDevice>(
|
||||
return this.http.authedRequest<IDehydratedDevice>(
|
||||
undefined,
|
||||
Method.Get,
|
||||
"/dehydrated_device",
|
||||
@@ -1324,7 +1324,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* dehydrated device.
|
||||
* @return {Promise} A promise that resolves when the dehydrated device is stored.
|
||||
*/
|
||||
public async setDehydrationKey(
|
||||
public setDehydrationKey(
|
||||
key: Uint8Array,
|
||||
keyInfo: IDehydratedDeviceKeyInfo,
|
||||
deviceDisplayName?: string,
|
||||
@@ -1333,7 +1333,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
logger.warn('not dehydrating device if crypto is not enabled');
|
||||
return;
|
||||
}
|
||||
return await this.crypto.dehydrationManager.setKeyAndQueueDehydration(key, keyInfo, deviceDisplayName);
|
||||
return this.crypto.dehydrationManager.setKeyAndQueueDehydration(key, keyInfo, deviceDisplayName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1354,11 +1354,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
logger.warn('not dehydrating device if crypto is not enabled');
|
||||
return;
|
||||
}
|
||||
await this.crypto.dehydrationManager.setKey(
|
||||
key, keyInfo, deviceDisplayName,
|
||||
);
|
||||
// XXX: Private member access.
|
||||
return await this.crypto.dehydrationManager.dehydrateDevice();
|
||||
await this.crypto.dehydrationManager.setKey(key, keyInfo, deviceDisplayName);
|
||||
return this.crypto.dehydrationManager.dehydrateDevice();
|
||||
}
|
||||
|
||||
public async exportDevice(): Promise<IExportedDevice> {
|
||||
@@ -2605,9 +2602,9 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @returns {Promise<IKeyBackupInfo | null>} Information object from API or null
|
||||
*/
|
||||
public async getKeyBackupVersion(): Promise<IKeyBackupInfo | null> {
|
||||
let res;
|
||||
let res: IKeyBackupInfo;
|
||||
try {
|
||||
res = await this.http.authedRequest(
|
||||
res = await this.http.authedRequest<IKeyBackupInfo>(
|
||||
undefined, Method.Get, "/room_keys/version", undefined, undefined,
|
||||
{ prefix: PREFIX_UNSTABLE },
|
||||
);
|
||||
@@ -2618,11 +2615,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
try {
|
||||
BackupManager.checkBackupVersion(res);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
BackupManager.checkBackupVersion(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -3144,10 +3137,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
});
|
||||
}
|
||||
|
||||
const res = await this.http.authedRequest(
|
||||
const res = await this.http.authedRequest<IRoomsKeysResponse | IRoomKeysResponse | IKeyBackupSession>(
|
||||
undefined, Method.Get, path.path, path.queryData, undefined,
|
||||
{ prefix: PREFIX_UNSTABLE },
|
||||
) as IRoomsKeysResponse | IRoomKeysResponse | IKeyBackupSession;
|
||||
);
|
||||
|
||||
if ((res as IRoomsKeysResponse).rooms) {
|
||||
const rooms = (res as IRoomsKeysResponse).rooms;
|
||||
@@ -3372,7 +3365,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* data event.
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
*/
|
||||
public async getAccountDataFromServer<T extends {[k: string]: any}>(eventType: string): Promise<T> {
|
||||
public getAccountDataFromServer<T extends {[k: string]: any}>(eventType: string): Promise<T> {
|
||||
if (this.isInitialSyncComplete()) {
|
||||
const event = this.store.getAccountData(eventType);
|
||||
if (!event) {
|
||||
@@ -3387,7 +3380,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
$type: eventType,
|
||||
});
|
||||
try {
|
||||
return await this.http.authedRequest(
|
||||
return this.http.authedRequest(
|
||||
undefined, Method.Get, path, undefined,
|
||||
);
|
||||
} catch (e) {
|
||||
@@ -3655,7 +3648,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
if (event?.getType() === EventType.RoomPowerLevels) {
|
||||
// take a copy of the content to ensure we don't corrupt
|
||||
// existing client state with a failed power level change
|
||||
content = utils.deepCopy(event.getContent()) as typeof content;
|
||||
content = utils.deepCopy(event.getContent());
|
||||
}
|
||||
content.users[userId] = powerLevel;
|
||||
const path = utils.encodeUri("/rooms/$roomId/state/m.room.power_levels", {
|
||||
@@ -6109,7 +6102,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
this.syncLeftRoomsPromise = syncApi.syncLeftRooms();
|
||||
|
||||
// cleanup locks
|
||||
this.syncLeftRoomsPromise.then((res) => {
|
||||
this.syncLeftRoomsPromise.then(() => {
|
||||
logger.log("Marking success of sync left room request");
|
||||
this.syncedLeftRooms = true; // flip the bit on success
|
||||
}).finally(() => {
|
||||
@@ -7203,7 +7196,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @param {Object} [opts] options with optional values for the request.
|
||||
* @return {Object} the response, with chunk, prev_batch and, next_batch.
|
||||
*/
|
||||
public async fetchRelations(
|
||||
public fetchRelations(
|
||||
roomId: string,
|
||||
eventId: string,
|
||||
relationType?: RelationType | string | null,
|
||||
@@ -7231,7 +7224,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
$relationType: relationType,
|
||||
$eventType: eventType,
|
||||
});
|
||||
return await this.http.authedRequest(
|
||||
return this.http.authedRequest(
|
||||
undefined, Method.Get, path, null, null, {
|
||||
prefix: PREFIX_UNSTABLE,
|
||||
},
|
||||
@@ -8324,7 +8317,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
* @throws Error if no identity server is set
|
||||
*/
|
||||
public async requestEmailToken(
|
||||
public requestEmailToken(
|
||||
email: string,
|
||||
clientSecret: string,
|
||||
sendAttempt: number,
|
||||
@@ -8339,7 +8332,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
next_link: nextLink,
|
||||
};
|
||||
|
||||
return await this.http.idServerRequest(
|
||||
return this.http.idServerRequest(
|
||||
callback, Method.Post, "/validate/email/requestToken",
|
||||
params, PREFIX_IDENTITY_V2, identityAccessToken,
|
||||
);
|
||||
@@ -8372,7 +8365,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
* @throws Error if no identity server is set
|
||||
*/
|
||||
public async requestMsisdnToken(
|
||||
public requestMsisdnToken(
|
||||
phoneCountry: string,
|
||||
phoneNumber: string,
|
||||
clientSecret: string,
|
||||
@@ -8389,7 +8382,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
next_link: nextLink,
|
||||
};
|
||||
|
||||
return await this.http.idServerRequest(
|
||||
return this.http.idServerRequest(
|
||||
callback, Method.Post, "/validate/msisdn/requestToken",
|
||||
params, PREFIX_IDENTITY_V2, identityAccessToken,
|
||||
);
|
||||
@@ -8414,7 +8407,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* @return {module:http-api.MatrixError} Rejects: with an error response.
|
||||
* @throws Error if No identity server is set
|
||||
*/
|
||||
public async submitMsisdnToken(
|
||||
public submitMsisdnToken(
|
||||
sid: string,
|
||||
clientSecret: string,
|
||||
msisdnToken: string,
|
||||
@@ -8426,7 +8419,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
token: msisdnToken,
|
||||
};
|
||||
|
||||
return await this.http.idServerRequest(
|
||||
return this.http.idServerRequest(
|
||||
undefined, Method.Post, "/validate/msisdn/submitToken",
|
||||
params, PREFIX_IDENTITY_V2, identityAccessToken,
|
||||
);
|
||||
@@ -8947,7 +8940,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
* origin_server_ts of the closest event to the timestamp in the given
|
||||
* direction
|
||||
*/
|
||||
public async timestampToEvent(
|
||||
public timestampToEvent(
|
||||
roomId: string,
|
||||
timestamp: number,
|
||||
dir: Direction,
|
||||
@@ -8956,7 +8949,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
$roomId: roomId,
|
||||
});
|
||||
|
||||
return await this.http.authedRequest(
|
||||
return this.http.authedRequest(
|
||||
undefined,
|
||||
Method.Get,
|
||||
path,
|
||||
|
||||
@@ -909,12 +909,12 @@ export class OlmDevice {
|
||||
await this.cryptoStore.storeEndToEndSessionProblem(deviceKey, type, fixed);
|
||||
}
|
||||
|
||||
public async sessionMayHaveProblems(deviceKey: string, timestamp: number): Promise<IProblem> {
|
||||
return await this.cryptoStore.getEndToEndSessionProblem(deviceKey, timestamp);
|
||||
public sessionMayHaveProblems(deviceKey: string, timestamp: number): Promise<IProblem> {
|
||||
return this.cryptoStore.getEndToEndSessionProblem(deviceKey, timestamp);
|
||||
}
|
||||
|
||||
public async filterOutNotifiedErrorDevices(devices: IOlmDevice[]): Promise<IOlmDevice[]> {
|
||||
return await this.cryptoStore.filterOutNotifiedErrorDevices(devices);
|
||||
public filterOutNotifiedErrorDevices(devices: IOlmDevice[]): Promise<IOlmDevice[]> {
|
||||
return this.cryptoStore.filterOutNotifiedErrorDevices(devices);
|
||||
}
|
||||
|
||||
// Outbound group session
|
||||
|
||||
@@ -189,9 +189,7 @@ export class OutgoingRoomKeyRequestManager {
|
||||
// in state ROOM_KEY_REQUEST_STATES.SENT, so we must have
|
||||
// raced with another tab to mark the request cancelled.
|
||||
// Try again, to make sure the request is resent.
|
||||
return await this.queueRoomKeyRequest(
|
||||
requestBody, recipients, resend,
|
||||
);
|
||||
return this.queueRoomKeyRequest(requestBody, recipients, resend);
|
||||
}
|
||||
|
||||
// We don't want to wait for the timer, so we send it
|
||||
|
||||
@@ -329,7 +329,7 @@ export class SecretStorage {
|
||||
// encoded, since this is how a key would normally be stored.
|
||||
if (encInfo.passthrough) return encodeBase64(decryption.get_private_key());
|
||||
|
||||
return await decryption.decrypt(encInfo);
|
||||
return decryption.decrypt(encInfo);
|
||||
} finally {
|
||||
if (decryption && decryption.free) decryption.free();
|
||||
}
|
||||
@@ -345,15 +345,10 @@ export class SecretStorage {
|
||||
* with, or null if it is not present or not encrypted with a trusted
|
||||
* key
|
||||
*/
|
||||
public async isStored(name: string, checkKey: boolean): Promise<Record<string, ISecretStorageKeyInfo> | null> {
|
||||
public async isStored(name: string, checkKey = true): Promise<Record<string, ISecretStorageKeyInfo> | null> {
|
||||
// check if secret exists
|
||||
const secretInfo = await this.accountDataAdapter.getAccountDataFromServer<ISecretInfo>(name);
|
||||
if (!secretInfo) return null;
|
||||
if (!secretInfo.encrypted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkKey === undefined) checkKey = true;
|
||||
if (!secretInfo?.encrypted) return null;
|
||||
|
||||
const ret = {};
|
||||
|
||||
@@ -598,11 +593,11 @@ export class SecretStorage {
|
||||
|
||||
if (keys[keyId].algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {
|
||||
const decryption = {
|
||||
encrypt: async function(secret: string): Promise<IEncryptedPayload> {
|
||||
return await encryptAES(secret, privateKey, name);
|
||||
encrypt: function(secret: string): Promise<IEncryptedPayload> {
|
||||
return encryptAES(secret, privateKey, name);
|
||||
},
|
||||
decrypt: async function(encInfo: IEncryptedPayload): Promise<string> {
|
||||
return await decryptAES(encInfo, privateKey, name);
|
||||
decrypt: function(encInfo: IEncryptedPayload): Promise<string> {
|
||||
return decryptAES(encInfo, privateKey, name);
|
||||
},
|
||||
};
|
||||
return [keyId, decryption];
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ async function deriveKeysBrowser(key: Uint8Array, name: string): Promise<[Crypto
|
||||
['sign', 'verify'],
|
||||
);
|
||||
|
||||
return await Promise.all([aesProm, hmacProm]);
|
||||
return Promise.all([aesProm, hmacProm]);
|
||||
}
|
||||
|
||||
export function encryptAES(data: string, key: Uint8Array, name: string, ivStr?: string): Promise<IEncryptedPayload> {
|
||||
|
||||
@@ -70,7 +70,7 @@ class OlmEncryption extends EncryptionAlgorithm {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this.prepPromise = this.crypto.downloadKeys(roomMembers).then((res) => {
|
||||
this.prepPromise = this.crypto.downloadKeys(roomMembers).then(() => {
|
||||
return this.crypto.ensureOlmSessionsForUsers(roomMembers);
|
||||
}).then(() => {
|
||||
this.sessionPrepared = true;
|
||||
@@ -144,7 +144,7 @@ class OlmEncryption extends EncryptionAlgorithm {
|
||||
}
|
||||
}
|
||||
|
||||
return await Promise.all(promises).then(() => encryptedContent);
|
||||
return Promise.all(promises).then(() => encryptedContent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ class OlmDecryption extends DecryptionAlgorithm {
|
||||
*
|
||||
* @return {string} payload, if decrypted successfully.
|
||||
*/
|
||||
private async decryptMessage(theirDeviceIdentityKey: string, message: IMessage): Promise<string> {
|
||||
private decryptMessage(theirDeviceIdentityKey: string, message: IMessage): Promise<string> {
|
||||
// This is a wrapper that serialises decryptions of prekey messages, because
|
||||
// otherwise we race between deciding we have no active sessions for the message
|
||||
// and creating a new one, which we can only do once because it removes the OTK.
|
||||
@@ -274,7 +274,7 @@ class OlmDecryption extends DecryptionAlgorithm {
|
||||
});
|
||||
// we want the error, but don't propagate it to the next decryption
|
||||
this.olmDevice.olmPrekeyPromise = myPromise.catch(() => {});
|
||||
return await myPromise;
|
||||
return myPromise;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,18 +132,18 @@ export class BackupManager {
|
||||
if (!Algorithm) {
|
||||
throw new Error("Unknown backup algorithm: " + info.algorithm);
|
||||
}
|
||||
if (!(typeof info.auth_data === "object")) {
|
||||
if (typeof info.auth_data !== "object") {
|
||||
throw new Error("Invalid backup data returned");
|
||||
}
|
||||
return Algorithm.checkBackupVersion(info);
|
||||
}
|
||||
|
||||
public static async makeAlgorithm(info: IKeyBackupInfo, getKey: GetKey): Promise<BackupAlgorithm> {
|
||||
public static makeAlgorithm(info: IKeyBackupInfo, getKey: GetKey): Promise<BackupAlgorithm> {
|
||||
const Algorithm = algorithmsByName[info.algorithm];
|
||||
if (!Algorithm) {
|
||||
throw new Error("Unknown backup algorithm");
|
||||
}
|
||||
return await Algorithm.init(info.auth_data, getKey);
|
||||
return Algorithm.init(info.auth_data, getKey);
|
||||
}
|
||||
|
||||
public async enableKeyBackup(info: IKeyBackupInfo): Promise<void> {
|
||||
@@ -777,15 +777,15 @@ export class Aes256 implements BackupAlgorithm {
|
||||
|
||||
public get untrusted() { return false; }
|
||||
|
||||
async encryptSession(data: Record<string, any>): Promise<any> {
|
||||
public encryptSession(data: Record<string, any>): Promise<any> {
|
||||
const plainText: Record<string, any> = Object.assign({}, data);
|
||||
delete plainText.session_id;
|
||||
delete plainText.room_id;
|
||||
delete plainText.first_known_index;
|
||||
return await encryptAES(JSON.stringify(plainText), this.key, data.session_id);
|
||||
return encryptAES(JSON.stringify(plainText), this.key, data.session_id);
|
||||
}
|
||||
|
||||
async decryptSessions(sessions: Record<string, IKeyBackupSession>): Promise<IMegolmSessionData[]> {
|
||||
public async decryptSessions(sessions: Record<string, IKeyBackupSession>): Promise<IMegolmSessionData[]> {
|
||||
const keys: IMegolmSessionData[] = [];
|
||||
|
||||
for (const [sessionId, sessionData] of Object.entries(sessions)) {
|
||||
@@ -800,7 +800,7 @@ export class Aes256 implements BackupAlgorithm {
|
||||
return keys;
|
||||
}
|
||||
|
||||
async keyMatches(key: Uint8Array): Promise<boolean> {
|
||||
public async keyMatches(key: Uint8Array): Promise<boolean> {
|
||||
if (this.authData.mac) {
|
||||
const { mac } = await calculateKeyCheck(key, this.authData.iv);
|
||||
return this.authData.mac.replace(/=+$/g, '') === mac.replace(/=+/g, '');
|
||||
|
||||
@@ -61,11 +61,13 @@ export class DehydrationManager {
|
||||
private key: Uint8Array;
|
||||
private keyInfo: {[props: string]: any};
|
||||
private deviceDisplayName: string;
|
||||
|
||||
constructor(private readonly crypto: Crypto) {
|
||||
this.getDehydrationKeyFromCache();
|
||||
}
|
||||
async getDehydrationKeyFromCache(): Promise<void> {
|
||||
return await this.crypto.cryptoStore.doTxn(
|
||||
|
||||
public getDehydrationKeyFromCache(): Promise<void> {
|
||||
return this.crypto.cryptoStore.doTxn(
|
||||
'readonly',
|
||||
[IndexedDBCryptoStore.STORE_ACCOUNT],
|
||||
(txn) => {
|
||||
@@ -93,7 +95,7 @@ export class DehydrationManager {
|
||||
}
|
||||
|
||||
/** set the key, and queue periodic dehydration to the server in the background */
|
||||
async setKeyAndQueueDehydration(
|
||||
public async setKeyAndQueueDehydration(
|
||||
key: Uint8Array, keyInfo: {[props: string]: any} = {},
|
||||
deviceDisplayName: string = undefined,
|
||||
): Promise<void> {
|
||||
@@ -104,7 +106,7 @@ export class DehydrationManager {
|
||||
}
|
||||
}
|
||||
|
||||
async setKey(
|
||||
public async setKey(
|
||||
key: Uint8Array, keyInfo: {[props: string]: any} = {},
|
||||
deviceDisplayName: string = undefined,
|
||||
): Promise<boolean> {
|
||||
@@ -148,7 +150,7 @@ export class DehydrationManager {
|
||||
}
|
||||
|
||||
/** returns the device id of the newly created dehydrated device */
|
||||
async dehydrateDevice(): Promise<string> {
|
||||
public async dehydrateDevice(): Promise<string> {
|
||||
if (this.inProgress) {
|
||||
logger.log("Dehydration already in progress -- not starting new dehydration");
|
||||
return;
|
||||
|
||||
+3
-3
@@ -402,7 +402,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
||||
|
||||
// try to get key from app
|
||||
if (this.baseApis.cryptoCallbacks && this.baseApis.cryptoCallbacks.getBackupKey) {
|
||||
return await this.baseApis.cryptoCallbacks.getBackupKey();
|
||||
return this.baseApis.cryptoCallbacks.getBackupKey();
|
||||
}
|
||||
|
||||
throw new Error("Unable to get private key");
|
||||
@@ -690,7 +690,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
||||
|
||||
// Cross-sign own device
|
||||
const device = this.deviceList.getStoredDevice(this.userId, this.deviceId);
|
||||
const deviceSignature = await crossSigningInfo.signDevice(this.userId, device) as ISignedKey;
|
||||
const deviceSignature = await crossSigningInfo.signDevice(this.userId, device);
|
||||
builder.addKeySignature(this.userId, this.deviceId, deviceSignature);
|
||||
|
||||
// Sign message key backup with cross-signing master key
|
||||
@@ -2890,7 +2890,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
||||
} else {
|
||||
const content = event.getWireContent();
|
||||
const alg = this.getRoomDecryptor(event.getRoomId(), content.algorithm);
|
||||
return await alg.decryptEvent(event);
|
||||
return alg.decryptEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ interface IKey {
|
||||
iterations: number;
|
||||
}
|
||||
|
||||
export async function keyFromAuthData(authData: IAuthData, password: string): Promise<Uint8Array> {
|
||||
export function keyFromAuthData(authData: IAuthData, password: string): Promise<Uint8Array> {
|
||||
if (!global.Olm) {
|
||||
throw new Error("Olm is not available");
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export async function keyFromAuthData(authData: IAuthData, password: string): Pr
|
||||
);
|
||||
}
|
||||
|
||||
return await deriveKey(
|
||||
return deriveKey(
|
||||
password, authData.private_key_salt,
|
||||
authData.private_key_iterations,
|
||||
authData.private_key_bits || DEFAULT_BITSIZE,
|
||||
|
||||
@@ -271,9 +271,9 @@ export class SAS extends Base<SasEvent, EventHandlerMap> {
|
||||
do {
|
||||
try {
|
||||
if (this.initiatedByMe) {
|
||||
return await this.doSendVerification();
|
||||
return this.doSendVerification();
|
||||
} else {
|
||||
return await this.doRespondVerification();
|
||||
return this.doRespondVerification();
|
||||
}
|
||||
} catch (err) {
|
||||
if (err instanceof SwitchStartEventError) {
|
||||
|
||||
@@ -184,7 +184,7 @@ export class InRoomChannel implements IVerificationChannel {
|
||||
* @param {boolean} isLiveEvent whether this is an even received through sync or not
|
||||
* @returns {Promise} a promise that resolves when any requests as an answer to the passed-in event are sent.
|
||||
*/
|
||||
public async handleEvent(event: MatrixEvent, request: VerificationRequest, isLiveEvent = false): Promise<void> {
|
||||
public handleEvent(event: MatrixEvent, request: VerificationRequest, isLiveEvent = false): Promise<void> {
|
||||
// prevent processing the same event multiple times, as under
|
||||
// some circumstances Room.timeline can get emitted twice for the same event
|
||||
if (request.hasEventId(event.getId())) {
|
||||
@@ -221,8 +221,7 @@ export class InRoomChannel implements IVerificationChannel {
|
||||
const isRemoteEcho = !!event.getUnsigned().transaction_id;
|
||||
const isSentByUs = event.getSender() === this.client.getUserId();
|
||||
|
||||
return await request.handleEvent(
|
||||
type, event, isLiveEvent, isRemoteEcho, isSentByUs);
|
||||
return request.handleEvent(type, event, isLiveEvent, isRemoteEcho, isSentByUs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -30,7 +30,7 @@ import type { Request as _Request, CoreOptions } from "request";
|
||||
import * as callbacks from "./realtime-callbacks";
|
||||
import { IUploadOpts } from "./@types/requests";
|
||||
import { IAbortablePromise, IUsageLimit } from "./@types/partials";
|
||||
import { IDeferred } from "./utils";
|
||||
import { IDeferred, sleep } from "./utils";
|
||||
import { Callback } from "./client";
|
||||
import * as utils from "./utils";
|
||||
import { logger } from './logger';
|
||||
@@ -1114,9 +1114,9 @@ export async function retryNetworkOperation<T>(maxAttempts: number, callback: ()
|
||||
const timeout = 1000 * Math.pow(2, attempts);
|
||||
logger.log(`network operation failed ${attempts} times,` +
|
||||
` retrying in ${timeout}ms...`);
|
||||
await new Promise(r => setTimeout(r, timeout));
|
||||
await sleep(timeout);
|
||||
}
|
||||
return await callback();
|
||||
return callback();
|
||||
} catch (err) {
|
||||
if (err instanceof ConnectionError) {
|
||||
attempts += 1;
|
||||
|
||||
+1
-2
@@ -17,8 +17,7 @@ limitations under the License.
|
||||
import { MemoryCryptoStore } from "./crypto/store/memory-crypto-store";
|
||||
import { MemoryStore } from "./store/memory";
|
||||
import { MatrixScheduler } from "./scheduler";
|
||||
import { MatrixClient } from "./client";
|
||||
import { ICreateClientOpts } from "./client";
|
||||
import { MatrixClient, ICreateClientOpts } from "./client";
|
||||
import { DeviceTrustLevel } from "./crypto/CrossSigning";
|
||||
import { ISecretStorageKeyInfo } from "./crypto/api";
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ export class PushProcessor {
|
||||
|
||||
const memberCount = room.currentState.getJoinedMemberCount();
|
||||
|
||||
const m = cond.is.match(/^([=<>]*)([0-9]*)$/);
|
||||
const m = cond.is.match(/^([=<>]*)(\d*)$/);
|
||||
if (!m) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+9
-3
@@ -465,7 +465,7 @@ export function defer<T = void>(): IDeferred<T> {
|
||||
|
||||
export async function promiseMapSeries<T>(
|
||||
promises: Array<T | Promise<T>>,
|
||||
fn: (t: T) => void,
|
||||
fn: (t: T) => Promise<unknown> | void, // if async/promise we don't care about the type as we only await resolution
|
||||
): Promise<void> {
|
||||
for (const o of promises) {
|
||||
await fn(await o);
|
||||
@@ -473,7 +473,7 @@ export async function promiseMapSeries<T>(
|
||||
}
|
||||
|
||||
export function promiseTry<T>(fn: () => T | Promise<T>): Promise<T> {
|
||||
return new Promise((resolve) => resolve(fn()));
|
||||
return Promise.resolve(fn());
|
||||
}
|
||||
|
||||
// Creates and awaits all promises, running no more than `chunkSize` at the same time
|
||||
@@ -676,7 +676,13 @@ export function prevString(s: string, alphabet = DEFAULT_ALPHABET): string {
|
||||
export function lexicographicCompare(a: string, b: string): number {
|
||||
// Dev note: this exists because I'm sad that you can use math operators on strings, so I've
|
||||
// hidden the operation in this function.
|
||||
return (a < b) ? -1 : ((a === b) ? 0 : 1);
|
||||
if (a < b) {
|
||||
return -1;
|
||||
} else if (a > b) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const collator = new Intl.Collator();
|
||||
|
||||
+2
-4
@@ -988,9 +988,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
|
||||
* @param {string} desktopCapturerSourceId optional id of the desktop capturer source to use
|
||||
* @returns {boolean} new screensharing state
|
||||
*/
|
||||
public async setScreensharingEnabled(
|
||||
enabled: boolean, desktopCapturerSourceId?: string,
|
||||
): Promise<boolean> {
|
||||
public async setScreensharingEnabled(enabled: boolean, desktopCapturerSourceId?: string): Promise<boolean> {
|
||||
// Skip if there is nothing to do
|
||||
if (enabled && this.isScreensharing()) {
|
||||
logger.warn(`There is already a screensharing stream - there is nothing to do!`);
|
||||
@@ -1002,7 +1000,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
|
||||
|
||||
// Fallback to replaceTrack()
|
||||
if (!this.opponentSupportsSDPStreamMetadata()) {
|
||||
return await this.setScreensharingEnabledWithoutMetadataSupport(enabled, desktopCapturerSourceId);
|
||||
return this.setScreensharingEnabledWithoutMetadataSupport(enabled, desktopCapturerSourceId);
|
||||
}
|
||||
|
||||
logger.debug(`Set screensharing enabled? ${enabled}`);
|
||||
|
||||
Reference in New Issue
Block a user