decentralized-identity / did-resolver

Universal did-resolver for javascript environments
Apache License 2.0
216 stars 44 forks source link

[proposal] Allow query of a key fragment as a document #141

Open F-Node-Karlsruhe opened 2 years ago

F-Node-Karlsruhe commented 2 years ago

Is your feature request related to a problem? Please describe. I'm currently using the web-did-resolver in a custom document loader and it works very well, but i still have to query key fragments separately like so:

  const [did, keyFragment] = url.split('#')

  // fetch document
  const didDocument: any = (await getResolver().resolve(url)).didDocument

  // if a keyFragment of the DID document is queried
  if (keyFragment && didDocument) {

      // TODO allow query of other fields than verification method as well
      const keyFragmentDoc: any | undefined = didDocument.verificationMethod.filter(function(method: any) {
                                                                      return method.id === url || method.id === verificationMethod;
                                                                  })[0];

      if (!keyFragmentDoc)
          throw new jsonldSignatures.VerificationError(
                      new Error(`${verificationMethod} is an unknown key fragment for ${did}`)
                      );

      return {
          contextUrl: null,
          documentUrl: url,
          // deliver keyFragment with the DID doc context
          document: Object.assign(verificationMethodDoc, {'@context': didDocument['@context']}),
      };

  }

  return {
      contextUrl: null,
      documentUrl: url,
      document: didDocument,
  };

Describe the solution you'd like If the key fragment is specified the resolver should not return the DID document, but the key fragment document. (See code above)

Describe alternatives you've considered See code above

Moved here from https://github.com/decentralized-identity/web-did-resolver/issues/121

peacekeeper commented 2 years ago

I agree this would be a useful feature. This is part of a bigger concept called DID URL Dereferencing, which is partially explained in the DID Core spec (see here), and partially in the DID Resolution spec (see here). There are also some test cases in the DID Resolution test suite (see here).

There are some things to consider, e.g. the representation of the DID document (JSON-LD or JSON or CBOR etc.) and relative references. In general URI architecture, dereferencing a fragment depends not on the URI scheme (i.e. "did:"), but on the content type of the deferenced primary resource (i.e. the DID document).

Anyway, this is just some background information, and not all the details are "officially" specified yet. In general, +1 to supporting the dereferencing of fragments in DID resolution libraries like this one.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.