Atex.DID.Document.Service (atex v0.9.1)

View Source

Struct and schema for a service entry in a DID document.

Each service entry describes a network endpoint associated with the DID subject. In atproto, the most relevant service is the PDS (Personal Data Server), identified by the #atproto_pds fragment and type "AtprotoPersonalDataServer".

Fields

  • :id - URI identifying the service, typically a DID fragment (e.g. "#atproto_pds" or the fully-qualified form "did:plc:abc123#atproto_pds").
  • :type - Service type string or list of type strings.
  • :service_endpoint - The endpoint URI, a map of URIs, or a list of either.

Summary

Types

A service endpoint: a URI string, a map of URI strings, or a list of either.

t()

Functions

Validates and builds a Service struct from a map (snake_case or camelCase keys).

Converts a Service struct to a camelCase map suitable for JSON serialisation.

Types

endpoint()

@type endpoint() ::
  String.t()
  | %{required(String.t()) => String.t()}
  | [String.t() | %{required(String.t()) => String.t()}]

A service endpoint: a URI string, a map of URI strings, or a list of either.

t()

@type t() :: %Atex.DID.Document.Service{
  id: String.t(),
  service_endpoint: endpoint(),
  type: String.t() | [String.t()]
}

Functions

get_schema(atom)

new(map)

@spec new(map()) :: {:ok, t()} | {:error, Peri.Error.t()}

Validates and builds a Service struct from a map (snake_case or camelCase keys).

Returns {:ok, t()} on success, or {:error, Peri.Error.t()} on validation failure.

Examples

iex> Atex.DID.Document.Service.new(%{
...>   "id" => "#atproto_pds",
...>   "type" => "AtprotoPersonalDataServer",
...>   "serviceEndpoint" => "https://pds.example.com"
...> })
{:ok, %Atex.DID.Document.Service{
  id: "#atproto_pds",
  type: "AtprotoPersonalDataServer",
  service_endpoint: "https://pds.example.com"
}}

schema(data)

schema!(data)

to_json(service)

@spec to_json(t()) :: map()

Converts a Service struct to a camelCase map suitable for JSON serialisation.

Examples

iex> svc = %Atex.DID.Document.Service{
...>   id: "#atproto_pds",
...>   type: "AtprotoPersonalDataServer",
...>   service_endpoint: "https://pds.example.com"
...> }
iex> Atex.DID.Document.Service.to_json(svc)
%{
  "id" => "#atproto_pds",
  "type" => "AtprotoPersonalDataServer",
  "serviceEndpoint" => "https://pds.example.com"
}