diff --git a/validator/accounts/v2/BUILD.bazel b/validator/accounts/v2/BUILD.bazel index cf3318954..1b90db529 100644 --- a/validator/accounts/v2/BUILD.bazel +++ b/validator/accounts/v2/BUILD.bazel @@ -40,6 +40,8 @@ go_library( "@com_github_pkg_errors//:go_default_library", "@com_github_schollz_progressbar_v3//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", + "@com_github_tyler_smith_go_bip39//:go_default_library", + "@com_github_tyler_smith_go_bip39//wordlists:go_default_library", "@com_github_urfave_cli_v2//:go_default_library", "@com_github_wealdtech_go_eth2_wallet_encryptor_keystorev4//:go_default_library", ], diff --git a/validator/accounts/v2/wallet_recover.go b/validator/accounts/v2/wallet_recover.go index b91a75983..522de9fab 100644 --- a/validator/accounts/v2/wallet_recover.go +++ b/validator/accounts/v2/wallet_recover.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io/ioutil" + "sort" "strconv" "strings" @@ -12,6 +13,8 @@ import ( "github.com/prysmaticlabs/prysm/validator/flags" v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2" "github.com/prysmaticlabs/prysm/validator/keymanager/v2/derived" + "github.com/tyler-smith/go-bip39" + "github.com/tyler-smith/go-bip39/wordlists" "github.com/urfave/cli/v2" ) @@ -99,6 +102,34 @@ func inputMnemonic(cliCtx *cli.Context) (string, error) { } return enteredMnemonic, nil } + allowedLanguages := map[string][]string{ + "english": wordlists.English, + "chinese_simplified": wordlists.ChineseSimplified, + "chinese_traditional": wordlists.ChineseTraditional, + "french": wordlists.French, + "italian": wordlists.Italian, + "japanese": wordlists.Japanese, + "korean": wordlists.Korean, + "spanish": wordlists.Spanish, + } + languages := make([]string, 0) + for k := range allowedLanguages { + languages = append(languages, k) + } + sort.Strings(languages) + selectedLanguage, err := promptutil.ValidatePrompt( + fmt.Sprintf("Enter the language of your seed phrase: %s", strings.Join(languages, ", ")), + func(input string) error { + if _, ok := allowedLanguages[input]; !ok { + return errors.New("input not in the list of allowed languages") + } + return nil + }, + ) + if err != nil { + return "", fmt.Errorf("could not get mnemonic language: %v", err) + } + bip39.SetWordList(allowedLanguages[selectedLanguage]) mnemonicPhrase, err := promptutil.ValidatePrompt("Enter the seed phrase for the wallet you would like to recover", validateMnemonic) if err != nil { return "", fmt.Errorf("could not get mnemonic phrase: %v", err)