ark_models_ext/models/bls12/
g2.rs1use 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 G2Affine<P> = Affine<<P as Bls12Config>::G2Config>;
11pub type G2Projective<P> = Projective<<P as Bls12Config>::G2Config>;
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 G2Prepared<P: Bls12Config>(pub G2Affine<P>);
22
23impl<P: Bls12Config> From<G2Affine<P>> for G2Prepared<P> {
24 fn from(other: G2Affine<P>) -> Self {
25 G2Prepared(other)
26 }
27}
28
29impl<P: Bls12Config> From<G2Projective<P>> for G2Prepared<P> {
30 fn from(q: G2Projective<P>) -> Self {
31 q.into_affine().into()
32 }
33}
34
35impl<'a, P: Bls12Config> From<&'a G2Affine<P>> for G2Prepared<P> {
36 fn from(other: &'a G2Affine<P>) -> Self {
37 G2Prepared(*other)
38 }
39}
40
41impl<'a, P: Bls12Config> From<&'a G2Projective<P>> for G2Prepared<P> {
42 fn from(q: &'a G2Projective<P>) -> Self {
43 q.into_affine().into()
44 }
45}
46
47impl<P: Bls12Config> G2Prepared<P> {
48 pub fn is_zero(&self) -> bool {
49 self.0.is_zero()
50 }
51}
52
53impl<P: Bls12Config> Default for G2Prepared<P> {
54 fn default() -> Self {
55 G2Prepared(G2Affine::<P>::generator())
56 }
57}