@mattrglobal/verifier-sdk-web 1.1.1-unstable.153 → 1.1.1-unstable.155

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,7 +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
- - [Initialise the SDK](#initialise-the-sdk)
15
+ - [Initialize the SDK](#initialize-the-sdk)
16
16
  - [Prepare a credential query](#prepare-a-credential-query)
17
17
  - [Generate challenge](#generate-challenge)
18
18
  - [Determine supported presentation flows](#determine-supported-presentation-flows)
@@ -29,7 +29,7 @@
29
29
  ## Licensing
30
30
 
31
31
  Request or download the
32
- [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
33
33
  [MATTR Customer Agreement](https://learn.mattr.global/docs/terms/customer-agreement) and review these terms carefully.
34
34
 
35
35
  ## Overview
@@ -69,7 +69,7 @@ yarn add @mattrglobal/verifier-sdk-web
69
69
  ```javascript
70
70
  import * as MATTRVerifierSDK from "@mattrglobal/verifier-sdk-web";
71
71
 
72
- MATTRVerifierSDK.initialise(...);
72
+ MATTRVerifierSDK.initialize(...);
73
73
  ```
74
74
 
75
75
  ### Loading directly from script tag
@@ -86,26 +86,26 @@ MATTRVerifierSDK.initialise(...);
86
86
 
87
87
  ```javascript
88
88
  <script>
89
- MATTRVerifierSDK.initialise(...);
89
+ MATTRVerifierSDK.initialize(...);
90
90
  </script>
91
91
  ```
92
92
 
93
93
  # Usage
94
94
 
95
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:
96
- * 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.
97
97
  * Prepare a credential query that defines what claims are required for verification.
98
98
  * Generate a unique challenge for the presentation session.
99
99
  * Determine what presentation flows are supported in the session.
100
100
  * Define what wallets can be used to respond to the verification request.
101
101
  * Configure the URI the user will be redirected to when the verification workflow is completed (only required for same-device flows).
102
102
 
103
- ## Initialise the SDK
103
+ ## Initialize the SDK
104
104
 
105
- 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:
106
106
 
107
107
  ```javascript
108
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId });
108
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
109
109
  ```
110
110
 
111
111
  - `apiBaseUrl` (required): URL of the MATTR VII verifier tenant.
@@ -144,7 +144,7 @@ const credentialQuery = [
144
144
  ```
145
145
  * `profile`: Credential format of the credential that will be verified. Currently only mobile (mDocs) is supported.
146
146
  * `docType`: the mDL’s type. Confirm with the certificate issuer for what docType they are issuing. Some common examples include:
147
- * Mobile Driver Licence (`org.iso.18013.5.1.mDL`).
147
+ * Mobile Driver License (`org.iso.18013.5.1.mDL`).
148
148
  * PhotoID (`org.iso.23220.photoid.1`).
149
149
  * Mobile Vehicle Registration Card (`org.iso.7367.1.mVRC`).
150
150
  * Health certificate (`org.micov.vtr.1`).
@@ -197,7 +197,7 @@ When using the same-device presentation flow, the SDK must define what URI to re
197
197
  ## Request credentials with automatic flow selection
198
198
 
199
199
  ```javascript
200
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId }); // Initialise the SDK
200
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId }); // Initialize the SDK
201
201
  const result = await MATTRVerifierSDK.requestCredentials({
202
202
  credentialQuery: [credentialQuery], // Define what credential query to use
203
203
  challenge: MATTRVerifierSDK.utils.generateChallenge(), // Pass a unique challenge
@@ -221,7 +221,7 @@ if (result.isErr()) {
221
221
  ## Request credentials with explicit same-device flow
222
222
 
223
223
  ```javascript
224
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId });
224
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
225
225
  const result = await MATTRVerifierSDK.requestCredentials({
226
226
  credentialQuery: [credentialQuery],
227
227
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
@@ -232,7 +232,7 @@ const result = await MATTRVerifierSDK.requestCredentials({
232
232
 
233
233
  // result can be retrieved on redirect uri page. for example
234
234
  window.addEventListener("load", async () => {
235
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId });
235
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
236
236
  const result = await MATTRVerifierSDK.handleRedirectCallback();
237
237
  });
238
238
  ```
@@ -244,7 +244,7 @@ window.addEventListener("load", async () => {
244
244
  ## Request credentials with explicit cross-device flow
245
245
 
246
246
  ```javascript
247
- MATTRVerifierSDK.initialise({ apiBaseUrl, applicationId });
247
+ MATTRVerifierSDK.initialize({ apiBaseUrl, applicationId });
248
248
  const result = await MATTRVerifierSDK.requestCredentials({
249
249
  credentialQuery: [credentialQuery],
250
250
  challenge: MATTRVerifierSDK.utils.generateChallenge(),
@@ -7,7 +7,7 @@
7
7
  * Do Not Translate or Localize
8
8
  *
9
9
  * Bundle of @mattrglobal/verifier-sdk-web
10
- * Generated: 2025-05-16
10
+ * Generated: 2025-05-18
11
11
  * Version: 1.1.0
12
12
  * Dependencies:
13
13
  */
@@ -307,7 +307,7 @@ var AbortSessionErrorMessage;
307
307
  AbortSessionErrorMessage["FailedToAbortSession"] = "Failed to abort session";
308
308
  })(AbortSessionErrorMessage || (AbortSessionErrorMessage = {}));
309
309
 
310
- const InitialiseOptionsValidator = v__namespace.object({
310
+ const InitializeOptionsValidator = v__namespace.object({
311
311
  apiBaseUrl: v__namespace.pipe(v__namespace.string(), v__namespace.nonEmpty("Must not be empty")),
312
312
  applicationId: v__namespace.pipe(v__namespace.string(), v__namespace.nonEmpty("Must not be empty"))
313
313
  });
@@ -350,20 +350,20 @@ const safeFetch = async (input, init) => {
350
350
  }
351
351
  };
352
352
 
353
- let initialiseOptions = undefined;
353
+ let initializeOptions = undefined;
354
354
 
355
- var InitialiseErrorMessage;
355
+ var InitializeErrorMessage;
356
356
 
357
- (function(InitialiseErrorMessage) {
358
- InitialiseErrorMessage["SdkNotInitialised"] = "SDK not initialised";
359
- })(InitialiseErrorMessage || (InitialiseErrorMessage = {}));
357
+ (function(InitializeErrorMessage) {
358
+ InitializeErrorMessage["SdkNotInitialized"] = "SDK not initialized";
359
+ })(InitializeErrorMessage || (InitializeErrorMessage = {}));
360
360
 
361
- const initialise = options => {
362
- assertType(InitialiseOptionsValidator, "Invalid initialise options")(options);
363
- initialiseOptions = options;
361
+ const initialize = options => {
362
+ assertType(InitializeOptionsValidator, "Invalid initialize options")(options);
363
+ initializeOptions = options;
364
364
  };
365
365
 
366
- const getInitialiseOptions = () => initialiseOptions;
366
+ const getInitializeOptions = () => initializeOptions;
367
367
 
368
368
  let sessionAbortController = undefined;
369
369
 
@@ -371,22 +371,27 @@ let _sessionId = undefined;
371
371
 
372
372
  let _sessionKey = undefined;
373
373
 
374
+ let _sessionTimeoutId = undefined;
375
+
374
376
  const getActiveSession = () => {
375
377
  const sessionId = _sessionId;
376
378
  const sessionKey = _sessionKey;
379
+ const sessionTimeoutId = _sessionTimeoutId;
377
380
  if (sessionId) {
378
381
  return {
379
382
  sessionId: sessionId,
380
- sessionKey: sessionKey
383
+ sessionKey: sessionKey,
384
+ sessionTimeoutId: sessionTimeoutId
381
385
  };
382
386
  }
383
387
  return undefined;
384
388
  };
385
389
 
386
390
  const setActiveSession = session => {
387
- const {sessionId: sessionId, sessionKey: sessionKey} = session;
391
+ const {sessionId: sessionId, sessionKey: sessionKey, sessionTimeoutId: sessionTimeoutId} = session;
388
392
  _sessionId = sessionId;
389
393
  _sessionKey = sessionKey;
394
+ _sessionTimeoutId = sessionTimeoutId;
390
395
  const abortController = new AbortController;
391
396
  sessionAbortController = abortController;
392
397
  return abortController;
@@ -394,9 +399,13 @@ const setActiveSession = session => {
394
399
 
395
400
  const removeActiveSession = () => {
396
401
  sessionAbortController === null || sessionAbortController === void 0 ? void 0 : sessionAbortController.abort();
402
+ if (_sessionTimeoutId) {
403
+ window.clearTimeout(_sessionTimeoutId);
404
+ }
397
405
  sessionAbortController = undefined;
398
406
  _sessionKey = undefined;
399
407
  _sessionId = undefined;
408
+ _sessionTimeoutId = undefined;
400
409
  };
401
410
 
402
411
  const defaultRetryDelay = attempt => Math.pow(2, attempt) * 1e3;
@@ -677,25 +686,50 @@ const requestCredentialsWithCrossDevice = async options => {
677
686
  }));
678
687
  };
679
688
 
689
+ const abortCredentialRequest = async () => {
690
+ const initializeOptions = getInitializeOptions();
691
+ if (!initializeOptions) {
692
+ throw new Exception(InitializeErrorMessage.SdkNotInitialized);
693
+ }
694
+ const {apiBaseUrl: apiBaseUrl} = initializeOptions;
695
+ const session = getActiveSession();
696
+ if (!session || !session.sessionKey) {
697
+ return neverthrow.ok(undefined);
698
+ }
699
+ const {sessionId: sessionId, sessionKey: sessionKey} = session;
700
+ removeActiveSession();
701
+ const abortSessionResult = await abortSession({
702
+ apiBaseUrl: apiBaseUrl,
703
+ sessionId: sessionId,
704
+ sessionKey: sessionKey
705
+ });
706
+ if (abortSessionResult.isErr()) {
707
+ return neverthrow.err({
708
+ type: exports.AbortSessionErrorType.AbortSessionFailed,
709
+ message: AbortSessionErrorMessage.FailedToAbortSession,
710
+ cause: abortSessionResult.error
711
+ });
712
+ }
713
+ return neverthrow.ok(undefined);
714
+ };
715
+
680
716
  const requestCredentialsWithDigitalCredentialsApi = async options => {
681
- const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request} = options;
682
- const credentialResponseResult = await getCredentials(request);
717
+ const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request, sessionTtl: sessionTtl} = options;
718
+ const sessionTimeoutId = window.setTimeout((() => removeActiveSession()), sessionTtl * 1e3);
719
+ const abortController = setActiveSession({
720
+ sessionId: sessionId,
721
+ sessionKey: sessionKey,
722
+ sessionTimeoutId: sessionTimeoutId
723
+ });
724
+ const credentialResponseResult = await getCredentials(request, abortController);
683
725
  if (credentialResponseResult.isErr()) {
684
- await abortSession({
685
- apiBaseUrl: apiBaseUrl,
686
- sessionId: sessionId,
687
- sessionKey: sessionKey
688
- });
726
+ await abortCredentialRequest();
689
727
  return neverthrow.err(credentialResponseResult.error);
690
728
  }
691
729
  const credentialResponse = credentialResponseResult.value;
692
730
  const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
693
731
  if (parsedCredentialResponseResult.isErr()) {
694
- await abortSession({
695
- apiBaseUrl: apiBaseUrl,
696
- sessionId: sessionId,
697
- sessionKey: sessionKey
698
- });
732
+ await abortCredentialRequest();
699
733
  return neverthrow.err(parsedCredentialResponseResult.error);
700
734
  }
701
735
  const parsedCredentialResponse = parsedCredentialResponseResult.value;
@@ -717,9 +751,11 @@ const requestCredentialsWithDigitalCredentialsApi = async options => {
717
751
  return neverthrow.ok(credentialVerificationResult.value);
718
752
  };
719
753
 
720
- const getCredentials = async request => {
754
+ const getCredentials = async (request, abortController) => {
721
755
  try {
722
- const credentialResponse = await navigator.credentials.get(request);
756
+ const credentialResponse = await navigator.credentials.get(Object.assign(Object.assign({}, request), {
757
+ signal: abortController.signal
758
+ }));
723
759
  return neverthrow.ok(credentialResponse);
724
760
  } catch (exception) {
725
761
  return neverthrow.err({
@@ -869,12 +905,12 @@ const requestCredentialsSameDevice = async options => {
869
905
 
870
906
  const requestCredentials = async options => {
871
907
  var _a;
872
- const initialiseOptions = getInitialiseOptions();
873
- if (!initialiseOptions) {
874
- throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
908
+ const initializeOptions = getInitializeOptions();
909
+ if (!initializeOptions) {
910
+ throw new Exception(InitializeErrorMessage.SdkNotInitialized);
875
911
  }
876
912
  assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
877
- const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
913
+ const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initializeOptions;
878
914
  const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
879
915
  const dcApiSupported = isDigitalCredentialsApiSupported();
880
916
  const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
@@ -897,13 +933,14 @@ const requestCredentials = async options => {
897
933
  const session = createSessionResult.value;
898
934
  const {sessionKey: sessionKey, sessionId: sessionId} = session;
899
935
  if (session.type === SessionType.DigitalCredentialsApi) {
900
- const {request: request} = session;
936
+ const {request: request, sessionTtl: sessionTtl} = session;
901
937
  return await requestCredentialsWithDigitalCredentialsApi({
902
938
  apiBaseUrl: apiBaseUrl,
903
939
  request: request,
904
940
  sessionId: sessionId,
905
941
  sessionKey: sessionKey,
906
- challenge: challenge
942
+ challenge: challenge,
943
+ sessionTtl: sessionTtl
907
944
  });
908
945
  }
909
946
  if (!openid4vpConfiguration) {
@@ -964,11 +1001,11 @@ var HandleRedirectCallbackErrorMessage;
964
1001
  })(HandleRedirectCallbackErrorMessage || (HandleRedirectCallbackErrorMessage = {}));
965
1002
 
966
1003
  const handleRedirectCallback = async () => {
967
- const initialiseOptions = getInitialiseOptions();
968
- if (!initialiseOptions) {
969
- throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
1004
+ const initializeOptions = getInitializeOptions();
1005
+ if (!initializeOptions) {
1006
+ throw new Exception(InitializeErrorMessage.SdkNotInitialized);
970
1007
  }
971
- const {apiBaseUrl: apiBaseUrl} = initialiseOptions;
1008
+ const {apiBaseUrl: apiBaseUrl} = initializeOptions;
972
1009
  const responseCode = getHashParamValue(window.location.hash, "response_code");
973
1010
  if (!responseCode) {
974
1011
  return neverthrow.err({
@@ -1003,33 +1040,6 @@ const handleRedirectCallback = async () => {
1003
1040
  });
1004
1041
  };
1005
1042
 
1006
- const abortCredentialRequest = async () => {
1007
- const initialiseOptions = getInitialiseOptions();
1008
- if (!initialiseOptions) {
1009
- throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
1010
- }
1011
- const {apiBaseUrl: apiBaseUrl} = initialiseOptions;
1012
- const session = getActiveSession();
1013
- if (!session || !session.sessionKey) {
1014
- return neverthrow.ok(undefined);
1015
- }
1016
- const {sessionId: sessionId, sessionKey: sessionKey} = session;
1017
- removeActiveSession();
1018
- const abortSessionResult = await abortSession({
1019
- apiBaseUrl: apiBaseUrl,
1020
- sessionId: sessionId,
1021
- sessionKey: sessionKey
1022
- });
1023
- if (abortSessionResult.isErr()) {
1024
- return neverthrow.err({
1025
- type: exports.AbortSessionErrorType.AbortSessionFailed,
1026
- message: AbortSessionErrorMessage.FailedToAbortSession,
1027
- cause: abortSessionResult.error
1028
- });
1029
- }
1030
- return neverthrow.ok(undefined);
1031
- };
1032
-
1033
1043
  const utils = {
1034
1044
  generateChallenge: generateChallenge,
1035
1045
  getVersion: getVersion,
@@ -1040,7 +1050,7 @@ exports.abortCredentialRequest = abortCredentialRequest;
1040
1050
 
1041
1051
  exports.handleRedirectCallback = handleRedirectCallback;
1042
1052
 
1043
- exports.initialise = initialise;
1053
+ exports.initialize = initialize;
1044
1054
 
1045
1055
  exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
1046
1056