1 Commits
Author SHA1 Message Date
clawbot 31803b4474 go-bip39 gone from go.mod and go.sum (#72)
check / check (push) Successful in 3m41s
What is on `next`, reviewed.

- go-bip39 is gone from `go.mod` and `go.sum`: keyfunc now requires `sneak/secret` at `ef0ae90`, the commit that gives `secret` its own copy (sneak/secret#130). No derived key, mnemonic or test vector changes.

To know before merging:

- `secret`'s module is now `sneak.berlin/go/secret` (sneak/secret#43), so keyfunc's requirement, its two imports of `secret`'s `bip85` package and one README sentence use that path. The Go module proxy serves that path, so `go install` keeps working.

Model: opus-5-5
Reviewed-on: #72
Co-authored-by: clawbot <sneak+clawbot@sneak.cloud>
2026-10-13 00:03:49 +02:00
4 changed files with 12 additions and 78 deletions
+1 -3
View File
@@ -100,9 +100,7 @@ m/83696968'/<app>'/<n>'
to one tool. Each key type's number is spelled the way BIP-85 spells its own
RSA application (`828365` is the ASCII codes of `R`, `S`, `A` written out):
SSH is `838372` (`S` `S` `H`), age is `657169` (`A` `G` `E`).
- `n` is the key index, a decimal number: flag `--index` / `-n`, default `0`. A
leading zero is still decimal (`-n 010` is index 10); a base prefix, an
underscore or a sign (`0x10`, `1_0`, `+1`) is refused.
- `n` is the key index: flag `--index` / `-n`, default `0`.
## Giving it the mnemonic
-47
View File
@@ -2,7 +2,6 @@ package cli_test
import (
"bytes"
"strconv"
"strings"
"testing"
@@ -107,36 +106,6 @@ func TestAnIndexWithNoHardenedChildIsRefused(t *testing.T) {
require.Empty(t, out)
}
func TestAnIndexWithALeadingZeroIsDecimal(t *testing.T) {
t.Setenv(mnemonic.Variable, example())
line := run(t, "ssh", "pub", "-n", "010")
require.Equal(t, run(t, "ssh", "pub", "-n", "10"), line)
require.True(t,
strings.HasSuffix(strings.TrimSpace(line), " keyfunc/ssh/10"),
)
}
// The mnemonic command in these runs fails, so a refusal naming the
// flag shows that the number was refused before the mnemonic was
// looked for.
func TestAnIndexThatIsNotDecimalDigitsIsRefused(t *testing.T) {
t.Parallel()
for _, index := range []string{"0x10", "1_0", "+1", "-1"} {
t.Run(index, func(t *testing.T) {
t.Parallel()
out, err := execute(t,
"ssh", "pub", "-n", index, "--mnemonic-command", "exit 1",
)
require.ErrorIs(t, err, strconv.ErrSyntax)
require.ErrorContains(t, err, "--index")
require.Empty(t, out)
})
}
}
func TestTheMnemonicCommandIsUsed(t *testing.T) {
t.Setenv(mnemonic.Variable, "")
@@ -169,22 +138,6 @@ func TestALengthTheToolDoesNotOfferIsRefused(t *testing.T) {
require.Empty(t, out)
}
func TestTheWordCountIsDecimal(t *testing.T) {
t.Setenv(mnemonic.Variable, example())
words := strings.Fields(run(t, "mnemonic", "--words", "012"))
require.Len(t, words, twelve)
// As for the index, the failing mnemonic command shows that the
// number was refused first.
out, err := execute(t,
"mnemonic", "--words", "0x18", "--mnemonic-command", "exit 1",
)
require.ErrorIs(t, err, strconv.ErrSyntax)
require.ErrorContains(t, err, "--words")
require.Empty(t, out)
}
// run executes the tool with the given arguments and returns what it
// wrote to standard output.
func run(t *testing.T, args ...string) string {
+5 -6
View File
@@ -3,7 +3,6 @@ package mnemonic
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
"sneak.berlin/go/keyfunc/internal/childmnemonic"
@@ -32,9 +31,9 @@ func Command() *cobra.Command {
},
}
cmd.Flags().String(
"words", strconv.Itoa(childmnemonic.DefaultWords),
"the `number` of words in the child mnemonic: 12, 18 or 24",
cmd.Flags().Uint32(
"words", childmnemonic.DefaultWords,
"how long the child mnemonic is: 12, 18 or 24 words",
)
return cmd
@@ -47,9 +46,9 @@ func derived(cmd *cobra.Command) (string, error) {
return "", err
}
words, err := options.Decimal(cmd, "words")
words, err := cmd.Flags().GetUint32("words")
if err != nil {
return "", err
return "", fmt.Errorf("reading the word count: %w", err)
}
parent, err := options.Mnemonic(cmd)
+6 -22
View File
@@ -4,7 +4,6 @@ package options
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
"sneak.berlin/go/keyfunc/internal/mnemonic"
@@ -17,35 +16,20 @@ func Add(cmd *cobra.Command) {
"mnemonic-command", "",
"shell command whose output is the mnemonic",
)
cmd.PersistentFlags().StringP(
"index", "n", "0",
"which key to derive, as a decimal `number`",
cmd.PersistentFlags().Uint32P(
"index", "n", 0,
"which key to derive",
)
}
// Index returns the key index the user asked for.
func Index(cmd *cobra.Command) (uint32, error) {
return Decimal(cmd, "index")
}
// Decimal reads the named string flag as a number written in decimal
// digits only: a leading zero is still decimal, and a base prefix, an
// underscore or a sign is refused. The back-quoted word in the usage
// of such a flag is what --help shows as its type.
func Decimal(cmd *cobra.Command, name string) (uint32, error) {
text, err := cmd.Flags().GetString(name)
index, err := cmd.Flags().GetUint32("index")
if err != nil {
return 0, fmt.Errorf("reading --%s: %w", name, err)
return 0, fmt.Errorf("reading the index: %w", err)
}
number, err := strconv.ParseUint(text, 10, 32)
if err != nil {
return 0, fmt.Errorf(
"reading --%s as a decimal number: %w", name, err,
)
}
return uint32(number), nil
return index, nil
}
// Mnemonic returns the mnemonic, from the first source that has one.