diff --git a/Gopkg.lock b/Gopkg.lock index 24b638a55..a475c6656 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -134,8 +134,8 @@ [[projects]] name = "github.com/tendermint/go-amino" packages = ["."] - revision = "3c22a7a539411f89a96738fcfa14c1027e24e5ec" - version = "0.9.10" + revision = "1715b7b78c65d6adcc5937315be4710234cefe09" + version = "0.10.0-rc2" [[projects]] name = "github.com/tendermint/tmlibs" diff --git a/Gopkg.toml b/Gopkg.toml index d2b50e5a1..df7e5e221 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -46,7 +46,7 @@ [[constraint]] name = "github.com/tendermint/go-amino" - version = "0.9.6" + version = "0.10.0-rc2" [[constraint]] name = "github.com/tendermint/tmlibs" diff --git a/amino.go b/amino.go index 2af765434..ddf3e193a 100644 --- a/amino.go +++ b/amino.go @@ -32,7 +32,7 @@ func RegisterAmino(cdc *amino.Codec) { cdc.RegisterInterface((*Signature)(nil), nil) cdc.RegisterConcrete(SignatureEd25519{}, - "tendermint/SignatureKeyEd25519", nil) + "tendermint/SignatureEd25519", nil) cdc.RegisterConcrete(SignatureSecp256k1{}, - "tendermint/SignatureKeySecp256k1", nil) + "tendermint/SignatureSecp256k1", nil) } diff --git a/encode_test.go b/encode_test.go index f78d9439c..ed5395db8 100644 --- a/encode_test.go +++ b/encode_test.go @@ -1,6 +1,7 @@ package crypto import ( + "os" "testing" "github.com/stretchr/testify/assert" @@ -41,6 +42,19 @@ func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool) require.Nil(t, err, "%+v", err) } +func ExamplePrintRegisteredTypes() { + cdc.PrintTypes(os.Stdout) + // Output: | Type | Name | Prefix | Length | Notes | + //| ---- | ---- | ------ | ----- | ------ | + //| PubKeyEd25519 | tendermint/PubKeyEd25519 | 0x1624DE64 | 0x20 | | + //| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE987 | 0x21 | | + //| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288910 | 0x40 | | + //| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | 0x20 | | + //| PrivKeyLedgerSecp256k1 | tendermint/PrivKeyLedgerSecp256k1 | 0x10CAB393 | variable | | + //| SignatureEd25519 | tendermint/SignatureEd25519 | 0x2031EA53 | 0x40 | | + //| SignatureSecp256k1 | tendermint/SignatureSecp256k1 | 0x7FC4A495 | variable | | +} + func TestKeyEncodings(t *testing.T) { cases := []struct { privKey PrivKey diff --git a/signature_test.go b/signature_test.go index 52da65572..560815ccf 100644 --- a/signature_test.go +++ b/signature_test.go @@ -3,10 +3,8 @@ package crypto import ( "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/ed25519" - amino "github.com/tendermint/go-amino" + "github.com/stretchr/testify/assert" ) func TestSignAndValidateEd25519(t *testing.T) { @@ -48,67 +46,3 @@ func TestSignAndValidateSecp256k1(t *testing.T) { assert.False(t, pubKey.VerifyBytes(msg, sig)) } - -func TestSignatureEncodings(t *testing.T) { - cases := []struct { - privKey PrivKey - sigSize int - sigPrefix amino.PrefixBytes - }{ - { - privKey: GenPrivKeyEd25519(), - sigSize: ed25519.SignatureSize, - sigPrefix: [4]byte{0x3d, 0xa1, 0xdb, 0x2a}, - }, - { - privKey: GenPrivKeySecp256k1(), - sigSize: 0, // unknown - sigPrefix: [4]byte{0x16, 0xe1, 0xfe, 0xea}, - }, - } - - for _, tc := range cases { - // note we embed them from the beginning.... - pubKey, err := tc.privKey.PubKey() - require.Nil(t, err) - - msg := CRandBytes(128) - sig, err := tc.privKey.Sign(msg) - require.Nil(t, err) - - // store as amino - bin, err := cdc.MarshalBinaryBare(sig) - require.Nil(t, err, "%+v", err) - if tc.sigSize != 0 { - // Q: where is 1 byte coming from? - assert.Equal(t, tc.sigSize+amino.PrefixBytesLen+1, len(bin)) - } - assert.Equal(t, tc.sigPrefix[:], bin[0:amino.PrefixBytesLen]) - - // and back - sig2 := Signature(nil) - err = cdc.UnmarshalBinaryBare(bin, &sig2) - require.Nil(t, err, "%+v", err) - assert.EqualValues(t, sig, sig2) - assert.True(t, pubKey.VerifyBytes(msg, sig2)) - - /* - // store as json - js, err := data.ToJSON(sig) - require.Nil(t, err, "%+v", err) - assert.True(t, strings.Contains(string(js), tc.sigName)) - - // and back - sig3 := Signature{} - err = data.FromJSON(js, &sig3) - require.Nil(t, err, "%+v", err) - assert.EqualValues(t, sig, sig3) - assert.True(t, pubKey.VerifyBytes(msg, sig3)) - - // and make sure we can textify it - text, err := data.ToText(sig) - require.Nil(t, err, "%+v", err) - assert.True(t, strings.HasPrefix(text, tc.sigName)) - */ - } -}