use thiserror::Error;
use crate::group::{Curve, PairingCurve};
#[cfg(feature = "bls12_381")]
pub mod bls12381;
#[cfg(feature = "bn254")]
pub mod bn254;
#[derive(Debug, Error)]
pub enum CurveError {
#[cfg(feature = "bls12_381")]
#[error("Bellman Error: {0}")]
BLS12_381(bls12381::BLS12Error),
#[cfg(feature = "bn254")]
#[error("Bellman Error: {0}")]
BN254(bn254::BNError),
}
#[derive(Debug, Error)]
pub enum BLSError {
#[error("signature verification failed")]
VerificationFailed,
#[error("io error {0}")]
IoError(#[from] std::io::Error),
#[error("error in hasher {0}")]
HashingError(#[from] Box<dyn std::error::Error>),
#[error("domain length is too large: {0}")]
DomainTooLarge(usize),
#[error("Could not hash to curve")]
HashToCurveError,
#[error("there must be the same number of keys and messages")]
UnevenNumKeysMessages,
#[error(transparent)]
SerializationError(#[from] ark_serialize::SerializationError),
#[error("serialization error when transform to/from contract form")]
ContractSerializationError,
#[error("not a valid group element")]
NotValidPoint,
}
pub trait CurveType {
type G1Curve: Curve;
type G2Curve: Curve;
type PairingCurve: PairingCurve;
}
#[cfg(test)]
mod tests {
use crate::curve::bn254::G2Curve;
use crate::group::Curve;
use crate::group::Element;
use ethers_core::utils::hex;
use rand::prelude::*;
fn keypair<C: Curve>() -> (C::Scalar, C::Point) {
let private = C::Scalar::rand(&mut thread_rng());
let mut public = C::Point::one();
public.mul(&private);
(private, public)
}
#[test]
fn keypairs() {
for _ in 0..12 {
let (private, public) = keypair::<G2Curve>();
println!("{:?}", hex::encode(bincode::serialize(&private).unwrap()));
println!("{:?}", hex::encode(bincode::serialize(&public).unwrap()));
}
}
}