Skip to content

Commit

Permalink
Merge PR #1477: gaiacli: Make recovery allow new keys
Browse files Browse the repository at this point in the history
* gaiacli: Make recovery allow new keys
* Move create key to a temporary method, restore create fundraiser key
  • Loading branch information
ValarDragon authored and cwgoes committed Jun 29, 2018
1 parent 097dd8a commit fc3dd56
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
info, err := kb.CreateFundraiserKey(name, seed, pass)
info, err := kb.CreateKey(name, seed, pass)
if err != nil {
return err
}
Expand Down
17 changes: 16 additions & 1 deletion crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,28 @@ func (kb dbKeybase) CreateMnemonic(name string, language Language, passwd string
return
}

// TEMPORARY METHOD UNTIL WE FIGURE OUT USER FACING HD DERIVATION API
func (kb dbKeybase) CreateKey(name, mnemonic, passwd string) (info Info, err error) {
words := strings.Split(mnemonic, " ")
if len(words) != 12 && len(words) != 24 {
err = fmt.Errorf("recovering only works with 12 word (fundraiser) or 24 word mnemonics, got: %v words", len(words))
return
}
seed, err := bip39.MnemonicToSeedWithErrChecking(mnemonic)
if err != nil {
return
}
info, err = kb.persistDerivedKey(seed, passwd, name, hd.FullFundraiserPath)
return
}

// CreateFundraiserKey converts a mnemonic to a private key and persists it,
// encrypted with the given password.
// TODO(ismail)
func (kb dbKeybase) CreateFundraiserKey(name, mnemonic, passwd string) (info Info, err error) {
words := strings.Split(mnemonic, " ")
if len(words) != 12 {
err = fmt.Errorf("recovering only works with 12 word (fundraiser) mnemonics, got: %v words", len(words))
err = fmt.Errorf("recovering only works with 12 word (fundraiser), got: %v words", len(words))
return
}
seed, err := bip39.MnemonicToSeedWithErrChecking(mnemonic)
Expand Down
2 changes: 2 additions & 0 deletions crypto/keys/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Keybase interface {
// CreateMnemonic creates a new mnemonic, and derives a hierarchical deterministic
// key from that.
CreateMnemonic(name string, language Language, passwd string, algo SigningAlgo) (info Info, seed string, err error)
// CreateKey takes a mnemonic and derives, a password. This method is temporary
CreateKey(name, mnemonic, passwd string) (info Info, err error)
// CreateFundraiserKey takes a mnemonic and derives, a password
CreateFundraiserKey(name, mnemonic, passwd string) (info Info, err error)
// Derive derives a key from the passed mnemonic using a BIP44 path.
Expand Down

0 comments on commit fc3dd56

Please sign in to comment.