From bd75c719125d91c8a4c01597d696880c6a622f0f Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Tue, 12 Nov 2024 11:25:59 +0100 Subject: [PATCH] Add `CryptoApi.getBackupInfo` --- spec/unit/rust-crypto/rust-crypto.spec.ts | 15 +++++++++++++++ src/client.ts | 2 +- src/crypto-api/index.ts | 8 ++++++++ src/crypto/index.ts | 7 +++++++ src/rust-crypto/rust-crypto.ts | 7 +++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index 117112dd09..bc8688c250 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -1526,6 +1526,21 @@ describe("RustCrypto", () => { failures: 1, }); }); + + 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()); + const olmMachine: OlmMachine = rustCrypto["olmMachine"]; + + const backupVersion = testData.SIGNED_BACKUP_DATA.version!; + await olmMachine.enableBackupV1( + (testData.SIGNED_BACKUP_DATA.auth_data as Curve25519AuthData).public_key, + backupVersion, + ); + + await expect(rustCrypto.getKeyBackupInfo()).resolves.toStrictEqual(testData.SIGNED_BACKUP_DATA); + }); }); describe("device dehydration", () => { diff --git a/src/client.ts b/src/client.ts index 6337392bad..999517a107 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 1713bf1a8b..7726ac2450 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 2e3bef6eec..d562cc30d0 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 c2c9b8304f..5b3c760573 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. *