@raytio/core 10.1.0 → 11.1.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.
Files changed (208) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +198 -59
  3. package/dist/{util/hash.d.ts → __tests__/docs.test.d.ts} +1 -1
  4. package/dist/__tests__/docs.test.js +24 -0
  5. package/dist/accessApplication/createAA.d.ts +17 -17
  6. package/dist/accessApplication/createAA.js +71 -71
  7. package/dist/accessApplication/index.d.ts +1 -1
  8. package/dist/accessApplication/index.js +17 -17
  9. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  10. package/dist/crypto/cognitoAttributes.js +33 -33
  11. package/dist/crypto/decryptKeys.d.ts +1 -1
  12. package/dist/crypto/decryptKeys.js +33 -33
  13. package/dist/crypto/decryptSharedData.d.ts +26 -26
  14. package/dist/crypto/decryptSharedData.js +38 -38
  15. package/dist/crypto/getAADecryptor.d.ts +16 -16
  16. package/dist/crypto/getAADecryptor.js +20 -20
  17. package/dist/crypto/helpers.d.ts +18 -18
  18. package/dist/crypto/helpers.js +26 -26
  19. package/dist/crypto/index.d.ts +4 -4
  20. package/dist/crypto/index.js +21 -21
  21. package/dist/general/conditional.d.ts +17 -17
  22. package/dist/general/conditional.js +32 -32
  23. package/dist/general/date.d.ts +2 -2
  24. package/dist/general/date.js +18 -18
  25. package/dist/general/index.d.ts +4 -4
  26. package/dist/general/index.js +20 -20
  27. package/dist/general/password.d.ts +10 -10
  28. package/dist/general/password.js +31 -31
  29. package/dist/general/types.d.ts +6 -6
  30. package/dist/general/types.js +13 -13
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +22 -22
  33. package/dist/rules/calculateScore.d.ts +28 -23
  34. package/dist/rules/calculateScore.js +82 -76
  35. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  36. package/dist/rules/convertInstanceToRuleInput.js +138 -139
  37. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  38. package/dist/rules/evaluateScoreCondition.js +44 -45
  39. package/dist/{verifications/checkVerifications.d.ts → rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts} +1 -1
  40. package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
  41. package/dist/{verifications/checkVerificationsNew.d.ts → rules/helpers/__tests__/checkTypeofValue.test.d.ts} +1 -1
  42. package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
  43. package/dist/{verifications/verifyCheck/util/canonicalJsonify.d.ts → rules/helpers/__tests__/getValuesFromPath.test.d.ts} +1 -1
  44. package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
  45. package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
  46. package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
  47. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  48. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  49. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
  50. package/dist/rules/helpers/checkTypeofValue.js +60 -55
  51. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  52. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  53. package/dist/rules/helpers/index.d.ts +5 -5
  54. package/dist/rules/helpers/index.js +21 -21
  55. package/dist/rules/helpers/symbols.d.ts +2 -2
  56. package/dist/rules/helpers/symbols.js +5 -5
  57. package/dist/rules/helpers/thresholds.d.ts +5 -5
  58. package/dist/rules/helpers/thresholds.js +46 -47
  59. package/dist/rules/index.d.ts +7 -7
  60. package/dist/rules/index.js +25 -25
  61. package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
  62. package/dist/rules/operators/__tests__/bool.test.js +21 -0
  63. package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
  64. package/dist/rules/operators/__tests__/date.test.js +81 -0
  65. package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
  66. package/dist/rules/operators/__tests__/hfield.test.js +38 -0
  67. package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
  68. package/dist/rules/operators/__tests__/hschema.test.js +24 -0
  69. package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
  70. package/dist/rules/operators/__tests__/number.test.js +53 -0
  71. package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
  72. package/dist/rules/operators/__tests__/string.test.js +74 -0
  73. package/dist/rules/operators/bool.d.ts +2 -2
  74. package/dist/rules/operators/bool.js +17 -17
  75. package/dist/rules/operators/date.d.ts +2 -2
  76. package/dist/rules/operators/date.js +91 -91
  77. package/dist/rules/operators/hfield.d.ts +2 -2
  78. package/dist/rules/operators/hfield.js +33 -33
  79. package/dist/rules/operators/hschema.d.ts +2 -2
  80. package/dist/rules/operators/hschema.js +21 -21
  81. package/dist/rules/operators/index.d.ts +3 -3
  82. package/dist/rules/operators/index.js +11 -11
  83. package/dist/rules/operators/number.d.ts +2 -2
  84. package/dist/rules/operators/number.js +41 -41
  85. package/dist/rules/operators/string.d.ts +2 -2
  86. package/dist/rules/operators/string.js +58 -58
  87. package/dist/rules/types/config.d.ts +95 -91
  88. package/dist/rules/types/config.js +2 -2
  89. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  90. package/dist/rules/types/dataValueTypes.js +4 -4
  91. package/dist/rules/types/index.d.ts +3 -3
  92. package/dist/rules/types/index.js +19 -19
  93. package/dist/rules/types/internal.d.ts +20 -20
  94. package/dist/rules/types/internal.js +2 -2
  95. package/dist/rules/validate.d.ts +6 -6
  96. package/dist/rules/validate.js +14 -14
  97. package/dist/rules/version.d.ts +1 -1
  98. package/dist/rules/version.js +5 -5
  99. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
  100. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
  101. package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
  102. package/dist/schema/expandSchema/__tests__/expandSchema.test.js +95 -0
  103. package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
  104. package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
  105. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
  106. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
  107. package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
  108. package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
  109. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
  110. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
  111. package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
  112. package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
  113. package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
  114. package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
  115. package/dist/schema/expandSchema/constants.d.ts +2 -0
  116. package/dist/schema/expandSchema/constants.js +11 -0
  117. package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
  118. package/dist/schema/expandSchema/expandSchema.js +19 -0
  119. package/dist/schema/expandSchema/i18n.d.ts +5 -0
  120. package/dist/schema/expandSchema/i18n.js +20 -0
  121. package/dist/schema/expandSchema/index.d.ts +3 -0
  122. package/dist/schema/expandSchema/index.js +21 -0
  123. package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
  124. package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
  125. package/dist/schema/expandSchema/processSchema.d.ts +4 -0
  126. package/dist/schema/expandSchema/processSchema.js +94 -0
  127. package/dist/schema/expandSchema/removePrivateFields.d.ts +119 -0
  128. package/dist/schema/expandSchema/removePrivateFields.js +15 -0
  129. package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
  130. package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
  131. package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
  132. package/dist/schema/expandSchema/unwrapSchema.js +7 -0
  133. package/dist/schema/expandSchema/util.d.ts +6 -0
  134. package/dist/schema/expandSchema/util.js +15 -0
  135. package/dist/schema/index.d.ts +2 -1
  136. package/dist/schema/index.js +18 -17
  137. package/dist/schema/labels.d.ts +2 -2
  138. package/dist/schema/labels.js +20 -20
  139. package/dist/util/canonicalJsonify.d.ts +1 -1
  140. package/dist/util/canonicalJsonify.js +50 -50
  141. package/dist/util/handleResponse.d.ts +1 -1
  142. package/dist/util/handleResponse.js +21 -21
  143. package/dist/util/index.d.ts +2 -2
  144. package/dist/util/index.js +18 -18
  145. package/dist/verifications/cleanInstance.d.ts +9 -9
  146. package/dist/verifications/cleanInstance.js +15 -15
  147. package/dist/verifications/getPOVerification.d.ts +19 -16
  148. package/dist/verifications/getPOVerification.js +105 -94
  149. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  150. package/dist/verifications/getVerifiedBy.js +19 -19
  151. package/dist/verifications/index.d.ts +5 -5
  152. package/dist/verifications/index.js +21 -21
  153. package/dist/verifications/maybeRereference.d.ts +1 -1
  154. package/dist/verifications/maybeRereference.js +10 -10
  155. package/dist/verifications/safeHarbour.d.ts +20 -20
  156. package/dist/verifications/safeHarbour.js +67 -74
  157. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
  158. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
  159. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
  160. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
  161. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  162. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
  163. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  164. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
  165. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  166. package/dist/verifications/verifyCheck/index.js +21 -21
  167. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
  168. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
  169. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
  170. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
  171. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
  172. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  173. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  174. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  175. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  176. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  177. package/dist/verifications/verifyCheck/operations/index.js +18 -18
  178. package/package.json +13 -10
  179. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  180. package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
  181. package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
  182. package/dist/rules/helpers/getValueFromPath.js +0 -35
  183. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
  184. package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
  185. package/dist/rules/isScoreResultValid.d.ts +0 -2
  186. package/dist/rules/isScoreResultValid.js +0 -9
  187. package/dist/rules/operators/array.d.ts +0 -2
  188. package/dist/rules/operators/array.js +0 -74
  189. package/dist/rules/types/operators.d.ts +0 -19
  190. package/dist/rules/types/operators.js +0 -2
  191. package/dist/rules/types/score.d.ts +0 -50
  192. package/dist/rules/types/score.js +0 -2
  193. package/dist/util/conditional.d.ts +0 -7
  194. package/dist/util/conditional.js +0 -15
  195. package/dist/util/hash.js +0 -11
  196. package/dist/verifications/checkSingleVerification.d.ts +0 -9
  197. package/dist/verifications/checkSingleVerification.js +0 -29
  198. package/dist/verifications/checkVerifications.js +0 -16
  199. package/dist/verifications/checkVerificationsNew.js +0 -16
  200. package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
  201. package/dist/verifications/getOwnRealVerifications.js +0 -64
  202. package/dist/verifications/getRealVerifications.d.ts +0 -22
  203. package/dist/verifications/getRealVerifications.js +0 -71
  204. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
  205. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
  206. package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
  207. package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
  208. package/dist/verifications/verifyCheck/util/index.js +0 -14
