summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 503479715dfaa5775ec846fefc374c4b65ac7cc0 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# muxstr

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 -ws-addr :8080 -db relay.db
```

The relay will start:
- **gRPC** (native) on `:50051`
- **HTTP** server on `:8080`:
  - **Connect** (gRPC over HTTP/JSON) at `/nostr.v1.NostrRelay/*`
  - **WebSocket** (Nostr protocol) at `/`

### 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 (gRPC):**
```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
```

**With nak CLI (WebSocket/Nostr):**
```bash
# Standard Nostr clients work out of the box!
nak req -k 1 --limit 10 ws://localhost:8080

# Publish via WebSocket
echo '{"kind":1,"content":"hello","tags":[]}' | nak event --sec <nsec> | nak publish ws://localhost:8080
```

**With Connect (HTTP/JSON):**
```bash
# Call gRPC methods over HTTP with JSON
curl -X POST http://localhost:8080/nostr.v1.NostrRelay/PublishEvent \
  -H "Content-Type: application/json" \
  -d '{"event": {...}}'

# Works from browsers, curl, fetch(), etc.
```

## 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: Complete** ✅
- ✅ SQLite storage with binary-first design
- ✅ Event validation (ID, signature)
- ✅ **Triple protocol support:**
  - **gRPC** (native binary protocol)
  - **Connect** (gRPC over HTTP/JSON - browser compatible!)
  - **WebSocket** (NIP-01 - standard Nostr protocol)
- ✅ Subscribe/streaming (real-time event delivery)
- ✅ Subscription management (filter matching, fan-out)
- ✅ **NIP-09** - Event deletion (hard delete, authors can delete their own events)
- ✅ **NIP-11** - Relay info document (GET with `Accept: application/nostr+json`)

**Compatible with:**
- Any gRPC client (Go, Python, JS, etc.)
- Any HTTP client (curl, fetch, browsers)
- Any Nostr client (Damus, Amethyst, Snort, Iris, Gossip, etc.)
- nak CLI for testing

## 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