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, IssuedTicketBook};
5use nym_crypto::asymmetric::ed25519;
6use nym_ecash_time::OffsetDateTime;
7use nym_validator_client::nym_api::EpochId;
8
9pub use controller::BandwidthController;
10pub use nym_credentials_interface::TicketType;
11pub use ticketbooks::AvailableTicketbooks;
12pub use traits::{
13    BandwidthTicketProvider, CredentialFetcher, CredentialFetcherError,
14    CredentialPublicDataFetcher, FetcherError,
15};
16
17pub mod config;
18mod controller;
19pub mod error;
20mod in_flight;
21pub mod mock;
22mod readiness;
23pub mod requests;
24mod ticketbooks;
25mod traits;
26
27pub const DEFAULT_TICKETS_TO_SPEND: u32 = 1;
28
29pub const UPGRADE_MODE_JWT_TYPE: &str = "UPGRADE_MODE_JWT";
30
31#[derive(Clone, Debug)]
32pub struct PreparedCredential {
33    /// The cryptographic material required for spending the underlying credential.
34    pub data: CredentialSpendingData,
35
36    /// The (DKG) epoch id under which the credential has been issued so that the verifier
37    /// could use correct verification key for validation.
38    pub epoch_id: EpochId,
39
40    /// Auxiliary metadata associated with the withdrawn credential
41    pub metadata: PreparedCredentialMetadata,
42}
43
44#[derive(Copy, Clone, Debug)]
45pub struct PreparedCredentialMetadata {
46    /// The database id of the stored credential.
47    pub ticketbook_id: i64,
48
49    /// The number of tickets withdrawn in this credential
50    pub tickets_withdrawn: u32,
51
52    /// The amount of tickets used INCLUDING those tickets that JUST got withdrawn
53    pub used_tickets: u32,
54}
55
56#[derive(Copy, Clone, Debug)]
57pub struct EcashTicketRequest {
58    pub ticket_type: TicketType,
59    pub gateway_id: ed25519::PublicKey,
60    pub tickets_to_spend: u32,
61    pub spend_time: OffsetDateTime,
62}
63
64pub enum NymCredential {
65    Ticketbook(Box<IssuedTicketBook>),
66    UpgradeModeToken {
67        jwt: String,
68        expiration: OffsetDateTime,
69    },
70}