@raytio/core 10.0.1 → 10.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 (145) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +35 -2
  3. package/dist/accessApplication/createAA.d.ts +17 -17
  4. package/dist/accessApplication/createAA.js +71 -71
  5. package/dist/accessApplication/index.d.ts +1 -1
  6. package/dist/accessApplication/index.js +17 -17
  7. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  8. package/dist/crypto/cognitoAttributes.js +33 -33
  9. package/dist/crypto/decryptKeys.d.ts +1 -1
  10. package/dist/crypto/decryptKeys.js +33 -33
  11. package/dist/crypto/decryptSharedData.d.ts +26 -26
  12. package/dist/crypto/decryptSharedData.js +38 -38
  13. package/dist/crypto/getAADecryptor.d.ts +16 -11
  14. package/dist/crypto/getAADecryptor.js +20 -20
  15. package/dist/crypto/helpers.d.ts +18 -18
  16. package/dist/crypto/helpers.js +26 -26
  17. package/dist/crypto/index.d.ts +4 -4
  18. package/dist/crypto/index.js +21 -21
  19. package/dist/general/conditional.d.ts +17 -7
  20. package/dist/general/conditional.js +32 -22
  21. package/dist/general/date.d.ts +2 -0
  22. package/dist/general/date.js +18 -0
  23. package/dist/general/index.d.ts +4 -3
  24. package/dist/general/index.js +20 -19
  25. package/dist/general/password.d.ts +10 -10
  26. package/dist/general/password.js +31 -31
  27. package/dist/general/types.d.ts +6 -6
  28. package/dist/general/types.js +13 -13
  29. package/dist/index.d.ts +6 -6
  30. package/dist/index.js +22 -22
  31. package/dist/rules/calculateScore.d.ts +23 -23
  32. package/dist/rules/calculateScore.js +76 -76
  33. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  34. package/dist/rules/convertInstanceToRuleInput.js +139 -139
  35. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  36. package/dist/rules/evaluateScoreCondition.js +45 -45
  37. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  38. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  39. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
  40. package/dist/rules/helpers/checkTypeofValue.js +55 -55
  41. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  42. package/dist/rules/helpers/getLhsTypeofValue.js +1 -0
  43. package/dist/rules/helpers/getValueFromPath.d.ts +2 -0
  44. package/dist/rules/helpers/getValueFromPath.js +35 -0
  45. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  46. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  47. package/dist/rules/helpers/index.d.ts +5 -5
  48. package/dist/rules/helpers/index.js +21 -21
  49. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +3 -0
  50. package/dist/rules/helpers/rebuildInfiniteValues.js +6 -0
  51. package/dist/rules/helpers/symbols.d.ts +2 -2
  52. package/dist/rules/helpers/symbols.js +5 -5
  53. package/dist/rules/helpers/thresholds.d.ts +5 -5
  54. package/dist/rules/helpers/thresholds.js +47 -47
  55. package/dist/rules/index.d.ts +7 -7
  56. package/dist/rules/index.js +25 -25
  57. package/dist/rules/isScoreResultValid.d.ts +2 -0
  58. package/dist/rules/isScoreResultValid.js +9 -0
  59. package/dist/rules/operators/array.d.ts +2 -0
  60. package/dist/rules/operators/array.js +74 -0
  61. package/dist/rules/operators/bool.d.ts +2 -2
  62. package/dist/rules/operators/bool.js +17 -17
  63. package/dist/rules/operators/date.d.ts +2 -2
  64. package/dist/rules/operators/date.js +91 -91
  65. package/dist/rules/operators/hfield.d.ts +2 -2
  66. package/dist/rules/operators/hfield.js +33 -33
  67. package/dist/rules/operators/hschema.d.ts +2 -2
  68. package/dist/rules/operators/hschema.js +21 -21
  69. package/dist/rules/operators/index.d.ts +3 -3
  70. package/dist/rules/operators/index.js +11 -11
  71. package/dist/rules/operators/number.d.ts +2 -2
  72. package/dist/rules/operators/number.js +41 -41
  73. package/dist/rules/operators/string.d.ts +2 -2
  74. package/dist/rules/operators/string.js +58 -58
  75. package/dist/rules/types/config.d.ts +91 -91
  76. package/dist/rules/types/config.js +2 -2
  77. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  78. package/dist/rules/types/dataValueTypes.js +4 -4
  79. package/dist/rules/types/index.d.ts +3 -3
  80. package/dist/rules/types/index.js +19 -19
  81. package/dist/rules/types/internal.d.ts +20 -20
  82. package/dist/rules/types/internal.js +2 -2
  83. package/dist/rules/types/operators.d.ts +19 -0
  84. package/dist/rules/types/operators.js +2 -0
  85. package/dist/rules/types/score.d.ts +50 -0
  86. package/dist/rules/types/score.js +2 -0
  87. package/dist/rules/validate.d.ts +6 -6
  88. package/dist/rules/validate.js +14 -14
  89. package/dist/rules/version.d.ts +1 -1
  90. package/dist/rules/version.js +5 -5
  91. package/dist/schema/index.d.ts +1 -1
  92. package/dist/schema/index.js +17 -17
  93. package/dist/schema/labels.d.ts +2 -2
  94. package/dist/schema/labels.js +20 -20
  95. package/dist/util/canonicalJsonify.d.ts +1 -1
  96. package/dist/util/canonicalJsonify.js +50 -50
  97. package/dist/util/conditional.d.ts +7 -0
  98. package/dist/util/conditional.js +15 -0
  99. package/dist/util/handleResponse.d.ts +1 -1
  100. package/dist/util/handleResponse.js +21 -21
  101. package/dist/util/hash.d.ts +1 -0
  102. package/dist/util/hash.js +11 -0
  103. package/dist/util/index.d.ts +2 -2
  104. package/dist/util/index.js +18 -18
  105. package/dist/verifications/checkSingleVerification.d.ts +9 -0
  106. package/dist/verifications/checkSingleVerification.js +29 -0
  107. package/dist/verifications/checkVerifications.d.ts +1 -0
  108. package/dist/verifications/checkVerifications.js +16 -0
  109. package/dist/verifications/checkVerificationsNew.d.ts +1 -0
  110. package/dist/verifications/checkVerificationsNew.js +16 -0
  111. package/dist/verifications/cleanInstance.d.ts +9 -9
  112. package/dist/verifications/cleanInstance.js +15 -15
  113. package/dist/verifications/getOwnRealVerifications.d.ts +14 -0
  114. package/dist/verifications/getOwnRealVerifications.js +64 -0
  115. package/dist/verifications/getPOVerification.d.ts +16 -16
  116. package/dist/verifications/getPOVerification.js +94 -94
  117. package/dist/verifications/getRealVerifications.d.ts +22 -0
  118. package/dist/verifications/getRealVerifications.js +71 -0
  119. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  120. package/dist/verifications/getVerifiedBy.js +19 -19
  121. package/dist/verifications/index.d.ts +5 -5
  122. package/dist/verifications/index.js +21 -21
  123. package/dist/verifications/maybeRereference.d.ts +1 -1
  124. package/dist/verifications/maybeRereference.js +10 -10
  125. package/dist/verifications/safeHarbour.d.ts +20 -20
  126. package/dist/verifications/safeHarbour.js +74 -74
  127. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  128. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +64 -63
  129. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  130. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -71
  131. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  132. package/dist/verifications/verifyCheck/index.js +21 -21
  133. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  134. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  135. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  136. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  137. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  138. package/dist/verifications/verifyCheck/operations/index.js +18 -18
  139. package/dist/verifications/verifyCheck/util/canonicalJsonify.d.ts +1 -0
  140. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +48 -0
  141. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +2 -0
  142. package/dist/verifications/verifyCheck/util/getValuesForAField.js +9 -0
  143. package/dist/verifications/verifyCheck/util/index.d.ts +2 -0
  144. package/dist/verifications/verifyCheck/util/index.js +14 -0
  145. package/package.json +4 -4
