Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 106 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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<void> {
public sendKeyBackup(roomId: undefined, sessionId: undefined, version: string, data: IKeyBackup): Promise<void>;
public sendKeyBackup(roomId: string, sessionId: undefined, version: string, data: IKeyBackup): Promise<void>;
public sendKeyBackup(roomId: string, sessionId: string, version: string, data: IKeyBackup): Promise<void>;
public sendKeyBackup(
roomId: string,
sessionId: string | undefined,
version: string | undefined,
data: IKeyBackup,
): Promise<void> {
if (!this.crypto) {
throw new Error("End-to-end encryption disabled");
}
Expand Down Expand Up @@ -2771,12 +2786,33 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
public async restoreKeyBackupWithPassword(
password: string,
targetRoomId: undefined,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public async restoreKeyBackupWithPassword(
password: string,
targetRoomId: string,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public async restoreKeyBackupWithPassword(
password: string,
targetRoomId: string,
targetSessionId: string,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public async restoreKeyBackupWithPassword(
password: string,
targetRoomId: string | undefined,
targetSessionId: string | undefined,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult> {
const privKey = await keyFromAuthData(backupInfo.auth_data, password);
return this.restoreKeyBackup(
Expand Down Expand Up @@ -2833,22 +2869,61 @@ export class MatrixClient extends EventEmitter {
* @return {Promise<object>} Status of restoration with `total` and `imported`
* key counts.
*/
public restoreKeyBackupWithRecoveryKey(
recoveryKey: string,
targetRoomId: undefined,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public restoreKeyBackupWithRecoveryKey(
recoveryKey: string,
targetRoomId: string,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public restoreKeyBackupWithRecoveryKey(
recoveryKey: string,
targetRoomId: string,
targetSessionId: string,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public restoreKeyBackupWithRecoveryKey(
recoveryKey: string,
targetRoomId: string | undefined,
targetSessionId: string | undefined,
backupInfo: IKeyBackupInfo,
opts: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult> {
const privKey = decodeRecoveryKey(recoveryKey);
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
}

public async restoreKeyBackupWithCache(
targetRoomId: undefined,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public async restoreKeyBackupWithCache(
targetRoomId: string,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public async restoreKeyBackupWithCache(
targetRoomId: string,
targetSessionId: string,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
public async restoreKeyBackupWithCache(
targetRoomId: string | undefined,
targetSessionId: string | undefined,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult> {
const privKey = await this.crypto.getSessionBackupPrivateKey();
if (!privKey) {
Expand All @@ -2857,12 +2932,33 @@ export class MatrixClient extends EventEmitter {
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
}

private async restoreKeyBackup(
privKey: ArrayLike<number>,
targetRoomId: undefined,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
private async restoreKeyBackup(
privKey: ArrayLike<number>,
targetRoomId: string,
targetSessionId: undefined,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
private async restoreKeyBackup(
privKey: ArrayLike<number>,
targetRoomId: string,
targetSessionId: string,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult>;
private async restoreKeyBackup(
privKey: ArrayLike<number>,
targetRoomId: string | undefined,
targetSessionId: string | undefined,
backupInfo: IKeyBackupInfo,
opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult> {
const cacheCompleteCallback = opts?.cacheCompleteCallback;
const progressCallback = opts?.progressCallback;
Expand Down Expand Up @@ -2953,7 +3049,14 @@ export class MatrixClient extends EventEmitter {
return { total: totalKeyCount, imported: keys.length };
}

public deleteKeysFromBackup(roomId: string, sessionId: string, version: string): Promise<void> {
public deleteKeysFromBackup(roomId: undefined, sessionId: undefined, version: string): Promise<void>;
public deleteKeysFromBackup(roomId: string, sessionId: undefined, version: string): Promise<void>;
public deleteKeysFromBackup(roomId: string, sessionId: string, version: string): Promise<void>;
public deleteKeysFromBackup(
roomId: string | undefined,
sessionId: string | undefined,
version: string,
): Promise<void> {
if (!this.crypto) {
throw new Error("End-to-end encryption disabled");
}
Expand Down