@raytio/core 10.1.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +100 -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/index.d.ts +1 -1
  100. package/dist/schema/index.js +17 -17
  101. package/dist/schema/labels.d.ts +2 -2
  102. package/dist/schema/labels.js +20 -20
  103. package/dist/util/canonicalJsonify.d.ts +1 -1
  104. package/dist/util/canonicalJsonify.js +50 -50
  105. package/dist/util/handleResponse.d.ts +1 -1
  106. package/dist/util/handleResponse.js +21 -21
  107. package/dist/util/index.d.ts +2 -2
  108. package/dist/util/index.js +18 -18
  109. package/dist/verifications/cleanInstance.d.ts +9 -9
  110. package/dist/verifications/cleanInstance.js +15 -15
  111. package/dist/verifications/getPOVerification.d.ts +19 -16
  112. package/dist/verifications/getPOVerification.js +105 -94
  113. package/dist/verifications/getVerifiedBy.d.ts +1 -1
  114. package/dist/verifications/getVerifiedBy.js +19 -19
  115. package/dist/verifications/index.d.ts +5 -5
  116. package/dist/verifications/index.js +21 -21
  117. package/dist/verifications/maybeRereference.d.ts +1 -1
  118. package/dist/verifications/maybeRereference.js +10 -10
  119. package/dist/verifications/safeHarbour.d.ts +20 -20
  120. package/dist/verifications/safeHarbour.js +74 -74
  121. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
  122. package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
  123. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
  124. package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
  125. package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
  126. package/dist/verifications/verifyCheck/getOwnRealVerifications.js +66 -64
  127. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
  128. package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -72
  129. package/dist/verifications/verifyCheck/index.d.ts +3 -3
  130. package/dist/verifications/verifyCheck/index.js +21 -21
  131. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
  132. package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
  133. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
  134. package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
  135. package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
  136. package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
  137. package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
  138. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
  139. package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
  140. package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
  141. package/dist/verifications/verifyCheck/operations/index.js +18 -18
  142. package/package.json +13 -10
  143. package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
  144. package/dist/rules/helpers/getLhsTypeofValue.js +0 -1
  145. package/dist/rules/helpers/getValueFromPath.d.ts +0 -2
  146. package/dist/rules/helpers/getValueFromPath.js +0 -35
  147. package/dist/rules/helpers/rebuildInfiniteValues.d.ts +0 -3
  148. package/dist/rules/helpers/rebuildInfiniteValues.js +0 -6
  149. package/dist/rules/isScoreResultValid.d.ts +0 -2
  150. package/dist/rules/isScoreResultValid.js +0 -9
  151. package/dist/rules/operators/array.d.ts +0 -2
  152. package/dist/rules/operators/array.js +0 -74
  153. package/dist/rules/types/operators.d.ts +0 -19
  154. package/dist/rules/types/operators.js +0 -2
  155. package/dist/rules/types/score.d.ts +0 -50
  156. package/dist/rules/types/score.js +0 -2
  157. package/dist/util/conditional.d.ts +0 -7
  158. package/dist/util/conditional.js +0 -15
  159. package/dist/util/hash.js +0 -11
  160. package/dist/verifications/checkSingleVerification.d.ts +0 -9
  161. package/dist/verifications/checkSingleVerification.js +0 -29
  162. package/dist/verifications/checkVerifications.js +0 -16
  163. package/dist/verifications/checkVerificationsNew.js +0 -16
  164. package/dist/verifications/getOwnRealVerifications.d.ts +0 -14
  165. package/dist/verifications/getOwnRealVerifications.js +0 -64
  166. package/dist/verifications/getRealVerifications.d.ts +0 -22
  167. package/dist/verifications/getRealVerifications.js +0 -71
  168. package/dist/verifications/verifyCheck/util/canonicalJsonify.js +0 -48
  169. package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +0 -2
  170. package/dist/verifications/verifyCheck/util/getValuesForAField.js +0 -9
  171. package/dist/verifications/verifyCheck/util/index.d.ts +0 -2
  172. package/dist/verifications/verifyCheck/util/index.js +0 -14
