Skip to content

Commit 2a19422

Browse files
committed
Add CryptoApi.getBackupInfo
1 parent 635879e commit 2a19422

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-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
@@ -3352,7 +3352,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
33523352
*
33533353
* @returns Information object from API, or null if no backup is present on the server.
33543354
*
3355-
* @deprecated Prefer {@link CryptoApi.getActiveSessionBackupVersion}.
3355+
* @deprecated Prefer {@link CryptoApi.getKeyBackupInfo}.
33563356
*/
33573357
public async getKeyBackupVersion(): Promise<IKeyBackupInfo | null> {
33583358
let res: IKeyBackupInfo;

src/crypto-api/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,14 @@ export interface CryptoApi {
516516
*/
517517
isKeyBackupTrusted(info: KeyBackupInfo): Promise<BackupTrustInfo>;
518518

519+
/**
520+
* Get information about the current key backup.
521+
* Return null if there is no backup.
522+
*
523+
* @returns the key backup information
524+
*/
525+
getKeyBackupInfo(): Promise<KeyBackupInfo | null>;
526+
519527
/**
520528
* Force a re-check of the key backup and enable/disable it as appropriate.
521529
*

src/crypto/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,13 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
13181318
return null;
13191319
}
13201320

1321+
/**
1322+
* Implementation of {@link Crypto.CryptoApi#getKeyBackupInfo}.
1323+
*/
1324+
public async getKeyBackupInfo(): Promise<KeyBackupInfo | null> {
1325+
throw new Error("Not implemented");
1326+
}
1327+
13211328
/**
13221329
* Determine if a key backup can be trusted.
13231330
*

src/rust-crypto/rust-crypto.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,13 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
12111211
return await this.backupManager.getActiveBackupVersion();
12121212
}
12131213

1214+
/**
1215+
* Implementation of {@link CryptoApi#getKeyBackupInfo}.
1216+
*/
1217+
public async getKeyBackupInfo(): Promise<KeyBackupInfo | null> {
1218+
return (await this.backupManager.getServerBackupInfo()) || null;
1219+
}
1220+
12141221
/**
12151222
* Determine if a key backup can be trusted.
12161223
*

0 commit comments

Comments
 (0)