macula_did_nif (macula v1.4.23)

View Source

Decentralized Identifier (DID) operations for Macula mesh.

This module provides DID document creation, parsing, and verification for the Macula identity hierarchy. It uses Rust NIFs when available, falling back to pure Erlang implementations otherwise.

DID Format

Macula uses the did:macula:` method with hierarchical identities: - Realm: `did:macula:io.macula - Organization: did:macula:io.macula.{org} - Application: did:macula:io.macula.{org}.{app}

DID Document Structure

DID documents follow W3C DID Core specification with Ed25519 keys:

  #{
    <<"@context">> => [<<"https://www.w3.org/ns/did/v1">>],
    <<"id">> => <<"did:macula:io.macula.acme">>,
    <<"controller">> => <<"did:macula:io.macula">>,
    <<"verificationMethod">> => [...],
    <<"authentication">> => [...],
    <<"assertionMethod">> => [...]
  }

Summary

Functions

Create a new DID Document. Returns a JSON-encoded DID document.

Extract the public key from a DID Document. Returns the 32-byte Ed25519 public key.

Get the controller DID from a DID Document. Returns the controller, or the DID itself if self-controlled.

Get the DID from a DID Document.

Check if one DID is a descendant of another.

Check if the NIF is loaded.

Parse a DID string and extract its components. Returns a map with method, identity, parts, and depth.

Parse and validate a DID Document from JSON.

Verify that a DID Document is controlled by the expected controller.

Functions

create_document(Did, PublicKey)

-spec create_document(Did :: binary(), PublicKey :: binary()) ->
                         {ok, DocumentJson :: binary()} | {error, atom()}.

Create a new DID Document. Returns a JSON-encoded DID document.

extract_public_key(DocumentJson)

-spec extract_public_key(DocumentJson :: binary()) -> {ok, PublicKey :: binary()} | {error, atom()}.

Extract the public key from a DID Document. Returns the 32-byte Ed25519 public key.

get_controller(DocumentJson)

-spec get_controller(DocumentJson :: binary()) -> {ok, Controller :: binary()} | {error, atom()}.

Get the controller DID from a DID Document. Returns the controller, or the DID itself if self-controlled.

get_did(DocumentJson)

-spec get_did(DocumentJson :: binary()) -> {ok, Did :: binary()} | {error, atom()}.

Get the DID from a DID Document.

is_descendant(ChildDid, ParentDid)

-spec is_descendant(ChildDid :: binary(), ParentDid :: binary()) -> boolean().

Check if one DID is a descendant of another.

is_nif_loaded()

-spec is_nif_loaded() -> boolean().

Check if the NIF is loaded.

nif_create_document(Did, PublicKey)

nif_extract_public_key(DocumentJson)

nif_get_controller(DocumentJson)

nif_get_did(DocumentJson)

nif_is_descendant(ChildDid, ParentDid)

nif_parse_did(Did)

nif_parse_document(DocumentJson)

nif_verify_controller(DocumentJson, ExpectedController)

parse_did(Did)

-spec parse_did(Did :: binary()) -> {ok, Components :: map()} | {error, atom()}.

Parse a DID string and extract its components. Returns a map with method, identity, parts, and depth.

parse_document(DocumentJson)

-spec parse_document(DocumentJson :: binary()) -> {ok, DocumentJson :: binary()} | {error, atom()}.

Parse and validate a DID Document from JSON.

verify_controller(DocumentJson, ExpectedController)

-spec verify_controller(DocumentJson :: binary(), ExpectedController :: binary()) ->
                           ok | {error, atom()}.

Verify that a DID Document is controlled by the expected controller.