From 12cef67401e2e7fb605e8d83f773950b9ed6c9e5 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 17 Jun 2024 17:28:15 +0100 Subject: [PATCH] Remove support for legacy crypto stack in `StorageManager` We're not going to use the legacy stack any more. --- src/utils/StorageManager.ts | 75 +++++++++++++------------------------ 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/src/utils/StorageManager.ts b/src/utils/StorageManager.ts index 0cee3d9ef5dc..be9c9c417818 100644 --- a/src/utils/StorageManager.ts +++ b/src/utils/StorageManager.ts @@ -14,11 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { LocalStorageCryptoStore, IndexedDBStore, IndexedDBCryptoStore } from "matrix-js-sdk/src/matrix"; +import { IndexedDBStore, IndexedDBCryptoStore } from "matrix-js-sdk/src/matrix"; import { logger } from "matrix-js-sdk/src/logger"; -import SettingsStore from "../settings/SettingsStore"; -import { Features } from "../settings/Settings"; import { getIDBFactory } from "./StorageAccess"; const localStorage = window.localStorage; @@ -141,55 +139,34 @@ async function checkSyncStore(): Promise { } async function checkCryptoStore(): Promise { - if (await SettingsStore.getValue(Features.RustCrypto)) { - // check first if there is a rust crypto store - try { - const rustDbExists = await IndexedDBCryptoStore.exists(getIDBFactory()!, RUST_CRYPTO_STORE_NAME); - log(`Rust Crypto store using IndexedDB contains data? ${rustDbExists}`); - - if (rustDbExists) { - // There was an existing rust database, so consider it healthy. - return { exists: true, healthy: true }; - } else { - // No rust store, so let's check if there is a legacy store not yet migrated. - try { - const legacyIdbExists = await IndexedDBCryptoStore.existsAndIsNotMigrated( - getIDBFactory()!, - LEGACY_CRYPTO_STORE_NAME, - ); - log(`Legacy Crypto store using IndexedDB contains non migrated data? ${legacyIdbExists}`); - return { exists: legacyIdbExists, healthy: true }; - } catch (e) { - error("Legacy crypto store using IndexedDB inaccessible", e); - } - - // No need to check local storage or memory as rust stack doesn't support them. - // Given that rust stack requires indexeddb, set healthy to false. - return { exists: false, healthy: false }; + // check first if there is a rust crypto store + try { + const rustDbExists = await IndexedDBCryptoStore.exists(getIDBFactory()!, RUST_CRYPTO_STORE_NAME); + log(`Rust Crypto store using IndexedDB contains data? ${rustDbExists}`); + + if (rustDbExists) { + // There was an existing rust database, so consider it healthy. + return { exists: true, healthy: true }; + } else { + // No rust store, so let's check if there is a legacy store not yet migrated. + try { + const legacyIdbExists = await IndexedDBCryptoStore.existsAndIsNotMigrated( + getIDBFactory()!, + LEGACY_CRYPTO_STORE_NAME, + ); + log(`Legacy Crypto store using IndexedDB contains non migrated data? ${legacyIdbExists}`); + return { exists: legacyIdbExists, healthy: true }; + } catch (e) { + error("Legacy crypto store using IndexedDB inaccessible", e); } - } catch (e) { - error("Rust crypto store using IndexedDB inaccessible", e); + + // No need to check local storage or memory as rust stack doesn't support them. + // Given that rust stack requires indexeddb, set healthy to false. return { exists: false, healthy: false }; } - } else { - let exists = false; - // legacy checks - try { - exists = await IndexedDBCryptoStore.exists(getIDBFactory()!, LEGACY_CRYPTO_STORE_NAME); - log(`Crypto store using IndexedDB contains data? ${exists}`); - return { exists, healthy: true }; - } catch (e) { - error("Crypto store using IndexedDB inaccessible", e); - } - try { - exists = LocalStorageCryptoStore.exists(localStorage); - log(`Crypto store using local storage contains data? ${exists}`); - return { exists, healthy: true }; - } catch (e) { - error("Crypto store using local storage inaccessible", e); - } - log("Crypto store using memory only"); - return { exists, healthy: false }; + } catch (e) { + error("Rust crypto store using IndexedDB inaccessible", e); + return { exists: false, healthy: false }; } }