From 5195d8031b7930069ba5441a6cd1e7a59c21c546 Mon Sep 17 00:00:00 2001 From: Clawd Date: Sun, 22 Feb 2026 14:08:54 -0800 Subject: NIP-11: make relay info configurable - Add relay config section (name, description, pubkey, contact, icon) - Wire config to NIP-11 handler - AuthRequired/RestrictedWrites now reflect actual auth config - Add NIP-42 to supported_nips list - Update example config --- internal/handler/websocket/handler.go | 27 ++++++++++++----- internal/handler/websocket/nip11.go | 56 +++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 20 deletions(-) (limited to 'internal/handler') diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go index 6eb8763..b11171d 100644 --- a/internal/handler/websocket/handler.go +++ b/internal/handler/websocket/handler.go @@ -49,6 +49,14 @@ type AuthConfig struct { WriteAllowedPubkeys []string } +type RelayInfoConfig struct { + Name string + Description string + Pubkey string + Contact string + Icon string +} + type connState struct { authenticatedPubkey string authChallenge string @@ -56,13 +64,14 @@ type connState struct { } type Handler struct { - store EventStore - auth AuthStore - subs *subscription.Manager - metrics MetricsRecorder - limiter RateLimiter - authConfig *AuthConfig - indexData IndexData + store EventStore + auth AuthStore + subs *subscription.Manager + metrics MetricsRecorder + limiter RateLimiter + authConfig *AuthConfig + relayConfig *RelayInfoConfig + indexData IndexData } func NewHandler(store EventStore, subs *subscription.Manager) *Handler { @@ -88,6 +97,10 @@ func (h *Handler) SetAuthConfig(cfg *AuthConfig) { h.authConfig = cfg } +func (h *Handler) SetRelayConfig(cfg *RelayInfoConfig) { + h.relayConfig = cfg +} + // SetIndexData sets the addresses for the index page func (h *Handler) SetIndexData(grpcAddr, httpAddr, wsAddr string) { h.indexData = IndexData{ diff --git a/internal/handler/websocket/nip11.go b/internal/handler/websocket/nip11.go index 8de95a2..f51faa6 100644 --- a/internal/handler/websocket/nip11.go +++ b/internal/handler/websocket/nip11.go @@ -6,14 +6,15 @@ import ( ) type RelayInfo struct { - Name string `json:"name"` - Description string `json:"description"` - Pubkey string `json:"pubkey,omitempty"` - Contact string `json:"contact,omitempty"` - SupportedNIPs []int `json:"supported_nips"` - Software string `json:"software"` - Version string `json:"version"` - Limitation *Limits `json:"limitation,omitempty"` + Name string `json:"name"` + Description string `json:"description"` + Pubkey string `json:"pubkey,omitempty"` + Contact string `json:"contact,omitempty"` + Icon string `json:"icon,omitempty"` + SupportedNIPs []int `json:"supported_nips"` + Software string `json:"software"` + Version string `json:"version"` + Limitation *Limits `json:"limitation,omitempty"` } type Limits struct { @@ -31,10 +32,39 @@ type Limits struct { } func (h *Handler) ServeNIP11(w http.ResponseWriter, r *http.Request) { + // Defaults + name := "muxstr relay" + description := "High-performance Nostr relay with gRPC, Connect, and WebSocket support" + var pubkey, contact, icon string + + // Override from config if set + if h.relayConfig != nil { + if h.relayConfig.Name != "" { + name = h.relayConfig.Name + } + if h.relayConfig.Description != "" { + description = h.relayConfig.Description + } + pubkey = h.relayConfig.Pubkey + contact = h.relayConfig.Contact + icon = h.relayConfig.Icon + } + + // Determine auth status from authConfig + authRequired := false + restrictedWrites := false + if h.authConfig != nil { + authRequired = h.authConfig.ReadEnabled + restrictedWrites = h.authConfig.WriteEnabled + } + info := RelayInfo{ - Name: "muxstr relay", - Description: "High-performance Nostr relay with gRPC, Connect, and WebSocket support", - SupportedNIPs: []int{1, 9, 11}, + Name: name, + Description: description, + Pubkey: pubkey, + Contact: contact, + Icon: icon, + SupportedNIPs: []int{1, 9, 11, 42}, Software: "northwest.io/muxstr", Version: "0.1.0", Limitation: &Limits{ @@ -45,9 +75,9 @@ func (h *Handler) ServeNIP11(w http.ResponseWriter, r *http.Request) { MaxSubidLength: 64, MaxEventTags: 2000, MaxContentLength: 65536, - AuthRequired: false, + AuthRequired: authRequired, PaymentRequired: false, - RestrictedWrites: false, + RestrictedWrites: restrictedWrites, }, } -- cgit v1.2.3