An Elixir toolkit for the AT Protocol. hexdocs.pm/atex
elixir bluesky atproto decentralization
25
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs(identity): add moduledoc and resolve/2 doc to IdentityResolver

+36
+36
lib/atex/identity_resolver.ex
··· 1 1 defmodule Atex.IdentityResolver do 2 + @moduledoc """ 3 + Resolves AT Protocol identifiers (DIDs and handles) to `Atex.IdentityResolver.Identity` structs. 4 + 5 + Resolution results are cached in `Atex.IdentityResolver.Cache` (ETS) to avoid 6 + repeated network calls. Handle resolution strategy is compile-time configurable: 7 + 8 + config :atex, handle_resolver_strategy: :dns_first # default: :dns_first 9 + 10 + ## Examples 11 + 12 + {:ok, identity} = Atex.IdentityResolver.resolve("user.bsky.social") 13 + {:ok, identity} = Atex.IdentityResolver.resolve("did:plc:abc123") 14 + 15 + """ 16 + 2 17 alias Atex.IdentityResolver.{Cache, DID, Handle, Identity} 3 18 alias Atex.DID.Document, as: DIDDocument 4 19 ··· 7 22 8 23 # TODO: simplify errors 9 24 25 + @doc """ 26 + Resolve a DID or handle to an `Atex.IdentityResolver.Identity` struct. 27 + 28 + For a DID, resolves the DID document and optionally cross-checks the handle 29 + declared in it. For a handle, resolves to a DID via DNS or HTTP, then fetches 30 + and validates the DID document. 31 + 32 + Results are cached. Pass `skip_cache: true` to force a fresh resolution. 33 + 34 + ## Parameters 35 + 36 + - `identifier` - A DID string (e.g., `"did:plc:abc123"`) or a handle (e.g., `"user.bsky.social"`) 37 + - `opts` - Keyword options: 38 + - `:skip_cache` - If `true`, bypass the cache (default: `false`) 39 + 40 + ## Returns 41 + 42 + - `{:ok, identity}` - Successfully resolved identity 43 + - `{:error, :handle_mismatch}` - Handle in DID document does not match resolved handle 44 + - `{:error, reason}` - Resolution or network failure 45 + """ 10 46 @spec resolve(String.t(), list(options())) :: {:ok, Identity.t()} | {:error, any()} 11 47 def resolve(identifier, opts \\ []) do 12 48 opts = Keyword.validate!(opts, skip_cache: false)