From 23a9f46aad02b8af4f463c2a8183b35415e19f78 Mon Sep 17 00:00:00 2001 From: SaReN Date: Fri, 28 Aug 2020 21:32:38 +0530 Subject: [PATCH] Update tm pubkey references (#7102) * Update pubkey references * Update ledger_mock * Migrate encoding from tm * Update pubkey prefix * revert ed25519 to tendermint key * random account revert * Revert ed25519 references * revert secp key name * test revert * remove ed25519 * Update x/staking/types/validator.go Co-authored-by: Amaury Martiny * Revert "remove ed25519" This reverts commit 66d2e1d061aeae81c4c0a3daf718536b09dda19e. * remove ed25519 & sr25519 * Apply suggestions from code review * remove codec Co-authored-by: Marko Baricevic Co-authored-by: Amaury Martiny --- client/keys/show_test.go | 2 +- crypto/armor_test.go | 2 +- crypto/codec/amino.go | 2 +- crypto/hd/algo.go | 3 +- crypto/hd/fundraiser_test.go | 2 +- crypto/keyring/keyring_test.go | 2 +- crypto/keyring/output_test.go | 2 +- crypto/keyring/types_test.go | 2 +- crypto/keys/ed25519/bench_test.go | 27 --- crypto/keys/ed25519/ed25519.go | 163 ------------------ crypto/keys/ed25519/ed25519_test.go | 30 ---- crypto/keys/secp256k1/secp256k1.go | 2 + crypto/keys/secp256k1/secp256k1_cgo.go | 2 +- crypto/keys/secp256k1/secp256k1_test.go | 3 +- crypto/keys/sr25519/bench_test.go | 27 --- crypto/keys/sr25519/encoding.go | 13 -- crypto/keys/sr25519/privkey.go | 110 ------------ crypto/keys/sr25519/pubkey.go | 77 --------- crypto/keys/sr25519/sr25519_test.go | 31 ---- crypto/ledger/ledger_mock.go | 6 +- crypto/ledger/ledger_secp256k1.go | 6 +- crypto/types/multisig/codec.go | 4 +- .../types/multisig/threshold_pubkey_test.go | 9 +- go.sum | 1 + simapp/genesis_account_test.go | 2 +- simapp/state.go | 2 +- std/pubkey.go | 10 +- std/pubkey_test.go | 5 +- tests/mocks/account_retriever.go | 65 +++++++ tests/mocks/types_module_module.go | 3 +- testutil/testdata/test_tx.go | 2 +- types/address_bench_test.go | 3 +- types/address_test.go | 5 +- types/context_test.go | 2 +- types/rest/rest_test.go | 2 +- types/simulation/account.go | 2 +- x/auth/ante/ante_test.go | 2 +- x/auth/ante/sigverify.go | 8 +- x/auth/ante/sigverify_test.go | 11 +- x/auth/client/tx_test.go | 3 +- x/auth/signing/handler_map_test.go | 3 +- x/auth/types/account_test.go | 2 +- x/auth/types/amino_signing_test.go | 2 +- x/auth/vesting/types/test_common.go | 2 +- x/auth/vesting/types/vesting_account_test.go | 2 +- x/bank/app_test.go | 2 +- x/distribution/client/cli/tx_test.go | 2 +- x/distribution/legacy/v0_36/migrate_test.go | 3 +- x/evidence/types/msgs_test.go | 3 +- x/genaccounts/legacy/v0_36/migrate_test.go | 2 +- x/genutil/gentx_test.go | 4 +- x/ibc/07-tendermint/types/msgs_test.go | 2 +- x/ibc/testing/chain.go | 2 +- x/slashing/app_test.go | 2 +- x/staking/client/cli/cli_test.go | 1 - x/staking/common_test.go | 2 +- x/staking/handler_test.go | 2 +- x/staking/types/validator.go | 8 +- x/staking/types/validator_test.go | 7 +- 59 files changed, 145 insertions(+), 563 deletions(-) delete mode 100644 crypto/keys/ed25519/bench_test.go delete mode 100644 crypto/keys/ed25519/ed25519.go delete mode 100644 crypto/keys/ed25519/ed25519_test.go delete mode 100644 crypto/keys/sr25519/bench_test.go delete mode 100644 crypto/keys/sr25519/encoding.go delete mode 100644 crypto/keys/sr25519/privkey.go delete mode 100644 crypto/keys/sr25519/pubkey.go delete mode 100644 crypto/keys/sr25519/sr25519_test.go create mode 100644 tests/mocks/account_retriever.go diff --git a/client/keys/show_test.go b/client/keys/show_test.go index dc102c9728..a186442079 100644 --- a/client/keys/show_test.go +++ b/client/keys/show_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" "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/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/crypto/armor_test.go b/crypto/armor_test.go index 120b88e045..3e5f256faa 100644 --- a/crypto/armor_test.go +++ b/crypto/armor_test.go @@ -11,7 +11,6 @@ import ( "github.com/tendermint/crypto/bcrypt" tmcrypto "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/armor" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/xsalsa20symmetric" "github.com/cosmos/cosmos-sdk/codec/legacy" @@ -19,6 +18,7 @@ import ( cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/types" ) diff --git a/crypto/codec/amino.go b/crypto/codec/amino.go index b5a7c0e86f..027a831e49 100644 --- a/crypto/codec/amino.go +++ b/crypto/codec/amino.go @@ -3,10 +3,10 @@ package codec import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/sr25519" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" ) diff --git a/crypto/hd/algo.go b/crypto/hd/algo.go index 9a32835d05..d88b88e4ab 100644 --- a/crypto/hd/algo.go +++ b/crypto/hd/algo.go @@ -3,7 +3,8 @@ package hd import ( bip39 "github.com/cosmos/go-bip39" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" ) // PubKeyType defines an algorithm to derive key-pairs which can be used for cryptographic signing. diff --git a/crypto/hd/fundraiser_test.go b/crypto/hd/fundraiser_test.go index 255a2696b9..2bc396721c 100644 --- a/crypto/hd/fundraiser_test.go +++ b/crypto/hd/fundraiser_test.go @@ -12,9 +12,9 @@ import ( bip39 "github.com/cosmos/go-bip39" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" ) type addrData struct { diff --git a/crypto/keyring/keyring_test.go b/crypto/keyring/keyring_test.go index 918eb5e5e0..e586fe38a0 100644 --- a/crypto/keyring/keyring_test.go +++ b/crypto/keyring/keyring_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/require" tmcrypto "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/crypto" "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/crypto/keyring/output_test.go b/crypto/keyring/output_test.go index 150a546b58..dd92a0e1d0 100644 --- a/crypto/keyring/output_test.go +++ b/crypto/keyring/output_test.go @@ -5,8 +5,8 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/crypto/keyring/types_test.go b/crypto/keyring/types_test.go index 50981d177b..18e818c0d1 100644 --- a/crypto/keyring/types_test.go +++ b/crypto/keyring/types_test.go @@ -5,9 +5,9 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/crypto/keys/ed25519/bench_test.go b/crypto/keys/ed25519/bench_test.go deleted file mode 100644 index d3961c4247..0000000000 --- a/crypto/keys/ed25519/bench_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package ed25519 - -import ( - "io" - "testing" - - "github.com/tendermint/tendermint/crypto" - - "github.com/cosmos/cosmos-sdk/crypto/keys/internal/benchmarking" -) - -func BenchmarkKeyGeneration(b *testing.B) { - benchmarkKeygenWrapper := func(reader io.Reader) crypto.PrivKey { - return genPrivKey(reader) - } - benchmarking.BenchmarkKeyGeneration(b, benchmarkKeygenWrapper) -} - -func BenchmarkSigning(b *testing.B) { - priv := GenPrivKey() - benchmarking.BenchmarkSigning(b, priv) -} - -func BenchmarkVerification(b *testing.B) { - priv := GenPrivKey() - benchmarking.BenchmarkVerification(b, priv) -} diff --git a/crypto/keys/ed25519/ed25519.go b/crypto/keys/ed25519/ed25519.go deleted file mode 100644 index 73574c0169..0000000000 --- a/crypto/keys/ed25519/ed25519.go +++ /dev/null @@ -1,163 +0,0 @@ -package ed25519 - -import ( - "bytes" - "crypto/subtle" - "fmt" - "io" - - "golang.org/x/crypto/ed25519" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/tmhash" -) - -//------------------------------------- - -var _ crypto.PrivKey = PrivKey{} - -const ( - // PubKeySize is is the size, in bytes, of public keys as used in this package. - PubKeySize = 32 - // PrivateKeySize is the size, in bytes, of private keys as used in this package. - PrivateKeySize = 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" -) - -// PrivKey implements crypto.PrivKey. -type PrivKey []byte - -// Bytes returns the privkey byte format. -func (privKey PrivKey) Bytes() []byte { - return []byte(privKey) -} - -// 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) { - signatureBytes := ed25519.Sign(ed25519.PrivateKey(privKey), msg) - return signatureBytes, 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[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[32:]) - return PubKey(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 otherEd, ok := other.(PrivKey); ok { - return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1 - } - - return false -} - -func (privKey PrivKey) Type() string { - return keyType -} - -// 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(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(ed25519.NewKeyFromSeed(seed)) -} - -//------------------------------------- - -var _ crypto.PubKey = PubKey{} - -// PubKeyEd25519 implements crypto.PubKey for the Ed25519 signature scheme. -type PubKey []byte - -// Address is the SHA256-20 of the raw pubkey bytes. -func (pubKey PubKey) Address() crypto.Address { - if len(pubKey) != PubKeySize { - panic("pubkey is incorrect size") - } - return crypto.Address(tmhash.SumTruncated(pubKey)) -} - -// Bytes returns the PubKey byte format. -func (pubKey PubKey) Bytes() []byte { - return []byte(pubKey) -} - -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), msg, sig) -} - -func (pubKey PubKey) String() string { - return fmt.Sprintf("PubKeyEd25519{%X}", []byte(pubKey)) -} - -func (pubKey PubKey) Type() string { - return keyType -} - -func (pubKey PubKey) Equals(other crypto.PubKey) bool { - if otherEd, ok := other.(PubKey); ok { - return bytes.Equal(pubKey[:], otherEd[:]) - } - - return false -} diff --git a/crypto/keys/ed25519/ed25519_test.go b/crypto/keys/ed25519/ed25519_test.go deleted file mode 100644 index 8c48847c07..0000000000 --- a/crypto/keys/ed25519/ed25519_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package ed25519_test - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/ed25519" -) - -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)) -} diff --git a/crypto/keys/secp256k1/secp256k1.go b/crypto/keys/secp256k1/secp256k1.go index 68a5239463..2ff2685b3a 100644 --- a/crypto/keys/secp256k1/secp256k1.go +++ b/crypto/keys/secp256k1/secp256k1.go @@ -19,6 +19,8 @@ var _ crypto.PrivKey = PrivKey{} const ( PrivKeySize = 32 keyType = "secp256k1" + PrivKeyName = "tendermint/PrivKeySecp256k1" + PubKeyName = "tendermint/PubKeySecp256k1" ) // PrivKey implements PrivKey. diff --git a/crypto/keys/secp256k1/secp256k1_cgo.go b/crypto/keys/secp256k1/secp256k1_cgo.go index e44899fb5d..59ba3f14dd 100644 --- a/crypto/keys/secp256k1/secp256k1_cgo.go +++ b/crypto/keys/secp256k1/secp256k1_cgo.go @@ -3,8 +3,8 @@ package secp256k1 import ( + "github.com/cosmos/cosmos-sdk/crypto/secp256k1/internal/secp256k1" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1/internal/secp256k1" ) // Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg. diff --git a/crypto/keys/secp256k1/secp256k1_test.go b/crypto/keys/secp256k1/secp256k1_test.go index 869773a198..8f7b9bc4e9 100644 --- a/crypto/keys/secp256k1/secp256k1_test.go +++ b/crypto/keys/secp256k1/secp256k1_test.go @@ -10,9 +10,10 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" underlyingSecp256k1 "github.com/btcsuite/btcd/btcec" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" ) type keyData struct { diff --git a/crypto/keys/sr25519/bench_test.go b/crypto/keys/sr25519/bench_test.go deleted file mode 100644 index 8f9207a2a9..0000000000 --- a/crypto/keys/sr25519/bench_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package sr25519 - -import ( - "io" - "testing" - - "github.com/tendermint/tendermint/crypto" - - "github.com/cosmos/cosmos-sdk/crypto/keys/internal/benchmarking" -) - -func BenchmarkKeyGeneration(b *testing.B) { - benchmarkKeygenWrapper := func(reader io.Reader) crypto.PrivKey { - return genPrivKey(reader) - } - benchmarking.BenchmarkKeyGeneration(b, benchmarkKeygenWrapper) -} - -func BenchmarkSigning(b *testing.B) { - priv := GenPrivKey() - benchmarking.BenchmarkSigning(b, priv) -} - -func BenchmarkVerification(b *testing.B) { - priv := GenPrivKey() - benchmarking.BenchmarkVerification(b, priv) -} diff --git a/crypto/keys/sr25519/encoding.go b/crypto/keys/sr25519/encoding.go deleted file mode 100644 index 58debb7d2b..0000000000 --- a/crypto/keys/sr25519/encoding.go +++ /dev/null @@ -1,13 +0,0 @@ -package sr25519 - -import ( - "github.com/tendermint/tendermint/crypto" -) - -var _ crypto.PrivKey = PrivKey{} - -const ( - // SignatureSize is the size of an Edwards25519 signature. Namely the size of a compressed - // Sr25519 point, and a field element. Both of which are 32 bytes. - SignatureSize = 64 -) diff --git a/crypto/keys/sr25519/privkey.go b/crypto/keys/sr25519/privkey.go deleted file mode 100644 index e77ca375ce..0000000000 --- a/crypto/keys/sr25519/privkey.go +++ /dev/null @@ -1,110 +0,0 @@ -package sr25519 - -import ( - "crypto/subtle" - "fmt" - "io" - - "github.com/tendermint/tendermint/crypto" - - schnorrkel "github.com/ChainSafe/go-schnorrkel" -) - -// PrivKeySize is the number of bytes in an Sr25519 private key. -const PrivKeySize = 32 - -// PrivKeySr25519 implements crypto.PrivKey. -type PrivKey []byte - -// Bytes returns the byte representation of the PrivKey. -func (privKey PrivKey) Bytes() []byte { - return []byte(privKey) -} - -// Sign produces a signature on the provided message. -func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { - var p [PrivKeySize]byte - copy(p[:], privKey) - miniSecretKey, err := schnorrkel.NewMiniSecretKeyFromRaw(p) - if err != nil { - return []byte{}, err - } - secretKey := miniSecretKey.ExpandEd25519() - - signingContext := schnorrkel.NewSigningContext([]byte{}, msg) - - sig, err := secretKey.Sign(signingContext) - if err != nil { - return []byte{}, err - } - - sigBytes := sig.Encode() - return sigBytes[:], nil -} - -// PubKey gets the corresponding public key from the private key. -func (privKey PrivKey) PubKey() crypto.PubKey { - var p [PrivKeySize]byte - copy(p[:], privKey) - miniSecretKey, err := schnorrkel.NewMiniSecretKeyFromRaw(p) - if err != nil { - panic(fmt.Sprintf("Invalid private key: %v", err)) - } - secretKey := miniSecretKey.ExpandEd25519() - - pubkey, err := secretKey.Public() - if err != nil { - panic(fmt.Sprintf("Could not generate public key: %v", err)) - } - key := pubkey.Encode() - return PubKey(key[:]) -} - -// 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 otherEd, ok := other.(PrivKey); ok { - return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1 - } - return false -} - -func (privKey PrivKey) Type() string { - return keyType -} - -// GenPrivKey generates a new sr25519 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 sr25519 private key using the provided reader. -func genPrivKey(rand io.Reader) PrivKey { - var seed [64]byte - - out := make([]byte, 64) - _, err := io.ReadFull(rand, out) - if err != nil { - panic(err) - } - - copy(seed[:], out) - - key := schnorrkel.NewMiniSecretKey(seed).ExpandEd25519().Encode() - return key[:] -} - -// 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. - var bz [PrivKeySize]byte - copy(bz[:], seed) - privKey, _ := schnorrkel.NewMiniSecretKeyFromRaw(bz) - key := privKey.ExpandEd25519().Encode() - return key[:] -} diff --git a/crypto/keys/sr25519/pubkey.go b/crypto/keys/sr25519/pubkey.go deleted file mode 100644 index 87805cacba..0000000000 --- a/crypto/keys/sr25519/pubkey.go +++ /dev/null @@ -1,77 +0,0 @@ -package sr25519 - -import ( - "bytes" - "fmt" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/tmhash" - - schnorrkel "github.com/ChainSafe/go-schnorrkel" -) - -var _ crypto.PubKey = PubKey{} - -// PubKeySize is the number of bytes in an Sr25519 public key. -const ( - PubKeySize = 32 - keyType = "sr25519" -) - -// PubKeySr25519 implements crypto.PubKey for the Sr25519 signature scheme. -type PubKey []byte - -// Address is the SHA256-20 of the raw pubkey bytes. -func (pubKey PubKey) Address() crypto.Address { - return crypto.Address(tmhash.SumTruncated(pubKey[:])) -} - -// Bytes returns the byte representation of the PubKey. -func (pubKey PubKey) Bytes() []byte { - return []byte(pubKey) -} - -func (pubKey PubKey) VerifySignature(msg []byte, sig []byte) bool { - // make sure we use the same algorithm to sign - if len(sig) != SignatureSize { - return false - } - var sig64 [SignatureSize]byte - copy(sig64[:], sig) - - publicKey := &(schnorrkel.PublicKey{}) - var p [PubKeySize]byte - copy(p[:], pubKey) - err := publicKey.Decode(p) - if err != nil { - return false - } - - signingContext := schnorrkel.NewSigningContext([]byte{}, msg) - - signature := &(schnorrkel.Signature{}) - err = signature.Decode(sig64) - if err != nil { - return false - } - - return publicKey.Verify(signature, signingContext) -} - -func (pubKey PubKey) String() string { - return fmt.Sprintf("PubKeySr25519{%X}", []byte(pubKey)) -} - -// Equals - checks that two public keys are the same time -// Runs in constant time based on length of the keys. -func (pubKey PubKey) Equals(other crypto.PubKey) bool { - if otherEd, ok := other.(PubKey); ok { - return bytes.Equal(pubKey[:], otherEd[:]) - } - return false -} - -func (pubKey PubKey) Type() string { - return keyType - -} diff --git a/crypto/keys/sr25519/sr25519_test.go b/crypto/keys/sr25519/sr25519_test.go deleted file mode 100644 index 1efe31cad8..0000000000 --- a/crypto/keys/sr25519/sr25519_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package sr25519_test - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/sr25519" -) - -func TestSignAndValidateSr25519(t *testing.T) { - - privKey := sr25519.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)) - 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)) -} diff --git a/crypto/ledger/ledger_mock.go b/crypto/ledger/ledger_mock.go index cb75a00884..45efc5c301 100644 --- a/crypto/ledger/ledger_mock.go +++ b/crypto/ledger/ledger_mock.go @@ -10,11 +10,11 @@ import ( secp256k1 "github.com/tendermint/btcd/btcec" "github.com/tendermint/tendermint/crypto" - tmsecp256k1 "github.com/tendermint/tendermint/crypto/secp256k1" - bip39 "github.com/cosmos/go-bip39" + "github.com/cosmos/go-bip39" "github.com/cosmos/cosmos-sdk/crypto/hd" + csecp256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -77,7 +77,7 @@ func (mock LedgerSECP256K1Mock) GetAddressPubKeySECP256K1(derivationPath []uint3 return nil, "", fmt.Errorf("error parsing public key: %v", err) } - compressedPublicKey := make(tmsecp256k1.PubKey, tmsecp256k1.PubKeySize) + compressedPublicKey := make(csecp256k1.PubKey, csecp256k1.PubKeySize) copy(compressedPublicKey, cmp.SerializeCompressed()) // Generate the bech32 addr using existing tmcrypto/etc. diff --git a/crypto/ledger/ledger_secp256k1.go b/crypto/ledger/ledger_secp256k1.go index 6ad8c7ff43..0884e36eb4 100644 --- a/crypto/ledger/ledger_secp256k1.go +++ b/crypto/ledger/ledger_secp256k1.go @@ -9,9 +9,9 @@ import ( tmbtcec "github.com/tendermint/btcd/btcec" tmcrypto "github.com/tendermint/tendermint/crypto" - tmsecp256k1 "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" ) var ( @@ -246,7 +246,7 @@ func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (tmcrypto.PubKey, er return nil, fmt.Errorf("error parsing public key: %v", err) } - compressedPublicKey := make(tmsecp256k1.PubKey, tmsecp256k1.PubKeySize) + compressedPublicKey := make(secp256k1.PubKey, secp256k1.PubKeySize) copy(compressedPublicKey, cmp.SerializeCompressed()) return compressedPublicKey, nil @@ -270,7 +270,7 @@ func getPubKeyAddrSafe(device SECP256K1, path hd.BIP44Params, hrp string) (tmcry return nil, "", fmt.Errorf("error parsing public key: %v", err) } - compressedPublicKey := make(tmsecp256k1.PubKey, tmsecp256k1.PubKeySize) + compressedPublicKey := make(secp256k1.PubKey, secp256k1.PubKeySize) copy(compressedPublicKey, cmp.SerializeCompressed()) return compressedPublicKey, addr, nil diff --git a/crypto/types/multisig/codec.go b/crypto/types/multisig/codec.go index a18c6968a7..54bd0f225a 100644 --- a/crypto/types/multisig/codec.go +++ b/crypto/types/multisig/codec.go @@ -2,11 +2,11 @@ package multisig import ( amino "github.com/tendermint/go-amino" - "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/sr25519" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" ) // TODO: Figure out API for others to either add their own pubkey types, or diff --git a/crypto/types/multisig/threshold_pubkey_test.go b/crypto/types/multisig/threshold_pubkey_test.go index cb40646032..2396e09ad5 100644 --- a/crypto/types/multisig/threshold_pubkey_test.go +++ b/crypto/types/multisig/threshold_pubkey_test.go @@ -5,17 +5,16 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto" + "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/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" "github.com/cosmos/cosmos-sdk/types/tx/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" - "github.com/tendermint/tendermint/crypto/sr25519" ) // This tests multisig functionality, but it expects the first k signatures to be valid diff --git a/go.sum b/go.sum index 5362e53fd2..fcab033538 100644 --- a/go.sum +++ b/go.sum @@ -745,6 +745,7 @@ 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= diff --git a/simapp/genesis_account_test.go b/simapp/genesis_account_test.go index 385bb7b217..5d5c59003e 100644 --- a/simapp/genesis_account_test.go +++ b/simapp/genesis_account_test.go @@ -4,13 +4,13 @@ import ( "testing" "time" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" ) func TestSimGenesisAccountValidate(t *testing.T) { diff --git a/simapp/state.go b/simapp/state.go index 921aac5906..62a19e7f64 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -8,11 +8,11 @@ import ( "math/rand" "time" - "github.com/tendermint/tendermint/crypto/secp256k1" tmjson "github.com/tendermint/tendermint/libs/json" tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" simapparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" diff --git a/std/pubkey.go b/std/pubkey.go index 4caf3ba2ac..72f71933af 100644 --- a/std/pubkey.go +++ b/std/pubkey.go @@ -4,10 +4,10 @@ import ( "fmt" "github.com/tendermint/tendermint/crypto" - ed255192 "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/sr25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" ) @@ -39,11 +39,11 @@ func (cdc DefaultPublicKeyCodec) Decode(key *types.PublicKey) (crypto.PubKey, er return res, nil case *types.PublicKey_Ed25519: n := len(key.Ed25519) - if n != ed255192.PubKeySize { + if n != ed25519.PubKeySize { return nil, fmt.Errorf("wrong length %d for ed25519 public key", n) } - res := make(ed255192.PubKey, ed255192.PubKeySize) + res := make(ed25519.PubKey, ed25519.PubKeySize) copy(res, key.Ed25519) return res, nil case *types.PublicKey_Sr25519: @@ -81,7 +81,7 @@ func (cdc DefaultPublicKeyCodec) Encode(key crypto.PubKey) (*types.PublicKey, er switch key := key.(type) { case secp256k1.PubKey: return &types.PublicKey{Sum: &types.PublicKey_Secp256K1{Secp256K1: key}}, nil - case ed255192.PubKey: + case ed25519.PubKey: return &types.PublicKey{Sum: &types.PublicKey_Ed25519{Ed25519: key}}, nil case sr25519.PubKey: return &types.PublicKey{Sum: &types.PublicKey_Sr25519{Sr25519: key}}, nil diff --git a/std/pubkey_test.go b/std/pubkey_test.go index 484a5d8990..302ba22387 100644 --- a/std/pubkey_test.go +++ b/std/pubkey_test.go @@ -3,15 +3,14 @@ package std_test import ( "testing" - "github.com/cosmos/cosmos-sdk/std" - "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/sr25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" + "github.com/cosmos/cosmos-sdk/std" ) func roundTripTest(t *testing.T, pubKey crypto.PubKey) { diff --git a/tests/mocks/account_retriever.go b/tests/mocks/account_retriever.go new file mode 100644 index 0000000000..f571fcbd15 --- /dev/null +++ b/tests/mocks/account_retriever.go @@ -0,0 +1,65 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: client/account_retriever.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + client "github.com/cosmos/cosmos-sdk/client" + types "github.com/cosmos/cosmos-sdk/types" + gomock "github.com/golang/mock/gomock" + reflect "reflect" +) + +// MockAccountRetriever is a mock of AccountRetriever interface +type MockAccountRetriever struct { + ctrl *gomock.Controller + recorder *MockAccountRetrieverMockRecorder +} + +// MockAccountRetrieverMockRecorder is the mock recorder for MockAccountRetriever +type MockAccountRetrieverMockRecorder struct { + mock *MockAccountRetriever +} + +// NewMockAccountRetriever creates a new mock instance +func NewMockAccountRetriever(ctrl *gomock.Controller) *MockAccountRetriever { + mock := &MockAccountRetriever{ctrl: ctrl} + mock.recorder = &MockAccountRetrieverMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockAccountRetriever) EXPECT() *MockAccountRetrieverMockRecorder { + return m.recorder +} + +// EnsureExists mocks base method +func (m *MockAccountRetriever) EnsureExists(clientCtx client.Context, addr types.AccAddress) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "EnsureExists", clientCtx, addr) + ret0, _ := ret[0].(error) + return ret0 +} + +// EnsureExists indicates an expected call of EnsureExists +func (mr *MockAccountRetrieverMockRecorder) EnsureExists(clientCtx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EnsureExists", reflect.TypeOf((*MockAccountRetriever)(nil).EnsureExists), clientCtx, addr) +} + +// GetAccountNumberSequence mocks base method +func (m *MockAccountRetriever) GetAccountNumberSequence(clientCtx client.Context, addr types.AccAddress) (uint64, uint64, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAccountNumberSequence", clientCtx, addr) + ret0, _ := ret[0].(uint64) + ret1, _ := ret[1].(uint64) + ret2, _ := ret[2].(error) + return ret0, ret1, ret2 +} + +// GetAccountNumberSequence indicates an expected call of GetAccountNumberSequence +func (mr *MockAccountRetrieverMockRecorder) GetAccountNumberSequence(clientCtx, addr interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountNumberSequence", reflect.TypeOf((*MockAccountRetriever)(nil).GetAccountNumberSequence), clientCtx, addr) +} diff --git a/tests/mocks/types_module_module.go b/tests/mocks/types_module_module.go index d674a8ba33..81221aef03 100644 --- a/tests/mocks/types_module_module.go +++ b/tests/mocks/types_module_module.go @@ -6,8 +6,6 @@ package mocks import ( json "encoding/json" - reflect "reflect" - client "github.com/cosmos/cosmos-sdk/client" codec "github.com/cosmos/cosmos-sdk/codec" types "github.com/cosmos/cosmos-sdk/codec/types" @@ -18,6 +16,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" cobra "github.com/spf13/cobra" types1 "github.com/tendermint/tendermint/abci/types" + reflect "reflect" ) // MockAppModuleBasic is a mock of AppModuleBasic interface diff --git a/testutil/testdata/test_tx.go b/testutil/testdata/test_tx.go index 92972fe417..bbcfde5f81 100644 --- a/testutil/testdata/test_tx.go +++ b/testutil/testdata/test_tx.go @@ -4,8 +4,8 @@ import ( "encoding/json" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/types/address_bench_test.go b/types/address_bench_test.go index 640d180411..d9c1aa7325 100644 --- a/types/address_bench_test.go +++ b/types/address_bench_test.go @@ -6,10 +6,9 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tendermint/tendermint/crypto/ed25519" "github.com/cosmos/cosmos-sdk/types" - - "github.com/tendermint/tendermint/crypto/ed25519" ) func BenchmarkBech32ifyPubKey(b *testing.B) { diff --git a/types/address_test.go b/types/address_test.go index 0b2701dcae..67e3add6c0 100644 --- a/types/address_test.go +++ b/types/address_test.go @@ -10,11 +10,10 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/ed25519" yaml "gopkg.in/yaml.v2" - "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" - + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/types" ) diff --git a/types/context_test.go b/types/context_test.go index 0698199a0a..64e4141659 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/store" "github.com/cosmos/cosmos-sdk/types" ) diff --git a/types/rest/rest_test.go b/types/rest/rest_test.go index 5116593ca9..b6ff87be5c 100644 --- a/types/rest/rest_test.go +++ b/types/rest/rest_test.go @@ -13,12 +13,12 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" diff --git a/types/simulation/account.go b/types/simulation/account.go index 2078cddc2d..2f45ad43d6 100644 --- a/types/simulation/account.go +++ b/types/simulation/account.go @@ -5,8 +5,8 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 698cb62e91..84602abcb9 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -10,8 +10,8 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index 16c3c07151..fc783c6b85 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -5,16 +5,14 @@ import ( "encoding/hex" "fmt" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - - "github.com/cosmos/cosmos-sdk/types/tx/signing" - "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx/signing" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/auth/types" ) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index 93b794b565..d757f720cf 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -3,18 +3,15 @@ package ante_test import ( "fmt" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - - "github.com/cosmos/cosmos-sdk/types/tx/signing" - - "github.com/cosmos/cosmos-sdk/simapp" - "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" + "github.com/cosmos/cosmos-sdk/simapp" + "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/types" ) diff --git a/x/auth/client/tx_test.go b/x/auth/client/tx_test.go index 1a5847d424..3483f17f4a 100644 --- a/x/auth/client/tx_test.go +++ b/x/auth/client/tx_test.go @@ -5,6 +5,8 @@ import ( "strings" "testing" + "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" @@ -13,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "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" diff --git a/x/auth/signing/handler_map_test.go b/x/auth/signing/handler_map_test.go index 3d28117581..35a2f022d4 100644 --- a/x/auth/signing/handler_map_test.go +++ b/x/auth/signing/handler_map_test.go @@ -5,8 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/secp256k1" - + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth/signing" diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 3d30b6b45c..033b1c3ef9 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/secp256k1" yaml "gopkg.in/yaml.v2" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" diff --git a/x/auth/types/amino_signing_test.go b/x/auth/types/amino_signing_test.go index a321ddfa3d..a436f0b221 100644 --- a/x/auth/types/amino_signing_test.go +++ b/x/auth/types/amino_signing_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" diff --git a/x/auth/vesting/types/test_common.go b/x/auth/vesting/types/test_common.go index 948e506b3c..347faba046 100644 --- a/x/auth/vesting/types/test_common.go +++ b/x/auth/vesting/types/test_common.go @@ -2,8 +2,8 @@ package types import ( "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index eb6e13412b..01a5e2ad98 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -5,9 +5,9 @@ import ( "time" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/secp256k1" tmtime "github.com/tendermint/tendermint/types/time" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" diff --git a/x/bank/app_test.go b/x/bank/app_test.go index c554d53574..4f0822398d 100644 --- a/x/bank/app_test.go +++ b/x/bank/app_test.go @@ -5,9 +5,9 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" diff --git a/x/distribution/client/cli/tx_test.go b/x/distribution/client/cli/tx_test.go index bc40c15105..3ab4808ecd 100644 --- a/x/distribution/client/cli/tx_test.go +++ b/x/distribution/client/cli/tx_test.go @@ -5,13 +5,13 @@ import ( "github.com/spf13/pflag" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/stretchr/testify/require" "github.com/stretchr/testify/assert" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" diff --git a/x/distribution/legacy/v0_36/migrate_test.go b/x/distribution/legacy/v0_36/migrate_test.go index 1aadbe29a4..fcffc7fe9a 100644 --- a/x/distribution/legacy/v0_36/migrate_test.go +++ b/x/distribution/legacy/v0_36/migrate_test.go @@ -3,8 +3,7 @@ package v0_36 import ( "testing" - "github.com/tendermint/tendermint/crypto/secp256k1" - + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/types" v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34" diff --git a/x/evidence/types/msgs_test.go b/x/evidence/types/msgs_test.go index 6c1297ea64..5947065a72 100644 --- a/x/evidence/types/msgs_test.go +++ b/x/evidence/types/msgs_test.go @@ -4,12 +4,13 @@ import ( "testing" "time" + "github.com/tendermint/tendermint/crypto/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" - "github.com/tendermint/tendermint/crypto/ed25519" ) func testMsgSubmitEvidence(t *testing.T, e exported.Evidence, s sdk.AccAddress) exported.MsgSubmitEvidence { diff --git a/x/genaccounts/legacy/v0_36/migrate_test.go b/x/genaccounts/legacy/v0_36/migrate_test.go index 250dd85474..7fbd9f66a4 100644 --- a/x/genaccounts/legacy/v0_36/migrate_test.go +++ b/x/genaccounts/legacy/v0_36/migrate_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/types" v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34" v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_34" diff --git a/x/genutil/gentx_test.go b/x/genutil/gentx_test.go index 2f690c0ee9..c88d33fef9 100644 --- a/x/genutil/gentx_test.go +++ b/x/genutil/gentx_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/crypto/secp256k1" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp/helpers" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" @@ -16,7 +16,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil/types" - staking "github.com/cosmos/cosmos-sdk/x/staking" + "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) diff --git a/x/ibc/07-tendermint/types/msgs_test.go b/x/ibc/07-tendermint/types/msgs_test.go index 0cab73d337..6cfc111b53 100644 --- a/x/ibc/07-tendermint/types/msgs_test.go +++ b/x/ibc/07-tendermint/types/msgs_test.go @@ -2,9 +2,9 @@ package types_test import ( ics23 "github.com/confio/ics23/go" - "github.com/tendermint/tendermint/crypto/secp256k1" tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" types "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types" diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 29b6db995e..e14a2dc2f4 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/tmhash" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/proto/tendermint/version" @@ -17,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 9310d912e0..bfe8c8b45b 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -7,9 +7,9 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" diff --git a/x/staking/client/cli/cli_test.go b/x/staking/client/cli/cli_test.go index ea809ee036..0981df3b4f 100644 --- a/x/staking/client/cli/cli_test.go +++ b/x/staking/client/cli/cli_test.go @@ -6,7 +6,6 @@ import ( "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/suite" - "github.com/tendermint/tendermint/crypto/ed25519" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/x/staking/common_test.go b/x/staking/common_test.go index f029e4eac8..52dd0ec6c8 100644 --- a/x/staking/common_test.go +++ b/x/staking/common_test.go @@ -3,10 +3,10 @@ package staking_test import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/tendermint/tendermint/crypto/secp256k1" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking/keeper" diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 2e9f6f51ae..481484ad92 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -9,10 +9,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/crypto/secp256k1" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/staking/types/validator.go b/x/staking/types/validator.go index ef7af32a42..7328bfbc80 100644 --- a/x/staking/types/validator.go +++ b/x/staking/types/validator.go @@ -9,9 +9,9 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" - cryptoenc "github.com/tendermint/tendermint/crypto/encoding" + "github.com/tendermint/tendermint/crypto/encoding" tmtypes "github.com/tendermint/tendermint/types" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -224,7 +224,7 @@ func (d Description) EnsureLength() (Description, error) { // ABCIValidatorUpdate returns an abci.ValidatorUpdate from a staking validator type // with the full validator power func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate { - pk, err := cryptoenc.PubKeyToProto(v.GetConsPubKey()) + pk, err := encoding.PubKeyToProto(v.GetConsPubKey()) if err != nil { panic(err) } @@ -238,7 +238,7 @@ func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate { // ABCIValidatorUpdateZero returns an abci.ValidatorUpdate from a staking validator type // with zero power used for validator updates. func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate { - pk, err := cryptoenc.PubKeyToProto(v.GetConsPubKey()) + pk, err := encoding.PubKeyToProto(v.GetConsPubKey()) if err != nil { panic(err) } diff --git a/x/staking/types/validator_test.go b/x/staking/types/validator_test.go index c4714c1f53..beb6c22ffd 100644 --- a/x/staking/types/validator_test.go +++ b/x/staking/types/validator_test.go @@ -9,11 +9,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" - cryptoenc "github.com/tendermint/tendermint/crypto/encoding" + tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/crypto/encoding" ) func TestValidatorTestEquivalent(t *testing.T) { @@ -62,7 +63,7 @@ func TestABCIValidatorUpdate(t *testing.T) { validator := NewValidator(valAddr1, pk1, Description{}) abciVal := validator.ABCIValidatorUpdate() - pk, err := cryptoenc.PubKeyToProto(validator.GetConsPubKey()) + pk, err := encoding.PubKeyToProto(validator.GetConsPubKey()) require.NoError(t, err) require.Equal(t, pk, abciVal.PubKey) require.Equal(t, validator.BondedTokens().Int64(), abciVal.Power) @@ -72,7 +73,7 @@ func TestABCIValidatorUpdateZero(t *testing.T) { validator := NewValidator(valAddr1, pk1, Description{}) abciVal := validator.ABCIValidatorUpdateZero() - pk, err := cryptoenc.PubKeyToProto(validator.GetConsPubKey()) + pk, err := encoding.PubKeyToProto(validator.GetConsPubKey()) require.NoError(t, err) require.Equal(t, pk, abciVal.PubKey) require.Equal(t, int64(0), abciVal.Power)