mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-30 02:20:37 +02:00
validating/parsing nip05 and nip46.
This commit is contained in:
@ -3,11 +3,14 @@ package nip46
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nip04"
|
||||
)
|
||||
|
||||
var BUNKER_REGEX = regexp.MustCompile(`^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$`)
|
||||
|
||||
type Request struct {
|
||||
ID string `json:"id"`
|
||||
Method string `json:"method"`
|
||||
@ -77,3 +80,7 @@ func (s Session) MakeResponse(
|
||||
|
||||
return resp, evt, nil
|
||||
}
|
||||
|
||||
func IsValidBunkerURL(input string) bool {
|
||||
return BUNKER_REGEX.MatchString(input)
|
||||
}
|
||||
|
21
nip46/nip46_test.go
Normal file
21
nip46/nip46_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
package nip46
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValidBunkerURL(t *testing.T) {
|
||||
if !IsValidBunkerURL("bunker://3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d?relay=wss%3A%2F%2Frelay.damus.io&relay=wss%3A%2F%2Frelay.snort.social&relay=wss%3A%2F%2Frelay.nsecbunker.com") {
|
||||
t.Fatalf("should be valid")
|
||||
}
|
||||
if IsValidBunkerURL("askjdbkajdbv") {
|
||||
t.Fatalf("should be invalid")
|
||||
}
|
||||
if IsValidBunkerURL("asdjasbndksa@asjdnksa.com") {
|
||||
t.Fatalf("should be invalid")
|
||||
}
|
||||
if IsValidBunkerURL("https://hello.com?relays=wss://xxxxxx.xxxx") {
|
||||
t.Fatalf("should be invalid")
|
||||
}
|
||||
if IsValidBunkerURL("bunker://fa883d107ef9e558472c4eb9aaaefa459d?relay=wss%3A%2F%2Frelay.damus.io&relay=wss%3A%2F%2Frelay.snort.social&relay=wss%3A%2F%2Frelay.nsecbunker.com") {
|
||||
t.Fatalf("should be invalid")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user