From faa822aaf49ebbb8c1c990380e1ff0e25bc07b3a Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 3 Nov 2020 16:54:56 +0100 Subject: [PATCH] Move PubKey bech32 to legacy package and migrate the usage where possible --- client/keys/add.go | 43 ++++++------ client/keys/show.go | 12 ++-- server/tm_cmds.go | 3 + types/address.go | 119 +------------------------------ types/address_test.go | 42 ----------- types/bech32/legacybech32/pk.go | 120 ++++++++++++++++++++++++++++++++ types/tx/signing/signing.pb.go | 9 +-- x/auth/legacy/v038/types.go | 17 ++--- x/slashing/client/rest/query.go | 1 + x/staking/client/cli/tx.go | 13 +--- 10 files changed, 170 insertions(+), 209 deletions(-) create mode 100644 types/bech32/legacybech32/pk.go diff --git a/client/keys/add.go b/client/keys/add.go index b2e267e83e8a..885326416008 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -61,21 +61,21 @@ the flag --nosort is set. Args: cobra.ExactArgs(1), RunE: runAddCmd, } - - cmd.Flags().StringSlice(flagMultisig, nil, "Construct and store a multisig public key (implies --pubkey)") - cmd.Flags().Int(flagMultiSigThreshold, 1, "K out of N required signatures. For use in conjunction with --multisig") - cmd.Flags().Bool(flagNoSort, false, "Keys passed to --multisig are taken in the order they're supplied") - cmd.Flags().String(FlagPublicKey, "", "Parse a public key in bech32 format and save it to disk") - cmd.Flags().BoolP(flagInteractive, "i", false, "Interactively prompt user for BIP39 passphrase and mnemonic") - cmd.Flags().Bool(flags.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device") - cmd.Flags().Bool(flagRecover, false, "Provide seed phrase to recover existing key instead of creating") - cmd.Flags().Bool(flagNoBackup, false, "Don't print out seed phrase (if others are watching the terminal)") - cmd.Flags().Bool(flags.FlagDryRun, false, "Perform action, but don't add key to local keystore") - cmd.Flags().String(flagHDPath, "", "Manual HD Path derivation (overrides BIP44 config)") - cmd.Flags().Uint32(flagCoinType, sdk.GetConfig().GetCoinType(), "coin type number for HD derivation") - cmd.Flags().Uint32(flagAccount, 0, "Account number for HD derivation") - cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation") - cmd.Flags().String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for") + flags := cmd.Flags() + flags.StringSlice(flagMultisig, nil, "Construct and store a multisig public key (implies --pubkey)") + flags.Int(flagMultiSigThreshold, 1, "K out of N required signatures. For use in conjunction with --multisig") + flags.Bool(flagNoSort, false, "Keys passed to --multisig are taken in the order they're supplied") + flags.String(FlagPublicKey, "", "Parse a public key in bech32 format and save it to disk") + flags.BoolP(flagInteractive, "i", false, "Interactively prompt user for BIP39 passphrase and mnemonic") + flags.Bool(flags.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device") + flags.Bool(flagRecover, false, "Provide seed phrase to recover existing key instead of creating") + flags.Bool(flagNoBackup, false, "Don't print out seed phrase (if others are watching the terminal)") + flags.Bool(flags.FlagDryRun, false, "Perform action, but don't add key to local keystore") + flags.String(flagHDPath, "", "Manual HD Path derivation (overrides BIP44 config)") + flags.Uint32(flagCoinType, sdk.GetConfig().GetCoinType(), "coin type number for HD derivation") + flags.Uint32(flagAccount, 0, "Account number for HD derivation") + flags.Uint32(flagIndex, 0, "Address index number for HD derivation") + flags.String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for") cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.ErrOrStderr()) @@ -186,16 +186,15 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf pubKey, _ := cmd.Flags().GetString(FlagPublicKey) if pubKey != "" { - pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, pubKey) - if err != nil { - return err - } - - if _, err := kb.SavePubKey(name, pk, algo.Name()); err != nil { + var pk crypto.PubKey + // TODO: shall we use KeysCdc here (global from this module, = codec.NewLegacyAmino)? + marshaller := client.GetClientContextFromCmd(cmd).JSONMarshaler + if err := marshaller.UnmarshalJSON([]byte(pubKey), &pk); err != nil { return err } - return nil + _, err := kb.SavePubKey(name, pk, algo.Name()) + return err } coinType, _ := cmd.Flags().GetUint32(flagCoinType) diff --git a/client/keys/show.go b/client/keys/show.go index 102f29793b4a..88611bfe9c32 100644 --- a/client/keys/show.go +++ b/client/keys/show.go @@ -41,12 +41,12 @@ consisting of all the keys provided by name and multisig threshold.`, Args: cobra.MinimumNArgs(1), RunE: runShowCmd, } - - cmd.Flags().String(FlagBechPrefix, sdk.PrefixAccount, "The Bech32 prefix encoding for a key (acc|val|cons)") - cmd.Flags().BoolP(FlagAddress, "a", false, "Output the address only (overrides --output)") - cmd.Flags().BoolP(FlagPublicKey, "p", false, "Output the public key only (overrides --output)") - cmd.Flags().BoolP(FlagDevice, "d", false, "Output the address in a ledger device") - cmd.Flags().Int(flagMultiSigThreshold, 1, "K out of N required signatures") + flags := cmd.Flags() + flags.String(FlagBechPrefix, sdk.PrefixAccount, "The Bech32 prefix encoding for a key (acc|val|cons)") + flags.BoolP(FlagAddress, "a", false, "Output the address only (overrides --output)") + flags.BoolP(FlagPublicKey, "p", false, "Output the public key only (overrides --output)") + flags.BoolP(FlagDevice, "d", false, "Output the address in a ledger device") + flags.Int(flagMultiSigThreshold, 1, "K out of N required signatures") return cmd } diff --git a/server/tm_cmds.go b/server/tm_cmds.go index d6c8b665f9c4..0e43fa8c5f70 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -12,6 +12,7 @@ import ( "github.com/tendermint/tendermint/p2p" pvm "github.com/tendermint/tendermint/privval" tversion "github.com/tendermint/tendermint/version" + "google.golang.org/protobuf/proto" yaml "gopkg.in/yaml.v2" "github.com/cosmos/cosmos-sdk/codec" @@ -59,6 +60,8 @@ func ShowValidatorCmd() *cobra.Command { return printlnJSON(valPubKey) } + pk, ok := valPubKey.(proto.Message) + pubkey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey) if err != nil { return err diff --git a/types/address.go b/types/address.go index 345c44fa8e1c..0f92e8667b3f 100644 --- a/types/address.go +++ b/types/address.go @@ -9,15 +9,9 @@ import ( "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" "github.com/cosmos/cosmos-sdk/types/bech32" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) const ( @@ -604,121 +598,12 @@ func (ca ConsAddress) Format(s fmt.State, verb rune) { // auxiliary // ---------------------------------------------------------------------------- -// Bech32PubKeyType defines a string type alias for a Bech32 public key type. -type Bech32PubKeyType string - -// Bech32 conversion constants -const ( - Bech32PubKeyTypeAccPub Bech32PubKeyType = "accpub" - Bech32PubKeyTypeValPub Bech32PubKeyType = "valpub" - Bech32PubKeyTypeConsPub Bech32PubKeyType = "conspub" -) - -// 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) { - var bech32Prefix string - - switch pkt { - case Bech32PubKeyTypeAccPub: - bech32Prefix = GetConfig().GetBech32AccountPubPrefix() - - case Bech32PubKeyTypeValPub: - bech32Prefix = GetConfig().GetBech32ValidatorPubPrefix() - - case Bech32PubKeyTypeConsPub: - bech32Prefix = GetConfig().GetBech32ConsensusPubPrefix() - - } - - // This piece of code is to keep backwards-compatibility. - // For ed25519 keys, our own ed25519 is registered in Amino under a - // different name than TM's ed25519. But since users are already using - // TM's ed25519 bech32 encoding, we explicitly say to bech32-encode our own - // ed25519 the same way as TM's ed25519. - // TODO: Remove Bech32ifyPubKey and all usages (cosmos/cosmos-sdk/issues/#7357) - pkToMarshal := pubkey - if ed25519Pk, ok := pubkey.(*ed25519.PubKey); ok { - pkToMarshal = ed25519Pk.AsTmPubKey() - } - - return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.MustMarshalBinaryBare(pkToMarshal)) -} - -// MustBech32ifyPubKey calls Bech32ifyPubKey except it panics on error. -func MustBech32ifyPubKey(pkt Bech32PubKeyType, pubkey crypto.PubKey) string { - res, err := Bech32ifyPubKey(pkt, pubkey) - if err != nil { - panic(err) - } - - return res -} - -// GetPubKeyFromBech32 returns a PublicKey from a bech32-encoded PublicKey with -// a given key type. -func GetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) (crypto.PubKey, error) { - var bech32Prefix string - - switch pkt { - case Bech32PubKeyTypeAccPub: - bech32Prefix = GetConfig().GetBech32AccountPubPrefix() - - case Bech32PubKeyTypeValPub: - bech32Prefix = GetConfig().GetBech32ValidatorPubPrefix() - - case Bech32PubKeyTypeConsPub: - bech32Prefix = GetConfig().GetBech32ConsensusPubPrefix() - - } - - bz, err := GetFromBech32(pubkeyStr, bech32Prefix) - if err != nil { - 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 -} - -// MustGetPubKeyFromBech32 calls GetPubKeyFromBech32 except it panics on error. -func MustGetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) crypto.PubKey { - res, err := GetPubKeyFromBech32(pkt, pubkeyStr) - if err != nil { - panic(err) - } - - return res -} +var errBech32EmptyAddress = errors.New("decoding Bech32 address failed: must provide a non empty address") // GetFromBech32 decodes a bytestring from a Bech32 encoded string. func GetFromBech32(bech32str, prefix string) ([]byte, error) { if len(bech32str) == 0 { - return nil, errors.New("decoding Bech32 address failed: must provide an address") + return nil, errBech32EmptyAddress } hrp, bz, err := bech32.DecodeAndConvert(bech32str) diff --git a/types/address_test.go b/types/address_test.go index 9de4bea4f360..720995f8a5d4 100644 --- a/types/address_test.go +++ b/types/address_test.go @@ -68,48 +68,6 @@ func (s *addressTestSuite) TestEmptyAddresses() { s.Require().Error(err) } -func (s *addressTestSuite) TestRandBech32PubkeyConsistency() { - pubBz := make([]byte, ed25519.PubKeySize) - pub := &ed25519.PubKey{Key: pubBz} - - for i := 0; i < 1000; i++ { - rand.Read(pub.Key) - - mustBech32AccPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeAccPub, pub) - bech32AccPub, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeAccPub, pub) - s.Require().Nil(err) - s.Require().Equal(bech32AccPub, mustBech32AccPub) - - mustBech32ValPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeValPub, pub) - bech32ValPub, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeValPub, pub) - s.Require().Nil(err) - s.Require().Equal(bech32ValPub, mustBech32ValPub) - - mustBech32ConsPub := types.MustBech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pub) - bech32ConsPub, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pub) - s.Require().Nil(err) - s.Require().Equal(bech32ConsPub, mustBech32ConsPub) - - mustAccPub := types.MustGetPubKeyFromBech32(types.Bech32PubKeyTypeAccPub, bech32AccPub) - accPub, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeAccPub, bech32AccPub) - s.Require().Nil(err) - s.Require().Equal(accPub, mustAccPub) - - mustValPub := types.MustGetPubKeyFromBech32(types.Bech32PubKeyTypeValPub, bech32ValPub) - valPub, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeValPub, bech32ValPub) - s.Require().Nil(err) - s.Require().Equal(valPub, mustValPub) - - mustConsPub := types.MustGetPubKeyFromBech32(types.Bech32PubKeyTypeConsPub, bech32ConsPub) - consPub, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeConsPub, bech32ConsPub) - s.Require().Nil(err) - s.Require().Equal(consPub, mustConsPub) - - s.Require().Equal(valPub, accPub) - s.Require().Equal(valPub, consPub) - } -} - func (s *addressTestSuite) TestYAMLMarshalers() { addr := secp256k1.GenPrivKey().PubKey().Address() diff --git a/types/bech32/legacybech32/pk.go b/types/bech32/legacybech32/pk.go new file mode 100644 index 000000000000..53df87f3b8fc --- /dev/null +++ b/types/bech32/legacybech32/pk.go @@ -0,0 +1,120 @@ +// Deprecated: The module provides legacy bech32 functions which will be removed in a future +// release. +package legacybech32 + +// nolint + +// TODO: remove Bech32 prefix, it's already in package + +import ( + "github.com/tendermint/tendermint/crypto" + tmed25519 "github.com/tendermint/tendermint/crypto/ed25519" + + "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" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// Deprecated: Bech32PubKeyType defines a string type alias for a Bech32 public key type. +type Bech32PubKeyType string + +// Bech32 conversion constants +const ( + Bech32PubKeyTypeAccPub Bech32PubKeyType = "accpub" + Bech32PubKeyTypeValPub Bech32PubKeyType = "valpub" + Bech32PubKeyTypeConsPub Bech32PubKeyType = "conspub" +) + +// Deprecated: 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) { + // 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() + } + + bech32Prefix := getPrefix(pkt) + return bech32.ConvertAndEncode(bech32Prefix, legacy.Cdc.MustMarshalBinaryBare(pkToMarshal)) +} + +// Deprecated: MustBech32ifyPubKey calls Bech32ifyPubKey and panics on error. +func MustBech32ifyPubKey(pkt Bech32PubKeyType, pubkey crypto.PubKey) string { + res, err := Bech32ifyPubKey(pkt, pubkey) + if err != nil { + panic(err) + } + + return res +} + +func getPrefix(pkt Bech32PubKeyType) string { + cfg := sdk.GetConfig() + switch pkt { + case Bech32PubKeyTypeAccPub: + return cfg.GetBech32AccountPubPrefix() + + case Bech32PubKeyTypeValPub: + return cfg.GetBech32ValidatorPubPrefix() + case Bech32PubKeyTypeConsPub: + return cfg.GetBech32ConsensusPubPrefix() + } + + return "" +} + +// Deprecated: GetPubKeyFromBech32 returns a PublicKey from a bech32-encoded PublicKey with +// a given key type. +func GetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) (crypto.PubKey, error) { + bech32Prefix := getPrefix(pkt) + bz, err := sdk.GetFromBech32(pubkeyStr, bech32Prefix) + if err != nil { + 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 +} + +// Deprecated: MustGetPubKeyFromBech32 calls GetPubKeyFromBech32 except it panics on error. +func MustGetPubKeyFromBech32(pkt Bech32PubKeyType, pubkeyStr string) crypto.PubKey { + res, err := GetPubKeyFromBech32(pkt, pubkeyStr) + if err != nil { + panic(err) + } + + return res +} diff --git a/types/tx/signing/signing.pb.go b/types/tx/signing/signing.pb.go index 424e7395df30..377a60e3ebdf 100644 --- a/types/tx/signing/signing.pb.go +++ b/types/tx/signing/signing.pb.go @@ -5,12 +5,13 @@ package signing import ( fmt "fmt" - types "github.com/cosmos/cosmos-sdk/codec/types" - types1 "github.com/cosmos/cosmos-sdk/crypto/types" - proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" + + types "github.com/cosmos/cosmos-sdk/codec/types" + types1 "github.com/cosmos/cosmos-sdk/crypto/types" + proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. @@ -38,7 +39,7 @@ const ( // human-readable textual representation on top of the binary representation // from SIGN_MODE_DIRECT SignMode_SIGN_MODE_TEXTUAL SignMode = 2 - // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses + // Deprecated: SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses // Amino JSON and will be removed in the future SignMode_SIGN_MODE_LEGACY_AMINO_JSON SignMode = 127 ) diff --git a/x/auth/legacy/v038/types.go b/x/auth/legacy/v038/types.go index aeb554eeeab5..035db9629c3f 100644 --- a/x/auth/legacy/v038/types.go +++ b/x/auth/legacy/v038/types.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32/legacybech32" v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034" ) @@ -174,7 +175,7 @@ func (acc BaseAccount) MarshalJSON() ([]byte, error) { } if acc.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, acc.PubKey) + pks, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeAccPub, acc.PubKey) if err != nil { return nil, err } @@ -193,7 +194,7 @@ func (acc *BaseAccount) UnmarshalJSON(bz []byte) error { } if alias.PubKey != "" { - pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) + pk, err := legacybech32.GetPubKeyFromBech32(legacybech32.Bech32PubKeyTypeAccPub, alias.PubKey) if err != nil { return err } @@ -240,7 +241,7 @@ func (bva BaseVestingAccount) MarshalJSON() ([]byte, error) { } if bva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, bva.PubKey) + pks, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeAccPub, bva.PubKey) if err != nil { return nil, err } @@ -264,7 +265,7 @@ func (bva *BaseVestingAccount) UnmarshalJSON(bz []byte) error { ) if alias.PubKey != "" { - pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) + pk, err = legacybech32.GetPubKeyFromBech32(legacybech32.Bech32PubKeyTypeAccPub, alias.PubKey) if err != nil { return err } @@ -309,7 +310,7 @@ func (cva ContinuousVestingAccount) MarshalJSON() ([]byte, error) { } if cva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, cva.PubKey) + pks, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeAccPub, cva.PubKey) if err != nil { return nil, err } @@ -333,7 +334,7 @@ func (cva *ContinuousVestingAccount) UnmarshalJSON(bz []byte) error { ) if alias.PubKey != "" { - pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) + pk, err = legacybech32.GetPubKeyFromBech32(legacybech32.Bech32PubKeyTypeAccPub, alias.PubKey) if err != nil { return err } @@ -375,7 +376,7 @@ func (dva DelayedVestingAccount) MarshalJSON() ([]byte, error) { } if dva.PubKey != nil { - pks, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, dva.PubKey) + pks, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeAccPub, dva.PubKey) if err != nil { return nil, err } @@ -399,7 +400,7 @@ func (dva *DelayedVestingAccount) UnmarshalJSON(bz []byte) error { ) if alias.PubKey != "" { - pk, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeAccPub, alias.PubKey) + pk, err = legacybech32.GetPubKeyFromBech32(legacybech32.Bech32PubKeyTypeAccPub, alias.PubKey) if err != nil { return err } diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 36eb8cc24a68..0e1c68da145d 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -30,6 +30,7 @@ func registerQueryRoutes(clientCtx client.Context, r *mux.Router) { } // http request handler to query signing info +// [DEPRECATED] func signingInfoHandlerFn(clientCtx client.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index ab486c5a9841..563ec6c49dbf 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -407,7 +407,7 @@ type TxCreateValidatorConfig struct { CommissionMaxChangeRate string MinSelfDelegation string - PubKey string + PubKey crypto.PubKey IP string Website string @@ -479,7 +479,7 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c } c.NodeID = nodeID - c.PubKey = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey) + c.PubKey = valPubKey c.Website = website c.SecurityContact = securityContact c.Details = details @@ -520,13 +520,6 @@ func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorC } valAddr := clientCtx.GetFromAddress() - pkStr := config.PubKey - - pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, pkStr) - if err != nil { - return txBldr, nil, err - } - description := types.NewDescription( config.Moniker, config.Identity, @@ -554,7 +547,7 @@ func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorC } msg, err := types.NewMsgCreateValidator( - sdk.ValAddress(valAddr), pk, amount, description, commissionRates, minSelfDelegation, + sdk.ValAddress(valAddr), config.PubKey, amount, description, commissionRates, minSelfDelegation, ) if err != nil { return txBldr, msg, err