Drop the BIP39 passphrase from cbk
The seed is always computed with an empty passphrase; Params is just the mnemonic and the BIP85 index.
This commit is contained in:
+9
-53
@@ -16,9 +16,9 @@ import (
|
||||
)
|
||||
|
||||
// The BIP85 specification publishes its test vectors against one master
|
||||
// key. specMnemonic is the BIP39 phrase that produces that master key with
|
||||
// an empty passphrase, so the whole mnemonic-to-entropy chain this package
|
||||
// relies on can be checked against the specification.
|
||||
// key. specMnemonic is the BIP39 phrase that produces that master key, so
|
||||
// the whole mnemonic-to-entropy chain this package relies on can be
|
||||
// checked against the specification.
|
||||
const (
|
||||
specMnemonic = "install scatter logic circle pencil average fall shoe " +
|
||||
"quantum disease suspect usage"
|
||||
@@ -72,11 +72,7 @@ func TestPrivateKeyIsBIP85HexApplicationOutput(t *testing.T) {
|
||||
expected, err := bip85.DeriveHex(masterKey, cbk.KeySize, index)
|
||||
require.NoError(t, err)
|
||||
|
||||
keypair, err := cbk.New(cbk.Params{
|
||||
Mnemonic: specMnemonic,
|
||||
Passphrase: "",
|
||||
Index: index,
|
||||
})
|
||||
keypair, err := cbk.New(cbk.Params{Mnemonic: specMnemonic, Index: index})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, expected, keypair.PrivateKeyHex(), "index %d", index)
|
||||
@@ -86,10 +82,10 @@ func TestPrivateKeyIsBIP85HexApplicationOutput(t *testing.T) {
|
||||
func TestNewIndexSelectsIndependentKeypairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
first, err := cbk.New(cbk.Params{Mnemonic: specMnemonic, Passphrase: "", Index: 0})
|
||||
first, err := cbk.New(cbk.Params{Mnemonic: specMnemonic, Index: 0})
|
||||
require.NoError(t, err)
|
||||
|
||||
second, err := cbk.New(cbk.Params{Mnemonic: specMnemonic, Passphrase: "", Index: 1})
|
||||
second, err := cbk.New(cbk.Params{Mnemonic: specMnemonic, Index: 1})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotEqual(t, first.PublicKey, second.PublicKey)
|
||||
@@ -103,18 +99,10 @@ func TestNewIndexSelectsIndependentKeypairs(t *testing.T) {
|
||||
func TestNewRejectsIndexBeyondHardenedRange(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := cbk.New(cbk.Params{
|
||||
Mnemonic: specMnemonic,
|
||||
Passphrase: "",
|
||||
Index: cbk.MaxIndex + 1,
|
||||
})
|
||||
_, err := cbk.New(cbk.Params{Mnemonic: specMnemonic, Index: cbk.MaxIndex + 1})
|
||||
require.ErrorIs(t, err, cbk.ErrIndexTooLarge)
|
||||
|
||||
_, err = cbk.New(cbk.Params{
|
||||
Mnemonic: specMnemonic,
|
||||
Passphrase: "",
|
||||
Index: cbk.MaxIndex,
|
||||
})
|
||||
_, err = cbk.New(cbk.Params{Mnemonic: specMnemonic, Index: cbk.MaxIndex})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -128,44 +116,12 @@ func TestNewNormalizesMnemonic(t *testing.T) {
|
||||
messy := " " + strings.ToUpper(words[0]) + "\t" +
|
||||
strings.Join(words[1:], " ") + "\n"
|
||||
|
||||
normalized, err := cbk.New(cbk.Params{
|
||||
Mnemonic: messy,
|
||||
Passphrase: "",
|
||||
Index: 0,
|
||||
})
|
||||
normalized, err := cbk.New(cbk.Params{Mnemonic: messy, Index: 0})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, canonical, normalized)
|
||||
}
|
||||
|
||||
func TestNewPassphraseChangesKeys(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
plain, err := cbk.FromMnemonic(specMnemonic)
|
||||
require.NoError(t, err)
|
||||
|
||||
extraWord := "TREZOR"
|
||||
|
||||
withExtraWord, err := cbk.New(cbk.Params{
|
||||
Mnemonic: specMnemonic,
|
||||
Passphrase: extraWord,
|
||||
Index: 0,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotEqual(t, plain.PublicKey, withExtraWord.PublicKey)
|
||||
assert.NotEqual(t, plain.PrivateKey, withExtraWord.PrivateKey)
|
||||
|
||||
again, err := cbk.New(cbk.Params{
|
||||
Mnemonic: specMnemonic,
|
||||
Passphrase: extraWord,
|
||||
Index: 0,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, withExtraWord, again, "derivation is deterministic")
|
||||
}
|
||||
|
||||
func TestNewDifferentMnemonicsGiveDifferentKeys(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user