@raytio/core 8.1.2 → 9.0.2

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 (77) hide show
  1. package/README.md +482 -1
  2. package/dist/accessApplication/createAA.js +0 -1
  3. package/dist/crypto/decryptKeys.js +0 -2
  4. package/dist/crypto/helpers.d.ts +1 -1
  5. package/dist/general/index.d.ts +1 -0
  6. package/dist/general/index.js +1 -0
  7. package/dist/general/types.d.ts +6 -0
  8. package/dist/general/types.js +13 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +1 -0
  11. package/dist/rules/calculateScore.d.ts +11 -0
  12. package/dist/rules/calculateScore.js +52 -0
  13. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -0
  14. package/dist/rules/convertInstanceToRuleInput.js +139 -0
  15. package/dist/rules/evaluateScoreCondition.d.ts +2 -0
  16. package/dist/rules/evaluateScoreCondition.js +45 -0
  17. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -0
  18. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -0
  19. package/dist/rules/helpers/checkTypeofValue.d.ts +3 -0
  20. package/dist/rules/helpers/checkTypeofValue.js +43 -0
  21. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -0
  22. package/dist/rules/helpers/getValuesFromPath.js +50 -0
  23. package/dist/rules/helpers/index.d.ts +5 -0
  24. package/dist/rules/helpers/index.js +17 -0
  25. package/dist/rules/helpers/symbols.d.ts +2 -0
  26. package/dist/rules/helpers/symbols.js +5 -0
  27. package/dist/rules/helpers/thresholds.d.ts +5 -0
  28. package/dist/rules/helpers/thresholds.js +47 -0
  29. package/dist/rules/index.d.ts +6 -0
  30. package/dist/rules/index.js +20 -0
  31. package/dist/rules/operators/bool.d.ts +2 -0
  32. package/dist/rules/operators/bool.js +17 -0
  33. package/dist/rules/operators/date.d.ts +2 -0
  34. package/dist/rules/operators/date.js +91 -0
  35. package/dist/rules/operators/hfield.d.ts +2 -0
  36. package/dist/rules/operators/hfield.js +33 -0
  37. package/dist/rules/operators/hschema.d.ts +2 -0
  38. package/dist/rules/operators/hschema.js +21 -0
  39. package/dist/rules/operators/index.d.ts +3 -0
  40. package/dist/rules/operators/index.js +11 -0
  41. package/dist/rules/operators/number.d.ts +2 -0
  42. package/dist/rules/operators/number.js +41 -0
  43. package/dist/rules/operators/string.d.ts +2 -0
  44. package/dist/rules/operators/string.js +58 -0
  45. package/dist/rules/types/config.d.ts +86 -0
  46. package/dist/rules/types/config.js +2 -0
  47. package/dist/rules/types/dataValueTypes.d.ts +19 -0
  48. package/dist/rules/types/dataValueTypes.js +4 -0
  49. package/dist/rules/types/index.d.ts +3 -0
  50. package/dist/rules/types/index.js +15 -0
  51. package/dist/rules/types/internal.d.ts +20 -0
  52. package/dist/rules/types/internal.js +2 -0
  53. package/dist/{verifications/checkVerifications.d.ts → util/canonicalJsonify.d.ts} +0 -0
  54. package/dist/util/canonicalJsonify.js +48 -0
  55. package/dist/util/handleResponse.js +0 -1
  56. package/dist/util/index.d.ts +1 -0
  57. package/dist/util/index.js +1 -0
  58. package/dist/verifications/getPOVerification.d.ts +5 -2
  59. package/dist/verifications/getPOVerification.js +3 -4
  60. package/dist/verifications/index.d.ts +1 -1
  61. package/dist/verifications/index.js +1 -2
  62. package/dist/verifications/safeHarbour.d.ts +1 -1
  63. package/dist/verifications/safeHarbour.js +2 -2
  64. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -0
  65. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +63 -0
  66. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -0
  67. package/dist/verifications/{getRealVerifications.js → verifyCheck/getSomeoneElsesRealVerifications.js} +21 -19
  68. package/dist/verifications/verifyCheck/index.d.ts +3 -0
  69. package/dist/verifications/verifyCheck/index.js +17 -0
  70. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -0
  71. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -0
  72. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -0
  73. package/dist/verifications/{checkVerifications.js → verifyCheck/operations/checkSomeoneElsesVerifications.js} +4 -4
  74. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -0
  75. package/dist/verifications/verifyCheck/operations/index.js +14 -0
  76. package/package.json +8 -8
  77. package/dist/verifications/getRealVerifications.d.ts +0 -22
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.numberOperators = void 0;
4
+ exports.numberOperators = {
5
+ num_eq: {
6
+ operands: ["Number", "Number"],
7
+ implementation(n1, n2) {
8
+ return n1 === n2;
9
+ },
10
+ },
11
+ num_neq: {
12
+ operands: ["Number", "Number"],
13
+ implementation(n1, n2) {
14
+ return n1 !== n2;
15
+ },
16
+ },
17
+ num_gt_eq: {
18
+ operands: ["Number", "Number"],
19
+ implementation(n1, n2) {
20
+ return n1 >= n2;
21
+ },
22
+ },
23
+ num_lt_eq: {
24
+ operands: ["Number", "Number"],
25
+ implementation(n1, n2) {
26
+ return n1 <= n2;
27
+ },
28
+ },
29
+ num_gt: {
30
+ operands: ["Number", "Number"],
31
+ implementation(n1, n2) {
32
+ return n1 > n2;
33
+ },
34
+ },
35
+ num_lt: {
36
+ operands: ["Number", "Number"],
37
+ implementation(n1, n2) {
38
+ return n1 < n2;
39
+ },
40
+ },
41
+ };
@@ -0,0 +1,2 @@
1
+ import { OperatorID, OperatorDef } from "../types";
2
+ export declare const stringOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringOperators = void 0;
4
+ // also string operators are case-insensitive
5
+ exports.stringOperators = {
6
+ string_eq: {
7
+ operands: ["String", "String"],
8
+ implementation(s1, s2) {
9
+ return s1.toLowerCase() === s2.toLowerCase();
10
+ },
11
+ },
12
+ string_neq: {
13
+ operands: ["String", "String"],
14
+ implementation(s1, s2) {
15
+ return s1.toLowerCase() !== s2.toLowerCase();
16
+ },
17
+ },
18
+ string_contains: {
19
+ operands: ["String", "String"],
20
+ implementation(s1, s2) {
21
+ return s1.toLowerCase().includes(s2.toLowerCase());
22
+ },
23
+ },
24
+ string_ncontains: {
25
+ operands: ["String", "String"],
26
+ implementation(s1, s2) {
27
+ return !s1.toLowerCase().includes(s2.toLowerCase());
28
+ },
29
+ },
30
+ string_startsWith: {
31
+ operands: ["String", "String"],
32
+ implementation(s1, s2) {
33
+ return s1.toLowerCase().startsWith(s2.toLowerCase());
34
+ },
35
+ },
36
+ string_nstartsWith: {
37
+ operands: ["String", "String"],
38
+ implementation(s1, s2) {
39
+ return !s1.toLowerCase().startsWith(s2.toLowerCase());
40
+ },
41
+ },
42
+ string_endsWith: {
43
+ operands: ["String", "String"],
44
+ implementation(s1, s2) {
45
+ return s1.toLowerCase().endsWith(s2.toLowerCase());
46
+ },
47
+ },
48
+ string_nendsWith: {
49
+ operands: ["String", "String"],
50
+ implementation(s1, s2) {
51
+ return !s1.toLowerCase().endsWith(s2.toLowerCase());
52
+ },
53
+ },
54
+ string_regex: {
55
+ operands: ["String", "RegEx"],
56
+ implementation: (str, regEx) => !!str.match(regEx),
57
+ },
58
+ };
@@ -0,0 +1,86 @@
1
+ import { GetTSType } from "./dataValueTypes";
2
+ /**
3
+ * @ignore
4
+ * these are just IDs, the string is never parsed by anything.
5
+ *
6
+ * However, since they're saved into the WizardConfig schema,
7
+ * we can't just rename or remove any, since that would break
8
+ * existing rules.
9
+ */
10
+ export declare type OperatorID = "bool_eq" | "bool_neq" | "num_eq" | "num_neq" | "num_lt_eq" | "num_gt_eq" | "num_lt" | "num_gt" | "date_valid" | "date_invalid" | "date_before" | "date_after" | "date_eq" | "date_neq" | "date_older_than" | "date_newer_than" | "date_between" | "string_eq" | "string_neq" | "string_contains" | "string_ncontains" | "string_startsWith" | "string_nstartsWith" | "string_endsWith" | "string_nendsWith" | "string_regex" | "field_verifiedBy" | "field_shared" | "field_hasVerStatus" | "field_cameFromSchema" | "field_ncameFromSchema" | "schema_verifiedBy" | "schema_shared" | "schema_hasVerStatus";
11
+ /** @ignore */
12
+ export declare type ValuePathFieldProp = "meta" | "value" | "valueLength" | `subField|${string}`;
13
+ /** @ignore */
14
+ export declare type ValuePath = [type: "schema", schemaName: string, prop: "meta"] | [
15
+ type: "field",
16
+ schemaName: string,
17
+ fieldName: string,
18
+ prop: ValuePathFieldProp
19
+ ];
20
+ /** @ignore */
21
+ export declare type ValueRefConst<T> = {
22
+ type: "constant";
23
+ value: T;
24
+ };
25
+ /** @ignore */
26
+ export declare type ValueRefVar = {
27
+ type: "variable";
28
+ path: ValuePath;
29
+ };
30
+ /** @ignore */
31
+ export declare type ValueRef<T> = ValueRefConst<T> | ValueRefVar;
32
+ /** @ignore these are the LHS & RHS operands which come from variables (or constants) */
33
+ export declare type FieldValueTypes = "Bool" | "Number" | "String" | "Date" | "Array" | "HField" | "HSchema";
34
+ /** @ignore these are the RHS-only operands which come from constants ONLY */
35
+ export declare type ConstValueTypes = "DateUnit" | "RegEx" | "FieldVerification" | "POVerification";
36
+ /** @ignore full list of operands which come from variables OR constants */
37
+ export declare type ValueType = ConstValueTypes | FieldValueTypes;
38
+ /** @ignore */
39
+ export declare type ValueDef<T = ValueType> = {
40
+ type: T;
41
+ value: ValueRef<GetTSType<T>>;
42
+ };
43
+ /** @ignore */
44
+ export declare type ASTScoreConditionNode = {
45
+ type: "ScoreCondition";
46
+ operator: OperatorID;
47
+ values: ValueDef<ValueType>[];
48
+ };
49
+ /** @ignore */
50
+ export declare type ASTLanguageOperatorNode = {
51
+ type: "LanguageOperator";
52
+ operator: "OR" | "AND";
53
+ children: ASTNode[];
54
+ };
55
+ /** @ignore */
56
+ export declare type ASTNode = ASTLanguageOperatorNode | ASTScoreConditionNode;
57
+ /** @ignore */
58
+ export declare type ScoreRule = {
59
+ /** user defined */
60
+ name: string;
61
+ /** user defined */
62
+ description?: string;
63
+ /** must be an integer */
64
+ trueWeight: number;
65
+ /** must be an integer */
66
+ falseWeight: number;
67
+ /** must have a single root node */
68
+ tree: [ASTNode];
69
+ };
70
+ /** @ignore e.g. 0-10 is "red". We only work with integers. Comparisons use >= and <= */
71
+ export declare type ScoreThreshold = {
72
+ from: number;
73
+ to: number;
74
+ name: string;
75
+ };
76
+ /** @ignore */
77
+ export declare type Combinator = "+" | "*";
78
+ /**
79
+ * @ignore
80
+ * the big object for configuring score rules
81
+ */
82
+ export declare type ScoreConfig = {
83
+ combinator: Combinator;
84
+ scoreThresholds: ScoreThreshold[];
85
+ rules: ScoreRule[];
86
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import { FieldVerification, NId, POVerification } from "@raytio/types";
2
+ import type { HFieldSymbol, HSchemaSymbol } from "../helpers";
3
+ /** undefined if not shared */
4
+ export declare type HField = {
5
+ __typeof__: typeof HFieldSymbol;
6
+ verification: FieldVerification;
7
+ verifiedBy: readonly NId[];
8
+ /** schemaName */
9
+ cameFromSchema: string;
10
+ };
11
+ /** undefined if not shared */
12
+ export declare type HSchema = {
13
+ __typeof__: typeof HSchemaSymbol;
14
+ verification?: POVerification;
15
+ verifiedBy: readonly NId[];
16
+ };
17
+ export declare const DATE_UNITS: readonly ["ms", "s", "m", "h", "D", "M", "W", "Y"];
18
+ export declare type DateUnit = typeof DATE_UNITS[number];
19
+ export declare type GetTSType<T> = T extends "Bool" ? boolean : T extends "Number" ? number : T extends "String" ? string : T extends "Date" ? Date : T extends "Array" ? unknown[] : T extends "HField" ? HField : T extends "HSchema" ? HSchema : T extends "DateUnit" ? DateUnit : T extends "RegEx" ? RegExp : T extends "FieldVerification" ? FieldVerification : T extends "POVerification" ? POVerification : never;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DATE_UNITS = void 0;
4
+ exports.DATE_UNITS = ["ms", "s", "m", "h", "D", "M", "W", "Y"];
@@ -0,0 +1,3 @@
1
+ export * from "./dataValueTypes";
2
+ export * from "./config";
3
+ export * from "./internal";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./dataValueTypes"), exports);
14
+ __exportStar(require("./config"), exports);
15
+ __exportStar(require("./internal"), exports);
@@ -0,0 +1,20 @@
1
+ import { HField, HSchema, GetTSType } from "./dataValueTypes";
2
+ import { FieldValueTypes, ValueType } from "./config";
3
+ export declare type RuleDataProperty<T extends FieldValueTypes> = {
4
+ type: T;
5
+ value: GetTSType<T>;
6
+ hField: HField;
7
+ };
8
+ export declare type RuleData = {
9
+ [schemaName: string]: {
10
+ hSchema: HSchema;
11
+ properties: {
12
+ [fieldName: string]: RuleDataProperty<FieldValueTypes>;
13
+ };
14
+ }[];
15
+ };
16
+ export declare type OperatorDef = {
17
+ /** the first operand is the LHS, all others are RHS */
18
+ operands: ValueType[];
19
+ implementation: (...args: any[]) => boolean;
20
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /* eslint-disable fp/no-mutating-methods, fp/no-mutation, fp/no-let, prefer-reflect */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.canonicalJsonify = void 0;
5
+ const isObject = (a) => Object.prototype.toString.call(a) === "[object Object]"; // TODO: wtf ?
6
+ const REGEX =
7
+ // eslint-disable-next-line no-control-regex
8
+ /[\u0000-\u001F]|"|\\|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
9
+ const SLASH_ESC = {
10
+ "\b": "\\b",
11
+ "\t": "\\t",
12
+ "\n": "\\n",
13
+ "\f": "\\f",
14
+ "\r": "\\r",
15
+ '"': '\\"',
16
+ "\\": "\\\\",
17
+ };
18
+ const replacer = (char) => SLASH_ESC[char] ||
19
+ `\\u${char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
20
+ function copyObjectWithSortedKeys(object) {
21
+ if (isObject(object)) {
22
+ return `{${Object.keys(object)
23
+ .sort()
24
+ .map(key => `"${key}":${copyObjectWithSortedKeys(object[key])}`)
25
+ .join(",")}}`;
26
+ }
27
+ if (Array.isArray(object)) {
28
+ return `[${object.map(copyObjectWithSortedKeys).join(",")}]`;
29
+ }
30
+ if (typeof object === "number" && object % 1 !== 0) {
31
+ // float
32
+ const exponent = Math.round(Math.log10(Math.abs(object)));
33
+ let mantissa = `${object / 10 ** exponent}`;
34
+ if (!mantissa.includes("."))
35
+ mantissa += ".0";
36
+ return `${mantissa}E${exponent}`;
37
+ }
38
+ if (typeof object === "string")
39
+ return `"${object.replace(REGEX, replacer)}"`;
40
+ return object; // bool or int
41
+ }
42
+ /**
43
+ * @internal
44
+ * spec compliant, and matches
45
+ * https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/canonical_json.py
46
+ */
47
+ const canonicalJsonify = (object) => `${copyObjectWithSortedKeys(object)}`;
48
+ exports.canonicalJsonify = canonicalJsonify;
@@ -14,7 +14,6 @@ const handleResponse = async (response) => {
14
14
  const json = await response.json();
15
15
  // json could be a string | number
16
16
  if (typeof json === "object" && "message" in json) {
17
- // eslint-disable-next-line fp/no-throw
18
17
  throw new Error(json.message);
19
18
  }
20
19
  return json;
@@ -1 +1,2 @@
1
+ export * from "./canonicalJsonify";
1
2
  export * from "./handleResponse";
@@ -10,4 +10,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./canonicalJsonify"), exports);
13
14
  __exportStar(require("./handleResponse"), exports);
@@ -1,4 +1,4 @@
1
- import { FieldVerification, ProfileObject, POVerification, RealVer, Schema, VerificationProvider, ProfileObjectForUpload } from "@raytio/types";
1
+ import { FieldVerification, ProfileObject, POVerification, RealVer, Schema, VerificationProvider, ProfileObjectForUpload, NId } from "@raytio/types";
2
2
  /**
3
3
  * Determines the verification status of a profile object, and its individual fields.
4
4
  */
@@ -8,6 +8,9 @@ export declare function getPOVerification({ PO, schema, realVers, }: {
8
8
  realVers: RealVer[];
9
9
  }): {
10
10
  status: POVerification;
11
- details: VerificationProvider[];
11
+ details: {
12
+ sourceNId?: NId;
13
+ verifiers: VerificationProvider[];
14
+ };
12
15
  fieldVerifications: Record<string, FieldVerification>;
13
16
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPOVerification = void 0;
4
- /* eslint-disable fp/no-throw */
5
4
  const ramda_1 = require("ramda");
6
5
  const types_1 = require("@raytio/types");
7
6
  const crypto_1 = require("../crypto");
@@ -23,7 +22,7 @@ function getPOVerification({ PO, schema, realVers, }) {
23
22
  if (someAreEncrypted) {
24
23
  return {
25
24
  status: types_1.POVerification.Encrypted,
26
- details: [],
25
+ details: { sourceNId: PO.n_id, verifiers: [] },
27
26
  fieldVerifications: {},
28
27
  };
29
28
  }
@@ -81,14 +80,14 @@ function getPOVerification({ PO, schema, realVers, }) {
81
80
  /* istanbul ignore next */
82
81
  return types_1.POVerification.NotVerified;
83
82
  })();
84
- const details = (0, getVerifiedBy_1.getVerifiedBy)({
83
+ const verifiers = (0, getVerifiedBy_1.getVerifiedBy)({
85
84
  nId: PO.n_id,
86
85
  realVers,
87
86
  shouldBeVerifiedProps,
88
87
  });
89
88
  return {
90
89
  status,
91
- details,
90
+ details: { sourceNId: PO.n_id, verifiers },
92
91
  fieldVerifications,
93
92
  };
94
93
  }
@@ -1,5 +1,5 @@
1
1
  export * from "./cleanInstance";
2
2
  export * from "./getPOVerification";
3
- export * from "./getRealVerifications";
3
+ export * from "./verifyCheck";
4
4
  export * from "./getVerifiedBy";
5
5
  export * from "./safeHarbour";
@@ -10,9 +10,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- // not exporting checkVerifications; it's not a public API
14
13
  __exportStar(require("./cleanInstance"), exports);
15
14
  __exportStar(require("./getPOVerification"), exports);
16
- __exportStar(require("./getRealVerifications"), exports);
15
+ __exportStar(require("./verifyCheck"), exports);
17
16
  __exportStar(require("./getVerifiedBy"), exports);
18
17
  __exportStar(require("./safeHarbour"), exports);
@@ -9,7 +9,7 @@ export declare type SafeHarbourResult = {
9
9
  /**
10
10
  * The Safe Harbour Score indidicates whether a person's identity has been verified
11
11
  * to the extent requried for Safe Harbour Compliance. This requires multiple verifications
12
- * from different sources. For infomation, refer to the
12
+ * from different sources. For information, refer to the
13
13
  * {@link https://dev-docs.rayt.io/docs/features/pep-checks Raytio Documentation}.
14
14
  */
15
15
  export declare const calcSafeHarbourScore: (data: {
@@ -38,7 +38,7 @@ async function getFlags({ person, profileObjects, realVers, getSchema, }) {
38
38
  }));
39
39
  })))
40
40
  .filter(v => v.status === types_1.POVerification.FullyVerified)
41
- .flatMap(v => v.details.map(verProvider => realVers.find(ver => ver.belongsToNId === v.nId &&
41
+ .flatMap(v => v.details.verifiers.map(verProvider => realVers.find(ver => ver.belongsToNId === v.nId &&
42
42
  ver.provider.dataSourceNId === verProvider.dataSourceNId)))
43
43
  .filter((x) => !!x);
44
44
  // in case there are somehow duplicates (see #922)
@@ -67,7 +67,7 @@ exports.safeHarbourRequirementsMet = safeHarbourRequirementsMet;
67
67
  /**
68
68
  * The Safe Harbour Score indidicates whether a person's identity has been verified
69
69
  * to the extent requried for Safe Harbour Compliance. This requires multiple verifications
70
- * from different sources. For infomation, refer to the
70
+ * from different sources. For information, refer to the
71
71
  * {@link https://dev-docs.rayt.io/docs/features/pep-checks Raytio Documentation}.
72
72
  */
73
73
  const calcSafeHarbourScore = (data) => getFlags(data).then(safeHarbourRequirementsMet);
@@ -0,0 +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[]>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOwnRealVerifications = void 0;
4
+ const maybeRereference_1 = require("../maybeRereference");
5
+ const operations_1 = require("./operations");
6
+ /**
7
+ * Given a list of verifications and decrypted profile objects, this function
8
+ * locally verifies the credibility of the signatures in the verifications.
9
+ *
10
+ * This function does NOT call the API, except to fetch the public key.
11
+ * @returns a list of authentic RealVer
12
+ */
13
+ const getOwnRealVerifications = async ({ verifications, profileObjects, userId, }) => {
14
+ const realVers = [];
15
+ // this code is deliberaly written using for-loops instead of Promise.all,
16
+ // because attempting hundreds of webcrypto operations simultaneously will
17
+ // probably upset some heritage web browser.
18
+ for (const ver of verifications) {
19
+ for (const { data, signature } of ver.properties.verifications) {
20
+ const sourcePO = profileObjects.find(PO => PO.n_id === data.source_n_id);
21
+ if (!sourcePO)
22
+ continue;
23
+ const value = sourcePO.properties[data.field];
24
+ if (!value)
25
+ continue;
26
+ /**
27
+ * this does NOT mean that the data is correct. It means the
28
+ * verification is genuinely signed by raytio, but the data
29
+ * might be bogus (i.e. `passed: false`)
30
+ */
31
+ const isGenuine = await (0, operations_1.checkOwnVerification)({
32
+ verObject: data,
33
+ userId,
34
+ value: (0, maybeRereference_1.maybeRereference)(value),
35
+ signature,
36
+ });
37
+ if (!isGenuine)
38
+ continue;
39
+ // a "RealVer" is what the client likes to deal with,
40
+ // rather than the "VerificationPayload" which is stored on the API.
41
+ // eslint-disable-next-line fp/no-mutating-methods
42
+ realVers.push({
43
+ fieldName: data.field,
44
+ value,
45
+ provider: {
46
+ dataSourceNId: data.verifier_source_id,
47
+ serviceProviderNId: data.verifier_service_id,
48
+ verifierNId: data.verifier_id,
49
+ date: new Date(`${data.verification_date}Z`), // the api returns invalid dates (missing the `Z`)
50
+ },
51
+ expired: data.valid_until ? new Date(data.valid_until) : false,
52
+ metadata: data.metadata,
53
+ xId: data.request_div,
54
+ signature,
55
+ verified: data.passed,
56
+ nID: ver.n_id,
57
+ belongsToNId: data.source_n_id,
58
+ });
59
+ }
60
+ }
61
+ return realVers;
62
+ };
63
+ exports.getOwnRealVerifications = getOwnRealVerifications;
@@ -0,0 +1,19 @@
1
+ import { ProfileObject, Verification, RealVer, AId } from "@raytio/types";
2
+ declare type Props = {
3
+ aId: AId;
4
+ apiUrl: string;
5
+ verifications: Verification[];
6
+ profileObjects: ProfileObject[];
7
+ controller?: AbortController;
8
+ };
9
+ /**
10
+ * Given a list of verifications and decrypted profile objects, this function calls
11
+ * the Raytio API to verify the credibility of these verifications, returning only valid
12
+ * verifications.
13
+ *
14
+ * ❗ prefer `getOwnRealVerifications` if the data to be verified belongs to the current user.
15
+ *
16
+ * @returns a list of fileNames/values that are verified.
17
+ */
18
+ export declare const getSomeoneElsesRealVerifications: ({ aId, apiUrl, verifications, profileObjects, controller, }: Props) => Promise<RealVer[]>;
19
+ export {};
@@ -1,25 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRealVerifications = void 0;
3
+ exports.getSomeoneElsesRealVerifications = void 0;
4
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) => (0, ramda_1.pipe)((0, ramda_1.map)(x => { var _a; return (_a = x.properties) === null || _a === void 0 ? void 0 : _a[fieldName]; }), (0, ramda_1.filter)(x => !!x), // truthy only
9
- (0, ramda_1.reject)(crypto_1.isEncrypted), // ignore encrypted properties. this function will be called again once they're decrypted
10
- ramda_1.uniq);
5
+ const operations_1 = require("./operations");
6
+ const maybeRereference_1 = require("../maybeRereference");
7
+ const crypto_1 = require("../../crypto");
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
11
  /**
12
12
  * Given a list of verifications and decrypted profile objects, this function calls
13
13
  * the Raytio API to verify the credibility of these verifications, returning only valid
14
14
  * verifications.
15
+ *
16
+ * ❗ prefer `getOwnRealVerifications` if the data to be verified belongs to the current user.
17
+ *
15
18
  * @returns a list of fileNames/values that are verified.
16
19
  */
17
- const getRealVerifications = async ({ apiUrl, verifications, profileObjects, controller, UNSAFE_treatNoValueAsVerified, }) => {
20
+ const getSomeoneElsesRealVerifications = async ({ aId, apiUrl, verifications, profileObjects, controller, }) => {
18
21
  // for each verification (including passed: false), create a list of every possible that
19
22
  // value that that verification might have been for. Flatten the list
20
23
  // and send the whole thing to the API.
21
24
  const toVerify = verifications.flatMap(ver => {
22
- const values = getValuesForAField(ver.properties.field)(profileObjects);
25
+ const values = getValuesForAField(ver.properties.field, profileObjects);
23
26
  return values.flatMap(value => ver.properties.verifications.map(({ signature }) => ({
24
27
  verifications: [
25
28
  Object.assign({ signature }, (ver.n_id.startsWith("HASHED::")
@@ -35,19 +38,16 @@ const getRealVerifications = async ({ apiUrl, verifications, profileObjects, con
35
38
  // the API can't cope with an empty array
36
39
  if (!toVerify.length)
37
40
  return [];
38
- const apiResponse = await (0, checkVerifications_1.checkVerifications)({
41
+ const apiResponse = await (0, operations_1.checkSomeoneElsesVerifications)({
39
42
  apiUrl,
40
43
  toVerify,
41
44
  controller,
42
45
  });
43
46
  // do NOT expose the `verified` prop from the /verify_check API to avoid semantic confusion,
44
47
  // since verified: true does not mean that the verification is verified!
45
- const realVers = (0, ramda_1.pipe)((0, ramda_1.filter)(x => x.verified ||
46
- // if UNSAFE_treatNoValueAsVerified is enabled, and we don't know the value of this field,
47
- // treat is as verified if the `passed` property is true (this is NOT a safe check).
48
- (!!UNSAFE_treatNoValueAsVerified &&
49
- x.data.value === UNSAFE_treatNoValueAsVerified &&
50
- x.data.passed)), (0, ramda_1.map)(({ signature, data, n_id: nID, valid_until }) => ({
48
+ const realVers = apiResponse
49
+ .filter(x => x.verified)
50
+ .map(({ signature, data, n_id: nID, valid_until }) => ({
51
51
  fieldName: data.field,
52
52
  value: data.value,
53
53
  provider: {
@@ -62,8 +62,10 @@ const getRealVerifications = async ({ apiUrl, verifications, profileObjects, con
62
62
  signature,
63
63
  verified: data.passed,
64
64
  nID,
65
- belongsToNId: data.source_n_id,
66
- })))(apiResponse);
65
+ belongsToNId: data.source_hashed_n_id
66
+ ? `HASHED::${data.source_hashed_n_id}::${aId}`
67
+ : data.source_n_id,
68
+ }));
67
69
  return realVers;
68
70
  };
69
- exports.getRealVerifications = getRealVerifications;
71
+ exports.getSomeoneElsesRealVerifications = getSomeoneElsesRealVerifications;
@@ -0,0 +1,3 @@
1
+ export * from "./getOwnRealVerifications";
2
+ export * from "./getSomeoneElsesRealVerifications";
3
+ export { checkJsonSignature } from "./operations";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.checkJsonSignature = void 0;
14
+ __exportStar(require("./getOwnRealVerifications"), exports);
15
+ __exportStar(require("./getSomeoneElsesRealVerifications"), exports);
16
+ var operations_1 = require("./operations");
17
+ Object.defineProperty(exports, "checkJsonSignature", { enumerable: true, get: function () { return operations_1.checkJsonSignature; } });