macula_did_nif (macula v1.4.23)
View SourceDecentralized 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
-spec create_document(Did :: binary(), PublicKey :: binary()) -> {ok, DocumentJson :: binary()} | {error, atom()}.
Create a new DID Document. Returns a JSON-encoded DID document.
-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 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.
-spec is_nif_loaded() -> boolean().
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.
-spec verify_controller(DocumentJson :: binary(), ExpectedController :: binary()) -> ok | {error, atom()}.
Verify that a DID Document is controlled by the expected controller.