Clean up AddNostrAddr for testing
This commit is contained in:
parent
f9106373c5
commit
03da6cf23d
2 changed files with 10 additions and 6 deletions
4
main.go
4
main.go
|
@ -11,11 +11,11 @@ func main() {
|
|||
/*
|
||||
nostrTest := nostr.NostrRequest{
|
||||
Name: "asara",
|
||||
Key: "abcdefg",
|
||||
Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6",
|
||||
Hostname: "devvul.com",
|
||||
}
|
||||
nostr.AddNostrAddr(nostrTest)
|
||||
*/
|
||||
nostr.AddNostrAddr(nostrTest)
|
||||
// matrix endpoints
|
||||
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
|
||||
http.HandleFunc("/.well-known/matrix/client", matrix.MatrixClient)
|
||||
|
|
|
@ -34,7 +34,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
|||
relays := make(map[string][]string)
|
||||
npub := r.FormValue("Key")
|
||||
// convert npub to hex
|
||||
hexKey, err := convertNpubtoHex(npub)
|
||||
hexKey, err := convertNpubToHex(npub)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
|
@ -90,10 +90,14 @@ func AddNostrAddr(n NostrRequest) {
|
|||
// transform request to well known struct
|
||||
relays := make(map[string][]string)
|
||||
user := nostrWellKnown{}
|
||||
names := map[string]string{n.Name: n.Key}
|
||||
hexKey, err := convertNpubToHex(n.Key)
|
||||
if err != nil {
|
||||
fmt.Printf("Not an npub")
|
||||
}
|
||||
names := map[string]string{n.Name: hexKey}
|
||||
|
||||
if n.Relays != nil {
|
||||
relays = map[string][]string{n.Key: n.Relays}
|
||||
relays = map[string][]string{hexKey: n.Relays}
|
||||
user = nostrWellKnown{Names: names, Relays: relays}
|
||||
} else {
|
||||
user = nostrWellKnown{Names: names}
|
||||
|
@ -119,7 +123,7 @@ func getHostname(hostname string) string {
|
|||
return hostname
|
||||
}
|
||||
|
||||
func convertNpubtoHex(npub string) (string, error) {
|
||||
func convertNpubToHex(npub string) (string, error) {
|
||||
if !strings.HasPrefix(npub, "npub1") {
|
||||
return "", errors.New("Not an npub key")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue