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
|
package websocket
import (
"encoding/json"
"net/http"
)
type RelayInfo struct {
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 {
MaxMessageLength int `json:"max_message_length,omitempty"`
MaxSubscriptions int `json:"max_subscriptions,omitempty"`
MaxFilters int `json:"max_filters,omitempty"`
MaxLimit int `json:"max_limit,omitempty"`
MaxSubidLength int `json:"max_subid_length,omitempty"`
MaxEventTags int `json:"max_event_tags,omitempty"`
MaxContentLength int `json:"max_content_length,omitempty"`
MinPowDifficulty int `json:"min_pow_difficulty,omitempty"`
AuthRequired bool `json:"auth_required"`
PaymentRequired bool `json:"payment_required"`
RestrictedWrites bool `json:"restricted_writes"`
}
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: 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{
MaxMessageLength: 65536,
MaxSubscriptions: 20,
MaxFilters: 10,
MaxLimit: 5000,
MaxSubidLength: 64,
MaxEventTags: 2000,
MaxContentLength: 65536,
AuthRequired: authRequired,
PaymentRequired: false,
RestrictedWrites: restrictedWrites,
},
}
w.Header().Set("Content-Type", "application/nostr+json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Accept")
w.Header().Set("Access-Control-Allow-Methods", "GET")
json.NewEncoder(w).Encode(info)
}
|