Skip to content
This repository has been archived by the owner on Jul 15, 2018. It is now read-only.

keys package: fundraiser compatibility and HD keys (BIP 39 & BIP 32 / BIP 44) #118

Merged
merged 28 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
16678ac
WIP: bip39/32/44 things
liamsi Jun 6, 2018
b584bdb
WIP: bip39/32/44 things, delete code
liamsi Jun 6, 2018
134795e
WIP: bip39/32/44 things: delete more code!
liamsi Jun 7, 2018
310c22e
some test vectors, delete obsolete tests, params moved to hd package
liamsi Jun 7, 2018
fc16d36
minor cleanups
liamsi Jun 7, 2018
bdff560
unexport methods for a cleaner interface, some code cleanup
liamsi Jun 8, 2018
ca85172
cleanup, renaming according to latest discussions
liamsi Jun 8, 2018
9f5eabf
reactivate and adapt some tests
liamsi Jun 8, 2018
b702429
reactivate and adapt more tests
liamsi Jun 8, 2018
55f3a86
all tests working again
liamsi Jun 9, 2018
e625d6f
some quick refactoring: use enum instead of strings for language
liamsi Jun 9, 2018
58a13c9
WIP: properly document everything ...
liamsi Jun 11, 2018
8e46bed
merging changes from development
liamsi Jun 11, 2018
e5dff33
Merge remote-tracking branch 'remotes/origin/develop' into bip39-2nd-…
liamsi Jun 12, 2018
af28f3a
Merge remote-tracking branch 'remotes/origin/develop' into bip39-2nd-…
liamsi Jun 12, 2018
54b9bd5
document things
liamsi Jun 12, 2018
e9506fc
document more things
liamsi Jun 12, 2018
9d30e65
remove TODOs (we currently only support english)
liamsi Jun 12, 2018
2251ce0
replace common.Panic* with vanilla panic
liamsi Jun 12, 2018
64ea127
print using t.Log(f)
liamsi Jun 12, 2018
1b6c7b8
consistent line breaks for method params
liamsi Jun 12, 2018
1b92b7f
sentinel errors / 'constant' errors to further expose suppported lang…
liamsi Jun 12, 2018
301a30e
review comment: iota+1
liamsi Jun 12, 2018
723ac19
Merge remote-tracking branch 'remotes/origin/develop' into bip39-2nd-…
liamsi Jun 19, 2018
5c539d8
catch up with development
liamsi Jun 19, 2018
7e69a9a
review comments:
liamsi Jun 20, 2018
86405ce
review comments:
liamsi Jun 20, 2018
6a675f5
Merge remote-tracking branch 'remotes/fork/bip39-2nd-approach' into b…
liamsi Jun 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
name = "github.com/btcsuite/btcutil"
branch = "master"

[[constraint]]
name = "github.com/howeyc/crc16"
branch = "master"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ check: check_tools
# Command to generate the workd list (kept here for documentation purposes only):
wordlist:
# To re-generate wordlist.go run:
# go-bindata -ignore ".*\.go" -o keys/words/wordlist/wordlist.go -pkg "wordlist" keys/words/wordlist/...
# go-bindata -ignore ".*\.go" -o keys/words/bip39/wordlist.go -pkg "wordlist" keys/bip39/wordlist/...

build: wordlist
# Nothing else to build!
Expand Down
1 change: 1 addition & 0 deletions amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func init() {
RegisterAmino(cdc)
}

// RegisterAmino registers all go-crypto related types in the given (amino) codec.
func RegisterAmino(cdc *amino.Codec) {
cdc.RegisterInterface((*PubKey)(nil), nil)
cdc.RegisterConcrete(PubKeyEd25519{},
Expand Down
8 changes: 4 additions & 4 deletions armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ package crypto

import (
"bytes"
"fmt"
"io/ioutil"

. "github.com/tendermint/tmlibs/common"
"golang.org/x/crypto/openpgp/armor"
)

func EncodeArmor(blockType string, headers map[string]string, data []byte) string {
buf := new(bytes.Buffer)
w, err := armor.Encode(buf, blockType, headers)
if err != nil {
PanicSanity("Error encoding ascii armor: " + err.Error())
panic(fmt.Errorf("could not encode ascii armor: %s", err))
}
_, err = w.Write(data)
if err != nil {
PanicSanity("Error encoding ascii armor: " + err.Error())
panic(fmt.Errorf("could not encode ascii armor: %s", err))
}
err = w.Close()
if err != nil {
PanicSanity("Error encoding ascii armor: " + err.Error())
panic(fmt.Errorf("could not encode ascii armor: %s", err))
}
return buf.String()
}
Expand Down
2 changes: 1 addition & 1 deletion keys/bcrypt/bcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type hashed struct {
// to compare the returned hashed password with its cleartext version.
func GenerateFromPassword(salt []byte, password []byte, cost int) ([]byte, error) {
if len(salt) != maxSaltSize {
return nil, fmt.Errorf("Salt len must be %v", maxSaltSize)
return nil, fmt.Errorf("salt len must be %v", maxSaltSize)
}
p, err := newFromPassword(salt, password, cost)
if err != nil {
Expand Down
62 changes: 62 additions & 0 deletions keys/bip39/wordcodec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package bip39

import (
"strings"

"github.com/bartekn/go-bip39"
)

// ValidSentenceLen defines the mnemonic sentence lengths supported by this BIP 39 library.
type ValidSentenceLen uint8

const (
// FundRaiser is the sentence length used during the cosmos fundraiser (12 words).
FundRaiser ValidSentenceLen = 12
// FreshKey is the sentence length used for newly created keys (24 words).
FreshKey ValidSentenceLen = 24
)

// NewMnemonic will return a string consisting of the mnemonic words for
// the given sentence length.
func NewMnemonic(len ValidSentenceLen) (words []string, err error) {
// len = (ENT + checksum) / 11
var ENT int
switch len {
case FundRaiser:
ENT = 128
case FreshKey:
ENT = 256
}
var entropy []byte
entropy, err = bip39.NewEntropy(ENT)
if err != nil {
return
}
var mnemonic string
mnemonic, err = bip39.NewMnemonic(entropy)
if err != nil {
return
}
words = strings.Split(mnemonic, " ")
return
}

// MnemonicToSeed creates a BIP 39 seed from the passed mnemonic (with an empty BIP 39 password).
// This method does not validate the mnemonics checksum.
func MnemonicToSeed(mne string) (seed []byte) {
// we do not checksum here...
seed = bip39.NewSeed(mne, "")
return
}

// MnemonicToSeedWithErrChecking returns the same seed as MnemonicToSeed.
// It creates a BIP 39 seed from the passed mnemonic (with an empty BIP 39 password).
//
// Different from MnemonicToSeed it validates the checksum.
// For details on the checksum see the BIP 39 spec.
func MnemonicToSeedWithErrChecking(mne string) (seed []byte, err error) {
seed, err = bip39.NewSeedWithErrorChecking(mne, "")
return
}


15 changes: 15 additions & 0 deletions keys/bip39/wordcodec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package bip39

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestWordCodec_NewMnemonic(t *testing.T) {
_, err := NewMnemonic(FundRaiser)
assert.NoError(t, err, "unexpected error generating fundraiser mnemonic")

_, err = NewMnemonic(FreshKey)
assert.NoError(t, err, "unexpected error generating new 24-word mnemonic")
}
Loading