mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-23 17:51:39 +00:00
update go-amino
This commit is contained in:
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@ -125,9 +125,9 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "develop"
|
branch = "develop"
|
||||||
name = "github.com/tendermint/go-wire"
|
name = "github.com/tendermint/go-amino"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "dec83f641903b22f039da3974607859715d0377e"
|
revision = "3b9e2b978447707c255922bc3f87a53d55c400c9"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "develop"
|
branch = "develop"
|
||||||
@ -163,6 +163,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "e0628df240b8ceeb91403f5218f5561d8580f15f3d5b0ea0da40710d1cba3707"
|
inputs-digest = "375b661ad202b62c6847981416c03ce0518c33ac293f5f0863b69af04d2af91f"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "develop"
|
branch = "develop"
|
||||||
name = "github.com/tendermint/go-wire"
|
name = "github.com/tendermint/go-amino"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "develop"
|
branch = "develop"
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
ledger "github.com/ethanfrey/ledger"
|
ledger "github.com/ethanfrey/ledger"
|
||||||
|
|
||||||
crypto "github.com/tendermint/go-crypto"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
wire "github.com/tendermint/go-wire"
|
amino "github.com/tendermint/go-amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint
|
//nolint
|
||||||
@ -58,7 +58,7 @@ func signLedger(device *ledger.Ledger, msg []byte) (pub crypto.PubKey, sig crypt
|
|||||||
// PrivKeyLedgerEd25519 implements PrivKey, calling the ledger nano
|
// PrivKeyLedgerEd25519 implements PrivKey, calling the ledger nano
|
||||||
// we cache the PubKey from the first call to use it later
|
// we cache the PubKey from the first call to use it later
|
||||||
type PrivKeyLedgerEd25519 struct {
|
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
|
// so we can view the address later, even without having the ledger
|
||||||
// attached
|
// attached
|
||||||
CachedPubKey crypto.PubKey
|
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
|
// Bytes fulfils PrivKey Interface - but it stores the cached pubkey so we can verify
|
||||||
// the same key when we reconnect to a ledger
|
// the same key when we reconnect to a ledger
|
||||||
func (pk *PrivKeyLedgerEd25519) Bytes() []byte {
|
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
|
// 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
|
// Bytes fulfils pk Interface - no data, just type info
|
||||||
func (pk PubKeyLedgerEd25519) Bytes() []byte {
|
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
|
// VerifyBytes uses the normal Ed25519 algorithm but a sha512 hash beforehand
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
package crypto
|
package crypto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-wire"
|
amino "github.com/tendermint/go-amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = wire.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// NOTE: It's important that there be no conflicts here,
|
// NOTE: It's important that there be no conflicts here,
|
||||||
// as that would change the canonical representations,
|
// as that would change the canonical representations,
|
||||||
// and therefore change the address.
|
// 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.
|
// are no conflicts.
|
||||||
RegisterWire(cdc)
|
RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterWire(cdc *wire.Codec) {
|
func RegisterAmino(cdc *amino.Codec) {
|
||||||
cdc.RegisterInterface((*PubKey)(nil), nil)
|
cdc.RegisterInterface((*PubKey)(nil), nil)
|
||||||
cdc.RegisterConcrete(PubKeyEd25519{},
|
cdc.RegisterConcrete(PubKeyEd25519{},
|
||||||
"com.tendermint.wire.PubKeyEd25519", nil)
|
"com.tendermint.amino.PubKeyEd25519", nil)
|
||||||
cdc.RegisterConcrete(PubKeySecp256k1{},
|
cdc.RegisterConcrete(PubKeySecp256k1{},
|
||||||
"com.tendermint.wire.PubKeySecp256k1", nil)
|
"com.tendermint.amino.PubKeySecp256k1", nil)
|
||||||
|
|
||||||
cdc.RegisterInterface((*PrivKey)(nil), nil)
|
cdc.RegisterInterface((*PrivKey)(nil), nil)
|
||||||
cdc.RegisterConcrete(PrivKeyEd25519{},
|
cdc.RegisterConcrete(PrivKeyEd25519{},
|
||||||
"com.tendermint.wire.PrivKeyEd25519", nil)
|
"com.tendermint.amino.PrivKeyEd25519", nil)
|
||||||
cdc.RegisterConcrete(PrivKeySecp256k1{},
|
cdc.RegisterConcrete(PrivKeySecp256k1{},
|
||||||
"com.tendermint.wire.PrivKeySecp256k1", nil)
|
"com.tendermint.amino.PrivKeySecp256k1", nil)
|
||||||
|
|
||||||
cdc.RegisterInterface((*Signature)(nil), nil)
|
cdc.RegisterInterface((*Signature)(nil), nil)
|
||||||
cdc.RegisterConcrete(SignatureEd25519{},
|
cdc.RegisterConcrete(SignatureEd25519{},
|
||||||
"com.tendermint.wire.SignatureKeyEd25519", nil)
|
"com.tendermint.amino.SignatureKeyEd25519", nil)
|
||||||
cdc.RegisterConcrete(SignatureSecp256k1{},
|
cdc.RegisterConcrete(SignatureSecp256k1{},
|
||||||
"com.tendermint.wire.SignatureKeySecp256k1", nil)
|
"com.tendermint.amino.SignatureKeySecp256k1", nil)
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package crypto
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -10,15 +10,15 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
wire "github.com/tendermint/go-wire"
|
amino "github.com/tendermint/go-amino"
|
||||||
data "github.com/tendermint/go-wire/data"
|
data "github.com/tendermint/go-amino/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
type byter interface {
|
type byter interface {
|
||||||
Bytes() []byte
|
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) {
|
func checkWire(t *testing.T, in byter, reader interface{}, typ byte, size int) {
|
||||||
// test to and from binary
|
// test to and from binary
|
||||||
bin, err := data.ToWire(in)
|
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]))
|
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) {
|
func checkWireJSON(t *testing.T, in interface{}, reader interface{}, typ byte) {
|
||||||
// test to and from binary
|
// test to and from binary
|
||||||
var err error
|
var err error
|
||||||
js := wire.JSONBytes(in)
|
js := amino.JSONBytes(in)
|
||||||
btyp := fmt.Sprintf("[%d,", typ)
|
btyp := fmt.Sprintf("[%d,", typ)
|
||||||
assert.True(t, strings.HasPrefix(string(js), btyp), string(js), btyp)
|
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)
|
require.Nil(t, err, "%+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ type SigMessage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SigMessage) Bytes() []byte {
|
func (s SigMessage) Bytes() []byte {
|
||||||
return wire.BinaryBytes(s)
|
return amino.BinaryBytes(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmbededWireEncodings(t *testing.T) {
|
func TestEmbededWireEncodings(t *testing.T) {
|
||||||
|
2
glide.lock
generated
2
glide.lock
generated
@ -59,7 +59,7 @@ imports:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- edwards25519
|
- edwards25519
|
||||||
- extra25519
|
- extra25519
|
||||||
- name: github.com/tendermint/go-wire
|
- name: github.com/tendermint/go-amino
|
||||||
version: dec83f641903b22f039da3974607859715d0377e
|
version: dec83f641903b22f039da3974607859715d0377e
|
||||||
- name: github.com/tendermint/tmlibs
|
- name: github.com/tendermint/tmlibs
|
||||||
version: 26f2ab65f82cfc6873c312e8030104c47c05f10e
|
version: 26f2ab65f82cfc6873c312e8030104c47c05f10e
|
||||||
|
@ -12,7 +12,7 @@ import:
|
|||||||
- package: github.com/tendermint/ed25519
|
- package: github.com/tendermint/ed25519
|
||||||
subpackages:
|
subpackages:
|
||||||
- extra25519
|
- extra25519
|
||||||
- package: github.com/tendermint/go-wire
|
- package: github.com/tendermint/go-amino
|
||||||
version: develop
|
version: develop
|
||||||
- package: github.com/tendermint/tmlibs
|
- package: github.com/tendermint/tmlibs
|
||||||
version: develop
|
version: develop
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package keys
|
package keys
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-crypto"
|
amino "github.com/tendermint/go-amino"
|
||||||
"github.com/tendermint/go-wire"
|
crypto "github.com/tendermint/go-crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = wire.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
crypto.RegisterWire(cdc)
|
crypto.RegisterAmino(cdc)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tendermint/ed25519"
|
"github.com/tendermint/ed25519"
|
||||||
"github.com/tendermint/go-wire"
|
amino "github.com/tendermint/go-amino"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSignAndValidateEd25519(t *testing.T) {
|
func TestSignAndValidateEd25519(t *testing.T) {
|
||||||
@ -49,17 +49,17 @@ func TestSignatureEncodings(t *testing.T) {
|
|||||||
cases := []struct {
|
cases := []struct {
|
||||||
privKey PrivKey
|
privKey PrivKey
|
||||||
sigSize int
|
sigSize int
|
||||||
sigPrefix wire.PrefixBytes
|
sigPrefix amino.PrefixBytes
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
privKey: GenPrivKeyEd25519(),
|
privKey: GenPrivKeyEd25519(),
|
||||||
sigSize: ed25519.SignatureSize,
|
sigSize: ed25519.SignatureSize,
|
||||||
sigPrefix: [4]byte{0xe4, 0x51, 0x7b, 0xa3},
|
sigPrefix: [4]byte{0xc8, 0x5d, 0xf4, 0xba},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
privKey: GenPrivKeySecp256k1(),
|
privKey: GenPrivKeySecp256k1(),
|
||||||
sigSize: 0, // unknown
|
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)
|
msg := CRandBytes(128)
|
||||||
sig := tc.privKey.Sign(msg)
|
sig := tc.privKey.Sign(msg)
|
||||||
|
|
||||||
// store as wire
|
// store as amino
|
||||||
bin, err := cdc.MarshalBinary(sig)
|
bin, err := cdc.MarshalBinaryBare(sig)
|
||||||
require.Nil(t, err, "%+v", err)
|
require.Nil(t, err, "%+v", err)
|
||||||
if tc.sigSize != 0 {
|
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
|
// and back
|
||||||
sig2 := Signature(nil)
|
sig2 := Signature(nil)
|
||||||
err = cdc.UnmarshalBinary(bin, &sig2)
|
err = cdc.UnmarshalBinaryBare(bin, &sig2)
|
||||||
require.Nil(t, err, "%+v", err)
|
require.Nil(t, err, "%+v", err)
|
||||||
assert.EqualValues(t, sig, sig2)
|
assert.EqualValues(t, sig, sig2)
|
||||||
assert.True(t, pubKey.VerifyBytes(msg, sig2))
|
assert.True(t, pubKey.VerifyBytes(msg, sig2))
|
||||||
|
Reference in New Issue
Block a user