1use blst::BLST_ERROR;
2use thiserror::Error;
3
4#[derive(Debug, Clone, PartialEq, Eq, Error)]
5pub enum Error {
6 #[error("SecretKey byte data must be less than the group order")]
7 SecretKeyGroupOrder,
8 #[error("Given G1 infinity element must be canonical")]
9 G1NotCanonical,
10 #[error("Given G1 non-infinity element must start with 0b10")]
11 G1InfinityInvalidBits,
12 #[error("G1 non-infinity element can't have only zeros")]
13 G1InfinityNotZero,
14 #[error("PublicKey is invalid (BLST ERROR: {0:?})")]
15 InvalidPublicKey(BLST_ERROR),
16 #[error("Signature is invalid (BLST ERROR: {0:?})")]
17 InvalidSignature(BLST_ERROR),
18}
19
20pub type Result<T> = std::result::Result<T, Error>;
21
22impl From<Error> for chik_traits::Error {
23 fn from(err: Error) -> chik_traits::Error {
24 chik_traits::Error::Custom(format!("{err}"))
25 }
26}
27
28#[cfg(feature = "py-bindings")]
29mod pybindings {
30 use super::*;
31
32 use pyo3::{exceptions::PyValueError, PyErr};
33
34 impl From<Error> for PyErr {
35 fn from(err: Error) -> PyErr {
36 PyValueError::new_err(format!("BLS Error {err:?}"))
37 }
38 }
39}