Skip to main content

arcanum_threshold/
error.rs

1//! Error types for threshold cryptography operations.
2
3use thiserror::Error;
4
5/// Errors that can occur in threshold operations.
6#[derive(Debug, Error)]
7pub enum ThresholdError {
8    /// Threshold must be at least 1.
9    #[error("threshold must be at least 1, got {threshold}")]
10    ThresholdTooLow {
11        /// The invalid threshold value.
12        threshold: usize,
13    },
14
15    /// Threshold cannot exceed total number of shares.
16    #[error("threshold ({threshold}) cannot exceed total shares ({total})")]
17    ThresholdExceedsTotal {
18        /// The threshold value.
19        threshold: usize,
20        /// The total number of shares.
21        total: usize,
22    },
23
24    /// Invalid threshold parameters (legacy variant).
25    #[error("invalid threshold: need {threshold} of {total} shares, but {threshold} > {total}")]
26    InvalidThreshold {
27        /// The threshold value.
28        threshold: usize,
29        /// The total number of shares.
30        total: usize,
31    },
32
33    /// Not enough shares for reconstruction.
34    #[error("insufficient shares: need {required}, got {provided}")]
35    InsufficientShares {
36        /// Number of shares required.
37        required: usize,
38        /// Number of shares provided.
39        provided: usize,
40    },
41
42    /// Share index is out of range.
43    #[error("invalid share index: {index} (valid range: 1-{max})")]
44    InvalidShareIndex {
45        /// The invalid index.
46        index: usize,
47        /// Maximum valid index.
48        max: usize,
49    },
50
51    /// Duplicate share indices detected.
52    #[error("duplicate share index: {index}")]
53    DuplicateShareIndex {
54        /// The duplicated index.
55        index: usize,
56    },
57
58    /// Share verification failed.
59    #[error("share verification failed for participant {participant}")]
60    ShareVerificationFailed {
61        /// The participant whose share failed verification.
62        participant: u16,
63    },
64
65    /// Invalid share format.
66    #[error("invalid share format")]
67    InvalidShareFormat,
68
69    /// Invalid share data with reason.
70    #[error("invalid share data: {reason}")]
71    InvalidShare {
72        /// The reason for invalidity.
73        reason: String,
74    },
75
76    /// Invalid commitment.
77    #[error("invalid commitment")]
78    InvalidCommitment,
79
80    /// DKG protocol error.
81    #[error("DKG protocol error: {0}")]
82    DkgError(String),
83
84    /// Signing protocol error.
85    #[error("signing protocol error: {0}")]
86    SigningError(String),
87
88    /// Invalid participant identifier.
89    #[error("invalid participant identifier: {0}")]
90    InvalidParticipant(u16),
91
92    /// Missing participant in round.
93    #[error("missing participant {0} in round")]
94    MissingParticipant(u16),
95
96    /// Invalid signature.
97    #[error("invalid signature")]
98    InvalidSignature,
99
100    /// Serialization error.
101    #[error("serialization error: {0}")]
102    SerializationError(String),
103
104    /// Internal error.
105    #[error("internal error: {0}")]
106    InternalError(String),
107}
108
109/// Result type for threshold operations.
110pub type Result<T> = std::result::Result<T, ThresholdError>;