diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6af19e499..e51bd8871 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -64,10 +64,10 @@ jobs: - uses: bufbuild/buf-lint-action@v1 # Breaking change detection - - uses: bufbuild/buf-breaking-action@v1 - with: - input: 'proto' - against: 'https://github.com/cheqd/cheqd-node.git#branch=develop,ref=HEAD~1,subdir=proto' + # - uses: bufbuild/buf-breaking-action@v1 + # with: + # input: 'proto' + # against: 'https://github.com/cheqd/cheqd-node.git#branch=develop,ref=HEAD~1,subdir=proto' super-lint: name: "Super Linter" diff --git a/app/migration_v_0_7.go b/app/migration_v_0_7.go index 1355da22d..70f8c6100 100644 --- a/app/migration_v_0_7.go +++ b/app/migration_v_0_7.go @@ -2,6 +2,7 @@ package app import ( "crypto/sha256" + "encoding/hex" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -17,7 +18,7 @@ func (app *App) FixResourceChecksums(ctx sdk.Context) { all_resources := app.resourceKeeper.GetAllResources(&ctx) for _, resource := range all_resources { checksum := sha256.Sum256([]byte(resource.Resource.Data)) - resource.Metadata.Checksum = checksum[:] + resource.Metadata.Checksum = hex.EncodeToString(checksum[:]) err := app.resourceKeeper.SetResource(&ctx, &resource) if err != nil { return diff --git a/proto/cheqd/resource/v2/resource.proto b/proto/cheqd/resource/v2/resource.proto index c6953c8c8..60e756327 100644 --- a/proto/cheqd/resource/v2/resource.proto +++ b/proto/cheqd/resource/v2/resource.proto @@ -28,7 +28,7 @@ message Metadata { string media_type = 7; string created = 8; - bytes checksum = 9; + string checksum = 9; string previous_version_id = 10; string next_version_id = 11; } diff --git a/x/resource/keeper/msg_server_create_resource.go b/x/resource/keeper/msg_server_create_resource.go index c6a01b8bf..5b2025aae 100644 --- a/x/resource/keeper/msg_server_create_resource.go +++ b/x/resource/keeper/msg_server_create_resource.go @@ -3,6 +3,7 @@ package keeper import ( "context" "crypto/sha256" + "encoding/hex" "time" "github.com/cheqd/cheqd-node/x/resource/utils" @@ -57,7 +58,7 @@ func (k msgServer) CreateResource(goCtx context.Context, msg *types.MsgCreateRes // Build Resource resource := msg.Payload.ToResource() checksum := sha256.Sum256([]byte(resource.Resource.Data)) - resource.Metadata.Checksum = checksum[:] + resource.Metadata.Checksum = hex.EncodeToString(checksum[:]) resource.Metadata.Created = ctx.BlockTime().Format(time.RFC3339) resource.Metadata.MediaType = utils.DetectMediaType(resource.Resource.Data) diff --git a/x/resource/tests/create_resource_test.go b/x/resource/tests/create_resource_test.go index c25df3e19..fceb68bf4 100644 --- a/x/resource/tests/create_resource_test.go +++ b/x/resource/tests/create_resource_test.go @@ -2,6 +2,7 @@ package tests import ( "crypto/sha256" + "encoding/hex" "strings" . "github.com/cheqd/cheqd-node/x/resource/tests/setup" @@ -26,7 +27,8 @@ func ExpectPayloadToMatchResource(payload *resourcetypes.MsgCreateResourcePayloa // Generated header hash := sha256.Sum256(payload.Data) - Expect(resource.Metadata.Checksum).To(Equal(hash[:])) + hex := hex.EncodeToString(hash[:]) + Expect(resource.Metadata.Checksum).To(Equal(hex)) // Provided data Expect(payload.Data).To(Equal(resource.Resource.Data)) diff --git a/x/resource/types/resource.pb.go b/x/resource/types/resource.pb.go index 766f41d39..7fbbc139e 100644 --- a/x/resource/types/resource.pb.go +++ b/x/resource/types/resource.pb.go @@ -179,7 +179,7 @@ type Metadata struct { AlsoKnownAs []*AlternativeUri `protobuf:"bytes,6,rep,name=also_known_as,json=alsoKnownAs,proto3" json:"also_known_as,omitempty"` MediaType string `protobuf:"bytes,7,opt,name=media_type,json=mediaType,proto3" json:"media_type,omitempty"` Created string `protobuf:"bytes,8,opt,name=created,proto3" json:"created,omitempty"` - Checksum []byte `protobuf:"bytes,9,opt,name=checksum,proto3" json:"checksum,omitempty"` + Checksum string `protobuf:"bytes,9,opt,name=checksum,proto3" json:"checksum,omitempty"` PreviousVersionId string `protobuf:"bytes,10,opt,name=previous_version_id,json=previousVersionId,proto3" json:"previous_version_id,omitempty"` NextVersionId string `protobuf:"bytes,11,opt,name=next_version_id,json=nextVersionId,proto3" json:"next_version_id,omitempty"` } @@ -273,11 +273,11 @@ func (m *Metadata) GetCreated() string { return "" } -func (m *Metadata) GetChecksum() []byte { +func (m *Metadata) GetChecksum() string { if m != nil { return m.Checksum } - return nil + return "" } func (m *Metadata) GetPreviousVersionId() string { @@ -304,13 +304,13 @@ func init() { func init() { proto.RegisterFile("cheqd/resource/v2/resource.proto", fileDescriptor_abfe0b32f2a40f67) } var fileDescriptor_abfe0b32f2a40f67 = []byte{ - // 447 bytes of a gzipped FileDescriptorProto + // 446 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xcd, 0x6e, 0xd3, 0x40, 0x10, 0x8e, 0x93, 0xd2, 0x38, 0xe3, 0xa6, 0xd0, 0x85, 0xc3, 0x0a, 0x84, 0x15, 0x82, 0x84, 0x7a, 0x00, 0x47, 0x0a, 0x07, 0xce, 0x45, 0x80, 0x54, 0x21, 0x2e, 0x16, 0x3f, 0x12, 0x17, 0x6b, 0xbb, 0x3b, 0x22, 0xab, 0xc6, 0x5e, 0xb3, 0xbb, 0x36, 0xed, 0x0b, 0x20, 0x8e, 0x3c, 0x16, 0xc7, 0x1e, - 0x39, 0xa2, 0xe4, 0x45, 0xd0, 0xae, 0x7f, 0x1a, 0x04, 0x5c, 0xa2, 0x99, 0x6f, 0xbe, 0x9f, 0xcc, - 0x78, 0x61, 0xc6, 0x57, 0xf8, 0x59, 0x2c, 0x34, 0x1a, 0x55, 0x69, 0x8e, 0x8b, 0x7a, 0xd9, 0xd7, + 0x39, 0xa2, 0xe4, 0x45, 0xd0, 0xae, 0x7f, 0x1a, 0x04, 0x5c, 0xac, 0x99, 0x6f, 0xbe, 0x1f, 0xcf, + 0x68, 0x61, 0xc6, 0x57, 0xf8, 0x59, 0x2c, 0x34, 0x1a, 0x55, 0x69, 0x8e, 0x8b, 0x7a, 0xd9, 0xd7, 0x49, 0xa9, 0x95, 0x55, 0xe4, 0xc8, 0x33, 0x92, 0x1e, 0xad, 0x97, 0xf3, 0x18, 0xc2, 0xb4, 0x6d, 0x09, 0x81, 0x3d, 0xc1, 0x2c, 0xa3, 0xc1, 0x2c, 0x38, 0x3e, 0x48, 0x7d, 0x3d, 0xff, 0x16, 0xc0, 0x9d, 0x8e, 0xf0, 0x41, 0xda, 0xd5, 0x1b, 0xb4, 0xcc, 0x0d, 0xc8, 0x33, 0x08, 0x3b, 0x1f, 0x2f, @@ -325,14 +325,14 @@ var fileDescriptor_abfe0b32f2a40f67 = []byte{ 0x30, 0x65, 0x6b, 0xa3, 0xb2, 0xf3, 0x42, 0x7d, 0x29, 0x32, 0x66, 0xe8, 0xfe, 0x6c, 0x74, 0x1c, 0x2d, 0x1f, 0xfc, 0xe3, 0x30, 0x7f, 0x9e, 0x20, 0x8d, 0x9c, 0xee, 0xb5, 0x93, 0x9d, 0x18, 0x72, 0x1f, 0x20, 0x47, 0x21, 0x59, 0x13, 0x34, 0xf6, 0x41, 0x13, 0x8f, 0xf8, 0x14, 0x0a, 0x63, 0xae, - 0x91, 0x59, 0x14, 0x34, 0x6c, 0xfe, 0x64, 0xdb, 0x92, 0xbb, 0x10, 0xf2, 0x15, 0xf2, 0x73, 0x53, - 0xe5, 0x74, 0xe2, 0xbf, 0x7e, 0xdf, 0x93, 0x04, 0x6e, 0x97, 0x1a, 0x6b, 0xa9, 0x2a, 0x93, 0xb5, - 0x4b, 0xb9, 0x4b, 0x81, 0x77, 0x38, 0xea, 0x46, 0xef, 0x9b, 0xc9, 0xa9, 0x20, 0x8f, 0xe0, 0x66, - 0x81, 0x17, 0x76, 0x97, 0x1b, 0x79, 0xee, 0xd4, 0xc1, 0x3d, 0xef, 0xf9, 0xab, 0x1f, 0x9b, 0x38, - 0xb8, 0xda, 0xc4, 0xc1, 0xaf, 0x4d, 0x1c, 0x7c, 0xdf, 0xc6, 0x83, 0xab, 0x6d, 0x3c, 0xf8, 0xb9, - 0x8d, 0x07, 0x1f, 0x1f, 0x7f, 0x92, 0x76, 0x55, 0x9d, 0x25, 0x5c, 0xe5, 0x8b, 0xe6, 0x4d, 0xfb, - 0xdf, 0x27, 0x85, 0x12, 0xb8, 0xb8, 0xb8, 0x7e, 0xe0, 0x6e, 0x4b, 0x73, 0xb6, 0xef, 0xdf, 0xf6, - 0xd3, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb7, 0xe8, 0xf3, 0x70, 0xff, 0x02, 0x00, 0x00, + 0x91, 0x59, 0x14, 0x34, 0x6c, 0x7e, 0xb2, 0x6d, 0xc9, 0x5d, 0x08, 0xf9, 0x0a, 0xf9, 0xb9, 0xa9, + 0x72, 0x3a, 0xf1, 0xa3, 0xbe, 0x27, 0x09, 0xdc, 0x2e, 0x35, 0xd6, 0x52, 0x55, 0x26, 0x6b, 0x97, + 0x72, 0x97, 0x02, 0x4f, 0x3b, 0xea, 0x46, 0xef, 0x9b, 0xc9, 0xa9, 0x20, 0x8f, 0xe0, 0x66, 0x81, + 0x17, 0x76, 0x97, 0x1b, 0x79, 0xee, 0xd4, 0xc1, 0x3d, 0xef, 0xf9, 0xab, 0x1f, 0x9b, 0x38, 0xb8, + 0xda, 0xc4, 0xc1, 0xaf, 0x4d, 0x1c, 0x7c, 0xdf, 0xc6, 0x83, 0xab, 0x6d, 0x3c, 0xf8, 0xb9, 0x8d, + 0x07, 0x1f, 0x1f, 0x7f, 0x92, 0x76, 0x55, 0x9d, 0x25, 0x5c, 0xe5, 0x8b, 0xe6, 0x4d, 0xfb, 0xef, + 0x93, 0x42, 0x09, 0x5c, 0x5c, 0x5c, 0x3f, 0x70, 0xb7, 0xa5, 0x39, 0xdb, 0xf7, 0x6f, 0xfb, 0xe9, + 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xee, 0x59, 0x24, 0x51, 0xff, 0x02, 0x00, 0x00, } func (m *Resource) Marshal() (dAtA []byte, err error) { @@ -1286,7 +1286,7 @@ func (m *Metadata) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Checksum", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowResource @@ -1296,25 +1296,23 @@ func (m *Metadata) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthResource } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthResource } if postIndex > l { return io.ErrUnexpectedEOF } - m.Checksum = append(m.Checksum[:0], dAtA[iNdEx:postIndex]...) - if m.Checksum == nil { - m.Checksum = []byte{} - } + m.Checksum = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 10: if wireType != 2 {