esdb_identity (reckon_gater v1.3.0)

View Source

Identity management for capability-based security

Provides Ed25519 keypair generation and DID (Decentralized Identifier) encoding/decoding using the did:key method.

DID Key Method

DIDs are encoded as: did:key:z{base58btc(multicodec_prefix + public_key)}

For Ed25519: multicodec prefix is 0xed01

NIF Acceleration

Base58 encoding/decoding can be accelerated via optional Rust NIFs. When the NIF is available (Enterprise Edition), operations are 5-10x faster. Pure Erlang fallbacks are always available (Community Edition).

Example

Generate new identity and get DID:

Identity = esdb_identity:generate(), DID = esdb_identity:did(Identity), {ok, PubKey} = esdb_identity:public_key_from_did(DID).

Summary

Functions

Decode Base58 to binary

Encode binary to Base58 (Bitcoin alphabet)

Get the DID from an identity

Create an identity from an existing Ed25519 keypair

Create an identity from a public key only (for verification)

Generate a new Ed25519 identity with random keypair

Check if NIF acceleration is available

Check if a binary is a valid did:key DID

Get the private key from an identity (may be undefined)

Get the public key from an identity

Extract public key from a did:key DID

Types

identity/0

-type identity() ::
          #identity{did :: binary(), public_key :: binary(), private_key :: binary() | undefined}.

Functions

base58_decode(Base58)

-spec base58_decode(binary()) -> {ok, binary()} | {error, term()}.

Decode Base58 to binary

Uses NIF acceleration when available, otherwise pure Erlang.

base58_encode(Bin)

-spec base58_encode(binary()) -> binary().

Encode binary to Base58 (Bitcoin alphabet)

Uses NIF acceleration when available, otherwise pure Erlang.

did(Identity)

-spec did(identity()) -> binary().

Get the DID from an identity

from_keypair(PubKey, PrivKey)

-spec from_keypair(binary(), binary()) -> identity().

Create an identity from an existing Ed25519 keypair

from_public_key(PubKey)

-spec from_public_key(binary()) -> identity().

Create an identity from a public key only (for verification)

generate()

-spec generate() -> identity().

Generate a new Ed25519 identity with random keypair

is_nif_available()

-spec is_nif_available() -> boolean().

Check if NIF acceleration is available

Returns true if the Rust NIF is loaded and functional. When false, pure Erlang implementations are used.

is_valid_did(DID)

-spec is_valid_did(binary()) -> boolean().

Check if a binary is a valid did:key DID

private_key(Identity)

-spec private_key(identity()) -> binary() | undefined.

Get the private key from an identity (may be undefined)

public_key(Identity)

-spec public_key(identity()) -> binary().

Get the public key from an identity

public_key_from_did(DID)

-spec public_key_from_did(binary()) -> {ok, binary()} | {error, term()}.

Extract public key from a did:key DID