Skip to content

Commit

Permalink
Merge pull request #17 from webb-tools/m
Browse files Browse the repository at this point in the history
make getrandom behind the wasm feature flag
  • Loading branch information
maurges authored Feb 15, 2024
2 parents 3de295d + e628fde commit c3754c6
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 34 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
cache-on-failure: "true"
- name: Run tests
run: cargo test --all-features
run: cargo test --all-features --workspace --exclude nostd-example
fmt:
runs-on: ubuntu-latest
steps:
Expand All @@ -59,7 +59,7 @@ jobs:
with:
cache-on-failure: "true"
- name: Run clippy
run: cargo clippy --all --lib --all-features --exclude generic-ec-tests -- --no-deps -D clippy::all -D clippy::unwrap_used -D clippy::expect_used
run: cargo clippy --all --lib --workspace --all-features --exclude generic-ec-tests --exclude nostd-example -- --no-deps -D clippy::all -D clippy::unwrap_used -D clippy::expect_used
clippy-nostd:
runs-on: ubuntu-latest
steps:
Expand All @@ -77,7 +77,7 @@ jobs:
with:
cache-on-failure: "true"
- name: Run clippy tests
run: cargo clippy --tests --all-features -- -D clippy::all
run: cargo clippy --workspace --tests --all-features --exclude nostd-example -- -D clippy::all
check-doc:
runs-on: ubuntu-latest
steps:
Expand All @@ -87,7 +87,7 @@ jobs:
with:
cache-on-failure: "true"
- name: Check docs
run: RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo +nightly doc --all-features --no-deps
run: RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo +nightly doc --workspace --all-features --no-deps --exclude nostd-example
build-wasm:
runs-on: ubuntu-latest
steps:
Expand All @@ -99,10 +99,23 @@ jobs:
run: rustup target add wasm32-unknown-unknown
- name: Build on wasm32-unknown-unknown
run:
cargo check -p generic-ec --target wasm32-unknown-unknown --features wasm,all-curves
cargo check -p generic-ec --target wasm32-unknown-unknown --features all-curves
- name: Install wasm-pack
uses: baptiste0928/cargo-install@v1
with:
crate: wasm-pack
- name: wasm-pack an example project
run: (cd wasm/wasm-example; wasm-pack build)

build-wasm-nostd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"
- name: Install wasm32-unknown-unknown toolchain
run: rustup target add wasm32-unknown-unknown
- name: Build on wasm32-unknown-unknown (no_std)
run:
cargo build -p nostd-example --target wasm32-unknown-unknown
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ members = [
"generic-ec-curves",
"generic-ec-zkp",
"wasm/wasm-example",
"wasm/nostd",
"tests",
]
15 changes: 7 additions & 8 deletions generic-ec-curves/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ repository = "https://github.com/dfns/generic-ec"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
generic-ec-core = "0.1"
generic-ec-core = { version = "0.1", path = "../generic-ec-core", default-features = false }

subtle = { version = "2.4", default-features = false }
rand_core = { version = "0.6", default-features = false }
zeroize = { version = "1", default-features = false }

crypto-bigint = { version = "0.5", optional = true }
elliptic-curve = { version = "0.13", features = ["sec1", "hash2curve"], optional = true }
k256 = { version = "0.13", optional = true, features = ["hash2curve"] }
p256 = { version = "0.13", optional = true, features = ["hash2curve"] }
sha2 = { version = "0.10", optional = true }
stark-curve = { version = "0.1", optional = true }
crypto-bigint = { version = "0.5", default-features = false, optional = true }
elliptic-curve = { version = "0.13", default-features = false, features = ["sec1", "hash2curve"], optional = true }
k256 = { version = "0.13", optional = true, default-features = false, features = ["hash2curve"] }
p256 = { version = "0.13", optional = true, default-features = false, features = ["hash2curve"] }
sha2 = { version = "0.10", default-features = false, optional = true }
stark-curve = { version = "0.1", default-features = false, optional = true }

group = { version = "0.13", default-features = false, optional = true }

Expand All @@ -33,7 +33,6 @@ optional = true

[features]
default = []

rust-crypto = ["elliptic-curve", "crypto-bigint"]
secp256k1 = ["rust-crypto", "k256", "sha2"]
secp256r1 = ["rust-crypto", "p256", "sha2"]
Expand Down
2 changes: 1 addition & 1 deletion generic-ec-curves/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl core::cmp::Ord for Point {
}

impl core::hash::Hash for Point {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.0.compress().as_bytes().hash(state)
}
}
Expand Down
1 change: 1 addition & 0 deletions generic-ec-curves/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! [`generic-ec` crate]: https://docs.rs/generic-ec
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]
#![no_std]

