Add an experimental `nscript` filter that runs a user-supplied WASM guest, behind the `nscript` cargo feature (wasmtime), on both the write path (should this note be stored) and the read path (should this note be delivered to this subscriber). This is the experimental part of the plugin work — the readPolicy trait, engine and throttles in the preceding commits stand on their own without it, and a build without the feature skips an `nscript` pipeline entry (fail open) rather than failing. The ABI is an accessor interface over an opaque note handle: the guest never parses a note buffer, it calls imported `note_*` host functions (note_pubkey/id/kind/created_at/content, note_targets_owner, is_following, log) to read fields. The note's byte format is thus a host implementation detail — today backed by the serde Note; later an ndb_note with an optional zero-copy raw fast path. Owner-relative context (the scoped npub and its follows) lives on the host so guests stay reusable, owner-agnostic logic. Guests are bounded by wasm fuel and a memory cap per note, and noteguard fails open on trap/exhaustion so a broken or runaway filter can't block writes, hang the relay, or withhold a subscriber's own authorized feed. On the read path the subscriber (the NIP-42 authed pubkey) is the script owner, so a per-npub feed filter runs scoped to whoever is reading. Runtime::rescope re-binds an already-compiled guest to a different owner and follow-set by cloning the (internally reference-counted) engine/module/linker, so the guest is JIT-compiled once per process and a subscription costs no compile or file read on strfry's serving thread; a failed load is logged once rather than once per subscription. The Verdict collapses on the read path to deliver (Accept) vs withhold (anything else) — there is no shadow concept for reads. Only this filter calls UnparsedNote::parse(); the throttles still never deserialize a Note. Script/follow distribution is stubbed for this phase (configured statically via `module`/`owner`/`follows` rather than sourced from signed submission events on the relay); the point today is the ABI + runtime wiring. Includes three example guests: follows-only (an inbox filter, <300 bytes with no note parser linked in), an adversarial infinite-loop guest, and mute-word (an owner-independent content mute, convenient for exercising the read path without AUTH). Verified end-to-end on the write path: followed->accept, stranger->reject, off-target->accept, and the spinner is stopped by fuel in ~15ms. And on the read path against strfry (branch config): content filtering withholds exactly the muted events, a trapping guest fails open and delivers all; plugin logs show reqOpen(+filter) -> req(+events) -> connClose. Changelog-Added: Experimental nscript WASM note filter (behind the `nscript` feature), on both the write path and the readPolicy delivery path Headway: headway:noteguard/chair-kick-reopen Headway: headway:noteguard/gloom-lucky-budget Agentium: agentium:exhaust-bus-combine Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
15 lines
175 B
TOML
15 lines
175 B
TOML
[workspace]
|
|
|
|
[package]
|
|
name = "loop-forever"
|
|
version = "0.1.0"
|
|
edition = "2021"
|
|
|
|
[lib]
|
|
crate-type = ["cdylib"]
|
|
|
|
[profile.release]
|
|
opt-level = "s"
|
|
panic = "abort"
|
|
strip = true
|