@raytio/core 10.1.0 → 11.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 (208) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +198 -59
  3. package/dist/{util/hash.d.ts → __tests__/docs.test.d.ts} +1 -1
  4. package/dist/__tests__/docs.test.js +24 -0
  5. package/dist/accessApplication/createAA.d.ts +17 -17
  6. package/dist/accessApplication/createAA.js +71 -71
  7. package/dist/accessApplication/index.d.ts +1 -1
  8. package/dist/accessApplication/index.js +17 -17
  9. package/dist/crypto/cognitoAttributes.d.ts +15 -15
  10. package/dist/crypto/cognitoAttributes.js +33 -33
  11. package/dist/crypto/decryptKeys.d.ts +1 -1
  12. package/dist/crypto/decryptKeys.js +33 -33
  13. package/dist/crypto/decryptSharedData.d.ts +26 -26
  14. package/dist/crypto/decryptSharedData.js +38 -38
  15. package/dist/crypto/getAADecryptor.d.ts +16 -16
  16. package/dist/crypto/getAADecryptor.js +20 -20
  17. package/dist/crypto/helpers.d.ts +18 -18
  18. package/dist/crypto/helpers.js +26 -26
  19. package/dist/crypto/index.d.ts +4 -4
  20. package/dist/crypto/index.js +21 -21
  21. package/dist/general/conditional.d.ts +17 -17
  22. package/dist/general/conditional.js +32 -32
  23. package/dist/general/date.d.ts +2 -2
  24. package/dist/general/date.js +18 -18
  25. package/dist/general/index.d.ts +4 -4
  26. package/dist/general/index.js +20 -20
  27. package/dist/general/password.d.ts +10 -10
  28. package/dist/general/password.js +31 -31
  29. package/dist/general/types.d.ts +6 -6
  30. package/dist/general/types.js +13 -13
  31. package/dist/index.d.ts +6 -6
  32. package/dist/index.js +22 -22
  33. package/dist/rules/calculateScore.d.ts +28 -23
  34. package/dist/rules/calculateScore.js +82 -76
  35. package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
  36. package/dist/rules/convertInstanceToRuleInput.js +138 -139
  37. package/dist/rules/evaluateScoreCondition.d.ts +2 -2
  38. package/dist/rules/evaluateScoreCondition.js +44 -45
  39. package/dist/{verifications/checkVerifications.d.ts → rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts} +1 -1
  40. package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
  41. package/dist/{verifications/checkVerificationsNew.d.ts → rules/helpers/__tests__/checkTypeofValue.test.d.ts} +1 -1
  42. package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
  43. package/dist/{verifications/verifyCheck/util/canonicalJsonify.d.ts → rules/helpers/__tests__/getValuesFromPath.test.d.ts} +1 -1
  44. package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
  45. package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
  46. package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
  47. package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
  48. package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
  49. package/dist/rules/helpers/checkTypeofValue.d.ts +9 -9
  50. package/dist/rules/helpers/checkTypeofValue.js +60 -55
  51. package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
  52. package/dist/rules/helpers/getValuesFromPath.js +50 -50
  53. package/dist/rules/helpers/index.d.ts +5 -5
  54. package/dist/rules/helpers/index.js +21 -21
  55. package/dist/rules/helpers/symbols.d.ts +2 -2
  56. package/dist/rules/helpers/symbols.js +5 -5
  57. package/dist/rules/helpers/thresholds.d.ts +5 -5
  58. package/dist/rules/helpers/thresholds.js +46 -47
  59. package/dist/rules/index.d.ts +7 -7
  60. package/dist/rules/index.js +25 -25
  61. package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
  62. package/dist/rules/operators/__tests__/bool.test.js +21 -0
  63. package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
  64. package/dist/rules/operators/__tests__/date.test.js +81 -0
  65. package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
  66. package/dist/rules/operators/__tests__/hfield.test.js +38 -0
  67. package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
  68. package/dist/rules/operators/__tests__/hschema.test.js +24 -0
  69. package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
  70. package/dist/rules/operators/__tests__/number.test.js +53 -0
  71. package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
  72. package/dist/rules/operators/__tests__/string.test.js +74 -0
  73. package/dist/rules/operators/bool.d.ts +2 -2
  74. package/dist/rules/operators/bool.js +17 -17
  75. package/dist/rules/operators/date.d.ts +2 -2
  76. package/dist/rules/operators/date.js +91 -91
  77. package/dist/rules/operators/hfield.d.ts +2 -2
  78. package/dist/rules/operators/hfield.js +33 -33
  79. package/dist/rules/operators/hschema.d.ts +2 -2
  80. package/dist/rules/operators/hschema.js +21 -21
  81. package/dist/rules/operators/index.d.ts +3 -3
  82. package/dist/rules/operators/index.js +11 -11
  83. package/dist/rules/operators/number.d.ts +2 -2
  84. package/dist/rules/operators/number.js +41 -41
  85. package/dist/rules/operators/string.d.ts +2 -2
  86. package/dist/rules/operators/string.js +58 -58
  87. package/dist/rules/types/config.d.ts +95 -91
  88. package/dist/rules/types/config.js +2 -2
  89. package/dist/rules/types/dataValueTypes.d.ts +19 -19
  90. package/dist/rules/types/dataValueTypes.js +4 -4
  91. package/dist/rules/types/index.d.ts +3 -3
  92. package/dist/rules/types/index.js +19 -19
  93. package/dist/rules/types/internal.d.ts +20 -20
  94. package/dist/rules/types/internal.js +2 -2
  95. package/dist/rules/validate.d.ts +6 -6
  96. package/dist/rules/validate.js +14 -14
  97. package/dist/rules/version.d.ts +1 -1
  98. package/dist/rules/version.js +5 -5
  99. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
  100. package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
  101. package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
  102. package/dist/schema/expandSchema/__tests__/expandSchema.test.js +95 -0
  103. package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
  104. package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
  105. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
  106. package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
  107. package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
  108. package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
  109. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
  110. package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
  111. package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
  112. package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
  113. package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
  114. package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
  115. package/dist/schema/expandSchema/constants.d.ts +2 -0
  116. package/dist/schema/expandSchema/constants.js +11 -0
  117. package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
  118. package/dist/schema/expandSchema/expandSchema.js +19 -0
  119. package/dist/schema/expandSchema/i18n.d.ts +5 -0
  120. package/dist/schema/expandSchema/i18n.js +20 -0
  121. package/dist/schema/expandSchema/index.d.ts +3 -0
  122. package/dist/schema/expandSchema/index.js +21 -0
  123. package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
  124. package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
  125. package/dist/schema/expandSchema/processSchema.d.ts +4 -0
  126. package/dist/schema/expandSchema/processSchema.js +94 -0
  127. package/dist/schema/expandSchema/removePrivateFields.d.ts +119 -0
  128. package/dist/schema/expandSchema/removePrivateFields.js +15 -0
  129. package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
  130. package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
  131. package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
  132. package/dist/schema/expandSchema/unwrapSchema.js +7 -0
  133. package/dist/schema/expandSchema/util.d.ts +6 -0
  134. package/dist/schema/expandSchema/util.js +15 -0
  135. package/dist/schema/index.d.ts +2 -1
  136. package/dist/schema/index.js +18 -17
  137. package/dist/schema/labels.d.ts +2 -2
  138. package/dist/schema/labels.js +20 -20
  139. package/dist/util/canonicalJsonify.d.ts +1 -1
  140. package/dist/util/canonicalJsonify.js +50 -50
  141. package/dist/util/handleResponse.d.ts +1 -1
  142. package/dist/util/handleResponse.js +21 -21
  143. package/dist/util/index.d.ts +2 -2
  144. package/dist/util/index.js +18 -18
  145. package/dist/verifications/cleanInstance.d.ts +9 -9
  146. package/dist/verifications/cleanInstance.js +15 -15
  147. package/dist/verifications/getPOVerification.d.ts +19 -16
  148. package/dist/verifications/getPOVerification.js +105 -94
  149. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  150. package/dist/verifications/getVerifiedBy.js +19 -19
  151. package/dist/verifications/index.d.ts +5 -5
  152. package/dist/verifications/index.js +21 -21
  153. package/dist/verifications/maybeRereference.d.ts +1 -1
  154. package/dist/verifications/maybeRereference.js +10 -10
  155. package/dist/verifications/safeHarbour.d.ts +20 -20
  156. package/dist/verifications/safeHarbour.js +67 -74
  157. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
  158. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
  159. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
  160. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
  161. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  162. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
  163. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  164. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
  165. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  166. package/dist/verifications/verifyCheck/index.js +21 -21
  167. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
  168. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
  169. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
  170. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
  171. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
  172. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  173. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  174. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  175. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  176. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  177. package/dist/verifications/verifyCheck/operations/index.js +18 -18
  178. package/package.json +13 -10
  179. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  180. package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
  181. package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
  182. package/dist/rules/helpers/getValueFromPath.js +0 -35
  183. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
  184. package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
  185. package/dist/rules/isScoreResultValid.d.ts +0 -2
  186. package/dist/rules/isScoreResultValid.js +0 -9
  187. package/dist/rules/operators/array.d.ts +0 -2
  188. package/dist/rules/operators/array.js +0 -74
  189. package/dist/rules/types/operators.d.ts +0 -19
  190. package/dist/rules/types/operators.js +0 -2
  191. package/dist/rules/types/score.d.ts +0 -50
  192. package/dist/rules/types/score.js +0 -2
  193. package/dist/util/conditional.d.ts +0 -7
  194. package/dist/util/conditional.js +0 -15
  195. package/dist/util/hash.js +0 -11
  196. package/dist/verifications/checkSingleVerification.d.ts +0 -9
  197. package/dist/verifications/checkSingleVerification.js +0 -29
  198. package/dist/verifications/checkVerifications.js +0 -16
  199. package/dist/verifications/checkVerificationsNew.js +0 -16
  200. package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
  201. package/dist/verifications/getOwnRealVerifications.js +0 -64
  202. package/dist/verifications/getRealVerifications.d.ts +0 -22
  203. package/dist/verifications/getRealVerifications.js +0 -71
  204. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
  205. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
  206. package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
  207. package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
  208. package/dist/verifications/verifyCheck/util/index.js +0 -14
