@raytio/core 8.1.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +460 -1
  2. package/dist/accessApplication/createAA.js +0 -1
  3. package/dist/crypto/decryptKeys.js +0 -2
  4. package/dist/crypto/decryptSharedData.js +7 -4
  5. package/dist/crypto/helpers.d.ts +1 -1
  6. package/dist/general/index.d.ts +1 -0
  7. package/dist/general/index.js +1 -0
  8. package/dist/general/types.d.ts +6 -0
  9. package/dist/general/types.js +13 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +1 -0
  12. package/dist/rules/calculateScore.d.ts +11 -0
  13. package/dist/rules/calculateScore.js +52 -0
  14. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -0
  15. package/dist/rules/convertInstanceToRuleInput.js +140 -0
  16. package/dist/rules/evaluateScoreCondition.d.ts +2 -0
  17. package/dist/rules/evaluateScoreCondition.js +45 -0
  18. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -0
  19. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -0
  20. package/dist/rules/helpers/checkTypeofValue.d.ts +3 -0
  21. package/dist/rules/helpers/checkTypeofValue.js +43 -0
  22. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -0
  23. package/dist/rules/helpers/getValuesFromPath.js +50 -0
  24. package/dist/rules/helpers/index.d.ts +5 -0
  25. package/dist/rules/helpers/index.js +17 -0
  26. package/dist/rules/helpers/symbols.d.ts +2 -0
  27. package/dist/rules/helpers/symbols.js +5 -0
  28. package/dist/rules/helpers/thresholds.d.ts +5 -0
  29. package/dist/rules/helpers/thresholds.js +47 -0
  30. package/dist/rules/index.d.ts +6 -0
  31. package/dist/rules/index.js +20 -0
  32. package/dist/rules/operators/bool.d.ts +2 -0
  33. package/dist/rules/operators/bool.js +17 -0
  34. package/dist/rules/operators/date.d.ts +2 -0
  35. package/dist/rules/operators/date.js +91 -0
  36. package/dist/rules/operators/hfield.d.ts +2 -0
  37. package/dist/rules/operators/hfield.js +33 -0
  38. package/dist/rules/operators/hschema.d.ts +2 -0
  39. package/dist/rules/operators/hschema.js +21 -0
  40. package/dist/rules/operators/index.d.ts +3 -0
  41. package/dist/rules/operators/index.js +11 -0
  42. package/dist/rules/operators/number.d.ts +2 -0
  43. package/dist/rules/operators/number.js +41 -0
  44. package/dist/rules/operators/string.d.ts +2 -0
  45. package/dist/rules/operators/string.js +58 -0
  46. package/dist/rules/types/config.d.ts +86 -0
  47. package/dist/rules/types/config.js +2 -0
  48. package/dist/rules/types/dataValueTypes.d.ts +19 -0
  49. package/dist/rules/types/dataValueTypes.js +4 -0
  50. package/dist/rules/types/index.d.ts +3 -0
  51. package/dist/rules/types/index.js +15 -0
  52. package/dist/rules/types/internal.d.ts +20 -0
  53. package/dist/rules/types/internal.js +2 -0
  54. package/dist/{verifications/checkVerifications.d.ts → util/canonicalJsonify.d.ts} +0 -0
  55. package/dist/util/canonicalJsonify.js +48 -0
  56. package/dist/util/handleResponse.js +0 -1
  57. package/dist/util/index.d.ts +1 -0
  58. package/dist/util/index.js +1 -0
  59. package/dist/verifications/cleanInstance.d.ts +9 -0
  60. package/dist/verifications/cleanInstance.js +15 -0
  61. package/dist/verifications/getPOVerification.d.ts +5 -2
  62. package/dist/verifications/getPOVerification.js +3 -4
  63. package/dist/verifications/index.d.ts +2 -1
  64. package/dist/verifications/index.js +2 -1
  65. package/dist/verifications/safeHarbour.d.ts +2 -3
  66. package/dist/verifications/safeHarbour.js +2 -2
  67. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -0
  68. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +63 -0
  69. package/dist/verifications/{getRealVerifications.d.ts → verifyCheck/getSomeoneElsesRealVerifications.d.ts} +6 -2
  70. package/dist/verifications/{getRealVerifications.js → verifyCheck/getSomeoneElsesRealVerifications.js} +26 -16
  71. package/dist/verifications/verifyCheck/index.d.ts +2 -0
  72. package/dist/verifications/verifyCheck/index.js +14 -0
  73. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +9 -0
  74. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +31 -0
  75. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -0
  76. package/dist/verifications/{checkVerifications.js → verifyCheck/operations/checkSomeoneElsesVerifications.js} +4 -4
  77. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -0
  78. package/dist/verifications/verifyCheck/operations/index.js +14 -0
  79. package/package.json +8 -8
