@mattrglobal/verifier-sdk-web 2.0.0-preview-digital-credential-api.1 → 2.0.0-preview-digital-credential-api.3

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
@@ -12,6 +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)
15
16
  - [Initialise the SDK](#initialise-the-sdk)
16
17
  - [Prepare a credential query](#prepare-a-credential-query)
17
18
  - [Generate challenge](#generate-challenge)
@@ -61,7 +62,7 @@ to any of our SDKs.
61
62
  1. Install dependencies via yarn:
62
63
 
63
64
  ```bash
64
- yarn add @mattrglobal/verifier-sdk-web
65
+ yarn add @mattrglobal/verifier-sdk-web@2.0.0-preview-digital-credential-api.2
65
66
  ```
66
67
 
67
68
  2. Import the sdk module in your code:
@@ -77,11 +78,9 @@ MATTRVerifierSDK.initialise(...);
77
78
  1. Load the following script tag from your web page:
78
79
 
79
80
  ```html
80
- <script src="https://cdn.mattr.global/js/verifier-sdk-web/1.0/verifier-js.production.js"></script>
81
+ <script src="https://cdn.mattr.global/js/verifier-sdk-web/2.0.0-preview-digital-credential-api.2/verifier-js.production.js"></script>
81
82
  ```
82
83
 
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
-
85
84
  2. Access SDK functions via global `MATTRVerifierSDK` object.
86
85
 
87
86
  ```javascript
@@ -100,11 +99,26 @@ The SDK can make a request to create a presentation session with a configured MA
100
99
  * Define what wallets can be used to respond to the verification request.
101
100
  * Configure the URI the user will be redirected to when the verification workflow is completed (only required for same-device flows).
102
101
 
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
+
103
108
  ## Initialise the SDK
104
109
 
105
110
  You must initialise the SDK before you can use any of its functions and methods.
106
111
 
107
- When initialising the SDK, you must provide the URL of the MATTR VII verifier tenant.
112
+ ```javascript
113
+ MATTRVerifierSDK.initialise({
114
+ apiBaseUrl: "{tenant_url}", // provide the URL of the MATTR VII verifier tenant.
115
+ /**
116
+ * Configurations when Digital Credential Api is available
117
+ **/
118
+ enableDigitalCredentialsApiSameDeviceFlow: true, // indicates whether the SDK will use the Digital Credential API in same-device flows.
119
+ enableDigitalCredentialsApiCrossDeviceFlow: false, // indicates whether the SDK will use the Digital Credential API in cross-device flows.
120
+ });
121
+ ```
108
122
 
109
123
  ## Prepare a credential query
110
124
 
@@ -159,9 +173,11 @@ You can define an identifier of a specific wallet you want to invoke with this v
159
173
  * If an identifier is provided and does not match the `id` of any of the objects in the `walletProviders array`, the request will fail.
160
174
  * If an identifier is not provided, the verifier tenant will use `mdoc-openid4vp://` (default OID4VP scheme) to invoke any wallet.
161
175
 
176
+ **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.
177
+
162
178
  ## Configure redirectUri
163
179
 
164
- 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/latest/tag/mDocs-verification#operation/putVerifierConfiguration!path=redirectUris&t=request) in the MATTR VII tenant's verifier configuration.
180
+ 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.
165
181
 
166
182
  # Request credentials examples
167
183
 
@@ -169,7 +185,7 @@ When using the same-device presentation flow, the SDK must define what URI to re
169
185
 
170
186
  ```javascript
171
187
  MATTRVerifierSDK.initialise({ apiBaseUrl }); // Initialise the SDK
172
- const result = await MATTRVerifierSDK.requestCredentials({
188
+ const requestCredentialsResult = await MATTRVerifierSDK.requestCredentials({
173
189
  credentialQuery: [credentialQuery], // Define what credential query to use
174
190
  challenge: MATTRVerifierSDK.utils.generateChallenge(), // Pass a unique challenge
175
191
  walletProviderId, // Define the wallet identifier
@@ -183,6 +199,17 @@ const result = await MATTRVerifierSDK.requestCredentials({
183
199
  },
184
200
  },
185
201
  });
202
+
203
+ // Check result when it's available in the return value
204
+ if (requestCredentialsResult.isOk() && "result" in requestCredentialsResult.value) {
205
+ console.info("<<< MATTRVerifierSDK.requestCredentials result",result.value.result);
206
+ }
207
+
208
+ // Check result also in your page of redirect_uri
209
+ window.addEventListener("load", async () => {
210
+ MATTRVerifierSDK.initialise({ apiBaseUrl });
211
+ const result = await MATTRVerifierSDK.handleRedirectCallback();
212
+ });
186
213
  ```
187
214
  * `apiBaseUrl` : Replace with the [`tenant_url`](https://learn.mattr.global/docs/security/authentication) of your MATTR VII verifier tenant.
188
215
  * `credentialQuery`: The credential query to be used in the request.
@@ -196,7 +223,7 @@ const result = await MATTRVerifierSDK.requestCredentials({
196
223
 
197
224
  ```javascript
198
225
  MATTRVerifierSDK.initialise({ apiBaseUrl });
199
- const result = await MATTRVerifierSDK.requestCredentials({
226
+ const requestCredentialsResult = await MATTRVerifierSDK.requestCredentials({
200
227
  credentialQuery: [credentialQuery],
201
228
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
202
229
  redirectUri,
@@ -204,7 +231,12 @@ const result = await MATTRVerifierSDK.requestCredentials({
204
231
  mode: "sameDevice",
205
232
  });
206
233
 
207
- // result can be retrieved on redirect uri page. for example
234
+ // Check result when it's available in the return value
235
+ if (requestCredentialsResult.isOk() && "result" in requestCredentialsResult.value) {
236
+ console.info("<<< MATTRVerifierSDK.requestCredentials result",result.value.result);
237
+ }
238
+
239
+ // Check result also in your page of redirect_uri
208
240
  window.addEventListener("load", async () => {
209
241
  MATTRVerifierSDK.initialise({ apiBaseUrl });
210
242
  const result = await MATTRVerifierSDK.handleRedirectCallback();
@@ -219,7 +251,7 @@ window.addEventListener("load", async () => {
219
251
 
220
252
  ```javascript
221
253
  MATTRVerifierSDK.initialise({ apiBaseUrl });
222
- const result = await MATTRVerifierSDK.requestCredentials({
254
+ const requestCredentialsResult = await MATTRVerifierSDK.requestCredentials({
223
255
  credentialQuery: [credentialQuery],
224
256
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
225
257
  walletProviderId,
@@ -233,6 +265,11 @@ const result = await MATTRVerifierSDK.requestCredentials({
233
265
  },
234
266
  },
235
267
  });
268
+
269
+ // Check result when it's available in the return value
270
+ if (requestCredentialsResult.isOk() && "result" in requestCredentialsResult.value) {
271
+ console.info("<<< MATTRVerifierSDK.requestCredentials result",result.value.result);
272
+ }
236
273
  ```
237
274
 
238
275
  * `mode`: When set to `crossDevice`, the SDK will only support cross-device flow in this verification workflow.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Copyright 2024 - MATTR Limited
2
+ * Copyright 2025 - MATTR Limited
3
3
  * All rights reserved
4
4
  * Confidential and proprietary
5
5
  *
@@ -7,8 +7,8 @@
7
7
  * Do Not Translate or Localize
8
8
  *
9
9
  * Bundle of @mattrglobal/verifier-sdk-web
10
- * Generated: 2024-10-21
11
- * Version: 2.0.0-preview-digital-credential-api.1
10
+ * Generated: 2025-02-18
11
+ * Version: 2.0.0-preview-digital-credential-api.3
12
12
  * Dependencies:
13
13
  */
14
14
 
@@ -394,11 +394,13 @@ const isDigitalCredentialsApiSupported = () => {
394
394
  }
395
395
  };
396
396
 
397
- const createDigitalCredentialsApiSession = async ({credentialQuery: credentialQuery, challenge: challenge, apiBaseUrl: apiBaseUrl}) => {
398
- const postData = {
397
+ const createDigitalCredentialsApiSession = async ({credentialQuery: credentialQuery, challenge: challenge, apiBaseUrl: apiBaseUrl, protocol: protocol}) => {
398
+ const postData = Object.assign({
399
399
  credentialQuery: credentialQuery,
400
400
  challenge: challenge
401
- };
401
+ }, protocol && {
402
+ protocol: protocol
403
+ });
402
404
  const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/browserApi/request`, {
403
405
  method: "POST",
404
406
  headers: {
@@ -633,7 +635,7 @@ var SameDeviceRequestCredentialsErrorMessage;
633
635
 
634
636
  const requestCredentialsDigitalCredentialsApi = async options => {
635
637
  const {challenge: challenge, credentialQuery: credentialQuery, initialiseOptions: initialiseOptions} = options;
636
- const {apiBaseUrl: apiBaseUrl} = initialiseOptions;
638
+ const {apiBaseUrl: apiBaseUrl, digitalCredentialsApiProtocol: digitalCredentialsApiProtocol} = initialiseOptions;
637
639
  window.localStorage.setItem(LocalStorageKey.challenge, challenge);
638
640
  const storedChallenge = window.localStorage.getItem(LocalStorageKey.challenge);
639
641
  if (!storedChallenge) {
@@ -645,7 +647,8 @@ const requestCredentialsDigitalCredentialsApi = async options => {
645
647
  const createSessionResult = await createDigitalCredentialsApiSession({
646
648
  credentialQuery: credentialQuery,
647
649
  challenge: storedChallenge,
648
- apiBaseUrl: apiBaseUrl
650
+ apiBaseUrl: apiBaseUrl,
651
+ protocol: digitalCredentialsApiProtocol
649
652
  });
650
653
  if (createSessionResult.isErr()) {
651
654
  return neverthrow.err({