You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

  1. // Copyright © 2017 Ethan Frey
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package cmd
  15. import (
  16. "github.com/pkg/errors"
  17. "github.com/spf13/cobra"
  18. )
  19. // recoverCmd represents the recover command
  20. var recoverCmd = &cobra.Command{
  21. Use: "recover [name]",
  22. Short: "Recover a private key from a seed phrase",
  23. Long: `Recover a private key from a seed phrase.
  24. I really hope you wrote this down when you created the new key.
  25. The seed is only displayed on creation, never again.
  26. You can also use this to copy a key between multiple testnets,
  27. simply by "recovering" the key in the other nets you want to copy
  28. to. Of course, it has no coins on the other nets, just the same address.`,
  29. RunE: runRecoverCmd,
  30. }
  31. func runRecoverCmd(cmd *cobra.Command, args []string) error {
  32. if len(args) != 1 || len(args[0]) == 0 {
  33. return errors.New("You must provide a name for the key")
  34. }
  35. name := args[0]
  36. pass, err := getPassword("Enter the new passphrase:")
  37. if err != nil {
  38. return err
  39. }
  40. // not really a password... huh?
  41. seed, err := getSeed("Enter your recovery seed phrase:")
  42. if err != nil {
  43. return err
  44. }
  45. info, err := GetKeyManager().Recover(name, pass, seed)
  46. if err != nil {
  47. return err
  48. }
  49. printInfo(info)
  50. return nil
  51. }