Skip to content

Commit 02e6c40

Browse files
committed
napi: use macro params closer to plonk-wasms names
1 parent c406d9d commit 02e6c40

File tree

1 file changed

+45
-38
lines changed

1 file changed

+45
-38
lines changed

plonk-napi/src/srs.rs

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,40 @@ use wasm_types::FlatVector as WasmFlatVector;
1414
use crate::{
1515
poly_comm::{pallas::WasmFqPolyComm, vesta::WasmFpPolyComm},
1616
wasm_vector::WasmVector,
17-
wrappers::field::{WasmPastaFp, WasmPastaFq},
18-
wrappers::group::{WasmGPallas, WasmGVesta},
17+
wrappers::{
18+
field::{WasmPastaFp, WasmPastaFq},
19+
group::{WasmGPallas, WasmGVesta},
20+
},
1921
};
2022

21-
macro_rules! impl_srs_module {
23+
macro_rules! impl_srs {
2224
(
23-
$mod_name:ident,
25+
$name:ident,
2426
$field_ty:ty,
25-
$wasm_field:ty,
27+
$wasmF:ty,
2628
$group_ty:ty,
2729
$group_wrapper:ty,
2830
$poly_comm_wrapper:ty,
29-
$struct_ident:ident
31+
$field_name:ident
3032
) => {
31-
pub mod $mod_name {
33+
pub mod $name {
3234
use super::*;
3335

3436
#[napi]
3537
#[derive(Clone)]
36-
pub struct $struct_ident {
37-
#[napi(skip)]
38-
pub inner: Arc<SRS<$group_ty>>,
39-
}
38+
pub struct [Napi $field_name:camel Srs] (
39+
#[napi(skip)] pub Arc<SRS<$group_ty>>
40+
);
4041

41-
impl $struct_ident {
42+
impl [Napi $field_name:camel Srs] {
4243
fn new(inner: SRS<$group_ty>) -> Self {
43-
Self {
44-
inner: Arc::new(inner),
45-
}
44+
Self (
45+
Arc::new(inner),
46+
)
4647
}
4748

4849
fn from_arc(inner: Arc<SRS<$group_ty>>) -> Self {
49-
Self { inner }
50+
Self (inner)
5051
}
5152
}
5253

@@ -188,7 +189,7 @@ macro_rules! impl_srs_module {
188189
domain_size: i32,
189190
evaluations: Uint8Array,
190191
) -> Result<$poly_comm_wrapper> {
191-
let elems: Vec<$field_ty> = WasmFlatVector::<$wasm_field>::from_bytes(
192+
let elems: Vec<$field_ty> = WasmFlatVector::<$wasmF>::from_bytes(
192193
evaluations.as_ref().to_vec(),
193194
)
194195
.into_iter()
@@ -203,7 +204,7 @@ macro_rules! impl_srs_module {
203204

204205
#[napi]
205206
pub fn b_poly_commitment(&self, chals: Uint8Array) -> Result<$poly_comm_wrapper> {
206-
let elements: Vec<$field_ty> = WasmFlatVector::<$wasm_field>::from_bytes(
207+
let elements: Vec<$field_ty> = WasmFlatVector::<$wasmF>::from_bytes(
207208
chals.as_ref().to_vec(),
208209
)
209210
.into_iter()
@@ -221,7 +222,7 @@ macro_rules! impl_srs_module {
221222
chals: Uint8Array,
222223
) -> Result<bool> {
223224
let comms: Vec<$group_ty> = commitments.into_iter().map(Into::into).collect();
224-
let chals: Vec<$field_ty> = WasmFlatVector::<$wasm_field>::from_bytes(
225+
let chals: Vec<$field_ty> = WasmFlatVector::<$wasmF>::from_bytes(
225226
chals.as_ref().to_vec(),
226227
)
227228
.into_iter()
@@ -240,7 +241,7 @@ macro_rules! impl_srs_module {
240241
count: i32,
241242
chals: Uint8Array,
242243
) -> Result<WasmVector<$group_wrapper>> {
243-
let chals: Vec<$field_ty> = WasmFlatVector::<$wasm_field>::from_bytes(
244+
let chals: Vec<$field_ty> = WasmFlatVector::<$wasmF>::from_bytes(
244245
chals.as_ref().to_vec(),
245246
)
246247
.into_iter()
@@ -263,22 +264,28 @@ macro_rules! impl_srs_module {
263264
};
264265
}
265266

266-
impl_srs_module!(
267-
fp,
268-
mina_curves::pasta::Fp,
269-
WasmPastaFp,
270-
mina_curves::pasta::Vesta,
271-
WasmGVesta,
272-
WasmFpPolyComm,
273-
WasmFpSrs
274-
);
267+
pub mod fp {
268+
use super::*;
269+
impl_srs!(
270+
fp,
271+
mina_curves::pasta::Fp,
272+
WasmPastaFp,
273+
mina_curves::pasta::Vesta,
274+
WasmGVesta,
275+
WasmFpPolyComm,
276+
Fp
277+
);
278+
}
275279

276-
impl_srs_module!(
277-
fq,
278-
mina_curves::pasta::Fq,
279-
WasmPastaFq,
280-
mina_curves::pasta::Pallas,
281-
WasmGPallas,
282-
WasmFqPolyComm,
283-
WasmFqSrs
284-
);
280+
pub mod fq {
281+
use super::*;
282+
impl_srs!(
283+
fq,
284+
mina_curves::pasta::Fq,
285+
WasmPastaFq,
286+
mina_curves::pasta::Pallas,
287+
WasmGPallas,
288+
WasmFqPolyComm,
289+
Fq
290+
);
291+
}

0 commit comments

Comments
 (0)