From f499ce871362f456e127da24fd3dc244dc863f00 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 12 Mar 2018 12:18:30 +0400 Subject: [PATCH 1/3] update go-amino --- Gopkg.lock | 6 +++--- Gopkg.toml | 2 +- README.md | 2 +- _nano/keys.go | 8 ++++---- wire.go => amino.go | 22 +++++++++++----------- encode_test.go | 16 ++++++++-------- glide.lock | 2 +- glide.yaml | 2 +- keys/wire.go | 8 ++++---- signature_test.go | 19 ++++++++++--------- 10 files changed, 44 insertions(+), 43 deletions(-) rename wire.go => amino.go (56%) diff --git a/Gopkg.lock b/Gopkg.lock index 6dd1154b1..b945d9199 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -125,9 +125,9 @@ [[projects]] branch = "develop" - name = "github.com/tendermint/go-wire" + name = "github.com/tendermint/go-amino" packages = ["."] - revision = "dec83f641903b22f039da3974607859715d0377e" + revision = "3b9e2b978447707c255922bc3f87a53d55c400c9" [[projects]] branch = "develop" @@ -163,6 +163,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "e0628df240b8ceeb91403f5218f5561d8580f15f3d5b0ea0da40710d1cba3707" + inputs-digest = "375b661ad202b62c6847981416c03ce0518c33ac293f5f0863b69af04d2af91f" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 058eb5838..84a26764e 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -47,7 +47,7 @@ [[constraint]] branch = "develop" - name = "github.com/tendermint/go-wire" + name = "github.com/tendermint/go-amino" [[constraint]] branch = "develop" diff --git a/README.md b/README.md index da76fe823..3c33532fc 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,4 @@ go-crypto is the cryptographic package adapted for Tendermint's uses ## Importing it -`import "github.com/tendermint/go-crypto"` \ No newline at end of file +`import "github.com/tendermint/go-crypto"` diff --git a/_nano/keys.go b/_nano/keys.go index b50efd7ec..8cf1c3721 100644 --- a/_nano/keys.go +++ b/_nano/keys.go @@ -9,7 +9,7 @@ import ( ledger "github.com/ethanfrey/ledger" crypto "github.com/tendermint/go-crypto" - wire "github.com/tendermint/go-wire" + amino "github.com/tendermint/go-amino" ) //nolint @@ -58,7 +58,7 @@ func signLedger(device *ledger.Ledger, msg []byte) (pub crypto.PubKey, sig crypt // PrivKeyLedgerEd25519 implements PrivKey, calling the ledger nano // we cache the PubKey from the first call to use it later type PrivKeyLedgerEd25519 struct { - // PubKey should be private, but we want to encode it via go-wire + // PubKey should be private, but we want to encode it via go-amino // so we can view the address later, even without having the ledger // attached CachedPubKey crypto.PubKey @@ -97,7 +97,7 @@ func (pk *PrivKeyLedgerEd25519) AssertIsPrivKeyInner() {} // Bytes fulfils PrivKey Interface - but it stores the cached pubkey so we can verify // the same key when we reconnect to a ledger func (pk *PrivKeyLedgerEd25519) Bytes() []byte { - return wire.BinaryBytes(pk.Wrap()) + return amino.BinaryBytes(pk.Wrap()) } // Sign calls the ledger and stores the PubKey for future use @@ -250,7 +250,7 @@ func PubKeyLedgerEd25519FromBytes(key [32]byte) crypto.PubKey { // Bytes fulfils pk Interface - no data, just type info func (pk PubKeyLedgerEd25519) Bytes() []byte { - return wire.BinaryBytes(pk.Wrap()) + return amino.BinaryBytes(pk.Wrap()) } // VerifyBytes uses the normal Ed25519 algorithm but a sha512 hash beforehand diff --git a/wire.go b/amino.go similarity index 56% rename from wire.go rename to amino.go index 18035964f..f9d7b9580 100644 --- a/wire.go +++ b/amino.go @@ -1,36 +1,36 @@ package crypto import ( - "github.com/tendermint/go-wire" + amino "github.com/tendermint/go-amino" ) -var cdc = wire.NewCodec() +var cdc = amino.NewCodec() func init() { // NOTE: It's important that there be no conflicts here, // as that would change the canonical representations, // and therefore change the address. - // TODO: Add feature to go-wire to ensure that there + // TODO: Add feature to go-amino to ensure that there // are no conflicts. - RegisterWire(cdc) + RegisterAmino(cdc) } -func RegisterWire(cdc *wire.Codec) { +func RegisterAmino(cdc *amino.Codec) { cdc.RegisterInterface((*PubKey)(nil), nil) cdc.RegisterConcrete(PubKeyEd25519{}, - "com.tendermint.wire.PubKeyEd25519", nil) + "com.tendermint.amino.PubKeyEd25519", nil) cdc.RegisterConcrete(PubKeySecp256k1{}, - "com.tendermint.wire.PubKeySecp256k1", nil) + "com.tendermint.amino.PubKeySecp256k1", nil) cdc.RegisterInterface((*PrivKey)(nil), nil) cdc.RegisterConcrete(PrivKeyEd25519{}, - "com.tendermint.wire.PrivKeyEd25519", nil) + "com.tendermint.amino.PrivKeyEd25519", nil) cdc.RegisterConcrete(PrivKeySecp256k1{}, - "com.tendermint.wire.PrivKeySecp256k1", nil) + "com.tendermint.amino.PrivKeySecp256k1", nil) cdc.RegisterInterface((*Signature)(nil), nil) cdc.RegisterConcrete(SignatureEd25519{}, - "com.tendermint.wire.SignatureKeyEd25519", nil) + "com.tendermint.amino.SignatureKeyEd25519", nil) cdc.RegisterConcrete(SignatureSecp256k1{}, - "com.tendermint.wire.SignatureKeySecp256k1", nil) + "com.tendermint.amino.SignatureKeySecp256k1", nil) } diff --git a/encode_test.go b/encode_test.go index bcd9e60c2..bc3f1a736 100644 --- a/encode_test.go +++ b/encode_test.go @@ -1,7 +1,7 @@ package crypto /* -XXX Needs to be refactored to not use go-wire/data +XXX Needs to be refactored to not use go-amino/data import ( "fmt" @@ -10,15 +10,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - wire "github.com/tendermint/go-wire" - data "github.com/tendermint/go-wire/data" + amino "github.com/tendermint/go-amino" + data "github.com/tendermint/go-amino/data" ) type byter interface { Bytes() []byte } -// go to wire encoding and back +// go to amino encoding and back func checkWire(t *testing.T, in byter, reader interface{}, typ byte, size int) { // test to and from binary bin, err := data.ToWire(in) @@ -55,15 +55,15 @@ func checkJSON(t *testing.T, in interface{}, reader interface{}, typ string) { assert.True(t, strings.Contains(string(js), parts[1])) } -// make sure go-wire json can still figure this out... +// make sure go-amino json can still figure this out... func checkWireJSON(t *testing.T, in interface{}, reader interface{}, typ byte) { // test to and from binary var err error - js := wire.JSONBytes(in) + js := amino.JSONBytes(in) btyp := fmt.Sprintf("[%d,", typ) assert.True(t, strings.HasPrefix(string(js), btyp), string(js), btyp) - wire.ReadJSON(reader, js, &err) + amino.ReadJSON(reader, js, &err) require.Nil(t, err, "%+v", err) } @@ -144,7 +144,7 @@ type SigMessage struct { } func (s SigMessage) Bytes() []byte { - return wire.BinaryBytes(s) + return amino.BinaryBytes(s) } func TestEmbededWireEncodings(t *testing.T) { diff --git a/glide.lock b/glide.lock index b97d8bc07..ff6e97630 100644 --- a/glide.lock +++ b/glide.lock @@ -59,7 +59,7 @@ imports: subpackages: - edwards25519 - extra25519 -- name: github.com/tendermint/go-wire +- name: github.com/tendermint/go-amino version: dec83f641903b22f039da3974607859715d0377e - name: github.com/tendermint/tmlibs version: 26f2ab65f82cfc6873c312e8030104c47c05f10e diff --git a/glide.yaml b/glide.yaml index d99809211..8e8b55b50 100644 --- a/glide.yaml +++ b/glide.yaml @@ -12,7 +12,7 @@ import: - package: github.com/tendermint/ed25519 subpackages: - extra25519 -- package: github.com/tendermint/go-wire +- package: github.com/tendermint/go-amino version: develop - package: github.com/tendermint/tmlibs version: develop diff --git a/keys/wire.go b/keys/wire.go index 65d69ba5e..7deaad673 100644 --- a/keys/wire.go +++ b/keys/wire.go @@ -1,12 +1,12 @@ package keys import ( - "github.com/tendermint/go-crypto" - "github.com/tendermint/go-wire" + amino "github.com/tendermint/go-amino" + crypto "github.com/tendermint/go-crypto" ) -var cdc = wire.NewCodec() +var cdc = amino.NewCodec() func init() { - crypto.RegisterWire(cdc) + crypto.RegisterAmino(cdc) } diff --git a/signature_test.go b/signature_test.go index 7bc94e677..b698e5167 100644 --- a/signature_test.go +++ b/signature_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/ed25519" - "github.com/tendermint/go-wire" + amino "github.com/tendermint/go-amino" ) func TestSignAndValidateEd25519(t *testing.T) { @@ -49,17 +49,17 @@ func TestSignatureEncodings(t *testing.T) { cases := []struct { privKey PrivKey sigSize int - sigPrefix wire.PrefixBytes + sigPrefix amino.PrefixBytes }{ { privKey: GenPrivKeyEd25519(), sigSize: ed25519.SignatureSize, - sigPrefix: [4]byte{0xe4, 0x51, 0x7b, 0xa3}, + sigPrefix: [4]byte{0xc8, 0x5d, 0xf4, 0xba}, }, { privKey: GenPrivKeySecp256k1(), sigSize: 0, // unknown - sigPrefix: [4]byte{0x37, 0xb9, 0x21, 0x3e}, + sigPrefix: [4]byte{0xc6, 0xa0, 0xa, 0x42}, }, } @@ -70,17 +70,18 @@ func TestSignatureEncodings(t *testing.T) { msg := CRandBytes(128) sig := tc.privKey.Sign(msg) - // store as wire - bin, err := cdc.MarshalBinary(sig) + // store as amino + bin, err := cdc.MarshalBinaryBare(sig) require.Nil(t, err, "%+v", err) if tc.sigSize != 0 { - assert.Equal(t, tc.sigSize+4, len(bin)) + // Q: where is 1 byte coming from? + assert.Equal(t, tc.sigSize+amino.PrefixBytesLen+1, len(bin)) } - assert.Equal(t, tc.sigPrefix[:], bin[0:4]) + assert.Equal(t, tc.sigPrefix[:], bin[0:amino.PrefixBytesLen]) // and back sig2 := Signature(nil) - err = cdc.UnmarshalBinary(bin, &sig2) + err = cdc.UnmarshalBinaryBare(bin, &sig2) require.Nil(t, err, "%+v", err) assert.EqualValues(t, sig, sig2) assert.True(t, pubKey.VerifyBytes(msg, sig2)) From 47b8a8864b7e7b63b2d34902cee6e7b5a99466d2 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 12 Mar 2018 12:34:43 +0400 Subject: [PATCH 2/3] remove any mention of glide --- Makefile | 6 ++-- glide.lock | 93 ------------------------------------------------------ glide.yaml | 34 -------------------- 3 files changed, 3 insertions(+), 130 deletions(-) delete mode 100644 glide.lock delete mode 100644 glide.yaml diff --git a/Makefile b/Makefile index b8c95b7df..9ae475983 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ GOTOOLS = \ github.com/golang/dep/cmd/dep \ - github.com/jteeuwen/go-bindata/go-bindata + github.com/jteeuwen/go-bindata/go-bindata # gopkg.in/alecthomas/gometalinter.v2 \ # -GOTOOLS_CHECK = glide go-bindata #gometalinter.v2 +GOTOOLS_CHECK = dep go-bindata #gometalinter.v2 -all: check get_vendor_deps build test install +all: check get_vendor_deps build test install check: check_tools diff --git a/glide.lock b/glide.lock deleted file mode 100644 index ff6e97630..000000000 --- a/glide.lock +++ /dev/null @@ -1,93 +0,0 @@ -hash: 95b2c2a089ca7242bc52c3bfe5a0286ae68201197f7f5855dd6e8f2ee3974068 -updated: 2018-03-02T11:41:11.205350024-05:00 -imports: -- name: github.com/btcsuite/btcd - version: 2be2f12b358dc57d70b8f501b00be450192efbc3 - subpackages: - - btcec -- name: github.com/btcsuite/btcutil - version: 501929d3d046174c3d39f0ea54ece471aa17238c - subpackages: - - base58 -- name: github.com/davecgh/go-spew - version: 346938d642f2ec3594ed81d874461961cd0faa76 - subpackages: - - spew -- name: github.com/go-kit/kit - version: 4dc7be5d2d12881735283bcab7352178e190fc71 - subpackages: - - log - - log/level - - log/term -- name: github.com/go-logfmt/logfmt - version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 -- name: github.com/go-stack/stack - version: 259ab82a6cad3992b4e21ff5cac294ccb06474bc -- name: github.com/gogo/protobuf - version: 1adfc126b41513cc696b209667c8656ea7aac67c - subpackages: - - gogoproto - - proto - - protoc-gen-gogo/descriptor -- name: github.com/golang/snappy - version: 553a641470496b2327abcac10b36396bd98e45c9 -- name: github.com/howeyc/crc16 - version: 2b2a61e366a66d3efb279e46176e7291001e0354 -- name: github.com/jmhodges/levigo - version: c42d9e0ca023e2198120196f842701bb4c55d7b9 -- name: github.com/kr/logfmt - version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 -- name: github.com/pkg/errors - version: 645ef00459ed84a119197bfb8d8205042c6df63d -- name: github.com/syndtr/goleveldb - version: c7a14d4b00e222eab6111b4cd1af829c13f53ec2 - subpackages: - - leveldb - - leveldb/cache - - leveldb/comparer - - leveldb/errors - - leveldb/filter - - leveldb/iterator - - leveldb/journal - - leveldb/memdb - - leveldb/opt - - leveldb/storage - - leveldb/table - - leveldb/util -- name: github.com/tendermint/ed25519 - version: d8387025d2b9d158cf4efb07e7ebf814bcce2057 - subpackages: - - edwards25519 - - extra25519 -- name: github.com/tendermint/go-amino - version: dec83f641903b22f039da3974607859715d0377e -- name: github.com/tendermint/tmlibs - version: 26f2ab65f82cfc6873c312e8030104c47c05f10e - subpackages: - - common - - db - - log -- name: golang.org/x/crypto - version: 91a49db82a88618983a78a06c1cbd4e00ab749ab - subpackages: - - bcrypt - - blowfish - - nacl/secretbox - - openpgp/armor - - openpgp/errors - - pbkdf2 - - poly1305 - - ripemd160 - - salsa20/salsa -testImports: -- name: github.com/pmezard/go-difflib - version: 792786c7400a136282c1664665ae0a8db921c6c2 - subpackages: - - difflib -- name: github.com/stretchr/testify - version: 12b6f73e6084dad08a7c6e575284b177ecafbc71 - subpackages: - - assert - - require -- name: github.com/tyler-smith/go-bip39 - version: 8e7a99b3e716f36d3b080a9a70f9eb45abe4edcc diff --git a/glide.yaml b/glide.yaml deleted file mode 100644 index 8e8b55b50..000000000 --- a/glide.yaml +++ /dev/null @@ -1,34 +0,0 @@ -package: github.com/tendermint/go-crypto -import: -- package: github.com/btcsuite/btcd - subpackages: - - btcec -- package: github.com/btcsuite/btcutil - subpackages: - - base58 -- package: github.com/howeyc/crc16 -- package: github.com/pkg/errors - version: ^0.8.0 -- package: github.com/tendermint/ed25519 - subpackages: - - extra25519 -- package: github.com/tendermint/go-amino - version: develop -- package: github.com/tendermint/tmlibs - version: develop - subpackages: - - common - - db -- package: golang.org/x/crypto - subpackages: - - blowfish - - nacl/secretbox - - openpgp/armor - - ripemd160 -testImport: -- package: github.com/stretchr/testify - version: ^1.2.1 - subpackages: - - assert - - require -- package: github.com/tyler-smith/go-bip39 From 73407e7cff462bf4ffcc44d55a9dd4570dd57fed Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 12 Mar 2018 12:37:19 +0400 Subject: [PATCH 3/3] add CODEOWNERS file --- .github/CODEOWNERS | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..3876c1ac5 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# CODEOWNERS: https://help.github.com/articles/about-codeowners/ + +* @ebuchman @jaekwon