Skip to content

Commit 410c80a

Browse files
committed
napi: wrapper for group types
1 parent c1cc82f commit 410c80a

File tree

3 files changed

+126
-2
lines changed

3 files changed

+126
-2
lines changed

plonk-napi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ pub use poseidon::{
77
};
88

99
pub use wrappers::field::{WasmPastaFp, WasmPastaFq};
10-
10+
pub use wrappers::group::{WasmGPallas, WasmGVesta};

plonk-napi/src/wrappers/group.rs

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

plonk-napi/src/wrappers/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pub(crate) mod field;
1+
pub(crate) mod field;
2+
pub(crate) mod group;

0 commit comments

Comments
 (0)