diff --git a/spec/unit/crypto/backup.spec.ts b/spec/unit/crypto/backup.spec.ts index 2d655a90117..28bb0d4c443 100644 --- a/spec/unit/crypto/backup.spec.ts +++ b/spec/unit/crypto/backup.spec.ts @@ -780,4 +780,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 44ed6216b1a..1bd3fb3f3a3 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3359,7 +3359,7 @@ export class MatrixClient extends TypedEventEmitter { let res: IKeyBackupInfo; diff --git a/src/crypto-api/index.ts b/src/crypto-api/index.ts index 4a89b7b443d..89ece07acbe 100644 --- a/src/crypto-api/index.ts +++ b/src/crypto-api/index.ts @@ -534,6 +534,18 @@ export interface CryptoApi { */ isKeyBackupTrusted(info: KeyBackupInfo): Promise; + /** + * Return the details of the latest backup on the server, when we last checked. + * + * This normally returns a cached value, but if we haven't yet made a request to the server, it will fire one off. + * It will always return the details of the active backup if key backup is enabled. + * + * 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 c75589813e7..8cb04dd5e03 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -1327,6 +1327,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 333af68ca47..82760bed13e 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -1233,6 +1233,13 @@ export class RustCrypto extends TypedEventEmitter { + return (await this.backupManager.getServerBackupInfo()) || null; + } + /** * Determine if a key backup can be trusted. *