# `ExWapp.Noise`
[🔗](https://github.com/elchemista/ex_wapp/blob/v0.1.5/lib/ex_wapp/noise.ex#L1)

Implements the Noise_XX_25519_AESGCM_SHA256 handshake used by WhatsApp Web.

The module exposes helpers to produce the client hello, process the server
hello (including certificate verification) and to encrypt/decrypt transport
payloads once the handshake completes.

# `certificate_verifier_fun`

```elixir
@type certificate_verifier_fun() :: (binary(), binary() -&gt; :ok | {:error, term()})
```

# `t`

```elixir
@type t() :: %ExWapp.Noise{
  certificate_verifier: certificate_verifier_fun() | nil,
  cipher_ref: term() | nil,
  client_payload_fun:
    nil
    | (t() -&gt;
         binary()
         | {:ok, binary()}
         | {:error, term()}
         | {:ok, binary(), ExWapp.Store.data()}),
  handshake_hash: binary() | nil,
  handshake_header: binary(),
  handshake_ref: term() | nil,
  handshake_salt: binary() | nil,
  pending_store_data: ExWapp.Store.data() | nil,
  phase: :handshake | :transport,
  rx_counter: non_neg_integer(),
  rx_key: binary() | nil,
  static_key: %{priv: binary(), pub: binary()} | nil,
  store: ExWapp.Store.t() | nil,
  tx_counter: non_neg_integer(),
  tx_key: binary() | nil
}
```

# `decrypt`

```elixir
@spec decrypt(t(), binary()) ::
  {:ok, binary(), t()} | {:error, term(), t()} | {:error, term()}
```

Decrypts a transport payload once the handshake has completed.

# `encrypt`

```elixir
@spec encrypt(t(), binary()) :: {:ok, binary(), t()} | {:error, term()}
```

Encrypts a transport payload once the handshake has completed.

# `handle_server_hello`

```elixir
@spec handle_server_hello(t(), binary()) :: {:ok, binary(), t()} | {:error, term()}
```

Processes the server hello frame and returns the client finish frame together
with the updated Noise state (now ready for transport encryption/decryption).

# `init`

```elixir
@spec init(keyword()) :: {:ok, binary(), t()} | {:error, term()}
```

Initialises a new Noise handshake state.

Returns the binary client hello frame that must be sent immediately together
with the updated state.

---

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