Skip to content

Commit 781c3b0

Browse files
authored
Add CryptoApi.getBackupInfo (#4512)
* Add `CryptoApi.getBackupInfo` * improve doc
1 parent 325dace commit 781c3b0

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

spec/unit/crypto/backup.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -780,4 +780,12 @@ describe("MegolmBackup", function () {
780780
client.stopClient();
781781
});
782782
});
783+
784+
describe("getKeyBackupInfo", () => {
785+
it("should return throw an `Not implemented`", async () => {
786+
const client = makeTestClient(cryptoStore);
787+
await client.initCrypto();
788+
await expect(client.getCrypto()?.getKeyBackupInfo()).rejects.toThrow("Not implemented");
789+
});
790+
});
783791
});

spec/unit/rust-crypto/rust-crypto.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,20 @@ describe("RustCrypto", () => {
15261526
failures: 1,
15271527
});
15281528
});
1529+
1530+
describe("getKeyBackupInfo", () => {
1531+
it("should return the current key backup info", async () => {
1532+
fetchMock.get("path:/_matrix/client/v3/room_keys/version", testData.SIGNED_BACKUP_DATA);
1533+
1534+
const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi());
1535+
await expect(rustCrypto.getKeyBackupInfo()).resolves.toStrictEqual(testData.SIGNED_BACKUP_DATA);
1536+
});
1537+
1538+
it("should return null if not available", async () => {
1539+
const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi());
1540+
await expect(rustCrypto.getKeyBackupInfo()).resolves.toBeNull();
1541+
});
1542+
});
15291543
});
15301544

15311545
describe("device dehydration", () => {

src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3359,7 +3359,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
33593359
*
33603360
* @returns Information object from API, or null if no backup is present on the server.
33613361
*
3362-
* @deprecated Prefer {@link CryptoApi.getActiveSessionBackupVersion}.
3362+
* @deprecated Prefer {@link CryptoApi.getKeyBackupInfo}.
33633363
*/
33643364
public async getKeyBackupVersion(): Promise<IKeyBackupInfo | null> {
33653365
let res: IKeyBackupInfo;

src/crypto-api/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,18 @@ export interface CryptoApi {
534534
*/
535535
isKeyBackupTrusted(info: KeyBackupInfo): Promise<BackupTrustInfo>;
536536

537+
/**
538+
* Return the details of the latest backup on the server, when we last checked.
539+
*
540+
* This normally returns a cached value, but if we haven't yet made a request to the server, it will fire one off.
541+
* It will always return the details of the active backup if key backup is enabled.
542+
*
543+
* Return null if there is no backup.
544+
*
545+
* @returns the key backup information
546+
*/
547+
getKeyBackupInfo(): Promise<KeyBackupInfo | null>;
548+
537549
/**
538550
* Force a re-check of the key backup and enable/disable it as appropriate.
539551
*

src/crypto/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,13 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
13271327
return null;
13281328
}
13291329

1330+
/**
1331+
* Implementation of {@link Crypto.CryptoApi#getKeyBackupInfo}.
1332+
*/
1333+
public async getKeyBackupInfo(): Promise<KeyBackupInfo | null> {
1334+
throw new Error("Not implemented");
1335+
}
1336+
13301337
/**
13311338
* Determine if a key backup can be trusted.
13321339
*

src/rust-crypto/rust-crypto.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,13 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
12331233
return await this.backupManager.getActiveBackupVersion();
12341234
}
12351235

1236+
/**
1237+
* Implementation of {@link CryptoApi#getKeyBackupInfo}.
1238+
*/
1239+
public async getKeyBackupInfo(): Promise<KeyBackupInfo | null> {
1240+
return (await this.backupManager.getServerBackupInfo()) || null;
1241+
}
1242+
12361243
/**
12371244
* Determine if a key backup can be trusted.
12381245
*

0 commit comments

Comments
 (0)