@@ -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);
@@ -0,0 +1,9 @@
1
+ import { Instance } from "@raytio/types";
2
+ /**
3
+ * The API response from share/v2/access_application/instance/:iId
4
+ * returns a complicated hashed_n_id format, so you need to clean up
5
+ * the API response using this function as soon as possible.
6
+ *
7
+ * We relace `hashed_n_id`s with a string `HASHED::{NId}::{AId}`
8
+ */
9
+ export declare function cleanInstance(instance: Instance): Instance;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanInstance = void 0;
4
+ const ramda_1 = require("ramda");
5
+ /**
6
+ * The API response from share/v2/access_application/instance/:iId
7
+ * returns a complicated hashed_n_id format, so you need to clean up
8
+ * the API response using this function as soon as possible.
9
+ *
10
+ * We relace `hashed_n_id`s with a string `HASHED::{NId}::{AId}`
11
+ */
12
+ function cleanInstance(instance) {
13
+ return Object.assign(Object.assign({}, instance), { profile_objects: instance.profile_objects.map((PO) => (Object.assign(Object.assign({}, (0, ramda_1.omit)(["hashed_n_id"], PO)), { n_id: PO.n_id || `HASHED::${PO.hashed_n_id}::${instance.a_id}` }))) });
14
+ }
15
+ exports.cleanInstance = cleanInstance;
@@ -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,4 +1,5 @@
1
+ export * from "./cleanInstance";
1
2
  export * from "./getPOVerification";
2
- export * from "./getRealVerifications";
3
+ export * from "./verifyCheck";
3
4
  export * from "./getVerifiedBy";
4
5
  export * from "./safeHarbour";
@@ -11,7 +11,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  // not exporting checkVerifications; it's not a public API
14
+ __exportStar(require("./cleanInstance"), exports);
14
15
  __exportStar(require("./getPOVerification"), exports);
15
- __exportStar(require("./getRealVerifications"), exports);
16
+ __exportStar(require("./verifyCheck"), exports);
16
17
  __exportStar(require("./getVerifiedBy"), exports);
17
18
  __exportStar(require("./safeHarbour"), exports);
@@ -3,14 +3,13 @@ import { ProfileObject, RealVer, Schema } from "@raytio/types";
3
3
  export declare type SafeHarbourObj = Partial<Record<SafeHarbourCode, string[]>>;
4
4
  /** the response from {@link calcSafeHarbourScore} */
5
5
  export declare type SafeHarbourResult = {
6
- /** undefined means loading */
7
- isSafe: boolean | undefined;
6
+ isSafe: boolean;
8
7
  flags: SafeHarbourObj;
9
8
  };
10
9
  /**
11
10
  * The Safe Harbour Score indidicates whether a person's identity has been verified
12
11
  * to the extent requried for Safe Harbour Compliance. This requires multiple verifications
13
- * from different sources. For infomation, refer to the
12
+ * from different sources. For information, refer to the
14
13
  * {@link https://dev-docs.rayt.io/docs/features/pep-checks Raytio Documentation}.
15
14
  */
16
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;
@@ -1,5 +1,6 @@
1
- import { ProfileObject, Verification, RealVer } from "@raytio/types";
1
+ import { ProfileObject, Verification, RealVer, AId } from "@raytio/types";
2
2
  declare type Props = {
3
+ aId: AId;
3
4
  apiUrl: string;
4
5
  verifications: Verification[];
5
6
  profileObjects: ProfileObject[];
@@ -16,7 +17,10 @@ declare type Props = {
16
17
  * Given a list of verifications and decrypted profile objects, this function calls
17
18
  * the Raytio API to verify the credibility of these verifications, returning only valid
18
19
  * verifications.
20
+ *
21
+ * ❗ prefer `getOwnRealVerifications` if the data to be verified belongs to the current user.
22
+ *
19
23
  * @returns a list of fileNames/values that are verified.
20
24
  */
21
- export declare const getRealVerifications: ({ apiUrl, verifications, profileObjects, controller, UNSAFE_treatNoValueAsVerified, }: Props) => Promise<RealVer[]>;
25
+ export declare const getSomeoneElsesRealVerifications: ({ aId, apiUrl, verifications, profileObjects, controller, UNSAFE_treatNoValueAsVerified, }: Props) => Promise<RealVer[]>;
22
26
  export {};