btc+lnd: allow to paste seed with numbers, dots and spaces from lnd backup output

pull/17/head
Oliver Gugger 4 years ago
parent af2094bafc
commit b5d3485fe0
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

@ -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)

@ -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()

Loading…
Cancel
Save