Skip to content
Wallet and Entity Collection draft updates
Documentation menu

16.6. Authenticate a wallet with attestation and proof

Feature guides / 16. Wallet workflows · Example context

Maya's wallet presents Wallet Provider's attestation and a proof signed with the bound wallet key. Licensing Authority uses the pair to authenticate the wallet for its operation.

How to use it

authenticateWallet() verifies provider evidence, the attestation, proof binding, audience, freshness, and replay use. The application supplies acceptWallet for its acceptance policy. parseConcatenatedClientAttestation() splits the supported two-JWT representation but does not verify either token. Attestation authentication.

import { CredentialIssuerRole, type AuthenticateWalletOptions } from "@oidfed/wallet";
import { parseConcatenatedClientAttestation, type TrustAnchorSet } from "@oidfed/core";

export async function authenticateMemberWallet(
  value: string, anchors: TrustAnchorSet, policy: AuthenticateWalletOptions,
) {
  const pair = parseConcatenatedClientAttestation(value);
  if (!pair.ok) return pair;
  return CredentialIssuerRole.authenticateWallet(pair.value.attestationJwt, pair.value.popJwt,
    anchors, policy);
}

What your application owns

Configure the exact receiver audience, expected challenge where used, an explicit replay policy, and a meaningful acceptWallet callback. Use shared storage for single-use protection across replicas; challenge consumption and deliberate freshness-only policies are alternatives described below. Use parseClientAttestationHeaders from core to parse the HTTP header pair and reject duplicate or malformed JWT values before authentication. The callback must check the framework's required status or device policy; returning true unconditionally is not a production acceptance policy.

Bind proof to the current request

The wallet uses its instance key to create the proof associated with the provider's attestation. The recipient validates the pair, audience, freshness, and configured replay protection before treating the wallet as authenticated. Keep challenge issuance and challenge consumption under the host's endpoint policy.

If a fresh challenge or attestation is required, return the protocol-appropriate failure through the host integration. Do not fall back to accepting the attestation alone. Authentication establishes the wallet's proof for this interaction; Licensing Authority still decides whether the requested driving licence operation is authorized.

Client Attestation deployments

The Wallet path above uses CredentialIssuerRole.authenticateWallet(). The Core client-attestation example below is for an endpoint that deliberately uses a different attester trust mechanism. Do not substitute it for Wallet Provider federation validation.

The protocol profile determines how an attester becomes trusted. For federated Wallets, validate the Wallet Provider through Federation as Wallet §§8.4–8.5 require. Generic OAuth deployments may configure another attester trust mechanism; that does not relax the Wallet profile.

When offering draft-07's challenge endpoint, publish its URL, issue unpredictable or authenticated opaque challenges, and verify their origin and validity. Choose whether freshness alone is sufficient or whether each proof must also be single-use. Multi-replica deployments need shared atomic replay storage when single-use protection is required. The library's in-memory store is local to one process.

The host authorization server must bind refresh tokens to the authenticated client instance and its confirmation key, as draft-07 §10.3 requires. A refresh request must prove possession of that same key. These helpers do not store or redeem refresh tokens. Changing the client instance key requires a new attestation; it cannot rewrite an existing attestation's cnf claim.

Consider separate client-instance keys for different authorization servers to reduce correlation. Configure HTTP header-size limits to accommodate the two JWTs. Do not log attestation JWTs, PoPs, credentials, or refresh tokens.

For self-signed mTLS at PAR, the host supplies authenticated transport evidence and proves client-key possession during the TLS handshake. Forwarding headers are not transport evidence unless a trusted deployment component authenticates and protects them. The library compares the resulting certificate with the RP's resolved protocol JWK Set; it does not run a TLS server or validate a PKI chain for this authentication method.

Client Attestation primitives and profile boundaries

The shared implementation follows Client Attestation draft-07, §§5–10. createClientAttestation creates an attester-signed JWT; createClientAttestationProof creates a fresh proof signed by the client instance. clientAttestationHeaders and serializeClientAttestation encode the pair. parseClientAttestationHeaders and parseConcatenatedClientAttestation only parse it; parsing does not establish trust.

