mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
mobile, accounts/keystore: enable export of private key
This commit is contained in:
parent
55599ee95d
commit
0553c2cf5e
2 changed files with 18 additions and 0 deletions
|
|
@ -444,6 +444,15 @@ func (ks *KeyStore) Import(keyJSON []byte, passphrase, newPassphrase string) (ac
|
||||||
return ks.importKey(key, newPassphrase)
|
return ks.importKey(key, newPassphrase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExportECDSA exports as an unencrypted key.
|
||||||
|
func (ks *KeyStore) ExportECDSA(a accounts.Account, passphrase string) (priv *ecdsa.PrivateKey, err error) {
|
||||||
|
_, key, err := ks.getDecryptedKey(a, passphrase)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return key.PrivateKey, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ImportECDSA stores the given key into the key directory, encrypting it with the passphrase.
|
// ImportECDSA stores the given key into the key directory, encrypting it with the passphrase.
|
||||||
func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (accounts.Account, error) {
|
func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (accounts.Account, error) {
|
||||||
key := newKeyFromECDSA(priv)
|
key := newKeyFromECDSA(priv)
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,15 @@ func (ks *KeyStore) ExportKey(account *Account, passphrase, newPassphrase string
|
||||||
return ks.keystore.Export(account.account, passphrase, newPassphrase)
|
return ks.keystore.Export(account.account, passphrase, newPassphrase)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExportECDSA exports as an unencrypted key.
|
||||||
|
func (ks *KeyStore) ExportECDSAKey(account *Account, passphrase string) (key []byte, _ error) {
|
||||||
|
priv, err := ks.keystore.ExportECDSA(account.account, passphrase)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return crypto.FromECDSA(priv), nil
|
||||||
|
}
|
||||||
|
|
||||||
// ImportKey stores the given encrypted JSON key into the key directory.
|
// ImportKey stores the given encrypted JSON key into the key directory.
|
||||||
func (ks *KeyStore) ImportKey(keyJSON []byte, passphrase, newPassphrase string) (account *Account, _ error) {
|
func (ks *KeyStore) ImportKey(keyJSON []byte, passphrase, newPassphrase string) (account *Account, _ error) {
|
||||||
acc, err := ks.keystore.Import(common.CopyBytes(keyJSON), passphrase, newPassphrase)
|
acc, err := ks.keystore.Import(common.CopyBytes(keyJSON), passphrase, newPassphrase)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue