From df8d44b57d37fa0139e44411e20a4ca4d2541ae1 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 13 Dec 2022 11:12:42 +0000 Subject: [PATCH] Use a constant for the indexeddb prefix --- src/client.ts | 6 +++++- src/rust-crypto/constants.ts | 18 ++++++++++++++++++ src/rust-crypto/index.ts | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/rust-crypto/constants.ts diff --git a/src/client.ts b/src/client.ts index f3fe0cda6c9..31bf5145d26 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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; @@ -1667,7 +1668,10 @@ export class MatrixClient extends TypedEventEmitter { logger.info(`Removing IndexedDB instance ${dbname}`); const req = indexedDB.deleteDatabase(dbname); diff --git a/src/rust-crypto/constants.ts b/src/rust-crypto/constants.ts new file mode 100644 index 00000000000..9d72060c379 --- /dev/null +++ b/src/rust-crypto/constants.ts @@ -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"; diff --git a/src/rust-crypto/index.ts b/src/rust-crypto/index.ts index 5af74efde3c..7485836cdc2 100644 --- a/src/rust-crypto/index.ts +++ b/src/rust-crypto/index.ts @@ -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 { // initialise the rust matrix-sdk-crypto-js, if it hasn't already been done @@ -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");