#[cfg(feature = "ed25519")]
pub mod ed25519;
Expand Down
12 changes: 6 additions & 6 deletions generic-ec-zkp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ keywords = ["elliptic-curves", "zk-proof"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
generic-ec = { version = "0.1", default-features = false }
generic-ec = { version = "0.1", path = "../generic-ec", default-features = false }
udigest = { version = "0.1", features = ["derive"], optional = true }

subtle = "2.4"
rand_core = "0.6"
subtle = { version = "2.4", default-features = false }
rand_core = { version = "0.6", default-features = false }

serde = { version = "1", features = ["derive"], optional = true }
serde = { version = "1", default-features = false, features = ["derive"], optional = true }

# We don't depend on this crates directly, but need to specify features to make it compile
generic-array = "0.14"
Expand All @@ -30,12 +30,12 @@ sha2 = "0.10"

generic-tests = "0.1"

generic-ec = { version = "0.1", default-features = false, features = ["all-curves"] }
generic-ec = { version = "0.1", path = "../generic-ec", default-features = false, features = ["all-curves"] }

[features]
default = ["std"]
std = ["alloc"]
alloc = ["udigest/alloc"]
alloc = ["udigest?/alloc", "serde?/alloc"]
serde = ["dep:serde", "generic-ec/serde", "generic-array/serde"]
udigest = ["dep:udigest", "generic-ec/udigest"]

Expand Down
11 changes: 3 additions & 8 deletions generic-ec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ keywords = ["elliptic-curves"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
generic-ec-core = "0.1"
generic-ec-curves = { version = "0.1", optional = true }
generic-ec-core = { version = "0.1", path = "../generic-ec-core" }
generic-ec-curves = { version = "0.1", path = "../generic-ec-curves", optional = true }
udigest = { version = "0.1", features = ["derive"], optional = true }

subtle = { version = "2.4", default-features = false }
Expand All @@ -27,9 +27,6 @@ hex = { version = "0.4", default-features = false, optional = true }

phantom-type = { version = "0.4", default-features = false }

# We don't depend on this crate directly, but we need to enable certain features when wasm is required
getrandom = "0.2"

[dev-dependencies]
rand = "0.8"
serde_json = "1"
Expand All @@ -47,9 +44,7 @@ curve-secp256k1 = ["curves", "generic-ec-curves/secp256k1"]
curve-secp256r1 = ["curves", "generic-ec-curves/secp256r1"]
curve-stark = ["curves", "generic-ec-curves/stark"]
curve-ed25519 = ["curves", "generic-ec-curves/ed25519"]
all-curves = ["curve-secp256k1", "curve-secp256r1", "curve-stark"]

wasm = ["getrandom/js"]
all-curves = ["curve-secp256k1", "curve-secp256r1", "curve-stark", "curve-ed25519"]

[package.metadata.docs.rs]
all-features = true
Expand Down
4 changes: 0 additions & 4 deletions generic-ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@
#[cfg(feature = "alloc")]
extern crate alloc;

// We do not use getrandom directly, we just need to enable certain features
// when `wasm` is required
use getrandom as _;

pub use generic_ec_core as core;

mod arithmetic;
Expand Down
1 change: 1 addition & 0 deletions generic-ec/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
//! # Ok(()) }
//! ```
#![cfg(feature = "serde")]
use core::{convert::TryInto, fmt};

use phantom_type::PhantomType;
Expand Down
10 changes: 10 additions & 0 deletions wasm/nostd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "nostd-example"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
generic-ec = { path = "../../generic-ec", default-features = false, features = ["udigest", "all-curves"] }
generic-ec-curves = { path = "../../generic-ec-curves", default-features = false }
generic-ec-zkp = { path = "../../generic-ec-zkp", default-features = false, features = ["udigest"] }
12 changes: 12 additions & 0 deletions wasm/nostd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![no_std]

use ::core::panic::PanicInfo;

pub use generic_ec::*;
pub use generic_ec_curves::*;
pub use generic_ec_zkp::*;

#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
loop {}
}
5 changes: 3 additions & 2 deletions wasm/wasm-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ publish = false
crate-type = ["cdylib", "rlib"]

[dependencies]
generic-ec = { path = "../../generic-ec", features = ["all-curves", "wasm"] }
rand_core = "0.6"
generic-ec = { path = "../../generic-ec", features = ["all-curves"] }
rand_core = { version = "0.6", features = ["getrandom"] }
wasm-bindgen = "0.2.84"
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
wasm-bindgen-test = "0.3.34"

0 comments on commit c3754c6

Please sign in to comment.