From e25e75de7b9ca1835e7c3b3fa8c741bbc9459986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Querol?= Date: Tue, 30 Sep 2025 20:12:10 +0200 Subject: [PATCH 1/7] napi: wrapper for field types --- plonk-napi/src/lib.rs | 3 +- plonk-napi/src/poseidon.rs | 2 +- plonk-napi/src/wrappers/field.rs | 99 ++++++++++++++++++++++++++++++++ plonk-napi/src/wrappers/mod.rs | 1 + 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 plonk-napi/src/wrappers/field.rs create mode 100644 plonk-napi/src/wrappers/mod.rs diff --git a/plonk-napi/src/lib.rs b/plonk-napi/src/lib.rs index f0c304a7b98..c46288a072b 100644 --- a/plonk-napi/src/lib.rs +++ b/plonk-napi/src/lib.rs @@ -1,8 +1,9 @@ mod circuit; mod poseidon; mod types; +mod wrappers; pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher}; - +pub use wrappers::field::{WasmPastaFp, WasmPastaFq}; pub use circuit::prover_to_json; pub use types::{prover_index_from_bytes, prover_index_to_bytes, WasmPastaFpPlonkIndex}; diff --git a/plonk-napi/src/poseidon.rs b/plonk-napi/src/poseidon.rs index dc7c9f108d8..4f910b5b54a 100644 --- a/plonk-napi/src/poseidon.rs +++ b/plonk-napi/src/poseidon.rs @@ -1,4 +1,4 @@ -use arkworks::{WasmPastaFp, WasmPastaFq}; +use crate::wrappers::field::{WasmPastaFp, WasmPastaFq}; use mina_curves::pasta::{Fp, Fq}; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, permutation::poseidon_block_cipher}; use napi::bindgen_prelude::*; diff --git a/plonk-napi/src/wrappers/field.rs b/plonk-napi/src/wrappers/field.rs new file mode 100644 index 00000000000..8f396ab97e5 --- /dev/null +++ b/plonk-napi/src/wrappers/field.rs @@ -0,0 +1,99 @@ +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; +use mina_curves::pasta::{Fp, Fq}; +use napi::bindgen_prelude::*; +use wasm_types::FlatVectorElem; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct WasmPastaFp(pub Fp); + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct WasmPastaFq(pub Fq); + +macro_rules! impl_field_wrapper { + ($name:ident, $field:ty) => { + impl $name { + fn serialize(&self) -> Vec { + let mut bytes = Vec::with_capacity(core::mem::size_of::<$field>()); + self.0 + .serialize_compressed(&mut bytes) + .expect("serialization failure"); + bytes + } + + fn deserialize(bytes: &[u8]) -> Self { + let value = + <$field>::deserialize_compressed(bytes).expect("deserialization failure"); + Self(value) + } + } + + impl From<$field> for $name { + fn from(value: $field) -> Self { + Self(value) + } + } + + impl From<$name> for $field { + fn from(value: $name) -> Self { + value.0 + } + } + + impl<'a> From<&'a $name> for &'a $field { + fn from(value: &'a $name) -> Self { + &value.0 + } + } + + impl FlatVectorElem for $name { + const FLATTENED_SIZE: usize = core::mem::size_of::<$field>(); + + fn flatten(self) -> Vec { + self.serialize() + } + + fn unflatten(flat: Vec) -> Self { + Self::deserialize(&flat) + } + } + + impl TypeName for $name { + fn type_name() -> &'static str { + ::type_name() + } + + fn value_type() -> ValueType { + ::value_type() + } + } + + impl ValidateNapiValue for $name { + unsafe fn validate( + env: sys::napi_env, + napi_val: sys::napi_value, + ) -> Result { + ::validate(env, napi_val) + } + } + + impl FromNapiValue for $name { + unsafe fn from_napi_value( + env: sys::napi_env, + napi_val: sys::napi_value, + ) -> Result { + let buffer = ::from_napi_value(env, napi_val)?; + Ok(Self::deserialize(buffer.as_ref())) + } + } + + impl ToNapiValue for $name { + unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result { + let buffer = Buffer::from(val.serialize()); + ::to_napi_value(env, buffer) + } + } + }; +} + +impl_field_wrapper!(WasmPastaFp, Fp); +impl_field_wrapper!(WasmPastaFq, Fq); \ No newline at end of file diff --git a/plonk-napi/src/wrappers/mod.rs b/plonk-napi/src/wrappers/mod.rs new file mode 100644 index 00000000000..70f3d34a62b --- /dev/null +++ b/plonk-napi/src/wrappers/mod.rs @@ -0,0 +1 @@ +pub(crate) mod field; \ No newline at end of file From a5d32fee40f2f30d51fbfbe5ee788c9aa220a772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Querol?= Date: Tue, 30 Sep 2025 20:14:53 +0200 Subject: [PATCH 2/7] napi: wrapper for group types --- plonk-napi/src/lib.rs | 1 + plonk-napi/src/wrappers/group.rs | 123 +++++++++++++++++++++++++++++++ plonk-napi/src/wrappers/mod.rs | 3 +- 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 plonk-napi/src/wrappers/group.rs diff --git a/plonk-napi/src/lib.rs b/plonk-napi/src/lib.rs index c46288a072b..4321ee69112 100644 --- a/plonk-napi/src/lib.rs +++ b/plonk-napi/src/lib.rs @@ -7,3 +7,4 @@ pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_b pub use wrappers::field::{WasmPastaFp, WasmPastaFq}; pub use circuit::prover_to_json; pub use types::{prover_index_from_bytes, prover_index_to_bytes, WasmPastaFpPlonkIndex}; +pub use wrappers::group::{WasmGPallas, WasmGVesta}; diff --git a/plonk-napi/src/wrappers/group.rs b/plonk-napi/src/wrappers/group.rs new file mode 100644 index 00000000000..be8cbff4a0e --- /dev/null +++ b/plonk-napi/src/wrappers/group.rs @@ -0,0 +1,123 @@ +use crate::wrappers::field::{WasmPastaFp, WasmPastaFq}; +use mina_curves::pasta::{ + curves::{ + pallas::{G_GENERATOR_X as GeneratorPallasX, G_GENERATOR_Y as GeneratorPallasY}, + vesta::{G_GENERATOR_X as GeneratorVestaX, G_GENERATOR_Y as GeneratorVestaY}, + }, + Pallas as AffinePallas, Vesta as AffineVesta, +}; +use napi_derive::napi; + +#[napi(object)] +#[derive(Clone, Debug)] +pub struct WasmGPallas { + pub x: WasmPastaFp, + pub y: WasmPastaFp, + pub infinity: bool, +} + +#[napi(object)] +#[derive(Clone, Debug)] +pub struct WasmGVesta { + pub x: WasmPastaFq, + pub y: WasmPastaFq, + pub infinity: bool, +} + +impl From for WasmGPallas { + fn from(point: AffinePallas) -> Self { + Self { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +impl From<&AffinePallas> for WasmGPallas { + fn from(point: &AffinePallas) -> Self { + Self { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +impl From for AffinePallas { + fn from(point: WasmGPallas) -> Self { + AffinePallas { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +impl From<&WasmGPallas> for AffinePallas { + fn from(point: &WasmGPallas) -> Self { + AffinePallas { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +impl From for WasmGVesta { + fn from(point: AffineVesta) -> Self { + Self { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +impl From<&AffineVesta> for WasmGVesta { + fn from(point: &AffineVesta) -> Self { + Self { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +impl From for AffineVesta { + fn from(point: WasmGVesta) -> Self { + AffineVesta { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +impl From<&WasmGVesta> for AffineVesta { + fn from(point: &WasmGVesta) -> Self { + AffineVesta { + x: point.x.into(), + y: point.y.into(), + infinity: point.infinity, + } + } +} + +#[napi] +pub fn caml_pallas_affine_one() -> WasmGPallas { + WasmGPallas { + x: WasmPastaFp::from(GeneratorPallasX), + y: WasmPastaFp::from(GeneratorPallasY), + infinity: false, + } +} + +#[napi] +pub fn caml_vesta_affine_one() -> WasmGVesta { + WasmGVesta { + x: WasmPastaFq::from(GeneratorVestaX), + y: WasmPastaFq::from(GeneratorVestaY), + infinity: false, + } +} \ No newline at end of file diff --git a/plonk-napi/src/wrappers/mod.rs b/plonk-napi/src/wrappers/mod.rs index 70f3d34a62b..15443ca3d87 100644 --- a/plonk-napi/src/wrappers/mod.rs +++ b/plonk-napi/src/wrappers/mod.rs @@ -1 +1,2 @@ -pub(crate) mod field; \ No newline at end of file +pub(crate) mod field; +pub(crate) mod group; \ No newline at end of file From 4b320f3832e79d61c59e63281c180cda93196894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Querol?= Date: Tue, 30 Sep 2025 20:18:59 +0200 Subject: [PATCH 3/7] napi: impls for wasm vectors --- plonk-napi/src/lib.rs | 6 +- plonk-napi/src/wasm_vector.rs | 199 ++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 plonk-napi/src/wasm_vector.rs diff --git a/plonk-napi/src/lib.rs b/plonk-napi/src/lib.rs index 4321ee69112..22e9577972c 100644 --- a/plonk-napi/src/lib.rs +++ b/plonk-napi/src/lib.rs @@ -2,9 +2,11 @@ mod circuit; mod poseidon; mod types; mod wrappers; +mod wasm_vector; -pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher}; -pub use wrappers::field::{WasmPastaFp, WasmPastaFq}; pub use circuit::prover_to_json; +pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher}; pub use types::{prover_index_from_bytes, prover_index_to_bytes, WasmPastaFpPlonkIndex}; +pub use wasm_vector::{fp::WasmVecVecFp, fq::WasmVecVecFq}; +pub use wrappers::field::{WasmPastaFp, WasmPastaFq}; pub use wrappers::group::{WasmGPallas, WasmGVesta}; diff --git a/plonk-napi/src/wasm_vector.rs b/plonk-napi/src/wasm_vector.rs new file mode 100644 index 00000000000..278b408a210 --- /dev/null +++ b/plonk-napi/src/wasm_vector.rs @@ -0,0 +1,199 @@ +use std::{iter::FromIterator, ops::Deref}; + +use napi::{bindgen_prelude::*, sys}; +use wasm_types::{FlatVector, FlatVectorElem}; + +#[derive(Clone, Debug, Default)] +pub struct WasmVector(pub Vec); + +impl WasmVector { + pub fn into_inner(self) -> Vec { + self.0 + } +} + +impl Deref for WasmVector { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl From> for WasmVector { + fn from(value: Vec) -> Self { + WasmVector(value) + } +} + +impl From> for Vec { + fn from(value: WasmVector) -> Self { + value.0 + } +} + +impl<'a, T> From<&'a WasmVector> for &'a Vec { + fn from(value: &'a WasmVector) -> Self { + &value.0 + } +} + +impl IntoIterator for WasmVector { + type Item = T; + type IntoIter = as IntoIterator>::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl<'a, T> IntoIterator for &'a WasmVector { + type Item = &'a T; + type IntoIter = <&'a Vec as IntoIterator>::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.0.iter() + } +} + +impl FromIterator for WasmVector { + fn from_iter>(iter: I) -> Self { + WasmVector(Vec::from_iter(iter)) + } +} + +impl Extend for WasmVector { + fn extend>(&mut self, iter: I) { + self.0.extend(iter); + } +} + +impl TypeName for WasmVector +where + Vec: TypeName, +{ + fn type_name() -> &'static str { + as TypeName>::type_name() + } + + fn value_type() -> ValueType { + as TypeName>::value_type() + } +} + +impl ValidateNapiValue for WasmVector +where + Vec: ValidateNapiValue, + T: FromNapiValue, +{ + unsafe fn validate(env: sys::napi_env, napi_val: sys::napi_value) -> Result { + as ValidateNapiValue>::validate(env, napi_val) + } +} + +impl FromNapiValue for WasmVector +where + Vec: FromNapiValue, +{ + unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result { + Ok(WasmVector( as FromNapiValue>::from_napi_value( + env, napi_val, + )?)) + } +} + +impl ToNapiValue for WasmVector +where + Vec: ToNapiValue, +{ + unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result { + as ToNapiValue>::to_napi_value(env, val.0) + } +} + +macro_rules! impl_vec_vec_fp { + ($name:ident, $field:ty, $wasm_field:ty) => { + #[napi] + #[derive(Clone, Debug, Default)] + pub struct $name(#[napi(skip)] pub Vec>); + + #[napi] + impl $name { + #[napi(constructor)] + pub fn create(capacity: i32) -> Self { + Self(Vec::with_capacity(capacity as usize)) + } + + #[napi] + pub fn push(&mut self, vector: Uint8Array) -> Result<()> { + let flattened = vector.as_ref().to_vec(); + let values = FlatVector::<$wasm_field>::from_bytes(flattened) + .into_iter() + .map(Into::into) + .collect(); + self.0.push(values); + Ok(()) + } + + #[napi] + pub fn get(&self, index: i32) -> Result { + let slice = self.0.get(index as usize).ok_or_else(|| { + Error::new(Status::InvalidArg, "index out of bounds".to_string()) + })?; + + let bytes = slice + .iter() + .cloned() + .map(<$wasm_field>::from) + .flat_map(FlatVectorElem::flatten) + .collect::>(); + + Ok(Uint8Array::from(bytes)) + } + + #[napi] + pub fn set(&mut self, index: i32, vector: Uint8Array) -> Result<()> { + let entry = self.0.get_mut(index as usize).ok_or_else(|| { + Error::new(Status::InvalidArg, "index out of bounds".to_string()) + })?; + + let flattened = vector.as_ref().to_vec(); + *entry = FlatVector::<$wasm_field>::from_bytes(flattened) + .into_iter() + .map(Into::into) + .collect(); + Ok(()) + } + } + + impl From>> for $name { + fn from(value: Vec>) -> Self { + Self(value) + } + } + + impl From<$name> for Vec> { + fn from(value: $name) -> Self { + value.0 + } + } + }; +} + +pub mod fp { + use super::*; + use crate::wrappers::field::WasmPastaFp; + use mina_curves::pasta::Fp; + use napi_derive::napi; + + impl_vec_vec_fp!(WasmVecVecFp, Fp, WasmPastaFp); +} + +pub mod fq { + use super::*; + use crate::wrappers::field::WasmPastaFq; + use mina_curves::pasta::Fq; + use napi_derive::napi; + + impl_vec_vec_fp!(WasmVecVecFq, Fq, WasmPastaFq); +} \ No newline at end of file From 8638b153d054385d8621f4f7309e9ea9f39e47eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Querol?= Date: Wed, 1 Oct 2025 13:24:13 +0200 Subject: [PATCH 4/7] napi: impls for polycomm --- plonk-napi/src/lib.rs | 2 + plonk-napi/src/poly_comm.rs | 115 ++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 plonk-napi/src/poly_comm.rs diff --git a/plonk-napi/src/lib.rs b/plonk-napi/src/lib.rs index 22e9577972c..5e62cc5d165 100644 --- a/plonk-napi/src/lib.rs +++ b/plonk-napi/src/lib.rs @@ -3,8 +3,10 @@ mod poseidon; mod types; mod wrappers; mod wasm_vector; +mod poly_comm; pub use circuit::prover_to_json; +pub use poly_comm::{pallas::WasmFqPolyComm, vesta::WasmFpPolyComm}; pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher}; pub use types::{prover_index_from_bytes, prover_index_to_bytes, WasmPastaFpPlonkIndex}; pub use wasm_vector::{fp::WasmVecVecFp, fq::WasmVecVecFq}; diff --git a/plonk-napi/src/poly_comm.rs b/plonk-napi/src/poly_comm.rs new file mode 100644 index 00000000000..b90e9df9783 --- /dev/null +++ b/plonk-napi/src/poly_comm.rs @@ -0,0 +1,115 @@ +use crate::{ + wrappers::group::{WasmGPallas, WasmGVesta}, + wasm_vector::WasmVector, +}; +use napi_derive::napi; +use paste::paste; +use poly_commitment::commitment::PolyComm; + +macro_rules! impl_poly_comm { + ( + $wasm_g:ty, + $g:ty, + $field_name:ident + ) => { + paste! { + #[napi] + #[derive(Clone)] + pub struct [] { + #[napi(skip)] + pub unshifted: WasmVector<$wasm_g>, + pub shifted: Option<$wasm_g>, + } + + #[napi] + impl [] { + #[napi(constructor)] + pub fn new(unshifted: WasmVector<$wasm_g>, shifted: Option<$wasm_g>) -> Self { + assert!( + shifted.is_none(), + "mina#14628: Shifted commitments are deprecated and must not be used", + ); + Self { unshifted, shifted } + } + + #[napi(getter)] + pub fn unshifted(&self) -> WasmVector<$wasm_g> { + self.unshifted.clone() + } + + #[napi(setter)] + pub fn set_unshifted(&mut self, value: WasmVector<$wasm_g>) { + self.unshifted = value; + } + } + + impl From> for [] { + fn from(value: PolyComm<$g>) -> Self { + let PolyComm { chunks } = value; + let unshifted: Vec<$wasm_g> = chunks.into_iter().map(Into::into).collect(); + Self { + unshifted: unshifted.into(), + shifted: None, + } + } + } + + impl From<&PolyComm<$g>> for [] { + fn from(value: &PolyComm<$g>) -> Self { + let unshifted: Vec<$wasm_g> = value.chunks.iter().map(|chunk| (*chunk).into()).collect(); + Self { + unshifted: unshifted.into(), + shifted: None, + } + } + } + + impl From<[]> for PolyComm<$g> { + fn from(value: []) -> Self { + let [] { unshifted, shifted } = value; + assert!( + shifted.is_none(), + "mina#14628: Shifted commitments are deprecated and must not be used", + ); + PolyComm { + chunks: Vec::<$wasm_g>::from(unshifted) + .into_iter() + .map(Into::into) + .collect(), + } + } + } + + impl From<&[]> for PolyComm<$g> { + fn from(value: &[]) -> Self { + assert!( + value.shifted.is_none(), + "mina#14628: Shifted commitments are deprecated and must not be used", + ); + PolyComm { + chunks: value + .unshifted + .iter() + .cloned() + .map(Into::into) + .collect(), + } + } + } + } + }; +} + +pub mod pallas { + use super::*; + use mina_curves::pasta::Pallas as GAffine; + + impl_poly_comm!(WasmGPallas, GAffine, Fq); +} + +pub mod vesta { + use super::*; + use mina_curves::pasta::Vesta as GAffine; + + impl_poly_comm!(WasmGVesta, GAffine, Fp); +} From 0d95c15db34911f5a73bc6ec4efb8817138a5739 Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 16 Oct 2025 19:42:49 +0200 Subject: [PATCH 5/7] napi: uniformize format to match plonk-wasm side --- plonk-napi/src/poly_comm.rs | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/plonk-napi/src/poly_comm.rs b/plonk-napi/src/poly_comm.rs index b90e9df9783..b988f3e1e76 100644 --- a/plonk-napi/src/poly_comm.rs +++ b/plonk-napi/src/poly_comm.rs @@ -1,14 +1,11 @@ -use crate::{ - wrappers::group::{WasmGPallas, WasmGVesta}, - wasm_vector::WasmVector, -}; +use crate::wasm_vector::WasmVector; use napi_derive::napi; use paste::paste; use poly_commitment::commitment::PolyComm; macro_rules! impl_poly_comm { ( - $wasm_g:ty, + $WasmG:ty, $g:ty, $field_name:ident ) => { @@ -17,14 +14,14 @@ macro_rules! impl_poly_comm { #[derive(Clone)] pub struct [] { #[napi(skip)] - pub unshifted: WasmVector<$wasm_g>, - pub shifted: Option<$wasm_g>, + pub unshifted: WasmVector<$WasmG>, + pub shifted: Option<$WasmG>, } #[napi] impl [] { #[napi(constructor)] - pub fn new(unshifted: WasmVector<$wasm_g>, shifted: Option<$wasm_g>) -> Self { + pub fn new(unshifted: WasmVector<$WasmG>, shifted: Option<$WasmG>) -> Self { assert!( shifted.is_none(), "mina#14628: Shifted commitments are deprecated and must not be used", @@ -33,20 +30,20 @@ macro_rules! impl_poly_comm { } #[napi(getter)] - pub fn unshifted(&self) -> WasmVector<$wasm_g> { + pub fn unshifted(&self) -> WasmVector<$WasmG> { self.unshifted.clone() } #[napi(setter)] - pub fn set_unshifted(&mut self, value: WasmVector<$wasm_g>) { - self.unshifted = value; + pub fn set_unshifted(&mut self, x: WasmVector<$WasmG>) { + self.unshifted = x; } } impl From> for [] { - fn from(value: PolyComm<$g>) -> Self { - let PolyComm { chunks } = value; - let unshifted: Vec<$wasm_g> = chunks.into_iter().map(Into::into).collect(); + fn from(x: PolyComm<$g>) -> Self { + let PolyComm { chunks } = x; + let unshifted: Vec<$WasmG> = chunks.into_iter().map(Into::into).collect(); Self { unshifted: unshifted.into(), shifted: None, @@ -55,8 +52,8 @@ macro_rules! impl_poly_comm { } impl From<&PolyComm<$g>> for [] { - fn from(value: &PolyComm<$g>) -> Self { - let unshifted: Vec<$wasm_g> = value.chunks.iter().map(|chunk| (*chunk).into()).collect(); + fn from(x: &PolyComm<$g>) -> Self { + let unshifted: Vec<$WasmG> = x.chunks.iter().map(|chunk| (*chunk).into()).collect(); Self { unshifted: unshifted.into(), shifted: None, @@ -65,14 +62,14 @@ macro_rules! impl_poly_comm { } impl From<[]> for PolyComm<$g> { - fn from(value: []) -> Self { - let [] { unshifted, shifted } = value; + fn from(x: []) -> Self { + let [] { unshifted, shifted } = x; assert!( shifted.is_none(), "mina#14628: Shifted commitments are deprecated and must not be used", ); PolyComm { - chunks: Vec::<$wasm_g>::from(unshifted) + chunks: Vec::<$WasmG>::from(unshifted) .into_iter() .map(Into::into) .collect(), @@ -81,13 +78,13 @@ macro_rules! impl_poly_comm { } impl From<&[]> for PolyComm<$g> { - fn from(value: &[]) -> Self { + fn from(x: &[]) -> Self { assert!( - value.shifted.is_none(), + x.shifted.is_none(), "mina#14628: Shifted commitments are deprecated and must not be used", ); PolyComm { - chunks: value + chunks: x .unshifted .iter() .cloned() @@ -102,6 +99,7 @@ macro_rules! impl_poly_comm { pub mod pallas { use super::*; + use crate::wrappers::group::WasmGPallas; use mina_curves::pasta::Pallas as GAffine; impl_poly_comm!(WasmGPallas, GAffine, Fq); @@ -109,6 +107,7 @@ pub mod pallas { pub mod vesta { use super::*; + use crate::wrappers::group::WasmGVesta; use mina_curves::pasta::Vesta as GAffine; impl_poly_comm!(WasmGVesta, GAffine, Fp); From 9e4d1febcee50f80b110e78cf8a1b5b37bdebdf2 Mon Sep 17 00:00:00 2001 From: querolita Date: Tue, 4 Nov 2025 22:18:30 +0100 Subject: [PATCH 6/7] napi: prefix wrappers with napi and implement missing traits --- plonk-napi/src/lib.rs | 17 +++-- plonk-napi/src/poly_comm.rs | 76 +++++++++++++------- plonk-napi/src/poseidon.rs | 10 +-- plonk-napi/src/{wasm_vector.rs => vector.rs} | 76 +++++++++++++------- plonk-napi/src/wrappers/field.rs | 51 +++++++++---- plonk-napi/src/wrappers/group.rs | 61 ++++++++-------- 6 files changed, 182 insertions(+), 109 deletions(-) rename plonk-napi/src/{wasm_vector.rs => vector.rs} (71%) diff --git a/plonk-napi/src/lib.rs b/plonk-napi/src/lib.rs index 18379ab9795..74c704a9c8a 100644 --- a/plonk-napi/src/lib.rs +++ b/plonk-napi/src/lib.rs @@ -1,20 +1,25 @@ mod build_info; mod circuit; -pub mod plonk_verifier_index; +mod plonk_verifier_index; mod poly_comm; mod poseidon; mod prover_index; mod types; -mod wasm_vector; +mod vector; mod wrappers; pub use circuit::prover_to_json; -pub use poly_comm::{pallas::WasmFqPolyComm, vesta::WasmFpPolyComm}; +pub use plonk_verifier_index::{ + caml_pasta_fp_plonk_verifier_index_shifts, caml_pasta_fq_plonk_verifier_index_shifts, +}; +pub use poly_comm::{ + pallas::NapiFqPolyComm as WasmFqPolyComm, vesta::NapiFpPolyComm as WasmFpPolyComm, +}; pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher}; pub use prover_index::{prover_index_from_bytes, prover_index_to_bytes}; pub use types::WasmPastaFpPlonkIndex; -pub use wasm_vector::{fp::WasmVecVecFp, fq::WasmVecVecFq}; +pub use vector::{fp::NapiVecVecFp as WasmVecVecFp, fq::NapiVecVecFq as WasmVecVecFq}; pub use wrappers::{ - field::{WasmPastaFp, WasmPastaFq}, - group::{WasmGPallas, WasmGVesta}, + field::{NapiPastaFp as WasmPastaFp, NapiPastaFq as WasmPastaFq}, + group::{NapiGPallas as WasmGPallas, NapiGVesta as WasmGVesta}, }; diff --git a/plonk-napi/src/poly_comm.rs b/plonk-napi/src/poly_comm.rs index b988f3e1e76..f6a3c13b199 100644 --- a/plonk-napi/src/poly_comm.rs +++ b/plonk-napi/src/poly_comm.rs @@ -1,27 +1,30 @@ -use crate::wasm_vector::WasmVector; +use crate::vector::NapiVector; +use napi::bindgen_prelude::{ClassInstance, FromNapiValue}; use napi_derive::napi; use paste::paste; use poly_commitment::commitment::PolyComm; +use serde::{Deserialize, Serialize}; macro_rules! impl_poly_comm { ( - $WasmG:ty, + $NapiG:ty, $g:ty, $field_name:ident ) => { paste! { #[napi] - #[derive(Clone)] - pub struct [] { + #[derive(Clone, Debug, Serialize, Deserialize, Default)] + pub struct [] { #[napi(skip)] - pub unshifted: WasmVector<$WasmG>, - pub shifted: Option<$WasmG>, + pub unshifted: NapiVector<$NapiG>, + #[napi(skip)] + pub shifted: Option<$NapiG>, } #[napi] - impl [] { + impl [] { #[napi(constructor)] - pub fn new(unshifted: WasmVector<$WasmG>, shifted: Option<$WasmG>) -> Self { + pub fn new(unshifted: NapiVector<$NapiG>, shifted: Option<$NapiG>) -> Self { assert!( shifted.is_none(), "mina#14628: Shifted commitments are deprecated and must not be used", @@ -30,20 +33,30 @@ macro_rules! impl_poly_comm { } #[napi(getter)] - pub fn unshifted(&self) -> WasmVector<$WasmG> { + pub fn unshifted(&self) -> NapiVector<$NapiG> { self.unshifted.clone() } #[napi(setter)] - pub fn set_unshifted(&mut self, x: WasmVector<$WasmG>) { + pub fn set_unshifted(&mut self, x: NapiVector<$NapiG>) { self.unshifted = x; } + + #[napi(getter)] + pub fn shifted(&self) -> Option<$NapiG> { + self.shifted.clone() + } + + #[napi(setter)] + pub fn set_shifted(&mut self, value: Option<$NapiG>) { + self.shifted = value; + } } - impl From> for [] { + impl From> for [] { fn from(x: PolyComm<$g>) -> Self { let PolyComm { chunks } = x; - let unshifted: Vec<$WasmG> = chunks.into_iter().map(Into::into).collect(); + let unshifted: Vec<$NapiG> = chunks.into_iter().map(Into::into).collect(); Self { unshifted: unshifted.into(), shifted: None, @@ -51,9 +64,9 @@ macro_rules! impl_poly_comm { } } - impl From<&PolyComm<$g>> for [] { + impl From<&PolyComm<$g>> for [] { fn from(x: &PolyComm<$g>) -> Self { - let unshifted: Vec<$WasmG> = x.chunks.iter().map(|chunk| (*chunk).into()).collect(); + let unshifted: Vec<$NapiG> = x.chunks.iter().map(|chunk| (*chunk).into()).collect(); Self { unshifted: unshifted.into(), shifted: None, @@ -61,15 +74,15 @@ macro_rules! impl_poly_comm { } } - impl From<[]> for PolyComm<$g> { - fn from(x: []) -> Self { - let [] { unshifted, shifted } = x; + impl From<[]> for PolyComm<$g> { + fn from(x: []) -> Self { + let [] { unshifted, shifted } = x; assert!( shifted.is_none(), "mina#14628: Shifted commitments are deprecated and must not be used", ); PolyComm { - chunks: Vec::<$WasmG>::from(unshifted) + chunks: Vec::<$NapiG>::from(unshifted) .into_iter() .map(Into::into) .collect(), @@ -77,8 +90,8 @@ macro_rules! impl_poly_comm { } } - impl From<&[]> for PolyComm<$g> { - fn from(x: &[]) -> Self { + impl From<&[]> for PolyComm<$g> { + fn from(x: &[]) -> Self { assert!( x.shifted.is_none(), "mina#14628: Shifted commitments are deprecated and must not be used", @@ -93,22 +106,33 @@ macro_rules! impl_poly_comm { } } } + + impl FromNapiValue for [] { + unsafe fn from_napi_value( + env: napi::sys::napi_env, + napi_val: napi::sys::napi_value, + ) -> napi::Result { + let instance = ]> as FromNapiValue>::from_napi_value(env, napi_val)?; + Ok((*instance).clone()) + } + } + } }; } pub mod pallas { use super::*; - use crate::wrappers::group::WasmGPallas; - use mina_curves::pasta::Pallas as GAffine; + use crate::wrappers::group::NapiGPallas; + use mina_curves::pasta::Pallas; - impl_poly_comm!(WasmGPallas, GAffine, Fq); + impl_poly_comm!(NapiGPallas, Pallas, Fq); } pub mod vesta { use super::*; - use crate::wrappers::group::WasmGVesta; - use mina_curves::pasta::Vesta as GAffine; + use crate::wrappers::group::NapiGVesta; + use mina_curves::pasta::Vesta; - impl_poly_comm!(WasmGVesta, GAffine, Fp); + impl_poly_comm!(NapiGVesta, Vesta, Fp); } diff --git a/plonk-napi/src/poseidon.rs b/plonk-napi/src/poseidon.rs index 607fbea7e47..cc81d93de8c 100644 --- a/plonk-napi/src/poseidon.rs +++ b/plonk-napi/src/poseidon.rs @@ -1,4 +1,4 @@ -use crate::wrappers::field::{WasmPastaFp, WasmPastaFq}; +use crate::wrappers::field::{NapiPastaFp, NapiPastaFq}; use mina_curves::pasta::{Fp, Fq}; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, permutation::poseidon_block_cipher}; use napi::bindgen_prelude::*; @@ -15,7 +15,7 @@ pub fn caml_pasta_fp_poseidon_block_cipher(state: Uint8Array) -> Result = FlatVector::::from_bytes(state.to_vec()) + let mut state_vec: Vec = FlatVector::::from_bytes(state.to_vec()) .into_iter() .map(Into::into) .collect(); @@ -27,7 +27,7 @@ pub fn caml_pasta_fp_poseidon_block_cipher(state: Uint8Array) -> Result = state_vec .into_iter() - .map(WasmPastaFp) + .map(NapiPastaFp) .flat_map(FlatVectorElem::flatten) .collect(); @@ -42,7 +42,7 @@ pub fn caml_pasta_fq_poseidon_block_cipher(state: Uint8Array) -> Result = FlatVector::::from_bytes(state.to_vec()) + let mut state_vec: Vec = FlatVector::::from_bytes(state.to_vec()) .into_iter() .map(Into::into) .collect(); @@ -54,7 +54,7 @@ pub fn caml_pasta_fq_poseidon_block_cipher(state: Uint8Array) -> Result = state_vec .into_iter() - .map(WasmPastaFq) + .map(NapiPastaFq) .flat_map(FlatVectorElem::flatten) .collect(); diff --git a/plonk-napi/src/wasm_vector.rs b/plonk-napi/src/vector.rs similarity index 71% rename from plonk-napi/src/wasm_vector.rs rename to plonk-napi/src/vector.rs index 278b408a210..23cf87cbb8a 100644 --- a/plonk-napi/src/wasm_vector.rs +++ b/plonk-napi/src/vector.rs @@ -1,18 +1,18 @@ -use std::{iter::FromIterator, ops::Deref}; - use napi::{bindgen_prelude::*, sys}; +use serde::{Deserialize, Serialize}; +use std::{iter::FromIterator, ops::Deref}; use wasm_types::{FlatVector, FlatVectorElem}; -#[derive(Clone, Debug, Default)] -pub struct WasmVector(pub Vec); +#[derive(Clone, Debug, Serialize, Deserialize, Default)] +pub struct NapiVector(pub Vec); -impl WasmVector { +impl NapiVector { pub fn into_inner(self) -> Vec { self.0 } } -impl Deref for WasmVector { +impl Deref for NapiVector { type Target = Vec; fn deref(&self) -> &Self::Target { @@ -20,25 +20,25 @@ impl Deref for WasmVector { } } -impl From> for WasmVector { +impl From> for NapiVector { fn from(value: Vec) -> Self { - WasmVector(value) + NapiVector(value) } } -impl From> for Vec { - fn from(value: WasmVector) -> Self { +impl From> for Vec { + fn from(value: NapiVector) -> Self { value.0 } } -impl<'a, T> From<&'a WasmVector> for &'a Vec { - fn from(value: &'a WasmVector) -> Self { +impl<'a, T> From<&'a NapiVector> for &'a Vec { + fn from(value: &'a NapiVector) -> Self { &value.0 } } -impl IntoIterator for WasmVector { +impl IntoIterator for NapiVector { type Item = T; type IntoIter = as IntoIterator>::IntoIter; @@ -47,7 +47,7 @@ impl IntoIterator for WasmVector { } } -impl<'a, T> IntoIterator for &'a WasmVector { +impl<'a, T> IntoIterator for &'a NapiVector { type Item = &'a T; type IntoIter = <&'a Vec as IntoIterator>::IntoIter; @@ -56,19 +56,19 @@ impl<'a, T> IntoIterator for &'a WasmVector { } } -impl FromIterator for WasmVector { +impl FromIterator for NapiVector { fn from_iter>(iter: I) -> Self { - WasmVector(Vec::from_iter(iter)) + NapiVector(Vec::from_iter(iter)) } } -impl Extend for WasmVector { +impl Extend for NapiVector { fn extend>(&mut self, iter: I) { self.0.extend(iter); } } -impl TypeName for WasmVector +impl TypeName for NapiVector where Vec: TypeName, { @@ -81,7 +81,7 @@ where } } -impl ValidateNapiValue for WasmVector +impl ValidateNapiValue for NapiVector where Vec: ValidateNapiValue, T: FromNapiValue, @@ -91,18 +91,18 @@ where } } -impl FromNapiValue for WasmVector +impl FromNapiValue for NapiVector where Vec: FromNapiValue, { unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result { - Ok(WasmVector( as FromNapiValue>::from_napi_value( + Ok(NapiVector( as FromNapiValue>::from_napi_value( env, napi_val, )?)) } } -impl ToNapiValue for WasmVector +impl ToNapiValue for NapiVector where Vec: ToNapiValue, { @@ -111,6 +111,28 @@ where } } +impl<'a, T> ToNapiValue for &'a NapiVector +where + Vec: ToNapiValue, + T: Clone, +{ + unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result { + let cloned: Vec = val.0.clone(); + as ToNapiValue>::to_napi_value(env, cloned) + } +} + +impl<'a, T> ToNapiValue for &'a mut NapiVector +where + Vec: ToNapiValue, + T: Clone, +{ + unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result { + let cloned: Vec = val.0.clone(); + as ToNapiValue>::to_napi_value(env, cloned) + } +} + macro_rules! impl_vec_vec_fp { ($name:ident, $field:ty, $wasm_field:ty) => { #[napi] @@ -182,18 +204,18 @@ macro_rules! impl_vec_vec_fp { pub mod fp { use super::*; - use crate::wrappers::field::WasmPastaFp; + use crate::wrappers::field::NapiPastaFp; use mina_curves::pasta::Fp; use napi_derive::napi; - impl_vec_vec_fp!(WasmVecVecFp, Fp, WasmPastaFp); + impl_vec_vec_fp!(NapiVecVecFp, Fp, NapiPastaFp); } pub mod fq { use super::*; - use crate::wrappers::field::WasmPastaFq; + use crate::wrappers::field::NapiPastaFq; use mina_curves::pasta::Fq; use napi_derive::napi; - impl_vec_vec_fp!(WasmVecVecFq, Fq, WasmPastaFq); -} \ No newline at end of file + impl_vec_vec_fp!(NapiVecVecFq, Fq, NapiPastaFq); +} diff --git a/plonk-napi/src/wrappers/field.rs b/plonk-napi/src/wrappers/field.rs index 8f396ab97e5..022636f39d1 100644 --- a/plonk-napi/src/wrappers/field.rs +++ b/plonk-napi/src/wrappers/field.rs @@ -1,29 +1,50 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use mina_curves::pasta::{Fp, Fq}; use napi::bindgen_prelude::*; +use serde::{Deserialize, Serialize}; use wasm_types::FlatVectorElem; -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct WasmPastaFp(pub Fp); +#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)] +pub struct NapiPastaFp(pub Fp); -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub struct WasmPastaFq(pub Fq); +#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)] +pub struct NapiPastaFq(pub Fq); macro_rules! impl_field_wrapper { ($name:ident, $field:ty) => { impl $name { - fn serialize(&self) -> Vec { + fn from_bytes(bytes: &[u8]) -> Self { + let value = + <$field>::deserialize_compressed(bytes).expect("deserialization failure"); + Self(value) + } + + fn to_bytes(&self) -> Vec { let mut bytes = Vec::with_capacity(core::mem::size_of::<$field>()); self.0 .serialize_compressed(&mut bytes) .expect("serialization failure"); bytes } + } - fn deserialize(bytes: &[u8]) -> Self { - let value = - <$field>::deserialize_compressed(bytes).expect("deserialization failure"); - Self(value) + impl Serialize for $name { + fn serialize(&self, serializer: S) -> std::result::Result + where + S: serde::Serializer, + { + serializer.serialize_bytes(&self.to_bytes()) + } + } + impl<'de> Deserialize<'de> for $name { + fn deserialize(deserializer: D) -> std::result::Result + where + D: serde::Deserializer<'de>, + { + let bytes: Vec = Vec::::deserialize(deserializer)?; + <$field>::deserialize_compressed(bytes.as_slice()) + .map(Self) + .map_err(serde::de::Error::custom) } } @@ -49,11 +70,11 @@ macro_rules! impl_field_wrapper { const FLATTENED_SIZE: usize = core::mem::size_of::<$field>(); fn flatten(self) -> Vec { - self.serialize() + self.to_bytes() } fn unflatten(flat: Vec) -> Self { - Self::deserialize(&flat) + Self::from_bytes(&flat) } } @@ -82,18 +103,18 @@ macro_rules! impl_field_wrapper { napi_val: sys::napi_value, ) -> Result { let buffer = ::from_napi_value(env, napi_val)?; - Ok(Self::deserialize(buffer.as_ref())) + Ok(Self::from_bytes(buffer.as_ref())) } } impl ToNapiValue for $name { unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result { - let buffer = Buffer::from(val.serialize()); + let buffer = Buffer::from(val.to_bytes()); ::to_napi_value(env, buffer) } } }; } -impl_field_wrapper!(WasmPastaFp, Fp); -impl_field_wrapper!(WasmPastaFq, Fq); \ No newline at end of file +impl_field_wrapper!(NapiPastaFp, Fp); +impl_field_wrapper!(NapiPastaFq, Fq); diff --git a/plonk-napi/src/wrappers/group.rs b/plonk-napi/src/wrappers/group.rs index be8cbff4a0e..ed082dd9223 100644 --- a/plonk-napi/src/wrappers/group.rs +++ b/plonk-napi/src/wrappers/group.rs @@ -1,4 +1,4 @@ -use crate::wrappers::field::{WasmPastaFp, WasmPastaFq}; +use crate::wrappers::field::{NapiPastaFp, NapiPastaFq}; use mina_curves::pasta::{ curves::{ pallas::{G_GENERATOR_X as GeneratorPallasX, G_GENERATOR_Y as GeneratorPallasY}, @@ -7,24 +7,25 @@ use mina_curves::pasta::{ Pallas as AffinePallas, Vesta as AffineVesta, }; use napi_derive::napi; +use serde::{Deserialize, Serialize}; #[napi(object)] -#[derive(Clone, Debug)] -pub struct WasmGPallas { - pub x: WasmPastaFp, - pub y: WasmPastaFp, +#[derive(Clone, Debug, Default, Serialize, Deserialize)] +pub struct NapiGPallas { + pub x: NapiPastaFp, + pub y: NapiPastaFp, pub infinity: bool, } #[napi(object)] -#[derive(Clone, Debug)] -pub struct WasmGVesta { - pub x: WasmPastaFq, - pub y: WasmPastaFq, +#[derive(Clone, Debug, Default, Serialize, Deserialize)] +pub struct NapiGVesta { + pub x: NapiPastaFq, + pub y: NapiPastaFq, pub infinity: bool, } -impl From for WasmGPallas { +impl From for NapiGPallas { fn from(point: AffinePallas) -> Self { Self { x: point.x.into(), @@ -34,7 +35,7 @@ impl From for WasmGPallas { } } -impl From<&AffinePallas> for WasmGPallas { +impl From<&AffinePallas> for NapiGPallas { fn from(point: &AffinePallas) -> Self { Self { x: point.x.into(), @@ -44,8 +45,8 @@ impl From<&AffinePallas> for WasmGPallas { } } -impl From for AffinePallas { - fn from(point: WasmGPallas) -> Self { +impl From for AffinePallas { + fn from(point: NapiGPallas) -> Self { AffinePallas { x: point.x.into(), y: point.y.into(), @@ -54,8 +55,8 @@ impl From for AffinePallas { } } -impl From<&WasmGPallas> for AffinePallas { - fn from(point: &WasmGPallas) -> Self { +impl From<&NapiGPallas> for AffinePallas { + fn from(point: &NapiGPallas) -> Self { AffinePallas { x: point.x.into(), y: point.y.into(), @@ -64,7 +65,7 @@ impl From<&WasmGPallas> for AffinePallas { } } -impl From for WasmGVesta { +impl From for NapiGVesta { fn from(point: AffineVesta) -> Self { Self { x: point.x.into(), @@ -74,7 +75,7 @@ impl From for WasmGVesta { } } -impl From<&AffineVesta> for WasmGVesta { +impl From<&AffineVesta> for NapiGVesta { fn from(point: &AffineVesta) -> Self { Self { x: point.x.into(), @@ -84,8 +85,8 @@ impl From<&AffineVesta> for WasmGVesta { } } -impl From for AffineVesta { - fn from(point: WasmGVesta) -> Self { +impl From for AffineVesta { + fn from(point: NapiGVesta) -> Self { AffineVesta { x: point.x.into(), y: point.y.into(), @@ -94,8 +95,8 @@ impl From for AffineVesta { } } -impl From<&WasmGVesta> for AffineVesta { - fn from(point: &WasmGVesta) -> Self { +impl From<&NapiGVesta> for AffineVesta { + fn from(point: &NapiGVesta) -> Self { AffineVesta { x: point.x.into(), y: point.y.into(), @@ -105,19 +106,19 @@ impl From<&WasmGVesta> for AffineVesta { } #[napi] -pub fn caml_pallas_affine_one() -> WasmGPallas { - WasmGPallas { - x: WasmPastaFp::from(GeneratorPallasX), - y: WasmPastaFp::from(GeneratorPallasY), +pub fn caml_pallas_affine_one() -> NapiGPallas { + NapiGPallas { + x: NapiPastaFp::from(GeneratorPallasX), + y: NapiPastaFp::from(GeneratorPallasY), infinity: false, } } #[napi] -pub fn caml_vesta_affine_one() -> WasmGVesta { - WasmGVesta { - x: WasmPastaFq::from(GeneratorVestaX), - y: WasmPastaFq::from(GeneratorVestaY), +pub fn caml_vesta_affine_one() -> NapiGVesta { + NapiGVesta { + x: NapiPastaFq::from(GeneratorVestaX), + y: NapiPastaFq::from(GeneratorVestaY), infinity: false, } -} \ No newline at end of file +} From 6a9450a2369fce53ca4a3559379fc19626a5bb56 Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 5 Nov 2025 23:33:55 +0100 Subject: [PATCH 7/7] napi: added annotations js_name for polycomm and affine --- plonk-napi/src/poly_comm.rs | 6 +++--- plonk-napi/src/wrappers/group.rs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plonk-napi/src/poly_comm.rs b/plonk-napi/src/poly_comm.rs index f6a3c13b199..58d4bdeff20 100644 --- a/plonk-napi/src/poly_comm.rs +++ b/plonk-napi/src/poly_comm.rs @@ -12,7 +12,7 @@ macro_rules! impl_poly_comm { $field_name:ident ) => { paste! { - #[napi] + #[napi(js_name = [<"Wasm" $field_name "PolyComm">])] #[derive(Clone, Debug, Serialize, Deserialize, Default)] pub struct [] { #[napi(skip)] @@ -37,7 +37,7 @@ macro_rules! impl_poly_comm { self.unshifted.clone() } - #[napi(setter)] + #[napi(setter, js_name = "set_unshifted")] pub fn set_unshifted(&mut self, x: NapiVector<$NapiG>) { self.unshifted = x; } @@ -47,7 +47,7 @@ macro_rules! impl_poly_comm { self.shifted.clone() } - #[napi(setter)] + #[napi(setter, js_name = "set_shifted")] pub fn set_shifted(&mut self, value: Option<$NapiG>) { self.shifted = value; } diff --git a/plonk-napi/src/wrappers/group.rs b/plonk-napi/src/wrappers/group.rs index ed082dd9223..cf192b5c0cc 100644 --- a/plonk-napi/src/wrappers/group.rs +++ b/plonk-napi/src/wrappers/group.rs @@ -9,7 +9,7 @@ use mina_curves::pasta::{ use napi_derive::napi; use serde::{Deserialize, Serialize}; -#[napi(object)] +#[napi(object, js_name = "WasmGPallas")] #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct NapiGPallas { pub x: NapiPastaFp, @@ -17,7 +17,7 @@ pub struct NapiGPallas { pub infinity: bool, } -#[napi(object)] +#[napi(object, js_name = "WasmGVesta")] #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct NapiGVesta { pub x: NapiPastaFq, @@ -105,7 +105,7 @@ impl From<&NapiGVesta> for AffineVesta { } } -#[napi] +#[napi(js_name = "caml_pallas_affine_one")] pub fn caml_pallas_affine_one() -> NapiGPallas { NapiGPallas { x: NapiPastaFp::from(GeneratorPallasX), @@ -114,7 +114,7 @@ pub fn caml_pallas_affine_one() -> NapiGPallas { } } -#[napi] +#[napi(js_name = "caml_vesta_affine_one")] pub fn caml_vesta_affine_one() -> NapiGVesta { NapiGVesta { x: NapiPastaFq::from(GeneratorVestaX),