BaileysEx.Signal.Repository (baileys_ex v0.1.0-alpha.7)

Copy Markdown View Source

Public Signal repository boundary for connection and messaging consumers.

This module owns JID-to-Signal address translation, session bundle normalization, and the Elixir-facing return contracts. The cryptographic and session engine stays behind an adapter boundary, keeping the native surface minimal.

Summary

Types

Injected peer session bundle used to bootstrap an outgoing session.

Repository result for validate_session/2.

t()

Functions

Unlocks specific multi-cast message transmissions directly correlating known participant identifiers.

Reconstructs unencrypted cleartext directly from isolated Signal whisper responses.

Wipes persistent E2E tracks for corresponding device list JIDs.

Translates structural Sender Keys payloads to encrypt multirecipient group broadcasts.

Applies standard E2E Signal encryption payload converting binary messages to opaque node cipher blobs.

Maps traditional PN JID addresses towards localized identifiers dynamically resolving contexts.

Performs reverse mappings identifying real users masked via LID instances.

Safely decodes and writes an externally sourced E2E session state payload into the engine.

Converts a standard text JID to its internal Signal Protocol identifier strictly.

Pulls identity key data strictly for known device associations.

Moves established sessions to new aliases honoring WhatsApp's complex LID migration semantics safely.

Initializes a unified Signal Repository utilizing the provided config options.

Parses out group Sender key payloads sent from others ensuring group chats successfully decode.

TOFU processes and saves inbound device identity exchanges overriding any older values when matching.

Pass-through to LID maps linking canonical WA protocol endpoints.

Checks the store bounds asserting whether an active encrypted session currently exists.

Types

adapter_error()

@type adapter_error() ::
  :invalid_ciphertext
  | :invalid_identity_key
  | :invalid_session
  | :invalid_signal_address
  | :no_sender_key_state
  | :no_session
  | term()

e2e_session()

@type e2e_session() :: %{
  registration_id: non_neg_integer(),
  identity_key: binary(),
  signed_pre_key: %{
    key_id: non_neg_integer(),
    public_key: binary(),
    signature: binary()
  },
  pre_key: %{key_id: non_neg_integer(), public_key: binary()}
}

Injected peer session bundle used to bootstrap an outgoing session.

migration_operation()

@type migration_operation() :: %{
  from: BaileysEx.Signal.Address.t(),
  to: BaileysEx.Signal.Address.t(),
  pn_user: String.t(),
  lid_user: String.t(),
  device_id: non_neg_integer()
}

migration_result()

@type migration_result() :: %{
  migrated: non_neg_integer(),
  skipped: non_neg_integer(),
  total: non_neg_integer()
}

session_status()

@type session_status() ::
  %{exists: true}
  | %{exists: false, reason: :no_session | :no_open_session | :validation_error}

Repository result for validate_session/2.

t()

@type t() :: %BaileysEx.Signal.Repository{
  adapter: module(),
  adapter_state: term(),
  pn_to_lid_lookup: BaileysEx.Signal.LIDMappingStore.lookup_fun() | nil,
  store: BaileysEx.Signal.Store.t()
}

Functions

decrypt_group_message(repository, arg2)

@spec decrypt_group_message(t(), %{
  group: String.t(),
  author_jid: String.t(),
  msg: binary()
}) ::
  {:ok, t(), binary()} | {:error, adapter_error()}

Unlocks specific multi-cast message transmissions directly correlating known participant identifiers.

decrypt_message(repository, arg2)

@spec decrypt_message(t(), %{
  jid: String.t(),
  type: :pkmsg | :msg,
  ciphertext: binary()
}) ::
  {:ok, t(), binary()} | {:error, adapter_error()}

Reconstructs unencrypted cleartext directly from isolated Signal whisper responses.

delete_session(repository, jids)

@spec delete_session(t(), [String.t()]) :: {:ok, t()} | {:error, adapter_error()}

Wipes persistent E2E tracks for corresponding device list JIDs.

encrypt_group_message(repository, arg2)

@spec encrypt_group_message(t(), %{
  group: String.t(),
  me_id: String.t(),
  data: binary()
}) ::
  {:ok, t(), %{ciphertext: binary(), sender_key_distribution_message: binary()}}
  | {:error, adapter_error()}

Translates structural Sender Keys payloads to encrypt multirecipient group broadcasts.

encrypt_message(repository, arg2)

@spec encrypt_message(t(), %{jid: String.t(), data: binary()}) ::
  {:ok, t(), %{type: :pkmsg | :msg, ciphertext: binary()}}
  | {:error, adapter_error()}

Applies standard E2E Signal encryption payload converting binary messages to opaque node cipher blobs.

get_lid_for_pn(repository, pn)

@spec get_lid_for_pn(t(), String.t()) :: {:ok, t(), String.t() | nil}

Maps traditional PN JID addresses towards localized identifiers dynamically resolving contexts.

get_pn_for_lid(repository, lid)

@spec get_pn_for_lid(t(), String.t()) :: {:ok, t(), String.t() | nil}

Performs reverse mappings identifying real users masked via LID instances.

inject_e2e_session(repository, arg2)

@spec inject_e2e_session(t(), %{jid: String.t(), session: e2e_session()}) ::
  {:ok, t()} | {:error, adapter_error()}

Safely decodes and writes an externally sourced E2E session state payload into the engine.

jid_to_signal_protocol_address(jid)

@spec jid_to_signal_protocol_address(String.t()) ::
  {:ok, String.t()} | {:error, :invalid_signal_address}

Converts a standard text JID to its internal Signal Protocol identifier strictly.

load_identity_key(repository, jid)

@spec load_identity_key(t(), String.t()) ::
  {:ok, t(), binary() | nil} | {:error, adapter_error()}

Pulls identity key data strictly for known device associations.

migrate_session(repository, from_jid, to_jid)

@spec migrate_session(t(), String.t(), String.t()) ::
  {:ok, t(), migration_result()} | {:error, adapter_error()}

Moves established sessions to new aliases honoring WhatsApp's complex LID migration semantics safely.

new(opts)

@spec new(keyword()) :: t()

Initializes a unified Signal Repository utilizing the provided config options.

process_sender_key_distribution_message(repository, arg2)

@spec process_sender_key_distribution_message(
  t(),
  %{
    author_jid: String.t(),
    item: %{
      group_id: String.t() | nil,
      axolotl_sender_key_distribution_message: binary() | nil
    }
  }
) :: {:ok, t()} | {:error, adapter_error()}

Parses out group Sender key payloads sent from others ensuring group chats successfully decode.

save_identity(repository, arg2)

@spec save_identity(t(), %{jid: String.t(), identity_key: binary()}) ::
  {:ok, t(), boolean()} | {:error, adapter_error()}

TOFU processes and saves inbound device identity exchanges overriding any older values when matching.

store_lid_pn_mappings(repository, mappings)

@spec store_lid_pn_mappings(t(), [BaileysEx.Signal.LIDMappingStore.mapping()]) ::
  {:ok, t()} | {:error, BaileysEx.Signal.LIDMappingStore.error()}

Pass-through to LID maps linking canonical WA protocol endpoints.

validate_session(repository, jid)

@spec validate_session(t(), String.t()) ::
  {:ok, session_status()} | {:error, adapter_error()}

Checks the store bounds asserting whether an active encrypted session currently exists.