diff --git a/did/ion/did_test.go b/did/ion/did_test.go index e941cd3c..57bece32 100644 --- a/did/ion/did_test.go +++ b/did/ion/did_test.go @@ -12,6 +12,7 @@ import ( ) // Test vector from https://identity.foundation/sidetree/spec/#long-form-response, adjusted by replacing s/sidetree/ion/ +// and adding a `didResolutionMetadata` property (this is required by https://www.w3.org/TR/did-core/#did-resolution). func TestResolveLongFormDID(t *testing.T) { longFormDID := `did:ion:EiDyOQbbZAa3aiRzeCkV7LOx3SERjjH93EXoIM3UoN4oWg:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJwdWJsaWNLZXlNb2RlbDFJZCIsInB1YmxpY0tleUp3ayI6eyJjcnYiOiJzZWNwMjU2azEiLCJrdHkiOiJFQyIsIngiOiJ0WFNLQl9ydWJYUzdzQ2pYcXVwVkpFelRjVzNNc2ptRXZxMVlwWG45NlpnIiwieSI6ImRPaWNYcWJqRnhvR0otSzAtR0oxa0hZSnFpY19EX09NdVV3a1E3T2w2bmsifSwicHVycG9zZXMiOlsiYXV0aGVudGljYXRpb24iLCJrZXlBZ3JlZW1lbnQiXSwidHlwZSI6IkVjZHNhU2VjcDI1NmsxVmVyaWZpY2F0aW9uS2V5MjAxOSJ9XSwic2VydmljZXMiOlt7ImlkIjoic2VydmljZTFJZCIsInNlcnZpY2VFbmRwb2ludCI6Imh0dHA6Ly93d3cuc2VydmljZTEuY29tIiwidHlwZSI6InNlcnZpY2UxVHlwZSJ9XX19XSwidXBkYXRlQ29tbWl0bWVudCI6IkVpREtJa3dxTzY5SVBHM3BPbEhrZGI4Nm5ZdDBhTnhTSFp1MnItYmhFem5qZEEifSwic3VmZml4RGF0YSI6eyJkZWx0YUhhc2giOiJFaUNmRFdSbllsY0Q5RUdBM2RfNVoxQUh1LWlZcU1iSjluZmlxZHo1UzhWRGJnIiwicmVjb3ZlcnlDb21taXRtZW50IjoiRWlCZk9aZE10VTZPQnc4UGs4NzlRdFotMkotOUZiYmpTWnlvYUFfYnFENHpoQSJ9fQ` resolver, err := NewIONResolver(http.DefaultClient, "https://example.com") @@ -67,6 +68,8 @@ func TestResolveLongFormDID(t *testing.T) { "recoveryCommitment": "EiBfOZdMtU6OBw8Pk879QtZ-2J-9FbbjSZyoaA_bqD4zhA", "updateCommitment": "EiDKIkwqO69IPG3pOlHkdb86nYt0aNxSHZu2r-bhEznjdA" } + }, + "didResolutionMetadata": { } }` assert.JSONEq(t, expectedResolutionResultJSON, string(jsonResolutionResult)) diff --git a/did/resolution/model.go b/did/resolution/model.go index 65741d8c..b964636d 100644 --- a/did/resolution/model.go +++ b/did/resolution/model.go @@ -10,7 +10,7 @@ import ( // Result encapsulates the tuple of a DID resolution https://www.w3.org/TR/did-core/#did-resolution type Result struct { Context string `json:"@context,omitempty"` - *Metadata `json:"didResolutionMetadata,omitempty"` + Metadata `json:"didResolutionMetadata"` did.Document `json:"didDocument,omitempty"` *DocumentMetadata `json:"didDocumentMetadata,omitempty"` } @@ -23,22 +23,45 @@ func (r *Result) IsEmpty() bool { } type Method struct { - Published bool `json:"published"` + // The `method` property in https://identity.foundation/sidetree/spec/#did-resolver-output + Published bool `json:"published"` + + // The `recoveryCommitment` property in https://identity.foundation/sidetree/spec/#did-resolver-output RecoveryCommitment string `json:"recoveryCommitment,omitempty"` - UpdateCommitment string `json:"updateCommitment,omitempty"` + + // The `updateCommitment` property in https://identity.foundation/sidetree/spec/#did-resolver-output + UpdateCommitment string `json:"updateCommitment,omitempty"` } // DocumentMetadata https://www.w3.org/TR/did-core/#did-document-metadata type DocumentMetadata struct { - Created string `json:"created,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z"` - Updated string `json:"updated,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z"` - Deactivated bool `json:"deactivated,omitempty"` - NextUpdate string `json:"nextUpdate,omitempty"` - VersionID string `json:"versionId,omitempty"` - NextVersionID string `json:"nextVersionId,omitempty"` - EquivalentID []string `json:"equivalentId,omitempty"` - CanonicalID string `json:"canonicalId,omitempty"` - Method Method `json:"method,omitempty"` + // See `created` in https://www.w3.org/TR/did-core/#did-document-metadata + Created string `json:"created,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z"` + + // See `updated` in https://www.w3.org/TR/did-core/#did-document-metadata + Updated string `json:"updated,omitempty" validate:"omitempty,datetime=2006-01-02T15:04:05Z"` + + // See `deactivated` in https://www.w3.org/TR/did-core/#did-document-metadata + Deactivated bool `json:"deactivated,omitempty"` + + // See `nextUpdate` in https://www.w3.org/TR/did-core/#did-document-metadata + NextUpdate string `json:"nextUpdate,omitempty"` + + // See `versionId` in https://www.w3.org/TR/did-core/#did-document-metadata + VersionID string `json:"versionId,omitempty"` + + // See `nextVersionId` in https://www.w3.org/TR/did-core/#did-document-metadata + NextVersionID string `json:"nextVersionId,omitempty"` + + // See `equivalentId` in https://www.w3.org/TR/did-core/#did-document-metadata + EquivalentID []string `json:"equivalentId,omitempty"` + + // See `canonicalId` in https://www.w3.org/TR/did-core/#did-document-metadata + CanonicalID string `json:"canonicalId,omitempty"` + + // Optional information that is specific to the DID Method of the DID Document resolved. Populated only + // for sidetree based did methods (e.g. ION), as described in https://identity.foundation/sidetree/spec/#did-resolver-output + Method Method `json:"method,omitempty"` } func (s *DocumentMetadata) IsValid() bool { diff --git a/did/web/resolver.go b/did/web/resolver.go index 70411a49..70050e64 100644 --- a/did/web/resolver.go +++ b/did/web/resolver.go @@ -28,7 +28,7 @@ func (Resolver) Resolve(ctx context.Context, id string, _ ...resolution.Option) didWeb := DIDWeb(id) doc, err := didWeb.Resolve(ctx) if err != nil { - return nil, errors.Wrapf(err, "cresolving did:web DID: %s", id) + return nil, errors.Wrapf(err, "resolving did:web DID: %s", id) } return &resolution.Result{Document: *doc}, nil }