Skip to content

Commit

Permalink
Merge PR #1451: crypto/keys: move checksum size into constants
Browse files Browse the repository at this point in the history
Closes #1410
  • Loading branch information
ValarDragon authored and cwgoes committed Jun 29, 2018
1 parent b66a5cc commit 24a68d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crypto/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ExamplePrintRegisteredTypes() {
func TestKeyEncodings(t *testing.T) {
cases := []struct {
privKey tcrypto.PrivKey
privSize, pubSize int // binary sizes
privSize, pubSize int // binary sizes with the amino overhead
}{
{
privKey: tcrypto.GenPrivKeyEd25519(),
Expand Down
10 changes: 8 additions & 2 deletions crypto/keys/bip39/wordcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ type ValidSentenceLen uint8
const (
// FundRaiser is the sentence length used during the cosmos fundraiser (12 words).
FundRaiser ValidSentenceLen = 12
// Size of the checksum employed for the fundraiser
FundRaiserChecksumSize = 4
// FreshKey is the sentence length used for newly created keys (24 words).
FreshKey ValidSentenceLen = 24
// Size of the checksum employed for new keys
FreshKeyChecksumSize = 8
)

// NewMnemonic will return a string consisting of the mnemonic words for
Expand All @@ -23,9 +27,11 @@ func NewMnemonic(len ValidSentenceLen) (words []string, err error) {
var entropySize int
switch len {
case FundRaiser:
entropySize = 128
// entropySize = 128
entropySize = int(len)*11 - FundRaiserChecksumSize
case FreshKey:
entropySize = 256
// entropySize = 256
entropySize = int(len)*11 - FreshKeyChecksumSize
}
var entropy []byte
entropy, err = bip39.NewEntropy(entropySize)
Expand Down

0 comments on commit 24a68d3

Please sign in to comment.