mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
support relays in nip05.
This commit is contained in:
parent
024f89ac58
commit
a3e3b25dd9
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -17,7 +19,7 @@ type WellKnownResponse struct {
|
||||
Relays key2RelaysMap `json:"relays"` // NIP-35
|
||||
}
|
||||
|
||||
func QueryIdentifier(fullname string) string {
|
||||
func QueryIdentifier(fullname string) *nostr.ProfilePointer {
|
||||
spl := strings.Split(fullname, "@")
|
||||
|
||||
var name, domain string
|
||||
@ -29,25 +31,30 @@ func QueryIdentifier(fullname string) string {
|
||||
name = spl[0]
|
||||
domain = spl[1]
|
||||
default:
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.Index(domain, ".") == -1 {
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
res, err := http.Get(fmt.Sprintf("https://%s/.well-known/nostr.json?name=%s", domain, name))
|
||||
if err != nil {
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
var result WellKnownResponse
|
||||
if err := json.NewDecoder(res.Body).Decode(&result); err != nil {
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
pubkey, _ := result.Names[name]
|
||||
return pubkey
|
||||
relays, _ := result.Relays[pubkey]
|
||||
|
||||
return &nostr.ProfilePointer{
|
||||
PublicKey: pubkey,
|
||||
Relays: relays,
|
||||
}
|
||||
}
|
||||
|
||||
func NormalizeIdentifier(fullname string) string {
|
||||
|
@ -4,18 +4,10 @@ import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
type ProfilePointer struct {
|
||||
PublicKey string
|
||||
Relays []string
|
||||
}
|
||||
|
||||
type EventPointer struct {
|
||||
ID string
|
||||
Relays []string
|
||||
}
|
||||
|
||||
func Decode(bech32string string) (prefix string, value any, err error) {
|
||||
prefix, bits5, err := decode(bech32string)
|
||||
if err != nil {
|
||||
@ -35,7 +27,7 @@ func Decode(bech32string string) (prefix string, value any, err error) {
|
||||
|
||||
return prefix, hex.EncodeToString(data[0:32]), nil
|
||||
case "nprofile":
|
||||
var result ProfilePointer
|
||||
var result nostr.ProfilePointer
|
||||
curr := 0
|
||||
for {
|
||||
t, v := readTLVEntry(data[curr:])
|
||||
@ -60,7 +52,7 @@ func Decode(bech32string string) (prefix string, value any, err error) {
|
||||
curr = curr + 2 + len(v)
|
||||
}
|
||||
case "nevent":
|
||||
var result EventPointer
|
||||
var result nostr.EventPointer
|
||||
curr := 0
|
||||
for {
|
||||
t, v := readTLVEntry(data[curr:])
|
||||
|
11
pointers.go
Normal file
11
pointers.go
Normal file
@ -0,0 +1,11 @@
|
||||
package nostr
|
||||
|
||||
type ProfilePointer struct {
|
||||
PublicKey string
|
||||
Relays []string
|
||||
}
|
||||
|
||||
type EventPointer struct {
|
||||
ID string
|
||||
Relays []string
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user