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.

NOTE: Only one presentation session is allowed at a time, you must terminate the current session if you want to start a new one.

NOTE: When a request is received, you must response to it before a new request can come in in the same session.

typescript
Copy to clipboard.
1// start a new presentation session
2const createPresentationSessionResult = await wallet.credential.mobile.createProximityPresentationSession({
3  onRequestReceived: (data) => {
4    // request received with error
5    if ("error" in data) {
6      const { error } = data;
7      return;
8    }
9
10    const requests = data.request;
11    requests.map(({ request, matchedCredentials }) => {
12      // obtain each request with matching credentials in the mobile credential store
13    });
14  },
15  onConnected: (data: unknown) => {
16    // presentation session is connected
17  },
18  onSessionTerminated: (data: unknown) => {
19    // presentation session is terminated
20  },
21});
22
23if (createPresentationSessionResult.isErr()) {
24  // handle error creating presentation session
25}
26
27const { deviceEngagement } = createPresentationSessionResult.value;
28// Render device engagement string on a QRCode. A verifier app should scan and use it to establish the presentation session with this holder.
29
30// ....
31
32// construct and send a presentation response with the selected credentials
33await wallet.credential.mobile.sendProximityPresentationResponse({ credentialIds });
34
35// ...
36
37// terminate the session
38await wallet.credential.mobile.terminateProximityPresentationSession();