Clean up AddNostrAddr for testing

This commit is contained in:
Amarpreet Minhas 2023-02-04 17:46:13 -05:00
parent f9106373c5
commit 03da6cf23d
2 changed files with 10 additions and 6 deletions

View file

@ -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)

View file

@ -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")
}