@mattrglobal/verifier-sdk-web 2.2.1-unstable.47 → 2.2.1-unstable.48

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 (2) hide show
  1. package/README.md +49 -0
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -21,6 +21,7 @@
21
21
  - [Define wallet identifiers](#define-wallet-identifiers)
22
22
  - [Configure redirectUri](#configure-redirecturi)
23
23
  - [Correlate sessions with your own records using state](#correlate-sessions-with-your-own-records-using-state)
24
+ - [Run logic on session creation using onSessionCreate](#run-logic-on-session-creation-using-onsessioncreate)
24
25
  - [Request credentials using the DC API](#request-credentials-using-the-dc-api)
25
26
  - [Request credentials examples](#request-credentials-examples)
26
27
  - [Request credentials with automatic flow selection](#request-credentials-with-automatic-flow-selection)
@@ -113,6 +114,8 @@ the following configurations and settings:
113
114
  same-device flows).
114
115
  - Optionally pass a `state` string to correlate the session with a record in your own system (see
115
116
  [Correlate sessions with your own records using state](#correlate-sessions-with-your-own-records-using-state)).
117
+ - Optionally pass an `onSessionCreate` hook to run your own logic once the session has been created (see
118
+ [Run logic on session creation using onSessionCreate](#run-logic-on-session-creation-using-onsessioncreate)).
116
119
 
117
120
  ## Initialize the SDK
118
121
 
@@ -338,6 +341,44 @@ MATTR VII platform and the SDK, see the
338
341
  [Correlating verification sessions with your system](https://learn.mattr.global/docs/verification/remote-web-verifiers/guides/correlating-verification-sessions)
339
342
  guide on MATTR Learn.
340
343
 
344
+ ## Run logic on session creation using `onSessionCreate`
345
+
346
+ `requestCredentials()` accepts an optional `onSessionCreate` hook that the SDK invokes immediately after the
347
+ presentation session has been created on the MATTR VII verifier tenant, but before it continues with the rest of the
348
+ presentation flow (rendering the QR code for cross-device flows or redirecting to the wallet for same-device flows). Use
349
+ it to run your own logic against the freshly created session, for example persisting the `sessionId` in your backend,
350
+ starting a timer, or emitting analytics.
351
+
352
+ The hook receives the session creation result and may be synchronous or asynchronous; the SDK awaits it before
353
+ continuing:
354
+
355
+ ```typescript
356
+ const options: MATTRVerifierSDK.RequestCredentialsOptions = {
357
+ credentialQuery: [credentialQuery],
358
+ challenge: MATTRVerifierSDK.utils.generateChallenge(),
359
+ openid4vpConfiguration: {
360
+ redirectUri: window.location.origin,
361
+ walletProviderId,
362
+ },
363
+ onSessionCreate: async (session) => {
364
+ // e.g. record the session against your own system before the flow continues
365
+ await fetch("/api/sessions", {
366
+ method: "POST",
367
+ headers: { "Content-Type": "application/json" },
368
+ body: JSON.stringify({ sessionId: session.sessionId }),
369
+ });
370
+ },
371
+ };
372
+
373
+ const results = await MATTRVerifierSDK.requestCredentials(options);
374
+ ```
375
+
376
+ - The hook is supported in both same-device and cross-device sessions.
377
+ - The `session` argument exposes the identifiers for the created session, including its `sessionId`.
378
+ - Any error thrown or promise rejection from the hook is intentionally ignored so it cannot disrupt the presentation
379
+ flow. If a step is critical, handle its errors inside the hook rather than relying on `requestCredentials()` to
380
+ surface them.
381
+
341
382
  ## Request credentials using the DC API
342
383
 
343
384
  > DC API support is currently offered as a **tech preview**. As such, functionality may be limited, may not work in all
@@ -394,6 +435,10 @@ const result = await MATTRVerifierSDK.requestCredentials({
394
435
  walletProviderId, // Define the wallet identifier
395
436
  redirectUri, // Define the redirect URI (not required for cross-device only requests)
396
437
  },
438
+ onSessionCreate: (session) => {
439
+ // Optional: run your own logic once the session is created, before the flow continues
440
+ console.info("Session created", session.sessionId);
441
+ },
397
442
  });
398
443
 
399
444
  if (result.isErr()) {
@@ -418,6 +463,10 @@ if (result.isErr()) {
418
463
  wallet-facing request URI and stored in session records. Returned in the response from `requestCredentials()`
419
464
  (cross-device) or `handleRedirectCallback()` (same-device). See
420
465
  [Correlate sessions with your own records using state](#correlate-sessions-with-your-own-records-using-state).
466
+ - `onSessionCreate` (optional): A hook invoked with the session creation result once the presentation session has been
467
+ created, before the flow continues. Supported in both same-device and cross-device flows. Errors thrown by the hook
468
+ are ignored. See
469
+ [Run logic on session creation using onSessionCreate](#run-logic-on-session-creation-using-onsessioncreate).
421
470
  - `mode`: When omitted, the SDK defaults to automatically selecting a flow based on the browser's user agent (set to
422
471
  `undefined` in the example for clarity).
423
472
  - `redirectUri`: Replace with a URI that matches one of the values in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattrglobal/verifier-sdk-web",
3
- "version": "2.2.1-unstable.47+807e293e",
3
+ "version": "2.2.1-unstable.48+1fce962a",
4
4
  "main": "dist/lib/verifier-js.cjs.js",
5
5
  "types": "dist/typings/index.d.ts",
6
6
  "module": "dist/verifier-js.production.esm.js",
@@ -32,5 +32,5 @@
32
32
  "prepack": "cp README.md README_INTERNAL.md && cp README_PUBLIC.md README.md",
33
33
  "postpack": "mv README_INTERNAL.md README.md"
34
34
  },
35
- "gitHead": "807e293ec0f32a15e3987f52f6361a7def1dfdc7"
35
+ "gitHead": "1fce962a0d14a7d84db925ce6cffb3f3e6dfaa0d"
36
36
  }