@raytio/core 11.0.0 → 11.2.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 +16 -1
- package/README.md +100 -1
- package/dist/crypto/getAADecryptor.js +32 -4
- package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/addLoadingTimes.test.js +24 -0
- package/dist/schema/expandSchema/__tests__/expandSchema.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/expandSchema.test.js +96 -0
- package/dist/schema/expandSchema/__tests__/i18n.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/i18n.test.js +32 -0
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/maybeUseI18n.test.js +98 -0
- package/dist/schema/expandSchema/__tests__/processSchema.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/processSchema.test.js +326 -0
- package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/sortSchemaProperties.test.js +182 -0
- package/dist/schema/expandSchema/__tests__/util.test.d.ts +1 -0
- package/dist/schema/expandSchema/__tests__/util.test.js +19 -0
- package/dist/schema/expandSchema/addLoadingTimes.d.ts +2 -0
- package/dist/schema/expandSchema/addLoadingTimes.js +12 -0
- package/dist/schema/expandSchema/constants.d.ts +2 -0
- package/dist/schema/expandSchema/constants.js +11 -0
- package/dist/schema/expandSchema/expandSchema.d.ts +7 -0
- package/dist/schema/expandSchema/expandSchema.js +19 -0
- package/dist/schema/expandSchema/i18n.d.ts +5 -0
- package/dist/schema/expandSchema/i18n.js +20 -0
- package/dist/schema/expandSchema/index.d.ts +3 -0
- package/dist/schema/expandSchema/index.js +21 -0
- package/dist/schema/expandSchema/maybeUseI18n.d.ts +2 -0
- package/dist/schema/expandSchema/maybeUseI18n.js +40 -0
- package/dist/schema/expandSchema/processSchema.d.ts +3 -0
- package/dist/schema/expandSchema/processSchema.js +94 -0
- package/dist/schema/expandSchema/removePrivateFields.d.ts +121 -0
- package/dist/schema/expandSchema/removePrivateFields.js +15 -0
- package/dist/schema/expandSchema/sortSchemaProperties.d.ts +21 -0
- package/dist/schema/expandSchema/sortSchemaProperties.js +40 -0
- package/dist/schema/expandSchema/unwrapSchema.d.ts +6 -0
- package/dist/schema/expandSchema/unwrapSchema.js +7 -0
- package/dist/schema/expandSchema/util.d.ts +6 -0
- package/dist/schema/expandSchema/util.js +15 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/testHelpers.d.ts +9 -0
- package/dist/testHelpers.js +9 -0
- package/dist/verifications/getPOVerification.js +6 -2
- package/dist/verifications/getVerifiedBy.js +6 -1
- package/dist/verifications/safeHarbour.d.ts +1 -1
- package/dist/verifications/safeHarbour.js +4 -11
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +72 -7
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +3 -1
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +45 -5
- package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +1 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +3 -2
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +15 -8
- package/package.json +5 -5
|
@@ -7,8 +7,9 @@ const __1 = require("..");
|
|
|
7
7
|
const util_1 = require("../../../../util");
|
|
8
8
|
const checkOwnVerification_1 = require("../checkOwnVerification");
|
|
9
9
|
const sampleBundle_json_1 = __importDefault(require("./sampleBundle.json"));
|
|
10
|
-
|
|
11
|
-
text: async () =>
|
|
10
|
+
global.fetch = jest.fn().mockImplementation(async (url) => ({
|
|
11
|
+
text: async () => url.endsWith("raytio.pem")
|
|
12
|
+
? `-----BEGIN PUBLIC KEY-----
|
|
12
13
|
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA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zf9yX0J8ZEDEcw9ZsNLVkyl2U+Ya/h5CQt43ip/1eNM5LpTbfqBTtAH7iUO
|
|
35
|
+
4L9rxuSJFA2Q9kZfof6kYO9EGgMFB+GM47/Q068+IiTpifvPno4ilnowyS4hbLiy
|
|
36
|
+
Os2yudW79flaz0a7rq5dLdSg9Mm5k7ETBm7WguDcocaiETmuYTJT2PozAGOC3+EP
|
|
37
|
+
w5N7mQff4ecx/880FWYKQmU9Asav1V49DWSnG0ZXQ7U24dG8ANeAgKddDviJGlsh
|
|
38
|
+
SsjKrz8LJqeoNQu30iSGZhUCAwEAAQ==
|
|
24
39
|
-----END PUBLIC KEY-----`,
|
|
25
40
|
}));
|
|
26
41
|
describe("checkOwnVerification", () => {
|
|
27
|
-
it
|
|
42
|
+
it.each `
|
|
43
|
+
keyId | result
|
|
44
|
+
${undefined} | ${true}
|
|
45
|
+
${"whatever/raytio"} | ${true}
|
|
46
|
+
${"whatever/somethingElse"} | ${false}
|
|
47
|
+
`("returns $result for a PO with keyId=$keyId", async ({ keyId, result }) => {
|
|
28
48
|
//
|
|
29
49
|
// This is an important integration test from ca. 2021-12-02.
|
|
30
50
|
// If it is failing, it means our code no longer matches the
|
|
@@ -54,7 +74,13 @@ describe("checkOwnVerification", () => {
|
|
|
54
74
|
};
|
|
55
75
|
const value = "NZ Limited Company";
|
|
56
76
|
const userId = "fd9c4903-65c2-4b75-b454-4fda6b682f3e"; // for 27july21 🦈
|
|
57
|
-
expect(await (0, checkOwnVerification_1.checkOwnVerification)({
|
|
77
|
+
expect(await (0, checkOwnVerification_1.checkOwnVerification)({
|
|
78
|
+
value,
|
|
79
|
+
signature,
|
|
80
|
+
userId,
|
|
81
|
+
verObject,
|
|
82
|
+
keyId,
|
|
83
|
+
})).toBe(result);
|
|
58
84
|
});
|
|
59
85
|
it("errors if you forget to supply the uId", async () => {
|
|
60
86
|
await expect(() => (0, checkOwnVerification_1.checkOwnVerification)({
|
|
@@ -62,8 +88,22 @@ describe("checkOwnVerification", () => {
|
|
|
62
88
|
signature: "",
|
|
63
89
|
userId: "",
|
|
64
90
|
verObject: {},
|
|
91
|
+
keyId: undefined,
|
|
65
92
|
})).rejects.toThrow(new Error("No userId supplied"));
|
|
66
93
|
});
|
|
94
|
+
it.each `
|
|
95
|
+
keyId
|
|
96
|
+
${"../../malicious.pem"}
|
|
97
|
+
${"https://example.com/malicious.pem"}
|
|
98
|
+
`("errors if you supply an invalid keyId", async ({ keyId }) => {
|
|
99
|
+
await expect(() => (0, checkOwnVerification_1.checkOwnVerification)({
|
|
100
|
+
value: "whatever",
|
|
101
|
+
signature: "whatever",
|
|
102
|
+
userId: "whatever",
|
|
103
|
+
verObject: {},
|
|
104
|
+
keyId,
|
|
105
|
+
})).rejects.toThrow(new Error("Invalid key ID"));
|
|
106
|
+
});
|
|
67
107
|
});
|
|
68
108
|
describe("checkSignature", () => {
|
|
69
109
|
it("works", async () => {
|
|
@@ -86,6 +126,6 @@ describe("checkSignature", () => {
|
|
|
86
126
|
});
|
|
87
127
|
describe("checkJsonSignature", () => {
|
|
88
128
|
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);
|
|
129
|
+
expect(await (0, __1.checkJsonSignature)(sampleBundle_json_1.default.data, sampleBundle_json_1.default.signature, sampleBundle_json_1.default.key_id)).toBe(true);
|
|
90
130
|
});
|
|
91
131
|
});
|
|
@@ -39,5 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"valid_until": "2022-03-13T02:26:20.468171"
|
|
41
41
|
},
|
|
42
|
+
"key_id": "any string/raytio",
|
|
42
43
|
"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
44
|
}
|
|
@@ -4,12 +4,13 @@ type SingleVerToCheck = {
|
|
|
4
4
|
signature: string;
|
|
5
5
|
userId: UId;
|
|
6
6
|
value: unknown;
|
|
7
|
+
keyId: string | undefined;
|
|
7
8
|
};
|
|
8
9
|
/**
|
|
9
10
|
* checks that a json object was signed by the provided signature. Unless you're
|
|
10
11
|
* dealing with bundled verifications, you should use `getOwnRealVerifications`
|
|
11
12
|
* or `getSomeoneElsesRealVerifications` instead.
|
|
12
13
|
*/
|
|
13
|
-
export declare const checkJsonSignature: (data: unknown, signature: string) => Promise<boolean>;
|
|
14
|
-
export declare const checkOwnVerification: ({ verObject, signature, userId, value, }: SingleVerToCheck) => Promise<boolean>;
|
|
14
|
+
export declare const checkJsonSignature: (data: unknown, signature: string, keyId: string | undefined) => Promise<boolean>;
|
|
15
|
+
export declare const checkOwnVerification: ({ verObject, signature, userId, value, keyId, }: SingleVerToCheck) => Promise<boolean>;
|
|
15
16
|
export {};
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkOwnVerification = exports.checkJsonSignature = exports.checkSignature = void 0;
|
|
4
4
|
const util_1 = require("../../../util");
|
|
5
|
-
|
|
5
|
+
const cache = {};
|
|
6
6
|
const base64ToArrayBuffer = (str) => Uint8Array.from(atob(str), c => c.charCodeAt(0));
|
|
7
|
-
async function getJwk() {
|
|
7
|
+
async function getJwk(keyUrl) {
|
|
8
8
|
// eslint-disable-next-line fp/no-mutation
|
|
9
|
-
cache || (cache = fetch(
|
|
9
|
+
cache[keyUrl] || (cache[keyUrl] = fetch(keyUrl)
|
|
10
10
|
.then(r => r.text())
|
|
11
11
|
.then(pem => crypto.subtle.importKey("spki", base64ToArrayBuffer(pem.split("-----")[2].trim()), { name: "RSA-PSS", hash: "SHA-512" }, false, ["verify"])));
|
|
12
|
-
return cache;
|
|
12
|
+
return cache[keyUrl];
|
|
13
13
|
}
|
|
14
14
|
/** @internal exported only for tests */
|
|
15
15
|
async function checkSignature(publicCryptoKey, signature, data) {
|
|
@@ -24,16 +24,23 @@ exports.checkSignature = checkSignature;
|
|
|
24
24
|
* dealing with bundled verifications, you should use `getOwnRealVerifications`
|
|
25
25
|
* or `getSomeoneElsesRealVerifications` instead.
|
|
26
26
|
*/
|
|
27
|
-
const checkJsonSignature = async (data, signature) => {
|
|
28
|
-
const
|
|
27
|
+
const checkJsonSignature = async (data, signature, keyId) => {
|
|
28
|
+
const keyFileName = keyId ? keyId.split("/")[1] : "raytio";
|
|
29
|
+
// don't allow any special characters, e.g. to prevent
|
|
30
|
+
// someone using a keyID of "../../someOtherFile"
|
|
31
|
+
if (!keyFileName || /[^\w-]/.test(keyFileName)) {
|
|
32
|
+
throw new Error("Invalid key ID");
|
|
33
|
+
}
|
|
34
|
+
const keyUrl = `https://api-docs.rayt.io/lookups/${keyFileName}.pem`;
|
|
35
|
+
const jwk = await getJwk(keyUrl);
|
|
29
36
|
const stringified = (0, util_1.canonicalJsonify)(data);
|
|
30
37
|
const result = await checkSignature(jwk, signature, stringified);
|
|
31
38
|
return result;
|
|
32
39
|
};
|
|
33
40
|
exports.checkJsonSignature = checkJsonSignature;
|
|
34
|
-
const checkOwnVerification = async ({ verObject, signature, userId, value, }) => {
|
|
41
|
+
const checkOwnVerification = async ({ verObject, signature, userId, value, keyId, }) => {
|
|
35
42
|
if (!userId)
|
|
36
43
|
throw new Error("No userId supplied");
|
|
37
|
-
return (0, exports.checkJsonSignature)(Object.assign(Object.assign({}, verObject), { sub: userId, value }), signature);
|
|
44
|
+
return (0, exports.checkJsonSignature)(Object.assign(Object.assign({}, verObject), { sub: userId, value }), signature, keyId);
|
|
38
45
|
};
|
|
39
46
|
exports.checkOwnVerification = checkOwnVerification;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raytio/core",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "index",
|
|
6
6
|
"types": "index",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@raytio/maxcryptor": "3.1.0",
|
|
20
|
-
"@raytio/types": "7.
|
|
20
|
+
"@raytio/types": "7.2.0",
|
|
21
21
|
"ramda": "0.29.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/ramda": "0.
|
|
25
|
-
"jest": "29.
|
|
26
|
-
"ts-jest": "29.1.
|
|
24
|
+
"@types/ramda": "0.29.2",
|
|
25
|
+
"jest": "29.6.1",
|
|
26
|
+
"ts-jest": "29.1.1"
|
|
27
27
|
},
|
|
28
28
|
"jest": {
|
|
29
29
|
"transform": {
|