← Back to Official Package Registry
Tier 5: Cloud-Native, Noise, IaC & Wasm • Multi-Tenant Wasm 3.0 Plugin SDKv1.0.0 • 31 KB • Ed25519 Verified

wasm_plugin_sdk@1.0.0

Extism-style host-guest plugin manifest & VKPW RPC envelope with capability allowlists, deterministic fuel quotas, and audit logs.

use [wasm_plugin_sdk]
veko pkg add wasm_plugin_sdk@1.0.0
Run in Browser PlaygroundDownload 1.0.0.vkpRaw demo.vk

wasm_plugin_sdk

Extism-style multi-tenant WebAssembly 3.0 (vvm) plugin host, Ed25519 code-signing verifier, capability allowlist dispatcher, and VKPW Host-Guest RPC envelope SDK for Veko (wasm_plugin_sdk).

Overview

wasm_plugin_sdk enables Veko applications to compile, verify, and execute untrusted tenant .vk / .wasm plugins inside Veko's zero-trust Wasm 3.0 runtime (vvm) with deterministic resource quotas and audit logging:

  • PluginManifest & Ed25519 Verification: Declares per-plugin allowed_hosts (supporting exact domains and *.domain wildcards), confined allowed_paths, max_fuel instruction quota, max_mem_pages linear memory cap, static config map, and optional Ed25519 public key verification (crypto/x25519).
  • VKPW Binary + JSON RPC Envelope: Length-prefixed, IEEE CRC-32-protected binary wire framing (VKPW magic + version 1 + frame kind + uint32 BE length + JSON payload + uint32 BE CRC-32) for .call, .response, .error, and .host_call frames, plus guest-side helpers (guest-read-call, guest-write-response).
  • Host-Function Policy & Audit Trail: register-host-fn and dispatch-host-call enforce host and path allowlists before executing host callbacks and record sequential AuditEntry logs for every permitted, denied, or trapped operation.
  • Wasm 3.0 Compilation & Fuel-Metered Sandbox: compile-vk-plugin compiles .vk plugin source directly into Wasm 3.0 .wasm modules, while invoke-plugin executes them under --wasm --allow-fs=<sandbox_dir> --fuel=<max_fuel> --mem-pages=<max_mem_pages>, deterministically terminating infinite loops or memory violations.

Installation

powershell
veko pkg add wasm_plugin_sdk@1.0.0

Import in .vk source files:

rebol
use [sdk = wasm_plugin_sdk]

Architecture & VKPW Envelope Layout

Byte OffsetFieldWidthDescription
0..4Magic4 bytesASCII 'VKPW'
4Versionuint8Protocol version (1)
5Kinduint81 = Call, 2 = Response, 3 = Error, 4 = HostCall
6..10Body Lengthuint32 BEByte length N of UTF-8 JSON body
10..(10+N)JSON BodyN bytesMarshaled input, config, output, or error
(10+N)..(14+N)CRC-32uint32 BEIEEE 802.3 CRC-32 over bytes 0..(10+N)

During invoke-plugin, the host creates an ephemeral per-call sandbox directory (inv_<seq>), writes in.vkpw, mounts only that directory into vvm via --allow-fs=<inv_dir>, enforces --fuel and --mem-pages, reads out.vkpw, and removes the ephemeral directory via defer.

Complete API Reference

