Skip to content

Commit

Permalink
Use a constant for the indexeddb prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Dec 13, 2022
1 parent d4a54b2 commit df8d44b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ import { LocalNotificationSettings } from "./@types/local_notifications";
import { UNREAD_THREAD_NOTIFICATIONS } from "./@types/sync";
import { buildFeatureSupportMap, Feature, ServerSupport } from "./feature";
import { CryptoBackend } from "./common-crypto/CryptoBackend";
import { RUST_SDK_STORE_PREFIX } from "./rust-crypto/constants";

export type Store = IStore;

Expand Down Expand Up @@ -1667,7 +1668,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
// No indexeddb support
return;
}
for (const dbname of ["matrix-js-sdk::matrix-sdk-crypto", "matrix-js-sdk::matrix-sdk-crypto-meta"]) {
for (const dbname of [
`${RUST_SDK_STORE_PREFIX}::matrix-sdk-crypto`,
`${RUST_SDK_STORE_PREFIX}::matrix-sdk-crypto-meta`,
]) {
const prom = new Promise((resolve, reject) => {
logger.info(`Removing IndexedDB instance ${dbname}`);
const req = indexedDB.deleteDatabase(dbname);
Expand Down
18 changes: 18 additions & 0 deletions src/rust-crypto/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2022 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/** The prefix used on indexeddbs created by rust-crypto */
export const RUST_SDK_STORE_PREFIX = "matrix-js-sdk";
3 changes: 2 additions & 1 deletion src/rust-crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-js";
import { RustCrypto } from "./rust-crypto";
import { logger } from "../logger";
import { CryptoBackend } from "../common-crypto/CryptoBackend";
import { RUST_SDK_STORE_PREFIX } from "./constants";

export async function initRustCrypto(userId: string, deviceId: string): Promise<CryptoBackend> {
// initialise the rust matrix-sdk-crypto-js, if it hasn't already been done
Expand All @@ -32,7 +33,7 @@ export async function initRustCrypto(userId: string, deviceId: string): Promise<
logger.info("Init OlmMachine");

// TODO: use the pickle key for the passphrase
const olmMachine = await RustSdkCryptoJs.OlmMachine.initialize(u, d, "matrix-js-sdk", "test pass");
const olmMachine = await RustSdkCryptoJs.OlmMachine.initialize(u, d, RUST_SDK_STORE_PREFIX, "test pass");
const rustCrypto = new RustCrypto(olmMachine, userId, deviceId);

logger.info("Completed rust crypto-sdk setup");
Expand Down

0 comments on commit df8d44b

Please sign in to comment.