Derive the vault key from the mnemonic's words however they are spaced (closes #135)
check / check (push) Failing after 4s

The long-term key was derived from the mnemonic text exactly as typed,
so a double space, a tab or a trailing newline gave a different key,
and a vault made that way did not open with the same words typed
normally. agehd.DeriveEntropy, which init, vault create, vault import,
unlocker add and every unlock go through, now joins the words with
single spaces and puts them in Unicode NFKD, as BIP39 defines the
seed's input, before hashing them. golang.org/x/text, already an
indirect dependency, becomes a direct one for the NFKD step.

Judgement call: internal/bip39's NewSeed keeps hashing its input as
given, as upstream does; the normalising is in agehd.

Model: opus-5-5
This commit was merged in pull request #160.
This commit is contained in:
2026-10-13 01:09:36 +02:00
parent 2d6675a452
commit fd6c5df1a8
4 changed files with 43 additions and 3 deletions
+28
View File
@@ -175,6 +175,34 @@ func TestDeterministicDerivation(t *testing.T) {
t.Logf("Index 1: %s", id3.String())
}
// TestDeriveIdentityIgnoresExtraWhitespace checks that the same words give
// the same identity however they are spaced, as when a mnemonic is typed or
// pasted with a double space or a trailing newline.
func TestDeriveIdentityIgnoresExtraWhitespace(t *testing.T) {
t.Parallel()
want, err := DeriveIdentity(mnemonic, 0)
if err != nil {
t.Fatalf("derive: %v", err)
}
typedMnemonics := []string{
strings.Replace(mnemonic, " ", " ", 1) + " ",
"\t" + strings.ReplaceAll(mnemonic, " ", "\n") + "\n",
}
for _, typed := range typedMnemonics {
got, err := DeriveIdentity(typed, 0)
if err != nil {
t.Fatalf("derive from %q: %v", typed, err)
}
if got.String() != want.String() {
t.Errorf("%q derives a different identity from %q", typed, mnemonic)
}
}
}
func TestDeterministicXPRVDerivation(t *testing.T) {
t.Parallel()