mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
nip05 queryName() function.
This commit is contained in:
parent
5d1a29d135
commit
5f3221e966
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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user