diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-23 21:00:06 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-03-27 03:00:18 +0800 |
commit | c4ea921876b0535022882c568b5cc6b0269db7d4 (patch) | |
tree | ed01e6cae2563fd61e7d4eb4964e5fe2fcbcb744 /accounts | |
parent | 658204bafcba6332e979aee690dc5cff6e46fb42 (diff) | |
download | go-tangerine-c4ea921876b0535022882c568b5cc6b0269db7d4.tar.gz go-tangerine-c4ea921876b0535022882c568b5cc6b0269db7d4.tar.zst go-tangerine-c4ea921876b0535022882c568b5cc6b0269db7d4.zip |
import/export accounts
- cli: add passwordfile flag
- cli: change unlock flag only takes account
- cli: with unlock you are prompted for password or use passfile with password flag
- cli: unlockAccount used in normal client start (run) and accountExport
- cli: getPassword used in accountCreate and accountImport
- accounts: Manager.Import, Manager.Export
- crypto: SaveECDSA (to complement LoadECDSA) to save to file
- crypto: NewKeyFromECDSA added (used in accountImport and New = generated constructor)
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/account_manager.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go index 646dc8376..670d4337f 100644 --- a/accounts/account_manager.go +++ b/accounts/account_manager.go @@ -208,3 +208,23 @@ func zeroKey(k *ecdsa.PrivateKey) { b[i] = 0 } } + +func (am *Manager) Export(path string, addr []byte, keyAuth string) error { + key, err := am.keyStore.GetKey(addr, keyAuth) + if err != nil { + return err + } + return crypto.SaveECDSA(path, key.PrivateKey) +} + +func (am *Manager) Import(path string, keyAuth string) (Account, error) { + privateKeyECDSA, err := crypto.LoadECDSA(path) + if err != nil { + return Account{}, err + } + key := crypto.NewKeyFromECDSA(privateKeyECDSA) + if err = am.keyStore.StoreKey(key, keyAuth); err != nil { + return Account{}, err + } + return Account{Address: key.Address}, nil +} |