Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 69 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ libflate = "2"
log = "0.4.20"
num-bigint = { version = "0.4.4", features = ["rand", "serde"] }
num-integer = "0.1.45"
napi = { version = "2.16.8", default-features = false, features = ["napi7"] }
napi-derive = "2.16.8"
napi = { version = "3.2.5", features = ["napi7"] }
napi-derive = { version = "3.2.5", features = ["type-def"] }
napi-build = "2.1.0"
ocaml = { version = "0.22.2" }
ocaml-gen = { version = "1.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion plonk-napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "plonk_napi"
crate-type = ["cdylib"] # to generate a dynamic library that is loadable by Node

[dependencies]
napi = { workspace = true, features = ["napi7"] }
napi.workspace = true
napi-derive.workspace = true

# arkworks
Expand Down
5 changes: 5 additions & 0 deletions plonk-napi/src/canary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use napi_derive::napi;


#[napi]
pub const CANARY_VALUE:u64 = 1337;
5 changes: 5 additions & 0 deletions plonk-napi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
mod poseidon;
mod canary;

pub use poseidon::{
caml_pasta_fp_poseidon_block_cipher,
caml_pasta_fq_poseidon_block_cipher,
};

pub use canary::{
CANARY_VALUE,
};
4 changes: 2 additions & 2 deletions plonk-napi/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use wasm_types::{FlatVector, FlatVectorElem};

// fp

#[napi]
#[napi(js_name = "caml_pasta_fp_poseidon_block_cipher")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmm actually is this the right format or should it be camel case in the napi annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this tells napi what name to use when exporting to js-land

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was asking because when I was doing the plonk-wasm overrides for the first time, I had to create this snakeToCamel function in node_backend.js so that the function names coming from rust (in snake case) were mapped to camel case. So that makes me wonder if we could replace that whole function by just using #[napi(js_name = "camlPastaFpPoseidonBlockCipher")] in there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we don't need the snakeToCamel function if we do this here

Napi chooses to "snakeCase" your rust symbols by default, if we explicitly tell napi what name to give it, it will end up with this one guaranteed

pub fn caml_pasta_fp_poseidon_block_cipher(state: Uint8Array) -> Result<Uint8Array> {
println!("from native rust");

Expand All @@ -32,7 +32,7 @@ pub fn caml_pasta_fp_poseidon_block_cipher(state: Uint8Array) -> Result<Uint8Arr

// fq

#[napi]
#[napi(js_name = "caml_pasta_fq_poseidon_block_cipher")]
pub fn caml_pasta_fq_poseidon_block_cipher(state: Uint8Array) -> Result<Uint8Array> {
println!("from native rust");

Expand Down
Loading