From 7278093cf80a548ae1310849fdba71a0f2238ba7 Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Wed, 1 Nov 2023 11:40:35 -0400 Subject: [PATCH 1/3] bring back --- .../crypto/ethsecp256k1/v1/keys.pulsar.go | 1074 +++++++++++++++++ cosmos/crypto/codec/codec.go | 34 + cosmos/crypto/codec/codec_test.go | 41 + cosmos/crypto/hd/algo.go | 67 + cosmos/crypto/hd/algo_test.go | 99 ++ cosmos/crypto/hd/hd.go | 73 ++ cosmos/crypto/hd/hd_test.go | 33 + cosmos/crypto/keyring/option.go | 37 + cosmos/crypto/keyring/option_test.go | 178 +++ cosmos/crypto/keys/ethsecp256k1/keys.go | 137 +++ cosmos/crypto/keys/ethsecp256k1/keys.pb.go | 499 ++++++++ cosmos/crypto/keys/ethsecp256k1/keys_test.go | 80 ++ .../crypto/keys/ethsecp256k1/signature_cgo.go | 64 + .../keys/ethsecp256k1/signature_cgo_test.go | 66 + cosmos/go.mod | 5 +- cosmos/go.sum | 30 + e2e/hive/clients/polard/entrypoint.sh | 2 +- e2e/precompile/polard/start-node.sh | 2 +- e2e/testapp/app.go | 4 + e2e/testapp/docker/local/docker-init.sh | 2 +- e2e/testapp/docker/seed/init.sh | 2 +- .../docker/seed/scripts/seed0-init-step1.sh | 2 +- .../docker/seed/scripts/seed0-init-step2.sh | 2 +- .../docker/seed/scripts/seed1-init-step1.sh | 2 +- .../validator/scripts/val0-init-step1.sh | 2 +- .../validator/scripts/val1-init-step1.sh | 2 +- e2e/testapp/entrypoint.sh | 2 +- e2e/testapp/polard/cmd/root.go | 5 + eth/crypto/imported.go | 32 +- go.work.sum | 14 +- .../polaris/crypto/ethsecp256k1/v1/keys.proto | 40 + 31 files changed, 2608 insertions(+), 24 deletions(-) create mode 100644 cosmos/api/polaris/crypto/ethsecp256k1/v1/keys.pulsar.go create mode 100644 cosmos/crypto/codec/codec.go create mode 100644 cosmos/crypto/codec/codec_test.go create mode 100644 cosmos/crypto/hd/algo.go create mode 100644 cosmos/crypto/hd/algo_test.go create mode 100644 cosmos/crypto/hd/hd.go create mode 100644 cosmos/crypto/hd/hd_test.go create mode 100644 cosmos/crypto/keyring/option.go create mode 100644 cosmos/crypto/keyring/option_test.go create mode 100644 cosmos/crypto/keys/ethsecp256k1/keys.go create mode 100644 cosmos/crypto/keys/ethsecp256k1/keys.pb.go create mode 100644 cosmos/crypto/keys/ethsecp256k1/keys_test.go create mode 100644 cosmos/crypto/keys/ethsecp256k1/signature_cgo.go create mode 100644 cosmos/crypto/keys/ethsecp256k1/signature_cgo_test.go create mode 100644 proto/polaris/crypto/ethsecp256k1/v1/keys.proto diff --git a/cosmos/api/polaris/crypto/ethsecp256k1/v1/keys.pulsar.go b/cosmos/api/polaris/crypto/ethsecp256k1/v1/keys.pulsar.go new file mode 100644 index 000000000..8dc63e61b --- /dev/null +++ b/cosmos/api/polaris/crypto/ethsecp256k1/v1/keys.pulsar.go @@ -0,0 +1,1074 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package ethsecp256k1v1 + +import ( + fmt "fmt" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" +) + +var ( + md_PubKey protoreflect.MessageDescriptor + fd_PubKey_key protoreflect.FieldDescriptor +) + +func init() { + file_polaris_crypto_ethsecp256k1_v1_keys_proto_init() + md_PubKey = File_polaris_crypto_ethsecp256k1_v1_keys_proto.Messages().ByName("PubKey") + fd_PubKey_key = md_PubKey.Fields().ByName("key") +} + +var _ protoreflect.Message = (*fastReflection_PubKey)(nil) + +type fastReflection_PubKey PubKey + +func (x *PubKey) ProtoReflect() protoreflect.Message { + return (*fastReflection_PubKey)(x) +} + +func (x *PubKey) slowProtoReflect() protoreflect.Message { + mi := &file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_PubKey_messageType fastReflection_PubKey_messageType +var _ protoreflect.MessageType = fastReflection_PubKey_messageType{} + +type fastReflection_PubKey_messageType struct{} + +func (x fastReflection_PubKey_messageType) Zero() protoreflect.Message { + return (*fastReflection_PubKey)(nil) +} +func (x fastReflection_PubKey_messageType) New() protoreflect.Message { + return new(fastReflection_PubKey) +} +func (x fastReflection_PubKey_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_PubKey +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_PubKey) Descriptor() protoreflect.MessageDescriptor { + return md_PubKey +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_PubKey) Type() protoreflect.MessageType { + return _fastReflection_PubKey_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_PubKey) New() protoreflect.Message { + return new(fastReflection_PubKey) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_PubKey) Interface() protoreflect.ProtoMessage { + return (*PubKey)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_PubKey) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if len(x.Key) != 0 { + value := protoreflect.ValueOfBytes(x.Key) + if !f(fd_PubKey_key, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_PubKey) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PubKey.key": + return len(x.Key) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PubKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PubKey does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PubKey) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PubKey.key": + x.Key = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PubKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PubKey does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_PubKey) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PubKey.key": + value := x.Key + return protoreflect.ValueOfBytes(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PubKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PubKey does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PubKey) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PubKey.key": + x.Key = value.Bytes() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PubKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PubKey does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PubKey) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PubKey.key": + panic(fmt.Errorf("field key of message polaris.crypto.ethsecp256k1.v1.PubKey is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PubKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PubKey does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_PubKey) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PubKey.key": + return protoreflect.ValueOfBytes(nil) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PubKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PubKey does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_PubKey) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in polaris.crypto.ethsecp256k1.v1.PubKey", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_PubKey) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PubKey) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_PubKey) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_PubKey) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*PubKey) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Key) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*PubKey) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.Key) > 0 { + i -= len(x.Key) + copy(dAtA[i:], x.Key) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Key))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*PubKey) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire 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++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: PubKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: PubKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var byteLen int + 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++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + 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.Key = append(x.Key[:0], dAtA[iNdEx:postIndex]...) + if x.Key == nil { + x.Key = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var ( + md_PrivKey protoreflect.MessageDescriptor + fd_PrivKey_key protoreflect.FieldDescriptor +) + +func init() { + file_polaris_crypto_ethsecp256k1_v1_keys_proto_init() + md_PrivKey = File_polaris_crypto_ethsecp256k1_v1_keys_proto.Messages().ByName("PrivKey") + fd_PrivKey_key = md_PrivKey.Fields().ByName("key") +} + +var _ protoreflect.Message = (*fastReflection_PrivKey)(nil) + +type fastReflection_PrivKey PrivKey + +func (x *PrivKey) ProtoReflect() protoreflect.Message { + return (*fastReflection_PrivKey)(x) +} + +func (x *PrivKey) slowProtoReflect() protoreflect.Message { + mi := &file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_PrivKey_messageType fastReflection_PrivKey_messageType +var _ protoreflect.MessageType = fastReflection_PrivKey_messageType{} + +type fastReflection_PrivKey_messageType struct{} + +func (x fastReflection_PrivKey_messageType) Zero() protoreflect.Message { + return (*fastReflection_PrivKey)(nil) +} +func (x fastReflection_PrivKey_messageType) New() protoreflect.Message { + return new(fastReflection_PrivKey) +} +func (x fastReflection_PrivKey_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_PrivKey +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_PrivKey) Descriptor() protoreflect.MessageDescriptor { + return md_PrivKey +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_PrivKey) Type() protoreflect.MessageType { + return _fastReflection_PrivKey_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_PrivKey) New() protoreflect.Message { + return new(fastReflection_PrivKey) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_PrivKey) Interface() protoreflect.ProtoMessage { + return (*PrivKey)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_PrivKey) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if len(x.Key) != 0 { + value := protoreflect.ValueOfBytes(x.Key) + if !f(fd_PrivKey_key, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_PrivKey) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PrivKey.key": + return len(x.Key) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PrivKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PrivKey does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PrivKey) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PrivKey.key": + x.Key = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PrivKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PrivKey does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_PrivKey) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PrivKey.key": + value := x.Key + return protoreflect.ValueOfBytes(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PrivKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PrivKey does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PrivKey) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PrivKey.key": + x.Key = value.Bytes() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PrivKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PrivKey does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PrivKey) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PrivKey.key": + panic(fmt.Errorf("field key of message polaris.crypto.ethsecp256k1.v1.PrivKey is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PrivKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PrivKey does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_PrivKey) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "polaris.crypto.ethsecp256k1.v1.PrivKey.key": + return protoreflect.ValueOfBytes(nil) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: polaris.crypto.ethsecp256k1.v1.PrivKey")) + } + panic(fmt.Errorf("message polaris.crypto.ethsecp256k1.v1.PrivKey does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_PrivKey) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in polaris.crypto.ethsecp256k1.v1.PrivKey", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_PrivKey) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_PrivKey) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_PrivKey) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_PrivKey) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*PrivKey) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Key) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*PrivKey) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.Key) > 0 { + i -= len(x.Key) + copy(dAtA[i:], x.Key) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Key))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*PrivKey) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire 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++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: PrivKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: PrivKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var byteLen int + 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++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + 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.Key = append(x.Key[:0], dAtA[iNdEx:postIndex]...) + if x.Key == nil { + x.Key = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: polaris/crypto/ethsecp256k1/v1/keys.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// `PubKey` defines a type alias for an `ecdsa.PublicKey` that implements +// CometBFT's `PubKey` interface. It represents the 33-byte compressed public +// key format. +type PubKey struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // `key` is the public key in byte form. + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *PubKey) Reset() { + *x = PubKey{} + if protoimpl.UnsafeEnabled { + mi := &file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PubKey) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PubKey) ProtoMessage() {} + +// Deprecated: Use PubKey.ProtoReflect.Descriptor instead. +func (*PubKey) Descriptor() ([]byte, []int) { + return file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescGZIP(), []int{0} +} + +func (x *PubKey) GetKey() []byte { + if x != nil { + return x.Key + } + return nil +} + +// `PrivKey` defines a type alias for a n`ecdsa.PrivateKey` that implements +// CometBFT's `PrivateKey` interface. +type PrivKey struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // `key` is the private key in byte form. + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *PrivKey) Reset() { + *x = PrivKey{} + if protoimpl.UnsafeEnabled { + mi := &file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrivKey) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrivKey) ProtoMessage() {} + +// Deprecated: Use PrivKey.ProtoReflect.Descriptor instead. +func (*PrivKey) Descriptor() ([]byte, []int) { + return file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescGZIP(), []int{1} +} + +func (x *PrivKey) GetKey() []byte { + if x != nil { + return x.Key + } + return nil +} + +var File_polaris_crypto_ethsecp256k1_v1_keys_proto protoreflect.FileDescriptor + +var file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDesc = []byte{ + 0x0a, 0x29, 0x70, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, + 0x2f, 0x65, 0x74, 0x68, 0x73, 0x65, 0x63, 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x2f, 0x76, 0x31, + 0x2f, 0x6b, 0x65, 0x79, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1e, 0x70, 0x6f, 0x6c, + 0x61, 0x72, 0x69, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x65, 0x74, 0x68, 0x73, + 0x65, 0x63, 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x2e, 0x76, 0x31, 0x22, 0x1a, 0x0a, 0x06, 0x50, + 0x75, 0x62, 0x4b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x1b, 0x0a, 0x07, 0x50, 0x72, 0x69, 0x76, 0x4b, + 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x42, 0x8a, 0x02, 0x0a, 0x22, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6f, 0x6c, + 0x61, 0x72, 0x69, 0x73, 0x2e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x65, 0x74, 0x68, 0x73, + 0x65, 0x63, 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x2e, 0x76, 0x31, 0x42, 0x09, 0x4b, 0x65, 0x79, + 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6f, 0x6c, 0x61, 0x72, + 0x69, 0x73, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2f, 0x65, 0x74, 0x68, 0x73, 0x65, 0x63, + 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x2f, 0x76, 0x31, 0x3b, 0x65, 0x74, 0x68, 0x73, 0x65, 0x63, + 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x50, 0x43, 0x45, 0xaa, 0x02, + 0x1e, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x73, 0x2e, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, + 0x45, 0x74, 0x68, 0x73, 0x65, 0x63, 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x2e, 0x56, 0x31, 0xca, + 0x02, 0x1e, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x73, 0x5c, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, + 0x5c, 0x45, 0x74, 0x68, 0x73, 0x65, 0x63, 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x5c, 0x56, 0x31, + 0xe2, 0x02, 0x2a, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x73, 0x5c, 0x43, 0x72, 0x79, 0x70, 0x74, + 0x6f, 0x5c, 0x45, 0x74, 0x68, 0x73, 0x65, 0x63, 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x5c, 0x56, + 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x21, + 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x69, 0x73, 0x3a, 0x3a, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x3a, + 0x3a, 0x45, 0x74, 0x68, 0x73, 0x65, 0x63, 0x70, 0x32, 0x35, 0x36, 0x6b, 0x31, 0x3a, 0x3a, 0x56, + 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescOnce sync.Once + file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescData = file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDesc +) + +func file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescGZIP() []byte { + file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescOnce.Do(func() { + file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescData = protoimpl.X.CompressGZIP(file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescData) + }) + return file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDescData +} + +var file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_polaris_crypto_ethsecp256k1_v1_keys_proto_goTypes = []interface{}{ + (*PubKey)(nil), // 0: polaris.crypto.ethsecp256k1.v1.PubKey + (*PrivKey)(nil), // 1: polaris.crypto.ethsecp256k1.v1.PrivKey +} +var file_polaris_crypto_ethsecp256k1_v1_keys_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_polaris_crypto_ethsecp256k1_v1_keys_proto_init() } +func file_polaris_crypto_ethsecp256k1_v1_keys_proto_init() { + if File_polaris_crypto_ethsecp256k1_v1_keys_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PubKey); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PrivKey); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_polaris_crypto_ethsecp256k1_v1_keys_proto_goTypes, + DependencyIndexes: file_polaris_crypto_ethsecp256k1_v1_keys_proto_depIdxs, + MessageInfos: file_polaris_crypto_ethsecp256k1_v1_keys_proto_msgTypes, + }.Build() + File_polaris_crypto_ethsecp256k1_v1_keys_proto = out.File + file_polaris_crypto_ethsecp256k1_v1_keys_proto_rawDesc = nil + file_polaris_crypto_ethsecp256k1_v1_keys_proto_goTypes = nil + file_polaris_crypto_ethsecp256k1_v1_keys_proto_depIdxs = nil +} diff --git a/cosmos/crypto/codec/codec.go b/cosmos/crypto/codec/codec.go new file mode 100644 index 000000000..c3daf7490 --- /dev/null +++ b/cosmos/crypto/codec/codec.go @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package codec + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + + "pkg.berachain.dev/polaris/cosmos/crypto/keys/ethsecp256k1" +) + +// RegisterInterfaces registers the ethsecp256k1 key types. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations((*cryptotypes.PubKey)(nil), ðsecp256k1.PubKey{}) + registry.RegisterImplementations((*cryptotypes.PrivKey)(nil), ðsecp256k1.PrivKey{}) +} diff --git a/cosmos/crypto/codec/codec_test.go b/cosmos/crypto/codec/codec_test.go new file mode 100644 index 000000000..6e9542ccc --- /dev/null +++ b/cosmos/crypto/codec/codec_test.go @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package codec + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/codec/types" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestCodec(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "cosmos/crypto/codec") +} + +var _ = Describe("Codec", func() { + It("should not panic", func() { + RegisterInterfaces(types.NewInterfaceRegistry()) + }) +}) diff --git a/cosmos/crypto/hd/algo.go b/cosmos/crypto/hd/algo.go new file mode 100644 index 000000000..52f3cd66b --- /dev/null +++ b/cosmos/crypto/hd/algo.go @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package hd + +import ( + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + + "pkg.berachain.dev/polaris/cosmos/crypto/keys/ethsecp256k1" +) + +const ( + // EthSecp256k1Type defines the ECDSA secp256k1 used on Ethereum. + EthSecp256k1Type = hd.PubKeyType(ethsecp256k1.KeyType) +) + +var ( + // Compile-time type assertion. + _ keyring.SignatureAlgo = EthSecp256k1 + // EthSecp256k1 uses the Bitcoin secp256k1 ECDSA parameters. + EthSecp256k1 = ethSecp256k1Algo{} +) + +// ethSecp256k1Algo implements the `keyring.SignatureAlgo` interface for the +// eth_secp256k1 algorithm. +type ethSecp256k1Algo struct{} + +// Name returns eth_secp256k1. +func (s ethSecp256k1Algo) Name() hd.PubKeyType { + return EthSecp256k1Type +} + +// Derive derives and returns the eth_secp256k1 private key for the given mnemonic +// and HD path. +func (s ethSecp256k1Algo) Derive() hd.DeriveFn { + return hd.Secp256k1.Derive() +} + +// Generate generates a eth_secp256k1 private key from the given bytes. +func (s ethSecp256k1Algo) Generate() hd.GenerateFn { + return func(bz []byte) cryptotypes.PrivKey { + bzArr := make([]byte, ethsecp256k1.PrivKeySize) + copy(bzArr, bz) + return ðsecp256k1.PrivKey{ + Key: bzArr, + } + } +} diff --git a/cosmos/crypto/hd/algo_test.go b/cosmos/crypto/hd/algo_test.go new file mode 100644 index 000000000..6534203f9 --- /dev/null +++ b/cosmos/crypto/hd/algo_test.go @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package hd + +import ( + "strings" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" + + ethsecp256k1 "pkg.berachain.dev/polaris/cosmos/crypto/keys/ethsecp256k1" + "pkg.berachain.dev/polaris/eth/accounts" + "pkg.berachain.dev/polaris/eth/common" + crypto "pkg.berachain.dev/polaris/eth/crypto" + "pkg.berachain.dev/polaris/lib/utils" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +const ( + mnemonic = "absurd surge gather author blanket acquire proof struggle runway attract " + + "cereal quiz tattoo shed almost sudden survey boring film memory picnic favorite " + + "verb tank" +) + +var _ = Describe("HD", func() { + It("should derive the correct key", func() { + EthSecp256k1 := EthSecp256k1 + + // Derive the 0'th key from the mnemonic. + bz, err := EthSecp256k1.Derive()(mnemonic, keyring.DefaultBIP39Passphrase, + accounts.BIP44HDPath) + Expect(err).NotTo(HaveOccurred()) + Expect(bz).NotTo(BeEmpty()) + + badBz, err := EthSecp256k1.Derive()(mnemonic, keyring.DefaultBIP39Passphrase, + "44'/118'/0'/0/0") + Expect(err).NotTo(HaveOccurred()) + Expect(badBz).NotTo(BeEmpty()) + + Expect(bz).NotTo(Equal(badBz)) + + privkey := EthSecp256k1.Generate()(bz) + badPrivKey := EthSecp256k1.Generate()(badBz) + + Expect(privkey.Equals(badPrivKey)).To(BeFalse()) + + pk, err := utils.MustGetAs[*ethsecp256k1.PrivKey](privkey).ToECDSA() + Expect(err).NotTo(HaveOccurred()) + + wallet, path, err := GenerateWallet(mnemonic) + Expect(err).NotTo(HaveOccurred()) + *path = strings.Replace(*path, "H", "'", 3) // TODO: figure out why this is needed. + Expect(*path).To(Equal(accounts.BIP44HDPath)) + Expect(crypto.FromECDSA(wallet)).To(Equal(privkey.Bytes())) + + // Check to verify that the address is correct. + // Also verified manually with metamask: https://imgur.com/a/Bz2jLaP + Expect(crypto.PubkeyToAddress(pk.PublicKey).String()). + To(Equal("0x20f33CE90A13a4b5E7697E3544c3083B8F8A51D4")) + Expect(crypto.PubkeyToAddress(wallet.PublicKey).String()). + To(Equal("0x20f33CE90A13a4b5E7697E3544c3083B8F8A51D4")) + Expect(common.BytesToAddress(privkey.PubKey().Address().Bytes()).String()). + To(Equal("0x20f33CE90A13a4b5E7697E3544c3083B8F8A51D4")) + Expect(common.BytesToAddress(privkey.PubKey().Address()).String()). + To(Equal(crypto.PubkeyToAddress(wallet.PublicKey).String())) + }) +}) + +var _ = Describe("Prove EDSCAify isn't needed", func() { + It("should round trip", func() { + // Generate a random private key. + key, err := ethsecp256k1.GenPrivKey() + Expect(err).NotTo(HaveOccurred()) + + // Convert the private key to an ECDSA private key. + x, err := ethsecp256k1.PrivKey{Key: key.Key}.ToECDSA() + Expect(err).NotTo(HaveOccurred()) + Expect(key.Key).To(Equal(crypto.FromECDSA(x))) + }) +}) diff --git a/cosmos/crypto/hd/hd.go b/cosmos/crypto/hd/hd.go new file mode 100644 index 000000000..0588972e6 --- /dev/null +++ b/cosmos/crypto/hd/hd.go @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +// +//nolint:gomnd // ignore magic numbers +package hd + +import ( + "crypto/ecdsa" + + "github.com/btcsuite/btcd/btcutil/hdkeychain" + "github.com/btcsuite/btcd/chaincfg" + "github.com/cosmos/go-bip39" +) + +func GenerateWallet(mnemonic string) (*ecdsa.PrivateKey, *string, error) { + // Generate a Bip32 HD wallet for the mnemonic and a user supplied password + seed := bip39.NewSeed(mnemonic, "") + // Generate a new master node using the seed. + masterKey, err := hdkeychain.NewMaster(seed, &chaincfg.MainNetParams) + if err != nil { + return nil, nil, err + } + // This gives the path: m/44H + acc44H, err := masterKey.Derive(hdkeychain.HardenedKeyStart + 44) + if err != nil { + return nil, nil, err + } + // This gives the path: m/44H/60H + acc44H60H, err := acc44H.Derive(hdkeychain.HardenedKeyStart + 60) + if err != nil { + return nil, nil, err + } + // This gives the path: m/44H/60H/0H + acc44H60H0H, err := acc44H60H.Derive(hdkeychain.HardenedKeyStart + 0) + if err != nil { + return nil, nil, err + } + // This gives the path: m/44H/60H/0H/0 + acc44H60H0H0, err := acc44H60H0H.Derive(0) + if err != nil { + return nil, nil, err + } + // This gives the path: m/44H/60H/0H/0/0 + acc44H60H0H00, err := acc44H60H0H0.Derive(0) + if err != nil { + return nil, nil, err + } + btcecPrivKey, err := acc44H60H0H00.ECPrivKey() + if err != nil { + return nil, nil, err + } + privateKey := btcecPrivKey.ToECDSA() + path := "m/44H/60H/0H/0/0" + return privateKey, &path, nil +} diff --git a/cosmos/crypto/hd/hd_test.go b/cosmos/crypto/hd/hd_test.go new file mode 100644 index 000000000..2b0daa523 --- /dev/null +++ b/cosmos/crypto/hd/hd_test.go @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package hd + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestHD(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "cosmos/crypto/hd") +} diff --git a/cosmos/crypto/keyring/option.go b/cosmos/crypto/keyring/option.go new file mode 100644 index 000000000..e729595b3 --- /dev/null +++ b/cosmos/crypto/keyring/option.go @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package keyring + +import ( + sdkhd "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + + "pkg.berachain.dev/polaris/cosmos/crypto/hd" +) + +// EthSecp256k1Option defines a function keys options for the ethereum Secp256k1 curve. +// It supports ethsecp256k1 and secp256k1 keys for accounts. +func EthSecp256k1Option() keyring.Option { + return func(options *keyring.Options) { + options.SupportedAlgos = keyring.SigningAlgoList{hd.EthSecp256k1, sdkhd.Secp256k1} + options.SupportedAlgosLedger = keyring.SigningAlgoList{hd.EthSecp256k1, sdkhd.Secp256k1} + } +} diff --git a/cosmos/crypto/keyring/option_test.go b/cosmos/crypto/keyring/option_test.go new file mode 100644 index 000000000..98ac4ec17 --- /dev/null +++ b/cosmos/crypto/keyring/option_test.go @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package keyring + +import ( + "os" + "strings" + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/std" + + cryptocodec "pkg.berachain.dev/polaris/cosmos/crypto/codec" + "pkg.berachain.dev/polaris/cosmos/crypto/hd" + accounts "pkg.berachain.dev/polaris/eth/accounts" + "pkg.berachain.dev/polaris/eth/common" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var cdc *codec.ProtoCodec + +func registerCodec() { + interfaceRegistry := types.NewInterfaceRegistry() + std.RegisterInterfaces(interfaceRegistry) + cryptocodec.RegisterInterfaces(interfaceRegistry) + cdc = codec.NewProtoCodec(interfaceRegistry) +} + +func TestKeyring(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "cosmos/crypto/keyring") +} + +var _ = Describe("Keyring", func() { + var ( + dir string + mockIn *strings.Reader + kr keyring.Keyring + ) + + BeforeEach(func() { + var err error + dir, err = os.MkdirTemp("", "keyring_test") + Expect(err).NotTo(HaveOccurred()) + registerCodec() + + mockIn = strings.NewReader("") + + interfaceRegistry := types.NewInterfaceRegistry() + std.RegisterInterfaces(interfaceRegistry) + cryptocodec.RegisterInterfaces(interfaceRegistry) + cdc = codec.NewProtoCodec(interfaceRegistry) + + kr, err = keyring.New("accounts", keyring.BackendTest, dir, mockIn, cdc, EthSecp256k1Option()) + Expect(err).NotTo(HaveOccurred()) + }) + + AfterEach(func() { + err := os.RemoveAll(dir) + Expect(err).NotTo(HaveOccurred()) + }) + + Context("Key operations", func() { + It("should fail to retrieve key", func() { + info, err := kr.Key("foo") + Expect(err).To(HaveOccurred()) + Expect(info).To(BeNil()) + }) + }) + + Context("NewMnemonic operation", func() { + var ( + info *keyring.Record + mnemonic string + err error + ) + + BeforeEach(func() { + registerCodec() + mockIn.Reset("password\npassword\n") + info, mnemonic, err = kr.NewMnemonic("foo", keyring.English, accounts.BIP44HDPath, + keyring.DefaultBIP39Passphrase, hd.EthSecp256k1) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should create a new mnemonic and info", func() { + Expect(mnemonic).NotTo(BeEmpty()) + Expect(info.Name).To(Equal("foo")) + Expect(info.GetType().String()).To(Equal("local")) + var pubKey cryptotypes.PubKey + pubKey, err = info.GetPubKey() + Expect(err).NotTo(HaveOccurred()) + Expect(pubKey.Type()).To(Equal(string(hd.EthSecp256k1Type))) + }) + }) + + Context("HD path operations", func() { + var ( + mnemonic string + bz []byte + err error + ) + + BeforeEach(func() { + registerCodec() + mockIn.Reset("password\npassword\n") + _, mnemonic, err = kr.NewMnemonic("foo", keyring.English, accounts.BIP44HDPath, + keyring.DefaultBIP39Passphrase, hd.EthSecp256k1) + Expect(err).NotTo(HaveOccurred()) + + hdPath := accounts.BIP44HDPath + + bz, err = hd.EthSecp256k1.Derive()(mnemonic, keyring.DefaultBIP39Passphrase, hdPath) + Expect(err).NotTo(HaveOccurred()) + }) + + It("should derive the correct HD path", func() { + Expect(bz).NotTo(BeEmpty()) + var wrongBz []byte + wrongBz, err = hd.EthSecp256k1.Derive()(mnemonic, keyring.DefaultBIP39Passphrase, + "/wrong/hdPath") + Expect(err).To(HaveOccurred()) + Expect(wrongBz).To(BeEmpty()) + }) + + Context("Key generation and retrieval", func() { + var ( + privkey cryptotypes.PrivKey + addr common.Address + ) + + BeforeEach(func() { + registerCodec() + mockIn.Reset("password\npassword\n") + _, mnemonic, err = kr.NewMnemonic("foo", keyring.English, accounts.BIP44HDPath, + keyring.DefaultBIP39Passphrase, hd.EthSecp256k1) + Expect(err).NotTo(HaveOccurred()) + + hdPath := accounts.BIP44HDPath + + bz, err = hd.EthSecp256k1.Derive()(mnemonic, keyring.DefaultBIP39Passphrase, + hdPath) + Expect(err).NotTo(HaveOccurred()) + + privkey = hd.EthSecp256k1.Generate()(bz) + addr = common.BytesToAddress(privkey.PubKey().Address().Bytes()) + }) + + It("should generate and retrieve the correct private key and address", func() { + Expect(addr.String()).To(Equal(common.Address(privkey.PubKey(). + Address()).String())) + }) + }) + }) +}) diff --git a/cosmos/crypto/keys/ethsecp256k1/keys.go b/cosmos/crypto/keys/ethsecp256k1/keys.go new file mode 100644 index 000000000..5636e0aea --- /dev/null +++ b/cosmos/crypto/keys/ethsecp256k1/keys.go @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package ethsecp256k1 + +import ( + "bytes" + "crypto/ecdsa" + "crypto/subtle" + + cmcrypto "github.com/cometbft/cometbft/crypto" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + + "pkg.berachain.dev/polaris/eth/crypto" +) + +const ( + // PrivKeySize defines the length of the PrivKey byte array. + PrivKeySize = 32 + // PubKeySize defines the length of the PubKey byte array. + PubKeySize = PrivKeySize + 1 + // KeyType is the string constant for the secp256k1 algorithm. + KeyType = "eth_secp256k1" +) + +// =============================================================================================== +// Private Key +// =============================================================================================== + +// PrivKey is a wrapper around the Ethereum secp256k1 private key type. This wrapper conforms to +// crypotypes.Pubkey to allow for the use of the Ethereum secp256k1 private key type within the +// Cosmos SDK. + +// Compile-time type assertion. +var _ cryptotypes.PrivKey = &PrivKey{} + +// Bytes returns the byte representation of the ECDSA Private Key. +func (privKey PrivKey) Bytes() []byte { + return privKey.Key +} + +// PubKey returns the ECDSA private key's public key. If the privkey is not valid +// it returns a nil value. +func (privKey PrivKey) PubKey() cryptotypes.PubKey { + ecdsaPrivKey, err := privKey.ToECDSA() + if err != nil { + return nil + } + + return &PubKey{ + Key: crypto.CompressPubkey(&ecdsaPrivKey.PublicKey), + } +} + +// Equals returns true if two ECDSA private keys are equal and false otherwise. +func (privKey PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool { + return privKey.Type() == other.Type() && + subtle.ConstantTimeCompare(privKey.Bytes(), other.Bytes()) == 1 +} + +// Type returns eth_secp256k1. +func (privKey PrivKey) Type() string { + return KeyType +} + +// GenPrivKey generates a new random private key. It returns an error upon +// failure. +func GenPrivKey() (*PrivKey, error) { + priv, err := crypto.GenerateEthKey() + if err != nil { + return nil, err + } + + return &PrivKey{ + Key: crypto.FromECDSA(priv), + }, nil +} + +// ToECDSA returns the ECDSA private key as a reference to ecdsa.PrivateKey type. +func (privKey PrivKey) ToECDSA() (*ecdsa.PrivateKey, error) { + return crypto.ToECDSA(privKey.Bytes()) +} + +// =============================================================================================== +// Public Key +// =============================================================================================== + +// Pubkey is a wrapper around the Ethereum secp256k1 public key type. This wrapper conforms to +// crypotypes.Pubkey to allow for the use of the Ethereum secp256k1 public key type within the +// Cosmos SDK. + +// Compile-time type assertion. +var _ cryptotypes.PubKey = &PubKey{} + +// Address returns the address of the ECDSA public key. +// The function will return an empty address if the public key is invalid. +func (pubKey PubKey) Address() cmcrypto.Address { + key, err := crypto.DecompressPubkey(pubKey.Key) + if err != nil { + return nil + } + + return cmcrypto.Address(crypto.PubkeyToAddress(*key).Bytes()) +} + +// Bytes returns the pubkey byte format. +func (pubKey *PubKey) Bytes() []byte { + return pubKey.Key +} + +// Type returns eth_secp256k1. +func (pubKey *PubKey) Type() string { + return KeyType +} + +// Equals returns true if the pubkey type is the same and their bytes are deeply equal. +func (pubKey PubKey) Equals(other cryptotypes.PubKey) bool { + return pubKey.Type() == other.Type() && bytes.Equal(pubKey.Bytes(), other.Bytes()) +} diff --git a/cosmos/crypto/keys/ethsecp256k1/keys.pb.go b/cosmos/crypto/keys/ethsecp256k1/keys.pb.go new file mode 100644 index 000000000..7ace5fa0b --- /dev/null +++ b/cosmos/crypto/keys/ethsecp256k1/keys.pb.go @@ -0,0 +1,499 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: polaris/crypto/ethsecp256k1/v1/keys.proto + +package ethsecp256k1 + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// `PubKey` defines a type alias for an `ecdsa.PublicKey` that implements +// CometBFT's `PubKey` interface. It represents the 33-byte compressed public +// key format. +type PubKey struct { + // `key` is the public key in byte form. + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (m *PubKey) Reset() { *m = PubKey{} } +func (m *PubKey) String() string { return proto.CompactTextString(m) } +func (*PubKey) ProtoMessage() {} +func (*PubKey) Descriptor() ([]byte, []int) { + return fileDescriptor_e0c989ba1b8717d6, []int{0} +} +func (m *PubKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PubKey.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 *PubKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_PubKey.Merge(m, src) +} +func (m *PubKey) XXX_Size() int { + return m.Size() +} +func (m *PubKey) XXX_DiscardUnknown() { + xxx_messageInfo_PubKey.DiscardUnknown(m) +} + +var xxx_messageInfo_PubKey proto.InternalMessageInfo + +func (m *PubKey) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +// `PrivKey` defines a type alias for a n`ecdsa.PrivateKey` that implements +// CometBFT's `PrivateKey` interface. +type PrivKey struct { + // `key` is the private key in byte form. + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (m *PrivKey) Reset() { *m = PrivKey{} } +func (m *PrivKey) String() string { return proto.CompactTextString(m) } +func (*PrivKey) ProtoMessage() {} +func (*PrivKey) Descriptor() ([]byte, []int) { + return fileDescriptor_e0c989ba1b8717d6, []int{1} +} +func (m *PrivKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PrivKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PrivKey.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 *PrivKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_PrivKey.Merge(m, src) +} +func (m *PrivKey) XXX_Size() int { + return m.Size() +} +func (m *PrivKey) XXX_DiscardUnknown() { + xxx_messageInfo_PrivKey.DiscardUnknown(m) +} + +var xxx_messageInfo_PrivKey proto.InternalMessageInfo + +func (m *PrivKey) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func init() { + proto.RegisterType((*PubKey)(nil), "polaris.crypto.ethsecp256k1.v1.PubKey") + proto.RegisterType((*PrivKey)(nil), "polaris.crypto.ethsecp256k1.v1.PrivKey") +} + +func init() { + proto.RegisterFile("polaris/crypto/ethsecp256k1/v1/keys.proto", fileDescriptor_e0c989ba1b8717d6) +} + +var fileDescriptor_e0c989ba1b8717d6 = []byte{ + // 182 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2c, 0xc8, 0xcf, 0x49, + 0x2c, 0xca, 0x2c, 0xd6, 0x4f, 0x2e, 0xaa, 0x2c, 0x28, 0xc9, 0xd7, 0x4f, 0x2d, 0xc9, 0x28, 0x4e, + 0x4d, 0x2e, 0x30, 0x32, 0x35, 0xcb, 0x36, 0xd4, 0x2f, 0x33, 0xd4, 0xcf, 0x4e, 0xad, 0x2c, 0xd6, + 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x83, 0x2a, 0xd5, 0x83, 0x28, 0xd5, 0x43, 0x56, 0xaa, + 0x57, 0x66, 0xa8, 0x24, 0xc5, 0xc5, 0x16, 0x50, 0x9a, 0xe4, 0x9d, 0x5a, 0x29, 0x24, 0xc0, 0xc5, + 0x9c, 0x9d, 0x5a, 0x29, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x13, 0x04, 0x62, 0x2a, 0x49, 0x73, 0xb1, + 0x07, 0x14, 0x65, 0x96, 0x61, 0x95, 0x74, 0x0a, 0x3e, 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, 0xcb, 0x82, 0xec, 0x74, 0xbd, 0xa4, 0xd4, 0xa2, 0xc4, 0xe4, 0x8c, 0xc4, 0xcc, + 0x3c, 0xbd, 0x94, 0xd4, 0x32, 0x7d, 0xb8, 0x7b, 0xf3, 0x8b, 0x73, 0xf3, 0xe1, 0xce, 0x06, 0x39, + 0x13, 0xc5, 0xed, 0x49, 0x6c, 0x60, 0x47, 0x1b, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x5e, 0xa7, + 0xc8, 0x46, 0xe1, 0x00, 0x00, 0x00, +} + +func (m *PubKey) 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 *PubKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintKeys(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *PrivKey) 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 *PrivKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PrivKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintKeys(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintKeys(dAtA []byte, offset int, v uint64) int { + offset -= sovKeys(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *PubKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovKeys(uint64(l)) + } + return n +} + +func (m *PrivKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovKeys(uint64(l)) + } + return n +} + +func sovKeys(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozKeys(x uint64) (n int) { + return sovKeys(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *PubKey) 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: PubKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PubKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", 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 + } + m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) + if m.Key == nil { + m.Key = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipKeys(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthKeys + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PrivKey) 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: PrivKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PrivKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", 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 + } + m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) + if m.Key == nil { + m.Key = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipKeys(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (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 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowKeys + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowKeys + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowKeys + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthKeys + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupKeys + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthKeys + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthKeys = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowKeys = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupKeys = fmt.Errorf("proto: unexpected end of group") +) diff --git a/cosmos/crypto/keys/ethsecp256k1/keys_test.go b/cosmos/crypto/keys/ethsecp256k1/keys_test.go new file mode 100644 index 000000000..5e4e7b516 --- /dev/null +++ b/cosmos/crypto/keys/ethsecp256k1/keys_test.go @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package ethsecp256k1 + +import ( + "testing" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + + ethcrypto "pkg.berachain.dev/polaris/eth/crypto" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestEthSecp256K1(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "cosmos/crypto/keys/ethsecp256k1") +} + +var _ = Describe("PubPrivKey", func() { + var privKey *PrivKey + + BeforeEach(func() { + var err error + privKey, err = GenPrivKey() + Expect(err).ToNot(HaveOccurred()) + }) + + It("validates type and equality", func() { + Expect(privKey).To(BeAssignableToTypeOf((cryptotypes.PrivKey)(&PrivKey{}))) + }) + + It("validates inequality", func() { + privKey2, err := GenPrivKey() + Expect(err).ToNot(HaveOccurred()) + Expect(privKey.Equals(privKey2)).To(BeFalse()) + }) + + It("validates Ethereum address equality", func() { + addr := privKey.PubKey().Address() + key, err := privKey.ToECDSA() + Expect(err).ToNot(HaveOccurred()) + expectedAddr := ethcrypto.PubkeyToAddress(key.PublicKey) + Expect(expectedAddr.Bytes()).To(Equal(addr.Bytes())) + }) + + It("validates type", func() { + pubKey := &PubKey{ + Key: privKey.PubKey().Bytes(), + } + Expect(pubKey).To(BeAssignableToTypeOf((cryptotypes.PubKey)(&PubKey{}))) + }) + + It("validates equality", func() { + privKey2, err := GenPrivKey() + Expect(err).ToNot(HaveOccurred()) + Expect(privKey).ToNot(Equal(privKey2)) + Expect(privKey.PubKey()).ToNot(Equal(privKey2.PubKey())) + }) + +}) diff --git a/cosmos/crypto/keys/ethsecp256k1/signature_cgo.go b/cosmos/crypto/keys/ethsecp256k1/signature_cgo.go new file mode 100644 index 000000000..0b02aa042 --- /dev/null +++ b/cosmos/crypto/keys/ethsecp256k1/signature_cgo.go @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package ethsecp256k1 + +import ( + "pkg.berachain.dev/polaris/eth/crypto" +) + +// Sign signs the provided message using the ECDSA private key. It returns an error if the +// Sign creates a recoverable ECDSA signature on the `secp256k1` curve over the +// provided hash of the message. The produced signature is 65 bytes +// where the last byte contains the recovery ID. +func (privKey PrivKey) Sign(digestBz []byte) ([]byte, error) { + // We hash the provided input since EthSign expects a 32byte hash. + if len(digestBz) != crypto.DigestLength { + digestBz = crypto.Keccak256(digestBz) + } + + key, err := privKey.ToECDSA() + if err != nil { + return nil, err + } + + return crypto.EthSign(digestBz, key) +} + +// VerifySignature verifies that the ECDSA public key created a given signature over +// the provided message. The signature should be in [R || S] format. +func (pubKey PubKey) VerifySignature(msg, sig []byte) bool { + // This is a little hacky, but in order to work around the fact that the Cosmos-SDK typically + // does not hash messages, we have to accept an unhashed message and hash it. + // NOTE: this function will not work correctly if a msg of length 32 is provided, that is actually + // the hash of the message that was signed. + if len(msg) != crypto.DigestLength { + msg = crypto.Keccak256(msg) + } + + // The signature length must be correct. + if len(sig) == crypto.SignatureLength { + // remove recovery ID (V) if contained in the signature + sig = sig[:len(sig)-1] + } + + // The signature needs to be in [R || S] format when provided to `VerifySignature`. + return crypto.VerifySignature(pubKey.Key, msg, sig) +} diff --git a/cosmos/crypto/keys/ethsecp256k1/signature_cgo_test.go b/cosmos/crypto/keys/ethsecp256k1/signature_cgo_test.go new file mode 100644 index 000000000..1933a05b8 --- /dev/null +++ b/cosmos/crypto/keys/ethsecp256k1/signature_cgo_test.go @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package ethsecp256k1 + +import ( + "crypto/ecdsa" + + "pkg.berachain.dev/polaris/eth/crypto" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("PrivKey_PubKey", func() { + var privKey *PrivKey + var ecdsaPrivKey *ecdsa.PrivateKey + + BeforeEach(func() { + var err error + privKey, err = GenPrivKey() + Expect(err).ToNot(HaveOccurred()) + ecdsaPrivKey, err = privKey.ToECDSA() + Expect(err).ToNot(HaveOccurred()) + }) + + It("validates signing bytes", func() { + msg := []byte("hello world") + // for the eth case, we have to manually hash in the test. + sigHash := crypto.Keccak256(msg) + + expectedSig, err := crypto.EthSign(sigHash, ecdsaPrivKey) + Expect(err).ToNot(HaveOccurred()) + + sig, err := privKey.Sign(msg) + Expect(err).ToNot(HaveOccurred()) + Expect(expectedSig).To(Equal(sig)) + }) + + It("validates signature", func() { + msg := []byte("hello world") + sigHash := crypto.Keccak256(msg) + sig, err := privKey.Sign(sigHash) + Expect(err).ToNot(HaveOccurred()) + + res := privKey.PubKey().VerifySignature(sigHash, sig) + Expect(res).To(BeTrue()) + }) +}) diff --git a/cosmos/go.mod b/cosmos/go.mod index 0f870eff5..0e0f6b59b 100644 --- a/cosmos/go.mod +++ b/cosmos/go.mod @@ -17,10 +17,13 @@ require ( cosmossdk.io/math v1.1.3-rc.1 cosmossdk.io/store v1.0.0-rc.0 cosmossdk.io/x/tx v0.11.0 + github.com/btcsuite/btcd v0.23.0 + github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cometbft/cometbft v0.38.0 github.com/cosmos/cosmos-db v1.0.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.50.0-rc.1.0.20231023194456-42dbfc4d7087 + github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogoproto v1.4.11 github.com/ethereum/go-ethereum v1.13.1 github.com/golang/mock v1.6.0 @@ -52,6 +55,7 @@ require ( github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/bits-and-blooms/bitset v1.8.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect + github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect github.com/bytedance/sonic v1.10.0 // indirect github.com/cenkalti/backoff/v4 v4.2.0 // indirect github.com/cespare/xxhash v1.1.0 // indirect @@ -67,7 +71,6 @@ require ( github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v1.0.0-rc.1 // indirect github.com/cosmos/ics23/go v0.10.0 // indirect diff --git a/cosmos/go.sum b/cosmos/go.sum index 4fc9a2c7c..80e4a3533 100644 --- a/cosmos/go.sum +++ b/cosmos/go.sum @@ -83,6 +83,7 @@ github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrd github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I= github.com/adlio/schema v1.3.3/go.mod h1:1EsRssiv9/Ce2CMzq5DoL7RiMshhuigQxrR4DMV9fHg= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -118,12 +119,30 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsy github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c= github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= +github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= +github.com/btcsuite/btcd v0.23.0 h1:V2/ZgjfDFIygAX3ZapeigkVBoVUtOJKSwrhZdlpSvaA= +github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= +github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= +github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A= +github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE= github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/bufbuild/protocompile v0.6.0 h1:Uu7WiSQ6Yj9DbkdnOe7U4mNKp58y9WDMKDn28/ZlunY= github.com/bufbuild/protocompile v0.6.0/go.mod h1:YNP35qEYoYGme7QMtz5SBCoN4kL4g12jTtjuzRNdjpE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -237,15 +256,19 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set/v2 v2.3.1 h1:vjmkvJt/IV27WXPyYQpAh4bRyWJc5Y435D17XQ9QU5A= github.com/deckarep/golang-set/v2 v2.3.1/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/deepmap/oapi-codegen v1.13.4 h1:lRRQ8JAXaz5/4oidKFyk3fFZFQsbv0BzRtvDKDnvIfM= github.com/deepmap/oapi-codegen v1.13.4/go.mod h1:/h5nFQbTAMz4S/WtBz8sBfamlGByYKDr21O2uoNgCYI= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= @@ -581,6 +604,8 @@ github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 h1:vilfsD github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jhump/protoreflect v1.15.2 h1:7YppbATX94jEt9KLAc5hICx4h6Yt3SaavhQRsIUEHP0= github.com/jhump/protoreflect v1.15.2/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -588,6 +613,7 @@ github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -606,6 +632,7 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= @@ -737,6 +764,7 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= @@ -993,6 +1021,7 @@ go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1046,6 +1075,7 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/e2e/hive/clients/polard/entrypoint.sh b/e2e/hive/clients/polard/entrypoint.sh index a1a782eb8..c2bce64c0 100644 --- a/e2e/hive/clients/polard/entrypoint.sh +++ b/e2e/hive/clients/polard/entrypoint.sh @@ -24,7 +24,7 @@ KEYS[0]="dev0" CHAINID="polaris-2061" MONIKER="localtestnet" KEYRING="test" -KEYALGO="secp256k1" +KEYALGO="eth_secp256k1" LOGLEVEL="info" HOMEDIR="/" ETH_GENESIS_JSON="genesis.json" diff --git a/e2e/precompile/polard/start-node.sh b/e2e/precompile/polard/start-node.sh index 3ece948c6..1f16f9242 100755 --- a/e2e/precompile/polard/start-node.sh +++ b/e2e/precompile/polard/start-node.sh @@ -28,7 +28,7 @@ MONIKER="localtestnet" # otherwise your balance will be wiped quickly # The keyring test does not require private key to steal tokens from you KEYRING="test" -KEYALGO="secp256k1" +KEYALGO="eth_secp256k1" LOGLEVEL="info" # Set dedicated home directory for the ./build/bin/polard instance HOMEDIR="/" diff --git a/e2e/testapp/app.go b/e2e/testapp/app.go index a3db0b32c..25231c7e2 100644 --- a/e2e/testapp/app.go +++ b/e2e/testapp/app.go @@ -55,6 +55,7 @@ import ( evmv1alpha1 "pkg.berachain.dev/polaris/cosmos/api/polaris/evm/v1alpha1" evmconfig "pkg.berachain.dev/polaris/cosmos/config" + ethcryptocodec "pkg.berachain.dev/polaris/cosmos/crypto/codec" signinglib "pkg.berachain.dev/polaris/cosmos/lib/signing" polarruntime "pkg.berachain.dev/polaris/cosmos/runtime" evmkeeper "pkg.berachain.dev/polaris/cosmos/x/evm/keeper" @@ -205,6 +206,9 @@ func NewPolarisApp( // RegisterUpgradeHandlers is used for registering any on-chain upgrades. app.RegisterUpgradeHandlers() + // Register eth_secp256k1 keys + ethcryptocodec.RegisterInterfaces(app.interfaceRegistry) + // Load the app. if err := app.Load(loadLatest); err != nil { panic(err) diff --git a/e2e/testapp/docker/local/docker-init.sh b/e2e/testapp/docker/local/docker-init.sh index f0e43f975..6071d2cc5 100644 --- a/e2e/testapp/docker/local/docker-init.sh +++ b/e2e/testapp/docker/local/docker-init.sh @@ -29,7 +29,7 @@ MONIKER="localtestnet" # otherwise your balance will be wiped quickly # The keyring test does not require private key to steal tokens from you KEYRING="test" -KEYALGO="secp256k1" +KEYALGO="eth_secp256k1" LOGLEVEL="info" # Set dedicated home directory for the ./build/bin/polard instance HOMEDIR="/" diff --git a/e2e/testapp/docker/seed/init.sh b/e2e/testapp/docker/seed/init.sh index 118c45369..0ad79711c 100755 --- a/e2e/testapp/docker/seed/init.sh +++ b/e2e/testapp/docker/seed/init.sh @@ -22,7 +22,7 @@ KEY="brick" CHAINID="berachain-666" MONIKER="brickchain" KEYRING="test" -KEYALGO="secp256k1" +KEYALGO="eth_secp256k1" LOGLEVEL="info" HOMEDIR="data/.polard" TRACE="" diff --git a/e2e/testapp/docker/seed/scripts/seed0-init-step1.sh b/e2e/testapp/docker/seed/scripts/seed0-init-step1.sh index 7778ec2ff..4aa4cd5f0 100755 --- a/e2e/testapp/docker/seed/scripts/seed0-init-step1.sh +++ b/e2e/testapp/docker/seed/scripts/seed0-init-step1.sh @@ -25,7 +25,7 @@ if [ -z "$KEYRING" ]; then KEYRING="test" fi if [ -z "$KEYALGO" ]; then - KEYALGO="secp256k1" + KEYALGO="eth_secp256k1" fi if [ -z "$LOGLEVEL" ]; then LOGLEVEL="info" diff --git a/e2e/testapp/docker/seed/scripts/seed0-init-step2.sh b/e2e/testapp/docker/seed/scripts/seed0-init-step2.sh index 164d4f5ca..079e2a587 100644 --- a/e2e/testapp/docker/seed/scripts/seed0-init-step2.sh +++ b/e2e/testapp/docker/seed/scripts/seed0-init-step2.sh @@ -25,7 +25,7 @@ if [ -z "$KEYRING" ]; then KEYRING="test" fi if [ -z "$KEYALGO" ]; then - KEYALGO="secp256k1" + KEYALGO="eth_secp256k1" fi polard genesis collect-gentxs --home "$HOMEDIR" diff --git a/e2e/testapp/docker/seed/scripts/seed1-init-step1.sh b/e2e/testapp/docker/seed/scripts/seed1-init-step1.sh index 6042f4452..0f784b4b7 100644 --- a/e2e/testapp/docker/seed/scripts/seed1-init-step1.sh +++ b/e2e/testapp/docker/seed/scripts/seed1-init-step1.sh @@ -25,7 +25,7 @@ if [ -z "$KEYRING" ]; then KEYRING="test" fi if [ -z "$KEYALGO" ]; then - KEYALGO="secp256k1" + KEYALGO="eth_secp256k1" fi if [ -z "$LOGLEVEL" ]; then LOGLEVEL="info" diff --git a/e2e/testapp/docker/validator/scripts/val0-init-step1.sh b/e2e/testapp/docker/validator/scripts/val0-init-step1.sh index 0049b9c4e..1c5ce6f7a 100644 --- a/e2e/testapp/docker/validator/scripts/val0-init-step1.sh +++ b/e2e/testapp/docker/validator/scripts/val0-init-step1.sh @@ -22,7 +22,7 @@ KEY1="val0" CHAINID="brickchain-666" MONIKER1="val-0" KEYRING="test" -KEYALGO="secp256k1" +KEYALGO="eth_secp256k1" HOMEDIR="/.polard" polard init $MONIKER1 -o --chain-id $CHAINID --home "$HOMEDIR" diff --git a/e2e/testapp/docker/validator/scripts/val1-init-step1.sh b/e2e/testapp/docker/validator/scripts/val1-init-step1.sh index 68a49db78..e11b39721 100644 --- a/e2e/testapp/docker/validator/scripts/val1-init-step1.sh +++ b/e2e/testapp/docker/validator/scripts/val1-init-step1.sh @@ -22,7 +22,7 @@ KEY2="val1" CHAINID="brickchain-666" MONIKER1="val-1" KEYRING="test" -KEYALGO="secp256k1" +KEYALGO="eth_secp256k1" HOMEDIR="/.polard" polard init $MONIKER1 -o --chain-id $CHAINID --home "$HOMEDIR" diff --git a/e2e/testapp/entrypoint.sh b/e2e/testapp/entrypoint.sh index a5a4eea0a..ac4663f22 100755 --- a/e2e/testapp/entrypoint.sh +++ b/e2e/testapp/entrypoint.sh @@ -28,7 +28,7 @@ MONIKER="localtestnet" # otherwise your balance will be wiped quickly # The keyring test does not require private key to steal tokens from you KEYRING="test" -KEYALGO="secp256k1" +KEYALGO="eth_secp256k1" LOGLEVEL="info" # Set dedicated home directory for the ./build/bin/polard instance HOMEDIR="./.tmp/polard" diff --git a/e2e/testapp/polard/cmd/root.go b/e2e/testapp/polard/cmd/root.go index d508e78d2..b5940ae07 100644 --- a/e2e/testapp/polard/cmd/root.go +++ b/e2e/testapp/polard/cmd/root.go @@ -63,6 +63,8 @@ import ( evmv1alpha1 "pkg.berachain.dev/polaris/cosmos/api/polaris/evm/v1alpha1" evmconfig "pkg.berachain.dev/polaris/cosmos/config" + ethcryptocodec "pkg.berachain.dev/polaris/cosmos/crypto/codec" + "pkg.berachain.dev/polaris/cosmos/crypto/keyring" signinglib "pkg.berachain.dev/polaris/cosmos/lib/signing" testapp "pkg.berachain.dev/polaris/e2e/testapp" ) @@ -110,8 +112,11 @@ func NewRootCmd() *cobra.Command { WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). WithHomeDir(testapp.DefaultNodeHome). + WithKeyringOptions(keyring.EthSecp256k1Option()). WithViper("") // In simapp, we don't use any prefix for env variables. + ethcryptocodec.RegisterInterfaces(interfaceRegistry) + rootCmd := &cobra.Command{ Use: "polard", Short: "polaris sample app", diff --git a/eth/crypto/imported.go b/eth/crypto/imported.go index 8d1009768..703c7498a 100644 --- a/eth/crypto/imported.go +++ b/eth/crypto/imported.go @@ -22,18 +22,28 @@ package crypto import ( "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto/secp256k1" ) var ( - // GenerateEthKey is a function that generates a new Ethereum key. - GenerateEthKey = crypto.GenerateKey - // Keccak256 is a function that computes and returns the Keccak256 hash of the input data. - Keccak256 = crypto.Keccak256 - // Keccak256Hash is a function that computes and returns the Keccak256 hash of the input data, - // but the return type is Hash. - Keccak256Hash = crypto.Keccak256Hash - // PubkeyToAddress is a function that derives the Ethereum address from the given public key. - PubkeyToAddress = crypto.PubkeyToAddress - // LoadECDSA is a function that loads a private key from a given file. - LoadECDSA = crypto.LoadECDSA + SigToPub = crypto.SigToPub + Ecrecover = crypto.Ecrecover + CreateAddress = crypto.CreateAddress + UnmarshalPubkey = crypto.UnmarshalPubkey + CompressPubkey = crypto.CompressPubkey + DecompressPubkey = crypto.DecompressPubkey + DigestLength = crypto.DigestLength + EthSign = crypto.Sign + EthSecp256k1Sign = secp256k1.Sign + LoadECDSA = crypto.LoadECDSA + FromECDSA = crypto.FromECDSA + GenerateEthKey = crypto.GenerateKey + ValidateSignatureValues = crypto.ValidateSignatureValues + Keccak256 = crypto.Keccak256 + Keccak256Hash = crypto.Keccak256Hash + PubkeyToAddress = crypto.PubkeyToAddress + SignatureLength = crypto.SignatureLength + ToECDSA = crypto.ToECDSA + VerifySignature = crypto.VerifySignature + FromECDSAPub = crypto.FromECDSAPub ) diff --git a/go.work.sum b/go.work.sum index 434c59b6e..72a4e2100 100644 --- a/go.work.sum +++ b/go.work.sum @@ -407,6 +407,7 @@ github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTN github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg= github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 h1:rFw4nCn9iMW+Vajsk51NtYIcwSTkXr+JGrMd36kTDJw= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= @@ -495,8 +496,6 @@ github.com/berachain/polaris-geth 88eca5365ecc96474ca94bd4f0d8d9d99bed2a09/go.mo github.com/berachain/polaris-geth v0.0.0-20231024032003-b94ca5da2234/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw= github.com/berachain/polaris-geth v0.0.0-20231024032731-4fdd2b9deba9/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw= github.com/berachain/polaris-geth v0.0.0-20231024043959-88eca5365ecc/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q= -github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb h1:4oWKO5gaauAaOqAuVFz1J0/5+raBtr+SZuFNOU9HQn0= -github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw= github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= @@ -505,6 +504,13 @@ github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTS github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw= +github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4= +github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc= +github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.10.0-rc3/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/casbin/casbin/v2 v2.37.0 h1:/poEwPSovi4bTOcP752/CsTQiRz2xycyVKFG7GUhbDw= @@ -577,6 +583,7 @@ github.com/cristalhq/acmd v0.11.1 h1:DJ4fh2Pv0nPKmqT646IU/0Vh5FNdGblxvF+3/W3NAUI github.com/cristalhq/acmd v0.11.1/go.mod h1:LG5oa43pE/BbxtfMoImHCQN++0Su7dzipdgBjMCBVDQ= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c h1:/ovYnF02fwL0kvspmy9AuyKg1JhdTRUgPw4nUxd9oZM= github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X51MTk3ycuNI= +github.com/decred/dcrd/lru v1.0.0 h1:Kbsb1SFDsIlaupWPwsPp+dkxiBY1frcS07PCPgotKz8= github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw= github.com/dgraph-io/badger v1.6.0 h1:DshxFxZWXUcO0xX476VJC07Xsr6ZCBVRHKZ93Oh7Evo= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= @@ -810,6 +817,7 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267 h1:TMtDYDHKYY15rFihtRfck/bfFqNfvcabqvXAFQfAUpY= github.com/jedisct1/go-minisign v0.0.0-20230811132847-661be99b8267/go.mod h1:h1nSAbGFqGVzn6Jyl1R/iCcBUHN4g+gW1u9CoBTrb9E= +github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= github.com/jhump/gopoet v0.1.0 h1:gYjOPnzHd2nzB37xYQZxj4EIQNpBrBskRqQQ3q4ZgSg= github.com/jhump/gopoet v0.1.0/go.mod h1:me9yfT6IJSlOL3FCfrg+L6yzUEZ+5jW6WHt4Sk+UPUI= github.com/jhump/goprotoc v0.5.0 h1:Y1UgUX+txUznfqcGdDef8ZOVlyQvnV0pKWZH08RmZuo= @@ -820,6 +828,7 @@ github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0 github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= +github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI= github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 h1:rhqTjzJlm7EbkELJDKMTU7udov+Se0xZkWmugr6zGok= @@ -854,6 +863,7 @@ github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4 github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4= github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE= github.com/klauspost/asmfmt v1.3.2 h1:4Ri7ox3EwapiOjCki+hw14RyKk201CN4rzyCJRFLpK4= github.com/klauspost/asmfmt v1.3.2/go.mod h1:AG8TuvYojzulgDAMCnYn50l/5QV3Bs/tp6j0HLHbNSE= github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= diff --git a/proto/polaris/crypto/ethsecp256k1/v1/keys.proto b/proto/polaris/crypto/ethsecp256k1/v1/keys.proto new file mode 100644 index 000000000..e6414ace2 --- /dev/null +++ b/proto/polaris/crypto/ethsecp256k1/v1/keys.proto @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +syntax = "proto3"; + +package polaris.crypto.ethsecp256k1.v1; + +option go_package = "pkg.berachain.dev/polaris/cosmos/crypto/keys/ethsecp256k1"; + +// `PubKey` defines a type alias for an `ecdsa.PublicKey` that implements +// CometBFT's `PubKey` interface. It represents the 33-byte compressed public +// key format. +message PubKey { + // `key` is the public key in byte form. + bytes key = 1; +} + +// `PrivKey` defines a type alias for a n`ecdsa.PrivateKey` that implements +// CometBFT's `PrivateKey` interface. +message PrivKey { + // `key` is the private key in byte form. + bytes key = 1; +} From d23c3c13507d7a732906fecd119e5674de8a6675 Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Wed, 1 Nov 2023 11:43:42 -0400 Subject: [PATCH 2/3] bing --- cosmos/crypto/keyring/option.go | 10 ++++------ cosmos/crypto/keyring/option_test.go | 2 +- e2e/testapp/polard/cmd/root.go | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cosmos/crypto/keyring/option.go b/cosmos/crypto/keyring/option.go index e729595b3..c00291622 100644 --- a/cosmos/crypto/keyring/option.go +++ b/cosmos/crypto/keyring/option.go @@ -21,17 +21,15 @@ package keyring import ( - sdkhd "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "pkg.berachain.dev/polaris/cosmos/crypto/hd" ) -// EthSecp256k1Option defines a function keys options for the ethereum Secp256k1 curve. -// It supports ethsecp256k1 and secp256k1 keys for accounts. -func EthSecp256k1Option() keyring.Option { +// OnlyEthSecp256k1Option defines a function keys options for the ethereum Secp256k1 curve. +func OnlyEthSecp256k1Option() keyring.Option { return func(options *keyring.Options) { - options.SupportedAlgos = keyring.SigningAlgoList{hd.EthSecp256k1, sdkhd.Secp256k1} - options.SupportedAlgosLedger = keyring.SigningAlgoList{hd.EthSecp256k1, sdkhd.Secp256k1} + options.SupportedAlgos = keyring.SigningAlgoList{hd.EthSecp256k1} + options.SupportedAlgosLedger = keyring.SigningAlgoList{hd.EthSecp256k1} } } diff --git a/cosmos/crypto/keyring/option_test.go b/cosmos/crypto/keyring/option_test.go index 98ac4ec17..67eddce27 100644 --- a/cosmos/crypto/keyring/option_test.go +++ b/cosmos/crypto/keyring/option_test.go @@ -74,7 +74,7 @@ var _ = Describe("Keyring", func() { cryptocodec.RegisterInterfaces(interfaceRegistry) cdc = codec.NewProtoCodec(interfaceRegistry) - kr, err = keyring.New("accounts", keyring.BackendTest, dir, mockIn, cdc, EthSecp256k1Option()) + kr, err = keyring.New("accounts", keyring.BackendTest, dir, mockIn, cdc, OnlyEthSecp256k1Option()) Expect(err).NotTo(HaveOccurred()) }) diff --git a/e2e/testapp/polard/cmd/root.go b/e2e/testapp/polard/cmd/root.go index b5940ae07..9334a7ef3 100644 --- a/e2e/testapp/polard/cmd/root.go +++ b/e2e/testapp/polard/cmd/root.go @@ -112,7 +112,7 @@ func NewRootCmd() *cobra.Command { WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). WithHomeDir(testapp.DefaultNodeHome). - WithKeyringOptions(keyring.EthSecp256k1Option()). + WithKeyringOptions(keyring.OnlyEthSecp256k1Option()). WithViper("") // In simapp, we don't use any prefix for env variables. ethcryptocodec.RegisterInterfaces(interfaceRegistry) From a0afc91f04ff6a0bc46e5d84b70dc46ed548aebc Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Wed, 1 Nov 2023 11:49:24 -0400 Subject: [PATCH 3/3] lint --- cosmos/crypto/keyring/option_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cosmos/crypto/keyring/option_test.go b/cosmos/crypto/keyring/option_test.go index 67eddce27..190f77ce4 100644 --- a/cosmos/crypto/keyring/option_test.go +++ b/cosmos/crypto/keyring/option_test.go @@ -74,7 +74,9 @@ var _ = Describe("Keyring", func() { cryptocodec.RegisterInterfaces(interfaceRegistry) cdc = codec.NewProtoCodec(interfaceRegistry) - kr, err = keyring.New("accounts", keyring.BackendTest, dir, mockIn, cdc, OnlyEthSecp256k1Option()) + kr, err = keyring.New( + "accounts", keyring.BackendTest, dir, mockIn, cdc, OnlyEthSecp256k1Option(), + ) Expect(err).NotTo(HaveOccurred()) })