fix reading hex secret key from input.

This commit is contained in:
fiatjaf 2024-02-02 14:11:58 -03:00
parent 0d46d48881
commit bda18e035a
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -147,12 +147,12 @@ func gatherSecretKeyFromArguments(c *cli.Context) (string, error) {
if err != nil { if err != nil {
return "", fmt.Errorf("failed to decrypt: %w", err) return "", fmt.Errorf("failed to decrypt: %w", err)
} }
} else if bsec, err := hex.DecodeString(strings.Repeat("0", 64-len(sec)) + sec); err == nil {
sec = hex.EncodeToString(bsec)
} else if prefix, hexvalue, err := nip19.Decode(sec); err != nil { } else if prefix, hexvalue, err := nip19.Decode(sec); err != nil {
return "", fmt.Errorf("invalid nsec: %w", err) return "", fmt.Errorf("invalid nsec: %w", err)
} else if prefix == "nsec" { } else if prefix == "nsec" {
sec = hexvalue.(string) sec = hexvalue.(string)
} else if bsec, err := hex.DecodeString(strings.Repeat("0", 64-len(sec)) + sec); err == nil {
sec = hex.EncodeToString(bsec)
} }
if ok := nostr.IsValid32ByteHex(sec); !ok { if ok := nostr.IsValid32ByteHex(sec); !ok {