Add WASM bindings (offline DIGStore spend bundles) + npm package CI#33
Open
MichaelTaylor3d wants to merge 14 commits into
Open
Add WASM bindings (offline DIGStore spend bundles) + npm package CI#33MichaelTaylor3d wants to merge 14 commits into
MichaelTaylor3d wants to merge 14 commits into
Conversation
Add the brainstormed design spec and bite-sized implementation plan for offline WASM bindings mirroring the NAPI interface. Primary goal: build and sign DIGStore (DataStore) spend bundles client-side, published as @dignetwork/datalayer-driver-wasm via CI. Offline-only (no Peer/Tls networking); core crate gains a `native` feature so it compiles to wasm32. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Add `native` cargo feature (default-on) gating all networking code - Make `tokio`, `chia` meta-crate, and `chia-wallet-sdk` optional (native-only) - Add direct wasm-safe sub-crate deps: chia-bls, chia-consensus, chia-protocol, chia-puzzle-types, chia-traits, chia-sdk-driver, chia-sdk-signer, chia-sdk-types, chia-sdk-utils (all without tokio/mio in dep tree) - Gate all `pub async fn` taking `&Peer` in wallet.rs, dig_coin.rs, dig_collateral_coin.rs with #[cfg(feature = "native")] - Gate ClientError variant in WalletError and CoinRecord/coin_records_to_states - Replace all chia:: meta-crate paths with direct sub-crate paths - WASM build (--no-default-features) succeeds; native + napi builds unchanged Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…asm path) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The native DataStoreMetadata.size_proof is Option<String> (hex); the JS interface must expose it as Uint8Array like NAPI's Option<Buffer>, not a string. Convert 32 raw bytes <-> hex string on the boundary. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add build-wasm job (needs rust-checks): installs clang/lld, wasm-pack, builds NAPI for parity test, builds WASM nodejs+bundler targets, uploads pkg artifact. - Add publish-wasm-npm job (needs build-wasm): downloads pkg artifact and publishes to NPM on version-tag commits. - Fix wasm-crate clippy warnings: remove unused Bytes and Serialize imports in wasm/src/types.rs so cargo clippy --all-targets --all-features -D warnings passes. - Add [package.metadata.cargo-machete] ignored list for getrandom and js-sys in wasm/Cargo.toml so cargo machete passes. - Run cargo fmt --all to resolve formatting diffs in wasm/ and src/. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add wasm/README.md with install, scope note, worked mint example, and parity guarantee. Add a 3-sentence WASM pointer near the top of the root README.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…trandom + wasm-opt Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds WebAssembly bindings to
datalayer-driverthat mirror the offline subset of the existing NAPI interface, published as the npm package@dignetwork/datalayer-driver-wasmvia CI. Primary use case: build and sign DIGStore (DataStore) spend bundles client-side in the browser/bundler environments, producing byte-for-byte identical output to the NAPI bindings.What changed
nativefeature gating): new default-onnativecargo feature gates all networking (tokio,chia-wallet-sdknative-tls/peer-simulator, every&Peerasync fn). Thechiameta-crate (which transitively pullschia-client→tokio) was decomposed into wasm-safe sub-crates so the core crate compiles towasm32-unknown-unknown. Native + NAPI builds are unchanged.wasm/workspace member:wasm-bindgencrate exposing ~30 offline functions — key derivation, address codecs, coin selection, DIGStore spend builders (mintStore/oracleSpend/meltStore/updateStoreMetadata/updateStoreOwnership), signing, serialization, server coins. JS shape matches NAPI exactly:Uint8Arrayfor bytes,bigintfor amounts (BigInt-configured serializer — mojo amounts exceed 2^53), camelCase fields.wasm/tests/parity.mjs): loads both the NAPI.nodeand the WASM nodejs build and asserts byte-for-byte equality across the offline surface, including a fullmintStore→signCoinSpends→spendBundleToHexbundle, plusmeltStore/sendXch/signMessage/verifySignedMessage.wasm-pack --target bundler --release+ a patch script that sets the scoped package name and ships a hand-written, complete typed.d.ts.build-wasmjob (installs clang/lld for blst, builds, runs the parity test) andpublish-wasm-npmjob (version-tag-gated, mirrors the existingpublish-npmpattern). Existingrust-checks(clippy-D warnings,cargo machete,fmt) remain green.Scope notes
Peer/Tls/networking (WASM has no native sockets). Chain I/O stays the JS consumer's responsibility.DataStoreMetadata.sizeProofoutput is the symmetric 32-byte form (correct, round-trips) rather than replicating a NAPI output bug. Field type remainsUint8Array(matches NAPI).build:bundleruses--no-optbecause the bundledwasm-optrejects blst's bulk-memory ops; re-enable with awasm-optthat supports--enable-bulk-memoryfor size optimization.Design spec:
docs/superpowers/specs/2026-05-29-datalayer-driver-wasm-bindings-design.mdImplementation plan:
docs/superpowers/plans/2026-05-29-datalayer-driver-wasm-bindings.mdTest Plan
cargo build -p datalayer-driver --target wasm32-unknown-unknown --no-default-featuressucceedscargo build -p datalayer-driverand-p datalayer-driver-napisucceed (no native regression)cargo clippy --all-targets --all-features -- -D warnings,cargo machete,cargo fmt --all -- --checkpasswasm-pack build --target bundler --release+ patch produces@dignetwork/datalayer-driver-wasm@3.0.0build-wasmjob green on this PRpublish-wasm-npmpublishes on a version-tag commit🤖 Generated with Claude Code