For example, Driving Licence Federation can accept an attestation from a fleet application attester it has configured independently:

import type { CryptoEngine } from "@oidfed/crypto";
import { authenticateClientAttestation, ok, err, FederationErrorCode } from "@oidfed/core";
import { type FederationStorage, type TrustedClientAttester, type AuthenticateClientAttestationOptions } from "@oidfed/core";

export async function authenticateDrivingLicenceClient(
  engine: CryptoEngine,
  attestationJwt: string,
  popJwt: string,
  requestClientId: string,
  storage: FederationStorage,
  trustedAttesters: ReadonlyMap<string, TrustedClientAttester>,
  drivingLicencePolicy: NonNullable<AuthenticateClientAttestationOptions["acceptClient"]>,
) {
  // Reuse the host replay store across requests; share durable state across replicas.
  const result = await authenticateClientAttestation(attestationJwt, popJwt, {
    engine,
    audience: "https://licensing-authority.example",
    clientId: requestClientId,
    storage,
    getAttester: async (issuer, _header, signal) => {
      // Lookup input is unverified. Resolve it against your own trusted configuration.
      const attester = trustedAttesters.get(issuer);
      return attester ? ok(attester) : err({
        code: FederationErrorCode.InvalidRequest, description: "Unknown attester",
      });
    },
    acceptClient: drivingLicencePolicy,
  });

  if (!result.ok) {
    // Reject the authentication request using the host's error-response policy.
  } else {
    // result.value.attestation.sub identifies the authenticated client instance.
    // expiresAt includes the current attester-trust and proof-freshness deadlines.
  }
  return result;
}

getAttester returns a Result<TrustedClientAttester> containing trusted jwks and, when applicable, the trust evidence's expiresAt. It must not trust keys provided by the incoming JWT. Federation Wallet users should use the Wallet role methods instead: those methods establish the required Wallet Provider trust.

The engine checks signatures, public confirmation-key material, identity and audience binding, and validity intervals. Both signing algorithms must be supported asymmetric algorithms permitted by local policy. Additional claims are retained; creation rejects attempts to replace reserved identity or key claims. Missing, duplicated, or malformed attestation headers fail validation.

Configure challenge freshness and replay protection

Use fetchAttestationChallenge to POST to an advertised challenge_endpoint. Use readAttestationChallenge on responses to obtain a replacement challenge for the next proof. The host controls the request lifecycle; these helpers do not retry a token or PAR request automatically.

createAttestationChallengeHandler(issue, options) supplies the POST endpoint plumbing. The host's issue callback creates the opaque challenge. Successful responses use HTTP 200, JSON, and Cache-Control: no-store. The host must publish challenge_endpoint in its AS metadata when offering this endpoint.

Authentication supports two freshness choices:

  • The default checks PoP iat, with maxProofAgeSeconds defaulting to 300.
  • freshness: { mode: "challenge", verify } checks a host-verified challenge's issuedAt and expiresAt. The verifier must validate the challenge's origin, intended use, and validity. Client-supplied timestamps are not server evidence.

Replay protection is a separate choice:

  • Supply storage.replay. It is selected by default, or explicitly with replay: { mode: "jti" }.
  • Use replay: { mode: "challenge", consume } for atomic single-use challenges.
  • Explicitly choose replay: { mode: "freshness-only" } where the deployment accepts draft-07 §12.1's freshness-only model. Reuse within the freshness window is then possible.

Do not combine the legacy replay option with replay, or the legacy age option with freshness. No replay protection is silently disabled. Signatures and acceptance policy are checked before replay state is consumed. Time and trust expiry are checked again after asynchronous work.

The shared AS metadata parsers validate the attestation algorithm lists and challenge_endpoint. Effective metadata advertising attest_jwt_client_auth must include both algorithm lists. Publication parsing allows a Superior to supply missing fields later.

Return attestation errors and replacement challenges

Attestation verification returns Result errors as before. A ClientAttestationError can also carry attestationError, a stable reason for the host's HTTP response: use_attestation_challenge, use_fresh_attestation, or invalid_client_attestation. An expired attestation is distinguished from an expired proof. Trust lookup and storage failures are not evidence that the client needs a new attestation.

