diff --git a/src/client.ts b/src/client.ts index aff7be4d178..b5d59936ebd 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2658,7 +2658,14 @@ export class MatrixClient extends EventEmitter { ); } - private makeKeyBackupPath(roomId: string, sessionId: string, version: string): IKeyBackupPath { + private makeKeyBackupPath(roomId: undefined, sessionId: undefined, version: string): IKeyBackupPath; + private makeKeyBackupPath(roomId: string, sessionId: undefined, version: string): IKeyBackupPath; + private makeKeyBackupPath(roomId: string, sessionId: string, version: string): IKeyBackupPath; + private makeKeyBackupPath( + roomId: string | undefined, + sessionId: string | undefined, + version: string, + ): IKeyBackupPath { let path; if (sessionId !== undefined) { path = utils.encodeUri("/room_keys/keys/$roomId/$sessionId", { @@ -2685,7 +2692,15 @@ export class MatrixClient extends EventEmitter { * @return {Promise} a promise that will resolve when the keys * are uploaded */ - public sendKeyBackup(roomId: string, sessionId: string, version: string, data: IKeyBackup): Promise { + public sendKeyBackup(roomId: undefined, sessionId: undefined, version: string, data: IKeyBackup): Promise; + public sendKeyBackup(roomId: string, sessionId: undefined, version: string, data: IKeyBackup): Promise; + public sendKeyBackup(roomId: string, sessionId: string, version: string, data: IKeyBackup): Promise; + public sendKeyBackup( + roomId: string, + sessionId: string | undefined, + version: string | undefined, + data: IKeyBackup, + ): Promise { if (!this.crypto) { throw new Error("End-to-end encryption disabled"); } @@ -2771,12 +2786,33 @@ export class MatrixClient extends EventEmitter { * @return {Promise} Status of restoration with `total` and `imported` * key counts. */ + public async restoreKeyBackupWithPassword( + password: string, + targetRoomId: undefined, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts: IKeyBackupRestoreOpts, + ): Promise; + public async restoreKeyBackupWithPassword( + password: string, + targetRoomId: string, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts: IKeyBackupRestoreOpts, + ): Promise; public async restoreKeyBackupWithPassword( password: string, targetRoomId: string, targetSessionId: string, backupInfo: IKeyBackupInfo, opts: IKeyBackupRestoreOpts, + ): Promise; + public async restoreKeyBackupWithPassword( + password: string, + targetRoomId: string | undefined, + targetSessionId: string | undefined, + backupInfo: IKeyBackupInfo, + opts: IKeyBackupRestoreOpts, ): Promise { const privKey = await keyFromAuthData(backupInfo.auth_data, password); return this.restoreKeyBackup( @@ -2833,22 +2869,61 @@ export class MatrixClient extends EventEmitter { * @return {Promise} Status of restoration with `total` and `imported` * key counts. */ + public restoreKeyBackupWithRecoveryKey( + recoveryKey: string, + targetRoomId: undefined, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts: IKeyBackupRestoreOpts, + ): Promise; + public restoreKeyBackupWithRecoveryKey( + recoveryKey: string, + targetRoomId: string, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts: IKeyBackupRestoreOpts, + ): Promise; public restoreKeyBackupWithRecoveryKey( recoveryKey: string, targetRoomId: string, targetSessionId: string, backupInfo: IKeyBackupInfo, opts: IKeyBackupRestoreOpts, + ): Promise; + public restoreKeyBackupWithRecoveryKey( + recoveryKey: string, + targetRoomId: string | undefined, + targetSessionId: string | undefined, + backupInfo: IKeyBackupInfo, + opts: IKeyBackupRestoreOpts, ): Promise { const privKey = decodeRecoveryKey(recoveryKey); return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts); } + public async restoreKeyBackupWithCache( + targetRoomId: undefined, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts?: IKeyBackupRestoreOpts, + ): Promise; + public async restoreKeyBackupWithCache( + targetRoomId: string, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts?: IKeyBackupRestoreOpts, + ): Promise; public async restoreKeyBackupWithCache( targetRoomId: string, targetSessionId: string, backupInfo: IKeyBackupInfo, opts?: IKeyBackupRestoreOpts, + ): Promise; + public async restoreKeyBackupWithCache( + targetRoomId: string | undefined, + targetSessionId: string | undefined, + backupInfo: IKeyBackupInfo, + opts?: IKeyBackupRestoreOpts, ): Promise { const privKey = await this.crypto.getSessionBackupPrivateKey(); if (!privKey) { @@ -2857,12 +2932,33 @@ export class MatrixClient extends EventEmitter { return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts); } + private async restoreKeyBackup( + privKey: ArrayLike, + targetRoomId: undefined, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts?: IKeyBackupRestoreOpts, + ): Promise; + private async restoreKeyBackup( + privKey: ArrayLike, + targetRoomId: string, + targetSessionId: undefined, + backupInfo: IKeyBackupInfo, + opts?: IKeyBackupRestoreOpts, + ): Promise; private async restoreKeyBackup( privKey: ArrayLike, targetRoomId: string, targetSessionId: string, backupInfo: IKeyBackupInfo, opts?: IKeyBackupRestoreOpts, + ): Promise; + private async restoreKeyBackup( + privKey: ArrayLike, + targetRoomId: string | undefined, + targetSessionId: string | undefined, + backupInfo: IKeyBackupInfo, + opts?: IKeyBackupRestoreOpts, ): Promise { const cacheCompleteCallback = opts?.cacheCompleteCallback; const progressCallback = opts?.progressCallback; @@ -2953,7 +3049,14 @@ export class MatrixClient extends EventEmitter { return { total: totalKeyCount, imported: keys.length }; } - public deleteKeysFromBackup(roomId: string, sessionId: string, version: string): Promise { + public deleteKeysFromBackup(roomId: undefined, sessionId: undefined, version: string): Promise; + public deleteKeysFromBackup(roomId: string, sessionId: undefined, version: string): Promise; + public deleteKeysFromBackup(roomId: string, sessionId: string, version: string): Promise; + public deleteKeysFromBackup( + roomId: string | undefined, + sessionId: string | undefined, + version: string, + ): Promise { if (!this.crypto) { throw new Error("End-to-end encryption disabled"); }