From 40082b823f6a6b3255aa5f5faed3af90f4f3668b Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Thu, 14 May 2020 16:45:19 -0400 Subject: [PATCH] Merge PR #6217: Add pub key proto definitions --- crypto/types/types.pb.go | 1069 ++++++++++++++++- crypto/types/types.proto | 34 +- .../adr-020-protobuf-transaction-encoding.md | 27 + 3 files changed, 1114 insertions(+), 16 deletions(-) diff --git a/crypto/types/types.pb.go b/crypto/types/types.pb.go index 041217920..f859315e0 100644 --- a/crypto/types/types.pb.go +++ b/crypto/types/types.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -22,6 +24,247 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// PublicKey specifies a public key +type PublicKey struct { + // sum specifies which type of public key is wrapped + // + // Types that are valid to be assigned to Sum: + // *PublicKey_Secp256K1 + // *PublicKey_Ed25519 + // *PublicKey_Sr25519 + // *PublicKey_Multisig + // *PublicKey_Secp256R1 + // *PublicKey_AnyPubkey + Sum isPublicKey_Sum `protobuf_oneof:"sum"` +} + +func (m *PublicKey) Reset() { *m = PublicKey{} } +func (m *PublicKey) String() string { return proto.CompactTextString(m) } +func (*PublicKey) ProtoMessage() {} +func (*PublicKey) Descriptor() ([]byte, []int) { + return fileDescriptor_2165b2a1badb1b0c, []int{0} +} +func (m *PublicKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PublicKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PublicKey.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 *PublicKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_PublicKey.Merge(m, src) +} +func (m *PublicKey) XXX_Size() int { + return m.Size() +} +func (m *PublicKey) XXX_DiscardUnknown() { + xxx_messageInfo_PublicKey.DiscardUnknown(m) +} + +var xxx_messageInfo_PublicKey proto.InternalMessageInfo + +type isPublicKey_Sum interface { + isPublicKey_Sum() + MarshalTo([]byte) (int, error) + Size() int +} + +type PublicKey_Secp256K1 struct { + Secp256K1 []byte `protobuf:"bytes,1,opt,name=secp256k1,proto3,oneof" json:"secp256k1,omitempty"` +} +type PublicKey_Ed25519 struct { + Ed25519 []byte `protobuf:"bytes,2,opt,name=ed25519,proto3,oneof" json:"ed25519,omitempty"` +} +type PublicKey_Sr25519 struct { + Sr25519 []byte `protobuf:"bytes,3,opt,name=sr25519,proto3,oneof" json:"sr25519,omitempty"` +} +type PublicKey_Multisig struct { + Multisig *PubKeyMultisigThreshold `protobuf:"bytes,4,opt,name=multisig,proto3,oneof" json:"multisig,omitempty"` +} +type PublicKey_Secp256R1 struct { + Secp256R1 []byte `protobuf:"bytes,5,opt,name=secp256r1,proto3,oneof" json:"secp256r1,omitempty"` +} +type PublicKey_AnyPubkey struct { + AnyPubkey *types.Any `protobuf:"bytes,15,opt,name=any_pubkey,json=anyPubkey,proto3,oneof" json:"any_pubkey,omitempty"` +} + +func (*PublicKey_Secp256K1) isPublicKey_Sum() {} +func (*PublicKey_Ed25519) isPublicKey_Sum() {} +func (*PublicKey_Sr25519) isPublicKey_Sum() {} +func (*PublicKey_Multisig) isPublicKey_Sum() {} +func (*PublicKey_Secp256R1) isPublicKey_Sum() {} +func (*PublicKey_AnyPubkey) isPublicKey_Sum() {} + +func (m *PublicKey) GetSum() isPublicKey_Sum { + if m != nil { + return m.Sum + } + return nil +} + +func (m *PublicKey) GetSecp256K1() []byte { + if x, ok := m.GetSum().(*PublicKey_Secp256K1); ok { + return x.Secp256K1 + } + return nil +} + +func (m *PublicKey) GetEd25519() []byte { + if x, ok := m.GetSum().(*PublicKey_Ed25519); ok { + return x.Ed25519 + } + return nil +} + +func (m *PublicKey) GetSr25519() []byte { + if x, ok := m.GetSum().(*PublicKey_Sr25519); ok { + return x.Sr25519 + } + return nil +} + +func (m *PublicKey) GetMultisig() *PubKeyMultisigThreshold { + if x, ok := m.GetSum().(*PublicKey_Multisig); ok { + return x.Multisig + } + return nil +} + +func (m *PublicKey) GetSecp256R1() []byte { + if x, ok := m.GetSum().(*PublicKey_Secp256R1); ok { + return x.Secp256R1 + } + return nil +} + +func (m *PublicKey) GetAnyPubkey() *types.Any { + if x, ok := m.GetSum().(*PublicKey_AnyPubkey); ok { + return x.AnyPubkey + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*PublicKey) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*PublicKey_Secp256K1)(nil), + (*PublicKey_Ed25519)(nil), + (*PublicKey_Sr25519)(nil), + (*PublicKey_Multisig)(nil), + (*PublicKey_Secp256R1)(nil), + (*PublicKey_AnyPubkey)(nil), + } +} + +// PubKeyMultisigThreshold specifies a public key type which nests multiple public +// keys and a threshold +type PubKeyMultisigThreshold struct { + K uint32 `protobuf:"varint,1,opt,name=threshold,proto3" json:"threshold,omitempty" yaml:"threshold"` + PubKeys []*PublicKey `protobuf:"bytes,2,rep,name=pubkeys,proto3" json:"pubkeys,omitempty" yaml:"pubkeys"` +} + +func (m *PubKeyMultisigThreshold) Reset() { *m = PubKeyMultisigThreshold{} } +func (m *PubKeyMultisigThreshold) String() string { return proto.CompactTextString(m) } +func (*PubKeyMultisigThreshold) ProtoMessage() {} +func (*PubKeyMultisigThreshold) Descriptor() ([]byte, []int) { + return fileDescriptor_2165b2a1badb1b0c, []int{1} +} +func (m *PubKeyMultisigThreshold) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PubKeyMultisigThreshold) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PubKeyMultisigThreshold.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 *PubKeyMultisigThreshold) XXX_Merge(src proto.Message) { + xxx_messageInfo_PubKeyMultisigThreshold.Merge(m, src) +} +func (m *PubKeyMultisigThreshold) XXX_Size() int { + return m.Size() +} +func (m *PubKeyMultisigThreshold) XXX_DiscardUnknown() { + xxx_messageInfo_PubKeyMultisigThreshold.DiscardUnknown(m) +} + +var xxx_messageInfo_PubKeyMultisigThreshold proto.InternalMessageInfo + +func (m *PubKeyMultisigThreshold) GetK() uint32 { + if m != nil { + return m.K + } + return 0 +} + +func (m *PubKeyMultisigThreshold) GetPubKeys() []*PublicKey { + if m != nil { + return m.PubKeys + } + return nil +} + +// Multisignature wraps the signatures from a PubKeyMultisigThreshold. +// See cosmos_sdk.tx.v1.ModeInfo.Multi for how to specify which signers signed +// and with which modes +type Multisignature struct { + Sigs [][]byte `protobuf:"bytes,1,rep,name=sigs,proto3" json:"sigs,omitempty"` +} + +func (m *Multisignature) Reset() { *m = Multisignature{} } +func (m *Multisignature) String() string { return proto.CompactTextString(m) } +func (*Multisignature) ProtoMessage() {} +func (*Multisignature) Descriptor() ([]byte, []int) { + return fileDescriptor_2165b2a1badb1b0c, []int{2} +} +func (m *Multisignature) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Multisignature) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Multisignature.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 *Multisignature) XXX_Merge(src proto.Message) { + xxx_messageInfo_Multisignature.Merge(m, src) +} +func (m *Multisignature) XXX_Size() int { + return m.Size() +} +func (m *Multisignature) XXX_DiscardUnknown() { + xxx_messageInfo_Multisignature.DiscardUnknown(m) +} + +var xxx_messageInfo_Multisignature proto.InternalMessageInfo + +func (m *Multisignature) GetSigs() [][]byte { + if m != nil { + return m.Sigs + } + return nil +} + // CompactBitArray is an implementation of a space efficient bit array. // This is used to ensure that the encoded data takes up a minimal amount of // space after proto encoding. @@ -35,7 +278,7 @@ func (m *CompactBitArray) Reset() { *m = CompactBitArray{} } func (m *CompactBitArray) String() string { return proto.CompactTextString(m) } func (*CompactBitArray) ProtoMessage() {} func (*CompactBitArray) Descriptor() ([]byte, []int) { - return fileDescriptor_2165b2a1badb1b0c, []int{0} + return fileDescriptor_2165b2a1badb1b0c, []int{3} } func (m *CompactBitArray) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -79,26 +322,259 @@ func (m *CompactBitArray) GetElems() []byte { } func init() { + proto.RegisterType((*PublicKey)(nil), "cosmos_sdk.crypto.v1.PublicKey") + proto.RegisterType((*PubKeyMultisigThreshold)(nil), "cosmos_sdk.crypto.v1.PubKeyMultisigThreshold") + proto.RegisterType((*Multisignature)(nil), "cosmos_sdk.crypto.v1.Multisignature") proto.RegisterType((*CompactBitArray)(nil), "cosmos_sdk.crypto.v1.CompactBitArray") } func init() { proto.RegisterFile("crypto/types/types.proto", fileDescriptor_2165b2a1badb1b0c) } var fileDescriptor_2165b2a1badb1b0c = []byte{ - // 195 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0x2e, 0xaa, 0x2c, - 0x28, 0xc9, 0xd7, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x86, 0x90, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, - 0x42, 0x22, 0xc9, 0xf9, 0xc5, 0xb9, 0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x10, 0x45, 0x7a, - 0x65, 0x86, 0x4a, 0xc1, 0x5c, 0xfc, 0xce, 0xf9, 0xb9, 0x05, 0x89, 0xc9, 0x25, 0x4e, 0x99, 0x25, - 0x8e, 0x45, 0x45, 0x89, 0x95, 0x42, 0x5a, 0x5c, 0x82, 0xa9, 0x15, 0x25, 0x45, 0x89, 0xf1, 0x49, - 0x99, 0x25, 0xc5, 0xf1, 0xc5, 0x25, 0xf9, 0x45, 0xa9, 0x29, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0xbc, - 0x41, 0xfc, 0x60, 0x09, 0xa7, 0xcc, 0x92, 0xe2, 0x60, 0xb0, 0xb0, 0x90, 0x08, 0x17, 0x6b, 0x6a, - 0x4e, 0x6a, 0x6e, 0xb1, 0x04, 0x93, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x84, 0xe3, 0xe4, 0x7c, 0xe2, - 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, - 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x9a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, - 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x10, 0xf7, 0x40, 0x29, 0xdd, 0xe2, 0x94, 0x6c, 0x7d, 0x64, 0xb7, - 0x27, 0xb1, 0x81, 0x9d, 0x6d, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xa1, 0x4f, 0xac, 0xf3, 0xd2, - 0x00, 0x00, 0x00, + // 486 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xdd, 0x8a, 0xd3, 0x40, + 0x14, 0x6e, 0xda, 0xad, 0xb5, 0xb3, 0xeb, 0x56, 0x87, 0x82, 0xd9, 0x82, 0x49, 0x09, 0x22, 0x55, + 0xd8, 0x84, 0x54, 0xaa, 0xe8, 0xdd, 0x66, 0x6f, 0x16, 0x8a, 0x50, 0xb2, 0x5e, 0x88, 0x37, 0x21, + 0x3f, 0x63, 0x1a, 0x9a, 0x64, 0xc2, 0x9c, 0x89, 0x38, 0x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x9c, 0xf3, 0x5f, 0x95, 0xa6, 0x5c, 0x55, 0x9a, + 0xf2, 0xa7, 0xd2, 0x94, 0x1f, 0x3b, 0xad, 0x73, 0xb5, 0xd3, 0x3a, 0xbf, 0x77, 0x5a, 0xe7, 0xf3, + 0xcb, 0x38, 0xe1, 0xeb, 0x32, 0x30, 0x43, 0x9a, 0x59, 0x32, 0x67, 0xf3, 0x3a, 0x85, 0x68, 0x63, + 0xdd, 0xfd, 0xc9, 0x83, 0x07, 0xf5, 0x42, 0x5e, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x57, 0x64, + 0xcc, 0x04, 0xfb, 0x02, 0x00, 0x00, +} + +func (m *PublicKey) 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 *PublicKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey) 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 *PublicKey_Secp256K1) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Secp256K1) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Secp256K1 != nil { + i -= len(m.Secp256K1) + copy(dAtA[i:], m.Secp256K1) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Secp256K1))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} +func (m *PublicKey_Ed25519) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Ed25519) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Ed25519 != nil { + i -= len(m.Ed25519) + copy(dAtA[i:], m.Ed25519) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Ed25519))) + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *PublicKey_Sr25519) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Sr25519) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Sr25519 != nil { + i -= len(m.Sr25519) + copy(dAtA[i:], m.Sr25519) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Sr25519))) + i-- + dAtA[i] = 0x1a + } + return len(dAtA) - i, nil +} +func (m *PublicKey_Multisig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Multisig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Multisig != nil { + { + size, err := m.Multisig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + return len(dAtA) - i, nil +} +func (m *PublicKey_Secp256R1) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_Secp256R1) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.Secp256R1 != nil { + i -= len(m.Secp256R1) + copy(dAtA[i:], m.Secp256R1) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Secp256R1))) + i-- + dAtA[i] = 0x2a + } + return len(dAtA) - i, nil +} +func (m *PublicKey_AnyPubkey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PublicKey_AnyPubkey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.AnyPubkey != nil { + { + size, err := m.AnyPubkey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x7a + } + return len(dAtA) - i, nil +} +func (m *PubKeyMultisigThreshold) 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 *PubKeyMultisigThreshold) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PubKeyMultisigThreshold) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PubKeys) > 0 { + for iNdEx := len(m.PubKeys) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PubKeys[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if m.K != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.K)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Multisignature) 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 *Multisignature) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Multisignature) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Sigs) > 0 { + for iNdEx := len(m.Sigs) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Sigs[iNdEx]) + copy(dAtA[i:], m.Sigs[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Sigs[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil } func (m *CompactBitArray) Marshal() (dAtA []byte, err error) { @@ -147,6 +623,123 @@ func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *PublicKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sum != nil { + n += m.Sum.Size() + } + return n +} + +func (m *PublicKey_Secp256K1) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Secp256K1 != nil { + l = len(m.Secp256K1) + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *PublicKey_Ed25519) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Ed25519 != nil { + l = len(m.Ed25519) + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *PublicKey_Sr25519) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Sr25519 != nil { + l = len(m.Sr25519) + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *PublicKey_Multisig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Multisig != nil { + l = m.Multisig.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *PublicKey_Secp256R1) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Secp256R1 != nil { + l = len(m.Secp256R1) + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *PublicKey_AnyPubkey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.AnyPubkey != nil { + l = m.AnyPubkey.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} +func (m *PubKeyMultisigThreshold) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.K != 0 { + n += 1 + sovTypes(uint64(m.K)) + } + if len(m.PubKeys) > 0 { + for _, e := range m.PubKeys { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Multisignature) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Sigs) > 0 { + for _, b := range m.Sigs { + l = len(b) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + func (m *CompactBitArray) Size() (n int) { if m == nil { return 0 @@ -169,6 +762,452 @@ func sovTypes(x uint64) (n int) { func sozTypes(x uint64) (n int) { return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *PublicKey) 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 ErrIntOverflowTypes + } + 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: PublicKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PublicKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Secp256K1", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := make([]byte, postIndex-iNdEx) + copy(v, dAtA[iNdEx:postIndex]) + m.Sum = &PublicKey_Secp256K1{v} + iNdEx = postIndex + case 2: + 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 ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := make([]byte, postIndex-iNdEx) + copy(v, dAtA[iNdEx:postIndex]) + m.Sum = &PublicKey_Ed25519{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sr25519", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := make([]byte, postIndex-iNdEx) + copy(v, dAtA[iNdEx:postIndex]) + m.Sum = &PublicKey_Sr25519{v} + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Multisig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &PubKeyMultisigThreshold{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &PublicKey_Multisig{v} + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Secp256R1", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := make([]byte, postIndex-iNdEx) + copy(v, dAtA[iNdEx:postIndex]) + m.Sum = &PublicKey_Secp256R1{v} + iNdEx = postIndex + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AnyPubkey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &types.Any{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Sum = &PublicKey_AnyPubkey{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PubKeyMultisigThreshold) 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 ErrIntOverflowTypes + } + 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: PubKeyMultisigThreshold: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PubKeyMultisigThreshold: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field K", wireType) + } + m.K = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.K |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKeys", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PubKeys = append(m.PubKeys, &PublicKey{}) + if err := m.PubKeys[len(m.PubKeys)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Multisignature) 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 ErrIntOverflowTypes + } + 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: Multisignature: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Multisignature: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sigs", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sigs = append(m.Sigs, make([]byte, postIndex-iNdEx)) + copy(m.Sigs[len(m.Sigs)-1], dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *CompactBitArray) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/crypto/types/types.proto b/crypto/types/types.proto index acc1f060c..a03228ca8 100644 --- a/crypto/types/types.proto +++ b/crypto/types/types.proto @@ -1,10 +1,42 @@ syntax = "proto3"; package cosmos_sdk.crypto.v1; -//import "third_party/proto/gogoproto/gogo.proto"; +import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; option go_package = "github.com/cosmos/cosmos-sdk/crypto/types"; +// PublicKey specifies a public key +message PublicKey { + // sum specifies which type of public key is wrapped + oneof sum { + bytes secp256k1 = 1; + bytes ed25519 = 2; + bytes sr25519 = 3; + PubKeyMultisigThreshold multisig = 4; + bytes secp256r1 = 5; + + // any_pubkey can be used for any pubkey that an app may use which is + // not explicitly defined in the oneof + google.protobuf.Any any_pubkey = 15; // 15 is largest field that occupies one byte + } +} + +// PubKeyMultisigThreshold specifies a public key type which nests multiple public +// keys and a threshold +message PubKeyMultisigThreshold { + uint32 threshold = 1 [(gogoproto.customname) = "K", (gogoproto.moretags) = "yaml:\"threshold\""]; + repeated PublicKey pubkeys = 2 [(gogoproto.customname) = "PubKeys", (gogoproto.moretags) = "yaml:\"pubkeys\""]; +} + + +// MultiSignature wraps the signatures from a PubKeyMultisigThreshold. +// See cosmos_sdk.tx.v1.ModeInfo.Multi for how to specify which signers signed +// and with which modes +message MultiSignature { + repeated bytes sigs = 1; +} + // CompactBitArray is an implementation of a space efficient bit array. // This is used to ensure that the encoded data takes up a minimal amount of // space after proto encoding. diff --git a/docs/architecture/adr-020-protobuf-transaction-encoding.md b/docs/architecture/adr-020-protobuf-transaction-encoding.md index 7907c92f3..98670b026 100644 --- a/docs/architecture/adr-020-protobuf-transaction-encoding.md +++ b/docs/architecture/adr-020-protobuf-transaction-encoding.md @@ -6,6 +6,7 @@ - 2020 March 12: API Updates - 2020 April 13: Added details on interface `oneof` handling - 2020 April 30: Switch to `Any` +- 2020 May 14: Describe public key encoding ## Status @@ -259,6 +260,32 @@ fields with bit 11 set This will likely need to be a custom protobuf parser pass that takes message bytes and `FileDescriptor`s and returns a boolean result. +### Public Key Encoding + +Public keys in the Cosmos SDK implement Tendermint's `crypto.PubKey` interface, +so a natural solution might be to use `Any` as we are doing for other interfaces. +There are, however, a limited number of public keys in existence and new ones +aren't created overnight. The proposed solution is to use a `oneof` that: + +* attempts to catalog all known key types even if a given app can't use them all +* has an `Any` member that can be used when a key type isn't present in the `oneof` + +Ex: +```proto +message PublicKey { + oneof sum { + bytes secp256k1 = 1; + bytes ed25519 = 2; + ... + google.protobuf.Any any_pubkey = 15; + } +} +``` + +Apps should only attempt to handle a registered set of public keys that they +have tested. The provided signature verification ante handler decorators will +enforce this. + ### CLI & REST Currently, the REST and CLI handlers encode and decode types and txs via Amino