w3c-ccg / did-spec

Please see README.md for latest version being developed by W3C DID WG.
https://w3c.github.io/did-core/
Other
124 stars 45 forks source link

It would be useful to have `services` as a mapping instead of an `array` #224

Closed aaitor closed 5 years ago

aaitor commented 5 years ago

Currently, in the DID spec the services entry included in the DID Document is an array. An array doesn't enforce position so when you use a DID Document with multiple services, to search a specific subentry of the different services included is necessary to scan the complete array.

Typically when DID Documents are used to persist information in off-chain systems, modeling allowing to retrieve a specific service by a key or index would be recommended to search inside a specific subtree of the DID Document & retrieve specific service information in a more efficient way.

From JSON-LD spec:

JSON-LD introduces the notion of index maps that can be used to structure data into a form that is more efficient to access. The data indexing feature allows an author to structure data using a simple key-value map where the keys do not map to IRIs. This enables direct access to data instead of having to scan an array in search of a specific item. 

https://json-ld.org/spec/latest/json-ld/#data-indexing

For implementation purposes, only would be necessary to change the services to be a mapping or dict instead of an array:

{
    "@context": "https://w3id.org/did/v1",
    "id": "did:example:123456789abcdefghi",
    "authentication": [{
        "id": "did:example:123456789abcdefghi#keys-1",
        "type": "RsaVerificationKey2018",
        "controller": "did:example:123456789abcdefghi",
        "publicKeyPem": "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n"
    }],
    "service": {
        "myServiceId1": {
            "type": "VerifiableCredentialService",
            "serviceEndpoint": "https://example.com/vc/"
        },
        "myServiceId2": {
            "type": "VerifiableCredentialService2",
            "serviceEndpoint": "https://example2.com/vc/"
        }
    }
}
peacekeeper commented 5 years ago

Why wouldn't you just have ids for each service, i.e.:

    "service": [
        {
            "id": "did:example:123456789abcdefghi#myServiceId1",
            "type": "VerifiableCredentialService",
            "serviceEndpoint": "https://example.com/vc/"
        }, {
            "id": "did:example:123456789abcdefghi#myServiceId2",
            "type": "VerifiableCredentialService2",
            "serviceEndpoint": "https://example2.com/vc/"
        }
    ]

This should also be easy to use with a standard JSON-LD / RDF processor (and be compatible with the service matrix parameter).

aaitor commented 5 years ago

Hi @peacekeeper , yep we are using already that. But for finding a specific entry of the services array it would be necessary to read the elements of the array matching the id.

For example, if you persist the DID Document in a datastore (search engine or nosql like Elastic or Mongo) is not possible to run efficient queries to find a specific entry unless.

In the services case, where different kind of services can be provided by the same entity, it would be quite interesting to provide a way to find specific services. If the DID Document are going to be stored off-chain mainly, and especially when you have a lot of different DID Documents and services, search and retrieve specific information efficiently is a nice feature.

jandrieu commented 5 years ago

Closing because we've moved it to the DID WG did-spec repo. https://github.com/w3c/did-spec