@raytio/core 8.1.3 → 9.0.3

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 (78) hide show
  1. package/README.md +104 -11
  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 +50 -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 +4 -5
  60. package/dist/verifications/getVerifiedBy.js +1 -1
  61. package/dist/verifications/index.d.ts +1 -1
  62. package/dist/verifications/index.js +1 -2
  63. package/dist/verifications/safeHarbour.d.ts +1 -1
  64. package/dist/verifications/safeHarbour.js +2 -2
  65. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -0
  66. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +63 -0
  67. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -0
  68. package/dist/verifications/{getRealVerifications.js → verifyCheck/getSomeoneElsesRealVerifications.js} +21 -19
  69. package/dist/verifications/verifyCheck/index.d.ts +3 -0
  70. package/dist/verifications/verifyCheck/index.js +17 -0
  71. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -0
  72. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -0
  73. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -0
  74. package/dist/verifications/{checkVerifications.js → verifyCheck/operations/checkSomeoneElsesVerifications.js} +4 -4
  75. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -0
  76. package/dist/verifications/verifyCheck/operations/index.js +14 -0
  77. package/package.json +8 -8
  78. package/dist/verifications/getRealVerifications.d.ts +0 -22
@@ -0,0 +1,50 @@
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
+ if (Number.isNaN(object) || !Number.isFinite(object))
32
+ return "null";
33
+ // float
34
+ const exponent = Math.floor(Math.log10(Math.abs(object)));
35
+ let mantissa = `${object / 10 ** exponent}`;
36
+ if (!mantissa.includes("."))
37
+ mantissa += ".0";
38
+ return `${mantissa}E${exponent}`;
39
+ }
40
+ if (typeof object === "string")
41
+ return `"${object.replace(REGEX, replacer)}"`;
42
+ return object; // bool or int
43
+ }
44
+ /**
45
+ * @internal
46
+ * spec compliant, and matches
47
+ * https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/canonical_json.py
48
+ */
49
+ const canonicalJsonify = (object) => `${copyObjectWithSortedKeys(object)}`;
50
+ 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
  }
@@ -44,7 +43,7 @@ function getPOVerification({ PO, schema, realVers, }) {
44
43
  const fieldVerifications = (0, ramda_1.mapObjIndexed)((content, fieldName) => {
45
44
  const pertainingVers = realVers.filter(x => x.fieldName === fieldName &&
46
45
  // using ramda's `equals` because this needs to work for objects/arrays
47
- (0, ramda_1.equals)(x.value, (0, maybeRereference_1.maybeRereference)(content)) &&
46
+ (0, ramda_1.equals)((0, maybeRereference_1.maybeRereference)(x.value), (0, maybeRereference_1.maybeRereference)(content)) &&
48
47
  // if an nId is supplied, also filter out verifications that don't relate to that n_id
49
48
  (PO.n_id ? x.belongsToNId === PO.n_id : true));
50
49
  // .every() illogically returns true for arrays with zero length
@@ -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
  }
@@ -10,7 +10,7 @@ const getVerifiedBy = ({ nId, realVers, shouldBeVerifiedProps, }) => {
10
10
  const pertainingVers = realVers
11
11
  .filter(x => mayBeVerifiedFields.includes(x.fieldName) &&
12
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]), x.value) &&
13
+ (0, ramda_1.equals)((0, maybeRereference_1.maybeRereference)(shouldBeVerifiedProps[x.fieldName]), (0, maybeRereference_1.maybeRereference)(x.value)) &&
14
14
  // if an nId is supplied, also filter out verifications that don't relate to that n_id
15
15
  (nId ? x.belongsToNId === nId : true))
16
16
  .map(x => x.provider);
