From 51a480129b7dc75f1e250113be7f76ba631ec119 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 12 May 2022 12:47:13 +0200 Subject: [PATCH] walletunlocker+keychain+config_builder: use new aezeed version --- config_builder.go | 7 +++---- keychain/derivation.go | 26 +++++++++++++++++++++----- walletunlocker/service.go | 2 +- walletunlocker/service_test.go | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/config_builder.go b/config_builder.go index 71ab15611..18e9a3f6f 100644 --- a/config_builder.go +++ b/config_builder.go @@ -965,14 +965,13 @@ func waitForWalletPassword(cfg *Config, // seed. If it's greater than the current key derivation // version, then we'll return an error as we don't understand // this. - const latestVersion = keychain.KeyDerivationVersion if cipherSeed != nil && - cipherSeed.InternalVersion != latestVersion { + !keychain.IsKnownVersion(cipherSeed.InternalVersion) { return nil, fmt.Errorf("invalid internal "+ - "seed version %v, current version is %v", + "seed version %v, current max version is %v", cipherSeed.InternalVersion, - keychain.KeyDerivationVersion) + keychain.CurrentKeyDerivationVersion) } loader, err := btcwallet.NewWalletLoader( diff --git a/keychain/derivation.go b/keychain/derivation.go index 0d6a4ee5b..0e42ae966 100644 --- a/keychain/derivation.go +++ b/keychain/derivation.go @@ -8,11 +8,20 @@ import ( ) const ( - // KeyDerivationVersion is the version of the key derivation schema - // defined below. We use a version as this means that we'll be able to - // accept new seed in the future and be able to discern if the software - // is compatible with the version of the seed. - KeyDerivationVersion = 0 + // KeyDerivationVersionLegacy is the previous version of the key + // derivation schema defined below. We use a version as this means that + // we'll be able to accept new seed in the future and be able to discern + // if the software is compatible with the version of the seed. + 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 // version or our key derivation scheme. All keys are expected to be @@ -25,6 +34,13 @@ const ( 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 ( // 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 diff --git a/walletunlocker/service.go b/walletunlocker/service.go index ce3997666..e473a0c5b 100644 --- a/walletunlocker/service.go +++ b/walletunlocker/service.go @@ -309,7 +309,7 @@ func (u *UnlockerService) GenSeed(_ context.Context, // instance. // cipherSeed, err := aezeed.New( - keychain.KeyDerivationVersion, &entropy, time.Now(), + keychain.CurrentKeyDerivationVersion, &entropy, time.Now(), ) if err != nil { return nil, err diff --git a/walletunlocker/service_test.go b/walletunlocker/service_test.go index 88274459b..5c723d759 100644 --- a/walletunlocker/service_test.go +++ b/walletunlocker/service_test.go @@ -91,7 +91,7 @@ func createSeedAndMnemonic(t *testing.T, pass []byte) (*aezeed.CipherSeed, aezeed.Mnemonic) { cipherSeed, err := aezeed.New( - keychain.KeyDerivationVersion, &testEntropy, time.Now(), + keychain.CurrentKeyDerivationVersion, &testEntropy, time.Now(), ) require.NoError(t, err)