SymbolSignatureDescription
PluginManifeststructTenant plugin identity, host/path allowlists, fuel/memory caps, config, and Ed25519 signer
sign-plugin-bytesfn [seed32 bytes, wasm_bytes bytes] strSigns .wasm bytes with a 32-byte Ed25519 seed (hex output)
verify-plugin-bytesfn [pubkey_hex str, wasm_bytes bytes, sig_hex str] boolVerifies Ed25519 signature over .wasm bytes
valid-wasm-magic?fn [wasm_bytes bytes] boolChecks \0asm (0x00 0x61 0x73 0x6d) binary header
encode-rpc-callfn [fn_name str, input any, config map] bytesPacks a VKPW Host->Guest call envelope
encode-rpc-responsefn [output any] bytesPacks a VKPW Guest->Host response envelope
encode-rpc-errorfn [error_code i64, error_msg str] bytesPacks a VKPW Guest->Host error envelope
encode-host-call-framefn [fn_name str, args map /host h str = '' /path p str = ''] bytesPacks a VKPW host-call envelope
decode-rpc-framefn [wire bytes] RpcFrameVerifies CRC-32 and decodes a VKPW envelope
guest-read-call / guest-write-responseGuest helpersReads in.vkpw / writes out.vkpw inside Wasm 3.0 guests
new-plugin-hostfn [/work-dir dir str = ...] PluginHostInitializes a multi-tenant plugin host
register-host-fnfn [mut host PluginHost, name str, handler any /cap c str = '' /check-host ch bool = false /check-path cp bool = false] enumRegisters a capability-guarded host function
dispatch-host-callfn [mut host PluginHost, plugin_id str, fn_name str, args map /target-host th str = '' /target-path tp str = ''] anyEnforces allowlists, runs callback, and logs AuditEntry
compile-vk-pluginfn [vk_source str, out_wasm_path str /veko-bin vbin str = ''] bytesCompiles .vk source to Wasm 3.0 .wasm bytes
register-pluginfn [mut host PluginHost, manifest PluginManifest, wasm_path str /signature sig_hex str = ''] enumVerifies and registers a .wasm plugin
invoke-pluginfn [mut host PluginHost, plugin_id str, fn_name str, input any /veko-bin vbin str = ''] InvocationResultExecutes plugin in Wasm 3.0 with fuel & memory quotas
host-audit-logfn [host PluginHost] block[AuditEntry]Returns sequential security & execution audit entries

Idiomatic Veko Example

rebol
use [sdk = wasm_plugin_sdk]

mut host = sdk/new-plugin-host
wasm_b = sdk/compile-vk-plugin 'use [sdk = wasm_plugin_sdk]\ncall = sdk/guest-read-call\n_ = sdk/guest-write-response { doubled = ((as-i64 call.input.n) * 2) }' 'dist/doubler.wasm'

_ = sdk/register-plugin mut host (sdk/PluginManifest {
    plugin_id     = 'doubler'
    max_fuel      = 250000
    max_mem_pages = 32
}) 'dist/doubler.wasm'

res = sdk/invoke-plugin mut host 'doubler' 'run' { n = 21 }
println (map/get res.output 'doubled') // 42
packages/wasm_plugin_sdk/examples/demo.vkSelf-contained runnable example & assertion suite
Raw .vk
// packages/wasm_plugin_sdk/examples/demo.vk
// Self-contained verification suite & runnable example for `wasm_plugin_sdk`.

use [
	sdk = wasm_plugin_sdk
	fs
	hex = codec/hex
	x25 = crypto/x25519
]

assert-true = fn [cond bool, label str] enum [
	if not cond [
		println (str/join ['[FAIL] ' label] '')
		os/exit 1
	]
	println (str/join ['[PASS] ' label] '')
	.ok
]