The host issues any replacement challenge and passes the response through the existing renderer. For example, inside your endpoint handler:

import { authenticateClientAttestation, endpointAuthenticationErrorResponse } from "@oidfed/core";

export async function attestationErrorResponse(result: Awaited<ReturnType<typeof authenticateClientAttestation>>, challenges: { issue(): Promise<string> }) {
  if (!result.ok && result.error.attestationError) {
    const code = result.error.attestationError;
    const headers = code === "use_attestation_challenge"
      ? { "OAuth-Client-Attestation-Challenge": await challenges.issue() }
      : undefined;

    return endpointAuthenticationErrorResponse({
      ...result.error,
      authenticationResponse: { error: code, ...(headers ? { headers } : {}) },
    });
  }
  // Handle other failures through your endpoint's ordinary error policy.
}

Draft-07 §6.2 requires the challenge header with use_attestation_challenge. If challenge issuance fails, return a server error rather than sending that code without its header. A host applying its own attestation-age policy must likewise use use_fresh_attestation when that policy requires a fresh attestation. The library never retries the protected operation automatically.

verifyProtocolJwt accepts an optional allowedAlgorithms list for application policy. It always also applies its supported-algorithm and signature checks. An explicitly empty list accepts no algorithm; omission retains the supported algorithms. OIDC/OAuth roles derive this restriction from their protocol metadata.

Shared authentication and Wallet Provider trust

Wallet roles use core's Client Attestation draft-07 implementation. The Wallet profile still supplies its own trust decision: a Licensing Authority must establish Federation trust in the Wallet Provider before accepting its attestation. A generic out-of-band attester callback cannot replace that step in verifyWalletAttestation or authenticateWallet.

Standalone verification rechecks the Wallet Provider's trust expiration after protocol-key retrieval and signature verification. An attestation may outlive the current Trust Chain; the verifier needs fresh provider trust when it uses it. Pass a supplied chain for offline verification.

Wallet roles expose static createClientAttestationProof, clientAttestationHeaders, serializeClientAttestation, fetchAttestationChallenge, and readAttestationChallenge methods. Reuse an attestation while it is valid, but create a fresh PoP for each request. If the server supplies a replacement challenge, use it in the next PoP.

AuthenticateWalletOptions retains acceptWallet, the default PoP age check, and JTI replay storage. It also accepts core's explicit freshness and replay choices for server-managed challenge deployments. A freshness-only choice must be explicit; it permits reuse within the freshness window. Acceptance-policy failures use the shared message prefix Client acceptance.

See core's challenge guidance for the host callbacks and their responsibilities. Shared helpers do not install a challenge endpoint or publish its metadata automatically.

Wallet attestation verification and authentication preserve core's ClientAttestationError.attestationError distinctions. A host can request a new challenge or a fresh attestation without matching error-description strings; see returning attestation errors. These error hints do not replace Wallet Provider Federation trust validation.

Wallet proof binding and key policy

For authentication, also verify proof of possession and use a shared replay store:

import type { CryptoEngine } from "@oidfed/crypto";
import { CredentialIssuerRole, type AuthenticateWalletOptions } from "@oidfed/wallet";
import { type TrustAnchorSet, type FederationStorage } from "@oidfed/core";

export async function authenticateWalletRequest(
  engine: CryptoEngine,
  walletAttestationJwt: string,
  walletPopJwt: string,
  trustAnchors: TrustAnchorSet,
  authorizationServerIssuer: string,
  requestClientId: string,
  expectedChallenge: string,
  storage: FederationStorage,
  frameworkPolicy: NonNullable<AuthenticateWalletOptions["acceptWallet"]>,
) {
  const authenticated = await CredentialIssuerRole.authenticateWallet(
    walletAttestationJwt,
    walletPopJwt,
    trustAnchors,
    {
      engine,
      audience: authorizationServerIssuer,
      clientId: requestClientId,
      expectedChallenge,
      storage,
      acceptWallet: frameworkPolicy,
    },
  );
  return authenticated;
}

