NIF bindings for the DAVE (Discord Audio Video E2EE) MLS session.
Wraps the davey Rust crate which implements the MLS (RFC 9420) key
exchange protocol used by Discord's DAVE protocol.
The NIF is compiled and loaded automatically via Rustler when Rust is
available. If the NIF cannot be loaded, all functions raise :nif_not_loaded
and available?/0 returns false.
Summary
Functions
Returns true if the NIF is loaded and available.
Returns true if the user's decryptor has an active passthrough (epoch transition grace period).
Creates and returns the client's MLS key package as {:ok, binary}.
Decrypts a DAVE-encrypted audio packet. Returns {:ok, decrypted_binary}.
Encrypts an Opus audio packet using DAVE E2EE.
Returns the current MLS epoch number.
Returns the maximum DAVE protocol version supported by the davey crate.
Creates a new MLS session for the given protocol version, user ID, and channel ID.
Processes an MLS commit from the gateway.
Processes MLS proposals from the gateway.
Processes an MLS welcome message from the gateway.
Returns the DAVE protocol version of this session.
Returns true if the MLS session is ready (group established).
Re-initializes the session with new parameters without creating a new resource.
Resets the MLS group state without losing key material or external sender.
Sets the external sender credential (from the voice gateway).
Sets passthrough mode (disable/enable E2EE without destroying the session).
Returns the session status: :inactive, :pending, :awaiting_response, or :active.
Functions
@spec available?() :: boolean()
Returns true if the NIF is loaded and available.
@spec can_passthrough?(reference(), non_neg_integer()) :: {:ok, boolean()} | {:error, atom()} | boolean()
Returns true if the user's decryptor has an active passthrough (epoch transition grace period).
@spec create_key_package(reference()) :: {:ok, {:ok, binary()}} | {:ok, binary()} | {:error, atom()}
Creates and returns the client's MLS key package as {:ok, binary}.
@spec decrypt_audio(reference(), non_neg_integer(), binary()) :: {:ok, {:ok, binary()}} | {:ok, binary()} | {:error, atom()}
Decrypts a DAVE-encrypted audio packet. Returns {:ok, decrypted_binary}.
@spec encrypt_opus(reference(), binary()) :: {:ok, {:ok, binary()}} | {:ok, binary()} | {:error, :not_ready | :encryption_failed | :error}
Encrypts an Opus audio packet using DAVE E2EE.
Returns {:ok, encrypted_binary} or {:error, :not_ready | :encryption_failed | :error}.
@spec get_epoch(reference()) :: {:ok, non_neg_integer()} | {:error, atom()} | non_neg_integer()
Returns the current MLS epoch number.
@spec max_protocol_version() :: pos_integer()
Returns the maximum DAVE protocol version supported by the davey crate.
@spec new_session(pos_integer(), non_neg_integer(), non_neg_integer()) :: {:ok, reference()} | {:error, atom()} | reference() | no_return()
Creates a new MLS session for the given protocol version, user ID, and channel ID.
Processes an MLS commit from the gateway.
@spec process_proposals(reference(), :append | :revoke, binary(), [non_neg_integer()]) :: {:ok, {:ok, binary(), binary() | nil}} | {:ok, binary(), binary() | nil} | {:error, atom()}
Processes MLS proposals from the gateway.
operation_type is :append or :revoke.
user_ids is a list of connected client user IDs (integers).
Returns {:ok, commit_binary, welcome_binary_or_nil}.
Processes an MLS welcome message from the gateway.
@spec protocol_version(reference()) :: {:ok, pos_integer()} | {:error, atom()} | pos_integer()
Returns the DAVE protocol version of this session.
Returns true if the MLS session is ready (group established).
@spec reinit(reference(), pos_integer(), non_neg_integer(), non_neg_integer()) :: :ok | :error
Re-initializes the session with new parameters without creating a new resource.
@spec reset(reference()) :: :ok | :error
Resets the MLS group state without losing key material or external sender.
Sets the external sender credential (from the voice gateway).
Sets passthrough mode (disable/enable E2EE without destroying the session).
@spec status(reference()) :: {:ok, :inactive | :pending | :awaiting_response | :active} | {:error, atom()} | :inactive | :pending | :awaiting_response | :active
Returns the session status: :inactive, :pending, :awaiting_response, or :active.