//! Core abstractions for platform-agnostic cryptography and storage use crate::domain::entities::*; use crate::domain::error::DomainError; /// Mnemonic generation trait pub trait MnemonicGenerator { type Error: Into; fn generate(&self) -> Result; fn validate(&self, words: &[String]) -> Result<(), Self::Error>; } /// Key derivation trait pub trait KeyDeriver { type Error: Into; fn derive_from_seed(&self, seed: &Seed) -> Result<(PublicKey, PrivateKey), Self::Error>; fn derive_from_mnemonic(&self, mnemonic: &RecoveryPhrase, univ_id: &str) -> Result; } /// File encryption trait pub trait FileEncryptor { type Error: Into; fn encrypt( &self, seed: &Seed, password: &str, public_key: &PublicKey, did: &Did, univ_id: &str, user_profiles: &[UserProfile], ) -> Result; fn decrypt( &self, file: &PassportFile, password: &str, ) -> Result<(Seed, PublicKey, PrivateKey, Vec), Self::Error>; } /// Storage trait for passport files #[cfg_attr(target_arch = "wasm32", async_trait::async_trait)] #[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait(?Send))] pub trait FileStorage { type Error: Into; async fn save(&self, file: &PassportFile, path: &str) -> Result<(), Self::Error>; async fn load(&self, path: &str) -> Result; } /// Random number generation trait pub trait RngCore { type Error: Into; fn fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error>; } /// Time provider trait pub trait TimeProvider { type Error: Into; fn now_seconds(&self) -> Result; }