use crate::store::{BaseData, IndexKey, Object}; use serde::{Deserialize, Serialize}; /// Category of the secret box #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum SecretBoxCategory { Profile, } impl Default for SecretBoxCategory { fn default() -> Self { SecretBoxCategory::Profile } } /// Status of a notary #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum NotaryStatus { Active, Inactive, Suspended, Archived, Error, } impl Default for NotaryStatus { fn default() -> Self { NotaryStatus::Active } } /// Represents an encrypted secret box for storing sensitive data #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct SecretBox { pub notary_id: u32, pub value: String, pub version: u16, pub timestamp: u64, pub cat: SecretBoxCategory, } impl SecretBox { pub fn new() -> Self { Self { notary_id: 0, value: String::new(), version: 1, timestamp: 0, cat: SecretBoxCategory::default(), } } pub fn notary_id(mut self, notary_id: u32) -> Self { self.notary_id = notary_id; self } pub fn value(mut self, value: impl ToString) -> Self { self.value = value.to_string(); self } pub fn version(mut self, version: u16) -> Self { self.version = version; self } pub fn timestamp(mut self, timestamp: u64) -> Self { self.timestamp = timestamp; self } pub fn cat(mut self, cat: SecretBoxCategory) -> Self { self.cat = cat; self } pub fn build(self) -> Self { self } } /// Represents a notary who can decrypt secret boxes #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, crate::DeriveObject)] pub struct Notary { /// Base model data pub base_data: BaseData, #[index] pub userid: u32, pub status: NotaryStatus, pub myceliumaddress: String, #[index] pub pubkey: String, } impl Notary { /// Create a new notary instance pub fn new(id: u32) -> Self { let mut base_data = BaseData::new(); Self { base_data, userid: 0, status: NotaryStatus::default(), myceliumaddress: String::new(), pubkey: String::new(), } } /// Set the user ID (fluent) pub fn userid(mut self, userid: u32) -> Self { self.userid = userid; self } /// Set the notary status (fluent) pub fn status(mut self, status: NotaryStatus) -> Self { self.status = status; self } /// Set the mycelium address (fluent) pub fn myceliumaddress(mut self, myceliumaddress: impl ToString) -> Self { self.myceliumaddress = myceliumaddress.to_string(); self } /// Set the public key (fluent) pub fn pubkey(mut self, pubkey: impl ToString) -> Self { self.pubkey = pubkey.to_string(); self } /// Build the final notary instance pub fn build(self) -> Self { self } }