Skip to content

Commit b6631ed

Browse files
committed
feat(wasm-privacy-coin): wasm java packaging
Ticket: CSHLD: 784
1 parent 0fe0da2 commit b6631ed

12 files changed

Lines changed: 1068 additions & 1 deletion

File tree

.github/scripts/detect-changes.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { execSync } from 'child_process';
33
import { appendFileSync } from 'fs';
44

5-
const ALL_PACKAGES = ['wasm-bip32', 'wasm-mps', 'wasm-utxo', 'wasm-solana', 'wasm-dot', 'wasm-ton'];
5+
const ALL_PACKAGES = ['wasm-bip32', 'wasm-mps', 'wasm-utxo', 'wasm-solana', 'wasm-dot', 'wasm-ton', 'wasm-privacy-coin'];
66

77
function setOutput(packages) {
88
const value = JSON.stringify(packages);

.github/workflows/build-and-test.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
packages/wasm-solana
6565
packages/wasm-dot
6666
packages/wasm-ton
67+
packages/wasm-privacy-coin
6768
cache-on-failure: true
6869

6970
- name: Setup Node
@@ -101,6 +102,16 @@ jobs:
101102
- name: Build packages
102103
run: npm --workspaces run build
103104

105+
- name: Setup JDK 17 (for wasm-privacy-coin JAR)
106+
uses: actions/setup-java@v4
107+
with:
108+
distribution: corretto
109+
java-version: '17'
110+
111+
- name: Build wasm-privacy-coin JAR
112+
working-directory: packages/wasm-privacy-coin
113+
run: make jar
114+
104115
- name: Check Source Code Formatting
105116
run: npm run check-fmt
106117

@@ -121,6 +132,8 @@ jobs:
121132
packages/wasm-dot/js/wasm/
122133
packages/wasm-ton/dist/
123134
packages/wasm-ton/js/wasm/
135+
packages/wasm-privacy-coin/dist/
136+
packages/wasm-privacy-coin/js/wasm/
124137
retention-days: 1
125138

126139
- name: Upload webui artifact
@@ -156,6 +169,9 @@ jobs:
156169
- package: wasm-ton
157170
needs-wasm-pack: false
158171
has-wasm-pack-tests: false
172+
- package: wasm-privacy-coin
173+
needs-wasm-pack: false
174+
has-wasm-pack-tests: false
159175
steps:
160176
- uses: actions/checkout@v4
161177
with:
@@ -298,6 +314,16 @@ jobs:
298314
packages/wasm-ton/dist/
299315
retention-days: 1
300316

317+
- name: Upload wasm-privacy-coin build artifacts
318+
if: inputs.upload-artifacts
319+
uses: actions/upload-artifact@v4
320+
with:
321+
name: wasm-privacy-coin-build
322+
path: |
323+
packages/wasm-privacy-coin/pkg/
324+
packages/wasm-privacy-coin/dist/
325+
retention-days: 1
326+
301327
# This job provides a stable "test / Test" status check for branch protection.
302328
# It runs after all other jobs complete successfully.
303329
gate:

.github/workflows/publish.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,65 @@ jobs:
8080

8181
- name: Release (multi-semantic-release)
8282
run: npx multi-semantic-release --ignore-private-packages
83+
84+
publish-maven:
85+
name: Publish Maven Artifact
86+
needs: test
87+
runs-on: ubuntu-latest
88+
environment: publish
89+
permissions:
90+
id-token: write
91+
contents: read
92+
93+
steps:
94+
- name: Checkout repository
95+
uses: actions/checkout@v4
96+
97+
- name: Setup JDK 17
98+
uses: actions/setup-java@v4
99+
with:
100+
distribution: corretto
101+
java-version: '17'
102+
103+
- name: Download wasm-privacy-coin build artifacts
104+
uses: actions/download-artifact@v4
105+
with:
106+
name: wasm-privacy-coin-build
107+
path: packages/wasm-privacy-coin/dist/
108+
109+
- name: Configure AWS credentials
110+
uses: aws-actions/configure-aws-credentials@v4
111+
with:
112+
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
113+
aws-region: us-west-2
114+
115+
- name: Get CodeArtifact token
116+
run: |
117+
TOKEN=$(aws codeartifact get-authorization-token \
118+
--domain private \
119+
--domain-owner 199765120567 \
120+
--query authorizationToken \
121+
--output text)
122+
echo "::add-mask::$TOKEN"
123+
echo "AWS_CODEARTIFACT_TOKEN=$TOKEN" >> "$GITHUB_ENV"
124+
125+
- name: Read version from pom.xml
126+
id: version
127+
run: |
128+
VERSION=$(grep '<version>' packages/wasm-privacy-coin/pom.xml | head -1 | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
129+
if [ -z "$VERSION" ]; then echo "Failed to parse version from pom.xml" && exit 1; fi
130+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
131+
132+
- name: Deploy JAR to CodeArtifact
133+
working-directory: packages/wasm-privacy-coin
134+
run: |
135+
mvn deploy:deploy-file \
136+
-s .settings.xml \
137+
-Pcodeartifact-deploy \
138+
-DgroupId=com.bitgo \
139+
-DartifactId=wasm-privacy-coin \
140+
-Dversion=${{ steps.version.outputs.version }} \
141+
-Dpackaging=jar \
142+
-Dfile=dist/wasm-privacy-coin.jar \
143+
-DrepositoryId=codeartifact-central \
144+
-Durl=https://private-199765120567.d.codeartifact.us-west-2.amazonaws.com/maven/bitgo-maven-libs-release/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd"
4+
xmlns="http://maven.apache.org/SETTINGS/1.1.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6+
<servers>
7+
<server>
8+
<id>codeartifact-central</id>
9+
<username>aws</username>
10+
<password>${env.AWS_CODEARTIFACT_TOKEN}</password>
11+
</server>
12+
</servers>
13+
</settings>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "wasm-privacy-coin"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib", "lib"]
8+
9+
[dependencies]
10+
# Core tree crates — pinned to exact versions for deterministic builds.
11+
# These must stay in sync with the zcash ecosystem (NU6-compatible).
12+
shardtree = "=0.6.2"
13+
incrementalmerkletree = "=0.8.2"
14+
orchard = { version = "=0.14.0", default-features = false }
15+
16+
# IPC protocol
17+
serde = { version = "1", features = ["derive"] }
18+
serde_json = "1"
19+
hex = "0.4"
20+
21+
[profile.release]
22+
opt-level = 3
23+
lto = true
24+
strip = true
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
WASM_TARGET = wasm32-unknown-unknown
2+
3+
.PHONY: build
4+
build:
5+
cargo build --release --target $(WASM_TARGET)
6+
mkdir -p dist
7+
cp target/$(WASM_TARGET)/release/wasm_privacy_coin.wasm dist/wasm-privacy-coin.wasm
8+
9+
.PHONY: jar
10+
jar: build
11+
mkdir -p jar-staging/wasm
12+
cp dist/wasm-privacy-coin.wasm jar-staging/wasm/privacy_coin.wasm
13+
cd jar-staging && jar cf ../dist/wasm-privacy-coin.jar wasm/
14+
rm -rf jar-staging
15+
16+
.PHONY: clean
17+
clean:
18+
cargo clean
19+
rm -rf dist jar-staging
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# wasm-privacy-coin
2+
3+
Orchard commitment tree (Zcash NU6) compiled to WebAssembly for use by the
4+
indexer-utxo Java service via the Chicory WASM runtime.
5+
6+
## Building
7+
8+
```bash
9+
rustup target add wasm32-unknown-unknown
10+
make build
11+
```
12+
13+
The compiled WASM binary will be at `dist/wasm-privacy-coin.wasm`.
14+
15+
## Architecture
16+
17+
This module exposes a C-style FFI interface (no wasm-bindgen, no WASI).
18+
The host allocates memory via `alloc()`, writes JSON input, calls a function,
19+
then reads JSON output via `last_result_ptr()`/`last_result_len()`.
20+
21+
## Exported Functions
22+
23+
| Function | Signature | Description |
24+
|---|---|---|
25+
| `alloc` | `(len: u32) -> *mut u8` | Allocate buffer in WASM memory |
26+
| `dealloc` | `(ptr: *mut u8, len: u32)` | Free allocated buffer |
27+
| `ping` | `() -> i32` | Health check |
28+
| `init_from_frontier` | `(ptr, len) -> i32` | Initialize from z_gettreestate frontier |
29+
| `load_state` | `(ptr, len) -> i32` | Load persisted JSON state |
30+
| `save` | `() -> i32` | Serialize tree to JSON |
31+
| `get_info` | `() -> i32` | Return tip height, leaf count, checkpoint count |
32+
| `append_commitments` | `(ptr, len) -> i32` | Append Orchard commitments, verify root |
33+
| `truncate_to_checkpoint` | `(ptr, len) -> i32` | Reorg handling |
34+
| `last_result_ptr` | `() -> *const u8` | Pointer to last result buffer |
35+
| `last_result_len` | `() -> u32` | Length of last result buffer |
36+
37+
## Pinned Dependencies
38+
39+
The `shardtree`, `incrementalmerkletree`, and `orchard` crate versions are
40+
pinned to exact versions to ensure deterministic builds and compatibility with
41+
the NU6 Zcash protocol upgrade.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "@bitgo/wasm-privacy-coin",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "make build",
7+
"lint": "cargo fmt --check && cargo clippy --all-targets --all-features -- -D warnings",
8+
"check-fmt": "cargo fmt -- --check",
9+
"test": "cargo test --workspace"
10+
},
11+
"files": [
12+
"dist/wasm-privacy-coin.wasm"
13+
]
14+
}

packages/wasm-privacy-coin/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.bitgo</groupId>
8+
<artifactId>wasm-privacy-coin</artifactId>
9+
<version>0.1.0</version>
10+
<packaging>jar</packaging>
11+
12+
<description>WASM module for Orchard merkle tree operations</description>
13+
14+
<profiles>
15+
<profile>
16+
<id>codeartifact-deploy</id>
17+
<distributionManagement>
18+
<repository>
19+
<id>codeartifact-central</id>
20+
<name>BitGo CodeArtifact Release Repository</name>
21+
<url>https://private-199765120567.d.codeartifact.us-west-2.amazonaws.com/maven/bitgo-maven-libs-release/</url>
22+
</repository>
23+
</distributionManagement>
24+
</profile>
25+
</profiles>
26+
</project>

0 commit comments

Comments
 (0)