-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix keys migrate
command
#8703
Fix keys migrate
command
#8703
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,10 @@ type Importer interface { | |
|
||
// ImportPubKey imports ASCII armored public keys. | ||
ImportPubKey(uid string, armor string, keyType KeyType) error | ||
|
||
// MigrateInfo takes a keyring.Info (in practise, from an old keyring), and | ||
// writes it to the current keyring. | ||
MigrateInfo(oldInfo Info) error | ||
} | ||
|
||
// Exporter is implemented by key stores that support export of public and private keys. | ||
|
@@ -305,20 +309,20 @@ func (ks keystore) ImportPubKey(uid string, armor string, keyType KeyType) error | |
return err | ||
} | ||
|
||
pubKey, err := legacy.AminoPubKeyFromBytes(pubBytes) | ||
pubKey, err := legacy.PubKeyFromBytes(pubBytes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if keyType == TypeMulti { | ||
_, err = ks.writeMultisigKey(uid, &pubKey) | ||
_, err = ks.writeMultisigKey(uid, pubKey) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if keyType == TypeOffline || keyType == TypeLedger { | ||
_, err = ks.writeOfflineKey(uid, &pubKey, hd.PubKeyType(algo)) | ||
_, err = ks.writeOfflineKey(uid, pubKey, hd.PubKeyType(algo)) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -327,6 +331,15 @@ func (ks keystore) ImportPubKey(uid string, armor string, keyType KeyType) error | |
return nil | ||
} | ||
|
||
// MigrateInfo implements Importer.MigrateInfo. | ||
func (ks keystore) MigrateInfo(oldInfo Info) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only for BeforeThe old migration logic was inside In the process, we completely lose the Info: we were migrating old TypeMulti and old TypeLedger into new TypeOffline. #8639 (comment) AfterWe don't decode Info anymore (to extract pubkey etc). Since the infos didn't change, we just copy/paste the old Info into the new keyring. It's imo much simpler. |
||
if _, err := ks.Key(oldInfo.GetName()); err == nil { | ||
return fmt.Errorf("cannot overwrite key: %s", oldInfo.GetName()) | ||
} | ||
|
||
return ks.writeInfo(oldInfo) | ||
} | ||
|
||
func (ks keystore) Sign(uid string, msg []byte) ([]byte, types.PubKey, error) { | ||
info, err := ks.Key(uid) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImportPubKey
is only used in tests now. I propose to remove it in a subsequent PR (to not introduce breaking change). For reasons, see #8703 (comment).