@mattrglobal/verifier-sdk-web 2.1.2-unstable.98 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Table of Contents
4
4
 
5
+ - [verifier-sdk-web](#verifier-sdk-web)
6
+ - [Table of Contents](#table-of-contents)
5
7
  - [General](#general)
6
8
  - [Licensing](#licensing)
7
9
  - [Overview](#overview)
@@ -18,6 +20,7 @@
18
20
  - [Determine supported presentation flows](#determine-supported-presentation-flows)
19
21
  - [Define wallet identifiers](#define-wallet-identifiers)
20
22
  - [Configure redirectUri](#configure-redirecturi)
23
+ - [Correlate sessions with your own records using state](#correlate-sessions-with-your-own-records-using-state)
21
24
  - [Request credentials using the DC API](#request-credentials-using-the-dc-api)
22
25
  - [Request credentials examples](#request-credentials-examples)
23
26
  - [Request credentials with automatic flow selection](#request-credentials-with-automatic-flow-selection)
@@ -35,15 +38,21 @@ Request or download the
35
38
 
36
39
  ## Overview
37
40
 
38
- The Verifier Web SDK is a powerful tool for integrating online credential verification capabilities into your web applications. It enables secure and efficient verification of [mDocs](https://learn.mattr.global/docs/mdocs), supporting both [same-device](https://learn.mattr.global/docs/verification/online/mdocs/overview#same-device-verification-workflow) and [cross-device](https://learn.mattr.global/docs/verification/online/mdocs/overview#cross-device-verification-workflow) verification workflows. The SDK leverages the MATTR VII platform to handle credential presentation and verification processes.
41
+ The Verifier Web SDK is a powerful tool for integrating online credential verification capabilities into your web
42
+ applications. It enables secure and efficient verification of [mDocs](https://learn.mattr.global/docs/mdocs), supporting
43
+ both [same-device](https://learn.mattr.global/docs/verification/online/mdocs/overview#same-device-verification-workflow)
44
+ and
45
+ [cross-device](https://learn.mattr.global/docs/verification/online/mdocs/overview#cross-device-verification-workflow)
46
+ verification workflows. The SDK leverages the MATTR VII platform to handle credential presentation and verification
47
+ processes.
39
48
 
40
49
  ## Features
41
50
 
42
- * Simple integration into web applications.
43
- * Supports both same-device and cross-device presentation flows.
44
- * Secure handling of mDocs requests and responses.
45
- * Compliant with [ISO/IEC DTS 18013-7](https://www.iso.org/standard/82772.html).
46
- * Offers [DC API](https://wicg.github.io/digital-credentials/) support as a **tech-preview**.
51
+ - Simple integration into web applications.
52
+ - Supports both same-device and cross-device presentation flows.
53
+ - Secure handling of mDocs requests and responses.
54
+ - Compliant with [ISO/IEC DTS 18013-7](https://www.iso.org/standard/82772.html).
55
+ - Offers [DC API](https://wicg.github.io/digital-credentials/) support as a **tech-preview**.
47
56
 
48
57
  > In this SDK mDocs are referred to as Mobile Credentials.
49
58
 
@@ -51,8 +60,8 @@ The Verifier Web SDK is a powerful tool for integrating online credential verifi
51
60
 
52
61
  ## How to get access to the MATTR Pi Verifier Web SDK
53
62
 
54
- Refer to our [SDK Docs landing page](https://learn.mattr.global/guides/get-started-pi) for step-by-step instructions to gain access
55
- to any of our SDKs.
63
+ Refer to our [SDK Docs landing page](https://learn.mattr.global/guides/get-started-pi) for step-by-step instructions to
64
+ gain access to any of our SDKs.
56
65
 
57
66
  > Please [reach out](mailto:dev-support@mattr.global) if you need any assistance.
58
67
 
@@ -82,25 +91,30 @@ MATTRVerifierSDK.initialize(...);
82
91
  <script src="https://cdn.mattr.global/js/verifier-sdk-web/{VERSION}/verifier-js.production.js"></script>
83
92
  ```
84
93
 
85
- > This script will automatically pick up any SDK patch updates. You can lock your implementation to a specific patch version by replacing 1.0 with the specific version (e.g. https://cdn.mattr.global/js/verifier-sdk-web/1.0.1/verifier-js.production.js).
94
+ > This script will automatically pick up any SDK patch updates. You can lock your implementation to a specific patch
95
+ > version by replacing 1.0 with the specific version (e.g.
96
+ > https://cdn.mattr.global/js/verifier-sdk-web/1.0.1/verifier-js.production.js).
86
97
 
87
98
  2. Access SDK functions via global `MATTRVerifierSDK` object.
88
99
 
89
100
  ```javascript
90
- <script>
91
- MATTRVerifierSDK.initialize(...);
92
- </script>
101
+ <script>MATTRVerifierSDK.initialize(...);</script>
93
102
  ```
94
103
 
95
104
  # Usage
96
105
 
97
- The SDK can make a request to create a presentation session with a configured MATTR VII verifier tenant. This requires the following configurations and settings:
98
- * Initialize the SDK with the URL of the MATTR VII tenant that will handle the verification request.
99
- * Prepare a credential query that defines what claims are required for verification.
100
- * Generate a unique challenge for the presentation session.
101
- * Determine what presentation flows are supported in the session.
102
- * Define what wallets can be used to respond to the verification request.
103
- * Configure the URI the user will be redirected to when the verification workflow is completed (only required for same-device flows).
106
+ The SDK can make a request to create a presentation session with a configured MATTR VII verifier tenant. This requires
107
+ the following configurations and settings:
108
+
109
+ - Initialize the SDK with the URL of the MATTR VII tenant that will handle the verification request.
110
+ - Prepare a credential query that defines what claims are required for verification.
111
+ - Generate a unique challenge for the presentation session.
112
+ - Determine what presentation flows are supported in the session.
113
+ - Define what wallets can be used to respond to the verification request.
114
+ - Configure the URI the user will be redirected to when the verification workflow is completed (only required for
115
+ same-device flows).
116
+ - Optionally pass a `state` string to correlate the session with a record in your own system (see
117
+ [Correlate sessions with your own records using state](#correlate-sessions-with-your-own-records-using-state)).
104
118
 
105
119
  ## Initialize the SDK
106
120
 
@@ -111,96 +125,231 @@ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
111
125
  ```
112
126
 
113
127
  - `apiBaseUrl` (required): URL of the MATTR VII verifier tenant.
114
- - `applicationId` (required): Unique identifier of the verifier application. This must match the [`id`](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication!c=201&path=0/id&t=response) parameter in the response returned when [creating a Verifier application](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication) on the MATTR VII verifier tenant.
128
+ - `applicationId` (required): Unique identifier of the verifier application. This must match the
129
+ [`id`](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication!c=201&path=0/id&t=response)
130
+ parameter in the response returned when
131
+ [creating a Verifier application](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication)
132
+ on the MATTR VII verifier tenant.
115
133
 
116
134
  ## Prepare a credential query
117
135
 
118
- The following example credential query will request the `given_name`, `family_name`, `birth_date` and `portrait` claims from a `mobile` credential profile with `org.iso.18013.5.1.mDL` as a docType:
136
+ The following example credential query will request the `given_name`, `family_name`, `birth_date` and `portrait` claims
137
+ from a `mobile` credential profile with `org.iso.18013.5.1.mDL` as a docType:
119
138
 
120
139
  ```javascript
121
140
  const credentialQuery = [
122
141
  {
123
- "profile": "mobile",
124
- "docType": "org.iso.18013.5.1.mDL",
125
- "nameSpaces": {
142
+ profile: "mobile",
143
+ docType: "org.iso.18013.5.1.mDL",
144
+ nameSpaces: {
126
145
  "org.iso.18013.5.1": {
127
- "given_name": {
128
- "intentToRetain": false
146
+ given_name: {
147
+ intentToRetain: false,
148
+ },
149
+ family_name: {
150
+ intentToRetain: false,
129
151
  },
130
- "family_name": {
131
- "intentToRetain": false
152
+ birth_date: {
153
+ intentToRetain: false,
132
154
  },
133
- "birth_date": {
134
- "intentToRetain": false
155
+ portrait: {
156
+ intentToRetain: false,
135
157
  },
136
- "portrait": {
137
- "intentToRetain": false
158
+ resident_postal_code: {
159
+ intentToRetain: false,
138
160
  },
139
- "resident_postal_code": {
140
- "intentToRetain": false
141
- }
142
161
  },
143
- }
144
- }
162
+ },
163
+ },
145
164
  ];
146
165
  ```
147
- * `profile`: Credential format of the credential that will be verified. Currently only mobile (mDocs) is supported.
148
- * `docType`: the mDL’s type. Confirm with the certificate issuer for what docType they are issuing. Some common examples include:
149
- * Mobile Driver License (`org.iso.18013.5.1.mDL`).
150
- * PhotoID (`org.iso.23220.photoid.1`).
151
- * Mobile Vehicle Registration Card (`org.iso.7367.1.mVRC`).
152
- * Health certificate (`org.micov.vtr.1`).
153
- * `nameSpaces`: Each namespace corresponds to a group of claims included in the credential. These can be claims that are part of a specific standard, jurisdiction or any other reference. The namespace would usually correspond to the requested `docType`.
154
- * `intentToRetain` (Optional): When set to `true`, the holder will be indicated that the verifier intends to retain this claim beyond the verification workflow. Defaults to `false` when not specified.
155
-
156
- > The API supports including multiple query objects in the `credentialQuery` array in a single request. For simplicity, this example only includes a single query object.
157
166
 
158
- In this example the `credentialQuery` query will request for the `birthdate`, `portrait` and `resident_postal_code` claims from any credentials whose `profile` is `mobile` and `docType` is `org.iso.18013.5.1.mDL`.
167
+ - `profile`: Credential format of the credential that will be verified. Currently only mobile (mDocs) is supported.
168
+ - `docType`: the mDL’s type. Confirm with the certificate issuer for what docType they are issuing. Some common examples
169
+ include:
170
+ - Mobile Driver License (`org.iso.18013.5.1.mDL`).
171
+ - PhotoID (`org.iso.23220.photoid.1`).
172
+ - Mobile Vehicle Registration Card (`org.iso.7367.1.mVRC`).
173
+ - Health certificate (`org.micov.vtr.1`).
174
+ - `nameSpaces`: Each namespace corresponds to a group of claims included in the credential. These can be claims that are
175
+ part of a specific standard, jurisdiction or any other reference. The namespace would usually correspond to the
176
+ requested `docType`.
177
+ - `intentToRetain` (Optional): When set to `true`, the holder will be indicated that the verifier intends to retain
178
+ this claim beyond the verification workflow. Defaults to `false` when not specified.
179
+
180
+ > The API supports including multiple query objects in the `credentialQuery` array in a single request. For simplicity,
181
+ > this example only includes a single query object.
159
182
 
160
- It also sets `intentToRetain` as `false` for all claims, indicating to the holder that the verifier will not retain any of these claims.
183
+ In this example the `credentialQuery` query will request for the `birthdate`, `portrait` and `resident_postal_code`
184
+ claims from any credentials whose `profile` is `mobile` and `docType` is `org.iso.18013.5.1.mDL`.
161
185
 
162
- > While `intentToRetain` defaults to false, it is explicitly set to `false` in the example above for clarity purposes. If there is no intention to retain a claim, it is sufficient to simply exclude `intentToRetain` from the query.
186
+ It also sets `intentToRetain` as `false` for all claims, indicating to the holder that the verifier will not retain any
187
+ of these claims.
188
+
189
+ > While `intentToRetain` defaults to false, it is explicitly set to `false` in the example above for clarity purposes.
190
+ > If there is no intention to retain a claim, it is sufficient to simply exclude `intentToRetain` from the query.
163
191
 
164
192
  ## Generate challenge
165
193
 
166
- The Verifier Web SDK passes a unique challenge to the MATTR VII verifier tenant with every request to create a new presentation session. The purpose of the challenge is to ensure the security and integrity of the credential verification process by preventing replay attacks and verifying the authenticity of each request and response. You can either:
167
- * Generate this challenge by your backend and pass it to the SDK.
168
- * Generate it using the SDK built-in method.
194
+ The Verifier Web SDK passes a unique challenge to the MATTR VII verifier tenant with every request to create a new
195
+ presentation session. The purpose of the challenge is to ensure the security and integrity of the credential
196
+ verification process by preventing replay attacks and verifying the authenticity of each request and response. You can
197
+ either:
198
+
199
+ - Generate this challenge by your backend and pass it to the SDK.
200
+ - Generate it using the SDK built-in method.
169
201
 
170
- When the challenge is generated by your backend, you should use it to validate the verification results received from the MATTR VII verifier tenant.
202
+ When the challenge is generated by your backend, you should use it to validate the verification results received from
203
+ the MATTR VII verifier tenant.
171
204
 
172
205
  ## Determine supported presentation flows
173
206
 
174
- The **same-device flow** involves the user completing all steps on a single device, such as their smartphone. They initiate the credential request on the verifier's web app, are redirected to their wallet app to consent and present credentials, and then return to the verifier's web app with the results.
207
+ The **same-device flow** involves the user completing all steps on a single device, such as their smartphone. They
208
+ initiate the credential request on the verifier's web app, are redirected to their wallet app to consent and present
209
+ credentials, and then return to the verifier's web app with the results.
175
210
 
176
- In contrast, the **cross-device flow** starts on one device, like a laptop. When the user initiates the request, the web app responds by displaying a QR code. The user then scans this QR code with their smartphone, use their wallet app to present matching credentials, and the results are sent back to the verifier's web app.
211
+ In contrast, the **cross-device flow** starts on one device, like a laptop. When the user initiates the request, the web
212
+ app responds by displaying a QR code. The user then scans this QR code with their smartphone, use their wallet app to
213
+ present matching credentials, and the results are sent back to the verifier's web app.
177
214
 
178
- The main difference is that the same-device flow uses only one device for the entire process, while the cross-device flow uses two devices for added flexibility.
215
+ The main difference is that the same-device flow uses only one device for the entire process, while the cross-device
216
+ flow uses two devices for added flexibility.
179
217
 
180
218
  By default, the Verifier Web SDK automatically selects a flow based on the browser's user agent:
181
- * Same-device flows are used when the agent is a mobile device.
182
- * Cross-device flows are used in all other cases.
183
219
 
184
- This behavior can be explicitly overridden by specifying the desired mode in the SDK configuration, as shown in the [examples](#usage-examples) below.
220
+ - Same-device flows are used when the agent is a mobile device.
221
+ - Cross-device flows are used in all other cases.
222
+
223
+ This behavior can be explicitly overridden by specifying the desired mode in the SDK configuration, as shown in the
224
+ [examples](#request-credentials-examples) below.
185
225
 
186
226
  ## Define wallet identifiers
187
227
 
188
- You can define an identifier of a specific wallet you want to invoke with this verification request. The identifier defined by the SDK in the credential request must match one of the identifiers of a [wallet provider](https://learn.mattr.global/api-reference/latest/tag/Wallet-providers#operation/postWalletProvider!path=name&t=request) created on the MATTR VII verifier tenant.
189
- * If an identifier is provided and matches the `id` of one of the objects in the `walletProviders` array, the verifier tenant will invoke that specific wallet using its corresponding [`authorizationEndpoint`](https://learn.mattr.global/api-reference/latest/tag/Wallet-providers#operation/postWalletProvider!path=openid4vpConfiguration/authorizationEndpoint&t=request).
190
- * If an identifier is provided and does not match the `id` of any of the objects in the `walletProviders array`, the request will fail.
191
- * If an identifier is not provided, the verifier tenant will use `mdoc-openid4vp://` (default OID4VP scheme) to invoke any wallet.
228
+ You can define an identifier of a specific wallet you want to invoke with this verification request. The identifier
229
+ defined by the SDK in the credential request must match one of the identifiers of a
230
+ [wallet provider](https://learn.mattr.global/api-reference/latest/tag/Wallet-providers#operation/postWalletProvider!path=name&t=request)
231
+ created on the MATTR VII verifier tenant.
232
+
233
+ - If an identifier is provided and matches the `id` of one of the objects in the `walletProviders` array, the verifier
234
+ tenant will invoke that specific wallet using its corresponding
235
+ [`authorizationEndpoint`](https://learn.mattr.global/api-reference/latest/tag/Wallet-providers#operation/postWalletProvider!path=openid4vpConfiguration/authorizationEndpoint&t=request).
236
+ - If an identifier is provided and does not match the `id` of any of the objects in the `walletProviders array`, the
237
+ request will fail.
238
+ - If an identifier is not provided, the verifier tenant will use `mdoc-openid4vp://` (default OID4VP scheme) to invoke
239
+ any wallet.
192
240
 
193
241
  ## Configure redirectUri
194
242
 
195
- When using the same-device presentation flow, the SDK must define what URI to redirect the user to once they complete the verification workflow in their wallet app. This can be any URI (including custom URI schemes), and must match one of the values defined in the [`redirectUris` array](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication!path=0/openid4vpConfiguration/redirectUris&t=request) when creating a verifier application.
243
+ When using the same-device presentation flow, the SDK must define what URI to redirect the user to once they complete
244
+ the verification workflow in their wallet app. This can be any URI (including custom URI schemes), and must match one of
245
+ the values defined in the
246
+ [`redirectUris` array](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication!path=0/openid4vpConfiguration/redirectUris&t=request)
247
+ when creating a verifier application.
248
+
249
+ ## Correlate sessions with your own records using `state`
250
+
251
+ When you create a presentation session, MATTR VII generates its own `sessionId` (a UUID) to track the session through
252
+ its lifecycle. That identifier is meaningful within MATTR VII, but it does not map to anything in your own system. If
253
+ you need to attach a verification to an existing record on your side, such as an onboarding application, a checkout
254
+ intent, or an account opening flow, pass an optional `state` string to `requestCredentials()`.
255
+
256
+ `state` is an opaque correlation reference that you generate and control. MATTR VII carries it through the verification
257
+ session and returns it to you with the result, so no additional state management is required in your application or
258
+ backend. The value:
259
+
260
+ - Travels through the entire session, including the wallet interaction.
261
+ - Is returned in both same-device and cross-device flows.
262
+ - Is available on both successful and failed results.
263
+
264
+ If you only need to verify a credential and act on the result immediately in the same browser session, `state` is not
265
+ required; the MATTR VII `sessionId` is enough on its own. Use `state` when correlation needs to survive the round-trip
266
+ to the wallet and back.
267
+
268
+ > The `state` value is transmitted in plain text as a query parameter on the wallet-facing authorization request URI and
269
+ > is stored in session records. It should not contain personally identifiable information (PII), credentials, or
270
+ > anything sensitive. Use an opaque reference, such as an internal record ID or a randomly generated token your system
271
+ > can map back to the underlying record.
272
+
273
+ > `state` is a correlation reference, not a security mechanism. It does not replace the `challenge` used to detect
274
+ > session replay. Continue to generate a unique `challenge` per session and validate it against the result you receive.
275
+
276
+ ### Setting `state`
277
+
278
+ Pass `state` alongside the other options when calling `requestCredentials()`:
279
+
280
+ ```typescript
281
+ const options: MATTRVerifierSDK.RequestCredentialsOptions = {
282
+ credentialQuery: [credentialQuery],
283
+ challenge: MATTRVerifierSDK.utils.generateChallenge(),
284
+ state: "onboarding-app-7f3a4e8c", // Your own opaque correlation reference
285
+ openid4vpConfiguration: {
286
+ redirectUri: window.location.origin,
287
+ walletProviderId,
288
+ },
289
+ };
290
+
291
+ const results = await MATTRVerifierSDK.requestCredentials(options);
292
+ ```
293
+
294
+ The SDK requires `state` to be a non-empty string. The MATTR VII platform additionally enforces a maximum length of 256
295
+ characters and rejects an empty or over-length value with an HTTP 400 validation error. If your internal identifier is
296
+ longer, store it on your side and pass a shorter reference that maps back to it.
297
+
298
+ When `state` is not supplied, the OpenID4VP `state` claim falls back to the MATTR VII `sessionId`, no `state` field
299
+ appears in the result, and existing integrations see no change in behavior.
300
+
301
+ For the complete end-to-end flow across both the MATTR VII platform and the SDK, see the
302
+ [Correlating verification sessions with your system](https://learn.mattr.global/docs/verification/remote-web-verifiers/guides/correlating-verification-sessions)
303
+ guide on MATTR Learn.
304
+
305
+ ### Reading `state` back
306
+
307
+ `state` is echoed back wherever a session result is exposed. In cross-device flows it is returned on the
308
+ `RequestCredentialsResponse` resolved by `requestCredentials()`:
309
+
310
+ ```typescript
311
+ const results = await MATTRVerifierSDK.requestCredentials(options);
312
+
313
+ if (results.isOk()) {
314
+ const { state, result } = results.value; // state === "onboarding-app-7f3a4e8c"
315
+ // Use state to look up the matching record in your system.
316
+ }
317
+ ```
318
+
319
+ In same-device flows it is returned on the `HandleRedirectCallbackResponse` resolved by `handleRedirectCallback()` on
320
+ your redirect page:
321
+
322
+ ```typescript
323
+ const results = await MATTRVerifierSDK.handleRedirectCallback();
324
+
325
+ if (results.isOk()) {
326
+ const { sessionId, state, result } = results.value; // state === "onboarding-app-7f3a4e8c"
327
+ }
328
+ ```
329
+
330
+ > For same-device flows, the SDK persists `state` to `localStorage` before redirecting to the wallet and removes it
331
+ > after `handleRedirectCallback()` completes. This is an implementation detail that guards against frameworks stripping
332
+ > query parameters from redirect URIs; you do not need to read or write this storage entry yourself.
333
+
334
+ When your verifier application delivers results through the back channel (`resultAvailableInFrontChannel: false`), the
335
+ same `state` field is included in the response from the retrieve presentation session result endpoint, on both success
336
+ and failure shapes.
337
+
338
+ For the full end-to-end pattern, including a worked onboarding example and the back-channel result flow across both the
339
+ MATTR VII platform and the SDK, see the
340
+ [Correlating verification sessions with your system](https://learn.mattr.global/docs/verification/remote-web-verifiers/guides/correlating-verification-sessions)
341
+ guide on MATTR Learn.
196
342
 
197
343
  ## Request credentials using the DC API
198
344
 
199
- > DC API support is currently offered as a **tech preview**. As such, functionality may be limited, may not work in all scenarios, and could change or break without prior notice.
345
+ > DC API support is currently offered as a **tech preview**. As such, functionality may be limited, may not work in all
346
+ > scenarios, and could change or break without prior notice.
200
347
 
201
- 1. Add the `dcApiConfiguration` object to your MATTR VII [verifier application configuration](https://learn.mattr.global/docs/verification/remote-verification-api-reference/verifier-applications#update-a-verifier-application).
348
+ 1. Add the `dcApiConfiguration` object to your MATTR VII
349
+ [verifier application configuration](https://learn.mattr.global/docs/verification/remote-verification-api-reference/verifier-applications#update-a-verifier-application).
202
350
 
203
- 2. Use the SDK's `isDigitalCredentialsApiSupported` method to determine if the user's browser supports the Digital Credentials API:
351
+ 2. Use the SDK's `isDigitalCredentialsApiSupported` method to determine if the user's browser supports the Digital
352
+ Credentials API:
204
353
 
205
354
  ```typescript
206
355
  import * as MattrVerifierSDK from "@mattrglobal/verifier-sdk-web";
@@ -242,10 +391,11 @@ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId }); // Initialize the SD
242
391
  const result = await MATTRVerifierSDK.requestCredentials({
243
392
  credentialQuery: credentialQuery, // Define what credential query to use
244
393
  challenge: MATTRVerifierSDK.utils.generateChallenge(), // Pass a unique challenge
394
+ state: "YOUR-REFERENCE-ID", // Optional: attach your own correlation reference
245
395
  openid4vpConfiguration: {
246
- walletProviderId, // Define the wallet identifier
247
- redirectUri, // Define the redirect URI (not required for cross-device only requests)
248
- }
396
+ walletProviderId, // Define the wallet identifier
397
+ redirectUri, // Define the redirect URI (not required for cross-device only requests)
398
+ },
249
399
  });
250
400
 
251
401
  if (result.isErr()) {
@@ -254,12 +404,26 @@ if (result.isErr()) {
254
404
  console.info("<<< MATTRVerifierSDK.requestCredentials succeed", result.value);
255
405
  }
256
406
  ```
257
- * `apiBaseUrl` : Replace with the [`tenant_url`](https://learn.mattr.global/docs/platform-management/authentication) of your MATTR VII verifier tenant.
258
- * `credentialQuery`: The credential query to be used in the request.
259
- * `challenge`: The challenge that will be passed to the MATTR VII tenant with the request to create a presentation session. This example uses the SDK built-in method to generate the challenge, but you can replace it with a challenge generated by your backend system.
260
- * `walletProviderId`: Replace with a wallet identifier that matches one of the identifiers of a [wallet provider](https://learn.mattr.global/api-reference/latest/tag/Wallet-providers#operation/postWalletProvider!path=name&t=request) created on the MATTR VII verifier tenant..
261
- * `mode`: When omitted, the SDK defaults to automatically selecting a flow based on the browser's user agent (set to `undefined` in the example for clarity).
262
- * `redirectUri` Replace with a URI that matches one of the values in the [`redirectUris` array](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication!path=0/openid4vpConfiguration/redirectUris&t=request) in the MATTR VII tenant's verifier application.
407
+
408
+ - `apiBaseUrl` : Replace with the [`tenant_url`](https://learn.mattr.global/docs/platform-management/authentication) of
409
+ your MATTR VII verifier tenant.
410
+ - `credentialQuery`: The credential query to be used in the request.
411
+ - `challenge`: The challenge that will be passed to the MATTR VII tenant with the request to create a presentation
412
+ session. This example uses the SDK built-in method to generate the challenge, but you can replace it with a challenge
413
+ generated by your backend system.
414
+ - `walletProviderId`: Replace with a wallet identifier that matches one of the identifiers of a
415
+ [wallet provider](https://learn.mattr.global/api-reference/latest/tag/Wallet-providers#operation/postWalletProvider!path=name&t=request)
416
+ created on the MATTR VII verifier tenant..
417
+ - `state` (optional): Your own opaque correlation reference for this presentation session. Do not include personally
418
+ identifiable information (PII), credentials, or anything sensitive, as the value is transmitted in plain text on the
419
+ wallet-facing request URI and stored in session records. Returned in the response from `requestCredentials()`
420
+ (cross-device) or `handleRedirectCallback()` (same-device). See
421
+ [Correlate sessions with your own records using state](#correlate-sessions-with-your-own-records-using-state).
422
+ - `mode`: When omitted, the SDK defaults to automatically selecting a flow based on the browser's user agent (set to
423
+ `undefined` in the example for clarity).
424
+ - `redirectUri` Replace with a URI that matches one of the values in the
425
+ [`redirectUris` array](https://learn.mattr.global/api-reference/latest/tag/Verifier-applications#operation/postVerifierApplication!path=0/openid4vpConfiguration/redirectUris&t=request)
426
+ in the MATTR VII tenant's verifier application.
263
427
 
264
428
  ## Request credentials with explicit same-device flow
265
429
 
@@ -268,23 +432,25 @@ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
268
432
  const result = await MATTRVerifierSDK.requestCredentials({
269
433
  credentialQuery: credentialQuery,
270
434
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
435
+ state: "YOUR-REFERENCE-ID", // Optional
271
436
  openid4vpConfiguration: {
272
- redirectUri,
273
- walletProviderId,
274
- mode: "sameDevice",
275
- }
437
+ redirectUri,
438
+ walletProviderId,
439
+ mode: "sameDevice",
440
+ },
276
441
  });
277
442
 
278
443
  // result can be retrieved on redirect uri page. for example
279
444
  window.addEventListener("load", async () => {
280
445
  MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
281
446
  const result = await MATTRVerifierSDK.handleRedirectCallback();
447
+ // result.value contains { sessionId, state, result? }
282
448
  });
283
449
  ```
284
450
 
285
- * `mode`: When set to `sameDevice`, the SDK will only support same-device flow in this verification workflow.
286
- * Note that in this case you must define a `redirectUri`.
287
- * This example shows how you can redirect the user to page that will retrieve and display the verification results.
451
+ - `mode`: When set to `sameDevice`, the SDK will only support same-device flow in this verification workflow.
452
+ - Note that in this case you must define a `redirectUri`.
453
+ - This example shows how you can redirect the user to page that will retrieve and display the verification results.
288
454
 
289
455
  ## Request credentials with explicit cross-device flow
290
456
 
@@ -293,10 +459,11 @@ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
293
459
  const result = await MATTRVerifierSDK.requestCredentials({
294
460
  credentialQuery: credentialQuery,
295
461
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
462
+ state: "YOUR-REFERENCE-ID", // Optional
296
463
  openid4vpConfiguration: {
297
- walletProviderId,
298
- mode: "crossDevice",
299
- }
464
+ walletProviderId,
465
+ mode: "crossDevice",
466
+ },
300
467
  });
301
468
 
302
469
  if (result.isErr()) {
@@ -306,8 +473,10 @@ if (result.isErr()) {
306
473
  }
307
474
  ```
308
475
 
309
- * `mode`: When set to `crossDevice`, the SDK will only support cross-device flow in this verification workflow.
310
- * Note that in this case you must define how to handle verification completion and failure.
476
+ - `mode`: When set to `crossDevice`, the SDK will only support cross-device flow in this verification workflow.
477
+ - Note that in this case you must define how to handle verification completion and failure.
311
478
 
312
479
  # Error Handling
313
- The SDK includes mechanisms for handling errors, such as invalid requests, session timeouts, and user aborts. Callbacks provide detailed error information to help diagnose and remedy issues.
480
+
481
+ The SDK includes mechanisms for handling errors, such as invalid requests, session timeouts, and user aborts. Callbacks
482
+ provide detailed error information to help diagnose and remedy issues.