TBD54566975 / web5-spec

https://tbd54566975.github.io/sdk-report-runner/
Apache License 2.0
6 stars 6 forks source link

Question about DID Resolution Test Vectors #76

Closed frankhinek closed 6 months ago

frankhinek commented 7 months ago

resolve function test vectors for did:jwk and did:web have been committed to the sdk-development repo and others will be added fairly soon. There are inconsistencies in the existing two vectors that would be good to resolve before we modify the SDKs that are consuming these vectors (and cover more DID methods).

Per the W3C DID spec, the resolve function is expected to return:

resolve(did, resolutionOptions) →
   « didResolutionMetadata, didDocument, didDocumentMetadata »

Section 7.1, DID Resolution of the DID spec states:

didResolutionMetadata A metadata structure consisting of values relating to the results of the DID resolution process which typically changes between invocations of the resolve and resolveRepresentation functions, as it represents data about the resolution process itself. This structure is REQUIRED, and in the case of an error in the resolution process, this MUST NOT be empty. This metadata is defined by 7.1.2 DID Resolution Metadata. If resolveRepresentation was called, this structure MUST contain a contentType property containing the Media Type of the representation found in the didDocumentStream. If the resolution is not successful, this structure MUST contain an error property describing the error.

didDocument If the resolution is successful, and if the resolve function was called, this MUST be a DID document abstract data model (a map) as described in 4. Data Model that is capable of being transformed into a conforming DID Document (representation), using the production rules specified by the representation. The value of id in the resolved DID document MUST match the DID that was resolved. If the resolution is unsuccessful, this value MUST be empty.

didDocumentStream If the resolution is successful, and if the resolveRepresentation function was called, this MUST be a byte stream of the resolved DID document in one of the conformant representations. The byte stream might then be parsed by the caller of the resolveRepresentation function into a data model, which can in turn be validated and processed. If the resolution is unsuccessful, this value MUST be an empty stream.

didDocumentMetadata If the resolution is successful, this MUST be a metadata structure. This structure contains metadata about the DID document contained in the didDocument property. This metadata typically does not change between invocations of the resolve and resolveRepresentation functions unless the DID document changes, as it represents metadata about the DID document. If the resolution is unsuccessful, this output MUST be an empty metadata structure. Properties defined by this specification are in 7.1.3 DID Document Metadata.

Given that it seems that, in the event of an error, the DID Resolution Result of the resolve function should look something like this:

{
    "didResolutionMetadata": {
        "error": "invalidDid"
    },
    "didDocument": {},
    "didDocumentMetadata": {}
}

Referencing the relevant excerpts from the DID spec:

Given the use of the terminology "empty" and "structure" it would seem that an empty object ({}) is the most appropriate value to select.

frankhinek commented 7 months ago

@andresuribe87 pointed out on Discord that there was a recent discussion on this topic.

andresuribe87 commented 7 months ago

I think the proposal makes sense. Crafting a PR to correct the test-vectors to have { }.

mistermoe commented 7 months ago

Contrary to didDocumentMetadata where the spec text is clear about empty metadata structure, the spec text has left room for interpretation wrt how to represent empty for didDocument

I tend to lean towards using null over an empty object for didDocument because it seems more straightforward to check for null vs. checking to make sure an "object" is empty across languages. Depending on the language, when parsed, "empty object" can be represented as:

mistermoe commented 6 months ago

@frankhinek @decentralgabe

didDocument: "If the resolution is unsuccessful, this value MUST be empty."

looks like the draft spec for did resolution also considers this to be null. Reference

image
andresuribe87 commented 6 months ago

For the abundance of clarity, the suggestion is to:

Is this correct?

mistermoe commented 6 months ago

correct