# WASM Toolchain The Galaxy UI client compiles the Go module `ui/core` (canonical bytes, signature verification, keypair helpers) to WebAssembly via **TinyGo**. The compiled artefact `core.wasm` and its companion runtime shim `wasm_exec.js` ship under `ui/frontend/static/`. ## Why TinyGo Two viable Go-to-WASM toolchains exist: | Toolchain | Bundle size (Phase 5) | Notes | |---------------|------------------------------------|--------------------------------------------| | **TinyGo** | ~903 KB (under 1 MB acceptance bar) | LLVM-based, no full GC, fast cold-start | | Standard Go | ~2 MB (`GOOS=js GOARCH=wasm`) | Drops in without extra tooling | `ui/core` was written under the TinyGo invariants documented in `ui/core/README.md` (no `crypto/x509`, no `encoding/pem`, no goroutines or `sync` primitives in production files), so the TinyGo build is a drop-in compile. The standard-Go fallback stays available in case TinyGo lags behind a future Go release we depend on. To switch the build, swap the `tinygo build` invocation in `ui/Makefile` for `GOOS=js GOARCH=wasm go build -o frontend/static/core.wasm ./wasm`, and copy the matching shim from `$(go env GOROOT)/lib/wasm/wasm_exec.js`. ## Prerequisites - TinyGo ≥ 0.41 (`brew install tinygo`). - Go 1.26+ (TinyGo's host compiler). - `buf` 1.67+ on PATH for TS protobuf generation (`brew install bufbuild/buf/buf`). - pnpm + Node 22+ for the JS runtime. ## Build commands ```bash make -C ui wasm # produces frontend/static/{core.wasm,wasm_exec.js} make -C ui ts-protos # regenerates frontend/src/proto/* from gateway/proto ``` `make wasm` runs `tinygo build -target=wasm` and copies the matching TinyGo shim into the static asset directory. The shim **must** be the TinyGo one — the standard Go shim is ABI-incompatible. The Makefile resolves the shim path via `tinygo env TINYGOROOT`. ## Loading recipes ### Browser SvelteKit serves `static/` at the application root, so the WASM adapter at `ui/frontend/src/platform/core/wasm.ts` does the following on first call: 1. Inject `