@mattrglobal/verifier-sdk-web 2.0.0-preview-digital-credential-api.4 → 2.0.0
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 +71 -86
- package/dist/lib/verifier-js-no-deps.cjs.js +608 -336
- package/dist/lib/verifier-js-no-deps.cjs.js.map +1 -1
- package/dist/lib/verifier-js.cjs.js +911 -511
- 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 -7
- 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/requestCredentials.d.ts +2 -2
- package/dist/typings/verifier/requestCredentialsCrossDevice.d.ts +3 -47
- package/dist/typings/verifier/requestCredentialsDigitalCredentialsApi.d.ts +17 -0
- package/dist/typings/verifier/requestCredentialsSameDevice.d.ts +1 -1
- package/dist/typings/verifier/types/credential-presentation.d.ts +136 -37
- package/dist/typings/verifier/types/verifier-web-sdk.d.ts +153 -214
- package/dist/typings/verifier/utils.d.ts +23 -37
- package/dist/verifier-js.development.js +866 -499
- package/dist/verifier-js.development.js.map +1 -1
- package/dist/verifier-js.production.esm.js +4 -4
- package/dist/verifier-js.production.esm.js.map +1 -1
- package/dist/verifier-js.production.js +4 -4
- package/dist/verifier-js.production.js.map +1 -1
- package/package.json +3 -3
- package/dist/typings/verifier/initialise.d.ts +0 -12
- package/dist/typings/verifier/requestCredentialsViaDigitalCredentialsApi.d.ts +0 -7
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* Do Not Translate or Localize
|
|
8
8
|
*
|
|
9
9
|
* Bundle of @mattrglobal/verifier-sdk-web
|
|
10
|
-
* Generated: 2025-
|
|
11
|
-
* Version: 2.0.0
|
|
10
|
+
* Generated: 2025-05-28
|
|
11
|
+
* Version: 2.0.0
|
|
12
12
|
* Dependencies:
|
|
13
13
|
*
|
|
14
14
|
* neverthrow -- 4.3.0
|
|
15
15
|
*
|
|
16
|
-
* valibot --
|
|
16
|
+
* valibot -- 1.1.0
|
|
17
17
|
*
|
|
18
18
|
* is-mobile -- 4.0.0
|
|
19
19
|
*/
|
|
@@ -605,9 +605,9 @@
|
|
|
605
605
|
abortPipeEarly: config2.abortPipeEarly
|
|
606
606
|
};
|
|
607
607
|
var isSchema = context.kind === "schema";
|
|
608
|
-
var
|
|
609
|
-
if (
|
|
610
|
-
issue.message = typeof
|
|
608
|
+
var message2 = (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_other$message = other === null || other === void 0 ? void 0 : other.message) !== null && _other$message !== void 0 ? _other$message : context.message) !== null && _ref6 !== void 0 ? _ref6 : getSpecificMessage(context.reference, issue.lang)) !== null && _ref5 !== void 0 ? _ref5 : isSchema ? getSchemaMessage(issue.lang) : null) !== null && _ref4 !== void 0 ? _ref4 : config2.message) !== null && _ref3 !== void 0 ? _ref3 : getGlobalMessage(issue.lang);
|
|
609
|
+
if (message2 !== void 0) {
|
|
610
|
+
issue.message = typeof message2 === "function" ? message2(issue) : message2;
|
|
611
611
|
}
|
|
612
612
|
if (isSchema) {
|
|
613
613
|
dataset.typed = false;
|
|
@@ -618,26 +618,37 @@
|
|
|
618
618
|
dataset.issues = [ issue ];
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
|
+
function _getStandardProps(context) {
|
|
622
|
+
return {
|
|
623
|
+
version: 1,
|
|
624
|
+
vendor: "valibot",
|
|
625
|
+
validate: function validate(value2) {
|
|
626
|
+
return context["~run"]({
|
|
627
|
+
value: value2
|
|
628
|
+
}, getGlobalConfig());
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
}
|
|
621
632
|
function _isValidObjectKey(object2, key) {
|
|
622
633
|
return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
|
|
623
634
|
}
|
|
624
|
-
function _joinExpects(
|
|
635
|
+
function _joinExpects(values2, separator) {
|
|
625
636
|
var _list$;
|
|
626
|
-
var list = _toConsumableArray(new Set(
|
|
637
|
+
var list = _toConsumableArray(new Set(values2));
|
|
627
638
|
if (list.length > 1) {
|
|
628
639
|
return "(".concat(list.join(" ".concat(separator, " ")), ")");
|
|
629
640
|
}
|
|
630
641
|
return (_list$ = list[0]) !== null && _list$ !== void 0 ? _list$ : "never";
|
|
631
642
|
}
|
|
632
|
-
function nonEmpty(
|
|
643
|
+
function nonEmpty(message2) {
|
|
633
644
|
return {
|
|
634
645
|
kind: "validation",
|
|
635
646
|
type: "non_empty",
|
|
636
647
|
reference: nonEmpty,
|
|
637
648
|
async: false,
|
|
638
649
|
expects: "!0",
|
|
639
|
-
message:
|
|
640
|
-
|
|
650
|
+
message: message2,
|
|
651
|
+
"~run": function run(dataset, config2) {
|
|
641
652
|
if (dataset.typed && dataset.value.length === 0) {
|
|
642
653
|
_addIssue(this, "length", dataset, config2, {
|
|
643
654
|
received: "0"
|
|
@@ -647,10 +658,53 @@
|
|
|
647
658
|
}
|
|
648
659
|
};
|
|
649
660
|
}
|
|
661
|
+
function url(message2) {
|
|
662
|
+
return {
|
|
663
|
+
kind: "validation",
|
|
664
|
+
type: "url",
|
|
665
|
+
reference: url,
|
|
666
|
+
async: false,
|
|
667
|
+
expects: null,
|
|
668
|
+
requirement: function requirement(input) {
|
|
669
|
+
try {
|
|
670
|
+
new URL(input);
|
|
671
|
+
return true;
|
|
672
|
+
} catch (_unused) {
|
|
673
|
+
return false;
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
message: message2,
|
|
677
|
+
"~run": function run(dataset, config2) {
|
|
678
|
+
if (dataset.typed && !this.requirement(dataset.value)) {
|
|
679
|
+
_addIssue(this, "URL", dataset, config2);
|
|
680
|
+
}
|
|
681
|
+
return dataset;
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
function getFallback(schema, dataset, config2) {
|
|
686
|
+
return typeof schema.fallback === "function" ? schema.fallback(dataset, config2) : schema.fallback;
|
|
687
|
+
}
|
|
650
688
|
function getDefault(schema, dataset, config2) {
|
|
651
689
|
return typeof schema["default"] === "function" ? schema["default"](dataset, config2) : schema["default"];
|
|
652
690
|
}
|
|
653
|
-
function
|
|
691
|
+
function any() {
|
|
692
|
+
return {
|
|
693
|
+
kind: "schema",
|
|
694
|
+
type: "any",
|
|
695
|
+
reference: any,
|
|
696
|
+
expects: "any",
|
|
697
|
+
async: false,
|
|
698
|
+
get "~standard"() {
|
|
699
|
+
return _getStandardProps(this);
|
|
700
|
+
},
|
|
701
|
+
"~run": function run(dataset) {
|
|
702
|
+
dataset.typed = true;
|
|
703
|
+
return dataset;
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function array(item, message2) {
|
|
654
708
|
return {
|
|
655
709
|
kind: "schema",
|
|
656
710
|
type: "array",
|
|
@@ -658,16 +712,18 @@
|
|
|
658
712
|
expects: "Array",
|
|
659
713
|
async: false,
|
|
660
714
|
item: item,
|
|
661
|
-
message:
|
|
662
|
-
|
|
715
|
+
message: message2,
|
|
716
|
+
get "~standard"() {
|
|
717
|
+
return _getStandardProps(this);
|
|
718
|
+
},
|
|
719
|
+
"~run": function run(dataset, config2) {
|
|
663
720
|
var input = dataset.value;
|
|
664
721
|
if (Array.isArray(input)) {
|
|
665
722
|
dataset.typed = true;
|
|
666
723
|
dataset.value = [];
|
|
667
724
|
for (var key = 0; key < input.length; key++) {
|
|
668
725
|
var value2 = input[key];
|
|
669
|
-
var itemDataset = this.item
|
|
670
|
-
typed: false,
|
|
726
|
+
var itemDataset = this.item["~run"]({
|
|
671
727
|
value: value2
|
|
672
728
|
}, config2);
|
|
673
729
|
if (itemDataset.issues) {
|
|
@@ -678,11 +734,11 @@
|
|
|
678
734
|
key: key,
|
|
679
735
|
value: value2
|
|
680
736
|
};
|
|
681
|
-
var
|
|
737
|
+
var _iterator14 = _createForOfIteratorHelper(itemDataset.issues), _step14;
|
|
682
738
|
try {
|
|
683
|
-
for (
|
|
739
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done; ) {
|
|
684
740
|
var _dataset$issues;
|
|
685
|
-
var issue =
|
|
741
|
+
var issue = _step14.value;
|
|
686
742
|
if (issue.path) {
|
|
687
743
|
issue.path.unshift(pathItem);
|
|
688
744
|
} else {
|
|
@@ -691,9 +747,9 @@
|
|
|
691
747
|
(_dataset$issues = dataset.issues) === null || _dataset$issues === void 0 || _dataset$issues.push(issue);
|
|
692
748
|
}
|
|
693
749
|
} catch (err) {
|
|
694
|
-
|
|
750
|
+
_iterator14.e(err);
|
|
695
751
|
} finally {
|
|
696
|
-
|
|
752
|
+
_iterator14.f();
|
|
697
753
|
}
|
|
698
754
|
if (!dataset.issues) {
|
|
699
755
|
dataset.issues = itemDataset.issues;
|
|
@@ -715,15 +771,18 @@
|
|
|
715
771
|
}
|
|
716
772
|
};
|
|
717
773
|
}
|
|
718
|
-
function _boolean(
|
|
774
|
+
function _boolean(message2) {
|
|
719
775
|
return {
|
|
720
776
|
kind: "schema",
|
|
721
777
|
type: "boolean",
|
|
722
778
|
reference: _boolean,
|
|
723
779
|
expects: "boolean",
|
|
724
780
|
async: false,
|
|
725
|
-
message:
|
|
726
|
-
|
|
781
|
+
message: message2,
|
|
782
|
+
get "~standard"() {
|
|
783
|
+
return _getStandardProps(this);
|
|
784
|
+
},
|
|
785
|
+
"~run": function run(dataset, config2) {
|
|
727
786
|
if (typeof dataset.value === "boolean") {
|
|
728
787
|
dataset.typed = true;
|
|
729
788
|
} else {
|
|
@@ -733,16 +792,41 @@
|
|
|
733
792
|
}
|
|
734
793
|
};
|
|
735
794
|
}
|
|
736
|
-
function
|
|
795
|
+
function literal(literal_, message2) {
|
|
737
796
|
return {
|
|
738
797
|
kind: "schema",
|
|
739
|
-
type: "
|
|
740
|
-
reference:
|
|
741
|
-
expects:
|
|
798
|
+
type: "literal",
|
|
799
|
+
reference: literal,
|
|
800
|
+
expects: _stringify(literal_),
|
|
742
801
|
async: false,
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
802
|
+
literal: literal_,
|
|
803
|
+
message: message2,
|
|
804
|
+
get "~standard"() {
|
|
805
|
+
return _getStandardProps(this);
|
|
806
|
+
},
|
|
807
|
+
"~run": function run(dataset, config2) {
|
|
808
|
+
if (dataset.value === this.literal) {
|
|
809
|
+
dataset.typed = true;
|
|
810
|
+
} else {
|
|
811
|
+
_addIssue(this, "type", dataset, config2);
|
|
812
|
+
}
|
|
813
|
+
return dataset;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
function number(message2) {
|
|
818
|
+
return {
|
|
819
|
+
kind: "schema",
|
|
820
|
+
type: "number",
|
|
821
|
+
reference: number,
|
|
822
|
+
expects: "number",
|
|
823
|
+
async: false,
|
|
824
|
+
message: message2,
|
|
825
|
+
get "~standard"() {
|
|
826
|
+
return _getStandardProps(this);
|
|
827
|
+
},
|
|
828
|
+
"~run": function run(dataset, config2) {
|
|
829
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
|
|
746
830
|
dataset.typed = true;
|
|
747
831
|
} else {
|
|
748
832
|
_addIssue(this, "type", dataset, config2);
|
|
@@ -751,65 +835,85 @@
|
|
|
751
835
|
}
|
|
752
836
|
};
|
|
753
837
|
}
|
|
754
|
-
function object(
|
|
838
|
+
function object(entries2, message2) {
|
|
755
839
|
return {
|
|
756
840
|
kind: "schema",
|
|
757
841
|
type: "object",
|
|
758
842
|
reference: object,
|
|
759
843
|
expects: "Object",
|
|
760
844
|
async: false,
|
|
761
|
-
entries:
|
|
762
|
-
message:
|
|
763
|
-
|
|
845
|
+
entries: entries2,
|
|
846
|
+
message: message2,
|
|
847
|
+
get "~standard"() {
|
|
848
|
+
return _getStandardProps(this);
|
|
849
|
+
},
|
|
850
|
+
"~run": function run(dataset, config2) {
|
|
764
851
|
var input = dataset.value;
|
|
765
852
|
if (input && _typeof(input) === "object") {
|
|
766
853
|
dataset.typed = true;
|
|
767
854
|
dataset.value = {};
|
|
768
855
|
for (var key in this.entries) {
|
|
769
|
-
var
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}, config2);
|
|
774
|
-
if (valueDataset.issues) {
|
|
775
|
-
var pathItem = {
|
|
776
|
-
type: "object",
|
|
777
|
-
origin: "value",
|
|
778
|
-
input: input,
|
|
779
|
-
key: key,
|
|
856
|
+
var valueSchema = this.entries[key];
|
|
857
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema["default"] !== void 0) {
|
|
858
|
+
var value2 = key in input ? input[key] : getDefault(valueSchema);
|
|
859
|
+
var valueDataset = valueSchema["~run"]({
|
|
780
860
|
value: value2
|
|
781
|
-
};
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
861
|
+
}, config2);
|
|
862
|
+
if (valueDataset.issues) {
|
|
863
|
+
var pathItem = {
|
|
864
|
+
type: "object",
|
|
865
|
+
origin: "value",
|
|
866
|
+
input: input,
|
|
867
|
+
key: key,
|
|
868
|
+
value: value2
|
|
869
|
+
};
|
|
870
|
+
var _iterator30 = _createForOfIteratorHelper(valueDataset.issues), _step30;
|
|
871
|
+
try {
|
|
872
|
+
for (_iterator30.s(); !(_step30 = _iterator30.n()).done; ) {
|
|
873
|
+
var _dataset$issues13;
|
|
874
|
+
var issue = _step30.value;
|
|
875
|
+
if (issue.path) {
|
|
876
|
+
issue.path.unshift(pathItem);
|
|
877
|
+
} else {
|
|
878
|
+
issue.path = [ pathItem ];
|
|
879
|
+
}
|
|
880
|
+
(_dataset$issues13 = dataset.issues) === null || _dataset$issues13 === void 0 || _dataset$issues13.push(issue);
|
|
791
881
|
}
|
|
792
|
-
|
|
882
|
+
} catch (err) {
|
|
883
|
+
_iterator30.e(err);
|
|
884
|
+
} finally {
|
|
885
|
+
_iterator30.f();
|
|
886
|
+
}
|
|
887
|
+
if (!dataset.issues) {
|
|
888
|
+
dataset.issues = valueDataset.issues;
|
|
889
|
+
}
|
|
890
|
+
if (config2.abortEarly) {
|
|
891
|
+
dataset.typed = false;
|
|
892
|
+
break;
|
|
793
893
|
}
|
|
794
|
-
} catch (err) {
|
|
795
|
-
_iterator26.e(err);
|
|
796
|
-
} finally {
|
|
797
|
-
_iterator26.f();
|
|
798
894
|
}
|
|
799
|
-
if (!
|
|
800
|
-
dataset.
|
|
895
|
+
if (!valueDataset.typed) {
|
|
896
|
+
dataset.typed = false;
|
|
801
897
|
}
|
|
898
|
+
dataset.value[key] = valueDataset.value;
|
|
899
|
+
} else if (valueSchema.fallback !== void 0) {
|
|
900
|
+
dataset.value[key] = getFallback(valueSchema);
|
|
901
|
+
} else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
902
|
+
_addIssue(this, "key", dataset, config2, {
|
|
903
|
+
input: void 0,
|
|
904
|
+
expected: '"'.concat(key, '"'),
|
|
905
|
+
path: [ {
|
|
906
|
+
type: "object",
|
|
907
|
+
origin: "key",
|
|
908
|
+
input: input,
|
|
909
|
+
key: key,
|
|
910
|
+
value: input[key]
|
|
911
|
+
} ]
|
|
912
|
+
});
|
|
802
913
|
if (config2.abortEarly) {
|
|
803
|
-
dataset.typed = false;
|
|
804
914
|
break;
|
|
805
915
|
}
|
|
806
916
|
}
|
|
807
|
-
if (!valueDataset.typed) {
|
|
808
|
-
dataset.typed = false;
|
|
809
|
-
}
|
|
810
|
-
if (valueDataset.value !== void 0 || key in input) {
|
|
811
|
-
dataset.value[key] = valueDataset.value;
|
|
812
|
-
}
|
|
813
917
|
}
|
|
814
918
|
} else {
|
|
815
919
|
_addIssue(this, "type", dataset, config2);
|
|
@@ -818,17 +922,21 @@
|
|
|
818
922
|
}
|
|
819
923
|
};
|
|
820
924
|
}
|
|
821
|
-
function optional(wrapped) {
|
|
822
|
-
|
|
925
|
+
function optional(wrapped, default_) {
|
|
926
|
+
return {
|
|
823
927
|
kind: "schema",
|
|
824
928
|
type: "optional",
|
|
825
929
|
reference: optional,
|
|
826
930
|
expects: "(".concat(wrapped.expects, " | undefined)"),
|
|
827
931
|
async: false,
|
|
828
932
|
wrapped: wrapped,
|
|
829
|
-
|
|
933
|
+
default: default_,
|
|
934
|
+
get "~standard"() {
|
|
935
|
+
return _getStandardProps(this);
|
|
936
|
+
},
|
|
937
|
+
"~run": function run(dataset, config2) {
|
|
830
938
|
if (dataset.value === void 0) {
|
|
831
|
-
if ("default"
|
|
939
|
+
if (this["default"] !== void 0) {
|
|
832
940
|
dataset.value = getDefault(this, dataset, config2);
|
|
833
941
|
}
|
|
834
942
|
if (dataset.value === void 0) {
|
|
@@ -836,18 +944,11 @@
|
|
|
836
944
|
return dataset;
|
|
837
945
|
}
|
|
838
946
|
}
|
|
839
|
-
return this.wrapped
|
|
947
|
+
return this.wrapped["~run"](dataset, config2);
|
|
840
948
|
}
|
|
841
949
|
};
|
|
842
|
-
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key11 = 1; _key11 < _len5; _key11++) {
|
|
843
|
-
args[_key11 - 1] = arguments[_key11];
|
|
844
|
-
}
|
|
845
|
-
if (0 in args) {
|
|
846
|
-
schema["default"] = args[0];
|
|
847
|
-
}
|
|
848
|
-
return schema;
|
|
849
950
|
}
|
|
850
|
-
function picklist(options,
|
|
951
|
+
function picklist(options, message2) {
|
|
851
952
|
return {
|
|
852
953
|
kind: "schema",
|
|
853
954
|
type: "picklist",
|
|
@@ -855,8 +956,11 @@
|
|
|
855
956
|
expects: _joinExpects(options.map(_stringify), "|"),
|
|
856
957
|
async: false,
|
|
857
958
|
options: options,
|
|
858
|
-
message:
|
|
859
|
-
|
|
959
|
+
message: message2,
|
|
960
|
+
get "~standard"() {
|
|
961
|
+
return _getStandardProps(this);
|
|
962
|
+
},
|
|
963
|
+
"~run": function run(dataset, config2) {
|
|
860
964
|
if (this.options.includes(dataset.value)) {
|
|
861
965
|
dataset.typed = true;
|
|
862
966
|
} else {
|
|
@@ -866,7 +970,7 @@
|
|
|
866
970
|
}
|
|
867
971
|
};
|
|
868
972
|
}
|
|
869
|
-
function record(key, value2,
|
|
973
|
+
function record(key, value2, message2) {
|
|
870
974
|
return {
|
|
871
975
|
kind: "schema",
|
|
872
976
|
type: "record",
|
|
@@ -875,8 +979,11 @@
|
|
|
875
979
|
async: false,
|
|
876
980
|
key: key,
|
|
877
981
|
value: value2,
|
|
878
|
-
message:
|
|
879
|
-
|
|
982
|
+
message: message2,
|
|
983
|
+
get "~standard"() {
|
|
984
|
+
return _getStandardProps(this);
|
|
985
|
+
},
|
|
986
|
+
"~run": function run(dataset, config2) {
|
|
880
987
|
var input = dataset.value;
|
|
881
988
|
if (input && _typeof(input) === "object") {
|
|
882
989
|
dataset.typed = true;
|
|
@@ -884,8 +991,7 @@
|
|
|
884
991
|
for (var entryKey in input) {
|
|
885
992
|
if (_isValidObjectKey(input, entryKey)) {
|
|
886
993
|
var entryValue = input[entryKey];
|
|
887
|
-
var keyDataset = this.key
|
|
888
|
-
typed: false,
|
|
994
|
+
var keyDataset = this.key["~run"]({
|
|
889
995
|
value: entryKey
|
|
890
996
|
}, config2);
|
|
891
997
|
if (keyDataset.issues) {
|
|
@@ -896,18 +1002,18 @@
|
|
|
896
1002
|
key: entryKey,
|
|
897
1003
|
value: entryValue
|
|
898
1004
|
};
|
|
899
|
-
var
|
|
1005
|
+
var _iterator39 = _createForOfIteratorHelper(keyDataset.issues), _step39;
|
|
900
1006
|
try {
|
|
901
|
-
for (
|
|
1007
|
+
for (_iterator39.s(); !(_step39 = _iterator39.n()).done; ) {
|
|
902
1008
|
var _dataset$issues19;
|
|
903
|
-
var issue =
|
|
1009
|
+
var issue = _step39.value;
|
|
904
1010
|
issue.path = [ pathItem ];
|
|
905
1011
|
(_dataset$issues19 = dataset.issues) === null || _dataset$issues19 === void 0 || _dataset$issues19.push(issue);
|
|
906
1012
|
}
|
|
907
1013
|
} catch (err) {
|
|
908
|
-
|
|
1014
|
+
_iterator39.e(err);
|
|
909
1015
|
} finally {
|
|
910
|
-
|
|
1016
|
+
_iterator39.f();
|
|
911
1017
|
}
|
|
912
1018
|
if (!dataset.issues) {
|
|
913
1019
|
dataset.issues = keyDataset.issues;
|
|
@@ -917,8 +1023,7 @@
|
|
|
917
1023
|
break;
|
|
918
1024
|
}
|
|
919
1025
|
}
|
|
920
|
-
var valueDataset = this.value
|
|
921
|
-
typed: false,
|
|
1026
|
+
var valueDataset = this.value["~run"]({
|
|
922
1027
|
value: entryValue
|
|
923
1028
|
}, config2);
|
|
924
1029
|
if (valueDataset.issues) {
|
|
@@ -929,11 +1034,11 @@
|
|
|
929
1034
|
key: entryKey,
|
|
930
1035
|
value: entryValue
|
|
931
1036
|
};
|
|
932
|
-
var
|
|
1037
|
+
var _iterator40 = _createForOfIteratorHelper(valueDataset.issues), _step40;
|
|
933
1038
|
try {
|
|
934
|
-
for (
|
|
1039
|
+
for (_iterator40.s(); !(_step40 = _iterator40.n()).done; ) {
|
|
935
1040
|
var _dataset$issues20;
|
|
936
|
-
var _issue5 =
|
|
1041
|
+
var _issue5 = _step40.value;
|
|
937
1042
|
if (_issue5.path) {
|
|
938
1043
|
_issue5.path.unshift(_pathItem5);
|
|
939
1044
|
} else {
|
|
@@ -942,9 +1047,9 @@
|
|
|
942
1047
|
(_dataset$issues20 = dataset.issues) === null || _dataset$issues20 === void 0 || _dataset$issues20.push(_issue5);
|
|
943
1048
|
}
|
|
944
1049
|
} catch (err) {
|
|
945
|
-
|
|
1050
|
+
_iterator40.e(err);
|
|
946
1051
|
} finally {
|
|
947
|
-
|
|
1052
|
+
_iterator40.f();
|
|
948
1053
|
}
|
|
949
1054
|
if (!dataset.issues) {
|
|
950
1055
|
dataset.issues = valueDataset.issues;
|
|
@@ -969,79 +1074,98 @@
|
|
|
969
1074
|
}
|
|
970
1075
|
};
|
|
971
1076
|
}
|
|
972
|
-
function strictObject(
|
|
1077
|
+
function strictObject(entries2, message2) {
|
|
973
1078
|
return {
|
|
974
1079
|
kind: "schema",
|
|
975
1080
|
type: "strict_object",
|
|
976
1081
|
reference: strictObject,
|
|
977
1082
|
expects: "Object",
|
|
978
1083
|
async: false,
|
|
979
|
-
entries:
|
|
980
|
-
message:
|
|
981
|
-
|
|
1084
|
+
entries: entries2,
|
|
1085
|
+
message: message2,
|
|
1086
|
+
get "~standard"() {
|
|
1087
|
+
return _getStandardProps(this);
|
|
1088
|
+
},
|
|
1089
|
+
"~run": function run(dataset, config2) {
|
|
982
1090
|
var input = dataset.value;
|
|
983
1091
|
if (input && _typeof(input) === "object") {
|
|
984
1092
|
dataset.typed = true;
|
|
985
1093
|
dataset.value = {};
|
|
986
1094
|
for (var key in this.entries) {
|
|
987
|
-
var
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
}, config2);
|
|
992
|
-
if (valueDataset.issues) {
|
|
993
|
-
var pathItem = {
|
|
994
|
-
type: "object",
|
|
995
|
-
origin: "value",
|
|
996
|
-
input: input,
|
|
997
|
-
key: key,
|
|
1095
|
+
var valueSchema = this.entries[key];
|
|
1096
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema["default"] !== void 0) {
|
|
1097
|
+
var value2 = key in input ? input[key] : getDefault(valueSchema);
|
|
1098
|
+
var valueDataset = valueSchema["~run"]({
|
|
998
1099
|
value: value2
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1100
|
+
}, config2);
|
|
1101
|
+
if (valueDataset.issues) {
|
|
1102
|
+
var pathItem = {
|
|
1103
|
+
type: "object",
|
|
1104
|
+
origin: "value",
|
|
1105
|
+
input: input,
|
|
1106
|
+
key: key,
|
|
1107
|
+
value: value2
|
|
1108
|
+
};
|
|
1109
|
+
var _iterator48 = _createForOfIteratorHelper(valueDataset.issues), _step48;
|
|
1110
|
+
try {
|
|
1111
|
+
for (_iterator48.s(); !(_step48 = _iterator48.n()).done; ) {
|
|
1112
|
+
var _dataset$issues25;
|
|
1113
|
+
var issue = _step48.value;
|
|
1114
|
+
if (issue.path) {
|
|
1115
|
+
issue.path.unshift(pathItem);
|
|
1116
|
+
} else {
|
|
1117
|
+
issue.path = [ pathItem ];
|
|
1118
|
+
}
|
|
1119
|
+
(_dataset$issues25 = dataset.issues) === null || _dataset$issues25 === void 0 || _dataset$issues25.push(issue);
|
|
1009
1120
|
}
|
|
1010
|
-
|
|
1121
|
+
} catch (err) {
|
|
1122
|
+
_iterator48.e(err);
|
|
1123
|
+
} finally {
|
|
1124
|
+
_iterator48.f();
|
|
1125
|
+
}
|
|
1126
|
+
if (!dataset.issues) {
|
|
1127
|
+
dataset.issues = valueDataset.issues;
|
|
1128
|
+
}
|
|
1129
|
+
if (config2.abortEarly) {
|
|
1130
|
+
dataset.typed = false;
|
|
1131
|
+
break;
|
|
1011
1132
|
}
|
|
1012
|
-
} catch (err) {
|
|
1013
|
-
_iterator44.e(err);
|
|
1014
|
-
} finally {
|
|
1015
|
-
_iterator44.f();
|
|
1016
1133
|
}
|
|
1017
|
-
if (!
|
|
1018
|
-
dataset.
|
|
1134
|
+
if (!valueDataset.typed) {
|
|
1135
|
+
dataset.typed = false;
|
|
1019
1136
|
}
|
|
1137
|
+
dataset.value[key] = valueDataset.value;
|
|
1138
|
+
} else if (valueSchema.fallback !== void 0) {
|
|
1139
|
+
dataset.value[key] = getFallback(valueSchema);
|
|
1140
|
+
} else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
1141
|
+
_addIssue(this, "key", dataset, config2, {
|
|
1142
|
+
input: void 0,
|
|
1143
|
+
expected: '"'.concat(key, '"'),
|
|
1144
|
+
path: [ {
|
|
1145
|
+
type: "object",
|
|
1146
|
+
origin: "key",
|
|
1147
|
+
input: input,
|
|
1148
|
+
key: key,
|
|
1149
|
+
value: input[key]
|
|
1150
|
+
} ]
|
|
1151
|
+
});
|
|
1020
1152
|
if (config2.abortEarly) {
|
|
1021
|
-
dataset.typed = false;
|
|
1022
1153
|
break;
|
|
1023
1154
|
}
|
|
1024
1155
|
}
|
|
1025
|
-
if (!valueDataset.typed) {
|
|
1026
|
-
dataset.typed = false;
|
|
1027
|
-
}
|
|
1028
|
-
if (valueDataset.value !== void 0 || key in input) {
|
|
1029
|
-
dataset.value[key] = valueDataset.value;
|
|
1030
|
-
}
|
|
1031
1156
|
}
|
|
1032
1157
|
if (!dataset.issues || !config2.abortEarly) {
|
|
1033
|
-
for (var
|
|
1034
|
-
if (!(
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
input: _value3,
|
|
1158
|
+
for (var _key9 in input) {
|
|
1159
|
+
if (!(_key9 in this.entries)) {
|
|
1160
|
+
_addIssue(this, "key", dataset, config2, {
|
|
1161
|
+
input: _key9,
|
|
1038
1162
|
expected: "never",
|
|
1039
1163
|
path: [ {
|
|
1040
1164
|
type: "object",
|
|
1041
|
-
origin: "
|
|
1165
|
+
origin: "key",
|
|
1042
1166
|
input: input,
|
|
1043
|
-
key:
|
|
1044
|
-
value:
|
|
1167
|
+
key: _key9,
|
|
1168
|
+
value: input[_key9]
|
|
1045
1169
|
} ]
|
|
1046
1170
|
});
|
|
1047
1171
|
break;
|
|
@@ -1055,15 +1179,18 @@
|
|
|
1055
1179
|
}
|
|
1056
1180
|
};
|
|
1057
1181
|
}
|
|
1058
|
-
function string(
|
|
1182
|
+
function string(message2) {
|
|
1059
1183
|
return {
|
|
1060
1184
|
kind: "schema",
|
|
1061
1185
|
type: "string",
|
|
1062
1186
|
reference: string,
|
|
1063
1187
|
expects: "string",
|
|
1064
1188
|
async: false,
|
|
1065
|
-
message:
|
|
1066
|
-
|
|
1189
|
+
message: message2,
|
|
1190
|
+
get "~standard"() {
|
|
1191
|
+
return _getStandardProps(this);
|
|
1192
|
+
},
|
|
1193
|
+
"~run": function run(dataset, config2) {
|
|
1067
1194
|
if (typeof dataset.value === "string") {
|
|
1068
1195
|
dataset.typed = true;
|
|
1069
1196
|
} else {
|
|
@@ -1076,10 +1203,10 @@
|
|
|
1076
1203
|
function _subIssues(datasets) {
|
|
1077
1204
|
var issues;
|
|
1078
1205
|
if (datasets) {
|
|
1079
|
-
var
|
|
1206
|
+
var _iterator63 = _createForOfIteratorHelper(datasets), _step63;
|
|
1080
1207
|
try {
|
|
1081
|
-
for (
|
|
1082
|
-
var dataset =
|
|
1208
|
+
for (_iterator63.s(); !(_step63 = _iterator63.n()).done; ) {
|
|
1209
|
+
var dataset = _step63.value;
|
|
1083
1210
|
if (issues) {
|
|
1084
1211
|
var _issues;
|
|
1085
1212
|
(_issues = issues).push.apply(_issues, _toConsumableArray(dataset.issues));
|
|
@@ -1088,14 +1215,14 @@
|
|
|
1088
1215
|
}
|
|
1089
1216
|
}
|
|
1090
1217
|
} catch (err) {
|
|
1091
|
-
|
|
1218
|
+
_iterator63.e(err);
|
|
1092
1219
|
} finally {
|
|
1093
|
-
|
|
1220
|
+
_iterator63.f();
|
|
1094
1221
|
}
|
|
1095
1222
|
}
|
|
1096
1223
|
return issues;
|
|
1097
1224
|
}
|
|
1098
|
-
function union(options,
|
|
1225
|
+
function union(options, message2) {
|
|
1099
1226
|
return {
|
|
1100
1227
|
kind: "schema",
|
|
1101
1228
|
type: "union",
|
|
@@ -1105,18 +1232,20 @@
|
|
|
1105
1232
|
})), "|"),
|
|
1106
1233
|
async: false,
|
|
1107
1234
|
options: options,
|
|
1108
|
-
message:
|
|
1109
|
-
|
|
1235
|
+
message: message2,
|
|
1236
|
+
get "~standard"() {
|
|
1237
|
+
return _getStandardProps(this);
|
|
1238
|
+
},
|
|
1239
|
+
"~run": function run(dataset, config2) {
|
|
1110
1240
|
var _untypedDatasets;
|
|
1111
1241
|
var validDataset;
|
|
1112
1242
|
var typedDatasets;
|
|
1113
1243
|
var untypedDatasets;
|
|
1114
|
-
var
|
|
1244
|
+
var _iterator64 = _createForOfIteratorHelper(this.options), _step64;
|
|
1115
1245
|
try {
|
|
1116
|
-
for (
|
|
1117
|
-
var schema =
|
|
1118
|
-
var optionDataset = schema
|
|
1119
|
-
typed: false,
|
|
1246
|
+
for (_iterator64.s(); !(_step64 = _iterator64.n()).done; ) {
|
|
1247
|
+
var schema = _step64.value;
|
|
1248
|
+
var optionDataset = schema["~run"]({
|
|
1120
1249
|
value: dataset.value
|
|
1121
1250
|
}, config2);
|
|
1122
1251
|
if (optionDataset.typed) {
|
|
@@ -1139,9 +1268,9 @@
|
|
|
1139
1268
|
}
|
|
1140
1269
|
}
|
|
1141
1270
|
} catch (err) {
|
|
1142
|
-
|
|
1271
|
+
_iterator64.e(err);
|
|
1143
1272
|
} finally {
|
|
1144
|
-
|
|
1273
|
+
_iterator64.f();
|
|
1145
1274
|
}
|
|
1146
1275
|
if (validDataset) {
|
|
1147
1276
|
return validDataset;
|
|
@@ -1172,28 +1301,34 @@
|
|
|
1172
1301
|
reference: unknown,
|
|
1173
1302
|
expects: "unknown",
|
|
1174
1303
|
async: false,
|
|
1175
|
-
|
|
1304
|
+
get "~standard"() {
|
|
1305
|
+
return _getStandardProps(this);
|
|
1306
|
+
},
|
|
1307
|
+
"~run": function run(dataset) {
|
|
1176
1308
|
dataset.typed = true;
|
|
1177
1309
|
return dataset;
|
|
1178
1310
|
}
|
|
1179
1311
|
};
|
|
1180
1312
|
}
|
|
1181
1313
|
function pipe() {
|
|
1182
|
-
for (var
|
|
1183
|
-
pipe2[
|
|
1314
|
+
for (var _len3 = arguments.length, pipe2 = new Array(_len3), _key13 = 0; _key13 < _len3; _key13++) {
|
|
1315
|
+
pipe2[_key13] = arguments[_key13];
|
|
1184
1316
|
}
|
|
1185
1317
|
return _objectSpread2(_objectSpread2({}, pipe2[0]), {}, {
|
|
1186
1318
|
pipe: pipe2,
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1319
|
+
get "~standard"() {
|
|
1320
|
+
return _getStandardProps(this);
|
|
1321
|
+
},
|
|
1322
|
+
"~run": function run(dataset, config2) {
|
|
1323
|
+
for (var _i2 = 0, _pipe = pipe2; _i2 < _pipe.length; _i2++) {
|
|
1324
|
+
var item = _pipe[_i2];
|
|
1190
1325
|
if (item.kind !== "metadata") {
|
|
1191
1326
|
if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
|
|
1192
1327
|
dataset.typed = false;
|
|
1193
1328
|
break;
|
|
1194
1329
|
}
|
|
1195
1330
|
if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
|
|
1196
|
-
dataset = item
|
|
1331
|
+
dataset = item["~run"](dataset, config2);
|
|
1197
1332
|
}
|
|
1198
1333
|
}
|
|
1199
1334
|
}
|
|
@@ -1202,8 +1337,7 @@
|
|
|
1202
1337
|
});
|
|
1203
1338
|
}
|
|
1204
1339
|
function safeParse(schema, input, config2) {
|
|
1205
|
-
var dataset = schema
|
|
1206
|
-
typed: false,
|
|
1340
|
+
var dataset = schema["~run"]({
|
|
1207
1341
|
value: input
|
|
1208
1342
|
}, getGlobalConfig(config2));
|
|
1209
1343
|
return {
|
|
@@ -1214,10 +1348,20 @@
|
|
|
1214
1348
|
};
|
|
1215
1349
|
}
|
|
1216
1350
|
const isType = validator => value => safeParse(validator, value).success;
|
|
1217
|
-
const getValidationErrors = issues =>
|
|
1218
|
-
message: message,
|
|
1219
|
-
|
|
1220
|
-
|
|
1351
|
+
const getValidationErrors = issues => {
|
|
1352
|
+
const formatIssue = ({message: message, path: path}) => ({
|
|
1353
|
+
message: message,
|
|
1354
|
+
path: path === null || path === void 0 ? void 0 : path.map((p => p.key))
|
|
1355
|
+
});
|
|
1356
|
+
const uniqueErrors = new Map;
|
|
1357
|
+
issues.flatMap((issue => issue.type === "union" && issue.issues ? issue.issues.map(formatIssue) : [ formatIssue(issue) ])).forEach((error => {
|
|
1358
|
+
const key = `${error.message}-${JSON.stringify(error.path)}`;
|
|
1359
|
+
if (!uniqueErrors.has(key)) {
|
|
1360
|
+
uniqueErrors.set(key, error);
|
|
1361
|
+
}
|
|
1362
|
+
}));
|
|
1363
|
+
return Array.from(uniqueErrors.values());
|
|
1364
|
+
};
|
|
1221
1365
|
const validateType = (value, validator) => {
|
|
1222
1366
|
const result = safeParse(validator, value);
|
|
1223
1367
|
return result.success ? ok(result.output) : err(getValidationErrors(result.issues));
|
|
@@ -1231,41 +1375,20 @@
|
|
|
1231
1375
|
});
|
|
1232
1376
|
}
|
|
1233
1377
|
};
|
|
1234
|
-
var SafeFetchCommonRespondErrorType;
|
|
1235
|
-
(function(SafeFetchCommonRespondErrorType) {
|
|
1236
|
-
SafeFetchCommonRespondErrorType["UnexpectedRespond"] = "UnexpectedRespond";
|
|
1237
|
-
})(SafeFetchCommonRespondErrorType || (SafeFetchCommonRespondErrorType = {}));
|
|
1238
|
-
var SafeFetchErrorType;
|
|
1239
|
-
(function(SafeFetchErrorType) {
|
|
1240
|
-
SafeFetchErrorType["HttpError"] = "HttpError";
|
|
1241
|
-
SafeFetchErrorType["UnknownError"] = "UnknownError";
|
|
1242
|
-
})(SafeFetchErrorType || (SafeFetchErrorType = {}));
|
|
1243
|
-
const safeFetch = async (input, init) => {
|
|
1244
|
-
try {
|
|
1245
|
-
const response = await fetch(input, init);
|
|
1246
|
-
if (response.status > 299 || response.status < 200) {
|
|
1247
|
-
return err({
|
|
1248
|
-
type: SafeFetchErrorType.HttpError,
|
|
1249
|
-
message: `HTTP error, status = ${response.status}`,
|
|
1250
|
-
status: response.status
|
|
1251
|
-
});
|
|
1252
|
-
}
|
|
1253
|
-
return ok(response);
|
|
1254
|
-
} catch (error) {
|
|
1255
|
-
return err({
|
|
1256
|
-
type: SafeFetchErrorType.UnknownError,
|
|
1257
|
-
message: "Unknown error",
|
|
1258
|
-
cause: error
|
|
1259
|
-
});
|
|
1260
|
-
}
|
|
1261
|
-
};
|
|
1262
1378
|
exports.MobileCredentialVerificationReasonType = void 0;
|
|
1263
1379
|
(function(MobileCredentialVerificationReasonType) {
|
|
1264
|
-
MobileCredentialVerificationReasonType["
|
|
1265
|
-
MobileCredentialVerificationReasonType["
|
|
1266
|
-
MobileCredentialVerificationReasonType["
|
|
1267
|
-
MobileCredentialVerificationReasonType["
|
|
1268
|
-
MobileCredentialVerificationReasonType["
|
|
1380
|
+
MobileCredentialVerificationReasonType["TrustedIssuerCertificateExpired"] = "TrustedIssuerCertificateExpired";
|
|
1381
|
+
MobileCredentialVerificationReasonType["TrustedIssuerCertificateNotYetValid"] = "TrustedIssuerCertificateNotYetValid";
|
|
1382
|
+
MobileCredentialVerificationReasonType["IssuerNotTrusted"] = "IssuerNotTrusted";
|
|
1383
|
+
MobileCredentialVerificationReasonType["MobileCredentialInvalid"] = "MobileCredentialInvalid";
|
|
1384
|
+
MobileCredentialVerificationReasonType["MobileCredentialExpired"] = "MobileCredentialExpired";
|
|
1385
|
+
MobileCredentialVerificationReasonType["MobileCredentialNotYetValid"] = "MobileCredentialNotYetValid";
|
|
1386
|
+
MobileCredentialVerificationReasonType["InvalidSignerCertificate"] = "InvalidSignerCertificate";
|
|
1387
|
+
MobileCredentialVerificationReasonType["DeviceKeyInvalid"] = "DeviceKeyInvalid";
|
|
1388
|
+
MobileCredentialVerificationReasonType["UnsupportedCurve"] = "UnsupportedCurve";
|
|
1389
|
+
MobileCredentialVerificationReasonType["StatusRevoked"] = "StatusRevoked";
|
|
1390
|
+
MobileCredentialVerificationReasonType["StatusSuspended"] = "StatusSuspended";
|
|
1391
|
+
MobileCredentialVerificationReasonType["StatusUnknown"] = "StatusUnknown";
|
|
1269
1392
|
})(exports.MobileCredentialVerificationReasonType || (exports.MobileCredentialVerificationReasonType = {}));
|
|
1270
1393
|
exports.ClaimType = void 0;
|
|
1271
1394
|
(function(ClaimType) {
|
|
@@ -1291,6 +1414,13 @@
|
|
|
1291
1414
|
(function(OpenidPresentationCredentialProfileSupported) {
|
|
1292
1415
|
OpenidPresentationCredentialProfileSupported["MOBILE"] = "mobile";
|
|
1293
1416
|
})(exports.OpenidPresentationCredentialProfileSupported || (exports.OpenidPresentationCredentialProfileSupported = {}));
|
|
1417
|
+
var PresentationStatusCode;
|
|
1418
|
+
(function(PresentationStatusCode) {
|
|
1419
|
+
PresentationStatusCode["AwaitingRequestRetrieval"] = "AwaitingRequestRetrieval";
|
|
1420
|
+
PresentationStatusCode["AwaitingResponse"] = "AwaitingResponse";
|
|
1421
|
+
PresentationStatusCode["ResponseSubmitted"] = "ResponseSubmitted";
|
|
1422
|
+
PresentationStatusCode["ResultReady"] = "ResultReady";
|
|
1423
|
+
})(PresentationStatusCode || (PresentationStatusCode = {}));
|
|
1294
1424
|
const CredentialQueryValidator = object({
|
|
1295
1425
|
profile: picklist([ exports.OpenidPresentationCredentialProfileSupported.MOBILE ]),
|
|
1296
1426
|
docType: string(),
|
|
@@ -1314,85 +1444,208 @@
|
|
|
1314
1444
|
credentialErrors: optional(unknown()),
|
|
1315
1445
|
error: optional(unknown())
|
|
1316
1446
|
});
|
|
1447
|
+
exports.Mode = void 0;
|
|
1448
|
+
(function(Mode) {
|
|
1449
|
+
Mode["SameDevice"] = "sameDevice";
|
|
1450
|
+
Mode["CrossDevice"] = "crossDevice";
|
|
1451
|
+
})(exports.Mode || (exports.Mode = {}));
|
|
1452
|
+
var SessionType;
|
|
1453
|
+
(function(SessionType) {
|
|
1454
|
+
SessionType["DigitalCredentialsApi"] = "digital-credentials-api";
|
|
1455
|
+
SessionType["Openid4vp"] = "openid4vp";
|
|
1456
|
+
})(SessionType || (SessionType = {}));
|
|
1317
1457
|
object({
|
|
1318
1458
|
credentialQuery: array(CredentialQueryValidator),
|
|
1319
1459
|
challenge: string(),
|
|
1320
1460
|
redirectUri: optional(string()),
|
|
1321
|
-
walletProviderId: optional(string())
|
|
1461
|
+
walletProviderId: optional(string()),
|
|
1462
|
+
dcApiSupported: optional(_boolean())
|
|
1322
1463
|
});
|
|
1323
|
-
const
|
|
1464
|
+
const CreateSessionDigitalCredentialsValidator = object({
|
|
1465
|
+
type: literal(SessionType.DigitalCredentialsApi),
|
|
1324
1466
|
sessionId: string(),
|
|
1325
|
-
|
|
1467
|
+
sessionKey: string(),
|
|
1468
|
+
sessionTtl: number(),
|
|
1469
|
+
request: record(string(), any())
|
|
1326
1470
|
});
|
|
1327
|
-
const
|
|
1471
|
+
const CreateSessionOpenId4vpResponseValidator = object({
|
|
1472
|
+
type: optional(literal(SessionType.Openid4vp)),
|
|
1328
1473
|
sessionId: string(),
|
|
1329
|
-
|
|
1474
|
+
sessionKey: string(),
|
|
1475
|
+
sessionUrl: string()
|
|
1330
1476
|
});
|
|
1477
|
+
const CreateSessionResponseValidator = union([ CreateSessionDigitalCredentialsValidator, CreateSessionOpenId4vpResponseValidator ]);
|
|
1478
|
+
const GetSessionStatusResponseValidator = union([ object({
|
|
1479
|
+
status: picklist([ PresentationStatusCode.ResultReady ]),
|
|
1480
|
+
responseCode: optional(string())
|
|
1481
|
+
}), object({
|
|
1482
|
+
status: string()
|
|
1483
|
+
}) ]);
|
|
1331
1484
|
var LocalStorageKey;
|
|
1332
1485
|
(function(LocalStorageKey) {
|
|
1333
1486
|
LocalStorageKey["challenge"] = "mattr_chg";
|
|
1334
1487
|
LocalStorageKey["sessionId"] = "mattr_sid";
|
|
1335
1488
|
})(LocalStorageKey || (LocalStorageKey = {}));
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
Mode["sameDevice"] = "sameDevice";
|
|
1339
|
-
Mode["crossDevice"] = "crossDevice";
|
|
1340
|
-
})(exports.Mode || (exports.Mode = {}));
|
|
1489
|
+
const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
|
|
1490
|
+
const MATTR_SDK_VERSION_VALUE = "2.0.0";
|
|
1341
1491
|
var MessageEventDataType;
|
|
1342
1492
|
(function(MessageEventDataType) {
|
|
1343
1493
|
MessageEventDataType["PresentationCompleted"] = "PresentationCompleted";
|
|
1344
1494
|
MessageEventDataType["PresentationTimeout"] = "PresentationTimeout";
|
|
1345
1495
|
MessageEventDataType["PresentationAbort"] = "PresentationAbort";
|
|
1346
1496
|
})(MessageEventDataType || (MessageEventDataType = {}));
|
|
1347
|
-
const
|
|
1348
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1349
|
-
redirectUri: string(),
|
|
1350
|
-
challenge: optional(string()),
|
|
1497
|
+
const OpenId4vpConfigSameDeviceOptionsValidator = object({
|
|
1351
1498
|
walletProviderId: optional(string()),
|
|
1352
|
-
mode:
|
|
1499
|
+
mode: literal(exports.Mode.SameDevice),
|
|
1500
|
+
redirectUri: pipe(string(), nonEmpty("Must not be empty"), url())
|
|
1353
1501
|
});
|
|
1354
|
-
const
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
}),
|
|
1360
|
-
challenge: optional(string()),
|
|
1502
|
+
const OpenId4vpConfigCrossDeviceOptionsValidator = object({
|
|
1503
|
+
walletProviderId: optional(string()),
|
|
1504
|
+
mode: literal(exports.Mode.CrossDevice)
|
|
1505
|
+
});
|
|
1506
|
+
const OpenId4vpConfigAutoDetectOptionsValidator = object({
|
|
1361
1507
|
walletProviderId: optional(string()),
|
|
1362
|
-
|
|
1508
|
+
redirectUri: pipe(string(), nonEmpty("Must not be empty"), url()),
|
|
1509
|
+
mode: optional(picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
|
|
1363
1510
|
});
|
|
1364
|
-
const
|
|
1511
|
+
const RequestCredentialsOptionsValidator = object({
|
|
1365
1512
|
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1366
|
-
crossDeviceCallback: object({
|
|
1367
|
-
onComplete: function_(),
|
|
1368
|
-
onFailure: function_()
|
|
1369
|
-
}),
|
|
1370
|
-
redirectUri: string(),
|
|
1371
1513
|
challenge: optional(string()),
|
|
1372
|
-
|
|
1373
|
-
mode: optional(picklist([ exports.Mode.crossDevice, exports.Mode.sameDevice ]))
|
|
1514
|
+
openid4vpConfiguration: optional(union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
|
|
1374
1515
|
});
|
|
1375
|
-
const RequestCredentialsOptionsValidator = union([ RequestCredentialsSameDeviceOptionsValidator, RequestCredentialsCrossDeviceOptionsValidator, RequestCredentialsAutoDetectDeviceOptionsValidator ]);
|
|
1376
1516
|
exports.RequestCredentialsErrorType = void 0;
|
|
1377
1517
|
(function(RequestCredentialsErrorType) {
|
|
1378
1518
|
RequestCredentialsErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
|
|
1519
|
+
RequestCredentialsErrorType["Timeout"] = "Timeout";
|
|
1520
|
+
RequestCredentialsErrorType["Abort"] = "Abort";
|
|
1379
1521
|
})(exports.RequestCredentialsErrorType || (exports.RequestCredentialsErrorType = {}));
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1522
|
+
var RequestCredentialsErrorMessage;
|
|
1523
|
+
(function(RequestCredentialsErrorMessage) {
|
|
1524
|
+
RequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1525
|
+
RequestCredentialsErrorMessage["FailedToGetSessionStatus"] = "Failed to get session status";
|
|
1526
|
+
RequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1527
|
+
RequestCredentialsErrorMessage["FailedToVerifyCredentialResponse"] = "Failed to verify credential response";
|
|
1528
|
+
RequestCredentialsErrorMessage["MissingOpenId4vpConfig"] = "Identified openid4vp session, but missing openId4vpConfiguration on `requestCredentials`";
|
|
1529
|
+
RequestCredentialsErrorMessage["DcApiError"] = "Failed to request credentials with Digital Credentials API";
|
|
1530
|
+
RequestCredentialsErrorMessage["DcApiResponseParseError"] = "Failed to parse response from Digital Credentials API";
|
|
1531
|
+
RequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1532
|
+
RequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1533
|
+
})(RequestCredentialsErrorMessage || (RequestCredentialsErrorMessage = {}));
|
|
1534
|
+
exports.AbortSessionErrorType = void 0;
|
|
1535
|
+
(function(AbortSessionErrorType) {
|
|
1536
|
+
AbortSessionErrorType["AbortSessionFailed"] = "AbortSessionFailed";
|
|
1537
|
+
})(exports.AbortSessionErrorType || (exports.AbortSessionErrorType = {}));
|
|
1538
|
+
var AbortSessionErrorMessage;
|
|
1539
|
+
(function(AbortSessionErrorMessage) {
|
|
1540
|
+
AbortSessionErrorMessage["FailedToAbortSession"] = "Failed to abort session";
|
|
1541
|
+
})(AbortSessionErrorMessage || (AbortSessionErrorMessage = {}));
|
|
1542
|
+
const InitializeOptionsValidator = object({
|
|
1543
|
+
apiBaseUrl: pipe(string(), nonEmpty("Must not be empty"), url()),
|
|
1544
|
+
applicationId: pipe(string(), nonEmpty("Must not be empty"))
|
|
1385
1545
|
});
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1546
|
+
var SafeFetchCommonResponseErrorType;
|
|
1547
|
+
(function(SafeFetchCommonResponseErrorType) {
|
|
1548
|
+
SafeFetchCommonResponseErrorType["UnexpectedResponse"] = "UnexpectedResponse";
|
|
1549
|
+
})(SafeFetchCommonResponseErrorType || (SafeFetchCommonResponseErrorType = {}));
|
|
1550
|
+
var SafeFetchErrorType;
|
|
1551
|
+
(function(SafeFetchErrorType) {
|
|
1552
|
+
SafeFetchErrorType["HttpError"] = "HttpError";
|
|
1553
|
+
SafeFetchErrorType["UnknownError"] = "UnknownError";
|
|
1554
|
+
})(SafeFetchErrorType || (SafeFetchErrorType = {}));
|
|
1555
|
+
const safeFetch = async (input, init) => {
|
|
1556
|
+
try {
|
|
1557
|
+
const headers = Object.assign(Object.assign({}, init === null || init === void 0 ? void 0 : init.headers), {
|
|
1558
|
+
[MATTR_SDK_VERSION_HEADER]: `verifier-sdk-web/${MATTR_SDK_VERSION_VALUE}`
|
|
1559
|
+
});
|
|
1560
|
+
const response = await fetch(input, Object.assign(Object.assign({}, init), {
|
|
1561
|
+
headers: headers
|
|
1562
|
+
}));
|
|
1563
|
+
const defaultHttpErrorMessage = `HTTP error, status = ${response.status}`;
|
|
1564
|
+
if (response.status >= 400 && response.status < 500) {
|
|
1565
|
+
try {
|
|
1566
|
+
const errorBody = await response.json();
|
|
1567
|
+
if (typeof (errorBody === null || errorBody === void 0 ? void 0 : errorBody.message) === "string") {
|
|
1568
|
+
return err({
|
|
1569
|
+
type: SafeFetchErrorType.HttpError,
|
|
1570
|
+
message: errorBody.message,
|
|
1571
|
+
status: response.status
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
} catch (_a) {
|
|
1575
|
+
return err({
|
|
1576
|
+
type: SafeFetchErrorType.HttpError,
|
|
1577
|
+
message: defaultHttpErrorMessage,
|
|
1578
|
+
status: response.status
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (response.status > 299 || response.status < 200) {
|
|
1583
|
+
return err({
|
|
1584
|
+
type: SafeFetchErrorType.HttpError,
|
|
1585
|
+
message: defaultHttpErrorMessage,
|
|
1586
|
+
status: response.status
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
return ok(response);
|
|
1590
|
+
} catch (error) {
|
|
1591
|
+
return err({
|
|
1592
|
+
type: SafeFetchErrorType.UnknownError,
|
|
1593
|
+
message: "Unknown error",
|
|
1594
|
+
cause: error
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
let initializeOptions = undefined;
|
|
1599
|
+
var InitializeErrorMessage;
|
|
1600
|
+
(function(InitializeErrorMessage) {
|
|
1601
|
+
InitializeErrorMessage["SdkNotInitialized"] = "SDK not initialized";
|
|
1602
|
+
})(InitializeErrorMessage || (InitializeErrorMessage = {}));
|
|
1603
|
+
const initialize = options => {
|
|
1604
|
+
assertType(InitializeOptionsValidator, "Invalid initialize options")(options);
|
|
1605
|
+
const {apiBaseUrl: apiBaseUrl} = options;
|
|
1606
|
+
const trimmedApiBaseUrl = apiBaseUrl.trim();
|
|
1607
|
+
initializeOptions = {
|
|
1608
|
+
apiBaseUrl: trimmedApiBaseUrl,
|
|
1609
|
+
applicationId: options.applicationId
|
|
1610
|
+
};
|
|
1611
|
+
};
|
|
1612
|
+
const getInitializeOptions = () => initializeOptions;
|
|
1613
|
+
let sessionAbortController = undefined;
|
|
1614
|
+
let _sessionId = undefined;
|
|
1615
|
+
let _sessionKey = undefined;
|
|
1616
|
+
let _sessionTimeoutId = undefined;
|
|
1617
|
+
const getActiveSession = () => {
|
|
1618
|
+
const sessionId = _sessionId;
|
|
1619
|
+
const sessionKey = _sessionKey;
|
|
1620
|
+
const sessionTimeoutId = _sessionTimeoutId;
|
|
1621
|
+
if (sessionId) {
|
|
1622
|
+
return {
|
|
1623
|
+
sessionId: sessionId,
|
|
1624
|
+
sessionKey: sessionKey,
|
|
1625
|
+
sessionTimeoutId: sessionTimeoutId
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
return undefined;
|
|
1629
|
+
};
|
|
1630
|
+
const setActiveSession = session => {
|
|
1631
|
+
const {sessionId: sessionId, sessionKey: sessionKey, sessionTimeoutId: sessionTimeoutId} = session;
|
|
1632
|
+
_sessionId = sessionId;
|
|
1633
|
+
_sessionKey = sessionKey;
|
|
1634
|
+
_sessionTimeoutId = sessionTimeoutId;
|
|
1635
|
+
const abortController = new AbortController;
|
|
1636
|
+
sessionAbortController = abortController;
|
|
1637
|
+
return abortController;
|
|
1638
|
+
};
|
|
1639
|
+
const removeActiveSession = () => {
|
|
1640
|
+
sessionAbortController === null || sessionAbortController === void 0 ? void 0 : sessionAbortController.abort();
|
|
1641
|
+
if (_sessionTimeoutId) {
|
|
1642
|
+
window.clearTimeout(_sessionTimeoutId);
|
|
1643
|
+
}
|
|
1644
|
+
sessionAbortController = undefined;
|
|
1645
|
+
_sessionKey = undefined;
|
|
1646
|
+
_sessionId = undefined;
|
|
1647
|
+
_sessionTimeoutId = undefined;
|
|
1394
1648
|
};
|
|
1395
|
-
const getInitialiseOptions = () => initialiseOptions;
|
|
1396
1649
|
var isMobile_1 = isMobile;
|
|
1397
1650
|
var isMobile_2 = isMobile;
|
|
1398
1651
|
var default_1 = isMobile;
|
|
@@ -1417,6 +1670,23 @@
|
|
|
1417
1670
|
isMobile_1["default"] = default_1;
|
|
1418
1671
|
const defaultRetryDelay = attempt => Math.pow(2, attempt) * 1e3;
|
|
1419
1672
|
const defaultRetry = 2;
|
|
1673
|
+
const withRetry = async (fn, options) => {
|
|
1674
|
+
const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0} = options;
|
|
1675
|
+
try {
|
|
1676
|
+
return await fn();
|
|
1677
|
+
} catch (err) {
|
|
1678
|
+
if (retries > 0) {
|
|
1679
|
+
const delay = typeof retryDelay === "function" ? retryDelay(attempt) : retryDelay;
|
|
1680
|
+
await new Promise((resolve => setTimeout(resolve, delay)));
|
|
1681
|
+
return await withRetry(fn, Object.assign(Object.assign({}, options), {
|
|
1682
|
+
retries: retries - 1,
|
|
1683
|
+
retryDelay: retryDelay,
|
|
1684
|
+
attempt: attempt + 1
|
|
1685
|
+
}));
|
|
1686
|
+
}
|
|
1687
|
+
throw err;
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1420
1690
|
const withRetrySafeFetch = async (fn, options) => {
|
|
1421
1691
|
const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0, retryHttpStatus: retryHttpStatus} = options;
|
|
1422
1692
|
const result = await fn();
|
|
@@ -1442,17 +1712,15 @@
|
|
|
1442
1712
|
const urlParams = new URLSearchParams(hash.split("#")[1]);
|
|
1443
1713
|
return urlParams.get(param);
|
|
1444
1714
|
};
|
|
1445
|
-
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl,
|
|
1446
|
-
const postData =
|
|
1715
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
|
|
1716
|
+
const postData = {
|
|
1447
1717
|
credentialQuery: credentialQuery,
|
|
1448
|
-
challenge: challenge
|
|
1449
|
-
|
|
1450
|
-
redirectUri: redirectUri
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
}
|
|
1454
|
-
walletProviderId: walletProviderId
|
|
1455
|
-
} : {});
|
|
1718
|
+
challenge: challenge,
|
|
1719
|
+
applicationId: applicationId,
|
|
1720
|
+
redirectUri: redirectUri,
|
|
1721
|
+
walletProviderId: walletProviderId,
|
|
1722
|
+
dcApiSupported: dcApiSupported
|
|
1723
|
+
};
|
|
1456
1724
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
|
|
1457
1725
|
method: "POST",
|
|
1458
1726
|
headers: {
|
|
@@ -1466,89 +1734,50 @@
|
|
|
1466
1734
|
const data = await responseResult.value.json();
|
|
1467
1735
|
if (!isType(CreateSessionResponseValidator)(data)) {
|
|
1468
1736
|
return err({
|
|
1469
|
-
type:
|
|
1470
|
-
message: "Create session
|
|
1737
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1738
|
+
message: "Create session returned unsupported response"
|
|
1471
1739
|
});
|
|
1472
1740
|
}
|
|
1473
1741
|
return ok(data);
|
|
1474
1742
|
};
|
|
1475
|
-
const
|
|
1476
|
-
const
|
|
1477
|
-
challenge: challenge,
|
|
1478
|
-
responseCode: responseCode
|
|
1479
|
-
};
|
|
1480
|
-
const fetchResultFn = async () => await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/result`, {
|
|
1743
|
+
const abortSession = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
|
|
1744
|
+
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/abort`, {
|
|
1481
1745
|
method: "POST",
|
|
1482
1746
|
headers: {
|
|
1483
|
-
"Content-Type": "application/json"
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
});
|
|
1487
|
-
const responseResult = await withRetrySafeFetch(fetchResultFn, {
|
|
1488
|
-
retries: 2,
|
|
1489
|
-
retryHttpStatus: 404
|
|
1747
|
+
"Content-Type": "application/json",
|
|
1748
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1749
|
+
}
|
|
1490
1750
|
});
|
|
1491
1751
|
if (responseResult.isErr()) {
|
|
1492
1752
|
return err(responseResult.error);
|
|
1493
1753
|
}
|
|
1494
|
-
|
|
1495
|
-
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
1496
|
-
return err({
|
|
1497
|
-
type: SafeFetchCommonRespondErrorType.UnexpectedRespond,
|
|
1498
|
-
message: "Exchange session result return unsupported response",
|
|
1499
|
-
details: {
|
|
1500
|
-
data: data
|
|
1501
|
-
}
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
return ok(data);
|
|
1505
|
-
};
|
|
1506
|
-
const isMobileDetect = userAgent => isMobile_2({
|
|
1507
|
-
ua: userAgent,
|
|
1508
|
-
tablet: false
|
|
1509
|
-
});
|
|
1510
|
-
const isDigitalCredentialsApiSupported = () => {
|
|
1511
|
-
var _a;
|
|
1512
|
-
try {
|
|
1513
|
-
return typeof ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.identity) === null || _a === void 0 ? void 0 : _a.get) === "function";
|
|
1514
|
-
} catch (error) {
|
|
1515
|
-
return false;
|
|
1516
|
-
}
|
|
1754
|
+
return ok(undefined);
|
|
1517
1755
|
};
|
|
1518
|
-
const
|
|
1519
|
-
const
|
|
1520
|
-
|
|
1521
|
-
challenge: challenge
|
|
1522
|
-
}, protocol && {
|
|
1523
|
-
protocol: protocol
|
|
1524
|
-
});
|
|
1525
|
-
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/web/request`, {
|
|
1526
|
-
method: "POST",
|
|
1756
|
+
const getSessionStatus = async ({apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey}) => {
|
|
1757
|
+
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/status`, {
|
|
1758
|
+
method: "GET",
|
|
1527
1759
|
headers: {
|
|
1528
|
-
|
|
1529
|
-
}
|
|
1530
|
-
body: JSON.stringify(postData)
|
|
1760
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1761
|
+
}
|
|
1531
1762
|
});
|
|
1532
1763
|
if (responseResult.isErr()) {
|
|
1533
1764
|
return err(responseResult.error);
|
|
1534
1765
|
}
|
|
1535
1766
|
const data = await responseResult.value.json();
|
|
1536
|
-
if (!isType(
|
|
1767
|
+
if (!isType(GetSessionStatusResponseValidator)(data)) {
|
|
1537
1768
|
return err({
|
|
1538
|
-
type:
|
|
1539
|
-
message: "
|
|
1769
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1770
|
+
message: "Get session status return unsupported response"
|
|
1540
1771
|
});
|
|
1541
1772
|
}
|
|
1542
1773
|
return ok(data);
|
|
1543
1774
|
};
|
|
1544
|
-
const
|
|
1775
|
+
const exchangeSessionResult = async ({challenge: challenge, responseCode: responseCode, sessionId: sessionId, apiBaseUrl: apiBaseUrl}) => {
|
|
1545
1776
|
const postData = {
|
|
1546
1777
|
challenge: challenge,
|
|
1547
|
-
|
|
1548
|
-
response: response,
|
|
1549
|
-
protocol: protocol
|
|
1778
|
+
responseCode: responseCode
|
|
1550
1779
|
};
|
|
1551
|
-
const fetchResultFn = async () => await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/
|
|
1780
|
+
const fetchResultFn = async () => await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/result`, {
|
|
1552
1781
|
method: "POST",
|
|
1553
1782
|
headers: {
|
|
1554
1783
|
"Content-Type": "application/json"
|
|
@@ -1563,28 +1792,32 @@
|
|
|
1563
1792
|
return err(responseResult.error);
|
|
1564
1793
|
}
|
|
1565
1794
|
const data = await responseResult.value.json();
|
|
1795
|
+
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
1796
|
+
return err({
|
|
1797
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1798
|
+
message: "Exchange session result return unsupported response",
|
|
1799
|
+
details: {
|
|
1800
|
+
data: data
|
|
1801
|
+
}
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1566
1804
|
return ok(data);
|
|
1567
1805
|
};
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
})(exports.CrossDeviceCallbackErrorType || (exports.CrossDeviceCallbackErrorType = {}));
|
|
1574
|
-
var CrossDeviceRequestCredentialsErrorMessage;
|
|
1575
|
-
(function(CrossDeviceRequestCredentialsErrorMessage) {
|
|
1576
|
-
CrossDeviceRequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1577
|
-
CrossDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1578
|
-
CrossDeviceRequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1579
|
-
CrossDeviceRequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1580
|
-
})(CrossDeviceRequestCredentialsErrorMessage || (CrossDeviceRequestCredentialsErrorMessage = {}));
|
|
1806
|
+
const isMobileDetect = userAgent => isMobile_2({
|
|
1807
|
+
ua: userAgent,
|
|
1808
|
+
tablet: false
|
|
1809
|
+
});
|
|
1810
|
+
const getVersion = () => MATTR_SDK_VERSION_VALUE;
|
|
1581
1811
|
var WindowEventListenerType;
|
|
1582
1812
|
(function(WindowEventListenerType) {
|
|
1583
1813
|
WindowEventListenerType["message"] = "message";
|
|
1584
1814
|
})(WindowEventListenerType || (WindowEventListenerType = {}));
|
|
1585
|
-
let listener;
|
|
1815
|
+
let listener = undefined;
|
|
1586
1816
|
const removeWindowMessageEventListener = () => {
|
|
1587
|
-
|
|
1817
|
+
if (listener) {
|
|
1818
|
+
window.removeEventListener(WindowEventListenerType.message, listener, false);
|
|
1819
|
+
}
|
|
1820
|
+
listener = undefined;
|
|
1588
1821
|
};
|
|
1589
1822
|
const closeCrossDeviceModal = options => {
|
|
1590
1823
|
const {container: container} = options;
|
|
@@ -1594,8 +1827,7 @@
|
|
|
1594
1827
|
removeWindowMessageEventListener();
|
|
1595
1828
|
};
|
|
1596
1829
|
const receiveMessageHandler = options => async event => {
|
|
1597
|
-
const {
|
|
1598
|
-
const {onComplete: onComplete, onFailure: onFailure} = crossDeviceCallback;
|
|
1830
|
+
const {onComplete: onComplete, onFailure: onFailure, container: container, sessionId: sessionId, apiBaseUrl: apiBaseUrl, challenge: challenge} = options;
|
|
1599
1831
|
if (event.origin !== apiBaseUrl) {
|
|
1600
1832
|
return;
|
|
1601
1833
|
}
|
|
@@ -1609,8 +1841,8 @@
|
|
|
1609
1841
|
});
|
|
1610
1842
|
if (result.isErr()) {
|
|
1611
1843
|
onFailure({
|
|
1612
|
-
type: exports.
|
|
1613
|
-
message:
|
|
1844
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1845
|
+
message: RequestCredentialsErrorMessage.FailedToGetSessionResult
|
|
1614
1846
|
});
|
|
1615
1847
|
closeCrossDeviceModal({
|
|
1616
1848
|
container: container
|
|
@@ -1618,8 +1850,9 @@
|
|
|
1618
1850
|
return;
|
|
1619
1851
|
}
|
|
1620
1852
|
onComplete({
|
|
1621
|
-
result: result.value,
|
|
1622
|
-
sessionId: result.value.sessionId
|
|
1853
|
+
result: "challenge" in result.value ? result.value : undefined,
|
|
1854
|
+
sessionId: result.value.sessionId,
|
|
1855
|
+
sessionCompletedInRedirect: false
|
|
1623
1856
|
});
|
|
1624
1857
|
closeCrossDeviceModal({
|
|
1625
1858
|
container: container
|
|
@@ -1628,8 +1861,8 @@
|
|
|
1628
1861
|
}
|
|
1629
1862
|
if (event.data.type === MessageEventDataType.PresentationTimeout) {
|
|
1630
1863
|
onFailure({
|
|
1631
|
-
type: exports.
|
|
1632
|
-
message:
|
|
1864
|
+
type: exports.RequestCredentialsErrorType.Timeout,
|
|
1865
|
+
message: RequestCredentialsErrorMessage.Timeout
|
|
1633
1866
|
});
|
|
1634
1867
|
closeCrossDeviceModal({
|
|
1635
1868
|
container: container
|
|
@@ -1638,8 +1871,8 @@
|
|
|
1638
1871
|
}
|
|
1639
1872
|
if (event.data.type === MessageEventDataType.PresentationAbort) {
|
|
1640
1873
|
onFailure({
|
|
1641
|
-
type: exports.
|
|
1642
|
-
message:
|
|
1874
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
1875
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1643
1876
|
});
|
|
1644
1877
|
closeCrossDeviceModal({
|
|
1645
1878
|
container: container
|
|
@@ -1662,186 +1895,324 @@
|
|
|
1662
1895
|
modalContainer.setAttribute("class", "mattr-verifier-modal-container");
|
|
1663
1896
|
return modalContainer;
|
|
1664
1897
|
};
|
|
1665
|
-
const
|
|
1666
|
-
const {challenge: challenge,
|
|
1667
|
-
const
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1898
|
+
const requestCredentialsWithCrossDevice = async options => {
|
|
1899
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, sessionUrl: sessionUrl, sessionId: sessionId, sessionKey: sessionKey} = options;
|
|
1900
|
+
const container = openCrossDeviceModal({
|
|
1901
|
+
sessionUrl: sessionUrl
|
|
1902
|
+
});
|
|
1903
|
+
return await new Promise((resolve => {
|
|
1904
|
+
const abortController = setActiveSession({
|
|
1905
|
+
sessionId: sessionId,
|
|
1906
|
+
sessionKey: sessionKey
|
|
1907
|
+
});
|
|
1908
|
+
abortController.signal.addEventListener("abort", (() => {
|
|
1909
|
+
closeCrossDeviceModal({
|
|
1910
|
+
container: container
|
|
1911
|
+
});
|
|
1912
|
+
resolve(err({
|
|
1913
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
1914
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1915
|
+
}));
|
|
1916
|
+
}));
|
|
1917
|
+
removeWindowMessageEventListener();
|
|
1918
|
+
listener = receiveMessageHandler({
|
|
1919
|
+
container: container,
|
|
1920
|
+
sessionId: sessionId,
|
|
1921
|
+
apiBaseUrl: apiBaseUrl,
|
|
1922
|
+
challenge: challenge,
|
|
1923
|
+
onComplete: data => resolve(ok(data)),
|
|
1924
|
+
onFailure: error => resolve(err(error))
|
|
1925
|
+
});
|
|
1926
|
+
window.addEventListener(WindowEventListenerType.message, listener, false);
|
|
1927
|
+
}));
|
|
1928
|
+
};
|
|
1929
|
+
const abortCredentialRequest = async () => {
|
|
1930
|
+
const initializeOptions = getInitializeOptions();
|
|
1931
|
+
if (!initializeOptions) {
|
|
1932
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1933
|
+
}
|
|
1934
|
+
const {apiBaseUrl: apiBaseUrl} = initializeOptions;
|
|
1935
|
+
const session = getActiveSession();
|
|
1936
|
+
if (!session || !session.sessionKey) {
|
|
1937
|
+
return ok(undefined);
|
|
1938
|
+
}
|
|
1939
|
+
const {sessionId: sessionId, sessionKey: sessionKey} = session;
|
|
1940
|
+
removeActiveSession();
|
|
1941
|
+
const abortSessionResult = await abortSession({
|
|
1671
1942
|
apiBaseUrl: apiBaseUrl,
|
|
1672
|
-
|
|
1673
|
-
|
|
1943
|
+
sessionId: sessionId,
|
|
1944
|
+
sessionKey: sessionKey
|
|
1674
1945
|
});
|
|
1675
|
-
if (
|
|
1946
|
+
if (abortSessionResult.isErr()) {
|
|
1676
1947
|
return err({
|
|
1677
|
-
type: exports.
|
|
1678
|
-
message:
|
|
1679
|
-
cause:
|
|
1948
|
+
type: exports.AbortSessionErrorType.AbortSessionFailed,
|
|
1949
|
+
message: AbortSessionErrorMessage.FailedToAbortSession,
|
|
1950
|
+
cause: abortSessionResult.error
|
|
1680
1951
|
});
|
|
1681
1952
|
}
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
crossDeviceCallback: crossDeviceCallback,
|
|
1689
|
-
container: container,
|
|
1953
|
+
return ok(undefined);
|
|
1954
|
+
};
|
|
1955
|
+
const requestCredentialsWithDigitalCredentialsApi = async options => {
|
|
1956
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, request: request, sessionTtl: sessionTtl} = options;
|
|
1957
|
+
const sessionTimeoutId = window.setTimeout((() => removeActiveSession()), sessionTtl * 1e3);
|
|
1958
|
+
const abortController = setActiveSession({
|
|
1690
1959
|
sessionId: sessionId,
|
|
1960
|
+
sessionKey: sessionKey,
|
|
1961
|
+
sessionTimeoutId: sessionTimeoutId
|
|
1962
|
+
});
|
|
1963
|
+
const credentialResponseResult = await getCredentials(request, abortController);
|
|
1964
|
+
if (credentialResponseResult.isErr()) {
|
|
1965
|
+
await abortCredentialRequest();
|
|
1966
|
+
return err(credentialResponseResult.error);
|
|
1967
|
+
}
|
|
1968
|
+
const credentialResponse = credentialResponseResult.value;
|
|
1969
|
+
const parsedCredentialResponseResult = parseCredentialResponse(credentialResponse);
|
|
1970
|
+
if (parsedCredentialResponseResult.isErr()) {
|
|
1971
|
+
await abortCredentialRequest();
|
|
1972
|
+
return err(parsedCredentialResponseResult.error);
|
|
1973
|
+
}
|
|
1974
|
+
const parsedCredentialResponse = parsedCredentialResponseResult.value;
|
|
1975
|
+
const credentialVerificationResult = await verifyCredentialResponse({
|
|
1691
1976
|
apiBaseUrl: apiBaseUrl,
|
|
1692
|
-
|
|
1977
|
+
sessionId: sessionId,
|
|
1978
|
+
sessionKey: sessionKey,
|
|
1979
|
+
challenge: challenge,
|
|
1980
|
+
protocol: parsedCredentialResponse.protocol,
|
|
1981
|
+
data: parsedCredentialResponse.data
|
|
1693
1982
|
});
|
|
1694
|
-
|
|
1983
|
+
if (credentialVerificationResult.isErr()) {
|
|
1984
|
+
return err({
|
|
1985
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1986
|
+
message: RequestCredentialsErrorMessage.FailedToVerifyCredentialResponse,
|
|
1987
|
+
cause: credentialVerificationResult.error
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
const verificationResult = credentialVerificationResult.value;
|
|
1695
1991
|
return ok({
|
|
1992
|
+
result: "challenge" in verificationResult ? verificationResult : undefined,
|
|
1696
1993
|
sessionId: sessionId
|
|
1697
1994
|
});
|
|
1698
1995
|
};
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
1707
|
-
window.localStorage.setItem(LocalStorageKey.challenge, challenge);
|
|
1708
|
-
const storedChallenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
1709
|
-
if (!storedChallenge) {
|
|
1996
|
+
const getCredentials = async (request, abortController) => {
|
|
1997
|
+
try {
|
|
1998
|
+
const credentialResponse = await navigator.credentials.get(Object.assign(Object.assign({}, request), {
|
|
1999
|
+
signal: abortController.signal
|
|
2000
|
+
}));
|
|
2001
|
+
return ok(credentialResponse);
|
|
2002
|
+
} catch (exception) {
|
|
1710
2003
|
return err({
|
|
1711
2004
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1712
|
-
message:
|
|
2005
|
+
message: RequestCredentialsErrorMessage.DcApiError,
|
|
2006
|
+
cause: exception
|
|
1713
2007
|
});
|
|
1714
2008
|
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
redirectUri: redirectUri,
|
|
1719
|
-
apiBaseUrl: apiBaseUrl,
|
|
1720
|
-
applicationId: applicationId,
|
|
1721
|
-
walletProviderId: walletProviderId
|
|
1722
|
-
});
|
|
1723
|
-
if (createSessionResult.isErr()) {
|
|
2009
|
+
};
|
|
2010
|
+
const parseCredentialResponse = credentialResponse => {
|
|
2011
|
+
if (!credentialResponse) {
|
|
1724
2012
|
return err({
|
|
1725
2013
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1726
|
-
message:
|
|
1727
|
-
|
|
2014
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2015
|
+
details: {
|
|
2016
|
+
response: credentialResponse
|
|
2017
|
+
}
|
|
1728
2018
|
});
|
|
1729
2019
|
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
2020
|
+
if (typeof credentialResponse === "object") {
|
|
2021
|
+
return ok(credentialResponse);
|
|
2022
|
+
}
|
|
2023
|
+
if (typeof credentialResponse === "string") {
|
|
2024
|
+
try {
|
|
2025
|
+
const parsed = JSON.parse(credentialResponse);
|
|
2026
|
+
return ok(parsed);
|
|
2027
|
+
} catch (_a) {
|
|
2028
|
+
return err({
|
|
2029
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2030
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2031
|
+
details: {
|
|
2032
|
+
response: credentialResponse
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
return err({
|
|
2038
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2039
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2040
|
+
details: {
|
|
2041
|
+
response: credentialResponse
|
|
2042
|
+
}
|
|
2043
|
+
});
|
|
2044
|
+
};
|
|
2045
|
+
const verifyCredentialResponse = async options => {
|
|
2046
|
+
const {apiBaseUrl: apiBaseUrl, sessionId: sessionId, sessionKey: sessionKey, challenge: challenge, protocol: protocol, data: data} = options;
|
|
2047
|
+
const requestBody = {
|
|
2048
|
+
protocol: protocol,
|
|
2049
|
+
data: data,
|
|
2050
|
+
challenge: challenge
|
|
2051
|
+
};
|
|
2052
|
+
const credentialVerificationResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/dc-api/response`, {
|
|
2053
|
+
method: "POST",
|
|
2054
|
+
headers: {
|
|
2055
|
+
"Content-Type": "application/json",
|
|
2056
|
+
Authorization: `Bearer ${sessionKey}`
|
|
2057
|
+
},
|
|
2058
|
+
body: JSON.stringify(requestBody)
|
|
1735
2059
|
});
|
|
2060
|
+
if (credentialVerificationResult.isErr()) {
|
|
2061
|
+
return err(credentialVerificationResult.error);
|
|
2062
|
+
}
|
|
2063
|
+
const credentialVerificationResponse = await credentialVerificationResult.value.json();
|
|
2064
|
+
if (!isType(PresentationResultRelaxValidator)(credentialVerificationResponse)) {
|
|
2065
|
+
return err({
|
|
2066
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
2067
|
+
message: "Verify credential returned unsupported response",
|
|
2068
|
+
details: {
|
|
2069
|
+
response: credentialVerificationResponse
|
|
2070
|
+
}
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
return ok(credentialVerificationResponse);
|
|
1736
2074
|
};
|
|
2075
|
+
const isDigitalCredentialsApiSupported = () => {
|
|
2076
|
+
var _a;
|
|
2077
|
+
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";
|
|
2078
|
+
};
|
|
2079
|
+
const sleep = ms => new Promise((resolve => setTimeout(resolve, ms)));
|
|
2080
|
+
const SESSION_STATUS_POLLING_MAX_RETRY = 1e3;
|
|
2081
|
+
const SESSION_STATUS_POLLING_INTERVAL_MS = 3e3;
|
|
2082
|
+
const SESSION_STATUS_POLLING_INITIAL_DELAY_MS = 3e3;
|
|
1737
2083
|
var SameDeviceRequestCredentialsErrorMessage;
|
|
1738
2084
|
(function(SameDeviceRequestCredentialsErrorMessage) {
|
|
1739
2085
|
SameDeviceRequestCredentialsErrorMessage["FailedToStoreChallenge"] = "Failed to store challenge";
|
|
1740
2086
|
SameDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1741
2087
|
})(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
|
|
1742
|
-
const
|
|
1743
|
-
const {challenge: challenge,
|
|
1744
|
-
const
|
|
2088
|
+
const requestCredentialsSameDevice = async options => {
|
|
2089
|
+
const {challenge: challenge, apiBaseUrl: apiBaseUrl, applicationId: applicationId, sessionUrl: sessionUrl, sessionKey: sessionKey, sessionId: sessionId} = options;
|
|
2090
|
+
const abortController = setActiveSession({
|
|
2091
|
+
sessionId: sessionId,
|
|
2092
|
+
sessionKey: sessionKey
|
|
2093
|
+
});
|
|
2094
|
+
window.localStorage.setItem(LocalStorageKey.sessionId, sessionId);
|
|
1745
2095
|
window.localStorage.setItem(LocalStorageKey.challenge, challenge);
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
2096
|
+
window.location.assign(sessionUrl);
|
|
2097
|
+
await sleep(SESSION_STATUS_POLLING_INITIAL_DELAY_MS);
|
|
2098
|
+
const checkResult = await withRetry((async () => {
|
|
2099
|
+
const statusResult = await getSessionStatus({
|
|
2100
|
+
apiBaseUrl: apiBaseUrl,
|
|
2101
|
+
applicationId: applicationId,
|
|
2102
|
+
sessionId: sessionId,
|
|
2103
|
+
sessionKey: sessionKey
|
|
1751
2104
|
});
|
|
2105
|
+
if (abortController.signal.aborted) {
|
|
2106
|
+
return err({
|
|
2107
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
2108
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
if (statusResult.isErr()) {
|
|
2112
|
+
if (statusResult.error.status === 404) {
|
|
2113
|
+
return err({
|
|
2114
|
+
type: exports.RequestCredentialsErrorType.Timeout,
|
|
2115
|
+
message: RequestCredentialsErrorMessage.Timeout
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
throw Error("Unexpected status response. Retry");
|
|
2119
|
+
}
|
|
2120
|
+
if (statusResult.value.status !== PresentationStatusCode.ResultReady) {
|
|
2121
|
+
throw Error("Result is not ready. Retry");
|
|
2122
|
+
}
|
|
2123
|
+
return ok(undefined);
|
|
2124
|
+
}), {
|
|
2125
|
+
retries: SESSION_STATUS_POLLING_MAX_RETRY,
|
|
2126
|
+
retryDelay: SESSION_STATUS_POLLING_INTERVAL_MS
|
|
2127
|
+
});
|
|
2128
|
+
if (checkResult.isErr()) {
|
|
2129
|
+
return err(checkResult.error);
|
|
2130
|
+
}
|
|
2131
|
+
window.close();
|
|
2132
|
+
return ok({
|
|
2133
|
+
sessionId: sessionId,
|
|
2134
|
+
sessionCompletedInRedirect: true
|
|
2135
|
+
});
|
|
2136
|
+
};
|
|
2137
|
+
const requestCredentials = async options => {
|
|
2138
|
+
var _a;
|
|
2139
|
+
const initializeOptions = getInitializeOptions();
|
|
2140
|
+
if (!initializeOptions) {
|
|
2141
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1752
2142
|
}
|
|
1753
|
-
|
|
2143
|
+
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
2144
|
+
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initializeOptions;
|
|
2145
|
+
const {challenge: challenge = generateChallenge(), credentialQuery: credentialQuery, openid4vpConfiguration: openid4vpConfiguration} = options;
|
|
2146
|
+
const dcApiSupported = isDigitalCredentialsApiSupported();
|
|
2147
|
+
const openId4VpRedirectUri = deriveOpenId4vpRedirectUri(openid4vpConfiguration);
|
|
2148
|
+
const createSessionResult = await createSession({
|
|
1754
2149
|
credentialQuery: credentialQuery,
|
|
1755
|
-
challenge:
|
|
2150
|
+
challenge: challenge,
|
|
2151
|
+
redirectUri: openId4VpRedirectUri,
|
|
2152
|
+
walletProviderId: (_a = openid4vpConfiguration === null || openid4vpConfiguration === void 0 ? void 0 : openid4vpConfiguration.walletProviderId) !== null && _a !== void 0 ? _a : undefined,
|
|
1756
2153
|
apiBaseUrl: apiBaseUrl,
|
|
1757
|
-
|
|
2154
|
+
applicationId: applicationId,
|
|
2155
|
+
dcApiSupported: dcApiSupported
|
|
1758
2156
|
});
|
|
1759
2157
|
if (createSessionResult.isErr()) {
|
|
1760
2158
|
return err({
|
|
1761
2159
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1762
|
-
message:
|
|
2160
|
+
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1763
2161
|
cause: createSessionResult.error
|
|
1764
2162
|
});
|
|
1765
2163
|
}
|
|
1766
|
-
const
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
2164
|
+
const session = createSessionResult.value;
|
|
2165
|
+
const {sessionKey: sessionKey, sessionId: sessionId} = session;
|
|
2166
|
+
if (session.type === SessionType.DigitalCredentialsApi) {
|
|
2167
|
+
const {request: request, sessionTtl: sessionTtl} = session;
|
|
2168
|
+
return await requestCredentialsWithDigitalCredentialsApi({
|
|
2169
|
+
apiBaseUrl: apiBaseUrl,
|
|
2170
|
+
request: request,
|
|
2171
|
+
sessionId: sessionId,
|
|
2172
|
+
sessionKey: sessionKey,
|
|
2173
|
+
challenge: challenge,
|
|
2174
|
+
sessionTtl: sessionTtl
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
if (!openid4vpConfiguration) {
|
|
1772
2178
|
return err({
|
|
1773
2179
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1774
|
-
message:
|
|
2180
|
+
message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
|
|
1775
2181
|
});
|
|
1776
2182
|
}
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
2183
|
+
const {sessionUrl: sessionUrl} = session;
|
|
2184
|
+
if (openId4VpRedirectUri) {
|
|
2185
|
+
return await requestCredentialsSameDevice({
|
|
2186
|
+
challenge: challenge,
|
|
2187
|
+
apiBaseUrl: apiBaseUrl,
|
|
2188
|
+
applicationId: applicationId,
|
|
2189
|
+
sessionUrl: sessionUrl,
|
|
2190
|
+
sessionKey: sessionKey,
|
|
2191
|
+
sessionId: sessionId
|
|
2192
|
+
});
|
|
1782
2193
|
}
|
|
1783
|
-
|
|
2194
|
+
return await requestCredentialsWithCrossDevice({
|
|
1784
2195
|
challenge: challenge,
|
|
1785
|
-
sessionId: sessionId,
|
|
1786
|
-
response: response,
|
|
1787
2196
|
apiBaseUrl: apiBaseUrl,
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
return ok({
|
|
1792
|
-
sessionId: sessionId,
|
|
1793
|
-
result: result.value
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
return err({
|
|
1797
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1798
|
-
message: "Invalid response from digital credentials api"
|
|
2197
|
+
sessionUrl: sessionUrl,
|
|
2198
|
+
sessionKey: sessionKey,
|
|
2199
|
+
sessionId: sessionId
|
|
1799
2200
|
});
|
|
1800
2201
|
};
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
if (!initialiseOptions) {
|
|
1805
|
-
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
1806
|
-
}
|
|
1807
|
-
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
1808
|
-
const {challenge: challenge = generateChallenge()} = options;
|
|
1809
|
-
const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : isMobileDetect(navigator.userAgent) ? exports.Mode.sameDevice : exports.Mode.crossDevice;
|
|
1810
|
-
if (initialiseOptions.enableDigitalCredentialsApiCrossDeviceFlow && isDigitalCredentialsApiSupported() && mode === exports.Mode.crossDevice) {
|
|
1811
|
-
console.log("Digital Credentials API support found, proceeding with request using API in cross device flow");
|
|
1812
|
-
return await requestCredentialsDigitalCredentialsApi(Object.assign(Object.assign({}, options), {
|
|
1813
|
-
initialiseOptions: initialiseOptions,
|
|
1814
|
-
challenge: challenge
|
|
1815
|
-
}));
|
|
1816
|
-
} else if (initialiseOptions.enableDigitalCredentialsApiCrossDeviceFlow) {
|
|
1817
|
-
console.log("Digital Credentials API support not found, falling back to OpenID4VP");
|
|
1818
|
-
}
|
|
1819
|
-
if (initialiseOptions.enableDigitalCredentialsApiSameDeviceFlow && isDigitalCredentialsApiSupported() && mode === exports.Mode.sameDevice) {
|
|
1820
|
-
console.log("Digital Credentials API support found, proceeding with request using API in same device flow");
|
|
1821
|
-
return await requestCredentialsDigitalCredentialsApi(Object.assign(Object.assign({}, options), {
|
|
1822
|
-
initialiseOptions: initialiseOptions,
|
|
1823
|
-
challenge: challenge
|
|
1824
|
-
}));
|
|
1825
|
-
} else if (initialiseOptions.enableDigitalCredentialsApiSameDeviceFlow) {
|
|
1826
|
-
console.log("Digital Credentials API support not found, falling back to OpenID4VP");
|
|
2202
|
+
const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
|
|
2203
|
+
if (!openid4vpConfiguration) {
|
|
2204
|
+
return undefined;
|
|
1827
2205
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
}));
|
|
2206
|
+
let detectedMode;
|
|
2207
|
+
if (openid4vpConfiguration && openid4vpConfiguration.mode) {
|
|
2208
|
+
detectedMode = openid4vpConfiguration.mode;
|
|
2209
|
+
} else {
|
|
2210
|
+
detectedMode = isMobileDetect(navigator.userAgent) ? exports.Mode.SameDevice : exports.Mode.CrossDevice;
|
|
1834
2211
|
}
|
|
1835
|
-
if (
|
|
1836
|
-
return
|
|
1837
|
-
initialiseOptions: initialiseOptions,
|
|
1838
|
-
challenge: challenge,
|
|
1839
|
-
mode: mode
|
|
1840
|
-
}));
|
|
2212
|
+
if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
|
|
2213
|
+
return openid4vpConfiguration.redirectUri.trim();
|
|
1841
2214
|
}
|
|
1842
|
-
|
|
1843
|
-
data: options
|
|
1844
|
-
});
|
|
2215
|
+
return undefined;
|
|
1845
2216
|
};
|
|
1846
2217
|
exports.HandleRedirectCallbackErrorType = void 0;
|
|
1847
2218
|
(function(HandleRedirectCallbackErrorType) {
|
|
@@ -1851,15 +2222,15 @@
|
|
|
1851
2222
|
(function(HandleRedirectCallbackErrorMessage) {
|
|
1852
2223
|
HandleRedirectCallbackErrorMessage["FailedToFindResponseCode"] = "Failed to find response code";
|
|
1853
2224
|
HandleRedirectCallbackErrorMessage["FailedToFindChallenge"] = "Failed to find challenge";
|
|
1854
|
-
HandleRedirectCallbackErrorMessage["
|
|
2225
|
+
HandleRedirectCallbackErrorMessage["FailedToFindActiveSession"] = "Failed to find active session";
|
|
1855
2226
|
HandleRedirectCallbackErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1856
2227
|
})(HandleRedirectCallbackErrorMessage || (HandleRedirectCallbackErrorMessage = {}));
|
|
1857
2228
|
const handleRedirectCallback = async () => {
|
|
1858
|
-
const
|
|
1859
|
-
if (!
|
|
1860
|
-
throw new Exception(
|
|
2229
|
+
const initializeOptions = getInitializeOptions();
|
|
2230
|
+
if (!initializeOptions) {
|
|
2231
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
1861
2232
|
}
|
|
1862
|
-
const {apiBaseUrl: apiBaseUrl} =
|
|
2233
|
+
const {apiBaseUrl: apiBaseUrl} = initializeOptions;
|
|
1863
2234
|
const responseCode = getHashParamValue(window.location.hash, "response_code");
|
|
1864
2235
|
if (!responseCode) {
|
|
1865
2236
|
return err({
|
|
@@ -1867,18 +2238,12 @@
|
|
|
1867
2238
|
message: HandleRedirectCallbackErrorMessage.FailedToFindResponseCode
|
|
1868
2239
|
});
|
|
1869
2240
|
}
|
|
1870
|
-
const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
1871
|
-
if (!challenge) {
|
|
1872
|
-
return err({
|
|
1873
|
-
type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
|
|
1874
|
-
message: HandleRedirectCallbackErrorMessage.FailedToFindChallenge
|
|
1875
|
-
});
|
|
1876
|
-
}
|
|
1877
2241
|
const sessionId = window.localStorage.getItem(LocalStorageKey.sessionId);
|
|
1878
|
-
|
|
2242
|
+
const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
2243
|
+
if (!sessionId || !challenge) {
|
|
1879
2244
|
return err({
|
|
1880
2245
|
type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
|
|
1881
|
-
message: HandleRedirectCallbackErrorMessage.
|
|
2246
|
+
message: HandleRedirectCallbackErrorMessage.FailedToFindActiveSession
|
|
1882
2247
|
});
|
|
1883
2248
|
}
|
|
1884
2249
|
const result = await exchangeSessionResult({
|
|
@@ -1895,17 +2260,19 @@
|
|
|
1895
2260
|
});
|
|
1896
2261
|
}
|
|
1897
2262
|
return ok({
|
|
1898
|
-
result: result.value,
|
|
2263
|
+
result: "challenge" in result.value ? result.value : undefined,
|
|
1899
2264
|
sessionId: result.value.sessionId
|
|
1900
2265
|
});
|
|
1901
2266
|
};
|
|
1902
2267
|
const utils = {
|
|
1903
2268
|
generateChallenge: generateChallenge,
|
|
1904
|
-
|
|
1905
|
-
|
|
2269
|
+
getVersion: getVersion,
|
|
2270
|
+
unwrap: unwrap
|
|
1906
2271
|
};
|
|
2272
|
+
exports.abortCredentialRequest = abortCredentialRequest;
|
|
1907
2273
|
exports.handleRedirectCallback = handleRedirectCallback;
|
|
1908
|
-
exports.
|
|
2274
|
+
exports.initialize = initialize;
|
|
2275
|
+
exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
|
|
1909
2276
|
exports.requestCredentials = requestCredentials;
|
|
1910
2277
|
exports.utils = utils;
|
|
1911
2278
|
Object.defineProperty(exports, "__esModule", {
|