run-demo = fn [] enum [
	tmp_dir = 'packages/wasm_plugin_sdk/.demo_tmp'
	_ = fs/mkdir-all tmp_dir
	defer [ _ = fs/remove-all tmp_dir ]

	// --- 1. `VKPW` Binary + JSON Host-Guest RPC Envelope Roundtrip & CRC-32 Integrity ---
	call_wire = sdk/encode-rpc-call 'calc-discount' { subtotal_cents = 25000, tier = 'gold' } { max_pct = 20 }
	dec_call = sdk/decode-rpc-frame call_wire

	mut bad_wire = bytes/with-cap (len call_wire)
	_ = bytes/push-all mut bad_wire call_wire
	_ = bytes/set mut bad_wire 12 (bad_wire[12] ^ 0xff)
	crc_rejected = err? (sdk/decode-rpc-frame/or bad_wire [e -> e])

	rpc_ok = dec_call.kind == (sdk/FRAME-CALL) and dec_call.fn_name == 'calc-discount' and (map/get dec_call.input 'subtotal_cents') == 25000 and crc_rejected
	_ = assert-true rpc_ok 'VKPW binary+JSON RPC envelope roundtrip and CRC-32 tamper rejection'

	// --- 2. Compile Real Tenant Pricing-Rule `.vk` Guest Plugin -> Wasm 3.0 + Ed25519 Sign ---
	// Notice the guest speaks the exact VKPW binary protocol over its confined sandbox files!
	pricing_guest_src = str/join [
		'use [bits, buf]\n'
		'args = os/args\n'
		'wire = os/read-bytes args[0]\n'
		'blen = bytes/get-u32-be wire 6\n'
		'req = json/decode (bytes/to-str wire[10..(10 + blen)])\n'
		'inp = map/get req \'input\'\n'
		'cfg = map/get req \'config\'\n'
		'subtotal = as-i64 (map/get inp \'subtotal_cents\')\n'
		'tier = str/append \'\' (map/get inp \'tier\')\n'
		'rate = if tier == \'enterprise\' [ as-i64 (map/get cfg \'enterprise_pct\') ] else [ 5 ]\n'
		'disc = (subtotal * rate) / 100\n'
		'resp_json = json/encode { output = { discount_cents = disc, final_cents = (subtotal - disc), applied_pct = rate } }\n'
		'jb = bytes/from-str resp_json\n'
		'mut w = buf/writer-new ((len jb) + 14)\n'
		'_ = buf/write-str mut w \'VKPW\'\n'
		'_ = buf/write-u8 mut w 1\n'
		'_ = buf/write-u8 mut w 2\n'
		'_ = buf/write-u32-be mut w (len jb)\n'
		'_ = buf/write-bytes mut w jb\n'
		'wo = buf/writer-bytes w\n'
		'crc = bits/crc32 wo\n'
		'mut out = buf/writer-new ((len wo) + 4)\n'
		'_ = buf/write-bytes mut out wo\n'
		'_ = buf/write-u32-be mut out crc\n'
		'_ = os/write-file args[1] (buf/writer-bytes out)\n'
	] ''

	pricing_wasm_path = str/join [tmp_dir '/tenant_pricing.wasm'] ''
	wasm_bytes = sdk/compile-vk-plugin pricing_guest_src pricing_wasm_path

	signer_seed = bytes/from-str 'veko-plugin-ed25519-seed-32bytes'
	signer_pub_hex = hex/encode (x25/ed25519-pubkey signer_seed)
	plugin_sig_hex = sdk/sign-plugin-bytes signer_seed wasm_bytes

	mut host = sdk/new-plugin-host/work-dir (str/join [tmp_dir '/work'] '')

	manifest = sdk/PluginManifest {
		plugin_id      = 'tenant-acme-pricing'
		version        = '1.0.0'
		allowed_hosts  = ['fx.acme.internal' '*.pricing.veko.dev']
		allowed_paths  = ['/catalog/']
		max_fuel       = 2000000
		max_mem_pages  = 64
		config         = { enterprise_pct = 15 }
		ed25519_signer = signer_pub_hex
	}

	// Verify forged signature is rejected before registering with authentic signature
	bad_reg = sdk/register-plugin/signature/or mut host manifest pricing_wasm_path (str/append 'ff' plugin_sig_hex[2..128]) [e -> e]
	ok_reg = sdk/register-plugin/signature mut host manifest pricing_wasm_path plugin_sig_hex
	_ = assert-true ((sdk/valid-wasm-magic? wasm_bytes) and (err? bad_reg) and ok_reg == .ok) 'Real .vk -> Wasm 3.0 compilation and Ed25519 code-signing verification'

	// --- 3. Host-Call Allowlist Enforcement (Permit Allowed Host, Block Unauthorized Host & Traversal) ---
	_ = sdk/register-host-fn/cap/check-host mut host 'http_fetch_rate' (fn [a map] any [
		{ rate = 1.08, source = (map/get a 'host') }
	]) 'net' true

	_ = sdk/register-host-fn/cap/check-path mut host 'kv_read_catalog' (fn [a map] any [
		{ sku = 'VK-ENT', path = (map/get a 'path') }
	]) 'fs' true

	allowed_hc = sdk/dispatch-host-call/target-host mut host 'tenant-acme-pricing' 'http_fetch_rate' { host = 'eu.pricing.veko.dev' } 'eu.pricing.veko.dev'
	blocked_hc = sdk/dispatch-host-call/target-host/or mut host 'tenant-acme-pricing' 'http_fetch_rate' { host = 'evil.exfil.io' } 'evil.exfil.io' [e -> e]
	blocked_path = sdk/dispatch-host-call/target-path/or mut host 'tenant-acme-pricing' 'kv_read_catalog' { path = '/etc/passwd' } '/etc/passwd' [e -> e]

	hc_ok = (map/get allowed_hc 'rate') == 1.08 and (err? blocked_hc) and (err? blocked_path)
	_ = assert-true hc_ok 'Host-function allowlist permits *.pricing.veko.dev and blocks evil.exfil.io & /etc/passwd'

	// --- 4. Execute Tenant Pricing Plugin Inside Wasm 3.0 Sandbox with JSON Marshaling ---
	inv_res = sdk/invoke-plugin mut host 'tenant-acme-pricing' 'evaluate-order' {
		subtotal_cents = 40000
		tier           = 'enterprise'
	}
	disc_c = as-i64 (map/get inv_res.output 'discount_cents')
	final_c = as-i64 (map/get inv_res.output 'final_cents')
	inv_ok = disc_c == 6000 and final_c == 34000 and inv_res.metrics.wasm_bytes > 1000 and inv_res.metrics.response_bytes > 20
	_ = assert-true inv_ok 'Wasm 3.0 tenant pricing plugin execution (40000 -> 6000 discount, 34000 final)'

	// --- 5. Deterministic Fuel Exhaustion Terminates Runaway Infinite-Loop Wasm 3.0 Plugin ---
	runaway_src = 'mut acc = 0\nwhile true [\n\tacc = acc + 1\n]\n'
	runaway_wasm = str/join [tmp_dir '/runaway_loop.wasm'] ''
	_ = sdk/compile-vk-plugin runaway_src runaway_wasm

	runaway_manifest = sdk/PluginManifest {
		plugin_id     = 'tenant-runaway-loop'
		version       = '1.0.0'
		max_fuel      = 5000
		max_mem_pages = 32
	}
	_ = sdk/register-plugin mut host runaway_manifest runaway_wasm
	trap_res = sdk/invoke-plugin/or mut host 'tenant-runaway-loop' 'spin' {} [e -> e]
	_ = assert-true (err? trap_res) 'Wasm 3.0 --fuel=5000 quota deterministically terminates runaway infinite-loop plugin'

	// --- 6. Audit Trail Inspection ---
	logs = sdk/host-audit-log host
	// Expected entries:
	// 0: bad_signature (denied)
	// 1: register tenant-acme-pricing (ok)
	// 2: http_fetch_rate eu.pricing.veko.dev (ok)
	// 3: http_fetch_rate evil.exfil.io (denied_host)
	// 4: kv_read_catalog /etc/passwd (denied_path)
	// 5: invoke tenant-acme-pricing (ok)
	// 6: register tenant-runaway-loop (ok)
	// 7: invoke tenant-runaway-loop (trapped_or_fuel_exhausted)
	audit_ok_1 = (len logs) == 8 and logs[0].outcome == 'bad_signature' and (not logs[0].allowed)
	audit_ok_2 = logs[2].outcome == 'ok' and logs[3].outcome == 'denied_host' and logs[4].outcome == 'denied_path'
	audit_ok_3 = logs[5].outcome == 'ok' and logs[7].outcome == 'trapped_or_fuel_exhausted' and (not logs[7].allowed)
	_ = assert-true (audit_ok_1 and audit_ok_2 and audit_ok_3) 'Deterministic AuditEntry log captures signature, host/path policy, execution, and fuel trap events'

	.ok
]

