diff --git a/btc/bip39.go b/btc/bip39.go index dfaf146..f9579ba 100644 --- a/btc/bip39.go +++ b/btc/bip39.go @@ -30,7 +30,7 @@ func ReadMnemonicFromTerminal(params *chaincfg.Params) (*hdkeychain.ExtendedKey, fmt.Println() // We'll trim off extra spaces, and ensure the mnemonic is all - // lower case, then populate our request. + // lower case. mnemonicStr = strings.TrimSpace(mnemonicStr) mnemonicStr = strings.ToLower(mnemonicStr) diff --git a/lnd/aezeed.go b/lnd/aezeed.go index bba3c9f..67ea390 100644 --- a/lnd/aezeed.go +++ b/lnd/aezeed.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "os" + "regexp" "strings" "syscall" "time" @@ -14,6 +15,11 @@ import ( "golang.org/x/crypto/ssh/terminal" ) +var ( + numberDotsRegex = regexp.MustCompile("[\\d.\\-\\n\\r\\t]*") + multipleSpaces = regexp.MustCompile(" [ ]+") +) + func ReadAezeedFromTerminal(params *chaincfg.Params) (*hdkeychain.ExtendedKey, time.Time, error) { @@ -26,10 +32,17 @@ func ReadAezeedFromTerminal(params *chaincfg.Params) (*hdkeychain.ExtendedKey, } // We'll trim off extra spaces, and ensure the mnemonic is all - // lower case, then populate our request. + // lower case. mnemonicStr = strings.TrimSpace(mnemonicStr) mnemonicStr = strings.ToLower(mnemonicStr) + // To allow the tool to also accept the copy/pasted version of the + // backup text (which contains numbers and dots and multiple spaces), + // we do some more cleanup with regex. + mnemonicStr = numberDotsRegex.ReplaceAllString(mnemonicStr, "") + mnemonicStr = multipleSpaces.ReplaceAllString(mnemonicStr, " ") + mnemonicStr = strings.TrimSpace(mnemonicStr) + cipherSeedMnemonic := strings.Split(mnemonicStr, " ") fmt.Println()