# nostr-grpc A high-performance Nostr relay with gRPC and WebSocket support. ## Features - **gRPC-first**: Binary protobuf storage with gRPC API - **SQLite storage**: WAL mode, optimized indexes - **Event validation**: Signature and ID verification - **Nostr compatible**: NIP-01 compliant ## Quick Start ### Build ```bash make build # Build relay make build-client # Build test client make build-all # Build both ``` ### Run the Relay ```bash ./bin/relay # or with custom settings: ./bin/relay -grpc-addr :50051 -db relay.db ``` The relay will start listening on `:50051` (gRPC). ### Test with Client **Standalone mode:** ```bash ./bin/testclient # Output: # Generated key: npub1... # Publishing event... # ✓ Event published successfully: abc123... # Querying events... # Found 1 events from author abc123... # - abc123...: Hello from gRPC client! ``` **With nak CLI:** ```bash # Pipe events from nak nak event "Hello from nak!" | ./bin/testclient # Or generate a signed event nak event --sec --kind 1 "My message" | ./bin/testclient # Output: # Read event from stdin: abc123... # Publishing event... # ✓ Event published successfully: abc123... ``` ## gRPC API See [proto/nostr/v1/nostr.proto](proto/nostr/v1/nostr.proto) for the full API. ### Available RPCs - `PublishEvent` - Publish a single event (with validation) - `PublishBatch` - Publish multiple events - `QueryEvents` - Query events with filters (paginated) - `CountEvents` - Count events matching filters - `Subscribe` - Stream events (past + real-time) ✅ - `Unsubscribe` - Close subscription ✅ ## Current Status **Phase 1: gRPC Relay** - ✅ SQLite storage with binary-first design - ✅ Event validation (ID, signature) - ✅ gRPC publish/query API - ✅ Subscribe/streaming (real-time event delivery) - ✅ Subscription management (filter matching, fan-out) - ⏳ WebSocket server (planned for Nostr client compatibility) ## Development ```bash make proto # Regenerate protobuf code make test # Run tests make proto-lint # Lint proto files ``` ## Architecture ``` ┌─────────────────┐ │ gRPC Client │ └────────┬────────┘ │ pb.Event ▼ ┌─────────────────┐ │ gRPC Handler │ ← validates using nostr.Event │ (convert.go) │ ← generates canonical JSON └────────┬────────┘ │ pb.Event + canonicalJSON ▼ ┌─────────────────┐ │ Storage Layer │ ← protobuf + compressed JSON │ (SQLite) │ ← query by filter └─────────────────┘ ``` ## License MIT