DidWeb (did_web v0.2.1)

This module contains functions to resolve a Web DID.

Summary

Functions

Resolves the URL from a Web DID, gets the DID document from the URL, and validates the returned DID document.

Resolve the URL of a Web DID.

Functions

Link to this function

resolve(did, options \\ [doh: :none])

(since 0.1.0)
@spec resolve(did :: String.t(), options :: keyword()) ::
  {:ok, map()}
  | {:error, {:options_error, String.t()}}
  | {:error, {:input_error, String.t()}}
  | {:error, {:dns_error, String.t()}}
  | {:error, {:http_error, String.t()}}
  | {:error, {:json_error, String.t()}}
  | {:error, {:validation_error, String.t()}}

Resolves the URL from a Web DID, gets the DID document from the URL, and validates the returned DID document.

Returns the resolved DID document or an error.

Options

  • :doh: The Web DID specification recommends using DNS over HTTPS (DoH). DoH is not enabled by default, and currently only the Cloudflare DoH service is supported. In case you want to use a different DoH service, you can use the resolve_url/1 function to do the HTTP request yourself.

    Possible values: :none (default), :cloudflare

Validation

The "id" of the resolved DID document is validated to be equal to the provided Web DID.

Examples

# Default HTTPS request

> DidWeb.resolve("did:web:example.com")
{:ok, did_document}

# Request using Cloudflares DNS over HTTPS service

> DidWeb.resolve("did:web:example.com", doh: :cloudflare)
{:ok, did_document}
Link to this function

resolve_url(did)

(since 0.1.0)
@spec resolve_url(did :: String.t()) ::
  {:ok, URI.t()} | {:error, {:input_error, String.t()}}

Resolve the URL of a Web DID.

Returns the resolved URL or an error.

Examples

iex> DidWeb.resolve_url("did:web:example.com")
{:ok, %URI{scheme: "https", authority: "example.com", host: "example.com", path: "/.well-known/did.json", port: 443}}

iex> DidWeb.resolve_url("did:web:example.com%3A3000:some:path")
{:ok, %URI{scheme: "https", authority: "example.com:3000", host: "example.com", path: "/some/path/did.json", port: 3000}}

iex> DidWeb.resolve_url("did:web:notaurl")
{:error, {:input_error, "Not a valid URL: https://notaurl"}}