-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Main purpose of this is to quickly test wallet builds that require seeds that are external to the wallet's db
- Loading branch information
1 parent
d62e8e5
commit 0f87b66
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |