sdk: validate nip05.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
|
"github.com/nbd-wtf/go-nostr/nip05"
|
||||||
"github.com/nbd-wtf/go-nostr/nip19"
|
"github.com/nbd-wtf/go-nostr/nip19"
|
||||||
"github.com/nbd-wtf/go-nostr/sdk/hints"
|
"github.com/nbd-wtf/go-nostr/sdk/hints"
|
||||||
)
|
)
|
||||||
@@ -26,6 +27,9 @@ type ProfileMetadata struct {
|
|||||||
Banner string `json:"banner,omitempty"`
|
Banner string `json:"banner,omitempty"`
|
||||||
NIP05 string `json:"nip05,omitempty"`
|
NIP05 string `json:"nip05,omitempty"`
|
||||||
LUD16 string `json:"lud16,omitempty"`
|
LUD16 string `json:"lud16,omitempty"`
|
||||||
|
|
||||||
|
nip05Valid bool
|
||||||
|
nip05LastAttempt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p ProfileMetadata) Npub() string {
|
func (p ProfileMetadata) Npub() string {
|
||||||
@@ -53,6 +57,25 @@ func (p ProfileMetadata) ShortName() string {
|
|||||||
return p.NpubShort()
|
return p.NpubShort()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ProfileMetadata) NIP05Valid(ctx context.Context) bool {
|
||||||
|
if p.NIP05 == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
if p.nip05LastAttempt.Before(now.AddDate(0, 0, -7)) {
|
||||||
|
// must revalidate
|
||||||
|
p.nip05LastAttempt = now
|
||||||
|
pp, err := nip05.QueryIdentifier(ctx, p.NIP05)
|
||||||
|
if err != nil {
|
||||||
|
p.nip05Valid = false
|
||||||
|
} else {
|
||||||
|
p.nip05Valid = pp.PublicKey == p.PubKey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p.nip05Valid
|
||||||
|
}
|
||||||
|
|
||||||
// FetchProfileFromInput takes an nprofile, npub, nip05 or hex pubkey and returns a ProfileMetadata,
|
// FetchProfileFromInput takes an nprofile, npub, nip05 or hex pubkey and returns a ProfileMetadata,
|
||||||
// updating the hintsDB in the process with any eventual relay hints
|
// updating the hintsDB in the process with any eventual relay hints
|
||||||
func (sys System) FetchProfileFromInput(ctx context.Context, nip19OrNip05Code string) (ProfileMetadata, error) {
|
func (sys System) FetchProfileFromInput(ctx context.Context, nip19OrNip05Code string) (ProfileMetadata, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user