From 5f3221e966dccd275bbd563069ab3dd3590d20cc Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 4 May 2022 11:15:26 -0300 Subject: [PATCH] nip05 queryName() function. --- nip05/nip05.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 nip05/nip05.go diff --git a/nip05/nip05.go b/nip05/nip05.go new file mode 100644 index 0000000..b9d550e --- /dev/null +++ b/nip05/nip05.go @@ -0,0 +1,32 @@ +package nip05 + +import ( + "encoding/json" + "fmt" + "net/http" + "strings" +) + +func queryName(fullname string) string { + spl := strings.Split(fullname, "@") + if len(spl) != 2 { + return "" + } + + name := spl[0] + domain := spl[1] + res, err := http.Get(fmt.Sprintf("https://%s/.well-known/nostr.json?name=%s", domain, name)) + if err != nil { + return "" + } + + var result struct { + Names map[string]string `json:"names"` + } + if err := json.NewDecoder(res.Body).Decode(&result); err != nil { + return "" + } + + pubkey, _ := result.Names[name] + return pubkey +}