2020-09-03 15:11:17 +00:00
package rpc
import (
"context"
"encoding/json"
"fmt"
2020-09-30 14:13:37 +00:00
"os"
2020-11-23 22:11:42 +00:00
"path/filepath"
2020-09-03 15:11:17 +00:00
"testing"
2021-03-12 00:03:19 +00:00
"github.com/golang/protobuf/ptypes/empty"
2020-09-03 15:11:17 +00:00
"github.com/google/uuid"
2021-09-18 17:26:11 +00:00
"github.com/prysmaticlabs/prysm/async/event"
2021-09-15 01:18:39 +00:00
"github.com/prysmaticlabs/prysm/config/features"
2021-09-15 22:55:11 +00:00
"github.com/prysmaticlabs/prysm/crypto/bls"
2021-10-20 14:23:59 +00:00
"github.com/prysmaticlabs/prysm/crypto/rand"
2021-09-17 21:55:24 +00:00
"github.com/prysmaticlabs/prysm/io/file"
2021-08-18 21:24:01 +00:00
pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client"
2021-09-23 18:53:46 +00:00
"github.com/prysmaticlabs/prysm/testing/assert"
"github.com/prysmaticlabs/prysm/testing/require"
2020-10-15 22:31:52 +00:00
"github.com/prysmaticlabs/prysm/validator/accounts"
2021-02-24 18:05:46 +00:00
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
2020-10-15 22:31:52 +00:00
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
"github.com/prysmaticlabs/prysm/validator/keymanager"
2020-10-16 18:45:14 +00:00
"github.com/prysmaticlabs/prysm/validator/keymanager/imported"
2021-10-20 14:23:59 +00:00
"github.com/tyler-smith/go-bip39"
2021-02-24 18:05:46 +00:00
keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4"
2020-09-03 15:11:17 +00:00
)
2021-03-02 11:39:54 +00:00
const strongPass = "29384283xasjasd32%%&*@*#*"
2020-10-16 18:45:14 +00:00
func TestServer_CreateWallet_Imported ( t * testing . T ) {
2020-09-03 15:11:17 +00:00
localWalletDir := setupWalletDir ( t )
defaultWalletPath = localWalletDir
ctx := context . Background ( )
2020-09-22 14:49:07 +00:00
s := & Server {
walletInitializedFeed : new ( event . Feed ) ,
2020-10-10 02:07:28 +00:00
walletDir : defaultWalletPath ,
2020-09-22 14:49:07 +00:00
}
2020-09-03 15:11:17 +00:00
req := & pb . CreateWalletRequest {
2020-10-16 18:45:14 +00:00
Keymanager : pb . KeymanagerKind_IMPORTED ,
2020-10-10 02:07:28 +00:00
WalletPassword : strongPass ,
2020-09-03 15:11:17 +00:00
}
2020-09-30 14:13:37 +00:00
// We delete the directory at defaultWalletPath as CreateWallet will return an error if it tries to create a wallet
// where a directory already exists
require . NoError ( t , os . RemoveAll ( defaultWalletPath ) )
2021-10-20 16:37:05 +00:00
_ , err := s . CreateWallet ( ctx , req )
2020-10-10 02:07:28 +00:00
require . NoError ( t , err )
importReq := & pb . ImportKeystoresRequest {
KeystoresPassword : strongPass ,
KeystoresImported : [ ] string { "badjson" } ,
}
_ , err = s . ImportKeystores ( ctx , importReq )
2020-09-03 15:11:17 +00:00
require . ErrorContains ( t , "Not a valid EIP-2335 keystore" , err )
encryptor := keystorev4 . New ( )
keystores := make ( [ ] string , 3 )
for i := 0 ; i < len ( keystores ) ; i ++ {
2020-10-30 19:06:33 +00:00
privKey , err := bls . RandKey ( )
require . NoError ( t , err )
2020-09-03 15:11:17 +00:00
pubKey := fmt . Sprintf ( "%x" , privKey . PublicKey ( ) . Marshal ( ) )
id , err := uuid . NewRandom ( )
require . NoError ( t , err )
cryptoFields , err := encryptor . Encrypt ( privKey . Marshal ( ) , strongPass )
require . NoError ( t , err )
2020-10-15 22:31:52 +00:00
item := & keymanager . Keystore {
2020-09-03 15:11:17 +00:00
Crypto : cryptoFields ,
ID : id . String ( ) ,
Version : encryptor . Version ( ) ,
Pubkey : pubKey ,
Name : encryptor . Name ( ) ,
}
encodedFile , err := json . MarshalIndent ( item , "" , "\t" )
require . NoError ( t , err )
keystores [ i ] = string ( encodedFile )
}
2020-10-10 02:07:28 +00:00
importReq . KeystoresImported = keystores
_ , err = s . ImportKeystores ( ctx , importReq )
2020-09-03 15:11:17 +00:00
require . NoError ( t , err )
}
2021-04-05 20:42:03 +00:00
func TestServer_RecoverWallet_Derived ( t * testing . T ) {
2020-09-03 15:11:17 +00:00
localWalletDir := setupWalletDir ( t )
ctx := context . Background ( )
2020-09-22 14:49:07 +00:00
s := & Server {
walletInitializedFeed : new ( event . Feed ) ,
2020-11-23 06:29:58 +00:00
walletDir : localWalletDir ,
2020-09-22 14:49:07 +00:00
}
2021-04-05 20:42:03 +00:00
req := & pb . RecoverWalletRequest {
2020-09-03 15:11:17 +00:00
WalletPassword : strongPass ,
NumAccounts : 0 ,
}
2021-04-05 20:42:03 +00:00
// We delete the directory at defaultWalletPath as RecoverWallet will return an error if it tries to create a wallet
2020-09-30 14:13:37 +00:00
// where a directory already exists
2021-04-05 20:42:03 +00:00
require . NoError ( t , os . RemoveAll ( localWalletDir ) )
_ , err := s . RecoverWallet ( ctx , req )
2020-09-03 15:11:17 +00:00
require . ErrorContains ( t , "Must create at least 1 validator account" , err )
req . NumAccounts = 2
2021-04-05 20:42:03 +00:00
req . Language = "Swahili"
_ , err = s . RecoverWallet ( ctx , req )
require . ErrorContains ( t , "input not in the list of supported languages" , err )
req . Language = "ENglish"
_ , err = s . RecoverWallet ( ctx , req )
require . ErrorContains ( t , "invalid mnemonic in request" , err )
2020-09-03 15:11:17 +00:00
2021-10-20 14:23:59 +00:00
mnemonicRandomness := make ( [ ] byte , 32 )
_ , err = rand . NewGenerator ( ) . Read ( mnemonicRandomness )
2020-09-03 15:11:17 +00:00
require . NoError ( t , err )
2021-10-20 14:23:59 +00:00
mnemonic , err := bip39 . NewMnemonic ( mnemonicRandomness )
require . NoError ( t , err )
req . Mnemonic = mnemonic
2020-09-03 15:11:17 +00:00
2021-04-05 20:42:03 +00:00
req . Mnemonic25ThWord = " "
_ , err = s . RecoverWallet ( ctx , req )
require . ErrorContains ( t , "mnemonic 25th word cannot be empty" , err )
req . Mnemonic25ThWord = "outer"
// Test weak password.
req . WalletPassword = "123qwe"
_ , err = s . RecoverWallet ( ctx , req )
require . ErrorContains ( t , "password did not pass validation" , err )
req . WalletPassword = strongPass
// Create(derived) should fail then test recover.
reqCreate := & pb . CreateWalletRequest {
Keymanager : pb . KeymanagerKind_DERIVED ,
WalletPassword : strongPass ,
NumAccounts : 2 ,
2021-10-20 14:23:59 +00:00
Mnemonic : mnemonic ,
2021-04-05 20:42:03 +00:00
}
_ , err = s . CreateWallet ( ctx , reqCreate )
require . ErrorContains ( t , "create wallet not supported through web" , err , "Create wallet for DERIVED or REMOTE types not supported through web, either import keystore or recover" )
// This defer will be the last to execute in this func.
2021-09-15 01:18:39 +00:00
resetCfgFalse := features . InitWithReset ( & features . Flags {
2021-04-05 20:42:03 +00:00
WriteWalletPasswordOnWebOnboarding : false ,
} )
defer resetCfgFalse ( )
2021-09-15 01:18:39 +00:00
resetCfgTrue := features . InitWithReset ( & features . Flags {
2021-04-05 20:42:03 +00:00
WriteWalletPasswordOnWebOnboarding : true ,
} )
defer resetCfgTrue ( )
// Finally test recover.
_ , err = s . RecoverWallet ( ctx , req )
2020-09-03 15:11:17 +00:00
require . NoError ( t , err )
2021-04-05 20:42:03 +00:00
// Password File should have been written.
passwordFilePath := filepath . Join ( localWalletDir , wallet . DefaultWalletPasswordFile )
2021-09-17 21:55:24 +00:00
assert . Equal ( t , true , file . FileExists ( passwordFilePath ) )
2021-04-05 20:42:03 +00:00
// Attempting to write again should trigger an error.
err = writeWalletPasswordToDisk ( localWalletDir , "somepassword" )
require . ErrorContains ( t , "cannot write wallet password file as it already exists" , err )
2020-09-03 15:11:17 +00:00
}
2021-10-20 14:23:59 +00:00
func TestServer_ValidateKeystores_FailedPreconditions ( t * testing . T ) {
ctx := context . Background ( )
strongPass := "29384283xasjasd32%%&*@*#*"
ss := & Server { }
_ , err := ss . ValidateKeystores ( ctx , & pb . ValidateKeystoresRequest { } )
assert . ErrorContains ( t , "Password required for keystores" , err )
_ , err = ss . ValidateKeystores ( ctx , & pb . ValidateKeystoresRequest {
KeystoresPassword : strongPass ,
} )
assert . ErrorContains ( t , "No keystores included in request" , err )
_ , err = ss . ValidateKeystores ( ctx , & pb . ValidateKeystoresRequest {
KeystoresPassword : strongPass ,
Keystores : [ ] string { "badjson" } ,
} )
assert . ErrorContains ( t , "Not a valid EIP-2335 keystore" , err )
}
func TestServer_ValidateKeystores_OK ( t * testing . T ) {
ctx := context . Background ( )
strongPass := "29384283xasjasd32%%&*@*#*"
ss := & Server { }
// Create 3 keystores with the strong password.
encryptor := keystorev4 . New ( )
keystores := make ( [ ] string , 3 )
pubKeys := make ( [ ] [ ] byte , 3 )
for i := 0 ; i < len ( keystores ) ; i ++ {
privKey , err := bls . RandKey ( )
require . NoError ( t , err )
pubKey := fmt . Sprintf ( "%x" , privKey . PublicKey ( ) . Marshal ( ) )
id , err := uuid . NewRandom ( )
require . NoError ( t , err )
cryptoFields , err := encryptor . Encrypt ( privKey . Marshal ( ) , strongPass )
require . NoError ( t , err )
item := & keymanager . Keystore {
Crypto : cryptoFields ,
ID : id . String ( ) ,
Version : encryptor . Version ( ) ,
Pubkey : pubKey ,
Name : encryptor . Name ( ) ,
}
encodedFile , err := json . MarshalIndent ( item , "" , "\t" )
require . NoError ( t , err )
keystores [ i ] = string ( encodedFile )
pubKeys [ i ] = privKey . PublicKey ( ) . Marshal ( )
}
// Validate the keystores and ensure no error.
_ , err := ss . ValidateKeystores ( ctx , & pb . ValidateKeystoresRequest {
KeystoresPassword : strongPass ,
Keystores : keystores ,
} )
require . NoError ( t , err )
// Check that using a different password will return an error.
_ , err = ss . ValidateKeystores ( ctx , & pb . ValidateKeystoresRequest {
KeystoresPassword : "badpassword" ,
Keystores : keystores ,
} )
require . ErrorContains ( t , "is incorrect" , err )
// Add a new keystore that was encrypted with a different password and expect
// a failure from the function.
differentPassword := "differentkeystorepass"
privKey , err := bls . RandKey ( )
require . NoError ( t , err )
pubKey := "somepubkey"
id , err := uuid . NewRandom ( )
require . NoError ( t , err )
cryptoFields , err := encryptor . Encrypt ( privKey . Marshal ( ) , differentPassword )
require . NoError ( t , err )
item := & keymanager . Keystore {
Crypto : cryptoFields ,
ID : id . String ( ) ,
Version : encryptor . Version ( ) ,
Pubkey : pubKey ,
Name : encryptor . Name ( ) ,
}
encodedFile , err := json . MarshalIndent ( item , "" , "\t" )
keystores = append ( keystores , string ( encodedFile ) )
require . NoError ( t , err )
_ , err = ss . ValidateKeystores ( ctx , & pb . ValidateKeystoresRequest {
KeystoresPassword : strongPass ,
Keystores : keystores ,
} )
require . ErrorContains ( t , "Password for keystore with public key somepubkey is incorrect" , err )
}
2020-09-03 15:11:17 +00:00
func TestServer_WalletConfig_NoWalletFound ( t * testing . T ) {
s := & Server { }
2021-03-12 00:03:19 +00:00
resp , err := s . WalletConfig ( context . Background ( ) , & empty . Empty { } )
2020-09-03 15:11:17 +00:00
require . NoError ( t , err )
assert . DeepEqual ( t , resp , & pb . WalletResponse { } )
}
func TestServer_WalletConfig ( t * testing . T ) {
localWalletDir := setupWalletDir ( t )
defaultWalletPath = localWalletDir
ctx := context . Background ( )
2020-09-22 14:49:07 +00:00
s := & Server {
walletInitializedFeed : new ( event . Feed ) ,
2020-10-10 02:07:28 +00:00
walletDir : defaultWalletPath ,
2020-09-22 14:49:07 +00:00
}
2020-09-03 15:11:17 +00:00
// We attempt to create the wallet.
2020-10-15 22:31:52 +00:00
w , err := accounts . CreateWalletWithKeymanager ( ctx , & accounts . CreateWalletConfig {
2020-09-17 01:34:42 +00:00
WalletCfg : & wallet . Config {
2020-09-03 15:11:17 +00:00
WalletDir : defaultWalletPath ,
2020-10-16 18:45:14 +00:00
KeymanagerKind : keymanager . Imported ,
2020-09-03 15:11:17 +00:00
WalletPassword : strongPass ,
} ,
SkipMnemonicConfirm : true ,
} )
require . NoError ( t , err )
2021-02-24 18:05:46 +00:00
km , err := w . InitializeKeymanager ( ctx , iface . InitKeymanagerConfig { ListenForChanges : false } )
2020-09-24 20:37:59 +00:00
require . NoError ( t , err )
s . wallet = w
s . keymanager = km
2021-03-12 00:03:19 +00:00
resp , err := s . WalletConfig ( ctx , & empty . Empty { } )
2020-09-03 15:11:17 +00:00
require . NoError ( t , err )
2020-09-24 20:37:59 +00:00
2020-09-03 15:11:17 +00:00
assert . DeepEqual ( t , resp , & pb . WalletResponse {
2020-11-17 06:00:20 +00:00
WalletPath : localWalletDir ,
KeymanagerKind : pb . KeymanagerKind_IMPORTED ,
2020-09-03 15:11:17 +00:00
} )
}
2020-09-21 19:44:43 +00:00
2020-09-30 19:03:54 +00:00
func TestServer_ImportKeystores_FailedPreconditions_WrongKeymanagerKind ( t * testing . T ) {
localWalletDir := setupWalletDir ( t )
defaultWalletPath = localWalletDir
ctx := context . Background ( )
2020-10-15 22:31:52 +00:00
w , err := accounts . CreateWalletWithKeymanager ( ctx , & accounts . CreateWalletConfig {
2020-09-30 19:03:54 +00:00
WalletCfg : & wallet . Config {
WalletDir : defaultWalletPath ,
2020-10-15 22:31:52 +00:00
KeymanagerKind : keymanager . Derived ,
2020-09-30 19:03:54 +00:00
WalletPassword : strongPass ,
} ,
SkipMnemonicConfirm : true ,
} )
require . NoError ( t , err )
2021-02-24 18:05:46 +00:00
km , err := w . InitializeKeymanager ( ctx , iface . InitKeymanagerConfig { ListenForChanges : false } )
2020-09-30 19:03:54 +00:00
require . NoError ( t , err )
ss := & Server {
wallet : w ,
keymanager : km ,
}
_ , err = ss . ImportKeystores ( ctx , & pb . ImportKeystoresRequest { } )
2020-10-16 18:45:14 +00:00
assert . ErrorContains ( t , "Only imported wallets can import more" , err )
2020-09-30 19:03:54 +00:00
}
func TestServer_ImportKeystores_FailedPreconditions ( t * testing . T ) {
localWalletDir := setupWalletDir ( t )
defaultWalletPath = localWalletDir
ctx := context . Background ( )
2020-10-15 22:31:52 +00:00
w , err := accounts . CreateWalletWithKeymanager ( ctx , & accounts . CreateWalletConfig {
2020-09-30 19:03:54 +00:00
WalletCfg : & wallet . Config {
WalletDir : defaultWalletPath ,
2020-10-16 18:45:14 +00:00
KeymanagerKind : keymanager . Imported ,
2020-09-30 19:03:54 +00:00
WalletPassword : strongPass ,
} ,
SkipMnemonicConfirm : true ,
} )
require . NoError ( t , err )
2021-02-24 18:05:46 +00:00
km , err := w . InitializeKeymanager ( ctx , iface . InitKeymanagerConfig { ListenForChanges : false } )
2020-09-30 19:03:54 +00:00
require . NoError ( t , err )
ss := & Server {
keymanager : km ,
}
_ , err = ss . ImportKeystores ( ctx , & pb . ImportKeystoresRequest { } )
assert . ErrorContains ( t , "No wallet initialized" , err )
ss . wallet = w
_ , err = ss . ImportKeystores ( ctx , & pb . ImportKeystoresRequest { } )
assert . ErrorContains ( t , "Password required for keystores" , err )
_ , err = ss . ImportKeystores ( ctx , & pb . ImportKeystoresRequest {
KeystoresPassword : strongPass ,
} )
assert . ErrorContains ( t , "No keystores included for import" , err )
_ , err = ss . ImportKeystores ( ctx , & pb . ImportKeystoresRequest {
KeystoresPassword : strongPass ,
KeystoresImported : [ ] string { "badjson" } ,
} )
assert . ErrorContains ( t , "Not a valid EIP-2335 keystore" , err )
}
func TestServer_ImportKeystores_OK ( t * testing . T ) {
2020-10-16 18:45:14 +00:00
imported . ResetCaches ( )
2020-09-30 19:03:54 +00:00
localWalletDir := setupWalletDir ( t )
defaultWalletPath = localWalletDir
ctx := context . Background ( )
2020-10-15 22:31:52 +00:00
w , err := accounts . CreateWalletWithKeymanager ( ctx , & accounts . CreateWalletConfig {
2020-09-30 19:03:54 +00:00
WalletCfg : & wallet . Config {
WalletDir : defaultWalletPath ,
2020-10-16 18:45:14 +00:00
KeymanagerKind : keymanager . Imported ,
2020-09-30 19:03:54 +00:00
WalletPassword : strongPass ,
} ,
SkipMnemonicConfirm : true ,
} )
require . NoError ( t , err )
2021-02-24 18:05:46 +00:00
km , err := w . InitializeKeymanager ( ctx , iface . InitKeymanagerConfig { ListenForChanges : false } )
2020-09-30 19:03:54 +00:00
require . NoError ( t , err )
ss := & Server {
2020-10-10 02:07:28 +00:00
keymanager : km ,
wallet : w ,
walletInitializedFeed : new ( event . Feed ) ,
2020-09-30 19:03:54 +00:00
}
// Create 3 keystores.
encryptor := keystorev4 . New ( )
keystores := make ( [ ] string , 3 )
pubKeys := make ( [ ] [ ] byte , 3 )
for i := 0 ; i < len ( keystores ) ; i ++ {
2020-10-30 19:06:33 +00:00
privKey , err := bls . RandKey ( )
require . NoError ( t , err )
2020-09-30 19:03:54 +00:00
pubKey := fmt . Sprintf ( "%x" , privKey . PublicKey ( ) . Marshal ( ) )
id , err := uuid . NewRandom ( )
require . NoError ( t , err )
cryptoFields , err := encryptor . Encrypt ( privKey . Marshal ( ) , strongPass )
require . NoError ( t , err )
2020-10-15 22:31:52 +00:00
item := & keymanager . Keystore {
2020-09-30 19:03:54 +00:00
Crypto : cryptoFields ,
ID : id . String ( ) ,
Version : encryptor . Version ( ) ,
Pubkey : pubKey ,
Name : encryptor . Name ( ) ,
}
encodedFile , err := json . MarshalIndent ( item , "" , "\t" )
require . NoError ( t , err )
keystores [ i ] = string ( encodedFile )
pubKeys [ i ] = privKey . PublicKey ( ) . Marshal ( )
}
// Check the wallet has no accounts to start with.
keys , err := km . FetchValidatingPublicKeys ( ctx )
require . NoError ( t , err )
assert . Equal ( t , 0 , len ( keys ) )
// Import the 3 keystores and verify the wallet has 3 new accounts.
res , err := ss . ImportKeystores ( ctx , & pb . ImportKeystoresRequest {
KeystoresPassword : strongPass ,
KeystoresImported : keystores ,
} )
require . NoError ( t , err )
assert . DeepEqual ( t , & pb . ImportKeystoresResponse {
ImportedPublicKeys : pubKeys ,
} , res )
2021-02-24 18:05:46 +00:00
km , err = w . InitializeKeymanager ( ctx , iface . InitKeymanagerConfig { ListenForChanges : false } )
2020-09-30 19:03:54 +00:00
require . NoError ( t , err )
keys , err = km . FetchValidatingPublicKeys ( ctx )
require . NoError ( t , err )
assert . Equal ( t , 3 , len ( keys ) )
}
2020-11-23 22:11:42 +00:00
func Test_writeWalletPasswordToDisk ( t * testing . T ) {
walletDir := setupWalletDir ( t )
2021-09-15 01:18:39 +00:00
resetCfg := features . InitWithReset ( & features . Flags {
2020-11-23 22:11:42 +00:00
WriteWalletPasswordOnWebOnboarding : false ,
} )
defer resetCfg ( )
err := writeWalletPasswordToDisk ( walletDir , "somepassword" )
require . NoError ( t , err )
// Expected a silent failure if the feature flag is not enabled.
passwordFilePath := filepath . Join ( walletDir , wallet . DefaultWalletPasswordFile )
2021-09-17 21:55:24 +00:00
assert . Equal ( t , false , file . FileExists ( passwordFilePath ) )
2021-09-15 01:18:39 +00:00
resetCfg = features . InitWithReset ( & features . Flags {
2020-11-23 22:11:42 +00:00
WriteWalletPasswordOnWebOnboarding : true ,
} )
defer resetCfg ( )
err = writeWalletPasswordToDisk ( walletDir , "somepassword" )
require . NoError ( t , err )
// File should have been written.
2021-09-17 21:55:24 +00:00
assert . Equal ( t , true , file . FileExists ( passwordFilePath ) )
2020-11-23 22:11:42 +00:00
// Attempting to write again should trigger an error.
err = writeWalletPasswordToDisk ( walletDir , "somepassword" )
require . NotNil ( t , err )
}
2021-04-02 09:33:42 +00:00
func createImportedWalletWithAccounts ( t testing . TB , numAccounts int ) ( * Server , [ ] [ ] byte ) {
localWalletDir := setupWalletDir ( t )
defaultWalletPath = localWalletDir
ctx := context . Background ( )
w , err := accounts . CreateWalletWithKeymanager ( ctx , & accounts . CreateWalletConfig {
WalletCfg : & wallet . Config {
WalletDir : defaultWalletPath ,
KeymanagerKind : keymanager . Imported ,
WalletPassword : strongPass ,
} ,
SkipMnemonicConfirm : true ,
} )
require . NoError ( t , err )
km , err := w . InitializeKeymanager ( ctx , iface . InitKeymanagerConfig { ListenForChanges : false } )
require . NoError ( t , err )
s := & Server {
keymanager : km ,
wallet : w ,
walletDir : defaultWalletPath ,
walletInitializedFeed : new ( event . Feed ) ,
}
// First we import accounts into the wallet.
encryptor := keystorev4 . New ( )
keystores := make ( [ ] string , numAccounts )
pubKeys := make ( [ ] [ ] byte , len ( keystores ) )
for i := 0 ; i < len ( keystores ) ; i ++ {
privKey , err := bls . RandKey ( )
require . NoError ( t , err )
pubKey := fmt . Sprintf ( "%x" , privKey . PublicKey ( ) . Marshal ( ) )
id , err := uuid . NewRandom ( )
require . NoError ( t , err )
cryptoFields , err := encryptor . Encrypt ( privKey . Marshal ( ) , strongPass )
require . NoError ( t , err )
item := & keymanager . Keystore {
Crypto : cryptoFields ,
ID : id . String ( ) ,
Version : encryptor . Version ( ) ,
Pubkey : pubKey ,
Name : encryptor . Name ( ) ,
}
encodedFile , err := json . MarshalIndent ( item , "" , "\t" )
require . NoError ( t , err )
keystores [ i ] = string ( encodedFile )
pubKeys [ i ] = privKey . PublicKey ( ) . Marshal ( )
}
_ , err = s . ImportKeystores ( ctx , & pb . ImportKeystoresRequest {
KeystoresImported : keystores ,
KeystoresPassword : strongPass ,
} )
require . NoError ( t , err )
s . keymanager , err = s . wallet . InitializeKeymanager ( ctx , iface . InitKeymanagerConfig { ListenForChanges : false } )
require . NoError ( t , err )
return s , pubKeys
}