nip46: fix IsValidBunkerURL because that regex was borked.

This commit is contained in:
fiatjaf 2024-12-17 11:05:43 -03:00
parent 11bdc95a37
commit 9cb853d6b1

View File

@ -2,16 +2,14 @@ package nip46
import ( import (
"context" "context"
"regexp" "net/url"
"strings"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
) )
var ( var json = jsoniter.ConfigFastest
BUNKER_REGEX = regexp.MustCompile(`^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$`)
json = jsoniter.ConfigFastest
)
type Request struct { type Request struct {
ID string `json:"id"` ID string `json:"id"`
@ -41,5 +39,18 @@ type Signer interface {
} }
func IsValidBunkerURL(input string) bool { func IsValidBunkerURL(input string) bool {
return BUNKER_REGEX.MatchString(input) p, err := url.Parse(input)
if err != nil {
return false
}
if p.Scheme != "bunker" {
return false
}
if !nostr.IsValidPublicKey(p.Host) {
return false
}
if !strings.Contains(p.RawQuery, "relay=") {
return false
}
return true
} }