kimchi_napi/wrappers/
group.rs1use crate::wrappers::field::{NapiPastaFp, NapiPastaFq};
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 napi_derive::napi;
10use serde::{Deserialize, Serialize};
11
12#[napi(object, js_name = "WasmGPallas")]
13#[derive(Clone, Debug, Default, Serialize, Deserialize)]
14pub struct NapiGPallas {
15 pub x: NapiPastaFp,
16 pub y: NapiPastaFp,
17 pub infinity: bool,
18}
19
20#[napi(object, js_name = "WasmGVesta")]
21#[derive(Clone, Debug, Default, Serialize, Deserialize)]
22pub struct NapiGVesta {
23 pub x: NapiPastaFq,
24 pub y: NapiPastaFq,
25 pub infinity: bool,
26}
27
28impl From<AffinePallas> for NapiGPallas {
29 fn from(point: AffinePallas) -> Self {
30 Self {
31 x: point.x.into(),
32 y: point.y.into(),
33 infinity: point.infinity,
34 }
35 }
36}
37
38impl From<&AffinePallas> for NapiGPallas {
39 fn from(point: &AffinePallas) -> Self {
40 Self {
41 x: point.x.into(),
42 y: point.y.into(),
43 infinity: point.infinity,
44 }
45 }
46}
47
48impl From<NapiGPallas> for AffinePallas {
49 fn from(point: NapiGPallas) -> Self {
50 AffinePallas {
51 x: point.x.into(),
52 y: point.y.into(),
53 infinity: point.infinity,
54 }
55 }
56}
57
58impl From<&NapiGPallas> for AffinePallas {
59 fn from(point: &NapiGPallas) -> Self {
60 AffinePallas {
61 x: point.x.into(),
62 y: point.y.into(),
63 infinity: point.infinity,
64 }
65 }
66}
67
68impl From<AffineVesta> for NapiGVesta {
69 fn from(point: AffineVesta) -> Self {
70 Self {
71 x: point.x.into(),
72 y: point.y.into(),
73 infinity: point.infinity,
74 }
75 }
76}
77
78impl From<&AffineVesta> for NapiGVesta {
79 fn from(point: &AffineVesta) -> Self {
80 Self {
81 x: point.x.into(),
82 y: point.y.into(),
83 infinity: point.infinity,
84 }
85 }
86}
87
88impl From<NapiGVesta> for AffineVesta {
89 fn from(point: NapiGVesta) -> Self {
90 AffineVesta {
91 x: point.x.into(),
92 y: point.y.into(),
93 infinity: point.infinity,
94 }
95 }
96}
97
98impl From<&NapiGVesta> for AffineVesta {
99 fn from(point: &NapiGVesta) -> Self {
100 AffineVesta {
101 x: point.x.into(),
102 y: point.y.into(),
103 infinity: point.infinity,
104 }
105 }
106}
107
108#[allow(dead_code)]
109#[napi(js_name = "caml_pallas_affine_one")]
110pub fn caml_pallas_affine_one() -> NapiGPallas {
111 NapiGPallas {
112 x: NapiPastaFp::from(GeneratorPallasX),
113 y: NapiPastaFp::from(GeneratorPallasY),
114 infinity: false,
115 }
116}
117
118#[allow(dead_code)]
119#[napi(js_name = "caml_vesta_affine_one")]
120pub fn caml_vesta_affine_one() -> NapiGVesta {
121 NapiGVesta {
122 x: NapiPastaFq::from(GeneratorVestaX),
123 y: NapiPastaFq::from(GeneratorVestaY),
124 infinity: false,
125 }
126}