mod.rs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 super::DbTransactionFinalizer;
  6. use crate::database::Error;
  7. use crate::mint::MintKeySetInfo;
  8. use crate::nuts::nut07::State;
  9. use crate::nuts::{AuthProof, BlindSignature, Id, PublicKey};
  10. /// Mint Database transaction
  11. #[async_trait]
  12. pub trait MintAuthTransaction<Error>: DbTransactionFinalizer<Err = Error> {
  13. /// Add Active Keyset
  14. async fn set_active_keyset(&mut self, id: Id) -> Result<(), Error>;
  15. /// Add [`MintKeySetInfo`]
  16. async fn add_keyset_info(&mut self, keyset: MintKeySetInfo) -> Result<(), Error>;
  17. /// Add spent [`AuthProof`]
  18. async fn add_proof(&mut self, proof: AuthProof) -> Result<(), Error>;
  19. /// Update [`AuthProof`]s state
  20. async fn update_proof_state(
  21. &mut self,
  22. y: &PublicKey,
  23. proofs_state: State,
  24. ) -> Result<Option<State>, Error>;
  25. /// Add [`BlindSignature`]
  26. async fn add_blind_signatures(
  27. &mut self,
  28. blinded_messages: &[PublicKey],
  29. blind_signatures: &[BlindSignature],
  30. ) -> Result<(), Error>;
  31. /// Add protected endpoints
  32. async fn add_protected_endpoints(
  33. &mut self,
  34. protected_endpoints: HashMap<ProtectedEndpoint, AuthRequired>,
  35. ) -> Result<(), Error>;
  36. /// Removed Protected endpoints
  37. async fn remove_protected_endpoints(
  38. &mut self,
  39. protected_endpoints: Vec<ProtectedEndpoint>,
  40. ) -> Result<(), Error>;
  41. }
  42. /// Mint Database trait
  43. #[async_trait]
  44. pub trait MintAuthDatabase {
  45. /// Mint Database Error
  46. type Err: Into<Error> + From<Error>;
  47. /// Begins a transaction
  48. async fn begin_transaction<'a>(
  49. &'a self,
  50. ) -> Result<Box<dyn MintAuthTransaction<Self::Err> + Send + Sync + 'a>, Self::Err>;
  51. /// Get Active Keyset
  52. async fn get_active_keyset_id(&self) -> Result<Option<Id>, Self::Err>;
  53. /// Get [`MintKeySetInfo`]
  54. async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
  55. /// Get [`MintKeySetInfo`]s
  56. async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
  57. /// Get [`AuthProof`] state
  58. async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
  59. /// Get [`BlindSignature`]s
  60. async fn get_blind_signatures(
  61. &self,
  62. blinded_messages: &[PublicKey],
  63. ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
  64. /// Get auth for protected_endpoint
  65. async fn get_auth_for_endpoint(
  66. &self,
  67. protected_endpoint: ProtectedEndpoint,
  68. ) -> Result<Option<AuthRequired>, Self::Err>;
  69. /// Get protected endpoints
  70. async fn get_auth_for_endpoints(
  71. &self,
  72. ) -> Result<HashMap<ProtectedEndpoint, Option<AuthRequired>>, Self::Err>;
  73. }