wasm: add walletdk browser demo - #431
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces walletdk, a wallet-facing SDK that provides a stable API over an embedded darepod daemon, supporting both native and browser-based environments. Significant additions include a WebAssembly bridge, a web demo utilizing OPFS-backed SQLite, and gRPC-gateway support for HTTP/JSON communication. The review identified high-severity bugs in the WASM implementation where satoshi amounts could be truncated due to 32-bit integer limits, as well as a medium-severity XSS risk in the web demo's UI rendering. Additionally, the reviewer recommended using limited readers for gateway responses to mitigate potential memory exhaustion from oversized payloads.
| } | ||
|
|
||
| return client.Receive(ctx, walletdk.ReceiveRequest{ | ||
| AmountSat: int64(req.Get("amountSat").Int()), |
There was a problem hiding this comment.
In Go WASM builds, syscall/js.Value.Int() returns a 32-bit integer. Satoshi amounts can easily exceed the 32-bit range (approx 21.47 BTC), which will result in silent truncation for large values. Since JavaScript numbers are 64-bit floats, they can safely represent integers up to
| AmountSat: int64(req.Get("amountSat").Int()), | |
| AmountSat: int64(req.Get("amountSat").Float()), |
|
|
||
| return client.Send(ctx, walletdk.SendRequest{ | ||
| Invoice: stringValue(req.Get("invoice")), | ||
| MaxFeeSat: uint64(req.Get("maxFeeSat").Int()), |
There was a problem hiding this comment.
| body.replaceChildren(); | ||
| for (const swap of swaps || []) { | ||
| const row = document.createElement("tr"); | ||
| row.innerHTML = `<td>${swap.Direction}</td><td>${swap.State}</td><td>${swap.AmountSat}</td><td>${swap.PaymentHash}</td>`; |
There was a problem hiding this comment.
Using innerHTML to render swap data is a security risk as it can lead to Cross-Site Scripting (XSS) if the data contains malicious HTML. Use textContent for each cell to ensure safe rendering.
[swap.Direction, swap.State, swap.AmountSat, swap.PaymentHash].forEach(text => {
const cell = document.createElement("td");
cell.textContent = text;
row.appendChild(cell);
});| } | ||
| defer httpResp.Body.Close() | ||
|
|
||
| respBody, err := io.ReadAll(httpResp.Body) |
| defer httpResp.Body.Close() | ||
|
|
||
| respBody, err := io.ReadAll(httpResp.Body) | ||
| if err != nil { |
| defer httpResp.Body.Close() | ||
|
|
||
| respBody, err := io.ReadAll(httpResp.Body) | ||
| if err != nil { |
ec77b9f to
1dc3883
Compare
1dc3883 to
de06b74
Compare
itest: cut wall-clock on the suite's slowest tests by ~60%
de06b74 to
04d0d1c
Compare
Add wasm-safe SQLite open, migrate, and error handling through go-wasmsqlite. Browser builds use OPFS while native builds keep the existing database/sql path. Move lwwallet walletdb and seed storage behind native and wasm files so browser wallets can persist state in OPFS.
Expose the embedded walletdk runtime through a js/wasm command callable from browser code. The bridge wraps wallet, swap, and raw RPC methods without a separate gateway process. Add wasm Ark transport and inline OOR actor wiring for the single browser process.
Add a React workspace with core, wasm-web, and react packages. The UI starts the wasm runtime, creates or unlocks the OPFS wallet, and exposes receive, send, and activity flows matching the TUI demo. Include local build, serve, and Playwright smoke targets for reviewers.
Add a GitHub Pages workflow that builds the wasm wallet demo and publishes the static bundle with the isolation headers needed for OPFS and SharedArrayBuffer support.
74fe8aa to
fa132a6
Compare
|
Superseded by #803, which rebuilds the wasm wallet bindings against current The new PR drops the inline OOR actor entirely (the durable registry + per-session actors run under cc @jamaljsr |
Summary
Adds the walletdk browser demo implementation branch:
Validation
make wasm-wallet-demo-browser-testmake unit pkg=./db timeout=5mmake unit pkg=./sdk/swaps timeout=5mmake unit pkg=./sdk/walletdk timeout=5menv GOOS=js GOARCH=wasm go test -c -o /private/tmp/db.test.wasm ./dbenv GOOS=js GOARCH=wasm go test -c -o /private/tmp/swaps.test.wasm ./sdk/swapsenv GOOS=js GOARCH=wasm go test -c -tags swapruntime -o /private/tmp/walletdk.test.wasm ./sdk/walletdkenv GOOS=js GOARCH=wasm go build -tags swapruntime -o /private/tmp/walletdk.wasm ./cmd/walletdk-wasmmake commitmsg-lint range=90888222..HEADRemaining follow-up
This is a draft because Playwright MCP was not exposed in the local session, the Pages workflow has not run from
main, and full receive/send behavior still needs validation against a live SwapDK test instance.