Accounts V2: Resolve Remaining Keymanager Bugs (#6706)

* v2 fix bugs
* better doc
* include wallet build fix
* fixed broken list test
* add round trip recover seed unit test
* imports
* implement list with tests
* add altona flags
* tests for unicode
* added is valid unicode tests
* fixed up tests to ensure wallet is persisted after everything works
* resolve confs and integrate medalla testnet
* fix build
* add medalla
* fixed import spacing
This commit is contained in:
Raul Jordan
2020-07-23 19:43:01 -05:00
committed by GitHub
parent cc773a1641
commit a5b408769a
22 changed files with 408 additions and 46 deletions

View File

@@ -44,11 +44,13 @@ go_test(
"//proto/validator/accounts/v2:go_default_library",
"//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/rand:go_default_library",
"//shared/testutil:go_default_library",
"//shared/testutil/assert:go_default_library",
"//shared/testutil/require:go_default_library",
"//validator/accounts/v2/testing:go_default_library",
"//validator/keymanager/v2:go_default_library",
"@com_github_google_uuid//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@com_github_tyler_smith_go_bip39//:go_default_library",
"@com_github_wealdtech_go_eth2_wallet_encryptor_keystorev4//:go_default_library",

View File

@@ -207,7 +207,7 @@ func InitializeWalletSeedFile(ctx context.Context, password string, skipMnemonic
// SeedFileFromMnemonic uses the provided mnemonic seed phrase to generate the
// appropriate seed file for recovering a derived wallets.
func SeedFileFromMnemonic(ctx context.Context, mnemonic string, password string) (*SeedConfig, error) {
walletSeed, err := bip39.MnemonicToByteArray(mnemonic)
walletSeed, err := bip39.EntropyFromMnemonic(mnemonic)
if err != nil {
return nil, errors.Wrap(err, "could not convert mnemonic to wallet seed")
}

View File

@@ -9,18 +9,68 @@ import (
"strings"
"testing"
"github.com/google/uuid"
validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/rand"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
mock "github.com/prysmaticlabs/prysm/validator/accounts/v2/testing"
v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
logTest "github.com/sirupsen/logrus/hooks/test"
"github.com/tyler-smith/go-bip39"
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"
)
func TestDerivedKeymanager_RecoverSeedRoundTrip(t *testing.T) {
walletSeed := make([]byte, 32)
n, err := rand.NewGenerator().Read(walletSeed)
require.NoError(t, err)
require.Equal(t, n, len(walletSeed))
encryptor := keystorev4.New()
password := "Passwz0rdz2020%"
cryptoFields, err := encryptor.Encrypt(walletSeed, []byte(password))
require.NoError(t, err)
id, err := uuid.NewRandom()
require.NoError(t, err)
cfg := &SeedConfig{
Crypto: cryptoFields,
ID: id.String(),
NextAccount: 0,
Version: encryptor.Version(),
Name: encryptor.Name(),
}
phrase, err := bip39.NewMnemonic(walletSeed)
require.NoError(t, err)
recoveredSeed, err := bip39.EntropyFromMnemonic(phrase)
require.NoError(t, err)
// Ensure the recovered seed matches the old wallet seed.
assert.DeepEqual(t, walletSeed, recoveredSeed)
cryptoFields, err = encryptor.Encrypt(recoveredSeed, []byte(password))
require.NoError(t, err)
newCfg := &SeedConfig{
Crypto: cryptoFields,
ID: cfg.ID,
NextAccount: 0,
Version: encryptor.Version(),
Name: encryptor.Name(),
}
// Ensure we can decrypt the newly recovered config.
decryptor := keystorev4.New()
seed, err := decryptor.Decrypt(newCfg.Crypto, []byte(password))
assert.NoError(t, err)
// Ensure the decrypted seed matches the old wallet seed and the new wallet seed.
assert.DeepEqual(t, walletSeed, seed)
assert.DeepEqual(t, recoveredSeed, seed)
}
func TestDerivedKeymanager_CreateAccount(t *testing.T) {
hook := logTest.NewGlobal()
wallet := &mock.Wallet{

View File

@@ -151,6 +151,7 @@ func (dr *Keymanager) CreateAccount(ctx context.Context, password string) (strin
===================================================================
`, withdrawalKey.Marshal())
fmt.Println(" ")
// Upon confirmation of the withdrawal key, proceed to display
// and write associated deposit data to disk.

View File

@@ -164,9 +164,9 @@ func (c *Config) String() string {
return b.String()
}
// CreateAccount based on the keymanager's logic. Returns the account name.
func (k *Keymanager) CreateAccount(ctx context.Context, password string) (string, error) {
return "", errors.New("a remote validator account cannot be created from the client")
// Config for the remote keymanager.
func (k *Keymanager) Config() *Config {
return k.cfg
}
// FetchValidatingPublicKeys fetches the list of public keys that should be used to validate with.