cdk_common/database/mint/auth/
mod.rs1use std::collections::HashMap;
4
5use async_trait::async_trait;
6use cashu::{AuthRequired, ProtectedEndpoint};
7
8use super::DbTransactionFinalizer;
9use crate::database::Error;
10use crate::mint::MintKeySetInfo;
11use crate::nuts::nut07::State;
12use crate::nuts::{AuthProof, BlindSignature, Id, PublicKey};
13
14#[async_trait]
16pub trait MintAuthTransaction<Error>: DbTransactionFinalizer<Err = Error> {
17 async fn set_active_keyset(&mut self, id: Id) -> Result<(), Error>;
19
20 async fn add_keyset_info(&mut self, keyset: MintKeySetInfo) -> Result<(), Error>;
22
23 async fn add_proof(&mut self, proof: AuthProof) -> Result<(), Error>;
28
29 async fn update_proof_state(
31 &mut self,
32 y: &PublicKey,
33 proofs_state: State,
34 ) -> Result<Option<State>, Error>;
35
36 async fn add_blind_signatures(
38 &mut self,
39 blinded_messages: &[PublicKey],
40 blind_signatures: &[BlindSignature],
41 ) -> Result<(), Error>;
42
43 async fn add_protected_endpoints(
45 &mut self,
46 protected_endpoints: HashMap<ProtectedEndpoint, AuthRequired>,
47 ) -> Result<(), Error>;
48
49 async fn remove_protected_endpoints(
51 &mut self,
52 protected_endpoints: Vec<ProtectedEndpoint>,
53 ) -> Result<(), Error>;
54}
55
56#[async_trait]
58pub trait MintAuthDatabase {
59 type Err: Into<Error> + From<Error>;
61
62 async fn begin_transaction<'a>(
64 &'a self,
65 ) -> Result<Box<dyn MintAuthTransaction<Self::Err> + Send + Sync + 'a>, Self::Err>;
66
67 async fn get_active_keyset_id(&self) -> Result<Option<Id>, Self::Err>;
69
70 async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
72 async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
74
75 async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
77
78 async fn get_blind_signatures(
80 &self,
81 blinded_messages: &[PublicKey],
82 ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
83
84 async fn get_auth_for_endpoint(
86 &self,
87 protected_endpoint: ProtectedEndpoint,
88 ) -> Result<Option<AuthRequired>, Self::Err>;
89 async fn get_auth_for_endpoints(
91 &self,
92 ) -> Result<HashMap<ProtectedEndpoint, Option<AuthRequired>>, Self::Err>;
93}
94
95pub type DynMintAuthDatabase =
97 std::sync::Arc<dyn MintAuthDatabase<Err = super::Error> + Send + Sync>;