mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Keymanager api alignment (#10176)
* keymanager-api * import updates to standards * adding in more unit tests and code fixes to improve api experience * deleting accidently generated files * deleting accidently generated files * adding in more test coverage * fixing linter issue * removing incorrect unit tests * improving logic for accounts import * linter fix * addressing review comments * fixing based on comments * fixing nonzero root * fixing protos * regen protos * adjusting protos again * updating api specs * fixing code and unit tests after specs changed * fixing imports * adding in required changes for api middleware also adding unit tests to catch changes for protos * fixing deepsource issues * fixing linting * seeing if using pointers helps * addressing comments * updating bazel build Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
@@ -81,6 +81,7 @@ go_test(
|
||||
"//crypto/bls:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//io/file:go_default_library",
|
||||
"//proto/eth/service:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//proto/prysm/v1alpha1/validator-client:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
|
||||
@@ -239,6 +239,19 @@ func ImportAccountsCli(cliCtx *cli.Context) error {
|
||||
// ImportAccounts can import external, EIP-2335 compliant keystore.json files as
|
||||
// new accounts into the Prysm validator wallet.
|
||||
func ImportAccounts(ctx context.Context, cfg *ImportAccountsConfig) ([]*ethpbservice.ImportedKeystoreStatus, error) {
|
||||
if cfg.AccountPassword == "" {
|
||||
statuses := make([]*ethpbservice.ImportedKeystoreStatus, len(cfg.Keystores))
|
||||
for i, keystore := range cfg.Keystores {
|
||||
statuses[i] = ðpbservice.ImportedKeystoreStatus{
|
||||
Status: ethpbservice.ImportedKeystoreStatus_ERROR,
|
||||
Message: fmt.Sprintf(
|
||||
"account password is required to import keystore %s",
|
||||
keystore.Pubkey,
|
||||
),
|
||||
}
|
||||
}
|
||||
return statuses, nil
|
||||
}
|
||||
passwords := make([]string, len(cfg.Keystores))
|
||||
for i := 0; i < len(cfg.Keystores); i++ {
|
||||
passwords[i] = cfg.AccountPassword
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/crypto/bls"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpbservice "github.com/prysmaticlabs/prysm/proto/eth/service"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
prysmTime "github.com/prysmaticlabs/prysm/time"
|
||||
@@ -131,6 +133,43 @@ func TestImport_DuplicateKeys(t *testing.T) {
|
||||
assert.Equal(t, 1, len(keys))
|
||||
}
|
||||
|
||||
func TestImportAccounts_NoPassword(t *testing.T) {
|
||||
local.ResetCaches()
|
||||
walletDir, passwordsDir, passwordFilePath := setupWalletAndPasswordsDir(t)
|
||||
keysDir := filepath.Join(t.TempDir(), "keysDir")
|
||||
require.NoError(t, os.MkdirAll(keysDir, os.ModePerm))
|
||||
|
||||
cliCtx := setupWalletCtx(t, &testWalletConfig{
|
||||
walletDir: walletDir,
|
||||
passwordsDir: passwordsDir,
|
||||
keysDir: keysDir,
|
||||
keymanagerKind: keymanager.Local,
|
||||
walletPasswordFile: passwordFilePath,
|
||||
accountPasswordFile: passwordFilePath,
|
||||
})
|
||||
w, err := CreateWalletWithKeymanager(cliCtx.Context, &CreateWalletConfig{
|
||||
WalletCfg: &wallet.Config{
|
||||
WalletDir: walletDir,
|
||||
KeymanagerKind: keymanager.Local,
|
||||
WalletPassword: password,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
km, err := w.InitializeKeymanager(cliCtx.Context, iface.InitKeymanagerConfig{ListenForChanges: false})
|
||||
require.NoError(t, err)
|
||||
importer, ok := km.(keymanager.Importer)
|
||||
require.Equal(t, true, ok)
|
||||
resp, err := ImportAccounts(context.Background(), &ImportAccountsConfig{
|
||||
Keystores: []*keymanager.Keystore{&keymanager.Keystore{}},
|
||||
Importer: importer,
|
||||
AccountPassword: "",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(resp))
|
||||
require.Equal(t, resp[0].Status, ethpbservice.ImportedKeystoreStatus_ERROR)
|
||||
|
||||
}
|
||||
|
||||
func TestImport_Noninteractive_RandomName(t *testing.T) {
|
||||
local.ResetCaches()
|
||||
walletDir, passwordsDir, passwordFilePath := setupWalletAndPasswordsDir(t)
|
||||
|
||||
Reference in New Issue
Block a user