Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JavaScript SDK for the Universal Resolver #28

Open
thomas-tran opened this issue Dec 6, 2018 · 7 comments
Open

Add JavaScript SDK for the Universal Resolver #28

thomas-tran opened this issue Dec 6, 2018 · 7 comments

Comments

@thomas-tran
Copy link
Contributor

thomas-tran commented Dec 6, 2018

As noted in the comments, there are SDKs for python and java here

@OR13
Copy link
Contributor

OR13 commented Aug 12, 2019

Can you be more specific? This repo contains docker examples, are you looking for a node-js sdk for the universal resolver http interface?

@OR13
Copy link
Contributor

OR13 commented Aug 12, 2019

@peacekeeper I'd be happy to provide a js sdk for the public http interface if that would help resolve this issue, its something I would find very useful generally.

@peacekeeper
Copy link
Member

@OR13 yes that would be great! This could be added here in the directory structure:
https://github.com/decentralized-identity/universal-resolver/tree/master/resolver

The idea has always been for DIF to develop DID Resolvers and clients in multiple languages.

@OR13
Copy link
Contributor

OR13 commented Aug 14, 2019

I will open a PR, it might be rough, but it will work in both the browser and nodejs... it will be based on: https://github.com/transmute-industries/PROPOSAL-OpenPgpSignature2019/blob/master/src/universalResolver.js

@OR13 OR13 changed the title Where is the repository for nodejs Add JavaScript SDK for the Universal Resolver Aug 14, 2019
@peacekeeper
Copy link
Member

We revisited this on the 23 Jun 2021 Universal Resolver call.

Even though there hasn't been any activity on this issue for a while, this still sounds useful; is anyone aware of a JS library (NPM package?) that resolves DIDs via the Universal Resolver HTTPS interface? @thomas-tran @OR13 ?

@OR13
Copy link
Contributor

OR13 commented Jun 23, 2021

I think this would be helpful, particularly to help test resolution and dereferencing.

We would need code that maps a DID_URL and RESOLUTION_OPTIONS to an http request...

We've avoided this so far, by just using JSON-LD Document Loaders....

You can consider the use of a document loader to be equivalent to RESOLUTION_OPTIONS defaulted to application/did+ld+json:

import { contexts } from "./contexts";

import axios from "axios";

import * as ed25519 from "@transmute/did-key-ed25519";
import * as bls12381 from "@transmute/did-key-bls12381";

export const documentLoader = async (iri) => {
  if (contexts[iri]) {
    return {
      documentUrl: iri,
      document: contexts[iri],
    };
  }

  if (iri.includes("did:web:")) {
    let url = `https://did-web.web.app/api/v1/identifiers/${iri}`;
    const resp = await axios.get(url);
    return {
      documentUrl: iri,
      document: resp.data,
    };
  }

  if (iri.startsWith("did:key:z6M")) {
    const { didDocument } = await ed25519.driver.resolve(iri, {
      accept: "application/did+ld+json",
    });
    return {
      documentUrl: iri,
      document: didDocument,
    };
  }

  if (iri.startsWith("did:key:zUC")) {
    const { didDocument } = await bls12381.driver.resolve(iri, {
      accept: "application/did+ld+json",
    });
    return {
      documentUrl: iri,
      document: didDocument,
    };
  }

  if (
    iri.startsWith(
      "https://w3c-ccg.github.io/vc-http-api/fixtures/revocationList.json"
    )
  ) {
    const resp = await axios.get(iri);

    return {
      documentUrl: iri,
      document: resp.data,
    };
  }

  if (iri.startsWith("did:trustbloc")) {
    const url = `https://resolver.sandbox.trustbloc.dev/1.0/identifiers/${iri}`;
    const resp = await axios.get(url);
    return {
      documentUrl: iri,
      document: resp.data.didDocument,
    };
  }

  if (iri.startsWith("https://issuer.sandbox.trustbloc.dev/status/1")) {
    const resp = await axios.get(iri);
    return {
      documentUrl: iri,
      document: resp.data,
    };
  }

  if (iri.includes("did:")) {
    const url = `https://dev.uniresolver.io/1.0/identifiers/${iri}`;
    const resp = await axios.get(url);
    return {
      documentUrl: iri,
      document: resp.data.didDocument,
    };
  }

  try {
    const resp = await axios({
      method: "get",
      url: iri,
      headers: {
        // Authorization: `Bearer ${token}`,
        accept: "application/json",
      },
    });
    return {
      documentUrl: iri,
      document: resp.data,
    };
  } catch (e) {
    console.error(e);
    // error will be thrown
  }

  console.error("Unsupporteed iri " + iri);
  throw new Error("Unsupporteed iri " + iri);
};

There remain questions about whether document loaders should do "resolution" or "dereferencing" which would impact the return type that the universal resolver would send, or would require "framing" on the client...

See digitalbazaar/jsonld-signatures#141

@peacekeeper
Copy link
Member

We discussed this on the 29 Sep 2021 Universal Resolver work item call. A JavaScript client DID resolver would definitely be useful, and it is also clearly useful for JSON-LD document loaders. Not sure however if it makes sense to keep this issue here open.

If anyone is interested in working on such a JavaScript library as a standalone module, then a new repository and work item should be created for this, and this issue here should probably be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants