kimchi_stubs/arkworks/
group_affine.rs1use crate::arkworks::{CamlFp, CamlFq};
2use ark_ec::AffineRepr;
3use mina_curves::pasta::{Pallas as AffinePallas, Vesta as AffineVesta};
4
5pub type CamlGVesta = CamlGroupAffine<CamlFq>;
10pub type CamlGPallas = CamlGroupAffine<CamlFp>;
11
12#[derive(Clone, Copy, Debug, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Enum)]
17pub enum CamlGroupAffine<F> {
18 Infinity,
19 Finite((F, F)),
20}
21
22impl From<AffineVesta> for CamlGVesta {
25 fn from(point: AffineVesta) -> Self {
26 if point.infinity {
27 Self::Infinity
28 } else {
29 Self::Finite((point.x.into(), point.y.into()))
30 }
31 }
32}
33
34impl From<&AffineVesta> for CamlGVesta {
35 fn from(point: &AffineVesta) -> Self {
36 if point.infinity {
37 Self::Infinity
38 } else {
39 Self::Finite((point.x.into(), point.y.into()))
40 }
41 }
42}
43
44impl From<CamlGVesta> for AffineVesta {
45 fn from(camlg: CamlGVesta) -> Self {
46 match camlg {
47 CamlGVesta::Infinity => AffineVesta::zero(),
48 CamlGVesta::Finite((x, y)) => AffineVesta::new_unchecked(x.into(), y.into()),
49 }
50 }
51}
52
53impl From<&CamlGVesta> for AffineVesta {
54 fn from(camlg: &CamlGVesta) -> Self {
55 match camlg {
56 CamlGroupAffine::Infinity => AffineVesta::zero(),
57 CamlGroupAffine::Finite((x, y)) => AffineVesta::new_unchecked(x.into(), y.into()),
58 }
59 }
60}
61
62impl From<AffinePallas> for CamlGPallas {
65 fn from(point: AffinePallas) -> Self {
66 if point.infinity {
67 Self::Infinity
68 } else {
69 Self::Finite((point.x.into(), point.y.into()))
70 }
71 }
72}
73
74impl From<&AffinePallas> for CamlGPallas {
75 fn from(point: &AffinePallas) -> Self {
76 if point.infinity {
77 Self::Infinity
78 } else {
79 Self::Finite((point.x.into(), point.y.into()))
80 }
81 }
82}
83
84impl From<CamlGPallas> for AffinePallas {
85 fn from(camlg: CamlGPallas) -> Self {
86 match camlg {
87 CamlGPallas::Infinity => AffinePallas::zero(),
88 CamlGPallas::Finite((x, y)) => AffinePallas::new_unchecked(x.into(), y.into()),
89 }
90 }
91}
92
93impl From<&CamlGPallas> for AffinePallas {
94 fn from(camlg: &CamlGPallas) -> Self {
95 match camlg {
96 CamlGroupAffine::Infinity => AffinePallas::zero(),
97 CamlGroupAffine::Finite((x, y)) => AffinePallas::new_unchecked(x.into(), y.into()),
98 }
99 }
100}