Browse Source

Merge pull request #110 from tendermint/bucky/sig-name

SignatureKey -> Signature
pull/1782/head
Alexander Simmerl 7 years ago
committed by GitHub
parent
commit
260d69f372
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 72 deletions
  1. +2
    -2
      Gopkg.lock
  2. +1
    -1
      Gopkg.toml
  3. +2
    -2
      amino.go
  4. +14
    -0
      encode_test.go
  5. +1
    -67
      signature_test.go

+ 2
- 2
Gopkg.lock View File

@ -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"


+ 1
- 1
Gopkg.toml View File

@ -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"


+ 2
- 2
amino.go View File

@ -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)
}

+ 14
- 0
encode_test.go View File

@ -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


+ 1
- 67
signature_test.go View File

@ -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))
*/
}
}

Loading…
Cancel
Save