Only publish zap receipts to public wss relays

Relay URLs come from the zap request. Keep at most 10 of them, only
wss://, and make the websocket dialer refuse non-public addresses.

Manual port of kravens/BitTipBot efe2fa2 (the only conflict was the
hard-coded default relay list, which is kept as is).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-13 20:34:56 +00:00
co-authored by Claude Fable 5.1
parent 2c3c9fb3ce
commit 39bddc2cb5
2 changed files with 26 additions and 3 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ require (
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-redis/redis/v8 v8.8.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.4.2
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.2 // indirect
github.com/kkdai/bstream v1.0.0 // indirect
+25 -2
View File
@@ -7,12 +7,35 @@ import (
"time"
"github.com/LightningTipBot/LightningTipBot/internal"
"github.com/LightningTipBot/LightningTipBot/internal/netguard"
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
"github.com/gorilla/websocket"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19"
log "github.com/sirupsen/logrus"
)
// maxRequestedRelays caps the relays taken from a zap request, so they can't
// push the default relays out of the list.
const maxRequestedRelays = 10
// go-nostr connects with the default websocket dialer. Relay URLs come from
// zap requests, so it must only reach public addresses.
func init() {
websocket.DefaultDialer.NetDialContext = netguard.DialContext
}
// requestedRelays keeps the wss:// relays of a zap request, up to maxRequestedRelays.
func requestedRelays(relays []string) []string {
list := []string{}
for _, relay := range relays {
if strings.HasPrefix(relay, "wss://") && len(list) < maxRequestedRelays {
list = append(list, relay)
}
}
return list
}
var (
nosterRegisterMessage = "📖 Add your nostr pubkey for zap receipts"
nostrInfoMessage = "💜 *Your nostr information*\n\nYour pubkey: `%s`"
@@ -64,8 +87,8 @@ func (bot *TipBot) publishNostrEvent(ev nostr.Event, relays []string) {
ev.Sign(pk)
log.Debugf("[NOSTR] 🟣 publishing nostr event %s", ev.ID)
// more relays
relays = append(relays, "wss://relay.nostr.ch", "wss://eden.nostr.land", "wss://nostr.btcmp.com", "wss://nostr.relayer.se", "wss://relay.current.fyi", "wss://nos.lol", "wss://nostr.mom", "wss://relay.nostr.info", "wss://nostr.zebedee.cloud", "wss://nostr-pub.wellorder.net", "wss://relay.snort.social/", "wss://relay.damus.io/", "wss://nostr.oxtr.dev/", "wss://nostr.fmt.wiz.biz/", "wss://brb.io")
// more relays (only public wss:// relays are taken from the zap request)
relays = append(requestedRelays(relays), "wss://relay.nostr.ch", "wss://eden.nostr.land", "wss://nostr.btcmp.com", "wss://nostr.relayer.se", "wss://relay.current.fyi", "wss://nos.lol", "wss://nostr.mom", "wss://relay.nostr.info", "wss://nostr.zebedee.cloud", "wss://nostr-pub.wellorder.net", "wss://relay.snort.social/", "wss://relay.damus.io/", "wss://nostr.oxtr.dev/", "wss://nostr.fmt.wiz.biz/", "wss://brb.io")
// remove trailing /
relays = cleanUrls(relays)