@workos-inc/node 8.9.0 → 8.10.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/lib/{factory-ClnPnWTz.mjs → factory-Dl_P8aZA.mjs} +101 -5
- package/lib/factory-Dl_P8aZA.mjs.map +1 -0
- package/lib/{factory-DlHvKYOI.cjs → factory-DwdIHLNE.cjs} +101 -5
- package/lib/factory-DwdIHLNE.cjs.map +1 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +1 -1
- package/lib/index.worker.cjs +1 -1
- package/lib/index.worker.d.cts +2 -2
- package/lib/index.worker.d.mts +2 -2
- package/lib/index.worker.mjs +1 -1
- package/lib/{webapi-oTg8yaNv.mjs → webapi-Cj8QQOwM.mjs} +773 -847
- package/lib/webapi-Cj8QQOwM.mjs.map +1 -0
- package/lib/{webapi-DoOhnR2U.cjs → webapi-Dk3R7830.cjs} +773 -847
- package/lib/webapi-Dk3R7830.cjs.map +1 -0
- package/lib/{workos-CcjPGl_n.d.cts → workos-DdsaFn8s.d.cts} +164 -19
- package/lib/{workos-DYZ38_bk.d.mts → workos-eC0BwRfM.d.mts} +164 -19
- package/package.json +6 -6
- package/lib/factory-ClnPnWTz.mjs.map +0 -1
- package/lib/factory-DlHvKYOI.cjs.map +0 -1
- package/lib/webapi-DoOhnR2U.cjs.map +0 -1
- package/lib/webapi-oTg8yaNv.mjs.map +0 -1
|
@@ -98,6 +98,127 @@ function encode(input) {
|
|
|
98
98
|
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
99
99
|
}
|
|
100
100
|
//#endregion
|
|
101
|
+
//#region node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
102
|
+
const unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
103
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
104
|
+
function getHashLength(hash) {
|
|
105
|
+
return parseInt(hash.name.slice(4), 10);
|
|
106
|
+
}
|
|
107
|
+
function checkHashLength(algorithm, expected) {
|
|
108
|
+
if (getHashLength(algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
109
|
+
}
|
|
110
|
+
function getNamedCurve(alg) {
|
|
111
|
+
switch (alg) {
|
|
112
|
+
case "ES256": return "P-256";
|
|
113
|
+
case "ES384": return "P-384";
|
|
114
|
+
case "ES512": return "P-521";
|
|
115
|
+
default: throw new Error("unreachable");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function checkUsage(key, usage) {
|
|
119
|
+
if (usage && !key.usages.includes(usage)) throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
120
|
+
}
|
|
121
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
122
|
+
switch (alg) {
|
|
123
|
+
case "HS256":
|
|
124
|
+
case "HS384":
|
|
125
|
+
case "HS512":
|
|
126
|
+
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
127
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
128
|
+
break;
|
|
129
|
+
case "RS256":
|
|
130
|
+
case "RS384":
|
|
131
|
+
case "RS512":
|
|
132
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
133
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
134
|
+
break;
|
|
135
|
+
case "PS256":
|
|
136
|
+
case "PS384":
|
|
137
|
+
case "PS512":
|
|
138
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
139
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
140
|
+
break;
|
|
141
|
+
case "Ed25519":
|
|
142
|
+
case "EdDSA":
|
|
143
|
+
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
144
|
+
break;
|
|
145
|
+
case "ML-DSA-44":
|
|
146
|
+
case "ML-DSA-65":
|
|
147
|
+
case "ML-DSA-87":
|
|
148
|
+
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
149
|
+
break;
|
|
150
|
+
case "ES256":
|
|
151
|
+
case "ES384":
|
|
152
|
+
case "ES512": {
|
|
153
|
+
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
154
|
+
const expected = getNamedCurve(alg);
|
|
155
|
+
if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
default: throw new TypeError("CryptoKey does not support this operation");
|
|
159
|
+
}
|
|
160
|
+
checkUsage(key, usage);
|
|
161
|
+
}
|
|
162
|
+
function checkEncCryptoKey(key, alg, usage) {
|
|
163
|
+
switch (alg) {
|
|
164
|
+
case "A128GCM":
|
|
165
|
+
case "A192GCM":
|
|
166
|
+
case "A256GCM": {
|
|
167
|
+
if (!isAlgorithm(key.algorithm, "AES-GCM")) throw unusable("AES-GCM");
|
|
168
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
169
|
+
if (key.algorithm.length !== expected) throw unusable(expected, "algorithm.length");
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case "A128KW":
|
|
173
|
+
case "A192KW":
|
|
174
|
+
case "A256KW": {
|
|
175
|
+
if (!isAlgorithm(key.algorithm, "AES-KW")) throw unusable("AES-KW");
|
|
176
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
177
|
+
if (key.algorithm.length !== expected) throw unusable(expected, "algorithm.length");
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case "ECDH":
|
|
181
|
+
switch (key.algorithm.name) {
|
|
182
|
+
case "ECDH":
|
|
183
|
+
case "X25519": break;
|
|
184
|
+
default: throw unusable("ECDH or X25519");
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
case "PBES2-HS256+A128KW":
|
|
188
|
+
case "PBES2-HS384+A192KW":
|
|
189
|
+
case "PBES2-HS512+A256KW":
|
|
190
|
+
if (!isAlgorithm(key.algorithm, "PBKDF2")) throw unusable("PBKDF2");
|
|
191
|
+
break;
|
|
192
|
+
case "RSA-OAEP":
|
|
193
|
+
case "RSA-OAEP-256":
|
|
194
|
+
case "RSA-OAEP-384":
|
|
195
|
+
case "RSA-OAEP-512":
|
|
196
|
+
if (!isAlgorithm(key.algorithm, "RSA-OAEP")) throw unusable("RSA-OAEP");
|
|
197
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(9), 10) || 1);
|
|
198
|
+
break;
|
|
199
|
+
default: throw new TypeError("CryptoKey does not support this operation");
|
|
200
|
+
}
|
|
201
|
+
checkUsage(key, usage);
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
205
|
+
function message(msg, actual, ...types) {
|
|
206
|
+
types = types.filter(Boolean);
|
|
207
|
+
if (types.length > 2) {
|
|
208
|
+
const last = types.pop();
|
|
209
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
210
|
+
} else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
211
|
+
else msg += `of type ${types[0]}.`;
|
|
212
|
+
if (actual == null) msg += ` Received ${actual}`;
|
|
213
|
+
else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
|
|
214
|
+
else if (typeof actual === "object" && actual != null) {
|
|
215
|
+
if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
|
|
216
|
+
}
|
|
217
|
+
return msg;
|
|
218
|
+
}
|
|
219
|
+
const invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
220
|
+
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
221
|
+
//#endregion
|
|
101
222
|
//#region node_modules/jose/dist/webapi/util/errors.js
|
|
102
223
|
var errors_exports = /* @__PURE__ */ __exportAll({
|
|
103
224
|
JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
|
|
@@ -224,8 +345,39 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
|
224
345
|
}
|
|
225
346
|
};
|
|
226
347
|
//#endregion
|
|
227
|
-
//#region node_modules/jose/dist/webapi/lib/
|
|
228
|
-
function
|
|
348
|
+
//#region node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
349
|
+
function assertCryptoKey(key) {
|
|
350
|
+
if (!isCryptoKey(key)) throw new Error("CryptoKey instance expected");
|
|
351
|
+
}
|
|
352
|
+
const isCryptoKey = (key) => {
|
|
353
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
354
|
+
try {
|
|
355
|
+
return key instanceof CryptoKey;
|
|
356
|
+
} catch {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
const isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
361
|
+
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region node_modules/jose/dist/webapi/lib/content_encryption.js
|
|
364
|
+
function cekLength(alg) {
|
|
365
|
+
switch (alg) {
|
|
366
|
+
case "A128GCM": return 128;
|
|
367
|
+
case "A192GCM": return 192;
|
|
368
|
+
case "A256GCM":
|
|
369
|
+
case "A128CBC-HS256": return 256;
|
|
370
|
+
case "A192CBC-HS384": return 384;
|
|
371
|
+
case "A256CBC-HS512": return 512;
|
|
372
|
+
default: throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
376
|
+
function checkCekLength(cek, expected) {
|
|
377
|
+
const actual = cek.byteLength << 3;
|
|
378
|
+
if (actual !== expected) throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
379
|
+
}
|
|
380
|
+
function ivBitLength(alg) {
|
|
229
381
|
switch (alg) {
|
|
230
382
|
case "A128GCM":
|
|
231
383
|
case "A128GCMKW":
|
|
@@ -239,200 +391,89 @@ function bitLength(alg) {
|
|
|
239
391
|
default: throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
240
392
|
}
|
|
241
393
|
}
|
|
242
|
-
const generateIv = (alg) => crypto.getRandomValues(new Uint8Array(
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region node_modules/jose/dist/webapi/lib/check_iv_length.js
|
|
394
|
+
const generateIv = (alg) => crypto.getRandomValues(new Uint8Array(ivBitLength(alg) >> 3));
|
|
245
395
|
function checkIvLength(enc, iv) {
|
|
246
|
-
if (iv.length << 3 !==
|
|
396
|
+
if (iv.length << 3 !== ivBitLength(enc)) throw new JWEInvalid("Invalid Initialization Vector length");
|
|
247
397
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
398
|
+
async function cbcKeySetup(enc, cek, usage) {
|
|
399
|
+
if (!(cek instanceof Uint8Array)) throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
400
|
+
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
401
|
+
return {
|
|
402
|
+
encKey: await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, [usage]),
|
|
403
|
+
macKey: await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
404
|
+
hash: `SHA-${keySize << 1}`,
|
|
405
|
+
name: "HMAC"
|
|
406
|
+
}, false, ["sign"]),
|
|
407
|
+
keySize
|
|
408
|
+
};
|
|
253
409
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
257
|
-
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
258
|
-
function getHashLength(hash) {
|
|
259
|
-
return parseInt(hash.name.slice(4), 10);
|
|
410
|
+
async function cbcHmacTag(macKey, macData, keySize) {
|
|
411
|
+
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
260
412
|
}
|
|
261
|
-
function
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
413
|
+
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
414
|
+
const { encKey, macKey, keySize } = await cbcKeySetup(enc, cek, "encrypt");
|
|
415
|
+
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
416
|
+
iv,
|
|
417
|
+
name: "AES-CBC"
|
|
418
|
+
}, encKey, plaintext));
|
|
419
|
+
return {
|
|
420
|
+
ciphertext,
|
|
421
|
+
tag: await cbcHmacTag(macKey, concat(aad, iv, ciphertext, uint64be(aad.length << 3)), keySize),
|
|
422
|
+
iv
|
|
423
|
+
};
|
|
268
424
|
}
|
|
269
|
-
function
|
|
270
|
-
if (
|
|
425
|
+
async function timingSafeEqual(a, b) {
|
|
426
|
+
if (!(a instanceof Uint8Array)) throw new TypeError("First argument must be a buffer");
|
|
427
|
+
if (!(b instanceof Uint8Array)) throw new TypeError("Second argument must be a buffer");
|
|
428
|
+
const algorithm = {
|
|
429
|
+
name: "HMAC",
|
|
430
|
+
hash: "SHA-256"
|
|
431
|
+
};
|
|
432
|
+
const key = await crypto.subtle.generateKey(algorithm, false, ["sign"]);
|
|
433
|
+
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
434
|
+
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
435
|
+
let out = 0;
|
|
436
|
+
let i = -1;
|
|
437
|
+
while (++i < 32) out |= aHmac[i] ^ bHmac[i];
|
|
438
|
+
return out === 0;
|
|
271
439
|
}
|
|
272
|
-
function
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
case "PS256":
|
|
291
|
-
case "PS384":
|
|
292
|
-
case "PS512": {
|
|
293
|
-
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
294
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
295
|
-
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
case "Ed25519":
|
|
299
|
-
case "EdDSA":
|
|
300
|
-
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
301
|
-
break;
|
|
302
|
-
case "ML-DSA-44":
|
|
303
|
-
case "ML-DSA-65":
|
|
304
|
-
case "ML-DSA-87":
|
|
305
|
-
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
306
|
-
break;
|
|
307
|
-
case "ES256":
|
|
308
|
-
case "ES384":
|
|
309
|
-
case "ES512": {
|
|
310
|
-
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
311
|
-
const expected = getNamedCurve(alg);
|
|
312
|
-
if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
default: throw new TypeError("CryptoKey does not support this operation");
|
|
316
|
-
}
|
|
317
|
-
checkUsage(key, usage);
|
|
440
|
+
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
441
|
+
const { encKey, macKey, keySize } = await cbcKeySetup(enc, cek, "decrypt");
|
|
442
|
+
const expectedTag = await cbcHmacTag(macKey, concat(aad, iv, ciphertext, uint64be(aad.length << 3)), keySize);
|
|
443
|
+
let macCheckPassed;
|
|
444
|
+
try {
|
|
445
|
+
macCheckPassed = await timingSafeEqual(tag, expectedTag);
|
|
446
|
+
} catch {}
|
|
447
|
+
if (!macCheckPassed) throw new JWEDecryptionFailed();
|
|
448
|
+
let plaintext;
|
|
449
|
+
try {
|
|
450
|
+
plaintext = new Uint8Array(await crypto.subtle.decrypt({
|
|
451
|
+
iv,
|
|
452
|
+
name: "AES-CBC"
|
|
453
|
+
}, encKey, ciphertext));
|
|
454
|
+
} catch {}
|
|
455
|
+
if (!plaintext) throw new JWEDecryptionFailed();
|
|
456
|
+
return plaintext;
|
|
318
457
|
}
|
|
319
|
-
function
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const expected = parseInt(alg.slice(1, 4), 10);
|
|
326
|
-
if (key.algorithm.length !== expected) throw unusable(expected, "algorithm.length");
|
|
327
|
-
break;
|
|
328
|
-
}
|
|
329
|
-
case "A128KW":
|
|
330
|
-
case "A192KW":
|
|
331
|
-
case "A256KW": {
|
|
332
|
-
if (!isAlgorithm(key.algorithm, "AES-KW")) throw unusable("AES-KW");
|
|
333
|
-
const expected = parseInt(alg.slice(1, 4), 10);
|
|
334
|
-
if (key.algorithm.length !== expected) throw unusable(expected, "algorithm.length");
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
case "ECDH":
|
|
338
|
-
switch (key.algorithm.name) {
|
|
339
|
-
case "ECDH":
|
|
340
|
-
case "X25519": break;
|
|
341
|
-
default: throw unusable("ECDH or X25519");
|
|
342
|
-
}
|
|
343
|
-
break;
|
|
344
|
-
case "PBES2-HS256+A128KW":
|
|
345
|
-
case "PBES2-HS384+A192KW":
|
|
346
|
-
case "PBES2-HS512+A256KW":
|
|
347
|
-
if (!isAlgorithm(key.algorithm, "PBKDF2")) throw unusable("PBKDF2");
|
|
348
|
-
break;
|
|
349
|
-
case "RSA-OAEP":
|
|
350
|
-
case "RSA-OAEP-256":
|
|
351
|
-
case "RSA-OAEP-384":
|
|
352
|
-
case "RSA-OAEP-512": {
|
|
353
|
-
if (!isAlgorithm(key.algorithm, "RSA-OAEP")) throw unusable("RSA-OAEP");
|
|
354
|
-
const expected = parseInt(alg.slice(9), 10) || 1;
|
|
355
|
-
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
default: throw new TypeError("CryptoKey does not support this operation");
|
|
359
|
-
}
|
|
360
|
-
checkUsage(key, usage);
|
|
361
|
-
}
|
|
362
|
-
//#endregion
|
|
363
|
-
//#region node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
364
|
-
function message(msg, actual, ...types) {
|
|
365
|
-
types = types.filter(Boolean);
|
|
366
|
-
if (types.length > 2) {
|
|
367
|
-
const last = types.pop();
|
|
368
|
-
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
369
|
-
} else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
370
|
-
else msg += `of type ${types[0]}.`;
|
|
371
|
-
if (actual == null) msg += ` Received ${actual}`;
|
|
372
|
-
else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
|
|
373
|
-
else if (typeof actual === "object" && actual != null) {
|
|
374
|
-
if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
|
|
375
|
-
}
|
|
376
|
-
return msg;
|
|
377
|
-
}
|
|
378
|
-
const invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
379
|
-
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
380
|
-
//#endregion
|
|
381
|
-
//#region node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
382
|
-
function assertCryptoKey(key) {
|
|
383
|
-
if (!isCryptoKey(key)) throw new Error("CryptoKey instance expected");
|
|
384
|
-
}
|
|
385
|
-
const isCryptoKey = (key) => {
|
|
386
|
-
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
387
|
-
try {
|
|
388
|
-
return key instanceof CryptoKey;
|
|
389
|
-
} catch {
|
|
390
|
-
return false;
|
|
458
|
+
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
459
|
+
let encKey;
|
|
460
|
+
if (cek instanceof Uint8Array) encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
|
|
461
|
+
else {
|
|
462
|
+
checkEncCryptoKey(cek, enc, "encrypt");
|
|
463
|
+
encKey = cek;
|
|
391
464
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
465
|
+
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
466
|
+
additionalData: aad,
|
|
467
|
+
iv,
|
|
468
|
+
name: "AES-GCM",
|
|
469
|
+
tagLength: 128
|
|
470
|
+
}, encKey, plaintext));
|
|
471
|
+
const tag = encrypted.slice(-16);
|
|
472
|
+
return {
|
|
473
|
+
ciphertext: encrypted.slice(0, -16),
|
|
474
|
+
tag,
|
|
475
|
+
iv
|
|
403
476
|
};
|
|
404
|
-
const key = await crypto.subtle.generateKey(algorithm, false, ["sign"]);
|
|
405
|
-
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
406
|
-
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
407
|
-
let out = 0;
|
|
408
|
-
let i = -1;
|
|
409
|
-
while (++i < 32) out |= aHmac[i] ^ bHmac[i];
|
|
410
|
-
return out === 0;
|
|
411
|
-
}
|
|
412
|
-
async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
413
|
-
if (!(cek instanceof Uint8Array)) throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
414
|
-
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
415
|
-
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["decrypt"]);
|
|
416
|
-
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
417
|
-
hash: `SHA-${keySize << 1}`,
|
|
418
|
-
name: "HMAC"
|
|
419
|
-
}, false, ["sign"]);
|
|
420
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
421
|
-
const expectedTag = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
422
|
-
let macCheckPassed;
|
|
423
|
-
try {
|
|
424
|
-
macCheckPassed = await timingSafeEqual(tag, expectedTag);
|
|
425
|
-
} catch {}
|
|
426
|
-
if (!macCheckPassed) throw new JWEDecryptionFailed();
|
|
427
|
-
let plaintext;
|
|
428
|
-
try {
|
|
429
|
-
plaintext = new Uint8Array(await crypto.subtle.decrypt({
|
|
430
|
-
iv,
|
|
431
|
-
name: "AES-CBC"
|
|
432
|
-
}, encKey, ciphertext));
|
|
433
|
-
} catch {}
|
|
434
|
-
if (!plaintext) throw new JWEDecryptionFailed();
|
|
435
|
-
return plaintext;
|
|
436
477
|
}
|
|
437
478
|
async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
438
479
|
let encKey;
|
|
@@ -452,6 +493,25 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
452
493
|
throw new JWEDecryptionFailed();
|
|
453
494
|
}
|
|
454
495
|
}
|
|
496
|
+
const unsupportedEnc = "Unsupported JWE Content Encryption Algorithm";
|
|
497
|
+
async function encrypt$1(enc, plaintext, cek, iv, aad) {
|
|
498
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
499
|
+
if (iv) checkIvLength(enc, iv);
|
|
500
|
+
else iv = generateIv(enc);
|
|
501
|
+
switch (enc) {
|
|
502
|
+
case "A128CBC-HS256":
|
|
503
|
+
case "A192CBC-HS384":
|
|
504
|
+
case "A256CBC-HS512":
|
|
505
|
+
if (cek instanceof Uint8Array) checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
506
|
+
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
507
|
+
case "A128GCM":
|
|
508
|
+
case "A192GCM":
|
|
509
|
+
case "A256GCM":
|
|
510
|
+
if (cek instanceof Uint8Array) checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
511
|
+
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
512
|
+
default: throw new JOSENotSupported(unsupportedEnc);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
455
515
|
async function decrypt$1(enc, cek, ciphertext, iv, tag, aad) {
|
|
456
516
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
457
517
|
if (!iv) throw new JWEInvalid("JWE Initialization Vector missing");
|
|
@@ -468,11 +528,36 @@ async function decrypt$1(enc, cek, ciphertext, iv, tag, aad) {
|
|
|
468
528
|
case "A256GCM":
|
|
469
529
|
if (cek instanceof Uint8Array) checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
470
530
|
return gcmDecrypt(enc, cek, ciphertext, iv, tag, aad);
|
|
471
|
-
default: throw new JOSENotSupported(
|
|
531
|
+
default: throw new JOSENotSupported(unsupportedEnc);
|
|
472
532
|
}
|
|
473
533
|
}
|
|
474
534
|
//#endregion
|
|
475
|
-
//#region node_modules/jose/dist/webapi/lib/
|
|
535
|
+
//#region node_modules/jose/dist/webapi/lib/helpers.js
|
|
536
|
+
const unprotected = Symbol();
|
|
537
|
+
function assertNotSet(value, name) {
|
|
538
|
+
if (value) throw new TypeError(`${name} can only be called once`);
|
|
539
|
+
}
|
|
540
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
541
|
+
try {
|
|
542
|
+
return decode(value);
|
|
543
|
+
} catch {
|
|
544
|
+
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
async function digest(algorithm, data) {
|
|
548
|
+
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
549
|
+
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
550
|
+
}
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region node_modules/jose/dist/webapi/lib/type_checks.js
|
|
553
|
+
const isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
554
|
+
function isObject(input) {
|
|
555
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
556
|
+
if (Object.getPrototypeOf(input) === null) return true;
|
|
557
|
+
let proto = input;
|
|
558
|
+
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
559
|
+
return Object.getPrototypeOf(input) === proto;
|
|
560
|
+
}
|
|
476
561
|
function isDisjoint(...headers) {
|
|
477
562
|
const sources = headers.filter(Boolean);
|
|
478
563
|
if (sources.length === 0 || sources.length === 1) return true;
|
|
@@ -490,16 +575,10 @@ function isDisjoint(...headers) {
|
|
|
490
575
|
}
|
|
491
576
|
return true;
|
|
492
577
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
498
|
-
if (Object.getPrototypeOf(input) === null) return true;
|
|
499
|
-
let proto = input;
|
|
500
|
-
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
501
|
-
return Object.getPrototypeOf(input) === proto;
|
|
502
|
-
}
|
|
578
|
+
const isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
579
|
+
const isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
580
|
+
const isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
581
|
+
const isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
503
582
|
//#endregion
|
|
504
583
|
//#region node_modules/jose/dist/webapi/lib/aeskw.js
|
|
505
584
|
function checkKeySize(key, alg) {
|
|
@@ -529,12 +608,6 @@ async function unwrap$2(alg, key, encryptedKey) {
|
|
|
529
608
|
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
530
609
|
}
|
|
531
610
|
//#endregion
|
|
532
|
-
//#region node_modules/jose/dist/webapi/lib/digest.js
|
|
533
|
-
async function digest(algorithm, data) {
|
|
534
|
-
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
535
|
-
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
536
|
-
}
|
|
537
|
-
//#endregion
|
|
538
611
|
//#region node_modules/jose/dist/webapi/lib/ecdhes.js
|
|
539
612
|
function lengthAndInput(input) {
|
|
540
613
|
return concat(uint32be(input.length), input);
|
|
@@ -609,16 +682,80 @@ async function unwrap$1(alg, key, encryptedKey, p2c, p2s) {
|
|
|
609
682
|
return unwrap$2(alg.slice(-6), derived, encryptedKey);
|
|
610
683
|
}
|
|
611
684
|
//#endregion
|
|
612
|
-
//#region node_modules/jose/dist/webapi/lib/
|
|
685
|
+
//#region node_modules/jose/dist/webapi/lib/signing.js
|
|
613
686
|
function checkKeyLength(alg, key) {
|
|
614
687
|
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
615
688
|
const { modulusLength } = key.algorithm;
|
|
616
689
|
if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
617
690
|
}
|
|
618
691
|
}
|
|
692
|
+
function subtleAlgorithm$1(alg, algorithm) {
|
|
693
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
694
|
+
switch (alg) {
|
|
695
|
+
case "HS256":
|
|
696
|
+
case "HS384":
|
|
697
|
+
case "HS512": return {
|
|
698
|
+
hash,
|
|
699
|
+
name: "HMAC"
|
|
700
|
+
};
|
|
701
|
+
case "PS256":
|
|
702
|
+
case "PS384":
|
|
703
|
+
case "PS512": return {
|
|
704
|
+
hash,
|
|
705
|
+
name: "RSA-PSS",
|
|
706
|
+
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
707
|
+
};
|
|
708
|
+
case "RS256":
|
|
709
|
+
case "RS384":
|
|
710
|
+
case "RS512": return {
|
|
711
|
+
hash,
|
|
712
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
713
|
+
};
|
|
714
|
+
case "ES256":
|
|
715
|
+
case "ES384":
|
|
716
|
+
case "ES512": return {
|
|
717
|
+
hash,
|
|
718
|
+
name: "ECDSA",
|
|
719
|
+
namedCurve: algorithm.namedCurve
|
|
720
|
+
};
|
|
721
|
+
case "Ed25519":
|
|
722
|
+
case "EdDSA": return { name: "Ed25519" };
|
|
723
|
+
case "ML-DSA-44":
|
|
724
|
+
case "ML-DSA-65":
|
|
725
|
+
case "ML-DSA-87": return { name: alg };
|
|
726
|
+
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
async function getSigKey(alg, key, usage) {
|
|
730
|
+
if (key instanceof Uint8Array) {
|
|
731
|
+
if (!alg.startsWith("HS")) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
732
|
+
return crypto.subtle.importKey("raw", key, {
|
|
733
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
734
|
+
name: "HMAC"
|
|
735
|
+
}, false, [usage]);
|
|
736
|
+
}
|
|
737
|
+
checkSigCryptoKey(key, alg, usage);
|
|
738
|
+
return key;
|
|
739
|
+
}
|
|
740
|
+
async function sign(alg, key, data) {
|
|
741
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
742
|
+
checkKeyLength(alg, cryptoKey);
|
|
743
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm$1(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
744
|
+
return new Uint8Array(signature);
|
|
745
|
+
}
|
|
746
|
+
async function verify(alg, key, signature, data) {
|
|
747
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
748
|
+
checkKeyLength(alg, cryptoKey);
|
|
749
|
+
const algorithm = subtleAlgorithm$1(alg, cryptoKey.algorithm);
|
|
750
|
+
try {
|
|
751
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
752
|
+
} catch {
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
619
756
|
//#endregion
|
|
620
757
|
//#region node_modules/jose/dist/webapi/lib/rsaes.js
|
|
621
|
-
const subtleAlgorithm
|
|
758
|
+
const subtleAlgorithm = (alg) => {
|
|
622
759
|
switch (alg) {
|
|
623
760
|
case "RSA-OAEP":
|
|
624
761
|
case "RSA-OAEP-256":
|
|
@@ -627,48 +764,266 @@ const subtleAlgorithm$1 = (alg) => {
|
|
|
627
764
|
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
628
765
|
}
|
|
629
766
|
};
|
|
630
|
-
async function encrypt
|
|
767
|
+
async function encrypt(alg, key, cek) {
|
|
631
768
|
checkEncCryptoKey(key, alg, "encrypt");
|
|
632
769
|
checkKeyLength(alg, key);
|
|
633
|
-
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm
|
|
770
|
+
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm(alg), key, cek));
|
|
634
771
|
}
|
|
635
772
|
async function decrypt(alg, key, encryptedKey) {
|
|
636
773
|
checkEncCryptoKey(key, alg, "decrypt");
|
|
637
774
|
checkKeyLength(alg, key);
|
|
638
|
-
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm
|
|
639
|
-
}
|
|
640
|
-
//#endregion
|
|
641
|
-
//#region node_modules/jose/dist/webapi/lib/cek.js
|
|
642
|
-
function cekLength(alg) {
|
|
643
|
-
switch (alg) {
|
|
644
|
-
case "A128GCM": return 128;
|
|
645
|
-
case "A192GCM": return 192;
|
|
646
|
-
case "A256GCM":
|
|
647
|
-
case "A128CBC-HS256": return 256;
|
|
648
|
-
case "A192CBC-HS384": return 384;
|
|
649
|
-
case "A256CBC-HS512": return 512;
|
|
650
|
-
default: throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
651
|
-
}
|
|
775
|
+
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm(alg), key, encryptedKey));
|
|
652
776
|
}
|
|
653
|
-
const generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
654
777
|
//#endregion
|
|
655
|
-
//#region node_modules/jose/dist/webapi/lib/
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
778
|
+
//#region node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
779
|
+
const unsupportedAlg = "Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value";
|
|
780
|
+
function subtleMapping(jwk) {
|
|
781
|
+
let algorithm;
|
|
782
|
+
let keyUsages;
|
|
783
|
+
switch (jwk.kty) {
|
|
784
|
+
case "AKP":
|
|
785
|
+
switch (jwk.alg) {
|
|
786
|
+
case "ML-DSA-44":
|
|
787
|
+
case "ML-DSA-65":
|
|
788
|
+
case "ML-DSA-87":
|
|
789
|
+
algorithm = { name: jwk.alg };
|
|
790
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
791
|
+
break;
|
|
792
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
793
|
+
}
|
|
794
|
+
break;
|
|
795
|
+
case "RSA":
|
|
796
|
+
switch (jwk.alg) {
|
|
797
|
+
case "PS256":
|
|
798
|
+
case "PS384":
|
|
799
|
+
case "PS512":
|
|
800
|
+
algorithm = {
|
|
801
|
+
name: "RSA-PSS",
|
|
802
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
803
|
+
};
|
|
804
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
805
|
+
break;
|
|
806
|
+
case "RS256":
|
|
807
|
+
case "RS384":
|
|
808
|
+
case "RS512":
|
|
809
|
+
algorithm = {
|
|
810
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
811
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
812
|
+
};
|
|
813
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
814
|
+
break;
|
|
815
|
+
case "RSA-OAEP":
|
|
816
|
+
case "RSA-OAEP-256":
|
|
817
|
+
case "RSA-OAEP-384":
|
|
818
|
+
case "RSA-OAEP-512":
|
|
819
|
+
algorithm = {
|
|
820
|
+
name: "RSA-OAEP",
|
|
821
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
822
|
+
};
|
|
823
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
824
|
+
break;
|
|
825
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
826
|
+
}
|
|
827
|
+
break;
|
|
828
|
+
case "EC":
|
|
829
|
+
switch (jwk.alg) {
|
|
830
|
+
case "ES256":
|
|
831
|
+
case "ES384":
|
|
832
|
+
case "ES512":
|
|
833
|
+
algorithm = {
|
|
834
|
+
name: "ECDSA",
|
|
835
|
+
namedCurve: {
|
|
836
|
+
ES256: "P-256",
|
|
837
|
+
ES384: "P-384",
|
|
838
|
+
ES512: "P-521"
|
|
839
|
+
}[jwk.alg]
|
|
840
|
+
};
|
|
841
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
842
|
+
break;
|
|
843
|
+
case "ECDH-ES":
|
|
844
|
+
case "ECDH-ES+A128KW":
|
|
845
|
+
case "ECDH-ES+A192KW":
|
|
846
|
+
case "ECDH-ES+A256KW":
|
|
847
|
+
algorithm = {
|
|
848
|
+
name: "ECDH",
|
|
849
|
+
namedCurve: jwk.crv
|
|
850
|
+
};
|
|
851
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
852
|
+
break;
|
|
853
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
854
|
+
}
|
|
855
|
+
break;
|
|
856
|
+
case "OKP":
|
|
857
|
+
switch (jwk.alg) {
|
|
858
|
+
case "Ed25519":
|
|
859
|
+
case "EdDSA":
|
|
860
|
+
algorithm = { name: "Ed25519" };
|
|
861
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
862
|
+
break;
|
|
863
|
+
case "ECDH-ES":
|
|
864
|
+
case "ECDH-ES+A128KW":
|
|
865
|
+
case "ECDH-ES+A192KW":
|
|
866
|
+
case "ECDH-ES+A256KW":
|
|
867
|
+
algorithm = { name: jwk.crv };
|
|
868
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
869
|
+
break;
|
|
870
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
871
|
+
}
|
|
872
|
+
break;
|
|
873
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
|
|
874
|
+
}
|
|
875
|
+
return {
|
|
876
|
+
algorithm,
|
|
877
|
+
keyUsages
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
async function jwkToKey(jwk) {
|
|
881
|
+
if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
|
|
882
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
883
|
+
const keyData = { ...jwk };
|
|
884
|
+
if (keyData.kty !== "AKP") delete keyData.alg;
|
|
885
|
+
delete keyData.use;
|
|
886
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
887
|
+
}
|
|
888
|
+
//#endregion
|
|
889
|
+
//#region node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
890
|
+
const unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
891
|
+
let cache;
|
|
892
|
+
const handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
893
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
894
|
+
let cached = cache.get(key);
|
|
895
|
+
if (cached?.[alg]) return cached[alg];
|
|
896
|
+
const cryptoKey = await jwkToKey({
|
|
897
|
+
...jwk,
|
|
898
|
+
alg
|
|
899
|
+
});
|
|
900
|
+
if (freeze) Object.freeze(key);
|
|
901
|
+
if (!cached) cache.set(key, { [alg]: cryptoKey });
|
|
902
|
+
else cached[alg] = cryptoKey;
|
|
903
|
+
return cryptoKey;
|
|
904
|
+
};
|
|
905
|
+
const handleKeyObject = (keyObject, alg) => {
|
|
906
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
907
|
+
let cached = cache.get(keyObject);
|
|
908
|
+
if (cached?.[alg]) return cached[alg];
|
|
909
|
+
const isPublic = keyObject.type === "public";
|
|
910
|
+
const extractable = isPublic ? true : false;
|
|
911
|
+
let cryptoKey;
|
|
912
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
913
|
+
switch (alg) {
|
|
914
|
+
case "ECDH-ES":
|
|
915
|
+
case "ECDH-ES+A128KW":
|
|
916
|
+
case "ECDH-ES+A192KW":
|
|
917
|
+
case "ECDH-ES+A256KW": break;
|
|
918
|
+
default: throw new TypeError(unusableForAlg);
|
|
919
|
+
}
|
|
920
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
921
|
+
}
|
|
922
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
923
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") throw new TypeError(unusableForAlg);
|
|
924
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
925
|
+
}
|
|
926
|
+
switch (keyObject.asymmetricKeyType) {
|
|
927
|
+
case "ml-dsa-44":
|
|
928
|
+
case "ml-dsa-65":
|
|
929
|
+
case "ml-dsa-87":
|
|
930
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError(unusableForAlg);
|
|
931
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
932
|
+
}
|
|
933
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
934
|
+
let hash;
|
|
935
|
+
switch (alg) {
|
|
936
|
+
case "RSA-OAEP":
|
|
937
|
+
hash = "SHA-1";
|
|
938
|
+
break;
|
|
939
|
+
case "RS256":
|
|
940
|
+
case "PS256":
|
|
941
|
+
case "RSA-OAEP-256":
|
|
942
|
+
hash = "SHA-256";
|
|
943
|
+
break;
|
|
944
|
+
case "RS384":
|
|
945
|
+
case "PS384":
|
|
946
|
+
case "RSA-OAEP-384":
|
|
947
|
+
hash = "SHA-384";
|
|
948
|
+
break;
|
|
949
|
+
case "RS512":
|
|
950
|
+
case "PS512":
|
|
951
|
+
case "RSA-OAEP-512":
|
|
952
|
+
hash = "SHA-512";
|
|
953
|
+
break;
|
|
954
|
+
default: throw new TypeError(unusableForAlg);
|
|
955
|
+
}
|
|
956
|
+
if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
|
|
957
|
+
name: "RSA-OAEP",
|
|
958
|
+
hash
|
|
959
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
960
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
961
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
962
|
+
hash
|
|
963
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
964
|
+
}
|
|
965
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
966
|
+
const namedCurve = new Map([
|
|
967
|
+
["prime256v1", "P-256"],
|
|
968
|
+
["secp384r1", "P-384"],
|
|
969
|
+
["secp521r1", "P-521"]
|
|
970
|
+
]).get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
971
|
+
if (!namedCurve) throw new TypeError(unusableForAlg);
|
|
972
|
+
const expectedCurve = {
|
|
973
|
+
ES256: "P-256",
|
|
974
|
+
ES384: "P-384",
|
|
975
|
+
ES512: "P-521"
|
|
976
|
+
};
|
|
977
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) cryptoKey = keyObject.toCryptoKey({
|
|
978
|
+
name: "ECDSA",
|
|
979
|
+
namedCurve
|
|
980
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
981
|
+
if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
|
|
982
|
+
name: "ECDH",
|
|
983
|
+
namedCurve
|
|
984
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
985
|
+
}
|
|
986
|
+
if (!cryptoKey) throw new TypeError(unusableForAlg);
|
|
987
|
+
if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
|
|
988
|
+
else cached[alg] = cryptoKey;
|
|
989
|
+
return cryptoKey;
|
|
990
|
+
};
|
|
991
|
+
async function normalizeKey(key, alg) {
|
|
992
|
+
if (key instanceof Uint8Array) return key;
|
|
993
|
+
if (isCryptoKey(key)) return key;
|
|
994
|
+
if (isKeyObject(key)) {
|
|
995
|
+
if (key.type === "secret") return key.export();
|
|
996
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
|
|
997
|
+
return handleKeyObject(key, alg);
|
|
998
|
+
} catch (err) {
|
|
999
|
+
if (err instanceof TypeError) throw err;
|
|
1000
|
+
}
|
|
1001
|
+
return handleJWK(key, key.export({ format: "jwk" }), alg);
|
|
1002
|
+
}
|
|
1003
|
+
if (isJWK(key)) {
|
|
1004
|
+
if (key.k) return decode(key.k);
|
|
1005
|
+
return handleJWK(key, key, alg, true);
|
|
1006
|
+
}
|
|
1007
|
+
throw new Error("unreachable");
|
|
1008
|
+
}
|
|
1009
|
+
//#endregion
|
|
1010
|
+
//#region node_modules/jose/dist/webapi/lib/asn1.js
|
|
1011
|
+
const formatPEM = (b64, descriptor) => {
|
|
1012
|
+
return `-----BEGIN ${descriptor}-----\n${(b64.match(/.{1,64}/g) || []).join("\n")}\n-----END ${descriptor}-----`;
|
|
1013
|
+
};
|
|
1014
|
+
const genericExport = async (keyType, keyFormat, key) => {
|
|
1015
|
+
if (isKeyObject(key)) {
|
|
1016
|
+
if (key.type !== keyType) throw new TypeError(`key is not a ${keyType} key`);
|
|
1017
|
+
return key.export({
|
|
1018
|
+
format: "pem",
|
|
1019
|
+
type: keyFormat
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
if (!isCryptoKey(key)) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject"));
|
|
1023
|
+
if (!key.extractable) throw new TypeError("CryptoKey is not extractable");
|
|
1024
|
+
if (key.type !== keyType) throw new TypeError(`key is not a ${keyType} key`);
|
|
1025
|
+
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
1026
|
+
};
|
|
672
1027
|
const toSPKI = (key) => genericExport("public", "spki", key);
|
|
673
1028
|
const toPKCS8 = (key) => genericExport("private", "pkcs8", key);
|
|
674
1029
|
const bytesEqual = (a, b) => {
|
|
@@ -920,142 +1275,24 @@ const fromX509 = (pem, alg, options) => {
|
|
|
920
1275
|
return fromSPKI(formatPEM(encodeBase64(spki), "PUBLIC KEY"), alg, options);
|
|
921
1276
|
};
|
|
922
1277
|
//#endregion
|
|
923
|
-
//#region node_modules/jose/dist/webapi/
|
|
924
|
-
function
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
case "PS256":
|
|
942
|
-
case "PS384":
|
|
943
|
-
case "PS512":
|
|
944
|
-
algorithm = {
|
|
945
|
-
name: "RSA-PSS",
|
|
946
|
-
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
947
|
-
};
|
|
948
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
949
|
-
break;
|
|
950
|
-
case "RS256":
|
|
951
|
-
case "RS384":
|
|
952
|
-
case "RS512":
|
|
953
|
-
algorithm = {
|
|
954
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
955
|
-
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
956
|
-
};
|
|
957
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
958
|
-
break;
|
|
959
|
-
case "RSA-OAEP":
|
|
960
|
-
case "RSA-OAEP-256":
|
|
961
|
-
case "RSA-OAEP-384":
|
|
962
|
-
case "RSA-OAEP-512":
|
|
963
|
-
algorithm = {
|
|
964
|
-
name: "RSA-OAEP",
|
|
965
|
-
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
966
|
-
};
|
|
967
|
-
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
968
|
-
break;
|
|
969
|
-
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
970
|
-
}
|
|
971
|
-
break;
|
|
972
|
-
case "EC":
|
|
973
|
-
switch (jwk.alg) {
|
|
974
|
-
case "ES256":
|
|
975
|
-
algorithm = {
|
|
976
|
-
name: "ECDSA",
|
|
977
|
-
namedCurve: "P-256"
|
|
978
|
-
};
|
|
979
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
980
|
-
break;
|
|
981
|
-
case "ES384":
|
|
982
|
-
algorithm = {
|
|
983
|
-
name: "ECDSA",
|
|
984
|
-
namedCurve: "P-384"
|
|
985
|
-
};
|
|
986
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
987
|
-
break;
|
|
988
|
-
case "ES512":
|
|
989
|
-
algorithm = {
|
|
990
|
-
name: "ECDSA",
|
|
991
|
-
namedCurve: "P-521"
|
|
992
|
-
};
|
|
993
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
994
|
-
break;
|
|
995
|
-
case "ECDH-ES":
|
|
996
|
-
case "ECDH-ES+A128KW":
|
|
997
|
-
case "ECDH-ES+A192KW":
|
|
998
|
-
case "ECDH-ES+A256KW":
|
|
999
|
-
algorithm = {
|
|
1000
|
-
name: "ECDH",
|
|
1001
|
-
namedCurve: jwk.crv
|
|
1002
|
-
};
|
|
1003
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1004
|
-
break;
|
|
1005
|
-
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
1006
|
-
}
|
|
1007
|
-
break;
|
|
1008
|
-
case "OKP":
|
|
1009
|
-
switch (jwk.alg) {
|
|
1010
|
-
case "Ed25519":
|
|
1011
|
-
case "EdDSA":
|
|
1012
|
-
algorithm = { name: "Ed25519" };
|
|
1013
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1014
|
-
break;
|
|
1015
|
-
case "ECDH-ES":
|
|
1016
|
-
case "ECDH-ES+A128KW":
|
|
1017
|
-
case "ECDH-ES+A192KW":
|
|
1018
|
-
case "ECDH-ES+A256KW":
|
|
1019
|
-
algorithm = { name: jwk.crv };
|
|
1020
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1021
|
-
break;
|
|
1022
|
-
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
1023
|
-
}
|
|
1024
|
-
break;
|
|
1025
|
-
default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
|
|
1026
|
-
}
|
|
1027
|
-
return {
|
|
1028
|
-
algorithm,
|
|
1029
|
-
keyUsages
|
|
1030
|
-
};
|
|
1031
|
-
}
|
|
1032
|
-
async function jwkToKey(jwk) {
|
|
1033
|
-
if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
|
|
1034
|
-
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
1035
|
-
const keyData = { ...jwk };
|
|
1036
|
-
if (keyData.kty !== "AKP") delete keyData.alg;
|
|
1037
|
-
delete keyData.use;
|
|
1038
|
-
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
1039
|
-
}
|
|
1040
|
-
//#endregion
|
|
1041
|
-
//#region node_modules/jose/dist/webapi/key/import.js
|
|
1042
|
-
async function importSPKI(spki, alg, options) {
|
|
1043
|
-
if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) throw new TypeError("\"spki\" must be SPKI formatted string");
|
|
1044
|
-
return fromSPKI(spki, alg, options);
|
|
1045
|
-
}
|
|
1046
|
-
async function importX509(x509, alg, options) {
|
|
1047
|
-
if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) throw new TypeError("\"x509\" must be X.509 formatted string");
|
|
1048
|
-
return fromX509(x509, alg, options);
|
|
1049
|
-
}
|
|
1050
|
-
async function importPKCS8(pkcs8, alg, options) {
|
|
1051
|
-
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) throw new TypeError("\"pkcs8\" must be PKCS#8 formatted string");
|
|
1052
|
-
return fromPKCS8(pkcs8, alg, options);
|
|
1053
|
-
}
|
|
1054
|
-
async function importJWK(jwk, alg, options) {
|
|
1055
|
-
if (!isObject(jwk)) throw new TypeError("JWK must be an object");
|
|
1056
|
-
let ext;
|
|
1057
|
-
alg ??= jwk.alg;
|
|
1058
|
-
ext ??= options?.extractable ?? jwk.ext;
|
|
1278
|
+
//#region node_modules/jose/dist/webapi/key/import.js
|
|
1279
|
+
async function importSPKI(spki, alg, options) {
|
|
1280
|
+
if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) throw new TypeError("\"spki\" must be SPKI formatted string");
|
|
1281
|
+
return fromSPKI(spki, alg, options);
|
|
1282
|
+
}
|
|
1283
|
+
async function importX509(x509, alg, options) {
|
|
1284
|
+
if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) throw new TypeError("\"x509\" must be X.509 formatted string");
|
|
1285
|
+
return fromX509(x509, alg, options);
|
|
1286
|
+
}
|
|
1287
|
+
async function importPKCS8(pkcs8, alg, options) {
|
|
1288
|
+
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) throw new TypeError("\"pkcs8\" must be PKCS#8 formatted string");
|
|
1289
|
+
return fromPKCS8(pkcs8, alg, options);
|
|
1290
|
+
}
|
|
1291
|
+
async function importJWK(jwk, alg, options) {
|
|
1292
|
+
if (!isObject(jwk)) throw new TypeError("JWK must be an object");
|
|
1293
|
+
let ext;
|
|
1294
|
+
alg ??= jwk.alg;
|
|
1295
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
1059
1296
|
switch (jwk.kty) {
|
|
1060
1297
|
case "oct":
|
|
1061
1298
|
if (typeof jwk.k !== "string" || !jwk.k) throw new TypeError("missing \"k\" (Key Value) Parameter value");
|
|
@@ -1084,68 +1321,35 @@ async function importJWK(jwk, alg, options) {
|
|
|
1084
1321
|
}
|
|
1085
1322
|
}
|
|
1086
1323
|
//#endregion
|
|
1087
|
-
//#region node_modules/jose/dist/webapi/lib/
|
|
1088
|
-
async function
|
|
1089
|
-
if (
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
name: "HMAC"
|
|
1095
|
-
}, false, ["sign"]);
|
|
1096
|
-
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
1097
|
-
iv,
|
|
1098
|
-
name: "AES-CBC"
|
|
1099
|
-
}, encKey, plaintext));
|
|
1100
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
1101
|
-
return {
|
|
1102
|
-
ciphertext,
|
|
1103
|
-
tag: new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3)),
|
|
1104
|
-
iv
|
|
1324
|
+
//#region node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
1325
|
+
async function keyToJWK(key) {
|
|
1326
|
+
if (isKeyObject(key)) if (key.type === "secret") key = key.export();
|
|
1327
|
+
else return key.export({ format: "jwk" });
|
|
1328
|
+
if (key instanceof Uint8Array) return {
|
|
1329
|
+
kty: "oct",
|
|
1330
|
+
k: encode(key)
|
|
1105
1331
|
};
|
|
1332
|
+
if (!isCryptoKey(key)) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
1333
|
+
if (!key.extractable) throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
1334
|
+
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
1335
|
+
if (jwk.kty === "AKP") jwk.alg = alg;
|
|
1336
|
+
return jwk;
|
|
1106
1337
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
checkEncCryptoKey(cek, enc, "encrypt");
|
|
1112
|
-
encKey = cek;
|
|
1113
|
-
}
|
|
1114
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
1115
|
-
additionalData: aad,
|
|
1116
|
-
iv,
|
|
1117
|
-
name: "AES-GCM",
|
|
1118
|
-
tagLength: 128
|
|
1119
|
-
}, encKey, plaintext));
|
|
1120
|
-
const tag = encrypted.slice(-16);
|
|
1121
|
-
return {
|
|
1122
|
-
ciphertext: encrypted.slice(0, -16),
|
|
1123
|
-
tag,
|
|
1124
|
-
iv
|
|
1125
|
-
};
|
|
1338
|
+
//#endregion
|
|
1339
|
+
//#region node_modules/jose/dist/webapi/key/export.js
|
|
1340
|
+
async function exportSPKI(key) {
|
|
1341
|
+
return toSPKI(key);
|
|
1126
1342
|
}
|
|
1127
|
-
async function
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
case "A128CBC-HS256":
|
|
1133
|
-
case "A192CBC-HS384":
|
|
1134
|
-
case "A256CBC-HS512":
|
|
1135
|
-
if (cek instanceof Uint8Array) checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
1136
|
-
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
1137
|
-
case "A128GCM":
|
|
1138
|
-
case "A192GCM":
|
|
1139
|
-
case "A256GCM":
|
|
1140
|
-
if (cek instanceof Uint8Array) checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
1141
|
-
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
1142
|
-
default: throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
1143
|
-
}
|
|
1343
|
+
async function exportPKCS8(key) {
|
|
1344
|
+
return toPKCS8(key);
|
|
1345
|
+
}
|
|
1346
|
+
async function exportJWK(key) {
|
|
1347
|
+
return keyToJWK(key);
|
|
1144
1348
|
}
|
|
1145
1349
|
//#endregion
|
|
1146
1350
|
//#region node_modules/jose/dist/webapi/lib/aesgcmkw.js
|
|
1147
1351
|
async function wrap(alg, key, cek, iv) {
|
|
1148
|
-
const wrapped = await encrypt(alg.slice(0, 7), cek, key, iv, new Uint8Array());
|
|
1352
|
+
const wrapped = await encrypt$1(alg.slice(0, 7), cek, key, iv, new Uint8Array());
|
|
1149
1353
|
return {
|
|
1150
1354
|
encryptedKey: wrapped.ciphertext,
|
|
1151
1355
|
iv: encode(wrapped.iv),
|
|
@@ -1156,7 +1360,11 @@ async function unwrap(alg, key, encryptedKey, iv, tag) {
|
|
|
1156
1360
|
return decrypt$1(alg.slice(0, 7), key, encryptedKey, iv, tag, new Uint8Array());
|
|
1157
1361
|
}
|
|
1158
1362
|
//#endregion
|
|
1159
|
-
//#region node_modules/jose/dist/webapi/lib/
|
|
1363
|
+
//#region node_modules/jose/dist/webapi/lib/key_management.js
|
|
1364
|
+
const unsupportedAlgHeader = "Invalid or unsupported \"alg\" (JWE Algorithm) header value";
|
|
1365
|
+
function assertEncryptedKey(encryptedKey) {
|
|
1366
|
+
if (encryptedKey === void 0) throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1367
|
+
}
|
|
1160
1368
|
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
1161
1369
|
switch (alg) {
|
|
1162
1370
|
case "dir":
|
|
@@ -1175,227 +1383,152 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options)
|
|
|
1175
1383
|
let partyVInfo;
|
|
1176
1384
|
if (joseHeader.apu !== void 0) {
|
|
1177
1385
|
if (typeof joseHeader.apu !== "string") throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
1178
|
-
|
|
1179
|
-
partyUInfo = decode(joseHeader.apu);
|
|
1180
|
-
} catch {
|
|
1181
|
-
throw new JWEInvalid("Failed to base64url decode the apu");
|
|
1182
|
-
}
|
|
1386
|
+
partyUInfo = decodeBase64url(joseHeader.apu, "apu", JWEInvalid);
|
|
1183
1387
|
}
|
|
1184
1388
|
if (joseHeader.apv !== void 0) {
|
|
1185
1389
|
if (typeof joseHeader.apv !== "string") throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
1186
|
-
|
|
1187
|
-
partyVInfo = decode(joseHeader.apv);
|
|
1188
|
-
} catch {
|
|
1189
|
-
throw new JWEInvalid("Failed to base64url decode the apv");
|
|
1190
|
-
}
|
|
1390
|
+
partyVInfo = decodeBase64url(joseHeader.apv, "apv", JWEInvalid);
|
|
1191
1391
|
}
|
|
1192
1392
|
const sharedSecret = await deriveKey$1(epk, key, alg === "ECDH-ES" ? joseHeader.enc : alg, alg === "ECDH-ES" ? cekLength(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
1193
1393
|
if (alg === "ECDH-ES") return sharedSecret;
|
|
1194
|
-
|
|
1394
|
+
assertEncryptedKey(encryptedKey);
|
|
1195
1395
|
return unwrap$2(alg.slice(-6), sharedSecret, encryptedKey);
|
|
1196
1396
|
}
|
|
1197
1397
|
case "RSA-OAEP":
|
|
1198
1398
|
case "RSA-OAEP-256":
|
|
1199
1399
|
case "RSA-OAEP-384":
|
|
1200
1400
|
case "RSA-OAEP-512":
|
|
1201
|
-
|
|
1401
|
+
assertEncryptedKey(encryptedKey);
|
|
1202
1402
|
assertCryptoKey(key);
|
|
1203
1403
|
return decrypt(alg, key, encryptedKey);
|
|
1204
1404
|
case "PBES2-HS256+A128KW":
|
|
1205
1405
|
case "PBES2-HS384+A192KW":
|
|
1206
1406
|
case "PBES2-HS512+A256KW": {
|
|
1207
|
-
|
|
1407
|
+
assertEncryptedKey(encryptedKey);
|
|
1208
1408
|
if (typeof joseHeader.p2c !== "number") throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
1209
1409
|
const p2cLimit = options?.maxPBES2Count || 1e4;
|
|
1210
1410
|
if (joseHeader.p2c > p2cLimit) throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
1211
1411
|
if (typeof joseHeader.p2s !== "string") throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
1212
1412
|
let p2s;
|
|
1213
|
-
|
|
1214
|
-
p2s = decode(joseHeader.p2s);
|
|
1215
|
-
} catch {
|
|
1216
|
-
throw new JWEInvalid("Failed to base64url decode the p2s");
|
|
1217
|
-
}
|
|
1413
|
+
p2s = decodeBase64url(joseHeader.p2s, "p2s", JWEInvalid);
|
|
1218
1414
|
return unwrap$1(alg, key, encryptedKey, joseHeader.p2c, p2s);
|
|
1219
1415
|
}
|
|
1220
1416
|
case "A128KW":
|
|
1221
1417
|
case "A192KW":
|
|
1222
1418
|
case "A256KW":
|
|
1223
|
-
|
|
1419
|
+
assertEncryptedKey(encryptedKey);
|
|
1224
1420
|
return unwrap$2(alg, key, encryptedKey);
|
|
1225
1421
|
case "A128GCMKW":
|
|
1226
1422
|
case "A192GCMKW":
|
|
1227
1423
|
case "A256GCMKW": {
|
|
1228
|
-
|
|
1424
|
+
assertEncryptedKey(encryptedKey);
|
|
1229
1425
|
if (typeof joseHeader.iv !== "string") throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
1230
1426
|
if (typeof joseHeader.tag !== "string") throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
1231
1427
|
let iv;
|
|
1232
|
-
|
|
1233
|
-
iv = decode(joseHeader.iv);
|
|
1234
|
-
} catch {
|
|
1235
|
-
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
1236
|
-
}
|
|
1428
|
+
iv = decodeBase64url(joseHeader.iv, "iv", JWEInvalid);
|
|
1237
1429
|
let tag;
|
|
1238
|
-
|
|
1239
|
-
tag = decode(joseHeader.tag);
|
|
1240
|
-
} catch {
|
|
1241
|
-
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
1242
|
-
}
|
|
1430
|
+
tag = decodeBase64url(joseHeader.tag, "tag", JWEInvalid);
|
|
1243
1431
|
return unwrap(alg, key, encryptedKey, iv, tag);
|
|
1244
1432
|
}
|
|
1245
|
-
default: throw new JOSENotSupported(
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
//#endregion
|
|
1249
|
-
//#region node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1250
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1251
|
-
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
|
|
1252
|
-
if (!protectedHeader || protectedHeader.crit === void 0) return /* @__PURE__ */ new Set();
|
|
1253
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
|
|
1254
|
-
let recognized;
|
|
1255
|
-
if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1256
|
-
else recognized = recognizedDefault;
|
|
1257
|
-
for (const parameter of protectedHeader.crit) {
|
|
1258
|
-
if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1259
|
-
if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1260
|
-
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1433
|
+
default: throw new JOSENotSupported(unsupportedAlgHeader);
|
|
1261
1434
|
}
|
|
1262
|
-
return new Set(protectedHeader.crit);
|
|
1263
1435
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
let
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
let cryptoKey;
|
|
1300
|
-
if (keyObject.asymmetricKeyType === "x25519") {
|
|
1301
|
-
switch (alg) {
|
|
1302
|
-
case "ECDH-ES":
|
|
1303
|
-
case "ECDH-ES+A128KW":
|
|
1304
|
-
case "ECDH-ES+A192KW":
|
|
1305
|
-
case "ECDH-ES+A256KW": break;
|
|
1306
|
-
default: throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1307
|
-
}
|
|
1308
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1309
|
-
}
|
|
1310
|
-
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
1311
|
-
if (alg !== "EdDSA" && alg !== "Ed25519") throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1312
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
1313
|
-
}
|
|
1314
|
-
switch (keyObject.asymmetricKeyType) {
|
|
1315
|
-
case "ml-dsa-44":
|
|
1316
|
-
case "ml-dsa-65":
|
|
1317
|
-
case "ml-dsa-87":
|
|
1318
|
-
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1319
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
1320
|
-
}
|
|
1321
|
-
if (keyObject.asymmetricKeyType === "rsa") {
|
|
1322
|
-
let hash;
|
|
1323
|
-
switch (alg) {
|
|
1324
|
-
case "RSA-OAEP":
|
|
1325
|
-
hash = "SHA-1";
|
|
1326
|
-
break;
|
|
1327
|
-
case "RS256":
|
|
1328
|
-
case "PS256":
|
|
1329
|
-
case "RSA-OAEP-256":
|
|
1330
|
-
hash = "SHA-256";
|
|
1331
|
-
break;
|
|
1332
|
-
case "RS384":
|
|
1333
|
-
case "PS384":
|
|
1334
|
-
case "RSA-OAEP-384":
|
|
1335
|
-
hash = "SHA-384";
|
|
1336
|
-
break;
|
|
1337
|
-
case "RS512":
|
|
1338
|
-
case "PS512":
|
|
1339
|
-
case "RSA-OAEP-512":
|
|
1340
|
-
hash = "SHA-512";
|
|
1341
|
-
break;
|
|
1342
|
-
default: throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1343
|
-
}
|
|
1344
|
-
if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
|
|
1345
|
-
name: "RSA-OAEP",
|
|
1346
|
-
hash
|
|
1347
|
-
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
1348
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1349
|
-
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
1350
|
-
hash
|
|
1351
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1352
|
-
}
|
|
1353
|
-
if (keyObject.asymmetricKeyType === "ec") {
|
|
1354
|
-
const namedCurve = new Map([
|
|
1355
|
-
["prime256v1", "P-256"],
|
|
1356
|
-
["secp384r1", "P-384"],
|
|
1357
|
-
["secp521r1", "P-521"]
|
|
1358
|
-
]).get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
1359
|
-
if (!namedCurve) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1360
|
-
if (alg === "ES256" && namedCurve === "P-256") cryptoKey = keyObject.toCryptoKey({
|
|
1361
|
-
name: "ECDSA",
|
|
1362
|
-
namedCurve
|
|
1363
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1364
|
-
if (alg === "ES384" && namedCurve === "P-384") cryptoKey = keyObject.toCryptoKey({
|
|
1365
|
-
name: "ECDSA",
|
|
1366
|
-
namedCurve
|
|
1367
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1368
|
-
if (alg === "ES512" && namedCurve === "P-521") cryptoKey = keyObject.toCryptoKey({
|
|
1369
|
-
name: "ECDSA",
|
|
1370
|
-
namedCurve
|
|
1371
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1372
|
-
if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
|
|
1373
|
-
name: "ECDH",
|
|
1374
|
-
namedCurve
|
|
1375
|
-
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1376
|
-
}
|
|
1377
|
-
if (!cryptoKey) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1378
|
-
if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
|
|
1379
|
-
else cached[alg] = cryptoKey;
|
|
1380
|
-
return cryptoKey;
|
|
1381
|
-
};
|
|
1382
|
-
async function normalizeKey(key, alg) {
|
|
1383
|
-
if (key instanceof Uint8Array) return key;
|
|
1384
|
-
if (isCryptoKey(key)) return key;
|
|
1385
|
-
if (isKeyObject(key)) {
|
|
1386
|
-
if (key.type === "secret") return key.export();
|
|
1387
|
-
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
|
|
1388
|
-
return handleKeyObject(key, alg);
|
|
1389
|
-
} catch (err) {
|
|
1390
|
-
if (err instanceof TypeError) throw err;
|
|
1436
|
+
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
1437
|
+
let encryptedKey;
|
|
1438
|
+
let parameters;
|
|
1439
|
+
let cek;
|
|
1440
|
+
switch (alg) {
|
|
1441
|
+
case "dir":
|
|
1442
|
+
cek = key;
|
|
1443
|
+
break;
|
|
1444
|
+
case "ECDH-ES":
|
|
1445
|
+
case "ECDH-ES+A128KW":
|
|
1446
|
+
case "ECDH-ES+A192KW":
|
|
1447
|
+
case "ECDH-ES+A256KW": {
|
|
1448
|
+
assertCryptoKey(key);
|
|
1449
|
+
if (!allowed(key)) throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
1450
|
+
const { apu, apv } = providedParameters;
|
|
1451
|
+
let ephemeralKey;
|
|
1452
|
+
if (providedParameters.epk) ephemeralKey = await normalizeKey(providedParameters.epk, alg);
|
|
1453
|
+
else ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
1454
|
+
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
1455
|
+
const sharedSecret = await deriveKey$1(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
1456
|
+
parameters = { epk: {
|
|
1457
|
+
x,
|
|
1458
|
+
crv,
|
|
1459
|
+
kty
|
|
1460
|
+
} };
|
|
1461
|
+
if (kty === "EC") parameters.epk.y = y;
|
|
1462
|
+
if (apu) parameters.apu = encode(apu);
|
|
1463
|
+
if (apv) parameters.apv = encode(apv);
|
|
1464
|
+
if (alg === "ECDH-ES") {
|
|
1465
|
+
cek = sharedSecret;
|
|
1466
|
+
break;
|
|
1467
|
+
}
|
|
1468
|
+
cek = providedCek || generateCek(enc);
|
|
1469
|
+
encryptedKey = await wrap$2(alg.slice(-6), sharedSecret, cek);
|
|
1470
|
+
break;
|
|
1391
1471
|
}
|
|
1392
|
-
|
|
1472
|
+
case "RSA-OAEP":
|
|
1473
|
+
case "RSA-OAEP-256":
|
|
1474
|
+
case "RSA-OAEP-384":
|
|
1475
|
+
case "RSA-OAEP-512":
|
|
1476
|
+
cek = providedCek || generateCek(enc);
|
|
1477
|
+
assertCryptoKey(key);
|
|
1478
|
+
encryptedKey = await encrypt(alg, key, cek);
|
|
1479
|
+
break;
|
|
1480
|
+
case "PBES2-HS256+A128KW":
|
|
1481
|
+
case "PBES2-HS384+A192KW":
|
|
1482
|
+
case "PBES2-HS512+A256KW": {
|
|
1483
|
+
cek = providedCek || generateCek(enc);
|
|
1484
|
+
const { p2c, p2s } = providedParameters;
|
|
1485
|
+
({encryptedKey, ...parameters} = await wrap$1(alg, key, cek, p2c, p2s));
|
|
1486
|
+
break;
|
|
1487
|
+
}
|
|
1488
|
+
case "A128KW":
|
|
1489
|
+
case "A192KW":
|
|
1490
|
+
case "A256KW":
|
|
1491
|
+
cek = providedCek || generateCek(enc);
|
|
1492
|
+
encryptedKey = await wrap$2(alg, key, cek);
|
|
1493
|
+
break;
|
|
1494
|
+
case "A128GCMKW":
|
|
1495
|
+
case "A192GCMKW":
|
|
1496
|
+
case "A256GCMKW": {
|
|
1497
|
+
cek = providedCek || generateCek(enc);
|
|
1498
|
+
const { iv } = providedParameters;
|
|
1499
|
+
({encryptedKey, ...parameters} = await wrap(alg, key, cek, iv));
|
|
1500
|
+
break;
|
|
1501
|
+
}
|
|
1502
|
+
default: throw new JOSENotSupported(unsupportedAlgHeader);
|
|
1393
1503
|
}
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1504
|
+
return {
|
|
1505
|
+
cek,
|
|
1506
|
+
encryptedKey,
|
|
1507
|
+
parameters
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
//#endregion
|
|
1511
|
+
//#region node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1512
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1513
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
|
|
1514
|
+
if (!protectedHeader || protectedHeader.crit === void 0) return /* @__PURE__ */ new Set();
|
|
1515
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
|
|
1516
|
+
let recognized;
|
|
1517
|
+
if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1518
|
+
else recognized = recognizedDefault;
|
|
1519
|
+
for (const parameter of protectedHeader.crit) {
|
|
1520
|
+
if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1521
|
+
if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1522
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1397
1523
|
}
|
|
1398
|
-
|
|
1524
|
+
return new Set(protectedHeader.crit);
|
|
1525
|
+
}
|
|
1526
|
+
//#endregion
|
|
1527
|
+
//#region node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
1528
|
+
function validateAlgorithms(option, algorithms) {
|
|
1529
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
|
|
1530
|
+
if (!algorithms) return;
|
|
1531
|
+
return new Set(algorithms);
|
|
1399
1532
|
}
|
|
1400
1533
|
//#endregion
|
|
1401
1534
|
//#region node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
@@ -1560,11 +1693,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
1560
1693
|
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
|
|
1561
1694
|
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) throw new JOSEAlgNotAllowed("\"enc\" (Encryption Algorithm) Header Parameter value not allowed");
|
|
1562
1695
|
let encryptedKey;
|
|
1563
|
-
if (jwe.encrypted_key !== void 0)
|
|
1564
|
-
encryptedKey = decode(jwe.encrypted_key);
|
|
1565
|
-
} catch {
|
|
1566
|
-
throw new JWEInvalid("Failed to base64url decode the encrypted_key");
|
|
1567
|
-
}
|
|
1696
|
+
if (jwe.encrypted_key !== void 0) encryptedKey = decodeBase64url(jwe.encrypted_key, "encrypted_key", JWEInvalid);
|
|
1568
1697
|
let resolvedKey = false;
|
|
1569
1698
|
if (typeof key === "function") {
|
|
1570
1699
|
key = await key(parsedProt, jwe);
|
|
@@ -1581,26 +1710,13 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
1581
1710
|
}
|
|
1582
1711
|
let iv;
|
|
1583
1712
|
let tag;
|
|
1584
|
-
if (jwe.iv !== void 0)
|
|
1585
|
-
|
|
1586
|
-
} catch {
|
|
1587
|
-
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
1588
|
-
}
|
|
1589
|
-
if (jwe.tag !== void 0) try {
|
|
1590
|
-
tag = decode(jwe.tag);
|
|
1591
|
-
} catch {
|
|
1592
|
-
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
1593
|
-
}
|
|
1713
|
+
if (jwe.iv !== void 0) iv = decodeBase64url(jwe.iv, "iv", JWEInvalid);
|
|
1714
|
+
if (jwe.tag !== void 0) tag = decodeBase64url(jwe.tag, "tag", JWEInvalid);
|
|
1594
1715
|
const protectedHeader = jwe.protected !== void 0 ? encode$1(jwe.protected) : new Uint8Array();
|
|
1595
1716
|
let additionalData;
|
|
1596
1717
|
if (jwe.aad !== void 0) additionalData = concat(protectedHeader, encode$1("."), encode$1(jwe.aad));
|
|
1597
1718
|
else additionalData = protectedHeader;
|
|
1598
|
-
|
|
1599
|
-
try {
|
|
1600
|
-
ciphertext = decode(jwe.ciphertext);
|
|
1601
|
-
} catch {
|
|
1602
|
-
throw new JWEInvalid("Failed to base64url decode the ciphertext");
|
|
1603
|
-
}
|
|
1719
|
+
const ciphertext = decodeBase64url(jwe.ciphertext, "ciphertext", JWEInvalid);
|
|
1604
1720
|
const plaintext = await decrypt$1(enc, cek, ciphertext, iv, tag, additionalData);
|
|
1605
1721
|
const result = { plaintext };
|
|
1606
1722
|
if (joseHeader.zip === "DEF") {
|
|
@@ -1610,11 +1726,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
1610
1726
|
result.plaintext = await decompress(plaintext, maxDecompressedLength);
|
|
1611
1727
|
}
|
|
1612
1728
|
if (jwe.protected !== void 0) result.protectedHeader = parsedProt;
|
|
1613
|
-
if (jwe.aad !== void 0)
|
|
1614
|
-
result.additionalAuthenticatedData = decode(jwe.aad);
|
|
1615
|
-
} catch {
|
|
1616
|
-
throw new JWEInvalid("Failed to base64url decode the aad");
|
|
1617
|
-
}
|
|
1729
|
+
if (jwe.aad !== void 0) result.additionalAuthenticatedData = decodeBase64url(jwe.aad, "aad", JWEInvalid);
|
|
1618
1730
|
if (jwe.unprotected !== void 0) result.sharedUnprotectedHeader = jwe.unprotected;
|
|
1619
1731
|
if (jwe.header !== void 0) result.unprotectedHeader = jwe.header;
|
|
1620
1732
|
if (resolvedKey) return {
|
|
@@ -1668,111 +1780,6 @@ async function generalDecrypt(jwe, key, options) {
|
|
|
1668
1780
|
throw new JWEDecryptionFailed();
|
|
1669
1781
|
}
|
|
1670
1782
|
//#endregion
|
|
1671
|
-
//#region node_modules/jose/dist/webapi/lib/private_symbols.js
|
|
1672
|
-
const unprotected = Symbol();
|
|
1673
|
-
//#endregion
|
|
1674
|
-
//#region node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
1675
|
-
async function keyToJWK(key) {
|
|
1676
|
-
if (isKeyObject(key)) if (key.type === "secret") key = key.export();
|
|
1677
|
-
else return key.export({ format: "jwk" });
|
|
1678
|
-
if (key instanceof Uint8Array) return {
|
|
1679
|
-
kty: "oct",
|
|
1680
|
-
k: encode(key)
|
|
1681
|
-
};
|
|
1682
|
-
if (!isCryptoKey(key)) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
1683
|
-
if (!key.extractable) throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
1684
|
-
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
1685
|
-
if (jwk.kty === "AKP") jwk.alg = alg;
|
|
1686
|
-
return jwk;
|
|
1687
|
-
}
|
|
1688
|
-
//#endregion
|
|
1689
|
-
//#region node_modules/jose/dist/webapi/key/export.js
|
|
1690
|
-
async function exportSPKI(key) {
|
|
1691
|
-
return toSPKI(key);
|
|
1692
|
-
}
|
|
1693
|
-
async function exportPKCS8(key) {
|
|
1694
|
-
return toPKCS8(key);
|
|
1695
|
-
}
|
|
1696
|
-
async function exportJWK(key) {
|
|
1697
|
-
return keyToJWK(key);
|
|
1698
|
-
}
|
|
1699
|
-
//#endregion
|
|
1700
|
-
//#region node_modules/jose/dist/webapi/lib/encrypt_key_management.js
|
|
1701
|
-
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
1702
|
-
let encryptedKey;
|
|
1703
|
-
let parameters;
|
|
1704
|
-
let cek;
|
|
1705
|
-
switch (alg) {
|
|
1706
|
-
case "dir":
|
|
1707
|
-
cek = key;
|
|
1708
|
-
break;
|
|
1709
|
-
case "ECDH-ES":
|
|
1710
|
-
case "ECDH-ES+A128KW":
|
|
1711
|
-
case "ECDH-ES+A192KW":
|
|
1712
|
-
case "ECDH-ES+A256KW": {
|
|
1713
|
-
assertCryptoKey(key);
|
|
1714
|
-
if (!allowed(key)) throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
1715
|
-
const { apu, apv } = providedParameters;
|
|
1716
|
-
let ephemeralKey;
|
|
1717
|
-
if (providedParameters.epk) ephemeralKey = await normalizeKey(providedParameters.epk, alg);
|
|
1718
|
-
else ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
1719
|
-
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
1720
|
-
const sharedSecret = await deriveKey$1(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
1721
|
-
parameters = { epk: {
|
|
1722
|
-
x,
|
|
1723
|
-
crv,
|
|
1724
|
-
kty
|
|
1725
|
-
} };
|
|
1726
|
-
if (kty === "EC") parameters.epk.y = y;
|
|
1727
|
-
if (apu) parameters.apu = encode(apu);
|
|
1728
|
-
if (apv) parameters.apv = encode(apv);
|
|
1729
|
-
if (alg === "ECDH-ES") {
|
|
1730
|
-
cek = sharedSecret;
|
|
1731
|
-
break;
|
|
1732
|
-
}
|
|
1733
|
-
cek = providedCek || generateCek(enc);
|
|
1734
|
-
encryptedKey = await wrap$2(alg.slice(-6), sharedSecret, cek);
|
|
1735
|
-
break;
|
|
1736
|
-
}
|
|
1737
|
-
case "RSA-OAEP":
|
|
1738
|
-
case "RSA-OAEP-256":
|
|
1739
|
-
case "RSA-OAEP-384":
|
|
1740
|
-
case "RSA-OAEP-512":
|
|
1741
|
-
cek = providedCek || generateCek(enc);
|
|
1742
|
-
assertCryptoKey(key);
|
|
1743
|
-
encryptedKey = await encrypt$1(alg, key, cek);
|
|
1744
|
-
break;
|
|
1745
|
-
case "PBES2-HS256+A128KW":
|
|
1746
|
-
case "PBES2-HS384+A192KW":
|
|
1747
|
-
case "PBES2-HS512+A256KW": {
|
|
1748
|
-
cek = providedCek || generateCek(enc);
|
|
1749
|
-
const { p2c, p2s } = providedParameters;
|
|
1750
|
-
({encryptedKey, ...parameters} = await wrap$1(alg, key, cek, p2c, p2s));
|
|
1751
|
-
break;
|
|
1752
|
-
}
|
|
1753
|
-
case "A128KW":
|
|
1754
|
-
case "A192KW":
|
|
1755
|
-
case "A256KW":
|
|
1756
|
-
cek = providedCek || generateCek(enc);
|
|
1757
|
-
encryptedKey = await wrap$2(alg, key, cek);
|
|
1758
|
-
break;
|
|
1759
|
-
case "A128GCMKW":
|
|
1760
|
-
case "A192GCMKW":
|
|
1761
|
-
case "A256GCMKW": {
|
|
1762
|
-
cek = providedCek || generateCek(enc);
|
|
1763
|
-
const { iv } = providedParameters;
|
|
1764
|
-
({encryptedKey, ...parameters} = await wrap(alg, key, cek, iv));
|
|
1765
|
-
break;
|
|
1766
|
-
}
|
|
1767
|
-
default: throw new JOSENotSupported("Invalid or unsupported \"alg\" (JWE Algorithm) header value");
|
|
1768
|
-
}
|
|
1769
|
-
return {
|
|
1770
|
-
cek,
|
|
1771
|
-
encryptedKey,
|
|
1772
|
-
parameters
|
|
1773
|
-
};
|
|
1774
|
-
}
|
|
1775
|
-
//#endregion
|
|
1776
1783
|
//#region node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
1777
1784
|
var FlattenedEncrypt = class {
|
|
1778
1785
|
#plaintext;
|
|
@@ -1788,22 +1795,22 @@ var FlattenedEncrypt = class {
|
|
|
1788
1795
|
this.#plaintext = plaintext;
|
|
1789
1796
|
}
|
|
1790
1797
|
setKeyManagementParameters(parameters) {
|
|
1791
|
-
|
|
1798
|
+
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
1792
1799
|
this.#keyManagementParameters = parameters;
|
|
1793
1800
|
return this;
|
|
1794
1801
|
}
|
|
1795
1802
|
setProtectedHeader(protectedHeader) {
|
|
1796
|
-
|
|
1803
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
1797
1804
|
this.#protectedHeader = protectedHeader;
|
|
1798
1805
|
return this;
|
|
1799
1806
|
}
|
|
1800
1807
|
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
1801
|
-
|
|
1808
|
+
assertNotSet(this.#sharedUnprotectedHeader, "setSharedUnprotectedHeader");
|
|
1802
1809
|
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
1803
1810
|
return this;
|
|
1804
1811
|
}
|
|
1805
1812
|
setUnprotectedHeader(unprotectedHeader) {
|
|
1806
|
-
|
|
1813
|
+
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
1807
1814
|
this.#unprotectedHeader = unprotectedHeader;
|
|
1808
1815
|
return this;
|
|
1809
1816
|
}
|
|
@@ -1812,12 +1819,12 @@ var FlattenedEncrypt = class {
|
|
|
1812
1819
|
return this;
|
|
1813
1820
|
}
|
|
1814
1821
|
setContentEncryptionKey(cek) {
|
|
1815
|
-
|
|
1822
|
+
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
1816
1823
|
this.#cek = cek;
|
|
1817
1824
|
return this;
|
|
1818
1825
|
}
|
|
1819
1826
|
setInitializationVector(iv) {
|
|
1820
|
-
|
|
1827
|
+
assertNotSet(this.#iv, "setInitializationVector");
|
|
1821
1828
|
this.#iv = iv;
|
|
1822
1829
|
return this;
|
|
1823
1830
|
}
|
|
@@ -1872,7 +1879,7 @@ var FlattenedEncrypt = class {
|
|
|
1872
1879
|
} else additionalData = protectedHeaderB;
|
|
1873
1880
|
let plaintext = this.#plaintext;
|
|
1874
1881
|
if (joseHeader.zip === "DEF") plaintext = await compress(plaintext);
|
|
1875
|
-
const { ciphertext, tag, iv } = await encrypt(enc, plaintext, cek, this.#iv, additionalData);
|
|
1882
|
+
const { ciphertext, tag, iv } = await encrypt$1(enc, plaintext, cek, this.#iv, additionalData);
|
|
1876
1883
|
const jwe = { ciphertext: encode(ciphertext) };
|
|
1877
1884
|
if (iv) jwe.iv = encode(iv);
|
|
1878
1885
|
if (tag) jwe.tag = encode(tag);
|
|
@@ -1898,12 +1905,12 @@ var IndividualRecipient = class {
|
|
|
1898
1905
|
this.options = options;
|
|
1899
1906
|
}
|
|
1900
1907
|
setUnprotectedHeader(unprotectedHeader) {
|
|
1901
|
-
|
|
1908
|
+
assertNotSet(this.unprotectedHeader, "setUnprotectedHeader");
|
|
1902
1909
|
this.unprotectedHeader = unprotectedHeader;
|
|
1903
1910
|
return this;
|
|
1904
1911
|
}
|
|
1905
1912
|
setKeyManagementParameters(parameters) {
|
|
1906
|
-
|
|
1913
|
+
assertNotSet(this.keyManagementParameters, "setKeyManagementParameters");
|
|
1907
1914
|
this.keyManagementParameters = parameters;
|
|
1908
1915
|
return this;
|
|
1909
1916
|
}
|
|
@@ -1932,12 +1939,12 @@ var GeneralEncrypt = class {
|
|
|
1932
1939
|
return recipient;
|
|
1933
1940
|
}
|
|
1934
1941
|
setProtectedHeader(protectedHeader) {
|
|
1935
|
-
|
|
1942
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
1936
1943
|
this.#protectedHeader = protectedHeader;
|
|
1937
1944
|
return this;
|
|
1938
1945
|
}
|
|
1939
1946
|
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
1940
|
-
|
|
1947
|
+
assertNotSet(this.#unprotectedHeader, "setSharedUnprotectedHeader");
|
|
1941
1948
|
this.#unprotectedHeader = sharedUnprotectedHeader;
|
|
1942
1949
|
return this;
|
|
1943
1950
|
}
|
|
@@ -2020,70 +2027,6 @@ var GeneralEncrypt = class {
|
|
|
2020
2027
|
}
|
|
2021
2028
|
};
|
|
2022
2029
|
//#endregion
|
|
2023
|
-
//#region node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
2024
|
-
function subtleAlgorithm(alg, algorithm) {
|
|
2025
|
-
const hash = `SHA-${alg.slice(-3)}`;
|
|
2026
|
-
switch (alg) {
|
|
2027
|
-
case "HS256":
|
|
2028
|
-
case "HS384":
|
|
2029
|
-
case "HS512": return {
|
|
2030
|
-
hash,
|
|
2031
|
-
name: "HMAC"
|
|
2032
|
-
};
|
|
2033
|
-
case "PS256":
|
|
2034
|
-
case "PS384":
|
|
2035
|
-
case "PS512": return {
|
|
2036
|
-
hash,
|
|
2037
|
-
name: "RSA-PSS",
|
|
2038
|
-
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
2039
|
-
};
|
|
2040
|
-
case "RS256":
|
|
2041
|
-
case "RS384":
|
|
2042
|
-
case "RS512": return {
|
|
2043
|
-
hash,
|
|
2044
|
-
name: "RSASSA-PKCS1-v1_5"
|
|
2045
|
-
};
|
|
2046
|
-
case "ES256":
|
|
2047
|
-
case "ES384":
|
|
2048
|
-
case "ES512": return {
|
|
2049
|
-
hash,
|
|
2050
|
-
name: "ECDSA",
|
|
2051
|
-
namedCurve: algorithm.namedCurve
|
|
2052
|
-
};
|
|
2053
|
-
case "Ed25519":
|
|
2054
|
-
case "EdDSA": return { name: "Ed25519" };
|
|
2055
|
-
case "ML-DSA-44":
|
|
2056
|
-
case "ML-DSA-65":
|
|
2057
|
-
case "ML-DSA-87": return { name: alg };
|
|
2058
|
-
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
//#endregion
|
|
2062
|
-
//#region node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
2063
|
-
async function getSigKey(alg, key, usage) {
|
|
2064
|
-
if (key instanceof Uint8Array) {
|
|
2065
|
-
if (!alg.startsWith("HS")) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
2066
|
-
return crypto.subtle.importKey("raw", key, {
|
|
2067
|
-
hash: `SHA-${alg.slice(-3)}`,
|
|
2068
|
-
name: "HMAC"
|
|
2069
|
-
}, false, [usage]);
|
|
2070
|
-
}
|
|
2071
|
-
checkSigCryptoKey(key, alg, usage);
|
|
2072
|
-
return key;
|
|
2073
|
-
}
|
|
2074
|
-
//#endregion
|
|
2075
|
-
//#region node_modules/jose/dist/webapi/lib/verify.js
|
|
2076
|
-
async function verify(alg, key, signature, data) {
|
|
2077
|
-
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
2078
|
-
checkKeyLength(alg, cryptoKey);
|
|
2079
|
-
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
2080
|
-
try {
|
|
2081
|
-
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
2082
|
-
} catch {
|
|
2083
|
-
return false;
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
//#endregion
|
|
2087
2030
|
//#region node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
2088
2031
|
async function flattenedVerify(jws, key, options) {
|
|
2089
2032
|
if (!isObject(jws)) throw new JWSInvalid("Flattened JWS must be an object");
|
|
@@ -2124,20 +2067,11 @@ async function flattenedVerify(jws, key, options) {
|
|
|
2124
2067
|
}
|
|
2125
2068
|
checkKeyType(alg, key, "verify");
|
|
2126
2069
|
const data = concat(jws.protected !== void 0 ? encode$1(jws.protected) : new Uint8Array(), encode$1("."), typeof jws.payload === "string" ? b64 ? encode$1(jws.payload) : encoder.encode(jws.payload) : jws.payload);
|
|
2127
|
-
|
|
2128
|
-
try {
|
|
2129
|
-
signature = decode(jws.signature);
|
|
2130
|
-
} catch {
|
|
2131
|
-
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
2132
|
-
}
|
|
2070
|
+
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
2133
2071
|
const k = await normalizeKey(key, alg);
|
|
2134
2072
|
if (!await verify(alg, k, signature, data)) throw new JWSSignatureVerificationFailed();
|
|
2135
2073
|
let payload;
|
|
2136
|
-
if (b64)
|
|
2137
|
-
payload = decode(jws.payload);
|
|
2138
|
-
} catch {
|
|
2139
|
-
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
2140
|
-
}
|
|
2074
|
+
if (b64) payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
2141
2075
|
else if (typeof jws.payload === "string") payload = encoder.encode(jws.payload);
|
|
2142
2076
|
else payload = jws.payload;
|
|
2143
2077
|
const result = { payload };
|
|
@@ -2419,14 +2353,6 @@ var CompactEncrypt = class {
|
|
|
2419
2353
|
}
|
|
2420
2354
|
};
|
|
2421
2355
|
//#endregion
|
|
2422
|
-
//#region node_modules/jose/dist/webapi/lib/sign.js
|
|
2423
|
-
async function sign(alg, key, data) {
|
|
2424
|
-
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
2425
|
-
checkKeyLength(alg, cryptoKey);
|
|
2426
|
-
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
2427
|
-
return new Uint8Array(signature);
|
|
2428
|
-
}
|
|
2429
|
-
//#endregion
|
|
2430
2356
|
//#region node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
2431
2357
|
var FlattenedSign = class {
|
|
2432
2358
|
#payload;
|
|
@@ -2437,12 +2363,12 @@ var FlattenedSign = class {
|
|
|
2437
2363
|
this.#payload = payload;
|
|
2438
2364
|
}
|
|
2439
2365
|
setProtectedHeader(protectedHeader) {
|
|
2440
|
-
|
|
2366
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2441
2367
|
this.#protectedHeader = protectedHeader;
|
|
2442
2368
|
return this;
|
|
2443
2369
|
}
|
|
2444
2370
|
setUnprotectedHeader(unprotectedHeader) {
|
|
2445
|
-
|
|
2371
|
+
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
2446
2372
|
this.#unprotectedHeader = unprotectedHeader;
|
|
2447
2373
|
return this;
|
|
2448
2374
|
}
|
|
@@ -2521,12 +2447,12 @@ var IndividualSignature = class {
|
|
|
2521
2447
|
this.options = options;
|
|
2522
2448
|
}
|
|
2523
2449
|
setProtectedHeader(protectedHeader) {
|
|
2524
|
-
|
|
2450
|
+
assertNotSet(this.protectedHeader, "setProtectedHeader");
|
|
2525
2451
|
this.protectedHeader = protectedHeader;
|
|
2526
2452
|
return this;
|
|
2527
2453
|
}
|
|
2528
2454
|
setUnprotectedHeader(unprotectedHeader) {
|
|
2529
|
-
|
|
2455
|
+
assertNotSet(this.unprotectedHeader, "setUnprotectedHeader");
|
|
2530
2456
|
this.unprotectedHeader = unprotectedHeader;
|
|
2531
2457
|
return this;
|
|
2532
2458
|
}
|
|
@@ -2660,22 +2586,22 @@ var EncryptJWT = class {
|
|
|
2660
2586
|
return this;
|
|
2661
2587
|
}
|
|
2662
2588
|
setProtectedHeader(protectedHeader) {
|
|
2663
|
-
|
|
2589
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2664
2590
|
this.#protectedHeader = protectedHeader;
|
|
2665
2591
|
return this;
|
|
2666
2592
|
}
|
|
2667
2593
|
setKeyManagementParameters(parameters) {
|
|
2668
|
-
|
|
2594
|
+
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
2669
2595
|
this.#keyManagementParameters = parameters;
|
|
2670
2596
|
return this;
|
|
2671
2597
|
}
|
|
2672
2598
|
setContentEncryptionKey(cek) {
|
|
2673
|
-
|
|
2599
|
+
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
2674
2600
|
this.#cek = cek;
|
|
2675
2601
|
return this;
|
|
2676
2602
|
}
|
|
2677
2603
|
setInitializationVector(iv) {
|
|
2678
|
-
|
|
2604
|
+
assertNotSet(this.#iv, "setInitializationVector");
|
|
2679
2605
|
this.#iv = iv;
|
|
2680
2606
|
return this;
|
|
2681
2607
|
}
|
|
@@ -2891,7 +2817,7 @@ function isCloudflareWorkers() {
|
|
|
2891
2817
|
return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
|
|
2892
2818
|
}
|
|
2893
2819
|
let USER_AGENT;
|
|
2894
|
-
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) USER_AGENT = `jose/v6.2.
|
|
2820
|
+
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) USER_AGENT = `jose/v6.2.1`;
|
|
2895
2821
|
const customFetch = Symbol();
|
|
2896
2822
|
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
2897
2823
|
const response = await fetchImpl(url, {
|
|
@@ -3286,4 +3212,4 @@ const cryptoRuntime = "WebCryptoAPI";
|
|
|
3286
3212
|
//#endregion
|
|
3287
3213
|
export { CompactEncrypt, CompactSign, EmbeddedJWK, EncryptJWT, FlattenedEncrypt, FlattenedSign, GeneralEncrypt, GeneralSign, SignJWT, UnsecuredJWT, base64url_exports as base64url, calculateJwkThumbprint, calculateJwkThumbprintUri, compactDecrypt, compactVerify, createLocalJWKSet, createRemoteJWKSet, cryptoRuntime, customFetch, decodeJwt, decodeProtectedHeader, errors_exports as errors, exportJWK, exportPKCS8, exportSPKI, flattenedDecrypt, flattenedVerify, generalDecrypt, generalVerify, generateKeyPair, generateSecret, importJWK, importPKCS8, importSPKI, importX509, jwksCache, jwtDecrypt, jwtVerify };
|
|
3288
3214
|
|
|
3289
|
-
//# sourceMappingURL=webapi-
|
|
3215
|
+
//# sourceMappingURL=webapi-Cj8QQOwM.mjs.map
|