Skip to content

v0.2.0 — Transport & local-first store

Choose a tag to compare

@sepehr-safari sepehr-safari released this 10 Jul 21:06
ed08c61

Milestones A3 (relay transport) and A4 (the local-first event store) — the transport layer and the performance spine that make a Nostr client feel instant.

Highlights

Relay transport (A3)

  • RFC 6455 WebSocket framing and handshake, verified against the spec's worked examples.
  • A relay connection state machine — publish / subscribe / unsubscribe, ping→pong, fragmentation reassembly — generic over its byte stream, so the entire protocol flow is proven in CI against an in-memory stream, plus a live TCP/TLS dialer with system-CA certificate verification.
  • NIP-01 wire types: the filter model, client REQ/EVENT/CLOSE encoders, and relay EVENT/OK/EOSE/CLOSED/NOTICE parsing.
  • NIP-65 outbox routing: parse kind:10002 relay lists and route reads/writes by relay list, with zero hardcoded relays.

Local-first event store (A4) — modeled on nostrdb

  • A zero-copy, memory-mapped LMDB store: events live in a compact binary record whose scalar fields are read straight from the memory map, with no JSON re-parse on read.
  • Secondary indexes (author, kind, created_at, single-letter tags) and a filter-driven query API that reuses the exact subscription matching semantics, returning results newest-first with pagination.
  • Validate-on-insert ingestion: optional signature verification, replaceable and parameterized-replaceable "latest-wins" upserts, and NIP-09 deletion with author-scoped tombstones.
  • A direct-message conversation index (keyed by the canonical participant pair) for instant DM threads, local-first reconciliation helpers, a size-cap cache, and batched bulk insert.

Performance

Benchmark (zig build bench, ReleaseFast, 100k events across 100 authors):

  • ingest ~149,000 events/s
  • warm 500-note feed query in ~0.6 ms

Quality

  • 107 tests passing, CI green on Linux and macOS.
  • The relay protocol flow is tested hermetically over an in-memory stream; the store is verified end-to-end against real LMDB.
  • No hand-rolled cryptography or storage engine — signing binds to audited bitcoin-core/secp256k1, storage to LMDB, both compiled from pinned sources.

Install

zig fetch --save https://github.com/zig-nostr/nostr/archive/refs/tags/v0.2.0.tar.gz

What's next

Milestone A5: a native signer with NIP-49 at-rest encryption and a NIP-46 bunker (remote signing with per-request approval).