diff --git a/helpers.go b/helpers.go index 52da7d7..e3b1348 100644 --- a/helpers.go +++ b/helpers.go @@ -210,7 +210,7 @@ func gatherSecretKeyOrBunkerFromArguments(ctx context.Context, c *cli.Command) ( if err != nil { return "", nil, fmt.Errorf("failed to decrypt: %w", err) } - } else if bsec, err := hex.DecodeString(strings.Repeat("0", 64-len(sec)) + sec); err == nil { + } else if bsec, err := hex.DecodeString(leftPadKey(sec)); err == nil { sec = hex.EncodeToString(bsec) } else if prefix, hexvalue, err := nip19.Decode(sec); err != nil { return "", nil, fmt.Errorf("invalid nsec: %w", err) @@ -284,3 +284,7 @@ func randString(n int) string { } return string(b) } + +func leftPadKey(k string) string { + return strings.Repeat("0", 64-len(k)) + k +} diff --git a/key.go b/key.go index f885b14..7c9d28a 100644 --- a/key.go +++ b/key.go @@ -269,6 +269,7 @@ func getSecretKeysFromStdinLinesOrSlice(ctx context.Context, c *cli.Command, key } sec = data.(string) } + sec = leftPadKey(sec) if !nostr.IsValid32ByteHex(sec) { ctx = lineProcessingError(ctx, "invalid hex key") continue