@@ -1,94 +1,94 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPOVerification = void 0;
4
- const ramda_1 = require("ramda");
5
- const types_1 = require("@raytio/types");
6
- const crypto_1 = require("../crypto");
7
- const getVerifiedBy_1 = require("./getVerifiedBy");
8
- const maybeRereference_1 = require("./maybeRereference");
9
- const general_1 = require("../general");
10
- const schema_1 = require("../schema");
11
- /**
12
- * Determines the verification status of a profile object, and its individual fields.
13
- */
14
- function getPOVerification({ PO, schema, realVers, }) {
15
- var _a, _b;
16
- // safe guard to avoid a misleading response from this function
17
- const schemaName = PO.schema || (0, schema_1.findSchemaLabel)(PO.labels);
18
- if (schema.name !== schemaName) {
19
- throw new Error(`Wrong schema supplied to getPOVerification: ${schema.name} != ${schemaName}`);
20
- }
21
- const someAreEncrypted = !!(0, crypto_1.someEncrypted)(PO.properties);
22
- if (someAreEncrypted) {
23
- return {
24
- status: types_1.POVerification.Encrypted,
25
- details: { sourceNId: PO.n_id, verifiers: [] },
26
- fieldVerifications: {},
27
- };
28
- }
29
- // if a subObject is supplied, properties might not be an object.
30
- // In which case this PO is definitely not verified
31
- const shouldBeVerifiedProps = PO.properties instanceof Object
32
- ? (0, ramda_1.pick)(
33
- // 📛 part1: this is the straightforward case, we pick the fields that are always verifiable
34
- ((_a = schema.verified_fields) === null || _a === void 0 ? void 0 : _a.filter((x) => typeof x === "string")) || [], PO.properties)
35
- : {};
36
- // 📛 part2: some fields may be conditionally verifiable. if so, and the condition is true, add them to shouldBeVerifiedProps
37
- ((_b = schema.verified_fields) !== null && _b !== void 0 ? _b : [])
38
- .filter((x) => typeof x !== "string" && (0, general_1.isConditionMet)(x.if, PO.properties))
39
- .forEach(x => {
40
- // eslint-disable-next-line fp/no-mutation
41
- shouldBeVerifiedProps[x.field] = PO.properties[x.field];
42
- });
43
- const fieldVerifications = (0, ramda_1.mapObjIndexed)((content, fieldName) => {
44
- const pertainingVers = realVers.filter(x => x.fieldName === fieldName &&
45
- // using ramda's `equals` because this needs to work for objects/arrays
46
- (0, ramda_1.equals)((0, maybeRereference_1.maybeRereference)(x.value), (0, maybeRereference_1.maybeRereference)(content)) &&
47
- // if an nId is supplied, also filter out verifications that don't relate to that n_id
48
- (PO.n_id ? x.belongsToNId === PO.n_id : true));
49
- // .every() illogically returns true for arrays with zero length
50
- if (pertainingVers.length && pertainingVers.every(x => x.expired)) {
51
- return types_1.FieldVerification.Expired;
52
- }
53
- if (pertainingVers.some(x => !x.verified)) {
54
- return types_1.FieldVerification.VerifiedFalse;
55
- }
56
- return pertainingVers.length
57
- ? types_1.FieldVerification.Verified
58
- : types_1.FieldVerification.NotVerified;
59
- }, shouldBeVerifiedProps);
60
- const status = (() => {
61
- if (!Object.values(shouldBeVerifiedProps).length) {
62
- return types_1.POVerification.NotVerified;
63
- }
64
- const allExpired = Object.values(fieldVerifications).every(x => x === types_1.FieldVerification.Expired);
65
- if (allExpired)
66
- return types_1.POVerification.Expired;
67
- const anyVerfiedFalse = Object.values(fieldVerifications).some(x => x === types_1.FieldVerification.VerifiedFalse);
68
- if (anyVerfiedFalse)
69
- return types_1.POVerification.VerifiedFalse;
70
- const allVerified = Object.values(fieldVerifications).every(x => x === types_1.FieldVerification.Verified);
71
- if (allVerified)
72
- return types_1.POVerification.FullyVerified;
73
- const anyVerified = Object.values(fieldVerifications).some(x => x === types_1.FieldVerification.Verified);
74
- if (anyVerified)
75
- return types_1.POVerification.PartiallyVerified;
76
- const noneVerified = Object.values(fieldVerifications).every(x => x === types_1.FieldVerification.NotVerified);
77
- if (noneVerified)
78
- return types_1.POVerification.NotVerified;
79
- // can't happen, but just in case the logic above fails
80
- /* istanbul ignore next */
81
- return types_1.POVerification.NotVerified;
82
- })();
83
- const verifiers = (0, getVerifiedBy_1.getVerifiedBy)({
84
- nId: PO.n_id,
85
- realVers,
86
- shouldBeVerifiedProps,
87
- });
88
- return {
89
- status,
90
- details: { sourceNId: PO.n_id, verifiers },
91
- fieldVerifications,
92
- };
93
- }
94
- exports.getPOVerification = getPOVerification;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPOVerification = void 0;
4
+ const ramda_1 = require("ramda");
5
+ const types_1 = require("@raytio/types");
6
+ const crypto_1 = require("../crypto");
7
+ const getVerifiedBy_1 = require("./getVerifiedBy");
8
+ const maybeRereference_1 = require("./maybeRereference");
9
+ const general_1 = require("../general");
10
+ const schema_1 = require("../schema");
11
+ /**
12
+ * Determines the verification status of a profile object, and its individual fields.
13
+ */
14
+ function getPOVerification({ PO, schema, realVers, }) {
15
+ var _a, _b;
16
+ // safe guard to avoid a misleading response from this function
17
+ const schemaName = PO.schema || (0, schema_1.findSchemaLabel)(PO.labels);
18
+ if (schema.name !== schemaName) {
19
+ throw new Error(`Wrong schema supplied to getPOVerification: ${schema.name} != ${schemaName}`);
20
+ }
21
+ const someAreEncrypted = !!(0, crypto_1.someEncrypted)(PO.properties);
22
+ if (someAreEncrypted) {
23
+ return {
24
+ status: types_1.POVerification.Encrypted,
25
+ details: { sourceNId: PO.n_id, verifiers: [] },
26
+ fieldVerifications: {},
27
+ };
28
+ }
29
+ // if a subObject is supplied, properties might not be an object.
30
+ // In which case this PO is definitely not verified
31
+ const shouldBeVerifiedProps = PO.properties instanceof Object
32
+ ? (0, ramda_1.pick)(
33
+ // 📛 part1: this is the straightforward case, we pick the fields that are always verifiable
34
+ ((_a = schema.verified_fields) === null || _a === void 0 ? void 0 : _a.filter((x) => typeof x === "string")) || [], PO.properties)
35
+ : {};
36
+ // 📛 part2: some fields may be conditionally verifiable. if so, and the condition is true, add them to shouldBeVerifiedProps
37
+ ((_b = schema.verified_fields) !== null && _b !== void 0 ? _b : [])
38
+ .filter((x) => typeof x !== "string" && (0, general_1.isConditionMet)(x.if, PO.properties))
39
+ .forEach(x => {
40
+ // eslint-disable-next-line fp/no-mutation
41
+ shouldBeVerifiedProps[x.field] = PO.properties[x.field];
42
+ });
43
+ const fieldVerifications = (0, ramda_1.mapObjIndexed)((content, fieldName) => {
44
+ const pertainingVers = realVers.filter(x => x.fieldName === fieldName &&
45
+ // using ramda's `equals` because this needs to work for objects/arrays
46
+ (0, ramda_1.equals)((0, maybeRereference_1.maybeRereference)(x.value), (0, maybeRereference_1.maybeRereference)(content)) &&
47
+ // if an nId is supplied, also filter out verifications that don't relate to that n_id
48
+ (PO.n_id ? x.belongsToNId === PO.n_id : true));
49
+ // .every() illogically returns true for arrays with zero length
50
+ if (pertainingVers.length && pertainingVers.every(x => x.expired)) {
51
+ return types_1.FieldVerification.Expired;
52
+ }
53
+ if (pertainingVers.some(x => !x.verified)) {
54
+ return types_1.FieldVerification.VerifiedFalse;
55
+ }
56
+ return pertainingVers.length
57
+ ? types_1.FieldVerification.Verified
58
+ : types_1.FieldVerification.NotVerified;
59
+ }, shouldBeVerifiedProps);
60
+ const status = (() => {
61
+ if (!Object.values(shouldBeVerifiedProps).length) {
62
+ return types_1.POVerification.NotVerified;
63
+ }
64
+ const allExpired = Object.values(fieldVerifications).every(x => x === types_1.FieldVerification.Expired);
65
+ if (allExpired)
66
+ return types_1.POVerification.Expired;
67
+ const anyVerfiedFalse = Object.values(fieldVerifications).some(x => x === types_1.FieldVerification.VerifiedFalse);
68
+ if (anyVerfiedFalse)
69
+ return types_1.POVerification.VerifiedFalse;
70
+ const allVerified = Object.values(fieldVerifications).every(x => x === types_1.FieldVerification.Verified);
71
+ if (allVerified)
72
+ return types_1.POVerification.FullyVerified;
73
+ const anyVerified = Object.values(fieldVerifications).some(x => x === types_1.FieldVerification.Verified);
74
+ if (anyVerified)
75
+ return types_1.POVerification.PartiallyVerified;
76
+ const noneVerified = Object.values(fieldVerifications).every(x => x === types_1.FieldVerification.NotVerified);
77
+ if (noneVerified)
78
+ return types_1.POVerification.NotVerified;
79
+ // can't happen, but just in case the logic above fails
80
+ /* istanbul ignore next */
81
+ return types_1.POVerification.NotVerified;
82
+ })();
83
+ const verifiers = (0, getVerifiedBy_1.getVerifiedBy)({
84
+ nId: PO.n_id,
85
+ realVers,
86
+ shouldBeVerifiedProps,
87
+ });
88
+ return {
89
+ status,
90
+ details: { sourceNId: PO.n_id, verifiers },
91
+ fieldVerifications,
92
+ };
93
+ }
94
+ exports.getPOVerification = getPOVerification;
@@ -0,0 +1,22 @@
1
+ import { ProfileObject, Verification, RealVer } from "@raytio/types";
2
+ declare type Props = {
3
+ apiUrl: string;
4
+ verifications: Verification[];
5
+ profileObjects: ProfileObject[];
6
+ controller?: AbortController;
7
+ /**
8
+ * do NOT use this option. If the value of a field
9
+ * equals the value of this prop, that field will be treated
10
+ * as verified, even if the API says it's not verified. See
11
+ * #614 for context. @deprecated
12
+ */
13
+ UNSAFE_treatNoValueAsVerified?: string;
14
+ };
15
+ /**
16
+ * Given a list of verifications and decrypted profile objects, this function calls
17
+ * the Raytio API to verify the credibility of these verifications, returning only valid
18
+ * verifications.
19
+ * @returns a list of fileNames/values that are verified.
20
+ */
21
+ export declare const getRealVerifications: ({ apiUrl, verifications, profileObjects, controller, UNSAFE_treatNoValueAsVerified, }: Props) => Promise<RealVer[]>;
22
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRealVerifications = void 0;
4
+ const ramda_1 = require("ramda");
5
+ const crypto_1 = require("../crypto");
6
+ const checkVerifications_1 = require("./checkVerifications");
7
+ const maybeRereference_1 = require("./maybeRereference");
8
+ const getValuesForAField = (fieldName, POs) => (0, ramda_1.uniq)(
9
+ // truthy only, and ignore encrypted properties. this function will be called again once they're decrypted
10
+ POs.map(x => { var _a; return (_a = x.properties) === null || _a === void 0 ? void 0 : _a[fieldName]; }).filter(x => !!x && !(0, crypto_1.isEncrypted)(x)));
11
+ /**
12
+ * Given a list of verifications and decrypted profile objects, this function calls
13
+ * the Raytio API to verify the credibility of these verifications, returning only valid
14
+ * verifications.
15
+ * @returns a list of fileNames/values that are verified.
16
+ */
17
+ const getRealVerifications = async ({ apiUrl, verifications, profileObjects, controller, UNSAFE_treatNoValueAsVerified, }) => {
18
+ // for each verification (including passed: false), create a list of every possible that
19
+ // value that that verification might have been for. Flatten the list
20
+ // and send the whole thing to the API.
21
+ const toVerify = verifications.flatMap(ver => {
22
+ const values = getValuesForAField(ver.properties.field, profileObjects);
23
+ return values.flatMap(value => ver.properties.verifications.map(({ signature }) => ({
24
+ verifications: [
25
+ Object.assign({ signature }, (ver.n_id.startsWith("HASHED::")
26
+ ? {
27
+ hashed_n_id: ver.n_id.split("::")[1],
28
+ a_id: ver.n_id.split("::")[2],
29
+ }
30
+ : { n_id: ver.n_id })),
31
+ ],
32
+ data_to_verify: [{ value: (0, maybeRereference_1.maybeRereference)(value) }],
33
+ })));
34
+ });
35
+ // the API can't cope with an empty array
36
+ if (!toVerify.length)
37
+ return [];
38
+ const apiResponse = await (0, checkVerifications_1.checkVerifications)({
39
+ apiUrl,
40
+ toVerify,
41
+ controller,
42
+ });
43
+ // do NOT expose the `verified` prop from the /verify_check API to avoid semantic confusion,
44
+ // since verified: true does not mean that the verification is verified!
45
+ const realVers = apiResponse
46
+ .filter(x => x.verified ||
47
+ // if UNSAFE_treatNoValueAsVerified is enabled, and we don't know the value of this field,
48
+ // treat is as verified if the `passed` property is true (this is NOT a safe check).
49
+ (!!UNSAFE_treatNoValueAsVerified &&
50
+ x.data.value === UNSAFE_treatNoValueAsVerified &&
51
+ x.data.passed))
52
+ .map(({ signature, data, n_id: nID, valid_until }) => ({
53
+ fieldName: data.field,
54
+ value: data.value,
55
+ provider: {
56
+ dataSourceNId: data.verifier_source_id,
57
+ serviceProviderNId: data.verifier_service_id,
58
+ verifierNId: data.verifier_id,
59
+ date: new Date(`${data.verification_date}Z`), // the api returns invalid dates (missing the `Z`)
60
+ },
61
+ expired: valid_until ? new Date(valid_until) : false,
62
+ metadata: data.metadata,
63
+ xId: data.request_div,
64
+ signature,
65
+ verified: data.passed,
66
+ nID,
67
+ belongsToNId: data.source_n_id,
68
+ }));
69
+ return realVers;
70
+ };
71
+ exports.getRealVerifications = getRealVerifications;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,19 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVerifiedBy = void 0;
4
- const ramda_1 = require("ramda");
5
- const maybeRereference_1 = require("./maybeRereference");
6
- // we should probably document this
7
- /** @internal */
8
- const getVerifiedBy = ({ nId, realVers, shouldBeVerifiedProps, }) => {
9
- const mayBeVerifiedFields = Object.keys(shouldBeVerifiedProps);
10
- const pertainingVers = realVers
11
- .filter(x => mayBeVerifiedFields.includes(x.fieldName) &&
12
- // using ramda's `equals` because this needs to work for objects/arrays
13
- (0, ramda_1.equals)((0, maybeRereference_1.maybeRereference)(shouldBeVerifiedProps[x.fieldName]), (0, maybeRereference_1.maybeRereference)(x.value)) &&
14
- // if an nId is supplied, also filter out verifications that don't relate to that n_id
15
- (nId ? x.belongsToNId === nId : true))
16
- .map(x => x.provider);
17
- return (0, ramda_1.uniqBy)(x => x.dataSourceNId, pertainingVers);
18
- };
19
- exports.getVerifiedBy = getVerifiedBy;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVerifiedBy = void 0;
4
+ const ramda_1 = require("ramda");
5
+ const maybeRereference_1 = require("./maybeRereference");
6
+ // we should probably document this
7
+ /** @internal */
8
+ const getVerifiedBy = ({ nId, realVers, shouldBeVerifiedProps, }) => {
9
+ const mayBeVerifiedFields = Object.keys(shouldBeVerifiedProps);
10
+ const pertainingVers = realVers
11
+ .filter(x => mayBeVerifiedFields.includes(x.fieldName) &&
12
+ // using ramda's `equals` because this needs to work for objects/arrays
13
+ (0, ramda_1.equals)((0, maybeRereference_1.maybeRereference)(shouldBeVerifiedProps[x.fieldName]), (0, maybeRereference_1.maybeRereference)(x.value)) &&
14
+ // if an nId is supplied, also filter out verifications that don't relate to that n_id
15
+ (nId ? x.belongsToNId === nId : true))
16
+ .map(x => x.provider);
17
+ return (0, ramda_1.uniqBy)(x => x.dataSourceNId, pertainingVers);
18
+ };
19
+ exports.getVerifiedBy = getVerifiedBy;
@@ -1,5 +1,5 @@
1
- export * from "./cleanInstance";
2
- export * from "./getPOVerification";
3
- export * from "./verifyCheck";
4
- export * from "./getVerifiedBy";
5
- export * from "./safeHarbour";
1
+ export * from "./cleanInstance";
2
+ export * from "./getPOVerification";
3
+ export * from "./verifyCheck";
4
+ export * from "./getVerifiedBy";
5
+ export * from "./safeHarbour";
@@ -1,21 +1,21 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cleanInstance"), exports);
18
- __exportStar(require("./getPOVerification"), exports);
19
- __exportStar(require("./verifyCheck"), exports);
20
- __exportStar(require("./getVerifiedBy"), exports);
21
- __exportStar(require("./safeHarbour"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cleanInstance"), exports);
18
+ __exportStar(require("./getPOVerification"), exports);
19
+ __exportStar(require("./verifyCheck"), exports);
20
+ __exportStar(require("./getVerifiedBy"), exports);
21
+ __exportStar(require("./safeHarbour"), exports);
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maybeRereference = void 0;
4
- const hasNId = (value) => typeof value === "object" && !!value && "n_id" in value;
5
- /**
6
- * @internal see #578
7
- * For values that have already been dereferenced, we recreate the `$ref`.
8
- */
9
- const maybeRereference = (value) => hasNId(value) ? { $ref: `urn:profile_object:${value.n_id}` } : value;
10
- exports.maybeRereference = maybeRereference;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybeRereference = void 0;
4
+ const hasNId = (value) => typeof value === "object" && !!value && "n_id" in value;
5
+ /**
6
+ * @internal see #578
7
+ * For values that have already been dereferenced, we recreate the `$ref`.
8
+ */
9
+ const maybeRereference = (value) => hasNId(value) ? { $ref: `urn:profile_object:${value.n_id}` } : value;
10
+ exports.maybeRereference = maybeRereference;
@@ -1,20 +1,20 @@
1
- import { ProfileObject, RealVer, Schema } from "@raytio/types";
2
- /** an object listing the `xId`s for each SafeHarbourCode */
3
- export declare type SafeHarbourObj = Partial<Record<SafeHarbourCode, string[]>>;
4
- /** the response from {@link calcSafeHarbourScore} */
5
- export declare type SafeHarbourResult = {
6
- isSafe: boolean;
7
- flags: SafeHarbourObj;
8
- };
9
- /**
10
- * The Safe Harbour Score indidicates whether a person's identity has been verified
11
- * to the extent requried for Safe Harbour Compliance. This requires multiple verifications
12
- * from different sources. For information, refer to the
13
- * {@link https://dev-docs.rayt.io/docs/features/pep-checks Raytio Documentation}.
14
- */
15
- export declare const calcSafeHarbourScore: (data: {
16
- person: ProfileObject;
17
- profileObjects: ProfileObject[];
18
- realVers: RealVer[];
19
- getSchema(schemaName: string): Promise<Schema>;
20
- }) => Promise<SafeHarbourResult>;
1
+ import { ProfileObject, RealVer, Schema } from "@raytio/types";
2
+ /** an object listing the `xId`s for each SafeHarbourCode */
3
+ export declare type SafeHarbourObj = Partial<Record<SafeHarbourCode, string[]>>;
4
+ /** the response from {@link calcSafeHarbourScore} */
5
+ export declare type SafeHarbourResult = {
6
+ isSafe: boolean;
7
+ flags: SafeHarbourObj;
8
+ };
9
+ /**
10
+ * The Safe Harbour Score indidicates whether a person's identity has been verified
11
+ * to the extent requried for Safe Harbour Compliance. This requires multiple verifications
12
+ * from different sources. For information, refer to the
13
+ * {@link https://dev-docs.rayt.io/docs/features/pep-checks Raytio Documentation}.
14
+ */
15
+ export declare const calcSafeHarbourScore: (data: {
16
+ person: ProfileObject;
17
+ profileObjects: ProfileObject[];
18
+ realVers: RealVer[];
19
+ getSchema(schemaName: string): Promise<Schema>;
20
+ }) => Promise<SafeHarbourResult>;
@@ -1,74 +1,74 @@
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
+ /** @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,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[]>;