-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZK-643: General bindings crate #76
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few small comments, but no blockers; feel free to resolve them on your own
good job with taking care of two completely different compilation targets!
@@ -0,0 +1,60 @@ | |||
[package] | |||
name = "shielder_bindings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all other crates in this repo (and crate directories) use dash instead of underscore; if you don't mind - please rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately uniffi breaks if we use dash :D
crates/shielder_bindings/Cargo.toml
Outdated
edition.workspace = true | ||
authors = ["Cardinal", "Piotr Roslaniec <[email protected]>"] | ||
homepage.workspace = true | ||
license = "Apache-2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
licence can be inherited as well
rand = { workspace = true, features = ["small_rng"] } | ||
rand_chacha = { workspace = true } | ||
rand_core = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused deps
crates/shielder_bindings/Cargo.toml
Outdated
rand_chacha = { workspace = true } | ||
rand_core = { workspace = true } | ||
rayon = { workspace = true, optional = true } | ||
sha2 = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused dep
wasm-bindgen = { workspace = true, optional = true } | ||
|
||
[build-dependencies] | ||
rand = { workspace = true, features = ["small_rng"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused dep
"description": "WASM bindings for Shielder cryptography. Intended for use in web applications.", | ||
"license": "Apache-2.0", | ||
"author": "Cardinal", | ||
"contributors": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we expand this section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean to expand it with our names, it seems to me that "author: Cardinal" covers us sufficiently, and we can leave "contributors" just for any external contributors, otherwise we'd need to start putting our names everywhere.
use wasm_bindgen::prelude::wasm_bindgen; | ||
|
||
#[cfg_attr(feature = "build-wasm", wasm_bindgen)] | ||
pub fn private_key_to_f(hex: &str) -> Vec<u8> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you don't want to remove the source of this copy-paste (from shielder-wasm
) in this PR, pls add at least deprecation
#![cfg_attr(not(feature = "build-uniffi"), no_std)] | ||
|
||
#[cfg(feature = "build-uniffi")] | ||
uniffi::setup_scaffolding!(); | ||
|
||
#[cfg(feature = "multithreading-wasm")] | ||
pub use wasm_bindgen_rayon::init_thread_pool; | ||
|
||
extern crate alloc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should include building this crate with different feature flags in our CI (probably by just calling Makefile targets)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really want to do this later, when the critical part is written and working
else | ||
SED_CMD := sed -i | ||
endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you might add help
target as we do in other Makefiles
- Rust toolchain (see rust-toolchain.toml) | ||
- wasm-pack (for WebAssembly builds) | ||
- Rust target: aarch64-apple-ios-sim (for iOS simulator builds) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something more, because when I do make ios
I get error: failed to get iphonesimulator SDK path: No such file or directory (os error 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool:)
@@ -0,0 +1,19 @@ | |||
{ | |||
"name": "shielder-wasm", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover name?
{ | ||
"name": "shielder-wasm", | ||
"version": "0.0.1", | ||
"description": "WASM bindings for Shielder cryptography. Intended for use in web applications.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe "zkOS cryptography" here in the description?
"description": "WASM bindings for Shielder cryptography. Intended for use in web applications.", | ||
"license": "Apache-2.0", | ||
"author": "Cardinal", | ||
"contributors": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean to expand it with our names, it seems to me that "author: Cardinal" covers us sufficiently, and we can leave "contributors" just for any external contributors, otherwise we'd need to start putting our names everywhere.
crates/shielder_bindings/Cargo.toml
Outdated
[package] | ||
name = "shielder_bindings" | ||
version = "0.1.0" | ||
description = "WASM and mobile bindings for the shielder-circuits" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think language sounds better if you remove "the" from the description, because shielder-circuits is a crate name
@@ -0,0 +1,35 @@ | |||
use alloc::vec::Vec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you name this module differently? This is not just hashing. Perhaps "primitives" (seen this in Poseidon repo)? This term seems to cover both important constants and the hash function.
crates/shielder_bindings/src/hash.rs
Outdated
|
||
#[cfg_attr(feature = "build-wasm", wasm_bindgen)] | ||
#[cfg_attr(feature = "build-uniffi", uniffi::export)] | ||
pub fn arity() -> u32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage looks cool:) Nice that we have one interface for both binding libraries.
This pull request introduces a new crate,
shielder_bindings
, which provides WebAssembly (WASM) and mobile bindings (uniffi-rs) for the Shielder cryptographic operations.Key changes include:
New Crate Setup:
crates/shielder_bindings/Cargo.toml
]: Added new crateshielder_bindings
which is mostly a copy ofshielder-wasm
crate, but currently only with poseidon hash and private-key-to-scalar conversion.Build and Configuration:
crates/shielder_bindings/Makefile
]: Added separate makefile targets for building WASM packages and iOS bindings.crates/shielder_bindings/Cargo.toml
]: Added feature flags for binding generation options:build-wasm
- webassemblymultithreading-wasm
- optional multithreaded webassemblybuild-uniffi
- mobile bindings through uniffiDocumentation:
crates/shielder_bindings/README.md
]: Added README with an overview, build instructions for WebAssembly and iOS, and prerequisites.