You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Fix more function typings relating to key backup (#2086)
* Fix more function typings relating to key backup * Use function overloads to specify allowed params
This commit is contained in:
109
src/client.ts
109
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;
|
let path;
|
||||||
if (sessionId !== undefined) {
|
if (sessionId !== undefined) {
|
||||||
path = utils.encodeUri("/room_keys/keys/$roomId/$sessionId", {
|
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
|
* @return {Promise} a promise that will resolve when the keys
|
||||||
* are uploaded
|
* 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) {
|
if (!this.crypto) {
|
||||||
throw new Error("End-to-end encryption disabled");
|
throw new Error("End-to-end encryption disabled");
|
||||||
}
|
}
|
||||||
@@ -2771,12 +2786,33 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||||
* key counts.
|
* 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(
|
public async restoreKeyBackupWithPassword(
|
||||||
password: string,
|
password: string,
|
||||||
targetRoomId: string,
|
targetRoomId: string,
|
||||||
targetSessionId: string,
|
targetSessionId: string,
|
||||||
backupInfo: IKeyBackupInfo,
|
backupInfo: IKeyBackupInfo,
|
||||||
opts: IKeyBackupRestoreOpts,
|
opts: IKeyBackupRestoreOpts,
|
||||||
|
): Promise<IKeyBackupRestoreResult>;
|
||||||
|
public async restoreKeyBackupWithPassword(
|
||||||
|
password: string,
|
||||||
|
targetRoomId: string | undefined,
|
||||||
|
targetSessionId: string | undefined,
|
||||||
|
backupInfo: IKeyBackupInfo,
|
||||||
|
opts: IKeyBackupRestoreOpts,
|
||||||
): Promise<IKeyBackupRestoreResult> {
|
): Promise<IKeyBackupRestoreResult> {
|
||||||
const privKey = await keyFromAuthData(backupInfo.auth_data, password);
|
const privKey = await keyFromAuthData(backupInfo.auth_data, password);
|
||||||
return this.restoreKeyBackup(
|
return this.restoreKeyBackup(
|
||||||
@@ -2833,22 +2869,61 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||||
* key counts.
|
* 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(
|
public restoreKeyBackupWithRecoveryKey(
|
||||||
recoveryKey: string,
|
recoveryKey: string,
|
||||||
targetRoomId: string,
|
targetRoomId: string,
|
||||||
targetSessionId: string,
|
targetSessionId: string,
|
||||||
backupInfo: IKeyBackupInfo,
|
backupInfo: IKeyBackupInfo,
|
||||||
opts: IKeyBackupRestoreOpts,
|
opts: IKeyBackupRestoreOpts,
|
||||||
|
): Promise<IKeyBackupRestoreResult>;
|
||||||
|
public restoreKeyBackupWithRecoveryKey(
|
||||||
|
recoveryKey: string,
|
||||||
|
targetRoomId: string | undefined,
|
||||||
|
targetSessionId: string | undefined,
|
||||||
|
backupInfo: IKeyBackupInfo,
|
||||||
|
opts: IKeyBackupRestoreOpts,
|
||||||
): Promise<IKeyBackupRestoreResult> {
|
): Promise<IKeyBackupRestoreResult> {
|
||||||
const privKey = decodeRecoveryKey(recoveryKey);
|
const privKey = decodeRecoveryKey(recoveryKey);
|
||||||
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
|
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(
|
public async restoreKeyBackupWithCache(
|
||||||
targetRoomId: string,
|
targetRoomId: string,
|
||||||
targetSessionId: string,
|
targetSessionId: string,
|
||||||
backupInfo: IKeyBackupInfo,
|
backupInfo: IKeyBackupInfo,
|
||||||
opts?: IKeyBackupRestoreOpts,
|
opts?: IKeyBackupRestoreOpts,
|
||||||
|
): Promise<IKeyBackupRestoreResult>;
|
||||||
|
public async restoreKeyBackupWithCache(
|
||||||
|
targetRoomId: string | undefined,
|
||||||
|
targetSessionId: string | undefined,
|
||||||
|
backupInfo: IKeyBackupInfo,
|
||||||
|
opts?: IKeyBackupRestoreOpts,
|
||||||
): Promise<IKeyBackupRestoreResult> {
|
): Promise<IKeyBackupRestoreResult> {
|
||||||
const privKey = await this.crypto.getSessionBackupPrivateKey();
|
const privKey = await this.crypto.getSessionBackupPrivateKey();
|
||||||
if (!privKey) {
|
if (!privKey) {
|
||||||
@@ -2857,12 +2932,33 @@ export class MatrixClient extends EventEmitter {
|
|||||||
return this.restoreKeyBackup(privKey, targetRoomId, targetSessionId, backupInfo, opts);
|
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(
|
private async restoreKeyBackup(
|
||||||
privKey: ArrayLike<number>,
|
privKey: ArrayLike<number>,
|
||||||
targetRoomId: string,
|
targetRoomId: string,
|
||||||
targetSessionId: string,
|
targetSessionId: string,
|
||||||
backupInfo: IKeyBackupInfo,
|
backupInfo: IKeyBackupInfo,
|
||||||
opts?: IKeyBackupRestoreOpts,
|
opts?: IKeyBackupRestoreOpts,
|
||||||
|
): Promise<IKeyBackupRestoreResult>;
|
||||||
|
private async restoreKeyBackup(
|
||||||
|
privKey: ArrayLike<number>,
|
||||||
|
targetRoomId: string | undefined,
|
||||||
|
targetSessionId: string | undefined,
|
||||||
|
backupInfo: IKeyBackupInfo,
|
||||||
|
opts?: IKeyBackupRestoreOpts,
|
||||||
): Promise<IKeyBackupRestoreResult> {
|
): Promise<IKeyBackupRestoreResult> {
|
||||||
const cacheCompleteCallback = opts?.cacheCompleteCallback;
|
const cacheCompleteCallback = opts?.cacheCompleteCallback;
|
||||||
const progressCallback = opts?.progressCallback;
|
const progressCallback = opts?.progressCallback;
|
||||||
@@ -2953,7 +3049,14 @@ export class MatrixClient extends EventEmitter {
|
|||||||
return { total: totalKeyCount, imported: keys.length };
|
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) {
|
if (!this.crypto) {
|
||||||
throw new Error("End-to-end encryption disabled");
|
throw new Error("End-to-end encryption disabled");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user