Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more function typings relating to key backup #2086

Merged
merged 2 commits into from
Dec 23, 2021
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 {
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
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,
hughns marked this conversation as resolved.
Show resolved Hide resolved
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,
hughns marked this conversation as resolved.
Show resolved Hide resolved
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,
hughns marked this conversation as resolved.
Show resolved Hide resolved
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,
hughns marked this conversation as resolved.
Show resolved Hide resolved
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> {
hughns marked this conversation as resolved.
Show resolved Hide resolved
if (!this.crypto) {
throw new Error("End-to-end encryption disabled");
}
Expand Down