Skip to content

Commit

Permalink
Add CryptoApi.getBackupInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Nov 12, 2024
1 parent 23d2d03 commit bd75c71
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
15 changes: 15 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,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", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3352,7 +3352,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
8 changes: 8 additions & 0 deletions src/crypto-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@ export interface CryptoApi {
*/
isKeyBackupTrusted(info: KeyBackupInfo): Promise<BackupTrustInfo>;

/**
* Get information about the current key backup.
* 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 @@ -1318,6 +1318,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 @@ -1211,6 +1211,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

0 comments on commit bd75c71

Please sign in to comment.