nym_credentials/
error.rs

1// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::ecash::bandwidth::issued::CURRENT_SERIALIZATION_REVISION;
5use nym_credentials_interface::CompactEcashError;
6use nym_crypto::asymmetric::x25519::KeyRecoveryError;
7use nym_validator_client::{nym_api::error::NymAPIError, ValidatorClientError};
8use thiserror::Error;
9
10#[derive(Debug, Error)]
11pub enum Error {
12    #[error("IO error")]
13    IOError(#[from] std::io::Error),
14
15    #[error("failed to deserialize a recovery credential: {source}")]
16    RecoveryCredentialDeserializationFailure { source: bincode::Error },
17
18    #[error("failed to (de)serialize provided credential using revision {revision}: {source}")]
19    SerializationFailure {
20        #[source]
21        source: bincode::Error,
22        revision: u8,
23    },
24
25    #[error("unsupported data serialization revision {revision}. the current (and max supported) version is {CURRENT_SERIALIZATION_REVISION}")]
26    UnsupportedSerializationRevision { revision: u8 },
27
28    #[error("unknown data serialization revision {revision}. the current (and max supported) version is {CURRENT_SERIALIZATION_REVISION}")]
29    UnknownSerializationRevision { revision: u8 },
30
31    #[error("Could not contact any validator")]
32    NoValidatorsAvailable,
33
34    #[error("Ran into a Compact ecash error - {0}")]
35    CompactEcashError(#[from] CompactEcashError),
36
37    #[error("Ran into a validator client error - {0}")]
38    ValidatorClientError(#[from] ValidatorClientError),
39
40    #[error("Nym API request failed - {0}")]
41    NymAPIError(Box<NymAPIError>),
42
43    #[error("Bandwidth operation overflowed. {0}")]
44    BandwidthOverflow(String),
45
46    #[error("There is not associated bandwidth for the given client")]
47    MissingBandwidth,
48
49    #[error("Could not parse the key - {0}")]
50    ParsePublicKey(#[from] KeyRecoveryError),
51
52    #[error("Could not gather enough signature shares. Try again using the recovery command")]
53    NotEnoughShares,
54
55    #[error("Could not aggregate signature shares - {0}. Try again using the recovery command")]
56    SignatureAggregationError(CompactEcashError),
57
58    #[error("Could not deserialize bandwidth voucher - {0}")]
59    BandwidthVoucherDeserializationError(String),
60
61    #[error("the provided issuance data wasn't prepared for a bandwidth voucher")]
62    NotABandwdithVoucher,
63
64    #[error("failed to create a secp256k1 signature")]
65    Secp256k1SignFailure,
66}
67
68impl From<NymAPIError> for Error {
69    fn from(e: NymAPIError) -> Self {
70        Error::NymAPIError(Box::new(e))
71    }
72}