mod.rs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //! Mint in memory database use std::collections::HashMap;
  2. use std::collections::HashMap;
  3. use async_trait::async_trait;
  4. use cashu::{AuthRequired, ProtectedEndpoint};
  5. use crate::database::Error;
  6. use crate::mint::MintKeySetInfo;
  7. use crate::nuts::nut07::State;
  8. use crate::nuts::{AuthProof, BlindSignature, Id, PublicKey};
  9. /// Mint Database trait
  10. #[async_trait]
  11. pub trait MintAuthDatabase {
  12. /// Mint Database Error
  13. type Err: Into<Error> + From<Error>;
  14. /// Add Active Keyset
  15. async fn set_active_keyset(&self, id: Id) -> Result<(), Self::Err>;
  16. /// Get Active Keyset
  17. async fn get_active_keyset_id(&self) -> Result<Option<Id>, Self::Err>;
  18. /// Add [`MintKeySetInfo`]
  19. async fn add_keyset_info(&self, keyset: MintKeySetInfo) -> Result<(), Self::Err>;
  20. /// Get [`MintKeySetInfo`]
  21. async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
  22. /// Get [`MintKeySetInfo`]s
  23. async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
  24. /// Add spent [`AuthProof`]
  25. async fn add_proof(&self, proof: AuthProof) -> Result<(), Self::Err>;
  26. /// Get [`AuthProof`] state
  27. async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
  28. /// Update [`AuthProof`]s state
  29. async fn update_proof_state(
  30. &self,
  31. y: &PublicKey,
  32. proofs_state: State,
  33. ) -> Result<Option<State>, Self::Err>;
  34. /// Add [`BlindSignature`]
  35. async fn add_blind_signatures(
  36. &self,
  37. blinded_messages: &[PublicKey],
  38. blind_signatures: &[BlindSignature],
  39. ) -> Result<(), Self::Err>;
  40. /// Get [`BlindSignature`]s
  41. async fn get_blind_signatures(
  42. &self,
  43. blinded_messages: &[PublicKey],
  44. ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
  45. /// Add protected endpoints
  46. async fn add_protected_endpoints(
  47. &self,
  48. protected_endpoints: HashMap<ProtectedEndpoint, AuthRequired>,
  49. ) -> Result<(), Self::Err>;
  50. /// Removed Protected endpoints
  51. async fn remove_protected_endpoints(
  52. &self,
  53. protected_endpoints: Vec<ProtectedEndpoint>,
  54. ) -> Result<(), Self::Err>;
  55. /// Get auth for protected_endpoint
  56. async fn get_auth_for_endpoint(
  57. &self,
  58. protected_endpoint: ProtectedEndpoint,
  59. ) -> Result<Option<AuthRequired>, Self::Err>;
  60. /// Get protected endpoints
  61. async fn get_auth_for_endpoints(
  62. &self,
  63. ) -> Result<HashMap<ProtectedEndpoint, Option<AuthRequired>>, Self::Err>;
  64. }