validate and normalize relay urls received from kind 3 and 10002.
This commit is contained in:
15
utils.go
15
utils.go
@@ -1,6 +1,7 @@
|
||||
package nostr
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
@@ -129,3 +130,17 @@ func InsertEventIntoDescendingList(sortedArray []*Event, event *Event) []*Event
|
||||
|
||||
return sortedArray
|
||||
}
|
||||
|
||||
func IsValidRelayURL(u string) bool {
|
||||
parsed, err := url.Parse(u)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if parsed.Scheme != "wss" && parsed.Scheme != "ws" {
|
||||
return false
|
||||
}
|
||||
if len(strings.Split(parsed.Host, ".")) < 2 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user