Scripts for exercising the spike. Several cover the design end-to-end on direct pipes (no network); others exercise the swarm transport (over the public DHT or a private one you run yourself).
src/demos/
├── smoke.ts ← live DHT, runtime-only (2 peers)
├── end-to-end.ts ← bundle → topic → log, via live DHT
├── acme-org.ts ← small-org walk-through, direct pipe (no network)
├── key-delivery.ts ← inviting a peer AFTER creation (#9), direct pipe
├── topic-auth.ts ← connect-time membership gate (#10), private DHT
├── workspace-sdk.ts ← the whole flow via @workspace.sh/workspace, private DHT
├── bootstrap-dht.ts ← private hyperdht bootstrap node
└── acme-org-live.ts ← acme-org, but over the private DHT
See docs/network/discovery-layers.md for
why we offer both pipe-based and swarm-based versions — the discovery
layer is the first thing that differs across local / LAN / WAN
scenarios.
Two NodeRuntime instances find each other via the public DHT and
replicate a log. Exercises discovery + transport through the real
Hyperswarm swarm. The unit test at
packages/p2p-runtime/tests/replicate.test.ts covers the same
replication code path via a direct duplex pipe — no network.
npm -w @workspace.sh/p2p-spike-node run smokeRequires internet access. Flaky if the public DHT is slow or your network throttles UDP; rerun if it times out.
The first cohesive walk-through of the design, over the real swarm:
- Peer A creates a workspace (root identity, attestation, K0_org)
- Peer A writes a
.workspace/bundle to disk for Peer B - Peer B reads the folder, validates the attestation, unwraps the envelope
- Both peers join the topic derived from
workspaceId - Peer A creates a Hypercore log and appends data
- Peer B opens the log and reads it back via Hyperswarm
npm -w @workspace.sh/p2p-spike-node run demo:end-to-endSame network caveat as smoke.
A more thorough demo: three members of "Acme" share a workspace. The working tree carries plaintext markdown files (workspace-public, per the spec); the data log carries the same content sealed under K0_org. Bob and Carol unwrap K0_org from their envelopes and decrypt; Eve (no envelope) cannot.
npm -w @workspace.sh/p2p-spike-node run demo:acmeUses the runtime's direct duplex pipe rather than the swarm. Same Hypercore replication code path, just deterministic and fast (~20ms). Doesn't touch the network at all.
The two-carrier model's live half. The bundle handles offline first-contact; this handles the peer who joins on Tuesday when the bundle was cut on Friday. Alice (admin) appends one sealed envelope addressed to Dave's DID to a replicated key delivery log; Dave scans from his cursor, validates the UCAN against the workspace root, unwraps K0_org, and then decrypts actual workspace content with it — without re-cutting any bundle or touching anyone else's keys.
npm -w @workspace.sh/p2p-spike-node run demo:key-deliveryDirect pipe, no network. Demonstrates publishDelivery / scanDeliveries
from @workspace.sh/portable-bootstrap composed with encryptedLog.
The second revocation lever: gating who can connect, not just who can
decrypt. Each peer runs with an auth hook that exchanges membership
proofs on every connection. Alice + Bob (root-issued UCANs) verify each
other and replicate; Mallory (a UCAN from a different root) reaches the
topic but fails the gate and replicates nothing.
npm -w @workspace.sh/p2p-spike-node run demo:topic-authRuns over a real Hyperswarm against a private in-process bootstrap (no
public DHT). Demonstrates the Noise-key↔DID binding (identitySeed), the
auth gate in the runtime, and verifyMembership rejecting a wrong-root
proof at connect time.
The whole Acme flow via @workspace.sh/workspace: Workspace.create →
invite → write; then Workspace.open on a second peer →
replicate → entries. Same outcome as demo:acme:live but ~10 lines
instead of ~200 — the surface the app is actually built against.
npm -w @workspace.sh/p2p-spike-node run demo:workspaceReal Hyperswarm, private in-process bootstrap. Eve (uninvited) is
rejected at open.
Default to the containerised version below for iterative work. The bare-host scripts in this section are kept for cases where you can't or don't want to run Docker.
For exercising the actual Hyperswarm transport without polluting your network: run a private hyperdht bootstrap node, point peers at it instead of the public DHT.
# Terminal 1 — start the private DHT (listens on 127.0.0.1:49737)
npm -w @workspace.sh/p2p-spike-node run demo:bootstrap
# Terminal 2 — run the Acme demo against it
npm -w @workspace.sh/p2p-spike-node run demo:acme:liveThe runtime accepts a bootstrap option (see
CreateRuntimeOptions) so any code can opt into this private-DHT
mode. The bootstrap process keeps running until Ctrl-C; the demo
shuts down its own peers.
See docs/network/discovery-layers.md for
the architectural framing of why this exists — it's the same
mechanism a self-hosted org would use to run a workspace's swarm on
their own infrastructure.
For anything iterative or unattended, run the live demo inside
Docker. The bootstrap and the peer process each get their own
container on a private bridge network; nothing leaks to the host
network namespace and each container has hard memory + CPU caps. If
anything misbehaves, docker compose down cleans up reliably
regardless of Node's state.
From the repo root:
docker compose build # once, or after dep changes
docker compose up acme # runs the Acme demo end-to-endSee docker/README.md for the full
rationale and the testing-mode matrix. Short version:
| Mode | Use case |
|---|---|
npm test |
Day-to-day dev (no network) |
demo:acme |
Multi-peer flows without sockets (direct pipe) |
docker compose up acme |
Real swarm transport, fully isolated |
demo:bootstrap + demo:acme:live |
Same as above but bare host |
smoke / demo:end-to-end |
Verify the public DHT actually works |
Default to the first two; reach for the container when you need the swarm transport; bare host only when Docker isn't an option.
- Topic rotation on departure — the membership gate (#10) is in, but rotating the discovery topic alongside K0_org so a revoked peer can't rediscover the swarm is still pending
- Autobase multi-writer (#11) — the demos use a single-writer log per
peer; concurrent multi-writer editing with conflict resolution is
pending. (Transparent block encryption itself is done —
encryptedLogwraps any log; the demos use it.) - LAN discovery (mDNS) — designed in
docs/network/discovery-layers.md; not yet implemented