Skip to content

Commit

Permalink
Merge pull request cosmos#46 from tendermint/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ebuchman authored Oct 27, 2017
2 parents 311e8c1 + 8630b72 commit d1f00be
Show file tree
Hide file tree
Showing 41 changed files with 1,455 additions and 788 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.4.0 (October 27, 2017)

BREAKING CHANGES:

- `keys`: use bcrypt plus salt

FEATURES:

- add support for signing via Ledger Nano

IMPROVEMENTS:

- linting and comments

## 0.3.0 (September 22, 2017)

BREAKING CHANGES:
Expand Down
42 changes: 39 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

GOTOOLS = \
github.com/Masterminds/glide \
github.com/jteeuwen/go-bindata/go-bindata
github.com/jteeuwen/go-bindata/go-bindata \
github.com/alecthomas/gometalinter

REPO:=github.com/tendermint/go-crypto

all: get_vendor_deps test
all: get_vendor_deps metalinter_test test

test:
go test `glide novendor`
go test -p 1 `glide novendor`

get_vendor_deps: ensure_tools
@rm -rf vendor/
Expand All @@ -31,3 +33,37 @@ codegen:
@echo "--> regenerating all interface wrappers"
@gen
@echo "Done!"

metalinter: ensure_tools
@gometalinter --install
gometalinter --vendor --deadline=600s --enable-all --disable=lll ./...

metalinter_test: ensure_tools
@gometalinter --install
gometalinter --vendor --deadline=600s --disable-all \
--enable=deadcode \
--enable=gas \
--enable=goconst \
--enable=gocyclo \
--enable=gosimple \
--enable=ineffassign \
--enable=interfacer \
--enable=maligned \
--enable=megacheck \
--enable=misspell \
--enable=safesql \
--enable=staticcheck \
--enable=structcheck \
--enable=unconvert \
--enable=unused \
--enable=vetshadow \
--enable=vet \
--enable=varcheck \
./...

#--enable=dupl \
#--enable=errcheck \
#--enable=goimports \
#--enable=golint \ <== comments on anything exported
#--enable=gotype \
#--enable=unparam \
6 changes: 0 additions & 6 deletions _gen.go

This file was deleted.

2 changes: 1 addition & 1 deletion armor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func EncodeArmor(blockType string, headers map[string]string, data []byte) strin
if err != nil {
PanicSanity("Error encoding ascii armor: " + err.Error())
}
return string(buf.Bytes())
return buf.String()
}

func DecodeArmor(armorStr string) (blockType string, headers map[string]string, data []byte, err error) {
Expand Down
2 changes: 1 addition & 1 deletion bcrypt/bcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (ih InvalidHashPrefixError) Error() string {
type InvalidCostError int

func (ic InvalidCostError) Error() string {
return fmt.Sprintf("crypto/bcrypt: cost %d is outside allowed range (%d,%d)", int(ic), int(MinCost), int(MaxCost))
return fmt.Sprintf("crypto/bcrypt: cost %d is outside allowed range (%d,%d)", int(ic), int(MinCost), int(MaxCost)) // nolint: unconvert
}

const (
Expand Down
48 changes: 48 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
go-crypto is a customized/convenience cryptography package
for supporting Tendermint.
It wraps select functionality of equivalent functions in the
Go standard library, for easy usage with our libraries.
Keys:
All key generation functions return an instance of the PrivKey interface
which implements methods
AssertIsPrivKeyInner()
Bytes() []byte
Sign(msg []byte) Signature
PubKey() PubKey
Equals(PrivKey) bool
Wrap() PrivKey
From the above method we can:
a) Retrieve the public key if needed
pubKey := key.PubKey()
For example:
privKey, err := crypto.GenPrivKeyEd25519()
if err != nil {
...
}
pubKey := privKey.PubKey()
...
// And then you can use the private and public key
doSomething(privKey, pubKey)
We also provide hashing wrappers around algorithms:
Sha256
sum := crypto.Sha256([]byte("This is Tendermint"))
fmt.Printf("%x\n", sum)
Ripemd160
sum := crypto.Ripemd160([]byte("This is consensus"))
fmt.Printf("%x\n", sum)
*/
package crypto

// TODO: Add more docs in here
8 changes: 4 additions & 4 deletions embed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ func TestEncodeDemo(t *testing.T) {
// Try to encode as binary
b, err := data.ToWire(tc.in)
if assert.Nil(err, "%d: %#v", i, tc.in) {
err := data.FromWire(b, tc.out)
if assert.Nil(err) {
err2 := data.FromWire(b, tc.out)
if assert.Nil(err2) {
assert.Equal(tc.expected, tc.out.String())
}
}

// Try to encode it as json
j, err := data.ToJSON(tc.in)
if assert.Nil(err, "%d: %#v", i, tc.in) {
err := data.FromJSON(j, tc.out)
if assert.Nil(err) {
err2 := data.FromJSON(j, tc.out)
if assert.Nil(err2) {
assert.Equal(tc.expected, tc.out.String())
}
}
Expand Down
35 changes: 35 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2017 Tendermint. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package crypto_test

import (
"fmt"

"github.com/tendermint/go-crypto"
)

func ExampleSha256() {
sum := crypto.Sha256([]byte("This is Tendermint"))
fmt.Printf("%x\n", sum)
// Output:
// f91afb642f3d1c87c17eb01aae5cb65c242dfdbe7cf1066cc260f4ce5d33b94e
}

func ExampleRipemd160() {
sum := crypto.Ripemd160([]byte("This is Tendermint"))
fmt.Printf("%x\n", sum)
// Output:
// 051e22663e8f0fd2f2302f1210f954adff009005
}
56 changes: 17 additions & 39 deletions glide.lock

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

7 changes: 1 addition & 6 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ import:
- nacl/secretbox
- openpgp/armor
- ripemd160
- package: github.com/bgentry/speakeasy
- package: github.com/gorilla/handlers
- package: github.com/gorilla/mux
- package: github.com/pkg/errors
- package: github.com/spf13/cobra
- package: github.com/spf13/viper
- package: gopkg.in/go-playground/validator.v9
- package: github.com/howeyc/crc16
- package: github.com/ethanfrey/ledger
testImport:
- package: github.com/mndrix/btcutil
- package: github.com/stretchr/testify
Expand Down
Loading

0 comments on commit d1f00be

Please sign in to comment.