diff --git a/services/request_service.go b/services/request_service.go index 8c18bbbb..3b59c072 100644 --- a/services/request_service.go +++ b/services/request_service.go @@ -238,13 +238,13 @@ func (rs RequestService) dereferenceSecondary(did string, fragmentId string, did func (rs RequestService) ResolveMetadata(did string, metadata cheqdTypes.Metadata) (types.ResolutionDidDocMetadata, error) { if metadata.Resources == nil { - return types.NewResolutionDidDocMetadata(metadata, []*resourceTypes.ResourceHeader{}), nil + return types.NewResolutionDidDocMetadata(did, metadata, []*resourceTypes.ResourceHeader{}), nil } resources, err := rs.ledgerService.QueryCollectionResources(did) if err != nil { return types.ResolutionDidDocMetadata{}, err } - return types.NewResolutionDidDocMetadata(metadata, resources), nil + return types.NewResolutionDidDocMetadata(did, metadata, resources), nil } func createJsonResolution(didDoc string, metadata string, resolutionMetadata string) (string, error) { diff --git a/services/request_service_test.go b/services/request_service_test.go index 1f3c1c89..1fad69a1 100644 --- a/services/request_service_test.go +++ b/services/request_service_test.go @@ -137,7 +137,7 @@ func TestResolve(t *testing.T) { method: validMethod, namespace: validNamespace, expectedDID: validDIDDoc, - expectedMetadata: types.NewResolutionDidDocMetadata(validMetadata, []*resource.ResourceHeader{validResource.Header}), + expectedMetadata: types.NewResolutionDidDocMetadata(validDid, validMetadata, []*resource.ResourceHeader{validResource.Header}), expectedError: "", }, { @@ -224,7 +224,7 @@ func TestDereferencing(t *testing.T) { validChecksum, _ := json.Marshal(validResource.Header.Checksum) validData, _ := json.Marshal(validResource.Data) validMetadata := validMetadata() - validFragmentMetadata := types.NewResolutionDidDocMetadata(validMetadata, []*resource.ResourceHeader{}) + validFragmentMetadata := types.NewResolutionDidDocMetadata(validDid, validMetadata, []*resource.ResourceHeader{}) subtests := []struct { name string ledgerService MockLedgerService @@ -241,7 +241,7 @@ func TestDereferencing(t *testing.T) { didUrl: validDid, expectedContentStream: fmt.Sprintf("{\"@context\":[\"%s\"],\"id\":\"%s\",\"verificationMethod\":[{\"id\":\"%s\",\"type\":\"%s\",\"controller\":\"%s\",\"publicKeyJwk\":%s}],\"service\":[{\"id\":\"%s\",\"type\":\"%s\",\"serviceEndpoint\":\"%s\"}]}", types.DIDSchemaJSONLD, validDid, validVerificationMethod.Id, validVerificationMethod.Type, validVerificationMethod.Controller, validPubKeyJWK, validService.Id, validService.Type, validService.ServiceEndpoint), - expectedMetadata: types.NewResolutionDidDocMetadata(validMetadata, []*resource.ResourceHeader{validResource.Header}), + expectedMetadata: types.NewResolutionDidDocMetadata(validDid, validMetadata, []*resource.ResourceHeader{validResource.Header}), expectedError: "", }, { @@ -268,7 +268,7 @@ func TestDereferencing(t *testing.T) { name: "successful Primary dereferencing (resource)", ledgerService: NewMockLedgerService(validDIDDoc, validMetadata, validResource), dereferencingType: types.DIDJSONLD, - didUrl: validDid + "/resources/" + validResourceId, + 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}", types.DIDSchemaJSONLD, validResource.Header.CollectionId, validResource.Header.Id, validResource.Header.Name, validResource.Header.ResourceType, validResource.Header.MediaType, validChecksum, validData), expectedMetadata: types.ResolutionDidDocMetadata{}, @@ -310,7 +310,7 @@ func TestDereferencing(t *testing.T) { name: "resource not found", ledgerService: NewMockLedgerService(cheqd.Did{}, cheqd.Metadata{}, resource.Resource{}), dereferencingType: types.DIDJSONLD, - didUrl: validDid + "/resources/00000000-0000-0000-0000-000000000000", + didUrl: validDid + types.RESOURCE_PATH + "00000000-0000-0000-0000-000000000000", expectedMetadata: types.ResolutionDidDocMetadata{}, expectedError: types.DereferencingNotFound, }, diff --git a/types/constants.go b/types/constants.go index 535ef2a1..db344280 100644 --- a/types/constants.go +++ b/types/constants.go @@ -26,3 +26,7 @@ const ( const ( DIDSchemaJSONLD = "https://www.w3.org/ns/did/v1" ) + +const ( + RESOURCE_PATH = "/resources/" +) diff --git a/types/did_doc_metadata.go b/types/did_doc_metadata.go index 58681714..48e891d3 100644 --- a/types/did_doc_metadata.go +++ b/types/did_doc_metadata.go @@ -14,14 +14,14 @@ type ResolutionDidDocMetadata struct { } type ResourcePreview struct { - Id string `json:"id,omitempty"` + ResourceURI string `json:"resourceURI,omitempty"` Name string `json:"name,omitempty"` ResourceType string `json:"resourceType,omitempty"` MediaType string `json:"mediaType,omitempty"` Created string `json:"created,omitempty"` } -func NewResolutionDidDocMetadata(metadata cheqd.Metadata, resources []*resource.ResourceHeader) ResolutionDidDocMetadata { +func NewResolutionDidDocMetadata(did string, metadata cheqd.Metadata, resources []*resource.ResourceHeader) ResolutionDidDocMetadata { newMetadata := ResolutionDidDocMetadata{ metadata.Created, metadata.Updated, @@ -34,7 +34,7 @@ func NewResolutionDidDocMetadata(metadata cheqd.Metadata, resources []*resource. } for _, r := range resources { resourcePreview := ResourcePreview{ - r.Id, + did + RESOURCE_PATH + r.Id, r.Name, r.ResourceType, r.MediaType,