Merge branch 'master' into adr_gov_split_vote

This commit is contained in:
Sunny Aggarwal 2020-11-11 13:35:22 -04:00 committed by GitHub
commit c1557a2b90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
274 changed files with 6545 additions and 5030 deletions

View File

@ -30,7 +30,7 @@ jobs:
- name: install runsim
run: |
export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/runsim@v1.0.0
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
@ -40,7 +40,7 @@ jobs:
needs: [build, install-runsim]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary

View File

@ -39,7 +39,7 @@ jobs:
run: go version
- name: Install runsim
run: export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/runsim@v1.0.0
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
@ -60,7 +60,7 @@ jobs:
**/**.go
go.mod
go.sum
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
@ -88,7 +88,7 @@ jobs:
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
@ -116,7 +116,7 @@ jobs:
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
@ -144,7 +144,7 @@ jobs:
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary

View File

@ -26,7 +26,7 @@ jobs:
- name: install tparse
run: |
export GO111MODULE="on" && go get github.com/mfridman/tparse@v0.8.3
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tparse-binary
@ -216,7 +216,7 @@ jobs:
with:
name: "${{ github.sha }}-03-race-output"
if: env.GIT_DIFF
- uses: actions/cache@v2.1.2
- uses: actions/cache@v2.1.3
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tparse-binary

View File

@ -36,6 +36,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
## [v0.40.0-rc3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.40.0-rc3) - 2020-11-06
### Client Breaking
* (x/staking) [\#7419](https://github.com/cosmos/cosmos-sdk/pull/7419) The `TmConsPubKey` method on ValidatorI has been removed and replaced instead by `ConsPubKey` (which returns a SDK `cryptotypes.PubKey`) and `TmConsPublicKey` (which returns a Tendermint proto PublicKey).
### Improvements
* (tendermint) [\#7828](https://github.com/cosmos/cosmos-sdk/pull/7828) Update tendermint dependency to v0.34.0-rc6

View File

@ -1,15 +1,14 @@
package client
import (
"github.com/tendermint/tendermint/crypto"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Account defines a read-only version of the auth module's AccountI.
type Account interface {
GetAddress() sdk.AccAddress
GetPubKey() crypto.PubKey // can return nil.
GetPubKey() cryptotypes.PubKey // can return nil.
GetAccountNumber() uint64
GetSequence() uint64
}

View File

@ -8,10 +8,10 @@ import (
"strings"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/version"
@ -34,7 +34,7 @@ func Cmd() *cobra.Command {
// getPubKeyFromString returns a Tendermint PubKey (PubKeyEd25519) by attempting
// 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) {
func getPubKeyFromString(pkstr string) (cryptotypes.PubKey, error) {
bz, err := hex.DecodeString(pkstr)
if err == nil {
if len(bz) == ed25519.PubKeySize {

View File

@ -15760,7 +15760,7 @@ paths:
}
tags:
- Query
/ibc/channel/v1beta1/channels:
/ibc/core/channel/v1beta1/channels:
get:
summary: Channels queries all the IBC channels of a chain.
operationId: Channels
@ -16146,7 +16146,7 @@ paths:
type: boolean
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}':
get:
summary: Channel queries an IBC Channel.
operationId: Channel
@ -16471,7 +16471,7 @@ paths:
type: string
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/client_state':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/client_state':
get:
summary: >-
ChannelClientState queries for the client state for the channel
@ -16909,7 +16909,7 @@ paths:
type: string
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/consensus_state/version/{version_number}/height/{version_height}':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/consensus_state/version/{version_number}/height/{version_height}':
get:
summary: |-
ChannelConsensusState queries for the consensus state for the channel
@ -17344,7 +17344,7 @@ paths:
format: uint64
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/next_sequence':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/next_sequence':
get:
summary: >-
NextSequenceReceive returns the next receive sequence for a given
@ -17596,7 +17596,7 @@ paths:
type: string
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acknowledgements':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acknowledgements':
get:
summary: >-
PacketAcknowledgements returns all the packet acknowledgements
@ -17945,7 +17945,7 @@ paths:
type: boolean
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acks/{sequence}':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acks/{sequence}':
get:
summary: PacketAcknowledgement queries a stored packet acknowledgement hash.
operationId: PacketAcknowledgement
@ -18205,7 +18205,7 @@ paths:
format: uint64
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments':
get:
summary: |-
PacketCommitments returns all the packet commitments hashes associated
@ -18552,7 +18552,7 @@ paths:
type: boolean
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{packet_ack_sequences}/unreceived_acks':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{packet_ack_sequences}/unreceived_acks':
get:
summary: >-
UnreceivedAcks returns all the unreceived IBC acknowledgements
@ -18814,7 +18814,7 @@ paths:
minItems: 1
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{packet_commitment_sequences}/unreceived_packets':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{packet_commitment_sequences}/unreceived_packets':
get:
summary: >-
UnreceivedPackets returns all the unreceived IBC packets associated with
@ -19076,7 +19076,7 @@ paths:
minItems: 1
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{sequence}':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{sequence}':
get:
summary: PacketCommitment queries a stored packet commitment hash.
operationId: PacketCommitment
@ -19337,7 +19337,7 @@ paths:
format: uint64
tags:
- Query
'/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_receipts/{sequence}':
'/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_receipts/{sequence}':
get:
summary: >-
PacketReceipt queries if a given packet sequence has been received on
@ -19599,7 +19599,7 @@ paths:
format: uint64
tags:
- Query
'/ibc/channel/v1beta1/connections/{connection}/channels':
'/ibc/core/channel/v1beta1/connections/{connection}/channels':
get:
summary: |-
ConnectionChannels queries all the channels associated with a connection
@ -19992,7 +19992,7 @@ paths:
type: boolean
tags:
- Query
/ibc/client/v1beta1/client_states:
/ibc/core/client/v1beta1/client_states:
get:
summary: ClientStates queries all the IBC light clients of a chain.
operationId: ClientStates
@ -20465,7 +20465,7 @@ paths:
type: boolean
tags:
- Query
'/ibc/client/v1beta1/client_states/{client_id}':
'/ibc/core/client/v1beta1/client_states/{client_id}':
get:
summary: ClientState queries an IBC light client.
operationId: ClientState
@ -20883,7 +20883,7 @@ paths:
type: string
tags:
- Query
'/ibc/client/v1beta1/consensus_states/{client_id}':
'/ibc/core/client/v1beta1/consensus_states/{client_id}':
get:
summary: |-
ConsensusStates queries all the consensus state associated with a given
@ -21383,7 +21383,7 @@ paths:
type: boolean
tags:
- Query
'/ibc/client/v1beta1/consensus_states/{client_id}/version/{version_number}/height/{version_height}':
'/ibc/core/client/v1beta1/consensus_states/{client_id}/version/{version_number}/height/{version_height}':
get:
summary: >-
ConsensusState queries a consensus state associated with a client state
@ -21825,7 +21825,7 @@ paths:
type: boolean
tags:
- Query
'/ibc/connection/v1beta1/client_connections/{client_id}':
'/ibc/core/connection/v1beta1/client_connections/{client_id}':
get:
summary: |-
ClientConnections queries the connection paths associated with a client
@ -22073,7 +22073,7 @@ paths:
type: string
tags:
- Query
/ibc/connection/v1beta1/connections:
/ibc/core/connection/v1beta1/connections:
get:
summary: Connections queries all the IBC connections of a chain.
operationId: Connections
@ -22457,7 +22457,7 @@ paths:
type: boolean
tags:
- Query
'/ibc/connection/v1beta1/connections/{connection_id}':
'/ibc/core/connection/v1beta1/connections/{connection_id}':
get:
summary: Connection queries an IBC connection end.
operationId: Connection
@ -22777,7 +22777,7 @@ paths:
type: string
tags:
- Query
'/ibc/connection/v1beta1/connections/{connection_id}/client_state':
'/ibc/core/connection/v1beta1/connections/{connection_id}/client_state':
get:
summary: |-
ConnectionClientState queries the client state associated with the
@ -23208,7 +23208,7 @@ paths:
type: string
tags:
- Query
'/ibc/connection/v1beta1/connections/{connection_id}/consensus_state/version/{version_number}/height/{version_height}':
'/ibc/core/connection/v1beta1/connections/{connection_id}/consensus_state/version/{version_number}/height/{version_height}':
get:
summary: |-
ConnectionConsensusState queries the consensus state associated with the
@ -23636,7 +23636,7 @@ paths:
format: uint64
tags:
- Query
/ibc_transfer/v1beta1/denom_traces:
/ibc/applications/transfer/v1beta1/denom_traces:
get:
summary: DenomTraces queries all denomination traces.
operationId: DenomTraces
@ -23761,7 +23761,7 @@ paths:
type: boolean
tags:
- Query
'/ibc_transfer/v1beta1/denom_traces/{hash}':
'/ibc/applications/transfer/v1beta1/denom_traces/{hash}':
get:
summary: DenomTrace queries a denomination trace information.
operationId: DenomTrace
@ -23822,7 +23822,7 @@ paths:
type: string
tags:
- Query
/ibc_transfer/v1beta1/params:
/ibc/applications/transfer/v1beta1/params:
get:
summary: Params queries all parameters of the ibc-transfer module.
operationId: IBCTransferParams

View File

@ -9,7 +9,6 @@ import (
bip39 "github.com/cosmos/go-bip39"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
@ -18,6 +17,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -152,7 +152,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
multisigKeys, _ := cmd.Flags().GetStringSlice(flagMultisig)
if len(multisigKeys) != 0 {
var pks []crypto.PubKey
var pks []cryptotypes.PubKey
multisigThreshold, _ := cmd.Flags().GetInt(flagMultiSigThreshold)
if err := validateMultisigThreshold(multisigThreshold, len(multisigKeys)); err != nil {
@ -247,7 +247,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
}
if len(mnemonic) == 0 {
// read entropy seed straight from crypto.Rand and convert to mnemonic
// read entropy seed straight from tmcrypto.Rand and convert to mnemonic
entropySeed, err := bip39.NewEntropy(mnemonicEntropySize)
if err != nil {
return err

View File

@ -5,13 +5,13 @@ import (
"fmt"
"github.com/spf13/cobra"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/ledger"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -61,7 +61,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
return fmt.Errorf("%s is not a valid name or address: %v", args[0], err)
}
} else {
pks := make([]tmcrypto.PubKey, len(args))
pks := make([]cryptotypes.PubKey, len(args))
for i, keyref := range args {
info, err := fetchKey(clientCtx.Keyring, keyref)
if err != nil {

View File

@ -7,14 +7,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
"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/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -23,7 +22,7 @@ func Test_multiSigKey_Properties(t *testing.T) {
tmpKey1 := secp256k1.GenPrivKeyFromSecret([]byte("mySecret"))
pk := multisig.NewLegacyAminoPubKey(
1,
[]crypto.PubKey{tmpKey1.PubKey()},
[]cryptotypes.PubKey{tmpKey1.PubKey()},
)
tmp := keyring.NewMultiInfo("myMultisig", pk)

View File

@ -14,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
)
@ -99,7 +100,11 @@ func (rvo ResultValidatorsOutput) String() string {
}
func bech32ValidatorOutput(validator *tmtypes.Validator) (ValidatorOutput, error) {
bechValPubkey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, validator.PubKey)
pk, err := cryptocodec.FromTmPubKeyInterface(validator.PubKey)
if err != nil {
return ValidatorOutput{}, err
}
bechValPubkey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk)
if err != nil {
return ValidatorOutput{}, err
}

View File

@ -3,8 +3,7 @@ package client
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -26,7 +25,7 @@ func (t TestAccount) GetAddress() sdk.AccAddress {
}
// GetPubKey implements client Account.GetPubKey
func (t TestAccount) GetPubKey() crypto.PubKey {
func (t TestAccount) GetPubKey() cryptotypes.PubKey {
return nil
}

View File

@ -8,13 +8,13 @@ import (
"os"
"github.com/spf13/pflag"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
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/types/rest"
@ -343,7 +343,7 @@ func PrepareFactory(clientCtx client.Context, txf Factory) (Factory, error) {
// corresponding SignatureV2 if the signing is successful.
func SignWithPrivKey(
signMode signing.SignMode, signerData authsigning.SignerData,
txBuilder client.TxBuilder, priv crypto.PrivKey, txConfig client.TxConfig,
txBuilder client.TxBuilder, priv cryptotypes.PrivKey, txConfig client.TxConfig,
accSeq uint64,
) (signing.SignatureV2, error) {
var sigV2 signing.SignatureV2

View File

@ -0,0 +1,25 @@
package unknownproto_test
import (
"encoding/hex"
"io"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/simapp"
)
// Issue #7739: Catch parse errors resulting from unexpected EOF in
// protowire.ConsumeFieldValue. Discovered from fuzzing.
func TestBadBytesPassedIntoDecoder(t *testing.T) {
data, _ := hex.DecodeString("0A9F010A9C200A2D2F6962632E636F72652E636F6E6E656374696F6E2E76312E4D7367436F6E6E656374696F584F75656E496E6974126B0A0D6962637A65726F636C69656E74120B6962637A65726F636F6E6E1A1C0A0C6962636F6E65636C69656E74120A6962636F6E65636F6E6E00002205312E302E302A283235454635364341373935313335453430393336384536444238313130463232413442453035433212080A0612040A0208011A40143342993E25DA936CDDC7BE3D8F603CA6E9661518D536D0C482E18A0154AA096E438A6B9BCADFCFC2F0D689DCCAF55B96399D67A8361B70F5DA13091E2F929")
cfg := simapp.MakeTestEncodingConfig()
decoder := cfg.TxConfig.TxDecoder()
tx, err := decoder(data)
// TODO: When issue https://github.com/cosmos/cosmos-sdk/issues/7846
// is addressed, we'll remove this .Contains check.
require.Contains(t, err.Error(), io.ErrUnexpectedEOF.Error())
require.Nil(t, tx)
}

View File

@ -92,6 +92,11 @@ func RejectUnknownFields(bz []byte, msg proto.Message, allowUnknownNonCriticals
// Skip over the bytes that store fieldNumber and wireType bytes.
bz = bz[m:]
n := protowire.ConsumeFieldValue(tagNum, wireType, bz)
if n < 0 {
err = fmt.Errorf("could not consume field value for tagNum: %d, wireType: %q; %w",
tagNum, wireTypeToString(wireType), protowire.ParseError(n))
return hasUnknownNonCriticals, err
}
fieldBytes := bz[:n]
bz = bz[n:]

View File

@ -5,10 +5,18 @@ import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
func TestConfigPaths(t *testing.T) {
type argsTestSuite struct {
suite.Suite
}
func TestArgsTestSuite(t *testing.T) {
suite.Run(t, new(argsTestSuite))
}
func (s *argsTestSuite) TestConfigPaths() {
cases := map[string]struct {
cfg Config
upgradeName string
@ -32,23 +40,21 @@ func TestConfigPaths(t *testing.T) {
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.cfg.Root(), filepath.FromSlash(tc.expectRoot))
assert.Equal(t, tc.cfg.GenesisBin(), filepath.FromSlash(tc.expectGenesis))
assert.Equal(t, tc.cfg.UpgradeBin(tc.upgradeName), filepath.FromSlash(tc.expectUpgrade))
})
for _, tc := range cases {
s.Require().Equal(tc.cfg.Root(), filepath.FromSlash(tc.expectRoot))
s.Require().Equal(tc.cfg.GenesisBin(), filepath.FromSlash(tc.expectGenesis))
s.Require().Equal(tc.cfg.UpgradeBin(tc.upgradeName), filepath.FromSlash(tc.expectUpgrade))
}
}
// Test validate
func TestValidate(t *testing.T) {
func (s *argsTestSuite) TestValidate() {
relPath := filepath.Join("testdata", "validate")
absPath, err := filepath.Abs(relPath)
assert.NoError(t, err)
s.Require().NoError(err)
testdata, err := filepath.Abs("testdata")
assert.NoError(t, err)
s.Require().NoError(err)
cases := map[string]struct {
cfg Config
@ -84,28 +90,25 @@ func TestValidate(t *testing.T) {
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
err := tc.cfg.validate()
if tc.valid {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
})
for _, tc := range cases {
err := tc.cfg.validate()
if tc.valid {
s.Require().NoError(err)
} else {
s.Require().Error(err)
}
}
}
func TestEnsureBin(t *testing.T) {
func (s *argsTestSuite) TestEnsureBin() {
relPath := filepath.Join("testdata", "validate")
absPath, err := filepath.Abs(relPath)
assert.NoError(t, err)
s.Require().NoError(err)
cfg := Config{Home: absPath, Name: "dummyd"}
assert.NoError(t, cfg.validate())
s.Require().NoError(cfg.validate())
err = EnsureBinary(cfg.GenesisBin())
assert.NoError(t, err)
s.Require().NoError(EnsureBinary(cfg.GenesisBin()))
cases := map[string]struct {
upgrade string
@ -117,14 +120,12 @@ func TestEnsureBin(t *testing.T) {
"no directory": {"foobarbaz", false},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
err := EnsureBinary(cfg.UpgradeBin(tc.upgrade))
if tc.hasBin {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
})
for _, tc := range cases {
err := EnsureBinary(cfg.UpgradeBin(tc.upgrade))
if tc.hasBin {
s.Require().NoError(err)
} else {
s.Require().Error(err)
}
}
}

View File

@ -1,110 +1,114 @@
// +build linux
package cosmovisor
package cosmovisor_test
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/cosmovisor"
)
// TestLaunchProcess will try running the script a few times and watch upgrades work properly
// and args are passed through
func TestLaunchProcess(t *testing.T) {
home, err := copyTestData("validate")
cfg := &Config{Home: home, Name: "dummyd"}
require.NoError(t, err)
defer os.RemoveAll(home)
type processTestSuite struct {
suite.Suite
}
// should run the genesis binary and produce expected output
var stdout, stderr bytes.Buffer
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
require.Equal(t, cfg.GenesisBin(), currentBin)
args := []string{"foo", "bar", "1234"}
doUpgrade, err := LaunchProcess(cfg, args, &stdout, &stderr)
require.NoError(t, err)
assert.True(t, doUpgrade)
assert.Equal(t, "", stderr.String())
assert.Equal(t, "Genesis foo bar 1234\nUPGRADE \"chain2\" NEEDED at height: 49: {}\n", stdout.String())
// ensure this is upgraded now and produces new output
currentBin, err = cfg.CurrentBin()
require.NoError(t, err)
require.Equal(t, cfg.UpgradeBin("chain2"), currentBin)
args = []string{"second", "run", "--verbose"}
stdout.Reset()
stderr.Reset()
doUpgrade, err = LaunchProcess(cfg, args, &stdout, &stderr)
require.NoError(t, err)
assert.False(t, doUpgrade)
assert.Equal(t, "", stderr.String())
assert.Equal(t, "Chain 2 is live!\nArgs: second run --verbose\nFinished successfully\n", stdout.String())
// ended without other upgrade
require.Equal(t, cfg.UpgradeBin("chain2"), currentBin)
func TestProcessTestSuite(t *testing.T) {
suite.Run(t, new(processTestSuite))
}
// TestLaunchProcess will try running the script a few times and watch upgrades work properly
// and args are passed through
func TestLaunchProcessWithDownloads(t *testing.T) {
func (s *processTestSuite) TestLaunchProcess() {
home := copyTestData(s.T(), "validate")
cfg := &cosmovisor.Config{Home: home, Name: "dummyd"}
// should run the genesis binary and produce expected output
var stdout, stderr bytes.Buffer
currentBin, err := cfg.CurrentBin()
s.Require().NoError(err)
s.Require().Equal(cfg.GenesisBin(), currentBin)
args := []string{"foo", "bar", "1234"}
doUpgrade, err := cosmovisor.LaunchProcess(cfg, args, &stdout, &stderr)
s.Require().NoError(err)
s.Require().True(doUpgrade)
s.Require().Equal("", stderr.String())
s.Require().Equal("Genesis foo bar 1234\nUPGRADE \"chain2\" NEEDED at height: 49: {}\n", stdout.String())
// ensure this is upgraded now and produces new output
currentBin, err = cfg.CurrentBin()
s.Require().NoError(err)
s.Require().Equal(cfg.UpgradeBin("chain2"), currentBin)
args = []string{"second", "run", "--verbose"}
stdout.Reset()
stderr.Reset()
doUpgrade, err = cosmovisor.LaunchProcess(cfg, args, &stdout, &stderr)
s.Require().NoError(err)
s.Require().False(doUpgrade)
s.Require().Equal("", stderr.String())
s.Require().Equal("Chain 2 is live!\nArgs: second run --verbose\nFinished successfully\n", stdout.String())
// ended without other upgrade
s.Require().Equal(cfg.UpgradeBin("chain2"), currentBin)
}
// TestLaunchProcess will try running the script a few times and watch upgrades work properly
// and args are passed through
func (s *processTestSuite) TestLaunchProcessWithDownloads() {
// this is a fun path
// genesis -> "chain2" = zip_binary
// zip_binary -> "chain3" = ref_zipped -> zip_directory
// zip_directory no upgrade
home, err := copyTestData("download")
cfg := &Config{Home: home, Name: "autod", AllowDownloadBinaries: true}
require.NoError(t, err)
defer os.RemoveAll(home)
home := copyTestData(s.T(), "download")
cfg := &cosmovisor.Config{Home: home, Name: "autod", AllowDownloadBinaries: true}
// should run the genesis binary and produce expected output
var stdout, stderr bytes.Buffer
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
s.Require().NoError(err)
require.Equal(t, cfg.GenesisBin(), currentBin)
s.Require().Equal(cfg.GenesisBin(), currentBin)
args := []string{"some", "args"}
doUpgrade, err := LaunchProcess(cfg, args, &stdout, &stderr)
require.NoError(t, err)
assert.True(t, doUpgrade)
assert.Equal(t, "", stderr.String())
assert.Equal(t, "Preparing auto-download some args\n"+`ERROR: UPGRADE "chain2" NEEDED at height: 49: {"binaries":{"linux/amd64":"https://github.com/cosmos/cosmos-sdk/raw/51249cb93130810033408934454841c98423ed4b/cosmovisor/testdata/repo/zip_binary/autod.zip?checksum=sha256:dc48829b4126ae95bc0db316c66d4e9da5f3db95e212665b6080638cca77e998"}} module=main`+"\n", stdout.String())
doUpgrade, err := cosmovisor.LaunchProcess(cfg, args, &stdout, &stderr)
s.Require().NoError(err)
s.Require().True(doUpgrade)
s.Require().Equal("", stderr.String())
s.Require().Equal("Preparing auto-download some args\n"+`ERROR: UPGRADE "chain2" NEEDED at height: 49: {"binaries":{"linux/amd64":"https://github.com/cosmos/cosmos-sdk/raw/51249cb93130810033408934454841c98423ed4b/cosmovisor/testdata/repo/zip_binary/autod.zip?checksum=sha256:dc48829b4126ae95bc0db316c66d4e9da5f3db95e212665b6080638cca77e998"}} module=main`+"\n", stdout.String())
// ensure this is upgraded now and produces new output
currentBin, err = cfg.CurrentBin()
require.NoError(t, err)
require.Equal(t, cfg.UpgradeBin("chain2"), currentBin)
s.Require().NoError(err)
s.Require().Equal(cfg.UpgradeBin("chain2"), currentBin)
args = []string{"run", "--fast"}
stdout.Reset()
stderr.Reset()
doUpgrade, err = LaunchProcess(cfg, args, &stdout, &stderr)
require.NoError(t, err)
assert.True(t, doUpgrade)
assert.Equal(t, "", stderr.String())
assert.Equal(t, "Chain 2 from zipped binary link to referral\nArgs: run --fast\n"+`ERROR: UPGRADE "chain3" NEEDED at height: 936: https://github.com/cosmos/cosmos-sdk/raw/0eae1a50612b8bf803336d35055896fbddaa1ddd/cosmovisor/testdata/repo/ref_zipped?checksum=sha256:0a428575de718ed3cf0771c9687eefaf6f19359977eca4d94a0abd0e11ef8e64 module=main`+"\n", stdout.String())
doUpgrade, err = cosmovisor.LaunchProcess(cfg, args, &stdout, &stderr)
s.Require().NoError(err)
s.Require().True(doUpgrade)
s.Require().Equal("", stderr.String())
s.Require().Equal("Chain 2 from zipped binary link to referral\nArgs: run --fast\n"+`ERROR: UPGRADE "chain3" NEEDED at height: 936: https://github.com/cosmos/cosmos-sdk/raw/0eae1a50612b8bf803336d35055896fbddaa1ddd/cosmovisor/testdata/repo/ref_zipped?checksum=sha256:0a428575de718ed3cf0771c9687eefaf6f19359977eca4d94a0abd0e11ef8e64 module=main`+"\n", stdout.String())
// ended with one more upgrade
currentBin, err = cfg.CurrentBin()
require.NoError(t, err)
require.Equal(t, cfg.UpgradeBin("chain3"), currentBin)
s.Require().NoError(err)
s.Require().Equal(cfg.UpgradeBin("chain3"), currentBin)
// make sure this is the proper binary now....
args = []string{"end", "--halt"}
stdout.Reset()
stderr.Reset()
doUpgrade, err = LaunchProcess(cfg, args, &stdout, &stderr)
require.NoError(t, err)
assert.False(t, doUpgrade)
assert.Equal(t, "", stderr.String())
assert.Equal(t, "Chain 2 from zipped directory\nArgs: end --halt\n", stdout.String())
doUpgrade, err = cosmovisor.LaunchProcess(cfg, args, &stdout, &stderr)
s.Require().NoError(err)
s.Require().False(doUpgrade)
s.Require().Equal("", stderr.String())
s.Require().Equal("Chain 2 from zipped directory\nArgs: end --halt\n", stdout.String())
// and this doesn't upgrade
currentBin, err = cfg.CurrentBin()
require.NoError(t, err)
require.Equal(t, cfg.UpgradeBin("chain3"), currentBin)
s.Require().NoError(err)
s.Require().Equal(cfg.UpgradeBin("chain3"), currentBin)
}

View File

@ -1,17 +1,19 @@
package cosmovisor
package cosmovisor_test
import (
"bufio"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/cosmos/cosmos-sdk/cosmovisor"
"github.com/stretchr/testify/require"
)
func TestWaitForInfo(t *testing.T) {
cases := map[string]struct {
write []string
expectUpgrade *UpgradeInfo
expectUpgrade *cosmovisor.UpgradeInfo
expectErr bool
}{
"no match": {
@ -19,14 +21,14 @@ func TestWaitForInfo(t *testing.T) {
},
"match name with no info": {
write: []string{"first line\n", `UPGRADE "myname" NEEDED at height: 123: `, "\nnext line\n"},
expectUpgrade: &UpgradeInfo{
expectUpgrade: &cosmovisor.UpgradeInfo{
Name: "myname",
Info: "",
},
},
"match name with info": {
write: []string{"first line\n", `UPGRADE "take2" NEEDED at height: 123: DownloadData here!`, "\nnext line\n"},
expectUpgrade: &UpgradeInfo{
expectUpgrade: &cosmovisor.UpgradeInfo{
Name: "take2",
Info: "DownloadData",
},
@ -42,20 +44,20 @@ func TestWaitForInfo(t *testing.T) {
go func() {
for _, line := range tc.write {
n, err := w.Write([]byte(line))
assert.NoError(t, err)
assert.Equal(t, len(line), n)
require.NoError(t, err)
require.Equal(t, len(line), n)
}
w.Close()
}()
// now scan the info
info, err := WaitForUpdate(scan)
info, err := cosmovisor.WaitForUpdate(scan)
if tc.expectErr {
assert.Error(t, err)
require.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tc.expectUpgrade, info)
require.NoError(t, err)
require.Equal(t, tc.expectUpgrade, info)
})
}
}

View File

@ -119,12 +119,12 @@ func GetDownloadURL(info *UpgradeInfo) (string, error) {
var config UpgradeConfig
if err := json.Unmarshal([]byte(doc), &config); err == nil {
url, ok := config.Binaries[osArch()]
url, ok := config.Binaries[OSArch()]
if !ok {
url, ok = config.Binaries["any"]
}
if !ok {
return "", fmt.Errorf("cannot find binary for os/arch: neither %s, nor any", osArch())
return "", fmt.Errorf("cannot find binary for os/arch: neither %s, nor any", OSArch())
}
return url, nil
@ -133,7 +133,7 @@ func GetDownloadURL(info *UpgradeInfo) (string, error) {
return "", errors.New("upgrade info doesn't contain binary map")
}
func osArch() string {
func OSArch() string {
return fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
}

View File

@ -1,139 +1,138 @@
// +build linux
package cosmovisor
package cosmovisor_test
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
copy2 "github.com/otiai10/copy"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/assert"
"github.com/otiai10/copy"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/cosmovisor"
)
func TestCurrentBin(t *testing.T) {
home, err := copyTestData("validate")
require.NoError(t, err)
defer os.RemoveAll(home)
type upgradeTestSuite struct {
suite.Suite
}
cfg := Config{Home: home, Name: "dummyd"}
func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(upgradeTestSuite))
}
func (s *upgradeTestSuite) TestCurrentBin() {
home := copyTestData(s.T(), "validate")
cfg := cosmovisor.Config{Home: home, Name: "dummyd"}
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
s.Require().NoError(err)
assert.Equal(t, cfg.GenesisBin(), currentBin)
s.Require().Equal(cfg.GenesisBin(), currentBin)
// ensure we cannot set this to an invalid value
for _, name := range []string{"missing", "nobin", "noexec"} {
err = cfg.SetCurrentUpgrade(name)
require.Error(t, err, name)
s.Require().Error(cfg.SetCurrentUpgrade(name), name)
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
s.Require().NoError(err)
assert.Equal(t, cfg.GenesisBin(), currentBin, name)
s.Require().Equal(cfg.GenesisBin(), currentBin, name)
}
// try a few times to make sure this can be reproduced
for _, upgrade := range []string{"chain2", "chain3", "chain2"} {
// now set it to a valid upgrade and make sure CurrentBin is now set properly
err = cfg.SetCurrentUpgrade(upgrade)
require.NoError(t, err)
s.Require().NoError(err)
// we should see current point to the new upgrade dir
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
s.Require().NoError(err)
assert.Equal(t, cfg.UpgradeBin(upgrade), currentBin)
s.Require().Equal(cfg.UpgradeBin(upgrade), currentBin)
}
}
func TestCurrentAlwaysSymlinkToDirectory(t *testing.T) {
home, err := copyTestData("validate")
require.NoError(t, err)
defer os.RemoveAll(home)
cfg := Config{Home: home, Name: "dummyd"}
func (s *upgradeTestSuite) TestCurrentAlwaysSymlinkToDirectory() {
home := copyTestData(s.T(), "validate")
cfg := cosmovisor.Config{Home: home, Name: "dummyd"}
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
assert.Equal(t, cfg.GenesisBin(), currentBin)
assertCurrentLink(t, cfg, "genesis")
s.Require().NoError(err)
s.Require().Equal(cfg.GenesisBin(), currentBin)
s.assertCurrentLink(cfg, "genesis")
err = cfg.SetCurrentUpgrade("chain2")
require.NoError(t, err)
s.Require().NoError(err)
currentBin, err = cfg.CurrentBin()
require.NoError(t, err)
assert.Equal(t, cfg.UpgradeBin("chain2"), currentBin)
assertCurrentLink(t, cfg, filepath.Join("upgrades", "chain2"))
s.Require().NoError(err)
s.Require().Equal(cfg.UpgradeBin("chain2"), currentBin)
s.assertCurrentLink(cfg, filepath.Join("upgrades", "chain2"))
}
func assertCurrentLink(t *testing.T, cfg Config, target string) {
link := filepath.Join(cfg.Root(), currentLink)
func (s *upgradeTestSuite) assertCurrentLink(cfg cosmovisor.Config, target string) {
link := filepath.Join(cfg.Root(), "current")
// ensure this is a symlink
info, err := os.Lstat(link)
require.NoError(t, err)
require.Equal(t, os.ModeSymlink, info.Mode()&os.ModeSymlink)
s.Require().NoError(err)
s.Require().Equal(os.ModeSymlink, info.Mode()&os.ModeSymlink)
dest, err := os.Readlink(link)
require.NoError(t, err)
s.Require().NoError(err)
expected := filepath.Join(cfg.Root(), target)
require.Equal(t, expected, dest)
s.Require().Equal(expected, dest)
}
// TODO: test with download (and test all download functions)
func TestDoUpgradeNoDownloadUrl(t *testing.T) {
home, err := copyTestData("validate")
require.NoError(t, err)
defer os.RemoveAll(home)
cfg := &Config{Home: home, Name: "dummyd", AllowDownloadBinaries: true}
func (s *upgradeTestSuite) TestDoUpgradeNoDownloadUrl() {
home := copyTestData(s.T(), "validate")
cfg := &cosmovisor.Config{Home: home, Name: "dummyd", AllowDownloadBinaries: true}
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
s.Require().NoError(err)
assert.Equal(t, cfg.GenesisBin(), currentBin)
s.Require().Equal(cfg.GenesisBin(), currentBin)
// do upgrade ignores bad files
for _, name := range []string{"missing", "nobin", "noexec"} {
info := &UpgradeInfo{Name: name}
err = DoUpgrade(cfg, info)
require.Error(t, err, name)
info := &cosmovisor.UpgradeInfo{Name: name}
err = cosmovisor.DoUpgrade(cfg, info)
s.Require().Error(err, name)
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
assert.Equal(t, cfg.GenesisBin(), currentBin, name)
s.Require().NoError(err)
s.Require().Equal(cfg.GenesisBin(), currentBin, name)
}
// make sure it updates a few times
for _, upgrade := range []string{"chain2", "chain3"} {
// now set it to a valid upgrade and make sure CurrentBin is now set properly
info := &UpgradeInfo{Name: upgrade}
err = DoUpgrade(cfg, info)
require.NoError(t, err)
info := &cosmovisor.UpgradeInfo{Name: upgrade}
err = cosmovisor.DoUpgrade(cfg, info)
s.Require().NoError(err)
// we should see current point to the new upgrade dir
upgradeBin := cfg.UpgradeBin(upgrade)
currentBin, err := cfg.CurrentBin()
require.NoError(t, err)
s.Require().NoError(err)
assert.Equal(t, upgradeBin, currentBin)
s.Require().Equal(upgradeBin, currentBin)
}
}
func TestOsArch(t *testing.T) {
func (s *upgradeTestSuite) TestOsArch() {
// all download tests will fail if we are not on linux...
assert.Equal(t, "linux/amd64", osArch())
s.Require().Equal("linux/amd64", cosmovisor.OSArch())
}
func TestGetDownloadURL(t *testing.T) {
func (s *upgradeTestSuite) TestGetDownloadURL() {
// all download tests will fail if we are not on linux...
ref, err := filepath.Abs(filepath.FromSlash("./testdata/repo/ref_zipped"))
require.NoError(t, err)
s.Require().NoError(err)
badref, err := filepath.Abs(filepath.FromSlash("./testdata/repo/zip_binary/autod.zip"))
require.NoError(t, err)
s.Require().NoError(err)
cases := map[string]struct {
info string
@ -173,20 +172,18 @@ func TestGetDownloadURL(t *testing.T) {
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
url, err := GetDownloadURL(&UpgradeInfo{Info: tc.info})
if tc.isErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tc.url, url)
}
})
for _, tc := range cases {
url, err := cosmovisor.GetDownloadURL(&cosmovisor.UpgradeInfo{Info: tc.info})
if tc.isErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().Equal(tc.url, url)
}
}
}
func TestDownloadBinary(t *testing.T) {
func (s *upgradeTestSuite) TestDownloadBinary() {
cases := map[string]struct {
url string
canDownload bool
@ -228,65 +225,55 @@ func TestDownloadBinary(t *testing.T) {
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
// make temp dir
home, err := copyTestData("download")
require.NoError(t, err)
defer os.RemoveAll(home)
for _, tc := range cases {
var err error
// make temp dir
home := copyTestData(s.T(), "download")
cfg := &Config{
Home: home,
Name: "autod",
AllowDownloadBinaries: true,
}
cfg := &cosmovisor.Config{
Home: home,
Name: "autod",
AllowDownloadBinaries: true,
}
// if we have a relative path, make it absolute, but don't change eg. https://... urls
url := tc.url
if strings.HasPrefix(url, "./") {
url, err = filepath.Abs(url)
require.NoError(t, err)
}
// if we have a relative path, make it absolute, but don't change eg. https://... urls
url := tc.url
if strings.HasPrefix(url, "./") {
url, err = filepath.Abs(url)
s.Require().NoError(err)
}
upgrade := "amazonas"
info := &UpgradeInfo{
Name: upgrade,
Info: fmt.Sprintf(`{"binaries":{"%s": "%s"}}`, osArch(), url),
}
upgrade := "amazonas"
info := &cosmovisor.UpgradeInfo{
Name: upgrade,
Info: fmt.Sprintf(`{"binaries":{"%s": "%s"}}`, cosmovisor.OSArch(), url),
}
err = DownloadBinary(cfg, info)
if !tc.canDownload {
assert.Error(t, err)
return
}
require.NoError(t, err)
err = cosmovisor.DownloadBinary(cfg, info)
if !tc.canDownload {
s.Require().Error(err)
return
}
s.Require().NoError(err)
err = EnsureBinary(cfg.UpgradeBin(upgrade))
if tc.validBinary {
require.NoError(t, err)
} else {
require.Error(t, err)
}
})
err = cosmovisor.EnsureBinary(cfg.UpgradeBin(upgrade))
if tc.validBinary {
s.Require().NoError(err)
} else {
s.Require().Error(err)
}
}
}
// copyTestData will make a tempdir and then
// "cp -r" a subdirectory under testdata there
// returns the directory (which can now be used as Config.Home) and modified safely
func copyTestData(subdir string) (string, error) {
tmpdir, err := ioutil.TempDir("", "upgrade-manager-test")
if err != nil {
return "", fmt.Errorf("couldn't create temporary directory: %w", err)
}
func copyTestData(t *testing.T, subdir string) string {
t.Helper()
src := filepath.Join("testdata", subdir)
tmpdir := t.TempDir()
err = copy2.Copy(src, tmpdir)
if err != nil {
os.RemoveAll(tmpdir)
return "", fmt.Errorf("couldn't copy files: %w", err)
}
require.NoError(t, copy.Copy(filepath.Join("testdata", subdir), tmpdir))
return tmpdir, nil
return tmpdir
}

View File

@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -124,7 +125,7 @@ func unarmorBytes(armorStr, blockType string) (bz []byte, header map[string]stri
// encrypt/decrypt with armor
// Encrypt and armor the private key.
func EncryptArmorPrivKey(privKey crypto.PrivKey, passphrase string, algo string) string {
func EncryptArmorPrivKey(privKey cryptotypes.PrivKey, passphrase string, algo string) string {
saltBytes, encBytes := encryptPrivKey(privKey, passphrase)
header := map[string]string{
"kdf": "bcrypt",
@ -143,7 +144,7 @@ func EncryptArmorPrivKey(privKey crypto.PrivKey, passphrase string, algo string)
// encrypt the given privKey with the passphrase using a randomly
// generated salt and the xsalsa20 cipher. returns the salt and the
// encrypted priv key.
func encryptPrivKey(privKey crypto.PrivKey, passphrase string) (saltBytes []byte, encBytes []byte) {
func encryptPrivKey(privKey cryptotypes.PrivKey, passphrase string) (saltBytes []byte, encBytes []byte) {
saltBytes = crypto.CRandBytes(16)
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
@ -158,7 +159,7 @@ func encryptPrivKey(privKey crypto.PrivKey, passphrase string) (saltBytes []byte
}
// UnarmorDecryptPrivKey returns the privkey byte slice, a string of the algo type, and an error
func UnarmorDecryptPrivKey(armorStr string, passphrase string) (privKey crypto.PrivKey, algo string, err error) {
func UnarmorDecryptPrivKey(armorStr string, passphrase string) (privKey cryptotypes.PrivKey, algo string, err error) {
blockType, header, encBytes, err := armor.DecodeArmor(armorStr)
if err != nil {
return privKey, "", err
@ -190,7 +191,7 @@ func UnarmorDecryptPrivKey(armorStr string, passphrase string) (privKey crypto.P
return privKey, header[headerType], err
}
func decryptPrivKey(saltBytes []byte, encBytes []byte, passphrase string) (privKey crypto.PrivKey, err error) {
func decryptPrivKey(saltBytes []byte, encBytes []byte, passphrase string) (privKey cryptotypes.PrivKey, err error) {
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
if err != nil {
return privKey, sdkerrors.Wrap(err, "error generating bcrypt key from passphrase")

View File

@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
)
@ -46,7 +47,7 @@ func TestArmorUnarmorPrivKey(t *testing.T) {
require.Contains(t, err.Error(), "unrecognized armor type")
// armor key manually
encryptPrivKeyFn := func(privKey tmcrypto.PrivKey, passphrase string) (saltBytes []byte, encBytes []byte) {
encryptPrivKeyFn := func(privKey cryptotypes.PrivKey, passphrase string) (saltBytes []byte, encBytes []byte) {
saltBytes = tmcrypto.CRandBytes(16)
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), crypto.BcryptSecurityParameter)
require.NoError(t, err)

View File

@ -1,8 +1,6 @@
package codec
import (
"github.com/tendermint/tendermint/crypto"
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/sr25519"
"github.com/cosmos/cosmos-sdk/codec"
@ -22,16 +20,9 @@ func init() {
// RegisterCrypto registers all crypto dependency types with the provided Amino
// codec.
func RegisterCrypto(cdc *codec.LegacyAmino) {
// 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 this
// first line.
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterInterface((*cryptotypes.PubKey)(nil), 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{},
@ -39,12 +30,9 @@ func RegisterCrypto(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&kmultisig.LegacyAminoPubKey{},
kmultisig.PubKeyAminoRoute, nil)
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
cdc.RegisterInterface((*cryptotypes.PrivKey)(nil), 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{},
@ -52,13 +40,13 @@ func RegisterCrypto(cdc *codec.LegacyAmino) {
}
// PrivKeyFromBytes unmarshals private key bytes and returns a PrivKey
func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {
func PrivKeyFromBytes(privKeyBytes []byte) (privKey cryptotypes.PrivKey, err error) {
err = amino.UnmarshalBinaryBare(privKeyBytes, &privKey)
return
}
// PubKeyFromBytes unmarshals public key bytes and returns a PubKey
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) {
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey cryptotypes.PubKey, err error) {
err = amino.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
return
}

View File

@ -1,8 +1,6 @@
package codec
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"
@ -12,14 +10,6 @@ import (
// RegisterInterfaces registers the sdk.Tx interface.
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.
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{})

57
crypto/codec/tm.go Normal file
View File

@ -0,0 +1,57 @@
package codec
import (
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/encoding"
tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// FromTmProtoPublicKey converts a TM's tmprotocrypto.PublicKey into our own PubKey.
func FromTmProtoPublicKey(protoPk tmprotocrypto.PublicKey) (cryptotypes.PubKey, error) {
switch protoPk := protoPk.Sum.(type) {
case *tmprotocrypto.PublicKey_Ed25519:
return &ed25519.PubKey{
Key: protoPk.Ed25519,
}, nil
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot convert %v from Tendermint public key", protoPk)
}
}
// ToTmProtoPublicKey converts our own PubKey to TM's tmprotocrypto.PublicKey.
func ToTmProtoPublicKey(pk cryptotypes.PubKey) (tmprotocrypto.PublicKey, error) {
switch pk := pk.(type) {
case *ed25519.PubKey:
return tmprotocrypto.PublicKey{
Sum: &tmprotocrypto.PublicKey_Ed25519{
Ed25519: pk.Key,
},
}, nil
default:
return tmprotocrypto.PublicKey{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot convert %v to Tendermint public key", pk)
}
}
// FromTmPubKeyInterface converts TM's tmcrypto.PubKey to our own PubKey.
func FromTmPubKeyInterface(tmPk tmcrypto.PubKey) (cryptotypes.PubKey, error) {
tmProtoPk, err := encoding.PubKeyToProto(tmPk)
if err != nil {
return nil, err
}
return FromTmProtoPublicKey(tmProtoPk)
}
// ToTmPubKeyInterface converts our own PubKey to TM's tmcrypto.PubKey.
func ToTmPubKeyInterface(pk cryptotypes.PubKey) (tmcrypto.PubKey, error) {
tmProtoPk, err := ToTmProtoPublicKey(pk)
if err != nil {
return nil, err
}
return encoding.PubKeyFromProto(tmProtoPk)
}

View File

@ -2,9 +2,9 @@ package hd
import (
bip39 "github.com/cosmos/go-bip39"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types"
)
// PubKeyType defines an algorithm to derive key-pairs which can be used for cryptographic signing.
@ -28,11 +28,11 @@ var (
)
type DeriveFn func(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
type GenerateFn func(bz []byte) crypto.PrivKey
type GenerateFn func(bz []byte) types.PrivKey
type WalletGenerator interface {
Derive(mnemonic string, bip39Passphrase, hdPath string) ([]byte, error)
Generate(bz []byte) crypto.PrivKey
Generate(bz []byte) types.PrivKey
}
type secp256k1Algo struct {
@ -62,7 +62,7 @@ func (s secp256k1Algo) Derive() DeriveFn {
// Generate generates a secp256k1 private key from the given bytes.
func (s secp256k1Algo) Generate() GenerateFn {
return func(bz []byte) crypto.PrivKey {
return func(bz []byte) types.PrivKey {
var bzArr = make([]byte, secp256k1.PrivKeySize)
copy(bzArr, bz)

View File

@ -3,11 +3,10 @@ package keyring
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
)
@ -18,7 +17,7 @@ type Info interface {
// Name of the key
GetName() string
// Public key
GetPubKey() crypto.PubKey
GetPubKey() cryptotypes.PubKey
// Address
GetAddress() types.AccAddress
// Bip44 Path
@ -37,13 +36,13 @@ var (
// localInfo is the public information about a locally stored key
// Note: Algo must be last field in struct for backwards amino compatibility
type localInfo struct {
Name string `json:"name"`
PubKey crypto.PubKey `json:"pubkey"`
PrivKeyArmor string `json:"privkey.armor"`
Algo hd.PubKeyType `json:"algo"`
Name string `json:"name"`
PubKey cryptotypes.PubKey `json:"pubkey"`
PrivKeyArmor string `json:"privkey.armor"`
Algo hd.PubKeyType `json:"algo"`
}
func newLocalInfo(name string, pub crypto.PubKey, privArmor string, algo hd.PubKeyType) Info {
func newLocalInfo(name string, pub cryptotypes.PubKey, privArmor string, algo hd.PubKeyType) Info {
return &localInfo{
Name: name,
PubKey: pub,
@ -63,7 +62,7 @@ func (i localInfo) GetName() string {
}
// GetType implements Info interface
func (i localInfo) GetPubKey() crypto.PubKey {
func (i localInfo) GetPubKey() cryptotypes.PubKey {
return i.PubKey
}
@ -85,13 +84,13 @@ func (i localInfo) GetPath() (*hd.BIP44Params, error) {
// ledgerInfo is the public information about a Ledger key
// Note: Algo must be last field in struct for backwards amino compatibility
type ledgerInfo struct {
Name string `json:"name"`
PubKey crypto.PubKey `json:"pubkey"`
Path hd.BIP44Params `json:"path"`
Algo hd.PubKeyType `json:"algo"`
Name string `json:"name"`
PubKey cryptotypes.PubKey `json:"pubkey"`
Path hd.BIP44Params `json:"path"`
Algo hd.PubKeyType `json:"algo"`
}
func newLedgerInfo(name string, pub crypto.PubKey, path hd.BIP44Params, algo hd.PubKeyType) Info {
func newLedgerInfo(name string, pub cryptotypes.PubKey, path hd.BIP44Params, algo hd.PubKeyType) Info {
return &ledgerInfo{
Name: name,
PubKey: pub,
@ -111,7 +110,7 @@ func (i ledgerInfo) GetName() string {
}
// GetPubKey implements Info interface
func (i ledgerInfo) GetPubKey() crypto.PubKey {
func (i ledgerInfo) GetPubKey() cryptotypes.PubKey {
return i.PubKey
}
@ -134,12 +133,12 @@ func (i ledgerInfo) GetPath() (*hd.BIP44Params, error) {
// offlineInfo is the public information about an offline key
// Note: Algo must be last field in struct for backwards amino compatibility
type offlineInfo struct {
Name string `json:"name"`
PubKey crypto.PubKey `json:"pubkey"`
Algo hd.PubKeyType `json:"algo"`
Name string `json:"name"`
PubKey cryptotypes.PubKey `json:"pubkey"`
Algo hd.PubKeyType `json:"algo"`
}
func newOfflineInfo(name string, pub crypto.PubKey, algo hd.PubKeyType) Info {
func newOfflineInfo(name string, pub cryptotypes.PubKey, algo hd.PubKeyType) Info {
return &offlineInfo{
Name: name,
PubKey: pub,
@ -158,7 +157,7 @@ func (i offlineInfo) GetName() string {
}
// GetPubKey implements Info interface
func (i offlineInfo) GetPubKey() crypto.PubKey {
func (i offlineInfo) GetPubKey() cryptotypes.PubKey {
return i.PubKey
}
@ -178,20 +177,20 @@ func (i offlineInfo) GetPath() (*hd.BIP44Params, error) {
}
type multisigPubKeyInfo struct {
PubKey crypto.PubKey `json:"pubkey"`
Weight uint `json:"weight"`
PubKey cryptotypes.PubKey `json:"pubkey"`
Weight uint `json:"weight"`
}
// multiInfo is the public information about a multisig key
type multiInfo struct {
Name string `json:"name"`
PubKey crypto.PubKey `json:"pubkey"`
PubKey cryptotypes.PubKey `json:"pubkey"`
Threshold uint `json:"threshold"`
PubKeys []multisigPubKeyInfo `json:"pubkeys"`
}
// NewMultiInfo creates a new multiInfo instance
func NewMultiInfo(name string, pub crypto.PubKey) Info {
func NewMultiInfo(name string, pub cryptotypes.PubKey) Info {
multiPK := pub.(*multisig.LegacyAminoPubKey)
pubKeys := make([]multisigPubKeyInfo, len(multiPK.PubKeys))
@ -219,7 +218,7 @@ func (i multiInfo) GetName() string {
}
// GetPubKey implements Info interface
func (i multiInfo) GetPubKey() crypto.PubKey {
func (i multiInfo) GetPubKey() cryptotypes.PubKey {
return i.PubKey
}

View File

@ -22,6 +22,7 @@ import (
cryptoamino "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/ledger"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -76,10 +77,10 @@ type Keyring interface {
SaveLedgerKey(uid string, algo SignatureAlgo, hrp string, coinType, account, index uint32) (Info, error)
// SavePubKey stores a public key and returns the persisted Info structure.
SavePubKey(uid string, pubkey tmcrypto.PubKey, algo hd.PubKeyType) (Info, error)
SavePubKey(uid string, pubkey types.PubKey, algo hd.PubKeyType) (Info, error)
// SaveMultisig stores and returns a new multsig (offline) key reference.
SaveMultisig(uid string, pubkey tmcrypto.PubKey) (Info, error)
SaveMultisig(uid string, pubkey types.PubKey) (Info, error)
Signer
@ -90,10 +91,10 @@ type Keyring interface {
// Signer is implemented by key stores that want to provide signing capabilities.
type Signer interface {
// Sign sign byte messages with a user key.
Sign(uid string, msg []byte) ([]byte, tmcrypto.PubKey, error)
Sign(uid string, msg []byte) ([]byte, types.PubKey, error)
// SignByAddress sign byte messages with a user key providing the address.
SignByAddress(address sdk.Address, msg []byte) ([]byte, tmcrypto.PubKey, error)
SignByAddress(address sdk.Address, msg []byte) ([]byte, types.PubKey, error)
}
// Importer is implemented by key stores that support import of public and private keys.
@ -224,13 +225,13 @@ func (ks keystore) ExportPrivKeyArmor(uid, encryptPassphrase string) (armor stri
}
// ExportPrivateKeyObject exports an armored private key object.
func (ks keystore) ExportPrivateKeyObject(uid string) (tmcrypto.PrivKey, error) {
func (ks keystore) ExportPrivateKeyObject(uid string) (types.PrivKey, error) {
info, err := ks.Key(uid)
if err != nil {
return nil, err
}
var priv tmcrypto.PrivKey
var priv types.PrivKey
switch linfo := info.(type) {
case localInfo:
@ -301,13 +302,13 @@ func (ks keystore) ImportPubKey(uid string, armor string) error {
return nil
}
func (ks keystore) Sign(uid string, msg []byte) ([]byte, tmcrypto.PubKey, error) {
func (ks keystore) Sign(uid string, msg []byte) ([]byte, types.PubKey, error) {
info, err := ks.Key(uid)
if err != nil {
return nil, nil, err
}
var priv tmcrypto.PrivKey
var priv types.PrivKey
switch i := info.(type) {
case localInfo:
@ -335,7 +336,7 @@ func (ks keystore) Sign(uid string, msg []byte) ([]byte, tmcrypto.PubKey, error)
return sig, priv.PubKey(), nil
}
func (ks keystore) SignByAddress(address sdk.Address, msg []byte) ([]byte, tmcrypto.PubKey, error) {
func (ks keystore) SignByAddress(address sdk.Address, msg []byte) ([]byte, types.PubKey, error) {
key, err := ks.KeyByAddress(address)
if err != nil {
return nil, nil, err
@ -359,7 +360,7 @@ func (ks keystore) SaveLedgerKey(uid string, algo SignatureAlgo, hrp string, coi
return ks.writeLedgerKey(uid, priv.PubKey(), *hdPath, algo.Name())
}
func (ks keystore) writeLedgerKey(name string, pub tmcrypto.PubKey, path hd.BIP44Params, algo hd.PubKeyType) (Info, error) {
func (ks keystore) writeLedgerKey(name string, pub types.PubKey, path hd.BIP44Params, algo hd.PubKeyType) (Info, error) {
info := newLedgerInfo(name, pub, path, algo)
if err := ks.writeInfo(info); err != nil {
return nil, err
@ -368,11 +369,11 @@ func (ks keystore) writeLedgerKey(name string, pub tmcrypto.PubKey, path hd.BIP4
return info, nil
}
func (ks keystore) SaveMultisig(uid string, pubkey tmcrypto.PubKey) (Info, error) {
func (ks keystore) SaveMultisig(uid string, pubkey types.PubKey) (Info, error) {
return ks.writeMultisigKey(uid, pubkey)
}
func (ks keystore) SavePubKey(uid string, pubkey tmcrypto.PubKey, algo hd.PubKeyType) (Info, error) {
func (ks keystore) SavePubKey(uid string, pubkey types.PubKey, algo hd.PubKeyType) (Info, error) {
return ks.writeOfflineKey(uid, pubkey, algo)
}
@ -533,7 +534,7 @@ func (ks keystore) SupportedAlgorithms() (SigningAlgoList, SigningAlgoList) {
// SignWithLedger signs a binary message with the ledger device referenced by an Info object
// and returns the signed bytes and the public key. It returns an error if the device could
// not be queried or it returned an error.
func SignWithLedger(info Info, msg []byte) (sig []byte, pub tmcrypto.PubKey, err error) {
func SignWithLedger(info Info, msg []byte) (sig []byte, pub types.PubKey, err error) {
switch info.(type) {
case *ledgerInfo, ledgerInfo:
default:
@ -691,7 +692,7 @@ func newRealPrompt(dir string, buf io.Reader) func(string) (string, error) {
}
}
func (ks keystore) writeLocalKey(name string, priv tmcrypto.PrivKey, algo hd.PubKeyType) (Info, error) {
func (ks keystore) writeLocalKey(name string, priv types.PrivKey, algo hd.PubKeyType) (Info, error) {
// encrypt private key using keyring
pub := priv.PubKey()
@ -753,7 +754,7 @@ func (ks keystore) existsInDb(info Info) (bool, error) {
return false, nil
}
func (ks keystore) writeOfflineKey(name string, pub tmcrypto.PubKey, algo hd.PubKeyType) (Info, error) {
func (ks keystore) writeOfflineKey(name string, pub types.PubKey, algo hd.PubKeyType) (Info, error) {
info := newOfflineInfo(name, pub, algo)
err := ks.writeInfo(info)
if err != nil {
@ -763,7 +764,7 @@ func (ks keystore) writeOfflineKey(name string, pub tmcrypto.PubKey, algo hd.Pub
return info, nil
}
func (ks keystore) writeMultisigKey(name string, pub tmcrypto.PubKey) (Info, error) {
func (ks keystore) writeMultisigKey(name string, pub types.PubKey) (Info, error) {
info := NewMultiInfo(name, pub)
err := ks.writeInfo(info)
if err != nil {

View File

@ -8,13 +8,13 @@ import (
"github.com/99designs/keyring"
bip39 "github.com/cosmos/go-bip39"
"github.com/stretchr/testify/require"
tmcrypto "github.com/tendermint/tendermint/crypto"
"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"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -166,7 +166,7 @@ func TestSignVerifyKeyRing(t *testing.T) {
// let's try to validate and make sure it only works when everything is proper
cases := []struct {
key tmcrypto.PubKey
key types.PubKey
data []byte
sig []byte
valid bool
@ -380,7 +380,7 @@ func TestInMemoryCreateMultisig(t *testing.T) {
kb, err := New("keybasename", "memory", "", nil)
require.NoError(t, err)
multi := multisig.NewLegacyAminoPubKey(
1, []tmcrypto.PubKey{
1, []types.PubKey{
secp256k1.GenPrivKey().PubKey(),
},
)
@ -521,7 +521,7 @@ func TestInMemorySignVerify(t *testing.T) {
// let's try to validate and make sure it only works when everything is proper
cases := []struct {
key tmcrypto.PubKey
key types.PubKey
data []byte
sig []byte
valid bool
@ -947,7 +947,7 @@ func TestAltKeyring_SaveMultisig(t *testing.T) {
key := "multi"
pub := multisig.NewLegacyAminoPubKey(
2,
[]tmcrypto.PubKey{
[]types.PubKey{
&secp256k1.PubKey{Key: mnemonic1.GetPubKey().Bytes()},
&secp256k1.PubKey{Key: mnemonic2.GetPubKey().Bytes()},
},

View File

@ -6,11 +6,11 @@ import (
"strings"
"github.com/pkg/errors"
tmcrypto "github.com/tendermint/tendermint/crypto"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -101,13 +101,13 @@ func (kb dbKeybase) Get(name string) (Info, error) {
// ExportPrivateKeyObject returns a PrivKey object given the key name and
// passphrase. An error is returned if the key does not exist or if the Info for
// the key is invalid.
func (kb dbKeybase) ExportPrivateKeyObject(name string, passphrase string) (tmcrypto.PrivKey, error) {
func (kb dbKeybase) ExportPrivateKeyObject(name string, passphrase string) (types.PrivKey, error) {
info, err := kb.Get(name)
if err != nil {
return nil, err
}
var priv tmcrypto.PrivKey
var priv types.PrivKey
switch i := info.(type) {
case localInfo:

View File

@ -4,10 +4,10 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -16,7 +16,7 @@ func TestBech32KeysOutput(t *testing.T) {
bechTmpKey := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, tmpKey)
tmpAddr := sdk.AccAddress(tmpKey.Address().Bytes())
multisigPks := kmultisig.NewLegacyAminoPubKey(1, []crypto.PubKey{tmpKey})
multisigPks := kmultisig.NewLegacyAminoPubKey(1, []types.PubKey{tmpKey})
multiInfo := NewMultiInfo("multisig", multisigPks)
accAddr := sdk.AccAddress(multiInfo.GetPubKey().Address().Bytes())
bechPubKey := sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, multiInfo.GetPubKey())

View File

@ -1,9 +1,8 @@
package keyring
import (
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
// Language is a language to create the BIP 39 mnemonic in.
@ -68,5 +67,5 @@ type (
// DeriveKeyFunc defines the function to derive a new key from a seed and hd path
DeriveKeyFunc func(mnemonic string, bip39Passphrase, hdPath string, algo hd.PubKeyType) ([]byte, error)
// PrivKeyGenFunc defines the function to convert derived key bytes to a tendermint private key
PrivKeyGenFunc func(bz []byte, algo hd.PubKeyType) (crypto.PrivKey, error)
PrivKeyGenFunc func(bz []byte, algo hd.PubKeyType) (cryptotypes.PrivKey, error)
)

View File

@ -7,7 +7,6 @@ import (
"io"
"github.com/tendermint/tendermint/crypto"
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/cosmos/cosmos-sdk/codec"
@ -18,8 +17,8 @@ import (
//-------------------------------------
const (
PrivKeyName = "cosmos/PrivKeyEd25519"
PubKeyName = "cosmos/PubKeyEd25519"
PrivKeyName = "tendermint/PrivKeyEd25519"
PubKeyName = "tendermint/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.
@ -56,7 +55,7 @@ func (privKey *PrivKey) Sign(msg []byte) ([]byte, error) {
// PubKey gets the corresponding public key from the private key.
//
// Panics if the private key is not initialized.
func (privKey *PrivKey) PubKey() crypto.PubKey {
func (privKey *PrivKey) PubKey() cryptotypes.PubKey {
// If the latter 32 bytes of the privkey are all zero, privkey is not
// initialized.
initialized := false
@ -78,7 +77,7 @@ func (privKey *PrivKey) PubKey() crypto.PubKey {
// 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 {
func (privKey *PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool {
if privKey.Type() != other.Type() {
return false
}
@ -150,7 +149,6 @@ func GenPrivKeyFromSecret(secret []byte) *PrivKey {
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 {
@ -182,7 +180,7 @@ func (pubKey *PubKey) Type() string {
return keyType
}
func (pubKey *PubKey) Equals(other crypto.PubKey) bool {
func (pubKey *PubKey) Equals(other cryptotypes.PubKey) bool {
if pubKey.Type() != other.Type() {
return false
}
@ -216,19 +214,3 @@ func (pubKey PubKey) MarshalAminoJSON() ([]byte, error) {
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
}

View File

@ -9,10 +9,10 @@ import (
"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"
ed25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
@ -51,7 +51,7 @@ func TestPubKeyEquals(t *testing.T) {
testCases := []struct {
msg string
pubKey cryptotypes.PubKey
other crypto.PubKey
other cryptotypes.PubKey
expectEq bool
}{
{
@ -71,7 +71,7 @@ func TestPubKeyEquals(t *testing.T) {
{
"different types",
ed25519PubKey,
sr25519.GenPrivKey().PubKey(),
secp256k1.GenPrivKey().PubKey(),
false,
},
}
@ -90,7 +90,7 @@ func TestPrivKeyEquals(t *testing.T) {
testCases := []struct {
msg string
privKey cryptotypes.PrivKey
other crypto.PrivKey
other cryptotypes.PrivKey
expectEq bool
}{
{
@ -110,7 +110,7 @@ func TestPrivKeyEquals(t *testing.T) {
{
"different types",
ed25519PrivKey,
sr25519.GenPrivKey(),
secp256k1.GenPrivKey(),
false,
},
}

View File

@ -4,7 +4,7 @@ import (
"io"
"testing"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/types"
)
// The code in this file is adapted from agl/ed25519.
@ -24,7 +24,7 @@ func (zeroReader) Read(buf []byte) (int, error) {
// BenchmarkKeyGeneration benchmarks the given key generation algorithm using
// a dummy reader.
func BenchmarkKeyGeneration(b *testing.B, generateKey func(reader io.Reader) crypto.PrivKey) {
func BenchmarkKeyGeneration(b *testing.B, generateKey func(reader io.Reader) types.PrivKey) {
var zero zeroReader
for i := 0; i < b.N; i++ {
generateKey(zero)
@ -33,7 +33,7 @@ func BenchmarkKeyGeneration(b *testing.B, generateKey func(reader io.Reader) cry
// BenchmarkSigning benchmarks the given signing algorithm using
// the provided privkey.
func BenchmarkSigning(b *testing.B, priv crypto.PrivKey) {
func BenchmarkSigning(b *testing.B, priv types.PrivKey) {
message := []byte("Hello, world!")
b.ResetTimer()
for i := 0; i < b.N; i++ {
@ -47,7 +47,7 @@ func BenchmarkSigning(b *testing.B, priv crypto.PrivKey) {
// BenchmarkVerification benchmarks the given verification algorithm using
// the provided privkey on a constant message.
func BenchmarkVerification(b *testing.B, priv crypto.PrivKey) {
func BenchmarkVerification(b *testing.B, priv types.PrivKey) {
pub := priv.PubKey()
// use a short message, so this time doesn't get dominated by hashing.
message := []byte("Hello, world!")

View File

@ -1,7 +1,6 @@
package multisig
import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/sr25519"
"github.com/cosmos/cosmos-sdk/codec"
@ -19,10 +18,6 @@ const (
var AminoCdc = codec.NewLegacyAmino()
func init() {
// 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 this
// first line.
AminoCdc.RegisterInterface((*crypto.PubKey)(nil), nil)
AminoCdc.RegisterInterface((*cryptotypes.PubKey)(nil), nil)
AminoCdc.RegisterConcrete(ed25519.PubKey{},
ed25519.PubKeyName, nil)

View File

@ -5,10 +5,8 @@ import (
tmcrypto "github.com/tendermint/tendermint/crypto"
proto "github.com/gogo/protobuf/proto"
"github.com/cosmos/cosmos-sdk/codec/types"
crypto "github.com/cosmos/cosmos-sdk/crypto/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
multisigtypes "github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
@ -18,7 +16,7 @@ var _ types.UnpackInterfacesMessage = &LegacyAminoPubKey{}
// NewLegacyAminoPubKey returns a new LegacyAminoPubKey.
// Panics if len(pubKeys) < k or 0 >= k.
func NewLegacyAminoPubKey(k int, pubKeys []tmcrypto.PubKey) *LegacyAminoPubKey {
func NewLegacyAminoPubKey(k int, pubKeys []cryptotypes.PubKey) *LegacyAminoPubKey {
if k <= 0 {
panic("threshold k of n multisignature: k <= 0")
}
@ -32,8 +30,8 @@ func NewLegacyAminoPubKey(k int, pubKeys []tmcrypto.PubKey) *LegacyAminoPubKey {
return &LegacyAminoPubKey{Threshold: uint32(k), PubKeys: anyPubKeys}
}
// Address implements crypto.PubKey Address method
func (m *LegacyAminoPubKey) Address() tmcrypto.Address {
// Address implements cryptotypes.PubKey Address method
func (m *LegacyAminoPubKey) Address() cryptotypes.Address {
return tmcrypto.AddressHash(m.Bytes())
}
@ -91,7 +89,7 @@ func (m *LegacyAminoPubKey) VerifyMultisignature(getSignBytes multisigtypes.GetS
return nil
}
// VerifySignature implements crypto.PubKey VerifySignature method,
// VerifySignature implements cryptotypes.PubKey VerifySignature method,
// it panics because it can't handle MultiSignatureData
// cf. https://github.com/cosmos/cosmos-sdk/issues/7109#issuecomment-686329936
func (m *LegacyAminoPubKey) VerifySignature(msg []byte, sig []byte) bool {
@ -99,11 +97,11 @@ func (m *LegacyAminoPubKey) VerifySignature(msg []byte, sig []byte) bool {
}
// GetPubKeys implements the PubKey.GetPubKeys method
func (m *LegacyAminoPubKey) GetPubKeys() []tmcrypto.PubKey {
func (m *LegacyAminoPubKey) GetPubKeys() []cryptotypes.PubKey {
if m != nil {
pubKeys := make([]tmcrypto.PubKey, len(m.PubKeys))
pubKeys := make([]cryptotypes.PubKey, len(m.PubKeys))
for i := 0; i < len(m.PubKeys); i++ {
pubKeys[i] = m.PubKeys[i].GetCachedValue().(tmcrypto.PubKey)
pubKeys[i] = m.PubKeys[i].GetCachedValue().(cryptotypes.PubKey)
}
return pubKeys
}
@ -113,7 +111,7 @@ func (m *LegacyAminoPubKey) GetPubKeys() []tmcrypto.PubKey {
// Equals returns true if m and other both have the same number of keys, and
// all constituent keys are the same, and in the same order.
func (m *LegacyAminoPubKey) Equals(key tmcrypto.PubKey) bool {
func (m *LegacyAminoPubKey) Equals(key cryptotypes.PubKey) bool {
otherKey, ok := key.(multisigtypes.PubKey)
if !ok {
return false
@ -145,7 +143,7 @@ func (m *LegacyAminoPubKey) Type() string {
// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces
func (m *LegacyAminoPubKey) UnpackInterfaces(unpacker types.AnyUnpacker) error {
for _, any := range m.PubKeys {
var pk crypto.PubKey
var pk cryptotypes.PubKey
err := unpacker.UnpackAny(any, &pk)
if err != nil {
return err
@ -154,11 +152,11 @@ func (m *LegacyAminoPubKey) UnpackInterfaces(unpacker types.AnyUnpacker) error {
return nil
}
func packPubKeys(pubKeys []tmcrypto.PubKey) ([]*types.Any, error) {
func packPubKeys(pubKeys []cryptotypes.PubKey) ([]*types.Any, error) {
anyPubKeys := make([]*types.Any, len(pubKeys))
for i := 0; i < len(pubKeys); i++ {
any, err := types.NewAnyWithValue(pubKeys[i].(proto.Message))
any, err := types.NewAnyWithValue(pubKeys[i])
if err != nil {
return nil, err
}

View File

@ -3,19 +3,16 @@ package multisig_test
import (
"testing"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec/types"
crypto "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
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"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)
func TestAddress(t *testing.T) {
@ -30,12 +27,12 @@ func TestEquals(t *testing.T) {
pubKey1 := secp256k1.GenPrivKey().PubKey()
pubKey2 := secp256k1.GenPrivKey().PubKey()
multisigKey := kmultisig.NewLegacyAminoPubKey(1, []tmcrypto.PubKey{pubKey1, pubKey2})
otherMultisigKey := kmultisig.NewLegacyAminoPubKey(1, []tmcrypto.PubKey{pubKey1, multisigKey})
multisigKey := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{pubKey1, pubKey2})
otherMultisigKey := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{pubKey1, multisigKey})
testCases := []struct {
msg string
other tmcrypto.PubKey
other cryptotypes.PubKey
expectEq bool
}{
{
@ -255,8 +252,8 @@ func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) {
ab, err := kmultisig.AminoCdc.MarshalBinaryLengthPrefixed(multisigKey)
require.NoError(t, err)
// like other crypto.Pubkey implementations (e.g. ed25519.PubKey),
// LegacyAminoPubKey should be deserializable into a crypto.LegacyAminoPubKey:
// like other cryptotypes.Pubkey implementations (e.g. ed25519.PubKey),
// LegacyAminoPubKey should be deserializable into a cryptotypes.LegacyAminoPubKey:
var pubKey kmultisig.LegacyAminoPubKey
err = kmultisig.AminoCdc.UnmarshalBinaryLengthPrefixed(ab, &pubKey)
require.NoError(t, err)
@ -264,8 +261,8 @@ func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) {
require.Equal(t, multisigKey.Equals(&pubKey), true)
}
func generatePubKeysAndSignatures(n int, msg []byte) (pubKeys []tmcrypto.PubKey, signatures []signing.SignatureData) {
pubKeys = make([]tmcrypto.PubKey, n)
func generatePubKeysAndSignatures(n int, msg []byte) (pubKeys []cryptotypes.PubKey, signatures []signing.SignatureData) {
pubKeys = make([]cryptotypes.PubKey, n)
signatures = make([]signing.SignatureData, n)
for i := 0; i < n; i++ {
@ -279,12 +276,12 @@ func generatePubKeysAndSignatures(n int, msg []byte) (pubKeys []tmcrypto.PubKey,
}
func generateNestedMultiSignature(n int, msg []byte) (multisig.PubKey, *signing.MultiSignatureData) {
pubKeys := make([]tmcrypto.PubKey, n)
pubKeys := make([]cryptotypes.PubKey, n)
signatures := make([]signing.SignatureData, n)
bitArray := crypto.NewCompactBitArray(n)
bitArray := cryptotypes.NewCompactBitArray(n)
for i := 0; i < n; i++ {
nestedPks, nestedSigs := generatePubKeysAndSignatures(5, msg)
nestedBitArray := crypto.NewCompactBitArray(5)
nestedBitArray := cryptotypes.NewCompactBitArray(5)
for j := 0; j < 5; j++ {
nestedBitArray.SetIndex(j, true)
}

View File

@ -4,13 +4,12 @@ import (
"io"
"testing"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys/internal/benchmarking"
"github.com/cosmos/cosmos-sdk/crypto/types"
)
func BenchmarkKeyGeneration(b *testing.B) {
benchmarkKeygenWrapper := func(reader io.Reader) crypto.PrivKey {
benchmarkKeygenWrapper := func(reader io.Reader) types.PrivKey {
priv := genPrivKey(reader)
return &PrivKey{Key: priv}
}

View File

@ -34,7 +34,7 @@ func (privKey *PrivKey) Bytes() []byte {
// PubKey performs the point-scalar multiplication from the privKey on the
// generator point to get the pubkey.
func (privKey *PrivKey) PubKey() crypto.PubKey {
func (privKey *PrivKey) PubKey() cryptotypes.PubKey {
_, pubkeyObject := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey.Key)
pk := pubkeyObject.SerializeCompressed()
return &PubKey{Key: pk}
@ -42,7 +42,7 @@ func (privKey *PrivKey) PubKey() crypto.PubKey {
// Equals - you probably don't need to use this.
// Runs in constant time based on length of the
func (privKey *PrivKey) Equals(other crypto.PrivKey) bool {
func (privKey *PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool {
return privKey.Type() == other.Type() && subtle.ConstantTimeCompare(privKey.Bytes(), other.Bytes()) == 1
}
@ -173,7 +173,7 @@ func (pubKey *PubKey) Type() string {
return keyType
}
func (pubKey *PubKey) Equals(other crypto.PubKey) bool {
func (pubKey *PubKey) Equals(other cryptotypes.PubKey) bool {
return pubKey.Type() == other.Type() && bytes.Equal(pubKey.Bytes(), other.Bytes())
}

View File

@ -12,9 +12,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/sr25519"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
@ -143,7 +143,7 @@ func TestPubKeyEquals(t *testing.T) {
testCases := []struct {
msg string
pubKey cryptotypes.PubKey
other crypto.PubKey
other cryptotypes.PubKey
expectEq bool
}{
{
@ -163,7 +163,7 @@ func TestPubKeyEquals(t *testing.T) {
{
"different types",
secp256K1PubKey,
sr25519.GenPrivKey().PubKey(),
ed25519.GenPrivKey().PubKey(),
false,
},
}
@ -182,7 +182,7 @@ func TestPrivKeyEquals(t *testing.T) {
testCases := []struct {
msg string
privKey cryptotypes.PrivKey
other crypto.PrivKey
other cryptotypes.PrivKey
expectEq bool
}{
{
@ -202,7 +202,7 @@ func TestPrivKeyEquals(t *testing.T) {
{
"different types",
secp256K1PrivKey,
sr25519.GenPrivKey(),
ed25519.GenPrivKey(),
false,
},
}

View File

@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
tcrypto "github.com/tendermint/tendermint/crypto"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
type byter interface {
@ -51,12 +51,12 @@ func TestNilEncodings(t *testing.T) {
require.EqualValues(t, a, b)
// Check nil PubKey.
var c, d tcrypto.PubKey
var c, d cryptotypes.PubKey
checkAminoJSON(t, &c, &d, true)
require.EqualValues(t, c, d)
// Check nil PrivKey.
var e, f tcrypto.PrivKey
var e, f cryptotypes.PrivKey
checkAminoJSON(t, &e, &f, true)
require.EqualValues(t, e, f)

View File

@ -8,10 +8,10 @@ import (
"github.com/pkg/errors"
tmbtcec "github.com/tendermint/btcd/btcec"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/types"
)
var (
@ -43,7 +43,7 @@ type (
// CachedPubKey should be private, but we want to encode it via
// go-amino so we can view the address later, even without having the
// ledger attached.
CachedPubKey tmcrypto.PubKey
CachedPubKey types.PubKey
Path hd.BIP44Params
}
)
@ -53,7 +53,7 @@ type (
// This function is marked as unsafe as it will retrieve a pubkey without user verification.
// It can only be used to verify a pubkey but never to create new accounts/keys. In that case,
// please refer to NewPrivKeySecp256k1
func NewPrivKeySecp256k1Unsafe(path hd.BIP44Params) (tmcrypto.PrivKey, error) {
func NewPrivKeySecp256k1Unsafe(path hd.BIP44Params) (types.LedgerPrivKey, error) {
device, err := getDevice()
if err != nil {
return nil, err
@ -70,7 +70,7 @@ func NewPrivKeySecp256k1Unsafe(path hd.BIP44Params) (tmcrypto.PrivKey, error) {
// NewPrivKeySecp256k1 will generate a new key and store the public key for later use.
// The request will require user confirmation and will show account and index in the device
func NewPrivKeySecp256k1(path hd.BIP44Params, hrp string) (tmcrypto.PrivKey, string, error) {
func NewPrivKeySecp256k1(path hd.BIP44Params, hrp string) (types.LedgerPrivKey, string, error) {
device, err := getDevice()
if err != nil {
return nil, "", err
@ -86,7 +86,7 @@ func NewPrivKeySecp256k1(path hd.BIP44Params, hrp string) (tmcrypto.PrivKey, str
}
// PubKey returns the cached public key.
func (pkl PrivKeyLedgerSecp256k1) PubKey() tmcrypto.PubKey {
func (pkl PrivKeyLedgerSecp256k1) PubKey() types.PubKey {
return pkl.CachedPubKey
}
@ -102,7 +102,7 @@ func (pkl PrivKeyLedgerSecp256k1) Sign(message []byte) ([]byte, error) {
}
// ShowAddress triggers a ledger device to show the corresponding address.
func ShowAddress(path hd.BIP44Params, expectedPubKey tmcrypto.PubKey,
func ShowAddress(path hd.BIP44Params, expectedPubKey types.PubKey,
accountAddressPrefix string) error {
device, err := getDevice()
if err != nil {
@ -154,7 +154,7 @@ func (pkl PrivKeyLedgerSecp256k1) Bytes() []byte {
// Equals implements the PrivKey interface. It makes sure two private keys
// refer to the same public key.
func (pkl PrivKeyLedgerSecp256k1) Equals(other tmcrypto.PrivKey) bool {
func (pkl PrivKeyLedgerSecp256k1) Equals(other types.LedgerPrivKey) bool {
if otherKey, ok := other.(PrivKeyLedgerSecp256k1); ok {
return pkl.CachedPubKey.Equals(otherKey.CachedPubKey)
}
@ -234,7 +234,7 @@ func sign(device SECP256K1, pkl PrivKeyLedgerSecp256k1, msg []byte) ([]byte, err
//
// since this involves IO, it may return an error, which is not exposed
// in the PubKey interface, so this function allows better error handling
func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (tmcrypto.PubKey, error) {
func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (types.PubKey, error) {
publicKey, err := device.GetPublicKeySECP256K1(path.DerivationPath())
if err != nil {
return nil, fmt.Errorf("please open Cosmos app on the Ledger device - error: %v", err)
@ -258,7 +258,7 @@ func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (tmcrypto.PubKey, er
//
// Since this involves IO, it may return an error, which is not exposed
// in the PubKey interface, so this function allows better error handling.
func getPubKeyAddrSafe(device SECP256K1, path hd.BIP44Params, hrp string) (tmcrypto.PubKey, string, error) {
func getPubKeyAddrSafe(device SECP256K1, path hd.BIP44Params, hrp string) (types.PubKey, string, error) {
publicKey, addr, err := device.GetAddressPubKeySECP256K1(path.DerivationPath(), hrp)
if err != nil {
return nil, "", fmt.Errorf("address %s rejected", addr)

View File

@ -6,10 +6,9 @@ import (
"github.com/stretchr/testify/require"
tmcrypto "github.com/tendermint/tendermint/crypto"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -58,7 +57,7 @@ func TestPublicKeyUnsafeHDPath(t *testing.T) {
const numIters = 10
privKeys := make([]tmcrypto.PrivKey, numIters)
privKeys := make([]types.LedgerPrivKey, numIters)
// Check with device
for i := uint32(0); i < 10; i++ {
@ -70,8 +69,8 @@ func TestPublicKeyUnsafeHDPath(t *testing.T) {
require.NotNil(t, priv)
// Check other methods
require.NoError(t, priv.(PrivKeyLedgerSecp256k1).ValidateKey())
tmp := priv.(PrivKeyLedgerSecp256k1)
require.NoError(t, tmp.ValidateKey())
(&tmp).AssertIsPrivKeyInner()
pubKeyAddr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, priv.PubKey())
@ -151,7 +150,7 @@ func TestPublicKeyHDPath(t *testing.T) {
const numIters = 10
privKeys := make([]tmcrypto.PrivKey, numIters)
privKeys := make([]types.LedgerPrivKey, numIters)
// Check with device
for i := uint32(0); i < 10; i++ {
@ -170,8 +169,8 @@ func TestPublicKeyHDPath(t *testing.T) {
"Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
// Check other methods
require.NoError(t, priv.(PrivKeyLedgerSecp256k1).ValidateKey())
tmp := priv.(PrivKeyLedgerSecp256k1)
require.NoError(t, tmp.ValidateKey())
(&tmp).AssertIsPrivKeyInner()
pubKeyAddr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, priv.PubKey())

View File

@ -4,8 +4,6 @@ import (
"fmt"
"strings"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
@ -27,7 +25,7 @@ func NewMultisig(n int) *signing.MultiSignatureData {
}
// GetIndex returns the index of pk in keys. Returns -1 if not found
func getIndex(pk crypto.PubKey, keys []crypto.PubKey) int {
func getIndex(pk types.PubKey, keys []types.PubKey) int {
for i := 0; i < len(keys); i++ {
if pk.Equals(keys[i]) {
return i
@ -60,7 +58,7 @@ func AddSignature(mSig *signing.MultiSignatureData, sig signing.SignatureData, i
// AddSignatureFromPubKey adds a signature to the multisig, at the index in
// keys corresponding to the provided pubkey.
func AddSignatureFromPubKey(mSig *signing.MultiSignatureData, sig signing.SignatureData, pubkey crypto.PubKey, keys []crypto.PubKey) error {
func AddSignatureFromPubKey(mSig *signing.MultiSignatureData, sig signing.SignatureData, pubkey types.PubKey, keys []types.PubKey) error {
if mSig == nil {
return fmt.Errorf("value of mSig is nil %v", mSig)
}
@ -85,6 +83,6 @@ func AddSignatureFromPubKey(mSig *signing.MultiSignatureData, sig signing.Signat
return nil
}
func AddSignatureV2(mSig *signing.MultiSignatureData, sig signing.SignatureV2, keys []crypto.PubKey) error {
func AddSignatureV2(mSig *signing.MultiSignatureData, sig signing.SignatureV2, keys []types.PubKey) error {
return AddSignatureFromPubKey(mSig, sig.Data, sig.PubKey, keys)
}

View File

@ -1,22 +1,21 @@
package multisig
import (
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
// PubKey defines a type which supports multi-signature verification via MultiSignatureData
// which supports multiple SignMode's.
type PubKey interface {
crypto.PubKey
types.PubKey
// VerifyMultisignature verifies the provide multi-signature represented by MultiSignatureData
// using getSignBytes to retrieve the sign bytes to verify against for the provided mode.
VerifyMultisignature(getSignBytes GetSignBytesFunc, sig *signing.MultiSignatureData) error
// GetPubKeys returns the crypto.PubKey's nested within the multi-sig PubKey
GetPubKeys() []crypto.PubKey
// GetPubKeys returns the types.PubKey's nested within the multi-sig PubKey
GetPubKeys() []types.PubKey
// GetThreshold returns the threshold number of signatures that must be obtained to verify a signature.
GetThreshold() uint

View File

@ -5,26 +5,39 @@ import (
tmcrypto "github.com/tendermint/tendermint/crypto"
)
// PubKey interface extends proto.Message
// and tendermint crypto.PubKey
// PubKey defines a public key and extends proto.Message.
type PubKey interface {
proto.Message
tmcrypto.PubKey
Address() Address
Bytes() []byte
VerifySignature(msg []byte, sig []byte) bool
Equals(PubKey) bool
Type() string
}
// PrivKey interface extends proto.Message
// and tendermint crypto.PrivKey
// LedgerPrivKey defines a private key that is not a proto message. For now,
// LedgerSecp256k1 keys are not converted to proto.Message yet, this is why
// they use LedgerPrivKey instead of PrivKey. All other keys must use PrivKey
// instead of LedgerPrivKey.
// TODO https://github.com/cosmos/cosmos-sdk/issues/7357.
type LedgerPrivKey interface {
Bytes() []byte
Sign(msg []byte) ([]byte, error)
PubKey() PubKey
Equals(LedgerPrivKey) bool
Type() string
}
// PrivKey defines a private key and extends proto.Message. For now, it extends
// LedgerPrivKey (see godoc for LedgerPrivKey). Ultimately, we should remove
// LedgerPrivKey and add its methods here directly.
// TODO https://github.com/cosmos/cosmos-sdk/issues/7357.
type PrivKey interface {
proto.Message
tmcrypto.PrivKey
LedgerPrivKey
}
type (
Address = tmcrypto.Address
)
// IntoTmPubKey allows our own PubKey types be converted into Tendermint's
// pubkey types.
type IntoTmPubKey interface {
AsTmPubKey() tmcrypto.PubKey
}

View File

@ -1,3 +1,2 @@
master master
v0.40.x v0.40
launchpad/backports v0.39

2
go.sum
View File

@ -595,8 +595,6 @@ github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=
github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4=
github.com/tendermint/tendermint v0.34.0-rc5 h1:2bnQfWyOMfTCbol5pwB8CgM2nxi6/Kz6zqlS6Udm/Cg=
github.com/tendermint/tendermint v0.34.0-rc5/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4=
github.com/tendermint/tendermint v0.34.0-rc6 h1:SVuKGvvE22KxfuK8QUHctUrmOWJsncZSYXIYtcnoKN0=
github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg=
github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM=

View File

@ -12,17 +12,17 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/ty
service Query {
// DenomTrace queries a denomination trace information.
rpc DenomTrace(QueryDenomTraceRequest) returns (QueryDenomTraceResponse) {
option (google.api.http).get = "/ibc_transfer/v1beta1/denom_traces/{hash}";
option (google.api.http).get = "/ibc/applications/transfer/v1beta1/denom_traces/{hash}";
}
// DenomTraces queries all denomination traces.
rpc DenomTraces(QueryDenomTracesRequest) returns (QueryDenomTracesResponse) {
option (google.api.http).get = "/ibc_transfer/v1beta1/denom_traces";
option (google.api.http).get = "/ibc/applications/transfer/v1beta1/denom_traces";
}
// Params queries all parameters of the ibc-transfer module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/ibc_transfer/v1beta1/params";
option (google.api.http).get = "/ibc/applications/transfer/v1beta1/params";
}
}

View File

@ -14,79 +14,79 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/types";
service Query {
// Channel queries an IBC Channel.
rpc Channel(QueryChannelRequest) returns (QueryChannelResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}";
}
// Channels queries all the IBC channels of a chain.
rpc Channels(QueryChannelsRequest) returns (QueryChannelsResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels";
}
// ConnectionChannels queries all the channels associated with a connection
// end.
rpc ConnectionChannels(QueryConnectionChannelsRequest) returns (QueryConnectionChannelsResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/connections/{connection}/channels";
option (google.api.http).get = "/ibc/core/channel/v1beta1/connections/{connection}/channels";
}
// ChannelClientState queries for the client state for the channel associated
// with the provided channel identifiers.
rpc ChannelClientState(QueryChannelClientStateRequest) returns (QueryChannelClientStateResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/client_state";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/client_state";
}
// ChannelConsensusState queries for the consensus state for the channel
// associated with the provided channel identifiers.
rpc ChannelConsensusState(QueryChannelConsensusStateRequest) returns (QueryChannelConsensusStateResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/consensus_state/version/"
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/consensus_state/version/"
"{version_number}/height/{version_height}";
}
// PacketCommitment queries a stored packet commitment hash.
rpc PacketCommitment(QueryPacketCommitmentRequest) returns (QueryPacketCommitmentResponse) {
option (google.api.http).get =
"/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{sequence}";
"/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/{sequence}";
}
// PacketCommitments returns all the packet commitments hashes associated
// with a channel.
rpc PacketCommitments(QueryPacketCommitmentsRequest) returns (QueryPacketCommitmentsResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments";
}
// PacketReceipt queries if a given packet sequence has been received on the queried chain
rpc PacketReceipt(QueryPacketReceiptRequest) returns (QueryPacketReceiptResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_receipts/{sequence}";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_receipts/{sequence}";
}
// PacketAcknowledgement queries a stored packet acknowledgement hash.
rpc PacketAcknowledgement(QueryPacketAcknowledgementRequest) returns (QueryPacketAcknowledgementResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acks/{sequence}";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acks/{sequence}";
}
// PacketAcknowledgements returns all the packet acknowledgements associated
// with a channel.
rpc PacketAcknowledgements(QueryPacketAcknowledgementsRequest) returns (QueryPacketAcknowledgementsResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acknowledgements";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_acknowledgements";
}
// UnreceivedPackets returns all the unreceived IBC packets associated with a
// channel and sequences.
rpc UnreceivedPackets(QueryUnreceivedPacketsRequest) returns (QueryUnreceivedPacketsResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/"
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/"
"{packet_commitment_sequences}/unreceived_packets";
}
// UnreceivedAcks returns all the unreceived IBC acknowledgements associated with a
// channel and sequences.
rpc UnreceivedAcks(QueryUnreceivedAcksRequest) returns (QueryUnreceivedAcksResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/"
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/packet_commitments/"
"{packet_ack_sequences}/unreceived_acks";
}
// NextSequenceReceive returns the next receive sequence for a given channel.
rpc NextSequenceReceive(QueryNextSequenceReceiveRequest) returns (QueryNextSequenceReceiveResponse) {
option (google.api.http).get = "/ibc/channel/v1beta1/channels/{channel_id}/ports/{port_id}/next_sequence";
option (google.api.http).get = "/ibc/core/channel/v1beta1/channels/{channel_id}/ports/{port_id}/next_sequence";
}
}

View File

@ -6,91 +6,6 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
// Msg defines the ibc/client Msg service.
service Msg {
// CreateClient defines a rpc handler method for MsgCreateClient.
rpc CreateClient(MsgCreateClient) returns (MsgCreateClientResponse);
// UpdateClient defines a rpc handler method for MsgUpdateClient.
rpc UpdateClient(MsgUpdateClient) returns (MsgUpdateClientResponse);
// UpgradeClient defines a rpc handler method for MsgUpgradeClient.
rpc UpgradeClient(MsgUpgradeClient) returns (MsgUpgradeClientResponse);
// SubmitMisbehaviour defines a rpc handler method for MsgSubmitMisbehaviour.
rpc SubmitMisbehaviour(MsgSubmitMisbehaviour) returns (MsgSubmitMisbehaviourResponse);
}
// MsgCreateClient defines a message to create an IBC client
message MsgCreateClient {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// light client state
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
// consensus state associated with the client that corresponds to a given
// height.
google.protobuf.Any consensus_state = 3 [(gogoproto.moretags) = "yaml:\"consensus_state\""];
// signer address
string signer = 4;
}
// MsgCreateClientResponse defines the Msg/CreateClient response type.
message MsgCreateClientResponse { }
// MsgUpdateClient defines an sdk.Msg to update a IBC client state using
// the given header.
message MsgUpdateClient {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// header to update the light client
google.protobuf.Any header = 2;
// signer address
string signer = 3;
}
// MsgUpdateClientResponse defines the Msg/UpdateClient response type.
message MsgUpdateClientResponse { }
// MsgUpgradeClient defines an sdk.Msg to upgrade an IBC client to a new client state
message MsgUpgradeClient {
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// upgraded client state
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
// height at which old chain halts and upgrades (i.e last block executed)
Height upgrade_height = 3 [(gogoproto.moretags) = "yaml:\"upgrade_height\""];
// proof that old chain committed to new client
bytes proof_upgrade = 4 [(gogoproto.moretags) = "yaml:\"proof_upgrade\""];
// signer address
string signer = 5;
}
// MsgUpgradeClientResponse defines the Msg/UpgradeClient response type.
message MsgUpgradeClientResponse { }
// MsgSubmitMisbehaviour defines an sdk.Msg type that submits Evidence for
// light client misbehaviour.
message MsgSubmitMisbehaviour {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// misbehaviour used for freezing the light client
google.protobuf.Any misbehaviour = 2;
// signer address
string signer = 3;
}
// MsgSubmitMisbehaviourResponse defines the Msg/SubmitMisbehaviour response type.
message MsgSubmitMisbehaviourResponse { }
// IdentifiedClientState defines a client state with an additional client
// identifier field.
message IdentifiedClientState {
@ -151,3 +66,9 @@ message Height {
// the height within the given version
uint64 version_height = 2 [(gogoproto.moretags) = "yaml:\"version_height\""];
}
// Params defines the set of IBC light client parameters.
message Params {
// allowed_clients defines the list of allowed client state types.
repeated string allowed_clients = 1 [(gogoproto.moretags) = "yaml:\"allowed_clients\""];
}

View File

@ -9,13 +9,17 @@ import "gogoproto/gogo.proto";
// GenesisState defines the ibc client submodule's genesis state.
message GenesisState {
// client states with their corresponding identifiers
repeated IdentifiedClientState clients = 1 [(gogoproto.nullable) = false];
repeated IdentifiedClientState clients = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "IdentifiedClientStates"
];
// consensus states from each client
repeated ClientConsensusStates clients_consensus = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "ClientsConsensusStates",
(gogoproto.moretags) = "yaml:\"clients_consensus\""
];
Params params = 3 [ (gogoproto.nullable) = false];
// create localhost on initialization
bool create_localhost = 3 [(gogoproto.moretags) = "yaml:\"create_localhost\""];
bool create_localhost = 4 [(gogoproto.moretags) = "yaml:\"create_localhost\""];
}

View File

@ -13,25 +13,30 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types";
service Query {
// ClientState queries an IBC light client.
rpc ClientState(QueryClientStateRequest) returns (QueryClientStateResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/client_states/{client_id}";
option (google.api.http).get = "/ibc/core/client/v1beta1/client_states/{client_id}";
}
// ClientStates queries all the IBC light clients of a chain.
rpc ClientStates(QueryClientStatesRequest) returns (QueryClientStatesResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/client_states";
option (google.api.http).get = "/ibc/core/client/v1beta1/client_states";
}
// ConsensusState queries a consensus state associated with a client state at
// a given height.
rpc ConsensusState(QueryConsensusStateRequest) returns (QueryConsensusStateResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/consensus_states/{client_id}/version/{version_number}/"
option (google.api.http).get = "/ibc/core/client/v1beta1/consensus_states/{client_id}/version/{version_number}/"
"height/{version_height}";
}
// ConsensusStates queries all the consensus state associated with a given
// client.
rpc ConsensusStates(QueryConsensusStatesRequest) returns (QueryConsensusStatesResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/consensus_states/{client_id}";
option (google.api.http).get = "/ibc/core/client/v1beta1/consensus_states/{client_id}";
}
// ClientParams queries all parameters of the ibc client.
rpc ClientParams(QueryClientParamsRequest) returns (QueryClientParamsResponse) {
option (google.api.http).get = "/ibc/client/v1beta1/params";
}
}
@ -65,7 +70,10 @@ message QueryClientStatesRequest {
// method.
message QueryClientStatesResponse {
// list of stored ClientStates of the chain.
repeated IdentifiedClientState client_states = 1;
repeated IdentifiedClientState client_states = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "IdentifiedClientStates"
];
// pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
@ -113,3 +121,12 @@ message QueryConsensusStatesResponse {
// pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryClientParamsRequest is the request type for the Query/ClientParams RPC method.
message QueryClientParamsRequest {}
// QueryClientParamsResponse is the response type for the Query/ClientParams RPC method.
message QueryClientParamsResponse {
// params defines the parameters of the module.
Params params = 1;
}

View File

@ -0,0 +1,93 @@
syntax = "proto3";
package ibc.core.client.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "ibc/core/client/v1/client.proto";
// Msg defines the ibc/client Msg service.
service Msg {
// CreateClient defines a rpc handler method for MsgCreateClient.
rpc CreateClient(MsgCreateClient) returns (MsgCreateClientResponse);
// UpdateClient defines a rpc handler method for MsgUpdateClient.
rpc UpdateClient(MsgUpdateClient) returns (MsgUpdateClientResponse);
// UpgradeClient defines a rpc handler method for MsgUpgradeClient.
rpc UpgradeClient(MsgUpgradeClient) returns (MsgUpgradeClientResponse);
// SubmitMisbehaviour defines a rpc handler method for MsgSubmitMisbehaviour.
rpc SubmitMisbehaviour(MsgSubmitMisbehaviour) returns (MsgSubmitMisbehaviourResponse);
}
// MsgCreateClient defines a message to create an IBC client
message MsgCreateClient {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// light client state
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
// consensus state associated with the client that corresponds to a given
// height.
google.protobuf.Any consensus_state = 3 [(gogoproto.moretags) = "yaml:\"consensus_state\""];
// signer address
string signer = 4;
}
// MsgCreateClientResponse defines the Msg/CreateClient response type.
message MsgCreateClientResponse { }
// MsgUpdateClient defines an sdk.Msg to update a IBC client state using
// the given header.
message MsgUpdateClient {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// header to update the light client
google.protobuf.Any header = 2;
// signer address
string signer = 3;
}
// MsgUpdateClientResponse defines the Msg/UpdateClient response type.
message MsgUpdateClientResponse { }
// MsgUpgradeClient defines an sdk.Msg to upgrade an IBC client to a new client state
message MsgUpgradeClient {
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// upgraded client state
google.protobuf.Any client_state = 2 [(gogoproto.moretags) = "yaml:\"client_state\""];
// height at which old chain halts and upgrades (i.e last block executed)
Height upgrade_height = 3 [(gogoproto.moretags) = "yaml:\"upgrade_height\""];
// proof that old chain committed to new client
bytes proof_upgrade = 4 [(gogoproto.moretags) = "yaml:\"proof_upgrade\""];
// signer address
string signer = 5;
}
// MsgUpgradeClientResponse defines the Msg/UpgradeClient response type.
message MsgUpgradeClientResponse { }
// MsgSubmitMisbehaviour defines an sdk.Msg type that submits Evidence for
// light client misbehaviour.
message MsgSubmitMisbehaviour {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
// client unique identifier
string client_id = 1 [(gogoproto.moretags) = "yaml:\"client_id\""];
// misbehaviour used for freezing the light client
google.protobuf.Any misbehaviour = 2;
// signer address
string signer = 3;
}
// MsgSubmitMisbehaviourResponse defines the Msg/SubmitMisbehaviour response type.
message MsgSubmitMisbehaviourResponse { }

View File

@ -4,7 +4,7 @@ package ibc.core.commitment.v1;
option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/23-commitment/types";
import "gogoproto/gogo.proto";
import "tendermint/crypto/proof.proto";
import "confio/proofs.proto";
// MerkleRoot defines a merkle root hash.
// In the Cosmos SDK, the AppHash of a block header becomes the root.
@ -23,42 +23,18 @@ message MerklePrefix {
// MerklePath is the path used to verify commitment proofs, which can be an
// arbitrary structured object (defined by a commitment type).
// MerklePath is represented from root-to-leaf
message MerklePath {
option (gogoproto.goproto_stringer) = false;
KeyPath key_path = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"key_path\""];
repeated string key_path = 1 [(gogoproto.moretags) = "yaml:\"key_path\""];
}
// MerkleProof is a wrapper type that contains a merkle proof.
// MerkleProof is a wrapper type over a chain of CommitmentProofs.
// It demonstrates membership or non-membership for an element or set of
// elements, verifiable in conjunction with a known commitment root. Proofs
// should be succinct.
// MerkleProofs are ordered from leaf-to-root
message MerkleProof {
tendermint.crypto.ProofOps proof = 1;
}
// KeyPath defines a slice of keys
message KeyPath {
option (gogoproto.goproto_stringer) = false;
option (gogoproto.goproto_getters) = false;
repeated Key keys = 1;
}
// Key defines a proof Key
message Key {
option (gogoproto.goproto_getters) = false;
bytes name = 1;
KeyEncoding enc = 2;
}
// KeyEncoding defines the encoding format of a key's bytes.
enum KeyEncoding {
option (gogoproto.goproto_enum_prefix) = false;
// URL encoding
KEY_ENCODING_URL_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "URL"];
// Hex encoding
KEY_ENCODING_HEX = 1 [(gogoproto.enumvalue_customname) = "HEX"];
}
repeated ics23.CommitmentProof proofs = 1;
}

View File

@ -14,30 +14,30 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/ibc/core/03-connection/types
service Query {
// Connection queries an IBC connection end.
rpc Connection(QueryConnectionRequest) returns (QueryConnectionResponse) {
option (google.api.http).get = "/ibc/connection/v1beta1/connections/{connection_id}";
option (google.api.http).get = "/ibc/core/connection/v1beta1/connections/{connection_id}";
}
// Connections queries all the IBC connections of a chain.
rpc Connections(QueryConnectionsRequest) returns (QueryConnectionsResponse) {
option (google.api.http).get = "/ibc/connection/v1beta1/connections";
option (google.api.http).get = "/ibc/core/connection/v1beta1/connections";
}
// ClientConnections queries the connection paths associated with a client
// state.
rpc ClientConnections(QueryClientConnectionsRequest) returns (QueryClientConnectionsResponse) {
option (google.api.http).get = "/ibc/connection/v1beta1/client_connections/{client_id}";
option (google.api.http).get = "/ibc/core/connection/v1beta1/client_connections/{client_id}";
}
// ConnectionClientState queries the client state associated with the
// connection.
rpc ConnectionClientState(QueryConnectionClientStateRequest) returns (QueryConnectionClientStateResponse) {
option (google.api.http).get = "/ibc/connection/v1beta1/connections/{connection_id}/client_state";
option (google.api.http).get = "/ibc/core/connection/v1beta1/connections/{connection_id}/client_state";
}
// ConnectionConsensusState queries the consensus state associated with the
// connection.
rpc ConnectionConsensusState(QueryConnectionConsensusStateRequest) returns (QueryConnectionConsensusStateResponse) {
option (google.api.http).get = "/ibc/connection/v1beta1/connections/{connection_id}/consensus_state/"
option (google.api.http).get = "/ibc/core/connection/v1beta1/connections/{connection_id}/consensus_state/"
"version/{version_number}/height/{version_height}";
}
}

View File

@ -106,8 +106,8 @@ message Header {
.tendermint.types.ValidatorSet trusted_validators = 4 [(gogoproto.moretags) = "yaml:\"trusted_validators\""];
}
// Fraction defines the protobuf message type for tmmath.Fraction
// Fraction defines the protobuf message type for tmmath.Fraction that only supports positive values.
message Fraction {
int64 numerator = 1;
int64 denominator = 2;
uint64 numerator = 1;
uint64 denominator = 2;
}

View File

@ -252,12 +252,20 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}
ctx.Logger.Debug("Initialization: tmNode started")
// Add the tx service to the gRPC router.
app.RegisterTxService(clientCtx)
config := config.GetConfig(ctx.Viper)
// Add the tx service to the gRPC router. We only need to register this
// service if API or gRPC is enabled, and avoid doing so in the general
// case, because it spawns a new local tendermint RPC client.
if config.API.Enable || config.GRPC.Enable {
clientCtx = clientCtx.
WithClient(local.New(tmNode))
app.RegisterTxService(clientCtx)
}
var apiSrv *api.Server
config := config.GetConfig(ctx.Viper)
if config.API.Enable {
genDoc, err := genDocProvider()
if err != nil {
@ -266,8 +274,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
clientCtx := clientCtx.
WithHomeDir(home).
WithChainID(genDoc.ChainID).
WithClient(local.New(tmNode))
WithChainID(genDoc.ChainID)
apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server"))
app.RegisterAPIRoutes(apiSrv, config.API)

View File

@ -39,7 +39,7 @@ func ShowNodeIDCmd() *cobra.Command {
}
}
// ShowValidator - ported from Tendermint, show this node's validator info
// ShowValidatorCmd - ported from Tendermint, show this node's validator info
func ShowValidatorCmd() *cobra.Command {
cmd := cobra.Command{
Use: "show-validator",
@ -59,12 +59,16 @@ func ShowValidatorCmd() *cobra.Command {
return printlnJSON(valPubKey)
}
pubkey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey)
pubkey, err := cryptocodec.FromTmPubKeyInterface(valPubKey)
if err != nil {
return err
}
pubkeyBech32, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubkey)
if err != nil {
return err
}
fmt.Println(pubkey)
fmt.Println(pubkeyBech32)
return nil
},
}

View File

@ -279,7 +279,7 @@ func NewSimApp(
// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper,
)
// register the proposal types
@ -609,6 +609,7 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
return paramsKeeper
}

View File

@ -4,9 +4,8 @@ import (
"math/rand"
"time"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
@ -20,7 +19,7 @@ const (
)
// GenTx generates a signed mock transaction.
func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...crypto.PrivKey) (sdk.Tx, error) {
func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) {
sigs := make([]signing.SignatureV2, len(priv))
// create a random length memo

View File

@ -12,7 +12,6 @@ import (
"github.com/spf13/cobra"
tmconfig "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
tmos "github.com/tendermint/tendermint/libs/os"
tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/types"
@ -23,6 +22,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -116,7 +116,7 @@ func InitTestnet(
}
nodeIDs := make([]string, numValidators)
valPubKeys := make([]crypto.PubKey, numValidators)
valPubKeys := make([]cryptotypes.PubKey, numValidators)
simappConfig := srvconfig.DefaultConfig()
simappConfig.MinGasPrices = minGasPrices
@ -311,7 +311,7 @@ func initGenFiles(
func collectGenFiles(
clientCtx client.Context, nodeConfig *tmconfig.Config, chainID string,
nodeIDs []string, valPubKeys []crypto.PubKey, numValidators int,
nodeIDs []string, valPubKeys []cryptotypes.PubKey, numValidators int,
outputDir, nodeDirPrefix, nodeDaemonHome string, genBalIterator banktypes.GenesisBalancesIterator,
) error {

View File

@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
@ -20,7 +19,9 @@ import (
bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
@ -92,10 +93,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
bondAmt := sdk.NewInt(1000000)
for _, val := range valSet.Validators {
// Currently validator requires tmcrypto.ed25519 keys, which don't support
// our Marshaling interfaces, so we need to pack them into our version of ed25519.
// There is ongoing work to add secp256k1 keys (https://github.com/cosmos/cosmos-sdk/pull/7604).
pk, err := ed25519.FromTmEd25519(val.PubKey)
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
require.NoError(t, err)
pkAny, err := codectypes.PackAny(pk)
require.NoError(t, err)
@ -230,7 +228,7 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress {
}
// AddTestAddrsFromPubKeys adds the addresses into the SimApp providing only the public keys.
func AddTestAddrsFromPubKeys(app *SimApp, ctx sdk.Context, pubKeys []crypto.PubKey, accAmt sdk.Int) {
func AddTestAddrsFromPubKeys(app *SimApp, ctx sdk.Context, pubKeys []cryptotypes.PubKey, accAmt sdk.Int) {
initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
setTotalSupply(app, ctx, accAmt, len(pubKeys))
@ -328,7 +326,7 @@ func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.C
// returned.
func SignCheckDeliver(
t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...crypto.PrivKey,
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
tx, err := helpers.GenTx(
@ -377,7 +375,7 @@ func SignCheckDeliver(
// GenSequenceOfTxs generates a set of signed transactions of messages, such
// that they differ only by having the sequence numbers incremented between
// every transaction.
func GenSequenceOfTxs(txGen client.TxConfig, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...crypto.PrivKey) ([]sdk.Tx, error) {
func GenSequenceOfTxs(txGen client.TxConfig, msgs []sdk.Msg, accNums []uint64, initSeqNums []uint64, numToGenerate int, priv ...cryptotypes.PrivKey) ([]sdk.Tx, error) {
txs := make([]sdk.Tx, numToGenerate)
var err error
for i := 0; i < numToGenerate; i++ {
@ -407,8 +405,8 @@ func incrementAllSequenceNumbers(initSeqNums []uint64) {
}
// CreateTestPubKeys returns a total of numPubKeys public keys in ascending order.
func CreateTestPubKeys(numPubKeys int) []crypto.PubKey {
var publicKeys []crypto.PubKey
func CreateTestPubKeys(numPubKeys int) []cryptotypes.PubKey {
var publicKeys []cryptotypes.PubKey
var buffer bytes.Buffer
// start at 10 to avoid changing 1 to 01, 2 to 02, etc
@ -424,7 +422,7 @@ func CreateTestPubKeys(numPubKeys int) []crypto.PubKey {
}
// NewPubKeyFromHex returns a PubKey from a hex string.
func NewPubKeyFromHex(pk string) (res crypto.PubKey) {
func NewPubKeyFromHex(pk string) (res cryptotypes.PubKey) {
pkBytes, err := hex.DecodeString(pk)
if err != nil {
panic(err)

View File

@ -6,9 +6,9 @@ package mocks
import (
client "github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
types "github.com/cosmos/cosmos-sdk/types"
gomock "github.com/golang/mock/gomock"
crypto "github.com/tendermint/tendermint/crypto"
reflect "reflect"
)
@ -50,10 +50,10 @@ func (mr *MockAccountMockRecorder) GetAddress() *gomock.Call {
}
// GetPubKey mocks base method
func (m *MockAccount) GetPubKey() crypto.PubKey {
func (m *MockAccount) GetPubKey() cryptotypes.PubKey {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPubKey")
ret0, _ := ret[0].(crypto.PubKey)
ret0, _ := ret[0].(cryptotypes.PubKey)
return ret0
}

View File

@ -16,7 +16,6 @@ import (
"github.com/stretchr/testify/require"
tmcfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
tmflags "github.com/tendermint/tendermint/libs/cli/flags"
"github.com/tendermint/tendermint/libs/log"
tmrand "github.com/tendermint/tendermint/libs/rand"
@ -32,6 +31,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
@ -148,7 +148,7 @@ type (
Ctx *server.Context
Dir string
NodeID string
PubKey crypto.PubKey
PubKey cryptotypes.PubKey
Moniker string
APIAddress string
RPCAddress string
@ -184,7 +184,7 @@ func New(t *testing.T, cfg Config) *Network {
monikers := make([]string, cfg.NumValidators)
nodeIDs := make([]string, cfg.NumValidators)
valPubKeys := make([]crypto.PubKey, cfg.NumValidators)
valPubKeys := make([]cryptotypes.PubKey, cfg.NumValidators)
var (
genAccounts []authtypes.GenesisAccount

View File

@ -3,14 +3,13 @@ package testdata
import (
"encoding/json"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// KeyTestPubAddr generates a new secp256k1 keypair.
func KeyTestPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
func KeyTestPubAddr() (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
key := secp256k1.GenPrivKey()
pub := key.PubKey()
addr := sdk.AccAddress(pub.Address())

View File

@ -8,16 +8,12 @@ import (
"fmt"
"strings"
"github.com/tendermint/tendermint/crypto"
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
yaml "gopkg.in/yaml.v2"
"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/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
@ -452,7 +448,7 @@ func ConsAddressFromBech32(address string) (addr ConsAddress, err error) {
}
// get ConsAddress from pubkey
func GetConsAddress(pubkey crypto.PubKey) ConsAddress {
func GetConsAddress(pubkey cryptotypes.PubKey) ConsAddress {
return ConsAddress(pubkey.Address())
}
@ -616,7 +612,8 @@ const (
// Bech32ifyPubKey returns a Bech32 encoded string containing the appropriate
// prefix based on the key type provided for a given PublicKey.
func Bech32ifyPubKey(pkt Bech32PubKeyType, pubkey crypto.PubKey) (string, error) {
// TODO: Remove Bech32ifyPubKey and all usages (cosmos/cosmos-sdk/issues/#7357)
func Bech32ifyPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) (string, error) {
var bech32Prefix string
switch pkt {
@ -631,22 +628,11 @@ func Bech32ifyPubKey(pkt Bech32PubKeyType, pubkey crypto.PubKey) (string, error)
}
// 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))
return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.MustMarshalBinaryBare(pubkey))
}
// MustBech32ifyPubKey calls Bech32ifyPubKey except it panics on error.
func MustBech32ifyPubKey(pkt Bech32PubKeyType, pubkey crypto.PubKey) string {
func MustBech32ifyPubKey(pkt Bech32PubKeyType, pubkey cryptotypes.PubKey) string {
res, err := Bech32ifyPubKey(pkt, pubkey)
if err != nil {
panic(err)
@ -657,7 +643,7 @@ func MustBech32ifyPubKey(pkt Bech32PubKeyType, pubkey crypto.PubKey) string {
// GetPubKeyFromBech32 returns a PublicKey from a bech32-encoded PublicKey with
// a given key type.
func GetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) (crypto.PubKey, error) {
func GetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) (cryptotypes.PubKey, error) {
var bech32Prefix string
switch pkt {
@ -677,36 +663,11 @@ func GetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) (crypto.PubKey,
return nil, err
}
aminoPk, err := cryptocodec.PubKeyFromBytes(bz)
if err != nil {
return nil, err
}
var protoPk crypto.PubKey
switch aminoPk.(type) {
// We are bech32ifying some secp256k1 keys in tests.
case *secp256k1.PubKey:
protoPk = aminoPk
case *ed25519.PubKey:
protoPk = aminoPk
// Real-life case.
case tmed25519.PubKey:
protoPk = &ed25519.PubKey{
Key: aminoPk.Bytes(),
}
default:
// We only allow ed25519 pubkeys to be bech32-ed right now.
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "bech32 pubkey does not support %T", aminoPk)
}
return protoPk, nil
return cryptocodec.PubKeyFromBytes(bz)
}
// MustGetPubKeyFromBech32 calls GetPubKeyFromBech32 except it panics on error.
func MustGetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) crypto.PubKey {
func MustGetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) cryptotypes.PubKey {
res, err := GetPubKeyFromBech32(pkt, pubkeyStr)
if err != nil {
panic(err)

View File

@ -10,11 +10,11 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"
"gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
)
@ -509,7 +509,7 @@ func (s *addressTestSuite) TestGetConsAddress() {
pk := secp256k1.GenPrivKey().PubKey()
s.Require().NotEqual(types.GetConsAddress(pk), pk.Address())
s.Require().True(bytes.Equal(types.GetConsAddress(pk).Bytes(), pk.Address().Bytes()))
s.Require().Panics(func() { types.GetConsAddress(crypto.PubKey(nil)) })
s.Require().Panics(func() { types.GetConsAddress(cryptotypes.PubKey(nil)) })
}
func (s *addressTestSuite) TestGetFromBech32() {

View File

@ -12,13 +12,13 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"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"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
@ -176,15 +176,15 @@ func TestParseQueryHeight(t *testing.T) {
func TestProcessPostResponse(t *testing.T) {
// mock account
// PubKey field ensures amino encoding is used first since standard
// JSON encoding will panic on crypto.PubKey
// JSON encoding will panic on cryptotypes.PubKey
t.Parallel()
type mockAccount struct {
Address types.AccAddress `json:"address"`
Coins types.Coins `json:"coins"`
PubKey crypto.PubKey `json:"public_key"`
AccountNumber uint64 `json:"account_number"`
Sequence uint64 `json:"sequence"`
Address types.AccAddress `json:"address"`
Coins types.Coins `json:"coins"`
PubKey cryptotypes.PubKey `json:"public_key"`
AccountNumber uint64 `json:"account_number"`
Sequence uint64 `json:"sequence"`
}
// setup

View File

@ -3,10 +3,9 @@ package simulation
import (
"math/rand"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -14,10 +13,10 @@ import (
// eventually more useful data can be placed in here.
// (e.g. number of coins)
type Account struct {
PrivKey crypto.PrivKey
PubKey crypto.PubKey
PrivKey cryptotypes.PrivKey
PubKey cryptotypes.PubKey
Address sdk.AccAddress
ConsKey crypto.PrivKey
ConsKey cryptotypes.PrivKey
}
// Equals returns true if two accounts are equal

View File

@ -3,9 +3,8 @@ package signing
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
// SignatureV2 is a convenience type that is easier to use in application logic
@ -15,7 +14,7 @@ import (
// signatures.
type SignatureV2 struct {
// PubKey is the public key to use for verifying the signature
PubKey crypto.PubKey
PubKey cryptotypes.PubKey
// Data is the actual data of the signature which includes SignMode's and
// the signatures themselves for either single or multi-signatures.
@ -104,5 +103,5 @@ func (sds *SignatureDescriptors) UnpackInterfaces(unpacker codectypes.AnyUnpacke
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (sd *SignatureDescriptor) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(sd.PublicKey, new(crypto.PubKey))
return unpacker.UnpackAny(sd.PublicKey, new(cryptotypes.PubKey))
}

View File

@ -4,9 +4,8 @@ import (
"fmt"
"strings"
"github.com/tendermint/tendermint/crypto"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -180,7 +179,7 @@ func (m *AuthInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (m *SignerInfo) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(m.PublicKey, new(crypto.PubKey))
return unpacker.UnpackAny(m.PublicKey, new(cryptotypes.PubKey))
}
// RegisterInterfaces registers the sdk.Tx interface.

View File

@ -1,9 +1,8 @@
package types
import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/crypto"
)
type (
@ -42,7 +41,7 @@ type (
// Signature defines an interface for an application application-defined
// concrete transaction type to be able to set and return transaction signatures.
Signature interface {
GetPubKey() crypto.PubKey
GetPubKey() cryptotypes.PubKey
GetSignature() []byte
}

View File

@ -17,6 +17,7 @@ func NewVersionCommand() *cobra.Command {
Short: "Print the application binary version information",
RunE: func(cmd *cobra.Command, _ []string) error {
verInfo := NewInfo()
cmd.SetOut(cmd.OutOrStdout())
if long, _ := cmd.Flags().GetBool(flagLong); !long {
cmd.Println(verInfo.Version)

View File

@ -17,8 +17,10 @@
package version
import (
"encoding/json"
"fmt"
"runtime"
"runtime/debug"
)
var (
@ -36,12 +38,13 @@ var (
// Info defines the application version information.
type Info struct {
Name string `json:"name" yaml:"name"`
AppName string `json:"server_name" yaml:"server_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
Name string `json:"name" yaml:"name"`
AppName string `json:"server_name" yaml:"server_name"`
Version string `json:"version" yaml:"version"`
GitCommit string `json:"commit" yaml:"commit"`
BuildTags string `json:"build_tags" yaml:"build_tags"`
GoVersion string `json:"go" yaml:"go"`
BuildDeps []buildDep `json:"build_deps" yaml:"build_deps"`
}
func NewInfo() Info {
@ -52,6 +55,7 @@ func NewInfo() Info {
GitCommit: Commit,
BuildTags: BuildTags,
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
BuildDeps: depsFromBuildInfo(),
}
}
@ -63,3 +67,24 @@ build tags: %s
vi.Name, vi.Version, vi.GitCommit, vi.BuildTags, vi.GoVersion,
)
}
func depsFromBuildInfo() (deps []buildDep) {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return nil
}
for _, dep := range buildInfo.Deps {
deps = append(deps, buildDep{dep})
}
return
}
type buildDep struct {
*debug.Module
}
func (d buildDep) String() string { return fmt.Sprintf("%s@%s", d.Path, d.Version) }
func (d buildDep) MarshalJSON() ([]byte, error) { return json.Marshal(d.String()) }
func (d buildDep) MarshalYAML() (interface{}, error) { return d.String(), nil }

View File

@ -1,4 +1,4 @@
package version
package version_test
import (
"encoding/json"
@ -11,10 +11,11 @@ import (
"github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/version"
)
func TestNewInfo(t *testing.T) {
info := NewInfo()
info := version.NewInfo()
want := fmt.Sprintf(`:
git commit:
build tags:
@ -23,7 +24,7 @@ build tags:
}
func TestInfo_String(t *testing.T) {
info := Info{
info := version.Info{
Name: "testapp",
AppName: "testappd",
Version: "1.0.0",
@ -39,12 +40,12 @@ go version go1.14 linux/amd64`
}
func Test_runVersionCmd(t *testing.T) {
cmd := NewVersionCommand()
cmd := version.NewVersionCommand()
_, mockOut := testutil.ApplyMockIO(cmd)
cmd.SetArgs([]string{
fmt.Sprintf("--%s=''", cli.OutputFlag),
fmt.Sprintf("--%s=false", flagLong),
"--long=false",
})
require.NoError(t, cmd.Execute())
@ -52,11 +53,10 @@ func Test_runVersionCmd(t *testing.T) {
mockOut.Reset()
cmd.SetArgs([]string{
fmt.Sprintf("--%s=json", cli.OutputFlag),
fmt.Sprintf("--%s=true", flagLong),
fmt.Sprintf("--%s=json", cli.OutputFlag), "--long=true",
})
info := NewInfo()
info := version.NewInfo()
stringInfo, err := json.Marshal(info)
require.NoError(t, err)
require.NoError(t, cmd.Execute())

View File

@ -8,11 +8,11 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"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"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -35,7 +35,7 @@ func (suite *AnteTestSuite) TestSimulateGasCost() {
feeAmount := testdata.NewTestFeeAmount()
gasLimit := testdata.NewTestGasLimit()
accSeqs := []uint64{0, 0, 0}
privs := []crypto.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}
privs := []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}
accNums := []uint64{0, 1, 2}
testCases := []TestCase{
@ -91,7 +91,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSigErrors() {
// Variable data per test case
var (
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accNums []uint64
accSeqs []uint64
)
@ -100,7 +100,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSigErrors() {
{
"check no signatures fails",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{}, []uint64{}, []uint64{}
privs, accNums, accSeqs = []cryptotypes.PrivKey{}, []uint64{}, []uint64{}
// Create tx manually to test the tx's signers
suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...))
@ -117,7 +117,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSigErrors() {
{
"num sigs dont match GetSigners",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{priv0}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{priv0}, []uint64{0}, []uint64{0}
},
false,
false,
@ -126,7 +126,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSigErrors() {
{
"unrecognized account",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{priv0, priv1, priv2}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{priv0, priv1, priv2}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
},
false,
false,
@ -169,7 +169,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbers() {
var (
accNums []uint64
msgs []sdk.Msg
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accSeqs []uint64
)
@ -180,7 +180,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbers() {
msg := testdata.NewTestMsg(accounts[0].acc.GetAddress())
msgs = []sdk.Msg{msg}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
true,
@ -189,7 +189,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbers() {
{
"new tx from wrong account number",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{1}, []uint64{1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{1}, []uint64{1}
},
false,
false,
@ -198,7 +198,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbers() {
{
"new tx from correct account number",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{1}
},
false,
true,
@ -210,7 +210,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbers() {
msg1 := testdata.NewTestMsg(accounts[0].acc.GetAddress(), accounts[1].acc.GetAddress())
msg2 := testdata.NewTestMsg(accounts[1].acc.GetAddress(), accounts[0].acc.GetAddress())
msgs = []sdk.Msg{msg1, msg2}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{1, 0}, []uint64{2, 0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{1, 0}, []uint64{2, 0}
},
false,
false,
@ -219,7 +219,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbers() {
{
"new tx with correct account numbers",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 1}, []uint64{2, 0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 1}, []uint64{2, 0}
},
false,
true,
@ -251,7 +251,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbersAtBlockHeightZero() {
var (
accNums []uint64
msgs []sdk.Msg
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accSeqs []uint64
)
@ -262,7 +262,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbersAtBlockHeightZero() {
msg := testdata.NewTestMsg(accounts[0].acc.GetAddress())
msgs = []sdk.Msg{msg}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
true,
@ -271,7 +271,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbersAtBlockHeightZero() {
{
"new tx from wrong account number",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{1}, []uint64{1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{1}, []uint64{1}
},
false,
false,
@ -280,7 +280,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbersAtBlockHeightZero() {
{
"new tx from correct account number",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{1}
},
false,
true,
@ -293,7 +293,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbersAtBlockHeightZero() {
msg2 := testdata.NewTestMsg(accounts[1].acc.GetAddress(), accounts[0].acc.GetAddress())
msgs = []sdk.Msg{msg1, msg2}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{1, 0}, []uint64{2, 0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{1, 0}, []uint64{2, 0}
},
false,
false,
@ -303,7 +303,7 @@ func (suite *AnteTestSuite) TestAnteHandlerAccountNumbersAtBlockHeightZero() {
"new tx with another signer and correct account numbers",
func() {
// Note that accNums is [0,0] at block 0.
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 0}, []uint64{2, 0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 0}, []uint64{2, 0}
},
false,
true,
@ -334,7 +334,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSequences() {
var (
accNums []uint64
msgs []sdk.Msg
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accSeqs []uint64
)
@ -345,7 +345,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSequences() {
msg := testdata.NewTestMsg(accounts[0].acc.GetAddress())
msgs = []sdk.Msg{msg}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
true,
@ -354,7 +354,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSequences() {
{
"test sending it again fails (replay protection)",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
false,
@ -363,7 +363,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSequences() {
{
"fix sequence, should pass",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{1}
},
false,
true,
@ -376,7 +376,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSequences() {
msg2 := testdata.NewTestMsg(accounts[2].acc.GetAddress(), accounts[0].acc.GetAddress())
msgs = []sdk.Msg{msg1, msg2}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}, []uint64{0, 1, 2}, []uint64{2, 0, 0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}, []uint64{0, 1, 2}, []uint64{2, 0, 0}
},
false,
true,
@ -394,7 +394,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSequences() {
func() {
msg := testdata.NewTestMsg(accounts[1].acc.GetAddress())
msgs = []sdk.Msg{msg}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{0}
},
false,
false,
@ -415,7 +415,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSequences() {
msg := testdata.NewTestMsg(accounts[0].acc.GetAddress(), accounts[1].acc.GetAddress())
msgs = []sdk.Msg{msg}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 1}, []uint64{3, 2}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 1}, []uint64{3, 2}
},
false,
true,
@ -445,7 +445,7 @@ func (suite *AnteTestSuite) TestAnteHandlerFees() {
msgs := []sdk.Msg{testdata.NewTestMsg(addr0)}
feeAmount := testdata.NewTestFeeAmount()
gasLimit := testdata.NewTestGasLimit()
privs, accNums, accSeqs := []crypto.PrivKey{priv0}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv0}, []uint64{0}, []uint64{0}
testCases := []struct {
desc string
@ -517,7 +517,7 @@ func (suite *AnteTestSuite) TestAnteHandlerMemoGas() {
// Same data for every test cases
accounts := suite.CreateTestAccounts(1)
msgs := []sdk.Msg{testdata.NewTestMsg(accounts[0].acc.GetAddress())}
privs, accNums, accSeqs := []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
// Variable data per test case
var (
@ -596,7 +596,7 @@ func (suite *AnteTestSuite) TestAnteHandlerMultiSigner() {
var (
accNums []uint64
msgs []sdk.Msg
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accSeqs []uint64
)
@ -605,7 +605,7 @@ func (suite *AnteTestSuite) TestAnteHandlerMultiSigner() {
"signers in order",
func() {
msgs = []sdk.Msg{msg1, msg2, msg3}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
suite.txBuilder.SetMemo("Check signers are in expected order and different account numbers works")
},
false,
@ -616,7 +616,7 @@ func (suite *AnteTestSuite) TestAnteHandlerMultiSigner() {
"change sequence numbers (only accounts 0 and 1 sign)",
func() {
msgs = []sdk.Msg{msg1}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 1}, []uint64{1, 1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv}, []uint64{0, 1}, []uint64{1, 1}
},
false,
true,
@ -626,7 +626,7 @@ func (suite *AnteTestSuite) TestAnteHandlerMultiSigner() {
"change sequence numbers (only accounts 1 and 2 sign)",
func() {
msgs = []sdk.Msg{msg2}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[2].priv, accounts[0].priv}, []uint64{2, 0}, []uint64{1, 2}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[2].priv, accounts[0].priv}, []uint64{2, 0}, []uint64{1, 2}
},
false,
true,
@ -636,7 +636,7 @@ func (suite *AnteTestSuite) TestAnteHandlerMultiSigner() {
"everyone signs again",
func() {
msgs = []sdk.Msg{msg1, msg2, msg3}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}, []uint64{0, 1, 2}, []uint64{3, 2, 2}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv, accounts[1].priv, accounts[2].priv}, []uint64{0, 1, 2}, []uint64{3, 2, 2}
},
false,
true,
@ -668,7 +668,7 @@ func (suite *AnteTestSuite) TestAnteHandlerBadSignBytes() {
feeAmount sdk.Coins
gasLimit uint64
msgs []sdk.Msg
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accSeqs []uint64
)
@ -680,7 +680,7 @@ func (suite *AnteTestSuite) TestAnteHandlerBadSignBytes() {
feeAmount = testdata.NewTestFeeAmount()
gasLimit = testdata.NewTestGasLimit()
msgs = []sdk.Msg{msg0}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
true,
@ -752,7 +752,7 @@ func (suite *AnteTestSuite) TestAnteHandlerBadSignBytes() {
func() {
feeAmount = testdata.NewTestFeeAmount()
gasLimit = testdata.NewTestGasLimit()
privs, accNums, accSeqs = []crypto.PrivKey{accounts[1].priv}, []uint64{0}, []uint64{1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[1].priv}, []uint64{0}, []uint64{1}
},
false,
false,
@ -762,7 +762,7 @@ func (suite *AnteTestSuite) TestAnteHandlerBadSignBytes() {
"test wrong signer if public doesn't exist",
func() {
msgs = []sdk.Msg{testdata.NewTestMsg(accounts[1].acc.GetAddress())}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{1}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{1}, []uint64{0}
},
false,
false,
@ -792,7 +792,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() {
var (
accNums []uint64
msgs []sdk.Msg
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accSeqs []uint64
)
@ -800,7 +800,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() {
{
"test good tx",
func() {
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
msgs = []sdk.Msg{testdata.NewTestMsg(accounts[0].acc.GetAddress())}
},
false,
@ -835,7 +835,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() {
acc1 := suite.app.AccountKeeper.GetAccount(suite.ctx, accounts[1].acc.GetAddress())
suite.Require().Nil(acc1.GetPubKey())
privs, accNums, accSeqs = []crypto.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{0}
msgs = []sdk.Msg{testdata.NewTestMsg(accounts[1].acc.GetAddress())}
suite.txBuilder.SetMsgs(msgs...)
suite.txBuilder.SetFeeAmount(feeAmount)
@ -858,7 +858,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() {
suite.Require().Nil(acc1.GetPubKey())
// Set incorrect accSeq, to generate incorrect signature.
privs, accNums, accSeqs = []crypto.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{1}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[1].priv}, []uint64{1}, []uint64{1}
},
false,
false,
@ -888,11 +888,11 @@ func (suite *AnteTestSuite) TestAnteHandlerSetPubKey() {
}
}
func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []crypto.PubKey, signatures [][]byte) {
pubkeys = make([]crypto.PubKey, n)
func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptotypes.PubKey, signatures [][]byte) {
pubkeys = make([]cryptotypes.PubKey, n)
signatures = make([][]byte, n)
for i := 0; i < n; i++ {
var privkey crypto.PrivKey
var privkey cryptotypes.PrivKey
privkey = secp256k1.GenPrivKey()
// TODO: also generate ed25519 keys as below when ed25519 keys are
@ -910,7 +910,7 @@ func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []crypto.P
return
}
func expectedGasCostByKeys(pubkeys []crypto.PubKey) uint64 {
func expectedGasCostByKeys(pubkeys []cryptotypes.PubKey) uint64 {
cost := uint64(0)
for _, pubkey := range pubkeys {
pubkeyType := strings.ToLower(fmt.Sprintf("%T", pubkey))
@ -927,8 +927,8 @@ func expectedGasCostByKeys(pubkeys []crypto.PubKey) uint64 {
}
func TestCountSubkeys(t *testing.T) {
genPubKeys := func(n int) []crypto.PubKey {
var ret []crypto.PubKey
genPubKeys := func(n int) []cryptotypes.PubKey {
var ret []cryptotypes.PubKey
for i := 0; i < n; i++ {
ret = append(ret, secp256k1.GenPrivKey().PubKey())
}
@ -938,10 +938,10 @@ func TestCountSubkeys(t *testing.T) {
singleLevelMultiKey := kmultisig.NewLegacyAminoPubKey(4, genPubKeys(5))
multiLevelSubKey1 := kmultisig.NewLegacyAminoPubKey(4, genPubKeys(5))
multiLevelSubKey2 := kmultisig.NewLegacyAminoPubKey(4, genPubKeys(5))
multiLevelMultiKey := kmultisig.NewLegacyAminoPubKey(2, []crypto.PubKey{
multiLevelMultiKey := kmultisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{
multiLevelSubKey1, multiLevelSubKey2, secp256k1.GenPrivKey().PubKey()})
type args struct {
pub crypto.PubKey
pub cryptotypes.PubKey
}
testCases := []struct {
name string
@ -965,7 +965,7 @@ func (suite *AnteTestSuite) TestAnteHandlerSigLimitExceeded() {
// Same data for every test cases
accounts := suite.CreateTestAccounts(8)
var addrs []sdk.AccAddress
var privs []crypto.PrivKey
var privs []cryptotypes.PrivKey
for i := 0; i < 8; i++ {
addrs = append(addrs, accounts[i].acc.GetAddress())
privs = append(privs, accounts[i].priv)
@ -1019,7 +1019,7 @@ func (suite *AnteTestSuite) TestCustomSignatureVerificationGasConsumer() {
var (
accNums []uint64
msgs []sdk.Msg
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accSeqs []uint64
)
@ -1028,7 +1028,7 @@ func (suite *AnteTestSuite) TestCustomSignatureVerificationGasConsumer() {
"verify that an secp256k1 account gets rejected",
func() {
msgs = []sdk.Msg{testdata.NewTestMsg(accounts[0].acc.GetAddress())}
privs, accNums, accSeqs = []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
},
false,
false,
@ -1067,7 +1067,7 @@ func (suite *AnteTestSuite) TestAnteHandlerReCheck() {
suite.txBuilder.SetMemo("thisisatestmemo")
// test that operations skipped on recheck do not run
privs, accNums, accSeqs := []crypto.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{accounts[0].priv}, []uint64{0}, []uint64{0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)

View File

@ -1,10 +1,9 @@
package ante
import (
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
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/types/tx/signing"
@ -110,7 +109,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
continue
}
var pubkey crypto.PubKey
var pubkey cryptotypes.PubKey
acc := cgts.ak.GetAccount(ctx, signer)

View File

@ -3,13 +3,11 @@ package ante_test
import (
"strings"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/tendermint/tendermint/crypto"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"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"
)
@ -28,7 +26,7 @@ func (suite *AnteTestSuite) TestValidateBasic() {
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
privs, accNums, accSeqs := []crypto.PrivKey{}, []uint64{}, []uint64{}
privs, accNums, accSeqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{}
invalidTx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
@ -38,7 +36,7 @@ func (suite *AnteTestSuite) TestValidateBasic() {
suite.Require().NotNil(err, "Did not error on invalid tx")
privs, accNums, accSeqs = []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs = []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
validTx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
@ -69,7 +67,7 @@ func (suite *AnteTestSuite) TestValidateMemo() {
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
privs, accNums, accSeqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
suite.txBuilder.SetMemo(strings.Repeat("01234567890", 500))
invalidTx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
@ -120,7 +118,7 @@ func (suite *AnteTestSuite) TestConsumeGasForTxSize() {
suite.txBuilder.SetGasLimit(gasLimit)
suite.txBuilder.SetMemo(strings.Repeat("01234567890", 10))
privs, accNums, accSeqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
@ -214,7 +212,7 @@ func (suite *AnteTestSuite) TestTxHeightTimeoutDecorator() {
suite.txBuilder.SetMemo(strings.Repeat("01234567890", 10))
suite.txBuilder.SetTimeoutHeight(tc.timeout)
privs, accNums, accSeqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)

View File

@ -1,10 +1,9 @@
package ante_test
import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
)
@ -27,7 +26,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() {
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
privs, accNums, accSeqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
@ -76,7 +75,7 @@ func (suite *AnteTestSuite) TestDeductFees() {
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
privs, accNums, accSeqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)

View File

@ -1,10 +1,8 @@
package ante_test
import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/tendermint/tendermint/crypto"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
@ -25,7 +23,7 @@ func (suite *AnteTestSuite) TestSetup() {
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
privs, accNums, accSeqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
@ -60,7 +58,7 @@ func (suite *AnteTestSuite) TestRecoverPanic() {
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
privs, accNums, accSeqs := []crypto.PrivKey{priv1}, []uint64{0}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)

View File

@ -5,11 +5,10 @@ import (
"encoding/hex"
"fmt"
"github.com/tendermint/tendermint/crypto"
"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"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -424,7 +423,7 @@ func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (types
}
// CountSubKeys counts the total number of keys for a multi-sig public key.
func CountSubKeys(pub crypto.PubKey) int {
func CountSubKeys(pub cryptotypes.PubKey) int {
v, ok := pub.(*kmultisig.LegacyAminoPubKey)
if !ok {
return 1

View File

@ -3,13 +3,12 @@ package ante_test
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
"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"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
@ -30,7 +29,7 @@ func (suite *AnteTestSuite) TestSetPubKey() {
priv3, pub3, addr3 := testdata.KeyTestPubAddr()
addrs := []sdk.AccAddress{addr1, addr2, addr3}
pubs := []crypto.PubKey{pub1, pub2, pub3}
pubs := []cryptotypes.PubKey{pub1, pub2, pub3}
msgs := make([]sdk.Msg, len(addrs))
// set accounts and create msg for each address
@ -47,7 +46,7 @@ func (suite *AnteTestSuite) TestSetPubKey() {
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
privs, accNums, accSeqs := []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
@ -85,7 +84,7 @@ func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() {
type args struct {
meter sdk.GasMeter
sig signing.SignatureData
pubkey crypto.PubKey
pubkey cryptotypes.PubKey
params types.Params
}
tests := []struct {
@ -148,20 +147,20 @@ func (suite *AnteTestSuite) TestSigVerification() {
type testCase struct {
name string
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accNums []uint64
accSeqs []uint64
recheck bool
shouldErr bool
}
testCases := []testCase{
{"no signers", []crypto.PrivKey{}, []uint64{}, []uint64{}, false, true},
{"not enough signers", []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}, false, true},
{"wrong order signers", []crypto.PrivKey{priv3, priv2, priv1}, []uint64{2, 1, 0}, []uint64{0, 0, 0}, false, true},
{"wrong accnums", []crypto.PrivKey{priv1, priv2, priv3}, []uint64{7, 8, 9}, []uint64{0, 0, 0}, false, true},
{"wrong sequences", []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{3, 4, 5}, false, true},
{"valid tx", []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}, false, false},
{"no err on recheck", []crypto.PrivKey{}, []uint64{}, []uint64{}, true, false},
{"no signers", []cryptotypes.PrivKey{}, []uint64{}, []uint64{}, false, true},
{"not enough signers", []cryptotypes.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}, false, true},
{"wrong order signers", []cryptotypes.PrivKey{priv3, priv2, priv1}, []uint64{2, 1, 0}, []uint64{0, 0, 0}, false, true},
{"wrong accnums", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{7, 8, 9}, []uint64{0, 0, 0}, false, true},
{"wrong sequences", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{3, 4, 5}, false, true},
{"valid tx", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}, false, false},
{"no err on recheck", []cryptotypes.PrivKey{}, []uint64{}, []uint64{}, true, false},
}
for i, tc := range testCases {
suite.ctx = suite.ctx.WithIsReCheckTx(tc.recheck)
@ -233,20 +232,20 @@ func (suite *AnteTestSuite) TestSigVerification_ExplicitAmino() {
type testCase struct {
name string
privs []crypto.PrivKey
privs []cryptotypes.PrivKey
accNums []uint64
accSeqs []uint64
recheck bool
shouldErr bool
}
testCases := []testCase{
{"no signers", []crypto.PrivKey{}, []uint64{}, []uint64{}, false, true},
{"not enough signers", []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}, false, true},
{"wrong order signers", []crypto.PrivKey{priv3, priv2, priv1}, []uint64{2, 1, 0}, []uint64{0, 0, 0}, false, true},
{"wrong accnums", []crypto.PrivKey{priv1, priv2, priv3}, []uint64{7, 8, 9}, []uint64{0, 0, 0}, false, true},
{"wrong sequences", []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{3, 4, 5}, false, true},
{"valid tx", []crypto.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}, false, false},
{"no err on recheck", []crypto.PrivKey{}, []uint64{}, []uint64{}, true, false},
{"no signers", []cryptotypes.PrivKey{}, []uint64{}, []uint64{}, false, true},
{"not enough signers", []cryptotypes.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}, false, true},
{"wrong order signers", []cryptotypes.PrivKey{priv3, priv2, priv1}, []uint64{2, 1, 0}, []uint64{0, 0, 0}, false, true},
{"wrong accnums", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{7, 8, 9}, []uint64{0, 0, 0}, false, true},
{"wrong sequences", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{3, 4, 5}, false, true},
{"valid tx", []cryptotypes.PrivKey{priv1, priv2, priv3}, []uint64{0, 1, 2}, []uint64{0, 0, 0}, false, false},
{"no err on recheck", []cryptotypes.PrivKey{}, []uint64{}, []uint64{}, true, false},
}
for i, tc := range testCases {
suite.ctx = suite.ctx.WithIsReCheckTx(tc.recheck)
@ -270,7 +269,7 @@ func (suite *AnteTestSuite) TestSigVerification_ExplicitAmino() {
func (suite *AnteTestSuite) TestSigIntegration() {
// generate private keys
privs := []crypto.PrivKey{
privs := []cryptotypes.PrivKey{
secp256k1.GenPrivKey(),
secp256k1.GenPrivKey(),
secp256k1.GenPrivKey(),
@ -288,7 +287,7 @@ func (suite *AnteTestSuite) TestSigIntegration() {
suite.Require().Equal(initialSigCost*uint64(len(privs)), doubleCost-initialCost)
}
func (suite *AnteTestSuite) runSigDecorators(params types.Params, _ bool, privs ...crypto.PrivKey) (sdk.Gas, error) {
func (suite *AnteTestSuite) runSigDecorators(params types.Params, _ bool, privs ...cryptotypes.PrivKey) (sdk.Gas, error) {
suite.SetupTest(true) // setup
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()
@ -343,7 +342,7 @@ func (suite *AnteTestSuite) TestIncrementSequenceDecorator() {
msgs := []sdk.Msg{testdata.NewTestMsg(addr)}
suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...))
privs := []crypto.PrivKey{priv}
privs := []cryptotypes.PrivKey{priv}
accNums := []uint64{suite.app.AccountKeeper.GetAccount(suite.ctx, addr).GetAccountNumber()}
accSeqs := []uint64{suite.app.AccountKeeper.GetAccount(suite.ctx, addr).GetSequence()}
feeAmount := testdata.NewTestFeeAmount()

View File

@ -6,11 +6,11 @@ import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
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"
@ -24,7 +24,7 @@ import (
// TestAccount represents an account used in the tests in x/auth/ante.
type TestAccount struct {
acc types.AccountI
priv crypto.PrivKey
priv cryptotypes.PrivKey
}
// AnteTestSuite is a test suite to be used with ante handler tests.
@ -86,7 +86,7 @@ func (suite *AnteTestSuite) CreateTestAccounts(numAccs int) []TestAccount {
}
// CreateTestTx is a helper function to create a tx given multiple inputs.
func (suite *AnteTestSuite) CreateTestTx(privs []crypto.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
func (suite *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
// First round: we gather all the signer infos. We use the "set empty
// signature" hack to do that.
var sigsV2 []signing.SignatureV2
@ -142,7 +142,7 @@ type TestCase struct {
}
// CreateTestTx is a helper function to create a tx given multiple inputs.
func (suite *AnteTestSuite) RunTestCase(privs []crypto.PrivKey, msgs []sdk.Msg, feeAmount sdk.Coins, gasLimit uint64, accNums, accSeqs []uint64, chainID string, tc TestCase) {
func (suite *AnteTestSuite) RunTestCase(privs []cryptotypes.PrivKey, msgs []sdk.Msg, feeAmount sdk.Coins, gasLimit uint64, accNums, accSeqs []uint64, chainID string, tc TestCase) {
suite.Run(fmt.Sprintf("Case %s", tc.desc), func() {
suite.Require().NoError(suite.txBuilder.SetMsgs(msgs...))
suite.txBuilder.SetFeeAmount(feeAmount)

View File

@ -1,5 +1,3 @@
// +build norace
package cli_test
import (
@ -12,7 +10,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
tmcrypto "github.com/tendermint/tendermint/crypto"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client"
@ -22,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
@ -63,7 +61,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
account2, _, err := kb.NewMnemonic("newAccount2", keyring.English, sdk.FullFundraiserPath, hd.Secp256k1)
s.Require().NoError(err)
multi := kmultisig.NewLegacyAminoPubKey(2, []tmcrypto.PubKey{account1.GetPubKey(), account2.GetPubKey()})
multi := kmultisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{account1.GetPubKey(), account2.GetPubKey()})
_, err = kb.SaveMultisig("multi", multi)
s.Require().NoError(err)

View File

@ -4,10 +4,10 @@ import (
"fmt"
gogotypes "github.com/gogo/protobuf/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/log"
"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/auth/types"
@ -35,7 +35,7 @@ type AccountKeeperI interface {
IterateAccounts(sdk.Context, func(types.AccountI) bool)
// Fetch the public key of an account at a specified address
GetPubKey(sdk.Context, sdk.AccAddress) (crypto.PubKey, error)
GetPubKey(sdk.Context, sdk.AccAddress) (cryptotypes.PubKey, error)
// Fetch the sequence of an account at a specified address.
GetSequence(sdk.Context, sdk.AccAddress) (uint64, error)
@ -90,7 +90,7 @@ func (ak AccountKeeper) Logger(ctx sdk.Context) log.Logger {
}
// GetPubKey Returns the PubKey of the account at address
func (ak AccountKeeper) GetPubKey(ctx sdk.Context, addr sdk.AccAddress) (crypto.PubKey, error) {
func (ak AccountKeeper) GetPubKey(ctx sdk.Context, addr sdk.AccAddress) (cryptotypes.PubKey, error) {
acc := ak.GetAccount(ctx, addr)
if acc == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)

View File

@ -3,11 +3,10 @@ package legacytx
import (
"encoding/json"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -57,8 +56,8 @@ func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee,
// Deprecated: StdSignature represents a sig
type StdSignature struct {
crypto.PubKey `json:"pub_key" yaml:"pub_key"` // optional
Signature []byte `json:"signature" yaml:"signature"`
cryptotypes.PubKey `json:"pub_key" yaml:"pub_key"` // optional
Signature []byte `json:"signature" yaml:"signature"`
}
// StdSignatureToSignatureV2 converts a StdSignature to a SignatureV2
@ -75,7 +74,7 @@ func StdSignatureToSignatureV2(cdc *codec.LegacyAmino, sig StdSignature) (signin
}, nil
}
func pubKeySigToSigData(cdc *codec.LegacyAmino, key crypto.PubKey, sig []byte) (signing.SignatureData, error) {
func pubKeySigToSigData(cdc *codec.LegacyAmino, key cryptotypes.PubKey, sig []byte) (signing.SignatureData, error) {
multiPK, ok := key.(multisig.PubKey)
if !ok {
return &signing.SingleSignatureData{

View File

@ -3,11 +3,11 @@ package legacytx
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
"gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/codec/legacy"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
@ -73,7 +73,7 @@ func (fee StdFee) GasPrices() sdk.DecCoins {
}
// Deprecated
func NewStdSignature(pk crypto.PubKey, sig []byte) StdSignature {
func NewStdSignature(pk cryptotypes.PubKey, sig []byte) StdSignature {
return StdSignature{PubKey: pk, Signature: sig}
}
@ -82,9 +82,9 @@ func (ss StdSignature) GetSignature() []byte {
return ss.Signature
}
// GetPubKey returns the public key of a signature as a crypto.PubKey using the
// GetPubKey returns the public key of a signature as a cryptotypes.PubKey using the
// Amino codec.
func (ss StdSignature) GetPubKey() crypto.PubKey {
func (ss StdSignature) GetPubKey() cryptotypes.PubKey {
return ss.PubKey
}
@ -238,8 +238,8 @@ func (tx StdTx) GetSignaturesV2() ([]signing.SignatureV2, error) {
// GetPubkeys returns the pubkeys of signers if the pubkey is included in the signature
// If pubkey is not included in the signature, then nil is in the slice instead
func (tx StdTx) GetPubKeys() []crypto.PubKey {
pks := make([]crypto.PubKey, len(tx.Signatures))
func (tx StdTx) GetPubKeys() []cryptotypes.PubKey {
pks := make([]cryptotypes.PubKey, len(tx.Signatures))
for i, stdSig := range tx.Signatures {
pks[i] = stdSig.GetPubKey()

View File

@ -5,7 +5,6 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
yaml "gopkg.in/yaml.v2"
@ -15,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -39,7 +39,7 @@ func NewTestStdFee() StdFee {
}
// Deprecated, use TxBuilder.
func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums []uint64, seqs []uint64, timeout uint64, fee StdFee) sdk.Tx {
func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []cryptotypes.PrivKey, accNums []uint64, seqs []uint64, timeout uint64, fee StdFee) sdk.Tx {
sigs := make([]StdSignature, len(privs))
for i, priv := range privs {
signBytes := StdSignBytes(ctx.ChainID(), accNums[i], seqs[i], timeout, fee, msgs, "")
@ -126,7 +126,7 @@ func TestTxValidateBasic(t *testing.T) {
require.Equal(t, sdkerrors.ErrInsufficientFee.ABCICode(), code)
// require to fail validation when no signatures exist
privs, accNums, seqs := []crypto.PrivKey{}, []uint64{}, []uint64{}
privs, accNums, seqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{}
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, 0, fee)
err = tx.ValidateBasic()
@ -135,7 +135,7 @@ func TestTxValidateBasic(t *testing.T) {
require.Equal(t, sdkerrors.ErrNoSignatures.ABCICode(), code)
// require to fail validation when signatures do not match expected signers
privs, accNums, seqs = []crypto.PrivKey{priv1}, []uint64{0, 1}, []uint64{0, 0}
privs, accNums, seqs = []cryptotypes.PrivKey{priv1}, []uint64{0, 1}, []uint64{0, 0}
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, 0, fee)
err = tx.ValidateBasic()
@ -154,7 +154,7 @@ func TestTxValidateBasic(t *testing.T) {
require.Equal(t, sdkerrors.ErrInvalidRequest.ABCICode(), code)
// require to pass when above criteria are matched
privs, accNums, seqs = []crypto.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}
privs, accNums, seqs = []cryptotypes.PrivKey{priv1, priv2}, []uint64{0, 1}, []uint64{0, 0}
tx = NewTestTx(ctx, msgs, privs, accNums, seqs, 0, fee)
err = tx.ValidateBasic()
@ -231,7 +231,7 @@ func TestSignatureV2Conversions(t *testing.T) {
// multisigs
_, pubKey2, _ := testdata.KeyTestPubAddr()
multiPK := kmultisig.NewLegacyAminoPubKey(1, []crypto.PubKey{
multiPK := kmultisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{
pubKey, pubKey2,
})
dummy2 := []byte("dummySig2")

View File

@ -11,9 +11,11 @@ import (
"sort"
"strings"
"github.com/tendermint/tendermint/crypto"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
)
@ -45,11 +47,11 @@ type (
}
BaseAccount struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey crypto.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey cryptotypes.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
}
baseAccountPretty struct {
@ -127,7 +129,7 @@ func NewBaseAccountWithAddress(addr sdk.AccAddress) BaseAccount {
}
func NewBaseAccount(
address sdk.AccAddress, coins sdk.Coins, pk crypto.PubKey, accountNumber, sequence uint64,
address sdk.AccAddress, coins sdk.Coins, pk cryptotypes.PubKey, accountNumber, sequence uint64,
) *BaseAccount {
return &BaseAccount{
@ -259,7 +261,7 @@ func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error {
}
var (
pk crypto.PubKey
pk cryptotypes.PubKey
err error
)
@ -328,7 +330,7 @@ func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error {
}
var (
pk crypto.PubKey
pk cryptotypes.PubKey
err error
)
@ -394,7 +396,7 @@ func (dva *DelayedVestingAccount) UnmarshalJSON(bz []byte) error {
}
var (
pk crypto.PubKey
pk cryptotypes.PubKey
err error
)
@ -417,7 +419,7 @@ func (dva *DelayedVestingAccount) UnmarshalJSON(bz []byte) error {
}
func NewModuleAddress(name string) sdk.AccAddress {
return sdk.AccAddress(crypto.AddressHash([]byte(name)))
return sdk.AccAddress(tmcrypto.AddressHash([]byte(name)))
}
func NewModuleAccount(baseAccount *BaseAccount, name string, permissions ...string) *ModuleAccount {
@ -437,7 +439,7 @@ func (ma ModuleAccount) Validate() error {
return errors.New("module account name cannot be blank")
}
if !ma.Address.Equals(sdk.AccAddress(crypto.AddressHash([]byte(ma.Name)))) {
if !ma.Address.Equals(sdk.AccAddress(tmcrypto.AddressHash([]byte(ma.Name)))) {
return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name)
}
@ -517,6 +519,7 @@ func ValidateGenAccounts(genAccounts GenesisAccounts) error {
}
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cryptocodec.RegisterCrypto(cdc)
cdc.RegisterInterface((*GenesisAccount)(nil), nil)
cdc.RegisterInterface((*Account)(nil), nil)
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/Account", nil)

View File

@ -0,0 +1,104 @@
package v039_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
)
func TestMigrate(t *testing.T) {
aminoCdc := codec.NewLegacyAmino()
v039auth.RegisterLegacyAminoCodec(aminoCdc)
pub1 := ed25519.GenPrivKeyFromSecret([]byte("acc1")).PubKey()
pub2 := secp256k1.GenPrivKeyFromSecret([]byte("acc2")).PubKey()
acc1 := v038auth.BaseAccount{
Address: sdk.AccAddress(pub1.Address()),
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000)),
Sequence: 1,
AccountNumber: 1,
PubKey: pub1,
}
acc2 := v038auth.BaseAccount{
Address: sdk.AccAddress(pub2.Address()),
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 400000)),
Sequence: 2,
AccountNumber: 2,
PubKey: pub2,
}
migrated := v039auth.Migrate(
v038auth.GenesisState{
Accounts: v038auth.GenesisAccounts{&acc1, &acc2},
},
)
expectedAcc1 := v039auth.NewBaseAccount(acc1.Address, acc1.Coins, acc1.PubKey, acc1.AccountNumber, acc1.Sequence)
expectedAcc2 := v039auth.NewBaseAccount(acc2.Address, acc2.Coins, acc2.PubKey, acc2.AccountNumber, acc2.Sequence)
require.Equal(
t, migrated, v039auth.GenesisState{
Accounts: v038auth.GenesisAccounts{expectedAcc1, expectedAcc2},
},
)
json, err := aminoCdc.MarshalJSONIndent(migrated, "", " ")
require.NoError(t, err)
expectedJSON := `{
"params": {
"max_memo_characters": "0",
"tx_sig_limit": "0",
"tx_size_cost_per_byte": "0",
"sig_verify_cost_ed25519": "0",
"sig_verify_cost_secp256k1": "0"
},
"accounts": [
{
"type": "cosmos-sdk/Account",
"value": {
"address": "cosmos1j7skdhh9raxdmfhmcy2gxz8hgn0jnhfmujjsfe",
"coins": [
{
"denom": "stake",
"amount": "400000"
}
],
"public_key": {
"type": "tendermint/PubKeyEd25519",
"value": "eB0AcLMLKFRNFfh4XAAMstexfAIUQQCDnfjLZ2KJg+A="
},
"account_number": "1",
"sequence": "1"
}
},
{
"type": "cosmos-sdk/Account",
"value": {
"address": "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h",
"coins": [
{
"denom": "stake",
"amount": "400000"
}
],
"public_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "AruDygh5HprMOpHOEato85dLgAsybMJVyxBGUa3KuWCr"
},
"account_number": "2",
"sequence": "2"
}
}
]
}`
require.Equal(t, expectedJSON, string(json))
}

View File

@ -9,10 +9,12 @@ import (
"fmt"
"strings"
"github.com/tendermint/tendermint/crypto"
tmcrypto "github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
@ -29,11 +31,11 @@ type (
}
BaseAccount struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey crypto.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins,omitempty"`
PubKey cryptotypes.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
}
BaseVestingAccount struct {
@ -47,15 +49,15 @@ type (
}
vestingAccountJSON struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins"`
PubKey crypto.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"`
DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"`
DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"`
EndTime int64 `json:"end_time" yaml:"end_time"`
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins,omitempty" yaml:"coins"`
PubKey cryptotypes.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
OriginalVesting sdk.Coins `json:"original_vesting" yaml:"original_vesting"`
DelegatedFree sdk.Coins `json:"delegated_free" yaml:"delegated_free"`
DelegatedVesting sdk.Coins `json:"delegated_vesting" yaml:"delegated_vesting"`
EndTime int64 `json:"end_time" yaml:"end_time"`
// custom fields based on concrete vesting type which can be omitted
StartTime int64 `json:"start_time,omitempty" yaml:"start_time,omitempty"`
@ -117,7 +119,7 @@ func NewBaseAccountWithAddress(addr sdk.AccAddress) BaseAccount {
}
func NewBaseAccount(
address sdk.AccAddress, coins sdk.Coins, pk crypto.PubKey, accountNumber, sequence uint64,
address sdk.AccAddress, coins sdk.Coins, pk cryptotypes.PubKey, accountNumber, sequence uint64,
) *BaseAccount {
return &BaseAccount{
@ -380,7 +382,7 @@ func (ma ModuleAccount) Validate() error {
return errors.New("module account name cannot be blank")
}
if x := sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))); !ma.Address.Equals(x) {
if x := sdk.AccAddress(tmcrypto.AddressHash([]byte(ma.Name))); !ma.Address.Equals(x) {
return fmt.Errorf("address %s cannot be derived from the module name '%s'; expected: %s", ma.Address, ma.Name, x)
}
@ -415,6 +417,7 @@ func (ma *ModuleAccount) UnmarshalJSON(bz []byte) error {
}
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cryptocodec.RegisterCrypto(cdc)
cdc.RegisterInterface((*v038auth.GenesisAccount)(nil), nil)
cdc.RegisterInterface((*v038auth.Account)(nil), nil)
cdc.RegisterConcrete(&BaseAccount{}, "cosmos-sdk/Account", nil)

View File

@ -1,8 +1,7 @@
package signing
import (
"github.com/tendermint/tendermint/crypto"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
@ -12,7 +11,7 @@ import (
type SigVerifiableTx interface {
types.Tx
GetSigners() []types.AccAddress
GetPubKeys() []crypto.PubKey // If signer already has pubkey in context, this list will have nil in its place
GetPubKeys() []cryptotypes.PubKey // If signer already has pubkey in context, this list will have nil in its place
GetSignaturesV2() ([]signing.SignatureV2, error)
}

View File

@ -3,8 +3,7 @@ package signing
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
@ -12,7 +11,7 @@ import (
// VerifySignature verifies a transaction signature contained in SignatureData abstracting over different signing modes
// and single vs multi-signatures.
func VerifySignature(pubKey crypto.PubKey, signerData SignerData, sigData signing.SignatureData, handler SignModeHandler, tx sdk.Tx) error {
func VerifySignature(pubKey cryptotypes.PubKey, signerData SignerData, sigData signing.SignatureData, handler SignModeHandler, tx sdk.Tx) error {
switch data := sigData.(type) {
case *signing.SingleSignatureData:
signBytes, err := handler.GetSignBytes(data.SignMode, signerData, tx)

View File

@ -4,11 +4,11 @@ import (
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
@ -65,7 +65,7 @@ func TestVerifySignature(t *testing.T) {
err = signing.VerifySignature(pubKey, signerData, sigV2.Data, handler, stdTx)
require.NoError(t, err)
pkSet := []crypto.PubKey{pubKey, pubKey1}
pkSet := []cryptotypes.PubKey{pubKey, pubKey1}
multisigKey := kmultisig.NewLegacyAminoPubKey(2, pkSet)
multisignature := multisig.NewMultisig(2)
msgs = []sdk.Msg{testdata.NewTestMsg(addr, addr1)}

View File

@ -4,10 +4,10 @@ import (
"bytes"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -81,7 +81,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetMsgs() {
func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() {
privKey, pubkey, addr := testdata.KeyTestPubAddr()
privKey2, pubkey2, _ := testdata.KeyTestPubAddr()
multisigPk := kmultisig.NewLegacyAminoPubKey(2, []crypto.PubKey{pubkey, pubkey2})
multisigPk := kmultisig.NewLegacyAminoPubKey(2, []cryptotypes.PubKey{pubkey, pubkey2})
txBuilder := s.TxConfig.NewTxBuilder()
@ -268,7 +268,7 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() {
tx3Sigs, err := tx3.GetSignaturesV2()
s.Require().NoError(err)
s.Require().Equal([]signingtypes.SignatureV2{sig}, tx3Sigs)
s.Require().Equal([]crypto.PubKey{pubkey}, tx3.GetPubKeys())
s.Require().Equal([]cryptotypes.PubKey{pubkey}, tx3.GetPubKeys())
log("JSON encode transaction")
jsonTxBytes, err := s.TxConfig.TxJSONEncoder()(tx)
@ -287,7 +287,7 @@ func (s *TxConfigTestSuite) TestTxEncodeDecode() {
tx3Sigs, err = tx3.GetSignaturesV2()
s.Require().NoError(err)
s.Require().Equal([]signingtypes.SignatureV2{sig}, tx3Sigs)
s.Require().Equal([]crypto.PubKey{pubkey}, tx3.GetPubKeys())
s.Require().Equal([]cryptotypes.PubKey{pubkey}, tx3.GetPubKeys())
}
func (s *TxConfigTestSuite) TestWrapTxBuilder() {

View File

@ -1,15 +1,12 @@
package tx
import (
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
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/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
@ -103,9 +100,9 @@ func (w *wrapper) GetSigners() []sdk.AccAddress {
return w.tx.GetSigners()
}
func (w *wrapper) GetPubKeys() []crypto.PubKey {
func (w *wrapper) GetPubKeys() []cryptotypes.PubKey {
signerInfos := w.tx.AuthInfo.SignerInfos
pks := make([]crypto.PubKey, len(signerInfos))
pks := make([]cryptotypes.PubKey, len(signerInfos))
for i, si := range signerInfos {
// NOTE: it is okay to leave this nil if there is no PubKey in the SignerInfo.
@ -114,7 +111,7 @@ func (w *wrapper) GetPubKeys() []crypto.PubKey {
continue
}
pk, ok := si.PublicKey.GetCachedValue().(crypto.PubKey)
pk, ok := si.PublicKey.GetCachedValue().(cryptotypes.PubKey)
if ok {
pks[i] = pk
}
@ -366,11 +363,7 @@ func (w *wrapper) SetNonCriticalExtensionOptions(extOpts ...*codectypes.Any) {
w.bodyBz = nil
}
// PubKeyToAny converts a crypto.PubKey to a proto Any.
func PubKeyToAny(key crypto.PubKey) (*codectypes.Any, error) {
protoMsg, ok := key.(proto.Message)
if !ok {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidPubKey, fmt.Sprintf("can't proto encode %T", protoMsg))
}
return codectypes.NewAnyWithValue(protoMsg)
// PubKeyToAny converts a cryptotypes.PubKey to a proto Any.
func PubKeyToAny(key cryptotypes.PubKey) (*codectypes.Any, error) {
return codectypes.NewAnyWithValue(key)
}

View File

@ -3,10 +3,8 @@ package tx
import (
"fmt"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)
@ -33,7 +31,7 @@ func SignatureDataToModeInfoAndSig(data signing.SignatureData) (*tx.ModeInfo, []
modeInfos[i], sigs[i] = SignatureDataToModeInfoAndSig(d)
}
multisig := types.MultiSignature{
multisig := cryptotypes.MultiSignature{
Signatures: sigs,
}
sig, err := multisig.Marshal()
@ -92,7 +90,7 @@ func ModeInfoAndSigToSignatureData(modeInfo *tx.ModeInfo, sig []byte) (signing.S
// decodeMultisignatures safely decodes the the raw bytes as a MultiSignature protobuf message
func decodeMultisignatures(bz []byte) ([][]byte, error) {
multisig := types.MultiSignature{}
multisig := cryptotypes.MultiSignature{}
err := multisig.Unmarshal(bz)
if err != nil {
return nil, err
@ -137,7 +135,7 @@ func (g config) UnmarshalSignatureJSON(bz []byte) ([]signing.SignatureV2, error)
sigs := make([]signing.SignatureV2, len(sigDescs.Signatures))
for i, desc := range sigDescs.Signatures {
pubKey, _ := desc.PublicKey.GetCachedValue().(crypto.PubKey)
pubKey, _ := desc.PublicKey.GetCachedValue().(cryptotypes.PubKey)
data := signing.SignatureDataFromProto(desc.Data)

View File

@ -13,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -26,7 +27,7 @@ var (
// NewBaseAccount creates a new BaseAccount object
//nolint:interfacer
func NewBaseAccount(address sdk.AccAddress, pubKey crypto.PubKey, accountNumber, sequence uint64) *BaseAccount {
func NewBaseAccount(address sdk.AccAddress, pubKey cryptotypes.PubKey, accountNumber, sequence uint64) *BaseAccount {
acc := &BaseAccount{
Address: address.String(),
AccountNumber: accountNumber,
@ -70,11 +71,11 @@ func (acc *BaseAccount) SetAddress(addr sdk.AccAddress) error {
}
// GetPubKey - Implements sdk.AccountI.
func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) {
func (acc BaseAccount) GetPubKey() (pk cryptotypes.PubKey) {
if acc.PubKey == nil {
return nil
}
content, ok := acc.PubKey.GetCachedValue().(crypto.PubKey)
content, ok := acc.PubKey.GetCachedValue().(cryptotypes.PubKey)
if !ok {
return nil
}
@ -82,7 +83,7 @@ func (acc BaseAccount) GetPubKey() (pk crypto.PubKey) {
}
// SetPubKey - Implements sdk.AccountI.
func (acc *BaseAccount) SetPubKey(pubKey crypto.PubKey) error {
func (acc *BaseAccount) SetPubKey(pubKey cryptotypes.PubKey) error {
any, err := codectypes.PackAny(pubKey)
if err != nil {
return err
@ -150,7 +151,7 @@ func (acc BaseAccount) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
if acc.PubKey == nil {
return nil
}
var pubKey crypto.PubKey
var pubKey cryptotypes.PubKey
return unpacker.UnpackAny(acc.PubKey, &pubKey)
}
@ -209,7 +210,7 @@ func (ma ModuleAccount) GetPermissions() []string {
}
// SetPubKey - Implements AccountI
func (ma ModuleAccount) SetPubKey(pubKey crypto.PubKey) error {
func (ma ModuleAccount) SetPubKey(pubKey cryptotypes.PubKey) error {
return fmt.Errorf("not supported for module accounts")
}
@ -311,8 +312,8 @@ type AccountI interface {
GetAddress() sdk.AccAddress
SetAddress(sdk.AccAddress) error // errors if already set.
GetPubKey() crypto.PubKey // can return nil.
SetPubKey(crypto.PubKey) error
GetPubKey() cryptotypes.PubKey // can return nil.
SetPubKey(cryptotypes.PubKey) error
GetAccountNumber() uint64
SetAccountNumber(uint64) error

Some files were not shown because too many files have changed in this diff Show More