plonk_wasm/arkworks/
group_affine.rs

1use crate::arkworks::{pasta_fp::WasmPastaFp, pasta_fq::WasmPastaFq};
2use mina_curves::pasta::{
3    curves::{
4        pallas::{G_GENERATOR_X as GeneratorPallasX, G_GENERATOR_Y as GeneratorPallasY},
5        vesta::{G_GENERATOR_X as GeneratorVestaX, G_GENERATOR_Y as GeneratorVestaY},
6    },
7    Pallas as AffinePallas, Vesta as AffineVesta,
8};
9use wasm_bindgen::prelude::*;
10
11//
12// handy types
13//
14
15#[wasm_bindgen]
16#[derive(Clone, Copy, Debug)]
17pub struct WasmGPallas {
18    pub x: WasmPastaFp,
19    pub y: WasmPastaFp,
20    pub infinity: bool,
21}
22
23#[wasm_bindgen]
24#[derive(Clone, Copy, Debug)]
25pub struct WasmGVesta {
26    pub x: WasmPastaFq,
27    pub y: WasmPastaFq,
28    pub infinity: bool,
29}
30
31// Conversions from/to AffineVesta
32
33impl From<AffineVesta> for WasmGVesta {
34    fn from(point: AffineVesta) -> Self {
35        WasmGVesta {
36            x: point.x.into(),
37            y: point.y.into(),
38            infinity: point.infinity,
39        }
40    }
41}
42
43impl From<&AffineVesta> for WasmGVesta {
44    fn from(point: &AffineVesta) -> Self {
45        WasmGVesta {
46            x: point.x.into(),
47            y: point.y.into(),
48            infinity: point.infinity,
49        }
50    }
51}
52
53impl From<WasmGVesta> for AffineVesta {
54    fn from(point: WasmGVesta) -> Self {
55        AffineVesta {
56            x: point.x.into(),
57            y: point.y.into(),
58            infinity: point.infinity,
59        }
60    }
61}
62
63impl From<&WasmGVesta> for AffineVesta {
64    fn from(point: &WasmGVesta) -> Self {
65        AffineVesta {
66            x: point.x.into(),
67            y: point.y.into(),
68            infinity: point.infinity,
69        }
70    }
71}
72
73// Conversion from/to AffinePallas
74
75impl From<AffinePallas> for WasmGPallas {
76    fn from(point: AffinePallas) -> Self {
77        WasmGPallas {
78            x: point.x.into(),
79            y: point.y.into(),
80            infinity: point.infinity,
81        }
82    }
83}
84
85impl From<&AffinePallas> for WasmGPallas {
86    fn from(point: &AffinePallas) -> Self {
87        WasmGPallas {
88            x: point.x.into(),
89            y: point.y.into(),
90            infinity: point.infinity,
91        }
92    }
93}
94
95impl From<WasmGPallas> for AffinePallas {
96    fn from(point: WasmGPallas) -> Self {
97        AffinePallas {
98            x: point.x.into(),
99            y: point.y.into(),
100            infinity: point.infinity,
101        }
102    }
103}
104
105impl From<&WasmGPallas> for AffinePallas {
106    fn from(point: &WasmGPallas) -> Self {
107        AffinePallas {
108            x: point.x.into(),
109            y: point.y.into(),
110            infinity: point.infinity,
111        }
112    }
113}
114
115#[wasm_bindgen]
116pub fn caml_pallas_affine_one() -> WasmGPallas {
117    WasmGPallas {
118        x: WasmPastaFp::from(GeneratorPallasX),
119        y: WasmPastaFp::from(GeneratorPallasY),
120        infinity: false,
121    }
122}
123
124#[wasm_bindgen]
125pub fn caml_vesta_affine_one() -> WasmGVesta {
126    WasmGVesta {
127        x: WasmPastaFq::from(GeneratorVestaX),
128        y: WasmPastaFq::from(GeneratorVestaY),
129        infinity: false,
130    }
131}