walletunlocker+keychain+config_builder: use new aezeed version

This commit is contained in:
Oliver Gugger
2022-05-12 12:47:13 +02:00
parent daa5966119
commit 51a480129b
4 changed files with 26 additions and 11 deletions

View File

@ -965,14 +965,13 @@ func waitForWalletPassword(cfg *Config,
// seed. If it's greater than the current key derivation // seed. If it's greater than the current key derivation
// version, then we'll return an error as we don't understand // version, then we'll return an error as we don't understand
// this. // this.
const latestVersion = keychain.KeyDerivationVersion
if cipherSeed != nil && if cipherSeed != nil &&
cipherSeed.InternalVersion != latestVersion { !keychain.IsKnownVersion(cipherSeed.InternalVersion) {
return nil, fmt.Errorf("invalid internal "+ return nil, fmt.Errorf("invalid internal "+
"seed version %v, current version is %v", "seed version %v, current max version is %v",
cipherSeed.InternalVersion, cipherSeed.InternalVersion,
keychain.KeyDerivationVersion) keychain.CurrentKeyDerivationVersion)
} }
loader, err := btcwallet.NewWalletLoader( loader, err := btcwallet.NewWalletLoader(

View File

@ -8,11 +8,20 @@ import (
) )
const ( const (
// KeyDerivationVersion is the version of the key derivation schema // KeyDerivationVersionLegacy is the previous version of the key
// defined below. We use a version as this means that we'll be able to // derivation schema defined below. We use a version as this means that
// accept new seed in the future and be able to discern if the software // we'll be able to accept new seed in the future and be able to discern
// is compatible with the version of the seed. // if the software is compatible with the version of the seed.
KeyDerivationVersion = 0 KeyDerivationVersionLegacy = 0
// KeyDerivationVersionTaproot is the most recent version of the key
// derivation scheme that marks the introduction of the Taproot
// derivation with BIP0086 support.
KeyDerivationVersionTaproot = 1
// CurrentKeyDerivationVersion is the current default key derivation
// version that is used for new seeds.
CurrentKeyDerivationVersion = KeyDerivationVersionTaproot
// BIP0043Purpose is the "purpose" value that we'll use for the first // BIP0043Purpose is the "purpose" value that we'll use for the first
// version or our key derivation scheme. All keys are expected to be // version or our key derivation scheme. All keys are expected to be
@ -25,6 +34,13 @@ const (
BIP0043Purpose = 1017 BIP0043Purpose = 1017
) )
// IsKnownVersion returns true if the given version is one of the known
// derivation scheme versions as defined by this package.
func IsKnownVersion(internalVersion uint8) bool {
return internalVersion == KeyDerivationVersionLegacy ||
internalVersion == KeyDerivationVersionTaproot
}
var ( var (
// MaxKeyRangeScan is the maximum number of keys that we'll attempt to // MaxKeyRangeScan is the maximum number of keys that we'll attempt to
// scan with if a caller knows the public key, but not the KeyLocator // scan with if a caller knows the public key, but not the KeyLocator

View File

@ -309,7 +309,7 @@ func (u *UnlockerService) GenSeed(_ context.Context,
// instance. // instance.
// //
cipherSeed, err := aezeed.New( cipherSeed, err := aezeed.New(
keychain.KeyDerivationVersion, &entropy, time.Now(), keychain.CurrentKeyDerivationVersion, &entropy, time.Now(),
) )
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -91,7 +91,7 @@ func createSeedAndMnemonic(t *testing.T,
pass []byte) (*aezeed.CipherSeed, aezeed.Mnemonic) { pass []byte) (*aezeed.CipherSeed, aezeed.Mnemonic) {
cipherSeed, err := aezeed.New( cipherSeed, err := aezeed.New(
keychain.KeyDerivationVersion, &testEntropy, time.Now(), keychain.CurrentKeyDerivationVersion, &testEntropy, time.Now(),
) )
require.NoError(t, err) require.NoError(t, err)