# `BaileysEx.Auth.NativeFilePersistence`
[🔗](https://github.com/jeffhuen/baileys_ex/blob/main/lib/baileys_ex/auth/native_file_persistence.ex#L1)

Recommended durable auth persistence for Elixir-first deployments.

This backend stores credentials and Signal keys as ETF on disk with crash-safe
writes. Use `BaileysEx.Auth.FilePersistence` when you need the
Baileys-compatible JSON multi-file helper instead.

Switching an existing linked device from the compatibility JSON backend to
this backend is explicit. Use `BaileysEx.Auth.PersistenceMigration` to
preserve the current session, or re-pair on a fresh native directory.

The built-in file lock here is `:global.trans`, which coordinates file access
inside one BEAM cluster. Treat one auth directory as owned by one runtime at a
time; this module is not a distributed storage protocol.

# `delete_keys`

```elixir
@spec delete_keys(atom(), term()) :: :ok | {:error, term()}
```

Deletes a Signal key record by type and ID from the default directory.

# `delete_keys`

```elixir
@spec delete_keys(Path.t(), atom(), term()) :: :ok | {:error, term()}
```

Deletes a Signal key record by type and ID from the specified directory.

# `load_credentials`

```elixir
@spec load_credentials() :: {:ok, BaileysEx.Auth.State.t()} | {:error, term()}
```

Loads the core credentials state from the default configured directory.

# `load_credentials`

```elixir
@spec load_credentials(Path.t()) :: {:ok, BaileysEx.Auth.State.t()} | {:error, term()}
```

Loads the core credentials state from the given path.

# `load_keys`

```elixir
@spec load_keys(atom(), term()) :: {:ok, term()} | {:error, term()}
```

Loads a Signal key record by type and ID from the default directory.

# `load_keys`

```elixir
@spec load_keys(Path.t(), atom(), term()) :: {:ok, term()} | {:error, term()}
```

Loads a Signal key record by type and ID from the given directory.

# `save_credentials`

```elixir
@spec save_credentials(BaileysEx.Auth.State.t()) :: :ok | {:error, term()}
```

Saves the core credentials state into the default directory.

# `save_credentials`

```elixir
@spec save_credentials(Path.t(), BaileysEx.Auth.State.t()) :: :ok | {:error, term()}
```

Saves the core credentials state into the given directory path.

# `save_keys`

```elixir
@spec save_keys(atom(), term(), term()) :: :ok | {:error, term()}
```

Saves a Signal key record by type and ID into the default directory.

# `save_keys`

```elixir
@spec save_keys(Path.t(), atom(), term(), term()) :: :ok | {:error, term()}
```

Saves a Signal key record by type and ID into the specified directory.

# `use_native_file_auth_state`

```elixir
@spec use_native_file_auth_state(Path.t()) ::
  {:ok, BaileysEx.Auth.Persistence.auth_state_helper()} | {:error, term()}
```

Loads the auth state and returns the runtime options for the built-in
file-backed Signal store using the durable native backend.

---

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