left pad keys on nak key too so nak key public 02 works, for example.

This commit is contained in:
fiatjaf 2024-07-12 14:04:14 -03:00
parent 79cb63a1b4
commit 27f925c05e
2 changed files with 6 additions and 1 deletions

View File

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

1
key.go
View File

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