mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-04-02 08:58:06 +02:00
Merge pull request #41 from 13x-tech/fix/ignore-trailing-slash
This commit is contained in:
commit
b45c289f1c
@ -2,6 +2,7 @@ package nip42
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
@ -25,7 +26,7 @@ func CreateUnsignedAuthEvent(challenge, pubkey, relayURL string) nostr.Event {
|
||||
// ValidateAuthEvent checks whether event is a valid NIP-42 event for given challenge and relayURL.
|
||||
// The result of the validation is encoded in the ok bool.
|
||||
func ValidateAuthEvent(event *nostr.Event, challenge string, relayURL string) (pubkey string, ok bool) {
|
||||
if ok, _ := event.CheckSignature(); ok == false {
|
||||
if ok, _ := event.CheckSignature(); !ok {
|
||||
return "", false
|
||||
}
|
||||
if event.Kind != 22242 {
|
||||
@ -41,16 +42,28 @@ func ValidateAuthEvent(event *nostr.Event, challenge string, relayURL string) (p
|
||||
return "", false
|
||||
}
|
||||
|
||||
expected, err1 := url.Parse(relayURL)
|
||||
found, err2 := url.Parse(event.Tags.GetFirst([]string{"relay", ""}).Value())
|
||||
if err1 != nil || err2 != nil {
|
||||
parseUrl := func(input string) (*url.URL, error) {
|
||||
return url.Parse(
|
||||
strings.ToLower(
|
||||
strings.TrimSuffix(input, "/"),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
expected, err := parseUrl(relayURL)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
found, err := parseUrl(event.Tags.GetFirst([]string{"relay", ""}).Value())
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
|
||||
if expected.Scheme != found.Scheme ||
|
||||
expected.Host != found.Host ||
|
||||
expected.Path != found.Path {
|
||||
return "", false
|
||||
} else {
|
||||
if expected.Scheme != found.Scheme ||
|
||||
expected.Host != found.Host ||
|
||||
expected.Path != found.Path {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
return event.PubKey, true
|
||||
|
Loading…
x
Reference in New Issue
Block a user