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 --- cmd/relay/main.go | 8 +++++ config.example.yaml | 7 +++++ internal/config/config.go | 13 ++++++++ internal/handler/websocket/handler.go | 27 +++++++++++----- internal/handler/websocket/nip11.go | 56 ++++++++++++++++++++++++++-------- relay | Bin 0 -> 27787846 bytes 6 files changed, 91 insertions(+), 20 deletions(-) create mode 100755 relay diff --git a/cmd/relay/main.go b/cmd/relay/main.go index 86a29cb..78ee469 100644 --- a/cmd/relay/main.go +++ b/cmd/relay/main.go @@ -116,6 +116,14 @@ func main() { }() } + wsHandler.SetRelayConfig(&wshandler.RelayInfoConfig{ + Name: cfg.Relay.Name, + Description: cfg.Relay.Description, + Pubkey: cfg.Relay.Pubkey, + Contact: cfg.Relay.Contact, + Icon: cfg.Relay.Icon, + }) + if cfg.Auth.Read.Enabled || cfg.Auth.Write.Enabled { wsHandler.SetAuth(store) wsHandler.SetAuthConfig(&wshandler.AuthConfig{ diff --git a/config.example.yaml b/config.example.yaml index 93f6000..5618b7e 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -1,3 +1,10 @@ +relay: + name: "muxstr relay" + description: "High-performance Nostr relay with gRPC, Connect, and WebSocket support" + pubkey: "" # operator's hex pubkey (optional) + contact: "" # admin contact email (optional) + icon: "" # relay icon URL (optional) + server: grpc_addr: "localhost:50051" http_addr: "localhost:8007" diff --git a/internal/config/config.go b/internal/config/config.go index 7eca750..36d3e1e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,6 +14,7 @@ import ( ) type Config struct { + Relay RelayConfig `yaml:"relay"` Server ServerConfig `yaml:"server"` Database DatabaseConfig `yaml:"database"` Auth AuthConfig `yaml:"auth"` @@ -23,6 +24,14 @@ type Config struct { Storage StorageConfig `yaml:"storage"` } +type RelayConfig struct { + Name string `yaml:"name"` + Description string `yaml:"description"` + Pubkey string `yaml:"pubkey"` + Contact string `yaml:"contact"` + Icon string `yaml:"icon"` +} + type ServerConfig struct { GrpcAddr string `yaml:"grpc_addr"` HttpAddr string `yaml:"http_addr"` @@ -90,6 +99,10 @@ type StorageConfig struct { // Default returns the default configuration. func Default() *Config { return &Config{ + Relay: RelayConfig{ + Name: "muxstr relay", + Description: "High-performance Nostr relay with gRPC, Connect, and WebSocket support", + }, Server: ServerConfig{ GrpcAddr: ":50051", HttpAddr: ":8080", 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, }, } diff --git a/relay b/relay new file mode 100755 index 0000000..1f873b0 Binary files /dev/null and b/relay differ -- cgit v1.2.3