Merge PR #1659: crypto/keys: Allow one to export their private key
* crypto/keys: Allow one to export their private key * Update changelog
This commit is contained in:
parent
41dd01906a
commit
98bc419d5e
|
@ -109,6 +109,7 @@ FEATURES
|
|||
- Auth has its invariants checked within the framework
|
||||
* [tests] Add WaitForNextNBlocksTM helper method
|
||||
* [keys] New keys now have 24 word recovery keys, for heightened security
|
||||
- [keys] Add a temporary method for exporting the private key
|
||||
|
||||
IMPROVEMENTS
|
||||
* [x/bank] Now uses go-wire codec instead of 'encoding/json'
|
||||
|
|
|
@ -240,6 +240,31 @@ func (kb dbKeybase) Sign(name, passphrase string, msg []byte) (sig tcrypto.Signa
|
|||
return sig, pub, nil
|
||||
}
|
||||
|
||||
func (kb dbKeybase) ExportPrivateKeyObject(name string, passphrase string) (tcrypto.PrivKey, error) {
|
||||
info, err := kb.Get(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var priv tcrypto.PrivKey
|
||||
switch info.(type) {
|
||||
case localInfo:
|
||||
linfo := info.(localInfo)
|
||||
if linfo.PrivKeyArmor == "" {
|
||||
err = fmt.Errorf("private key not available")
|
||||
return nil, err
|
||||
}
|
||||
priv, err = unarmorDecryptPrivKey(linfo.PrivKeyArmor, passphrase)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case ledgerInfo:
|
||||
return nil, errors.New("Only works on local private keys")
|
||||
case offlineInfo:
|
||||
return nil, errors.New("Only works on local private keys")
|
||||
}
|
||||
return priv, nil
|
||||
}
|
||||
|
||||
func (kb dbKeybase) Export(name string) (armor string, err error) {
|
||||
bz := kb.db.Get(infoKey(name))
|
||||
if bz == nil {
|
||||
|
|
|
@ -39,6 +39,9 @@ type Keybase interface {
|
|||
ImportPubKey(name string, armor string) (err error)
|
||||
Export(name string) (armor string, err error)
|
||||
ExportPubKey(name string) (armor string, err error)
|
||||
|
||||
// *only* works on locally-stored keys. Temporary method until we redo the exporting API
|
||||
ExportPrivateKeyObject(name string, passphrase string) (crypto.PrivKey, error)
|
||||
}
|
||||
|
||||
// Info is the publicly exposed information about a keypair
|
||||
|
|
Loading…
Reference in New Issue