nsecbunker work-in-progress.

This commit is contained in:
fiatjaf
2023-12-02 12:18:55 -03:00
parent 5657fdc6a7
commit bc7cd0939c
6 changed files with 167 additions and 30 deletions

View File

@@ -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