diff --git a/spec/integ/crypto/rust-crypto.spec.ts b/spec/integ/crypto/rust-crypto.spec.ts index 2394d9a3e..7abf96e4e 100644 --- a/spec/integ/crypto/rust-crypto.spec.ts +++ b/spec/integ/crypto/rust-crypto.spec.ts @@ -67,6 +67,23 @@ describe("MatrixClient.initRustCrypto", () => { expect(databaseNames).toEqual(expect.arrayContaining(["matrix-js-sdk::matrix-sdk-crypto"])); }); + it("should create the indexed db with a custom prefix", async () => { + const matrixClient = createClient({ + baseUrl: "http://test.server", + userId: "@alice:localhost", + deviceId: "aliceDevice", + }); + + // No databases. + expect(await indexedDB.databases()).toHaveLength(0); + + await matrixClient.initRustCrypto({ cryptoDatabasePrefix: "my-prefix" }); + + // should have an indexed db now + const databaseNames = (await indexedDB.databases()).map((db) => db.name); + expect(databaseNames).toEqual(expect.arrayContaining(["my-prefix::matrix-sdk-crypto"])); + }); + it("should create the meta db if given a storageKey", async () => { const matrixClient = createClient({ baseUrl: "http://test.server", @@ -475,4 +492,22 @@ describe("MatrixClient.clearStores", () => { await matrixClient.clearStores(); // No error thrown in clearStores }); + + it("should clear the indexeddbs with a custom prefix", async () => { + const matrixClient = createClient({ + baseUrl: "http://test.server", + userId: "@alice:localhost", + deviceId: "aliceDevice", + }); + + // No databases. + expect(await indexedDB.databases()).toHaveLength(0); + + await matrixClient.initRustCrypto({ cryptoDatabasePrefix: "my-prefix" }); + expect(await indexedDB.databases()).toHaveLength(1); + await matrixClient.stopClient(); + + await matrixClient.clearStores({ cryptoDatabasePrefix: "my-prefix" }); + expect(await indexedDB.databases()).toHaveLength(0); + }); }); diff --git a/src/client.ts b/src/client.ts index 4686fcd42..64dfb62ec 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1527,9 +1527,14 @@ export class MatrixClient extends TypedEventEmitter { + public clearStores( + args: { + cryptoDatabasePrefix?: string; + } = {}, + ): Promise { if (this.clientRunning) { throw new Error("Cannot clear stores while client is running"); } @@ -1552,8 +1557,8 @@ export class MatrixClient extends TypedEventEmitter { this.logger.info(`Removing IndexedDB instance ${dbname}`); @@ -1901,6 +1906,8 @@ export class MatrixClient extends TypedEventEmitter