Skip to content

Commit

Permalink
Add ResourceURI to DID Doc metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Jul 26, 2022
1 parent b6b2fe4 commit 1fc1674
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions services/request_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions services/request_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
},
{
Expand Down Expand Up @@ -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
Expand All @@ -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: "",
},
{
Expand All @@ -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{},
Expand Down Expand Up @@ -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,
},
Expand Down
4 changes: 4 additions & 0 deletions types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ const (
const (
DIDSchemaJSONLD = "https://www.w3.org/ns/did/v1"
)

const (
RESOURCE_PATH = "/resources/"
)
6 changes: 3 additions & 3 deletions types/did_doc_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 1fc1674

Please sign in to comment.