From 24a68d3bdf7adb1096af7a9aa2c422de8f712c5b Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 29 Jun 2018 00:52:32 -0700 Subject: [PATCH] Merge PR #1451: crypto/keys: move checksum size into constants Closes #1410 --- crypto/encode_test.go | 2 +- crypto/keys/bip39/wordcodec.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crypto/encode_test.go b/crypto/encode_test.go index f0627d4c4..f9ab851b4 100644 --- a/crypto/encode_test.go +++ b/crypto/encode_test.go @@ -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(), diff --git a/crypto/keys/bip39/wordcodec.go b/crypto/keys/bip39/wordcodec.go index d874fe58c..074d1393c 100644 --- a/crypto/keys/bip39/wordcodec.go +++ b/crypto/keys/bip39/wordcodec.go @@ -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 @@ -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)