Skip to content

Commit b5d3485

Browse files
committed
btc+lnd: allow to paste seed with numbers, dots and spaces from lnd backup output
1 parent af2094b commit b5d3485

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

btc/bip39.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func ReadMnemonicFromTerminal(params *chaincfg.Params) (*hdkeychain.ExtendedKey,
3030
fmt.Println()
3131

3232
// We'll trim off extra spaces, and ensure the mnemonic is all
33-
// lower case, then populate our request.
33+
// lower case.
3434
mnemonicStr = strings.TrimSpace(mnemonicStr)
3535
mnemonicStr = strings.ToLower(mnemonicStr)
3636

lnd/aezeed.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"fmt"
66
"os"
7+
"regexp"
78
"strings"
89
"syscall"
910
"time"
@@ -14,6 +15,11 @@ import (
1415
"golang.org/x/crypto/ssh/terminal"
1516
)
1617

18+
var (
19+
numberDotsRegex = regexp.MustCompile("[\\d.\\-\\n\\r\\t]*")
20+
multipleSpaces = regexp.MustCompile(" [ ]+")
21+
)
22+
1723
func ReadAezeedFromTerminal(params *chaincfg.Params) (*hdkeychain.ExtendedKey,
1824
time.Time, error) {
1925

@@ -26,10 +32,17 @@ func ReadAezeedFromTerminal(params *chaincfg.Params) (*hdkeychain.ExtendedKey,
2632
}
2733

2834
// We'll trim off extra spaces, and ensure the mnemonic is all
29-
// lower case, then populate our request.
35+
// lower case.
3036
mnemonicStr = strings.TrimSpace(mnemonicStr)
3137
mnemonicStr = strings.ToLower(mnemonicStr)
3238

39+
// To allow the tool to also accept the copy/pasted version of the
40+
// backup text (which contains numbers and dots and multiple spaces),
41+
// we do some more cleanup with regex.
42+
mnemonicStr = numberDotsRegex.ReplaceAllString(mnemonicStr, "")
43+
mnemonicStr = multipleSpaces.ReplaceAllString(mnemonicStr, " ")
44+
mnemonicStr = strings.TrimSpace(mnemonicStr)
45+
3346
cipherSeedMnemonic := strings.Split(mnemonicStr, " ")
3447

3548
fmt.Println()

0 commit comments

Comments
 (0)