nym_credential_proxy_lib/storage/
traits.rs

1// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: GPL-3.0-only
3
4use crate::error::CredentialProxyError;
5use crate::storage::CredentialProxyStorage;
6use nym_validator_client::nym_api::EpochId;
7use time::Date;
8
9pub use nym_credentials::ecash::bandwidth::serialiser::VersionedSerialise;
10pub use nym_credentials::{
11    AggregatedCoinIndicesSignatures, AggregatedExpirationDateSignatures, EpochVerificationKey,
12};
13
14// we use it in our code so it's fine
15#[allow(async_fn_in_trait)]
16pub trait GlobalEcashDataCache {
17    async fn get_master_verification_key(
18        &self,
19        epoch_id: EpochId,
20    ) -> Result<Option<EpochVerificationKey>, CredentialProxyError>;
21
22    async fn insert_master_verification_key(
23        &self,
24        key: &EpochVerificationKey,
25    ) -> Result<(), CredentialProxyError>;
26
27    async fn get_master_coin_index_signatures(
28        &self,
29        epoch_id: EpochId,
30    ) -> Result<Option<AggregatedCoinIndicesSignatures>, CredentialProxyError>;
31
32    async fn insert_master_coin_index_signatures(
33        &self,
34        signatures: &AggregatedCoinIndicesSignatures,
35    ) -> Result<(), CredentialProxyError>;
36
37    async fn get_master_expiration_date_signatures(
38        &self,
39        expiration_date: Date,
40        epoch_id: EpochId,
41    ) -> Result<Option<AggregatedExpirationDateSignatures>, CredentialProxyError>;
42
43    async fn insert_master_expiration_date_signatures(
44        &self,
45        signatures: &AggregatedExpirationDateSignatures,
46    ) -> Result<(), CredentialProxyError>;
47}
48
49impl GlobalEcashDataCache for CredentialProxyStorage {
50    async fn get_master_verification_key(
51        &self,
52        epoch_id: EpochId,
53    ) -> Result<Option<EpochVerificationKey>, CredentialProxyError> {
54        self.get_master_verification_key(epoch_id).await
55    }
56
57    async fn insert_master_verification_key(
58        &self,
59        key: &EpochVerificationKey,
60    ) -> Result<(), CredentialProxyError> {
61        self.insert_master_verification_key(key).await
62    }
63
64    async fn get_master_coin_index_signatures(
65        &self,
66        epoch_id: EpochId,
67    ) -> Result<Option<AggregatedCoinIndicesSignatures>, CredentialProxyError> {
68        self.get_master_coin_index_signatures(epoch_id).await
69    }
70
71    async fn insert_master_coin_index_signatures(
72        &self,
73        signatures: &AggregatedCoinIndicesSignatures,
74    ) -> Result<(), CredentialProxyError> {
75        self.insert_master_coin_index_signatures(signatures).await
76    }
77
78    async fn get_master_expiration_date_signatures(
79        &self,
80        expiration_date: Date,
81        epoch_id: EpochId,
82    ) -> Result<Option<AggregatedExpirationDateSignatures>, CredentialProxyError> {
83        self.get_master_expiration_date_signatures(expiration_date, epoch_id)
84            .await
85    }
86
87    async fn insert_master_expiration_date_signatures(
88        &self,
89        signatures: &AggregatedExpirationDateSignatures,
90    ) -> Result<(), CredentialProxyError> {
91        self.insert_master_expiration_date_signatures(signatures)
92            .await
93    }
94}