diff --git a/spec/unit/crypto/backup.spec.ts b/spec/unit/crypto/backup.spec.ts index 2d655a90117..7b0136971c6 100644 --- a/spec/unit/crypto/backup.spec.ts +++ b/spec/unit/crypto/backup.spec.ts @@ -16,6 +16,7 @@ limitations under the License. */ import "../../olm-loader"; + import { logger } from "../../../src/logger"; import * as olmlib from "../../../src/crypto/olmlib"; import { MatrixClient } from "../../../src/client"; @@ -780,4 +781,12 @@ describe("MegolmBackup", function () { client.stopClient(); }); }); + + describe("getKeyBackupInfo", () => { + it("should return throw an `Not implemented`", async () => { + const client = makeTestClient(cryptoStore); + await client.initCrypto(); + await expect(client.getCrypto()?.getKeyBackupInfo()).rejects.toThrow("Not implemented"); + }); + }); }); diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index 117112dd09b..8fedadd0d42 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -1526,6 +1526,20 @@ describe("RustCrypto", () => { failures: 1, }); }); + + describe("getKeyBackupInfo", () => { + it("should return the current key backup info", async () => { + fetchMock.get("path:/_matrix/client/v3/room_keys/version", testData.SIGNED_BACKUP_DATA); + + const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi()); + await expect(rustCrypto.getKeyBackupInfo()).resolves.toStrictEqual(testData.SIGNED_BACKUP_DATA); + }); + + it("should return null if not available", async () => { + const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi()); + await expect(rustCrypto.getKeyBackupInfo()).resolves.toBeNull(); + }); + }); }); describe("device dehydration", () => { diff --git a/src/client.ts b/src/client.ts index 6337392badf..999517a1076 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3352,7 +3352,7 @@ export class MatrixClient extends TypedEventEmitter { let res: IKeyBackupInfo; diff --git a/src/crypto-api/index.ts b/src/crypto-api/index.ts index 1713bf1a8b2..7726ac24504 100644 --- a/src/crypto-api/index.ts +++ b/src/crypto-api/index.ts @@ -516,6 +516,14 @@ export interface CryptoApi { */ isKeyBackupTrusted(info: KeyBackupInfo): Promise; + /** + * Get information about the current key backup. + * Return null if there is no backup. + * + * @returns the key backup information + */ + getKeyBackupInfo(): Promise; + /** * Force a re-check of the key backup and enable/disable it as appropriate. * diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 2e3bef6eecc..d562cc30d07 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -1318,6 +1318,13 @@ export class Crypto extends TypedEventEmitter { + throw new Error("Not implemented"); + } + /** * Determine if a key backup can be trusted. * diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index c2c9b8304f0..5b3c7605736 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -1211,6 +1211,13 @@ export class RustCrypto extends TypedEventEmitter { + return (await this.backupManager.getServerBackupInfo()) || null; + } + /** * Determine if a key backup can be trusted. *