View Source DIDTools.Resolver (DIDTools v0.1.0)

Resolver for ATProto handles or DID. Following https://atproto.com/specs/handle spec.

Usage

iex> alias DIDTools.{Resolver, DID, Document}
iex> {:ok, did} = Resolver.did_by_handle("arathunku.com")
{:ok, %DID{did: "did:plc:yww4iq4ogs7f4bmqbiwfzbck", type: :plc, resolver: :dns}}
iex> {:ok, _doc} = DIDTools.Resolver.doc_by_did(did);
{:ok, %Document{
   did: did,
   doc: %{
     "@context" => ["https://www.w3.org/ns/did/v1",
      "https://w3id.org/security/multikey/v1",
      "https://w3id.org/security/suites/secp256k1-2019/v1"],
     "alsoKnownAs" => ["at://arathunku.com"],
     "id" => "did:plc:yww4iq4ogs7f4bmqbiwfzbck",
     "service" => [
       %{
         "id" => "#atproto_pds",
         "serviceEndpoint" => "https://enoki.us-east.host.bsky.network",
         "type" => "AtprotoPersonalDataServer"
       }
     ],
     "verificationMethod" => [
       %{
         "controller" => "did:plc:yww4iq4ogs7f4bmqbiwfzbck",
         "id" => "did:plc:yww4iq4ogs7f4bmqbiwfzbck#atproto",
         "publicKeyMultibase" => "zQ3shQ81CThGCgKCogk2Ci3DpHwNJZRjQK1ii2LfWtEDPw37G",
         "type" => "Multikey"
       }
     ]
   }
 }}

iex> alias DIDTools.{Resolver, DID, Document}
iex> Resolver.doc_by_did("did:web:feed.atproto.blue")
{:ok, %Document{
   did: %DID{
     did: "did:web:feed.atproto.blue",
     type: :web,
     resolver: nil
   },
   doc: %{
     "@context" => ["https://www.w3.org/ns/did/v1"],
     "id" => "did:web:feed.atproto.blue",
     "service" => [
       %{
         "id" => "#bsky_fg",
         "serviceEndpoint" => "https://feed.atproto.blue",
         "type" => "BskyFeedGenerator"
       }
     ]
   }
 }}

Summary

Functions

Get DID by handle. It will first try to resolve by DNS, then by HTTP.

Fetches a DID document by DID string or DID struct.

Functions

@spec did_by_handle(String.t()) :: {:ok, DIDTools.DID.t()} | {:error, {atom(), any()}}

Get DID by handle. It will first try to resolve by DNS, then by HTTP.

DNS resolve expects to find a TXT record with the key _atproto and a value starting with did=. Right now defaults to Cloudflare DNS nameservers, but alternative nameserver can be configured. (config :did_tools, dns_options: [nameservers: [{{8, 8, 8, 8}, 53}, {{8, 8, 4, 4}, 53}]).

HTTP resolve expects to receive a plain text content with a DID string at https://<handle>/.well-known/atproto-did.

Timeouts and max redirects are very limited (within ~5s and 5 redirects).

@spec doc_by_did(String.t()) ::
  {:ok, DIDTools.Document.t()} | {:error, {atom(), any()}}
@spec doc_by_did(DIDTools.DID.t()) ::
  {:ok, DIDTools.Document.t()} | {:error, {atom(), any()}}

Fetches a DID document by DID string or DID struct.

See DIDTools.Document for the document structure and available methods.