Discount eligibility verifier

Embed and integrate

Add wallet-based discount checks to your service

Online, your backend starts a verification session and your page shows the <credential-verifier> web component. In person, open the ready-made kiosk page on a tablet at the counter. Either way, the verifier talks to the wallet and you get a signed result.

How it works

  1. Your backendCreates a session with its API key and gets a session id and a browser token.
  2. Your pageShows the web component with that session. The component draws the QR code and the wallet buttons.
  3. Customer's walletPresents the credential. The verifier checks the issuer, the signature, holder binding and the eligibility rule.
  4. Your backendReceives the signed result by webhook, or long-polls for it, and grants the discount.

Grant the discount only from the result your backend receives. The component's browser events are for showing feedback: anyone can fake them in their own browser.

1. Create a session

Call the verifier from your backend with your API key in the Authorization header. Never send the API key to a browser.

Request

POST /api/sessions
Authorization: Bearer <apiKey>
Content-Type: application/json

{
  "accepted_types": ["pension", "student"],
  "reference": "order-42",
  "return_url": "https://shop.example/checkout"
}

Response

{
  "session_id": "…",
  "browser_token": "…",
  "wallet_url": "openid4vp://?…",
  "same_device_wallet_url": "openid4vp://?…",
  "accepted_types": ["pension", "student"],
  "expires_at": "2026-11-25T10:05:00.000Z"
}
FieldMeaning (all optional)
accepted_typesCredential types that qualify, by their id in credential-types.json. Default: all configured types.
referenceYour own identifier, such as an order number. It comes back in the result.
return_urlWhere the wallet returns the customer after a same-device flow. It must start with one of the client's allowedReturnUrls. Without it, there is no same_device_wallet_url.
client_id_prefixHow the verifier identifies itself to the wallet: decentralized_identifier (did:web, signed), openid_federation or redirect_uri. Default: the server's configuration.

Sessions expire after five minutes by default (oid4vp.sessionTtlSeconds). Pass session_id and browser_token to the page that shows the session.

2. Embed the component

Load verifier.js from the verifier and place the element where the check belongs, for example next to the discount option at checkout. It has no dependencies and makes no requests to third parties.

<script type="module" src="https://verifier.example.com/verifier.js"></script>

<credential-verifier
    session-id="…" session-token="…"
    lang="fi" sound="on">
</credential-verifier>

<script>
  document.querySelector('credential-verifier')
    .addEventListener('verification-result', (e) => {
      // Show feedback, then let your backend decide from the signed result.
      console.log(e.detail.outcome, e.detail.credentialType);
    });
</script>

Instead of session-id and session-token, you can set start-url to an endpoint of your own backend. The component POSTs to it and expects { "session_id", "browser_token" } back. That way, the page can start a new session itself when the customer presses Try again.

The page's origin must be listed in the client's allowedOrigins, because the component calls the verifier from the browser and the Digital Credentials API binds the presentation to that origin.

3. Get the result

Either configure a webhookUrl for your client, or long-poll the session from your backend.

Webhook

When the session finishes, the verifier POSTs the signed result as application/jwt, with the session id in the x-verifier-session header. Failed deliveries are retried a few times within about 40 seconds.

Long polling

GET /api/sessions/{id}?wait=25
Authorization: Bearer <apiKey>

wait holds the request open for up to 30 seconds until the session finishes.

{
  "session_id": "…",
  "reference": "order-42",
  "status": "completed",
  "outcome": "accepted",
  "credential_type": "student",
  "credential_issuer": { "entityId": "https://…", "organizationName": "…", "trustAnchor": "https://findy.trustregistry.eu" },
  "claims": { "enrolment_status": "enrolled", "expiry_date": "2026-12-31" },
  "valid_until": "2026-12-31T21:59:59.999Z",
  "flow": "cross_device",
  "result_jwt": "eyJ…"
}
outcomeWhat to do
acceptedGrant the discount. valid_until tells how long the entitlement lasts, when the credential says.
rejectedThe credential did not qualify. reasons and checks say why.
errorA temporary failure, such as an unreachable federation. Let the customer try again.
wallet_errorThe wallet cancelled or reported an error.
expiredNobody answered before the session expired.
pendingStill waiting for the wallet.

Verify the result JWT

The result is signed by the verifier (typ: eligibility-result+jwt, iss: the verifier's public URL, aud: your client id). The keys are at /.well-known/jwks.json. Verify the signature whenever the result reaches you through a browser, for example in Node.js with jose:

import { createRemoteJWKSet, jwtVerify } from 'jose';

const VERIFIER = 'https://verifier.example.com';
const jwks = createRemoteJWKSet(new URL('/.well-known/jwks.json', VERIFIER));

const { payload } = await jwtVerify(resultJwt, jwks, {
  issuer: VERIFIER,
  audience: 'demo-shop',             // your client id
  typ: 'eligibility-result+jwt',
});
if (payload.outcome === 'accepted') { /* grant the discount */ }

After a same-device flow ("flow": "same_device"), rely on the result only when same_device_confirmed is true. It means the browser that started the session also received the wallet's response code, which defeats session fixation.

Component reference

AttributeMeaning
session-id, session-tokenA session created by your backend (session_id, browser_token).
start-urlOr: a URL the component POSTs to, which returns { session_id, browser_token }.
modeembedded (default) or kiosk: full screen, starts over after each result, never offers same-device options.
langfi, sv or en. Default: the page language.
soundon or off: success and failure tones. Default: on in kiosk mode.
page-feedbackon or off: turn the whole page green or red. Default: on in kiosk mode.
reset-afterSeconds before starting over after a result. Kiosk default from the configuration.
serverVerifier base URL. Default: where verifier.js was loaded from.

Events

verification-status fires as the session progresses and verification-result when it finishes. event.detail holds the display state: status, outcome, credentialType, validUntil and, when something failed, reason. The live demo prints them as they arrive.

Same-device flows

Outside kiosk mode, the component offers Use a wallet on this device when the browser supports the Digital Credentials API, and Open wallet app when the session has a same-device link. When the wallet returns the customer to return_url, the component picks up the result by itself.

Theming

The component draws inside a shadow root. Match it to your site with CSS custom properties. This site uses:

credential-verifier {
  --cv-accent: #0901b9;      /* buttons, spinner, focus */
  --cv-surface: #ffffff;
  --cv-text: #282539;
  --cv-font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --cv-radius: 28px;
  /* also: --cv-accepted, --cv-rejected, --cv-error */
}

Kiosk

For checks at a counter, open /kiosk.html on a tablet or a customer-facing screen. It needs no backend of your own: it starts its own sessions, shows a large QR code, sounds a tone and colours the screen by the result, then starts over.

Setting up a client

The verifier's operator adds each service provider to apiClients in the configuration:

apiClients:
  - id: demo-shop                         # the aud of your result JWTs
    apiKey: ${DEMO_SHOP_API_KEY}          # a long random secret
    webhookUrl: https://shop.example/hooks/eligibility
    allowedReturnUrls: [https://shop.example/checkout]
    allowedOrigins: [https://shop.example]

Running your own verifier, the configuration options and the credential type rules are described in the README.