diff --git a/mutiny-core/src/lib.rs b/mutiny-core/src/lib.rs index 4d29407b8..4a6b63e1d 100644 --- a/mutiny-core/src/lib.rs +++ b/mutiny-core/src/lib.rs @@ -1775,7 +1775,7 @@ impl MutinyWallet { let device_id = storage.get_device_id()?; let logs: Option> = storage.get_data(LOGGING_KEY)?; storage.stop().await; - S::clear().await?; + S::clear(storage.database()?).await?; storage.start().await?; storage.insert_mnemonic(m)?; storage.write_data(NEED_FULL_SYNC_KEY.to_string(), true, None)?; diff --git a/mutiny-core/src/storage.rs b/mutiny-core/src/storage.rs index 66b0fc613..26a017e26 100644 --- a/mutiny-core/src/storage.rs +++ b/mutiny-core/src/storage.rs @@ -173,6 +173,8 @@ impl DeviceLock { #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait MutinyStorage: Clone + Sized + Send + Sync + 'static { + /// Database + fn database(&self) -> Result; /// Get the password used to encrypt the storage fn password(&self) -> Option<&str>; @@ -351,14 +353,14 @@ pub trait MutinyStorage: Clone + Sized + Send + Sync + 'static { } /// Override the storage with the new JSON object - async fn import(json: Value) -> Result<(), MutinyError>; + async fn import(database: String, json: Value) -> Result<(), MutinyError>; /// Deletes all data from the storage - async fn clear() -> Result<(), MutinyError>; + async fn clear(database: String) -> Result<(), MutinyError>; /// Deletes all data from the storage and removes lock from VSS async fn delete_all(&self) -> Result<(), MutinyError> { - Self::clear().await?; + Self::clear(self.database()?).await?; // remove lock from VSS if is is enabled if self.vss_client().is_some() { let device = self.get_device_id()?; @@ -553,6 +555,7 @@ pub trait MutinyStorage: Clone + Sized + Send + Sync + 'static { #[derive(Clone)] pub struct MemoryStorage { + pub database: String, pub password: Option, pub cipher: Option, pub memory: Arc>>, @@ -569,6 +572,7 @@ impl MemoryStorage { vss_client: Option>, ) -> Self { Self { + database: "memdb".to_string(), cipher, password, memory: Arc::new(RwLock::new(HashMap::new())), @@ -607,6 +611,9 @@ impl Default for MemoryStorage { #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl MutinyStorage for MemoryStorage { + fn database(&self) -> Result { + Ok(self.database.clone()) + } fn password(&self) -> Option<&str> { self.password.as_deref() } @@ -709,11 +716,11 @@ impl MutinyStorage for MemoryStorage { Ok(()) } - async fn import(_json: Value) -> Result<(), MutinyError> { + async fn import(_database: String, _json: Value) -> Result<(), MutinyError> { Ok(()) } - async fn clear() -> Result<(), MutinyError> { + async fn clear(_database: String) -> Result<(), MutinyError> { Ok(()) } @@ -740,6 +747,10 @@ impl MutinyStorage for MemoryStorage { #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl MutinyStorage for () { + fn database(&self) -> Result { + Ok(String::new()) + } + fn password(&self) -> Option<&str> { None } @@ -793,11 +804,11 @@ impl MutinyStorage for () { Ok(()) } - async fn import(_json: Value) -> Result<(), MutinyError> { + async fn import(_database: String, _json: Value) -> Result<(), MutinyError> { Ok(()) } - async fn clear() -> Result<(), MutinyError> { + async fn clear(_database: String) -> Result<(), MutinyError> { Ok(()) } diff --git a/mutiny-wasm/src/indexed_db.rs b/mutiny-wasm/src/indexed_db.rs index f10e123c2..321ea48a9 100644 --- a/mutiny-wasm/src/indexed_db.rs +++ b/mutiny-wasm/src/indexed_db.rs @@ -40,6 +40,7 @@ unsafe impl Sync for RexieContainer {} #[derive(Clone)] pub struct IndexedDbStorage { + pub(crate) database: String, pub(crate) password: Option, pub cipher: Option, /// In-memory cache of the wallet data @@ -56,18 +57,28 @@ pub struct IndexedDbStorage { impl IndexedDbStorage { pub async fn new( + database: String, password: Option, cipher: Option, vss: Option>, logger: Arc, ) -> Result { + if !database.starts_with(WALLET_DATABASE_NAME) { + log_error!( + logger, + "IndexedDB database must prefix with '{WALLET_DATABASE_NAME}', got '{database}'", + ); + return Err(MutinyError::PersistenceFailed { + source: MutinyStorageError::IndexedDBError, + }); + } log_debug!( logger, "Initialize indexed DB storage with password {} cipher {}", password.is_some(), cipher.is_some() ); - let idx = Self::build_indexed_db_database().await?; + let idx = Self::build_indexed_db_database(database.clone()).await?; let indexed_db = Arc::new(RwLock::new(RexieContainer(Some(idx)))); let password = password.filter(|p| !p.is_empty()); @@ -84,6 +95,7 @@ impl IndexedDbStorage { log_debug!(logger, "Complete initialize indexed DB storage"); Ok(IndexedDbStorage { + database, password, cipher, memory, @@ -96,8 +108,8 @@ impl IndexedDbStorage { }) } - pub(crate) async fn has_mnemonic() -> Result { - let indexed_db = Self::build_indexed_db_database().await?; + pub(crate) async fn has_mnemonic(database: String) -> Result { + let indexed_db = Self::build_indexed_db_database(database).await?; let tx = indexed_db .transaction(&[WALLET_OBJECT_STORE_NAME], TransactionMode::ReadOnly) .map_err(|e| { @@ -124,11 +136,12 @@ impl IndexedDbStorage { /// Read the mnemonic from indexed db, if one does not exist, /// then generate a new one and save it to indexed db. pub(crate) async fn get_mnemonic( + database: String, override_mnemonic: Option, password: Option<&str>, cipher: Option, ) -> Result { - let indexed_db = Self::build_indexed_db_database().await?; + let indexed_db = Self::build_indexed_db_database(database).await?; let tx = indexed_db .transaction(&[WALLET_OBJECT_STORE_NAME], TransactionMode::ReadWrite) .map_err(|e| { @@ -182,8 +195,8 @@ impl IndexedDbStorage { Ok(res) } - pub(crate) async fn get_logs() -> Result>, MutinyError> { - let indexed_db = Self::build_indexed_db_database().await?; + pub(crate) async fn get_logs(database: String) -> Result>, MutinyError> { + let indexed_db = Self::build_indexed_db_database(database).await?; let tx = indexed_db .transaction(&[WALLET_OBJECT_STORE_NAME], TransactionMode::ReadOnly) .map_err(|e| { @@ -640,8 +653,13 @@ impl IndexedDbStorage { Ok(None) } - async fn build_indexed_db_database() -> Result { - let rexie = Rexie::builder(WALLET_DATABASE_NAME) + async fn build_indexed_db_database(database: String) -> Result { + if database.is_empty() { + return Err(MutinyError::PersistenceFailed { + source: MutinyStorageError::IndexedDBError, + }); + } + let rexie = Rexie::builder(&database) .version(1) .add_object_store(ObjectStore::new(WALLET_OBJECT_STORE_NAME)) .build() @@ -689,6 +707,10 @@ fn used_once(key: &str) -> bool { #[async_trait(?Send)] impl MutinyStorage for IndexedDbStorage { + fn database(&self) -> Result { + Ok(self.database.clone()) + } + fn password(&self) -> Option<&str> { self.password.as_deref() } @@ -812,7 +834,7 @@ impl MutinyStorage for IndexedDbStorage { log_debug!(self.logger, "starting storage"); let indexed_db = if self.indexed_db.try_read()?.0.is_none() { Arc::new(RwLock::new(RexieContainer(Some( - Self::build_indexed_db_database().await?, + Self::build_indexed_db_database(self.database.clone()).await?, )))) } else { self.indexed_db.clone() @@ -891,9 +913,9 @@ impl MutinyStorage for IndexedDbStorage { Ok(()) } - async fn import(json: Value) -> Result<(), MutinyError> { - Self::clear().await?; - let indexed_db = Self::build_indexed_db_database().await?; + async fn import(database: String, json: Value) -> Result<(), MutinyError> { + Self::clear(database.clone()).await?; + let indexed_db = Self::build_indexed_db_database(database).await?; let tx = indexed_db .transaction(&[WALLET_OBJECT_STORE_NAME], TransactionMode::ReadWrite) .map_err(|e| { @@ -927,8 +949,8 @@ impl MutinyStorage for IndexedDbStorage { Ok(()) } - async fn clear() -> Result<(), MutinyError> { - let indexed_db = Self::build_indexed_db_database().await?; + async fn clear(database: String) -> Result<(), MutinyError> { + let indexed_db = Self::build_indexed_db_database(database).await?; let tx = indexed_db .transaction(&[WALLET_OBJECT_STORE_NAME], TransactionMode::ReadWrite) .map_err(|e| MutinyError::write_err(anyhow!("Failed clear indexed db: {e}").into()))?; @@ -986,9 +1008,15 @@ mod tests { log!("{test_name}"); let logger = Arc::new(MutinyLogger::default()); - let storage = IndexedDbStorage::new(Some("".to_string()), None, None, logger) - .await - .unwrap(); + let storage = IndexedDbStorage::new( + WALLET_DATABASE_NAME.to_string(), + Some("".to_string()), + None, + None, + logger, + ) + .await + .unwrap(); assert_eq!(storage.password, None); } @@ -1004,9 +1032,15 @@ mod tests { let logger = Arc::new(MutinyLogger::default()); let password = "password".to_string(); let cipher = encryption_key_from_pass(&password).unwrap(); - let storage = IndexedDbStorage::new(Some(password), Some(cipher), None, logger) - .await - .unwrap(); + let storage = IndexedDbStorage::new( + WALLET_DATABASE_NAME.to_string(), + Some(password), + Some(cipher), + None, + logger, + ) + .await + .unwrap(); let result: Option = storage.get(&key).unwrap(); assert_eq!(result, None); @@ -1036,7 +1070,9 @@ mod tests { assert_eq!(result, None); // clear the storage to clean up - IndexedDbStorage::clear().await.unwrap(); + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap(); } #[test] @@ -1051,14 +1087,22 @@ mod tests { } ); - IndexedDbStorage::import(json).await.unwrap(); + IndexedDbStorage::import(WALLET_DATABASE_NAME.to_string(), json) + .await + .unwrap(); let logger = Arc::new(MutinyLogger::default()); let password = "password".to_string(); let cipher = encryption_key_from_pass(&password).unwrap(); - let storage = IndexedDbStorage::new(Some(password), Some(cipher), None, logger) - .await - .unwrap(); + let storage = IndexedDbStorage::new( + WALLET_DATABASE_NAME.to_string(), + Some(password), + Some(cipher), + None, + logger, + ) + .await + .unwrap(); let result: Option = storage.get("test_key").unwrap(); assert_eq!(result, Some("test_value".to_string())); @@ -1067,7 +1111,9 @@ mod tests { assert_eq!(result, Some("test_value2".to_string())); // clear the storage to clean up - IndexedDbStorage::clear().await.unwrap(); + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap(); } #[test] @@ -1081,13 +1127,21 @@ mod tests { let logger = Arc::new(MutinyLogger::default()); let password = "password".to_string(); let cipher = encryption_key_from_pass(&password).unwrap(); - let storage = IndexedDbStorage::new(Some(password), Some(cipher), None, logger) - .await - .unwrap(); + let storage = IndexedDbStorage::new( + WALLET_DATABASE_NAME.to_string(), + Some(password), + Some(cipher), + None, + logger, + ) + .await + .unwrap(); storage.write_raw(vec![(key.clone(), value)]).unwrap(); - IndexedDbStorage::clear().await.unwrap(); + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap(); storage.reload_from_indexed_db().await.unwrap(); @@ -1095,7 +1149,9 @@ mod tests { assert_eq!(result, None); // clear the storage to clean up - IndexedDbStorage::clear().await.unwrap(); + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap(); } #[test] @@ -1106,16 +1162,19 @@ mod tests { let seed = Mnemonic::from_str("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about").expect("could not generate"); let logger = Arc::new(MutinyLogger::default()); - let storage = IndexedDbStorage::new(None, None, None, logger) - .await - .unwrap(); + let storage = + IndexedDbStorage::new(WALLET_DATABASE_NAME.to_string(), None, None, None, logger) + .await + .unwrap(); let mnemonic = storage.insert_mnemonic(seed).unwrap(); let stored_mnemonic = storage.get_mnemonic().unwrap(); assert_eq!(Some(mnemonic), stored_mnemonic); // clear the storage to clean up - IndexedDbStorage::clear().await.unwrap(); + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap(); } #[test] @@ -1128,9 +1187,15 @@ mod tests { let logger = Arc::new(MutinyLogger::default()); let password = "password".to_string(); let cipher = encryption_key_from_pass(&password).unwrap(); - let storage = IndexedDbStorage::new(Some(password), Some(cipher), None, logger) - .await - .unwrap(); + let storage = IndexedDbStorage::new( + WALLET_DATABASE_NAME.to_string(), + Some(password), + Some(cipher), + None, + logger, + ) + .await + .unwrap(); let mnemonic = storage.insert_mnemonic(seed).unwrap(); @@ -1138,7 +1203,9 @@ mod tests { assert_eq!(Some(mnemonic), stored_mnemonic); // clear the storage to clean up - IndexedDbStorage::clear().await.unwrap(); + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap(); } #[test] @@ -1147,9 +1214,15 @@ mod tests { log!("{test_name}"); let logger = Arc::new(MutinyLogger::default()); - let storage = IndexedDbStorage::new(None, None, None, logger.clone()) - .await - .unwrap(); + let storage = IndexedDbStorage::new( + WALLET_DATABASE_NAME.to_string(), + None, + None, + None, + logger.clone(), + ) + .await + .unwrap(); let seed = generate_seed(12).unwrap(); storage .write_data(MNEMONIC_KEY.to_string(), seed, None) @@ -1165,9 +1238,15 @@ mod tests { .transpose() .unwrap(); - let storage = IndexedDbStorage::new(password, cipher, None, logger) - .await - .unwrap(); + let storage = IndexedDbStorage::new( + WALLET_DATABASE_NAME.to_string(), + password, + cipher, + None, + logger, + ) + .await + .unwrap(); match storage.get_mnemonic() { Err(MutinyError::IncorrectPassword) => (), @@ -1176,6 +1255,8 @@ mod tests { } // clear the storage to clean up - IndexedDbStorage::clear().await.unwrap(); + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap(); } } diff --git a/mutiny-wasm/src/lib.rs b/mutiny-wasm/src/lib.rs index f2e9e72b7..34a53f55d 100644 --- a/mutiny-wasm/src/lib.rs +++ b/mutiny-wasm/src/lib.rs @@ -79,6 +79,7 @@ impl MutinyWallet { #[wasm_bindgen] #[allow(clippy::too_many_arguments)] pub async fn new( + database: String, password: Option, mnemonic_str: Option, websocket_proxy_addr: Option, @@ -130,6 +131,7 @@ impl MutinyWallet { }); match Self::new_internal( + database, password, mnemonic_str, websocket_proxy_addr, @@ -172,6 +174,7 @@ impl MutinyWallet { #[allow(clippy::too_many_arguments)] async fn new_internal( + database: String, password: Option, mnemonic_str: Option, websocket_proxy_addr: Option, @@ -212,9 +215,13 @@ impl MutinyWallet { let override_mnemonic = mnemonic_str.map(|s| Mnemonic::from_str(&s)).transpose()?; - let mnemonic = - IndexedDbStorage::get_mnemonic(override_mnemonic, password.as_deref(), cipher.clone()) - .await?; + let mnemonic = IndexedDbStorage::get_mnemonic( + database.clone(), + override_mnemonic, + password.as_deref(), + cipher.clone(), + ) + .await?; let seed = mnemonic.to_seed(""); let xprivkey = Xpriv::new_master(network, &seed).unwrap(); @@ -231,7 +238,8 @@ impl MutinyWallet { }) }; - let storage = IndexedDbStorage::new(password, cipher, vss_client, logger.clone()).await?; + let storage = + IndexedDbStorage::new(database, password, cipher, vss_client, logger.clone()).await?; let mut config_builder = MutinyWalletConfigBuilder::new(xprivkey).with_network(network); if let Some(w) = websocket_proxy_addr { @@ -311,13 +319,14 @@ impl MutinyWallet { /// Returns if there is a saved wallet in storage. /// This is checked by seeing if a mnemonic seed exists in storage. #[wasm_bindgen] - pub async fn has_node_manager() -> Result { - Ok(IndexedDbStorage::has_mnemonic().await?) + pub async fn has_node_manager(database: String) -> Result { + Ok(IndexedDbStorage::has_mnemonic(database).await?) } /// Returns the number of remaining seconds until the device lock expires. #[wasm_bindgen] pub async fn get_device_lock_remaining_secs( + database: String, password: Option, _auth_url: Option, storage_url: Option, @@ -329,7 +338,8 @@ impl MutinyWallet { .map(|p| encryption_key_from_pass(p)) .transpose()?; let mnemonic = - IndexedDbStorage::get_mnemonic(None, password.as_deref(), cipher.clone()).await?; + IndexedDbStorage::get_mnemonic(database, None, password.as_deref(), cipher.clone()) + .await?; let seed = mnemonic.to_seed(""); // Network doesn't matter here, only for encoding @@ -1018,8 +1028,10 @@ impl MutinyWallet { /// Exports the current state of the node manager to a json object. #[wasm_bindgen] - pub async fn get_logs() -> Result> */, MutinyJsError> { - let logs = IndexedDbStorage::get_logs().await?; + pub async fn get_logs( + database: String, + ) -> Result> */, MutinyJsError> { + let logs = IndexedDbStorage::get_logs(database).await?; Ok(JsValue::from_serde(&logs)?) } @@ -1042,7 +1054,10 @@ impl MutinyWallet { /// Exports the current state of the node manager to a json object. #[wasm_bindgen] - pub async fn export_json(password: Option) -> Result { + pub async fn export_json( + database: String, + password: Option, + ) -> Result { let logger = Arc::new(MutinyLogger::default()); let cipher = password .as_ref() @@ -1050,7 +1065,7 @@ impl MutinyWallet { .map(|p| encryption_key_from_pass(p)) .transpose()?; // todo init vss - let storage = IndexedDbStorage::new(password, cipher, None, logger).await?; + let storage = IndexedDbStorage::new(database, password, cipher, None, logger).await?; if storage.get_mnemonic().is_err() { // if we get an error, then we have the wrong password return Err(MutinyJsError::IncorrectPassword); @@ -1061,9 +1076,9 @@ impl MutinyWallet { /// Restore a node manager from a json object. #[wasm_bindgen] - pub async fn import_json(json: String) -> Result<(), MutinyJsError> { + pub async fn import_json(database: String, json: String) -> Result<(), MutinyJsError> { let json: serde_json::Value = serde_json::from_str(&json)?; - IndexedDbStorage::import(json).await?; + IndexedDbStorage::import(database, json).await?; Ok(()) } @@ -1082,6 +1097,7 @@ impl MutinyWallet { /// Should refresh or restart afterwards. Wallet should be stopped. #[wasm_bindgen] pub async fn restore_mnemonic( + database: String, m: String, password: Option, ) -> Result<(), MutinyJsError> { @@ -1091,7 +1107,8 @@ impl MutinyWallet { .filter(|p| !p.is_empty()) .map(|p| encryption_key_from_pass(p)) .transpose()?; - let storage = IndexedDbStorage::new(password, cipher, None, logger.clone()).await?; + let storage = + IndexedDbStorage::new(database, password, cipher, None, logger.clone()).await?; mutiny_core::MutinyWallet::::restore_mnemonic( storage, Mnemonic::from_str(&m).map_err(|_| MutinyJsError::InvalidMnemonic)?, @@ -1161,7 +1178,7 @@ mod tests { use crate::{uninit, MutinyWallet}; use crate::error::MutinyJsError; - use crate::indexed_db::IndexedDbStorage; + use crate::indexed_db::{IndexedDbStorage, WALLET_DATABASE_NAME}; use js_sys::Array; use mutiny_core::storage::MutinyStorage; use mutiny_core::utils::sleep; @@ -1176,8 +1193,13 @@ mod tests { log!("creating mutiny wallet!"); let password = Some("password".to_string()); - assert!(!MutinyWallet::has_node_manager().await.unwrap()); + assert!( + !MutinyWallet::has_node_manager(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap() + ); MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), password.clone(), None, None, @@ -1204,9 +1226,13 @@ mod tests { .await .expect("mutiny wallet should initialize"); sleep(1_000).await; - assert!(MutinyWallet::has_node_manager().await.unwrap()); + assert!( + MutinyWallet::has_node_manager(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap() + ); - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await; @@ -1215,6 +1241,7 @@ mod tests { #[test] async fn fail_to_create_wallet_different_seed() { MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), None, None, None, @@ -1241,11 +1268,16 @@ mod tests { .await .expect("mutiny wallet should initialize"); sleep(1_000).await; - assert!(MutinyWallet::has_node_manager().await.unwrap()); + assert!( + MutinyWallet::has_node_manager(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap() + ); uninit().await; let seed = mutiny_core::generate_seed(12).unwrap(); let result = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), None, Some(seed.to_string()), None, @@ -1277,7 +1309,7 @@ mod tests { Ok(_) => panic!("should have failed to create wallet with different seed"), } - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await; @@ -1288,8 +1320,13 @@ mod tests { log!("trying to create 2 mutiny wallets!"); let password = Some("password".to_string()); - assert!(!MutinyWallet::has_node_manager().await.unwrap()); + assert!( + !MutinyWallet::has_node_manager(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap() + ); MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), password.clone(), None, None, @@ -1316,10 +1353,15 @@ mod tests { .await .expect("mutiny wallet should initialize"); sleep(1_000).await; - assert!(MutinyWallet::has_node_manager().await.unwrap()); + assert!( + MutinyWallet::has_node_manager(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap() + ); // try to create a second let result = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), password.clone(), None, None, @@ -1351,7 +1393,7 @@ mod tests { panic!("should have failed to create a second mutiny wallet"); }; - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await; @@ -1366,11 +1408,12 @@ mod tests { let password = Some("password".to_string()); // make sure storage is empty - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); let nm = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), password.clone(), Some(seed.to_string()), None, @@ -1398,11 +1441,15 @@ mod tests { .unwrap(); log!("checking nm"); - assert!(MutinyWallet::has_node_manager().await.unwrap()); + assert!( + MutinyWallet::has_node_manager(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap() + ); log!("checking seed"); assert_eq!(seed.to_string(), nm.show_seed()); - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await; @@ -1415,11 +1462,12 @@ mod tests { let password = Some("password".to_string()); // make sure storage is empty - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); let mut nm = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), password.clone(), Some(seed.to_string()), None, @@ -1447,7 +1495,11 @@ mod tests { .unwrap(); log!("checking nm"); - assert!(MutinyWallet::has_node_manager().await.unwrap()); + assert!( + MutinyWallet::has_node_manager(WALLET_DATABASE_NAME.to_string()) + .await + .unwrap() + ); log!("checking seed"); assert_eq!(seed.to_string(), nm.show_seed()); nm.stop().await.unwrap(); @@ -1456,6 +1508,7 @@ mod tests { // create with incorrect password let result = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), None, Some(seed.to_string()), None, @@ -1485,7 +1538,7 @@ mod tests { panic!("should have failed to create wallet with incorrect password"); } - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await; @@ -1496,6 +1549,7 @@ mod tests { log!("creating new nodes"); let nm = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), Some("password".to_string()), None, None, @@ -1534,7 +1588,7 @@ mod tests { assert_ne!("", node_identity.uuid()); assert_ne!("", node_identity.pubkey()); - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await; @@ -1566,6 +1620,7 @@ mod tests { log!("getting logs with no password"); let nm = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), None, None, None, @@ -1607,13 +1662,15 @@ mod tests { // sleep to make sure logs save sleep(6_000).await; - let logs = MutinyWallet::get_logs().await.expect("should get logs"); + let logs = MutinyWallet::get_logs(WALLET_DATABASE_NAME.to_string()) + .await + .expect("should get logs"); let parsed_logs = js_to_option_vec_string(logs).expect("should parse logs"); assert!(parsed_logs.is_some()); assert!(!parsed_logs.clone().unwrap().is_empty()); assert_ne!("", parsed_logs.unwrap()[0]); - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await; @@ -1625,6 +1682,7 @@ mod tests { let password = Some("password".to_string()); let nm = MutinyWallet::new( + WALLET_DATABASE_NAME.to_string(), password.clone(), None, None, @@ -1666,13 +1724,15 @@ mod tests { // sleep to make sure logs save sleep(6_000).await; - let logs = MutinyWallet::get_logs().await.expect("should get logs"); + let logs = MutinyWallet::get_logs(WALLET_DATABASE_NAME.to_string()) + .await + .expect("should get logs"); let parsed_logs = js_to_option_vec_string(logs).expect("should parse logs"); assert!(parsed_logs.is_some()); assert!(!parsed_logs.clone().unwrap().is_empty()); assert_ne!("", parsed_logs.unwrap()[0]); - IndexedDbStorage::clear() + IndexedDbStorage::clear(WALLET_DATABASE_NAME.to_string()) .await .expect("failed to clear storage"); uninit().await;