@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
|
*
|
|
@@ -426,6 +426,73 @@
|
|
|
426
426
|
};
|
|
427
427
|
ResultAsync.fromPromise;
|
|
428
428
|
ResultAsync.fromSafePromise;
|
|
429
|
+
function _arrayLikeToArray(r, a) {
|
|
430
|
+
(null == a || a > r.length) && (a = r.length);
|
|
431
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
432
|
+
return n;
|
|
433
|
+
}
|
|
434
|
+
function _arrayWithoutHoles(r) {
|
|
435
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
436
|
+
}
|
|
437
|
+
function _createForOfIteratorHelper(r, e) {
|
|
438
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
439
|
+
if (!t) {
|
|
440
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
441
|
+
t && (r = t);
|
|
442
|
+
var n = 0, F = function() {};
|
|
443
|
+
return {
|
|
444
|
+
s: F,
|
|
445
|
+
n: function() {
|
|
446
|
+
return n >= r.length ? {
|
|
447
|
+
done: !0
|
|
448
|
+
} : {
|
|
449
|
+
done: !1,
|
|
450
|
+
value: r[n++]
|
|
451
|
+
};
|
|
452
|
+
},
|
|
453
|
+
e: function(r) {
|
|
454
|
+
throw r;
|
|
455
|
+
},
|
|
456
|
+
f: F
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
460
|
+
}
|
|
461
|
+
var o, a = !0, u = !1;
|
|
462
|
+
return {
|
|
463
|
+
s: function() {
|
|
464
|
+
t = t.call(r);
|
|
465
|
+
},
|
|
466
|
+
n: function() {
|
|
467
|
+
var r = t.next();
|
|
468
|
+
return a = r.done, r;
|
|
469
|
+
},
|
|
470
|
+
e: function(r) {
|
|
471
|
+
u = !0, o = r;
|
|
472
|
+
},
|
|
473
|
+
f: function() {
|
|
474
|
+
try {
|
|
475
|
+
a || null == t.return || t.return();
|
|
476
|
+
} finally {
|
|
477
|
+
if (u) throw o;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
function _defineProperty(e, r, t) {
|
|
483
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
484
|
+
value: t,
|
|
485
|
+
enumerable: !0,
|
|
486
|
+
configurable: !0,
|
|
487
|
+
writable: !0
|
|
488
|
+
}) : e[r] = t, e;
|
|
489
|
+
}
|
|
490
|
+
function _iterableToArray(r) {
|
|
491
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
492
|
+
}
|
|
493
|
+
function _nonIterableSpread() {
|
|
494
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
495
|
+
}
|
|
429
496
|
function ownKeys(e, r) {
|
|
430
497
|
var t = Object.keys(e);
|
|
431
498
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -447,6 +514,23 @@
|
|
|
447
514
|
}
|
|
448
515
|
return e;
|
|
449
516
|
}
|
|
517
|
+
function _toConsumableArray(r) {
|
|
518
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
519
|
+
}
|
|
520
|
+
function _toPrimitive(t, r) {
|
|
521
|
+
if ("object" != typeof t || !t) return t;
|
|
522
|
+
var e = t[Symbol.toPrimitive];
|
|
523
|
+
if (void 0 !== e) {
|
|
524
|
+
var i = e.call(t, r || "default");
|
|
525
|
+
if ("object" != typeof i) return i;
|
|
526
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
527
|
+
}
|
|
528
|
+
return ("string" === r ? String : Number)(t);
|
|
529
|
+
}
|
|
530
|
+
function _toPropertyKey(t) {
|
|
531
|
+
var i = _toPrimitive(t, "string");
|
|
532
|
+
return "symbol" == typeof i ? i : i + "";
|
|
533
|
+
}
|
|
450
534
|
function _typeof(o) {
|
|
451
535
|
"@babel/helpers - typeof";
|
|
452
536
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -455,107 +539,12 @@
|
|
|
455
539
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
456
540
|
}, _typeof(o);
|
|
457
541
|
}
|
|
458
|
-
function
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
enumerable: true,
|
|
464
|
-
configurable: true,
|
|
465
|
-
writable: true
|
|
466
|
-
});
|
|
467
|
-
} else {
|
|
468
|
-
obj[key] = value;
|
|
542
|
+
function _unsupportedIterableToArray(r, a) {
|
|
543
|
+
if (r) {
|
|
544
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
545
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
546
|
+
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;
|
|
469
547
|
}
|
|
470
|
-
return obj;
|
|
471
|
-
}
|
|
472
|
-
function _toConsumableArray(arr) {
|
|
473
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
474
|
-
}
|
|
475
|
-
function _arrayWithoutHoles(arr) {
|
|
476
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
477
|
-
}
|
|
478
|
-
function _iterableToArray(iter) {
|
|
479
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
480
|
-
}
|
|
481
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
482
|
-
if (!o) return;
|
|
483
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
484
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
485
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
486
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
487
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
488
|
-
}
|
|
489
|
-
function _arrayLikeToArray(arr, len) {
|
|
490
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
491
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
492
|
-
return arr2;
|
|
493
|
-
}
|
|
494
|
-
function _nonIterableSpread() {
|
|
495
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
496
|
-
}
|
|
497
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
498
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
499
|
-
if (!it) {
|
|
500
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
501
|
-
if (it) o = it;
|
|
502
|
-
var i = 0;
|
|
503
|
-
var F = function() {};
|
|
504
|
-
return {
|
|
505
|
-
s: F,
|
|
506
|
-
n: function() {
|
|
507
|
-
if (i >= o.length) return {
|
|
508
|
-
done: true
|
|
509
|
-
};
|
|
510
|
-
return {
|
|
511
|
-
done: false,
|
|
512
|
-
value: o[i++]
|
|
513
|
-
};
|
|
514
|
-
},
|
|
515
|
-
e: function(e) {
|
|
516
|
-
throw e;
|
|
517
|
-
},
|
|
518
|
-
f: F
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
522
|
-
}
|
|
523
|
-
var normalCompletion = true, didErr = false, err;
|
|
524
|
-
return {
|
|
525
|
-
s: function() {
|
|
526
|
-
it = it.call(o);
|
|
527
|
-
},
|
|
528
|
-
n: function() {
|
|
529
|
-
var step = it.next();
|
|
530
|
-
normalCompletion = step.done;
|
|
531
|
-
return step;
|
|
532
|
-
},
|
|
533
|
-
e: function(e) {
|
|
534
|
-
didErr = true;
|
|
535
|
-
err = e;
|
|
536
|
-
},
|
|
537
|
-
f: function() {
|
|
538
|
-
try {
|
|
539
|
-
if (!normalCompletion && it.return != null) it.return();
|
|
540
|
-
} finally {
|
|
541
|
-
if (didErr) throw err;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
function _toPrimitive(input, hint) {
|
|
547
|
-
if (typeof input !== "object" || input === null) return input;
|
|
548
|
-
var prim = input[Symbol.toPrimitive];
|
|
549
|
-
if (prim !== undefined) {
|
|
550
|
-
var res = prim.call(input, hint || "default");
|
|
551
|
-
if (typeof res !== "object") return res;
|
|
552
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
553
|
-
}
|
|
554
|
-
return (hint === "string" ? String : Number)(input);
|
|
555
|
-
}
|
|
556
|
-
function _toPropertyKey(arg) {
|
|
557
|
-
var key = _toPrimitive(arg, "string");
|
|
558
|
-
return typeof key === "symbol" ? key : String(key);
|
|
559
548
|
}
|
|
560
549
|
var store;
|
|
561
550
|
function getGlobalConfig(config2) {
|
|
@@ -661,6 +650,19 @@
|
|
|
661
650
|
function getDefault(schema, dataset, config2) {
|
|
662
651
|
return typeof schema["default"] === "function" ? schema["default"](dataset, config2) : schema["default"];
|
|
663
652
|
}
|
|
653
|
+
function any() {
|
|
654
|
+
return {
|
|
655
|
+
kind: "schema",
|
|
656
|
+
type: "any",
|
|
657
|
+
reference: any,
|
|
658
|
+
expects: "any",
|
|
659
|
+
async: false,
|
|
660
|
+
_run: function _run(dataset) {
|
|
661
|
+
dataset.typed = true;
|
|
662
|
+
return dataset;
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
}
|
|
664
666
|
function array(item, message) {
|
|
665
667
|
return {
|
|
666
668
|
kind: "schema",
|
|
@@ -744,16 +746,35 @@
|
|
|
744
746
|
}
|
|
745
747
|
};
|
|
746
748
|
}
|
|
747
|
-
function
|
|
749
|
+
function literal(literal_, message) {
|
|
748
750
|
return {
|
|
749
751
|
kind: "schema",
|
|
750
|
-
type: "
|
|
751
|
-
reference:
|
|
752
|
-
expects:
|
|
752
|
+
type: "literal",
|
|
753
|
+
reference: literal,
|
|
754
|
+
expects: _stringify(literal_),
|
|
753
755
|
async: false,
|
|
756
|
+
literal: literal_,
|
|
754
757
|
message: message,
|
|
755
758
|
_run: function _run(dataset, config2) {
|
|
756
|
-
if (
|
|
759
|
+
if (dataset.value === this.literal) {
|
|
760
|
+
dataset.typed = true;
|
|
761
|
+
} else {
|
|
762
|
+
_addIssue(this, "type", dataset, config2);
|
|
763
|
+
}
|
|
764
|
+
return dataset;
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
function number(message) {
|
|
769
|
+
return {
|
|
770
|
+
kind: "schema",
|
|
771
|
+
type: "number",
|
|
772
|
+
reference: number,
|
|
773
|
+
expects: "number",
|
|
774
|
+
async: false,
|
|
775
|
+
message: message,
|
|
776
|
+
_run: function _run(dataset, config2) {
|
|
777
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
|
|
757
778
|
dataset.typed = true;
|
|
758
779
|
} else {
|
|
759
780
|
_addIssue(this, "type", dataset, config2);
|
|
@@ -1242,41 +1263,20 @@
|
|
|
1242
1263
|
});
|
|
1243
1264
|
}
|
|
1244
1265
|
};
|
|
1245
|
-
var SafeFetchCommonRespondErrorType;
|
|
1246
|
-
(function(SafeFetchCommonRespondErrorType) {
|
|
1247
|
-
SafeFetchCommonRespondErrorType["UnexpectedRespond"] = "UnexpectedRespond";
|
|
1248
|
-
})(SafeFetchCommonRespondErrorType || (SafeFetchCommonRespondErrorType = {}));
|
|
1249
|
-
var SafeFetchErrorType;
|
|
1250
|
-
(function(SafeFetchErrorType) {
|
|
1251
|
-
SafeFetchErrorType["HttpError"] = "HttpError";
|
|
1252
|
-
SafeFetchErrorType["UnknownError"] = "UnknownError";
|
|
1253
|
-
})(SafeFetchErrorType || (SafeFetchErrorType = {}));
|
|
1254
|
-
const safeFetch = async (input, init) => {
|
|
1255
|
-
try {
|
|
1256
|
-
const response = await fetch(input, init);
|
|
1257
|
-
if (response.status > 299 || response.status < 200) {
|
|
1258
|
-
return err({
|
|
1259
|
-
type: SafeFetchErrorType.HttpError,
|
|
1260
|
-
message: `HTTP error, status = ${response.status}`,
|
|
1261
|
-
status: response.status
|
|
1262
|
-
});
|
|
1263
|
-
}
|
|
1264
|
-
return ok(response);
|
|
1265
|
-
} catch (error) {
|
|
1266
|
-
return err({
|
|
1267
|
-
type: SafeFetchErrorType.UnknownError,
|
|
1268
|
-
message: "Unknown error",
|
|
1269
|
-
cause: error
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
};
|
|
1273
1266
|
exports.MobileCredentialVerificationReasonType = void 0;
|
|
1274
1267
|
(function(MobileCredentialVerificationReasonType) {
|
|
1275
|
-
MobileCredentialVerificationReasonType["
|
|
1276
|
-
MobileCredentialVerificationReasonType["
|
|
1277
|
-
MobileCredentialVerificationReasonType["
|
|
1278
|
-
MobileCredentialVerificationReasonType["
|
|
1279
|
-
MobileCredentialVerificationReasonType["
|
|
1268
|
+
MobileCredentialVerificationReasonType["TrustedIssuerCertificateExpired"] = "TrustedIssuerCertificateExpired";
|
|
1269
|
+
MobileCredentialVerificationReasonType["TrustedIssuerCertificateNotYetValid"] = "TrustedIssuerCertificateNotYetValid";
|
|
1270
|
+
MobileCredentialVerificationReasonType["IssuerNotTrusted"] = "IssuerNotTrusted";
|
|
1271
|
+
MobileCredentialVerificationReasonType["MobileCredentialInvalid"] = "MobileCredentialInvalid";
|
|
1272
|
+
MobileCredentialVerificationReasonType["MobileCredentialExpired"] = "MobileCredentialExpired";
|
|
1273
|
+
MobileCredentialVerificationReasonType["MobileCredentialNotYetValid"] = "MobileCredentialNotYetValid";
|
|
1274
|
+
MobileCredentialVerificationReasonType["InvalidSignerCertificate"] = "InvalidSignerCertificate";
|
|
1275
|
+
MobileCredentialVerificationReasonType["DeviceKeyInvalid"] = "DeviceKeyInvalid";
|
|
1276
|
+
MobileCredentialVerificationReasonType["UnsupportedCurve"] = "UnsupportedCurve";
|
|
1277
|
+
MobileCredentialVerificationReasonType["StatusRevoked"] = "StatusRevoked";
|
|
1278
|
+
MobileCredentialVerificationReasonType["StatusSuspended"] = "StatusSuspended";
|
|
1279
|
+
MobileCredentialVerificationReasonType["StatusUnknown"] = "StatusUnknown";
|
|
1280
1280
|
})(exports.MobileCredentialVerificationReasonType || (exports.MobileCredentialVerificationReasonType = {}));
|
|
1281
1281
|
exports.ClaimType = void 0;
|
|
1282
1282
|
(function(ClaimType) {
|
|
@@ -1302,6 +1302,13 @@
|
|
|
1302
1302
|
(function(OpenidPresentationCredentialProfileSupported) {
|
|
1303
1303
|
OpenidPresentationCredentialProfileSupported["MOBILE"] = "mobile";
|
|
1304
1304
|
})(exports.OpenidPresentationCredentialProfileSupported || (exports.OpenidPresentationCredentialProfileSupported = {}));
|
|
1305
|
+
var PresentationStatusCode;
|
|
1306
|
+
(function(PresentationStatusCode) {
|
|
1307
|
+
PresentationStatusCode["AwaitingRequestRetrieval"] = "AwaitingRequestRetrieval";
|
|
1308
|
+
PresentationStatusCode["AwaitingResponse"] = "AwaitingResponse";
|
|
1309
|
+
PresentationStatusCode["ResponseSubmitted"] = "ResponseSubmitted";
|
|
1310
|
+
PresentationStatusCode["ResultReady"] = "ResultReady";
|
|
1311
|
+
})(PresentationStatusCode || (PresentationStatusCode = {}));
|
|
1305
1312
|
const CredentialQueryValidator = object({
|
|
1306
1313
|
profile: picklist([ exports.OpenidPresentationCredentialProfileSupported.MOBILE ]),
|
|
1307
1314
|
docType: string(),
|
|
@@ -1317,6 +1324,13 @@
|
|
|
1317
1324
|
PresentationErrorType["WalletUnavailable"] = "WalletUnavailable";
|
|
1318
1325
|
PresentationErrorType["Unknown"] = "Unknown";
|
|
1319
1326
|
})(PresentationErrorType || (PresentationErrorType = {}));
|
|
1327
|
+
const PresentationSuccessResultValidator = object({
|
|
1328
|
+
sessionId: string(),
|
|
1329
|
+
challenge: string(),
|
|
1330
|
+
credentialQuery: array(CredentialQueryValidator),
|
|
1331
|
+
credentials: optional(array(any())),
|
|
1332
|
+
credentialErrors: optional(array(any()))
|
|
1333
|
+
});
|
|
1320
1334
|
const PresentationResultRelaxValidator = object({
|
|
1321
1335
|
sessionId: string(),
|
|
1322
1336
|
challenge: optional(string()),
|
|
@@ -1325,79 +1339,194 @@
|
|
|
1325
1339
|
credentialErrors: optional(unknown()),
|
|
1326
1340
|
error: optional(unknown())
|
|
1327
1341
|
});
|
|
1342
|
+
const PresentationFailureResultValidator = object({
|
|
1343
|
+
sessionId: string(),
|
|
1344
|
+
challenge: string(),
|
|
1345
|
+
credentialQuery: array(CredentialQueryValidator),
|
|
1346
|
+
error: object({
|
|
1347
|
+
type: picklist(Object.values(PresentationErrorType)),
|
|
1348
|
+
message: string()
|
|
1349
|
+
})
|
|
1350
|
+
});
|
|
1351
|
+
const PresentationSessionResultValidator = union([ PresentationSuccessResultValidator, PresentationFailureResultValidator ]);
|
|
1352
|
+
exports.Mode = void 0;
|
|
1353
|
+
(function(Mode) {
|
|
1354
|
+
Mode["SameDevice"] = "sameDevice";
|
|
1355
|
+
Mode["CrossDevice"] = "crossDevice";
|
|
1356
|
+
})(exports.Mode || (exports.Mode = {}));
|
|
1357
|
+
var SessionType;
|
|
1358
|
+
(function(SessionType) {
|
|
1359
|
+
SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
|
|
1360
|
+
SessionType["Openid4vp"] = "openid4vp";
|
|
1361
|
+
})(SessionType || (SessionType = {}));
|
|
1328
1362
|
object({
|
|
1329
1363
|
credentialQuery: array(CredentialQueryValidator),
|
|
1330
1364
|
challenge: string(),
|
|
1331
1365
|
redirectUri: optional(string()),
|
|
1332
|
-
walletProviderId: optional(string())
|
|
1366
|
+
walletProviderId: optional(string()),
|
|
1367
|
+
dcApiSupported: optional(_boolean())
|
|
1368
|
+
});
|
|
1369
|
+
const CreateSessionDigitalCredentialsValidator = object({
|
|
1370
|
+
type: literal(SessionType.DigitalCredentialsApi),
|
|
1371
|
+
sessionId: string(),
|
|
1372
|
+
sessionKey: string(),
|
|
1373
|
+
sessionTtl: number(),
|
|
1374
|
+
request: record(string(), any())
|
|
1333
1375
|
});
|
|
1334
|
-
const
|
|
1376
|
+
const CreateSessionOpenId4vpResponseValidator = object({
|
|
1377
|
+
type: optional(literal(SessionType.Openid4vp)),
|
|
1335
1378
|
sessionId: string(),
|
|
1379
|
+
sessionKey: string(),
|
|
1336
1380
|
sessionUrl: string()
|
|
1337
1381
|
});
|
|
1382
|
+
const CreateSessionResponseValidator = union([ CreateSessionDigitalCredentialsValidator, CreateSessionOpenId4vpResponseValidator ]);
|
|
1383
|
+
const GetSessionStatusResponseValidator = union([ object({
|
|
1384
|
+
status: picklist([ PresentationStatusCode.ResultReady ]),
|
|
1385
|
+
responseCode: optional(string())
|
|
1386
|
+
}), object({
|
|
1387
|
+
status: string()
|
|
1388
|
+
}) ]);
|
|
1338
1389
|
var LocalStorageKey;
|
|
1339
1390
|
(function(LocalStorageKey) {
|
|
1340
1391
|
LocalStorageKey["challenge"] = "mattr_chg";
|
|
1341
1392
|
LocalStorageKey["sessionId"] = "mattr_sid";
|
|
1342
1393
|
})(LocalStorageKey || (LocalStorageKey = {}));
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
Mode["sameDevice"] = "sameDevice";
|
|
1346
|
-
Mode["crossDevice"] = "crossDevice";
|
|
1347
|
-
})(exports.Mode || (exports.Mode = {}));
|
|
1394
|
+
const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
|
|
1395
|
+
const MATTR_SDK_VERSION_VALUE = "2.0.0";
|
|
1348
1396
|
var MessageEventDataType;
|
|
1349
1397
|
(function(MessageEventDataType) {
|
|
1350
1398
|
MessageEventDataType["PresentationCompleted"] = "PresentationCompleted";
|
|
1351
1399
|
MessageEventDataType["PresentationTimeout"] = "PresentationTimeout";
|
|
1352
1400
|
MessageEventDataType["PresentationAbort"] = "PresentationAbort";
|
|
1353
1401
|
})(MessageEventDataType || (MessageEventDataType = {}));
|
|
1354
|
-
const
|
|
1355
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1356
|
-
redirectUri: string(),
|
|
1357
|
-
challenge: optional(string()),
|
|
1402
|
+
const OpenId4vpConfigSameDeviceOptionsValidator = object({
|
|
1358
1403
|
walletProviderId: optional(string()),
|
|
1359
|
-
mode:
|
|
1404
|
+
mode: literal(exports.Mode.SameDevice),
|
|
1405
|
+
redirectUri: string()
|
|
1360
1406
|
});
|
|
1361
|
-
const
|
|
1362
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1363
|
-
crossDeviceCallback: object({
|
|
1364
|
-
onComplete: function_(),
|
|
1365
|
-
onFailure: function_()
|
|
1366
|
-
}),
|
|
1367
|
-
challenge: optional(string()),
|
|
1407
|
+
const OpenId4vpConfigCrossDeviceOptionsValidator = object({
|
|
1368
1408
|
walletProviderId: optional(string()),
|
|
1369
|
-
mode:
|
|
1409
|
+
mode: literal(exports.Mode.CrossDevice)
|
|
1370
1410
|
});
|
|
1371
|
-
const
|
|
1372
|
-
|
|
1373
|
-
crossDeviceCallback: object({
|
|
1374
|
-
onComplete: function_(),
|
|
1375
|
-
onFailure: function_()
|
|
1376
|
-
}),
|
|
1411
|
+
const OpenId4vpConfigAutoDetectOptionsValidator = object({
|
|
1412
|
+
walletProviderId: optional(string()),
|
|
1377
1413
|
redirectUri: string(),
|
|
1414
|
+
mode: optional(picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
|
|
1415
|
+
});
|
|
1416
|
+
const RequestCredentialsOptionsValidator = object({
|
|
1417
|
+
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1378
1418
|
challenge: optional(string()),
|
|
1379
|
-
|
|
1380
|
-
mode: optional(picklist([ exports.Mode.crossDevice, exports.Mode.sameDevice ]))
|
|
1419
|
+
openid4vpConfiguration: optional(union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
|
|
1381
1420
|
});
|
|
1382
|
-
const RequestCredentialsOptionsValidator = union([ RequestCredentialsSameDeviceOptionsValidator, RequestCredentialsCrossDeviceOptionsValidator, RequestCredentialsAutoDetectDeviceOptionsValidator ]);
|
|
1383
1421
|
exports.RequestCredentialsErrorType = void 0;
|
|
1384
1422
|
(function(RequestCredentialsErrorType) {
|
|
1385
1423
|
RequestCredentialsErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
|
|
1424
|
+
RequestCredentialsErrorType["Timeout"] = "Timeout";
|
|
1425
|
+
RequestCredentialsErrorType["Abort"] = "Abort";
|
|
1386
1426
|
})(exports.RequestCredentialsErrorType || (exports.RequestCredentialsErrorType = {}));
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1427
|
+
var RequestCredentialsErrorMessage;
|
|
1428
|
+
(function(RequestCredentialsErrorMessage) {
|
|
1429
|
+
RequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1430
|
+
RequestCredentialsErrorMessage["FailedToGetSessionStatus"] = "Failed to get session status";
|
|
1431
|
+
RequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1432
|
+
RequestCredentialsErrorMessage["FailedToVerifyCredentialResponse"] = "Failed to verify credential response";
|
|
1433
|
+
RequestCredentialsErrorMessage["MissingOpenId4vpConfig"] = "Identified openid4vp session, but missing openId4vpConfiguration on `requestCredentials`";
|
|
1434
|
+
RequestCredentialsErrorMessage["DcApiError"] = "Failed to request credentials with Digital Credentials API";
|
|
1435
|
+
RequestCredentialsErrorMessage["DcApiResponseParseError"] = "Failed to parse response from Digital Credentials API";
|
|
1436
|
+
RequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1437
|
+
RequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1438
|
+
})(RequestCredentialsErrorMessage || (RequestCredentialsErrorMessage = {}));
|
|
1439
|
+
exports.AbortSessionErrorType = void 0;
|
|
1440
|
+
(function(AbortSessionErrorType) {
|
|
1441
|
+
AbortSessionErrorType["AbortSessionFailed"] = "AbortSessionFailed";
|
|
1442
|
+
})(exports.AbortSessionErrorType || (exports.AbortSessionErrorType = {}));
|
|
1443
|
+
var AbortSessionErrorMessage;
|
|
1444
|
+
(function(AbortSessionErrorMessage) {
|
|
1445
|
+
AbortSessionErrorMessage["FailedToAbortSession"] = "Failed to abort session";
|
|
1446
|
+
})(AbortSessionErrorMessage || (AbortSessionErrorMessage = {}));
|
|
1447
|
+
const InitializeOptionsValidator = object({
|
|
1448
|
+
apiBaseUrl: pipe(string(), nonEmpty("Must not be empty")),
|
|
1449
|
+
applicationId: pipe(string(), nonEmpty("Must not be empty"))
|
|
1390
1450
|
});
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1451
|
+
var SafeFetchCommonResponseErrorType;
|
|
1452
|
+
(function(SafeFetchCommonResponseErrorType) {
|
|
1453
|
+
SafeFetchCommonResponseErrorType["UnexpectedResponse"] = "UnexpectedResponse";
|
|
1454
|
+
})(SafeFetchCommonResponseErrorType || (SafeFetchCommonResponseErrorType = {}));
|
|
1455
|
+
var SafeFetchErrorType;
|
|
1456
|
+
(function(SafeFetchErrorType) {
|
|
1457
|
+
SafeFetchErrorType["HttpError"] = "HttpError";
|
|
1458
|
+
SafeFetchErrorType["UnknownError"] = "UnknownError";
|
|
1459
|
+
})(SafeFetchErrorType || (SafeFetchErrorType = {}));
|
|
1460
|
+
const safeFetch = async (input, init) => {
|
|
1461
|
+
try {
|
|
1462
|
+
const headers = Object.assign(Object.assign({}, init === null || init === void 0 ? void 0 : init.headers), {
|
|
1463
|
+
[MATTR_SDK_VERSION_HEADER]: `verifier-sdk-web/${MATTR_SDK_VERSION_VALUE}`
|
|
1464
|
+
});
|
|
1465
|
+
const response = await fetch(input, Object.assign(Object.assign({}, init), {
|
|
1466
|
+
headers: headers
|
|
1467
|
+
}));
|
|
1468
|
+
if (response.status > 299 || response.status < 200) {
|
|
1469
|
+
return err({
|
|
1470
|
+
type: SafeFetchErrorType.HttpError,
|
|
1471
|
+
message: `HTTP error, status = ${response.status}`,
|
|
1472
|
+
status: response.status
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
return ok(response);
|
|
1476
|
+
} catch (error) {
|
|
1477
|
+
return err({
|
|
1478
|
+
type: SafeFetchErrorType.UnknownError,
|
|
1479
|
+
message: "Unknown error",
|
|
1480
|
+
cause: error
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
let initializeOptions = undefined;
|
|
1485
|
+
var InitializeErrorMessage;
|
|
1486
|
+
(function(InitializeErrorMessage) {
|
|
1487
|
+
InitializeErrorMessage["SdkNotInitialized"] = "SDK not initialized";
|
|
1488
|
+
})(InitializeErrorMessage || (InitializeErrorMessage = {}));
|
|
1489
|
+
const initialize = options => {
|
|
1490
|
+
assertType(InitializeOptionsValidator, "Invalid initialize options")(options);
|
|
1491
|
+
initializeOptions = options;
|
|
1492
|
+
};
|
|
1493
|
+
const getInitializeOptions = () => initializeOptions;
|
|
1494
|
+
let sessionAbortController = undefined;
|
|
1495
|
+
let _sessionId = undefined;
|
|
1496
|
+
let _sessionKey = undefined;
|
|
1497
|
+
let _sessionTimeoutId = undefined;
|
|
1498
|
+
const getActiveSession = () => {
|
|
1499
|
+
const sessionId = _sessionId;
|
|
1500
|
+
const sessionKey = _sessionKey;
|
|
1501
|
+
const sessionTimeoutId = _sessionTimeoutId;
|
|
1502
|
+
if (sessionId) {
|
|
1503
|
+
return {
|
|
1504
|
+
sessionId: sessionId,
|
|
1505
|
+
sessionKey: sessionKey,
|
|
1506
|
+
sessionTimeoutId: sessionTimeoutId
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
return undefined;
|
|
1510
|
+
};
|
|
1511
|
+
const setActiveSession = session => {
|
|
1512
|
+
const {sessionId: sessionId, sessionKey: sessionKey, sessionTimeoutId: sessionTimeoutId} = session;
|
|
1513
|
+
_sessionId = sessionId;
|
|
1514
|
+
_sessionKey = sessionKey;
|
|
1515
|
+
_sessionTimeoutId = sessionTimeoutId;
|
|
1516
|
+
const abortController = new AbortController;
|
|
1517
|
+
sessionAbortController = abortController;
|
|
1518
|
+
return abortController;
|
|
1519
|
+
};
|
|
1520
|
+
const removeActiveSession = () => {
|
|
1521
|
+
sessionAbortController === null || sessionAbortController === void 0 ? void 0 : sessionAbortController.abort();
|
|
1522
|
+
if (_sessionTimeoutId) {
|
|
1523
|
+
window.clearTimeout(_sessionTimeoutId);
|
|
1524
|
+
}
|
|
1525
|
+
sessionAbortController = undefined;
|
|
1526
|
+
_sessionKey = undefined;
|
|
1527
|
+
_sessionId = undefined;
|
|
1528
|
+
_sessionTimeoutId = undefined;
|
|
1399
1529
|
};
|
|
1400
|
-
const getInitialiseOptions = () => initialiseOptions;
|
|
1401
1530
|
var isMobile_1 = isMobile;
|
|
1402
1531
|
var isMobile_2 = isMobile;
|
|
1403
1532
|
var default_1 = isMobile;
|
|
@@ -1422,6 +1551,23 @@
|
|
|
1422
1551
|
isMobile_1["default"] = default_1;
|
|
1423
1552
|
const defaultRetryDelay = attempt => Math.pow(2, attempt) * 1e3;
|
|
1424
1553
|
const defaultRetry = 2;
|
|
1554
|
+
const withRetry = async (fn, options) => {
|
|
1555
|
+
const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0} = options;
|
|
1556
|
+
try {
|
|
1557
|
+
return await fn();
|
|
1558
|
+
} catch (err) {
|
|
1559
|
+
if (retries > 0) {
|
|
1560
|
+
const delay = typeof retryDelay === "function" ? retryDelay(attempt) : retryDelay;
|
|
1561
|
+
await new Promise((resolve => setTimeout(resolve, delay)));
|
|
1562
|
+
return await withRetry(fn, Object.assign(Object.assign({}, options), {
|
|
1563
|
+
retries: retries - 1,
|
|
1564
|
+
retryDelay: retryDelay,
|
|
1565
|
+
attempt: attempt + 1
|
|
1566
|
+
}));
|
|
1567
|
+
}
|
|
1568
|
+
throw err;
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1425
1571
|
const withRetrySafeFetch = async (fn, options) => {
|
|
1426
1572
|
const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0, retryHttpStatus: retryHttpStatus} = options;
|
|
1427
1573
|
const result = await fn();
|
|
@@ -1447,17 +1593,15 @@
|
|
|
1447
1593
|
const urlParams = new URLSearchParams(hash.split("#")[1]);
|
|
1448
1594
|
return urlParams.get(param);
|
|
1449
1595
|
};
|
|
1450
|
-
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl,
|
|
1451
|
-
const postData =
|
|
1596
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
|
|
1597
|
+
const postData = {
|
|
1452
1598
|
credentialQuery: credentialQuery,
|
|
1453
|
-
challenge: challenge
|
|
1454
|
-
|
|
1455
|
-
redirectUri: redirectUri
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
}
|
|
1459
|
-
walletProviderId: walletProviderId
|
|
1460
|
-
} : {});
|
|
1599
|
+
challenge: challenge,
|
|
1600
|
+
applicationId: applicationId,
|
|
1601
|
+
redirectUri: redirectUri,
|
|
1602
|
+
walletProviderId: walletProviderId,
|
|
1603
|
+
dcApiSupported: dcApiSupported
|
|
1604
|
+
};
|
|
1461
1605
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
|
|
1462
1606
|
method: "POST",
|
|
1463
1607
|
headers: {
|
|
@@ -1471,8 +1615,40 @@
|
|
|
1471
1615
|
const data = await responseResult.value.json();
|
|
1472
1616
|
if (!isType(CreateSessionResponseValidator)(data)) {
|
|
1473
1617
|
return err({
|
|
1474
|
-
type:
|
|
1475
|
-
message: "Create session
|
|
1618
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1619
|
+
message: "Create session returned unsupported response"
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
return ok(data);
|
|
1623
|
+
};
|
|
1624
|
+
const abortSession = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
|
|
1625
|
+
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/abort`, {
|
|
1626
|
+
method: "POST",
|
|
1627
|
+
headers: {
|
|
1628
|
+
"Content-Type": "application/json",
|
|
1629
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1630
|
+
}
|
|
1631
|
+
});
|
|
1632
|
+
if (responseResult.isErr()) {
|
|
1633
|
+
return err(responseResult.error);
|
|
1634
|
+
}
|
|
1635
|
+
return ok(undefined);
|
|
1636
|
+
};
|
|
1637
|
+
const getSessionStatus = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
|
|
1638
|
+
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/status`, {
|
|
1639
|
+
method: "GET",
|
|
1640
|
+
headers: {
|
|
1641
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
if (responseResult.isErr()) {
|
|
1645
|
+
return err(responseResult.error);
|
|
1646
|
+
}
|
|
1647
|
+
const data = await responseResult.value.json();
|
|
1648
|
+
if (!isType(GetSessionStatusResponseValidator)(data)) {
|
|
1649
|
+
return err({
|
|
1650
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1651
|
+
message: "Get session status return unsupported response"
|
|
1476
1652
|
});
|
|
1477
1653
|
}
|
|
1478
1654
|
return ok(data);
|
|
@@ -1499,7 +1675,7 @@
|
|
|
1499
1675
|
const data = await responseResult.value.json();
|
|
1500
1676
|
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
1501
1677
|
return err({
|
|
1502
|
-
type:
|
|
1678
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1503
1679
|
message: "Exchange session result return unsupported response",
|
|
1504
1680
|
details: {
|
|
1505
1681
|
data: data
|
|
@@ -1512,26 +1688,17 @@
|
|
|
1512
1688
|
ua: userAgent,
|
|
1513
1689
|
tablet: false
|
|
1514
1690
|
});
|
|
1515
|
-
|
|
1516
|
-
(function(CrossDeviceCallbackErrorType) {
|
|
1517
|
-
CrossDeviceCallbackErrorType["Timeout"] = "Timeout";
|
|
1518
|
-
CrossDeviceCallbackErrorType["Abort"] = "Abort";
|
|
1519
|
-
CrossDeviceCallbackErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
|
|
1520
|
-
})(exports.CrossDeviceCallbackErrorType || (exports.CrossDeviceCallbackErrorType = {}));
|
|
1521
|
-
var CrossDeviceRequestCredentialsErrorMessage;
|
|
1522
|
-
(function(CrossDeviceRequestCredentialsErrorMessage) {
|
|
1523
|
-
CrossDeviceRequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1524
|
-
CrossDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1525
|
-
CrossDeviceRequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1526
|
-
CrossDeviceRequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1527
|
-
})(CrossDeviceRequestCredentialsErrorMessage || (CrossDeviceRequestCredentialsErrorMessage = {}));
|
|
1691
|
+
const getVersion = () => MATTR_SDK_VERSION_VALUE;
|
|
1528
1692
|
var WindowEventListenerType;
|
|
1529
1693
|
(function(WindowEventListenerType) {
|
|
1530
1694
|
WindowEventListenerType["message"] = "message";
|
|
1531
1695
|
})(WindowEventListenerType || (WindowEventListenerType = {}));
|
|
1532
|
-
let listener;
|
|
1696
|
+
let listener = undefined;
|
|
1533
1697
|
const removeWindowMessageEventListener = () => {
|
|
1534
|
-
|
|
1698
|
+
if (listener) {
|
|
1699
|
+
window.removeEventListener(WindowEventListenerType.message, listener, false);
|
|
1700
|
+
}
|
|
1701
|
+
listener = undefined;
|
|
1535
1702
|
};
|
|
1536
1703
|
const closeCrossDeviceModal = options => {
|
|
1537
1704
|
const {container: container} = options;
|
|
@@ -1541,8 +1708,7 @@
|
|
|
1541
1708
|
removeWindowMessageEventListener();
|
|
1542
1709
|
};
|
|
1543
1710
|
const receiveMessageHandler = options => async event => {
|
|
1544
|
-
const {
|
|
1545
|
-
const {onComplete: onComplete, onFailure: onFailure} = crossDeviceCallback;
|
|
1711
|
+
const {onComplete: onComplete, onFailure: onFailure, container: container, sessionId: sessionId, apiBaseUrl: apiBaseUrl, challenge: challenge} = options;
|
|
1546
1712
|
if (event.origin !== apiBaseUrl) {
|
|
1547
1713
|
return;
|
|
1548
1714
|
}
|
|
@@ -1556,8 +1722,8 @@
|
|
|
1556
1722
|
});
|
|
1557
1723
|
if (result.isErr()) {
|
|
1558
1724
|
onFailure({
|
|
1559
|
-
type: exports.
|
|
1560
|
-
message:
|
|
1725
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1726
|
+
message: RequestCredentialsErrorMessage.FailedToGetSessionResult
|
|
1561
1727
|
});
|
|
1562
1728
|
closeCrossDeviceModal({
|
|
1563
1729
|
container: container
|
|
@@ -1565,8 +1731,9 @@
|
|
|
1565
1731
|
return;
|
|
1566
1732
|
}
|
|
1567
1733
|
onComplete({
|
|
1568
|
-
result: result.value,
|
|
1569
|
-
sessionId: result.value.sessionId
|
|
1734
|
+
result: isType(PresentationSessionResultValidator)(result.value) ? result.value : undefined,
|
|
1735
|
+
sessionId: result.value.sessionId,
|
|
1736
|
+
sessionCompletedInRedirect: false
|
|
1570
1737
|
});
|
|
1571
1738
|
closeCrossDeviceModal({
|
|
1572
1739
|
container: container
|
|
@@ -1575,8 +1742,8 @@
|
|
|
1575
1742
|
}
|
|
1576
1743
|
if (event.data.type === MessageEventDataType.PresentationTimeout) {
|
|
1577
1744
|
onFailure({
|
|
1578
|
-
type: exports.
|
|
1579
|
-
message:
|
|
1745
|
+
type: exports.RequestCredentialsErrorType.Timeout,
|
|
1746
|
+
message: RequestCredentialsErrorMessage.Timeout
|
|
1580
1747
|
});
|
|
1581
1748
|
closeCrossDeviceModal({
|
|
1582
1749
|
container: container
|
|
@@ -1585,8 +1752,8 @@
|
|
|
1585
1752
|
}
|
|
1586
1753
|
if (event.data.type === MessageEventDataType.PresentationAbort) {
|
|
1587
1754
|
onFailure({
|
|
1588
|
-
type: exports.
|
|
1589
|
-
message:
|
|
1755
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
1756
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1590
1757
|
});
|
|
1591
1758
|
closeCrossDeviceModal({
|
|
1592
1759
|
container: container
|
|
@@ -1609,104 +1776,324 @@
|
|
|
1609
1776
|
modalContainer.setAttribute("class", "mattr-verifier-modal-container");
|
|
1610
1777
|
return modalContainer;
|
|
1611
1778
|
};
|
|
1612
|
-
const
|
|
1613
|
-
const {challenge: challenge,
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1779
|
+
const requestCredentialsWithCrossDevice = async options => {
|
|
1780
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = options;
|
|
1781
|
+
const container = openCrossDeviceModal({
|
|
1782
|
+
sessionUrl: sessionUrl
|
|
1783
|
+
});
|
|
1784
|
+
return await new Promise((resolve => {
|
|
1785
|
+
const abortController = setActiveSession({
|
|
1786
|
+
sessionId: sessionId,
|
|
1787
|
+
sessionKey: sessionKey
|
|
1788
|
+
});
|
|
1789
|
+
abortController.signal.addEventListener("abort", (() => {
|
|
1790
|
+
closeCrossDeviceModal({
|
|
1791
|
+
container: container
|
|
1792
|
+
});
|
|
1793
|
+
resolve(err({
|
|
1794
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
1795
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1796
|
+
}));
|
|
1797
|
+
}));
|
|
1798
|
+
removeWindowMessageEventListener();
|
|
1799
|
+
listener = receiveMessageHandler({
|
|
1800
|
+
container: container,
|
|
1801
|
+
sessionId: sessionId,
|
|
1802
|
+
apiBaseUrl: apiBaseUrl,
|
|
1803
|
+
challenge: challenge,
|
|
1804
|
+
onComplete: data => resolve(ok(data)),
|
|
1805
|
+
onFailure: error => resolve(err(error))
|
|
1806
|
+
});
|
|
1807
|
+
window.addEventListener(WindowEventListenerType.message, listener, false);
|
|
1808
|
+
}));
|
|
1809
|
+
};
|
|
1810
|
+
const abortCredentialRequest = async () => {
|
|
1811
|
+
const initializeOptions = getInitializeOptions();
|
|
1812
|
+
if (!initializeOptions) {
|
|
1813
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1814
|
+
}
|
|
1815
|
+
const {apiBaseUrl: apiBaseUrl} = initializeOptions;
|
|
1816
|
+
const session = getActiveSession();
|
|
1817
|
+
if (!session || !session.sessionKey) {
|
|
1818
|
+
return ok(undefined);
|
|
1819
|
+
}
|
|
1820
|
+
const {sessionId: sessionId, sessionKey: sessionKey} = session;
|
|
1821
|
+
removeActiveSession();
|
|
1822
|
+
const abortSessionResult = await abortSession({
|
|
1618
1823
|
apiBaseUrl: apiBaseUrl,
|
|
1619
|
-
|
|
1620
|
-
|
|
1824
|
+
sessionId: sessionId,
|
|
1825
|
+
sessionKey: sessionKey
|
|
1621
1826
|
});
|
|
1622
|
-
if (
|
|
1827
|
+
if (abortSessionResult.isErr()) {
|
|
1623
1828
|
return err({
|
|
1624
|
-
type: exports.
|
|
1625
|
-
message:
|
|
1626
|
-
cause:
|
|
1829
|
+
type: exports.AbortSessionErrorType.AbortSessionFailed,
|
|
1830
|
+
message: AbortSessionErrorMessage.FailedToAbortSession,
|
|
1831
|
+
cause: abortSessionResult.error
|
|
1627
1832
|
});
|
|
1628
1833
|
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
crossDeviceCallback: crossDeviceCallback,
|
|
1636
|
-
container: container,
|
|
1834
|
+
return ok(undefined);
|
|
1835
|
+
};
|
|
1836
|
+
const requestCredentialsWithDigitalCredentialsApi = async options => {
|
|
1837
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request, sessionTtl: sessionTtl} = options;
|
|
1838
|
+
const sessionTimeoutId = window.setTimeout((() => removeActiveSession()), sessionTtl * 1e3);
|
|
1839
|
+
const abortController = setActiveSession({
|
|
1637
1840
|
sessionId: sessionId,
|
|
1841
|
+
sessionKey: sessionKey,
|
|
1842
|
+
sessionTimeoutId: sessionTimeoutId
|
|
1843
|
+
});
|
|
1844
|
+
const credentialResponseResult = await getCredentials(request, abortController);
|
|
1845
|
+
if (credentialResponseResult.isErr()) {
|
|
1846
|
+
await abortCredentialRequest();
|
|
1847
|
+
return err(credentialResponseResult.error);
|
|
1848
|
+
}
|
|
1849
|
+
const credentialResponse = credentialResponseResult.value;
|
|
1850
|
+
const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
|
|
1851
|
+
if (parsedCredentialResponseResult.isErr()) {
|
|
1852
|
+
await abortCredentialRequest();
|
|
1853
|
+
return err(parsedCredentialResponseResult.error);
|
|
1854
|
+
}
|
|
1855
|
+
const parsedCredentialResponse = parsedCredentialResponseResult.value;
|
|
1856
|
+
const credentialVerificationResult = await verifyCredentialResponse({
|
|
1638
1857
|
apiBaseUrl: apiBaseUrl,
|
|
1639
|
-
|
|
1858
|
+
sessionId: sessionId,
|
|
1859
|
+
sessionKey: sessionKey,
|
|
1860
|
+
challenge: challenge,
|
|
1861
|
+
protocol: parsedCredentialResponse.protocol,
|
|
1862
|
+
data: parsedCredentialResponse.data
|
|
1640
1863
|
});
|
|
1641
|
-
|
|
1864
|
+
if (credentialVerificationResult.isErr()) {
|
|
1865
|
+
return err({
|
|
1866
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1867
|
+
message: RequestCredentialsErrorMessage.FailedToVerifyCredentialResponse,
|
|
1868
|
+
cause: credentialVerificationResult.error
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
const verificationResult = credentialVerificationResult.value;
|
|
1642
1872
|
return ok({
|
|
1873
|
+
result: isType(PresentationSessionResultValidator)(verificationResult) ? verificationResult : undefined,
|
|
1643
1874
|
sessionId: sessionId
|
|
1644
1875
|
});
|
|
1645
1876
|
};
|
|
1877
|
+
const getCredentials = async (request, abortController) => {
|
|
1878
|
+
try {
|
|
1879
|
+
const credentialResponse = await navigator.credentials.get(Object.assign(Object.assign({}, request), {
|
|
1880
|
+
signal: abortController.signal
|
|
1881
|
+
}));
|
|
1882
|
+
return ok(credentialResponse);
|
|
1883
|
+
} catch (exception) {
|
|
1884
|
+
return err({
|
|
1885
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1886
|
+
message: RequestCredentialsErrorMessage.DcApiError,
|
|
1887
|
+
cause: exception
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
const parseCredentialResponse = credentialResponse => {
|
|
1892
|
+
if (!credentialResponse) {
|
|
1893
|
+
return err({
|
|
1894
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1895
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
1896
|
+
details: {
|
|
1897
|
+
response: credentialResponse
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
if (typeof credentialResponse === "object") {
|
|
1902
|
+
return ok(credentialResponse);
|
|
1903
|
+
}
|
|
1904
|
+
if (typeof credentialResponse === "string") {
|
|
1905
|
+
try {
|
|
1906
|
+
const parsed = JSON.parse(credentialResponse);
|
|
1907
|
+
return ok(parsed);
|
|
1908
|
+
} catch (_a) {
|
|
1909
|
+
return err({
|
|
1910
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1911
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
1912
|
+
details: {
|
|
1913
|
+
response: credentialResponse
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
return err({
|
|
1919
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1920
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
1921
|
+
details: {
|
|
1922
|
+
response: credentialResponse
|
|
1923
|
+
}
|
|
1924
|
+
});
|
|
1925
|
+
};
|
|
1926
|
+
const verifyCredentialResponse = async options => {
|
|
1927
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, protocol: protocol, data: data} = options;
|
|
1928
|
+
const requestBody = {
|
|
1929
|
+
protocol: protocol,
|
|
1930
|
+
data: data,
|
|
1931
|
+
challenge: challenge
|
|
1932
|
+
};
|
|
1933
|
+
const credentialVerificationResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/dc-api/response`, {
|
|
1934
|
+
method: "POST",
|
|
1935
|
+
headers: {
|
|
1936
|
+
"Content-Type": "application/json",
|
|
1937
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1938
|
+
},
|
|
1939
|
+
body: JSON.stringify(requestBody)
|
|
1940
|
+
});
|
|
1941
|
+
if (credentialVerificationResult.isErr()) {
|
|
1942
|
+
return err(credentialVerificationResult.error);
|
|
1943
|
+
}
|
|
1944
|
+
const credentialVerificationResponse = await credentialVerificationResult.value.json();
|
|
1945
|
+
if (!isType(PresentationResultRelaxValidator)(credentialVerificationResponse)) {
|
|
1946
|
+
return err({
|
|
1947
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1948
|
+
message: "Verify credential returned unsupported response",
|
|
1949
|
+
details: {
|
|
1950
|
+
response: credentialVerificationResponse
|
|
1951
|
+
}
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
return ok(credentialVerificationResponse);
|
|
1955
|
+
};
|
|
1956
|
+
const isDigitalCredentialsApiSupported = () => {
|
|
1957
|
+
var _a;
|
|
1958
|
+
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";
|
|
1959
|
+
};
|
|
1960
|
+
const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
|
|
1961
|
+
const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
|
|
1962
|
+
const SESSION_STATUS_POLLING_INTERVAL_MS = 3e3;
|
|
1963
|
+
const SESSION_STATUS_POLLING_INITIAL_DELAY_MS = 3e3;
|
|
1646
1964
|
var SameDeviceRequestCredentialsErrorMessage;
|
|
1647
1965
|
(function(SameDeviceRequestCredentialsErrorMessage) {
|
|
1648
1966
|
SameDeviceRequestCredentialsErrorMessage["FailedToStoreChallenge"] = "Failed to store challenge";
|
|
1649
1967
|
SameDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1650
1968
|
})(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
|
|
1651
1969
|
const requestCredentialsSameDevice = async options => {
|
|
1652
|
-
const {challenge: challenge,
|
|
1653
|
-
const
|
|
1970
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, applicationId: applicationId, sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = options;
|
|
1971
|
+
const abortController = setActiveSession({
|
|
1972
|
+
sessionId: sessionId,
|
|
1973
|
+
sessionKey: sessionKey
|
|
1974
|
+
});
|
|
1975
|
+
window.localStorage.setItem(LocalStorageKey.sessionId, sessionId);
|
|
1654
1976
|
window.localStorage.setItem(LocalStorageKey.challenge, challenge);
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1977
|
+
window.location.assign(sessionUrl);
|
|
1978
|
+
await sleep(SESSION_STATUS_POLLING_INITIAL_DELAY_MS);
|
|
1979
|
+
const checkResult = await withRetry((async () => {
|
|
1980
|
+
const statusResult = await getSessionStatus({
|
|
1981
|
+
apiBaseUrl: apiBaseUrl,
|
|
1982
|
+
applicationId: applicationId,
|
|
1983
|
+
sessionId: sessionId,
|
|
1984
|
+
sessionKey: sessionKey
|
|
1660
1985
|
});
|
|
1986
|
+
if (abortController.signal.aborted) {
|
|
1987
|
+
return err({
|
|
1988
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
1989
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
if (statusResult.isErr()) {
|
|
1993
|
+
if (statusResult.error.status === 404) {
|
|
1994
|
+
return err({
|
|
1995
|
+
type: exports.RequestCredentialsErrorType.Timeout,
|
|
1996
|
+
message: RequestCredentialsErrorMessage.Timeout
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
throw Error("Unexpected status response. Retry");
|
|
2000
|
+
}
|
|
2001
|
+
if (statusResult.value.status !== PresentationStatusCode.ResultReady) {
|
|
2002
|
+
throw Error("Result is not ready. Retry");
|
|
2003
|
+
}
|
|
2004
|
+
return ok(undefined);
|
|
2005
|
+
}), {
|
|
2006
|
+
retries: SESSION_STATUS_POLLING_MAX_RETRY,
|
|
2007
|
+
retryDelay: SESSION_STATUS_POLLING_INTERVAL_MS
|
|
2008
|
+
});
|
|
2009
|
+
if (checkResult.isErr()) {
|
|
2010
|
+
return err(checkResult.error);
|
|
1661
2011
|
}
|
|
2012
|
+
window.close();
|
|
2013
|
+
return ok({
|
|
2014
|
+
sessionId: sessionId,
|
|
2015
|
+
sessionCompletedInRedirect: true
|
|
2016
|
+
});
|
|
2017
|
+
};
|
|
2018
|
+
const requestCredentials = async options => {
|
|
2019
|
+
var _a;
|
|
2020
|
+
const initializeOptions = getInitializeOptions();
|
|
2021
|
+
if (!initializeOptions) {
|
|
2022
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
2023
|
+
}
|
|
2024
|
+
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
2025
|
+
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initializeOptions;
|
|
2026
|
+
const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
|
|
2027
|
+
const dcApiSupported = isDigitalCredentialsApiSupported();
|
|
2028
|
+
const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
|
|
1662
2029
|
const createSessionResult = await createSession({
|
|
1663
2030
|
credentialQuery: credentialQuery,
|
|
1664
|
-
challenge:
|
|
1665
|
-
redirectUri:
|
|
2031
|
+
challenge: challenge,
|
|
2032
|
+
redirectUri: openId4VpRedirectUri,
|
|
2033
|
+
walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
|
|
1666
2034
|
apiBaseUrl: apiBaseUrl,
|
|
1667
2035
|
applicationId: applicationId,
|
|
1668
|
-
|
|
2036
|
+
dcApiSupported: dcApiSupported
|
|
1669
2037
|
});
|
|
1670
2038
|
if (createSessionResult.isErr()) {
|
|
1671
2039
|
return err({
|
|
1672
2040
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1673
|
-
message:
|
|
2041
|
+
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1674
2042
|
cause: createSessionResult.error
|
|
1675
2043
|
});
|
|
1676
2044
|
}
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
2045
|
+
const session = createSessionResult.value;
|
|
2046
|
+
const {sessionKey: sessionKey, sessionId: sessionId} = session;
|
|
2047
|
+
if (session.type === SessionType.DigitalCredentialsApi) {
|
|
2048
|
+
const {request: request, sessionTtl: sessionTtl} = session;
|
|
2049
|
+
return await requestCredentialsWithDigitalCredentialsApi({
|
|
2050
|
+
apiBaseUrl: apiBaseUrl,
|
|
2051
|
+
request: request,
|
|
2052
|
+
sessionId: sessionId,
|
|
2053
|
+
sessionKey: sessionKey,
|
|
2054
|
+
challenge: challenge,
|
|
2055
|
+
sessionTtl: sessionTtl
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
if (!openid4vpConfiguration) {
|
|
2059
|
+
return err({
|
|
2060
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2061
|
+
message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
const {sessionUrl: sessionUrl} = session;
|
|
2065
|
+
if (openId4VpRedirectUri) {
|
|
2066
|
+
return await requestCredentialsSameDevice({
|
|
2067
|
+
challenge: challenge,
|
|
2068
|
+
apiBaseUrl: apiBaseUrl,
|
|
2069
|
+
applicationId: applicationId,
|
|
2070
|
+
sessionUrl: sessionUrl,
|
|
2071
|
+
sessionKey: sessionKey,
|
|
2072
|
+
sessionId: sessionId
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
return await requestCredentialsWithCrossDevice({
|
|
2076
|
+
challenge: challenge,
|
|
2077
|
+
apiBaseUrl: apiBaseUrl,
|
|
2078
|
+
sessionUrl: sessionUrl,
|
|
2079
|
+
sessionKey: sessionKey,
|
|
1681
2080
|
sessionId: sessionId
|
|
1682
2081
|
});
|
|
1683
2082
|
};
|
|
1684
|
-
const
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
if (!initialiseOptions) {
|
|
1688
|
-
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
2083
|
+
const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
|
|
2084
|
+
if (!openid4vpConfiguration) {
|
|
2085
|
+
return undefined;
|
|
1689
2086
|
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
initialiseOptions: initialiseOptions,
|
|
1696
|
-
challenge: challenge,
|
|
1697
|
-
mode: mode
|
|
1698
|
-
}));
|
|
2087
|
+
let detectedMode;
|
|
2088
|
+
if (openid4vpConfiguration && openid4vpConfiguration.mode) {
|
|
2089
|
+
detectedMode = openid4vpConfiguration.mode;
|
|
2090
|
+
} else {
|
|
2091
|
+
detectedMode = isMobileDetect(navigator.userAgent) ? exports.Mode.SameDevice : exports.Mode.CrossDevice;
|
|
1699
2092
|
}
|
|
1700
|
-
if (
|
|
1701
|
-
return
|
|
1702
|
-
initialiseOptions: initialiseOptions,
|
|
1703
|
-
challenge: challenge,
|
|
1704
|
-
mode: mode
|
|
1705
|
-
}));
|
|
2093
|
+
if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
|
|
2094
|
+
return openid4vpConfiguration.redirectUri;
|
|
1706
2095
|
}
|
|
1707
|
-
|
|
1708
|
-
data: options
|
|
1709
|
-
});
|
|
2096
|
+
return undefined;
|
|
1710
2097
|
};
|
|
1711
2098
|
exports.HandleRedirectCallbackErrorType = void 0;
|
|
1712
2099
|
(function(HandleRedirectCallbackErrorType) {
|
|
@@ -1716,15 +2103,15 @@
|
|
|
1716
2103
|
(function(HandleRedirectCallbackErrorMessage) {
|
|
1717
2104
|
HandleRedirectCallbackErrorMessage["FailedToFindResponseCode"] = "Failed to find response code";
|
|
1718
2105
|
HandleRedirectCallbackErrorMessage["FailedToFindChallenge"] = "Failed to find challenge";
|
|
1719
|
-
HandleRedirectCallbackErrorMessage["
|
|
2106
|
+
HandleRedirectCallbackErrorMessage["FailedToFindActiveSession"] = "Failed to find active session";
|
|
1720
2107
|
HandleRedirectCallbackErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1721
2108
|
})(HandleRedirectCallbackErrorMessage || (HandleRedirectCallbackErrorMessage = {}));
|
|
1722
2109
|
const handleRedirectCallback = async () => {
|
|
1723
|
-
const
|
|
1724
|
-
if (!
|
|
1725
|
-
throw new Exception(
|
|
2110
|
+
const initializeOptions = getInitializeOptions();
|
|
2111
|
+
if (!initializeOptions) {
|
|
2112
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1726
2113
|
}
|
|
1727
|
-
const {apiBaseUrl: apiBaseUrl} =
|
|
2114
|
+
const {apiBaseUrl: apiBaseUrl} = initializeOptions;
|
|
1728
2115
|
const responseCode = getHashParamValue(window.location.hash, "response_code");
|
|
1729
2116
|
if (!responseCode) {
|
|
1730
2117
|
return err({
|
|
@@ -1732,18 +2119,12 @@
|
|
|
1732
2119
|
message: HandleRedirectCallbackErrorMessage.FailedToFindResponseCode
|
|
1733
2120
|
});
|
|
1734
2121
|
}
|
|
1735
|
-
const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
1736
|
-
if (!challenge) {
|
|
1737
|
-
return err({
|
|
1738
|
-
type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
|
|
1739
|
-
message: HandleRedirectCallbackErrorMessage.FailedToFindChallenge
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
2122
|
const sessionId = window.localStorage.getItem(LocalStorageKey.sessionId);
|
|
1743
|
-
|
|
2123
|
+
const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
2124
|
+
if (!sessionId || !challenge) {
|
|
1744
2125
|
return err({
|
|
1745
2126
|
type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
|
|
1746
|
-
message: HandleRedirectCallbackErrorMessage.
|
|
2127
|
+
message: HandleRedirectCallbackErrorMessage.FailedToFindActiveSession
|
|
1747
2128
|
});
|
|
1748
2129
|
}
|
|
1749
2130
|
const result = await exchangeSessionResult({
|
|
@@ -1760,16 +2141,19 @@
|
|
|
1760
2141
|
});
|
|
1761
2142
|
}
|
|
1762
2143
|
return ok({
|
|
1763
|
-
result: result.value,
|
|
2144
|
+
result: "challenge" in result.value ? result.value : undefined,
|
|
1764
2145
|
sessionId: result.value.sessionId
|
|
1765
2146
|
});
|
|
1766
2147
|
};
|
|
1767
2148
|
const utils = {
|
|
1768
2149
|
generateChallenge: generateChallenge,
|
|
2150
|
+
getVersion: getVersion,
|
|
1769
2151
|
unwrap: unwrap
|
|
1770
2152
|
};
|
|
2153
|
+
exports.abortCredentialRequest = abortCredentialRequest;
|
|
1771
2154
|
exports.handleRedirectCallback = handleRedirectCallback;
|
|
1772
|
-
exports.
|
|
2155
|
+
exports.initialize = initialize;
|
|
2156
|
+
exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
|
|
1773
2157
|
exports.requestCredentials = requestCredentials;
|
|
1774
2158
|
exports.utils = utils;
|
|
1775
2159
|
Object.defineProperty(exports, "__esModule", {
|