accept bunker URIs in $NOSTR_SECRET_KEY, simplify.

fixes https://github.com/fiatjaf/nak/issues/66
This commit is contained in:
fiatjaf
2025-05-20 23:31:54 -03:00
parent 4387595437
commit aa89093d57
2 changed files with 5 additions and 20 deletions

View File

@@ -20,10 +20,12 @@ import (
var defaultKeyFlags = []cli.Flag{
&cli.StringFlag{
Name: "sec",
Usage: "secret key to sign the event, as nsec, ncryptsec or hex, or a bunker URL, it is more secure to use the environment variable NOSTR_SECRET_KEY than this flag",
Usage: "secret key to sign the event, as nsec, ncryptsec or hex, or a bunker URL",
DefaultText: "the key '1'",
Aliases: []string{"connect"},
Category: CATEGORY_SIGNER,
Sources: cli.EnvVars("NOSTR_SECRET_KEY"),
Value: nostr.KeyOne.Hex(),
HideDefault: true,
},
&cli.BoolFlag{
Name: "prompt-sec",
@@ -80,15 +82,6 @@ func gatherSecretKeyOrBunkerFromArguments(ctx context.Context, c *cli.Command) (
return nostr.SecretKey{}, bunker, err
}
// take private from flags, environment variable or default to 1
if sec == "" {
if key, ok := os.LookupEnv("NOSTR_SECRET_KEY"); ok {
sec = key
} else {
sec = "0000000000000000000000000000000000000000000000000000000000000001"
}
}
if c.Bool("prompt-sec") {
var err error
sec, err = askPassword("type your secret key as ncryptsec, nsec or hex: ", nil)