EDA.Voice.Dave.Native (EDA v0.3.0)

Copy Markdown View Source

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

available?()

@spec available?() :: boolean()

Returns true if the NIF is loaded and available.

can_passthrough?(ref, user_id)

@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).

create_key_package(ref)

@spec create_key_package(reference()) ::
  {:ok, {:ok, binary()}} | {:ok, binary()} | {:error, atom()}

Creates and returns the client's MLS key package as {:ok, binary}.

decrypt_audio(ref, sender_user_id, packet)

@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}.

encrypt_opus(ref, packet)

@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}.

get_epoch(ref)

@spec get_epoch(reference()) ::
  {:ok, non_neg_integer()} | {:error, atom()} | non_neg_integer()

Returns the current MLS epoch number.

max_protocol_version()

@spec max_protocol_version() :: pos_integer()

Returns the maximum DAVE protocol version supported by the davey crate.

new_session(protocol_version, user_id, channel_id)

@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.

process_commit(ref, commit)

@spec process_commit(reference(), binary()) :: :ok | :error

Processes an MLS commit from the gateway.

process_proposals(ref, operation_type, proposals, user_ids)

@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}.

process_welcome(ref, welcome)

@spec process_welcome(reference(), binary()) :: :ok | :error

Processes an MLS welcome message from the gateway.

protocol_version(ref)

@spec protocol_version(reference()) ::
  {:ok, pos_integer()} | {:error, atom()} | pos_integer()

Returns the DAVE protocol version of this session.

ready?(ref)

@spec ready?(reference()) :: {:ok, boolean()} | {:error, atom()} | boolean()

Returns true if the MLS session is ready (group established).

reinit(ref, protocol_version, user_id, channel_id)

@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.

reset(ref)

@spec reset(reference()) :: :ok | :error

Resets the MLS group state without losing key material or external sender.

set_external_sender(ref, credential)

@spec set_external_sender(reference(), binary()) :: :ok | :error

Sets the external sender credential (from the voice gateway).

set_passthrough_mode(ref, passthrough)

@spec set_passthrough_mode(reference(), boolean()) :: :ok | :error

Sets passthrough mode (disable/enable E2EE without destroying the session).

status(ref)

@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.