#How to Present Digital Credentials (W3C, SD-JWT VC, mDL) Via OID4VP with walt.id
TL;DR
Learn how to present digital credentials (W3C, SD-JWT VC, mDL) via OID4VP using walt.id's Wallet API, including extracting presentation definitions, finding matching credentials, and fulfilling presentation requests.
What you'll learn
Extract and parse presentation definitions from OID4VP request URLs
Find credentials in a wallet that match presentation definition requirements
Resolve and fulfill presentation requests via the Wallet API
Handle selective disclosure for SD-JWT credentials
Relevant concepts
OpenID4VP – Protocol for requesting and receiving verifiable presentations.
A credential presentation URL is a standardised method, as per the OID4VP specification, to communicate the needed
credentials and claims from verifier to the wallet. The URL can take various forms, such as QR code or a link, and
generally begins with openid4vp:// or haip://.
The most important parameter for us will be the presentation_definition.
The other parameters mainly define:
Internal wallet behaviour
Response types
Supported credential formats
Secure communication between wallet and verifier
For now, we don't need to worry about these details because the wallet API manages them. In a more advanced guide we
will also dive into the other parameters.
The presentation definition specifies the criteria for the wallet to know what credentials and claims should
be requested from the user and shard with the verifier.
A simple example for the JavaScript browser environment would look like the following:
async function decodePresentationURL(offerURL) {
// Create URL object
const url = new URL(offerURL);
// Get `presentation_definition_uri` query parameter
const offerParam = url.searchParams.get("presentation_definition_uri");
// Resolve the URL and get the result
const response = await fetch(offerParam);
if (!response.ok) {
throw new Error('Network response was not ok');
}
// Convert result to text
const resultText = await response.text();
// Decode and parse resultText to an Object
const offerObject = JSON.parse(resultText);
return offerObject;
}
The output of the function would look as follows and will be used in the next step. It's identical
to the one example we already saw of a presentation definition.
Optionally decode the presentation request URL with a site like this, then extract
and resolve presentation_definition by pasting it into your browser search bar.
Use the matchCredentialsForPresentationDefinition endpoint in the wallet API to find all user credentials matching the
presentation request constraints.
The open source wallet currently only supports Presentation Definition. In the latest versions of the the OID4VP standard, this has been replaced by DCQL.
CURL
Endpoint:/wallet-api/wallet/{wallet}/exchange/matchCredentialsForPresentationDefinition| API Reference
Our implementation of Presentation Definition only supports JSON based formats, and therefore does not support mDocs. You must know the credential id of the mDoc you want to share and provide it directly in the exchange flow in the next step.
Using the result of the previous request, we can now display the credential(s) to the user (owner of the wallet)
for confirming the exchange with the verifier.
Now that we have identified the credentials to share and received confirmation from the wallet owner, we are ready to
reply to the verifier's presentation request.
However, before we can do so we need to resolve the original presentation
request using the following endpoint /exchange/resolvePresentationRequest
selectedCredentials: Array - list of credential id's to share which we received from the call
to find matching credentials
disclosures: (optional) Object - This object specifies which selectively disclosable fields of a credential should
be shared with the verifier. It is applicable only if the credential to be shared contains selective disclosure
attributes. The object uses the credential ID as the key(s) and an array of the disclosures of the fields to be disclosed by credential as values.
Key: The unique identifier (ID) of the credential to be shared.
Value: An array containing the disclosures of credential fields that should be disclosed.
This structure allows you to specify which parts of a credential are shared on a per-credential basis, enhancing privacy and control over the information disclosed.
Example Response
If the verifier provided a redirect URI we will receive it as a response.