# `AttestoClient.Wallet.CredentialOffer`
[🔗](https://github.com/XukuLLC/attesto_client/blob/v2.26.0/lib/attesto_client/wallet/credential_offer.ex#L1)

Parse an OID4VCI Credential Offer (`OpenID4VCI 1.0`, 2025-09-16, §4.1) the
wallet receives - the holder-side mirror of `Attesto.CredentialOffer.build/1`.

A Credential Offer reaches the wallet in one of three shapes:

  * by value, as a decoded JSON object or a raw JSON string;
  * as an `openid-credential-offer://` deep link carrying the offer, JSON
    encoded, in its `credential_offer` query parameter; or
  * as an `openid-credential-offer://` deep link carrying a
    `credential_offer_uri` query parameter, from which the wallet fetches
    the offer object itself.

`parse/1` handles the first two forms directly and returns `{:fetch, uri}`
for the third, deferring the network fetch to `fetch/2`. This keeps parsing
conn-free and testable without a live issuer; `fetch/2` performs the GET
(through `AttestoClient.OAuthHTTP`, so it is mockable the same way as the
rest of this library) and parses the result the same way.

# `authorization_code_grant`

```elixir
@type authorization_code_grant() :: %{
  issuer_state: String.t() | nil,
  authorization_server: String.t() | nil
}
```

# `error`

```elixir
@type error() ::
  :invalid_credential_offer
  | :invalid_json
  | :invalid_credential_issuer
  | :invalid_credential_configuration_ids
  | :invalid_grants
  | :invalid_authorization_code_grant
  | :invalid_pre_authorized_code_grant
  | :invalid_tx_code
  | :missing_credential_offer
  | :ambiguous_credential_offer
```

# `grants`

```elixir
@type grants() :: %{
  pre_authorized_code: pre_authorized_code_grant() | nil,
  authorization_code: authorization_code_grant() | nil
}
```

# `pre_authorized_code_grant`

```elixir
@type pre_authorized_code_grant() :: %{
  code: String.t(),
  tx_code: tx_code() | nil,
  authorization_server: String.t() | nil
}
```

# `t`

```elixir
@type t() :: %AttestoClient.Wallet.CredentialOffer{
  credential_configuration_ids: [String.t()],
  credential_issuer: String.t(),
  grants: grants()
}
```

# `tx_code`

```elixir
@type tx_code() :: %{
  input_mode: String.t() | nil,
  length: pos_integer() | nil,
  description: String.t() | nil
}
```

# `fetch`

```elixir
@spec fetch(
  String.t(),
  keyword()
) :: {:ok, t()} | {:error, term()}
```

Fetch a by-reference offer from `credential_offer_uri` and parse it.

HTTP goes through `AttestoClient.OAuthHTTP.get_json/2`, so it is mockable
the same way as the rest of this library (`req_options: [plug: ...]`).

The URI comes from an offer link. `:outbound` is refused with `{:error, :outbound_not_supported}`: the address
comes from another party, so it gets no exception to the HTTPS and
public-address rules (see `AttestoClient.Outbound`).

# `parse`

```elixir
@spec parse(term()) :: {:ok, t()} | {:fetch, String.t()} | {:error, error()}
```

Parse an offer the wallet received: a decoded JSON object, a raw JSON
string, or an `openid-credential-offer://` deep link.

Returns `{:ok, offer}` for a by-value offer, `{:fetch, uri}` when the deep
link carries `credential_offer_uri` (pass `uri` to `fetch/2`), or
`{:error, reason}`.

---

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