diff --git a/crypto/encoding/codec.go b/crypto/encoding/codec.go index bf4250f68..56f33f4c7 100644 --- a/crypto/encoding/codec.go +++ b/crypto/encoding/codec.go @@ -1,7 +1,6 @@ package encoding import ( - "errors" "fmt" "github.com/tendermint/tendermint/crypto" @@ -40,36 +39,3 @@ func PubKeyFromProto(k pc.PublicKey) (crypto.PubKey, error) { return nil, fmt.Errorf("fromproto: key type %v is not supported", k) } } - -// PrivKeyToProto takes crypto.PrivKey and transforms it to a protobuf PrivKey -func PrivKeyToProto(k crypto.PrivKey) (pc.PrivateKey, error) { - var kp pc.PrivateKey - switch k := k.(type) { - case ed25519.PrivKey: - kp = pc.PrivateKey{ - Sum: &pc.PrivateKey_Ed25519{ - Ed25519: k, - }, - } - default: - return kp, errors.New("toproto: key type is not supported") - } - return kp, nil -} - -// PrivKeyFromProto takes a protobuf PrivateKey and transforms it to a crypto.PrivKey -func PrivKeyFromProto(k pc.PrivateKey) (crypto.PrivKey, error) { - switch k := k.Sum.(type) { - case *pc.PrivateKey_Ed25519: - - if len(k.Ed25519) != ed25519.PubKeySize { - return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", - len(k.Ed25519), ed25519.PubKeySize) - } - pk := make(ed25519.PrivKey, ed25519.PrivateKeySize) - copy(pk, k.Ed25519) - return pk, nil - default: - return nil, errors.New("fromproto: key type not supported") - } -} diff --git a/proto/tendermint/crypto/keys.pb.go b/proto/tendermint/crypto/keys.pb.go index ca7cc4586..cb54ce0f1 100644 --- a/proto/tendermint/crypto/keys.pb.go +++ b/proto/tendermint/crypto/keys.pb.go @@ -99,89 +99,14 @@ func (*PublicKey) XXX_OneofWrappers() []interface{} { } } -// PrivateKey defines the keys available for use with Tendermint Validators -// WARNING PrivateKey is used for internal purposes only -type PrivateKey struct { - // Types that are valid to be assigned to Sum: - // *PrivateKey_Ed25519 - Sum isPrivateKey_Sum `protobuf_oneof:"sum"` -} - -func (m *PrivateKey) Reset() { *m = PrivateKey{} } -func (m *PrivateKey) String() string { return proto.CompactTextString(m) } -func (*PrivateKey) ProtoMessage() {} -func (*PrivateKey) Descriptor() ([]byte, []int) { - return fileDescriptor_cb048658b234868c, []int{1} -} -func (m *PrivateKey) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *PrivateKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_PrivateKey.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *PrivateKey) XXX_Merge(src proto.Message) { - xxx_messageInfo_PrivateKey.Merge(m, src) -} -func (m *PrivateKey) XXX_Size() int { - return m.Size() -} -func (m *PrivateKey) XXX_DiscardUnknown() { - xxx_messageInfo_PrivateKey.DiscardUnknown(m) -} - -var xxx_messageInfo_PrivateKey proto.InternalMessageInfo - -type isPrivateKey_Sum interface { - isPrivateKey_Sum() - MarshalTo([]byte) (int, error) - Size() int -} - -type PrivateKey_Ed25519 struct { - Ed25519 []byte `protobuf:"bytes,1,opt,name=ed25519,proto3,oneof" json:"ed25519,omitempty"` -} - -func (*PrivateKey_Ed25519) isPrivateKey_Sum() {} - -func (m *PrivateKey) GetSum() isPrivateKey_Sum { - if m != nil { - return m.Sum - } - return nil -} - -func (m *PrivateKey) GetEd25519() []byte { - if x, ok := m.GetSum().(*PrivateKey_Ed25519); ok { - return x.Ed25519 - } - return nil -} - -// XXX_OneofWrappers is for the internal use of the proto package. -func (*PrivateKey) XXX_OneofWrappers() []interface{} { - return []interface{}{ - (*PrivateKey_Ed25519)(nil), - } -} - func init() { proto.RegisterType((*PublicKey)(nil), "tendermint.crypto.PublicKey") - proto.RegisterType((*PrivateKey)(nil), "tendermint.crypto.PrivateKey") } func init() { proto.RegisterFile("tendermint/crypto/keys.proto", fileDescriptor_cb048658b234868c) } var fileDescriptor_cb048658b234868c = []byte{ - // 195 bytes of a gzipped FileDescriptorProto + // 180 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x49, 0xcd, 0x4b, 0x49, 0x2d, 0xca, 0xcd, 0xcc, 0x2b, 0xd1, 0x4f, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0xd7, 0xcf, 0x4e, 0xad, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x44, 0xc8, 0xea, 0x41, 0x64, 0xa5, @@ -189,12 +114,11 @@ var fileDescriptor_cb048658b234868c = []byte{ 0x40, 0x69, 0x52, 0x4e, 0x66, 0xb2, 0x77, 0x6a, 0xa5, 0x90, 0x14, 0x17, 0x7b, 0x6a, 0x8a, 0x91, 0xa9, 0xa9, 0xa1, 0xa5, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8f, 0x07, 0x43, 0x10, 0x4c, 0xc0, 0x8a, 0xe3, 0xc5, 0x02, 0x79, 0xc6, 0x17, 0x0b, 0xe5, 0x19, 0x9d, 0x58, 0xb9, 0x98, 0x8b, 0x4b, 0x73, - 0x95, 0xf4, 0xb9, 0xb8, 0x02, 0x8a, 0x32, 0xcb, 0x12, 0x4b, 0x52, 0x09, 0x68, 0x85, 0x6a, 0x70, - 0x0a, 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, - 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x8b, 0xf4, 0xcc, 0x92, - 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x24, 0x6f, 0x21, 0x31, 0x21, 0xee, 0xc6, 0xf0, - 0x72, 0x12, 0x1b, 0x58, 0xc2, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xc5, 0x95, 0xd2, 0x85, 0x0e, - 0x01, 0x00, 0x00, + 0x9d, 0x82, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, + 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x22, 0x3d, 0xb3, + 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xc9, 0x95, 0x48, 0x4c, 0x88, 0x33, 0x30, + 0x7c, 0x90, 0xc4, 0x06, 0x96, 0x30, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x51, 0x7d, 0xc1, 0x7b, + 0xdd, 0x00, 0x00, 0x00, } func (this *PublicKey) Compare(that interface{}) int { @@ -387,54 +311,6 @@ func (m *PublicKey_Ed25519) MarshalToSizedBuffer(dAtA []byte) (int, error) { } return len(dAtA) - i, nil } -func (m *PrivateKey) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PrivateKey) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *PrivateKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Sum != nil { - { - size := m.Sum.Size() - i -= size - if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - } - } - return len(dAtA) - i, nil -} - -func (m *PrivateKey_Ed25519) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *PrivateKey_Ed25519) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - if m.Ed25519 != nil { - i -= len(m.Ed25519) - copy(dAtA[i:], m.Ed25519) - i = encodeVarintKeys(dAtA, i, uint64(len(m.Ed25519))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} func encodeVarintKeys(dAtA []byte, offset int, v uint64) int { offset -= sovKeys(v) base := offset @@ -470,30 +346,6 @@ func (m *PublicKey_Ed25519) Size() (n int) { } return n } -func (m *PrivateKey) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Sum != nil { - n += m.Sum.Size() - } - return n -} - -func (m *PrivateKey_Ed25519) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Ed25519 != nil { - l = len(m.Ed25519) - n += 1 + l + sovKeys(uint64(l)) - } - return n -} func sovKeys(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 @@ -587,92 +439,6 @@ func (m *PublicKey) Unmarshal(dAtA []byte) error { } return nil } -func (m *PrivateKey) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKeys - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PrivateKey: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PrivateKey: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Ed25519", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKeys - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKeys - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthKeys - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := make([]byte, postIndex-iNdEx) - copy(v, dAtA[iNdEx:postIndex]) - m.Sum = &PrivateKey_Ed25519{v} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipKeys(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthKeys - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthKeys - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipKeys(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/proto/tendermint/crypto/keys.proto b/proto/tendermint/crypto/keys.proto index e3a8ce934..af9db49fc 100644 --- a/proto/tendermint/crypto/keys.proto +++ b/proto/tendermint/crypto/keys.proto @@ -14,11 +14,3 @@ message PublicKey { bytes ed25519 = 1; } } - -// PrivateKey defines the keys available for use with Tendermint Validators -// WARNING PrivateKey is used for internal purposes only -message PrivateKey { - oneof sum { - bytes ed25519 = 1; - } -}