Migrate BaseAccount PubKey to use Any (#7268)
* WIP on BaseAccount protobuf pub_key * WIP on BaseAccount.PubKey * WIP on BaseAccount pub key * Update PubKey * Update Account * Docs * WIP on protobuf keys * Use Type() and Bytes() in sr25519 pub key Equals * Add tests * Add few more tests * Update other pub/priv key types Equals * Fix PrivKey's Sign method * Rename variables in tests * Fix infinite recursive calls * Use tm ed25519 keys * Add Sign and VerifySignature tests * Remove ed25519 and sr25519 references * proto linting * Add proto crypto file * Implement some of the new multisig proto type methods * Add tests for MultisigThresholdPubKey * Add tests for pubkey pb/amino conversion functions * Move crypto types.go and register new proto pubkeys * Add missing pointer ref * Address review comments * panic in MultisigThresholdPubKey VerifySignature * Fix compile errors * Remove pk conversion in ante handler * Use internal crypto.PubKey in multisig * Add tests for MultisigThresholdPubKey VerifyMultisignature * Only keep LegacyAminoMultisigThresholdPubKey and move to proto keys to v1 * Remove conversion functions and introduce internal PubKey type * Override Amino marshaling for proto pubkeys * Merge master * Make proto-gen * Start removal of old PubKeyMultisigThreshold references * Fix tests * Fix solomachine * Fix ante handler tests * Pull latest go-amino * Remove ed25519 * Remove old secp256k1 PubKey and PrivKey * Uncomment test case * Fix linting issues * More linting * Revert tests keys values * Add Amino overrides to proto keys * Add pubkey test * Fix tests * Use threshold isntead of K * Standardize Type * Revert standardize types commit * Fix build * Fix lint * Fix lint * Add comment * Register crypto.PubKey * Add empty key in BuildSimTx * Simplify proto names * Unpack interfaces for signing desc * Fix IBC tests? * Format proto * Use secp256k1 in ibc * Fixed merge issues * Uncomment tests * Update x/ibc/testing/solomachine.go * UnpackInterfaces for solomachine types * Remove old multisig * Add amino marshal for multisig * Fix lint * Correctly register amino * One test left! * Remove old struct * Fix test * Fix test * Unpack into tmcrypto * Remove old threshold pubkey tests * Fix register amino * Fix lint * Use sdk crypto PubKey in multisig UnpackInterfaces * Potential fix? * Register LegacyAminoPubKey * Register our own PubKey * Register tmcrypto PubKey * Register both PubKeys * Register interfaces in test * Refactor fiels * Add comments * Remove old cosmos-sdk/crypto/keys reference * Use anil's suggestion * Add norace back * Use our own ed25519 * Fix pubkey types * Fix network tests * Fix more tests * Make ibc work? * Use TM pubkey in NewValidator * Fix lint * Put interface in tpyes * rerun CI * Better name register * Remove stray code * Add ed25519 tests * Check nil * Correct interface impl assert * rerun CI * Add fix for Bech32 * Address comments * FIx lint * Add tests for solomachine unpack interfaces * Fix query tx by hash * Better name in amino register * Fix lint * Add back ed25519 test (fixes #7352) * go mod tidy * Fix merge issues * Sort import * Add test for backwards-compatibility * Fix tests * Fix merge issue * Update client/context.go Co-authored-by: Cory <cjlevinson@gmail.com> * Update types/address.go Co-authored-by: Cory <cjlevinson@gmail.com> * Address feedback * Add comment * Fix BaseAccount SetPubKey and address further comments * Lint * Remove unnecessary use of copy in getPubKeyFromString * Update comment Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Cory <cjlevinson@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
parent
30f9862b4b
commit
91ca8ad3c1
|
@ -5,12 +5,12 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/pkg/errors"
|
||||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
|
|
|
@ -9,10 +9,11 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
)
|
||||
|
||||
|
@ -34,18 +35,18 @@ func Cmd() *cobra.Command {
|
|||
// to decode the pubkey string from hex, base64, and finally bech32. If all
|
||||
// encodings fail, an error is returned.
|
||||
func getPubKeyFromString(pkstr string) (crypto.PubKey, error) {
|
||||
pubKey := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
|
||||
bz, err := hex.DecodeString(pkstr)
|
||||
if err == nil {
|
||||
copy(pubKey[:], bz)
|
||||
return pubKey, nil
|
||||
if len(bz) == ed25519.PubKeySize {
|
||||
return &ed25519.PubKey{Key: bz}, nil
|
||||
}
|
||||
}
|
||||
|
||||
bz, err = base64.StdEncoding.DecodeString(pkstr)
|
||||
if err == nil {
|
||||
copy(pubKey[:], bz)
|
||||
return pubKey, nil
|
||||
if len(bz) == ed25519.PubKeySize {
|
||||
return &ed25519.PubKey{Key: bz}, nil
|
||||
}
|
||||
}
|
||||
|
||||
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, pkstr)
|
||||
|
@ -63,7 +64,7 @@ func getPubKeyFromString(pkstr string) (crypto.PubKey, error) {
|
|||
return pk, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("pubkey '%s' invalid; expected hex, base64, or bech32", pubKey)
|
||||
return nil, fmt.Errorf("pubkey '%s' invalid; expected hex, base64, or bech32 of correct size", pkstr)
|
||||
}
|
||||
|
||||
func PubkeyCmd() *cobra.Command {
|
||||
|
@ -85,9 +86,9 @@ $ %s debug pubkey cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
|
|||
return err
|
||||
}
|
||||
|
||||
edPK, ok := pk.(ed25519.PubKey)
|
||||
edPK, ok := pk.(*ed25519.PubKey)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid pubkey type; expected ED25519")
|
||||
return errors.Wrapf(errors.ErrInvalidType, "invalid pubkey type; expected ED25519")
|
||||
}
|
||||
|
||||
pubKeyJSONBytes, err := clientCtx.LegacyAmino.MarshalJSON(edPK)
|
||||
|
@ -108,7 +109,7 @@ $ %s debug pubkey cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
|
|||
}
|
||||
|
||||
cmd.Println("Address:", edPK.Address())
|
||||
cmd.Printf("Hex: %X\n", edPK[:])
|
||||
cmd.Printf("Hex: %X\n", edPK.Key)
|
||||
cmd.Println("JSON (base64):", string(pubKeyJSONBytes))
|
||||
cmd.Println("Bech32 Acc:", accPub)
|
||||
cmd.Println("Bech32 Validator Operator:", valPub)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package codec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// MarshalYAML marshals the provided toPrint content with the provided JSON marshaler
|
||||
// by encoding JSON, decoding JSON, and then encoding YAML.
|
||||
func MarshalYAML(jsonMarshaler JSONMarshaler, toPrint proto.Message) ([]byte, error) {
|
||||
// only the JSONMarshaler has full context as to how the JSON
|
||||
// mashalling should look (which may be different for amino & proto codecs)
|
||||
// so we need to use it to marshal toPrint first
|
||||
bz, err := jsonMarshaler.MarshalJSON(toPrint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// generate YAML by decoding and re-encoding JSON as YAML
|
||||
var j interface{}
|
||||
|
||||
err = json.Unmarshal(bz, &j)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return yaml.Marshal(j)
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package codec_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
)
|
||||
|
||||
func TestMarshalYAML(t *testing.T) {
|
||||
dog := &testdata.Dog{
|
||||
Size_: "small",
|
||||
Name: "Spot",
|
||||
}
|
||||
any, err := types.NewAnyWithValue(dog)
|
||||
require.NoError(t, err)
|
||||
hasAnimal := &testdata.HasAnimal{
|
||||
Animal: any,
|
||||
X: 0,
|
||||
}
|
||||
|
||||
// proto
|
||||
protoCdc := codec.NewProtoCodec(NewTestInterfaceRegistry())
|
||||
bz, err := codec.MarshalYAML(protoCdc, hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, `animal:
|
||||
'@type': /testdata.Dog
|
||||
name: Spot
|
||||
size: small
|
||||
x: "0"
|
||||
`, string(bz))
|
||||
|
||||
// amino
|
||||
aminoCdc := codec.NewAminoCodec(&codec.LegacyAmino{testdata.NewTestAmino()})
|
||||
bz, err = codec.MarshalYAML(aminoCdc, hasAnimal)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, `type: testdata/HasAnimal
|
||||
value:
|
||||
animal:
|
||||
type: testdata/Dog
|
||||
value:
|
||||
name: Spot
|
||||
size: small
|
||||
`, string(bz))
|
||||
}
|
|
@ -2,10 +2,11 @@ package codec
|
|||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/sr25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
|
@ -26,20 +27,26 @@ func RegisterCrypto(cdc *codec.LegacyAmino) {
|
|||
// first line.
|
||||
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
|
||||
cdc.RegisterInterface((*cryptotypes.PubKey)(nil), nil)
|
||||
cdc.RegisterConcrete(ed25519.PubKey{},
|
||||
ed25519.PubKeyName, nil)
|
||||
cdc.RegisterConcrete(sr25519.PubKey{},
|
||||
sr25519.PubKeyName, nil)
|
||||
// TODO Same as above, for ED25519
|
||||
cdc.RegisterConcrete(tmed25519.PubKey{},
|
||||
tmed25519.PubKeyName, nil)
|
||||
cdc.RegisterConcrete(&ed25519.PubKey{},
|
||||
ed25519.PubKeyName, nil)
|
||||
cdc.RegisterConcrete(&secp256k1.PubKey{},
|
||||
secp256k1.PubKeyName, nil)
|
||||
cdc.RegisterConcrete(&kmultisig.LegacyAminoPubKey{},
|
||||
kmultisig.PubKeyAminoRoute, nil)
|
||||
|
||||
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
|
||||
cdc.RegisterConcrete(ed25519.PrivKey{},
|
||||
ed25519.PrivKeyName, nil)
|
||||
cdc.RegisterConcrete(sr25519.PrivKey{},
|
||||
sr25519.PrivKeyName, nil)
|
||||
// TODO Same as above
|
||||
cdc.RegisterConcrete(tmed25519.PrivKey{},
|
||||
tmed25519.PrivKeyName, nil)
|
||||
cdc.RegisterConcrete(&ed25519.PrivKey{},
|
||||
ed25519.PrivKeyName, nil)
|
||||
cdc.RegisterConcrete(&secp256k1.PrivKey{},
|
||||
secp256k1.PrivKeyName, nil)
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
|
@ -13,12 +14,14 @@ import (
|
|||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
// TODO We now register both Tendermint's PubKey and our own PubKey. In the
|
||||
// long-term, we should move away from Tendermint's PubKey, and delete
|
||||
// these lines
|
||||
// these lines.
|
||||
registry.RegisterInterface("tendermint.crypto.Pubkey", (*tmcrypto.PubKey)(nil))
|
||||
registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &ed25519.PubKey{})
|
||||
registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &secp256k1.PubKey{})
|
||||
registry.RegisterImplementations((*tmcrypto.PubKey)(nil), &multisig.LegacyAminoPubKey{})
|
||||
|
||||
registry.RegisterInterface("cosmos.crypto.Pubkey", (*cryptotypes.PubKey)(nil))
|
||||
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &ed25519.PubKey{})
|
||||
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &secp256k1.PubKey{})
|
||||
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &multisig.LegacyAminoPubKey{})
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
bip39 "github.com/cosmos/go-bip39"
|
||||
"github.com/stretchr/testify/require"
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
|
|
@ -0,0 +1,234 @@
|
|||
package ed25519
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
const (
|
||||
PrivKeyName = "cosmos/PrivKeyEd25519"
|
||||
PubKeyName = "cosmos/PubKeyEd25519"
|
||||
// PubKeySize is is the size, in bytes, of public keys as used in this package.
|
||||
PubKeySize = 32
|
||||
// PrivKeySize is the size, in bytes, of private keys as used in this package.
|
||||
PrivKeySize = 64
|
||||
// Size of an Edwards25519 signature. Namely the size of a compressed
|
||||
// Edwards25519 point, and a field element. Both of which are 32 bytes.
|
||||
SignatureSize = 64
|
||||
// SeedSize is the size, in bytes, of private key seeds. These are the
|
||||
// private key representations used by RFC 8032.
|
||||
SeedSize = 32
|
||||
|
||||
keyType = "ed25519"
|
||||
)
|
||||
|
||||
var _ cryptotypes.PrivKey = &PrivKey{}
|
||||
var _ codec.AminoMarshaler = &PrivKey{}
|
||||
|
||||
// Bytes returns the privkey byte format.
|
||||
func (privKey *PrivKey) Bytes() []byte {
|
||||
return privKey.Key
|
||||
}
|
||||
|
||||
// Sign produces a signature on the provided message.
|
||||
// This assumes the privkey is wellformed in the golang format.
|
||||
// The first 32 bytes should be random,
|
||||
// corresponding to the normal ed25519 private key.
|
||||
// The latter 32 bytes should be the compressed public key.
|
||||
// If these conditions aren't met, Sign will panic or produce an
|
||||
// incorrect signature.
|
||||
func (privKey *PrivKey) Sign(msg []byte) ([]byte, error) {
|
||||
return ed25519.Sign(ed25519.PrivateKey(privKey.Key), msg), nil
|
||||
}
|
||||
|
||||
// PubKey gets the corresponding public key from the private key.
|
||||
//
|
||||
// Panics if the private key is not initialized.
|
||||
func (privKey *PrivKey) PubKey() crypto.PubKey {
|
||||
// If the latter 32 bytes of the privkey are all zero, privkey is not
|
||||
// initialized.
|
||||
initialized := false
|
||||
for _, v := range privKey.Key[32:] {
|
||||
if v != 0 {
|
||||
initialized = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !initialized {
|
||||
panic("Expected ed25519 PrivKey to include concatenated pubkey bytes")
|
||||
}
|
||||
|
||||
pubkeyBytes := make([]byte, PubKeySize)
|
||||
copy(pubkeyBytes, privKey.Key[32:])
|
||||
return &PubKey{Key: pubkeyBytes}
|
||||
}
|
||||
|
||||
// Equals - you probably don't need to use this.
|
||||
// Runs in constant time based on length of the keys.
|
||||
func (privKey *PrivKey) Equals(other crypto.PrivKey) bool {
|
||||
if privKey.Type() != other.Type() {
|
||||
return false
|
||||
}
|
||||
|
||||
return subtle.ConstantTimeCompare(privKey.Bytes(), other.Bytes()) == 1
|
||||
}
|
||||
|
||||
func (privKey *PrivKey) Type() string {
|
||||
return keyType
|
||||
}
|
||||
|
||||
// MarshalAmino overrides Amino binary marshalling.
|
||||
func (privKey PrivKey) MarshalAmino() ([]byte, error) {
|
||||
return privKey.Key, nil
|
||||
}
|
||||
|
||||
// UnmarshalAmino overrides Amino binary marshalling.
|
||||
func (privKey *PrivKey) UnmarshalAmino(bz []byte) error {
|
||||
if len(bz) != PrivKeySize {
|
||||
return fmt.Errorf("invalid privkey size")
|
||||
}
|
||||
privKey.Key = bz
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalAminoJSON overrides Amino JSON marshalling.
|
||||
func (privKey PrivKey) MarshalAminoJSON() ([]byte, error) {
|
||||
// When we marshal to Amino JSON, we don't marshal the "key" field itself,
|
||||
// just its contents (i.e. the key bytes).
|
||||
return privKey.MarshalAmino()
|
||||
}
|
||||
|
||||
// UnmarshalAminoJSON overrides Amino JSON marshalling.
|
||||
func (privKey *PrivKey) UnmarshalAminoJSON(bz []byte) error {
|
||||
return privKey.UnmarshalAmino(bz)
|
||||
}
|
||||
|
||||
// GenPrivKey generates a new ed25519 private key.
|
||||
// It uses OS randomness in conjunction with the current global random seed
|
||||
// in tendermint/libs/common to generate the private key.
|
||||
func GenPrivKey() *PrivKey {
|
||||
return genPrivKey(crypto.CReader())
|
||||
}
|
||||
|
||||
// genPrivKey generates a new ed25519 private key using the provided reader.
|
||||
func genPrivKey(rand io.Reader) *PrivKey {
|
||||
seed := make([]byte, SeedSize)
|
||||
|
||||
_, err := io.ReadFull(rand, seed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &PrivKey{Key: ed25519.NewKeyFromSeed(seed)}
|
||||
}
|
||||
|
||||
// GenPrivKeyFromSecret hashes the secret with SHA2, and uses
|
||||
// that 32 byte output to create the private key.
|
||||
// NOTE: secret should be the output of a KDF like bcrypt,
|
||||
// if it's derived from user input.
|
||||
func GenPrivKeyFromSecret(secret []byte) *PrivKey {
|
||||
seed := crypto.Sha256(secret) // Not Ripemd160 because we want 32 bytes.
|
||||
|
||||
return &PrivKey{Key: ed25519.NewKeyFromSeed(seed)}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
var _ cryptotypes.PubKey = &PubKey{}
|
||||
var _ codec.AminoMarshaler = &PubKey{}
|
||||
var _ cryptotypes.IntoTmPubKey = &PubKey{}
|
||||
|
||||
// Address is the SHA256-20 of the raw pubkey bytes.
|
||||
func (pubKey *PubKey) Address() crypto.Address {
|
||||
if len(pubKey.Key) != PubKeySize {
|
||||
panic("pubkey is incorrect size")
|
||||
}
|
||||
return crypto.Address(tmhash.SumTruncated(pubKey.Key))
|
||||
}
|
||||
|
||||
// Bytes returns the PubKey byte format.
|
||||
func (pubKey *PubKey) Bytes() []byte {
|
||||
return pubKey.Key
|
||||
}
|
||||
|
||||
func (pubKey *PubKey) VerifySignature(msg []byte, sig []byte) bool {
|
||||
// make sure we use the same algorithm to sign
|
||||
if len(sig) != SignatureSize {
|
||||
return false
|
||||
}
|
||||
|
||||
return ed25519.Verify(ed25519.PublicKey(pubKey.Key), msg, sig)
|
||||
}
|
||||
|
||||
func (pubKey *PubKey) String() string {
|
||||
return fmt.Sprintf("PubKeyEd25519{%X}", pubKey.Key)
|
||||
}
|
||||
|
||||
func (pubKey *PubKey) Type() string {
|
||||
return keyType
|
||||
}
|
||||
|
||||
func (pubKey *PubKey) Equals(other crypto.PubKey) bool {
|
||||
if pubKey.Type() != other.Type() {
|
||||
return false
|
||||
}
|
||||
|
||||
return subtle.ConstantTimeCompare(pubKey.Bytes(), other.Bytes()) == 1
|
||||
}
|
||||
|
||||
// MarshalAmino overrides Amino binary marshalling.
|
||||
func (pubKey PubKey) MarshalAmino() ([]byte, error) {
|
||||
return pubKey.Key, nil
|
||||
}
|
||||
|
||||
// UnmarshalAmino overrides Amino binary marshalling.
|
||||
func (pubKey *PubKey) UnmarshalAmino(bz []byte) error {
|
||||
if len(bz) != PubKeySize {
|
||||
return errors.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size")
|
||||
}
|
||||
pubKey.Key = bz
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalAminoJSON overrides Amino JSON marshalling.
|
||||
func (pubKey PubKey) MarshalAminoJSON() ([]byte, error) {
|
||||
// When we marshal to Amino JSON, we don't marshal the "key" field itself,
|
||||
// just its contents (i.e. the key bytes).
|
||||
return pubKey.MarshalAmino()
|
||||
}
|
||||
|
||||
// UnmarshalAminoJSON overrides Amino JSON marshalling.
|
||||
func (pubKey *PubKey) UnmarshalAminoJSON(bz []byte) error {
|
||||
return pubKey.UnmarshalAmino(bz)
|
||||
}
|
||||
|
||||
// AsTmPubKey converts our own PubKey into a Tendermint ED25519 pubkey.
|
||||
func (pubKey *PubKey) AsTmPubKey() crypto.PubKey {
|
||||
return tmed25519.PubKey(pubKey.Key)
|
||||
}
|
||||
|
||||
// FromTmEd25519 converts a Tendermint ED25519 pubkey into our own ED25519
|
||||
// PubKey.
|
||||
func FromTmEd25519(pubKey crypto.PubKey) (*PubKey, error) {
|
||||
tmPk, ok := pubKey.(tmed25519.PubKey)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected %T, got %T", tmed25519.PubKey{}, pubKey)
|
||||
}
|
||||
|
||||
return &PubKey{Key: []byte(tmPk)}, nil
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
package ed25519_test
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/sr25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
)
|
||||
|
||||
func TestSignAndValidateEd25519(t *testing.T) {
|
||||
privKey := ed25519.GenPrivKey()
|
||||
pubKey := privKey.PubKey()
|
||||
|
||||
msg := crypto.CRandBytes(128)
|
||||
sig, err := privKey.Sign(msg)
|
||||
require.Nil(t, err)
|
||||
|
||||
// Test the signature
|
||||
assert.True(t, pubKey.VerifySignature(msg, sig))
|
||||
|
||||
// Mutate the signature, just one bit.
|
||||
// TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
|
||||
sig[7] ^= byte(0x01)
|
||||
|
||||
assert.False(t, pubKey.VerifySignature(msg, sig))
|
||||
}
|
||||
|
||||
func TestPubKeyEquals(t *testing.T) {
|
||||
ed25519PubKey := ed25519.GenPrivKey().PubKey().(*ed25519.PubKey)
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
pubKey cryptotypes.PubKey
|
||||
other crypto.PubKey
|
||||
expectEq bool
|
||||
}{
|
||||
{
|
||||
"different bytes",
|
||||
ed25519PubKey,
|
||||
ed25519.GenPrivKey().PubKey(),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"equals",
|
||||
ed25519PubKey,
|
||||
&ed25519.PubKey{
|
||||
Key: ed25519PubKey.Key,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"different types",
|
||||
ed25519PubKey,
|
||||
sr25519.GenPrivKey().PubKey(),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.msg, func(t *testing.T) {
|
||||
eq := tc.pubKey.Equals(tc.other)
|
||||
require.Equal(t, eq, tc.expectEq)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrivKeyEquals(t *testing.T) {
|
||||
ed25519PrivKey := ed25519.GenPrivKey()
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
privKey cryptotypes.PrivKey
|
||||
other crypto.PrivKey
|
||||
expectEq bool
|
||||
}{
|
||||
{
|
||||
"different bytes",
|
||||
ed25519PrivKey,
|
||||
ed25519.GenPrivKey(),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"equals",
|
||||
ed25519PrivKey,
|
||||
&ed25519.PrivKey{
|
||||
Key: ed25519PrivKey.Key,
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"different types",
|
||||
ed25519PrivKey,
|
||||
sr25519.GenPrivKey(),
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.msg, func(t *testing.T) {
|
||||
eq := tc.privKey.Equals(tc.other)
|
||||
require.Equal(t, eq, tc.expectEq)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalAmino(t *testing.T) {
|
||||
aminoCdc := codec.NewLegacyAmino()
|
||||
privKey := ed25519.GenPrivKey()
|
||||
pubKey := privKey.PubKey().(*ed25519.PubKey)
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
msg codec.AminoMarshaler
|
||||
typ interface{}
|
||||
expBinary []byte
|
||||
expJSON string
|
||||
}{
|
||||
{
|
||||
"ed25519 private key",
|
||||
privKey,
|
||||
&ed25519.PrivKey{},
|
||||
append([]byte{64}, privKey.Bytes()...), // Length-prefixed.
|
||||
"\"" + base64.StdEncoding.EncodeToString(privKey.Bytes()) + "\"",
|
||||
},
|
||||
{
|
||||
"ed25519 public key",
|
||||
pubKey,
|
||||
&ed25519.PubKey{},
|
||||
append([]byte{32}, pubKey.Bytes()...), // Length-prefixed.
|
||||
"\"" + base64.StdEncoding.EncodeToString(pubKey.Bytes()) + "\"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Do a round trip of encoding/decoding binary.
|
||||
bz, err := aminoCdc.MarshalBinaryBare(tc.msg)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expBinary, bz)
|
||||
|
||||
err = aminoCdc.UnmarshalBinaryBare(bz, tc.typ)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.msg, tc.typ)
|
||||
|
||||
// Do a round trip of encoding/decoding JSON.
|
||||
bz, err = aminoCdc.MarshalJSON(tc.msg)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.expJSON, string(bz))
|
||||
|
||||
err = aminoCdc.UnmarshalJSON(bz, tc.typ)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, tc.msg, tc.typ)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMarshalAmino_BackwardsCompatibility(t *testing.T) {
|
||||
aminoCdc := codec.NewLegacyAmino()
|
||||
// Create Tendermint keys.
|
||||
tmPrivKey := tmed25519.GenPrivKey()
|
||||
tmPubKey := tmPrivKey.PubKey()
|
||||
// Create our own keys, with the same private key as Tendermint's.
|
||||
privKey := &ed25519.PrivKey{Key: []byte(tmPrivKey)}
|
||||
pubKey := privKey.PubKey().(*ed25519.PubKey)
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
tmKey interface{}
|
||||
ourKey interface{}
|
||||
marshalFn func(o interface{}) ([]byte, error)
|
||||
}{
|
||||
{
|
||||
"ed25519 private key, binary",
|
||||
tmPrivKey,
|
||||
privKey,
|
||||
aminoCdc.MarshalBinaryBare,
|
||||
},
|
||||
{
|
||||
"ed25519 private key, JSON",
|
||||
tmPrivKey,
|
||||
privKey,
|
||||
aminoCdc.MarshalJSON,
|
||||
},
|
||||
{
|
||||
"ed25519 public key, binary",
|
||||
tmPubKey,
|
||||
pubKey,
|
||||
aminoCdc.MarshalBinaryBare,
|
||||
},
|
||||
{
|
||||
"ed25519 public key, JSON",
|
||||
tmPubKey,
|
||||
pubKey,
|
||||
aminoCdc.MarshalJSON,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
// Make sure Amino encoding override is not breaking backwards compatibility.
|
||||
bz1, err := tc.marshalFn(tc.tmKey)
|
||||
require.NoError(t, err)
|
||||
bz2, err := tc.marshalFn(tc.ourKey)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, bz1, bz2)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,502 @@
|
|||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: cosmos/crypto/ed25519/keys.proto
|
||||
|
||||
package ed25519
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// PubKey defines a ed25519 public key
|
||||
// Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte
|
||||
// if the y-coordinate is the lexicographically largest of the two associated with
|
||||
// the x-coordinate. Otherwise the first byte is a 0x03.
|
||||
// This prefix is followed with the x-coordinate.
|
||||
type PubKey struct {
|
||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *PubKey) Reset() { *m = PubKey{} }
|
||||
func (*PubKey) ProtoMessage() {}
|
||||
func (*PubKey) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_48fe3336771e732d, []int{0}
|
||||
}
|
||||
func (m *PubKey) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *PubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_PubKey.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *PubKey) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_PubKey.Merge(m, src)
|
||||
}
|
||||
func (m *PubKey) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *PubKey) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_PubKey.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_PubKey proto.InternalMessageInfo
|
||||
|
||||
func (m *PubKey) GetKey() []byte {
|
||||
if m != nil {
|
||||
return m.Key
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PrivKey defines a ed25519 private key.
|
||||
type PrivKey struct {
|
||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *PrivKey) Reset() { *m = PrivKey{} }
|
||||
func (m *PrivKey) String() string { return proto.CompactTextString(m) }
|
||||
func (*PrivKey) ProtoMessage() {}
|
||||
func (*PrivKey) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_48fe3336771e732d, []int{1}
|
||||
}
|
||||
func (m *PrivKey) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *PrivKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_PrivKey.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *PrivKey) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_PrivKey.Merge(m, src)
|
||||
}
|
||||
func (m *PrivKey) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *PrivKey) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_PrivKey.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_PrivKey proto.InternalMessageInfo
|
||||
|
||||
func (m *PrivKey) GetKey() []byte {
|
||||
if m != nil {
|
||||
return m.Key
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*PubKey)(nil), "cosmos.crypto.ed25519.PubKey")
|
||||
proto.RegisterType((*PrivKey)(nil), "cosmos.crypto.ed25519.PrivKey")
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("cosmos/crypto/ed25519/keys.proto", fileDescriptor_48fe3336771e732d) }
|
||||
|
||||
var fileDescriptor_48fe3336771e732d = []byte{
|
||||
// 183 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce,
|
||||
0xcd, 0x2f, 0xd6, 0x4f, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0xd7, 0x4f, 0x4d, 0x31, 0x32, 0x35, 0x35,
|
||||
0xb4, 0xd4, 0xcf, 0x4e, 0xad, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x85, 0xa8,
|
||||
0xd0, 0x83, 0xa8, 0xd0, 0x83, 0xaa, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd0, 0x07,
|
||||
0xb1, 0x20, 0x8a, 0x95, 0x14, 0xb8, 0xd8, 0x02, 0x4a, 0x93, 0xbc, 0x53, 0x2b, 0x85, 0x04, 0xb8,
|
||||
0x98, 0xb3, 0x53, 0x2b, 0x25, 0x18, 0x15, 0x18, 0x35, 0x78, 0x82, 0x40, 0x4c, 0x2b, 0x96, 0x19,
|
||||
0x0b, 0xe4, 0x19, 0x94, 0xa4, 0xb9, 0xd8, 0x03, 0x8a, 0x32, 0xcb, 0xb0, 0x2a, 0x71, 0xf2, 0x3a,
|
||||
0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63,
|
||||
0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x83, 0xf4, 0xcc, 0x92, 0x8c, 0xd2,
|
||||
0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x98, 0x93, 0xc1, 0x94, 0x6e, 0x71, 0x4a, 0x36, 0xcc, 0xf5,
|
||||
0x20, 0x57, 0xc3, 0xbc, 0x90, 0xc4, 0x06, 0x76, 0x91, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xcc,
|
||||
0xf3, 0x11, 0x99, 0xe2, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *PubKey) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *PubKey) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *PubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Key) > 0 {
|
||||
i -= len(m.Key)
|
||||
copy(dAtA[i:], m.Key)
|
||||
i = encodeVarintKeys(dAtA, i, uint64(len(m.Key)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *PrivKey) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *PrivKey) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *PrivKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Key) > 0 {
|
||||
i -= len(m.Key)
|
||||
copy(dAtA[i:], m.Key)
|
||||
i = encodeVarintKeys(dAtA, i, uint64(len(m.Key)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintKeys(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovKeys(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *PubKey) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Key)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovKeys(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *PrivKey) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Key)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovKeys(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovKeys(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozKeys(x uint64) (n int) {
|
||||
return sovKeys(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *PubKey) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: PubKey: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: PubKey: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Key == nil {
|
||||
m.Key = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipKeys(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *PrivKey) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: PrivKey: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: PrivKey: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.Key == nil {
|
||||
m.Key = []byte{}
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipKeys(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skippy < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if (iNdEx + skippy) < 0 {
|
||||
return ErrInvalidLengthKeys
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipKeys(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowKeys
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthKeys
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupKeys
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthKeys
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthKeys = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowKeys = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupKeys = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
|
@ -1,8 +1,8 @@
|
|||
package multisig
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/sr25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
@ -57,9 +58,10 @@ func (privKey PrivKey) MarshalAmino() ([]byte, error) {
|
|||
|
||||
// UnmarshalAmino overrides Amino binary marshalling.
|
||||
func (privKey *PrivKey) UnmarshalAmino(bz []byte) error {
|
||||
*privKey = PrivKey{
|
||||
Key: bz,
|
||||
if len(bz) != PrivKeySize {
|
||||
return fmt.Errorf("invalid privkey size")
|
||||
}
|
||||
privKey.Key = bz
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -183,9 +185,10 @@ func (pubKey PubKey) MarshalAmino() ([]byte, error) {
|
|||
|
||||
// UnmarshalAmino overrides Amino binary marshalling.
|
||||
func (pubKey *PubKey) UnmarshalAmino(bz []byte) error {
|
||||
*pubKey = PubKey{
|
||||
Key: bz,
|
||||
if len(bz) != PubKeySize {
|
||||
return errors.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size")
|
||||
}
|
||||
pubKey.Key = bz
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -22,3 +22,9 @@ type PrivKey interface {
|
|||
type (
|
||||
Address = tmcrypto.Address
|
||||
)
|
||||
|
||||
// IntoTmPubKey allows our own PubKey types be converted into Tendermint's
|
||||
// pubkey types.
|
||||
type IntoTmPubKey interface {
|
||||
AsTmPubKey() tmcrypto.PubKey
|
||||
}
|
||||
|
|
19
go.sum
19
go.sum
|
@ -568,7 +568,6 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
|
|||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca h1:Ld/zXl5t4+D69SiV4JoN7kkfvJdOWlPpfxrzxpLMoUk=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
|
||||
|
@ -610,7 +609,6 @@ go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
|||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
|
@ -634,7 +632,6 @@ golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPh
|
|||
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg=
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
|
||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
|
@ -642,7 +639,6 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL
|
|||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136 h1:A1gGSx58LAGVHUUsOf7IiR0u8Xb6W51gRwfDBhkdcaw=
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||
golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
|
@ -653,7 +649,6 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk
|
|||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
|
@ -682,17 +677,14 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc h1:zK/HqS5bZxDptfPJNq8v7vJfXtkU7r9TLIoSr1bXaP4=
|
||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
|
@ -735,15 +727,12 @@ golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
|
||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
|
||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed h1:J22ig1FUekjjkmZUM7pTKixYm8DvrYsvrBZdunYeIuQ=
|
||||
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
|
@ -773,12 +762,10 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn
|
|||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2 h1:V9r/14uGBqLgNlHRYWdVqjMdWkcOHnE2KG8DwVqQSEc=
|
||||
golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@ -787,13 +774,11 @@ google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEt
|
|||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.13.0 h1:Q3Ui3V3/CVinFWFiW39Iw0kMuVrRzYX0wN6OPFp0lTA=
|
||||
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I=
|
||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
|
@ -809,7 +794,6 @@ google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvx
|
|||
google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
|
@ -828,7 +812,6 @@ google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
|
|||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
|
||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.1 h1:SfXqXS5hkufcdZ/mHtYCh53P2b+92WQq/DZcKLgsFRs=
|
||||
google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
|
@ -842,7 +825,6 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
|
|||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
|
@ -854,7 +836,6 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8X
|
|||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
||||
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
|
||||
|
|
|
@ -3,6 +3,7 @@ package cosmos.auth.v1beta1;
|
|||
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";
|
||||
|
||||
|
@ -15,7 +16,7 @@ message BaseAccount {
|
|||
option (cosmos_proto.implements_interface) = "AccountI";
|
||||
|
||||
bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
|
||||
bytes pub_key = 2 [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""];
|
||||
google.protobuf.Any pub_key = 2 [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""];
|
||||
uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""];
|
||||
uint64 sequence = 4;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
syntax = "proto3";
|
||||
package cosmos.crypto.ed25519;
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519";
|
||||
|
||||
// PubKey defines a ed25519 public key
|
||||
// Key is the compressed form of the pubkey. The first byte depends is a 0x02 byte
|
||||
// if the y-coordinate is the lexicographically largest of the two associated with
|
||||
// the x-coordinate. Otherwise the first byte is a 0x03.
|
||||
// This prefix is followed with the x-coordinate.
|
||||
message PubKey {
|
||||
option (gogoproto.goproto_stringer) = false;
|
||||
|
||||
bytes key = 1;
|
||||
}
|
||||
|
||||
// PrivKey defines a ed25519 private key.
|
||||
message PrivKey {
|
||||
bytes key = 1;
|
||||
}
|
|
@ -12,7 +12,6 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
@ -20,8 +19,10 @@ import (
|
|||
|
||||
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
|
@ -420,7 +421,8 @@ func NewPubKeyFromHex(pk string) (res crypto.PubKey) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pkEd := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
copy(pkEd, pkBytes)
|
||||
return pkEd
|
||||
if len(pkBytes) != ed25519.PubKeySize {
|
||||
panic(errors.Wrap(errors.ErrInvalidPubKey, "invalid pubkey size"))
|
||||
}
|
||||
return &ed25519.PubKey{Key: pkBytes}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/codec/legacy"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/types/bech32"
|
||||
)
|
||||
|
||||
|
@ -626,7 +627,18 @@ func Bech32ifyPubKey(pkt Bech32PubKeyType, pubkey crypto.PubKey) (string, error)
|
|||
|
||||
}
|
||||
|
||||
return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.MustMarshalBinaryBare(pubkey))
|
||||
// This piece of code is to keep backwards-compatibility.
|
||||
// For ed25519 keys, our own ed25519 is registered in Amino under a
|
||||
// different name than TM's ed25519. But since users are already using
|
||||
// TM's ed25519 bech32 encoding, we explicitly say to bech32-encode our own
|
||||
// ed25519 the same way as TM's ed25519.
|
||||
// TODO: Remove Bech32ifyPubKey and all usages (cosmos/cosmos-sdk/issues/#7357)
|
||||
pkToMarshal := pubkey
|
||||
if ed25519Pk, ok := pubkey.(*ed25519.PubKey); ok {
|
||||
pkToMarshal = ed25519Pk.AsTmPubKey()
|
||||
}
|
||||
|
||||
return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.MustMarshalBinaryBare(pkToMarshal))
|
||||
}
|
||||
|
||||
// MustBech32ifyPubKey calls Bech32ifyPubKey except it panics on error.
|
||||
|
|
|
@ -6,20 +6,21 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func BenchmarkBech32ifyPubKey(b *testing.B) {
|
||||
pk := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
pkBz := make([]byte, ed25519.PubKeySize)
|
||||
pk := &ed25519.PubKey{Key: pkBz}
|
||||
rng := rand.New(rand.NewSource(time.Now().Unix()))
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
rng.Read(pk)
|
||||
rng.Read(pk.Key)
|
||||
b.StartTimer()
|
||||
|
||||
_, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
|
||||
|
@ -28,14 +29,15 @@ func BenchmarkBech32ifyPubKey(b *testing.B) {
|
|||
}
|
||||
|
||||
func BenchmarkGetPubKeyFromBech32(b *testing.B) {
|
||||
pk := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
pkBz := make([]byte, ed25519.PubKeySize)
|
||||
pk := &ed25519.PubKey{Key: pkBz}
|
||||
rng := rand.New(rand.NewSource(time.Now().Unix()))
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
rng.Read(pk)
|
||||
rng.Read(pk.Key)
|
||||
|
||||
pkStr, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
|
||||
require.NoError(b, err)
|
||||
|
|
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
@ -57,10 +57,11 @@ func TestEmptyAddresses(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRandBech32PubkeyConsistency(t *testing.T) {
|
||||
pub := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
pubBz := make([]byte, ed25519.PubKeySize)
|
||||
pub := &ed25519.PubKey{Key: pubBz}
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
rand.Read(pub)
|
||||
rand.Read(pub.Key)
|
||||
|
||||
mustBech32AccPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeAccPub, pub)
|
||||
bech32AccPub, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeAccPub, pub)
|
||||
|
@ -115,10 +116,11 @@ func TestYAMLMarshalers(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRandBech32AccAddrConsistency(t *testing.T) {
|
||||
pub := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
pubBz := make([]byte, ed25519.PubKeySize)
|
||||
pub := &ed25519.PubKey{Key: pubBz}
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
rand.Read(pub)
|
||||
rand.Read(pub.Key)
|
||||
|
||||
acc := types.AccAddress(pub.Address())
|
||||
res := types.AccAddress{}
|
||||
|
@ -153,10 +155,11 @@ func TestRandBech32AccAddrConsistency(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestValAddr(t *testing.T) {
|
||||
pub := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
pubBz := make([]byte, ed25519.PubKeySize)
|
||||
pub := &ed25519.PubKey{Key: pubBz}
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
rand.Read(pub[:])
|
||||
rand.Read(pub.Key)
|
||||
|
||||
acc := types.ValAddress(pub.Address())
|
||||
res := types.ValAddress{}
|
||||
|
@ -193,10 +196,11 @@ func TestValAddr(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestConsAddress(t *testing.T) {
|
||||
pub := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
pubBz := make([]byte, ed25519.PubKeySize)
|
||||
pub := &ed25519.PubKey{Key: pubBz}
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
rand.Read(pub[:])
|
||||
rand.Read(pub.Key[:])
|
||||
|
||||
acc := types.ConsAddress(pub.Address())
|
||||
res := types.ConsAddress{}
|
||||
|
@ -242,10 +246,11 @@ func RandString(n int) string {
|
|||
}
|
||||
|
||||
func TestConfiguredPrefix(t *testing.T) {
|
||||
pub := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
pubBz := make([]byte, ed25519.PubKeySize)
|
||||
pub := &ed25519.PubKey{Key: pubBz}
|
||||
for length := 1; length < 10; length++ {
|
||||
for times := 1; times < 20; times++ {
|
||||
rand.Read(pub[:])
|
||||
rand.Read(pub.Key[:])
|
||||
// Test if randomly generated prefix of a given length works
|
||||
prefix := RandString(length)
|
||||
|
||||
|
@ -297,8 +302,9 @@ func TestConfiguredPrefix(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAddressInterface(t *testing.T) {
|
||||
pub := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
rand.Read(pub)
|
||||
pubBz := make([]byte, ed25519.PubKeySize)
|
||||
pub := &ed25519.PubKey{Key: pubBz}
|
||||
rand.Read(pub.Key)
|
||||
|
||||
addrs := []types.Address{
|
||||
types.ConsAddress(pub.Address()),
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"math/rand"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
|
@ -1002,7 +1002,7 @@ func (suite *AnteTestSuite) TestCustomSignatureVerificationGasConsumer() {
|
|||
// setup an ante handler that only accepts PubKeyEd25519
|
||||
suite.anteHandler = ante.NewAnteHandler(suite.app.AccountKeeper, suite.app.BankKeeper, func(meter sdk.GasMeter, sig signing.SignatureV2, params types.Params) error {
|
||||
switch pubkey := sig.PubKey.(type) {
|
||||
case ed25519.PubKey:
|
||||
case *ed25519.PubKey:
|
||||
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
|
||||
return nil
|
||||
default:
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
|
||||
|
@ -360,9 +360,8 @@ func DefaultSigVerificationGasConsumer(
|
|||
meter sdk.GasMeter, sig signing.SignatureV2, params types.Params,
|
||||
) error {
|
||||
pubkey := sig.PubKey
|
||||
|
||||
switch pubkey := pubkey.(type) {
|
||||
case ed25519.PubKey:
|
||||
case *ed25519.PubKey:
|
||||
meter.ConsumeGas(params.SigVerifyCostED25519, "ante verify: ed25519")
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, "ED25519 public keys are unsupported")
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
|
|
|
@ -6,13 +6,13 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
gogotypes "github.com/gogo/protobuf/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
|
|
|
@ -12,7 +12,10 @@ import (
|
|||
"github.com/tendermint/tendermint/crypto"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -30,7 +33,10 @@ func NewBaseAccount(address sdk.AccAddress, pubKey crypto.PubKey, accountNumber,
|
|||
Sequence: sequence,
|
||||
}
|
||||
|
||||
acc.SetPubKey(pubKey)
|
||||
err := acc.SetPubKey(pubKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return acc
|
||||
}
|
||||
|
@ -64,12 +70,14 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error {
|
|||
|
||||
// GetPubKey - Implements sdk.AccountI.
|
||||
func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) {
|
||||
if len(acc.PubKey) == 0 {
|
||||
if acc.PubKey == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
amino.MustUnmarshalBinaryBare(acc.PubKey, &pk)
|
||||
return pk
|
||||
content, ok := acc.PubKey.GetCachedValue().(crypto.PubKey)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
// SetPubKey - Implements sdk.AccountI.
|
||||
|
@ -77,7 +85,17 @@ func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error {
|
|||
if pubKey == nil {
|
||||
acc.PubKey = nil
|
||||
} else {
|
||||
acc.PubKey = amino.MustMarshalBinaryBare(pubKey)
|
||||
protoMsg, ok := pubKey.(proto.Message)
|
||||
if !ok {
|
||||
return sdkerrors.ErrInvalidPubKey
|
||||
}
|
||||
|
||||
any, err := codectypes.NewAnyWithValue(protoMsg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
acc.PubKey = any
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -107,7 +125,7 @@ func (acc *BaseAccount) SetSequence(seq uint64) error {
|
|||
|
||||
// Validate checks for errors on the account fields
|
||||
func (acc BaseAccount) Validate() error {
|
||||
if len(acc.PubKey) != 0 && acc.Address != nil &&
|
||||
if acc.PubKey != nil && acc.Address != nil &&
|
||||
!bytes.Equal(acc.GetPubKey().Address().Bytes(), acc.Address.Bytes()) {
|
||||
return errors.New("account address and pubkey address do not match")
|
||||
}
|
||||
|
@ -120,38 +138,24 @@ func (acc BaseAccount) String() string {
|
|||
return out.(string)
|
||||
}
|
||||
|
||||
type baseAccountPretty struct {
|
||||
Address sdk.AccAddress `json:"address" yaml:"address"`
|
||||
PubKey string `json:"public_key" yaml:"public_key"`
|
||||
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
|
||||
Sequence uint64 `json:"sequence" yaml:"sequence"`
|
||||
}
|
||||
|
||||
// MarshalYAML returns the YAML representation of an account.
|
||||
func (acc BaseAccount) MarshalYAML() (interface{}, error) {
|
||||
alias := baseAccountPretty{
|
||||
Address: acc.Address,
|
||||
AccountNumber: acc.AccountNumber,
|
||||
Sequence: acc.Sequence,
|
||||
}
|
||||
|
||||
if acc.PubKey != nil {
|
||||
pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.GetPubKey())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
alias.PubKey = pks
|
||||
}
|
||||
|
||||
bz, err := yaml.Marshal(alias)
|
||||
bz, err := codec.MarshalYAML(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()), &acc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return string(bz), err
|
||||
}
|
||||
|
||||
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
|
||||
func (acc BaseAccount) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||
if acc.PubKey == nil {
|
||||
return nil
|
||||
}
|
||||
var pubKey crypto.PubKey
|
||||
return unpacker.UnpackAny(acc.PubKey, &pubKey)
|
||||
}
|
||||
|
||||
// NewModuleAddress creates an AccAddress from the hash of the module's name
|
||||
func NewModuleAddress(name string) sdk.AccAddress {
|
||||
return sdk.AccAddress(crypto.AddressHash([]byte(name)))
|
||||
|
|
|
@ -5,6 +5,7 @@ package types
|
|||
|
||||
import (
|
||||
fmt "fmt"
|
||||
types "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
|
@ -30,7 +31,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
|||
// type for additional functionality (e.g. vesting).
|
||||
type BaseAccount struct {
|
||||
Address github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=address,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"address,omitempty"`
|
||||
PubKey []byte `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"public_key,omitempty" yaml:"public_key"`
|
||||
PubKey *types.Any `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"public_key,omitempty" yaml:"public_key"`
|
||||
AccountNumber uint64 `protobuf:"varint,3,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty" yaml:"account_number"`
|
||||
Sequence uint64 `protobuf:"varint,4,opt,name=sequence,proto3" json:"sequence,omitempty"`
|
||||
}
|
||||
|
@ -191,49 +192,50 @@ func init() {
|
|||
func init() { proto.RegisterFile("cosmos/auth/v1beta1/auth.proto", fileDescriptor_7e1f7e915d020d2d) }
|
||||
|
||||
var fileDescriptor_7e1f7e915d020d2d = []byte{
|
||||
// 657 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xbf, 0x6f, 0xd3, 0x40,
|
||||
0x14, 0x8e, 0x9b, 0xd0, 0x1f, 0x97, 0xb6, 0x52, 0xdd, 0xb4, 0x4d, 0x03, 0xf2, 0x59, 0x9e, 0x8a,
|
||||
0x44, 0x12, 0xa5, 0xa8, 0x48, 0xcd, 0x80, 0xa8, 0x0b, 0x48, 0x55, 0x69, 0x55, 0xb9, 0x12, 0x03,
|
||||
0x8b, 0x39, 0x3b, 0x47, 0x6a, 0x35, 0x97, 0x73, 0x7d, 0xe7, 0x2a, 0xee, 0x5f, 0xc0, 0xc8, 0x84,
|
||||
0x18, 0xfb, 0x47, 0xf0, 0x1f, 0xb0, 0x30, 0x56, 0x4c, 0x4c, 0x06, 0xa5, 0x0b, 0x62, 0xf4, 0xc8,
|
||||
0x84, 0x7c, 0xe7, 0xa6, 0x4e, 0x15, 0x98, 0x7c, 0xef, 0x7b, 0xdf, 0xf7, 0xbd, 0xe7, 0xf7, 0x74,
|
||||
0x07, 0x34, 0x97, 0x32, 0x42, 0x59, 0x13, 0x85, 0xfc, 0xa4, 0x79, 0xde, 0x72, 0x30, 0x47, 0x2d,
|
||||
0x11, 0x34, 0xfc, 0x80, 0x72, 0xaa, 0x2e, 0xcb, 0x7c, 0x43, 0x40, 0x59, 0xbe, 0xb6, 0x2e, 0x41,
|
||||
0x5b, 0x50, 0x9a, 0x19, 0x43, 0x04, 0xb5, 0x4a, 0x97, 0x76, 0xa9, 0xc4, 0xd3, 0x93, 0x44, 0x8d,
|
||||
0x8f, 0x53, 0xa0, 0x6c, 0x22, 0x86, 0x77, 0x5c, 0x97, 0x86, 0x7d, 0xae, 0xee, 0x83, 0x19, 0xd4,
|
||||
0xe9, 0x04, 0x98, 0xb1, 0xaa, 0xa2, 0x2b, 0x1b, 0xf3, 0x66, 0xeb, 0x4f, 0x0c, 0xeb, 0x5d, 0x8f,
|
||||
0x9f, 0x84, 0x4e, 0xc3, 0xa5, 0x24, 0xf3, 0xcc, 0x3e, 0x75, 0xd6, 0x39, 0x6d, 0xf2, 0xc8, 0xc7,
|
||||
0xac, 0xb1, 0xe3, 0xba, 0x3b, 0x52, 0x68, 0xdd, 0x38, 0xa8, 0x2f, 0xc1, 0x8c, 0x1f, 0x3a, 0xf6,
|
||||
0x29, 0x8e, 0xaa, 0x53, 0xc2, 0xac, 0xfe, 0x3b, 0x86, 0x15, 0x3f, 0x74, 0x7a, 0x9e, 0x9b, 0xa2,
|
||||
0x8f, 0x28, 0xf1, 0x38, 0x26, 0x3e, 0x8f, 0x92, 0x18, 0x2e, 0x45, 0x88, 0xf4, 0xda, 0xc6, 0x6d,
|
||||
0xd6, 0xb0, 0xa6, 0xfd, 0xd0, 0xd9, 0xc7, 0x91, 0xfa, 0x0c, 0x2c, 0x22, 0xd9, 0x9f, 0xdd, 0x0f,
|
||||
0x89, 0x83, 0x83, 0x6a, 0x51, 0x57, 0x36, 0x4a, 0xe6, 0x7a, 0x12, 0xc3, 0x15, 0x29, 0x1b, 0xcf,
|
||||
0x1b, 0xd6, 0x42, 0x06, 0x1c, 0x8a, 0x58, 0xad, 0x81, 0x59, 0x86, 0xcf, 0x42, 0xdc, 0x77, 0x71,
|
||||
0xb5, 0x94, 0x6a, 0xad, 0x51, 0xdc, 0xae, 0xbc, 0xbf, 0x84, 0x85, 0x4f, 0x97, 0xb0, 0xf0, 0xed,
|
||||
0x73, 0x7d, 0x36, 0x9b, 0xc3, 0x9e, 0xf1, 0x45, 0x01, 0x0b, 0x07, 0xb4, 0x13, 0xf6, 0x46, 0xa3,
|
||||
0x79, 0x0b, 0xe6, 0x1d, 0xc4, 0xb0, 0x9d, 0x39, 0x8b, 0xf9, 0x94, 0x37, 0xf5, 0xc6, 0x84, 0x3d,
|
||||
0x34, 0x72, 0x23, 0x35, 0xef, 0x5f, 0xc5, 0x50, 0x49, 0x62, 0xb8, 0x2c, 0x3b, 0xcd, 0x7b, 0x18,
|
||||
0x56, 0xd9, 0xc9, 0x0d, 0x5f, 0x05, 0xa5, 0x3e, 0x22, 0x58, 0x0c, 0x6b, 0xce, 0x12, 0x67, 0x55,
|
||||
0x07, 0x65, 0x1f, 0x07, 0xc4, 0x63, 0xcc, 0xa3, 0x7d, 0x56, 0x2d, 0xea, 0xc5, 0x8d, 0x39, 0x2b,
|
||||
0x0f, 0xb5, 0x6b, 0xb9, 0xfe, 0x17, 0xc7, 0x5a, 0xde, 0x33, 0x7e, 0x14, 0xc1, 0xf4, 0x11, 0x0a,
|
||||
0x10, 0x61, 0xea, 0x21, 0x58, 0x26, 0x68, 0x60, 0x13, 0x4c, 0xa8, 0xed, 0x9e, 0xa0, 0x00, 0xb9,
|
||||
0x1c, 0x07, 0x72, 0xcb, 0x25, 0x53, 0x4b, 0x62, 0x58, 0x93, 0xfd, 0x4d, 0x20, 0x19, 0xd6, 0x12,
|
||||
0x41, 0x83, 0x03, 0x4c, 0xe8, 0xee, 0x08, 0x53, 0xb7, 0xc1, 0x3c, 0x1f, 0xd8, 0xcc, 0xeb, 0xda,
|
||||
0x3d, 0x8f, 0x78, 0x5c, 0x34, 0x5d, 0x32, 0xd7, 0x6e, 0x7f, 0x34, 0x9f, 0x35, 0x2c, 0xc0, 0x07,
|
||||
0xc7, 0x5e, 0xf7, 0x55, 0x1a, 0xa8, 0x16, 0x58, 0x11, 0xc9, 0x0b, 0x6c, 0xbb, 0x94, 0x71, 0xdb,
|
||||
0xc7, 0x81, 0xed, 0x44, 0x1c, 0x67, 0x6b, 0xd5, 0x93, 0x18, 0x3e, 0xc8, 0x79, 0xdc, 0xa5, 0x19,
|
||||
0xd6, 0x52, 0x6a, 0x76, 0x81, 0x77, 0x29, 0xe3, 0x47, 0x38, 0x30, 0x23, 0x8e, 0xd5, 0x33, 0xb0,
|
||||
0x96, 0x56, 0x3b, 0xc7, 0x81, 0xf7, 0x2e, 0x92, 0x7c, 0xdc, 0xd9, 0xdc, 0xda, 0x6a, 0x6d, 0xcb,
|
||||
0x85, 0x9b, 0xed, 0x61, 0x0c, 0x2b, 0xc7, 0x5e, 0xf7, 0xb5, 0x60, 0xa4, 0xd2, 0x17, 0xcf, 0x45,
|
||||
0x3e, 0x89, 0xa1, 0x26, 0xab, 0xfd, 0xc3, 0xc0, 0xb0, 0x2a, 0x6c, 0x4c, 0x27, 0x61, 0x35, 0x02,
|
||||
0xeb, 0x77, 0x15, 0x0c, 0xbb, 0xfe, 0xe6, 0xd6, 0x93, 0xd3, 0x56, 0xf5, 0x9e, 0x28, 0xfa, 0x74,
|
||||
0x18, 0xc3, 0xd5, 0xb1, 0xa2, 0xc7, 0x37, 0x8c, 0x24, 0x86, 0xfa, 0xe4, 0xb2, 0x23, 0x13, 0xc3,
|
||||
0x5a, 0x65, 0x13, 0xb5, 0xed, 0xd9, 0x74, 0xdf, 0xbf, 0x2e, 0xa1, 0x62, 0xee, 0x7e, 0x1d, 0x6a,
|
||||
0xca, 0xd5, 0x50, 0x53, 0x7e, 0x0e, 0x35, 0xe5, 0xc3, 0xb5, 0x56, 0xb8, 0xba, 0xd6, 0x0a, 0xdf,
|
||||
0xaf, 0xb5, 0xc2, 0x9b, 0x87, 0xff, 0xbd, 0xb5, 0x03, 0xf9, 0xb0, 0x88, 0xcb, 0xeb, 0x4c, 0x8b,
|
||||
0xc7, 0xe0, 0xf1, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x11, 0x68, 0xfa, 0x1e, 0x74, 0x04, 0x00,
|
||||
0x00,
|
||||
// 687 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0x3f, 0x6f, 0xd3, 0x5e,
|
||||
0x14, 0x8d, 0x9b, 0xfc, 0xfa, 0xe7, 0xa5, 0xad, 0x54, 0x37, 0x6d, 0x93, 0xfc, 0x90, 0x6d, 0x79,
|
||||
0x0a, 0x12, 0x71, 0x94, 0xa0, 0x22, 0x35, 0x03, 0x22, 0x2e, 0x0c, 0x55, 0x69, 0x55, 0xb9, 0x12,
|
||||
0x03, 0x42, 0x32, 0xcf, 0xce, 0xab, 0x6b, 0x35, 0x2f, 0xcf, 0xf5, 0x7b, 0xae, 0xe2, 0x7e, 0x02,
|
||||
0x46, 0x46, 0xc6, 0x7e, 0x00, 0x46, 0xbe, 0x01, 0x0b, 0x63, 0xc5, 0xc4, 0x64, 0x50, 0xba, 0x20,
|
||||
0xc6, 0x8c, 0x4c, 0xc8, 0xef, 0xb9, 0x69, 0x52, 0x05, 0xa6, 0xbc, 0x7b, 0xce, 0xb9, 0xf7, 0x9e,
|
||||
0xdc, 0xab, 0x6b, 0xa0, 0xb8, 0x84, 0x62, 0x42, 0x1b, 0x30, 0x62, 0xa7, 0x8d, 0x8b, 0xa6, 0x83,
|
||||
0x18, 0x6c, 0xf2, 0xc0, 0x08, 0x42, 0xc2, 0x88, 0xbc, 0x2e, 0x78, 0x83, 0x43, 0x19, 0x5f, 0xad,
|
||||
0x08, 0xd0, 0xe6, 0x92, 0x46, 0xa6, 0xe0, 0x41, 0xb5, 0xe4, 0x11, 0x8f, 0x08, 0x3c, 0x7d, 0x65,
|
||||
0x68, 0xc5, 0x23, 0xc4, 0xeb, 0xa1, 0x06, 0x8f, 0x9c, 0xe8, 0xa4, 0x01, 0xfb, 0xb1, 0xa0, 0xf4,
|
||||
0x8f, 0x73, 0xa0, 0x68, 0x42, 0x8a, 0x3a, 0xae, 0x4b, 0xa2, 0x3e, 0x93, 0xf7, 0xc1, 0x02, 0xec,
|
||||
0x76, 0x43, 0x44, 0x69, 0x59, 0xd2, 0xa4, 0xda, 0xb2, 0xd9, 0xfc, 0x9d, 0xa8, 0x75, 0xcf, 0x67,
|
||||
0xa7, 0x91, 0x63, 0xb8, 0x04, 0x67, 0xed, 0xb2, 0x9f, 0x3a, 0xed, 0x9e, 0x35, 0x58, 0x1c, 0x20,
|
||||
0x6a, 0x74, 0x5c, 0xb7, 0x23, 0x12, 0xad, 0xdb, 0x0a, 0xf2, 0x1b, 0xb0, 0x10, 0x44, 0x8e, 0x7d,
|
||||
0x86, 0xe2, 0xf2, 0x9c, 0x26, 0xd5, 0x8a, 0xad, 0x92, 0x21, 0x9c, 0x18, 0xb7, 0x4e, 0x8c, 0x4e,
|
||||
0x3f, 0x36, 0xeb, 0xbf, 0x12, 0xb5, 0x14, 0x44, 0x4e, 0xcf, 0x77, 0x53, 0xed, 0x23, 0x82, 0x7d,
|
||||
0x86, 0x70, 0xc0, 0xe2, 0x51, 0xa2, 0xae, 0xc5, 0x10, 0xf7, 0xda, 0xfa, 0x1d, 0xab, 0x5b, 0xf3,
|
||||
0x41, 0xe4, 0xec, 0xa3, 0x58, 0x7e, 0x06, 0x56, 0xa1, 0x70, 0x6d, 0xf7, 0x23, 0xec, 0xa0, 0xb0,
|
||||
0x9c, 0xd7, 0xa4, 0x5a, 0xc1, 0xac, 0x8c, 0x12, 0x75, 0x43, 0xa4, 0x4d, 0xf3, 0xba, 0xb5, 0x92,
|
||||
0x01, 0x87, 0x3c, 0x96, 0xab, 0x60, 0x91, 0xa2, 0xf3, 0x08, 0xf5, 0x5d, 0x54, 0x2e, 0xa4, 0xb9,
|
||||
0xd6, 0x38, 0x6e, 0x97, 0xde, 0x5d, 0xa9, 0xb9, 0x0f, 0x57, 0x6a, 0xee, 0xeb, 0xa7, 0xfa, 0x62,
|
||||
0x36, 0x9d, 0x3d, 0xfd, 0xb3, 0x04, 0x56, 0x0e, 0x48, 0x37, 0xea, 0x8d, 0x07, 0xf6, 0x16, 0x2c,
|
||||
0x3b, 0x90, 0x22, 0x3b, 0xab, 0xcc, 0xa7, 0x56, 0x6c, 0x69, 0xc6, 0x8c, 0xc5, 0x19, 0x13, 0x83,
|
||||
0x36, 0xff, 0xbf, 0x4e, 0x54, 0x69, 0x94, 0xa8, 0xeb, 0xc2, 0xe9, 0x64, 0x0d, 0xdd, 0x2a, 0x3a,
|
||||
0x13, 0x2b, 0x91, 0x41, 0xa1, 0x0f, 0x31, 0xe2, 0x23, 0x5c, 0xb2, 0xf8, 0x5b, 0xd6, 0x40, 0x31,
|
||||
0x40, 0x21, 0xf6, 0x29, 0xf5, 0x49, 0x9f, 0x96, 0xf3, 0x5a, 0xbe, 0xb6, 0x64, 0x4d, 0x42, 0xed,
|
||||
0xea, 0x84, 0xff, 0xd5, 0x29, 0xcb, 0x7b, 0xfa, 0xf7, 0x3c, 0x98, 0x3f, 0x82, 0x21, 0xc4, 0x54,
|
||||
0x3e, 0x04, 0xeb, 0x18, 0x0e, 0x6c, 0x8c, 0x30, 0xb1, 0xdd, 0x53, 0x18, 0x42, 0x97, 0xa1, 0x50,
|
||||
0xec, 0xbe, 0x60, 0x2a, 0xa3, 0x44, 0xad, 0x0a, 0x7f, 0x33, 0x44, 0xba, 0xb5, 0x86, 0xe1, 0xe0,
|
||||
0x00, 0x61, 0xb2, 0x3b, 0xc6, 0xe4, 0x1d, 0xb0, 0xcc, 0x06, 0x36, 0xf5, 0x3d, 0xbb, 0xe7, 0x63,
|
||||
0x9f, 0x71, 0xd3, 0x05, 0x73, 0xeb, 0xee, 0x8f, 0x4e, 0xb2, 0xba, 0x05, 0xd8, 0xe0, 0xd8, 0xf7,
|
||||
0x5e, 0xa6, 0x81, 0x6c, 0x81, 0x0d, 0x4e, 0x5e, 0x22, 0xdb, 0x25, 0x94, 0xd9, 0x01, 0x0a, 0x6d,
|
||||
0x27, 0x66, 0x28, 0x5b, 0xab, 0x36, 0x4a, 0xd4, 0x07, 0x13, 0x35, 0xee, 0xcb, 0x74, 0x6b, 0x2d,
|
||||
0x2d, 0x76, 0x89, 0x76, 0x09, 0x65, 0x47, 0x28, 0x34, 0x63, 0x86, 0xe4, 0x73, 0xb0, 0x95, 0x76,
|
||||
0xbb, 0x40, 0xa1, 0x7f, 0x12, 0x0b, 0x3d, 0xea, 0xb6, 0xb6, 0xb7, 0x9b, 0x3b, 0x62, 0xe1, 0x66,
|
||||
0x7b, 0x98, 0xa8, 0xa5, 0x63, 0xdf, 0x7b, 0xc5, 0x15, 0x69, 0xea, 0x8b, 0xe7, 0x9c, 0x1f, 0x25,
|
||||
0xaa, 0x22, 0xba, 0xfd, 0xa5, 0x80, 0x6e, 0x95, 0xe8, 0x54, 0x9e, 0x80, 0xe5, 0x18, 0x54, 0xee,
|
||||
0x67, 0x50, 0xe4, 0x06, 0xad, 0xed, 0x27, 0x67, 0xcd, 0xf2, 0x7f, 0xbc, 0xe9, 0xd3, 0x61, 0xa2,
|
||||
0x6e, 0x4e, 0x35, 0x3d, 0xbe, 0x55, 0x8c, 0x12, 0x55, 0x9b, 0xdd, 0x76, 0x5c, 0x44, 0xb7, 0x36,
|
||||
0xe9, 0xcc, 0xdc, 0xf6, 0x62, 0xba, 0xef, 0x9f, 0x57, 0xaa, 0x64, 0xee, 0x7e, 0x19, 0x2a, 0xd2,
|
||||
0xf5, 0x50, 0x91, 0x7e, 0x0c, 0x15, 0xe9, 0xfd, 0x8d, 0x92, 0xbb, 0xbe, 0x51, 0x72, 0xdf, 0x6e,
|
||||
0x94, 0xdc, 0xeb, 0x87, 0xff, 0xbc, 0xe5, 0x81, 0xf8, 0x12, 0xf1, 0x93, 0x76, 0xe6, 0xf9, 0x95,
|
||||
0x3e, 0xfe, 0x13, 0x00, 0x00, 0xff, 0xff, 0x5d, 0x49, 0xdd, 0xa9, 0xa5, 0x04, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (this *Params) Equal(that interface{}) bool {
|
||||
|
@ -302,10 +304,15 @@ func (m *BaseAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
i--
|
||||
dAtA[i] = 0x18
|
||||
}
|
||||
if len(m.PubKey) > 0 {
|
||||
i -= len(m.PubKey)
|
||||
copy(dAtA[i:], m.PubKey)
|
||||
i = encodeVarintAuth(dAtA, i, uint64(len(m.PubKey)))
|
||||
if m.PubKey != nil {
|
||||
{
|
||||
size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintAuth(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
|
@ -439,8 +446,8 @@ func (m *BaseAccount) Size() (n int) {
|
|||
if l > 0 {
|
||||
n += 1 + l + sovAuth(uint64(l))
|
||||
}
|
||||
l = len(m.PubKey)
|
||||
if l > 0 {
|
||||
if m.PubKey != nil {
|
||||
l = m.PubKey.Size()
|
||||
n += 1 + l + sovAuth(uint64(l))
|
||||
}
|
||||
if m.AccountNumber != 0 {
|
||||
|
@ -572,7 +579,7 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error {
|
|||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowAuth
|
||||
|
@ -582,24 +589,26 @@ func (m *BaseAccount) Unmarshal(dAtA []byte) error {
|
|||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthAuth
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthAuth
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.PubKey = append(m.PubKey[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.PubKey == nil {
|
||||
m.PubKey = []byte{}
|
||||
m.PubKey = &types.Any{}
|
||||
}
|
||||
if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
|
|
|
@ -2,8 +2,8 @@ package types
|
|||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
"github.com/tendermint/tendermint/types/time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence"
|
||||
|
|
|
@ -7,9 +7,9 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence"
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
|
@ -44,8 +44,7 @@ func newPubKey(pk string) (res crypto.PubKey) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
pubkey := make(ed25519.PubKey, ed25519.PubKeySize)
|
||||
copy(pubkey, pkBytes)
|
||||
pubkey := &ed25519.PubKey{Key: pkBytes}
|
||||
|
||||
return pubkey
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/types"
|
||||
)
|
||||
|
|
|
@ -4,13 +4,12 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/types"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func testMsgSubmitEvidence(t *testing.T, e exported.Evidence, s sdk.AccAddress) exported.MsgSubmitEvidence {
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
|
@ -63,7 +64,12 @@ func InitializeNodeValidatorFiles(config *cfg.Config) (nodeID string, valPubKey
|
|||
return "", nil, err
|
||||
}
|
||||
|
||||
valPubKey, err = privval.LoadOrGenFilePV(pvKeyFile, pvStateFile).GetPubKey()
|
||||
tmValPubKey, err := privval.LoadOrGenFilePV(pvKeyFile, pvStateFile).GetPubKey()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
valPubKey, err = ed25519.FromTmEd25519(tmValPubKey)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
|
@ -235,7 +236,7 @@ func (suite *KeeperTestSuite) TestCheckMisbehaviourAndUpdateState() {
|
|||
altPrivVal := ibctestingmock.NewPV()
|
||||
altPubKey, err := altPrivVal.GetPubKey()
|
||||
suite.Require().NoError(err)
|
||||
altVal := tmtypes.NewValidator(altPubKey, 4)
|
||||
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 4)
|
||||
|
||||
// Set valSet here with suite.valSet so it doesn't get reset on each testcase
|
||||
valSet := suite.valSet
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/keeper"
|
||||
|
@ -87,7 +88,7 @@ func (suite *KeeperTestSuite) SetupTest() {
|
|||
|
||||
testClientHeightMinus1 := types.NewHeight(0, height-1)
|
||||
|
||||
validator := tmtypes.NewValidator(pubKey, 1)
|
||||
validator := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 1)
|
||||
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
|
||||
suite.valSetHash = suite.valSet.Hash()
|
||||
suite.header = ibctmtypes.CreateTestHeader(testChainID, testClientHeight, testClientHeightMinus1, now2, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
client "github.com/cosmos/cosmos-sdk/x/ibc/02-client"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
|
||||
|
@ -50,7 +51,7 @@ func TestValidateGenesis(t *testing.T) {
|
|||
|
||||
now := time.Now().UTC()
|
||||
|
||||
val := tmtypes.NewValidator(pubKey, 10)
|
||||
val := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 10)
|
||||
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
|
||||
|
||||
heightMinus1 := types.NewHeight(0, height-1)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
|
@ -20,7 +21,7 @@ func (suite *TendermintTestSuite) TestCheckMisbehaviourAndUpdateState() {
|
|||
altPubKey, err := altPrivVal.GetPubKey()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
altVal := tmtypes.NewValidator(altPubKey, 4)
|
||||
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 4)
|
||||
|
||||
// Create bothValSet with both suite validator and altVal
|
||||
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
ibctestingmock "github.com/cosmos/cosmos-sdk/x/ibc/testing/mock"
|
||||
|
@ -35,7 +36,7 @@ func (suite *TendermintTestSuite) TestMisbehaviourValidateBasic() {
|
|||
|
||||
epochHeight := int64(height.EpochHeight)
|
||||
|
||||
altVal := tmtypes.NewValidator(altPubKey, epochHeight)
|
||||
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), epochHeight)
|
||||
|
||||
// Create bothValSet with both suite validator and altVal
|
||||
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
|
@ -76,7 +77,7 @@ func (suite *TendermintTestSuite) SetupTest() {
|
|||
|
||||
heightMinus1 := clienttypes.NewHeight(0, height.EpochHeight-1)
|
||||
|
||||
val := tmtypes.NewValidator(pubKey, 10)
|
||||
val := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 10)
|
||||
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
|
||||
suite.valsHash = suite.valSet.Hash()
|
||||
suite.header = ibctmtypes.CreateTestHeader(chainID, height, heightMinus1, suite.now, suite.valSet, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
types "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
commitmenttypes "github.com/cosmos/cosmos-sdk/x/ibc/23-commitment/types"
|
||||
|
@ -33,7 +34,7 @@ func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() {
|
|||
heightMinus3 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight-3)
|
||||
heightPlus5 := clienttypes.NewHeight(height.EpochNumber, height.EpochHeight+5)
|
||||
|
||||
altVal := tmtypes.NewValidator(altPubKey, epochHeight)
|
||||
altVal := tmtypes.NewValidator(altPubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), epochHeight)
|
||||
|
||||
// Create bothValSet with both suite validator and altVal. Would be valid update
|
||||
bothValSet := tmtypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
|
@ -60,7 +61,7 @@ func (suite *IBCTestSuite) SetupTest() {
|
|||
|
||||
now := time.Now().UTC()
|
||||
|
||||
val := tmtypes.NewValidator(pubKey, 10)
|
||||
val := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 10)
|
||||
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
|
||||
|
||||
clientHeightMinus1 := clienttypes.NewHeight(0, height-1)
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
@ -116,7 +117,7 @@ func NewTestChain(t *testing.T, chainID string) *TestChain {
|
|||
require.NoError(t, err)
|
||||
|
||||
// create validator set with single validator
|
||||
validator := tmtypes.NewValidator(pubKey, 1)
|
||||
validator := tmtypes.NewValidator(pubKey.(cryptotypes.IntoTmPubKey).AsTmPubKey(), 1)
|
||||
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})
|
||||
signers := []tmtypes.PrivValidator{privVal}
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@ package mock
|
|||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
)
|
||||
|
||||
var _ tmtypes.PrivValidator = PV{}
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
|
||||
gogotypes "github.com/gogo/protobuf/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
|
|
|
@ -10,12 +10,12 @@ import (
|
|||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
|
|
@ -2,10 +2,10 @@ package staking_test
|
|||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -153,7 +154,7 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
|
|||
require.True(t, found)
|
||||
assert.Equal(t, sdk.Bonded, validator.Status)
|
||||
assert.Equal(t, addr1, validator.OperatorAddress)
|
||||
assert.Equal(t, pk1, validator.GetConsPubKey())
|
||||
assert.Equal(t, pk1.(cryptotypes.IntoTmPubKey).AsTmPubKey(), validator.GetConsPubKey())
|
||||
assert.Equal(t, valTokens, validator.BondedTokens())
|
||||
assert.Equal(t, valTokens.ToDec(), validator.DelegatorShares)
|
||||
assert.Equal(t, types.Description{}, validator.Description)
|
||||
|
@ -185,7 +186,7 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
|
|||
require.True(t, found)
|
||||
assert.Equal(t, sdk.Bonded, validator.Status)
|
||||
assert.Equal(t, addr2, validator.OperatorAddress)
|
||||
assert.Equal(t, pk2, validator.GetConsPubKey())
|
||||
assert.Equal(t, pk2.(cryptotypes.IntoTmPubKey).AsTmPubKey(), validator.GetConsPubKey())
|
||||
assert.True(sdk.IntEq(t, valTokens, validator.Tokens))
|
||||
assert.True(sdk.DecEq(t, valTokens.ToDec(), validator.DelegatorShares))
|
||||
assert.Equal(t, types.Description{}, validator.Description)
|
||||
|
|
|
@ -6,10 +6,10 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/kv"
|
||||
|
|
|
@ -2,8 +2,8 @@ package types
|
|||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||
|
@ -421,7 +422,18 @@ func (v Validator) GetMoniker() string { return v.Description.Moniker }
|
|||
func (v Validator) GetStatus() sdk.BondStatus { return v.Status }
|
||||
func (v Validator) GetOperator() sdk.ValAddress { return v.OperatorAddress }
|
||||
func (v Validator) GetConsPubKey() crypto.PubKey {
|
||||
return sdk.MustGetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, v.ConsensusPubkey)
|
||||
// The way things are refactored now, v.ConsensusPubkey is sometimes a TM
|
||||
// ed25519 pubkey, sometimes our own ed25519 pubkey. This is very ugly and
|
||||
// inconsistent.
|
||||
// Luckily, here we coerce it into a TM ed25519 pubkey always, as this
|
||||
// pubkey will be passed into TM (eg calling encoding.PubKeyToProto).
|
||||
pk := sdk.MustGetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, v.ConsensusPubkey)
|
||||
|
||||
if intoTmPk, ok := pk.(cryptotypes.IntoTmPubKey); ok {
|
||||
return intoTmPk.AsTmPubKey()
|
||||
}
|
||||
|
||||
return pk
|
||||
}
|
||||
func (v Validator) GetConsAddr() sdk.ConsAddress { return sdk.ConsAddress(v.GetConsPubKey().Address()) }
|
||||
func (v Validator) GetTokens() sdk.Int { return v.Tokens }
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/encoding"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec/legacy"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
|
@ -318,7 +318,7 @@ func TestValidatorToTm(t *testing.T) {
|
|||
val.Status = sdk.Bonded
|
||||
val.Tokens = sdk.NewInt(rand.Int63())
|
||||
vals[i] = val
|
||||
expected[i] = tmtypes.NewValidator(pk, val.ConsensusPower())
|
||||
expected[i] = tmtypes.NewValidator(pk.(cryptotypes.IntoTmPubKey).AsTmPubKey(), val.ConsensusPower())
|
||||
}
|
||||
|
||||
require.Equal(t, expected, vals.ToTmValidators())
|
||||
|
|
Loading…
Reference in New Issue