# `BaileysEx.Signal.Repository`
[🔗](https://github.com/jeffhuen/baileys_ex/blob/main/lib/baileys_ex/signal/repository.ex#L1)

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.

# `adapter_error`

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

# `e2e_session`

```elixir
@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`

```elixir
@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`

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

# `session_status`

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

Repository result for `validate_session/2`.

# `t`

```elixir
@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()
}
```

# `decrypt_group_message`

```elixir
@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`

```elixir
@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`

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

Wipes persistent E2E tracks for corresponding device list JIDs.

# `encrypt_group_message`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

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

Initializes a unified Signal Repository utilizing the provided config options.

# `process_sender_key_distribution_message`

```elixir
@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`

```elixir
@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`

```elixir
@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`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
