# `AttestoClient.KeyAttestation`
[🔗](https://github.com/XukuLLC/attesto_client/blob/v2.26.0/lib/attesto_client/key_attestation.ex#L1)

Build an OID4VCI Key Attestation JWT (OpenID4VCI 1.0 "Key Attestation in JWT
format" §D.1), the client-side mirror of `Attesto.KeyAttestation.verify/2`.

A key attestation, issued by the wallet's key-storage component or its Wallet
Provider, vouches that a set of public keys are held in a class of secure
storage. A wallet attaches one to a Credential Request in the `key_attestation`
JOSE header of its `jwt` proof (see `AttestoClient.Wallet.Proof`); the issuer,
configured to trust the signer, then requires the proof's key to appear in the
attestation's `attested_keys`.

Signing and key-bound `:alg`/`:kid` validation behave as in
`AttestoClient.Wallet.Proof` (shared `AttestoClient.Builder` internals).

# `build_opt`

```elixir
@type build_opt() ::
  {:attested_keys, [jwk()]}
  | {:key_storage, [String.t()]}
  | {:user_authentication, [String.t()]}
  | {:certification, String.t()}
  | {:nonce, String.t()}
  | {:x5c, [String.t()]}
  | {:lifetime, pos_integer()}
  | {:alg, String.t()}
  | {:kid, String.t()}
  | {:now, integer()}
```

# `error`

```elixir
@type error() ::
  :invalid_key
  | :invalid_attested_keys
  | :invalid_key_storage
  | :invalid_user_authentication
  | :invalid_certification
  | :invalid_nonce
  | :invalid_x5c
  | :invalid_kid
  | :invalid_lifetime
  | :unsupported_alg
  | :unsupported_key
  | :invalid_time
  | {:signing_failed, String.t()}
```

# `jwk`

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

# `build`

```elixir
@spec build(jwk(), [build_opt()]) :: {:ok, String.t()} | {:error, error()}
```

Build a key attestation JWT, returning `{:ok, compact_jws}` or
`{:error, reason}`. Fails fast on invalid input.

`provider_key` is the key-storage / Wallet Provider private key that signs the
attestation. Required option `:attested_keys` is a non-empty list of the keys
the attestation vouches for (`JOSE.JWK`s or JWK maps); their public halves are
embedded, and the proof's holder key must be among them.

Optional: `:key_storage` / `:user_authentication` (attack-potential-resistance
string lists), `:certification` (an absolute HTTP(S) URL), `:nonce` (echo the
issuer's `c_nonce`), `:x5c` (base64 DER certificates for the header),
`:lifetime` (seconds to `exp`, default `300`), and
`:alg`, `:kid`, `:now` as in `AttestoClient.Wallet.Proof.build/2`.

---

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