mirror of
https://github.com/fiatjaf/nak.git
synced 2025-08-31 22:10:47 -04:00
nsecbunker work-in-progress.
This commit is contained in:
31
event.go
31
event.go
@@ -9,10 +9,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bgentry/speakeasy"
|
||||
"github.com/mailru/easyjson"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nip19"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/exp/slices"
|
||||
@@ -106,31 +104,10 @@ example:
|
||||
}
|
||||
}
|
||||
|
||||
// gather the secret key first
|
||||
sec := c.String("sec")
|
||||
if c.Bool("prompt-sec") {
|
||||
if isPiped() {
|
||||
return fmt.Errorf("can't prompt for a secret key when processing data from a pipe, try again without --prompt-sec")
|
||||
}
|
||||
var err error
|
||||
sec, err = speakeasy.FAsk(os.Stderr, "type your secret key as nsec or hex: ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get secret key: %w", err)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(sec, "nsec1") {
|
||||
_, hex, err := nip19.Decode(sec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid nsec: %w", err)
|
||||
}
|
||||
sec = hex.(string)
|
||||
}
|
||||
if len(sec) > 64 {
|
||||
return fmt.Errorf("invalid secret key: too large")
|
||||
}
|
||||
sec = strings.Repeat("0", 64-len(sec)) + sec // left-pad
|
||||
if err := validate32BytesHex(sec); err != nil {
|
||||
return fmt.Errorf("invalid secret key")
|
||||
// gather the secret key
|
||||
sec, err := gatherSecretKeyFromArguments(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// then process input and generate events
|
||||
|
Reference in New Issue
Block a user