2
0
mirror of https://github.com/guggero/chantools synced 2024-11-17 03:25:39 +00:00

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

This commit is contained in:
Oliver Gugger 2020-08-06 17:04:06 +02:00
parent af2094bafc
commit b5d3485fe0
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 15 additions and 2 deletions

View File

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

View File

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