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:
parent
af2094bafc
commit
b5d3485fe0
@ -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…
Reference in New Issue
Block a user