Merge PR #1451: crypto/keys: move checksum size into constants

Closes #1410
This commit is contained in:
Dev Ojha 2018-06-29 00:52:32 -07:00 committed by Christopher Goes
parent b66a5cc853
commit 24a68d3bdf
2 changed files with 9 additions and 3 deletions

View File

@ -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(),

View File

@ -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)