github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/hdwallet/hdwalletexport.go (about) 1 // Copyright (c) 2022 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package hdwallet 7 8 import ( 9 "github.com/pkg/errors" 10 "github.com/spf13/cobra" 11 12 "github.com/iotexproject/iotex-core/ioctl" 13 "github.com/iotexproject/iotex-core/ioctl/config" 14 ) 15 16 // Multi-language support 17 var ( 18 _hdwalletExportCmdShorts = map[config.Language]string{ 19 config.English: "export hdwallet mnemonic using password", 20 config.Chinese: "通过密码导出钱包助记词", 21 } 22 ) 23 24 // NewHdwalletExportCmd represents the hdwallet export command 25 func NewHdwalletExportCmd(client ioctl.Client) *cobra.Command { 26 short, _ := client.SelectTranslation(_hdwalletExportCmdShorts) 27 28 return &cobra.Command{ 29 Use: "export", 30 Short: short, 31 Args: cobra.ExactArgs(0), 32 RunE: func(cmd *cobra.Command, args []string) error { 33 cmd.SilenceUsage = true 34 35 cmd.Println("Enter password") 36 password, err := client.ReadSecret() 37 if err != nil { 38 return errors.Wrap(err, "failed to get password") 39 } 40 41 mnemonic, err := client.HdwalletMnemonic(password) 42 if err != nil { 43 return errors.Wrap(err, "failed to export mnemonic") 44 } 45 cmd.Printf("Mnemonic phrase: %s"+ 46 "It is used to recover your wallet in case you forgot the password. Write them down and store it in a safe place.\n", mnemonic) 47 return nil 48 }, 49 } 50 }