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