Presentation of Mobile Credentials
Mobile credential support presenting credential to a verifier device via bluetooth. The following example is how you could start and response to a credential presentation request from a verifier device.
tip
NOTE: Only one presentation session is allowed at a time, you must terminate the current session if you want to start a new one.
tip
NOTE: When a request is received, you must response to it before a new request can come in in the same session.
// start a new presentation session
const createPresentationSessionResult = await wallet.credential.mobile.createProximityPresentationSession({
onRequestReceived: (data) => {
// request received with error
if ("error" in data) {
const { error } = data;
return;
}
const requests = data.request;
requests.map(({ request, matchedCredentials }) => {
// obtain each request with matching credentials in the mobile credential store
});
},
onConnected: (data: unknown) => {
// presentation session is connected
},
onSessionTerminated: (data: unknown) => {
// presentation session is terminated
},
});
if (createPresentationSessionResult.isErr()) {
// handle error creating presentation session
}
const { deviceEngagement } = createPresentationSessionResult.value;
// Render device engagement string on a QRCode. A verifier app should scan and use it to establish the presentation session with this holder.
// ....
// construct and send a presentation response with the selected credentials
await wallet.credential.mobile.sendProximityPresentationResponse({ credentialIds });
// ...
// terminate the session
await wallet.credential.mobile.terminateProximityPresentationSession();