@mattrglobal/verifier-sdk-web 2.0.0-preview-digital-credential-api.4 → 2.0.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.
Files changed (29) hide show
  1. package/README.md +71 -86
  2. package/dist/lib/verifier-js-no-deps.cjs.js +608 -336
  3. package/dist/lib/verifier-js-no-deps.cjs.js.map +1 -1
  4. package/dist/lib/verifier-js.cjs.js +911 -511
  5. package/dist/lib/verifier-js.cjs.js.map +1 -1
  6. package/dist/typings/common/safeFetch.d.ts +6 -3
  7. package/dist/typings/common/sleep.d.ts +1 -0
  8. package/dist/typings/index.d.ts +6 -7
  9. package/dist/typings/verifier/abortCredentialRequest.d.ts +6 -0
  10. package/dist/typings/verifier/handleRedirectCallback.d.ts +1 -1
  11. package/dist/typings/verifier/index.d.ts +3 -1
  12. package/dist/typings/verifier/initialize.d.ts +12 -0
  13. package/dist/typings/verifier/instanceContext.d.ts +7 -0
  14. package/dist/typings/verifier/requestCredentials.d.ts +2 -2
  15. package/dist/typings/verifier/requestCredentialsCrossDevice.d.ts +3 -47
  16. package/dist/typings/verifier/requestCredentialsDigitalCredentialsApi.d.ts +17 -0
  17. package/dist/typings/verifier/requestCredentialsSameDevice.d.ts +1 -1
  18. package/dist/typings/verifier/types/credential-presentation.d.ts +136 -37
  19. package/dist/typings/verifier/types/verifier-web-sdk.d.ts +153 -214
  20. package/dist/typings/verifier/utils.d.ts +23 -37
  21. package/dist/verifier-js.development.js +866 -499
  22. package/dist/verifier-js.development.js.map +1 -1
  23. package/dist/verifier-js.production.esm.js +4 -4
  24. package/dist/verifier-js.production.esm.js.map +1 -1
  25. package/dist/verifier-js.production.js +4 -4
  26. package/dist/verifier-js.production.js.map +1 -1
  27. package/package.json +3 -3
  28. package/dist/typings/verifier/initialise.d.ts +0 -12
  29. package/dist/typings/verifier/requestCredentialsViaDigitalCredentialsApi.d.ts +0 -7
