@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,50 +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;
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;
@@ -0,0 +1,7 @@
1
+ declare type ConditionValue = string | number | boolean;
2
+ /**
3
+ * Checks all other form values in case any have a
4
+ * trigger value that makes this field requirted.
5
+ */
6
+ export declare const isConditionMet: (condition: Record<string, ConditionValue[]>, formValues: Record<string, unknown>) => boolean;
7
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isConditionMet = void 0;
4
+ /**
5
+ * Checks all other form values in case any have a
6
+ * trigger value that makes this field requirted.
7
+ */
8
+ const isConditionMet = (condition, formValues) => Object.entries(condition).every(([fieldName, triggerValues]) => {
9
+ if (Array.isArray(formValues[fieldName])) {
10
+ // if it's a multiselect, check if any of the selected values match the criteria
11
+ return formValues[fieldName].some(val => triggerValues.includes(val));
12
+ }
13
+ return triggerValues.includes(formValues[fieldName]);
14
+ });
15
+ exports.isConditionMet = isConditionMet;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,21 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleResponse = void 0;
4
- /**
5
- * @internal
6
- * Throws an error if the API request fails.
7
- * Drop-in replacement for `response.json()`
8
- * @example
9
- * ```
10
- * const json = await fetch(...).then(handleResponse)
11
- * ```
12
- */
13
- const handleResponse = async (response) => {
14
- const json = await response.json();
15
- // json could be a string | number
16
- if (typeof json === "object" && "message" in json) {
17
- throw new Error(json.message);
18
- }
19
- return json;
20
- };
21
- exports.handleResponse = handleResponse;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleResponse = void 0;
4
+ /**
5
+ * @internal
6
+ * Throws an error if the API request fails.
7
+ * Drop-in replacement for `response.json()`
8
+ * @example
9
+ * ```
10
+ * const json = await fetch(...).then(handleResponse)
11
+ * ```
12
+ */
13
+ const handleResponse = async (response) => {
14
+ const json = await response.json();
15
+ // json could be a string | number
16
+ if (typeof json === "object" && "message" in json) {
17
+ throw new Error(json.message);
18
+ }
19
+ return json;
20
+ };
21
+ exports.handleResponse = handleResponse;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sha512 = void 0;
4
+ /** @internal */
5
+ async function sha512(str) {
6
+ const buf = await crypto.subtle.digest("SHA-512", new TextEncoder().encode(str));
7
+ return Array.from(new Uint8Array(buf))
8
+ .map(b => b.toString(16).padStart(2, "0"))
9
+ .join("");
10
+ }
11
+ exports.sha512 = sha512;
@@ -1,2 +1,2 @@
1
- export * from "./canonicalJsonify";
2
- export * from "./handleResponse";
1
+ export * from "./canonicalJsonify";
2
+ export * from "./handleResponse";
@@ -1,18 +1,18 @@
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("./canonicalJsonify"), exports);
18
- __exportStar(require("./handleResponse"), 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("./canonicalJsonify"), exports);
18
+ __exportStar(require("./handleResponse"), exports);
@@ -0,0 +1,9 @@
1
+ import { VerificationPayload } from "@raytio/types";
2
+ declare type SingleVerToCheck = {
3
+ verObject: VerificationPayload<false>;
4
+ signature: string;
5
+ userId: string;
6
+ value: unknown;
7
+ };
8
+ export declare const checkSingleVerification: ({ verObject, signature, userId, value, }: SingleVerToCheck) => Promise<boolean>;
9
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkSingleVerification = exports.checkSignature = void 0;
4
+ const pem_jwk_1 = require("pem-jwk");
5
+ const util_1 = require("../util");
6
+ let cache; // eslint-disable-line fp/no-let
7
+ async function getJwk() {
8
+ const pem = await fetch("http://api-docs.rayt.io/lookups/raytio.pem").then(r => r.text());
9
+ // eslint-disable-next-line fp/no-mutation
10
+ cache = (0, pem_jwk_1.pem2jwk)(pem);
11
+ return cache;
12
+ }
13
+ /** @internal exported only for tests */
14
+ async function checkSignature(publicKeyJwk, signature, data) {
15
+ // must match https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/sign.py
16
+ const publicKey = await window.crypto.subtle.importKey("jwk", publicKeyJwk, { name: "RSA-PSS", hash: "SHA-512" }, false, ["verify"]);
17
+ const signatureBuf = Uint8Array.from(atob(signature), c => c.charCodeAt(0));
18
+ const res = await crypto.subtle.verify({ name: "RSA-PSS", hash: "SHA-512", saltLength: 512 / 8 }, publicKey, signatureBuf, new TextEncoder().encode(data));
19
+ return res;
20
+ }
21
+ exports.checkSignature = checkSignature;
22
+ const checkSingleVerification = async ({ verObject, signature, userId, value, }) => {
23
+ const jwk = await getJwk();
24
+ const exapandedObject = Object.assign(Object.assign({}, verObject), { sub: userId, value });
25
+ const stringified = (0, util_1.canonicalJsonify)(exapandedObject);
26
+ const result = await checkSignature(jwk, signature, stringified);
27
+ return result;
28
+ };
29
+ exports.checkSingleVerification = checkSingleVerification;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkVerifications = void 0;
4
+ const util_1 = require("../util");
5
+ /** @internal */
6
+ const checkVerifications = async ({ apiUrl, toVerify, controller, }) => {
7
+ const response = await fetch(`${apiUrl}/extract_verify/v2/verify_check`, {
8
+ method: "POST",
9
+ body: JSON.stringify(toVerify),
10
+ signal: controller === null || controller === void 0 ? void 0 : controller.signal,
11
+ }).then(util_1.handleResponse);
12
+ // if we send `n` items to the API, it returns `n + m` items. The
13
+ // extra `m` items are garbage and don't have the verified field.
14
+ return response.filter(ver => "verified" in ver);
15
+ };
16
+ exports.checkVerifications = checkVerifications;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkVerificationsNew = void 0;
4
+ const pem_jwk_1 = require("pem-jwk");
5
+ let cache; // eslint-disable-line fp/no-let
6
+ async function getJwk() {
7
+ const pem = await fetch("http://api-docs.rayt.io/lookups/raytio.pem").then(r => r.text());
8
+ // eslint-disable-next-line fp/no-mutation
9
+ cache = (0, pem_jwk_1.pem2jwk)(pem);
10
+ return cache;
11
+ }
12
+ /** @internal */
13
+ const checkVerificationsNew = async () => {
14
+ const jwk = await getJwk();
15
+ };
16
+ exports.checkVerificationsNew = checkVerificationsNew;
@@ -1,9 +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;
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;
@@ -1,15 +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
+ "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;
@@ -0,0 +1,14 @@
1
+ import { ProfileObject, Verification, RealVer } from "@raytio/types";
2
+ declare type Props = {
3
+ verifications: Verification[];
4
+ profileObjects: ProfileObject[];
5
+ userId: string;
6
+ };
7
+ /**
8
+ * Given a list of verifications and decrypted profile objects, this function calls
9
+ * the Raytio API to verify the credibility of these verifications, returning only valid
10
+ * verifications.
11
+ * @returns a list of fileNames/values that are verified.
12
+ */
13
+ export declare const getOwnRealVerifications: ({ verifications, profileObjects, userId, }: Props) => Promise<RealVer[]>;
14
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOwnRealVerifications = void 0;
4
+ /* eslint-disable fp/no-loops */
5
+ const ramda_1 = require("ramda");
6
+ const crypto_1 = require("../crypto");
7
+ const maybeRereference_1 = require("./maybeRereference");
8
+ const checkSingleVerification_1 = require("./checkSingleVerification");
9
+ const getValuesForAField = (fieldName, POs) => (0, ramda_1.uniq)(
10
+ // truthy only, and ignore encrypted properties. this function will be called again once they're decrypted
11
+ 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)));
12
+ /**
13
+ * Given a list of verifications and decrypted profile objects, this function calls
14
+ * the Raytio API to verify the credibility of these verifications, returning only valid
15
+ * verifications.
16
+ * @returns a list of fileNames/values that are verified.
17
+ */
18
+ const getOwnRealVerifications = async ({ verifications, profileObjects, userId, }) => {
19
+ // FIXME: support hashed_n_id
20
+ // FIXME: support UNSAFE_treatNoValueAsVerified
21
+ // TODO: support derived verifications
22
+ // for each verification (including passed: false), create a list of every possible that
23
+ // value that that verification might have been for. Flatten the list
24
+ // and check which ones are valid, keeping only the valid key passes
25
+ const realVers = [];
26
+ for (const ver of verifications) {
27
+ /** every possible value for this field */
28
+ const values = getValuesForAField(ver.properties.field, profileObjects);
29
+ for (const value of values) {
30
+ for (const { data, signature } of ver.properties.verifications) {
31
+ const isVerified = await (0, checkSingleVerification_1.checkSingleVerification)({
32
+ verObject: data,
33
+ userId,
34
+ value: (0, maybeRereference_1.maybeRereference)(value),
35
+ signature,
36
+ });
37
+ if (isVerified) {
38
+ // a "RealVer" is what the client likes to deal with,
39
+ // rather than the "VerificationPayload" which is stored on the API.
40
+ // eslint-disable-next-line fp/no-mutating-methods
41
+ realVers.push({
42
+ fieldName: data.field,
43
+ value,
44
+ provider: {
45
+ dataSourceNId: data.verifier_source_id,
46
+ serviceProviderNId: data.verifier_service_id,
47
+ verifierNId: data.verifier_id,
48
+ date: new Date(`${data.verification_date}Z`), // the api returns invalid dates (missing the `Z`)
49
+ },
50
+ expired: data.valid_until ? new Date(data.valid_until) : false,
51
+ metadata: data.metadata,
52
+ xId: data.request_div,
53
+ signature,
54
+ verified: data.passed,
55
+ nID: ver.n_id,
56
+ belongsToNId: data.source_n_id,
57
+ });
58
+ }
59
+ }
60
+ }
61
+ }
62
+ return realVers;
63
+ };
64
+ exports.getOwnRealVerifications = getOwnRealVerifications;
@@ -1,16 +1,16 @@
1
- import { FieldVerification, ProfileObject, POVerification, RealVer, Schema, VerificationProvider, ProfileObjectForUpload, NId } from "@raytio/types";
2
- /**
3
- * Determines the verification status of a profile object, and its individual fields.
4
- */
5
- export declare function getPOVerification({ PO, schema, realVers, }: {
6
- PO: ProfileObject | ProfileObjectForUpload;
7
- schema: Schema;
8
- realVers: RealVer[];
9
- }): {
10
- status: POVerification;
11
- details: {
12
- sourceNId?: NId;
13
- verifiers: VerificationProvider[];
14
- };
15
- fieldVerifications: Record<string, FieldVerification>;
16
- };
1
+ import { FieldVerification, ProfileObject, POVerification, RealVer, Schema, VerificationProvider, ProfileObjectForUpload, NId } from "@raytio/types";
2
+ /**
3
+ * Determines the verification status of a profile object, and its individual fields.
4
+ */
5
+ export declare function getPOVerification({ PO, schema, realVers, }: {
6
+ PO: ProfileObject | ProfileObjectForUpload;
7
+ schema: Schema;
8
+ realVers: RealVer[];
9
+ }): {
10
+ status: POVerification;
11
+ details: {
12
+ sourceNId?: NId;
13
+ verifiers: VerificationProvider[];
14
+ };
15
+ fieldVerifications: Record<string, FieldVerification>;
16
+ };