Skip to main content

nym_bandwidth_controller/
lib.rs

1// Copyright 2021-2024 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use nym_credentials::ecash::bandwidth::CredentialSpendingData;
5use nym_credentials_interface::TicketType;
6use nym_crypto::asymmetric::ed25519;
7use nym_ecash_time::OffsetDateTime;
8use nym_validator_client::nym_api::EpochId;
9
10pub use controller::BandwidthController;
11pub use fetcher::NyxdGlobalDataFetcher;
12pub use traits::{BandwidthTicketProvider, FetcherError};
13
14pub mod acquire;
15mod controller;
16pub mod error;
17mod fetcher;
18pub mod mock;
19pub mod requests;
20mod traits;
21mod utils;
22
23pub const DEFAULT_TICKETS_TO_SPEND: u32 = 1;
24
25pub const UPGRADE_MODE_JWT_TYPE: &str = "UPGRADE_MODE_JWT";
26
27#[derive(Clone, Debug)]
28pub struct PreparedCredential {
29    /// The cryptographic material required for spending the underlying credential.
30    pub data: CredentialSpendingData,
31
32    /// The (DKG) epoch id under which the credential has been issued so that the verifier
33    /// could use correct verification key for validation.
34    pub epoch_id: EpochId,
35
36    /// Auxiliary metadata associated with the withdrawn credential
37    pub metadata: PreparedCredentialMetadata,
38}
39
40#[derive(Copy, Clone, Debug)]
41pub struct PreparedCredentialMetadata {
42    /// The database id of the stored credential.
43    pub ticketbook_id: i64,
44
45    /// The number of tickets withdrawn in this credential
46    pub tickets_withdrawn: u32,
47
48    /// The amount of tickets used INCLUDING those tickets that JUST got withdrawn
49    pub used_tickets: u32,
50}
51
52#[derive(Copy, Clone, Debug)]
53pub struct EcashTicketRequest {
54    pub ticket_type: TicketType,
55    pub gateway_id: ed25519::PublicKey,
56    pub tickets_to_spend: u32,
57    pub spend_time: OffsetDateTime,
58}