Space Data Module SDK
space-data-module-sdk defines the canonical Space Data module architecture for
WebAssembly artifacts: an embedded FlatBuffer manifest, canonical ABI exports,
a stable capability vocabulary, single-file packaging, and the signing and
transport records used to move modules between hosts.
This repository is the source of truth for module-level concerns:
PluginManifest.fbs and manifest codecs
- embedded manifest exports inside
.wasm modules
- standards-aware compliance and capability validation
- module compilation and protection
- the REC+MBL single-file container
- deployment authorization plus SDS publication records (
REC, PNM, ENC)
- the first canonical module hostcall/import ABI surface
- the canonical runtime-host model for append-only standards rows, host-managed
runtime regions, and dynamic module installation/loading
- shared module-level testing/runtime harnesses, including the WasmEdge
process runner used by package-level validation suites
Shared Harness Ownership
This repo owns the generic module-side runtime harnesses used across the stack:
createModuleHarness(...) for process and WasmEdge-backed module invocation
resolveModuleHarnessLaunchPlan(...) for portable launch planning
buildWasmEdgeEmscriptenPthreadRunner(...) plus the shared native runner
source and runner-level pthread smoke test
Flow-specific standalone harnessing now lives in host runtime packages that
layer flow enqueue/drain behavior on top of the SDK runtime host. Package-
specific validation suites, including conjunction replay/V&V, are expected to
sit on top of these shared harnesses instead of defining their own runtime
process model.
Canonical Runtime Host
The SDK now owns the durable runtime identity model used by OrbPro, browser and
server SDN hosts, and the evolving WasmEdge harness:
- standards rows are addressed only by
($SCHEMA_FILE_ID, rowId)
rowId is append-only and never reused
- aligned-binary runtime state is addressed only by
(regionId, recordIndex)
- raw pointers remain internal execution details and are not durable APIs
The minimal host surface lives under src/runtime-host/ and covers three
responsibilities:
createFlatSqlRuntimeStore() for append-only row handles and row resolution
createFlatBufferStreamIngestor() for little-endian size-prefixed FlatBuffer
transport ingest into host-owned row storage without JSON transcoding
createModuleFlatBufferStreamPump() for feeding those same FlatBuffer stream
chunks into a resident stateful module instance without JSON envelopes
createRuntimeRegionStore() for host-allocated aligned-binary regions and
externally backed record-view descriptors
createModuleRegistry() for dynamic install/load/unload/invoke
createRuntimeHost() composes those stores into the canonical SDK host model.
OrbPro layers entity/view helpers on top of that host instead of inventing a
separate durable identity model.
The canonical FlatBuffer-to-FlatSQL streaming contract is documented in
docs/flatsql-streaming-standard.md.
Module Artifact Model
A compliant module built with this SDK is always a valid .wasm artifact with:
- an embedded
PluginManifest.fbs
- exported manifest accessors:
plugin_get_manifest_flatbuffer
plugin_get_manifest_flatbuffer_size
- canonical invoke exports when the artifact supports direct in-memory calls:
plugin_invoke_stream
plugin_alloc
plugin_free
- an exported
_start entry when the artifact supports WASI command mode
- optional
MBL bundle metadata carried in one appended SDS REC trailer for:
- manifest bytes
- resolved deployment plans and input bindings
- deployment authorization
- auxiliary FlatBuffer or raw payloads
- optional appended SDS FlatBuffer publication records in that same trailing
REC container carrying:
MBL single-file bundle metadata
PNM digital-signature/publication metadata
ENC encrypted-delivery metadata
Single-file bundling appends one SDS REC trailer to the end of the wasm
payload. That trailer carries an MBL record for the bundle contents and may
also carry PNM / ENC publication metadata when the artifact is signed or
encrypted.
The module contract stays the same whether the artifact is loaded directly,
wrapped in a deployment envelope, or shipped as one bundled .wasm file.
Canonical Invoke ABI
Modules can now declare one or both canonical invoke surfaces in
manifest.invokeSurfaces:
direct: in-memory invocation through plugin_invoke_stream
command: WASI command-mode invocation through _start
Both surfaces consume and produce the SDS PIV FlatBuffer envelope
(file_identifier "$PIV"). PIV.REQUEST and PIV.RESPONSE route SDS payload
frames by TAB.PORT_ID using a shared PAYLOAD_ARENA. TAB.WIRE_FORMAT
declares whether each frame body is a regular FlatBuffer or an aligned-binary
payload. Command mode reads one PIV request from stdin and writes one PIV
response to stdout. Direct mode takes the same request bytes from guest
memory and returns response bytes in guest memory. Direct-mode hosts must pass
request and response-length pointers allocated by the module's plugin_alloc;
the generated bridge validates those guest-memory ranges and returns a
canonical invalid-request-pointer response, or 0 for an invalid
response-length pointer, instead of dereferencing arbitrary addresses. When a
PIV request has an empty PAYLOAD_ARENA, the generated direct bridge treats
TAB.OFFSET as an absolute guest-memory pointer only if that range was
allocated by plugin_alloc; otherwise it fails closed with
invalid-request-pointer. Public JS decoders can materialize the same
empty-arena TAB offsets by passing { externalArena } to
decodePluginInvokeRequest or decodePluginInvokeResponse.
Public JS encoders can also emit empty-arena PIV descriptors by passing
externalArena to encodePluginInvokeRequest or
encodePluginInvokeResponse and supplying frame offset/size values into
that arena. Browser direct-mode harness invocation requires externalArena to
be a full view of the module's active SharedArrayBuffer-backed memory and
passes frame offset/size descriptors through without copying the selected
frame bytes into a separate allocation. The browser direct harness also authors
the PIV request envelope itself into plugin_alloc-owned module memory before calling
plugin_invoke_stream; it does not route external-arena direct calls through a
JS-owned invokeRaw request-byte frame. Command-mode invocation rejects
externalArena because stdin has no guest-memory address space.
SDS TAB is the canonical transport descriptor. It preserves port id, payload
offset/size, alignment, wire format, type identity, ownership, mutability, and
frame id. Older SDK-local invoke descriptors and fields are not part of the
wire ABI. For stream-pump compatibility, the SDK uses TAB.FRAME_ID as packed
stream bookkeeping: (sequence << 1) | endOfStream.
Source-built modules can set this on an emitted output frame with
plugin_set_output_stream_frame(outputIndex, sequence, endOfStream) or set the
raw frame id with plugin_set_output_frame_id(outputIndex, frameId).
Size-prefixed records
A size-prefixed FlatBuffer is not an unprefixed buffer with a length written in
front of it. FlatBuffers aligns each field relative to the start of the buffer.
A size-prefixed finish lays the record out so that the 4-byte prefix comes
before an aligned root:
- C++:
FinishSizePrefixed;
- JS:
finishSizePrefixed;
flatc --binary --size-prefixed.
Writing a length in front of an unprefixed buffer moves every field by 4
bytes. Eight-byte scalars and vectors, such as double and long, are then
misaligned. VerifySizePrefixedBuffer with alignment checks, which a module's
generated readers run, refuses the record.
- Build size-prefixed frames with the generated builder's size-prefixed finish,
or with
flatc --binary --size-prefixed from JSON.
- flatc-wasm 26.1.38 and later:
generateBinary(schema, json) with
sizePrefix: true, the default, runs flatc --binary --size-prefixed and
produces such a record. Pass sizePrefix: false for an unprefixed record.
Earlier versions write the length in front in JS; VerifySizePrefixedBuffer
refuses their record when it has an 8-byte field.
- Forward a module's size-prefixed output frames unchanged. Do not strip the
prefix or add one.
For simple single-input / single-output methods, command mode also supports a
raw shortcut:
wasmedge module.wasm --method echo < input.fb > output.fb
That shortcut is only valid when the method declares exactly one input port and
at most one output port.
Source-built modules can include space_data_module_invoke.h and use the
generated helper functions to read the active invocation inputs and emit SDS
outputs. The reference invoke examples live in
examples/invoke-echo:
manifest.direct.json
manifest.command.json
manifest.hybrid.json
module.c
Input and output ports can independently declare regular flatbuffer payloads
or aligned-binary layouts. Mixed contracts are valid. When a port advertises
an aligned-binary layout, it must also advertise a regular flatbuffer
fallback for the same schema in the same accepted type set. A module can accept
a regular OMM.fbs request and emit an aligned-binary StateVector.fbs
response, provided the output port also declares the regular StateVector.fbs
fallback and the aligned type ref carries the correct layout metadata.
Runtime Portability
The module format is language-neutral. A host can load modules from this SDK
anywhere it can:
- instantiate WebAssembly
- read FlatBuffers
- honor the module capability and host ABI contract
That architecture is intended to stay portable across the common WebAssembly
and FlatBuffer host environments:
- browser
- Node.js
- C#
- Go
- Java
- Kotlin
- Python
- Rust
- Swift
This repo currently includes:
- the JavaScript reference implementation for manifest, compliance, auth,
transport, bundle handling, and compilation
- deterministic REC+MBL conformance vectors under
examples/single-file-bundle/vectors
- reference Node and browser hosts plus the legacy sync
space_data_module_host bridge for
sync-safe guest hostcalls
The current host/runtime contract is two-tiered:
- raw guest
space_data_module_host imports stay sync-only
- generic async capabilities such as filesystem, network, IPFS, and protocol
adapters are exposed through
NodeHost, BrowserHost,
createRuntimeHost() capability registries, and the browser/module harness
callHost(...) APIs
Hosts can wire those async capabilities either through the built-in reference
implementations or through explicit capabilityAdapters keyed by capability
id (filesystem, network, ipfs, protocol_handle, protocol_dial). That
generic async capability boundary is the canonical SDK contract for awaited
host services; keep it aligned across Node, browser, and runtime-host entry
points.
Runtime Targets
Manifests can declare coarse runtime targets in manifest.runtimeTargets.
If a manifest declares runtimeTargets: ["wasi"], this SDK treats that as
"standalone WASI, no host wrapper required." In practice that currently means:
- the artifact must declare the
command invoke surface
- declared capabilities must stay within the pure WASI subset:
logging, clock, random, filesystem, pipe
- hosted protocols may only use
wasi-pipe transport
If a manifest declares runtimeTargets: ["wasmedge"], this SDK treats that as
the preferred server-side target when the guest needs network-oriented runtime
features such as sockets or TLS. Plain wasi remains the strict portability
baseline; wasmedge is the practical higher-capability target.
If a manifest declares runtimeTargets: ["browser", "wasmedge"], this SDK
treats that as the explicit "one binary for both" profile. That pair now
defaults to a shared single-thread artifact so the compiled wasm can be loaded
unchanged by the browser harness and the WasmEdge harness.
Composed flows derive their targets
A COMPOSED flow artifact (space-data-module flow compile) does not declare
its own runtimeTargets — it derives them, inside the universe a composed
artifact can reach at all (browser + wasmedge; the flow runtime template is
never a standalone wasi command, a node package, a desktop bundle or an
edge worker). Two things narrow that universe:
- Every part's declaration, tested with
runtimeTargetSatisfies — THE
SAME function every loader uses, so a declaration cannot mean one thing to
the compiler and another at the door. A flow runs only where all of its
parts run. A part that declares nothing constrains nothing. wasi is the
strict portability baseline rather than a fourth runtime, so a part
declaring it admits both legs — unless that part's own capabilities say
otherwise (pipe is in both the standalone-WASI subset and the
browser-incompatible set).
- The capability union. A capability in
BrowserIncompatibleCapabilityIds
(wallet_sign, tcp, storage_write, …) drops browser regardless of what
anything declared, because the composition provably cannot run there. This is
the proof-based half: it catches the commonest manifest shape, a plugin that
carries such a capability and simply omits runtimeTargets.
Outcomes:
- All parts isomorphic, no browser-incompatible capability → the flow keeps
["browser", "wasmedge"].
- One WasmEdge-only part, or one browser-incompatible capability → the flow is
["wasmedge"], its buildArtifacts[].target says wasmedge, and a
narrowed-runtime-targets warning names what cost it the browser. Losing a
runtime is never silent.
- No shared runtime →
empty-runtime-target-intersection, a hard error naming
the constraining plugins.
This is what makes a host-only capability usable from a flow at all: the
composed manifest is compliance-validated before the bake, and a
browser-incompatible capability next to a browser target is a hard
capability-runtime-conflict. Deriving the target set keeps that rule intact —
the conflict still fires whenever a browser target is genuinely claimed — while
letting the legitimate WasmEdge-only composition exist. wallet_sign gates
keyslot.unwrap, so before this the hardcoded pair meant no flow could unwrap a
host-held key at all.
Both legs refuse an artifact that is not theirs
A legitimate single-leg artifact now exists, so every loader that stands for a
runtime leg refuses one that declares itself out of scope — by name, quoting
the declaration, never a silent skip and never a trap five frames deep inside a
capability that leg cannot serve. The shared assert is
src/host/runtimeTargetGate.js:
| Loader |
Leg |
createBrowserModuleHarness |
browser |
createWorkerModuleHarness |
browser, checked before any worker is spawned |
createIsomorphicFlowRuntimeHost |
browser (it mounts children in the browser harness) |
createFlowRuntimeHost |
stated via runtimeTarget; defaults to browser in a real browser, ungated elsewhere |
loadModule({runtimeKind: "wasmedge"}) |
wasmedge |
Both declarations are consulted — the caller-supplied manifest and the
artifact's own embedded $PLG — and the embedded one wins on conflict,
because that is what the artifact's signature covers. The refusal throws a
RuntimeTargetError carrying declaredTargets, leg and declarationSource.