pub mod cache;
pub mod credential_storage;
pub mod credential_vault;
pub mod error;
pub mod keys;
pub mod paths;
pub mod traits;
pub mod types;
pub use cache::CacheDb;
pub use credential_storage::CredentialStore;
pub use credential_vault::CredentialVault;
pub use error::{StorageError, StorageResult};
pub use keys::StorageKeys;
pub use paths::StoragePaths;
pub use traits::{
ActivityChangedListener, AtomicBlobStore, DeviceKeystore, StorageProvider,
VaultChangedListener,
};
pub use types::{
ActivityEntry, ActivityFailureReason, ActivityMetadata, ActivityOutcome,
ActivityQuery, BlobKind, ContentId, CredentialRecord, Nullifier, ProtocolVersion,
ReplayGuardKind, ReplayGuardResult, RequestId,
};
pub use walletkit_db::{Lock as StorageLock, LockGuard as StorageLockGuard};
pub(crate) fn delete_database_files(path: &std::path::Path) {
for path in [
path.to_path_buf(),
path.with_extension("sqlite-journal"),
path.with_extension("sqlite-wal"),
path.with_extension("sqlite-shm"),
] {
if let Err(err) = delete_database_file(&path) {
tracing::error!("Failed to delete database file {}: {err}", path.display());
}
}
}
#[cfg(target_arch = "wasm32")]
fn delete_database_file(path: &std::path::Path) -> Result<(), String> {
walletkit_sqlite::opfs::delete_file(path).map_err(|err| err.to_string())
}
#[cfg(not(target_arch = "wasm32"))]
fn delete_database_file(path: &std::path::Path) -> Result<(), String> {
match std::fs::remove_file(path) {
Ok(()) => Ok(()),
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),
Err(err) => Err(err.to_string()),
}
}
#[cfg(target_arch = "wasm32")]
#[uniffi::export]
pub async fn initialize_persistent_storage() -> StorageResult<()> {
walletkit_sqlite::opfs::install()
.await
.map_err(|err| StorageError::PersistentStorage(err.to_string()))
}
pub(crate) const ACCOUNT_KEYS_FILENAME: &str = "account_keys.bin";
pub(crate) const ACCOUNT_KEY_ENVELOPE_AD: &[u8] = b"worldid:account-key-envelope";
#[cfg(test)]
pub(crate) mod tests_utils;