Skip to content

Commit

Permalink
Allow wallet to accept hex or words as seed.
Browse files Browse the repository at this point in the history
Also clarify error message.

OK jrick, ay-p
  • Loading branch information
jcvernaleo committed Feb 11, 2016
1 parent a0e5863 commit 2a407e4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions walletsetup.go
Expand Up @@ -373,15 +373,27 @@ func promptConsoleSeed(reader *bufio.Reader) ([]byte, error) {
}

seedStrTrimmed := strings.TrimSpace(seedStr)
wordCount := strings.Count(seedStrTrimmed, " ") + 1

seed, err := pgpwordlist.ToBytesChecksum(seedStrTrimmed)
if err != nil || len(seed) < hdkeychain.MinSeedBytes ||
len(seed) > hdkeychain.MaxSeedBytes {
var seed []byte
if wordCount == 1 {
if len(seedStrTrimmed)%2 != 0 {
seedStrTrimmed = "0" + seedStrTrimmed
}
seed, err = hex.DecodeString(seedStrTrimmed)
if err != nil {
fmt.Printf("Input error: %v\n", err.Error())
}

} else {
seed, err = pgpwordlist.ToBytesChecksum(seedStrTrimmed)
if err != nil {
fmt.Printf("Input error: %v\n", err.Error())
}
}
if err != nil || len(seed) < hdkeychain.MinSeedBytes ||
len(seed) > hdkeychain.MaxSeedBytes {
fmt.Printf("Invalid seed specified. Must be a "+
"word seed (usually 33 words) using the PGP wordlist or "+
"hexadecimal value that is at least %d bits and "+
"at most %d bits\n", hdkeychain.MinSeedBytes*8,
hdkeychain.MaxSeedBytes*8)
Expand Down

0 comments on commit 2a407e4

Please sign in to comment.