Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b117dba1e1 |
@@ -6,7 +6,7 @@ identities and child mnemonics, each of which can be recreated from that
|
||||
mnemonic at any time. The same mnemonic, key type and index always give the same
|
||||
key.
|
||||
|
||||
It uses the BIP-85 entropy deriver from `sneak.berlin/go/secret/pkg/bip85` and
|
||||
It uses the BIP-85 entropy deriver from `git.eeqj.de/sneak/secret/pkg/bip85` and
|
||||
takes the same steps as that repository's `agehd` package.
|
||||
|
||||
Commands are grouped by what is derived: `keyfunc ssh ...` for ed25519 SSH keys,
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ go 1.26.0
|
||||
|
||||
require (
|
||||
filippo.io/age v1.3.2
|
||||
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd
|
||||
github.com/btcsuite/btcd v0.25.0
|
||||
github.com/btcsuite/btcd/btcutil v1.2.0
|
||||
github.com/spf13/cobra v1.10.2
|
||||
github.com/stretchr/testify v1.12.1
|
||||
golang.org/x/crypto v0.57.0
|
||||
golang.org/x/term v0.46.0
|
||||
sneak.berlin/go/secret v0.0.0-20261007105610-ef0ae90768c8
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@@ -4,6 +4,8 @@ filippo.io/age v1.3.2 h1:r6RSZLFSMm6rzKepZ7ZAYkKCu14f3/Me8c7uKYh7C8c=
|
||||
filippo.io/age v1.3.2/go.mod h1:TH/Yr2sSRhCKbaH4XPxpUV0Us8Gv6txYUpiZQWz8Evk=
|
||||
filippo.io/hpke v0.4.0 h1:p575VVQ6ted4pL+it6M00V/f2qTZITO0zgmdKCkd5+A=
|
||||
filippo.io/hpke v0.4.0/go.mod h1:EmAN849/P3qdeK+PCMkDpDm83vRHM5cDipBJ8xbQLVY=
|
||||
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd h1:6YFV6horz2wDFPWWhour8qx8gLGyO0qoplwEeOuQ2J4=
|
||||
git.eeqj.de/sneak/secret v0.0.0-20260810132333-41cea400a7fd/go.mod h1:gKCcMZvlBOqusn/BxR8IyFmSJQr6R4vvjJ926iNpOSI=
|
||||
github.com/btcsuite/btcd v0.25.0 h1:JPbjwvHGpSywBRuorFFqTjaVP4y6Qw69XJ1nQ6MyWJM=
|
||||
github.com/btcsuite/btcd v0.25.0/go.mod h1:qbPE+pEiR9643E1s1xu57awsRhlCIm1ZIi6FfeRA4KE=
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.5.0 h1:KioMXOWa76b86sTZZOmbzv/ldaQCmB8KFAyn5PbB8E8=
|
||||
@@ -28,6 +30,8 @@ github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
|
||||
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
|
||||
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
|
||||
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
|
||||
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
|
||||
@@ -38,5 +42,3 @@ golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE=
|
||||
golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
sneak.berlin/go/secret v0.0.0-20261007105610-ef0ae90768c8 h1:Bd2bUsRCN8xhcrpH3LpJqHxR2QffeOuF5z76iP4BFnw=
|
||||
sneak.berlin/go/secret v0.0.0-20261007105610-ef0ae90768c8/go.mod h1:uVx9ZuE7ZMIOBY2B1ElXCs97CTsEfuham3NQRdLj5lI=
|
||||
|
||||
@@ -56,104 +56,6 @@ func TestPadByteSlice(t *testing.T) {
|
||||
assertEqualByteSlices(t, []byte{1, 1, 1}, padByteSlice([]byte{1, 1, 1}, 2))
|
||||
}
|
||||
|
||||
//nolint:funlen // the test vectors, kept as upstream wrote them
|
||||
func TestMnemonicToByteArrayForZeroLeadingSeeds(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ms := []string{
|
||||
"00000000000000000000000000000000",
|
||||
"00a84c51041d49acca66e6160c1fa999",
|
||||
"00ca45df1673c76537a2020bfed1dafd",
|
||||
"0019d5871c7b81fd83d474ef1c1e1dae",
|
||||
"00dcb021afb35ffcdd1d032d2056fc86",
|
||||
"0062be7bd09a27288b6cf0eb565ec739",
|
||||
"00dc705b5efa0adf25b9734226ba60d4",
|
||||
"0017747418d54c6003fa64fade83374b",
|
||||
"000d44d3ee7c3dfa45e608c65384431b",
|
||||
"008241c1ef976b0323061affe5bf24b9",
|
||||
"00a6aec77e4d16bea80b50a34991aaba",
|
||||
"0011527b8c6ddecb9d0c20beccdeb58d",
|
||||
"001c938c503c8f5a2bba2248ff621546",
|
||||
"0002f90aaf7a8327698f0031b6317c36",
|
||||
"00bff43071ed7e07f77b14f615993bac",
|
||||
"00da143e00ef17fc63b6fb22dcc2c326",
|
||||
"00ffc6764fb32a354cab1a3ddefb015d",
|
||||
"0062ef47e0985e8953f24760b7598cdd",
|
||||
"003bf9765064f71d304908d906c065f5",
|
||||
"00993851503471439d154b3613947474",
|
||||
"007ad0ffe9eae753a483a76af06dfa67",
|
||||
"00091824db9ec19e663bee51d64c83cc",
|
||||
"00f48ac621f7e3cb39b2012ac3121543",
|
||||
"0072917415cdca24dfa66c4a92c885b4",
|
||||
"0027ced2b279ea8a91d29364487cdbf4",
|
||||
"00b9c0d37fb10ba272e55842ad812583",
|
||||
"004b3d0d2b9285946c687a5350479c8c",
|
||||
"00c7c12a37d3a7f8c1532b17c89b724c",
|
||||
"00f400c5545f06ae17ad00f3041e4e26",
|
||||
"001e290be10df4d209f247ac5878662b",
|
||||
"00bf0f74568e582a7dd1ee64f792ec8b",
|
||||
"00d2e43ecde6b72b847db1539ed89e23",
|
||||
"00cecba6678505bb7bfec8ed307251f6",
|
||||
"000aeed1a9edcbb4bc88f610d3ce84eb",
|
||||
"00d06206aadfc25c2b21805d283f15ae",
|
||||
"00a31789a2ab2d54f8fadd5331010287",
|
||||
"003493c5f520e8d5c0483e895a121dc9",
|
||||
"004706112800b76001ece2e268bc830e",
|
||||
"00ab31e28bb5305be56e38337dbfa486",
|
||||
"006872fe85df6b0fa945248e6f9379d1",
|
||||
"00717e5e375da6934e3cfdf57edaf3bd",
|
||||
"007f1b46e7b9c4c76e77c434b9bccd6b",
|
||||
"00dc93735aa35def3b9a2ff676560205",
|
||||
"002cd5dcd881a49c7b87714c6a570a76",
|
||||
"0013b5af9e13fac87e0c505686cfb6bf",
|
||||
"007ab1ec9526b0bc04b64ae65fd42631",
|
||||
"00abb4e11d8385c1cca905a6a65e9144",
|
||||
"00574fc62a0501ad8afada2e246708c3",
|
||||
"005207e0a815bb2da6b4c35ec1f2bf52",
|
||||
"00f3460f136fb9700080099cbd62bc18",
|
||||
"007a591f204c03ca7b93981237112526",
|
||||
"00cfe0befd428f8e5f83a5bfc801472e",
|
||||
"00987551ac7a879bf0c09b8bc474d9af",
|
||||
"00cadd3ce3d78e49fbc933a85682df3f",
|
||||
"00bfbf2e346c855ccc360d03281455a1",
|
||||
"004cdf55d429d028f715544ce22d4f31",
|
||||
"0075c84a7d15e0ac85e1e41025eed23b",
|
||||
"00807dddd61f71725d336cab844d2cb5",
|
||||
"00422f21b77fe20e367467ed98c18410",
|
||||
"00b44d0ac622907119c626c850a462fd",
|
||||
"00363f5e7f22fc49f3cd662a28956563",
|
||||
"000fe5837e68397bbf58db9f221bdc4e",
|
||||
"0056af33835c888ef0c22599686445d3",
|
||||
"00790a8647fd3dfb38b7e2b6f578f2c6",
|
||||
"00da8d9009675cb7beec930e263014fb",
|
||||
"00d4b384540a5bb54aa760edaa4fb2fe",
|
||||
"00be9b1479ed680fdd5d91a41eb926d0",
|
||||
"009182347502af97077c40a6e74b4b5c",
|
||||
"00f5c90ee1c67fa77fd821f8e9fab4f1",
|
||||
"005568f9a2dd6b0c0cc2f5ba3d9cac38",
|
||||
"008b481f8678577d9cf6aa3f6cd6056b",
|
||||
"00c4323ece5e4fe3b6cd4c5c932931af",
|
||||
"009791f7550c3798c5a214cb2d0ea773",
|
||||
"008a7baab22481f0ad8167dd9f90d55c",
|
||||
"00f0e601519aafdc8ff94975e64c946d",
|
||||
"0083b61e0daa9219df59d697c270cd31",
|
||||
}
|
||||
|
||||
for _, m := range ms {
|
||||
seed, _ := hex.DecodeString(m)
|
||||
|
||||
mnemonic, err := NewMnemonic(seed)
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
_, err = EntropyFromMnemonic(mnemonic)
|
||||
if err != nil {
|
||||
t.Errorf("Failed for %x - %v", seed, mnemonic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEntropyFromMnemonic128(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.eeqj.de/sneak/secret/pkg/bip85"
|
||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||
"sneak.berlin/go/keyfunc/internal/bip39"
|
||||
"sneak.berlin/go/keyfunc/internal/derive"
|
||||
"sneak.berlin/go/secret/pkg/bip85"
|
||||
)
|
||||
|
||||
// english is the number BIP-85 gives the English word list.
|
||||
|
||||
@@ -2,7 +2,6 @@ package cli_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -107,56 +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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Neither a command group nor --version reads the index, so these
|
||||
// show that it is refused while the flags are parsed.
|
||||
func TestAnIndexNotInDecimalIsRefusedBeforeAnyCommandRuns(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, args := range [][]string{
|
||||
{"ssh", "-n", "0x10"},
|
||||
{"-n", "0x10", "--version"},
|
||||
} {
|
||||
t.Run(strings.Join(args, " "), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
out, err := execute(t, args...)
|
||||
require.ErrorIs(t, err, strconv.ErrSyntax)
|
||||
require.ErrorContains(t, err, "--index")
|
||||
require.Empty(t, out)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheMnemonicCommandIsUsed(t *testing.T) {
|
||||
t.Setenv(mnemonic.Variable, "")
|
||||
|
||||
@@ -189,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 {
|
||||
|
||||
@@ -31,9 +31,8 @@ func Command() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
words := options.Decimal(childmnemonic.DefaultWords)
|
||||
cmd.Flags().Var(
|
||||
&words, "words",
|
||||
cmd.Flags().Uint32(
|
||||
"words", childmnemonic.DefaultWords,
|
||||
"how long the child mnemonic is: 12, 18 or 24 words",
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ package options
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||
@@ -17,8 +16,8 @@ func Add(cmd *cobra.Command) {
|
||||
"mnemonic-command", "",
|
||||
"shell command whose output is the mnemonic",
|
||||
)
|
||||
cmd.PersistentFlags().VarP(
|
||||
new(Decimal), "index", "n",
|
||||
cmd.PersistentFlags().Uint32P(
|
||||
"index", "n", 0,
|
||||
"which key to derive",
|
||||
)
|
||||
}
|
||||
@@ -42,33 +41,3 @@ func Mnemonic(cmd *cobra.Command) (string, error) {
|
||||
|
||||
return mnemonic.Read(cmd.Context(), command)
|
||||
}
|
||||
|
||||
// Decimal is a flag value for a number written in decimal digits only.
|
||||
// The flag library's own uint32 flags read 010 as octal 8 and also
|
||||
// take 0x10 or 1_0.
|
||||
type Decimal uint32
|
||||
|
||||
// String returns the number in decimal digits.
|
||||
func (d *Decimal) String() string {
|
||||
return strconv.FormatUint(uint64(*d), 10)
|
||||
}
|
||||
|
||||
// Set reads text as a decimal number that fits in 32 bits: a leading
|
||||
// zero is still decimal, and a base prefix, an underscore or a sign is
|
||||
// refused.
|
||||
func (d *Decimal) Set(text string) error {
|
||||
number, err := strconv.ParseUint(text, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*d = Decimal(number)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Type is what --help shows as the flag's type, and what GetUint32
|
||||
// checks before it reads the value back.
|
||||
func (d *Decimal) Type() string {
|
||||
return "uint32"
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.eeqj.de/sneak/secret/pkg/bip85"
|
||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"sneak.berlin/go/keyfunc/internal/bip39"
|
||||
"sneak.berlin/go/secret/pkg/bip85"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user