@@ -1,64 +1,66 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOwnRealVerifications = void 0;
4
- const general_1 = require("../../general");
5
- const maybeRereference_1 = require("../maybeRereference");
6
- const operations_1 = require("./operations");
7
- /**
8
- * Given a list of verifications and decrypted profile objects, this function
9
- * locally verifies the credibility of the signatures in the verifications.
10
- *
11
- * This function does NOT call the API, except to fetch the public key.
12
- * @returns a list of authentic RealVer
13
- */
14
- const getOwnRealVerifications = async ({ verifications, profileObjects, userId, }) => {
15
- const realVers = [];
16
- // this code is deliberaly written using for-loops instead of Promise.all,
17
- // because attempting hundreds of webcrypto operations simultaneously will
18
- // probably upset some heritage web browser.
19
- for (const ver of verifications) {
20
- for (const { data, signature } of ver.properties.verifications) {
21
- const sourcePO = profileObjects.find(PO => PO.n_id === data.source_n_id);
22
- if (!sourcePO)
23
- continue;
24
- const value = sourcePO.properties[data.field];
25
- if (!value)
26
- continue;
27
- /**
28
- * this does NOT mean that the data is correct. It means the
29
- * verification is genuinely signed by raytio, but the data
30
- * might be bogus (i.e. `passed: false`)
31
- */
32
- const isGenuine = await (0, operations_1.checkOwnVerification)({
33
- verObject: data,
34
- userId,
35
- value: (0, maybeRereference_1.maybeRereference)(value),
36
- signature,
37
- });
38
- if (!isGenuine)
39
- continue;
40
- // a "RealVer" is what the client likes to deal with,
41
- // rather than the "VerificationPayload" which is stored on the API.
42
- // eslint-disable-next-line fp/no-mutating-methods
43
- realVers.push({
44
- fieldName: data.field,
45
- value,
46
- provider: {
47
- dataSourceNId: data.verifier_source_id,
48
- serviceProviderNId: data.verifier_service_id,
49
- verifierNId: data.verifier_id,
50
- date: (0, general_1.repairDate)(data.verification_date),
51
- },
52
- expired: data.valid_until ? (0, general_1.repairDate)(data.valid_until) : false,
53
- metadata: data.metadata,
54
- xId: data.request_div,
55
- signature,
56
- verified: data.passed,
57
- nID: ver.n_id,
58
- belongsToNId: data.source_n_id,
59
- });
60
- }
61
- }
62
- return realVers;
63
- };
64
- exports.getOwnRealVerifications = getOwnRealVerifications;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOwnRealVerifications = void 0;
4
+ const general_1 = require("../../general");
5
+ const maybeRereference_1 = require("../maybeRereference");
6
+ const operations_1 = require("./operations");
7
+ /**
8
+ * Given a list of verifications and decrypted profile objects, this function
9
+ * locally verifies the credibility of the signatures in the verifications.
10
+ *
11
+ * This function does NOT call the API, except to fetch the public key.
12
+ * @returns a list of authentic RealVer
13
+ */
14
+ const getOwnRealVerifications = async ({ verifications, profileObjects, userId, }) => {
15
+ const realVers = [];
16
+ // this code is deliberaly written using for-loops instead of Promise.all,
17
+ // because attempting hundreds of webcrypto operations simultaneously will
18
+ // probably upset some heritage web browser.
19
+ for (const ver of verifications) {
20
+ for (const { data, signature } of ver.properties.verifications) {
21
+ const sourcePO = profileObjects.find(PO => PO.n_id === data.source_n_id);
22
+ if (!sourcePO)
23
+ continue;
24
+ const value = sourcePO.properties[data.field];
25
+ if (!value)
26
+ continue;
27
+ /**
28
+ * this does NOT mean that the data is correct. It means the
29
+ * verification is genuinely signed by raytio, but the data
30
+ * might be bogus (i.e. `passed: false`)
31
+ */
32
+ const isGenuine = await (0, operations_1.checkOwnVerification)({
33
+ verObject: data,
34
+ userId,
35
+ value: (0, maybeRereference_1.maybeRereference)(value),
36
+ signature,
37
+ });
38
+ if (!isGenuine)
39
+ continue;
40
+ // a "RealVer" is what the client likes to deal with,
41
+ // rather than the "VerificationPayload" which is stored on the API.
42
+ // eslint-disable-next-line fp/no-mutating-methods
43
+ realVers.push({
44
+ fieldName: data.field,
45
+ value,
46
+ provider: {
47
+ dataSourceNId: data.verifier_source_id,
48
+ serviceProviderNId: data.verifier_service_id,
49
+ verifierNId: data.verifier_id,
50
+ date: (0, general_1.repairDate)(data.verification_date),
51
+ },
52
+ expired: ver.properties.valid_until
53
+ ? (0, general_1.repairDate)(ver.properties.valid_until)
54
+ : false,
55
+ metadata: data.metadata,
56
+ xId: data.request_div,
57
+ signature,
58
+ verified: data.passed,
59
+ nID: ver.n_id,
60
+ belongsToNId: data.source_n_id,
61
+ });
62
+ }
63
+ }
64
+ return realVers;
65
+ };
66
+ exports.getOwnRealVerifications = getOwnRealVerifications;
@@ -1,19 +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
+ import { ProfileObject, Verification, RealVer, AId } from "@raytio/types";
2
+ 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,72 +1,72 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSomeoneElsesRealVerifications = void 0;
4
- const ramda_1 = require("ramda");
5
- const operations_1 = require("./operations");
6
- const maybeRereference_1 = require("../maybeRereference");
7
- const crypto_1 = require("../../crypto");
8
- const general_1 = require("../../general");
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
- *
17
- * ❗ prefer `getOwnRealVerifications` if the data to be verified belongs to the current user.
18
- *
19
- * @returns a list of fileNames/values that are verified.
20
- */
21
- const getSomeoneElsesRealVerifications = async ({ aId, apiUrl, verifications, profileObjects, controller, }) => {
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 send the whole thing to the API.
25
- const toVerify = verifications.flatMap(ver => {
26
- const values = getValuesForAField(ver.properties.field, profileObjects);
27
- return values.flatMap(value => ver.properties.verifications.map(({ signature }) => ({
28
- verifications: [
29
- Object.assign({ signature }, (ver.n_id.startsWith("HASHED::")
30
- ? {
31
- hashed_n_id: ver.n_id.split("::")[1],
32
- a_id: ver.n_id.split("::")[2],
33
- }
34
- : { n_id: ver.n_id })),
35
- ],
36
- data_to_verify: [{ value: (0, maybeRereference_1.maybeRereference)(value) }],
37
- })));
38
- });
39
- // the API can't cope with an empty array
40
- if (!toVerify.length)
41
- return [];
42
- const apiResponse = await (0, operations_1.checkSomeoneElsesVerifications)({
43
- apiUrl,
44
- toVerify,
45
- controller,
46
- });
47
- // do NOT expose the `verified` prop from the /verify_check API to avoid semantic confusion,
48
- // since verified: true does not mean that the verification is verified!
49
- const realVers = apiResponse
50
- .filter(x => x.verified)
51
- .map(({ signature, data, n_id: nID, valid_until }) => ({
52
- fieldName: data.field,
53
- value: data.value,
54
- provider: {
55
- dataSourceNId: data.verifier_source_id,
56
- serviceProviderNId: data.verifier_service_id,
57
- verifierNId: data.verifier_id,
58
- date: (0, general_1.repairDate)(data.verification_date),
59
- },
60
- expired: valid_until ? (0, general_1.repairDate)(valid_until) : false,
61
- metadata: data.metadata,
62
- xId: data.request_div,
63
- signature,
64
- verified: data.passed,
65
- nID,
66
- belongsToNId: data.source_hashed_n_id
67
- ? `HASHED::${data.source_hashed_n_id}::${aId}`
68
- : data.source_n_id,
69
- }));
70
- return realVers;
71
- };
72
- exports.getSomeoneElsesRealVerifications = getSomeoneElsesRealVerifications;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSomeoneElsesRealVerifications = void 0;
4
+ const ramda_1 = require("ramda");
5
+ const operations_1 = require("./operations");
6
+ const maybeRereference_1 = require("../maybeRereference");
7
+ const crypto_1 = require("../../crypto");
8
+ const general_1 = require("../../general");
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
+ *
17
+ * ❗ prefer `getOwnRealVerifications` if the data to be verified belongs to the current user.
18
+ *
19
+ * @returns a list of fileNames/values that are verified.
20
+ */
21
+ const getSomeoneElsesRealVerifications = async ({ aId, apiUrl, verifications, profileObjects, controller, }) => {
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 send the whole thing to the API.
25
+ const toVerify = verifications.flatMap(ver => {
26
+ const values = getValuesForAField(ver.properties.field, profileObjects);
27
+ return values.flatMap(value => ver.properties.verifications.map(({ signature }) => ({
28
+ verifications: [
29
+ Object.assign({ signature }, (ver.n_id.startsWith("HASHED::")
30
+ ? {
31
+ hashed_n_id: ver.n_id.split("::")[1],
32
+ a_id: ver.n_id.split("::")[2],
33
+ }
34
+ : { n_id: ver.n_id })),
35
+ ],
36
+ data_to_verify: [{ value: (0, maybeRereference_1.maybeRereference)(value) }],
37
+ })));
38
+ });
39
+ // the API can't cope with an empty array
40
+ if (!toVerify.length)
41
+ return [];
42
+ const apiResponse = await (0, operations_1.checkSomeoneElsesVerifications)({
43
+ apiUrl,
44
+ toVerify,
45
+ controller,
46
+ });
47
+ // do NOT expose the `verified` prop from the /verify_check API to avoid semantic confusion,
48
+ // since verified: true does not mean that the verification is verified!
49
+ const realVers = apiResponse
50
+ .filter(x => x.verified)
51
+ .map(({ signature, data, n_id: nID, valid_until }) => ({
52
+ fieldName: data.field,
53
+ value: data.value,
54
+ provider: {
55
+ dataSourceNId: data.verifier_source_id,
56
+ serviceProviderNId: data.verifier_service_id,
57
+ verifierNId: data.verifier_id,
58
+ date: (0, general_1.repairDate)(data.verification_date),
59
+ },
60
+ expired: valid_until ? (0, general_1.repairDate)(valid_until) : false,
61
+ metadata: data.metadata,
62
+ xId: data.request_div,
63
+ signature,
64
+ verified: data.passed,
65
+ nID,
66
+ belongsToNId: data.source_hashed_n_id
67
+ ? `HASHED::${data.source_hashed_n_id}::${aId}`
68
+ : data.source_n_id,
69
+ }));
70
+ return realVers;
71
+ };
72
+ exports.getSomeoneElsesRealVerifications = getSomeoneElsesRealVerifications;
@@ -1,3 +1,3 @@
1
- export * from "./getOwnRealVerifications";
2
- export * from "./getSomeoneElsesRealVerifications";
3
- export { checkJsonSignature } from "./operations";
1
+ export * from "./getOwnRealVerifications";
2
+ export * from "./getSomeoneElsesRealVerifications";
3
+ export { checkJsonSignature } from "./operations";
@@ -1,21 +1,21 @@
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
- exports.checkJsonSignature = void 0;
18
- __exportStar(require("./getOwnRealVerifications"), exports);
19
- __exportStar(require("./getSomeoneElsesRealVerifications"), exports);
20
- var operations_1 = require("./operations");
21
- Object.defineProperty(exports, "checkJsonSignature", { enumerable: true, get: function () { return operations_1.checkJsonSignature; } });
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
+ exports.checkJsonSignature = void 0;
18
+ __exportStar(require("./getOwnRealVerifications"), exports);
19
+ __exportStar(require("./getSomeoneElsesRealVerifications"), exports);
20
+ var operations_1 = require("./operations");
21
+ Object.defineProperty(exports, "checkJsonSignature", { enumerable: true, get: function () { return operations_1.checkJsonSignature; } });
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const __1 = require("..");
7
+ const util_1 = require("../../../../util");
8
+ const checkOwnVerification_1 = require("../checkOwnVerification");
9
+ const sampleBundle_json_1 = __importDefault(require("./sampleBundle.json"));
10
+ Reflect.set(global, "fetch", jest.fn().mockResolvedValue({
11
+ text: async () => `-----BEGIN PUBLIC KEY-----
12
+ MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAn9QtCqYa3H3ipFFU0xP3
13
+ n6r7KHS3GMbh0h/xzel57HhCIaXDYjUeUtgUNtzm+uElb/qzGn50xQRzVqO32vKB
14
+ ZAW2kYyZ2+R5ruk9CSxr7K4Vk1FtDMcUCzqxm0eycFD2xbLsN3feRc3BMjfdaQ7P
15
+ OMAquVHxDqSHlL8hv3VEoPHyRz04ipGAlRzVCEQPQ8sZDNsgXo76OzLGlT4bEUGn
16
+ mzH+FhS6DGts+X5b5ZW1iCzQTNZM3yzk947dyMsJVHwx+VyTT/o8D6/zWrZnmjK+
17
+ lGOihted4AmvJePcF0kWP5XXpXiX12dRsluhXkIXkgmj9MuoxkdeqGuAxiZUVc5a
18
+ zWfZao3Y3O5UwtRIEJOeZmr6EkYfdhg+JuDjacZ53Dg6WduX+5nG7/UqpepqtmHe
19
+ R0Wsi2K8nXxkFkZmPy+s7e4+ABjN+IRrQYUJALziMjskqjxll8zKn+4Phmk8dIJw
20
+ Gut0BoM+DIwDu0uZaUprz7fSgNmYHHEiIFbOMVHiOn8oZAZbJXXbUbFIUYXA8u9+
21
+ J1Z+QEpgw+rhGzOf/TSeHfMC9nNbWgYglluAJusWf2XwG/t/VlhtzviHCVGEL7HQ
22
+ jQE5DrM7vaTg6Gu9bjKuoeLIRzbOYK6qAWFoa0CLcN84PLjhDSRw2duatP08hcWg
23
+ jTgOkLWnBFE7NyRU93uPp68CAwEAAQ==
24
+ -----END PUBLIC KEY-----`,
25
+ }));
26
+ describe("checkOwnVerification", () => {
27
+ it("works for a real PO", async () => {
28
+ //
29
+ // This is an important integration test from ca. 2021-12-02.
30
+ // If it is failing, it means our code no longer matches the
31
+ // backend, and all existing verifications will be erroneously
32
+ // considered invalid
33
+ //
34
+ const signature = "e3ra4x0iwAvcLURf2Je8IpibByd6dvdIMUxsh5ZVOUvnQYsY99U2RkZWk63nBePy6bVWqnYnhrAR\n7bGbPpf2GYWq1WymKro9SGB552xWU1BIyJ5+78agWXDOqIthsnuRNoos52u46Mh6bq6taIj0vip6\nwIbnN8A0eS/Ulh2PpzrXKbjM6ITKDUOjEMSgbO7sDbRzZ1GbOm3Bh0WMvtniEk9dsN6wwAYI2XXb\nhaHjKfKGxv73DpFlv04+371VfP24NN8R6RGgD5YUqn9iFiHN17GlPmDGjzId/cSwz9tMshUgV2ZA\nylkAcRIyao6mYDQk75BQs6eK/dOlvUeWjEWgRpeYSJ3/5GkqiJn906+7Rj7iJ6P9+zSGN+OlhW3p\n7D0gS70ZqwLG5AVNB+N9PCUZYdaHHulQc5W8devQB3GImKhjHhH6sKLd2JdwTWeEW/SAnnqzTLTJ\nRrg7/XDoYIH20x+FVYVom5QYbjHvxdbHML19+zw0jJuhiPgKmm1bKt8fFv7T1nOeDEQa4hRZfdNu\nmdxZPt0ilBsIN7cXYn+X3nKZuEo3udCvNQx+zjSiJfKqBEw2grqBCDrF1u2HWyL77pXPJNMfxlRN\nkedWDSFSG5rXKDC0ffVRXs3Q2our6DCT2RgdDoZejBm3jKckUwOxnqzG5yTbjWsmGdduo/ePh/g=\n";
35
+ // nId of this ver is "44371109-1a5c-41e7-b213-ff3befe194fc"
36
+ const verObject = {
37
+ passed: true,
38
+ schema: "ss_NZ_Company",
39
+ verifier_div: "ff341897-b847-4a56-8669-a7bef019758a",
40
+ source_n_id: "f73e33bd-6673-4069-9ed4-76b57c8da2de",
41
+ type: null,
42
+ verifier_service_id: "",
43
+ verification_date: "2021-11-16T20:35:59.147817",
44
+ request_div: "95cc6670-f704-4221-beb9-3559ac47bce9",
45
+ source: "NZ_COMPANY",
46
+ field: "entity_type_description",
47
+ v_id: "aec1c37d-f9d7-461a-b15d-1a83e41e981a",
48
+ verifier_source_id: "185e9cdc-e8fb-4147-b996-3c2dd60fab59",
49
+ verifier_id: "185e9cdc-e8fb-4147-b996-3c2dd60fab59",
50
+ metadata: {
51
+ date_retrieved: "2021-11-16T20:36:00.732608",
52
+ url: "https://api-dev.rayt.io/w-nz-mbie/v1/entities/9429033226651",
53
+ },
54
+ };
55
+ const value = "NZ Limited Company";
56
+ const userId = "fd9c4903-65c2-4b75-b454-4fda6b682f3e"; // for 27july21 🦈
57
+ expect(await (0, checkOwnVerification_1.checkOwnVerification)({ value, signature, userId, verObject })).toBe(true);
58
+ });
59
+ it("errors if you forget to supply the uId", async () => {
60
+ await expect(() => (0, checkOwnVerification_1.checkOwnVerification)({
61
+ value: "",
62
+ signature: "",
63
+ userId: "",
64
+ verObject: {},
65
+ })).rejects.toThrow(new Error("No userId supplied"));
66
+ });
67
+ });
68
+ describe("checkSignature", () => {
69
+ it("works", async () => {
70
+ // same test as the backend
71
+ // see https://gitlab.com/raytio/mono/-/blob/devo/common/signing/tests/test_sign.py#L104
72
+ const jwk = {
73
+ kty: "RSA",
74
+ alg: "PS512",
75
+ key_ops: ["verify"],
76
+ ext: true,
77
+ n: "wD6Oy9Wts0BAI7ObvxD73MNppefO3XMEMSZSxi1JTyfmavzV59rXMleRK5IBoY7ghOyy33-6131qQyh6cfbz5q67mHmTBEJmOccmw1hbl7SVSUHXOuUGUq5C7p3qnxeUhOFtxBlhMdIj0vkZ923lPHZpw9Yhit-RlLwW01Qnh-mGNmWMuUqrcj-WDb0WbIxjkaUR_DEIELkFiD9nF56mv3A6bMX_-ZJaF21ChD_b8qy_unQhNWrrUUwGzUaEMyw1dbPnvQ1iouMADlRlDBojZB0rWveK0PswqnUy3bB9dqVjpn50lN3CgdGeOPVVOcaLHhX0OLOCERpZY0hbuajfGIORMqnvF1dZJ_0OPrm-etpHK3ngK2qJ-mSjobd9DP_KISe2hAWs0FU4wbgG8U4VgcjYCkuABSh9c3xMEA5xyXV8iwGjTdmsOf4AvbBj1vY1dJVBYeGHuVRm-SxWepoVbYYDPg0366sYiim9IcQG0olxqAfkglB4yAmqYfp_kxqL2Cb8ysgyioHe9vmZDTbfTTm00qVAVKr2bctAgI787VEpS7Ou_2QTPIxYlsQCa-MbdgtUoXQ6__VdRklEaiQ_IFLBZzg5lFNBbF1Qytgav-BLfjZR31T5fhhougzrjBrtDGsSiV8qIvr5ZBfeJCatm1N_atbdjfWG7njoQMRwV5c",
78
+ e: "AQAB",
79
+ };
80
+ const cryptoKey = await crypto.subtle.importKey("jwk", jwk, { name: "RSA-PSS", hash: "SHA-512" }, false, ["verify"]);
81
+ const data = "This is definitely true";
82
+ const signature = "V0r2KI4TBTwyzV8fCmGIL6x3t11ROhG9UJts1VZiap94wXEnEP+TNQ6qVV1v8bWY9uoubYLNzzuVfbn4q1J1ERNJWEM469/A8zNRiptDEmrlfSMBHE2Ahrwn5h0nSjxttOGazqitX+Ir0Qo0itNINpIa5cRC4ttyumauSKFcaGhFHGCuOpQz4xPoCR6ww2UtEvfvomTI5PYedG2XzhOJioZ8P9QtgKDnt+mp5Baq5avRtDpK+gZ8zOHXW8YL5d/oO16K6HDdYe4nGjr4MQU93HJjzQVEtsZqtvwf2BznVSuChGd0kedlal2uIrDQ4H4l6Td1TqW+FJp+EHVdbdrbk+Gql2GwiDAVsIPHDDGfaeIZQSStbr9VgQSm0feqtRlI627VCQ5ewAd1+tEgRiVTz74ya8tmc62WzTF5dbSYkQtllc/SJNWxaMQ+MEBrDyatfRrurTeTXwnRROJ/idJFKGKdxQichNdiuqL/CnBQJc3oYzQNoQXAmIUGDelISY5+XgHKXDs9YX4AVbru/Ina3E86TIekLVOUqg7TJi1hLAdF3RANp48uXk7LuIffzcff5sBUQ0vtHVtyTFwd2Jmt1CiEd9DitMNQT5cjM21IC6uJ4HZ6Ni/fd0N9frZ6Svknd/MMsbM7aqt8z6IgREqYdGY2XLYZCeZ0qmCGW243v3A=";
83
+ const stringifiedData = (0, util_1.canonicalJsonify)(data);
84
+ expect(await (0, checkOwnVerification_1.checkSignature)(cryptoKey, signature, stringifiedData)).toBe(true);
85
+ });
86
+ });
87
+ describe("checkJsonSignature", () => {
88
+ it("can verify a bundled verification", async () => {
89
+ expect(await (0, __1.checkJsonSignature)(sampleBundle_json_1.default.data, sampleBundle_json_1.default.signature)).toBe(true);
90
+ });
91
+ });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const checkSomeoneElsesVerifications_1 = require("../checkSomeoneElsesVerifications");
4
+ const toVerify = [
5
+ {
6
+ verifications: [{ signature: "sig1", n_id: "nid1" }],
7
+ data_to_verify: [{ value: "val1" }],
8
+ },
9
+ {
10
+ verifications: [{ signature: "sig2", n_id: "nid2" }],
11
+ data_to_verify: [{ value: "val2" }],
12
+ },
13
+ ];
14
+ describe("checkSomeoneElsesVerifications", () => {
15
+ it("calls the API and filters out garbage", async () => {
16
+ global.fetch = jest
17
+ .fn()
18
+ .mockImplementation()
19
+ // first fetch request
20
+ .mockImplementationOnce(async () => ({
21
+ json: async () => [{ verified: true }, { verified: false }, {}, {}],
22
+ }));
23
+ const result = await (0, checkSomeoneElsesVerifications_1.checkSomeoneElsesVerifications)({
24
+ apiUrl: "https://example.com",
25
+ toVerify,
26
+ });
27
+ expect(fetch).toHaveBeenCalledTimes(1);
28
+ expect(fetch).toHaveBeenCalledWith("https://example.com/extract_verify/v2/verify_check", {
29
+ body: JSON.stringify(toVerify),
30
+ method: "POST",
31
+ signal: undefined,
32
+ });
33
+ // note how empty objects were filtered out
34
+ expect(result).toStrictEqual([{ verified: true }, { verified: false }]);
35
+ });
36
+ it("throws an error if the API rejects", async () => {
37
+ global.fetch = jest
38
+ .fn()
39
+ .mockImplementation()
40
+ // first fetch request
41
+ .mockImplementationOnce(async () => ({
42
+ json: async () => ({ message: "An API error" }),
43
+ }));
44
+ await expect(() => (0, checkSomeoneElsesVerifications_1.checkSomeoneElsesVerifications)({
45
+ apiUrl: "https://example.com",
46
+ toVerify,
47
+ })).rejects.toThrow(new Error("An API error"));
48
+ });
49
+ });
@@ -0,0 +1,43 @@
1
+ {
2
+ "__comment": "This belongs to 10feb22 🦈",
3
+ "bundle_version": 1,
4
+ "data": {
5
+ "n_id": "f4220899-4af7-4f66-8a00-1bc13936096b",
6
+ "schema": "ss_NZ_Company",
7
+ "fields": {
8
+ "nzbn": {
9
+ "verifiers": [
10
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" },
11
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" }
12
+ ],
13
+ "derivations": []
14
+ },
15
+ "entity_type_description": {
16
+ "verifiers": [
17
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" },
18
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" }
19
+ ],
20
+ "derivations": [],
21
+ "value": "NZ Limited Company"
22
+ },
23
+ "entity_status_description": {
24
+ "verifiers": [
25
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" },
26
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" }
27
+ ],
28
+ "derivations": [],
29
+ "value": "Registered"
30
+ },
31
+ "nz_legal_entity_name": {
32
+ "verifiers": [
33
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" },
34
+ { "verifier_id": "185e9cdc-e8fb-4147-b996-3c2dd60fab59" }
35
+ ],
36
+ "derivations": [],
37
+ "value": "DEPARTMENT OF CONVERSATION LIMITED"
38
+ }
39
+ },
40
+ "valid_until": "2022-03-13T02:26:20.468171"
41
+ },
42
+ "signature": "AiWWrL+S1paYOqJiOtU3qwLTCkkZjwDq3FuHl7oy14IATYOhCeHLf+ca44X1Wc6pYpTQckjKnJZL\nkfgiwNE97aymWIOc+ZZGEb5YhXRNO+inTV4k5zppaDN3n3YAGzn7zMxleh3+opzJqncNaJtpZ0Wv\na9Pu/m4WjyT5ee3Myz6VOOMuVkcaTL4FD8XT7NdCh0ybRevAZ5R9xl0YuWMhvNpf3P6ieTikHXYN\nkKbPTnAhNdBmqV4njSIR66M82Ek0d9VcsX4zhmlhpdCmGRlXLgHEyMCF4iHlCIxSeKtGaOm2QK2R\nOV/lN3VScDNWyD8lPBipcj++5ZGII6BnFFG8LlT3gY/Y/wt8KeH/xgdu0a7Lt6J/BOiGLFfscUmb\nH5K5t48gnQ5BQS+Cf/yhayMV49LlGiK9m1iPlbmuJH1L2/ZM+iLsIrSTGCU0Rpbkw7qvm0dkUNYf\nhvlj/RnUxcy0Lr/84CzLvBhFMmBX+RHlcPrCWpIiibsdaD81kRyvLY2TASLFTeHajfr+UvtP3LVs\n8NGwRQHd6c2/ptxv3ERRUnDtNASatsLe67ZHg9SeF3BDhMHZwU1neYyrBI1TMECasFli5rP5gviq\nC8ZwFQ9lnDDTidWBF8GjRl6ope4wIuNBBkOsIIeyqIJE5BRUH4LhVUnN1be696uCKnWOyOo7fkc=\n"
43
+ }
@@ -1,15 +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 {};
1
+ import { UId, VerificationPayload } from "@raytio/types";
2
+ 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 {};