# `Attesto.JWE`
[🔗](https://github.com/XukuLLC/attesto/blob/v2.28.0/lib/attesto/jwe.ex#L1)

Bounded compact JWE encryption for credential issuance and presentation.

Supports ECDH-ES with a P-256 recipient key and A128GCM or A256GCM. Callers
select the algorithms from authenticated protocol metadata and may narrow
them with `:accepted_algs` and `:accepted_encs`. This module performs no
network access or protocol-specific claim validation.

Input and plaintext limits default to 1 MiB. `:max_compact_bytes` and
`:max_plaintext_bytes` may explicitly override them. Protected headers are
limited to 16 KiB. Compression, critical extensions, duplicate JSON members,
noncanonical Base64URL, and invalid fixed-length GCM parameters are rejected
before decryption.

# `error`

```elixir
@type error() ::
  :invalid_jwe | :invalid_key | :invalid_header | :invalid_options | :size_limit
```

# `key`

```elixir
@type key() :: JOSE.JWK.t() | map()
```

# `decrypt`

```elixir
@spec decrypt(key(), binary(), keyword()) ::
  {:ok, binary(), map()} | {:error, error()}
```

Authenticate and decrypt a compact JWE, returning its protected header.

The recipient must include private key material. All compact and protected
header checks run before JOSE processes the ciphertext.

# `encrypt`

```elixir
@spec encrypt(key(), binary(), map(), keyword()) ::
  {:ok, binary()} | {:error, error()}
```

Encrypt bytes to a recipient using an authenticated protected header.

The header must include `alg` and `enc`. JOSE generates a fresh ephemeral
key; callers cannot supply `epk`. Private recipient keys are reduced to
their public part before encryption.

# `encrypt_deflated`

```elixir
@spec encrypt_deflated(key(), binary(), map(), keyword()) ::
  {:ok, binary()} | {:error, error()}
```

Encrypt locally produced plaintext with outbound-only RFC 7516 DEFLATE
compression. The caller's header must omit `zip`; this function supplies
`zip: "DEF"` and JOSE compresses the bounded plaintext before encryption.
Plaintext limits apply before compression. `decrypt/3` still refuses `zip`
before handing ciphertext to JOSE, and never inflates received input.

# `peek_protected_header`

```elixir
@spec peek_protected_header(binary()) ::
  {:ok, map()} | {:error, :invalid_jwe | :invalid_header}
```

Split a compact JWE and decode its protected header without decrypting it,
enforcing core's 16384-byte protected-header limit.

---

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