Exosphere.ATProto.Identity.DID (Exosphere v0.2.0)

Copy Markdown View Source

DID (Decentralized Identifier) resolution for Exosphere.ATProto.

Exosphere.ATProto supports two DID methods:

  • did:plc - Bluesky's novel DID method with key rotation and recovery
  • did:web - W3C standard based on HTTPS/DNS

Examples

# Resolve a did:plc
{:ok, doc} = Exosphere.ATProto.Identity.DID.resolve("did:plc:z72i7hdynmk6r22z27h6tvur")

# Resolve a did:web
{:ok, doc} = Exosphere.ATProto.Identity.DID.resolve("did:web:example.com")

# Extract PDS endpoint from DID document
{:ok, pds_url} = Exosphere.ATProto.Identity.DID.get_pds_endpoint(doc)

# Extract signing key
{:ok, public_key, curve} = Exosphere.ATProto.Identity.DID.get_signing_key(doc)

Summary

Functions

Extract the handle (alsoKnownAs) from a DID Document.

Extract the PDS (Personal Data Server) endpoint from a DID Document.

Extract the Exosphere.ATProto signing key from a DID Document.

Parse the DID method from a DID string.

Resolve a DID to its DID Document.

Validate DID syntax according to Exosphere.ATProto rules.

Types

did()

@type did() :: String.t()

resolve_opts()

@type resolve_opts() :: [timeout: pos_integer(), http_client: module()]

Functions

get_handle(doc)

@spec get_handle(Exosphere.ATProto.Identity.Document.t()) ::
  {:ok, String.t()} | {:error, :not_found}

Extract the handle (alsoKnownAs) from a DID Document.

Returns the first at:// URI from the alsoKnownAs array.

Examples

iex> Exosphere.ATProto.Identity.DID.get_handle(doc)
{:ok, "alice.example.com"}

get_pds_endpoint(doc)

@spec get_pds_endpoint(Exosphere.ATProto.Identity.Document.t()) ::
  {:ok, String.t()} | {:error, :not_found}

Extract the PDS (Personal Data Server) endpoint from a DID Document.

Looks for a service with id #atproto_pds and type AtprotoPersonalDataServer.

Examples

iex> Exosphere.ATProto.Identity.DID.get_pds_endpoint(doc)
{:ok, "https://pds.example.com"}

get_signing_key(doc)

@spec get_signing_key(Exosphere.ATProto.Identity.Document.t()) ::
  {:ok, binary(), atom()} | {:error, :not_found}

Extract the Exosphere.ATProto signing key from a DID Document.

Looks for a verification method with id #atproto and extracts the public key.

Examples

iex> Exosphere.ATProto.Identity.DID.get_signing_key(doc)
{:ok, <<public_key_bytes>>, :secp256k1}

method(arg1)

@spec method(did()) :: {:ok, atom()} | {:error, :invalid_did}

Parse the DID method from a DID string.

Examples

iex> Exosphere.ATProto.Identity.DID.method("did:plc:abc123")
{:ok, :plc}

iex> Exosphere.ATProto.Identity.DID.method("did:web:example.com")
{:ok, :web}

resolve(did, opts \\ [])

@spec resolve(did(), resolve_opts()) ::
  {:ok, Exosphere.ATProto.Identity.Document.t()} | {:error, term()}

Resolve a DID to its DID Document.

Supports did:plc and did:web methods.

Options

  • :timeout - HTTP request timeout in milliseconds (default: 10_000)

Examples

iex> Exosphere.ATProto.Identity.DID.resolve("did:plc:z72i7hdynmk6r22z27h6tvur")
{:ok, %Document{...}}

iex> Exosphere.ATProto.Identity.DID.resolve("did:web:example.com")
{:ok, %Document{...}}

iex> Exosphere.ATProto.Identity.DID.resolve("did:unsupported:xyz")
{:error, :unsupported_did_method}

valid?(did)

@spec valid?(String.t()) :: boolean()

Validate DID syntax according to Exosphere.ATProto rules.

Examples

iex> Exosphere.ATProto.Identity.DID.valid?("did:plc:z72i7hdynmk6r22z27h6tvur")
true

iex> Exosphere.ATProto.Identity.DID.valid?("not-a-did")
false