Skip to content
Open
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
7 changes: 6 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
rustflags = ["-C", "target-feature=+crt-static"]
# getrandom 0.3 (pulled in via chia-sdk-driver) refuses to build for
# wasm32-unknown-unknown unless a backend is named explicitly. The browser
# backend is selected by a cfg flag, not by a Cargo feature alone.
[target.wasm32-unknown-unknown]
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']
66 changes: 66 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,40 @@ jobs:
path: napi/${{ env.APP_NAME }}.*.node
if-no-files-found: error

build-wasm:
name: Build & test WASM bindings
needs: rust-checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Rust + wasm target
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Install clang/lld (blst needs a C/Clang toolchain for wasm32)
run: sudo apt-get update && sudo apt-get install -y clang lld
- name: Install wasm-pack
uses: jetli/wasm-pack-action@v0.4.0
with:
version: latest
- name: Build NAPI (needed by the parity test)
run: cd napi && npm install && npm run build
- name: Build WASM nodejs target and run parity test
run: cd wasm && npm install && npm run build:node && npm test
- name: Build WASM bundler artifact (published package)
run: cd wasm && npm run build:bundler
- name: Upload wasm pkg
uses: actions/upload-artifact@v4
with:
name: wasm-pkg
path: wasm/pkg
if-no-files-found: error

test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -315,6 +349,38 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-wasm-npm:
name: Publish WASM to NPM
runs-on: ubuntu-latest
needs:
- build-wasm
steps:
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Download wasm pkg
uses: actions/download-artifact@v4
with:
name: wasm-pkg
path: wasm/pkg
- name: Publish to NPM (on version-tag commit)
run: |
npm config set provenance true
if git log -1 --pretty=%B | grep -qE "^[0-9]+\.[0-9]+\.[0-9]+$"; then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
cd wasm/pkg && npm publish --access public
elif git log -1 --pretty=%B | grep -qE "^[0-9]+\.[0-9]+\.[0-9]+"; then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
cd wasm/pkg && npm publish --tag next --access public
else
echo "Not a release, skipping wasm npm publish"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-crates:
name: Publish to Crates.io
runs-on: ubuntu-latest
Expand Down
118 changes: 117 additions & 1 deletion Cargo.lock

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

39 changes: 31 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[workspace]
resolver = "2"
members = [".", "napi"]
members = [".", "napi", "wasm"]

[package]
edition = "2021"
name = "datalayer-driver"
version = "4.0.0"
license = "MIT"
version = "4.1.0"
edition = "2021"
authors = ["yakuhito <y@kuhi.to>", "William Wills <wwills2@protonmail.com>"]
homepage = "https://github.com/DIG-Network/DataLayer-Driver"
repository = "https://github.com/DIG-Network/DataLayer-Driver"
description = "Native Chia DataLayer Driver for storing and retrieving data in Chia blockchain"
license = "MIT"
repository = "https://github.com/DIG-Network/DataLayer-Driver"
readme = "README.md"
homepage = "https://github.com/DIG-Network/DataLayer-Driver"
keywords = ["chia", "blockchain", "datalayer", "storage", "web3"]
categories = ["cryptography::cryptocurrencies", "web-programming"]

Expand All @@ -25,8 +25,22 @@ chia-puzzles = "0.20.3"
chia-puzzle-types = "0.36.1"
thiserror = "1.0.61"
clvmr = "0.16.2"
tokio = "1.39.3"
chia-wallet-sdk = { version = "0.34.0", features = ["chip-0035", "native-tls", "peer-simulator", "action-layer"] }

# Native-only: the async peer client and its tokio runtime cannot build for
# wasm32. Both are optional and pulled in by the `native` feature.
tokio = { version = "1.39.3", optional = true }
chia-wallet-sdk = { version = "0.34.0", default-features = false, features = [
"chip-0035",
"action-layer",
], optional = true }

# The wasm-safe halves of the wallet SDK, depended on directly so that the
# wasm build never reaches the client/coinset/test crates re-exported by the
# `chia-wallet-sdk` facade.
chia-sdk-driver = { version = "0.34.0", features = ["chip-0035", "action-layer"] }
chia-sdk-signer = "0.34.0"
chia-sdk-types = { version = "0.34.0", features = ["chip-0035", "action-layer"] }
chia-sdk-utils = "0.34.0"
hex-literal = "0.4.1"
num-bigint = "0.4.6"
hex = "0.4.3"
Expand All @@ -38,6 +52,15 @@ indexmap = "2.11.4"
[dev-dependencies]
anyhow = "1.0.86"

[features]
default = ["native"]
native = [
"dep:tokio",
"dep:chia-wallet-sdk",
"chia-wallet-sdk/native-tls",
"chia-wallet-sdk/peer-simulator",
]

[target.aarch64-unknown-linux-gnu.dependencies]
openssl = { version = "0.10.64", features = ["vendored"] }
openssl-sys = { version = "0.9.102", features = ["vendored"] }
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Native Chia DataLayer Driver for storing and retrieving data in Chia blockchain.

This project provides both Rust library APIs and Node.js bindings for interacting with Chia's DataLayer.

A WebAssembly build is also available as [`@dignetwork/datalayer-driver-wasm`](./wasm/README.md) for browser and bundler environments (webpack, Vite, Next.js, esbuild). The WASM package mirrors the offline subset of the NAPI interface — no networking, no `Peer`/`Tls` — making it ideal for building and signing DIGStore spend bundles client-side without a full node. See [`wasm/README.md`](./wasm/README.md) for installation, usage, and a worked example.

## Installation

### As a Rust Crate
Expand Down
Loading
Loading