Skip to content

Commit

Permalink
cmd: creates generateseed command
Browse files Browse the repository at this point in the history
Main purpose of this is to quickly test wallet builds that require seeds that are external to the wallet's db
  • Loading branch information
githubsands committed Apr 20, 2020
1 parent d62e8e5 commit 0f87b66
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/genseed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generateseed returns a cryptographically secure random seed in either mnemonic or its hexadecimal form.
35 changes: 35 additions & 0 deletions cmd/genseed/generateseed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"encoding/hex"
"flag"
"fmt"
"github.com/decred/dcrwallet/walletseed"
"os"
)

var (
s = flag.Bool("mne", false, "Optional command line argument to print as seed as a mnemonic phrase rather then its hexadecimal form")
b = flag.Uint("size", 32, "Optional command line argument to print a seed as a certian size. The default size is 32 and recommended size is between 16 and 64. Anything under 16 or 64 will cause the program to crash")
m = flag.Bool("master", false, "Optional command line argument to print master key of the created seed.")
)

func main() {
flag.Parse()

sb, err := walletseed.GenerateRandomSeed(*b)
if err != nil {
fmt.Print(err)
os.Exit(1)
}

var seedString string
if *s {
seedString = walletseed.EncodeMnemonic(sb)
fmt.Printf("%v\n", seedString)
os.Exit(1)
}

seedString = hex.EncodeToString(sb)
fmt.Printf("%v\n", seedString)
}
20 changes: 20 additions & 0 deletions cmd/genseed/generateseedtest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Test 1: generateseed with no options
SEED=$(./genseed)
if [[ ${#SEED} -gt 64 || ${#SEED} -lt 16 ]]; then
echo "test 1 failed"
exit 1
fi

# Test 2: generateseed with option --mne set as true, and --size as 64
PARAMS=$(echo \
"--mne=true" \
"--size=64"
)

SEED2=$(./genseed $PARAMS)
if [[ $(echo ${#SEED2} | wc -c) -gt 500 ]]; then
echo "test 2 failed"
exit 1
fi

0 comments on commit 0f87b66

Please sign in to comment.