From 318838b3ff108fc92a28d9a5b3f6a596ecb1865e Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 3 Apr 2026 01:36:03 -0300 Subject: [PATCH] key: a command for expanding partial keys by left-padding with zeroes. --- key.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/key.go b/key.go index 2779740..56a6bb7 100644 --- a/key.go +++ b/key.go @@ -23,6 +23,7 @@ var key = &cli.Command{ Commands: []*cli.Command{ generate, public, + expand, encryptKey, decryptKey, combine, @@ -67,6 +68,37 @@ var public = &cli.Command{ }, } +var expand = &cli.Command{ + Name: "expand", + Usage: "left-pads a hex key to 64 characters", + Description: ``, + ArgsUsage: "[key]", + DisableSliceFlagSeparator: true, + Action: func(ctx context.Context, c *cli.Command) error { + for keyhex := range getStdinLinesOrArgumentsFromSlice(c.Args().Slice()) { + keyhex = strings.TrimSpace(keyhex) + if keyhex == "" { + continue + } + if len(keyhex) > 64 { + ctx = lineProcessingError(ctx, "invalid hex key: length %d", len(keyhex)) + continue + } + check := keyhex + if len(check)%2 == 1 { + check = "0" + check + } + if _, err := hex.DecodeString(check); err != nil { + ctx = lineProcessingError(ctx, "invalid hex key: %s", err) + continue + } + keyhex = strings.ToLower(keyhex) + stdout(strings.Repeat("0", 64-len(keyhex)) + keyhex) + } + return nil + }, +} + var encryptKey = &cli.Command{ Name: "encrypt", Usage: "encrypts a secret key and prints an ncryptsec code",