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>;
25
26 async fn update_proof_state(
28 &mut self,
29 y: &PublicKey,
30 proofs_state: State,
31 ) -> Result<Option<State>, Error>;
32
33 async fn add_blind_signatures(
35 &mut self,
36 blinded_messages: &[PublicKey],
37 blind_signatures: &[BlindSignature],
38 ) -> Result<(), Error>;
39
40 async fn add_protected_endpoints(
42 &mut self,
43 protected_endpoints: HashMap<ProtectedEndpoint, AuthRequired>,
44 ) -> Result<(), Error>;
45
46 async fn remove_protected_endpoints(
48 &mut self,
49 protected_endpoints: Vec<ProtectedEndpoint>,
50 ) -> Result<(), Error>;
51}
52
53#[async_trait]
55pub trait MintAuthDatabase {
56 type Err: Into<Error> + From<Error>;
58
59 async fn begin_transaction<'a>(
61 &'a self,
62 ) -> Result<Box<dyn MintAuthTransaction<Self::Err> + Send + Sync + 'a>, Self::Err>;
63
64 async fn get_active_keyset_id(&self) -> Result<Option<Id>, Self::Err>;
66
67 async fn get_keyset_info(&self, id: &Id) -> Result<Option<MintKeySetInfo>, Self::Err>;
69 async fn get_keyset_infos(&self) -> Result<Vec<MintKeySetInfo>, Self::Err>;
71
72 async fn get_proofs_states(&self, ys: &[PublicKey]) -> Result<Vec<Option<State>>, Self::Err>;
74
75 async fn get_blind_signatures(
77 &self,
78 blinded_messages: &[PublicKey],
79 ) -> Result<Vec<Option<BlindSignature>>, Self::Err>;
80
81 async fn get_auth_for_endpoint(
83 &self,
84 protected_endpoint: ProtectedEndpoint,
85 ) -> Result<Option<AuthRequired>, Self::Err>;
86 async fn get_auth_for_endpoints(
88 &self,
89 ) -> Result<HashMap<ProtectedEndpoint, Option<AuthRequired>>, Self::Err>;
90}
91
92pub type DynMintAuthDatabase =
94 std::sync::Arc<dyn MintAuthDatabase<Err = super::Error> + Send + Sync>;