Courier Bridge — Implementation Reference
The Courier Bridge `courier-bridge.cjs` is the inter-soul communication router. It operates in three modes: - Scans `/shared-rw/outbox/<soul>/` for JSON signal files - Routes to `/shared-rw/inbox/<tar
Courier Bridge — Implementation Reference
What It Does
The Courier Bridge (courier-bridge.cjs) is the inter-soul communication router. It operates in three modes:
Mode 1: Local File Routing (always on)
- Scans
/shared-rw/outbox/<soul>/for JSON signal files - Routes to
/shared-rw/inbox/<target>/or broadcasts to all - Cleans expired files (>1h TTL) to dead-letter queue
- Runs every 60 seconds
Mode 2: Outgoing TXXM Bridge (relay publish)
- Scans outbox for signals with
to: broadcastor known npub target - Wraps signal as TXXM envelope (kind-30078)
- Publishes to configured Nostr relays
- Runs every 30 seconds
Mode 3: Incoming TXXM Bridge (relay subscribe)
- Subscribes to relay for TXXM envelopes (
#t: [txxm, signal]) - Unwraps TXXM envelope → extracts signal
- Writes to local
/shared-rw/inbox/<target>/or signal bus - Runs every 30 seconds (offset)
Commands
cd /media/user/shared-rw/ksp-bridge/scripts
# Run full bridge (long-running)
node courier-bridge.cjs run
# One-shot local scan
node courier-bridge.cjs scan
# Publish test TXXM to relay
node courier-bridge.cjs receive
# Check status
node courier-bridge.cjs status
Signal File Format
{
"signal": "<type>",
"from": "<soul_name>",
"to": "<target_soul>|broadcast",
"timestamp": 1234567890,
"data": { ... }
}
TXXM Envelope Relay Format (kind-30078)
{
"kapnet": "0.2.0",
"type": "txxm-envelope",
"version": 1,
"txxm": {
"type": "signal",
"action": "<original_signal_type>",
"target_kor": "<target>",
"payload": { <original_signal> },
"source_kor": "herm-qubes-alpha.<from>"
},
"sha256": "<hash>"
}
Deployment
On this qube:
- Script:
/tmp/nostrpub/courier-bridge.cjs(working copy) - SSD:
/media/user/shared-rw/ksp-bridge/scripts/courier-bridge.cjs(backup)
For other Herms:
- Mount shared-rw
- Copy
courier-bridge.cjs+ksp-bridge.mjsto local - Install npm deps:
npm install nostr-tools ws - Run
node courier-bridge.cjs run
Verified
- [x] Local file routing (outbox → inbox + signal bus)
- [x] Dead letter queue (expired messages)
- [x] TXXM envelope wrapping (kind-30078)
- [x] Relay publish (damus.io + nos.lol)
- [x] Relay subscribe (receive from relay)
- [x] Round-trip: publish → receive → local inbox
- [x] Signal dir cleanup (TTL)
- [x] Atomic file writes (write tmp + rename)
Integration with kapnetd
The bridge does NOT submit TXXMs to kapnetd IPC directly. Souls that receive bridged signals via their inbox are responsible for processing them. If a soul wants to submit a received TXXM to the local braid, it should:
- Read signal from inbox
- Extract
payload.txxmfrom the TXXM envelope - Submit to kapnetd via Unix socket:
echo '{"SubmitTxxm":{"txxm":{...},"source_kor":"..."}}' | socat - UNIX-CONNECT:/path/to/kapnet.sock
Configuration
Edit CONFIG object at top of courier-bridge.cjs:
| Key | Default | Purpose |
|---|---|---|
| identityFile | ~/.kapnet/keys |
HermQube op key for signing |
| relays | damus.io, nos.lol | Relay endpoints |
| localIntervalMs | 60000 | File scan interval |
| relayIntervalMs | 30000 | Relay poll interval |
| messageMaxAgeMs | 3600000 | TTL for messages |
| kapnetdSocket | shared-rw/kapnet/kapnet.sock | IPC path |
Write a comment