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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
package websocket
import (
"html/template"
"net/http"
)
var indexTemplate = template.Must(template.New("index").Parse(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>muxstr</title>
<style>
body {
font-family: 'Courier New', Courier, monospace;
background: #f5f0e8;
color: #000;
max-width: 720px;
margin: 40px auto;
padding: 0 20px;
line-height: 1.6;
}
h1 {
font-size: 18px;
font-weight: normal;
margin: 20px 0 10px 0;
}
h2 {
font-size: 16px;
font-weight: normal;
margin: 30px 0 10px 0;
}
h3 {
font-size: 14px;
font-weight: normal;
margin: 20px 0 5px 0;
}
p, li {
font-size: 13px;
}
a {
color: #00e;
text-decoration: underline;
}
a:visited {
color: #551a8b;
}
hr {
border: none;
border-top: 1px solid #000;
margin: 30px 0;
}
pre {
font-size: 12px;
line-height: 1.4;
overflow-x: auto;
}
code {
font-family: 'Courier New', Courier, monospace;
font-size: 13px;
}
.hash {
color: #666;
font-size: 11px;
}
ul {
padding-left: 20px;
}
.pgp-block {
margin: 20px 0;
padding: 10px;
border: 1px solid #ccc;
background: #f5f5f5;
}
.logo-container {
margin: 20px 0 30px 0;
}
.logo-container svg {
width: 100%;
height: auto;
display: block;
}
</style>
</head>
<body>
<div class="logo-container">
<svg viewBox="0 0 1120 300" xmlns="http://www.w3.org/2000/svg">
<rect width="1120" height="300" fill="#c97556"/>
<text x="560" y="200" font-family="Arial, Helvetica, sans-serif" font-size="180" font-weight="bold" fill="#f5f0e8" text-anchor="middle">muxstr</text>
</svg>
</div>
<h1>Nostr Relay</h1>
<p>This relay implements the Nostr protocol with support for multiple transport layers. Connect using gRPC, HTTP/JSON (Connect), or standard WebSocket.</p>
<hr>
<h2>Connection Endpoints</h2>
<h3>gRPC (Native Binary)</h3>
<p><code>{{.GrpcAddr}}</code></p>
<p>High-performance binary protocol using Protocol Buffers over HTTP/2. For applications requiring low latency and high throughput.</p>
<h3>Connect (HTTP/JSON)</h3>
<p><code>{{.HttpAddr}}/nostr.v1.NostrRelay/*</code></p>
<p>Browser-compatible HTTP interface. Standard JSON over HTTP/1.1 or HTTP/2. CORS enabled.</p>
<h3>WebSocket (Nostr Protocol)</h3>
<p><code>{{.WsAddr}}/</code></p>
<p>Standard Nostr protocol implementation (NIP-01). Compatible with all Nostr clients: Damus, Amethyst, Snort, Iris, etc.</p>
<hr>
<h2>Supported NIPs</h2>
<ul>
<li><strong>NIP-01</strong> - Basic protocol flow (EVENT, REQ, CLOSE)</li>
<li><strong>NIP-09</strong> - Event deletion</li>
<li><strong>NIP-11</strong> - Relay information document</li>
</ul>
<hr>
<h2>Implementation Details</h2>
<p><strong>Storage:</strong> SQLite with Write-Ahead Logging (WAL mode)<br>
<strong>Event Format:</strong> Binary-first (Protocol Buffers + compressed JSON)<br>
<strong>Validation:</strong> Full cryptographic signature and event ID verification<br>
<strong>Subscriptions:</strong> Real-time event streaming with filter matching<br>
<strong>Deletion:</strong> Hard delete (events are permanently removed)</p>
<hr>
<h2>Technical Notes</h2>
<p>Events are stored in binary format using Protocol Buffers alongside compressed canonical JSON. This dual-storage approach provides both performance (binary queries) and compatibility (JSON export).</p>
<p>The relay validates all events before storage:</p>
<pre>1. Verify event ID matches SHA256(canonical_json)
2. Verify schnorr signature against pubkey
3. Store in SQLite with indexed queries</pre>
<p>Subscriptions use a shared manager across all three protocols. An event published via gRPC will be immediately broadcast to WebSocket subscribers and vice versa.</p>
<hr>
<div class="pgp-block">
<pre>-----BEGIN PGP SIGNATURE-----
<span class="hash">relay_fingerprint: a8f9c2e1d4b7a3f6</span>
<span class="hash">protocol_version: nostr_01</span>
<span class="hash">transport_types: grpc|connect|websocket</span>
-----END PGP SIGNATURE-----</pre>
</div>
<p><small>This relay runs on open-source software. Decentralized, censorship-resistant, user-owned.</small></p>
</body>
</html>`))
type IndexData struct {
GrpcAddr string
HttpAddr string
WsAddr string
}
func (h *Handler) ServeIndex(w http.ResponseWriter, r *http.Request, data IndexData) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
indexTemplate.Execute(w, data)
}
|