From b2b29d4909395ce3bf6944ce0b740fb5a689b218 Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaurym@users.noreply.github.com> Date: Sun, 15 May 2022 15:02:53 +0200 Subject: [PATCH] chore: Audit crypto folder (#11932) ## Description ref: #11362 I did **NOT** review the following folders, as they contain cryptography which I don't think I'm competent enough to give a useful review: - [ ] `crypto/xsalsa20symmetric` (new in v046, ported from TM i think) - [ ] `crypto/keys/secp256k1` (some new stuff in v046 too) Also performed some manual tests as part of #11939: - [x] Create keys on v0.45, make sure they still work in v0.46 https://github.com/cosmos/cosmos-sdk/issues/11939#issuecomment-1124881492 - [x] Create new keys in v0.46 https://github.com/cosmos/cosmos-sdk/issues/11939#issuecomment-1124881492 - [x] `--multisig` flag works with an address that's not in the keyring (see [repro](https://github.com/cosmos/cosmos-sdk/issues/9553)) --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- CHANGELOG.md | 5 +- api/cosmos/crypto/keyring/v1/record.pulsar.go | 135 ++++-------------- client/keys/export.go | 21 ++- client/keys/migrate.go | 4 +- client/keys/migrate_test.go | 4 +- crypto/keyring/doc.go | 10 +- crypto/keyring/keyring.go | 128 +++++++---------- crypto/keyring/keyring_test.go | 10 +- crypto/keyring/migration_test.go | 34 ++--- crypto/keyring/record.go | 2 +- crypto/keyring/record.pb.go | 101 ++++--------- crypto/keyring/record_test.go | 1 - proto/cosmos/crypto/keyring/v1/record.proto | 9 +- 13 files changed, 161 insertions(+), 303 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a622be931b2d..625212007f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,7 +89,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (types ) [#11881](https://github.com/cosmos/cosmos-sdk/issues/11881) Rename `AccAddressFromHex` to `AccAddressFromHexUnsafe`. +* (crypto/keyring) [#11932](https://github.com/cosmos/cosmos-sdk/pull/11932) Remove `Unsafe*` interfaces from keyring package. Please use interface casting if you wish to access those unsafe functions. +* (types) [#11881](https://github.com/cosmos/cosmos-sdk/issues/11881) Rename `AccAddressFromHex` to `AccAddressFromHexUnsafe`. * (types) [#11788](https://github.com/cosmos/cosmos-sdk/pull/11788) The `Int` and `Uint` types have been moved to their own dedicated module, `math`. Aliases are kept in the SDK's root `types` package, however, it is encouraged to utilize the new `math` module. As a result, the `Int#ToDec` API has been removed. * (grpc) [\#11642](https://github.com/cosmos/cosmos-sdk/pull/11642) The `RegisterTendermintService` method in the `tmservice` package now requires a `abciQueryFn` query function parameter. * [\#11496](https://github.com/cosmos/cosmos-sdk/pull/11496) Refactor abstractions for snapshot and pruning; snapshot intervals eventually pruned; unit tests. @@ -98,7 +99,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#10950](https://github.com/cosmos/cosmos-sdk/pull/10950) Add `envPrefix` parameter to `cmd.Execute`. * (x/mint) [\#10441](https://github.com/cosmos/cosmos-sdk/pull/10441) The `NewAppModule` function now accepts an inflation calculation function as an argument. * [\#10295](https://github.com/cosmos/cosmos-sdk/pull/10295) Remove store type aliases from /types -* [\#9695](https://github.com/cosmos/cosmos-sdk/pull/9695) Migrate keys from `Info` -> `Record` +* [\#9695](https://github.com/cosmos/cosmos-sdk/pull/9695) Migrate keys from `Info` (serialized as amino) -> `Record` (serialized as proto) * Add new `codec.Codec` argument in: * `keyring.NewInMemory` * `keyring.New` diff --git a/api/cosmos/crypto/keyring/v1/record.pulsar.go b/api/cosmos/crypto/keyring/v1/record.pulsar.go index 778a84d976b5..7a330c9c247d 100644 --- a/api/cosmos/crypto/keyring/v1/record.pulsar.go +++ b/api/cosmos/crypto/keyring/v1/record.pulsar.go @@ -945,16 +945,14 @@ func (x *fastReflection_Record) ProtoMethods() *protoiface.Methods { } var ( - md_Record_Local protoreflect.MessageDescriptor - fd_Record_Local_priv_key protoreflect.FieldDescriptor - fd_Record_Local_priv_key_type protoreflect.FieldDescriptor + md_Record_Local protoreflect.MessageDescriptor + fd_Record_Local_priv_key protoreflect.FieldDescriptor ) func init() { file_cosmos_crypto_keyring_v1_record_proto_init() md_Record_Local = File_cosmos_crypto_keyring_v1_record_proto.Messages().ByName("Record").Messages().ByName("Local") fd_Record_Local_priv_key = md_Record_Local.Fields().ByName("priv_key") - fd_Record_Local_priv_key_type = md_Record_Local.Fields().ByName("priv_key_type") } var _ protoreflect.Message = (*fastReflection_Record_Local)(nil) @@ -1028,12 +1026,6 @@ func (x *fastReflection_Record_Local) Range(f func(protoreflect.FieldDescriptor, return } } - if x.PrivKeyType != "" { - value := protoreflect.ValueOfString(x.PrivKeyType) - if !f(fd_Record_Local_priv_key_type, value) { - return - } - } } // Has reports whether a field is populated. @@ -1051,8 +1043,6 @@ func (x *fastReflection_Record_Local) Has(fd protoreflect.FieldDescriptor) bool switch fd.FullName() { case "cosmos.crypto.keyring.v1.Record.Local.priv_key": return x.PrivKey != nil - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - return x.PrivKeyType != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1071,8 +1061,6 @@ func (x *fastReflection_Record_Local) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { case "cosmos.crypto.keyring.v1.Record.Local.priv_key": x.PrivKey = nil - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - x.PrivKeyType = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1092,9 +1080,6 @@ func (x *fastReflection_Record_Local) Get(descriptor protoreflect.FieldDescripto case "cosmos.crypto.keyring.v1.Record.Local.priv_key": value := x.PrivKey return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - value := x.PrivKeyType - return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1117,8 +1102,6 @@ func (x *fastReflection_Record_Local) Set(fd protoreflect.FieldDescriptor, value switch fd.FullName() { case "cosmos.crypto.keyring.v1.Record.Local.priv_key": x.PrivKey = value.Message().Interface().(*anypb.Any) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - x.PrivKeyType = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1144,8 +1127,6 @@ func (x *fastReflection_Record_Local) Mutable(fd protoreflect.FieldDescriptor) p x.PrivKey = new(anypb.Any) } return protoreflect.ValueOfMessage(x.PrivKey.ProtoReflect()) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - panic(fmt.Errorf("field priv_key_type of message cosmos.crypto.keyring.v1.Record.Local is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1162,8 +1143,6 @@ func (x *fastReflection_Record_Local) NewField(fd protoreflect.FieldDescriptor) case "cosmos.crypto.keyring.v1.Record.Local.priv_key": m := new(anypb.Any) return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "cosmos.crypto.keyring.v1.Record.Local.priv_key_type": - return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.keyring.v1.Record.Local")) @@ -1237,10 +1216,6 @@ func (x *fastReflection_Record_Local) ProtoMethods() *protoiface.Methods { l = options.Size(x.PrivKey) n += 1 + l + runtime.Sov(uint64(l)) } - l = len(x.PrivKeyType) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -1270,13 +1245,6 @@ func (x *fastReflection_Record_Local) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } - if len(x.PrivKeyType) > 0 { - i -= len(x.PrivKeyType) - copy(dAtA[i:], x.PrivKeyType) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.PrivKeyType))) - i-- - dAtA[i] = 0x12 - } if x.PrivKey != nil { encoded, err := options.Marshal(x.PrivKey) if err != nil { @@ -1376,38 +1344,6 @@ func (x *fastReflection_Record_Local) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex - case 2: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field PrivKeyType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.PrivKeyType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -2699,22 +2635,22 @@ type isRecord_Item interface { } type Record_Local_ struct { - // local stores the public information about a locally stored key + // local stores the private key locally. Local *Record_Local `protobuf:"bytes,3,opt,name=local,proto3,oneof"` } type Record_Ledger_ struct { - // ledger stores the public information about a Ledger key + // ledger stores the information about a Ledger key. Ledger *Record_Ledger `protobuf:"bytes,4,opt,name=ledger,proto3,oneof"` } type Record_Multi_ struct { - // Multi does not store any information. + // Multi does not store any other information. Multi *Record_Multi `protobuf:"bytes,5,opt,name=multi,proto3,oneof"` } type Record_Offline_ struct { - // Offline does not store any information. + // Offline does not store any other information. Offline *Record_Offline `protobuf:"bytes,6,opt,name=offline,proto3,oneof"` } @@ -2733,8 +2669,7 @@ type Record_Local struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - PrivKey *anypb.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` - PrivKeyType string `protobuf:"bytes,2,opt,name=priv_key_type,json=privKeyType,proto3" json:"priv_key_type,omitempty"` + PrivKey *anypb.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` } func (x *Record_Local) Reset() { @@ -2764,13 +2699,6 @@ func (x *Record_Local) GetPrivKey() *anypb.Any { return nil } -func (x *Record_Local) GetPrivKeyType() string { - if x != nil { - return x.PrivKeyType - } - return "" -} - // Ledger item type Record_Ledger struct { state protoimpl.MessageState @@ -2873,7 +2801,7 @@ var file_cosmos_crypto_keyring_v1_record_proto_rawDesc = []byte{ 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2f, 0x68, 0x64, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0x8e, 0x04, 0x0a, 0x06, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x22, 0xea, 0x03, 0x0a, 0x06, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x70, 0x75, 0x62, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, @@ -2894,34 +2822,31 @@ var file_cosmos_crypto_keyring_v1_record_proto_rawDesc = []byte{ 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x2e, 0x4f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x48, 0x00, 0x52, 0x07, - 0x6f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x1a, 0x5c, 0x0a, 0x05, 0x4c, 0x6f, 0x63, 0x61, 0x6c, + 0x6f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x1a, 0x38, 0x0a, 0x05, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x12, 0x2f, 0x0a, 0x08, 0x70, 0x72, 0x69, 0x76, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, - 0x79, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x72, 0x69, 0x76, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x74, 0x79, - 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x4b, 0x65, - 0x79, 0x54, 0x79, 0x70, 0x65, 0x1a, 0x3e, 0x0a, 0x06, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x12, - 0x34, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x68, 0x64, - 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x49, 0x50, 0x34, 0x34, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, - 0x04, 0x70, 0x61, 0x74, 0x68, 0x1a, 0x07, 0x0a, 0x05, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x1a, 0x09, - 0x0a, 0x07, 0x4f, 0x66, 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x06, 0x0a, 0x04, 0x69, 0x74, 0x65, - 0x6d, 0x42, 0xe7, 0x01, 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, - 0x76, 0x31, 0x42, 0x0b, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, - 0x01, 0x5a, 0x33, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, - 0x6f, 0x2f, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x6b, 0x65, 0x79, - 0x72, 0x69, 0x6e, 0x67, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x4b, 0xaa, 0x02, 0x18, 0x43, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, - 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x5c, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x5c, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, - 0x56, 0x31, 0xe2, 0x02, 0x24, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x79, 0x70, - 0x74, 0x6f, 0x5c, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, - 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x3a, 0x3a, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x3a, 0x3a, 0x4b, 0x65, 0x79, 0x72, - 0x69, 0x6e, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0xc8, 0xe1, 0x1e, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x79, 0x1a, 0x3e, 0x0a, 0x06, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x12, 0x34, 0x0a, 0x04, 0x70, + 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x68, 0x64, 0x2e, 0x76, 0x31, 0x2e, + 0x42, 0x49, 0x50, 0x34, 0x34, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x04, 0x70, 0x61, 0x74, + 0x68, 0x1a, 0x07, 0x0a, 0x05, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x1a, 0x09, 0x0a, 0x07, 0x4f, 0x66, + 0x66, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x06, 0x0a, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x42, 0xe7, 0x01, + 0x0a, 0x1c, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x6f, 0x2e, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x0b, + 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x33, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2f, 0x6b, 0x65, + 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x6b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, + 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x43, 0x4b, 0xaa, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, + 0x2e, 0x56, 0x31, 0xca, 0x02, 0x18, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x79, + 0x70, 0x74, 0x6f, 0x5c, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, + 0x24, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x5c, 0x4b, + 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, + 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x3a, 0x3a, 0x4b, 0x65, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x3a, + 0x3a, 0x56, 0x31, 0xc8, 0xe1, 0x1e, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/client/keys/export.go b/client/keys/export.go index 13491b5e839a..7e2f7250d38f 100644 --- a/client/keys/export.go +++ b/client/keys/export.go @@ -2,6 +2,7 @@ package keys import ( "bufio" + "encoding/hex" "fmt" "github.com/spf13/cobra" @@ -9,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/input" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/types" ) const ( @@ -75,7 +77,7 @@ func exportUnsafeUnarmored(cmd *cobra.Command, uid string, buf *bufio.Reader, kr return nil } - hexPrivKey, err := keyring.NewUnsafe(kr).UnsafeExportPrivKeyHex(uid) + hexPrivKey, err := unsafeExportPrivKeyHex(kr.(unsafeExporter), uid) if err != nil { return err } @@ -84,3 +86,20 @@ func exportUnsafeUnarmored(cmd *cobra.Command, uid string, buf *bufio.Reader, kr return nil } + +// unsafeExporter is implemented by key stores that support unsafe export +// of private keys' material. +type unsafeExporter interface { + // ExportPrivateKeyObject returns a private key in unarmored format. + ExportPrivateKeyObject(uid string) (types.PrivKey, error) +} + +// unsafeExportPrivKeyHex exports private keys in unarmored hexadecimal format. +func unsafeExportPrivKeyHex(ks unsafeExporter, uid string) (privkey string, err error) { + priv, err := ks.ExportPrivateKeyObject(uid) + if err != nil { + return "", err + } + + return hex.EncodeToString(priv.Bytes()), nil +} diff --git a/client/keys/migrate.go b/client/keys/migrate.go index ff6cde2244a3..f76206f6ed9f 100644 --- a/client/keys/migrate.go +++ b/client/keys/migrate.go @@ -34,10 +34,10 @@ func runMigrateCmd(cmd *cobra.Command, _ []string) error { return err } - if _, err = clientCtx.Keyring.MigrateAll(); err != nil { + if err = clientCtx.Keyring.MigrateAll(); err != nil { return err } - cmd.Println("Keys migration has been successfully executed") + cmd.Println("Keys migration has been successfully executed.") return nil } diff --git a/client/keys/migrate_test.go b/client/keys/migrate_test.go index 48eefb168661..3e5e54942a91 100644 --- a/client/keys/migrate_test.go +++ b/client/keys/migrate_test.go @@ -55,9 +55,9 @@ func (s *MigrateTestSuite) Test_runListAndShowCmd() { serializedLegacyMultiInfo := keyring.MarshalInfo(legacyMultiInfo) item := design99keyring.Item{ - Key: s.appName, + Key: s.appName + ".info", Data: serializedLegacyMultiInfo, - Description: "SDK kerying version", + Description: "SDK keyring version", } //run test simd keys list - to see that the migrated key is there diff --git a/crypto/keyring/doc.go b/crypto/keyring/doc.go index 04a8b98cdfba..b642680c0662 100644 --- a/crypto/keyring/doc.go +++ b/crypto/keyring/doc.go @@ -1,17 +1,11 @@ // Package keys provides common key management API. // // -// The Keybase interface +// The Keyring interface // -// The Keybase interface defines the methods that a type needs to implement to be used +// The Keyring interface defines the methods that a type needs to implement to be used // as key storage backend. This package provides few implementations out-of-the-box. // -// NewLegacy -// -// The NewLegacy constructor returns an on-disk implementation backed by LevelDB storage that has been -// the default implementation used by the SDK until v0.38.0. Due to security concerns, it is -// recommended to drop it in favor of the NewKeyring constructor as it will be removed in future releases. -// // NewInMemory // // The NewInMemory constructor returns an implementation backed by an in-memory, goroutine-safe diff --git a/crypto/keyring/keyring.go b/crypto/keyring/keyring.go index 7cd3bd310730..303b0ed07fce 100644 --- a/crypto/keyring/keyring.go +++ b/crypto/keyring/keyring.go @@ -100,13 +100,6 @@ type Keyring interface { Migrator } -// UnsafeKeyring exposes unsafe operations such as unsafe unarmored export in -// addition to those that are made available by the Keyring interface. -type UnsafeKeyring interface { - Keyring - UnsafeExporter -} - // Signer is implemented by key stores that want to provide signing capabilities. type Signer interface { // Sign sign byte messages with a user key. @@ -125,9 +118,9 @@ type Importer interface { ImportPubKey(uid string, armor string) error } -// Migrator is implemented by key stores and enables migration of keys from amino to proto +// Migrator is implemented by key stores and enables migration of keys from amino to proto type Migrator interface { - MigrateAll() (bool, error) + MigrateAll() error } // Exporter is implemented by key stores that support export of public and private keys. @@ -142,13 +135,6 @@ type Exporter interface { ExportPrivKeyArmorByAddress(address sdk.Address, encryptPassphrase string) (armor string, err error) } -// UnsafeExporter is implemented by key stores that support unsafe export -// of private keys' material. -type UnsafeExporter interface { - // UnsafeExportPrivKeyHex returns a private key in unarmored hex format - UnsafeExportPrivKeyHex(uid string) (string, error) -} - // Option overrides keyring configuration options. type Option func(options *Options) @@ -500,7 +486,7 @@ func wrapKeyNotFound(err error, msg string) error { } func (ks keystore) List() ([]*Record, error) { - if _, err := ks.MigrateAll(); err != nil { + if err := ks.MigrateAll(); err != nil { return nil, err } @@ -512,7 +498,7 @@ func (ks keystore) List() ([]*Record, error) { var res []*Record //nolint:prealloc sort.Strings(keys) for _, key := range keys { - if strings.Contains(key, addressSuffix) { + if strings.HasSuffix(key, addressSuffix) { continue } @@ -597,7 +583,7 @@ func (ks keystore) isSupportedSigningAlgo(algo SignatureAlgo) bool { } func (ks keystore) Key(uid string) (*Record, error) { - k, _, err := ks.migrate(uid) + k, err := ks.migrate(uid) if err != nil { return nil, err } @@ -778,7 +764,11 @@ func (ks keystore) writeLocalKey(name string, privKey types.PrivKey) (*Record, e return k, ks.writeRecord(k) } -// writeRecord persists a keyring item in keystore if it does not exist there +// writeRecord persists a keyring item in keystore if it does not exist there. +// For each key record, we actually write 2 items: +// - one with key `.info`, with Data = the serialized protobuf key +// - another with key `.address`, with Data = the uid (i.e. the key name) +// This is to be able to query keys both by name and by address. func (ks keystore) writeRecord(k *Record) error { addr, err := k.GetAddress() if err != nil { @@ -797,7 +787,7 @@ func (ks keystore) writeRecord(k *Record) error { serializedRecord, err := ks.cdc.Marshal(k) if err != nil { - return fmt.Errorf("unable to serialize record, err - %s", err) + return fmt.Errorf("unable to serialize record; %+w", err) } item := keyring.Item{ @@ -871,83 +861,96 @@ func (ks keystore) writeMultisigKey(name string, pk types.PubKey) (*Record, erro return k, ks.writeRecord(k) } -func (ks keystore) MigrateAll() (bool, error) { +func (ks keystore) MigrateAll() error { keys, err := ks.db.Keys() if err != nil { - return false, err + return err } if len(keys) == 0 { - return false, nil + return nil } - var migrated bool for _, key := range keys { - if strings.Contains(key, addressSuffix) { + // The keyring items with `.address` suffix only holds as Data the + // key name uid, so there's nothing to migrate. + if strings.HasSuffix(key, addressSuffix) { continue } - _, migrated2, err := ks.migrate(key) + _, err := ks.migrate(key) if err != nil { - fmt.Printf("migrate err: %q", err) + fmt.Printf("migrate err for key %s: %q\n", key, err) continue } - - if migrated2 { - migrated = true - } } - return migrated, nil + return nil } // migrate converts keyring.Item from amino to proto serialization format. -func (ks keystore) migrate(key string) (*Record, bool, error) { - if !(strings.HasSuffix(key, infoSuffix)) && !(strings.HasPrefix(key, sdk.Bech32PrefixAccAddr)) { +// the `key` argument can be a key uid (e.g. "alice") or with the '.info' +// suffix (e.g. "alice.info"). +// +// It operates as follows: +// 1. retrieve any key +// 2. try to decode it using protobuf +// 3. if ok, then return the key, do nothing else +// 4. if it fails, then try to decode it using amino +// 5. convert from the amino struct to the protobuf struct +// 6. write the proto-encoded key back to the keyring +func (ks keystore) migrate(key string) (*Record, error) { + if !strings.HasSuffix(key, infoSuffix) { key = infoKey(key) } + + // 1. get the key. item, err := ks.db.Get(key) if err != nil { - return nil, false, wrapKeyNotFound(err, key) + return nil, wrapKeyNotFound(err, key) } if len(item.Data) == 0 { - return nil, false, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key) + return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key) } - // 2.try to deserialize using proto, if good then continue, otherwise try to deserialize using amino + // 2. Try to deserialize using proto k, err := ks.protoUnmarshalRecord(item.Data) + // 3. If ok then return the key if err == nil { - return k, false, nil + return k, nil } - LegacyInfo, err := unMarshalLegacyInfo(item.Data) + // 4. Try to decode with amino + legacyInfo, err := unMarshalLegacyInfo(item.Data) if err != nil { - return nil, false, fmt.Errorf("unable to unmarshal item.Data, err: %w", err) + return nil, fmt.Errorf("unable to unmarshal item.Data, err: %w", err) } - // 4.serialize info using proto - k, err = ks.convertFromLegacyInfo(LegacyInfo) + // 5. Convert and serialize info using proto + k, err = ks.convertFromLegacyInfo(legacyInfo) if err != nil { - return nil, false, fmt.Errorf("convertFromLegacyInfo, err: %w", err) + return nil, fmt.Errorf("convertFromLegacyInfo, err: %w", err) } serializedRecord, err := ks.cdc.Marshal(k) if err != nil { - return nil, false, fmt.Errorf("unable to serialize record, err: %w", err) + return nil, fmt.Errorf("unable to serialize record, err: %w", err) } item = keyring.Item{ - Key: key, - Data: serializedRecord, - Description: "SDK kerying version", + Key: key, + Data: serializedRecord, } - // 5.overwrite the keyring entry with + + // 6. Overwrite the keyring entry with the new proto-encoded key. if err := ks.SetItem(item); err != nil { - return nil, false, fmt.Errorf("unable to set keyring.Item, err: %w", err) + return nil, fmt.Errorf("unable to set keyring.Item, err: %w", err) } - return k, true, nil + fmt.Printf("Successfully migrated key %s.\n", key) + + return k, nil } func (ks keystore) protoUnmarshalRecord(bz []byte) (*Record, error) { @@ -996,29 +999,6 @@ func (ks keystore) convertFromLegacyInfo(info LegacyInfo) (*Record, error) { } } -type unsafeKeystore struct { - keystore -} - -// NewUnsafe returns a new keyring that provides support for unsafe operations. -func NewUnsafe(kr Keyring) UnsafeKeyring { - // The type assertion is against the only keystore - // implementation that is currently provided. - ks := kr.(keystore) - - return unsafeKeystore{ks} -} - -// UnsafeExportPrivKeyHex exports private keys in unarmored hexadecimal format. -func (ks unsafeKeystore) UnsafeExportPrivKeyHex(uid string) (privkey string, err error) { - priv, err := ks.ExportPrivateKeyObject(uid) - if err != nil { - return "", err - } - - return hex.EncodeToString(priv.Bytes()), nil -} - func addrHexKeyAsString(address sdk.Address) string { return fmt.Sprintf("%s.%s", hex.EncodeToString(address.Bytes()), addressSuffix) } diff --git a/crypto/keyring/keyring_test.go b/crypto/keyring/keyring_test.go index f258c05e3cf4..a0a006b4f112 100644 --- a/crypto/keyring/keyring_test.go +++ b/crypto/keyring/keyring_test.go @@ -1287,17 +1287,13 @@ func TestAltKeyring_UnsafeExportPrivKeyHex(t *testing.T) { _, _, err = kr.NewMnemonic(uid, English, sdk.FullFundraiserPath, DefaultBIP39Passphrase, hd.Secp256k1) require.NoError(t, err) - unsafeKeyring := NewUnsafe(kr) - privKey, err := unsafeKeyring.UnsafeExportPrivKeyHex(uid) + privKey, err := kr.(keystore).ExportPrivateKeyObject(uid) require.NoError(t, err) - require.Equal(t, 64, len(privKey)) - - _, err = hex.DecodeString(privKey) - require.NoError(t, err) + require.Equal(t, 64, len(hex.EncodeToString(privKey.Bytes()))) // test error on non existing key - _, err = unsafeKeyring.UnsafeExportPrivKeyHex("non-existing") + _, err = kr.(keystore).ExportPrivateKeyObject("non-existing") require.Error(t, err) } diff --git a/crypto/keyring/migration_test.go b/crypto/keyring/migration_test.go index cfe55bd657a9..939bc4a83ef0 100644 --- a/crypto/keyring/migration_test.go +++ b/crypto/keyring/migration_test.go @@ -16,7 +16,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -const n1 = "cosmos" +const n1 = "cosmos.info" type MigrationTestSuite struct { suite.Suite @@ -57,8 +57,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyLocalKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err := s.ks.migrate(n1) s.Require().NoError(err) } @@ -76,8 +75,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyLedgerKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err := s.ks.migrate(n1) s.Require().NoError(err) } @@ -93,8 +91,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyOfflineKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err := s.ks.migrate(n1) s.Require().NoError(err) } @@ -117,8 +114,7 @@ func (s *MigrationTestSuite) TestMigrateLegacyMultiKey() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().True(migrated) + _, err = s.ks.migrate(n1) s.Require().NoError(err) } @@ -137,7 +133,7 @@ func (s *MigrationTestSuite) TestMigrateLocalRecord() { s.Require().NoError(s.ks.SetItem(item)) - k2, migrated, err := s.ks.migrate(n1) + k2, err := s.ks.migrate(n1) s.Require().Equal(k2.Name, k1.Name) pub, err := k2.GetPubKey() @@ -148,7 +144,6 @@ func (s *MigrationTestSuite) TestMigrateLocalRecord() { s.Require().NoError(err) s.Require().Equal(priv, s.priv) - s.Require().False(migrated) s.Require().NoError(err) } @@ -162,8 +157,7 @@ func (s *MigrationTestSuite) TestMigrateOneRandomItemError() { s.Require().NoError(s.ks.SetItem(errItem)) - _, migrated, err := s.ks.migrate(n1) - s.Require().False(migrated) + _, err := s.ks.migrate(n1) s.Require().Error(err) } @@ -197,14 +191,12 @@ func (s *MigrationTestSuite) TestMigrateAllLegacyMultiOffline() { s.Require().NoError(s.ks.SetItem(item)) - migrated, err := s.kb.MigrateAll() - s.Require().True(migrated) + err = s.kb.MigrateAll() s.Require().NoError(err) } func (s *MigrationTestSuite) TestMigrateAllNoItem() { - migrated, err := s.kb.MigrateAll() - s.Require().False(migrated) + err := s.kb.MigrateAll() s.Require().NoError(err) } @@ -221,9 +213,8 @@ func (s *MigrationTestSuite) TestMigrateErrUnknownItemKey() { s.Require().NoError(s.ks.SetItem(item)) incorrectItemKey := n1 + "1" - _, migrated, err := s.ks.migrate(incorrectItemKey) - s.Require().False(migrated) - s.Require().EqualError(err, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, incorrectItemKey).Error()) + _, err := s.ks.migrate(incorrectItemKey) + s.Require().EqualError(err, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, infoKey(incorrectItemKey)).Error()) } func (s *MigrationTestSuite) TestMigrateErrEmptyItemData() { @@ -235,8 +226,7 @@ func (s *MigrationTestSuite) TestMigrateErrEmptyItemData() { s.Require().NoError(s.ks.SetItem(item)) - _, migrated, err := s.ks.migrate(n1) - s.Require().False(migrated) + _, err := s.ks.migrate(n1) s.Require().EqualError(err, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, n1).Error()) } func TestMigrationTestSuite(t *testing.T) { diff --git a/crypto/keyring/record.go b/crypto/keyring/record.go index acc84f6490b1..1b1885648e5e 100644 --- a/crypto/keyring/record.go +++ b/crypto/keyring/record.go @@ -28,7 +28,7 @@ func NewLocalRecord(name string, priv cryptotypes.PrivKey, pk cryptotypes.PubKey return nil, err } - recordLocal := &Record_Local{any, priv.Type()} + recordLocal := &Record_Local{any} recordLocalItem := &Record_Local_{recordLocal} return newRecord(name, pk, recordLocalItem) diff --git a/crypto/keyring/record.pb.go b/crypto/keyring/record.pb.go index c94e1ce0faa8..5e8df719a5c6 100644 --- a/crypto/keyring/record.pb.go +++ b/crypto/keyring/record.pb.go @@ -146,8 +146,7 @@ func (*Record) XXX_OneofWrappers() []interface{} { // Item is a keyring item stored in a keyring backend. // Local item type Record_Local struct { - PrivKey *types.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` - PrivKeyType string `protobuf:"bytes,2,opt,name=priv_key_type,json=privKeyType,proto3" json:"priv_key_type,omitempty"` + PrivKey *types.Any `protobuf:"bytes,1,opt,name=priv_key,json=privKey,proto3" json:"priv_key,omitempty"` } func (m *Record_Local) Reset() { *m = Record_Local{} } @@ -308,34 +307,33 @@ func init() { } var fileDescriptor_36d640103edea005 = []byte{ - // 424 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4d, 0x8b, 0xd4, 0x30, - 0x18, 0xc7, 0x5b, 0xed, 0xb4, 0x4e, 0x16, 0x2f, 0x61, 0x0f, 0xb5, 0x48, 0x19, 0x16, 0xd4, 0x01, - 0xd9, 0x84, 0xd5, 0x39, 0x2f, 0xec, 0xe0, 0x61, 0x16, 0x15, 0x97, 0xe0, 0x49, 0x84, 0xa5, 0x2f, - 0x99, 0xb6, 0x4c, 0xdb, 0x84, 0x4c, 0x3b, 0x90, 0x2f, 0x21, 0x7e, 0xac, 0x3d, 0xee, 0xd1, 0xa3, - 0xce, 0x7c, 0x11, 0xc9, 0x93, 0xf6, 0xe0, 0x82, 0x8e, 0xa7, 0xa6, 0xe4, 0xf7, 0xfc, 0x5f, 0x1e, - 0x82, 0x5e, 0x64, 0x62, 0xdb, 0x88, 0x2d, 0xcd, 0x94, 0x96, 0x9d, 0xa0, 0x1b, 0xae, 0x55, 0xd5, - 0x16, 0x74, 0x77, 0x41, 0x15, 0xcf, 0x84, 0xca, 0x89, 0x54, 0xa2, 0x13, 0x38, 0xb4, 0x18, 0xb1, - 0x18, 0x19, 0x30, 0xb2, 0xbb, 0x88, 0x4e, 0x0b, 0x51, 0x08, 0x80, 0xa8, 0x39, 0x59, 0x3e, 0x7a, - 0x56, 0x08, 0x51, 0xd4, 0x9c, 0xc2, 0x5f, 0xda, 0xaf, 0x69, 0xd2, 0xea, 0xe1, 0xea, 0xf9, 0x9f, - 0x8e, 0x65, 0x6e, 0xcc, 0xca, 0xc1, 0xe8, 0xec, 0x9b, 0x87, 0x7c, 0x06, 0xce, 0x18, 0x23, 0xaf, - 0x4d, 0x1a, 0x1e, 0xba, 0x33, 0x77, 0x3e, 0x65, 0x70, 0xc6, 0xe7, 0x28, 0x90, 0x7d, 0x7a, 0xbb, - 0xe1, 0x3a, 0x7c, 0x34, 0x73, 0xe7, 0x27, 0x6f, 0x4e, 0x89, 0x75, 0x22, 0xa3, 0x13, 0xb9, 0x6a, - 0x35, 0xf3, 0x65, 0x9f, 0xbe, 0xe7, 0x1a, 0x5f, 0xa2, 0x49, 0x2d, 0xb2, 0xa4, 0x0e, 0x1f, 0x03, - 0xfc, 0x92, 0xfc, 0xad, 0x06, 0xb1, 0x9e, 0xe4, 0x83, 0xa1, 0x57, 0x0e, 0xb3, 0x63, 0xf8, 0x0a, - 0xf9, 0x35, 0xcf, 0x0b, 0xae, 0x42, 0x0f, 0x04, 0x5e, 0x1d, 0x17, 0x00, 0x7c, 0xe5, 0xb0, 0x61, - 0xd0, 0x44, 0x68, 0xfa, 0xba, 0xab, 0xc2, 0xc9, 0x7f, 0x46, 0xf8, 0x68, 0x68, 0x13, 0x01, 0xc6, - 0xf0, 0x3b, 0x14, 0x88, 0xf5, 0xba, 0xae, 0x5a, 0x1e, 0xfa, 0xa0, 0x30, 0x3f, 0xaa, 0xf0, 0xc9, - 0xf2, 0x2b, 0x87, 0x8d, 0xa3, 0xd1, 0x57, 0x34, 0x81, 0x6a, 0x98, 0xa2, 0x27, 0x52, 0x55, 0x3b, - 0xd8, 0xa0, 0xfb, 0x8f, 0x0d, 0x06, 0x86, 0x32, 0x2b, 0x3c, 0x43, 0x4f, 0xc7, 0x81, 0xdb, 0x4e, - 0x4b, 0x0e, 0x7b, 0x9f, 0xb2, 0x93, 0xe1, 0xfe, 0xb3, 0x96, 0x3c, 0xba, 0x44, 0xbe, 0xed, 0x8d, - 0x17, 0xc8, 0x93, 0x49, 0x57, 0x0e, 0xd2, 0xb3, 0x07, 0x51, 0xcb, 0xdc, 0xa4, 0x5c, 0x5e, 0xdf, - 0x2c, 0x16, 0x37, 0x89, 0x4a, 0x9a, 0x2d, 0x03, 0x3a, 0x0a, 0xd0, 0x04, 0x5a, 0x47, 0x53, 0x14, - 0x0c, 0xe1, 0x97, 0x3e, 0xf2, 0xaa, 0x8e, 0x37, 0xcb, 0xeb, 0xbb, 0x5f, 0xb1, 0x73, 0xb7, 0x8f, - 0xdd, 0xfb, 0x7d, 0xec, 0xfe, 0xdc, 0xc7, 0xee, 0xf7, 0x43, 0xec, 0xdc, 0x1f, 0x62, 0xe7, 0xc7, - 0x21, 0x76, 0xbe, 0xbc, 0x2e, 0xaa, 0xae, 0xec, 0x53, 0x92, 0x89, 0x86, 0x8e, 0xef, 0x0a, 0x3e, - 0xe7, 0xdb, 0x7c, 0xf3, 0xe0, 0x51, 0xa7, 0x3e, 0x34, 0x7c, 0xfb, 0x3b, 0x00, 0x00, 0xff, 0xff, - 0xe8, 0x29, 0x24, 0x50, 0xf4, 0x02, 0x00, 0x00, + // 408 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3d, 0x6b, 0xdb, 0x40, + 0x1c, 0xc6, 0xa5, 0x5a, 0x2f, 0xf5, 0x75, 0x3b, 0x3c, 0xa8, 0xa2, 0x08, 0x53, 0x68, 0x6b, 0x28, + 0xbe, 0xc3, 0xad, 0x87, 0x4e, 0x06, 0x9b, 0x0e, 0x36, 0x4e, 0x88, 0xd1, 0x98, 0x25, 0xe8, 0xe5, + 0x2c, 0x09, 0x4b, 0x3a, 0x71, 0x92, 0x0c, 0xfa, 0x16, 0xf9, 0x58, 0x1e, 0x3d, 0x66, 0x4c, 0xec, + 0x2d, 0x9f, 0x22, 0xdc, 0x9d, 0x3c, 0xc4, 0x90, 0x38, 0x93, 0x4e, 0xdc, 0xef, 0xf9, 0x3f, 0xcf, + 0x73, 0xfc, 0xc1, 0x8f, 0x80, 0x96, 0x19, 0x2d, 0x71, 0xc0, 0x9a, 0xa2, 0xa2, 0x78, 0x43, 0x1a, + 0x96, 0xe4, 0x11, 0xde, 0x8e, 0x30, 0x23, 0x01, 0x65, 0x21, 0x2a, 0x18, 0xad, 0x28, 0xb4, 0x24, + 0x86, 0x24, 0x86, 0x5a, 0x0c, 0x6d, 0x47, 0x76, 0x2f, 0xa2, 0x11, 0x15, 0x10, 0xe6, 0x27, 0xc9, + 0xdb, 0x5f, 0x23, 0x4a, 0xa3, 0x94, 0x60, 0xf1, 0xe7, 0xd7, 0x6b, 0xec, 0xe5, 0x4d, 0x7b, 0xf5, + 0xed, 0xb5, 0x63, 0x1c, 0x72, 0xb3, 0xb8, 0x35, 0xfa, 0xfe, 0xdc, 0x01, 0x86, 0x2b, 0x9c, 0x21, + 0x04, 0x5a, 0xee, 0x65, 0xc4, 0x52, 0xfb, 0xea, 0xa0, 0xeb, 0x8a, 0x33, 0x1c, 0x02, 0xb3, 0xa8, + 0xfd, 0xbb, 0x0d, 0x69, 0xac, 0x4f, 0x7d, 0x75, 0xf0, 0xe5, 0x4f, 0x0f, 0x49, 0x27, 0x74, 0x72, + 0x42, 0xd3, 0xbc, 0x71, 0x8d, 0xa2, 0xf6, 0x97, 0xa4, 0x81, 0x13, 0xa0, 0xa7, 0x34, 0xf0, 0x52, + 0xab, 0x23, 0xe0, 0x9f, 0xe8, 0xad, 0x1a, 0x48, 0x7a, 0xa2, 0x2b, 0x4e, 0xcf, 0x15, 0x57, 0xca, + 0xe0, 0x14, 0x18, 0x29, 0x09, 0x23, 0xc2, 0x2c, 0x4d, 0x0c, 0xf8, 0x75, 0x79, 0x80, 0xc0, 0xe7, + 0x8a, 0xdb, 0x0a, 0x79, 0x84, 0xac, 0x4e, 0xab, 0xc4, 0xd2, 0x3f, 0x18, 0xe1, 0x9a, 0xd3, 0x3c, + 0x82, 0x90, 0xc1, 0xff, 0xc0, 0xa4, 0xeb, 0x75, 0x9a, 0xe4, 0xc4, 0x32, 0xc4, 0x84, 0xc1, 0xc5, + 0x09, 0x37, 0x92, 0x9f, 0x2b, 0xee, 0x49, 0x6a, 0xff, 0x03, 0xba, 0xa8, 0x06, 0x31, 0xf8, 0x5c, + 0xb0, 0x64, 0x2b, 0x5e, 0x50, 0x7d, 0xe7, 0x05, 0x4d, 0x4e, 0x2d, 0x49, 0x63, 0x4f, 0x80, 0x21, + 0x3b, 0xc1, 0x31, 0xd0, 0x0a, 0xaf, 0x8a, 0x5b, 0x59, 0xff, 0x2c, 0x46, 0x1c, 0xf2, 0x04, 0xb3, + 0xc5, 0x6a, 0x3c, 0x5e, 0x79, 0xcc, 0xcb, 0x4a, 0x57, 0xd0, 0xb6, 0x09, 0x74, 0xd1, 0xc8, 0xee, + 0x02, 0xb3, 0x0d, 0x36, 0x33, 0x80, 0x96, 0x54, 0x24, 0x9b, 0x2d, 0x76, 0x4f, 0x8e, 0xb2, 0x3b, + 0x38, 0xea, 0xfe, 0xe0, 0xa8, 0x8f, 0x07, 0x47, 0xbd, 0x3f, 0x3a, 0xca, 0xfe, 0xe8, 0x28, 0x0f, + 0x47, 0x47, 0xb9, 0xfd, 0x1d, 0x25, 0x55, 0x5c, 0xfb, 0x28, 0xa0, 0x19, 0x3e, 0xed, 0x8c, 0xf8, + 0x0c, 0xcb, 0x70, 0x73, 0xb6, 0xb0, 0xbe, 0x21, 0xd2, 0xff, 0x7d, 0x09, 0x00, 0x00, 0xff, 0xff, + 0x64, 0x83, 0x0c, 0x89, 0xd0, 0x02, 0x00, 0x00, } func (m *Record) Marshal() (dAtA []byte, err error) { @@ -493,13 +491,6 @@ func (m *Record_Local) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.PrivKeyType) > 0 { - i -= len(m.PrivKeyType) - copy(dAtA[i:], m.PrivKeyType) - i = encodeVarintRecord(dAtA, i, uint64(len(m.PrivKeyType))) - i-- - dAtA[i] = 0x12 - } if m.PrivKey != nil { { size, err := m.PrivKey.MarshalToSizedBuffer(dAtA[:i]) @@ -685,10 +676,6 @@ func (m *Record_Local) Size() (n int) { l = m.PrivKey.Size() n += 1 + l + sovRecord(uint64(l)) } - l = len(m.PrivKeyType) - if l > 0 { - n += 1 + l + sovRecord(uint64(l)) - } return n } @@ -1052,38 +1039,6 @@ func (m *Record_Local) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PrivKeyType", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRecord - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRecord - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRecord - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.PrivKeyType = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipRecord(dAtA[iNdEx:]) diff --git a/crypto/keyring/record_test.go b/crypto/keyring/record_test.go index 6c17379b4653..2ec0401d87ff 100644 --- a/crypto/keyring/record_test.go +++ b/crypto/keyring/record_test.go @@ -78,7 +78,6 @@ func (s *RecordTestSuite) TestLocalRecordMarshaling() { anyPrivKey, err := codectypes.NewAnyWithValue(s.priv) s.Require().NoError(err) s.Require().Equal(localRecord2.PrivKey, anyPrivKey) - s.Require().Equal(localRecord2.PrivKeyType, s.priv.Type()) } func (s *RecordTestSuite) TestLedgerRecordMarshaling() { diff --git a/proto/cosmos/crypto/keyring/v1/record.proto b/proto/cosmos/crypto/keyring/v1/record.proto index 1461c0193c9b..ca70aa984af6 100644 --- a/proto/cosmos/crypto/keyring/v1/record.proto +++ b/proto/cosmos/crypto/keyring/v1/record.proto @@ -18,13 +18,13 @@ message Record { // Record contains one of the following items oneof item { - // local stores the public information about a locally stored key + // local stores the private key locally. Local local = 3; - // ledger stores the public information about a Ledger key + // ledger stores the information about a Ledger key. Ledger ledger = 4; - // Multi does not store any information. + // Multi does not store any other information. Multi multi = 5; - // Offline does not store any information. + // Offline does not store any other information. Offline offline = 6; } @@ -32,7 +32,6 @@ message Record { // Local item message Local { google.protobuf.Any priv_key = 1; - string priv_key_type = 2; } // Ledger item