AttestoClient.Wallet.CredentialOffer (AttestoClient v2.3.1)

Copy Markdown View Source

Parse an OID4VCI Credential Offer (draft-ietf-oauth-openid4vci §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.

Summary

Functions

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

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

Types

authorization_code_grant()

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

error()

@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()

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

pre_authorized_code_grant()

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

t()

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

tx_code()

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

Functions

fetch(uri, opts \\ [])

@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: ...]).

parse(offer)

@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}.