Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CryptoApi.getBackupInfo #4512

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/unit/crypto/backup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
});
14 changes: 14 additions & 0 deletions spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3359,7 +3359,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
*
* @returns Information object from API, or null if no backup is present on the server.
*
* @deprecated Prefer {@link CryptoApi.getActiveSessionBackupVersion}.
* @deprecated Prefer {@link CryptoApi.getKeyBackupInfo}.
*/
public async getKeyBackupVersion(): Promise<IKeyBackupInfo | null> {
let res: IKeyBackupInfo;
Expand Down
12 changes: 12 additions & 0 deletions src/crypto-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,18 @@ export interface CryptoApi {
*/
isKeyBackupTrusted(info: KeyBackupInfo): Promise<BackupTrustInfo>;

/**
* 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<KeyBackupInfo | null>;

/**
* Force a re-check of the key backup and enable/disable it as appropriate.
*
Expand Down
7 changes: 7 additions & 0 deletions src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,13 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
return null;
}

/**
* Implementation of {@link Crypto.CryptoApi#getKeyBackupInfo}.
*/
public async getKeyBackupInfo(): Promise<KeyBackupInfo | null> {
throw new Error("Not implemented");
}

/**
* Determine if a key backup can be trusted.
*
Expand Down
7 changes: 7 additions & 0 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,13 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
return await this.backupManager.getActiveBackupVersion();
}

/**
* Implementation of {@link CryptoApi#getKeyBackupInfo}.
*/
public async getKeyBackupInfo(): Promise<KeyBackupInfo | null> {
return (await this.backupManager.getServerBackupInfo()) || null;
}

/**
* Determine if a key backup can be trusted.
*
Expand Down
Loading