@@ -1,74 +1,67 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calcSafeHarbourScore = exports.safeHarbourRequirementsMet = exports.getFlags = exports.filterByMutualFields = void 0;
4
- const ramda_1 = require("ramda");
5
- const types_1 = require("@raytio/types");
6
- const getPOVerification_1 = require("./getPOVerification");
7
- const schema_1 = require("../schema");
8
- /** @internal see #659 */
9
- var SafeHarbourCode;
10
- (function (SafeHarbourCode) {
11
- SafeHarbourCode["M1"] = "M1";
12
- SafeHarbourCode["M2"] = "M2";
13
- SafeHarbourCode["N1"] = "N1";
14
- })(SafeHarbourCode || (SafeHarbourCode = {}));
15
- /**
16
- * @internal
17
- * we filter to only include the POs where all the mutual fields match the
18
- * person, i.e. we only want POs that have fName, lName, etc. with the same
19
- * value as the base person
20
- */
21
- function filterByMutualFields(person, profileObjects) {
22
- const personFields = Object.entries(person.properties).filter(([fieldName]) => fieldName !== "n_id");
23
- if (!personFields.length)
24
- return [];
25
- return profileObjects.filter(PO => personFields.every(([k, v]) => { var _a; return ((_a = PO.properties) === null || _a === void 0 ? void 0 : _a[k]) && (0, ramda_1.equals)(PO.properties[k], v); }));
26
- }
27
- exports.filterByMutualFields = filterByMutualFields;
28
- /** @internal */
29
- async function getFlags({ person, profileObjects, realVers, getSchema, }) {
30
- const POsWithSameFields = filterByMutualFields(person, profileObjects);
31
- const relevantVers = (await Promise.all(POsWithSameFields.map(async (PO) => {
32
- const schemaName = (0, schema_1.findSchemaLabel)(PO.labels);
33
- const schema = await getSchema(schemaName);
34
- return Object.assign({ nId: PO.n_id }, (0, getPOVerification_1.getPOVerification)({
35
- schema,
36
- PO,
37
- realVers,
38
- }));
39
- })))
40
- .filter(v => v.status === types_1.POVerification.FullyVerified)
41
- .flatMap(v => v.details.verifiers.map(verProvider => realVers.find(ver => ver.belongsToNId === v.nId &&
42
- ver.provider.dataSourceNId === verProvider.dataSourceNId)))
43
- .filter((x) => !!x);
44
- // in case there are somehow duplicates (see #922)
45
- return (0, ramda_1.uniqBy)(x => x.nID, relevantVers)
46
- .filter(ver => { var _a; return (_a = ver.metadata) === null || _a === void 0 ? void 0 : _a["safeHarbourScore"]; })
47
- .reduce((ac, ver) => {
48
- var _a, _b;
49
- const key = (_a = ver.metadata) === null || _a === void 0 ? void 0 : _a["safeHarbourScore"];
50
- if ((_b = ac[key]) === null || _b === void 0 ? void 0 : _b.includes(ver.xId))
51
- return ac;
52
- return Object.assign(Object.assign({}, ac), { [key]: [...(ac[key] || []), ver.xId] });
53
- }, {});
54
- }
55
- exports.getFlags = getFlags;
56
- /** @internal */
57
- function safeHarbourRequirementsMet(flags) {
58
- const { M1 = 0, M2 = 0, N1 = 0 } = (0, ramda_1.mapObjIndexed)(xIds => xIds.length, flags);
59
- // see https://bit.ly/2KKo4rF
60
- const isSafe = M1 >= 2 ||
61
- (M1 >= 1 && M2 >= 1) ||
62
- (M1 >= 1 && N1 >= 1) ||
63
- (M2 >= 1 && N1 >= 1);
64
- return { isSafe, flags };
65
- }
66
- exports.safeHarbourRequirementsMet = safeHarbourRequirementsMet;
67
- /**
68
- * The Safe Harbour Score indidicates whether a person's identity has been verified
69
- * to the extent requried for Safe Harbour Compliance. This requires multiple verifications
70
- * from different sources. For information, refer to the
71
- * {@link https://dev-docs.rayt.io/docs/features/pep-checks Raytio Documentation}.
72
- */
73
- const calcSafeHarbourScore = (data) => getFlags(data).then(safeHarbourRequirementsMet);
74
- exports.calcSafeHarbourScore = calcSafeHarbourScore;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calcSafeHarbourScore = exports.safeHarbourRequirementsMet = exports.getFlags = exports.filterByMutualFields = void 0;
4
+ const ramda_1 = require("ramda");
5
+ const types_1 = require("@raytio/types");
6
+ const getPOVerification_1 = require("./getPOVerification");
7
+ const schema_1 = require("../schema");
8
+ /**
9
+ * @internal
10
+ * we filter to only include the POs where all the mutual fields match the
11
+ * person, i.e. we only want POs that have fName, lName, etc. with the same
12
+ * value as the base person
13
+ */
14
+ function filterByMutualFields(person, profileObjects) {
15
+ const personFields = Object.entries(person.properties).filter(([fieldName]) => fieldName !== "n_id");
16
+ if (!personFields.length)
17
+ return [];
18
+ return profileObjects.filter(PO => personFields.every(([k, v]) => { var _a; return ((_a = PO.properties) === null || _a === void 0 ? void 0 : _a[k]) && (0, ramda_1.equals)(PO.properties[k], v); }));
19
+ }
20
+ exports.filterByMutualFields = filterByMutualFields;
21
+ /** @internal */
22
+ async function getFlags({ person, profileObjects, realVers, getSchema, }) {
23
+ const POsWithSameFields = filterByMutualFields(person, profileObjects);
24
+ const relevantVers = (await Promise.all(POsWithSameFields.map(async (PO) => {
25
+ const schemaName = (0, schema_1.findSchemaLabel)(PO.labels);
26
+ const schema = await getSchema(schemaName);
27
+ return Object.assign({ nId: PO.n_id }, (0, getPOVerification_1.getPOVerification)({
28
+ schema,
29
+ PO,
30
+ realVers,
31
+ }));
32
+ })))
33
+ .filter(v => v.status === types_1.POVerification.FullyVerified)
34
+ .flatMap(v => v.details.verifiers.map(verProvider => realVers.find(ver => ver.belongsToNId === v.nId &&
35
+ ver.provider.dataSourceNId === verProvider.dataSourceNId)))
36
+ .filter((x) => !!x);
37
+ // in case there are somehow duplicates (see #922)
38
+ return (0, ramda_1.uniqBy)(x => x.nID, relevantVers)
39
+ .filter(ver => { var _a; return (_a = ver.metadata) === null || _a === void 0 ? void 0 : _a.safeHarbourScore; })
40
+ .reduce((ac, ver) => {
41
+ var _a;
42
+ const key = ver.metadata.safeHarbourScore;
43
+ if ((_a = ac[key]) === null || _a === void 0 ? void 0 : _a.includes(ver.xId))
44
+ return ac;
45
+ return Object.assign(Object.assign({}, ac), { [key]: [...(ac[key] || []), ver.xId] });
46
+ }, {});
47
+ }
48
+ exports.getFlags = getFlags;
49
+ /** @internal */
50
+ function safeHarbourRequirementsMet(flags) {
51
+ const { M1 = 0, M2 = 0, N1 = 0 } = (0, ramda_1.mapObjIndexed)(xIds => xIds.length, flags);
52
+ // see https://bit.ly/2KKo4rF
53
+ const isSafe = M1 >= 2 ||
54
+ (M1 >= 1 && M2 >= 1) ||
55
+ (M1 >= 1 && N1 >= 1) ||
56
+ (M2 >= 1 && N1 >= 1);
57
+ return { isSafe, flags };
58
+ }
59
+ exports.safeHarbourRequirementsMet = safeHarbourRequirementsMet;
60
+ /**
61
+ * The Safe Harbour Score indidicates whether a person's identity has been verified
62
+ * to the extent requried for Safe Harbour Compliance. This requires multiple verifications
63
+ * from different sources. For information, refer to the
64
+ * {@link https://dev-docs.rayt.io/docs/features/pep-checks Raytio Documentation}.
65
+ */
66
+ const calcSafeHarbourScore = (data) => getFlags(data).then(safeHarbourRequirementsMet);
67
+ exports.calcSafeHarbourScore = calcSafeHarbourScore;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __1 = require("..");
4
+ const operations_1 = require("../operations");
5
+ jest.mock("../operations");
6
+ /**
7
+ * in this test case:
8
+ * - there are valid verifications for fName=Max and fName=Erika, but we don't which
9
+ * verification corresponds to which value.
10
+ * - there is an invalid verification (tampered with) for lName=Mustermann
11
+ * - there are verifications for non-existant POs and fields, which will be skipped
12
+ *
13
+ * Also note:
14
+ * - the verification for fName=Max is expired
15
+ * - the verification for fName=Erika is "VerifiedFalse"
16
+ */
17
+ describe("getOwnRealVerifications", () => {
18
+ beforeAll(() => {
19
+ operations_1.checkOwnVerification.mockImplementation(async ({ signature }) => {
20
+ if (signature === "signatureForLastNameMustermannFromN2")
21
+ return false;
22
+ return true;
23
+ });
24
+ });
25
+ it("calls the verifyCheck function for each PO, keeping only the valid ones", async () => {
26
+ const profileObjects = [
27
+ { n_id: "n1", properties: { fName: "Max", lName: "Mustermann" } },
28
+ { n_id: "n2", properties: { fName: "Erika", lName: "Mustermann" } },
29
+ ];
30
+ const verifications = [
31
+ {
32
+ n_id: "nv1",
33
+ properties: {
34
+ valid_until: "2020-08-28T23:12:35.678Z",
35
+ verifications: [
36
+ {
37
+ signature: "signatureForFirstNameMax",
38
+ data: {
39
+ field: "fName",
40
+ verifier_source_id: "Ministry of pike river mine re-entry",
41
+ verifier_service_id: "Minister for pike river re-entry",
42
+ verifier_id: "v1",
43
+ verification_date: "2020-08-28T23:11:20.592912",
44
+ request_div: "x1",
45
+ passed: true,
46
+ source_n_id: "n1",
47
+ },
48
+ },
49
+ ],
50
+ },
51
+ },
52
+ {
53
+ n_id: "nv2",
54
+ properties: {
55
+ verifications: [
56
+ {
57
+ signature: "signatureForFirstNameErika",
58
+ data: {
59
+ field: "fName",
60
+ verifier_source_id: "Ministry of pike river mine re-entry",
61
+ verifier_service_id: "Minister for pike river re-entry",
62
+ verifier_id: "v1",
63
+ verification_date: "2020-08-28T23:11:20.592912",
64
+ request_div: "x2",
65
+ passed: false,
66
+ source_n_id: "n2",
67
+ },
68
+ },
69
+ ],
70
+ },
71
+ },
72
+ {
73
+ n_id: "nv3",
74
+ properties: {
75
+ verifications: [
76
+ {
77
+ signature: "signatureForLastNameMustermannFromN2",
78
+ data: {
79
+ field: "lName",
80
+ verifier_source_id: "Ministry of pike river mine re-entry",
81
+ verifier_service_id: "Minister for pike river re-entry",
82
+ verifier_id: "v1",
83
+ verification_date: "2020-08-28T23:11:20.592912",
84
+ request_div: "x3",
85
+ passed: false,
86
+ source_n_id: "n2", // this ver was for lName=Mustermann in n2, so doesn't apply to lName=Mustermann in n1 !
87
+ },
88
+ },
89
+ ],
90
+ },
91
+ },
92
+ {
93
+ n_id: "nv4",
94
+ properties: {
95
+ verifications: [{ data: { source_n_id: "doesn't exist" } }],
96
+ },
97
+ },
98
+ {
99
+ n_id: "nv5",
100
+ properties: {
101
+ verifications: [
102
+ { data: { source_n_id: "n2", field: "doesn't exist" } },
103
+ ],
104
+ },
105
+ },
106
+ ];
107
+ const realVers = await (0, __1.getOwnRealVerifications)({
108
+ profileObjects,
109
+ verifications,
110
+ userId: "geesepolice2002",
111
+ });
112
+ expect(operations_1.checkOwnVerification).toHaveBeenCalledTimes(3);
113
+ // 3 times, not 5. Because this new method doesn't need to build a big matrix of possible combinations
114
+ expect(realVers).toStrictEqual([
115
+ {
116
+ fieldName: "fName",
117
+ value: "Max",
118
+ belongsToNId: "n1",
119
+ nID: "nv1",
120
+ expired: new Date("2020-08-28T23:12:35.678Z"),
121
+ metadata: undefined,
122
+ provider: {
123
+ dataSourceNId: "Ministry of pike river mine re-entry",
124
+ date: new Date("2020-08-28T23:11:20.592Z"),
125
+ serviceProviderNId: "Minister for pike river re-entry",
126
+ verifierNId: "v1",
127
+ },
128
+ signature: "signatureForFirstNameMax",
129
+ verified: true,
130
+ xId: "x1",
131
+ },
132
+ {
133
+ fieldName: "fName",
134
+ value: "Erika",
135
+ belongsToNId: "n2",
136
+ nID: "nv2",
137
+ expired: false,
138
+ metadata: undefined,
139
+ provider: {
140
+ dataSourceNId: "Ministry of pike river mine re-entry",
141
+ date: new Date("2020-08-28T23:11:20.592Z"),
142
+ serviceProviderNId: "Minister for pike river re-entry",
143
+ verifierNId: "v1",
144
+ },
145
+ signature: "signatureForFirstNameErika",
146
+ verified: false,
147
+ xId: "x2",
148
+ },
149
+ // note how lastName is not included since it's invalid
150
+ ]);
151
+ });
152
+ });
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getSomeoneElsesRealVerifications_1 = require("../getSomeoneElsesRealVerifications");
4
+ const operations_1 = require("../operations");
5
+ jest.mock("../operations");
6
+ const checkVerificationsResp = [
7
+ {
8
+ verified: false,
9
+ signature: "sig2",
10
+ data: {
11
+ field: "a",
12
+ value: 1,
13
+ verifier_source_id: "verifier_source_id",
14
+ verifier_service_id: "verifier_service_id",
15
+ verifier_id: "verifier_id",
16
+ date: "date",
17
+ request_div: "request_div",
18
+ passed: "passed",
19
+ source_n_id: "source_n_id",
20
+ verification_date: "2003-05-18T11:22:33.456790",
21
+ },
22
+ n_id: "my_field",
23
+ },
24
+ {
25
+ verified: true,
26
+ signature: "sig",
27
+ data: {
28
+ field: "email_address",
29
+ value: "jean@example.com",
30
+ verifier_source_id: "verifier_source_id",
31
+ verifier_service_id: "verifier_service_id",
32
+ verifier_id: "verifier_id",
33
+ date: "date",
34
+ request_div: "request_div",
35
+ passed: "passed",
36
+ source_n_id: "source_n_id",
37
+ verification_date: "2020-08-28T23:11:20.592912",
38
+ metadata: {
39
+ status: "pending",
40
+ send_code_attempts: [
41
+ {
42
+ channel: "email",
43
+ time: "2020-08-28T23:11:24.157Z",
44
+ channel_id: "abc",
45
+ },
46
+ ],
47
+ },
48
+ },
49
+ n_id: "my_email",
50
+ },
51
+ ];
52
+ const profileObjects = [
53
+ { properties: { a: 1 } },
54
+ { properties: { email_address: "jean@example.com" } },
55
+ {
56
+ properties: {
57
+ my_photo: {
58
+ content: "...",
59
+ content_type: "...",
60
+ n_id: "n_id_of_my_ss_File",
61
+ },
62
+ },
63
+ },
64
+ ];
65
+ const verifications = [
66
+ {
67
+ n_id: "my_email",
68
+ properties: {
69
+ verifications: [
70
+ {
71
+ data: {
72
+ source: "EMAIL_ADDRESS",
73
+ passed: false,
74
+ request_div: "140c20e3-5146-4123-8e75-fe9064a6b71f",
75
+ source_n_id: "3ec48392-4211-4c6a-92f9-50031f0f5716",
76
+ verifier_source_id: "d796a383-5622-4e05-93b2-2fbe292d76fa",
77
+ metadata: {
78
+ url: "https://verify.twilio.com/v2/Services/VAa447486967ee88c1f59e2896f617f981/Verifications/VE398de58af34b4ef22fa24a404f30898d",
79
+ send_code_attempts: [
80
+ {
81
+ channel: "email",
82
+ time: "2020-08-28T23:11:24.157Z",
83
+ channel_id: "pCmrKC4qQBSC_3m3crMctA",
84
+ },
85
+ ],
86
+ status: "pending",
87
+ id: "VE398de58af34b4ef22fa24a404f30898d",
88
+ },
89
+ verifier_id: "d796a383-5622-4e05-93b2-2fbe292d76fa",
90
+ field: "email_address",
91
+ verifier_div: "7137da93-0a53-4de7-b6df-3aa4b2b8d5e6",
92
+ v_id: "d6c5246c-1141-4d0a-929f-1ed0aa00b52d",
93
+ verification_date: "2020-08-28T23:11:20.592912",
94
+ valid_until: "2020-08-28T23:12:35.678Z",
95
+ },
96
+ signature: "abcdefghijklmopqrstuvwxyz",
97
+ },
98
+ ],
99
+ field: "email_address",
100
+ initiator_n_id: "3ec48392-4211-4c6a-92f9-50031f0f5716",
101
+ n_id: "my_email",
102
+ },
103
+ labels: ["ss_Verification", "ProfileObject"],
104
+ referenceList: {},
105
+ },
106
+ {
107
+ n_id: "my_photo",
108
+ properties: {
109
+ verifications: [
110
+ {
111
+ data: {
112
+ passed: false,
113
+ request_div: "a",
114
+ source_n_id: "b",
115
+ verifier_source_id: "c",
116
+ verifier_id: "d",
117
+ field: "my_photo",
118
+ verifier_div: "e",
119
+ v_id: "f",
120
+ verification_date: "2020-12-05T11:22:33.456789",
121
+ valid_until: "2020-08-28T23:12:35.678Z",
122
+ },
123
+ signature: "abcdefghijklmopqrstuvwxyz",
124
+ },
125
+ ],
126
+ field: "my_photo",
127
+ initiator_n_id: "3ec48392-4211-4c6a-92f9-50031f0f5716",
128
+ n_id: "my_photo",
129
+ },
130
+ labels: ["ss_Verification", "ProfileObject"],
131
+ referenceList: {},
132
+ },
133
+ ];
134
+ describe("getSomeoneElsesRealVerifications", () => {
135
+ beforeEach(() => {
136
+ jest.resetAllMocks();
137
+ operations_1.checkSomeoneElsesVerifications.mockResolvedValue(checkVerificationsResp);
138
+ });
139
+ it("returns an empty array if provided nothing", async () => {
140
+ const result = await (0, getSomeoneElsesRealVerifications_1.getSomeoneElsesRealVerifications)({
141
+ apiUrl: "https://example.com",
142
+ profileObjects: [],
143
+ verifications: [],
144
+ });
145
+ expect(result).toStrictEqual([]);
146
+ expect(operations_1.checkSomeoneElsesVerifications).not.toHaveBeenCalled();
147
+ });
148
+ it("processes the user's verifications correctly", async () => {
149
+ const result = await (0, getSomeoneElsesRealVerifications_1.getSomeoneElsesRealVerifications)({
150
+ apiUrl: "https://example.com",
151
+ profileObjects,
152
+ verifications,
153
+ });
154
+ expect(result).toStrictEqual([
155
+ {
156
+ belongsToNId: "source_n_id",
157
+ expired: false,
158
+ fieldName: "email_address",
159
+ metadata: {
160
+ send_code_attempts: [
161
+ {
162
+ channel: "email",
163
+ channel_id: "abc",
164
+ time: "2020-08-28T23:11:24.157Z",
165
+ },
166
+ ],
167
+ status: "pending",
168
+ },
169
+ nID: "my_email",
170
+ provider: {
171
+ dataSourceNId: "verifier_source_id",
172
+ date: new Date("2020-08-28T23:11:20.592912Z"),
173
+ serviceProviderNId: "verifier_service_id",
174
+ verifierNId: "verifier_id",
175
+ },
176
+ signature: "sig",
177
+ value: "jean@example.com",
178
+ verified: "passed",
179
+ xId: "request_div",
180
+ },
181
+ ]);
182
+ expect(operations_1.checkSomeoneElsesVerifications).toHaveBeenCalledTimes(1);
183
+ expect(operations_1.checkSomeoneElsesVerifications).toHaveBeenNthCalledWith(1, {
184
+ apiUrl: "https://example.com",
185
+ controller: undefined,
186
+ toVerify: [
187
+ {
188
+ verifications: [
189
+ { n_id: "my_email", signature: "abcdefghijklmopqrstuvwxyz" },
190
+ ],
191
+ data_to_verify: [{ value: "jean@example.com" }],
192
+ },
193
+ {
194
+ verifications: [
195
+ { n_id: "my_photo", signature: "abcdefghijklmopqrstuvwxyz" },
196
+ ],
197
+ data_to_verify: [
198
+ // note how it re-created the $reference
199
+ { value: { $ref: "urn:profile_object:n_id_of_my_ss_File" } },
200
+ ],
201
+ },
202
+ ],
203
+ });
204
+ });
205
+ });
@@ -1,13 +1,13 @@
1
- import { ProfileObject, Verification, RealVer, UId } from "@raytio/types";
2
- /**
3
- * Given a list of verifications and decrypted profile objects, this function
4
- * locally verifies the credibility of the signatures in the verifications.
5
- *
6
- * This function does NOT call the API, except to fetch the public key.
7
- * @returns a list of authentic RealVer
8
- */
9
- export declare const getOwnRealVerifications: ({ verifications, profileObjects, userId, }: {
10
- verifications: Verification[];
11
- profileObjects: ProfileObject[];
12
- userId: UId;
13
- }) => Promise<RealVer[]>;
1
+ import { ProfileObject, Verification, RealVer, UId } from "@raytio/types";
2
+ /**
3
+ * Given a list of verifications and decrypted profile objects, this function
4
+ * locally verifies the credibility of the signatures in the verifications.
5
+ *
6
+ * This function does NOT call the API, except to fetch the public key.
7
+ * @returns a list of authentic RealVer
8
+ */
9
+ export declare const getOwnRealVerifications: ({ verifications, profileObjects, userId, }: {
10
+ verifications: Verification[];
11
+ profileObjects: ProfileObject[];
12
+ userId: UId;
13
+ }) => Promise<RealVer[]>;