-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R4R: Improve crypto/keys and add keys mnemonic
and keys new
commands
#2090
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b1064a5
crypto/keys/hd: use btcec to remove dep on tendermint
ebuchman cc61fa7
crypto/keys/bcrypt: improve comment about fork
ebuchman 115ec48
crypto/keys/bip39 -> crypto/keys/bip39/fundraiser
ebuchman d9390bf
crypto/keys/bip39: bring in fork of tyler-smith
ebuchman 860a1ce
crypto/keys/hd: update dep
ebuchman bd4876b
crypto/keys: update deps
ebuchman 930b934
crypto/keys: move mintkey.go into new crypto/keys/mintkey
ebuchman edc414b
crypto/keys/hd: NewParamsFromPath
ebuchman e79e35e
crypto/keys: keybase.Derive takes a bip39 passphrase too
ebuchman d743d10
crypto/keys/hd: BIP44Params.DerivationPath
ebuchman fcd3c86
gaiacli keys: add commands new and mnemonic
ebuchman 9d6f065
fix lints
ebuchman 32bc332
minor fixes from review
ebuchman f761d96
update Gopkg.toml
ebuchman 5fa2da1
crypto/keys/bcrypt: remove
ebuchman 27a5815
crypto/keys/bip39: remove completely
ebuchman 5b2221d
Gopkg.toml: dont use master
ebuchman f900022
Merge branch 'develop' into bucky/keys
cwgoes 24e8ec1
Pull in changes from my PR
mslipper fd8a1ee
Merge pull request #2196 from mslipper/bucky/keys
jackzampolin b22f835
Merge branch 'develop' into bucky/keys
ebuchman a41c32d
fixes from review
ebuchman a5bb443
enforce min len for --unsafe-entropy
ebuchman f3ec6bc
Merge remote-tracking branch 'origin/develop' into bucky/keys
rigelrozanski 57abdc8
lint fix
rigelrozanski 82f4def
Merge branch 'develop' into bucky/keys
ebuchman ac6bceb
feedback from review
ebuchman 71513e5
fix dep
ebuchman 96c0739
Merge branch 'develop' into bucky/keys
cwgoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,78 @@ | ||
package keys | ||
|
||
import ( | ||
"crypto/sha256" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/spf13/cobra" | ||
|
||
bip39 "github.com/bartekn/go-bip39" | ||
) | ||
|
||
const ( | ||
flagUserEntropy = "unsafe-entropy" | ||
|
||
mnemonicEntropySize = 256 | ||
) | ||
ebuchman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func mnemonicKeyCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "mnemonic", | ||
Short: "Compute the bip39 mnemonic for some input entropy", | ||
Long: "Create a bip39 mnemonic, sometimes called a seed phrase, by reading from the system entropy. To pass your own entropy, use --unsafe-entropy", | ||
RunE: runMnemonicCmd, | ||
} | ||
cmd.Flags().Bool(flagUserEntropy, false, "Prompt the user to supply their own entropy, instead of relying on the system") | ||
return cmd | ||
} | ||
|
||
func runMnemonicCmd(cmd *cobra.Command, args []string) error { | ||
flags := cmd.Flags() | ||
|
||
userEntropy, _ := flags.GetBool(flagUserEntropy) | ||
|
||
var entropySeed []byte | ||
|
||
if userEntropy { | ||
// prompt the user to enter some entropy | ||
buf := client.BufferStdin() | ||
inputEntropy, err := client.GetString("> WARNING: Generate at least 256-bits of entropy and enter the results here:", buf) | ||
if err != nil { | ||
return err | ||
} | ||
if len(inputEntropy) < 43 { | ||
return fmt.Errorf("256-bits is 43 characters in Base-64, and 100 in Base-6. You entered %v, and probably want more", len(inputEntropy)) | ||
} | ||
conf, err := client.GetConfirmation( | ||
fmt.Sprintf("> Input length: %d", len(inputEntropy)), | ||
buf) | ||
if err != nil { | ||
return err | ||
} | ||
if !conf { | ||
return nil | ||
} | ||
|
||
// hash input entropy to get entropy seed | ||
hashedEntropy := sha256.Sum256([]byte(inputEntropy)) | ||
entropySeed = hashedEntropy[:] | ||
printStep() | ||
} else { | ||
// read entropy seed straight from crypto.Rand | ||
var err error | ||
entropySeed, err = bip39.NewEntropy(mnemonicEntropySize) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
mnemonic, err := bip39.NewMnemonic(entropySeed[:]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(mnemonic) | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it's better to avoid modifying
msg
and just do