diff --git a/client/keys/add.go b/client/keys/add.go index f0055366ac9b..a39a374c8237 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -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 } diff --git a/crypto/keys/keybase.go b/crypto/keys/keybase.go index ad086b13c619..396bb5782109 100644 --- a/crypto/keys/keybase.go +++ b/crypto/keys/keybase.go @@ -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) diff --git a/crypto/keys/types.go b/crypto/keys/types.go index e143ed63d004..0e77725c3115 100644 --- a/crypto/keys/types.go +++ b/crypto/keys/types.go @@ -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.