Skip to content

Commit

Permalink
Added docs and fixed required fields for resolution (#437)
Browse files Browse the repository at this point in the history
* Added docs and fixed required fields for resolution

* Nicer lines
  • Loading branch information
andresuribe87 authored Jul 31, 2023
1 parent 8db407f commit d5c302a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
3 changes: 3 additions & 0 deletions did/ion/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -67,6 +68,8 @@ func TestResolveLongFormDID(t *testing.T) {
"recoveryCommitment": "EiBfOZdMtU6OBw8Pk879QtZ-2J-9FbbjSZyoaA_bqD4zhA",
"updateCommitment": "EiDKIkwqO69IPG3pOlHkdb86nYt0aNxSHZu2r-bhEznjdA"
}
},
"didResolutionMetadata": {
}
}`
assert.JSONEq(t, expectedResolutionResultJSON, string(jsonResolutionResult))
Expand Down
47 changes: 35 additions & 12 deletions did/resolution/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion did/web/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d5c302a

Please sign in to comment.