From 2922c1691ab4499af6a07034323cc78d95c9d710 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 13 Jun 2023 15:38:33 +0530 Subject: [PATCH] Add return type to methods --- src/matrix/ssss/SecretSharing.ts | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/matrix/ssss/SecretSharing.ts b/src/matrix/ssss/SecretSharing.ts index cedd8d3a..43c2057d 100644 --- a/src/matrix/ssss/SecretSharing.ts +++ b/src/matrix/ssss/SecretSharing.ts @@ -77,16 +77,14 @@ export class SecretSharing { this.crossSigning = options.crossSigning; this.logger = options.logger; this.aesEncryption = new AESEncryption(this.storage, options.crypto, this.encoding); - (window as any).foo = this; - this.init(); } - private async init() { + async load(): Promise { this.deviceMessageHandler.on("message", async ({ encrypted }) => { const type: EVENT_TYPE = encrypted?.event.type; switch (type) { case EVENT_TYPE.REQUEST: { - this._respondToRequest(encrypted); + await this._respondToRequest(encrypted); break; } case EVENT_TYPE.SEND: { @@ -102,9 +100,9 @@ export class SecretSharing { await this.aesEncryption.load(); } - private async _respondToRequest(request) { + private async _respondToRequest(request): Promise { await this.logger.run("SharedSecret.respondToRequest", async (log) => { - if (!this.shouldRespondToRequest(request, log)) { + if (!await this.shouldRespondToRequest(request, log)) { return; } const requestContent = request.event.content; @@ -127,9 +125,7 @@ export class SecretSharing { } const messages = await log.wrap("olm encrypt", log => this.olmEncryption.encrypt( EVENT_TYPE.SEND, content, [device], this.hsApi, log)); - console.log("messages", messages); const payload = formatToDeviceMessagesPayload(messages); - console.log("payload", payload); await this.hsApi.sendToDevice("m.room.encrypted", payload, makeTxnId(), {log}).response(); }); } @@ -162,7 +158,7 @@ export class SecretSharing { // 2. Validate message format // 3. Check if this is a cancellation return false; - } + } // 3. Check that the device is verified const deviceId = content.requesting_device_id; @@ -176,8 +172,7 @@ export class SecretSharing { return false; } return true; - }) - + }); } /** @@ -185,7 +180,7 @@ export class SecretSharing { * Returns undefined otherwise. * @param decryptionResult Encrypted to-device event that contains the secret */ - async shouldAcceptSecret(decryptionResult: DecryptionResult): Promise { + private async shouldAcceptSecret(decryptionResult: DecryptionResult): Promise { // 1. Check if we can trust this response const crossSigning = this.crossSigning.get(); if (!crossSigning) { @@ -221,7 +216,7 @@ export class SecretSharing { } } - async removeStoredRequestId(requestId: string): Promise { + private async removeStoredRequestId(requestId: string): Promise { const txn = await this.storage.readWriteTxn([this.storage.storeNames.session]); const storedIds = await txn.session.get(STORAGE_KEY); if (storedIds) { @@ -280,7 +275,7 @@ export class SecretSharing { return deferred.promise; } - private async sendRequestForSecret(name: string, request_id: string, log: ILogItem) { + private async sendRequestForSecret(name: string, request_id: string, log: ILogItem): Promise { const content = { action: "request", name, @@ -291,9 +286,7 @@ export class SecretSharing { devices = devices.filter(d => d.device_id !== this.deviceTracker.ownDeviceId); const messages = await log.wrap("olm encrypt", log => this.olmEncryption.encrypt( EVENT_TYPE.REQUEST, content, devices, this.hsApi, log)); - console.log("messages", messages); const payload = formatToDeviceMessagesPayload(messages); - console.log("payload", payload); await this.hsApi.sendToDevice("m.room.encrypted", payload, makeTxnId(), {log}).response(); } @@ -333,7 +326,7 @@ class AESEncryption { constructor(private storage: Storage, private crypto: Crypto, private encoding: Encoding) { }; - async load() { + async load(): Promise { const storageKey = `${SESSION_E2EE_KEY_PREFIX}localAESKey`; // 1. Check if we're already storing the AES key const txn = await this.storage.readTxn([StoreNames.session]); @@ -343,8 +336,8 @@ class AESEncryption { if (!key) { /** * Element creates the key as "non-extractable", meaning that it cannot - * be exported through the crypto API. But since it is going - * to end up in local-storage anyway, I don't see a reason to do that. + * be exported through the crypto DOM API. But since it's going + * to end up in indexeddb anyway, it really doesn't matter. */ key = await this.crypto.aes.generateKey("jwk"); iv = await this.crypto.aes.generateIV();