@pgherveou2/truapi-host
v0.2.0-dev.0
Published
WASM-backed TrUAPI host runtime: embeds the Rust core, with web iframe and Web Worker entry points
Readme
@pgherveou2/truapi-host
WASM-backed TrUAPI host runtime. It embeds the truapi-server Rust core (compiled to WASM)
behind a Web Worker provider, plus per-environment integration entry points. It is the
counterpart to the native Android/iOS host shells.
Entry points
The package exposes tree-shakeable subpath exports — import only what your environment needs:
| Import | Provides |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------- |
| @pgherveou2/truapi-host | Shared runtime types plus generated typed host callback contracts. |
| @pgherveou2/truapi-host/web | Browser pairing host: createIframeHost (iframe MessageChannel handshake) and createWebWorkerPairingHostRuntime. |
| @pgherveou2/truapi-host/worker-runtime | Web Worker entrypoint (import with your bundler's ?worker suffix) so the WASM core runs off the page main thread. |
| @pgherveou2/truapi-host/wasm/web | The raw browser wasm-bindgen glue, if you need to instantiate the core yourself. |
Generated WASM artefacts
The ignored bundle under dist/wasm/web/ is built with host-owned chain access.
Hosts wire their JSON-RPC provider through chainConnect; if they omit it,
chain calls fail with the core's standard unavailable error. Release builds use
the workspace size-optimized Rust profile plus wasm-opt -Oz, validate that
debug/name/producers custom sections were stripped, and emit .wasm.gz and
.wasm.br sidecars for hosts that serve precompressed assets.
Build them after editing rust/crates/truapi-server and before packaging, publishing, or running
tests that load the raw WASM bundle (requires wasm-pack on PATH):
npm run build:wasm # or `make wasm` from the repo rootExample — browser (Web Worker)
import HostWorker from "@pgherveou2/truapi-host/worker-runtime?worker";
import { createWebWorkerPairingHostRuntime } from "@pgherveou2/truapi-host/web";
const runtime = await createWebWorkerPairingHostRuntime(
new HostWorker(),
callbacks,
{
hostConfig,
},
);
const firstProvider = await runtime.createProvider({ productId: "first.dot" });
const secondProvider = await runtime.createProvider({
productId: "second.dot",
});@pgherveou2/truapi-host/web also exports createIframeHost for the
protocol-iframe MessageChannel handshake. Host code creates one worker runtime
and then opens one provider per product id.
Publishing
This package is published by the root Release workflow through
paritytech/npm_publish_automation. Do not run npm publish locally. Cut a
release: PR with a changeset for @pgherveou2/truapi-host; the workflow builds
the generated host bindings, the browser WASM bundle, packs the tarball, and
publishes it when the @pgherveou2/truapi-host@<version> tag does not already
exist.
Architecture
JS host code
protocol handlers / typed callbacks
(types from @pgherveou2/truapi-host)
|
v
createWebWorkerPairingHostRuntime
shared worker runtime: pairing session, chain runtime, WASM instance
|
+-- createProvider({ productId }) -> product core / WireProvider
|
+-- createProvider({ productId }) -> product core / WireProvider