use std::collections::HashMap; use crate::user_discovery::error::Result; use crate::user_discovery::UserID; use std::future::Future; #[derive(Clone, sqlx::FromRow)] pub struct OtherPromotion { pub promotion_id: u32, pub public_id: i64, pub from_contact_id: UserID, pub threshold: u8, pub announcement_share: Vec, pub public_key_verified_timestamp: Option, } #[derive(Clone, Hash, PartialEq, Eq)] pub struct AnnouncedUser { pub user_id: UserID, pub public_key: Vec, pub public_id: i64, } pub trait UserDiscoveryStore { fn new() -> impl std::future::Future + Send; fn get_config(&self) -> impl Future> + Send; fn update_config(&self, update: String) -> impl Future> + Send; fn set_shares(&self, shares: Vec>) -> impl Future> + Send; fn get_share_for_contact( &self, contact_id: UserID, ) -> impl Future>> + Send; fn push_own_promotion( &self, contact_id: UserID, version: u32, promotion: Vec, ) -> impl Future> + Send; fn get_own_promotions_after_version( &self, version: u32, ) -> impl Future>>> + Send; fn store_other_promotion( &self, promotion: OtherPromotion, ) -> impl Future> + Send; fn get_other_promotions_by_public_id( &self, public_id: i64, ) -> impl Future>> + Send; fn get_announced_user_by_public_id( &self, public_id: i64, ) -> impl Future>> + Send; fn push_new_user_relation( &self, from_contact_id: UserID, announced_user: AnnouncedUser, public_key_verified_timestamp: Option, ) -> impl Future> + Send; fn get_all_announced_users( &self, ) -> impl Future)>>>> + Send; fn get_contact_version( &self, contact_id: UserID, ) -> impl Future>>> + Send; fn set_contact_version( &self, contact_id: UserID, update: Vec, ) -> impl Future> + Send; } pub trait UserDiscoveryUtils { fn sign_data(&self, input_data: &[u8]) -> impl Future>> + Send; fn verify_signature( &self, input_data: &[u8], pubkey: &[u8], signature: &[u8], ) -> impl Future> + Send; fn verify_stored_pubkey( &self, from_contact_id: UserID, pubkey: &[u8], ) -> impl Future> + Send; } pub(crate) mod tests { use crate::user_discovery::traits::UserDiscoveryUtils; #[derive(Default)] pub(crate) struct TestingUtils {} impl UserDiscoveryUtils for TestingUtils { async fn sign_data( &self, _input_data: &[u8], ) -> crate::user_discovery::error::Result> { Ok(vec![0; 64]) } async fn verify_signature( &self, _data: &[u8], _pubkey: &[u8], _signature: &[u8], ) -> crate::user_discovery::error::Result { Ok(true) } async fn verify_stored_pubkey( &self, _from_contact_id: crate::user_discovery::UserID, _pubkey: &[u8], ) -> crate::user_discovery::error::Result { Ok(true) } } }