Search documentation of macula

# macula_did_nif (macula v4.4.9)

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:

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

# Summary

## Functions

create_document(Did, PublicKey)

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

extract_public_key(DocumentJson)

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

get_controller(DocumentJson)

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

get_did(DocumentJson)

Get the DID from a DID Document.

is_descendant(ChildDid, ParentDid)

Check if one DID is a descendant of another.

is_nif_loaded()

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)

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

parse_document(DocumentJson)

Parse and validate a DID Document from JSON.

verify_controller(DocumentJson, ExpectedController)

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.