diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 013e17c0203..d595548df23 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: release-npm: name: Release NPM packages runs-on: ubuntu-24.04 - timeout-minutes: 15 + timeout-minutes: 30 if: github.event_name != 'workflow_dispatch' steps: - name: Check out repo diff --git a/.github/workflows/wasm-sdk-build.yml b/.github/workflows/wasm-sdk-build.yml new file mode 100644 index 00000000000..56525ba0560 --- /dev/null +++ b/.github/workflows/wasm-sdk-build.yml @@ -0,0 +1,115 @@ +name: Build WASM SDK + +on: + pull_request: + paths: + - 'packages/wasm-sdk/**' + - 'packages/rs-sdk/**' + - 'packages/rs-drive-proof-verifier/**' + - 'packages/rs-platform-value/**' + - 'packages/rs-dpp/**' + - 'packages/rs-drive/src/verify/**' + - 'packages/rs-context-provider/**' + push: + branches: + - main + - master + - 'v[0-9]+.[0-9]+-dev' + - 'v[0-9]+.[0-9]+-dev-sdk' + paths: + - 'packages/wasm-sdk/**' + - 'packages/rs-sdk/**' + - 'packages/rs-drive-proof-verifier/**' + - 'packages/rs-platform-value/**' + - 'packages/rs-dpp/**' + - 'packages/rs-drive/src/verify/**' + - 'packages/rs-context-provider/**' + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-C lto=off" + CARGO_PROFILE_RELEASE_LTO: false + +jobs: + build-wasm-sdk: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + + - name: Install protoc + run: | + curl -Lo /tmp/protoc.zip \ + "https://github.com/protocolbuffers/protobuf/releases/download/v27.3/protoc-27.3-linux-x86_64.zip" + unzip -o /tmp/protoc.zip -d ${HOME}/.local + echo "${HOME}/.local/bin" >> $GITHUB_PATH + export PATH="${PATH}:${HOME}/.local/bin" + + - name: Install clang + run: | + sudo apt update -qq + sudo apt install -qq --yes clang llvm + + - name: Cache cargo dependencies + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: ${{ runner.os }}-cargo-wasm-sdk-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-wasm-sdk- + + - name: Install wasm-pack + run: | + if ! command -v wasm-pack &> /dev/null; then + echo "Installing wasm-pack..." + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + else + echo "wasm-pack already installed" + fi + + - name: Install wasm-opt + run: | + if ! command -v wasm-opt &> /dev/null; then + echo "Installing wasm-opt..." + sudo apt-get update + sudo apt-get install -y binaryen + else + echo "wasm-opt already installed" + fi + + - name: Build WASM SDK + working-directory: packages/wasm-sdk + run: | + chmod +x build.sh + ./build.sh + + - name: Verify build output + working-directory: packages/wasm-sdk + run: | + echo "Checking build output..." + ls -lah pkg/ + # Verify required files exist + test -f pkg/wasm_sdk_bg.wasm + test -f pkg/optimized.wasm + test -f pkg/wasm_sdk.js + test -f pkg/wasm_sdk.d.ts + test -f pkg/package.json + echo "Build verification successful!" + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: wasm-sdk-build + path: packages/wasm-sdk/pkg/ + retention-days: 7 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 263d09a8712..06da0bb1826 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -458,7 +458,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash 1.1.0", + "rustc-hash", "shlex", "syn 2.0.100", "which", @@ -479,7 +479,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash 1.1.0", + "rustc-hash", "shlex", "syn 2.0.100", ] @@ -598,7 +598,7 @@ source = "git+https://github.com/dashpay/bls-signatures?tag=1.3.3#4e070243aed142 dependencies = [ "bls-dash-sys 1.2.5 (git+https://github.com/dashpay/bls-signatures?tag=1.3.3)", "hex", - "rand 0.8.5", + "rand", "serde", ] @@ -609,7 +609,7 @@ source = "git+https://github.com/dashpay/bls-signatures?rev=0bb5c5b03249c463debb dependencies = [ "bls-dash-sys 1.2.5 (git+https://github.com/dashpay/bls-signatures?rev=0bb5c5b03249c463debb5cef5f7e52ee66f3aaab)", "hex", - "rand 0.8.5", + "rand", "serde", ] @@ -625,9 +625,9 @@ dependencies = [ "hkdf", "merlin", "pairing", - "rand 0.8.5", - "rand_chacha 0.3.1", - "rand_core 0.6.4", + "rand", + "rand_chacha", + "rand_core", "serde", "serde_bare", "sha2", @@ -663,7 +663,7 @@ dependencies = [ "ff", "group", "pairing", - "rand_core 0.6.4", + "rand_core", "serde", "subtle", "zeroize", @@ -1158,7 +1158,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array 0.14.7", - "rand_core 0.6.4", + "rand_core", "serdect", "subtle", "zeroize", @@ -1600,7 +1600,7 @@ dependencies = [ "platform-version", "platform-versioning", "pretty_assertions", - "rand 0.8.5", + "rand", "regex", "rust_decimal", "rust_decimal_macros", @@ -1646,7 +1646,7 @@ dependencies = [ "once_cell", "parking_lot", "platform-version", - "rand 0.8.5", + "rand", "serde", "serde_json", "sqlparser", @@ -1690,7 +1690,7 @@ dependencies = [ "mockall", "platform-version", "prost", - "rand 0.8.5", + "rand", "regex", "reopen", "rocksdb", @@ -1770,7 +1770,7 @@ checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", - "rand_core 0.6.4", + "rand_core", "serde", "sha2", "subtle", @@ -1797,7 +1797,7 @@ dependencies = [ "group", "hkdf", "pkcs8", - "rand_core 0.6.4", + "rand_core", "sec1", "subtle", "tap", @@ -1950,7 +1950,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ "bitvec", - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -2189,11 +2189,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" dependencies = [ "cfg-if", - "js-sys", "libc", "r-efi", "wasi 0.14.2+wasi-0.2.4", - "wasm-bindgen", ] [[package]] @@ -2227,8 +2225,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand 0.8.5", - "rand_core 0.6.4", + "rand", + "rand_core", "rand_xorshift", "subtle", ] @@ -2311,7 +2309,7 @@ dependencies = [ "indexmap 2.7.0", "integer-encoding", "num_cpus", - "rand 0.8.5", + "rand", "thiserror 2.0.12", ] @@ -2650,7 +2648,6 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots", ] [[package]] @@ -3222,12 +3219,6 @@ dependencies = [ "hashbrown 0.15.2", ] -[[package]] -name = "lru-slab" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" - [[package]] name = "lz4-sys" version = "1.10.0" @@ -3283,7 +3274,7 @@ checksum = "58c38e2799fc0978b65dfff8023ec7843e2330bb462f19198840b34b6582397d" dependencies = [ "byteorder", "keccak", - "rand_core 0.6.4", + "rand_core", "zeroize", ] @@ -3533,7 +3524,7 @@ checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", - "rand 0.8.5", + "rand", "serde", ] @@ -3550,7 +3541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", - "rand 0.8.5", + "rand", "serde", ] @@ -3789,7 +3780,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" dependencies = [ "base64ct", - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -3859,7 +3850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" dependencies = [ "phf_shared", - "rand 0.8.5", + "rand", ] [[package]] @@ -3949,7 +3940,7 @@ dependencies = [ "indexmap 2.7.0", "platform-serialization", "platform-version", - "rand 0.8.5", + "rand", "serde", "serde_json", "thiserror 2.0.12", @@ -4204,61 +4195,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "quinn" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626214629cda6781b6dc1d316ba307189c85ba657213ce642d9c77670f8202c8" -dependencies = [ - "bytes", - "cfg_aliases", - "pin-project-lite", - "quinn-proto", - "quinn-udp", - "rustc-hash 2.1.1", - "rustls", - "socket2", - "thiserror 2.0.12", - "tokio", - "tracing", - "web-time", -] - -[[package]] -name = "quinn-proto" -version = "0.11.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49df843a9161c85bb8aae55f101bc0bac8bcafd637a620d9122fd7e0b2f7422e" -dependencies = [ - "bytes", - "getrandom 0.3.2", - "lru-slab", - "rand 0.9.1", - "ring", - "rustc-hash 2.1.1", - "rustls", - "rustls-pki-types", - "slab", - "thiserror 2.0.12", - "tinyvec", - "tracing", - "web-time", -] - -[[package]] -name = "quinn-udp" -version = "0.5.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcebb1209ee276352ef14ff8732e24cc2b02bbac986cd74a4c81bcb2f9881970" -dependencies = [ - "cfg_aliases", - "libc", - "once_cell", - "socket2", - "tracing", - "windows-sys 0.59.0", -] - [[package]] name = "quote" version = "1.0.40" @@ -4287,18 +4223,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - -[[package]] -name = "rand" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" -dependencies = [ - "rand_chacha 0.9.0", - "rand_core 0.9.3", + "rand_chacha", + "rand_core", ] [[package]] @@ -4308,17 +4234,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" -dependencies = [ - "ppv-lite86", - "rand_core 0.9.3", + "rand_core", ] [[package]] @@ -4330,22 +4246,13 @@ dependencies = [ "getrandom 0.2.15", ] -[[package]] -name = "rand_core" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" -dependencies = [ - "getrandom 0.3.2", -] - [[package]] name = "rand_xorshift" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -4476,10 +4383,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "quinn", - "rustls", "rustls-pemfile", - "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", @@ -4487,13 +4391,11 @@ dependencies = [ "system-configuration", "tokio", "tokio-native-tls", - "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", "windows-registry", ] @@ -4573,15 +4475,17 @@ dependencies = [ "gloo-timers", "hex", "http", + "http-body-util", "http-serde", "lru", - "rand 0.8.5", + "rand", "serde", "serde_json", "sha2", "thiserror 2.0.12", "tokio", "tonic-web-wasm-client", + "tower-service", "tracing", "wasm-bindgen-futures", ] @@ -4628,7 +4532,7 @@ dependencies = [ "borsh", "bytes", "num-traits", - "rand 0.8.5", + "rand", "rkyv", "serde", "serde_json", @@ -4656,12 +4560,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - [[package]] name = "rustc_version" version = "0.4.0" @@ -4740,9 +4638,6 @@ name = "rustls-pki-types" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c" -dependencies = [ - "web-time", -] [[package]] name = "rustls-webpki" @@ -4827,7 +4722,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b50c5943d326858130af85e049f2661ba3c78b26589b8ab98e65e80ae44a1252" dependencies = [ "bitcoin_hashes", - "rand 0.8.5", + "rand", "secp256k1-sys", "serde", ] @@ -5114,7 +5009,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -5232,7 +5127,7 @@ dependencies = [ "platform-serialization", "platform-serialization-derive", "platform-version", - "rand 0.8.5", + "rand", "rocksdb", "serde_json", "simple-signer", @@ -5881,7 +5776,7 @@ dependencies = [ "indexmap 1.9.3", "pin-project", "pin-project-lite", - "rand 0.8.5", + "rand", "slab", "tokio", "tokio-util", @@ -6154,7 +6049,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" dependencies = [ "getrandom 0.2.15", - "rand 0.8.5", + "rand", ] [[package]] @@ -6210,7 +6105,7 @@ dependencies = [ "generic-array 1.1.0", "hex", "num", - "rand_core 0.6.4", + "rand_core", "serde", "sha3", "subtle", @@ -6438,16 +6333,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-time" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "webpki-roots" version = "0.26.3" diff --git a/Dockerfile b/Dockerfile index 63ac9485eff..a1f5affb3d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -387,11 +387,14 @@ COPY --parents \ packages/rs-json-schema-compatibility-validator \ # TODO: We don't need those. Maybe dynamically remove them from workspace or move outside of monorepo? packages/rs-drive-proof-verifier \ + packages/rs-context-provider \ + packages/rs-sdk-trusted-context-provider \ packages/wasm-dpp \ packages/wasm-drive-verify \ packages/rs-dapi-client \ packages/rs-sdk \ packages/check-features \ + packages/dash-platform-balance-checker \ /platform/ RUN --mount=type=secret,id=AWS \ @@ -470,11 +473,14 @@ COPY --parents \ packages/rs-json-schema-compatibility-validator \ # TODO: We don't need those. Maybe dynamically remove them from workspace or move outside of monorepo? packages/rs-drive-proof-verifier \ + packages/rs-context-provider \ + packages/rs-sdk-trusted-context-provider \ packages/wasm-dpp \ packages/wasm-drive-verify \ packages/rs-dapi-client \ packages/rs-sdk \ packages/check-features \ + packages/dash-platform-balance-checker \ /platform/ RUN mkdir /artifacts diff --git a/packages/dapi-grpc/Cargo.toml b/packages/dapi-grpc/Cargo.toml index a3416230c47..ab0abb3676c 100644 --- a/packages/dapi-grpc/Cargo.toml +++ b/packages/dapi-grpc/Cargo.toml @@ -43,11 +43,6 @@ tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", vers prost = { version = "0.13" } futures-core = "0.3.30" -tonic = { version = "0.13.0", features = [ - "codegen", - "prost", - "tls-ring", -], default-features = false } serde = { version = "1.0.219", optional = true, features = ["derive"] } serde_bytes = { version = "0.11.12", optional = true } serde_json = { version = "1.0", optional = true } @@ -55,6 +50,10 @@ dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" } platform-version = { path = "../rs-platform-version" } [target.'cfg(target_arch = "wasm32")'.dependencies] +tonic = { version = "0.13.0", features = [ + "codegen", + "prost", +], default-features = false } getrandom = { version = "0.2", features = ["js"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/packages/rs-dapi-client/Cargo.toml b/packages/rs-dapi-client/Cargo.toml index e2911b5addf..c15d3eda589 100644 --- a/packages/rs-dapi-client/Cargo.toml +++ b/packages/rs-dapi-client/Cargo.toml @@ -31,6 +31,8 @@ gloo-timers = { version = "0.3.0", features = ["futures"] } tonic-web-wasm-client = { version = "0.7.0" } wasm-bindgen-futures = { version = "0.4.49" } getrandom = { version = "0.2", features = ["js"] } +tower-service = { version = "0.3" } +http-body-util = { version = "0.1" } [dependencies] backon = { version = "1.3", default-features = false } diff --git a/packages/rs-dapi-client/src/transport/wasm_channel.rs b/packages/rs-dapi-client/src/transport/wasm_channel.rs index 22e7fca5b0f..6b1220bd33c 100644 --- a/packages/rs-dapi-client/src/transport/wasm_channel.rs +++ b/packages/rs-dapi-client/src/transport/wasm_channel.rs @@ -43,21 +43,26 @@ impl WasmClient { } } -impl tonic::client::GrpcService for WasmClient { +impl tonic::client::GrpcService for WasmClient { type Future = BoxFuture<'static, Result, Self::Error>>; - type ResponseBody = tonic::body::BoxBody; + type ResponseBody = tonic::body::Body; type Error = Status; - fn call(&mut self, request: http::Request) -> Self::Future { + fn call(&mut self, request: http::Request) -> Self::Future { let mut client = self.client.clone(); - let fut = client.call(request).map(|res| match res { - Ok(resp) => { - let body = tonic::body::boxed(resp.into_body()); - Ok(Response::new(body)) + + let fut = async move { + match client.call(request).await { + Ok(resp) => { + let (parts, body) = resp.into_parts(); + let tonic_body = tonic::body::Body::new(body); + Ok(Response::from_parts(parts, tonic_body)) + } + Err(e) => Err(wasm_client_error_to_status(e)), } - Err(e) => Err(wasm_client_error_to_status(e)), - }); + }; + // For WASM, we need to use into_send to make the future Send into_send(fut) } diff --git a/packages/rs-sdk-trusted-context-provider/Cargo.toml b/packages/rs-sdk-trusted-context-provider/Cargo.toml index 35669b1619e..18e83d229a1 100644 --- a/packages/rs-sdk-trusted-context-provider/Cargo.toml +++ b/packages/rs-sdk-trusted-context-provider/Cargo.toml @@ -9,8 +9,7 @@ description = "Trusted HTTP-based context provider for Dash Platform SDK" [dependencies] dash-context-provider = { path = "../rs-context-provider" } dpp = { path = "../rs-dpp", default-features = false, features = ["dash-sdk-features"] } -tokio = { version = "1.40", features = ["macros", "rt-multi-thread", "time"] } -reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false } +reqwest = { version = "0.12", features = ["json"], default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "2.0" @@ -24,4 +23,5 @@ futures = "0.3" url = "2.5" [dev-dependencies] +tokio = { version = "1.40", features = ["macros", "rt-multi-thread"] } tokio-test = "0.4.4" \ No newline at end of file diff --git a/packages/rs-sdk-trusted-context-provider/src/provider.rs b/packages/rs-sdk-trusted-context-provider/src/provider.rs index 16c8edb0ca0..6f82686ed79 100644 --- a/packages/rs-sdk-trusted-context-provider/src/provider.rs +++ b/packages/rs-sdk-trusted-context-provider/src/provider.rs @@ -3,7 +3,6 @@ use crate::get_quorum_base_url; use crate::types::{PreviousQuorumsResponse, QuorumData, QuorumsResponse}; use arc_swap::ArcSwap; -use async_trait::async_trait; use dash_context_provider::{ContextProvider, ContextProviderError}; use dpp::data_contract::accessors::v0::DataContractV0Getters; use dpp::prelude::{CoreBlockHeight, DataContract, Identifier}; @@ -13,23 +12,17 @@ use dpp::dashcore::Network; use dpp::data_contract::TokenConfiguration; use dpp::version::PlatformVersion; -/// Get the LLMQ type for the network -fn get_llmq_type_for_network(network: Network) -> u32 { - match network { - Network::Dash => 4, // Mainnet uses LLMQ type 4 - Network::Testnet => 6, // Testnet uses LLMQ type 6 - Network::Devnet => 107, // Devnet uses LLMQ type 107 - _ => 6, // Default to testnet type - } -} use lru::LruCache; use reqwest::Client; use std::collections::HashMap; +#[cfg(not(target_arch = "wasm32"))] use std::net::ToSocketAddrs; use std::num::NonZeroUsize; use std::sync::{Arc, Mutex}; +#[cfg(not(target_arch = "wasm32"))] use std::time::Duration; use tracing::{debug, info}; +#[cfg(not(target_arch = "wasm32"))] use url::Url; /// A trusted HTTP-based context provider that fetches quorum information @@ -56,10 +49,14 @@ pub struct TrustedHttpContextProvider { /// Known contracts cache - contracts that are pre-loaded and can be served immediately known_contracts: HashMap>, + + /// Whether to refetch quorums if not found in cache + refetch_if_not_found: bool, } impl TrustedHttpContextProvider { /// Verify that a URL's domain resolves + #[cfg(not(target_arch = "wasm32"))] fn verify_domain_resolves(url: &str) -> Result<(), TrustedContextProviderError> { let parsed_url = Url::parse(url).map_err(|e| { TrustedContextProviderError::NetworkError(format!("Invalid URL: {}", e)) @@ -111,9 +108,14 @@ impl TrustedHttpContextProvider { base_url: String, cache_size: NonZeroUsize, ) -> Result { - // Verify the domain resolves before proceeding + // Verify the domain resolves before proceeding (skip on WASM) + #[cfg(not(target_arch = "wasm32"))] Self::verify_domain_resolves(&base_url)?; + #[cfg(target_arch = "wasm32")] + let client = Client::builder().build()?; + + #[cfg(not(target_arch = "wasm32"))] let client = Client::builder().timeout(Duration::from_secs(30)).build()?; Ok(Self { @@ -126,6 +128,7 @@ impl TrustedHttpContextProvider { last_previous_quorums: Arc::new(ArcSwap::new(Arc::new(None))), fallback_provider: None, known_contracts: HashMap::new(), + refetch_if_not_found: true, }) } @@ -144,13 +147,39 @@ impl TrustedHttpContextProvider { self } + /// Set whether to refetch quorums if not found in cache + pub fn with_refetch_if_not_found(mut self, refetch: bool) -> Self { + self.refetch_if_not_found = refetch; + self + } + + /// Update the quorum caches by fetching current and previous quorums + pub async fn update_quorum_caches(&self) -> Result<(), TrustedContextProviderError> { + // Fetch current quorums + let current = self.fetch_current_quorums().await?; + + // Fetch previous quorums + let previous = self.fetch_previous_quorums().await?; + + // The caches are already updated by the fetch methods + debug!( + "Successfully updated quorum caches with {} current and {} previous quorums", + current.data.len(), + previous.data.quorums.len() + ); + + Ok(()) + } + /// Fetch current quorums from the HTTP endpoint - async fn fetch_current_quorums(&self) -> Result { - let llmq_type = get_llmq_type_for_network(self.network); - let url = format!("{}/quorums?quorumType={}", self.base_url, llmq_type); + pub async fn fetch_current_quorums( + &self, + ) -> Result { + let url = format!("{}/quorums", self.base_url); debug!("Fetching current quorums from: {}", url); let response = self.client.get(&url).send().await?; + debug!("Received response with status: {}", response.status()); if !response.status().is_success() { return Err(TrustedContextProviderError::NetworkError(format!( @@ -160,7 +189,9 @@ impl TrustedHttpContextProvider { ))); } + debug!("Parsing JSON response for current quorums"); let quorums: QuorumsResponse = response.json().await?; + debug!("Successfully parsed {} quorums", quorums.data.len()); // Update cache self.last_current_quorums @@ -190,14 +221,14 @@ impl TrustedHttpContextProvider { } /// Fetch previous quorums from the HTTP endpoint - async fn fetch_previous_quorums( + pub async fn fetch_previous_quorums( &self, ) -> Result { - let llmq_type = get_llmq_type_for_network(self.network); - let url = format!("{}/previous?quorumType={}", self.base_url, llmq_type); + let url = format!("{}/previous", self.base_url); debug!("Fetching previous quorums from: {}", url); let response = self.client.get(&url).send().await?; + debug!("Received response with status: {}", response.status()); if !response.status().is_success() { return Err(TrustedContextProviderError::NetworkError(format!( @@ -207,7 +238,12 @@ impl TrustedHttpContextProvider { ))); } + debug!("Parsing JSON response for previous quorums"); let quorums: PreviousQuorumsResponse = response.json().await?; + debug!( + "Successfully parsed {} previous quorums", + quorums.data.quorums.len() + ); // Update cache self.last_previous_quorums @@ -242,14 +278,6 @@ impl TrustedHttpContextProvider { quorum_type: u32, quorum_hash: QuorumHash, ) -> Result { - let expected_type = get_llmq_type_for_network(self.network); - if quorum_type != expected_type { - debug!( - "Quorum type {} doesn't match network type {}", - quorum_type, expected_type - ); - } - // Check current cache first if let Ok(mut cache) = self.current_quorums_cache.lock() { if let Some(quorum) = cache.get(&quorum_hash) { @@ -266,10 +294,22 @@ impl TrustedHttpContextProvider { } } + // Check if we should refetch + if !self.refetch_if_not_found { + return Err(TrustedContextProviderError::QuorumNotFound { + quorum_type, + quorum_hash: hex::encode(quorum_hash), + }); + } + // Fetch fresh data - info!("Quorum not in cache, fetching fresh data"); + info!( + "Quorum not in cache, fetching fresh data for hash: {}", + hex::encode(quorum_hash) + ); // Try current quorums first + debug!("Attempting to fetch current quorums"); if let Ok(current) = self.fetch_current_quorums().await { for quorum in ¤t.data { let hash_bytes: Option<[u8; 32]> = hex::decode(&quorum.quorum_hash) @@ -282,9 +322,12 @@ impl TrustedHttpContextProvider { } } } + } else { + debug!("Failed to fetch current quorums"); } // Try previous quorums + debug!("Attempting to fetch previous quorums"); if let Ok(previous) = self.fetch_previous_quorums().await { for quorum in &previous.data.quorums { let hash_bytes: Option<[u8; 32]> = hex::decode(&quorum.quorum_hash) @@ -306,7 +349,6 @@ impl TrustedHttpContextProvider { } } -#[async_trait] impl ContextProvider for TrustedHttpContextProvider { fn get_quorum_public_key( &self, @@ -314,26 +356,113 @@ impl ContextProvider for TrustedHttpContextProvider { quorum_hash: QuorumHash, _core_chain_locked_height: CoreBlockHeight, ) -> Result<[u8; 48], ContextProviderError> { - // Use blocking to run async code in sync context - let quorum = futures::executor::block_on(self.find_quorum(quorum_type, quorum_hash)) - .map_err(|e| ContextProviderError::Generic(e.to_string()))?; - - // Parse the public key from the 'key' field - let pubkey_hex = quorum.key.trim_start_matches("0x"); - let pubkey_bytes = hex::decode(pubkey_hex).map_err(|e| { - ContextProviderError::Generic(format!("Invalid hex in public key: {}", e)) - })?; + debug!( + "get_quorum_public_key called for type {} hash {}", + quorum_type, + hex::encode(quorum_hash) + ); + + // Check current cache first + if let Ok(mut cache) = self.current_quorums_cache.lock() { + if let Some(quorum) = cache.get(&quorum_hash) { + debug!("Found quorum in current cache"); + + // Parse the public key from the 'key' field + let pubkey_hex = quorum.key.trim_start_matches("0x"); + let pubkey_bytes = hex::decode(pubkey_hex).map_err(|e| { + ContextProviderError::Generic(format!("Invalid hex in public key: {}", e)) + })?; + + if pubkey_bytes.len() != 48 { + return Err(ContextProviderError::Generic(format!( + "Invalid public key length: {} bytes, expected 48", + pubkey_bytes.len() + ))); + } + + return pubkey_bytes.try_into().map_err(|_| { + ContextProviderError::Generic( + "Failed to convert public key to array".to_string(), + ) + }); + } + } + + // Check previous cache + if let Ok(mut cache) = self.previous_quorums_cache.lock() { + if let Some(quorum) = cache.get(&quorum_hash) { + debug!("Found quorum in previous cache"); - if pubkey_bytes.len() != 48 { - return Err(ContextProviderError::Generic(format!( - "Invalid public key length: {} bytes, expected 48", - pubkey_bytes.len() + // Parse the public key from the 'key' field + let pubkey_hex = quorum.key.trim_start_matches("0x"); + let pubkey_bytes = hex::decode(pubkey_hex).map_err(|e| { + ContextProviderError::Generic(format!("Invalid hex in public key: {}", e)) + })?; + + if pubkey_bytes.len() != 48 { + return Err(ContextProviderError::Generic(format!( + "Invalid public key length: {} bytes, expected 48", + pubkey_bytes.len() + ))); + } + + return pubkey_bytes.try_into().map_err(|_| { + ContextProviderError::Generic( + "Failed to convert public key to array".to_string(), + ) + }); + } + } + + // If not in cache and refetch is disabled, return error + if !self.refetch_if_not_found { + return Err(ContextProviderError::InvalidQuorum(format!( + "Quorum not found in cache for hash: {}", + hex::encode(quorum_hash) ))); } - pubkey_bytes.try_into().map_err(|_| { - ContextProviderError::Generic("Failed to convert public key to array".to_string()) - }) + // For non-WASM targets, we can use block_on to fetch + #[cfg(not(target_arch = "wasm32"))] + { + // Use blocking to run async code in sync context + let quorum = + match futures::executor::block_on(self.find_quorum(quorum_type, quorum_hash)) { + Ok(q) => q, + Err(e) => { + debug!("Error finding quorum: {}", e); + return Err(ContextProviderError::Generic(format!( + "Failed to find quorum: {}", + e + ))); + } + }; + + // Parse the public key from the 'key' field + let pubkey_hex = quorum.key.trim_start_matches("0x"); + let pubkey_bytes = hex::decode(pubkey_hex).map_err(|e| { + ContextProviderError::Generic(format!("Invalid hex in public key: {}", e)) + })?; + + if pubkey_bytes.len() != 48 { + return Err(ContextProviderError::Generic(format!( + "Invalid public key length: {} bytes, expected 48", + pubkey_bytes.len() + ))); + } + + pubkey_bytes.try_into().map_err(|_| { + ContextProviderError::Generic("Failed to convert public key to array".to_string()) + }) + } + #[cfg(target_arch = "wasm32")] + { + // For WASM, we rely on pre-fetched cache + Err(ContextProviderError::Generic( + "Quorum not found in cache. In WASM, call update_quorum_caches() first." + .to_string(), + )) + } } fn get_data_contract( diff --git a/packages/rs-sdk/src/sdk.rs b/packages/rs-sdk/src/sdk.rs index 790db1f70a0..f3d0398d82a 100644 --- a/packages/rs-sdk/src/sdk.rs +++ b/packages/rs-sdk/src/sdk.rs @@ -7,7 +7,7 @@ use crate::mock::MockResponse; use crate::mock::{provider::GrpcContextProvider, MockDashPlatformSdk}; use crate::platform::transition::put_settings::PutSettings; use crate::platform::{Fetch, Identifier}; -use arc_swap::{ArcSwapAny, ArcSwapOption}; +use arc_swap::ArcSwapOption; use dapi_grpc::mock::Mockable; use dapi_grpc::platform::v0::{Proof, ResponseMetadata}; #[cfg(not(target_arch = "wasm32"))] @@ -1117,7 +1117,7 @@ impl SdkBuilder { dump_dir: self.dump_dir.clone(), proofs:self.proofs, internal_cache: Default::default(), - context_provider:ArcSwapAny::new( Some(Arc::new(context_provider))), + context_provider: ArcSwapOption::new(Some(Arc::new(context_provider))), cancel_token: self.cancel_token, metadata_last_seen_height: Arc::new(atomic::AtomicU64::new(0)), metadata_height_tolerance: self.metadata_height_tolerance, diff --git a/packages/rs-sdk/src/sync.rs b/packages/rs-sdk/src/sync.rs index b494115e45c..4bfe4ba2976 100644 --- a/packages/rs-sdk/src/sync.rs +++ b/packages/rs-sdk/src/sync.rs @@ -95,6 +95,7 @@ where } /// Worker function that runs the provided future and sends the result back to the caller using oneshot channel. +#[cfg(not(target_arch = "wasm32"))] async fn worker( fut: F, // response: oneshot::Sender, diff --git a/packages/scripts/build-wasm.sh b/packages/scripts/build-wasm.sh new file mode 100755 index 00000000000..46934de5e98 --- /dev/null +++ b/packages/scripts/build-wasm.sh @@ -0,0 +1,234 @@ +#!/usr/bin/env bash +# Unified WASM build script for Dash Platform WASM packages +set -euo pipefail + +# Function to display usage +usage() { + echo "Usage: $0 [OPTIONS]" + echo "Options:" + echo " -p, --package NAME Package name (required)" + echo " -t, --target TYPE wasm-pack target type (default: web)" + echo " -o, --opt-level LEVEL Optimization level: full, minimal, none (default: full)" + echo " -h, --help Display this help message" + echo "" + echo "Example:" + echo " $0 --package wasm-sdk" + echo " $0 --package wasm-drive-verify --opt-level minimal" +} + +# Default values +PACKAGE_NAME="" +TARGET_TYPE="web" +OPT_LEVEL="full" +USE_WASM_PACK=false + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + case $1 in + -p|--package) + if [[ $# -lt 2 ]]; then + echo "Error: Missing argument for $1" + usage + exit 1 + fi + PACKAGE_NAME="$2" + shift 2 + ;; + -t|--target) + if [[ $# -lt 2 ]]; then + echo "Error: Missing argument for $1" + usage + exit 1 + fi + TARGET_TYPE="$2" + shift 2 + ;; + -o|--opt-level) + if [[ $# -lt 2 ]]; then + echo "Error: Missing argument for $1" + usage + exit 1 + fi + OPT_LEVEL="$2" + shift 2 + ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "Error: Unknown option $1" + usage + exit 1 + ;; + esac +done + +# Validate required arguments +if [ -z "$PACKAGE_NAME" ]; then + echo "Error: Package name is required" + usage + exit 1 +fi + +# Determine build method based on package +case "$PACKAGE_NAME" in + "wasm-sdk") + USE_WASM_PACK=true + WASM_FILE="wasm_sdk_bg.wasm" + ;; + "wasm-drive-verify") + USE_WASM_PACK=false + WASM_FILE="wasm_drive_verify_bg.wasm" + ;; + *) + echo "Error: Unknown package '$PACKAGE_NAME'" + exit 1 + ;; +esac + +# Get script directory and package directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PACKAGE_DIR="$(dirname "$SCRIPT_DIR")/$PACKAGE_NAME" + +# Change to package directory +cd "$PACKAGE_DIR" + +echo "Building $PACKAGE_NAME..." + +# Create pkg directory if it doesn't exist +mkdir -p pkg + +if [ "$USE_WASM_PACK" = true ]; then + # Build using wasm-pack + echo "Building with wasm-pack..." + + # Disable LTO for wasm-pack builds to avoid conflicts + export CARGO_PROFILE_RELEASE_LTO=false + export RUSTFLAGS="-C lto=off" + + wasm-pack build --target "$TARGET_TYPE" --release --no-opt +else + # Build using cargo directly + echo "Building with cargo..." + + cargo build --target wasm32-unknown-unknown --release \ + --config 'profile.release.panic="abort"' \ + --config 'profile.release.strip=true' \ + --config 'profile.release.debug=false' \ + --config 'profile.release.incremental=false' \ + --config 'profile.release.lto=true' \ + --config 'profile.release.opt-level="z"' \ + --config 'profile.release.codegen-units=1' + + # Run wasm-snip if available + if command -v wasm-snip &> /dev/null; then + wasm-snip "../../target/wasm32-unknown-unknown/release/${PACKAGE_NAME//-/_}.wasm" \ + -o "../../target/wasm32-unknown-unknown/release/${PACKAGE_NAME//-/_}.wasm" \ + --snip-rust-fmt-code \ + --snip-rust-panicking-code + fi + + # Run wasm-bindgen + echo "Running wasm-bindgen..." + if ! command -v wasm-bindgen &> /dev/null; then + echo "Error: 'wasm-bindgen' not found. Install via 'cargo install wasm-bindgen-cli'." >&2 + exit 1 + fi + + wasm-bindgen \ + --typescript \ + --out-dir=pkg \ + --target="$TARGET_TYPE" \ + --omit-default-module-path \ + "../../target/wasm32-unknown-unknown/release/${PACKAGE_NAME//-/_}.wasm" +fi + +# Optimize the WASM file +if [ "$OPT_LEVEL" != "none" ] && command -v wasm-opt &> /dev/null; then + echo "Optimizing wasm using Binaryen (level: $OPT_LEVEL)..." + + WASM_PATH="pkg/$WASM_FILE" + + if [ "$OPT_LEVEL" = "full" ]; then + # Check wasm-opt version to determine available options + WASM_OPT_VERSION=$(wasm-opt --version 2>/dev/null || echo "") + + # Core optimization flags that should work with most versions + CORE_FLAGS=( + --strip-producers + -Oz + --enable-bulk-memory + --enable-nontrapping-float-to-int + --flatten + --rereloop + -Oz + --converge + --vacuum + --merge-blocks + --simplify-locals + --remove-unused-brs + --remove-unused-module-elements + --remove-unused-names + -Oz + -Oz + ) + + # Additional flags to test for compatibility + OPTIONAL_FLAGS=( + "--code-folding" + "--const-hoisting" + "--dce" + "-tnh" + "--gsi" + "--inlining-optimizing" + "--optimize-added-constants" + "--optimize-casts" + "--optimize-instructions" + "--optimize-stack-ir" + "--remove-unused-types" + "--post-emscripten" + "--generate-global-effects" + "--abstract-type-refining" + ) + + # Test which optional flags are supported + SUPPORTED_FLAGS=() + for flag in "${OPTIONAL_FLAGS[@]}"; do + if wasm-opt "$flag" "$WASM_PATH" -o /dev/null 2>/dev/null; then + SUPPORTED_FLAGS+=("$flag") + else + echo "Note: $flag not supported by this wasm-opt version, skipping..." + fi + done + + # Run optimization with core flags and any supported optional flags + wasm-opt \ + "${CORE_FLAGS[@]}" \ + "${SUPPORTED_FLAGS[@]}" \ + "$WASM_PATH" \ + -o \ + "$WASM_PATH" + + # Create optimized version for wasm-sdk + if [ "$PACKAGE_NAME" = "wasm-sdk" ]; then + cp "$WASM_PATH" "pkg/optimized.wasm" + fi + else + # Minimal optimization for development builds + wasm-opt \ + --strip-producers \ + -O2 \ + "$WASM_PATH" \ + -o \ + "$WASM_PATH" + fi +else + if [ "$OPT_LEVEL" != "none" ]; then + echo "wasm-opt command not found. Skipping wasm optimization." + fi +fi + +echo "Build complete!" +echo "Output files are in the pkg/ directory" +ls -lah pkg/ \ No newline at end of file diff --git a/packages/wasm-dpp/scripts/build-wasm.sh b/packages/wasm-dpp/scripts/build-wasm.sh index 4dd833c452f..3ac8bc1a39d 100755 --- a/packages/wasm-dpp/scripts/build-wasm.sh +++ b/packages/wasm-dpp/scripts/build-wasm.sh @@ -49,7 +49,15 @@ fi if command -v wasm-opt &> /dev/null; then echo "Optimizing wasm using Binaryen" - wasm-opt -tnh --flatten --rereloop -Oz --gufa -Oz --gufa -Oz "$OUTPUT_FILE" -o "$OUTPUT_FILE" + + # Check if we're in a release build (via CARGO_BUILD_PROFILE or GitHub event) + if [ "${CARGO_BUILD_PROFILE}" = "release" ] || [ "${GITHUB_EVENT_NAME:-}" = "release" ] || [ "${GITHUB_EVENT_NAME:-}" = "workflow_dispatch" ]; then + echo "Running full optimizations for release build (CARGO_BUILD_PROFILE=${CARGO_BUILD_PROFILE}, GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME:-not_set})" + wasm-opt --flatten --rereloop -Oz --gufa "$OUTPUT_FILE" -o "$OUTPUT_FILE" + else + echo "Running minimal optimizations for development/PR build (CARGO_BUILD_PROFILE=${CARGO_BUILD_PROFILE}, GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME:-not_set})" + wasm-opt -O2 "$OUTPUT_FILE" -o "$OUTPUT_FILE" + fi else echo "wasm-opt command not found. Skipping wasm optimization." fi diff --git a/packages/wasm-drive-verify/build.sh b/packages/wasm-drive-verify/build.sh index feefc3b44c2..9180d19e640 100755 --- a/packages/wasm-drive-verify/build.sh +++ b/packages/wasm-drive-verify/build.sh @@ -1,82 +1,21 @@ #!/usr/bin/env bash +# +# Build wasm-drive-verify using unified build script +# + set -euo pipefail -# Always run from this script's location +# Get script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR" - -echo "Building wasm-drive-verify..." - -# Build the Rust WASM target -echo "Building Rust WASM target..." -cargo build --target wasm32-unknown-unknown --release \ - --config 'profile.release.panic="abort"' \ - --config 'profile.release.strip=true' \ - --config 'profile.release.debug=false' \ - --config 'profile.release.incremental=false' \ - --config 'profile.release.lto=true' \ - --config 'profile.release.opt-level="z"' \ - --config 'profile.release.codegen-units=1' \ - -# Create pkg directory if it doesn't exist -mkdir -p pkg -if command -v wasm-snip &> /dev/null; then - wasm-snip ../../target/wasm32-unknown-unknown/release/wasm_drive_verify.wasm -o ../../target/wasm32-unknown-unknown/release/wasm_drive_verify.wasm --snip-rust-fmt-code --snip-rust-panicking-code -fi - -# Run wasm-bindgen -echo "Running wasm-bindgen..." -if ! command -v wasm-bindgen &> /dev/null; then - echo "Error: 'wasm-bindgen' not found. Install via 'cargo install wasm-bindgen-cli'." >&2 - exit 1 -fi -wasm-bindgen \ - --typescript \ - --out-dir=pkg \ - --target=web \ - --omit-default-module-path ../../target/wasm32-unknown-unknown/release/wasm_drive_verify.wasm +# Initialize CARGO_BUILD_PROFILE with default value if not set +CARGO_BUILD_PROFILE="${CARGO_BUILD_PROFILE:-dev}" -if command -v wasm-opt &> /dev/null; then - echo "Optimizing wasm using Binaryen" - wasm-opt \ - --code-folding \ - --const-hoisting \ - --abstract-type-refining \ - --dce \ - --strip-producers \ - -Oz \ - --generate-global-effects \ - --enable-bulk-memory \ - --enable-nontrapping-float-to-int \ - -tnh \ - --flatten \ - --rereloop \ - -Oz \ - --converge \ - --vacuum \ - --dce \ - --gsi \ - --inlining-optimizing \ - --merge-blocks \ - --simplify-locals \ - --optimize-added-constants \ - --optimize-casts \ - --optimize-instructions \ - --optimize-stack-ir \ - --remove-unused-brs \ - --remove-unused-module-elements \ - --remove-unused-names \ - --remove-unused-types \ - --post-emscripten \ - -Oz \ - -Oz \ - "pkg/wasm_drive_verify_bg.wasm" \ - -o \ - "pkg/wasm_drive_verify_bg.wasm" -else - echo "wasm-opt command not found. Skipping wasm optimization." +# Determine optimization level based on environment +OPT_LEVEL="minimal" +if [ "${CARGO_BUILD_PROFILE}" = "release" ] || [ "${GITHUB_EVENT_NAME:-}" = "release" ] || [ "${GITHUB_EVENT_NAME:-}" = "workflow_dispatch" ]; then + OPT_LEVEL="full" fi -echo "Build complete!" -echo "Output files are in the pkg/ directory" +# Call unified build script +exec "$SCRIPT_DIR/../scripts/build-wasm.sh" --package wasm-drive-verify --opt-level "$OPT_LEVEL" diff --git a/packages/wasm-sdk/Cargo.toml b/packages/wasm-sdk/Cargo.toml index 086b8d9502c..f111a2eee6d 100644 --- a/packages/wasm-sdk/Cargo.toml +++ b/packages/wasm-sdk/Cargo.toml @@ -1,11 +1,20 @@ +[workspace] +members = ["."] + [package] name = "wasm-sdk" edition = "2021" -# rust-version.workspace = true publish = false [lib] crate-type = ["cdylib"] +[features] +default = [] + +mocks = ["dash-sdk/mocks"] +system-data-contracts = ["dash-sdk/system-data-contracts"] +token_reward_explanations = ["dash-sdk/token_reward_explanations"] + [dependencies] dash-sdk = { path = "../rs-sdk", default-features = false } console_error_panic_hook = { version = "0.1.6" } @@ -20,27 +29,21 @@ web-sys = { version = "0.3.4", features = [ ] } wasm-bindgen = { version = "=0.2.100" } wasm-bindgen-futures = { version = "0.4.49" } -drive-proof-verifier = { path = "../rs-drive-proof-verifier" } # TODO: I think it's not needed (LKl) -# tonic = { version = "*", features = ["transport"], default-features = false } -# client = [ -# "tonic/channel", FAIL -# "tonic/transport", FAIL -# "tonic/tls", -# "tonic/tls-roots", -# "tonic/tls-webpki-roots", -# "platform", -# ] +drive-proof-verifier = { path = "../rs-drive-proof-verifier", default-features = false } # TODO: I think it's not needed (LKl) +tracing = { version = "0.1" } tracing-wasm = { version = "0.2.1" } wee_alloc = "0.4" platform-value = { path = "../rs-platform-value", features = ["json"] } serde-wasm-bindgen = { version = "0.6.5" } +getrandom = { version = "0.2", features = ["js"] } +rs-sdk-trusted-context-provider = { path = "../rs-sdk-trusted-context-provider" } +once_cell = "1.19" [profile.release] -lto = "fat" opt-level = "z" panic = "abort" debug = false #[package.metadata.wasm-pack.profile.release] #wasm-opt = ['-g', '-O'] # -g for profiling -# -Oz -Oz -g +# -Oz -Oz -g \ No newline at end of file diff --git a/packages/wasm-sdk/build.sh b/packages/wasm-sdk/build.sh index d9c1016741c..81af0bd508c 100755 --- a/packages/wasm-sdk/build.sh +++ b/packages/wasm-sdk/build.sh @@ -1,12 +1,20 @@ -#! /bin/bash +#!/usr/bin/env bash # -# Build WASM-SDK. +# Build WASM-SDK using unified build script # # EXPERIMENTAL: This script is experimental and may be removed in the future. # -set -ex -o pipefail +set -euo pipefail -wasm-pack build --target web --release --no-opt -wasm-opt -tnh --flatten --rereloop -Oz --gufa -Oz --gufa -Oz -o pkg/optimized.wasm pkg/wasm_sdk_bg.wasm -ls -lah pkg +# Get script directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Determine optimization level based on environment +OPT_LEVEL="full" +if [ "${CARGO_BUILD_PROFILE:-}" = "dev" ] || [ "${CI:-}" != "true" ]; then + OPT_LEVEL="minimal" +fi + +# Call unified build script +exec "$SCRIPT_DIR/../scripts/build-wasm.sh" --package wasm-sdk --opt-level "$OPT_LEVEL" diff --git a/packages/wasm-sdk/index.html b/packages/wasm-sdk/index.html index 457479785a2..f0b3c6908bc 100644 --- a/packages/wasm-sdk/index.html +++ b/packages/wasm-sdk/index.html @@ -5,11 +5,214 @@ @@ -17,65 +220,291 @@
Loading...
-
- - + +
+ + +
+
+

Results

+
+ + +
+
+
No data fetched yet. Use the actions on the left to fetch identity or data contract information.
+
-
- - -
-
+
Initializing WASM SDK...