mirror of
https://github.com/fiatjaf/nak.git
synced 2026-10-05 15:18:23 +00:00
trim nostr: prefix so it works again on fetch and flags.
This commit is contained in:
@@ -43,6 +43,7 @@ var fetch = &cli.Command{
|
||||
}
|
||||
|
||||
for code := range getStdinLinesOrArguments(c.Args()) {
|
||||
code = strings.TrimPrefix(code, "nostr:")
|
||||
var filter nostr.Filter
|
||||
var authorHint nostr.PubKey
|
||||
relays := c.StringSlice("relay")
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"fiatjaf.com/nostr"
|
||||
@@ -253,6 +254,7 @@ func (t pubKeyOrAddressValue) ToString(b PubKeyOrAddress) string {
|
||||
}
|
||||
|
||||
func (t *pubKeyOrAddressValue) Set(value string) error {
|
||||
value = strings.TrimPrefix(value, "nostr:")
|
||||
pubkey, err1 := parsePubKey(value)
|
||||
if err1 == nil {
|
||||
t.value = PubKeyOrAddress{PubKey: pubkey}
|
||||
|
||||
@@ -476,6 +476,7 @@ func askConfirmation(msg string) bool {
|
||||
}
|
||||
|
||||
func parsePubKey(value string) (nostr.PubKey, error) {
|
||||
value = strings.TrimPrefix(value, "nostr:")
|
||||
if nip05.IsValidIdentifier(value) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
|
||||
pp, err := nip05.QueryIdentifier(ctx, value)
|
||||
@@ -508,6 +509,7 @@ func parsePubKey(value string) (nostr.PubKey, error) {
|
||||
}
|
||||
|
||||
func parseSecretKey(input string) (nostr.SecretKey, error) {
|
||||
input = strings.TrimPrefix(input, "nostr:")
|
||||
if prefix, ski, err := nip19.Decode(input); err == nil && prefix == "nsec" {
|
||||
return ski.(nostr.SecretKey), nil
|
||||
}
|
||||
@@ -521,6 +523,7 @@ func parseSecretKey(input string) (nostr.SecretKey, error) {
|
||||
}
|
||||
|
||||
func parseEventID(value string) (nostr.ID, error) {
|
||||
value = strings.TrimPrefix(value, "nostr:")
|
||||
id, err := nostr.IDFromHex(value)
|
||||
if err == nil {
|
||||
return id, nil
|
||||
|
||||
Reference in New Issue
Block a user