aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/account_manager.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-03-02 20:57:15 +0800
committerFelix Lange <fjl@twurst.com>2016-04-12 21:56:49 +0800
commit85e6c40c0081bd0db80448640db648887804010c (patch)
tree326a2c3bc115a445b481624cb20f00b28e44f92a /accounts/account_manager.go
parentdff9b4246f3ef9e6c254b57eef6d0433809f16b9 (diff)
downloadgo-tangerine-85e6c40c0081bd0db80448640db648887804010c.tar
go-tangerine-85e6c40c0081bd0db80448640db648887804010c.tar.gz
go-tangerine-85e6c40c0081bd0db80448640db648887804010c.tar.bz2
go-tangerine-85e6c40c0081bd0db80448640db648887804010c.tar.lz
go-tangerine-85e6c40c0081bd0db80448640db648887804010c.tar.xz
go-tangerine-85e6c40c0081bd0db80448640db648887804010c.tar.zst
go-tangerine-85e6c40c0081bd0db80448640db648887804010c.zip
accounts, crypto: move keystore to package accounts
The account management API was originally implemented as a thin layer around crypto.KeyStore, on the grounds that several kinds of key stores would be implemented later on. It turns out that this won't happen so KeyStore is a superflous abstraction. In this commit crypto.KeyStore and everything related to it moves to package accounts and is unexported.
Diffstat (limited to 'accounts/account_manager.go')
-rw-r--r--accounts/account_manager.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/accounts/account_manager.go b/accounts/account_manager.go
index 34cf0fa53..c85304066 100644
--- a/accounts/account_manager.go
+++ b/accounts/account_manager.go
@@ -19,9 +19,6 @@
// This abstracts part of a user's interaction with an account she controls.
package accounts
-// Currently this is pretty much a passthrough to the KeyStore interface,
-// and accounts persistence is derived from stored keys' addresses
-
import (
"crypto/ecdsa"
crand "crypto/rand"
@@ -49,19 +46,26 @@ func (acc *Account) MarshalJSON() ([]byte, error) {
}
type Manager struct {
- keyStore crypto.KeyStore
+ keyStore keyStore
unlocked map[common.Address]*unlocked
mutex sync.RWMutex
}
type unlocked struct {
- *crypto.Key
+ *Key
abort chan struct{}
}
-func NewManager(keyStore crypto.KeyStore) *Manager {
+func NewManager(keydir string, scryptN, scryptP int) *Manager {
+ return &Manager{
+ keyStore: newKeyStorePassphrase(keydir, scryptN, scryptP),
+ unlocked: make(map[common.Address]*unlocked),
+ }
+}
+
+func NewPlaintextManager(keydir string) *Manager {
return &Manager{
- keyStore: keyStore,
+ keyStore: newKeyStorePlain(keydir),
unlocked: make(map[common.Address]*unlocked),
}
}
@@ -216,19 +220,23 @@ func (am *Manager) Export(path string, addr common.Address, keyAuth string) erro
}
func (am *Manager) Import(path string, keyAuth string) (Account, error) {
- privateKeyECDSA, err := crypto.LoadECDSA(path)
+ priv, err := crypto.LoadECDSA(path)
if err != nil {
return Account{}, err
}
- key := crypto.NewKeyFromECDSA(privateKeyECDSA)
- if err = am.keyStore.StoreKey(key, keyAuth); err != nil {
+ return am.ImportECDSA(priv, keyAuth)
+}
+
+func (am *Manager) ImportECDSA(priv *ecdsa.PrivateKey, keyAuth string) (Account, error) {
+ key := newKeyFromECDSA(priv)
+ if err := am.keyStore.StoreKey(key, keyAuth); err != nil {
return Account{}, err
}
return Account{Address: key.Address}, nil
}
func (am *Manager) Update(addr common.Address, authFrom, authTo string) (err error) {
- var key *crypto.Key
+ var key *Key
key, err = am.keyStore.GetKey(addr, authFrom)
if err == nil {
@@ -241,8 +249,8 @@ func (am *Manager) Update(addr common.Address, authFrom, authTo string) (err err
}
func (am *Manager) ImportPreSaleKey(keyJSON []byte, password string) (acc Account, err error) {
- var key *crypto.Key
- key, err = crypto.ImportPreSaleKey(am.keyStore, keyJSON, password)
+ var key *Key
+ key, err = importPreSaleKey(am.keyStore, keyJSON, password)
if err != nil {
return
}