ark_models_ext/models/bls12/
g1.rs

1use crate::models::{
2    bls12::Bls12Config,
3    short_weierstrass::{Affine, Projective},
4};
5use ark_ec::{AffineRepr, CurveGroup};
6use ark_serialize::*;
7use ark_std::vec::Vec;
8use derivative::Derivative;
9
10pub type G1Affine<P> = Affine<<P as Bls12Config>::G1Config>;
11pub type G1Projective<P> = Projective<<P as Bls12Config>::G1Config>;
12
13#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
14#[derivative(
15    Copy(bound = "P: Bls12Config"),
16    Clone(bound = "P: Bls12Config"),
17    PartialEq(bound = "P: Bls12Config"),
18    Eq(bound = "P: Bls12Config"),
19    Debug(bound = "P: Bls12Config")
20)]
21pub struct G1Prepared<P: Bls12Config>(pub G1Affine<P>);
22
23impl<P: Bls12Config> From<G1Affine<P>> for G1Prepared<P> {
24    fn from(other: G1Affine<P>) -> Self {
25        G1Prepared(other)
26    }
27}
28
29impl<P: Bls12Config> From<G1Projective<P>> for G1Prepared<P> {
30    fn from(q: G1Projective<P>) -> Self {
31        q.into_affine().into()
32    }
33}
34
35impl<'a, P: Bls12Config> From<&'a G1Affine<P>> for G1Prepared<P> {
36    fn from(other: &'a G1Affine<P>) -> Self {
37        G1Prepared(*other)
38    }
39}
40
41impl<'a, P: Bls12Config> From<&'a G1Projective<P>> for G1Prepared<P> {
42    fn from(q: &'a G1Projective<P>) -> Self {
43        q.into_affine().into()
44    }
45}
46
47impl<P: Bls12Config> G1Prepared<P> {
48    pub fn is_zero(&self) -> bool {
49        self.0.is_zero()
50    }
51}
52
53impl<P: Bls12Config> Default for G1Prepared<P> {
54    fn default() -> Self {
55        G1Prepared(G1Affine::<P>::generator())
56    }
57}