use thiserror::Error;
#[derive(Debug, Error)]
pub enum ThresholdError {
#[error("threshold must be at least 1, got {threshold}")]
ThresholdTooLow {
threshold: usize,
},
#[error("threshold ({threshold}) cannot exceed total shares ({total})")]
ThresholdExceedsTotal {
threshold: usize,
total: usize,
},
#[error("invalid threshold: need {threshold} of {total} shares, but {threshold} > {total}")]
InvalidThreshold {
threshold: usize,
total: usize,
},
#[error("insufficient shares: need {required}, got {provided}")]
InsufficientShares {
required: usize,
provided: usize,
},
#[error("invalid share index: {index} (valid range: 1-{max})")]
InvalidShareIndex {
index: usize,
max: usize,
},
#[error("duplicate share index: {index}")]
DuplicateShareIndex {
index: usize,
},
#[error("share verification failed for participant {participant}")]
ShareVerificationFailed {
participant: u16,
},
#[error("invalid share format")]
InvalidShareFormat,
#[error("invalid share data: {reason}")]
InvalidShare {
reason: String,
},
#[error("invalid commitment")]
InvalidCommitment,
#[error("DKG protocol error: {0}")]
DkgError(String),
#[error("signing protocol error: {0}")]
SigningError(String),
#[error("invalid participant identifier: {0}")]
InvalidParticipant(u16),
#[error("missing participant {0} in round")]
MissingParticipant(u16),
#[error("invalid signature")]
InvalidSignature,
#[error("serialization error: {0}")]
SerializationError(String),
#[error("internal error: {0}")]
InternalError(String),
}
pub type Result<T> = std::result::Result<T, ThresholdError>;