blob: d0ff87243bf231cdb888793a6b54cc248ea9ac55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# 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 <nsec> --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
|