@@ -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; } });
@@ -0,0 +1,15 @@
1
+ import { UId, VerificationPayload } from "@raytio/types";
2
+ declare type SingleVerToCheck = {
3
+ verObject: VerificationPayload<false>;
4
+ signature: string;
5
+ userId: UId;
6
+ value: unknown;
7
+ };
8
+ /**
9
+ * checks that a json object was signed by the provided signature. Unless you're
10
+ * dealing with bundled verifications, you should use `getOwnRealVerifications`
11
+ * or `getSomeoneElsesRealVerifications` instead.
12
+ */
13
+ export declare const checkJsonSignature: (data: unknown, signature: string) => Promise<boolean>;
14
+ export declare const checkOwnVerification: ({ verObject, signature, userId, value, }: SingleVerToCheck) => Promise<boolean>;
15
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkOwnVerification = exports.checkJsonSignature = exports.checkSignature = void 0;
4
+ const util_1 = require("../../../util");
5
+ let cache; // eslint-disable-line fp/no-let
6
+ const base64ToArrayBuffer = (str) => Uint8Array.from(atob(str), c => c.charCodeAt(0));
7
+ async function getJwk() {
8
+ // eslint-disable-next-line fp/no-mutation
9
+ cache || (cache = fetch("https://api-docs.rayt.io/lookups/raytio.pem")
10
+ .then(r => r.text())
11
+ .then(pem => crypto.subtle.importKey("spki", base64ToArrayBuffer(pem.split("-----")[2].trim()), { name: "RSA-PSS", hash: "SHA-512" }, false, ["verify"])));
12
+ return cache;
13
+ }
14
+ /** @internal exported only for tests */
15
+ async function checkSignature(publicCryptoKey, signature, data) {
16
+ // the logic must match https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/sign.py
17
+ const signatureBuf = base64ToArrayBuffer(signature);
18
+ const isVerified = await crypto.subtle.verify({ name: "RSA-PSS", hash: "SHA-512", saltLength: 512 / 8 }, publicCryptoKey, signatureBuf, new TextEncoder().encode(data));
19
+ return isVerified;
20
+ }
21
+ exports.checkSignature = checkSignature;
22
+ /**
23
+ * checks that a json object was signed by the provided signature. Unless you're
24
+ * dealing with bundled verifications, you should use `getOwnRealVerifications`
25
+ * or `getSomeoneElsesRealVerifications` instead.
26
+ */
27
+ const checkJsonSignature = async (data, signature) => {
28
+ const jwk = await getJwk();
29
+ const stringified = (0, util_1.canonicalJsonify)(data);
30
+ const result = await checkSignature(jwk, signature, stringified);
31
+ return result;
32
+ };
33
+ exports.checkJsonSignature = checkJsonSignature;
34
+ const checkOwnVerification = async ({ verObject, signature, userId, value, }) => {
35
+ if (!userId)
36
+ throw new Error("No userId supplied");
37
+ return (0, exports.checkJsonSignature)(Object.assign(Object.assign({}, verObject), { sub: userId, value }), signature);
38
+ };
39
+ exports.checkOwnVerification = checkOwnVerification;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkVerifications = void 0;
4
- const util_1 = require("../util");
3
+ exports.checkSomeoneElsesVerifications = void 0;
4
+ const util_1 = require("../../../util");
5
5
  /** @internal */
6
- const checkVerifications = async ({ apiUrl, toVerify, controller, }) => {
6
+ const checkSomeoneElsesVerifications = async ({ apiUrl, toVerify, controller, }) => {
7
7
  const response = await fetch(`${apiUrl}/extract_verify/v2/verify_check`, {
8
8
  method: "POST",
9
9
  body: JSON.stringify(toVerify),
@@ -13,4 +13,4 @@ const checkVerifications = async ({ apiUrl, toVerify, controller, }) => {
13
13
  // extra `m` items are garbage and don't have the verified field.
14
14
  return response.filter(ver => "verified" in ver);
15
15
  };
16
- exports.checkVerifications = checkVerifications;
16
+ exports.checkSomeoneElsesVerifications = checkSomeoneElsesVerifications;
@@ -0,0 +1,2 @@
1
+ export * from "./checkOwnVerification";
2
+ export * from "./checkSomeoneElsesVerifications";
@@ -0,0 +1,14 @@
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("./checkOwnVerification"), exports);
14
+ __exportStar(require("./checkSomeoneElsesVerifications"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/core",
3
- "version": "8.1.3",
3
+ "version": "9.0.3",
4
4
  "license": "MIT",
5
5
  "main": "index",
6
6
  "types": "index",
@@ -15,22 +15,22 @@
15
15
  "test": "jest"
16
16
  },
17
17
  "dependencies": {
18
- "@raytio/maxcryptor": "3.0.1",
19
- "@raytio/types": "5.2.1",
20
- "ramda": "0.27.1"
18
+ "@raytio/maxcryptor": "3.1.0",
19
+ "@raytio/types": "6.0.0",
20
+ "ramda": "0.28.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/ramda": "0.27.44",
24
- "jest": "27.3.0",
23
+ "@types/ramda": "0.27.64",
24
+ "jest": "27.5.1",
25
25
  "localstorage-polyfill": "1.0.1",
26
- "ts-jest": "27.0.5"
26
+ "ts-jest": "27.1.3"
27
27
  },
28
28
  "jest": {
29
29
  "transform": {
30
30
  "^.+\\.(t|j)sx?$": "ts-jest"
31
31
  },
32
32
  "testEnvironment": "node",
33
- "collectCoverage": true,
33
+ "collectCoverage": false,
34
34
  "coverageThreshold": {
35
35
  "global": {
36
36
  "statements": 100
@@ -1,22 +0,0 @@
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 {};