Allow for Different Language Mnemonic Recovery (#6913)

* allow for different language mnemonics

* imports
This commit is contained in:
Raul Jordan 2020-08-06 15:33:28 -05:00 committed by GitHub
parent 5a216de6d2
commit ac82308e03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -40,6 +40,8 @@ go_library(
"@com_github_pkg_errors//:go_default_library", "@com_github_pkg_errors//:go_default_library",
"@com_github_schollz_progressbar_v3//:go_default_library", "@com_github_schollz_progressbar_v3//:go_default_library",
"@com_github_sirupsen_logrus//: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_urfave_cli_v2//:go_default_library",
"@com_github_wealdtech_go_eth2_wallet_encryptor_keystorev4//:go_default_library", "@com_github_wealdtech_go_eth2_wallet_encryptor_keystorev4//:go_default_library",
], ],

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"sort"
"strconv" "strconv"
"strings" "strings"
@ -12,6 +13,8 @@ import (
"github.com/prysmaticlabs/prysm/validator/flags" "github.com/prysmaticlabs/prysm/validator/flags"
v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2" v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
"github.com/prysmaticlabs/prysm/validator/keymanager/v2/derived" "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" "github.com/urfave/cli/v2"
) )
@ -99,6 +102,34 @@ func inputMnemonic(cliCtx *cli.Context) (string, error) {
} }
return enteredMnemonic, nil 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) mnemonicPhrase, err := promptutil.ValidatePrompt("Enter the seed phrase for the wallet you would like to recover", validateMnemonic)
if err != nil { if err != nil {
return "", fmt.Errorf("could not get mnemonic phrase: %v", err) return "", fmt.Errorf("could not get mnemonic phrase: %v", err)