ark_models_ext/models/bw6/
g2.rs

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