diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-27 05:42:46 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-27 05:42:46 +0800 |
commit | 6bd1f6cc49acd459e61559e5af515da2db2481e5 (patch) | |
tree | 3e4f7a51ca8e3cb03d24fbe1898578d88fd7456c /accounts/account_manager.go | |
parent | bb12dbe233db2e064715b329b7ba987c76ba3bfa (diff) | |
parent | b0b0939879b9fb8453ec1c8fa2ceb522e56df3bc (diff) | |
download | go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.gz go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.bz2 go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.lz go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.xz go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.zst go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.zip |
Merge remote-tracking branch 'origin' into rpcargs
Conflicts:
rpc/args.go
Diffstat (limited to 'accounts/account_manager.go')
-rw-r--r-- | accounts/account_manager.go | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go index 646dc8376..34a2c4891 100644 --- a/accounts/account_manager.go +++ b/accounts/account_manager.go @@ -36,9 +36,8 @@ import ( "bytes" "crypto/ecdsa" crand "crypto/rand" - "os" - "errors" + "os" "sync" "time" @@ -208,3 +207,37 @@ func zeroKey(k *ecdsa.PrivateKey) { b[i] = 0 } } + +// USE WITH CAUTION = this will save an unencrypted private key on disk +// no cli or js interface +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 +} + +func (am *Manager) ImportPreSaleKey(keyJSON []byte, password string) (acc Account, err error) { + var key *crypto.Key + key, err = crypto.ImportPreSaleKey(am.keyStore, keyJSON, password) + if err != nil { + return + } + if err = am.keyStore.StoreKey(key, password); err != nil { + return + } + return Account{Address: key.Address}, nil +} |