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

View Source

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

Internally, public keys are always stored as JOSE.JWK structs regardless of the wire encoding. Both the current Multikey format and the legacy EcdsaSecp256r1VerificationKey2019 / EcdsaSecp256k1VerificationKey2019 formats are accepted during parsing.

Wire formats

Current (Multikey)

{
  "id": "did:plc:abc123#atproto",
  "type": "Multikey",
  "controller": "did:plc:abc123",
  "publicKeyMultibase": "zDnaembgSGUhZULN2Caob4HLJPaxBh92N7rtH21TErzqf8HQo"
}

Legacy (uncompressed multibase, curve identified by type)

{
  "id": "#atproto",
  "type": "EcdsaSecp256k1VerificationKey2019",
  "controller": "did:plc:abc123",
  "publicKeyMultibase": "zQYEBzXeuTM9UR3rfvNag6L3RNAs5pQZyYPsomTsgQhsxLdEgCrPTLgFna8yqCnxPpNT7DBk6Ym3dgPKNu86vt9GR"
}

Fields

  • :id - URI identifying the key, typically a DID fragment (e.g. "#atproto").
  • :type - Key type string (e.g. "Multikey").
  • :controller - DID of the entity that controls this key.
  • :public_key_jwk - The public key as a JOSE.JWK struct, or nil if the wire format could not be decoded.

Summary

Functions

Validates and builds a VerificationMethod struct from a raw map.

Converts a VerificationMethod struct to a camelCase map for JSON serialisation.

Types

t()

@type t() :: %Atex.DID.Document.VerificationMethod{
  controller: String.t(),
  id: String.t(),
  public_key_jwk: (JOSE.JWK.t() | nil) | nil,
  type: String.t()
}

Functions

get_schema(atom)

new(map)

@spec new(map()) :: {:ok, t()} | {:error, term()}

Validates and builds a VerificationMethod struct from a raw map.

Accepts camelCase or snake_case keys. The public key in publicKeyMultibase - whether in the current Multikey format or the legacy uncompressed format - is decoded and stored as public_key_jwk.

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

Examples

iex> Atex.DID.Document.VerificationMethod.new(%{
...>   "id" => "did:plc:abc123#atproto",
...>   "type" => "Multikey",
...>   "controller" => "did:plc:abc123",
...>   "publicKeyMultibase" => "zDnaembgSGUhZULN2Caob4HLJPaxBh92N7rtH21TErzqf8HQo"
...> })
{:ok, %Atex.DID.Document.VerificationMethod{
  id: "did:plc:abc123#atproto",
  type: "Multikey",
  controller: "did:plc:abc123",
  public_key_jwk: %JOSE.JWK{}
}}

schema(data)

schema!(data)

to_json(vm)

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

Converts a VerificationMethod struct to a camelCase map for JSON serialisation.

The public key is always emitted in the canonical Multikey / publicKeyMultibase format. If no public key is present, "publicKeyMultibase" is omitted.

Examples

iex> {:ok, vm} = Atex.DID.Document.VerificationMethod.new(%{
...>   "id" => "did:plc:abc123#atproto",
...>   "type" => "Multikey",
...>   "controller" => "did:plc:abc123",
...>   "publicKeyMultibase" => "zDnaembgSGUhZULN2Caob4HLJPaxBh92N7rtH21TErzqf8HQo"
...> })
iex> json = Atex.DID.Document.VerificationMethod.to_json(vm)
iex> json["type"]
"Multikey"
iex> is_binary(json["publicKeyMultibase"])
true