@raytio/core 9.0.3 → 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.
- package/CHANGELOG.md +161 -0
- package/README.md +77 -4
- package/dist/accessApplication/createAA.d.ts +17 -17
- package/dist/accessApplication/createAA.js +71 -71
- package/dist/accessApplication/index.d.ts +1 -1
- package/dist/accessApplication/index.js +17 -13
- package/dist/crypto/cognitoAttributes.d.ts +15 -15
- package/dist/crypto/cognitoAttributes.js +33 -33
- package/dist/crypto/decryptKeys.d.ts +1 -1
- package/dist/crypto/decryptKeys.js +33 -33
- package/dist/crypto/decryptSharedData.d.ts +26 -26
- package/dist/crypto/decryptSharedData.js +38 -38
- package/dist/crypto/getAADecryptor.d.ts +16 -11
- package/dist/crypto/getAADecryptor.js +20 -20
- package/dist/crypto/helpers.d.ts +18 -18
- package/dist/crypto/helpers.js +26 -26
- package/dist/crypto/index.d.ts +4 -4
- package/dist/crypto/index.js +21 -17
- package/dist/general/conditional.d.ts +17 -7
- package/dist/general/conditional.js +32 -22
- package/dist/general/date.d.ts +2 -0
- package/dist/general/date.js +18 -0
- package/dist/general/index.d.ts +4 -3
- package/dist/general/index.js +20 -15
- package/dist/general/password.d.ts +10 -8
- package/dist/general/password.js +31 -29
- package/dist/general/types.d.ts +6 -6
- package/dist/general/types.js +13 -13
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -18
- package/dist/rules/calculateScore.d.ts +23 -11
- package/dist/rules/calculateScore.js +76 -52
- package/dist/rules/convertInstanceToRuleInput.d.ts +3 -3
- package/dist/rules/convertInstanceToRuleInput.js +139 -139
- package/dist/rules/evaluateScoreCondition.d.ts +2 -2
- package/dist/rules/evaluateScoreCondition.js +45 -45
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.d.ts +8 -8
- package/dist/rules/helpers/addInfiniteThresholdBoundaries.js +11 -11
- package/dist/rules/helpers/checkTypeofValue.d.ts +9 -3
- package/dist/rules/helpers/checkTypeofValue.js +55 -43
- package/dist/rules/helpers/getLhsTypeofValue.d.ts +0 -0
- package/dist/rules/helpers/getLhsTypeofValue.js +1 -0
- package/dist/rules/helpers/getValueFromPath.d.ts +2 -0
- package/dist/rules/helpers/getValueFromPath.js +35 -0
- package/dist/rules/helpers/getValuesFromPath.d.ts +3 -3
- package/dist/rules/helpers/getValuesFromPath.js +50 -50
- package/dist/rules/helpers/index.d.ts +5 -5
- package/dist/rules/helpers/index.js +21 -17
- package/dist/rules/helpers/rebuildInfiniteValues.d.ts +3 -0
- package/dist/rules/helpers/rebuildInfiniteValues.js +6 -0
- package/dist/rules/helpers/symbols.d.ts +2 -2
- package/dist/rules/helpers/symbols.js +5 -5
- package/dist/rules/helpers/thresholds.d.ts +5 -5
- package/dist/rules/helpers/thresholds.js +47 -47
- package/dist/rules/index.d.ts +7 -6
- package/dist/rules/index.js +25 -20
- package/dist/rules/isScoreResultValid.d.ts +2 -0
- package/dist/rules/isScoreResultValid.js +9 -0
- package/dist/rules/operators/array.d.ts +2 -0
- package/dist/rules/operators/array.js +74 -0
- package/dist/rules/operators/bool.d.ts +2 -2
- package/dist/rules/operators/bool.js +17 -17
- package/dist/rules/operators/date.d.ts +2 -2
- package/dist/rules/operators/date.js +91 -91
- package/dist/rules/operators/hfield.d.ts +2 -2
- package/dist/rules/operators/hfield.js +33 -33
- package/dist/rules/operators/hschema.d.ts +2 -2
- package/dist/rules/operators/hschema.js +21 -21
- package/dist/rules/operators/index.d.ts +3 -3
- package/dist/rules/operators/index.js +11 -11
- package/dist/rules/operators/number.d.ts +2 -2
- package/dist/rules/operators/number.js +41 -41
- package/dist/rules/operators/string.d.ts +2 -2
- package/dist/rules/operators/string.js +58 -58
- package/dist/rules/types/config.d.ts +91 -86
- package/dist/rules/types/config.js +2 -2
- package/dist/rules/types/dataValueTypes.d.ts +19 -19
- package/dist/rules/types/dataValueTypes.js +4 -4
- package/dist/rules/types/index.d.ts +3 -3
- package/dist/rules/types/index.js +19 -15
- package/dist/rules/types/internal.d.ts +20 -20
- package/dist/rules/types/internal.js +2 -2
- package/dist/rules/types/operators.d.ts +19 -0
- package/dist/rules/types/operators.js +2 -0
- package/dist/rules/types/score.d.ts +50 -0
- package/dist/rules/types/score.js +2 -0
- package/dist/rules/validate.d.ts +6 -0
- package/dist/rules/validate.js +14 -0
- package/dist/rules/version.d.ts +1 -0
- package/dist/rules/version.js +5 -0
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +17 -13
- package/dist/schema/labels.d.ts +2 -2
- package/dist/schema/labels.js +20 -20
- package/dist/util/canonicalJsonify.d.ts +1 -1
- package/dist/util/canonicalJsonify.js +50 -50
- package/dist/util/conditional.d.ts +7 -0
- package/dist/util/conditional.js +15 -0
- package/dist/util/handleResponse.d.ts +1 -1
- package/dist/util/handleResponse.js +21 -21
- package/dist/util/hash.d.ts +1 -0
- package/dist/util/hash.js +11 -0
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.js +18 -14
- package/dist/verifications/checkSingleVerification.d.ts +9 -0
- package/dist/verifications/checkSingleVerification.js +29 -0
- package/dist/verifications/checkVerifications.d.ts +1 -0
- package/dist/verifications/checkVerifications.js +16 -0
- package/dist/verifications/checkVerificationsNew.d.ts +1 -0
- package/dist/verifications/checkVerificationsNew.js +16 -0
- package/dist/verifications/cleanInstance.d.ts +9 -9
- package/dist/verifications/cleanInstance.js +15 -15
- package/dist/verifications/getOwnRealVerifications.d.ts +14 -0
- package/dist/verifications/getOwnRealVerifications.js +64 -0
- package/dist/verifications/getPOVerification.d.ts +16 -16
- package/dist/verifications/getPOVerification.js +94 -94
- package/dist/verifications/getRealVerifications.d.ts +22 -0
- package/dist/verifications/getRealVerifications.js +71 -0
- package/dist/verifications/getVerifiedBy.d.ts +1 -1
- package/dist/verifications/getVerifiedBy.js +19 -19
- package/dist/verifications/index.d.ts +5 -5
- package/dist/verifications/index.js +21 -17
- package/dist/verifications/maybeRereference.d.ts +1 -1
- package/dist/verifications/maybeRereference.js +10 -10
- package/dist/verifications/safeHarbour.d.ts +20 -20
- package/dist/verifications/safeHarbour.js +74 -74
- package/dist/verifications/verifyCheck/getOwnRealVerifications.d.ts +13 -13
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +64 -63
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +19 -19
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +72 -71
- package/dist/verifications/verifyCheck/index.d.ts +3 -3
- package/dist/verifications/verifyCheck/index.js +21 -17
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +15 -15
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +39 -39
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/operations/checkSomeoneElsesVerifications.js +16 -16
- package/dist/verifications/verifyCheck/operations/index.d.ts +2 -2
- package/dist/verifications/verifyCheck/operations/index.js +18 -14
- package/dist/verifications/verifyCheck/util/canonicalJsonify.d.ts +1 -0
- package/dist/verifications/verifyCheck/util/canonicalJsonify.js +48 -0
- package/dist/verifications/verifyCheck/util/getValuesForAField.d.ts +2 -0
- package/dist/verifications/verifyCheck/util/getValuesForAField.js +9 -0
- package/dist/verifications/verifyCheck/util/index.d.ts +2 -0
- package/dist/verifications/verifyCheck/util/index.js +14 -0
- package/package.json +6 -5
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOwnRealVerifications = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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,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
|
+
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,71 +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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* verifications
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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,17 +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
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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,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
|
+
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,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; // 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 +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,14 +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
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__exportStar(
|
|
14
|
-
|
|
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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable fp/no-mutating-methods, fp/no-mutation, fp/no-let, prefer-reflect */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.canonicalJsonify = void 0;
|
|
5
|
+
const isObject = (a) => Object.prototype.toString.call(a) === "[object Object]";
|
|
6
|
+
const REGEX =
|
|
7
|
+
// eslint-disable-next-line no-control-regex
|
|
8
|
+
/[\u0000-\u001F]|"|\\|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
|
|
9
|
+
const SLASH_ESC = {
|
|
10
|
+
"\b": "\\b",
|
|
11
|
+
"\t": "\\t",
|
|
12
|
+
"\n": "\\n",
|
|
13
|
+
"\f": "\\f",
|
|
14
|
+
"\r": "\\r",
|
|
15
|
+
'"': '\\"',
|
|
16
|
+
"\\": "\\\\",
|
|
17
|
+
};
|
|
18
|
+
const replacer = (char) => SLASH_ESC[char] ||
|
|
19
|
+
`\\u${char.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
20
|
+
function copyObjectWithSortedKeys(object) {
|
|
21
|
+
if (isObject(object)) {
|
|
22
|
+
return `{${Object.keys(object)
|
|
23
|
+
.sort()
|
|
24
|
+
.map(key => `"${key}":${copyObjectWithSortedKeys(object[key])}`)
|
|
25
|
+
.join(",")}}`;
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(object)) {
|
|
28
|
+
return `[${object.map(copyObjectWithSortedKeys).join(",")}]`;
|
|
29
|
+
}
|
|
30
|
+
if (typeof object === "number" && object % 1 !== 0) {
|
|
31
|
+
// float ->
|
|
32
|
+
const exponent = Math.round(Math.log10(Math.abs(object)));
|
|
33
|
+
let mantissa = `${object / 10 ** exponent}`;
|
|
34
|
+
if (!mantissa.includes("."))
|
|
35
|
+
mantissa += ".0";
|
|
36
|
+
return `${mantissa}E${exponent}`;
|
|
37
|
+
}
|
|
38
|
+
if (typeof object === "string")
|
|
39
|
+
return `"${object.replace(REGEX, replacer)}"`;
|
|
40
|
+
return object; // bool or int
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
* spec compliant, and matches
|
|
45
|
+
* https://gitlab.com/raytio/mono/-/blob/devo/common/signing/signing/canonical_json.py
|
|
46
|
+
*/
|
|
47
|
+
const canonicalJsonify = (object) => `${copyObjectWithSortedKeys(object)}`;
|
|
48
|
+
exports.canonicalJsonify = canonicalJsonify;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValuesForAField = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
const crypto_1 = require("../../../crypto");
|
|
6
|
+
const getValuesForAField = (fieldName, POs) => (0, ramda_1.uniq)(
|
|
7
|
+
// truthy only, and ignore encrypted properties. this function will be called again once they're decrypted
|
|
8
|
+
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)));
|
|
9
|
+
exports.getValuesForAField = getValuesForAField;
|