2019-12-19 18:27:27 +00:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-12-30 10:28:44 +00:00
|
|
|
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
|
2019-12-19 18:27:27 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// makeAccountManager creates ethereum accounts.Manager with single disk backend and lightweight kdf.
|
|
|
|
// If keydir is empty new temporary directory with go-ethereum-keystore will be intialized.
|
|
|
|
func makeAccountManager(keydir string) (manager *accounts.Manager, err error) {
|
|
|
|
if keydir == "" {
|
|
|
|
// There is no datadir.
|
2023-01-03 14:40:11 +00:00
|
|
|
keydir, err = os.MkdirTemp("", "go-ethereum-keystore")
|
2019-12-19 18:27:27 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := os.MkdirAll(keydir, 0700); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
config := accounts.Config{InsecureUnlockAllowed: false}
|
|
|
|
return accounts.NewManager(&config, keystore.NewKeyStore(keydir, keystore.LightScryptN, keystore.LightScryptP)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeKeyStore(manager *accounts.Manager) (types.KeyStore, error) {
|
|
|
|
backends := manager.Backends(keystore.KeyStoreType)
|
|
|
|
if len(backends) == 0 {
|
|
|
|
return nil, ErrAccountKeyStoreMissing
|
|
|
|
}
|
|
|
|
keyStore, ok := backends[0].(*keystore.KeyStore)
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrAccountKeyStoreMissing
|
|
|
|
}
|
|
|
|
|
2019-12-30 10:28:44 +00:00
|
|
|
return gethbridge.WrapKeyStore(keyStore), nil
|
2019-12-19 18:27:27 +00:00
|
|
|
}
|