@mattrglobal/verifier-sdk-web 1.1.1-unstable.16 → 1.1.1-unstable.160
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 +63 -42
- package/dist/lib/verifier-js-no-deps.cjs.js +610 -198
- package/dist/lib/verifier-js-no-deps.cjs.js.map +1 -1
- package/dist/lib/verifier-js.cjs.js +736 -312
- package/dist/lib/verifier-js.cjs.js.map +1 -1
- package/dist/typings/common/safeFetch.d.ts +6 -3
- package/dist/typings/common/sleep.d.ts +1 -0
- package/dist/typings/index.d.ts +6 -6
- package/dist/typings/verifier/abortCredentialRequest.d.ts +6 -0
- package/dist/typings/verifier/handleRedirectCallback.d.ts +1 -1
- package/dist/typings/verifier/index.d.ts +3 -1
- package/dist/typings/verifier/initialize.d.ts +12 -0
- package/dist/typings/verifier/instanceContext.d.ts +7 -0
- package/dist/typings/verifier/requestCredentialsCrossDevice.d.ts +3 -47
- package/dist/typings/verifier/requestCredentialsDigitalCredentialsApi.d.ts +16 -0
- package/dist/typings/verifier/requestCredentialsSameDevice.d.ts +1 -1
- package/dist/typings/verifier/types/credential-presentation.d.ts +156 -21
- package/dist/typings/verifier/types/verifier-web-sdk.d.ts +129 -186
- package/dist/typings/verifier/utils.d.ts +25 -5
- package/dist/verifier-js.development.js +678 -294
- package/dist/verifier-js.development.js.map +1 -1
- package/dist/verifier-js.production.esm.js +2 -2
- package/dist/verifier-js.production.esm.js.map +1 -1
- package/dist/verifier-js.production.js +2 -2
- package/dist/verifier-js.production.js.map +1 -1
- package/package.json +2 -2
- package/dist/typings/verifier/initialise.d.ts +0 -12
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Do Not Translate or Localize
|
|
8
8
|
*
|
|
9
9
|
* Bundle of @mattrglobal/verifier-sdk-web
|
|
10
|
-
* Generated: 2025-
|
|
10
|
+
* Generated: 2025-05-20
|
|
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
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|
|
461
|
-
|
|
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
|
|
473
|
-
"
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
|
|
538
|
-
done:
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
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(
|
|
546
|
-
throw
|
|
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
|
|
483
|
+
var o, a = !0, u = !1;
|
|
554
484
|
return {
|
|
555
485
|
s: function() {
|
|
556
|
-
|
|
486
|
+
t = t.call(r);
|
|
557
487
|
},
|
|
558
488
|
n: function() {
|
|
559
|
-
var
|
|
560
|
-
|
|
561
|
-
return step;
|
|
489
|
+
var r = t.next();
|
|
490
|
+
return a = r.done, r;
|
|
562
491
|
},
|
|
563
|
-
e: function(
|
|
564
|
-
|
|
565
|
-
err = e;
|
|
492
|
+
e: function(r) {
|
|
493
|
+
u = !0, o = r;
|
|
566
494
|
},
|
|
567
495
|
f: function() {
|
|
568
496
|
try {
|
|
569
|
-
|
|
497
|
+
a || null == t.return || t.return();
|
|
570
498
|
} finally {
|
|
571
|
-
if (
|
|
499
|
+
if (u) throw o;
|
|
572
500
|
}
|
|
573
501
|
}
|
|
574
502
|
};
|
|
575
503
|
}
|
|
576
504
|
|
|
577
|
-
function
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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 (
|
|
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
|
|
589
|
-
|
|
590
|
-
return typeof
|
|
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
|
|
799
|
+
function literal(literal_, message) {
|
|
797
800
|
return {
|
|
798
801
|
kind: "schema",
|
|
799
|
-
type: "
|
|
800
|
-
reference:
|
|
801
|
-
expects:
|
|
802
|
+
type: "literal",
|
|
803
|
+
reference: literal,
|
|
804
|
+
expects: _stringify(literal_),
|
|
802
805
|
async: false,
|
|
806
|
+
literal: literal_,
|
|
803
807
|
message: message,
|
|
804
808
|
_run: function _run(dataset, config2) {
|
|
805
|
-
if (
|
|
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) {
|
|
820
|
+
return {
|
|
821
|
+
kind: "schema",
|
|
822
|
+
type: "number",
|
|
823
|
+
reference: number,
|
|
824
|
+
expects: "number",
|
|
825
|
+
async: false,
|
|
826
|
+
message: message,
|
|
827
|
+
_run: function _run(dataset, config2) {
|
|
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["
|
|
1347
|
-
MobileCredentialVerificationReasonType["
|
|
1348
|
-
MobileCredentialVerificationReasonType["
|
|
1349
|
-
MobileCredentialVerificationReasonType["
|
|
1350
|
-
MobileCredentialVerificationReasonType["
|
|
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(),
|
|
@@ -1400,6 +1406,14 @@ var PresentationErrorType;
|
|
|
1400
1406
|
PresentationErrorType["Unknown"] = "Unknown";
|
|
1401
1407
|
})(PresentationErrorType || (PresentationErrorType = {}));
|
|
1402
1408
|
|
|
1409
|
+
const PresentationSuccessResultValidator = object({
|
|
1410
|
+
sessionId: string(),
|
|
1411
|
+
challenge: string(),
|
|
1412
|
+
credentialQuery: array(CredentialQueryValidator),
|
|
1413
|
+
credentials: optional(array(any())),
|
|
1414
|
+
credentialErrors: optional(array(any()))
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1403
1417
|
const PresentationResultRelaxValidator = object({
|
|
1404
1418
|
sessionId: string(),
|
|
1405
1419
|
challenge: optional(string()),
|
|
@@ -1409,18 +1423,64 @@ const PresentationResultRelaxValidator = object({
|
|
|
1409
1423
|
error: optional(unknown())
|
|
1410
1424
|
});
|
|
1411
1425
|
|
|
1426
|
+
const PresentationFailureResultValidator = object({
|
|
1427
|
+
sessionId: string(),
|
|
1428
|
+
challenge: string(),
|
|
1429
|
+
credentialQuery: array(CredentialQueryValidator),
|
|
1430
|
+
error: object({
|
|
1431
|
+
type: picklist(Object.values(PresentationErrorType)),
|
|
1432
|
+
message: string()
|
|
1433
|
+
})
|
|
1434
|
+
});
|
|
1435
|
+
|
|
1436
|
+
const PresentationSessionResultValidator = union([ PresentationSuccessResultValidator, PresentationFailureResultValidator ]);
|
|
1437
|
+
|
|
1438
|
+
exports.Mode = void 0;
|
|
1439
|
+
|
|
1440
|
+
(function(Mode) {
|
|
1441
|
+
Mode["SameDevice"] = "sameDevice";
|
|
1442
|
+
Mode["CrossDevice"] = "crossDevice";
|
|
1443
|
+
})(exports.Mode || (exports.Mode = {}));
|
|
1444
|
+
|
|
1445
|
+
var SessionType;
|
|
1446
|
+
|
|
1447
|
+
(function(SessionType) {
|
|
1448
|
+
SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
|
|
1449
|
+
SessionType["Openid4vp"] = "openid4vp";
|
|
1450
|
+
})(SessionType || (SessionType = {}));
|
|
1451
|
+
|
|
1412
1452
|
object({
|
|
1413
1453
|
credentialQuery: array(CredentialQueryValidator),
|
|
1414
1454
|
challenge: string(),
|
|
1415
1455
|
redirectUri: optional(string()),
|
|
1416
|
-
walletProviderId: optional(string())
|
|
1456
|
+
walletProviderId: optional(string()),
|
|
1457
|
+
dcApiSupported: optional(_boolean())
|
|
1417
1458
|
});
|
|
1418
1459
|
|
|
1419
|
-
const
|
|
1460
|
+
const CreateSessionDigitalCredentialsValidator = object({
|
|
1461
|
+
type: literal(SessionType.DigitalCredentialsApi),
|
|
1420
1462
|
sessionId: string(),
|
|
1463
|
+
sessionKey: string(),
|
|
1464
|
+
sessionTtl: number(),
|
|
1465
|
+
request: record(string(), any())
|
|
1466
|
+
});
|
|
1467
|
+
|
|
1468
|
+
const CreateSessionOpenId4vpResponseValidator = object({
|
|
1469
|
+
type: optional(literal(SessionType.Openid4vp)),
|
|
1470
|
+
sessionId: string(),
|
|
1471
|
+
sessionKey: string(),
|
|
1421
1472
|
sessionUrl: string()
|
|
1422
1473
|
});
|
|
1423
1474
|
|
|
1475
|
+
const CreateSessionResponseValidator = union([ CreateSessionDigitalCredentialsValidator, CreateSessionOpenId4vpResponseValidator ]);
|
|
1476
|
+
|
|
1477
|
+
const GetSessionStatusResponseValidator = union([ object({
|
|
1478
|
+
status: picklist([ PresentationStatusCode.ResultReady ]),
|
|
1479
|
+
responseCode: optional(string())
|
|
1480
|
+
}), object({
|
|
1481
|
+
status: string()
|
|
1482
|
+
}) ]);
|
|
1483
|
+
|
|
1424
1484
|
var LocalStorageKey;
|
|
1425
1485
|
|
|
1426
1486
|
(function(LocalStorageKey) {
|
|
@@ -1428,12 +1488,9 @@ var LocalStorageKey;
|
|
|
1428
1488
|
LocalStorageKey["sessionId"] = "mattr_sid";
|
|
1429
1489
|
})(LocalStorageKey || (LocalStorageKey = {}));
|
|
1430
1490
|
|
|
1431
|
-
|
|
1491
|
+
const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
|
|
1432
1492
|
|
|
1433
|
-
|
|
1434
|
-
Mode["sameDevice"] = "sameDevice";
|
|
1435
|
-
Mode["crossDevice"] = "crossDevice";
|
|
1436
|
-
})(exports.Mode || (exports.Mode = {}));
|
|
1493
|
+
const MATTR_SDK_VERSION_VALUE = "2.0.0";
|
|
1437
1494
|
|
|
1438
1495
|
var MessageEventDataType;
|
|
1439
1496
|
|
|
@@ -1443,64 +1500,163 @@ var MessageEventDataType;
|
|
|
1443
1500
|
MessageEventDataType["PresentationAbort"] = "PresentationAbort";
|
|
1444
1501
|
})(MessageEventDataType || (MessageEventDataType = {}));
|
|
1445
1502
|
|
|
1446
|
-
const
|
|
1447
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1448
|
-
redirectUri: string(),
|
|
1449
|
-
challenge: optional(string()),
|
|
1503
|
+
const OpenId4vpConfigSameDeviceOptionsValidator = object({
|
|
1450
1504
|
walletProviderId: optional(string()),
|
|
1451
|
-
mode:
|
|
1505
|
+
mode: literal(exports.Mode.SameDevice),
|
|
1506
|
+
redirectUri: string()
|
|
1452
1507
|
});
|
|
1453
1508
|
|
|
1454
|
-
const
|
|
1455
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1456
|
-
crossDeviceCallback: object({
|
|
1457
|
-
onComplete: function_(),
|
|
1458
|
-
onFailure: function_()
|
|
1459
|
-
}),
|
|
1460
|
-
challenge: optional(string()),
|
|
1509
|
+
const OpenId4vpConfigCrossDeviceOptionsValidator = object({
|
|
1461
1510
|
walletProviderId: optional(string()),
|
|
1462
|
-
mode:
|
|
1511
|
+
mode: literal(exports.Mode.CrossDevice)
|
|
1463
1512
|
});
|
|
1464
1513
|
|
|
1465
|
-
const
|
|
1466
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1467
|
-
crossDeviceCallback: object({
|
|
1468
|
-
onComplete: function_(),
|
|
1469
|
-
onFailure: function_()
|
|
1470
|
-
}),
|
|
1471
|
-
redirectUri: string(),
|
|
1472
|
-
challenge: optional(string()),
|
|
1514
|
+
const OpenId4vpConfigAutoDetectOptionsValidator = object({
|
|
1473
1515
|
walletProviderId: optional(string()),
|
|
1474
|
-
|
|
1516
|
+
redirectUri: string(),
|
|
1517
|
+
mode: optional(picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
|
|
1475
1518
|
});
|
|
1476
1519
|
|
|
1477
|
-
const RequestCredentialsOptionsValidator =
|
|
1520
|
+
const RequestCredentialsOptionsValidator = object({
|
|
1521
|
+
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1522
|
+
challenge: optional(string()),
|
|
1523
|
+
openid4vpConfiguration: optional(union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
|
|
1524
|
+
});
|
|
1478
1525
|
|
|
1479
1526
|
exports.RequestCredentialsErrorType = void 0;
|
|
1480
1527
|
|
|
1481
1528
|
(function(RequestCredentialsErrorType) {
|
|
1482
1529
|
RequestCredentialsErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
|
|
1530
|
+
RequestCredentialsErrorType["Timeout"] = "Timeout";
|
|
1531
|
+
RequestCredentialsErrorType["Abort"] = "Abort";
|
|
1483
1532
|
})(exports.RequestCredentialsErrorType || (exports.RequestCredentialsErrorType = {}));
|
|
1484
1533
|
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1534
|
+
var RequestCredentialsErrorMessage;
|
|
1535
|
+
|
|
1536
|
+
(function(RequestCredentialsErrorMessage) {
|
|
1537
|
+
RequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1538
|
+
RequestCredentialsErrorMessage["FailedToGetSessionStatus"] = "Failed to get session status";
|
|
1539
|
+
RequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1540
|
+
RequestCredentialsErrorMessage["FailedToVerifyCredentialResponse"] = "Failed to verify credential response";
|
|
1541
|
+
RequestCredentialsErrorMessage["MissingOpenId4vpConfig"] = "Identified openid4vp session, but missing openId4vpConfiguration on `requestCredentials`";
|
|
1542
|
+
RequestCredentialsErrorMessage["DcApiError"] = "Failed to request credentials with Digital Credentials API";
|
|
1543
|
+
RequestCredentialsErrorMessage["DcApiResponseParseError"] = "Failed to parse response from Digital Credentials API";
|
|
1544
|
+
RequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1545
|
+
RequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1546
|
+
})(RequestCredentialsErrorMessage || (RequestCredentialsErrorMessage = {}));
|
|
1547
|
+
|
|
1548
|
+
exports.AbortSessionErrorType = void 0;
|
|
1549
|
+
|
|
1550
|
+
(function(AbortSessionErrorType) {
|
|
1551
|
+
AbortSessionErrorType["AbortSessionFailed"] = "AbortSessionFailed";
|
|
1552
|
+
})(exports.AbortSessionErrorType || (exports.AbortSessionErrorType = {}));
|
|
1553
|
+
|
|
1554
|
+
var AbortSessionErrorMessage;
|
|
1555
|
+
|
|
1556
|
+
(function(AbortSessionErrorMessage) {
|
|
1557
|
+
AbortSessionErrorMessage["FailedToAbortSession"] = "Failed to abort session";
|
|
1558
|
+
})(AbortSessionErrorMessage || (AbortSessionErrorMessage = {}));
|
|
1559
|
+
|
|
1560
|
+
const InitializeOptionsValidator = object({
|
|
1561
|
+
apiBaseUrl: pipe(string(), nonEmpty("Must not be empty")),
|
|
1562
|
+
applicationId: pipe(string(), nonEmpty("Must not be empty"))
|
|
1488
1563
|
});
|
|
1489
1564
|
|
|
1490
|
-
|
|
1565
|
+
var SafeFetchCommonResponseErrorType;
|
|
1566
|
+
|
|
1567
|
+
(function(SafeFetchCommonResponseErrorType) {
|
|
1568
|
+
SafeFetchCommonResponseErrorType["UnexpectedResponse"] = "UnexpectedResponse";
|
|
1569
|
+
})(SafeFetchCommonResponseErrorType || (SafeFetchCommonResponseErrorType = {}));
|
|
1570
|
+
|
|
1571
|
+
var SafeFetchErrorType;
|
|
1572
|
+
|
|
1573
|
+
(function(SafeFetchErrorType) {
|
|
1574
|
+
SafeFetchErrorType["HttpError"] = "HttpError";
|
|
1575
|
+
SafeFetchErrorType["UnknownError"] = "UnknownError";
|
|
1576
|
+
})(SafeFetchErrorType || (SafeFetchErrorType = {}));
|
|
1577
|
+
|
|
1578
|
+
const safeFetch = async (input, init) => {
|
|
1579
|
+
try {
|
|
1580
|
+
const headers = Object.assign(Object.assign({}, init === null || init === void 0 ? void 0 : init.headers), {
|
|
1581
|
+
[MATTR_SDK_VERSION_HEADER]: `verifier-sdk-web/${MATTR_SDK_VERSION_VALUE}`
|
|
1582
|
+
});
|
|
1583
|
+
const response = await fetch(input, Object.assign(Object.assign({}, init), {
|
|
1584
|
+
headers: headers
|
|
1585
|
+
}));
|
|
1586
|
+
if (response.status > 299 || response.status < 200) {
|
|
1587
|
+
return err({
|
|
1588
|
+
type: SafeFetchErrorType.HttpError,
|
|
1589
|
+
message: `HTTP error, status = ${response.status}`,
|
|
1590
|
+
status: response.status
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
return ok(response);
|
|
1594
|
+
} catch (error) {
|
|
1595
|
+
return err({
|
|
1596
|
+
type: SafeFetchErrorType.UnknownError,
|
|
1597
|
+
message: "Unknown error",
|
|
1598
|
+
cause: error
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
let initializeOptions = undefined;
|
|
1491
1604
|
|
|
1492
|
-
var
|
|
1605
|
+
var InitializeErrorMessage;
|
|
1493
1606
|
|
|
1494
|
-
(function(
|
|
1495
|
-
|
|
1496
|
-
})(
|
|
1607
|
+
(function(InitializeErrorMessage) {
|
|
1608
|
+
InitializeErrorMessage["SdkNotInitialized"] = "SDK not initialized";
|
|
1609
|
+
})(InitializeErrorMessage || (InitializeErrorMessage = {}));
|
|
1497
1610
|
|
|
1498
|
-
const
|
|
1499
|
-
assertType(
|
|
1500
|
-
|
|
1611
|
+
const initialize = options => {
|
|
1612
|
+
assertType(InitializeOptionsValidator, "Invalid initialize options")(options);
|
|
1613
|
+
initializeOptions = options;
|
|
1501
1614
|
};
|
|
1502
1615
|
|
|
1503
|
-
const
|
|
1616
|
+
const getInitializeOptions = () => initializeOptions;
|
|
1617
|
+
|
|
1618
|
+
let sessionAbortController = undefined;
|
|
1619
|
+
|
|
1620
|
+
let _sessionId = undefined;
|
|
1621
|
+
|
|
1622
|
+
let _sessionKey = undefined;
|
|
1623
|
+
|
|
1624
|
+
let _sessionTimeoutId = undefined;
|
|
1625
|
+
|
|
1626
|
+
const getActiveSession = () => {
|
|
1627
|
+
const sessionId = _sessionId;
|
|
1628
|
+
const sessionKey = _sessionKey;
|
|
1629
|
+
const sessionTimeoutId = _sessionTimeoutId;
|
|
1630
|
+
if (sessionId) {
|
|
1631
|
+
return {
|
|
1632
|
+
sessionId: sessionId,
|
|
1633
|
+
sessionKey: sessionKey,
|
|
1634
|
+
sessionTimeoutId: sessionTimeoutId
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
return undefined;
|
|
1638
|
+
};
|
|
1639
|
+
|
|
1640
|
+
const setActiveSession = session => {
|
|
1641
|
+
const {sessionId: sessionId, sessionKey: sessionKey, sessionTimeoutId: sessionTimeoutId} = session;
|
|
1642
|
+
_sessionId = sessionId;
|
|
1643
|
+
_sessionKey = sessionKey;
|
|
1644
|
+
_sessionTimeoutId = sessionTimeoutId;
|
|
1645
|
+
const abortController = new AbortController;
|
|
1646
|
+
sessionAbortController = abortController;
|
|
1647
|
+
return abortController;
|
|
1648
|
+
};
|
|
1649
|
+
|
|
1650
|
+
const removeActiveSession = () => {
|
|
1651
|
+
sessionAbortController === null || sessionAbortController === void 0 ? void 0 : sessionAbortController.abort();
|
|
1652
|
+
if (_sessionTimeoutId) {
|
|
1653
|
+
window.clearTimeout(_sessionTimeoutId);
|
|
1654
|
+
}
|
|
1655
|
+
sessionAbortController = undefined;
|
|
1656
|
+
_sessionKey = undefined;
|
|
1657
|
+
_sessionId = undefined;
|
|
1658
|
+
_sessionTimeoutId = undefined;
|
|
1659
|
+
};
|
|
1504
1660
|
|
|
1505
1661
|
var isMobile_1 = isMobile;
|
|
1506
1662
|
|
|
@@ -1537,6 +1693,24 @@ const defaultRetryDelay = attempt => Math.pow(2, attempt) * 1e3;
|
|
|
1537
1693
|
|
|
1538
1694
|
const defaultRetry = 2;
|
|
1539
1695
|
|
|
1696
|
+
const withRetry = async (fn, options) => {
|
|
1697
|
+
const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0} = options;
|
|
1698
|
+
try {
|
|
1699
|
+
return await fn();
|
|
1700
|
+
} catch (err) {
|
|
1701
|
+
if (retries > 0) {
|
|
1702
|
+
const delay = typeof retryDelay === "function" ? retryDelay(attempt) : retryDelay;
|
|
1703
|
+
await new Promise((resolve => setTimeout(resolve, delay)));
|
|
1704
|
+
return await withRetry(fn, Object.assign(Object.assign({}, options), {
|
|
1705
|
+
retries: retries - 1,
|
|
1706
|
+
retryDelay: retryDelay,
|
|
1707
|
+
attempt: attempt + 1
|
|
1708
|
+
}));
|
|
1709
|
+
}
|
|
1710
|
+
throw err;
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
|
|
1540
1714
|
const withRetrySafeFetch = async (fn, options) => {
|
|
1541
1715
|
const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0, retryHttpStatus: retryHttpStatus} = options;
|
|
1542
1716
|
const result = await fn();
|
|
@@ -1565,17 +1739,15 @@ const getHashParamValue = (hash, param) => {
|
|
|
1565
1739
|
return urlParams.get(param);
|
|
1566
1740
|
};
|
|
1567
1741
|
|
|
1568
|
-
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl,
|
|
1569
|
-
const postData =
|
|
1742
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
|
|
1743
|
+
const postData = {
|
|
1570
1744
|
credentialQuery: credentialQuery,
|
|
1571
|
-
challenge: challenge
|
|
1572
|
-
|
|
1573
|
-
redirectUri: redirectUri
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
}
|
|
1577
|
-
walletProviderId: walletProviderId
|
|
1578
|
-
} : {});
|
|
1745
|
+
challenge: challenge,
|
|
1746
|
+
applicationId: applicationId,
|
|
1747
|
+
redirectUri: redirectUri,
|
|
1748
|
+
walletProviderId: walletProviderId,
|
|
1749
|
+
dcApiSupported: dcApiSupported
|
|
1750
|
+
};
|
|
1579
1751
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
|
|
1580
1752
|
method: "POST",
|
|
1581
1753
|
headers: {
|
|
@@ -1589,8 +1761,42 @@ const createSession = async ({credentialQuery: credentialQuery, challenge: chall
|
|
|
1589
1761
|
const data = await responseResult.value.json();
|
|
1590
1762
|
if (!isType(CreateSessionResponseValidator)(data)) {
|
|
1591
1763
|
return err({
|
|
1592
|
-
type:
|
|
1593
|
-
message: "Create session
|
|
1764
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1765
|
+
message: "Create session returned unsupported response"
|
|
1766
|
+
});
|
|
1767
|
+
}
|
|
1768
|
+
return ok(data);
|
|
1769
|
+
};
|
|
1770
|
+
|
|
1771
|
+
const abortSession = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
|
|
1772
|
+
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/abort`, {
|
|
1773
|
+
method: "POST",
|
|
1774
|
+
headers: {
|
|
1775
|
+
"Content-Type": "application/json",
|
|
1776
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
if (responseResult.isErr()) {
|
|
1780
|
+
return err(responseResult.error);
|
|
1781
|
+
}
|
|
1782
|
+
return ok(undefined);
|
|
1783
|
+
};
|
|
1784
|
+
|
|
1785
|
+
const getSessionStatus = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
|
|
1786
|
+
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/status`, {
|
|
1787
|
+
method: "GET",
|
|
1788
|
+
headers: {
|
|
1789
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1790
|
+
}
|
|
1791
|
+
});
|
|
1792
|
+
if (responseResult.isErr()) {
|
|
1793
|
+
return err(responseResult.error);
|
|
1794
|
+
}
|
|
1795
|
+
const data = await responseResult.value.json();
|
|
1796
|
+
if (!isType(GetSessionStatusResponseValidator)(data)) {
|
|
1797
|
+
return err({
|
|
1798
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1799
|
+
message: "Get session status return unsupported response"
|
|
1594
1800
|
});
|
|
1595
1801
|
}
|
|
1596
1802
|
return ok(data);
|
|
@@ -1618,7 +1824,7 @@ const exchangeSessionResult = async ({challenge: challenge, responseCode: respon
|
|
|
1618
1824
|
const data = await responseResult.value.json();
|
|
1619
1825
|
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
1620
1826
|
return err({
|
|
1621
|
-
type:
|
|
1827
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1622
1828
|
message: "Exchange session result return unsupported response",
|
|
1623
1829
|
details: {
|
|
1624
1830
|
data: data
|
|
@@ -1633,22 +1839,7 @@ const isMobileDetect = userAgent => isMobile_2({
|
|
|
1633
1839
|
tablet: false
|
|
1634
1840
|
});
|
|
1635
1841
|
|
|
1636
|
-
|
|
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 = {}));
|
|
1842
|
+
const getVersion = () => MATTR_SDK_VERSION_VALUE;
|
|
1652
1843
|
|
|
1653
1844
|
var WindowEventListenerType;
|
|
1654
1845
|
|
|
@@ -1656,10 +1847,13 @@ var WindowEventListenerType;
|
|
|
1656
1847
|
WindowEventListenerType["message"] = "message";
|
|
1657
1848
|
})(WindowEventListenerType || (WindowEventListenerType = {}));
|
|
1658
1849
|
|
|
1659
|
-
let listener;
|
|
1850
|
+
let listener = undefined;
|
|
1660
1851
|
|
|
1661
1852
|
const removeWindowMessageEventListener = () => {
|
|
1662
|
-
|
|
1853
|
+
if (listener) {
|
|
1854
|
+
window.removeEventListener(WindowEventListenerType.message, listener, false);
|
|
1855
|
+
}
|
|
1856
|
+
listener = undefined;
|
|
1663
1857
|
};
|
|
1664
1858
|
|
|
1665
1859
|
const closeCrossDeviceModal = options => {
|
|
@@ -1671,8 +1865,7 @@ const closeCrossDeviceModal = options => {
|
|
|
1671
1865
|
};
|
|
1672
1866
|
|
|
1673
1867
|
const receiveMessageHandler = options => async event => {
|
|
1674
|
-
const {
|
|
1675
|
-
const {onComplete: onComplete, onFailure: onFailure} = crossDeviceCallback;
|
|
1868
|
+
const {onComplete: onComplete, onFailure: onFailure, container: container, sessionId: sessionId, apiBaseUrl: apiBaseUrl, challenge: challenge} = options;
|
|
1676
1869
|
if (event.origin !== apiBaseUrl) {
|
|
1677
1870
|
return;
|
|
1678
1871
|
}
|
|
@@ -1686,8 +1879,8 @@ const receiveMessageHandler = options => async event => {
|
|
|
1686
1879
|
});
|
|
1687
1880
|
if (result.isErr()) {
|
|
1688
1881
|
onFailure({
|
|
1689
|
-
type: exports.
|
|
1690
|
-
message:
|
|
1882
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1883
|
+
message: RequestCredentialsErrorMessage.FailedToGetSessionResult
|
|
1691
1884
|
});
|
|
1692
1885
|
closeCrossDeviceModal({
|
|
1693
1886
|
container: container
|
|
@@ -1695,8 +1888,9 @@ const receiveMessageHandler = options => async event => {
|
|
|
1695
1888
|
return;
|
|
1696
1889
|
}
|
|
1697
1890
|
onComplete({
|
|
1698
|
-
result: result.value,
|
|
1699
|
-
sessionId: result.value.sessionId
|
|
1891
|
+
result: isType(PresentationSessionResultValidator)(result.value) ? result.value : undefined,
|
|
1892
|
+
sessionId: result.value.sessionId,
|
|
1893
|
+
sessionCompletedInRedirect: false
|
|
1700
1894
|
});
|
|
1701
1895
|
closeCrossDeviceModal({
|
|
1702
1896
|
container: container
|
|
@@ -1705,8 +1899,8 @@ const receiveMessageHandler = options => async event => {
|
|
|
1705
1899
|
}
|
|
1706
1900
|
if (event.data.type === MessageEventDataType.PresentationTimeout) {
|
|
1707
1901
|
onFailure({
|
|
1708
|
-
type: exports.
|
|
1709
|
-
message:
|
|
1902
|
+
type: exports.RequestCredentialsErrorType.Timeout,
|
|
1903
|
+
message: RequestCredentialsErrorMessage.Timeout
|
|
1710
1904
|
});
|
|
1711
1905
|
closeCrossDeviceModal({
|
|
1712
1906
|
container: container
|
|
@@ -1715,8 +1909,8 @@ const receiveMessageHandler = options => async event => {
|
|
|
1715
1909
|
}
|
|
1716
1910
|
if (event.data.type === MessageEventDataType.PresentationAbort) {
|
|
1717
1911
|
onFailure({
|
|
1718
|
-
type: exports.
|
|
1719
|
-
message:
|
|
1912
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
1913
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1720
1914
|
});
|
|
1721
1915
|
closeCrossDeviceModal({
|
|
1722
1916
|
container: container
|
|
@@ -1741,41 +1935,202 @@ const openCrossDeviceModal = options => {
|
|
|
1741
1935
|
return modalContainer;
|
|
1742
1936
|
};
|
|
1743
1937
|
|
|
1744
|
-
const
|
|
1745
|
-
const {challenge: challenge,
|
|
1746
|
-
const
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1938
|
+
const requestCredentialsWithCrossDevice = async options => {
|
|
1939
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = options;
|
|
1940
|
+
const container = openCrossDeviceModal({
|
|
1941
|
+
sessionUrl: sessionUrl
|
|
1942
|
+
});
|
|
1943
|
+
return await new Promise((resolve => {
|
|
1944
|
+
const abortController = setActiveSession({
|
|
1945
|
+
sessionId: sessionId,
|
|
1946
|
+
sessionKey: sessionKey
|
|
1947
|
+
});
|
|
1948
|
+
abortController.signal.addEventListener("abort", (() => {
|
|
1949
|
+
closeCrossDeviceModal({
|
|
1950
|
+
container: container
|
|
1951
|
+
});
|
|
1952
|
+
resolve(err({
|
|
1953
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
1954
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1955
|
+
}));
|
|
1956
|
+
}));
|
|
1957
|
+
removeWindowMessageEventListener();
|
|
1958
|
+
listener = receiveMessageHandler({
|
|
1959
|
+
container: container,
|
|
1960
|
+
sessionId: sessionId,
|
|
1961
|
+
apiBaseUrl: apiBaseUrl,
|
|
1962
|
+
challenge: challenge,
|
|
1963
|
+
onComplete: data => resolve(ok(data)),
|
|
1964
|
+
onFailure: error => resolve(err(error))
|
|
1965
|
+
});
|
|
1966
|
+
window.addEventListener(WindowEventListenerType.message, listener, false);
|
|
1967
|
+
}));
|
|
1968
|
+
};
|
|
1969
|
+
|
|
1970
|
+
const abortCredentialRequest = async () => {
|
|
1971
|
+
const initializeOptions = getInitializeOptions();
|
|
1972
|
+
if (!initializeOptions) {
|
|
1973
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1974
|
+
}
|
|
1975
|
+
const {apiBaseUrl: apiBaseUrl} = initializeOptions;
|
|
1976
|
+
const session = getActiveSession();
|
|
1977
|
+
if (!session || !session.sessionKey) {
|
|
1978
|
+
return ok(undefined);
|
|
1979
|
+
}
|
|
1980
|
+
const {sessionId: sessionId, sessionKey: sessionKey} = session;
|
|
1981
|
+
removeActiveSession();
|
|
1982
|
+
const abortSessionResult = await abortSession({
|
|
1750
1983
|
apiBaseUrl: apiBaseUrl,
|
|
1751
|
-
|
|
1752
|
-
|
|
1984
|
+
sessionId: sessionId,
|
|
1985
|
+
sessionKey: sessionKey
|
|
1753
1986
|
});
|
|
1754
|
-
if (
|
|
1987
|
+
if (abortSessionResult.isErr()) {
|
|
1755
1988
|
return err({
|
|
1756
|
-
type: exports.
|
|
1757
|
-
message:
|
|
1758
|
-
cause:
|
|
1989
|
+
type: exports.AbortSessionErrorType.AbortSessionFailed,
|
|
1990
|
+
message: AbortSessionErrorMessage.FailedToAbortSession,
|
|
1991
|
+
cause: abortSessionResult.error
|
|
1759
1992
|
});
|
|
1760
1993
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
container: container,
|
|
1994
|
+
return ok(undefined);
|
|
1995
|
+
};
|
|
1996
|
+
|
|
1997
|
+
const requestCredentialsWithDigitalCredentialsApi = async options => {
|
|
1998
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request, sessionTtl: sessionTtl} = options;
|
|
1999
|
+
const sessionTimeoutId = window.setTimeout((() => removeActiveSession()), sessionTtl * 1e3);
|
|
2000
|
+
const abortController = setActiveSession({
|
|
1769
2001
|
sessionId: sessionId,
|
|
2002
|
+
sessionKey: sessionKey,
|
|
2003
|
+
sessionTimeoutId: sessionTimeoutId
|
|
2004
|
+
});
|
|
2005
|
+
const credentialResponseResult = await getCredentials(request, abortController);
|
|
2006
|
+
if (credentialResponseResult.isErr()) {
|
|
2007
|
+
await abortCredentialRequest();
|
|
2008
|
+
return err(credentialResponseResult.error);
|
|
2009
|
+
}
|
|
2010
|
+
const credentialResponse = credentialResponseResult.value;
|
|
2011
|
+
const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
|
|
2012
|
+
if (parsedCredentialResponseResult.isErr()) {
|
|
2013
|
+
await abortCredentialRequest();
|
|
2014
|
+
return err(parsedCredentialResponseResult.error);
|
|
2015
|
+
}
|
|
2016
|
+
const parsedCredentialResponse = parsedCredentialResponseResult.value;
|
|
2017
|
+
const credentialVerificationResult = await verifyCredentialResponse({
|
|
1770
2018
|
apiBaseUrl: apiBaseUrl,
|
|
1771
|
-
|
|
2019
|
+
sessionId: sessionId,
|
|
2020
|
+
sessionKey: sessionKey,
|
|
2021
|
+
challenge: challenge,
|
|
2022
|
+
protocol: parsedCredentialResponse.protocol,
|
|
2023
|
+
data: parsedCredentialResponse.data
|
|
1772
2024
|
});
|
|
1773
|
-
|
|
2025
|
+
if (credentialVerificationResult.isErr()) {
|
|
2026
|
+
return err({
|
|
2027
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2028
|
+
message: RequestCredentialsErrorMessage.FailedToVerifyCredentialResponse,
|
|
2029
|
+
cause: credentialVerificationResult.error
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
const verificationResult = credentialVerificationResult.value;
|
|
1774
2033
|
return ok({
|
|
2034
|
+
result: isType(PresentationSessionResultValidator)(verificationResult) ? verificationResult : undefined,
|
|
1775
2035
|
sessionId: sessionId
|
|
1776
2036
|
});
|
|
1777
2037
|
};
|
|
1778
2038
|
|
|
2039
|
+
const getCredentials = async (request, abortController) => {
|
|
2040
|
+
try {
|
|
2041
|
+
const credentialResponse = await navigator.credentials.get(Object.assign(Object.assign({}, request), {
|
|
2042
|
+
signal: abortController.signal
|
|
2043
|
+
}));
|
|
2044
|
+
return ok(credentialResponse);
|
|
2045
|
+
} catch (exception) {
|
|
2046
|
+
return err({
|
|
2047
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2048
|
+
message: RequestCredentialsErrorMessage.DcApiError,
|
|
2049
|
+
cause: exception
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
|
|
2054
|
+
const parseCredentialResponse = credentialResponse => {
|
|
2055
|
+
if (!credentialResponse) {
|
|
2056
|
+
return err({
|
|
2057
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2058
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2059
|
+
details: {
|
|
2060
|
+
response: credentialResponse
|
|
2061
|
+
}
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
if (typeof credentialResponse === "object") {
|
|
2065
|
+
return ok(credentialResponse);
|
|
2066
|
+
}
|
|
2067
|
+
if (typeof credentialResponse === "string") {
|
|
2068
|
+
try {
|
|
2069
|
+
const parsed = JSON.parse(credentialResponse);
|
|
2070
|
+
return ok(parsed);
|
|
2071
|
+
} catch (_a) {
|
|
2072
|
+
return err({
|
|
2073
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2074
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2075
|
+
details: {
|
|
2076
|
+
response: credentialResponse
|
|
2077
|
+
}
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
return err({
|
|
2082
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2083
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2084
|
+
details: {
|
|
2085
|
+
response: credentialResponse
|
|
2086
|
+
}
|
|
2087
|
+
});
|
|
2088
|
+
};
|
|
2089
|
+
|
|
2090
|
+
const verifyCredentialResponse = async options => {
|
|
2091
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, protocol: protocol, data: data} = options;
|
|
2092
|
+
const requestBody = {
|
|
2093
|
+
protocol: protocol,
|
|
2094
|
+
data: data,
|
|
2095
|
+
challenge: challenge
|
|
2096
|
+
};
|
|
2097
|
+
const credentialVerificationResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/dc-api/response`, {
|
|
2098
|
+
method: "POST",
|
|
2099
|
+
headers: {
|
|
2100
|
+
"Content-Type": "application/json",
|
|
2101
|
+
Authorization: `Bearer ${sessionKey}`
|
|
2102
|
+
},
|
|
2103
|
+
body: JSON.stringify(requestBody)
|
|
2104
|
+
});
|
|
2105
|
+
if (credentialVerificationResult.isErr()) {
|
|
2106
|
+
return err(credentialVerificationResult.error);
|
|
2107
|
+
}
|
|
2108
|
+
const credentialVerificationResponse = await credentialVerificationResult.value.json();
|
|
2109
|
+
if (!isType(PresentationResultRelaxValidator)(credentialVerificationResponse)) {
|
|
2110
|
+
return err({
|
|
2111
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
2112
|
+
message: "Verify credential returned unsupported response",
|
|
2113
|
+
details: {
|
|
2114
|
+
response: credentialVerificationResponse
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
return ok(credentialVerificationResponse);
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2121
|
+
const isDigitalCredentialsApiSupported = () => {
|
|
2122
|
+
var _a;
|
|
2123
|
+
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";
|
|
2124
|
+
};
|
|
2125
|
+
|
|
2126
|
+
const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
|
|
2127
|
+
|
|
2128
|
+
const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
|
|
2129
|
+
|
|
2130
|
+
const SESSION_STATUS_POLLING_INTERVAL_MS = 3e3;
|
|
2131
|
+
|
|
2132
|
+
const SESSION_STATUS_POLLING_INITIAL_DELAY_MS = 3e3;
|
|
2133
|
+
|
|
1779
2134
|
var SameDeviceRequestCredentialsErrorMessage;
|
|
1780
2135
|
|
|
1781
2136
|
(function(SameDeviceRequestCredentialsErrorMessage) {
|
|
@@ -1784,65 +2139,135 @@ var SameDeviceRequestCredentialsErrorMessage;
|
|
|
1784
2139
|
})(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
|
|
1785
2140
|
|
|
1786
2141
|
const requestCredentialsSameDevice = async options => {
|
|
1787
|
-
const {challenge: challenge,
|
|
1788
|
-
const
|
|
2142
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, applicationId: applicationId, sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = options;
|
|
2143
|
+
const abortController = setActiveSession({
|
|
2144
|
+
sessionId: sessionId,
|
|
2145
|
+
sessionKey: sessionKey
|
|
2146
|
+
});
|
|
2147
|
+
window.localStorage.setItem(LocalStorageKey.sessionId, sessionId);
|
|
1789
2148
|
window.localStorage.setItem(LocalStorageKey.challenge, challenge);
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
2149
|
+
window.location.assign(sessionUrl);
|
|
2150
|
+
await sleep(SESSION_STATUS_POLLING_INITIAL_DELAY_MS);
|
|
2151
|
+
const checkResult = await withRetry((async () => {
|
|
2152
|
+
const statusResult = await getSessionStatus({
|
|
2153
|
+
apiBaseUrl: apiBaseUrl,
|
|
2154
|
+
applicationId: applicationId,
|
|
2155
|
+
sessionId: sessionId,
|
|
2156
|
+
sessionKey: sessionKey
|
|
1795
2157
|
});
|
|
2158
|
+
if (abortController.signal.aborted) {
|
|
2159
|
+
return err({
|
|
2160
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
2161
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
if (statusResult.isErr()) {
|
|
2165
|
+
if (statusResult.error.status === 404) {
|
|
2166
|
+
return err({
|
|
2167
|
+
type: exports.RequestCredentialsErrorType.Timeout,
|
|
2168
|
+
message: RequestCredentialsErrorMessage.Timeout
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
throw Error("Unexpected status response. Retry");
|
|
2172
|
+
}
|
|
2173
|
+
if (statusResult.value.status !== PresentationStatusCode.ResultReady) {
|
|
2174
|
+
throw Error("Result is not ready. Retry");
|
|
2175
|
+
}
|
|
2176
|
+
return ok(undefined);
|
|
2177
|
+
}), {
|
|
2178
|
+
retries: SESSION_STATUS_POLLING_MAX_RETRY,
|
|
2179
|
+
retryDelay: SESSION_STATUS_POLLING_INTERVAL_MS
|
|
2180
|
+
});
|
|
2181
|
+
if (checkResult.isErr()) {
|
|
2182
|
+
return err(checkResult.error);
|
|
2183
|
+
}
|
|
2184
|
+
window.close();
|
|
2185
|
+
return ok({
|
|
2186
|
+
sessionId: sessionId,
|
|
2187
|
+
sessionCompletedInRedirect: true
|
|
2188
|
+
});
|
|
2189
|
+
};
|
|
2190
|
+
|
|
2191
|
+
const requestCredentials = async options => {
|
|
2192
|
+
var _a;
|
|
2193
|
+
const initializeOptions = getInitializeOptions();
|
|
2194
|
+
if (!initializeOptions) {
|
|
2195
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1796
2196
|
}
|
|
2197
|
+
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
2198
|
+
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initializeOptions;
|
|
2199
|
+
const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
|
|
2200
|
+
const dcApiSupported = isDigitalCredentialsApiSupported();
|
|
2201
|
+
const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
|
|
1797
2202
|
const createSessionResult = await createSession({
|
|
1798
2203
|
credentialQuery: credentialQuery,
|
|
1799
|
-
challenge:
|
|
1800
|
-
redirectUri:
|
|
2204
|
+
challenge: challenge,
|
|
2205
|
+
redirectUri: openId4VpRedirectUri,
|
|
2206
|
+
walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
|
|
1801
2207
|
apiBaseUrl: apiBaseUrl,
|
|
1802
2208
|
applicationId: applicationId,
|
|
1803
|
-
|
|
2209
|
+
dcApiSupported: dcApiSupported
|
|
1804
2210
|
});
|
|
1805
2211
|
if (createSessionResult.isErr()) {
|
|
1806
2212
|
return err({
|
|
1807
2213
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1808
|
-
message:
|
|
2214
|
+
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1809
2215
|
cause: createSessionResult.error
|
|
1810
2216
|
});
|
|
1811
2217
|
}
|
|
1812
|
-
const
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
2218
|
+
const session = createSessionResult.value;
|
|
2219
|
+
const {sessionKey: sessionKey, sessionId: sessionId} = session;
|
|
2220
|
+
if (session.type === SessionType.DigitalCredentialsApi) {
|
|
2221
|
+
const {request: request, sessionTtl: sessionTtl} = session;
|
|
2222
|
+
return await requestCredentialsWithDigitalCredentialsApi({
|
|
2223
|
+
apiBaseUrl: apiBaseUrl,
|
|
2224
|
+
request: request,
|
|
2225
|
+
sessionId: sessionId,
|
|
2226
|
+
sessionKey: sessionKey,
|
|
2227
|
+
challenge: challenge,
|
|
2228
|
+
sessionTtl: sessionTtl
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
if (!openid4vpConfiguration) {
|
|
2232
|
+
return err({
|
|
2233
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2234
|
+
message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
|
|
2235
|
+
});
|
|
2236
|
+
}
|
|
2237
|
+
const {sessionUrl: sessionUrl} = session;
|
|
2238
|
+
if (openId4VpRedirectUri) {
|
|
2239
|
+
return await requestCredentialsSameDevice({
|
|
2240
|
+
challenge: challenge,
|
|
2241
|
+
apiBaseUrl: apiBaseUrl,
|
|
2242
|
+
applicationId: applicationId,
|
|
2243
|
+
sessionUrl: sessionUrl,
|
|
2244
|
+
sessionKey: sessionKey,
|
|
2245
|
+
sessionId: sessionId
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
return await requestCredentialsWithCrossDevice({
|
|
2249
|
+
challenge: challenge,
|
|
2250
|
+
apiBaseUrl: apiBaseUrl,
|
|
2251
|
+
sessionUrl: sessionUrl,
|
|
2252
|
+
sessionKey: sessionKey,
|
|
1816
2253
|
sessionId: sessionId
|
|
1817
2254
|
});
|
|
1818
2255
|
};
|
|
1819
2256
|
|
|
1820
|
-
const
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
if (!initialiseOptions) {
|
|
1824
|
-
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
2257
|
+
const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
|
|
2258
|
+
if (!openid4vpConfiguration) {
|
|
2259
|
+
return undefined;
|
|
1825
2260
|
}
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
initialiseOptions: initialiseOptions,
|
|
1832
|
-
challenge: challenge,
|
|
1833
|
-
mode: mode
|
|
1834
|
-
}));
|
|
2261
|
+
let detectedMode;
|
|
2262
|
+
if (openid4vpConfiguration && openid4vpConfiguration.mode) {
|
|
2263
|
+
detectedMode = openid4vpConfiguration.mode;
|
|
2264
|
+
} else {
|
|
2265
|
+
detectedMode = isMobileDetect(navigator.userAgent) ? exports.Mode.SameDevice : exports.Mode.CrossDevice;
|
|
1835
2266
|
}
|
|
1836
|
-
if (
|
|
1837
|
-
return
|
|
1838
|
-
initialiseOptions: initialiseOptions,
|
|
1839
|
-
challenge: challenge,
|
|
1840
|
-
mode: mode
|
|
1841
|
-
}));
|
|
2267
|
+
if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
|
|
2268
|
+
return openid4vpConfiguration.redirectUri;
|
|
1842
2269
|
}
|
|
1843
|
-
|
|
1844
|
-
data: options
|
|
1845
|
-
});
|
|
2270
|
+
return undefined;
|
|
1846
2271
|
};
|
|
1847
2272
|
|
|
1848
2273
|
exports.HandleRedirectCallbackErrorType = void 0;
|
|
@@ -1856,16 +2281,16 @@ var HandleRedirectCallbackErrorMessage;
|
|
|
1856
2281
|
(function(HandleRedirectCallbackErrorMessage) {
|
|
1857
2282
|
HandleRedirectCallbackErrorMessage["FailedToFindResponseCode"] = "Failed to find response code";
|
|
1858
2283
|
HandleRedirectCallbackErrorMessage["FailedToFindChallenge"] = "Failed to find challenge";
|
|
1859
|
-
HandleRedirectCallbackErrorMessage["
|
|
2284
|
+
HandleRedirectCallbackErrorMessage["FailedToFindActiveSession"] = "Failed to find active session";
|
|
1860
2285
|
HandleRedirectCallbackErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1861
2286
|
})(HandleRedirectCallbackErrorMessage || (HandleRedirectCallbackErrorMessage = {}));
|
|
1862
2287
|
|
|
1863
2288
|
const handleRedirectCallback = async () => {
|
|
1864
|
-
const
|
|
1865
|
-
if (!
|
|
1866
|
-
throw new Exception(
|
|
2289
|
+
const initializeOptions = getInitializeOptions();
|
|
2290
|
+
if (!initializeOptions) {
|
|
2291
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1867
2292
|
}
|
|
1868
|
-
const {apiBaseUrl: apiBaseUrl} =
|
|
2293
|
+
const {apiBaseUrl: apiBaseUrl} = initializeOptions;
|
|
1869
2294
|
const responseCode = getHashParamValue(window.location.hash, "response_code");
|
|
1870
2295
|
if (!responseCode) {
|
|
1871
2296
|
return err({
|
|
@@ -1873,18 +2298,12 @@ const handleRedirectCallback = async () => {
|
|
|
1873
2298
|
message: HandleRedirectCallbackErrorMessage.FailedToFindResponseCode
|
|
1874
2299
|
});
|
|
1875
2300
|
}
|
|
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
2301
|
const sessionId = window.localStorage.getItem(LocalStorageKey.sessionId);
|
|
1884
|
-
|
|
2302
|
+
const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
2303
|
+
if (!sessionId || !challenge) {
|
|
1885
2304
|
return err({
|
|
1886
2305
|
type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
|
|
1887
|
-
message: HandleRedirectCallbackErrorMessage.
|
|
2306
|
+
message: HandleRedirectCallbackErrorMessage.FailedToFindActiveSession
|
|
1888
2307
|
});
|
|
1889
2308
|
}
|
|
1890
2309
|
const result = await exchangeSessionResult({
|
|
@@ -1901,19 +2320,24 @@ const handleRedirectCallback = async () => {
|
|
|
1901
2320
|
});
|
|
1902
2321
|
}
|
|
1903
2322
|
return ok({
|
|
1904
|
-
result: result.value,
|
|
2323
|
+
result: "challenge" in result.value ? result.value : undefined,
|
|
1905
2324
|
sessionId: result.value.sessionId
|
|
1906
2325
|
});
|
|
1907
2326
|
};
|
|
1908
2327
|
|
|
1909
2328
|
const utils = {
|
|
1910
2329
|
generateChallenge: generateChallenge,
|
|
2330
|
+
getVersion: getVersion,
|
|
1911
2331
|
unwrap: unwrap
|
|
1912
2332
|
};
|
|
1913
2333
|
|
|
2334
|
+
exports.abortCredentialRequest = abortCredentialRequest;
|
|
2335
|
+
|
|
1914
2336
|
exports.handleRedirectCallback = handleRedirectCallback;
|
|
1915
2337
|
|
|
1916
|
-
exports.
|
|
2338
|
+
exports.initialize = initialize;
|
|
2339
|
+
|
|
2340
|
+
exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
|
|
1917
2341
|
|
|
1918
2342
|
exports.requestCredentials = requestCredentials;
|
|
1919
2343
|
|