# `ExWapp.Session.Outbound.Prekeys`
[🔗](https://github.com/elchemista/ex_wapp/blob/v0.1.5/lib/ex_wapp/session/outbound/prekeys.ex#L1)

Prekey target decisions and Signal-session bootstrap for outbound messages.

Raw network requests, response receives, and persistence remain in the
outbound worker. This module owns deterministic target selection, batch and
individual fallback decisions, missing-bundle retries, and the transformation
of parsed prekey bundles into Signal sessions.

# `fetch_many_fun`

```elixir
@type fetch_many_fun() :: ([String.t()], ExWapp.Signal.SessionStore.t() -&gt;
                       fetch_result())
```

# `fetch_one_fun`

```elixir
@type fetch_one_fun() :: (String.t(), ExWapp.Signal.SessionStore.t() -&gt;
                      fetch_result())
```

# `fetch_result`

```elixir
@type fetch_result() ::
  {:ok, ExWapp.Signal.SessionStore.t(), map()} | {:error, term()}
```

# `fetch_state`

```elixir
@type fetch_state() :: ExWapp.Signal.SessionStore.t() | {:error, term()}
```

# `create_sessions_for_bundles`

```elixir
@spec create_sessions_for_bundles(
  ExWapp.Signal.SessionStore.t(),
  term(),
  [map()],
  term(),
  non_neg_integer(),
  map()
) :: {:ok, ExWapp.Signal.SessionStore.t(), map()} | {:error, term()}
```

Creates Signal sessions and bundle aliases from parsed prekey bundles.

# `devices_needing_prekeys`

```elixir
@spec devices_needing_prekeys(
  ExWapp.Signal.SessionStore.t(),
  [term()],
  [term()],
  map(),
  pos_integer(),
  integer()
) :: [String.t()]
```

Returns outbound devices that require a prekey bootstrap.

Local-account identities are always refreshed. Other targets are selected
when their PN/LID session is missing or older than the configured maximum.

# `expand_recipient_identity_targets`

```elixir
@spec expand_recipient_identity_targets([term()], [term()]) :: [String.t()]
```

Expands a partial recipient prekey selection to all known recipient devices.

# `fetch_direct`

```elixir
@spec fetch_direct(
  [String.t()],
  ExWapp.Signal.SessionStore.t(),
  String.t(),
  fetch_many_fun(),
  fetch_one_fun()
) :: {fetch_state(), map()}
```

Fetches direct-message prekeys with batch fallback and missing-bundle retry.

# `fetch_group`

```elixir
@spec fetch_group(
  [String.t()],
  ExWapp.Signal.SessionStore.t(),
  term(),
  fetch_many_fun(),
  fetch_one_fun()
) :: {fetch_state(), map()}
```

Fetches group distribution prekeys with batch and individual fallback.

Missing bundles are retried individually after the initial result.

# `missing_bundle_targets`

```elixir
@spec missing_bundle_targets([term()], map()) :: [String.t()]
```

Returns requested device JIDs for which no prekey bundle was returned.

# `targets_needing_prekeys`

```elixir
@spec targets_needing_prekeys(
  ExWapp.Signal.SessionStore.t(),
  [term()],
  MapSet.t({String.t(), String.t()}),
  map(),
  pos_integer(),
  integer()
) :: [String.t()]
```

Selects targets requiring prekeys with an explicit forced identity set.

This form is shared by group sender-key distribution.

---

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