tauri_plugin_matrix_svelte/stronghold/
mod.rs

1// Code heavily inspired by the original Tauri Stronghold implementation available [here](https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/stronghold)
2
3//! Store secrets and keys using the [IOTA Stronghold](https://github.com/iotaledger/stronghold.rs) encrypted database and secure runtime.
4
5use std::{
6    collections::HashMap,
7    path::PathBuf,
8    sync::{Arc, Mutex},
9};
10
11use client::Stronghold;
12use tauri::{AppHandle, Manager, Runtime};
13
14use crate::utils::{config::get_plugin_config, fs::get_app_dir_or_create_it};
15
16pub mod builder;
17pub mod client;
18pub mod error;
19pub mod store;
20pub mod utils;
21
22#[derive(Default)]
23pub struct StrongholdCollection(Arc<Mutex<HashMap<PathBuf, Stronghold>>>);
24
25pub struct SnapshotPath(pub PathBuf);
26
27pub fn init_stronghold_client<R: Runtime>(app_handle: &AppHandle<R>) -> crate::Result<()> {
28    let plugin_config = get_plugin_config(&app_handle)?;
29
30    let app_dir = get_app_dir_or_create_it(&app_handle)?;
31
32    // stronghold config
33    let salt_path = app_dir.join("salt");
34    let snapshot_path = app_dir.join("matrix.stronghold");
35
36    let stronghold = builder::Builder::with_blake2(&salt_path);
37    stronghold.build_and_init(
38        &app_handle,
39        snapshot_path.clone(),
40        plugin_config.stronghold_password,
41    )?;
42
43    app_handle.manage(SnapshotPath(snapshot_path));
44    Ok(())
45}