Skip to content

Commit

Permalink
Change Checksum to hex for resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Aug 3, 2022
1 parent a5b81e9 commit 8e1e130
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion services/diddoc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
// jsonpb Marshaller is deprecated, but is needed because there's only one way to proto
// marshal in combination with our proto generator version
"encoding/json"
"fmt"
"strings"

cheqd "github.com/cheqd/cheqd-node/x/cheqd/types"
Expand Down Expand Up @@ -88,7 +89,7 @@ func (ds DIDDocService) MarshallContentStream(contentStream protoiface.MessageV1
ResourceType: contentStream.Header.ResourceType,
MediaType: contentStream.Header.MediaType,
Created: contentStream.Header.Created,
Checksum: contentStream.Header.Checksum,
Checksum: fmt.Sprintf("%x", contentStream.Header.Checksum),
PreviousVersionId: contentStream.Header.PreviousVersionId,
NextVersionId: contentStream.Header.NextVersionId,
Data: contentStream.Data,
Expand Down
4 changes: 2 additions & 2 deletions services/request_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestDereferencing(t *testing.T) {
validVerificationMethod := validVerificationMethod()
validService := validService()
validResource := validResource()
validChecksum, _ := json.Marshal(validResource.Header.Checksum)
validChecksum := fmt.Sprintf("%x", validResource.Header.Checksum)
validData, _ := json.Marshal(validResource.Data)
validMetadata := validMetadata()
validFragmentMetadata := types.NewResolutionDidDocMetadata(validDid, validMetadata, []*resource.ResourceHeader{})
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestDereferencing(t *testing.T) {
ledgerService: NewMockLedgerService(validDIDDoc, validMetadata, validResource),
dereferencingType: types.DIDJSONLD,
didUrl: validDid + types.RESOURCE_PATH + validResourceId,
expectedContentStream: fmt.Sprintf("{\"@context\":[\"%s\"],\"collectionId\":\"%s\",\"id\":\"%s\",\"name\":\"%s\",\"resourceType\":\"%s\",\"mediaType\":\"%s\",\"checksum\":%s,\"data\":%s}",
expectedContentStream: fmt.Sprintf("{\"@context\":[\"%s\"],\"collectionId\":\"%s\",\"id\":\"%s\",\"name\":\"%s\",\"resourceType\":\"%s\",\"mediaType\":\"%s\",\"checksum\":\"%s\",\"data\":%s}",
types.DIDSchemaJSONLD, validResource.Header.CollectionId, validResource.Header.Id, validResource.Header.Name, validResource.Header.ResourceType, validResource.Header.MediaType, validChecksum, validData),
expectedMetadata: types.ResolutionDidDocMetadata{},
expectedError: "",
Expand Down
2 changes: 1 addition & 1 deletion types/dereferencing_content_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type DereferencedResource struct {
ResourceType string `json:"resourceType,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Created string `json:"created,omitempty"`
Checksum []byte `json:"checksum,omitempty"`
Checksum string `json:"checksum,omitempty"`
PreviousVersionId string `json:"previousVersionId,omitempty"`
NextVersionId string `json:"nextVersionId,omitempty"`
Data []byte `json:"data,omitempty"`
Expand Down
6 changes: 4 additions & 2 deletions types/did_doc_metadata.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"fmt"

cheqd "github.com/cheqd/cheqd-node/x/cheqd/types"
resource "github.com/cheqd/cheqd-node/x/resource/types"
)
Expand All @@ -19,7 +21,7 @@ type ResourcePreview struct {
ResourceType string `json:"resourceType,omitempty"`
MediaType string `json:"mediaType,omitempty"`
Created string `json:"created,omitempty"`
Checksum []byte `json:"checksum,omitempty"`
Checksum string `json:"checksum,omitempty"`
PreviousVersionId string `json:"previousVersionId,omitempty"`
NextVersionId string `json:"nextVersionId,omitempty"`
}
Expand All @@ -42,7 +44,7 @@ func NewResolutionDidDocMetadata(did string, metadata cheqd.Metadata, resources
r.ResourceType,
r.MediaType,
r.Created,
r.Checksum,
fmt.Sprintf("%x", r.Checksum),
r.PreviousVersionId,
r.NextVersionId,
}
Expand Down
3 changes: 2 additions & 1 deletion types/did_doc_metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"fmt"
"testing"

cheqd "github.com/cheqd/cheqd-node/x/cheqd/types"
Expand All @@ -27,7 +28,7 @@ func TestNewResolutionDidDocMetadata(t *testing.T) {
ResourceType: resourceHeader.ResourceType,
MediaType: resourceHeader.MediaType,
Created: resourceHeader.Created,
Checksum: resourceHeader.Checksum,
Checksum: fmt.Sprintf("%x", resourceHeader.Checksum),
PreviousVersionId: resourceHeader.PreviousVersionId,
NextVersionId: resourceHeader.NextVersionId,
}
Expand Down

0 comments on commit 8e1e130

Please sign in to comment.