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

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.
@@ -7,7 +7,7 @@
7
7
  * Do Not Translate or Localize
8
8
  *
9
9
  * Bundle of @mattrglobal/verifier-sdk-web
10
- * Generated: 2025-01-14
10
+ * Generated: 2025-05-16
11
11
  * Version: 1.1.0
12
12
  * Dependencies:
13
13
  *
@@ -446,148 +446,137 @@ ResultAsync.fromPromise;
446
446
 
447
447
  ResultAsync.fromSafePromise;
448
448
 
449
- function ownKeys(e, r) {
450
- var t = Object.keys(e);
451
- if (Object.getOwnPropertySymbols) {
452
- var o = Object.getOwnPropertySymbols(e);
453
- r && (o = o.filter((function(r) {
454
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
455
- }))), t.push.apply(t, o);
456
- }
457
- return t;
449
+ function _arrayLikeToArray(r, a) {
450
+ (null == a || a > r.length) && (a = r.length);
451
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
452
+ return n;
458
453
  }
459
454
 
460
- function _objectSpread2(e) {
461
- for (var r = 1; r < arguments.length; r++) {
462
- var t = null != arguments[r] ? arguments[r] : {};
463
- r % 2 ? ownKeys(Object(t), !0).forEach((function(r) {
464
- _defineProperty(e, r, t[r]);
465
- })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach((function(r) {
466
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
467
- }));
468
- }
469
- return e;
455
+ function _arrayWithoutHoles(r) {
456
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
470
457
  }
471
458
 
472
- function _typeof(o) {
473
- "@babel/helpers - typeof";
474
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
475
- return typeof o;
476
- } : function(o) {
477
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
478
- }, _typeof(o);
479
- }
480
-
481
- function _defineProperty(obj, key, value) {
482
- key = _toPropertyKey(key);
483
- if (key in obj) {
484
- Object.defineProperty(obj, key, {
485
- value: value,
486
- enumerable: true,
487
- configurable: true,
488
- writable: true
489
- });
490
- } else {
491
- obj[key] = value;
492
- }
493
- return obj;
494
- }
495
-
496
- function _toConsumableArray(arr) {
497
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
498
- }
499
-
500
- function _arrayWithoutHoles(arr) {
501
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
502
- }
503
-
504
- function _iterableToArray(iter) {
505
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
506
- }
507
-
508
- function _unsupportedIterableToArray(o, minLen) {
509
- if (!o) return;
510
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
511
- var n = Object.prototype.toString.call(o).slice(8, -1);
512
- if (n === "Object" && o.constructor) n = o.constructor.name;
513
- if (n === "Map" || n === "Set") return Array.from(o);
514
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
515
- }
516
-
517
- function _arrayLikeToArray(arr, len) {
518
- if (len == null || len > arr.length) len = arr.length;
519
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
520
- return arr2;
521
- }
522
-
523
- function _nonIterableSpread() {
524
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
525
- }
526
-
527
- function _createForOfIteratorHelper(o, allowArrayLike) {
528
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
529
- if (!it) {
530
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
531
- if (it) o = it;
532
- var i = 0;
533
- var F = function() {};
459
+ function _createForOfIteratorHelper(r, e) {
460
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
461
+ if (!t) {
462
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
463
+ t && (r = t);
464
+ var n = 0, F = function() {};
534
465
  return {
535
466
  s: F,
536
467
  n: function() {
537
- if (i >= o.length) return {
538
- done: true
539
- };
540
- return {
541
- done: false,
542
- value: o[i++]
468
+ return n >= r.length ? {
469
+ done: !0
470
+ } : {
471
+ done: !1,
472
+ value: r[n++]
543
473
  };
544
474
  },
545
- e: function(e) {
546
- throw e;
475
+ e: function(r) {
476
+ throw r;
547
477
  },
548
478
  f: F
549
479
  };
550
480
  }
551
481
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
552
482
  }
553
- var normalCompletion = true, didErr = false, err;
483
+ var o, a = !0, u = !1;
554
484
  return {
555
485
  s: function() {
556
- it = it.call(o);
486
+ t = t.call(r);
557
487
  },
558
488
  n: function() {
559
- var step = it.next();
560
- normalCompletion = step.done;
561
- return step;
489
+ var r = t.next();
490
+ return a = r.done, r;
562
491
  },
563
- e: function(e) {
564
- didErr = true;
565
- err = e;
492
+ e: function(r) {
493
+ u = !0, o = r;
566
494
  },
567
495
  f: function() {
568
496
  try {
569
- if (!normalCompletion && it.return != null) it.return();
497
+ a || null == t.return || t.return();
570
498
  } finally {
571
- if (didErr) throw err;
499
+ if (u) throw o;
572
500
  }
573
501
  }
574
502
  };
575
503
  }
576
504
 
577
- function _toPrimitive(input, hint) {
578
- if (typeof input !== "object" || input === null) return input;
579
- var prim = input[Symbol.toPrimitive];
580
- if (prim !== undefined) {
581
- var res = prim.call(input, hint || "default");
582
- if (typeof res !== "object") return res;
505
+ function _defineProperty(e, r, t) {
506
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
507
+ value: t,
508
+ enumerable: !0,
509
+ configurable: !0,
510
+ writable: !0
511
+ }) : e[r] = t, e;
512
+ }
513
+
514
+ function _iterableToArray(r) {
515
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
516
+ }
517
+
518
+ function _nonIterableSpread() {
519
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
520
+ }
521
+
522
+ function ownKeys(e, r) {
523
+ var t = Object.keys(e);
524
+ if (Object.getOwnPropertySymbols) {
525
+ var o = Object.getOwnPropertySymbols(e);
526
+ r && (o = o.filter((function(r) {
527
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
528
+ }))), t.push.apply(t, o);
529
+ }
530
+ return t;
531
+ }
532
+
533
+ function _objectSpread2(e) {
534
+ for (var r = 1; r < arguments.length; r++) {
535
+ var t = null != arguments[r] ? arguments[r] : {};
536
+ r % 2 ? ownKeys(Object(t), !0).forEach((function(r) {
537
+ _defineProperty(e, r, t[r]);
538
+ })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach((function(r) {
539
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
540
+ }));
541
+ }
542
+ return e;
543
+ }
544
+
545
+ function _toConsumableArray(r) {
546
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
547
+ }
548
+
549
+ function _toPrimitive(t, r) {
550
+ if ("object" != typeof t || !t) return t;
551
+ var e = t[Symbol.toPrimitive];
552
+ if (void 0 !== e) {
553
+ var i = e.call(t, r || "default");
554
+ if ("object" != typeof i) return i;
583
555
  throw new TypeError("@@toPrimitive must return a primitive value.");
584
556
  }
585
- return (hint === "string" ? String : Number)(input);
557
+ return ("string" === r ? String : Number)(t);
558
+ }
559
+
560
+ function _toPropertyKey(t) {
561
+ var i = _toPrimitive(t, "string");
562
+ return "symbol" == typeof i ? i : i + "";
586
563
  }
587
564
 
588
- function _toPropertyKey(arg) {
589
- var key = _toPrimitive(arg, "string");
590
- return typeof key === "symbol" ? key : String(key);
565
+ function _typeof(o) {
566
+ "@babel/helpers - typeof";
567
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
568
+ return typeof o;
569
+ } : function(o) {
570
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
571
+ }, _typeof(o);
572
+ }
573
+
574
+ function _unsupportedIterableToArray(r, a) {
575
+ if (r) {
576
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
577
+ var t = {}.toString.call(r).slice(8, -1);
578
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
579
+ }
591
580
  }
592
581
 
593
582
  var store;
@@ -708,6 +697,20 @@ function getDefault(schema, dataset, config2) {
708
697
  return typeof schema["default"] === "function" ? schema["default"](dataset, config2) : schema["default"];
709
698
  }
710
699
 
700
+ function any() {
701
+ return {
702
+ kind: "schema",
703
+ type: "any",
704
+ reference: any,
705
+ expects: "any",
706
+ async: false,
707
+ _run: function _run(dataset) {
708
+ dataset.typed = true;
709
+ return dataset;
710
+ }
711
+ };
712
+ }
713
+
711
714
  function array(item, message) {
712
715
  return {
713
716
  kind: "schema",
@@ -793,16 +796,36 @@ function _boolean(message) {
793
796
  };
794
797
  }
795
798
 
796
- function function_(message) {
799
+ function literal(literal_, message) {
800
+ return {
801
+ kind: "schema",
802
+ type: "literal",
803
+ reference: literal,
804
+ expects: _stringify(literal_),
805
+ async: false,
806
+ literal: literal_,
807
+ message: message,
808
+ _run: function _run(dataset, config2) {
809
+ if (dataset.value === this.literal) {
810
+ dataset.typed = true;
811
+ } else {
812
+ _addIssue(this, "type", dataset, config2);
813
+ }
814
+ return dataset;
815
+ }
816
+ };
817
+ }
818
+
819
+ function number(message) {
797
820
  return {
798
821
  kind: "schema",
799
- type: "function",
800
- reference: function_,
801
- expects: "Function",
822
+ type: "number",
823
+ reference: number,
824
+ expects: "number",
802
825
  async: false,
803
826
  message: message,
804
827
  _run: function _run(dataset, config2) {
805
- if (typeof dataset.value === "function") {
828
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
806
829
  dataset.typed = true;
807
830
  } else {
808
831
  _addIssue(this, "type", dataset, config2);
@@ -1307,47 +1330,21 @@ const assertType = (validator, message) => data => {
1307
1330
  }
1308
1331
  };
1309
1332
 
1310
- var SafeFetchCommonRespondErrorType;
1311
-
1312
- (function(SafeFetchCommonRespondErrorType) {
1313
- SafeFetchCommonRespondErrorType["UnexpectedRespond"] = "UnexpectedRespond";
1314
- })(SafeFetchCommonRespondErrorType || (SafeFetchCommonRespondErrorType = {}));
1315
-
1316
- var SafeFetchErrorType;
1317
-
1318
- (function(SafeFetchErrorType) {
1319
- SafeFetchErrorType["HttpError"] = "HttpError";
1320
- SafeFetchErrorType["UnknownError"] = "UnknownError";
1321
- })(SafeFetchErrorType || (SafeFetchErrorType = {}));
1322
-
1323
- const safeFetch = async (input, init) => {
1324
- try {
1325
- const response = await fetch(input, init);
1326
- if (response.status > 299 || response.status < 200) {
1327
- return err({
1328
- type: SafeFetchErrorType.HttpError,
1329
- message: `HTTP error, status = ${response.status}`,
1330
- status: response.status
1331
- });
1332
- }
1333
- return ok(response);
1334
- } catch (error) {
1335
- return err({
1336
- type: SafeFetchErrorType.UnknownError,
1337
- message: "Unknown error",
1338
- cause: error
1339
- });
1340
- }
1341
- };
1342
-
1343
1333
  exports.MobileCredentialVerificationReasonType = void 0;
1344
1334
 
1345
1335
  (function(MobileCredentialVerificationReasonType) {
1346
- MobileCredentialVerificationReasonType["Expired"] = "expired";
1347
- MobileCredentialVerificationReasonType["Inactive"] = "inactive";
1348
- MobileCredentialVerificationReasonType["StatusRevoked"] = "invalid";
1349
- MobileCredentialVerificationReasonType["StatusSuspended"] = "suspended";
1350
- MobileCredentialVerificationReasonType["StatusUnknown"] = "unknown";
1336
+ MobileCredentialVerificationReasonType["TrustedIssuerCertificateExpired"] = "TrustedIssuerCertificateExpired";
1337
+ MobileCredentialVerificationReasonType["TrustedIssuerCertificateNotYetValid"] = "TrustedIssuerCertificateNotYetValid";
1338
+ MobileCredentialVerificationReasonType["IssuerNotTrusted"] = "IssuerNotTrusted";
1339
+ MobileCredentialVerificationReasonType["MobileCredentialInvalid"] = "MobileCredentialInvalid";
1340
+ MobileCredentialVerificationReasonType["MobileCredentialExpired"] = "MobileCredentialExpired";
1341
+ MobileCredentialVerificationReasonType["MobileCredentialNotYetValid"] = "MobileCredentialNotYetValid";
1342
+ MobileCredentialVerificationReasonType["InvalidSignerCertificate"] = "InvalidSignerCertificate";
1343
+ MobileCredentialVerificationReasonType["DeviceKeyInvalid"] = "DeviceKeyInvalid";
1344
+ MobileCredentialVerificationReasonType["UnsupportedCurve"] = "UnsupportedCurve";
1345
+ MobileCredentialVerificationReasonType["StatusRevoked"] = "StatusRevoked";
1346
+ MobileCredentialVerificationReasonType["StatusSuspended"] = "StatusSuspended";
1347
+ MobileCredentialVerificationReasonType["StatusUnknown"] = "StatusUnknown";
1351
1348
  })(exports.MobileCredentialVerificationReasonType || (exports.MobileCredentialVerificationReasonType = {}));
1352
1349
 
1353
1350
  exports.ClaimType = void 0;
@@ -1382,6 +1379,15 @@ exports.OpenidPresentationCredentialProfileSupported = void 0;
1382
1379
  OpenidPresentationCredentialProfileSupported["MOBILE"] = "mobile";
1383
1380
  })(exports.OpenidPresentationCredentialProfileSupported || (exports.OpenidPresentationCredentialProfileSupported = {}));
1384
1381
 
1382
+ var PresentationStatusCode;
1383
+
1384
+ (function(PresentationStatusCode) {
1385
+ PresentationStatusCode["AwaitingRequestRetrieval"] = "AwaitingRequestRetrieval";
1386
+ PresentationStatusCode["AwaitingResponse"] = "AwaitingResponse";
1387
+ PresentationStatusCode["ResponseSubmitted"] = "ResponseSubmitted";
1388
+ PresentationStatusCode["ResultReady"] = "ResultReady";
1389
+ })(PresentationStatusCode || (PresentationStatusCode = {}));
1390
+
1385
1391
  const CredentialQueryValidator = object({
1386
1392
  profile: picklist([ exports.OpenidPresentationCredentialProfileSupported.MOBILE ]),
1387
1393
  docType: string(),
@@ -1409,18 +1415,52 @@ const PresentationResultRelaxValidator = object({
1409
1415
  error: optional(unknown())
1410
1416
  });
1411
1417
 
1418
+ exports.Mode = void 0;
1419
+
1420
+ (function(Mode) {
1421
+ Mode["SameDevice"] = "sameDevice";
1422
+ Mode["CrossDevice"] = "crossDevice";
1423
+ })(exports.Mode || (exports.Mode = {}));
1424
+
1425
+ var SessionType;
1426
+
1427
+ (function(SessionType) {
1428
+ SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
1429
+ SessionType["Openid4vp"] = "openid4vp";
1430
+ })(SessionType || (SessionType = {}));
1431
+
1412
1432
  object({
1413
1433
  credentialQuery: array(CredentialQueryValidator),
1414
1434
  challenge: string(),
1415
1435
  redirectUri: optional(string()),
1416
- walletProviderId: optional(string())
1436
+ walletProviderId: optional(string()),
1437
+ dcApiSupported: optional(_boolean())
1438
+ });
1439
+
1440
+ const CreateSessionDigitalCredentialsValidator = object({
1441
+ type: literal(SessionType.DigitalCredentialsApi),
1442
+ sessionId: string(),
1443
+ sessionKey: string(),
1444
+ sessionTtl: number(),
1445
+ request: record(string(), any())
1417
1446
  });
1418
1447
 
1419
- const CreateSessionResponseValidator = object({
1448
+ const CreateSessionOpenId4vpResponseValidator = object({
1449
+ type: optional(literal(SessionType.Openid4vp)),
1420
1450
  sessionId: string(),
1451
+ sessionKey: string(),
1421
1452
  sessionUrl: string()
1422
1453
  });
1423
1454
 
1455
+ const CreateSessionResponseValidator = union([ CreateSessionDigitalCredentialsValidator, CreateSessionOpenId4vpResponseValidator ]);
1456
+
1457
+ const GetSessionStatusResponseValidator = union([ object({
1458
+ status: picklist([ PresentationStatusCode.ResultReady ]),
1459
+ responseCode: optional(string())
1460
+ }), object({
1461
+ status: string()
1462
+ }) ]);
1463
+
1424
1464
  var LocalStorageKey;
1425
1465
 
1426
1466
  (function(LocalStorageKey) {
@@ -1428,12 +1468,9 @@ var LocalStorageKey;
1428
1468
  LocalStorageKey["sessionId"] = "mattr_sid";
1429
1469
  })(LocalStorageKey || (LocalStorageKey = {}));
1430
1470
 
1431
- exports.Mode = void 0;
1471
+ const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
1432
1472
 
1433
- (function(Mode) {
1434
- Mode["sameDevice"] = "sameDevice";
1435
- Mode["crossDevice"] = "crossDevice";
1436
- })(exports.Mode || (exports.Mode = {}));
1473
+ const MATTR_SDK_VERSION_VALUE = "2.0.0";
1437
1474
 
1438
1475
  var MessageEventDataType;
1439
1476
 
@@ -1443,50 +1480,106 @@ var MessageEventDataType;
1443
1480
  MessageEventDataType["PresentationAbort"] = "PresentationAbort";
1444
1481
  })(MessageEventDataType || (MessageEventDataType = {}));
1445
1482
 
1446
- const RequestCredentialsSameDeviceOptionsValidator = object({
1447
- credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
1448
- redirectUri: string(),
1449
- challenge: optional(string()),
1483
+ const OpenId4vpConfigSameDeviceOptionsValidator = object({
1450
1484
  walletProviderId: optional(string()),
1451
- mode: picklist([ exports.Mode.sameDevice ])
1485
+ mode: literal(exports.Mode.SameDevice),
1486
+ redirectUri: string()
1452
1487
  });
1453
1488
 
1454
- const RequestCredentialsCrossDeviceOptionsValidator = object({
1455
- credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
1456
- crossDeviceCallback: object({
1457
- onComplete: function_(),
1458
- onFailure: function_()
1459
- }),
1460
- challenge: optional(string()),
1489
+ const OpenId4vpConfigCrossDeviceOptionsValidator = object({
1461
1490
  walletProviderId: optional(string()),
1462
- mode: picklist([ exports.Mode.crossDevice ])
1491
+ mode: literal(exports.Mode.CrossDevice)
1463
1492
  });
1464
1493
 
1465
- const RequestCredentialsAutoDetectDeviceOptionsValidator = object({
1466
- credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
1467
- crossDeviceCallback: object({
1468
- onComplete: function_(),
1469
- onFailure: function_()
1470
- }),
1471
- redirectUri: string(),
1472
- challenge: optional(string()),
1494
+ const OpenId4vpConfigAutoDetectOptionsValidator = object({
1473
1495
  walletProviderId: optional(string()),
1474
- mode: optional(picklist([ exports.Mode.crossDevice, exports.Mode.sameDevice ]))
1496
+ redirectUri: string(),
1497
+ mode: optional(picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
1475
1498
  });
1476
1499
 
1477
- const RequestCredentialsOptionsValidator = union([ RequestCredentialsSameDeviceOptionsValidator, RequestCredentialsCrossDeviceOptionsValidator, RequestCredentialsAutoDetectDeviceOptionsValidator ]);
1500
+ const RequestCredentialsOptionsValidator = object({
1501
+ credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
1502
+ challenge: optional(string()),
1503
+ openid4vpConfiguration: optional(union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
1504
+ });
1478
1505
 
1479
1506
  exports.RequestCredentialsErrorType = void 0;
1480
1507
 
1481
1508
  (function(RequestCredentialsErrorType) {
1482
1509
  RequestCredentialsErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
1510
+ RequestCredentialsErrorType["Timeout"] = "Timeout";
1511
+ RequestCredentialsErrorType["Abort"] = "Abort";
1483
1512
  })(exports.RequestCredentialsErrorType || (exports.RequestCredentialsErrorType = {}));
1484
1513
 
1514
+ var RequestCredentialsErrorMessage;
1515
+
1516
+ (function(RequestCredentialsErrorMessage) {
1517
+ RequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
1518
+ RequestCredentialsErrorMessage["FailedToGetSessionStatus"] = "Failed to get session status";
1519
+ RequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
1520
+ RequestCredentialsErrorMessage["FailedToVerifyCredentialResponse"] = "Failed to verify credential response";
1521
+ RequestCredentialsErrorMessage["MissingOpenId4vpConfig"] = "Identified openid4vp session, but missing openId4vpConfiguration on `requestCredentials`";
1522
+ RequestCredentialsErrorMessage["DcApiError"] = "Failed to request credentials with Digital Credentials API";
1523
+ RequestCredentialsErrorMessage["DcApiResponseParseError"] = "Failed to parse response from Digital Credentials API";
1524
+ RequestCredentialsErrorMessage["Abort"] = "User aborted the session";
1525
+ RequestCredentialsErrorMessage["Timeout"] = "User session timeout";
1526
+ })(RequestCredentialsErrorMessage || (RequestCredentialsErrorMessage = {}));
1527
+
1528
+ exports.AbortSessionErrorType = void 0;
1529
+
1530
+ (function(AbortSessionErrorType) {
1531
+ AbortSessionErrorType["AbortSessionFailed"] = "AbortSessionFailed";
1532
+ })(exports.AbortSessionErrorType || (exports.AbortSessionErrorType = {}));
1533
+
1534
+ var AbortSessionErrorMessage;
1535
+
1536
+ (function(AbortSessionErrorMessage) {
1537
+ AbortSessionErrorMessage["FailedToAbortSession"] = "Failed to abort session";
1538
+ })(AbortSessionErrorMessage || (AbortSessionErrorMessage = {}));
1539
+
1485
1540
  const InitialiseOptionsValidator = object({
1486
- apiBaseUrl: string(),
1487
- applicationId: optional(string())
1541
+ apiBaseUrl: pipe(string(), nonEmpty("Must not be empty")),
1542
+ applicationId: pipe(string(), nonEmpty("Must not be empty"))
1488
1543
  });
1489
1544
 
1545
+ var SafeFetchCommonResponseErrorType;
1546
+
1547
+ (function(SafeFetchCommonResponseErrorType) {
1548
+ SafeFetchCommonResponseErrorType["UnexpectedResponse"] = "UnexpectedResponse";
1549
+ })(SafeFetchCommonResponseErrorType || (SafeFetchCommonResponseErrorType = {}));
1550
+
1551
+ var SafeFetchErrorType;
1552
+
1553
+ (function(SafeFetchErrorType) {
1554
+ SafeFetchErrorType["HttpError"] = "HttpError";
1555
+ SafeFetchErrorType["UnknownError"] = "UnknownError";
1556
+ })(SafeFetchErrorType || (SafeFetchErrorType = {}));
1557
+
1558
+ const safeFetch = async (input, init) => {
1559
+ try {
1560
+ const headers = Object.assign(Object.assign({}, init === null || init === void 0 ? void 0 : init.headers), {
1561
+ [MATTR_SDK_VERSION_HEADER]: `verifier-sdk-web/${MATTR_SDK_VERSION_VALUE}`
1562
+ });
1563
+ const response = await fetch(input, Object.assign(Object.assign({}, init), {
1564
+ headers: headers
1565
+ }));
1566
+ if (response.status > 299 || response.status < 200) {
1567
+ return err({
1568
+ type: SafeFetchErrorType.HttpError,
1569
+ message: `HTTP error, status = ${response.status}`,
1570
+ status: response.status
1571
+ });
1572
+ }
1573
+ return ok(response);
1574
+ } catch (error) {
1575
+ return err({
1576
+ type: SafeFetchErrorType.UnknownError,
1577
+ message: "Unknown error",
1578
+ cause: error
1579
+ });
1580
+ }
1581
+ };
1582
+
1490
1583
  let initialiseOptions = undefined;
1491
1584
 
1492
1585
  var InitialiseErrorMessage;
@@ -1502,6 +1595,40 @@ const initialise = options => {
1502
1595
 
1503
1596
  const getInitialiseOptions = () => initialiseOptions;
1504
1597
 
1598
+ let sessionAbortController = undefined;
1599
+
1600
+ let _sessionId = undefined;
1601
+
1602
+ let _sessionKey = undefined;
1603
+
1604
+ const getActiveSession = () => {
1605
+ const sessionId = _sessionId;
1606
+ const sessionKey = _sessionKey;
1607
+ if (sessionId) {
1608
+ return {
1609
+ sessionId: sessionId,
1610
+ sessionKey: sessionKey
1611
+ };
1612
+ }
1613
+ return undefined;
1614
+ };
1615
+
1616
+ const setActiveSession = session => {
1617
+ const {sessionId: sessionId, sessionKey: sessionKey} = session;
1618
+ _sessionId = sessionId;
1619
+ _sessionKey = sessionKey;
1620
+ const abortController = new AbortController;
1621
+ sessionAbortController = abortController;
1622
+ return abortController;
1623
+ };
1624
+
1625
+ const removeActiveSession = () => {
1626
+ sessionAbortController === null || sessionAbortController === void 0 ? void 0 : sessionAbortController.abort();
1627
+ sessionAbortController = undefined;
1628
+ _sessionKey = undefined;
1629
+ _sessionId = undefined;
1630
+ };
1631
+
1505
1632
  var isMobile_1 = isMobile;
1506
1633
 
1507
1634
  var isMobile_2 = isMobile;
@@ -1537,6 +1664,24 @@ const defaultRetryDelay = attempt => Math.pow(2, attempt) * 1e3;
1537
1664
 
1538
1665
  const defaultRetry = 2;
1539
1666
 
1667
+ const withRetry = async (fn, options) => {
1668
+ const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0} = options;
1669
+ try {
1670
+ return await fn();
1671
+ } catch (err) {
1672
+ if (retries > 0) {
1673
+ const delay = typeof retryDelay === "function" ? retryDelay(attempt) : retryDelay;
1674
+ await new Promise((resolve => setTimeout(resolve, delay)));
1675
+ return await withRetry(fn, Object.assign(Object.assign({}, options), {
1676
+ retries: retries - 1,
1677
+ retryDelay: retryDelay,
1678
+ attempt: attempt + 1
1679
+ }));
1680
+ }
1681
+ throw err;
1682
+ }
1683
+ };
1684
+
1540
1685
  const withRetrySafeFetch = async (fn, options) => {
1541
1686
  const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0, retryHttpStatus: retryHttpStatus} = options;
1542
1687
  const result = await fn();
@@ -1565,17 +1710,15 @@ const getHashParamValue = (hash, param) => {
1565
1710
  return urlParams.get(param);
1566
1711
  };
1567
1712
 
1568
- const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, applicationId: applicationId, walletProviderId: walletProviderId}) => {
1569
- const postData = Object.assign(Object.assign(Object.assign({
1713
+ const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
1714
+ const postData = {
1570
1715
  credentialQuery: credentialQuery,
1571
- challenge: challenge
1572
- }, redirectUri ? {
1573
- redirectUri: redirectUri
1574
- } : {}), applicationId ? {
1575
- applicationId: applicationId
1576
- } : {}), walletProviderId ? {
1577
- walletProviderId: walletProviderId
1578
- } : {});
1716
+ challenge: challenge,
1717
+ applicationId: applicationId,
1718
+ redirectUri: redirectUri,
1719
+ walletProviderId: walletProviderId,
1720
+ dcApiSupported: dcApiSupported
1721
+ };
1579
1722
  const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
1580
1723
  method: "POST",
1581
1724
  headers: {
@@ -1589,8 +1732,42 @@ const createSession = async ({credentialQuery: credentialQuery, challenge: chall
1589
1732
  const data = await responseResult.value.json();
1590
1733
  if (!isType(CreateSessionResponseValidator)(data)) {
1591
1734
  return err({
1592
- type: SafeFetchCommonRespondErrorType.UnexpectedRespond,
1593
- message: "Create session return unsupported response"
1735
+ type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
1736
+ message: "Create session returned unsupported response"
1737
+ });
1738
+ }
1739
+ return ok(data);
1740
+ };
1741
+
1742
+ const abortSession = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
1743
+ const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/abort`, {
1744
+ method: "POST",
1745
+ headers: {
1746
+ "Content-Type": "application/json",
1747
+ Authorization: `Bearer ${sessionKey}`
1748
+ }
1749
+ });
1750
+ if (responseResult.isErr()) {
1751
+ return err(responseResult.error);
1752
+ }
1753
+ return ok(undefined);
1754
+ };
1755
+
1756
+ const getSessionStatus = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
1757
+ const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/status`, {
1758
+ method: "GET",
1759
+ headers: {
1760
+ Authorization: `Bearer ${sessionKey}`
1761
+ }
1762
+ });
1763
+ if (responseResult.isErr()) {
1764
+ return err(responseResult.error);
1765
+ }
1766
+ const data = await responseResult.value.json();
1767
+ if (!isType(GetSessionStatusResponseValidator)(data)) {
1768
+ return err({
1769
+ type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
1770
+ message: "Get session status return unsupported response"
1594
1771
  });
1595
1772
  }
1596
1773
  return ok(data);
@@ -1618,7 +1795,7 @@ const exchangeSessionResult = async ({challenge: challenge, responseCode: respon
1618
1795
  const data = await responseResult.value.json();
1619
1796
  if (!isType(PresentationResultRelaxValidator)(data)) {
1620
1797
  return err({
1621
- type: SafeFetchCommonRespondErrorType.UnexpectedRespond,
1798
+ type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
1622
1799
  message: "Exchange session result return unsupported response",
1623
1800
  details: {
1624
1801
  data: data
@@ -1633,22 +1810,7 @@ const isMobileDetect = userAgent => isMobile_2({
1633
1810
  tablet: false
1634
1811
  });
1635
1812
 
1636
- exports.CrossDeviceCallbackErrorType = void 0;
1637
-
1638
- (function(CrossDeviceCallbackErrorType) {
1639
- CrossDeviceCallbackErrorType["Timeout"] = "Timeout";
1640
- CrossDeviceCallbackErrorType["Abort"] = "Abort";
1641
- CrossDeviceCallbackErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
1642
- })(exports.CrossDeviceCallbackErrorType || (exports.CrossDeviceCallbackErrorType = {}));
1643
-
1644
- var CrossDeviceRequestCredentialsErrorMessage;
1645
-
1646
- (function(CrossDeviceRequestCredentialsErrorMessage) {
1647
- CrossDeviceRequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
1648
- CrossDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
1649
- CrossDeviceRequestCredentialsErrorMessage["Abort"] = "User aborted the session";
1650
- CrossDeviceRequestCredentialsErrorMessage["Timeout"] = "User session timeout";
1651
- })(CrossDeviceRequestCredentialsErrorMessage || (CrossDeviceRequestCredentialsErrorMessage = {}));
1813
+ const getVersion = () => MATTR_SDK_VERSION_VALUE;
1652
1814
 
1653
1815
  var WindowEventListenerType;
1654
1816
 
@@ -1656,10 +1818,13 @@ var WindowEventListenerType;
1656
1818
  WindowEventListenerType["message"] = "message";
1657
1819
  })(WindowEventListenerType || (WindowEventListenerType = {}));
1658
1820
 
1659
- let listener;
1821
+ let listener = undefined;
1660
1822
 
1661
1823
  const removeWindowMessageEventListener = () => {
1662
- window.removeEventListener(WindowEventListenerType.message, listener, false);
1824
+ if (listener) {
1825
+ window.removeEventListener(WindowEventListenerType.message, listener, false);
1826
+ }
1827
+ listener = undefined;
1663
1828
  };
1664
1829
 
1665
1830
  const closeCrossDeviceModal = options => {
@@ -1671,8 +1836,7 @@ const closeCrossDeviceModal = options => {
1671
1836
  };
1672
1837
 
1673
1838
  const receiveMessageHandler = options => async event => {
1674
- const {crossDeviceCallback: crossDeviceCallback, container: container, sessionId: sessionId, apiBaseUrl: apiBaseUrl, challenge: challenge} = options;
1675
- const {onComplete: onComplete, onFailure: onFailure} = crossDeviceCallback;
1839
+ const {onComplete: onComplete, onFailure: onFailure, container: container, sessionId: sessionId, apiBaseUrl: apiBaseUrl, challenge: challenge} = options;
1676
1840
  if (event.origin !== apiBaseUrl) {
1677
1841
  return;
1678
1842
  }
@@ -1686,8 +1850,8 @@ const receiveMessageHandler = options => async event => {
1686
1850
  });
1687
1851
  if (result.isErr()) {
1688
1852
  onFailure({
1689
- type: exports.CrossDeviceCallbackErrorType.RequestCredentialsFailed,
1690
- message: CrossDeviceRequestCredentialsErrorMessage.FailedToGetSessionResult
1853
+ type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
1854
+ message: RequestCredentialsErrorMessage.FailedToGetSessionResult
1691
1855
  });
1692
1856
  closeCrossDeviceModal({
1693
1857
  container: container
@@ -1695,8 +1859,9 @@ const receiveMessageHandler = options => async event => {
1695
1859
  return;
1696
1860
  }
1697
1861
  onComplete({
1698
- result: result.value,
1699
- sessionId: result.value.sessionId
1862
+ result: "challenge" in result.value ? result.value : undefined,
1863
+ sessionId: result.value.sessionId,
1864
+ sessionCompletedInRedirect: false
1700
1865
  });
1701
1866
  closeCrossDeviceModal({
1702
1867
  container: container
@@ -1705,8 +1870,8 @@ const receiveMessageHandler = options => async event => {
1705
1870
  }
1706
1871
  if (event.data.type === MessageEventDataType.PresentationTimeout) {
1707
1872
  onFailure({
1708
- type: exports.CrossDeviceCallbackErrorType.Timeout,
1709
- message: CrossDeviceRequestCredentialsErrorMessage.Timeout
1873
+ type: exports.RequestCredentialsErrorType.Timeout,
1874
+ message: RequestCredentialsErrorMessage.Timeout
1710
1875
  });
1711
1876
  closeCrossDeviceModal({
1712
1877
  container: container
@@ -1715,8 +1880,8 @@ const receiveMessageHandler = options => async event => {
1715
1880
  }
1716
1881
  if (event.data.type === MessageEventDataType.PresentationAbort) {
1717
1882
  onFailure({
1718
- type: exports.CrossDeviceCallbackErrorType.Abort,
1719
- message: CrossDeviceRequestCredentialsErrorMessage.Abort
1883
+ type: exports.RequestCredentialsErrorType.Abort,
1884
+ message: RequestCredentialsErrorMessage.Abort
1720
1885
  });
1721
1886
  closeCrossDeviceModal({
1722
1887
  container: container
@@ -1741,41 +1906,171 @@ const openCrossDeviceModal = options => {
1741
1906
  return modalContainer;
1742
1907
  };
1743
1908
 
1744
- const requestCredentialsCrossDevice = async options => {
1745
- const {challenge: challenge, walletProviderId: walletProviderId, credentialQuery: credentialQuery, crossDeviceCallback: crossDeviceCallback, initialiseOptions: initialiseOptions} = options;
1746
- const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
1747
- const createSessionResult = await createSession({
1748
- credentialQuery: credentialQuery,
1749
- challenge: challenge,
1909
+ const requestCredentialsWithCrossDevice = async options => {
1910
+ const {challenge: challenge, apiBaseUrl: apiBaseUrl, sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = options;
1911
+ const container = openCrossDeviceModal({
1912
+ sessionUrl: sessionUrl
1913
+ });
1914
+ return await new Promise((resolve => {
1915
+ const abortController = setActiveSession({
1916
+ sessionId: sessionId,
1917
+ sessionKey: sessionKey
1918
+ });
1919
+ abortController.signal.addEventListener("abort", (() => {
1920
+ closeCrossDeviceModal({
1921
+ container: container
1922
+ });
1923
+ resolve(err({
1924
+ type: exports.RequestCredentialsErrorType.Abort,
1925
+ message: RequestCredentialsErrorMessage.Abort
1926
+ }));
1927
+ }));
1928
+ removeWindowMessageEventListener();
1929
+ listener = receiveMessageHandler({
1930
+ container: container,
1931
+ sessionId: sessionId,
1932
+ apiBaseUrl: apiBaseUrl,
1933
+ challenge: challenge,
1934
+ onComplete: data => resolve(ok(data)),
1935
+ onFailure: error => resolve(err(error))
1936
+ });
1937
+ window.addEventListener(WindowEventListenerType.message, listener, false);
1938
+ }));
1939
+ };
1940
+
1941
+ const requestCredentialsWithDigitalCredentialsApi = async options => {
1942
+ const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request} = options;
1943
+ const credentialResponseResult = await getCredentials(request);
1944
+ if (credentialResponseResult.isErr()) {
1945
+ await abortSession({
1946
+ apiBaseUrl: apiBaseUrl,
1947
+ sessionId: sessionId,
1948
+ sessionKey: sessionKey
1949
+ });
1950
+ return err(credentialResponseResult.error);
1951
+ }
1952
+ const credentialResponse = credentialResponseResult.value;
1953
+ const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
1954
+ if (parsedCredentialResponseResult.isErr()) {
1955
+ await abortSession({
1956
+ apiBaseUrl: apiBaseUrl,
1957
+ sessionId: sessionId,
1958
+ sessionKey: sessionKey
1959
+ });
1960
+ return err(parsedCredentialResponseResult.error);
1961
+ }
1962
+ const parsedCredentialResponse = parsedCredentialResponseResult.value;
1963
+ const credentialVerificationResult = await verifyCredentialResponse({
1750
1964
  apiBaseUrl: apiBaseUrl,
1751
- applicationId: applicationId,
1752
- walletProviderId: walletProviderId
1965
+ sessionId: sessionId,
1966
+ sessionKey: sessionKey,
1967
+ challenge: challenge,
1968
+ protocol: parsedCredentialResponse.protocol,
1969
+ data: parsedCredentialResponse.data
1753
1970
  });
1754
- if (createSessionResult.isErr()) {
1971
+ if (credentialVerificationResult.isErr()) {
1755
1972
  return err({
1756
1973
  type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
1757
- message: CrossDeviceRequestCredentialsErrorMessage.FailedToCreateSession,
1758
- cause: createSessionResult.error
1974
+ message: RequestCredentialsErrorMessage.FailedToVerifyCredentialResponse,
1975
+ cause: credentialVerificationResult.error
1759
1976
  });
1760
1977
  }
1761
- const {sessionUrl: sessionUrl, sessionId: sessionId} = createSessionResult.value;
1762
- const container = openCrossDeviceModal({
1763
- sessionUrl: sessionUrl,
1764
- crossDeviceCallback: crossDeviceCallback
1978
+ return ok(credentialVerificationResult.value);
1979
+ };
1980
+
1981
+ const getCredentials = async request => {
1982
+ try {
1983
+ const credentialResponse = await navigator.credentials.get(request);
1984
+ return ok(credentialResponse);
1985
+ } catch (exception) {
1986
+ return err({
1987
+ type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
1988
+ message: RequestCredentialsErrorMessage.DcApiError,
1989
+ cause: exception
1990
+ });
1991
+ }
1992
+ };
1993
+
1994
+ const parseCredentialResponse = credentialResponse => {
1995
+ if (!credentialResponse) {
1996
+ return err({
1997
+ type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
1998
+ message: RequestCredentialsErrorMessage.DcApiResponseParseError,
1999
+ details: {
2000
+ response: credentialResponse
2001
+ }
2002
+ });
2003
+ }
2004
+ if (typeof credentialResponse === "object") {
2005
+ return ok(credentialResponse);
2006
+ }
2007
+ if (typeof credentialResponse === "string") {
2008
+ try {
2009
+ const parsed = JSON.parse(credentialResponse);
2010
+ return ok(parsed);
2011
+ } catch (_a) {
2012
+ return err({
2013
+ type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
2014
+ message: RequestCredentialsErrorMessage.DcApiResponseParseError,
2015
+ details: {
2016
+ response: credentialResponse
2017
+ }
2018
+ });
2019
+ }
2020
+ }
2021
+ return err({
2022
+ type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
2023
+ message: RequestCredentialsErrorMessage.DcApiResponseParseError,
2024
+ details: {
2025
+ response: credentialResponse
2026
+ }
1765
2027
  });
1766
- listener = receiveMessageHandler({
1767
- crossDeviceCallback: crossDeviceCallback,
1768
- container: container,
1769
- sessionId: sessionId,
1770
- apiBaseUrl: apiBaseUrl,
2028
+ };
2029
+
2030
+ const verifyCredentialResponse = async options => {
2031
+ const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, protocol: protocol, data: data} = options;
2032
+ const requestBody = {
2033
+ protocol: protocol,
2034
+ data: data,
1771
2035
  challenge: challenge
2036
+ };
2037
+ const credentialVerificationResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/dc-api/response`, {
2038
+ method: "POST",
2039
+ headers: {
2040
+ "Content-Type": "application/json",
2041
+ Authorization: `Bearer ${sessionKey}`
2042
+ },
2043
+ body: JSON.stringify(requestBody)
1772
2044
  });
1773
- window.addEventListener(WindowEventListenerType.message, listener, false);
1774
- return ok({
1775
- sessionId: sessionId
1776
- });
2045
+ if (credentialVerificationResult.isErr()) {
2046
+ return err(credentialVerificationResult.error);
2047
+ }
2048
+ const credentialVerificationResponse = await credentialVerificationResult.value.json();
2049
+ if (!isType(PresentationResultRelaxValidator)(credentialVerificationResponse)) {
2050
+ return err({
2051
+ type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
2052
+ message: "Verify credential returned unsupported response",
2053
+ details: {
2054
+ response: credentialVerificationResponse
2055
+ }
2056
+ });
2057
+ }
2058
+ return ok(credentialVerificationResponse);
1777
2059
  };
1778
2060
 
2061
+ const isDigitalCredentialsApiSupported = () => {
2062
+ var _a;
2063
+ return "DigitalCredential" in window && typeof window.DigitalCredential === "function" && typeof ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.credentials) === null || _a === void 0 ? void 0 : _a.get) === "function";
2064
+ };
2065
+
2066
+ const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
2067
+
2068
+ const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
2069
+
2070
+ const SESSION_STATUS_POLLING_INTERVAL_MS = 3e3;
2071
+
2072
+ const SESSION_STATUS_POLLING_INITIAL_DELAY_MS = 3e3;
2073
+
1779
2074
  var SameDeviceRequestCredentialsErrorMessage;
1780
2075
 
1781
2076
  (function(SameDeviceRequestCredentialsErrorMessage) {
@@ -1784,65 +2079,134 @@ var SameDeviceRequestCredentialsErrorMessage;
1784
2079
  })(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
1785
2080
 
1786
2081
  const requestCredentialsSameDevice = async options => {
1787
- const {challenge: challenge, credentialQuery: credentialQuery, redirectUri: redirectUri, walletProviderId: walletProviderId, initialiseOptions: initialiseOptions} = options;
1788
- const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
2082
+ const {challenge: challenge, apiBaseUrl: apiBaseUrl, applicationId: applicationId, sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = options;
2083
+ const abortController = setActiveSession({
2084
+ sessionId: sessionId,
2085
+ sessionKey: sessionKey
2086
+ });
2087
+ window.localStorage.setItem(LocalStorageKey.sessionId, sessionId);
1789
2088
  window.localStorage.setItem(LocalStorageKey.challenge, challenge);
1790
- const storedChallenge = window.localStorage.getItem(LocalStorageKey.challenge);
1791
- if (!storedChallenge) {
1792
- return err({
1793
- type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
1794
- message: SameDeviceRequestCredentialsErrorMessage.FailedToStoreChallenge
2089
+ window.location.assign(sessionUrl);
2090
+ await sleep(SESSION_STATUS_POLLING_INITIAL_DELAY_MS);
2091
+ const checkResult = await withRetry((async () => {
2092
+ const statusResult = await getSessionStatus({
2093
+ apiBaseUrl: apiBaseUrl,
2094
+ applicationId: applicationId,
2095
+ sessionId: sessionId,
2096
+ sessionKey: sessionKey
1795
2097
  });
2098
+ if (abortController.signal.aborted) {
2099
+ return err({
2100
+ type: exports.RequestCredentialsErrorType.Abort,
2101
+ message: RequestCredentialsErrorMessage.Abort
2102
+ });
2103
+ }
2104
+ if (statusResult.isErr()) {
2105
+ if (statusResult.error.status === 404) {
2106
+ return err({
2107
+ type: exports.RequestCredentialsErrorType.Timeout,
2108
+ message: RequestCredentialsErrorMessage.Timeout
2109
+ });
2110
+ }
2111
+ throw Error("Unexpected status response. Retry");
2112
+ }
2113
+ if (statusResult.value.status !== PresentationStatusCode.ResultReady) {
2114
+ throw Error("Result is not ready. Retry");
2115
+ }
2116
+ return ok(undefined);
2117
+ }), {
2118
+ retries: SESSION_STATUS_POLLING_MAX_RETRY,
2119
+ retryDelay: SESSION_STATUS_POLLING_INTERVAL_MS
2120
+ });
2121
+ if (checkResult.isErr()) {
2122
+ return err(checkResult.error);
1796
2123
  }
2124
+ window.close();
2125
+ return ok({
2126
+ sessionId: sessionId,
2127
+ sessionCompletedInRedirect: true
2128
+ });
2129
+ };
2130
+
2131
+ const requestCredentials = async options => {
2132
+ var _a;
2133
+ const initialiseOptions = getInitialiseOptions();
2134
+ if (!initialiseOptions) {
2135
+ throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
2136
+ }
2137
+ assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
2138
+ const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
2139
+ const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
2140
+ const dcApiSupported = isDigitalCredentialsApiSupported();
2141
+ const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
1797
2142
  const createSessionResult = await createSession({
1798
2143
  credentialQuery: credentialQuery,
1799
- challenge: storedChallenge,
1800
- redirectUri: redirectUri,
2144
+ challenge: challenge,
2145
+ redirectUri: openId4VpRedirectUri,
2146
+ walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
1801
2147
  apiBaseUrl: apiBaseUrl,
1802
2148
  applicationId: applicationId,
1803
- walletProviderId: walletProviderId
2149
+ dcApiSupported: dcApiSupported
1804
2150
  });
1805
2151
  if (createSessionResult.isErr()) {
1806
2152
  return err({
1807
2153
  type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
1808
- message: SameDeviceRequestCredentialsErrorMessage.FailedToCreateSession,
2154
+ message: RequestCredentialsErrorMessage.FailedToCreateSession,
1809
2155
  cause: createSessionResult.error
1810
2156
  });
1811
2157
  }
1812
- const {sessionUrl: sessionUrl, sessionId: sessionId} = createSessionResult.value;
1813
- window.localStorage.setItem(LocalStorageKey.sessionId, sessionId);
1814
- window.location.assign(sessionUrl);
1815
- return ok({
2158
+ const session = createSessionResult.value;
2159
+ const {sessionKey: sessionKey, sessionId: sessionId} = session;
2160
+ if (session.type === SessionType.DigitalCredentialsApi) {
2161
+ const {request: request} = session;
2162
+ return await requestCredentialsWithDigitalCredentialsApi({
2163
+ apiBaseUrl: apiBaseUrl,
2164
+ request: request,
2165
+ sessionId: sessionId,
2166
+ sessionKey: sessionKey,
2167
+ challenge: challenge
2168
+ });
2169
+ }
2170
+ if (!openid4vpConfiguration) {
2171
+ return err({
2172
+ type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
2173
+ message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
2174
+ });
2175
+ }
2176
+ const {sessionUrl: sessionUrl} = session;
2177
+ if (openId4VpRedirectUri) {
2178
+ return await requestCredentialsSameDevice({
2179
+ challenge: challenge,
2180
+ apiBaseUrl: apiBaseUrl,
2181
+ applicationId: applicationId,
2182
+ sessionUrl: sessionUrl,
2183
+ sessionKey: sessionKey,
2184
+ sessionId: sessionId
2185
+ });
2186
+ }
2187
+ return await requestCredentialsWithCrossDevice({
2188
+ challenge: challenge,
2189
+ apiBaseUrl: apiBaseUrl,
2190
+ sessionUrl: sessionUrl,
2191
+ sessionKey: sessionKey,
1816
2192
  sessionId: sessionId
1817
2193
  });
1818
2194
  };
1819
2195
 
1820
- const requestCredentials = async options => {
1821
- var _a;
1822
- const initialiseOptions = getInitialiseOptions();
1823
- if (!initialiseOptions) {
1824
- throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
2196
+ const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
2197
+ if (!openid4vpConfiguration) {
2198
+ return undefined;
1825
2199
  }
1826
- assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
1827
- const {challenge: challenge = generateChallenge()} = options;
1828
- const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : isMobileDetect(navigator.userAgent) ? exports.Mode.sameDevice : exports.Mode.crossDevice;
1829
- if (mode === exports.Mode.sameDevice && "redirectUri" in options) {
1830
- return await requestCredentialsSameDevice(Object.assign(Object.assign({}, options), {
1831
- initialiseOptions: initialiseOptions,
1832
- challenge: challenge,
1833
- mode: mode
1834
- }));
2200
+ let detectedMode;
2201
+ if (openid4vpConfiguration && openid4vpConfiguration.mode) {
2202
+ detectedMode = openid4vpConfiguration.mode;
2203
+ } else {
2204
+ detectedMode = isMobileDetect(navigator.userAgent) ? exports.Mode.SameDevice : exports.Mode.CrossDevice;
1835
2205
  }
1836
- if (mode === exports.Mode.crossDevice && "crossDeviceCallback" in options) {
1837
- return await requestCredentialsCrossDevice(Object.assign(Object.assign({}, options), {
1838
- initialiseOptions: initialiseOptions,
1839
- challenge: challenge,
1840
- mode: mode
1841
- }));
2206
+ if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
2207
+ return openid4vpConfiguration.redirectUri;
1842
2208
  }
1843
- throw new Exception("Invalid request credential options", {
1844
- data: options
1845
- });
2209
+ return undefined;
1846
2210
  };
1847
2211
 
1848
2212
  exports.HandleRedirectCallbackErrorType = void 0;
@@ -1856,7 +2220,7 @@ var HandleRedirectCallbackErrorMessage;
1856
2220
  (function(HandleRedirectCallbackErrorMessage) {
1857
2221
  HandleRedirectCallbackErrorMessage["FailedToFindResponseCode"] = "Failed to find response code";
1858
2222
  HandleRedirectCallbackErrorMessage["FailedToFindChallenge"] = "Failed to find challenge";
1859
- HandleRedirectCallbackErrorMessage["FailedToFindSessionId"] = "Failed to find sessionId";
2223
+ HandleRedirectCallbackErrorMessage["FailedToFindActiveSession"] = "Failed to find active session";
1860
2224
  HandleRedirectCallbackErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
1861
2225
  })(HandleRedirectCallbackErrorMessage || (HandleRedirectCallbackErrorMessage = {}));
1862
2226
 
@@ -1873,18 +2237,12 @@ const handleRedirectCallback = async () => {
1873
2237
  message: HandleRedirectCallbackErrorMessage.FailedToFindResponseCode
1874
2238
  });
1875
2239
  }
1876
- const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
1877
- if (!challenge) {
1878
- return err({
1879
- type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
1880
- message: HandleRedirectCallbackErrorMessage.FailedToFindChallenge
1881
- });
1882
- }
1883
2240
  const sessionId = window.localStorage.getItem(LocalStorageKey.sessionId);
1884
- if (!sessionId) {
2241
+ const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
2242
+ if (!sessionId || !challenge) {
1885
2243
  return err({
1886
2244
  type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
1887
- message: HandleRedirectCallbackErrorMessage.FailedToFindSessionId
2245
+ message: HandleRedirectCallbackErrorMessage.FailedToFindActiveSession
1888
2246
  });
1889
2247
  }
1890
2248
  const result = await exchangeSessionResult({
@@ -1901,20 +2259,52 @@ const handleRedirectCallback = async () => {
1901
2259
  });
1902
2260
  }
1903
2261
  return ok({
1904
- result: result.value,
2262
+ result: "challenge" in result.value ? result.value : undefined,
1905
2263
  sessionId: result.value.sessionId
1906
2264
  });
1907
2265
  };
1908
2266
 
2267
+ const abortCredentialRequest = async () => {
2268
+ const initialiseOptions = getInitialiseOptions();
2269
+ if (!initialiseOptions) {
2270
+ throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
2271
+ }
2272
+ const {apiBaseUrl: apiBaseUrl} = initialiseOptions;
2273
+ const session = getActiveSession();
2274
+ if (!session || !session.sessionKey) {
2275
+ return ok(undefined);
2276
+ }
2277
+ const {sessionId: sessionId, sessionKey: sessionKey} = session;
2278
+ removeActiveSession();
2279
+ const abortSessionResult = await abortSession({
2280
+ apiBaseUrl: apiBaseUrl,
2281
+ sessionId: sessionId,
2282
+ sessionKey: sessionKey
2283
+ });
2284
+ if (abortSessionResult.isErr()) {
2285
+ return err({
2286
+ type: exports.AbortSessionErrorType.AbortSessionFailed,
2287
+ message: AbortSessionErrorMessage.FailedToAbortSession,
2288
+ cause: abortSessionResult.error
2289
+ });
2290
+ }
2291
+ return ok(undefined);
2292
+ };
2293
+
1909
2294
  const utils = {
1910
2295
  generateChallenge: generateChallenge,
2296
+ getVersion: getVersion,
1911
2297
  unwrap: unwrap
1912
2298
  };
1913
2299
 
2300
+ exports.abortCredentialRequest = abortCredentialRequest;
2301
+
1914
2302
  exports.handleRedirectCallback = handleRedirectCallback;
1915
2303
 
1916
2304
  exports.initialise = initialise;
1917
2305
 
2306
+ exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
2307
+
1918
2308
  exports.requestCredentials = requestCredentials;
1919
2309
 
1920
2310
  exports.utils = utils;