_ = run-demo
println 'wasm_plugin_sdk: all verification checks passed'
Cryptographic Provenance

Ed25519 Signature & Merkle Integrity

Registry URL: https://veko-lang.org/pkg/wasm_plugin_sdk/1.0.0.vkp
Archive SHA-256: a4a67d775adfafe4c086faf1befb4f32bc66cd386c17d85941ef9f49989821bc
Merkle Root: e5cbce96199f6ceb5596f343b278ff176dcd0009634ff1c895480860bee1040c
Signer Trust Key: ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70
Embedded VKP1 Manifest

manifest.json

{"name":"wasm_plugin_sdk","version":"1.0.0","tier":5.0,"tier_label":"Tier 5: Cloud-Native, Noise, IaC & Wasm","category":"Multi-Tenant Wasm 3.0 Plugin SDK","description":"Extism-style host-guest plugin manifest & VKPW RPC envelope with capability allowlists, deterministic fuel quotas, and audit logs.","modules":["wasm_plugin_sdk"],"homepage":"https://veko-lang.org/packages/wasm_plugin_sdk"}
Bundle Entry PathSizeLeaf SHA-256 Digest
README.md5 KBc480884b317bd1d4519b693dbd3d7d51faae8fd2e260c32d24f945a5785bd30d
examples/demo.vk6 KBecf75feb46048e279abc4e344468bf8af864094254d8e66c107b623b6c701cf0
mod.vk17 KB18bb1b8b093475e1e913d0ca82b60ec94b8c35d45ce95750bb45d9ee5bc13fcc