package/README.md CHANGED
@@ -12,8 +12,7 @@
12
12
  - [Web project with an existing bundler set up](#web-project-with-an-existing-bundler-set-up)
13
13
  - [Loading directly from script tag](#loading-directly-from-script-tag)
14
14
  - [Usage](#usage)
15
- - [Support for Digital Credential API (Tech Preview)](#support-for-digital-credential-api-tech-preview)
16
- - [Initialise the SDK](#initialise-the-sdk)
15
+ - [Initialize the SDK](#initialize-the-sdk)
17
16
  - [Prepare a credential query](#prepare-a-credential-query)
18
17
  - [Generate challenge](#generate-challenge)
19
18
  - [Determine supported presentation flows](#determine-supported-presentation-flows)
@@ -30,7 +29,7 @@
30
29
  ## Licensing
31
30
 
32
31
  Request or download the
33
- [MATTR Pi SDK Trial Licence Agreement](https://learn.mattr.global/docs/terms/mattr-pi-sdk-licence-agreement) and the
32
+ [MATTR Pi SDK Trial License Agreement](https://learn.mattr.global/docs/terms/mattr-pi-sdk-licence-agreement) and the
34
33
  [MATTR Customer Agreement](https://learn.mattr.global/docs/terms/customer-agreement) and review these terms carefully.
35
34
 
36
35
  ## Overview
@@ -50,7 +49,7 @@ The Verifier Web SDK is a powerful tool for integrating online credential verifi
50
49
 
51
50
  ## How to get access to the MATTR Pi Verifier Web SDK
52
51
 
53
- Refer to our [SDK Docs landing page](https://learn.mattr.global/references#mattr-pi-sdk-docs) for step-by-step instructions to gain access
52
+ Refer to our [SDK Docs landing page](https://learn.mattr.global/guides/get-started-pi) for step-by-step instructions to gain access
54
53
  to any of our SDKs.
55
54
 
56
55
  > Please [reach out](mailto:dev-support@mattr.global) if you need any assistance.
@@ -62,7 +61,7 @@ to any of our SDKs.
62
61
  1. Install dependencies via yarn:
63
62
 
64
63
  ```bash
65
- yarn add @mattrglobal/verifier-sdk-web@2.0.0-preview-digital-credential-api.2
64
+ yarn add @mattrglobal/verifier-sdk-web
66
65
  ```
67
66
 
68
67
  2. Import the sdk module in your code:
@@ -70,7 +69,7 @@ yarn add @mattrglobal/verifier-sdk-web@2.0.0-preview-digital-credential-api.2
70
69
  ```javascript
71
70
  import * as MATTRVerifierSDK from "@mattrglobal/verifier-sdk-web";
72
71
 
73
- MATTRVerifierSDK.initialise(...);
72
+ MATTRVerifierSDK.initialize(...);
74
73
  ```
75
74
 
76
75
  ### Loading directly from script tag
@@ -78,55 +77,43 @@ MATTRVerifierSDK.initialise(...);
78
77
  1. Load the following script tag from your web page:
79
78
 
80
79
  ```html
81
- <script src="https://cdn.mattr.global/js/verifier-sdk-web/2.0.0-preview-digital-credential-api.2/verifier-js.production.js"></script>
80
+ <script src="https://cdn.mattr.global/js/verifier-sdk-web/1.0/verifier-js.production.js"></script>
82
81
  ```
83
82
 
83
+ > 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).
84
+
84
85
  2. Access SDK functions via global `MATTRVerifierSDK` object.
85
86
 
86
87
  ```javascript
87
- <script>
88
- MATTRVerifierSDK.initialise(...);
89
- </script>
88
+ <script>
89
+ MATTRVerifierSDK.initialize(...);
90
+ </script>
90
91
  ```
91
92
 
92
93
  # Usage
93
94
 
94
95
  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:
95
- * Initialise the SDK with the URL of the MATTR VII tenant that will handle the verification request.
96
+ * Initialize the SDK with the URL of the MATTR VII tenant that will handle the verification request.
96
97
  * Prepare a credential query that defines what claims are required for verification.
97
98
  * Generate a unique challenge for the presentation session.
98
99
  * Determine what presentation flows are supported in the session.
99
100
  * Define what wallets can be used to respond to the verification request.
100
101
  * Configure the URI the user will be redirected to when the verification workflow is completed (only required for same-device flows).
101
102
 
102
- ## Support for Digital Credential API (Tech Preview)
103
-
104
- This SDK supports the experimental Web Platform Digital Credential API and will automatically attempt to use the Digital Credential API (ahead of executing the request based on OpenID4VP as per ISO 18013-7) when the following conditions are met:
105
- - The SDK detects the Digital Credential API is available in the current web browser.
106
- - The feature has been enabled when the SDK was [initialised]((#initialise-the-sdk).
107
-
108
- ## Initialise the SDK
103
+ ## Initialize the SDK
109
104
 
110
- You must initialise the SDK before you can use any of its functions and methods:
105
+ You must initialize the SDK before you can use any of its functions and methods:
111
106
 
112
107
  ```javascript
113
- MATTRVerifierSDK.initialise({
114
- apiBaseUrl: "{tenant_url}",
115
- applicationId: "{applicationId}",
116
- /**
117
- * Configurations when Digital Credential Api is available
118
- **/
119
- enableDigitalCredentialsApiSameDeviceFlow: true, // indicate if SDK will request credential via Digital Credential Api in a same device flow
120
- enableDigitalCredentialsApiCrossDeviceFlow: false, // indicate if SDK request credential via Digital Credential Api in a cross device flow
121
- });
108
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
122
109
  ```
123
110
 
124
111
  - `apiBaseUrl` (required): URL of the MATTR VII verifier tenant.
125
- - `applicationId` (optional): Unique identifier of the verifier application. This must match the [`name`](https://learn.mattr.global/api-reference/latest/tag/mDocs-verification#operation/postVerifierApplication!path=name&t=request) parameter defined as part of a Verifier application created on the MATTR VII verifier tenant.
112
+ - `applicationId` (required): Unique identifier of the verifier application. This must match the [`id`](https://learn.mattr.global/api-reference/latest/tag/mDocs-verification#operation/postVerifierApplication!c=200&path=id&t=response) parameter in the response returned when [creating a Verifier application configuration](https://learn.mattr.global/api-reference/latest/tag/mDocs-verification#operation/postVerifierApplication) on the MATTR VII verifier tenant.
126
113
 
127
114
  ## Prepare a credential query
128
115
 
129
- The following example credential query will request the `birthdate` and `portrait` claims from a `mobile` credential `profile` with `org.iso.18013.5.1.mDL` as a `docType`:
116
+ 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:
130
117
 
131
118
  ```javascript
132
119
  const credentialQuery = [
@@ -135,7 +122,13 @@ const credentialQuery = [
135
122
  "docType": "org.iso.18013.5.1.mDL",
136
123
  "nameSpaces": {
137
124
  "org.iso.18013.5.1": {
138
- "birthdate": {
125
+ "given_name": {
126
+ "intentToRetain": false
127
+ },
128
+ "family_name": {
129
+ "intentToRetain": false
130
+ },
131
+ "birth_date": {
139
132
  "intentToRetain": false
140
133
  },
141
134
  "portrait": {
@@ -149,9 +142,23 @@ const credentialQuery = [
149
142
  }
150
143
  ];
151
144
  ```
152
-
145
+ * `profile`: Credential format of the credential that will be verified. Currently only mobile (mDocs) is supported.
146
+ * `docType`: the mDL’s type. Confirm with the certificate issuer for what docType they are issuing. Some common examples include:
147
+ * Mobile Driver License (`org.iso.18013.5.1.mDL`).
148
+ * PhotoID (`org.iso.23220.photoid.1`).
149
+ * Mobile Vehicle Registration Card (`org.iso.7367.1.mVRC`).
150
+ * Health certificate (`org.micov.vtr.1`).
151
+ * `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`.
152
+ * `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.
153
+
153
154
  > 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.
154
155
 
156
+ 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`.
157
+
158
+ It also sets `intentToRetain` as `false` for all claims, indicating to the holder that the verifier will not retain any of these claims.
159
+
160
+ > 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.
161
+
155
162
  ## Generate challenge
156
163
 
157
164
  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:
@@ -164,7 +171,7 @@ When the challenge is generated by your backend, you should use it to validate t
164
171
 
165
172
  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.
166
173
 
167
- 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.
174
+ 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.
168
175
 
169
176
  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.
170
177
 
@@ -181,72 +188,55 @@ You can define an identifier of a specific wallet you want to invoke with this v
181
188
  * If an identifier is provided and does not match the `id` of any of the objects in the `walletProviders array`, the request will fail.
182
189
  * If an identifier is not provided, the verifier tenant will use `mdoc-openid4vp://` (default OID4VP scheme) to invoke any wallet.
183
190
 
184
- **Note** that if the SDK request credentials via the Digital Credential API, the mobile operating system will prompt the user to make a selection of which credential from which wallet it would like to respond to the request with.
185
-
186
191
  ## Configure redirectUri
187
192
 
188
- When using the same-device presentation flow with OpenID4VP (ISO 18013-7) e.g instead of using the Digital Credential API, 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/latest/tag/mDocs-verification#operation/putVerifierConfiguration!path=redirectUris&t=request) in the MATTR VII tenant's verifier configuration.
193
+ 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/mDocs-verification#operation/postVerifierApplication!path=openid4vpConfiguration/redirectUris&t=request) in the MATTR VII tenant's verifier configuration.
189
194
 
190
195
  # Request credentials examples
191
196
 
192
197
  ## Request credentials with automatic flow selection
193
198
 
194
199
  ```javascript
195
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId }); // Initialise the SDK
200
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId }); // Initialize the SDK
196
201
  const result = await MATTRVerifierSDK.requestCredentials({
197
202
  credentialQuery: [credentialQuery], // Define what credential query to use
198
203
  challenge: MATTRVerifierSDK.utils.generateChallenge(), // Pass a unique challenge
199
- walletProviderId, // Define the wallet identifier
200
- redirectUri, // Define the redirect URI (not required for cross-device only requests)
201
- crossDeviceCallback: { // Define how to handle completion/failure of cross-device flows (not required for same-device only requests)
202
- onComplete: (result) => {
203
- console.info("<<< MATTRVerifierSDK.requestCredentials crossDeviceCallback.onComplete", result);
204
- },
205
- onFailure: (error) => {
206
- console.info("<<< MATTRVerifierSDK.requestCredentials crossDeviceCallback.onFailure", error);
207
- },
208
- },
204
+ openid4vpConfiguration: {
205
+ walletProviderId, // Define the wallet identifier
206
+ redirectUri, // Define the redirect URI (not required for cross-device only requests)
207
+ }
209
208
  });
210
209
 
211
- // Check result when it's available in the return value
212
- if (requestCredentialsResult.isOk() && "result" in requestCredentialsResult.value) {
213
- console.info("<<< MATTRVerifierSDK.requestCredentials result",result.value.result);
210
+ if (result.isErr()) {
211
+ console.info("<<< MATTRVerifierSDK.requestCredentials succeed", result.error);
212
+ } else {
213
+ console.info("<<< MATTRVerifierSDK.requestCredentials failure", result.value);
214
214
  }
215
-
216
- // Check result also in your page of redirect_uri
217
- window.addEventListener("load", async () => {
218
- MATTRVerifierSDK.initialise({ apiBaseUrl });
219
- const result = await MATTRVerifierSDK.handleRedirectCallback();
220
- });
221
215
  ```
222
- * `apiBaseUrl` : Replace with the [`tenant_url`](https://learn.mattr.global/docs/security/authentication) of your MATTR VII verifier tenant.
216
+ * `apiBaseUrl` : Replace with the [`tenant_url`](https://learn.mattr.global/docs/platform-management/authentication) of your MATTR VII verifier tenant.
223
217
  * `credentialQuery`: The credential query to be used in the request.
224
218
  * `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.
225
219
  * `walletProviderId`: Replace with a wallet identifier that matches one of the values in the [`walletProviders` array](https://learn.mattr.global/api-reference/latest/tag/mDocs-verification#operation/putVerifierConfiguration!path=walletProviders/id&t=request) of the MATTR VII tenant's verifier configuration.
226
220
  * `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).
227
- * `redirectUri` Replace with a URI that matches one of the values in the [`redirectUris` array](https://learn.mattr.global/latest/tag/mDocs-verification#operation/putVerifierConfiguration!path=redirectUris&t=request) in the MATTR VII tenant's verifier configuration.
228
- * `crossDeviceCallback`: Defines how to handle completion (`onComplete`) or failure (`onFailure`) of the verification workflow.
221
+ * `redirectUri` Replace with a URI that matches one of the values in the [`redirectUris` array](https://learn.mattr.global/api-reference/latest/tag/mDocs-verification#operation/postVerifierApplication!path=openid4vpConfiguration/redirectUris&t=request) in the MATTR VII tenant's verifier application configuration.
229
222
 
230
223
  ## Request credentials with explicit same-device flow
231
224
 
232
225
  ```javascript
233
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId });
234
- const requestCredentialsResult = await MATTRVerifierSDK.requestCredentials({
226
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
227
+ const result = await MATTRVerifierSDK.requestCredentials({
235
228
  credentialQuery: [credentialQuery],
236
229
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
237
- redirectUri,
238
- walletProviderId,
239
- mode: "sameDevice",
230
+ openid4vpConfiguration: {
231
+ redirectUri,
232
+ walletProviderId,
233
+ mode: "sameDevice",
234
+ }
240
235
  });
241
236
 
242
- // Check result when it's available in the return value
243
- if (requestCredentialsResult.isOk() && "result" in requestCredentialsResult.value) {
244
- console.info("<<< MATTRVerifierSDK.requestCredentials result",result.value.result);
245
- }
246
-
247
- // Check result also in your page of redirect_uri
237
+ // result can be retrieved on redirect uri page. for example
248
238
  window.addEventListener("load", async () => {
249
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId });
239
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
250
240
  const result = await MATTRVerifierSDK.handleRedirectCallback();
251
241
  });
252
242
  ```
@@ -258,25 +248,20 @@ window.addEventListener("load", async () => {
258
248
  ## Request credentials with explicit cross-device flow
259
249
 
260
250
  ```javascript
261
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId });
262
- const requestCredentialsResult = await MATTRVerifierSDK.requestCredentials({
251
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
252
+ const result = await MATTRVerifierSDK.requestCredentials({
263
253
  credentialQuery: [credentialQuery],
264
254
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
265
- walletProviderId,
266
- mode: "crossDevice",
267
- crossDeviceCallback: {
268
- onComplete: (result) => {
269
- console.info("<<< MATTRVerifierSDK.requestCredentials crossDeviceCallback.onComplete", result);
270
- },
271
- onFailure: (error) => {
272
- console.info("<<< MATTRVerifierSDK.requestCredentials crossDeviceCallback.onFailure", error);
273
- },
274
- },
255
+ openid4vpConfiguration: {
256
+ walletProviderId,
257
+ mode: "crossDevice",
258
+ }
275
259
  });
276
260
 
277
- // Check result when it's available in the return value
278
- if (requestCredentialsResult.isOk() && "result" in requestCredentialsResult.value) {
279
- console.info("<<< MATTRVerifierSDK.requestCredentials result",result.value.result);
261
+ if (result.isErr()) {
262
+ console.info("<<< MATTRVerifierSDK.requestCredentials succeed", result.error);
263
+ } else {
264
+ console.info("<<< MATTRVerifierSDK.requestCredentials failure", result.value);
280
265
  }
281
266
  ```
282
267