Skip to content

Commit

Permalink
nip46: fix IsValidBunkerURL because that regex was borked.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Dec 17, 2024
1 parent 11bdc95 commit 9cb853d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions nip46/nip46.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package nip46

import (
"context"
"regexp"
"net/url"
"strings"

jsoniter "github.com/json-iterator/go"
"github.com/nbd-wtf/go-nostr"
)

var (
BUNKER_REGEX = regexp.MustCompile(`^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$`)
json = jsoniter.ConfigFastest
)
var json = jsoniter.ConfigFastest

type Request struct {
ID string `json:"id"`
Expand Down Expand Up @@ -41,5 +39,18 @@ type Signer interface {
}

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
}

0 comments on commit 9cb853d

Please sign in to comment.