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)
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user