The attestation and PoP have distinct JWT types and signing keys. PoP verification uses the public cnf.jwk inside the attestation. The PoP issuer must match the attestation subject and any supplied request client identifier. The audience is the authorization server's issuer identifier, including when the authorization server is separate from the Credential Issuer.

A supplied expectedChallenge must be nonblank and matches the proof exactly. The application generates, binds, and retains the server challenge. By default, freshness uses the PoP’s iat. For server-timestamp-based challenge freshness, configure freshness: { mode: "challenge", verify }; see ACA §12.1.

Set allowedAttestationAlgorithms for Client Attestation verification and allowedProofAlgorithms for proof-of-possession verification. Each configured list must be nonempty and contain registered algorithms. When general protocol allowedAlgorithms is also set, an algorithm must be in both lists. If only one list is set, it defines the policy for that token. If neither is set, verification uses the classical defaults. The engine must support the selected algorithm. Publish the algorithms your authorization server accepts in its metadata, as required by ACA §10.1.

Attestation creation and verification require a usable public confirmation key with signature-verification usage. The cnf object uses jwk alone among the jwk, jwe, and jku representations, following RFC 7800 §§3.1–3.2. Unknown confirmation extensions remain uninterpreted. Authentication checks locally detectable proof failures before provider discovery and claims the replay identifier only after verification and application acceptance.

The default PoP freshness window is 300 seconds, configurable through maxProofAgeSeconds; clock-skew tolerance also applies. A host may instead select challenge freshness. Supply a shared replay store, atomic challenge consumption, or an explicit freshness-only replay policy. A replay store must claim identifiers atomically and retain them through the acceptance window. Authentication rejects replay-store failures; MemoryFederationStorage can supply it in development.

An attestation's iat and a PoP's exp are optional. A PoP still requires iat and jti. The formats do not require a JWT kid; usable trusted public keys remain necessary. Attestation subjects can be shared by a wallet implementation and must not be treated as unique federation identifiers.

Creation preserves an omitted iat and accepts historical issuance dates supplied by the caller, who is responsible for their accuracy. It rejects future iat, expired exp, and nbf >= exp; delayed activation before expiry is valid under ACA §5.1. Embedded-chain expiry does not cap attestation expiry, although offline verification needs a currently valid chain.

JWT type checks accept media-type case variants and the optional application/ prefix under RFC 7515 §4.1.9. Producers use the canonical type names.

Applications displaying wallet_name or wallet_link choose safe text rendering and navigable URL schemes; successful signature verification establishes the claims’ origin.

For ACA §7 concatenated serialization, parseConcatenatedClientAttestation(value, options) returns { attestationJwt, popJwt } in a Result. It requires exactly two nonempty compact JWTs separated by one ~ and applies maxResponseBytes to the complete value. Pass the pair to authenticateWallet for trust, signature, and claim verification.

The application parses any authentication headers. OAuth Draft 07 requires exactly one attestation field and one PoP field, each containing one well-formed JWT. Pass that validated pair to the authentication operation.

For standalone Wallet Attestation verification, supply expectedAudience when the token contains aud. Authentication uses its configured authorization-server audience for this check. An attestation without aud remains usable under ACA; the PoP always binds the recipient. The acceptWallet callback applies the framework's attestation status and acceptance policy.

Server challenges

Licensing Authority can advertise a challenge_endpoint and use a host-backed challenge handler. Wallet Provider calls fetchAttestationChallenge, then includes the returned value when calling createClientAttestationProof. A replacement challenge in a response must be used for the next proof.

For a server-managed timestamp, configure freshness: { mode: "challenge", verify }. The callback verifies the opaque challenge and returns trusted issuedAt and expiresAt values. Configure replay: { mode: "challenge", consume } when a challenge must be used only once; consumption must be atomic across instances. Configuring storage.replay selects JTI protection unless the application sets a different policy. See the shared authentication API.

If Driving Licence Federation needs a new challenge or a fresh attestation, the failure's attestationError identifies that condition. The host issues replacement challenges and sends the required response header; it does not need to interpret an English error message. A failed trust lookup is handled as a trust or service failure, not as a request to replace the wallet's attestation.

Next: 16.7. Create a signed driving licence presentation request

View source on GitHub