@@ -1,39 +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
+ "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;
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 +1 @@
1
- export {};
1
+ export {};
@@ -1,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkSomeoneElsesVerifications = void 0;
4
- const util_1 = require("../../../util");
5
- /** @internal */
6
- const checkSomeoneElsesVerifications = 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.checkSomeoneElsesVerifications = checkSomeoneElsesVerifications;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkSomeoneElsesVerifications = void 0;
4
+ const util_1 = require("../../../util");
5
+ /** @internal */
6
+ const checkSomeoneElsesVerifications = 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.checkSomeoneElsesVerifications = checkSomeoneElsesVerifications;
@@ -1,2 +1,2 @@
1
- export * from "./checkOwnVerification";
2
- export * from "./checkSomeoneElsesVerifications";
1
+ export * from "./checkOwnVerification";
2
+ export * from "./checkSomeoneElsesVerifications";
@@ -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("./checkOwnVerification"), exports);
18
- __exportStar(require("./checkSomeoneElsesVerifications"), 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("./checkOwnVerification"), exports);
18
+ __exportStar(require("./checkSomeoneElsesVerifications"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytio/core",
3
- "version": "10.1.0",
3
+ "version": "11.1.0",
4
4
  "license": "MIT",
5
5
  "main": "index",
6
6
  "types": "index",
@@ -12,19 +12,18 @@
12
12
  ],
13
13
  "scripts": {
14
14
  "docs": "sh ../../scripts/generate-docs.sh",
15
- "build": "tsc && find dist -path \"*/__tests__*\" -delete && rm -rf dist/setupTests*",
16
- "test": "jest"
15
+ "build": "tsc && rimraf dist/jest.setup.* dist/**/__tests__",
16
+ "test": "jest && yarn docs"
17
17
  },
18
18
  "dependencies": {
19
19
  "@raytio/maxcryptor": "3.1.0",
20
- "@raytio/types": "6.0.2",
21
- "ramda": "0.28.0"
20
+ "@raytio/types": "7.1.0",
21
+ "ramda": "0.29.0"
22
22
  },
23
23
  "devDependencies": {
24
- "@types/ramda": "0.28.15",
25
- "jest": "28.1.3",
26
- "localstorage-polyfill": "1.0.1",
27
- "ts-jest": "28.0.7"
24
+ "@types/ramda": "0.29.0",
25
+ "jest": "29.5.0",
26
+ "ts-jest": "29.1.0"
28
27
  },
29
28
  "jest": {
30
29
  "transform": {
@@ -54,10 +53,14 @@
54
53
  "jest-junit"
55
54
  ],
56
55
  "setupFilesAfterEnv": [
57
- "./src/setupTests.js"
56
+ "./src/jest.setup.ts"
58
57
  ]
59
58
  },
60
59
  "jest-junit": {
61
60
  "outputDirectory": "../../tmp"
61
+ },
62
+ "engineStrict": true,
63
+ "engines": {
64
+ "node": ">=18"
62
65
  }
63
66
  }
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,2 +0,0 @@
1
- import { RuleData, ValuePath } from "../types";
2
- export declare function getValueFromPath(path: ValuePath, data: RuleData): unknown;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValueFromPath = void 0;
4
- const general_1 = require("../../general");
5
- function getValueFromPath(path, data) {
6
- var _a, _b, _c, _d, _e;
7
- const type = path.split("|")[0];
8
- switch (type) {
9
- case "field": {
10
- const [, schemaName, fieldName, attr] = path.split("|");
11
- (0, general_1.assertSafeProperty)(schemaName);
12
- (0, general_1.assertSafeProperty)(fieldName);
13
- (0, general_1.assertSafeProperty)(attr);
14
- if (attr === "meta") {
15
- return (_b = (_a = data[schemaName]) === null || _a === void 0 ? void 0 : _a.properties[fieldName]) === null || _b === void 0 ? void 0 : _b.hField;
16
- }
17
- if (attr === "value") {
18
- return (_d = (_c = data[schemaName]) === null || _c === void 0 ? void 0 : _c.properties[fieldName]) === null || _d === void 0 ? void 0 : _d.value;
19
- }
20
- throw new Error(`Invalid ValuePath[3] for field (${attr})`);
21
- }
22
- case "schema": {
23
- const [, schemaName, attr] = path.split("|");
24
- (0, general_1.assertSafeProperty)(schemaName);
25
- (0, general_1.assertSafeProperty)(attr);
26
- if (attr === "meta") {
27
- return (_e = data[schemaName]) === null || _e === void 0 ? void 0 : _e.hSchema;
28
- }
29
- throw new Error(`Invalid ValuePath[2] for schema (${attr})`);
30
- }
31
- default:
32
- throw new Error(`Invalid ValuePath[0] (${type})`);
33
- }
34
- }
35
- exports.getValueFromPath = getValueFromPath;
@@ -1,3 +0,0 @@
1
- import { ScoreThreshold } from "../types";
2
- /** @ignore json converts non-finite numbers to `null` so we need to fix this */
3
- export declare const rebuildInfiniteValues: (list: readonly ScoreThreshold[]) => ScoreThreshold[];
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rebuildInfiniteValues = void 0;
4
- const ramda_1 = require("ramda");
5
- /** @ignore json converts non-finite numbers to `null` so we need to fix this */
6
- exports.rebuildInfiniteValues = (0, ramda_1.pipe)((0, ramda_1.adjust)(0, v => (Object.assign(Object.assign({}, v), { from: -Infinity }))), (0, ramda_1.adjust)(-1, v => (Object.assign(Object.assign({}, v), { to: Infinity }))));
@@ -1,2 +0,0 @@
1
- import { ScoreResult } from "./calculateScore";
2
- export declare const isScoreResultValid: (x: unknown) => x is ScoreResult;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isScoreResultValid = void 0;
4
- /** @internal - separate function so that TS understands whats going on */
5
- const isObjectLike = (x) => typeof x === "object" && !!x && "score" in x && "category" in x;
6
- const isScoreResultValid = (x) => isObjectLike(x) &&
7
- typeof x.category === "string" &&
8
- typeof x.score === "number";
9
- exports.isScoreResultValid = isScoreResultValid;
@@ -1,2 +0,0 @@
1
- import { OperatorID, OperatorDef } from "../types";
2
- export declare const arrayOperators: Partial<Record<OperatorID, OperatorDef>>;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arrayOperators = void 0;
4
- exports.arrayOperators = {
5
- // TODO: support these two
6
- // "Array<T> containsItem T": {
7
- // rhsFormat: " contains item {item}",
8
- // operands: [
9
- // { name: "array", type: "Array" },
10
- // { name: "item", type: "*" },
11
- // ],
12
- // implementation<T>(array: T[], item: T) {
13
- // return array.includes(item);
14
- // },
15
- // },
16
- // "Array<T> doesNotContainItem T": {
17
- // rhsFormat: " does not contain item {item}",
18
- // operands: [
19
- // { name: "array", type: "Array" },
20
- // { name: "item", type: "*" },
21
- // ],
22
- // implementation<T>(array: T[], item: T) {
23
- // return !array.includes(item);
24
- // },
25
- // },
26
- "Array length== Number": {
27
- rhsFormat: " length == {num}",
28
- operands: [
29
- { name: "str", type: "Array" },
30
- { name: "num", type: "Number" },
31
- ],
32
- implementation: (arr, num) => arr.length === num,
33
- },
34
- "Array length!= Number": {
35
- rhsFormat: " length != {num}",
36
- operands: [
37
- { name: "str", type: "Array" },
38
- { name: "num", type: "Number" },
39
- ],
40
- implementation: (arr, num) => arr.length !== num,
41
- },
42
- "Array length>= Number": {
43
- rhsFormat: " length >= {num}",
44
- operands: [
45
- { name: "str", type: "Array" },
46
- { name: "num", type: "Number" },
47
- ],
48
- implementation: (arr, num) => arr.length >= num,
49
- },
50
- "Array length<= Number": {
51
- rhsFormat: " length <= {num}",
52
- operands: [
53
- { name: "str", type: "Array" },
54
- { name: "num", type: "Number" },
55
- ],
56
- implementation: (arr, num) => arr.length <= num,
57
- },
58
- "Array length< Number": {
59
- rhsFormat: " length < {num}",
60
- operands: [
61
- { name: "str", type: "Array" },
62
- { name: "num", type: "Number" },
63
- ],
64
- implementation: (arr, num) => arr.length < num,
65
- },
66
- "Array length> Number": {
67
- rhsFormat: " length > {num}",
68
- operands: [
69
- { name: "str", type: "Array" },
70
- { name: "num", type: "Number" },
71
- ],
72
- implementation: (arr, num) => arr.length > num,
73
- },
74
- };
@@ -1,19 +0,0 @@
1
- import { ValueType } from "./dataValueTypes";
2
- /**
3
- * these are just IDs, the string is never parsed by anything.
4
- *
5
- * However, since they're saved into the WizardConfig schema,
6
- * we can't just rename or remove any, since that would break
7
- * existing rules.
8
- */
9
- export declare type OperatorID = "Bool == Bool" | "Bool != Bool" | "Number == Number" | "Number != Number" | "Number <= Number" | "Number >= Number" | "Number < Number" | "Number > Number" | "Date isValid" | "Date isInvalid" | "Date isBefore Date" | "Date isAfter Date" | "Date == Date" | "Date != Date" | "Date isMoreThan Number DateUnits ago" | "Date isMoreThan Number DateUnits in the future" | "Date isBetween Date Date" | "String == String" | "String != String" | "String contains String" | "String doesNotContain String" | "String startsWith String" | "String doesNotStartWith String" | "String endsWith String" | "String doesNotEndWith String" | "String length== Number" | "String length!= Number" | "String length<= Number" | "String length>= Number" | "String length< Number" | "String length> Number" | "String mathches RegEx" | "Array<T> containsItem T" | "Array<T> doesNotContainItem T" | "Array length== Number" | "Array length!= Number" | "Array length<= Number" | "Array length>= Number" | "Array length< Number" | "Array length> Number" | "HField verifiedBy String" | "HField wasShared" | "HField wasNotShared" | "HField hasVerStatus FieldVerification" | "HField cameFromSchema String" | "HField didNotComeFromSchema String" | "HSchema verifiedBy String" | "HSchema wasShared" | "HSchema wasNotShared" | "HSchema hasVerStatus POVerification";
10
- export declare type OperatorDef = {
11
- /** string to format the display of the operator and RHS */
12
- rhsFormat: string;
13
- /** the first operand is the LHS, all others are RHS */
14
- operands: {
15
- type: ValueType;
16
- name: string;
17
- }[];
18
- implementation: (...args: any[]) => boolean;
19
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,50 +0,0 @@
1
- import { FieldValueTypes, HField, HSchema, ValueDef, GetTSType } from "./dataValueTypes";
2
- import { OperatorID } from "./operators";
3
- export declare type ASTScoreConditionNode = {
4
- type: "ScoreCondition";
5
- operator: OperatorID;
6
- values: ValueDef[];
7
- };
8
- export declare type ASTLanguageOperatorNode = {
9
- type: "LanguageOperator";
10
- operator: "OR" | "AND";
11
- children: ASTNode[];
12
- };
13
- export declare type ASTNode = ASTLanguageOperatorNode | ASTScoreConditionNode;
14
- export declare type ScoreRule = {
15
- name: string;
16
- description: string;
17
- /** must be an integer */
18
- trueWeight: number;
19
- /** must be an integer */
20
- falseWeight: number;
21
- /** must have a single root node */
22
- tree: [ASTNode];
23
- };
24
- /** e.g. 0-10 is "red". We only work with integers. Comparisons use >= and <= */
25
- export declare type ScoreThreshold = {
26
- from: number;
27
- to: number;
28
- name: string;
29
- };
30
- /**
31
- * the big object for configuring score rules
32
- */
33
- export declare type ScoreConfig = {
34
- combinator: "+" | "*";
35
- scoreThresholds: ScoreThreshold[];
36
- rules: ScoreRule[];
37
- };
38
- export declare type RuleDataProperty<T extends FieldValueTypes> = {
39
- type: T;
40
- value: GetTSType<T>;
41
- hField: HField;
42
- };
43
- export declare type RuleData = {
44
- [schemaName: string]: {
45
- hSchema: HSchema;
46
- properties: {
47
- [fieldName: string]: RuleDataProperty<FieldValueTypes>;
48
- };
49
- };
50
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
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 {};
@@ -1,15 +0,0 @@
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;
package/dist/util/hash.js DELETED
@@ -1,11 +0,0 @@
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,9 +0,0 @@
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 {};
@@ -1,29 +0,0 @@
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;
@@ -1,16 +0,0 @@
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;
@@ -1,16 +0,0 @@
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,14 +0,0 @@
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 {};
@@ -1,64 +0,0 @@
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;