@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
|
*/
|
|
@@ -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(),
|
|
@@ -1398,23 +1530,52 @@ const PresentationResultRelaxValidator = object({
|
|
|
1398
1530
|
error: optional(unknown())
|
|
1399
1531
|
});
|
|
1400
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
|
+
|
|
1401
1547
|
object({
|
|
1402
1548
|
credentialQuery: array(CredentialQueryValidator),
|
|
1403
1549
|
challenge: string(),
|
|
1404
1550
|
redirectUri: optional(string()),
|
|
1405
|
-
walletProviderId: optional(string())
|
|
1551
|
+
walletProviderId: optional(string()),
|
|
1552
|
+
dcApiSupported: optional(_boolean())
|
|
1406
1553
|
});
|
|
1407
1554
|
|
|
1408
|
-
const
|
|
1555
|
+
const CreateSessionDigitalCredentialsValidator = object({
|
|
1556
|
+
type: literal(SessionType.DigitalCredentialsApi),
|
|
1409
1557
|
sessionId: string(),
|
|
1410
|
-
|
|
1558
|
+
sessionKey: string(),
|
|
1559
|
+
sessionTtl: number(),
|
|
1560
|
+
request: record(string(), any())
|
|
1411
1561
|
});
|
|
1412
1562
|
|
|
1413
|
-
const
|
|
1563
|
+
const CreateSessionOpenId4vpResponseValidator = object({
|
|
1564
|
+
type: optional(literal(SessionType.Openid4vp)),
|
|
1414
1565
|
sessionId: string(),
|
|
1415
|
-
|
|
1566
|
+
sessionKey: string(),
|
|
1567
|
+
sessionUrl: string()
|
|
1416
1568
|
});
|
|
1417
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
|
+
|
|
1418
1579
|
var LocalStorageKey;
|
|
1419
1580
|
|
|
1420
1581
|
(function(LocalStorageKey) {
|
|
@@ -1422,12 +1583,9 @@ var LocalStorageKey;
|
|
|
1422
1583
|
LocalStorageKey["sessionId"] = "mattr_sid";
|
|
1423
1584
|
})(LocalStorageKey || (LocalStorageKey = {}));
|
|
1424
1585
|
|
|
1425
|
-
|
|
1586
|
+
const MATTR_SDK_VERSION_HEADER = "x-mattr-sdk-version";
|
|
1426
1587
|
|
|
1427
|
-
|
|
1428
|
-
Mode["sameDevice"] = "sameDevice";
|
|
1429
|
-
Mode["crossDevice"] = "crossDevice";
|
|
1430
|
-
})(exports.Mode || (exports.Mode = {}));
|
|
1588
|
+
const MATTR_SDK_VERSION_VALUE = "2.0.0";
|
|
1431
1589
|
|
|
1432
1590
|
var MessageEventDataType;
|
|
1433
1591
|
|
|
@@ -1437,66 +1595,187 @@ var MessageEventDataType;
|
|
|
1437
1595
|
MessageEventDataType["PresentationAbort"] = "PresentationAbort";
|
|
1438
1596
|
})(MessageEventDataType || (MessageEventDataType = {}));
|
|
1439
1597
|
|
|
1440
|
-
const
|
|
1441
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1442
|
-
redirectUri: string(),
|
|
1443
|
-
challenge: optional(string()),
|
|
1598
|
+
const OpenId4vpConfigSameDeviceOptionsValidator = object({
|
|
1444
1599
|
walletProviderId: optional(string()),
|
|
1445
|
-
mode:
|
|
1600
|
+
mode: literal(exports.Mode.SameDevice),
|
|
1601
|
+
redirectUri: pipe(string(), nonEmpty("Must not be empty"), url())
|
|
1446
1602
|
});
|
|
1447
1603
|
|
|
1448
|
-
const
|
|
1449
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1450
|
-
crossDeviceCallback: object({
|
|
1451
|
-
onComplete: function_(),
|
|
1452
|
-
onFailure: function_()
|
|
1453
|
-
}),
|
|
1454
|
-
challenge: optional(string()),
|
|
1604
|
+
const OpenId4vpConfigCrossDeviceOptionsValidator = object({
|
|
1455
1605
|
walletProviderId: optional(string()),
|
|
1456
|
-
mode:
|
|
1606
|
+
mode: literal(exports.Mode.CrossDevice)
|
|
1457
1607
|
});
|
|
1458
1608
|
|
|
1459
|
-
const
|
|
1460
|
-
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1461
|
-
crossDeviceCallback: object({
|
|
1462
|
-
onComplete: function_(),
|
|
1463
|
-
onFailure: function_()
|
|
1464
|
-
}),
|
|
1465
|
-
redirectUri: string(),
|
|
1466
|
-
challenge: optional(string()),
|
|
1609
|
+
const OpenId4vpConfigAutoDetectOptionsValidator = object({
|
|
1467
1610
|
walletProviderId: optional(string()),
|
|
1468
|
-
|
|
1611
|
+
redirectUri: pipe(string(), nonEmpty("Must not be empty"), url()),
|
|
1612
|
+
mode: optional(picklist([ exports.Mode.CrossDevice, exports.Mode.SameDevice ]))
|
|
1469
1613
|
});
|
|
1470
1614
|
|
|
1471
|
-
const RequestCredentialsOptionsValidator =
|
|
1615
|
+
const RequestCredentialsOptionsValidator = object({
|
|
1616
|
+
credentialQuery: pipe(array(CredentialQueryValidator), nonEmpty()),
|
|
1617
|
+
challenge: optional(string()),
|
|
1618
|
+
openid4vpConfiguration: optional(union([ OpenId4vpConfigSameDeviceOptionsValidator, OpenId4vpConfigCrossDeviceOptionsValidator, OpenId4vpConfigAutoDetectOptionsValidator ]))
|
|
1619
|
+
});
|
|
1472
1620
|
|
|
1473
1621
|
exports.RequestCredentialsErrorType = void 0;
|
|
1474
1622
|
|
|
1475
1623
|
(function(RequestCredentialsErrorType) {
|
|
1476
1624
|
RequestCredentialsErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
|
|
1625
|
+
RequestCredentialsErrorType["Timeout"] = "Timeout";
|
|
1626
|
+
RequestCredentialsErrorType["Abort"] = "Abort";
|
|
1477
1627
|
})(exports.RequestCredentialsErrorType || (exports.RequestCredentialsErrorType = {}));
|
|
1478
1628
|
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
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"))
|
|
1484
1658
|
});
|
|
1485
1659
|
|
|
1486
|
-
|
|
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;
|
|
1718
|
+
|
|
1719
|
+
var InitializeErrorMessage;
|
|
1487
1720
|
|
|
1488
|
-
|
|
1721
|
+
(function(InitializeErrorMessage) {
|
|
1722
|
+
InitializeErrorMessage["SdkNotInitialized"] = "SDK not initialized";
|
|
1723
|
+
})(InitializeErrorMessage || (InitializeErrorMessage = {}));
|
|
1489
1724
|
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
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
|
+
};
|
|
1733
|
+
};
|
|
1734
|
+
|
|
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
|
+
};
|
|
1493
1758
|
|
|
1494
|
-
const
|
|
1495
|
-
|
|
1496
|
-
|
|
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;
|
|
1497
1767
|
};
|
|
1498
1768
|
|
|
1499
|
-
const
|
|
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
|
+
};
|
|
1500
1779
|
|
|
1501
1780
|
var isMobile_1 = isMobile;
|
|
1502
1781
|
|
|
@@ -1533,6 +1812,24 @@ const defaultRetryDelay = attempt => Math.pow(2, attempt) * 1e3;
|
|
|
1533
1812
|
|
|
1534
1813
|
const defaultRetry = 2;
|
|
1535
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
|
+
|
|
1536
1833
|
const withRetrySafeFetch = async (fn, options) => {
|
|
1537
1834
|
const {retries: retries = defaultRetry, retryDelay: retryDelay = defaultRetryDelay, attempt: attempt = 0, retryHttpStatus: retryHttpStatus} = options;
|
|
1538
1835
|
const result = await fn();
|
|
@@ -1561,17 +1858,15 @@ const getHashParamValue = (hash, param) => {
|
|
|
1561
1858
|
return urlParams.get(param);
|
|
1562
1859
|
};
|
|
1563
1860
|
|
|
1564
|
-
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl,
|
|
1565
|
-
const postData =
|
|
1861
|
+
const createSession = async ({credentialQuery: credentialQuery, challenge: challenge, redirectUri: redirectUri, apiBaseUrl: apiBaseUrl, walletProviderId: walletProviderId, dcApiSupported: dcApiSupported, applicationId: applicationId}) => {
|
|
1862
|
+
const postData = {
|
|
1566
1863
|
credentialQuery: credentialQuery,
|
|
1567
|
-
challenge: challenge
|
|
1568
|
-
|
|
1569
|
-
redirectUri: redirectUri
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
}
|
|
1573
|
-
walletProviderId: walletProviderId
|
|
1574
|
-
} : {});
|
|
1864
|
+
challenge: challenge,
|
|
1865
|
+
applicationId: applicationId,
|
|
1866
|
+
redirectUri: redirectUri,
|
|
1867
|
+
walletProviderId: walletProviderId,
|
|
1868
|
+
dcApiSupported: dcApiSupported
|
|
1869
|
+
};
|
|
1575
1870
|
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions`, {
|
|
1576
1871
|
method: "POST",
|
|
1577
1872
|
headers: {
|
|
@@ -1585,94 +1880,53 @@ const createSession = async ({credentialQuery: credentialQuery, challenge: chall
|
|
|
1585
1880
|
const data = await responseResult.value.json();
|
|
1586
1881
|
if (!isType(CreateSessionResponseValidator)(data)) {
|
|
1587
1882
|
return err({
|
|
1588
|
-
type:
|
|
1589
|
-
message: "Create session
|
|
1883
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1884
|
+
message: "Create session returned unsupported response"
|
|
1590
1885
|
});
|
|
1591
1886
|
}
|
|
1592
1887
|
return ok(data);
|
|
1593
1888
|
};
|
|
1594
1889
|
|
|
1595
|
-
const
|
|
1596
|
-
const
|
|
1597
|
-
challenge: challenge,
|
|
1598
|
-
responseCode: responseCode
|
|
1599
|
-
};
|
|
1600
|
-
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`, {
|
|
1601
1892
|
method: "POST",
|
|
1602
1893
|
headers: {
|
|
1603
|
-
"Content-Type": "application/json"
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
});
|
|
1607
|
-
const responseResult = await withRetrySafeFetch(fetchResultFn, {
|
|
1608
|
-
retries: 2,
|
|
1609
|
-
retryHttpStatus: 404
|
|
1894
|
+
"Content-Type": "application/json",
|
|
1895
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1896
|
+
}
|
|
1610
1897
|
});
|
|
1611
1898
|
if (responseResult.isErr()) {
|
|
1612
1899
|
return err(responseResult.error);
|
|
1613
1900
|
}
|
|
1614
|
-
|
|
1615
|
-
if (!isType(PresentationResultRelaxValidator)(data)) {
|
|
1616
|
-
return err({
|
|
1617
|
-
type: SafeFetchCommonRespondErrorType.UnexpectedRespond,
|
|
1618
|
-
message: "Exchange session result return unsupported response",
|
|
1619
|
-
details: {
|
|
1620
|
-
data: data
|
|
1621
|
-
}
|
|
1622
|
-
});
|
|
1623
|
-
}
|
|
1624
|
-
return ok(data);
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
|
-
const isMobileDetect = userAgent => isMobile_2({
|
|
1628
|
-
ua: userAgent,
|
|
1629
|
-
tablet: false
|
|
1630
|
-
});
|
|
1631
|
-
|
|
1632
|
-
const isDigitalCredentialsApiSupported = () => {
|
|
1633
|
-
var _a;
|
|
1634
|
-
try {
|
|
1635
|
-
return typeof ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.identity) === null || _a === void 0 ? void 0 : _a.get) === "function";
|
|
1636
|
-
} catch (error) {
|
|
1637
|
-
return false;
|
|
1638
|
-
}
|
|
1901
|
+
return ok(undefined);
|
|
1639
1902
|
};
|
|
1640
1903
|
|
|
1641
|
-
const
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
challenge: challenge
|
|
1645
|
-
}, protocol && {
|
|
1646
|
-
protocol: protocol
|
|
1647
|
-
});
|
|
1648
|
-
const responseResult = await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/web/request`, {
|
|
1649
|
-
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",
|
|
1650
1907
|
headers: {
|
|
1651
|
-
|
|
1652
|
-
}
|
|
1653
|
-
body: JSON.stringify(postData)
|
|
1908
|
+
Authorization: `Bearer ${sessionKey}`
|
|
1909
|
+
}
|
|
1654
1910
|
});
|
|
1655
1911
|
if (responseResult.isErr()) {
|
|
1656
1912
|
return err(responseResult.error);
|
|
1657
1913
|
}
|
|
1658
1914
|
const data = await responseResult.value.json();
|
|
1659
|
-
if (!isType(
|
|
1915
|
+
if (!isType(GetSessionStatusResponseValidator)(data)) {
|
|
1660
1916
|
return err({
|
|
1661
|
-
type:
|
|
1662
|
-
message: "
|
|
1917
|
+
type: SafeFetchCommonResponseErrorType.UnexpectedResponse,
|
|
1918
|
+
message: "Get session status return unsupported response"
|
|
1663
1919
|
});
|
|
1664
1920
|
}
|
|
1665
1921
|
return ok(data);
|
|
1666
1922
|
};
|
|
1667
1923
|
|
|
1668
|
-
const
|
|
1924
|
+
const exchangeSessionResult = async ({challenge: challenge, responseCode: responseCode, sessionId: sessionId, apiBaseUrl: apiBaseUrl}) => {
|
|
1669
1925
|
const postData = {
|
|
1670
1926
|
challenge: challenge,
|
|
1671
|
-
|
|
1672
|
-
response: response,
|
|
1673
|
-
protocol: protocol
|
|
1927
|
+
responseCode: responseCode
|
|
1674
1928
|
};
|
|
1675
|
-
const fetchResultFn = async () => await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/
|
|
1929
|
+
const fetchResultFn = async () => await safeFetch(`${apiBaseUrl}/v2/presentations/sessions/${sessionId}/result`, {
|
|
1676
1930
|
method: "POST",
|
|
1677
1931
|
headers: {
|
|
1678
1932
|
"Content-Type": "application/json"
|
|
@@ -1687,25 +1941,24 @@ const getDigitalCredentialsApiSessionResult = async ({challenge: challenge, sess
|
|
|
1687
1941
|
return err(responseResult.error);
|
|
1688
1942
|
}
|
|
1689
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
|
+
}
|
|
1690
1953
|
return ok(data);
|
|
1691
1954
|
};
|
|
1692
1955
|
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
CrossDeviceCallbackErrorType["Abort"] = "Abort";
|
|
1698
|
-
CrossDeviceCallbackErrorType["RequestCredentialsFailed"] = "RequestCredentialsFailed";
|
|
1699
|
-
})(exports.CrossDeviceCallbackErrorType || (exports.CrossDeviceCallbackErrorType = {}));
|
|
1700
|
-
|
|
1701
|
-
var CrossDeviceRequestCredentialsErrorMessage;
|
|
1956
|
+
const isMobileDetect = userAgent => isMobile_2({
|
|
1957
|
+
ua: userAgent,
|
|
1958
|
+
tablet: false
|
|
1959
|
+
});
|
|
1702
1960
|
|
|
1703
|
-
(
|
|
1704
|
-
CrossDeviceRequestCredentialsErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
1705
|
-
CrossDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1706
|
-
CrossDeviceRequestCredentialsErrorMessage["Abort"] = "User aborted the session";
|
|
1707
|
-
CrossDeviceRequestCredentialsErrorMessage["Timeout"] = "User session timeout";
|
|
1708
|
-
})(CrossDeviceRequestCredentialsErrorMessage || (CrossDeviceRequestCredentialsErrorMessage = {}));
|
|
1961
|
+
const getVersion = () => MATTR_SDK_VERSION_VALUE;
|
|
1709
1962
|
|
|
1710
1963
|
var WindowEventListenerType;
|
|
1711
1964
|
|
|
@@ -1713,10 +1966,13 @@ var WindowEventListenerType;
|
|
|
1713
1966
|
WindowEventListenerType["message"] = "message";
|
|
1714
1967
|
})(WindowEventListenerType || (WindowEventListenerType = {}));
|
|
1715
1968
|
|
|
1716
|
-
let listener;
|
|
1969
|
+
let listener = undefined;
|
|
1717
1970
|
|
|
1718
1971
|
const removeWindowMessageEventListener = () => {
|
|
1719
|
-
|
|
1972
|
+
if (listener) {
|
|
1973
|
+
window.removeEventListener(WindowEventListenerType.message, listener, false);
|
|
1974
|
+
}
|
|
1975
|
+
listener = undefined;
|
|
1720
1976
|
};
|
|
1721
1977
|
|
|
1722
1978
|
const closeCrossDeviceModal = options => {
|
|
@@ -1728,8 +1984,7 @@ const closeCrossDeviceModal = options => {
|
|
|
1728
1984
|
};
|
|
1729
1985
|
|
|
1730
1986
|
const receiveMessageHandler = options => async event => {
|
|
1731
|
-
const {
|
|
1732
|
-
const {onComplete: onComplete, onFailure: onFailure} = crossDeviceCallback;
|
|
1987
|
+
const {onComplete: onComplete, onFailure: onFailure, container: container, sessionId: sessionId, apiBaseUrl: apiBaseUrl, challenge: challenge} = options;
|
|
1733
1988
|
if (event.origin !== apiBaseUrl) {
|
|
1734
1989
|
return;
|
|
1735
1990
|
}
|
|
@@ -1743,8 +1998,8 @@ const receiveMessageHandler = options => async event => {
|
|
|
1743
1998
|
});
|
|
1744
1999
|
if (result.isErr()) {
|
|
1745
2000
|
onFailure({
|
|
1746
|
-
type: exports.
|
|
1747
|
-
message:
|
|
2001
|
+
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
2002
|
+
message: RequestCredentialsErrorMessage.FailedToGetSessionResult
|
|
1748
2003
|
});
|
|
1749
2004
|
closeCrossDeviceModal({
|
|
1750
2005
|
container: container
|
|
@@ -1752,8 +2007,9 @@ const receiveMessageHandler = options => async event => {
|
|
|
1752
2007
|
return;
|
|
1753
2008
|
}
|
|
1754
2009
|
onComplete({
|
|
1755
|
-
result: result.value,
|
|
1756
|
-
sessionId: result.value.sessionId
|
|
2010
|
+
result: "challenge" in result.value ? result.value : undefined,
|
|
2011
|
+
sessionId: result.value.sessionId,
|
|
2012
|
+
sessionCompletedInRedirect: false
|
|
1757
2013
|
});
|
|
1758
2014
|
closeCrossDeviceModal({
|
|
1759
2015
|
container: container
|
|
@@ -1762,8 +2018,8 @@ const receiveMessageHandler = options => async event => {
|
|
|
1762
2018
|
}
|
|
1763
2019
|
if (event.data.type === MessageEventDataType.PresentationTimeout) {
|
|
1764
2020
|
onFailure({
|
|
1765
|
-
type: exports.
|
|
1766
|
-
message:
|
|
2021
|
+
type: exports.RequestCredentialsErrorType.Timeout,
|
|
2022
|
+
message: RequestCredentialsErrorMessage.Timeout
|
|
1767
2023
|
});
|
|
1768
2024
|
closeCrossDeviceModal({
|
|
1769
2025
|
container: container
|
|
@@ -1772,8 +2028,8 @@ const receiveMessageHandler = options => async event => {
|
|
|
1772
2028
|
}
|
|
1773
2029
|
if (event.data.type === MessageEventDataType.PresentationAbort) {
|
|
1774
2030
|
onFailure({
|
|
1775
|
-
type: exports.
|
|
1776
|
-
message:
|
|
2031
|
+
type: exports.RequestCredentialsErrorType.Abort,
|
|
2032
|
+
message: RequestCredentialsErrorMessage.Abort
|
|
1777
2033
|
});
|
|
1778
2034
|
closeCrossDeviceModal({
|
|
1779
2035
|
container: container
|
|
@@ -1798,82 +2054,202 @@ const openCrossDeviceModal = options => {
|
|
|
1798
2054
|
return modalContainer;
|
|
1799
2055
|
};
|
|
1800
2056
|
|
|
1801
|
-
const
|
|
1802
|
-
const {challenge: challenge,
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
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({
|
|
1807
2102
|
apiBaseUrl: apiBaseUrl,
|
|
1808
|
-
|
|
1809
|
-
|
|
2103
|
+
sessionId: sessionId,
|
|
2104
|
+
sessionKey: sessionKey
|
|
1810
2105
|
});
|
|
1811
|
-
if (
|
|
2106
|
+
if (abortSessionResult.isErr()) {
|
|
1812
2107
|
return err({
|
|
1813
|
-
type: exports.
|
|
1814
|
-
message:
|
|
1815
|
-
cause:
|
|
2108
|
+
type: exports.AbortSessionErrorType.AbortSessionFailed,
|
|
2109
|
+
message: AbortSessionErrorMessage.FailedToAbortSession,
|
|
2110
|
+
cause: abortSessionResult.error
|
|
1816
2111
|
});
|
|
1817
2112
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
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({
|
|
1826
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({
|
|
1827
2137
|
apiBaseUrl: apiBaseUrl,
|
|
1828
|
-
|
|
2138
|
+
sessionId: sessionId,
|
|
2139
|
+
sessionKey: sessionKey,
|
|
2140
|
+
challenge: challenge,
|
|
2141
|
+
protocol: parsedCredentialResponse.protocol,
|
|
2142
|
+
data: parsedCredentialResponse.data
|
|
1829
2143
|
});
|
|
1830
|
-
|
|
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;
|
|
1831
2152
|
return ok({
|
|
2153
|
+
result: "challenge" in verificationResult ? verificationResult : undefined,
|
|
1832
2154
|
sessionId: sessionId
|
|
1833
2155
|
});
|
|
1834
2156
|
};
|
|
1835
2157
|
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
(
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
const requestCredentialsSameDevice = async options => {
|
|
1844
|
-
const {challenge: challenge, credentialQuery: credentialQuery, redirectUri: redirectUri, walletProviderId: walletProviderId, initialiseOptions: initialiseOptions} = options;
|
|
1845
|
-
const {apiBaseUrl: apiBaseUrl, applicationId: applicationId} = initialiseOptions;
|
|
1846
|
-
window.localStorage.setItem(LocalStorageKey.challenge, challenge);
|
|
1847
|
-
const storedChallenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
1848
|
-
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) {
|
|
1849
2165
|
return err({
|
|
1850
2166
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1851
|
-
message:
|
|
2167
|
+
message: RequestCredentialsErrorMessage.DcApiError,
|
|
2168
|
+
cause: exception
|
|
1852
2169
|
});
|
|
1853
2170
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
apiBaseUrl: apiBaseUrl,
|
|
1859
|
-
applicationId: applicationId,
|
|
1860
|
-
walletProviderId: walletProviderId
|
|
1861
|
-
});
|
|
1862
|
-
if (createSessionResult.isErr()) {
|
|
2171
|
+
};
|
|
2172
|
+
|
|
2173
|
+
const parseCredentialResponse = credentialResponse => {
|
|
2174
|
+
if (!credentialResponse) {
|
|
1863
2175
|
return err({
|
|
1864
2176
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1865
|
-
message:
|
|
1866
|
-
|
|
2177
|
+
message: RequestCredentialsErrorMessage.DcApiResponseParseError,
|
|
2178
|
+
details: {
|
|
2179
|
+
response: credentialResponse
|
|
2180
|
+
}
|
|
1867
2181
|
});
|
|
1868
2182
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
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)
|
|
1874
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";
|
|
1875
2243
|
};
|
|
1876
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
|
+
|
|
1877
2253
|
var SameDeviceRequestCredentialsErrorMessage;
|
|
1878
2254
|
|
|
1879
2255
|
(function(SameDeviceRequestCredentialsErrorMessage) {
|
|
@@ -1881,110 +2257,136 @@ var SameDeviceRequestCredentialsErrorMessage;
|
|
|
1881
2257
|
SameDeviceRequestCredentialsErrorMessage["FailedToCreateSession"] = "Failed to create session";
|
|
1882
2258
|
})(SameDeviceRequestCredentialsErrorMessage || (SameDeviceRequestCredentialsErrorMessage = {}));
|
|
1883
2259
|
|
|
1884
|
-
const
|
|
1885
|
-
const {challenge: challenge,
|
|
1886
|
-
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);
|
|
1887
2267
|
window.localStorage.setItem(LocalStorageKey.challenge, challenge);
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
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
|
|
1893
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);
|
|
1894
2315
|
}
|
|
1895
|
-
|
|
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({
|
|
1896
2322
|
credentialQuery: credentialQuery,
|
|
1897
|
-
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,
|
|
1898
2326
|
apiBaseUrl: apiBaseUrl,
|
|
1899
|
-
|
|
2327
|
+
applicationId: applicationId,
|
|
2328
|
+
dcApiSupported: dcApiSupported
|
|
1900
2329
|
});
|
|
1901
2330
|
if (createSessionResult.isErr()) {
|
|
1902
2331
|
return err({
|
|
1903
2332
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1904
|
-
message:
|
|
2333
|
+
message: RequestCredentialsErrorMessage.FailedToCreateSession,
|
|
1905
2334
|
cause: createSessionResult.error
|
|
1906
2335
|
});
|
|
1907
2336
|
}
|
|
1908
|
-
const
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
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) {
|
|
1914
2351
|
return err({
|
|
1915
2352
|
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1916
|
-
message:
|
|
2353
|
+
message: RequestCredentialsErrorMessage.MissingOpenId4vpConfig
|
|
1917
2354
|
});
|
|
1918
2355
|
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
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
|
+
});
|
|
1924
2366
|
}
|
|
1925
|
-
|
|
2367
|
+
return await requestCredentialsWithCrossDevice({
|
|
1926
2368
|
challenge: challenge,
|
|
1927
|
-
sessionId: sessionId,
|
|
1928
|
-
response: response,
|
|
1929
2369
|
apiBaseUrl: apiBaseUrl,
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
return ok({
|
|
1934
|
-
sessionId: sessionId,
|
|
1935
|
-
result: result.value
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1938
|
-
return err({
|
|
1939
|
-
type: exports.RequestCredentialsErrorType.RequestCredentialsFailed,
|
|
1940
|
-
message: "Invalid response from digital credentials api"
|
|
2370
|
+
sessionUrl: sessionUrl,
|
|
2371
|
+
sessionKey: sessionKey,
|
|
2372
|
+
sessionId: sessionId
|
|
1941
2373
|
});
|
|
1942
2374
|
};
|
|
1943
2375
|
|
|
1944
|
-
const
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
if (!initialiseOptions) {
|
|
1948
|
-
throw new Exception(InitialiseErrorMessage.SdkNotInitialised);
|
|
1949
|
-
}
|
|
1950
|
-
assertType(RequestCredentialsOptionsValidator, "Invalid request credential options")(options);
|
|
1951
|
-
const {challenge: challenge = generateChallenge()} = options;
|
|
1952
|
-
const mode = (_a = options.mode) !== null && _a !== void 0 ? _a : isMobileDetect(navigator.userAgent) ? exports.Mode.sameDevice : exports.Mode.crossDevice;
|
|
1953
|
-
if (initialiseOptions.enableDigitalCredentialsApiCrossDeviceFlow && isDigitalCredentialsApiSupported() && mode === exports.Mode.crossDevice) {
|
|
1954
|
-
console.log("Digital Credentials API support found, proceeding with request using API in cross device flow");
|
|
1955
|
-
return await requestCredentialsDigitalCredentialsApi(Object.assign(Object.assign({}, options), {
|
|
1956
|
-
initialiseOptions: initialiseOptions,
|
|
1957
|
-
challenge: challenge
|
|
1958
|
-
}));
|
|
1959
|
-
} else if (initialiseOptions.enableDigitalCredentialsApiCrossDeviceFlow) {
|
|
1960
|
-
console.log("Digital Credentials API support not found, falling back to OpenID4VP");
|
|
1961
|
-
}
|
|
1962
|
-
if (initialiseOptions.enableDigitalCredentialsApiSameDeviceFlow && isDigitalCredentialsApiSupported() && mode === exports.Mode.sameDevice) {
|
|
1963
|
-
console.log("Digital Credentials API support found, proceeding with request using API in same device flow");
|
|
1964
|
-
return await requestCredentialsDigitalCredentialsApi(Object.assign(Object.assign({}, options), {
|
|
1965
|
-
initialiseOptions: initialiseOptions,
|
|
1966
|
-
challenge: challenge
|
|
1967
|
-
}));
|
|
1968
|
-
} else if (initialiseOptions.enableDigitalCredentialsApiSameDeviceFlow) {
|
|
1969
|
-
console.log("Digital Credentials API support not found, falling back to OpenID4VP");
|
|
2376
|
+
const deriveOpenId4vpRedirectUri = openid4vpConfiguration => {
|
|
2377
|
+
if (!openid4vpConfiguration) {
|
|
2378
|
+
return undefined;
|
|
1970
2379
|
}
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
}));
|
|
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;
|
|
1977
2385
|
}
|
|
1978
|
-
if (
|
|
1979
|
-
return
|
|
1980
|
-
initialiseOptions: initialiseOptions,
|
|
1981
|
-
challenge: challenge,
|
|
1982
|
-
mode: mode
|
|
1983
|
-
}));
|
|
2386
|
+
if (detectedMode === exports.Mode.SameDevice && !isType(OpenId4vpConfigCrossDeviceOptionsValidator)(openid4vpConfiguration) && openid4vpConfiguration.redirectUri) {
|
|
2387
|
+
return openid4vpConfiguration.redirectUri.trim();
|
|
1984
2388
|
}
|
|
1985
|
-
|
|
1986
|
-
data: options
|
|
1987
|
-
});
|
|
2389
|
+
return undefined;
|
|
1988
2390
|
};
|
|
1989
2391
|
|
|
1990
2392
|
exports.HandleRedirectCallbackErrorType = void 0;
|
|
@@ -1998,16 +2400,16 @@ var HandleRedirectCallbackErrorMessage;
|
|
|
1998
2400
|
(function(HandleRedirectCallbackErrorMessage) {
|
|
1999
2401
|
HandleRedirectCallbackErrorMessage["FailedToFindResponseCode"] = "Failed to find response code";
|
|
2000
2402
|
HandleRedirectCallbackErrorMessage["FailedToFindChallenge"] = "Failed to find challenge";
|
|
2001
|
-
HandleRedirectCallbackErrorMessage["
|
|
2403
|
+
HandleRedirectCallbackErrorMessage["FailedToFindActiveSession"] = "Failed to find active session";
|
|
2002
2404
|
HandleRedirectCallbackErrorMessage["FailedToGetSessionResult"] = "Failed to get session result";
|
|
2003
2405
|
})(HandleRedirectCallbackErrorMessage || (HandleRedirectCallbackErrorMessage = {}));
|
|
2004
2406
|
|
|
2005
2407
|
const handleRedirectCallback = async () => {
|
|
2006
|
-
const
|
|
2007
|
-
if (!
|
|
2008
|
-
throw new Exception(
|
|
2408
|
+
const initializeOptions = getInitializeOptions();
|
|
2409
|
+
if (!initializeOptions) {
|
|
2410
|
+
throw new Exception(InitializeErrorMessage.SdkNotInitialized);
|
|
2009
2411
|
}
|
|
2010
|
-
const {apiBaseUrl: apiBaseUrl} =
|
|
2412
|
+
const {apiBaseUrl: apiBaseUrl} = initializeOptions;
|
|
2011
2413
|
const responseCode = getHashParamValue(window.location.hash, "response_code");
|
|
2012
2414
|
if (!responseCode) {
|
|
2013
2415
|
return err({
|
|
@@ -2015,18 +2417,12 @@ const handleRedirectCallback = async () => {
|
|
|
2015
2417
|
message: HandleRedirectCallbackErrorMessage.FailedToFindResponseCode
|
|
2016
2418
|
});
|
|
2017
2419
|
}
|
|
2018
|
-
const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
2019
|
-
if (!challenge) {
|
|
2020
|
-
return err({
|
|
2021
|
-
type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
|
|
2022
|
-
message: HandleRedirectCallbackErrorMessage.FailedToFindChallenge
|
|
2023
|
-
});
|
|
2024
|
-
}
|
|
2025
2420
|
const sessionId = window.localStorage.getItem(LocalStorageKey.sessionId);
|
|
2026
|
-
|
|
2421
|
+
const challenge = window.localStorage.getItem(LocalStorageKey.challenge);
|
|
2422
|
+
if (!sessionId || !challenge) {
|
|
2027
2423
|
return err({
|
|
2028
2424
|
type: exports.HandleRedirectCallbackErrorType.HandleRedirectCallbackFailed,
|
|
2029
|
-
message: HandleRedirectCallbackErrorMessage.
|
|
2425
|
+
message: HandleRedirectCallbackErrorMessage.FailedToFindActiveSession
|
|
2030
2426
|
});
|
|
2031
2427
|
}
|
|
2032
2428
|
const result = await exchangeSessionResult({
|
|
@@ -2043,20 +2439,24 @@ const handleRedirectCallback = async () => {
|
|
|
2043
2439
|
});
|
|
2044
2440
|
}
|
|
2045
2441
|
return ok({
|
|
2046
|
-
result: result.value,
|
|
2442
|
+
result: "challenge" in result.value ? result.value : undefined,
|
|
2047
2443
|
sessionId: result.value.sessionId
|
|
2048
2444
|
});
|
|
2049
2445
|
};
|
|
2050
2446
|
|
|
2051
2447
|
const utils = {
|
|
2052
2448
|
generateChallenge: generateChallenge,
|
|
2053
|
-
|
|
2054
|
-
|
|
2449
|
+
getVersion: getVersion,
|
|
2450
|
+
unwrap: unwrap
|
|
2055
2451
|
};
|
|
2056
2452
|
|
|
2453
|
+
exports.abortCredentialRequest = abortCredentialRequest;
|
|
2454
|
+
|
|
2057
2455
|
exports.handleRedirectCallback = handleRedirectCallback;
|
|
2058
2456
|
|
|
2059
|
-
exports.
|
|
2457
|
+
exports.initialize = initialize;
|
|
2458
|
+
|
|
2459
|
+
exports.isDigitalCredentialsApiSupported = isDigitalCredentialsApiSupported;
|
|
2060
2460
|
|
|
2061
2461
|
exports.requestCredentials = requestCredentials;
|
|
2062
2462
|
|