mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-11-18 18:16:50 +01:00
nip61, and related modifications to nip60.
This commit is contained in:
61
nip61/info.go
Normal file
61
nip61/info.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package nip61
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"github.com/elnosh/gonuts/cashu"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
type Info struct {
|
||||
PublicKey string
|
||||
Mints []string
|
||||
Relays []string
|
||||
}
|
||||
|
||||
func (zi *Info) toEvent(ctx context.Context, kr nostr.Keyer, evt *nostr.Event) error {
|
||||
evt.CreatedAt = nostr.Now()
|
||||
evt.Kind = 10019
|
||||
|
||||
evt.Tags = make(nostr.Tags, 0, len(zi.Mints)+len(zi.Relays)+1)
|
||||
for _, mint := range zi.Mints {
|
||||
evt.Tags = append(evt.Tags, nostr.Tag{"mint", mint})
|
||||
}
|
||||
for _, url := range zi.Relays {
|
||||
evt.Tags = append(evt.Tags, nostr.Tag{"relay", url})
|
||||
}
|
||||
if zi.PublicKey != "" {
|
||||
evt.Tags = append(evt.Tags, nostr.Tag{"pubkey", zi.PublicKey})
|
||||
}
|
||||
|
||||
if err := kr.SignEvent(ctx, evt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (zi *Info) parse(evt *nostr.Event) error {
|
||||
zi.Mints = make([]string, 0)
|
||||
for _, tag := range evt.Tags {
|
||||
if len(tag) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
switch tag[0] {
|
||||
case "mint":
|
||||
if len(tag) == 2 || slices.Contains(tag[2:], cashu.Sat.String()) {
|
||||
zi.Mints = append(zi.Mints, "http"+nostr.NormalizeURL(tag[1])[2:])
|
||||
}
|
||||
case "relay":
|
||||
zi.Relays = append(zi.Relays, tag[1])
|
||||
case "pubkey":
|
||||
if nostr.IsValidPublicKey(tag[1]) {
|
||||
zi.PublicKey = tag[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user