Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bech32 PubKey support #7477

Merged
merged 109 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
faa822a
Move PubKey bech32 to legacy package and migrate the usage where poss…
robert-zaremba Nov 3, 2020
2324c4e
update /server
robert-zaremba Nov 3, 2020
7df2182
wip
robert-zaremba Nov 3, 2020
9198817
move proto json encoding helper functions to internal
robert-zaremba Nov 5, 2020
412ccc4
update internal/marshal
robert-zaremba Nov 9, 2020
35275d7
wip
robert-zaremba Nov 9, 2020
dd6f93b
update sections which needs legacybech32
robert-zaremba Nov 16, 2020
17a6b1e
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Nov 16, 2020
7af7ab3
update validators output
robert-zaremba Nov 16, 2020
8331f33
fix conflicts
robert-zaremba Nov 16, 2020
41cbd9f
slashing update
robert-zaremba Nov 17, 2020
238e334
add more tests and helper function for ANY JSON serialization
robert-zaremba Nov 18, 2020
ee70afb
update slashing
robert-zaremba Nov 18, 2020
084c306
Update function documentation
robert-zaremba Nov 18, 2020
7974b42
Rename code any-marshal helper functions
robert-zaremba Nov 18, 2020
943a4ff
Update pubkey unpacking test
robert-zaremba Nov 18, 2020
3a0904b
Update test comments
robert-zaremba Nov 18, 2020
6d00c2e
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Nov 23, 2020
46f85ce
solve TestDecodeStore
robert-zaremba Nov 23, 2020
2b35020
solve legacytx issues
robert-zaremba Nov 23, 2020
f7411dd
all code compiles
robert-zaremba Nov 23, 2020
c906d74
keyring tests
robert-zaremba Nov 24, 2020
0632000
keyring cleanup
robert-zaremba Nov 24, 2020
7151b25
remove AssertMsg
robert-zaremba Nov 24, 2020
9a12242
fix some tests
robert-zaremba Nov 24, 2020
f4a585b
fix add_ledger_test.go
robert-zaremba Nov 24, 2020
b6e5582
update cli tests
robert-zaremba Nov 24, 2020
c5be087
debug cli test
robert-zaremba Nov 24, 2020
f6fd51e
rename clashed bech32 names
robert-zaremba Nov 24, 2020
21e3dc6
linter fixes
robert-zaremba Nov 24, 2020
55d4db2
merge master
robert-zaremba Nov 26, 2020
688e3ca
update tmservice tests
robert-zaremba Nov 27, 2020
14bfa7b
linter: update legacy deprecated checks
robert-zaremba Nov 27, 2020
218f54b
fix names
robert-zaremba Nov 27, 2020
829db7d
linting
robert-zaremba Nov 27, 2020
452e406
legacybech32 pubkey type rename
robert-zaremba Nov 27, 2020
81aab57
fix staking client
robert-zaremba Nov 27, 2020
ae91f0f
fix test compilation
robert-zaremba Nov 27, 2020
69572c6
fix TestGetCmdQuerySigningInfo
robert-zaremba Nov 28, 2020
288a080
rename NewIfcJSONAnyMarshaler
robert-zaremba Nov 28, 2020
773d0c6
keyring: remove duplicated information from multinfo structure
robert-zaremba Nov 30, 2020
8f86bf4
todo cleanups
robert-zaremba Nov 30, 2020
904129e
Update Changelog
robert-zaremba Nov 30, 2020
c6f003c
remove some legacybech32 from tests
robert-zaremba Nov 30, 2020
47eceb6
remove todos
robert-zaremba Nov 30, 2020
3a94d65
remove printlnJSON from /server CLI and amino encoding
robert-zaremba Nov 30, 2020
dc9f743
remove protocdc.MarshalJSON
robert-zaremba Nov 30, 2020
da24773
client/show remove duplicated function
robert-zaremba Nov 30, 2020
a965f3a
remove protocdc package
robert-zaremba Nov 30, 2020
2e95ae8
comment update
robert-zaremba Nov 30, 2020
937f11d
remove legacybech32.MustMarshalPubKey from a test
robert-zaremba Nov 30, 2020
18613c5
add todo
robert-zaremba Dec 1, 2020
20f44f2
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Dec 1, 2020
f60c9b7
fix TestPublicKeyUnsafe test
robert-zaremba Dec 1, 2020
50ecab7
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Dec 1, 2020
7401c1a
review update
robert-zaremba Dec 2, 2020
d3d83b8
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Jan 11, 2021
eb68268
fix bech32 UnmarshalPubKey
robert-zaremba Jan 11, 2021
4a28e7a
Use codec.MarshalIfcJSON
robert-zaremba Jan 11, 2021
801984b
fix linter issues
robert-zaremba Jan 11, 2021
a05c1b2
merging conflict: fix codec.Unmarshal calls
robert-zaremba Jan 11, 2021
7443c6c
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Jan 11, 2021
e6292e1
cleanups
robert-zaremba Jan 12, 2021
d55f19e
Update CHANGELOG.md
robert-zaremba Jan 12, 2021
4be2229
Reword changelog updates
robert-zaremba Jan 12, 2021
83fcfd0
use pubkey.String for comparison in Test_runAddCmdLedgerWithCustomCoi…
robert-zaremba Jan 12, 2021
84a0c21
Update GetCmdQuerySigningInfo example
robert-zaremba Jan 12, 2021
4e60fad
cli: update keys add docs
robert-zaremba Jan 13, 2021
8eba4b0
Add errors AsOf and errors.ErrIO type
robert-zaremba Jan 13, 2021
d0beb74
restore multisigPubKeyInfo structure bring it back to multiInfo struct
robert-zaremba Jan 13, 2021
09aca5c
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Jan 13, 2021
707f054
Update codec/proto_codec.go
robert-zaremba Jan 15, 2021
f5b060c
Update crypto/keys/ed25519/ed25519_test.go
robert-zaremba Jan 15, 2021
a0a0285
Update codec/proto_codec.go
robert-zaremba Jan 15, 2021
75fdcbd
move pubkey any marshaling tests
robert-zaremba Jan 15, 2021
7ebc098
Apply suggestions from code review
robert-zaremba Jan 15, 2021
142913f
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Jan 15, 2021
12b22b5
review updates
robert-zaremba Jan 15, 2021
6848e63
adding missing return
robert-zaremba Jan 15, 2021
d37b1c5
errors: use IsOf instead of AsOf
robert-zaremba Jan 16, 2021
f667fe4
keyring: add a correct check for key not found in keyring.Get
robert-zaremba Jan 16, 2021
1564845
add checkKeyNotFound
robert-zaremba Jan 18, 2021
190f0c0
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 9, 2021
a7cc794
fix linter issues
robert-zaremba Mar 9, 2021
705143e
fix: keyring key not found check
robert-zaremba Mar 9, 2021
e3ef9b8
fix keyring tests
robert-zaremba Mar 10, 2021
51f764d
fix linting issues
robert-zaremba Mar 10, 2021
17a47a2
cli tests
robert-zaremba Mar 10, 2021
ecdf1c3
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 10, 2021
61cba59
fix: 'simd keys show <key> -p'
robert-zaremba Mar 10, 2021
74e2b13
fix: TestVerifyMultisignature
robert-zaremba Mar 10, 2021
bccf755
rename keyring Bech32... functions to Mk...
robert-zaremba Mar 11, 2021
ba7042d
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 23, 2021
e58f6a8
fix RunAddCmd
robert-zaremba Mar 23, 2021
a9a0a55
Update pubkey display
robert-zaremba Mar 23, 2021
65485a5
wip
robert-zaremba Mar 23, 2021
eaea2f4
add more tests
robert-zaremba Mar 23, 2021
954f779
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 23, 2021
ba700c4
udate keyring output tests
robert-zaremba Mar 23, 2021
d6e76d7
remove todo from ledger tests
robert-zaremba Mar 23, 2021
192999e
rename MkKeyOutput
robert-zaremba Mar 24, 2021
d087500
Changelog update
robert-zaremba Mar 24, 2021
3ff91cc
solve liner issues
robert-zaremba Mar 24, 2021
d831489
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 24, 2021
b0b8f59
add link to github issue
robert-zaremba Mar 24, 2021
0436894
Merge branch 'master' into robert/rm-bech32-pk
aaronc Mar 24, 2021
75c36fc
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 25, 2021
1279ac6
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 25, 2021
152ad45
Merge branch 'master' into robert/rm-bech32-pk
robert-zaremba Mar 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,31 @@ required through --multisig-threshold. The keys are sorted by address, unless
the flag --nosort is set.
`,
Args: cobra.ExactArgs(1),
RunE: runAddCmd,
RunE: runAddCmdPrepare,
}

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")
f := cmd.Flags()
f.StringSlice(flagMultisig, nil, "Construct and store a multisig public key (implies --pubkey)")
f.Int(flagMultiSigThreshold, 1, "K out of N required signatures. For use in conjunction with --multisig")
f.Bool(flagNoSort, false, "Keys passed to --multisig are taken in the order they're supplied")
f.String(FlagPublicKey, "", "Parse a public key in bech32 format and save it to disk")
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
f.BoolP(flagInteractive, "i", false, "Interactively prompt user for BIP39 passphrase and mnemonic")
f.Bool(flags.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device")
f.Bool(flagRecover, false, "Provide seed phrase to recover existing key instead of creating")
f.Bool(flagNoBackup, false, "Don't print out seed phrase (if others are watching the terminal)")
f.Bool(flags.FlagDryRun, false, "Perform action, but don't add key to local keystore")
f.String(flagHDPath, "", "Manual HD Path derivation (overrides BIP44 config)")
f.Uint32(flagCoinType, sdk.GetConfig().GetCoinType(), "coin type number for HD derivation")
f.Uint32(flagAccount, 0, "Account number for HD derivation")
f.Uint32(flagIndex, 0, "Address index number for HD derivation")
f.String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")

cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())

return cmd
}

func runAddCmd(cmd *cobra.Command, args []string) error {
func runAddCmdPrepare(cmd *cobra.Command, args []string) error {
buf := bufio.NewReader(cmd.InOrStdin())
clientCtx := client.GetClientContextFromCmd(cmd)

Expand All @@ -104,7 +104,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
return err
}

return RunAddCmd(cmd, args, kr, buf)
return runAddCmd(clientCtx, cmd, args, kr, buf)
}

/*
Expand All @@ -116,7 +116,7 @@ input
output
- armor encrypted private key (saved to file)
*/
func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *bufio.Reader) error {
func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *bufio.Reader) error {
var err error

name := args[0]
Expand Down Expand Up @@ -186,16 +186,13 @@ 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 {
var pk crypto.PubKey
// TODO: shall we use KeysCdc here (global from this module, = codec.NewLegacyAmino)?
if err := ctx.JSONMarshaler.UnmarshalJSON([]byte(pubKey), &pk); err != nil {
return err
}

if _, err := kb.SavePubKey(name, pk, algo.Name()); err != nil {
return err
}

return nil
_, err := kb.SavePubKey(name, pk, algo.Name())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code compile?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, why not?

return err
}

coinType, _ := cmd.Flags().GetUint32(flagCoinType)
Expand Down
12 changes: 6 additions & 6 deletions client/keys/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
f := cmd.Flags()
f.String(FlagBechPrefix, sdk.PrefixAccount, "The Bech32 prefix encoding for a key (acc|val|cons)")
f.BoolP(FlagAddress, "a", false, "Output the address only (overrides --output)")
f.BoolP(FlagPublicKey, "p", false, "Output the public key only (overrides --output)")
f.BoolP(FlagDevice, "d", false, "Output the address in a ledger device")
f.Int(flagMultiSigThreshold, 1, "K out of N required signatures")

return cmd
}
Expand Down
25 changes: 9 additions & 16 deletions client/rpc/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gorilla/mux"
"github.com/spf13/cobra"

"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -63,10 +64,10 @@ func ValidatorCommand() *cobra.Command {
return cmd
}

// Validator output in bech32 format
// Validator output
type ValidatorOutput struct {
Address sdk.ConsAddress `json:"address"`
PubKey string `json:"pub_key"`
PubKey crypto.PubKey `json:"pub_key"`
ProposerPriority int64 `json:"proposer_priority"`
VotingPower int64 `json:"voting_power"`
}
Expand Down Expand Up @@ -98,18 +99,13 @@ func (rvo ResultValidatorsOutput) String() string {
return b.String()
}

func bech32ValidatorOutput(validator *tmtypes.Validator) (ValidatorOutput, error) {
bechValPubkey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, validator.PubKey)
if err != nil {
return ValidatorOutput{}, err
}

func validatorOutput(validator *tmtypes.Validator) ValidatorOutput {
return ValidatorOutput{
Address: sdk.ConsAddress(validator.Address),
PubKey: bechValPubkey,
PubKey: validator.PubKey,
ProposerPriority: validator.ProposerPriority,
VotingPower: validator.VotingPower,
}, nil
}
}

// GetValidators from client
Expand All @@ -125,19 +121,16 @@ func GetValidators(clientCtx client.Context, height *int64, page, limit *int) (R
return ResultValidatorsOutput{}, err
}

outputValidatorsRes := ResultValidatorsOutput{
out := ResultValidatorsOutput{
BlockHeight: validatorsRes.BlockHeight,
Validators: make([]ValidatorOutput, len(validatorsRes.Validators)),
}

for i := 0; i < len(validatorsRes.Validators); i++ {
outputValidatorsRes.Validators[i], err = bech32ValidatorOutput(validatorsRes.Validators[i])
if err != nil {
return ResultValidatorsOutput{}, err
}
out.Validators[i] = validatorOutput(validatorsRes.Validators[i])
}

return outputValidatorsRes, nil
return out, nil
}

// REST
Expand Down
31 changes: 28 additions & 3 deletions codec/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ package codec
import (
"bytes"

"github.com/cosmos/cosmos-sdk/codec/types"

"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"

"github.com/cosmos/cosmos-sdk/codec/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var defaultJM = &jsonpb.Marshaler{OrigName: true, EmitDefaults: true, AnyResolver: nil}

// ProtoMarshalJSON provides an auxiliary function to return Proto3 JSON encoded
// bytes of a message.
func ProtoMarshalJSON(msg proto.Message, resolver jsonpb.AnyResolver) ([]byte, error) {
// We use the OrigName because camel casing fields just doesn't make sense.
// EmitDefaults is also often the more expected behavior for CLI users
jm := &jsonpb.Marshaler{OrigName: true, EmitDefaults: true, AnyResolver: resolver}
jm := defaultJM
if resolver != nil {
jm = &jsonpb.Marshaler{OrigName: true, EmitDefaults: true, AnyResolver: resolver}
}
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
err := types.UnpackInterfaces(msg, types.ProtoJSONPacker{JSONPBMarshaler: jm})
if err != nil {
return nil, err
Expand All @@ -28,3 +34,22 @@ func ProtoMarshalJSON(msg proto.Message, resolver jsonpb.AnyResolver) ([]byte, e

return buf.Bytes(), nil
}

// ProtoMarshalJSONI same as ProtoMarshalJSON, but does msg type inspection to assert
// that it implements `proto.Message` and return an error if it doesn't.
func ProtoMarshalJSONI(msg interface{}, resolver jsonpb.AnyResolver) ([]byte, error) {
msgProto, err := AssertProtoMsg(msg)
if err != nil {
return nil, err
}
return ProtoMarshalJSON(msgProto, resolver)
}

// AssertProtoMsg casts i to a proto.Message. Returns an error if it's not possible.
func AssertProtoMsg(i interface{}) (proto.Message, error) {
pm, ok := i.(proto.Message)
if !ok {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "Expecting protobuf Message type, got %T", i)
}
return pm, nil
}
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 7 additions & 4 deletions crypto/keyring/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package keyring

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32/legacybech32"
)

// TODO: Update this file and remove legacybech32 ?

// KeyOutput defines a structure wrapping around an Info object used for output
// functionality.
type KeyOutput struct {
Expand Down Expand Up @@ -52,7 +55,7 @@ func Bech32KeysOutput(infos []Info) ([]KeyOutput, error) {
func Bech32ConsKeyOutput(keyInfo Info) (KeyOutput, error) {
consAddr := sdk.ConsAddress(keyInfo.GetPubKey().Address().Bytes())

bechPubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, keyInfo.GetPubKey())
bechPubKey, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeConsPub, keyInfo.GetPubKey())
if err != nil {
return KeyOutput{}, err
}
Expand All @@ -64,7 +67,7 @@ func Bech32ConsKeyOutput(keyInfo Info) (KeyOutput, error) {
func Bech32ValKeyOutput(keyInfo Info) (KeyOutput, error) {
valAddr := sdk.ValAddress(keyInfo.GetPubKey().Address().Bytes())

bechPubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeValPub, keyInfo.GetPubKey())
bechPubKey, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeValPub, keyInfo.GetPubKey())
if err != nil {
return KeyOutput{}, err
}
Expand All @@ -77,7 +80,7 @@ func Bech32ValKeyOutput(keyInfo Info) (KeyOutput, error) {
// public keys will be added.
func Bech32KeyOutput(keyInfo Info) (KeyOutput, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call this function something different? Or is bech32 still used here somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea. I will rename.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the function returns a KeyOutput, which contains an Address which is formatted using bech32.
That being said, I think we don't need bech32 prefix in this function names.

Copy link
Collaborator Author

@robert-zaremba robert-zaremba Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed: Bech32... -> Mk...

accAddr := sdk.AccAddress(keyInfo.GetPubKey().Address().Bytes())
bechPubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, keyInfo.GetPubKey())
bechPubKey, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeAccPub, keyInfo.GetPubKey())
if err != nil {
return KeyOutput{}, err
}
Expand All @@ -90,7 +93,7 @@ func Bech32KeyOutput(keyInfo Info) (KeyOutput, error) {
for i, pk := range mInfo.PubKeys {
accAddr := sdk.AccAddress(pk.PubKey.Address().Bytes())

bechPubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pk.PubKey)
bechPubKey, err := legacybech32.Bech32ifyPubKey(legacybech32.Bech32PubKeyTypeAccPub, pk.PubKey)
if err != nil {
return KeyOutput{}, err
}
Expand Down
7 changes: 7 additions & 0 deletions crypto/keys/ed25519/ed25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,10 @@ func TestMarshalAmino_BackwardsCompatibility(t *testing.T) {
})
}
}

// TODO - finish this test to show who the key will be presented in YAML
func TestMarshalYAML(t *testing.T) {
privKey := ed25519.GenPrivKey()
pubKey := privKey.PubKey()

}
8 changes: 4 additions & 4 deletions crypto/ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"

"github.com/stretchr/testify/require"

tmcrypto "github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/codec"
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/testutil"
Expand All @@ -32,10 +32,10 @@ func TestPublicKeyUnsafe(t *testing.T) {
fmt.Sprintf("%x", cdc.Amino.MustMarshalBinaryBare(priv.PubKey())),
"Is your device using test mnemonic: %s ?", testutil.TestMnemonic)

pubKeyAddr, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, priv.PubKey())
out, err := codec.ProtoMarshalJSONI(pk, nil)
require.NoError(t, err)
require.Equal(t, "cosmospub1addwnpepqd87l8xhcnrrtzxnkql7k55ph8fr9jarf4hn6udwukfprlalu8lgw0urza0",
pubKeyAddr, "Is your device using test mnemonic: %s ?", testutil.TestMnemonic)
// TODO: require.Equal(t, out, ...)
fmt.Println("TODO ledger_test.go", out)

addr := sdk.AccAddress(priv.PubKey().Address()).String()
require.Equal(t, "cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h",
Expand Down
22 changes: 7 additions & 15 deletions server/tm_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ func ShowNodeIDCmd() *cobra.Command {
cfg := serverCtx.Config

nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
if err != nil {
return err
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
if err == nil {
fmt.Println(nodeKey.ID())
}

fmt.Println(nodeKey.ID())
return nil
},
}
Expand All @@ -49,27 +47,19 @@ func ShowValidatorCmd() *cobra.Command {
cfg := serverCtx.Config

privValidator := pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile())
valPubKey, err := privValidator.GetPubKey()
pk, err := privValidator.GetPubKey()
if err != nil {
return err
}

output, _ := cmd.Flags().GetString(cli.OutputFlag)
if strings.ToLower(output) == "json" {
return printlnJSON(valPubKey)
}

pubkey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey)
out, err := codec.ProtoMarshalJSONI(pk, nil)
if err != nil {
return err
}

fmt.Println(pubkey)
fmt.Println(string(out))
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
return nil
},
}

cmd.Flags().StringP(cli.OutputFlag, "o", "text", "Output format (text|json)")
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
return &cmd
}

Expand Down Expand Up @@ -129,6 +119,8 @@ against which this app has been compiled.
}
}

// Deprecated: prints the content to the standard output using Legacy Amino
// TODO: add issue to trace it?
func printlnJSON(v interface{}) error {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shell we use protobuf here?

cdc := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(cdc)
Expand Down
Loading