use thiserror::Error;
#[derive(Error, Clone, Debug, Eq, PartialEq)]
pub enum MuSigError {
#[error("Point decoding failed")]
InvalidPoint,
#[error("Share {pubkey:?} failed to verify correctly")]
ShareError {
pubkey: [u8; 32],
},
#[error("Point operation failed")]
PointOperationFailed,
#[error("Bad arguments")]
BadArguments,
#[error("There are too many parties in the MuSig signature")]
TooManyParticipants,
}
#[derive(Eq, PartialEq, Debug, Error, Clone)]
pub enum SchnorrError {
#[error("Cannot decompress Edwards point")]
PointDecompressionError,
#[error("Cannot use scalar with high-bit set")]
ScalarFormatError,
#[error("Issue When Serilizing Data")]
SerError,
#[error("Verification equation was not satisfied")]
VerifyError,
#[error("Function is called with bad arguments")]
BadArguments,
#[error("Absent {kind:?} violated multi-signature protocol")]
MuSig { kind: MuSigError },
#[error("Signature verification failed")]
InvalidSignature,
#[error("Batch signature verification failed")]
InvalidBatch,
#[error("VSS share error")]
VerifyShareError
}
pub fn from_musig(err: MuSigError) -> SchnorrError {
SchnorrError::MuSig { kind: err }
}
pub(crate) fn serde_error_from_signature_error<E>(err: SchnorrError) -> E
where E: ::serde::de::Error
{
match err {
SchnorrError::PointDecompressionError
=> E::custom("Ristretto point decompression failed"),
SchnorrError::ScalarFormatError
=> E::custom("improper scalar has high-bit set"),
SchnorrError::SerError
=> E::custom("improper serde usage"),
_ => panic!("Non-serialisation error encountered by serde!"),
}
}