use crate::{
cyclic_group::IsGroup,
errors::PairingError,
field::{element::FieldElement, traits::IsField},
};
use core::fmt::Debug;
#[derive(Debug, PartialEq, Eq)]
pub enum EllipticCurveError {
InvalidPoint,
}
pub trait IsEllipticCurve {
type BaseField: IsField + Clone + Debug;
type PointRepresentation: IsGroup + FromAffine<Self::BaseField>;
fn generator() -> Self::PointRepresentation;
fn create_point_from_affine(
x: FieldElement<Self::BaseField>,
y: FieldElement<Self::BaseField>,
) -> Result<Self::PointRepresentation, EllipticCurveError> {
Self::PointRepresentation::from_affine(x, y)
}
}
pub trait FromAffine<F: IsField>: Sized {
fn from_affine(x: FieldElement<F>, y: FieldElement<F>) -> Result<Self, EllipticCurveError>;
}
pub trait IsPairing {
type G1Point: IsGroup;
type G2Point: IsGroup;
type OutputField: IsField;
fn compute_batch(
pairs: &[(&Self::G1Point, &Self::G2Point)],
) -> Result<FieldElement<Self::OutputField>, PairingError>;
fn compute(
p: &Self::G1Point,
q: &Self::G2Point,
) -> Result<FieldElement<Self::OutputField>, PairingError> {
Self::compute_batch(&[(p, q)])
}
}