nip05 queryName() function.
This commit is contained in:
32
nip05/nip05.go
Normal file
32
nip05/nip05.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user