diff --git a/src/matrix/Session.js b/src/matrix/Session.js index c5aedcb3..23c9cce6 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -252,7 +252,9 @@ export class Session { this._keyBackup.get().dispose(); this._keyBackup.set(undefined); } - if (this._crossSigning.get()) { + const crossSigning = this._crossSigning.get(); + if (crossSigning) { + crossSigning.dispose(); this._crossSigning.set(undefined); } const key = await ssssKeyFromCredential(type, credential, this._storage, this._platform, this._olm); @@ -317,7 +319,9 @@ export class Session { this._keyBackup.get().dispose(); this._keyBackup.set(undefined); } - if (this._crossSigning.get()) { + const crossSigning = this._crossSigning.get(); + if (crossSigning) { + crossSigning.dispose(); this._crossSigning.set(undefined); } } @@ -374,6 +378,9 @@ export class Session { if (await crossSigning.load(log)) { this._crossSigning.set(crossSigning); } + else { + crossSigning.dispose(); + } }); } } catch (err) { @@ -547,6 +554,7 @@ export class Session { this._e2eeAccount = undefined; this._callHandler?.dispose(); this._callHandler = undefined; + this._crossSigning.get()?.dispose(); for (const room of this._rooms.values()) { room.dispose(); } diff --git a/src/matrix/verification/CrossSigning.ts b/src/matrix/verification/CrossSigning.ts index 591d57cc..c23c2f54 100644 --- a/src/matrix/verification/CrossSigning.ts +++ b/src/matrix/verification/CrossSigning.ts @@ -119,10 +119,8 @@ export class CrossSigning { this.deviceId = options.deviceId; this.e2eeAccount = options.e2eeAccount this.deviceMessageHandler = options.deviceMessageHandler; - - this.deviceMessageHandler.on("message", async ({ unencrypted: unencryptedEvent }) => { - this._handleSASDeviceMessage(unencryptedEvent); - }) + this.handleSASDeviceMessage = this.handleSASDeviceMessage.bind(this); + this.deviceMessageHandler.on("message", this.handleSASDeviceMessage); } /** @return {boolean} whether cross signing has been enabled on this account */ @@ -209,7 +207,7 @@ export class CrossSigning { return this.sasVerificationInProgress; } - private _handleSASDeviceMessage(event: any) { + private handleSASDeviceMessage({ unencrypted: event }) { const txnId = event.content.transaction_id; /** * If we receive an event for the current/previously finished @@ -376,6 +374,10 @@ export class CrossSigning { }); } + dispose(): void { + this.deviceMessageHandler.off("message", this.handleSASDeviceMessage); + } + observeUserTrust(userId: string, log: ILogItem): BaseObservableValue { const existingValue = this.observedUsers.get(userId); if (existingValue) {