appstore-connect-sdk 1.3.1 → 1.3.2
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/README.md +38 -1
- package/dist/cjs/main.js +748 -480
- package/dist/cjs/main.js.map +4 -4
- package/dist/main.js +748 -470
- package/dist/main.js.map +4 -4
- package/dist/types/auth.d.ts +1 -1
- package/dist/types/main.d.ts +3 -1
- package/package.json +2 -2
package/dist/cjs/main.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/main.ts
|
|
@@ -234,10 +224,7 @@ function querystringSingleKey(key, value, keyPrefix = "") {
|
|
|
234
224
|
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
235
225
|
}
|
|
236
226
|
|
|
237
|
-
// node_modules/jose/dist/
|
|
238
|
-
var import_buffer = require("buffer");
|
|
239
|
-
|
|
240
|
-
// node_modules/jose/dist/node/esm/lib/buffer_utils.js
|
|
227
|
+
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
241
228
|
var encoder = new TextEncoder();
|
|
242
229
|
var decoder = new TextDecoder();
|
|
243
230
|
var MAX_INT32 = 2 ** 32;
|
|
@@ -245,75 +232,90 @@ function concat(...buffers) {
|
|
|
245
232
|
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
246
233
|
const buf = new Uint8Array(size);
|
|
247
234
|
let i = 0;
|
|
248
|
-
|
|
235
|
+
for (const buffer of buffers) {
|
|
249
236
|
buf.set(buffer, i);
|
|
250
237
|
i += buffer.length;
|
|
251
|
-
}
|
|
238
|
+
}
|
|
252
239
|
return buf;
|
|
253
240
|
}
|
|
254
241
|
|
|
255
|
-
// node_modules/jose/dist/
|
|
256
|
-
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
242
|
+
// node_modules/jose/dist/webapi/lib/base64.js
|
|
243
|
+
function encodeBase64(input) {
|
|
244
|
+
if (Uint8Array.prototype.toBase64) {
|
|
245
|
+
return input.toBase64();
|
|
246
|
+
}
|
|
247
|
+
const CHUNK_SIZE = 32768;
|
|
248
|
+
const arr = [];
|
|
249
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
250
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
251
|
+
}
|
|
252
|
+
return btoa(arr.join(""));
|
|
253
|
+
}
|
|
254
|
+
function decodeBase64(encoded) {
|
|
255
|
+
if (Uint8Array.fromBase64) {
|
|
256
|
+
return Uint8Array.fromBase64(encoded);
|
|
257
|
+
}
|
|
258
|
+
const binary = atob(encoded);
|
|
259
|
+
const bytes = new Uint8Array(binary.length);
|
|
260
|
+
for (let i = 0; i < binary.length; i++) {
|
|
261
|
+
bytes[i] = binary.charCodeAt(i);
|
|
262
|
+
}
|
|
263
|
+
return bytes;
|
|
261
264
|
}
|
|
262
265
|
|
|
263
|
-
// node_modules/jose/dist/
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return "
|
|
266
|
+
// node_modules/jose/dist/webapi/util/base64url.js
|
|
267
|
+
function decode(input) {
|
|
268
|
+
if (Uint8Array.fromBase64) {
|
|
269
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
270
|
+
alphabet: "base64url"
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
let encoded = input;
|
|
274
|
+
if (encoded instanceof Uint8Array) {
|
|
275
|
+
encoded = decoder.decode(encoded);
|
|
276
|
+
}
|
|
277
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
278
|
+
try {
|
|
279
|
+
return decodeBase64(encoded);
|
|
280
|
+
} catch {
|
|
281
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function encode(input) {
|
|
285
|
+
let unencoded = input;
|
|
286
|
+
if (typeof unencoded === "string") {
|
|
287
|
+
unencoded = encoder.encode(unencoded);
|
|
288
|
+
}
|
|
289
|
+
if (Uint8Array.prototype.toBase64) {
|
|
290
|
+
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
267
291
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
292
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// node_modules/jose/dist/webapi/util/errors.js
|
|
296
|
+
var JOSEError = class extends Error {
|
|
297
|
+
static code = "ERR_JOSE_GENERIC";
|
|
298
|
+
code = "ERR_JOSE_GENERIC";
|
|
299
|
+
constructor(message2, options) {
|
|
300
|
+
super(message2, options);
|
|
272
301
|
this.name = this.constructor.name;
|
|
273
|
-
|
|
302
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
274
303
|
}
|
|
275
304
|
};
|
|
276
305
|
var JOSENotSupported = class extends JOSEError {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
this.code = "ERR_JOSE_NOT_SUPPORTED";
|
|
280
|
-
}
|
|
281
|
-
static get code() {
|
|
282
|
-
return "ERR_JOSE_NOT_SUPPORTED";
|
|
283
|
-
}
|
|
306
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
307
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
284
308
|
};
|
|
285
309
|
var JWSInvalid = class extends JOSEError {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
this.code = "ERR_JWS_INVALID";
|
|
289
|
-
}
|
|
290
|
-
static get code() {
|
|
291
|
-
return "ERR_JWS_INVALID";
|
|
292
|
-
}
|
|
310
|
+
static code = "ERR_JWS_INVALID";
|
|
311
|
+
code = "ERR_JWS_INVALID";
|
|
293
312
|
};
|
|
294
313
|
var JWTInvalid = class extends JOSEError {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
this.code = "ERR_JWT_INVALID";
|
|
298
|
-
}
|
|
299
|
-
static get code() {
|
|
300
|
-
return "ERR_JWT_INVALID";
|
|
301
|
-
}
|
|
314
|
+
static code = "ERR_JWT_INVALID";
|
|
315
|
+
code = "ERR_JWT_INVALID";
|
|
302
316
|
};
|
|
303
317
|
|
|
304
|
-
// node_modules/jose/dist/
|
|
305
|
-
var import_crypto = require("crypto");
|
|
306
|
-
var util = __toESM(require("util"), 1);
|
|
307
|
-
var is_key_object_default = util.types.isKeyObject ? (obj) => util.types.isKeyObject(obj) : (obj) => obj != null && obj instanceof import_crypto.KeyObject;
|
|
308
|
-
|
|
309
|
-
// node_modules/jose/dist/node/esm/runtime/webcrypto.js
|
|
310
|
-
var crypto = __toESM(require("crypto"), 1);
|
|
311
|
-
var util2 = __toESM(require("util"), 1);
|
|
312
|
-
var webcrypto2 = crypto.webcrypto;
|
|
313
|
-
var webcrypto_default = webcrypto2;
|
|
314
|
-
var isCryptoKey = util2.types.isCryptoKey ? (key) => util2.types.isCryptoKey(key) : (key) => false;
|
|
315
|
-
|
|
316
|
-
// node_modules/jose/dist/node/esm/lib/crypto_key.js
|
|
318
|
+
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
317
319
|
function unusable(name, prop = "algorithm.name") {
|
|
318
320
|
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
319
321
|
}
|
|
@@ -335,21 +337,12 @@ function getNamedCurve(alg) {
|
|
|
335
337
|
throw new Error("unreachable");
|
|
336
338
|
}
|
|
337
339
|
}
|
|
338
|
-
function checkUsage(key,
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
if (usages.length > 2) {
|
|
342
|
-
const last = usages.pop();
|
|
343
|
-
msg += `one of ${usages.join(", ")}, or ${last}.`;
|
|
344
|
-
} else if (usages.length === 2) {
|
|
345
|
-
msg += `one of ${usages[0]} or ${usages[1]}.`;
|
|
346
|
-
} else {
|
|
347
|
-
msg += `${usages[0]}.`;
|
|
348
|
-
}
|
|
349
|
-
throw new TypeError(msg);
|
|
340
|
+
function checkUsage(key, usage) {
|
|
341
|
+
if (usage && !key.usages.includes(usage)) {
|
|
342
|
+
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
350
343
|
}
|
|
351
344
|
}
|
|
352
|
-
function checkSigCryptoKey(key, alg,
|
|
345
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
353
346
|
switch (alg) {
|
|
354
347
|
case "HS256":
|
|
355
348
|
case "HS384":
|
|
@@ -384,10 +377,10 @@ function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
384
377
|
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
385
378
|
break;
|
|
386
379
|
}
|
|
380
|
+
case "Ed25519":
|
|
387
381
|
case "EdDSA": {
|
|
388
|
-
if (key.algorithm
|
|
389
|
-
throw unusable("Ed25519
|
|
390
|
-
}
|
|
382
|
+
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
383
|
+
throw unusable("Ed25519");
|
|
391
384
|
break;
|
|
392
385
|
}
|
|
393
386
|
case "ES256":
|
|
@@ -404,46 +397,51 @@ function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
404
397
|
default:
|
|
405
398
|
throw new TypeError("CryptoKey does not support this operation");
|
|
406
399
|
}
|
|
407
|
-
checkUsage(key,
|
|
400
|
+
checkUsage(key, usage);
|
|
408
401
|
}
|
|
409
402
|
|
|
410
|
-
// node_modules/jose/dist/
|
|
411
|
-
function message(msg, actual, ...
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
403
|
+
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
404
|
+
function message(msg, actual, ...types) {
|
|
405
|
+
types = types.filter(Boolean);
|
|
406
|
+
if (types.length > 2) {
|
|
407
|
+
const last = types.pop();
|
|
408
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
409
|
+
} else if (types.length === 2) {
|
|
410
|
+
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
417
411
|
} else {
|
|
418
|
-
msg += `of type ${
|
|
412
|
+
msg += `of type ${types[0]}.`;
|
|
419
413
|
}
|
|
420
414
|
if (actual == null) {
|
|
421
415
|
msg += ` Received ${actual}`;
|
|
422
416
|
} else if (typeof actual === "function" && actual.name) {
|
|
423
417
|
msg += ` Received function ${actual.name}`;
|
|
424
418
|
} else if (typeof actual === "object" && actual != null) {
|
|
425
|
-
if (actual.constructor
|
|
419
|
+
if (actual.constructor?.name) {
|
|
426
420
|
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
427
421
|
}
|
|
428
422
|
}
|
|
429
423
|
return msg;
|
|
430
424
|
}
|
|
431
|
-
var invalid_key_input_default = (actual, ...
|
|
432
|
-
return message("Key must be ", actual, ...
|
|
425
|
+
var invalid_key_input_default = (actual, ...types) => {
|
|
426
|
+
return message("Key must be ", actual, ...types);
|
|
433
427
|
};
|
|
434
|
-
function withAlg(alg, actual, ...
|
|
435
|
-
return message(`Key for the ${alg} algorithm must be `, actual, ...
|
|
428
|
+
function withAlg(alg, actual, ...types) {
|
|
429
|
+
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
436
430
|
}
|
|
437
431
|
|
|
438
|
-
// node_modules/jose/dist/
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
432
|
+
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
433
|
+
function isCryptoKey(key) {
|
|
434
|
+
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
435
|
+
}
|
|
436
|
+
function isKeyObject(key) {
|
|
437
|
+
return key?.[Symbol.toStringTag] === "KeyObject";
|
|
443
438
|
}
|
|
439
|
+
var is_key_like_default = (key) => {
|
|
440
|
+
return isCryptoKey(key) || isKeyObject(key);
|
|
441
|
+
};
|
|
444
442
|
|
|
445
|
-
// node_modules/jose/dist/
|
|
446
|
-
var
|
|
443
|
+
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
444
|
+
var is_disjoint_default = (...headers) => {
|
|
447
445
|
const sources = headers.filter(Boolean);
|
|
448
446
|
if (sources.length === 0 || sources.length === 1) {
|
|
449
447
|
return true;
|
|
@@ -464,13 +462,12 @@ var isDisjoint = (...headers) => {
|
|
|
464
462
|
}
|
|
465
463
|
return true;
|
|
466
464
|
};
|
|
467
|
-
var is_disjoint_default = isDisjoint;
|
|
468
465
|
|
|
469
|
-
// node_modules/jose/dist/
|
|
466
|
+
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
470
467
|
function isObjectLike(value) {
|
|
471
468
|
return typeof value === "object" && value !== null;
|
|
472
469
|
}
|
|
473
|
-
|
|
470
|
+
var is_object_default = (input) => {
|
|
474
471
|
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
475
472
|
return false;
|
|
476
473
|
}
|
|
@@ -482,148 +479,194 @@ function isObject(input) {
|
|
|
482
479
|
proto = Object.getPrototypeOf(proto);
|
|
483
480
|
}
|
|
484
481
|
return Object.getPrototypeOf(input) === proto;
|
|
485
|
-
}
|
|
482
|
+
};
|
|
486
483
|
|
|
487
|
-
// node_modules/jose/dist/
|
|
488
|
-
var
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
var weakMap = /* @__PURE__ */ new WeakMap();
|
|
495
|
-
var namedCurveToJOSE = (namedCurve) => {
|
|
496
|
-
switch (namedCurve) {
|
|
497
|
-
case "prime256v1":
|
|
498
|
-
return "P-256";
|
|
499
|
-
case "secp384r1":
|
|
500
|
-
return "P-384";
|
|
501
|
-
case "secp521r1":
|
|
502
|
-
return "P-521";
|
|
503
|
-
case "secp256k1":
|
|
504
|
-
return "secp256k1";
|
|
505
|
-
default:
|
|
506
|
-
throw new JOSENotSupported("Unsupported key curve for this operation");
|
|
484
|
+
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
485
|
+
var check_key_length_default = (alg, key) => {
|
|
486
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
487
|
+
const { modulusLength } = key.algorithm;
|
|
488
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
489
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
490
|
+
}
|
|
507
491
|
}
|
|
508
492
|
};
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
case "ed25519":
|
|
524
|
-
case "ed448":
|
|
525
|
-
return `Ed${key.asymmetricKeyType.slice(2)}`;
|
|
526
|
-
case "x25519":
|
|
527
|
-
case "x448":
|
|
528
|
-
return `X${key.asymmetricKeyType.slice(1)}`;
|
|
529
|
-
case "ec": {
|
|
530
|
-
if (weakMap.has(key)) {
|
|
531
|
-
return weakMap.get(key);
|
|
532
|
-
}
|
|
533
|
-
let namedCurve = (_a = key.asymmetricKeyDetails) === null || _a === void 0 ? void 0 : _a.namedCurve;
|
|
534
|
-
if (!namedCurve && key.type === "private") {
|
|
535
|
-
namedCurve = getNamedCurve2((0, import_crypto2.createPublicKey)(key), true);
|
|
536
|
-
} else if (!namedCurve) {
|
|
537
|
-
const buf = key.export({ format: "der", type: "spki" });
|
|
538
|
-
const i = buf[1] < 128 ? 14 : 15;
|
|
539
|
-
const len = buf[i];
|
|
540
|
-
const curveOid = buf.slice(i + 1, i + 1 + len);
|
|
541
|
-
if (curveOid.equals(p256)) {
|
|
542
|
-
namedCurve = "prime256v1";
|
|
543
|
-
} else if (curveOid.equals(p384)) {
|
|
544
|
-
namedCurve = "secp384r1";
|
|
545
|
-
} else if (curveOid.equals(p521)) {
|
|
546
|
-
namedCurve = "secp521r1";
|
|
547
|
-
} else if (curveOid.equals(secp256k1)) {
|
|
548
|
-
namedCurve = "secp256k1";
|
|
549
|
-
} else {
|
|
550
|
-
throw new JOSENotSupported("Unsupported key curve for this operation");
|
|
493
|
+
|
|
494
|
+
// node_modules/jose/dist/webapi/lib/asn1.js
|
|
495
|
+
var getNamedCurve2 = (keyData) => {
|
|
496
|
+
const patterns = Object.entries({
|
|
497
|
+
"P-256": [6, 8, 42, 134, 72, 206, 61, 3, 1, 7],
|
|
498
|
+
"P-384": [6, 5, 43, 129, 4, 0, 34],
|
|
499
|
+
"P-521": [6, 5, 43, 129, 4, 0, 35]
|
|
500
|
+
});
|
|
501
|
+
const maxPatternLen = Math.max(...patterns.map(([, bytes]) => bytes.length));
|
|
502
|
+
for (let i = 0; i <= keyData.byteLength - maxPatternLen; i++) {
|
|
503
|
+
for (const [curve, bytes] of patterns) {
|
|
504
|
+
if (i <= keyData.byteLength - bytes.length) {
|
|
505
|
+
if (keyData.subarray(i, i + bytes.length).every((byte, idx) => byte === bytes[idx])) {
|
|
506
|
+
return curve;
|
|
551
507
|
}
|
|
552
508
|
}
|
|
553
|
-
if (raw)
|
|
554
|
-
return namedCurve;
|
|
555
|
-
const curve = namedCurveToJOSE(namedCurve);
|
|
556
|
-
weakMap.set(key, curve);
|
|
557
|
-
return curve;
|
|
558
509
|
}
|
|
559
|
-
default:
|
|
560
|
-
throw new TypeError("Invalid asymmetric key type for this operation");
|
|
561
510
|
}
|
|
511
|
+
return void 0;
|
|
562
512
|
};
|
|
563
|
-
var
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
513
|
+
var genericImport = async (keyFormat, keyData, alg, options) => {
|
|
514
|
+
let algorithm;
|
|
515
|
+
let keyUsages;
|
|
516
|
+
const isPublic = keyFormat === "spki";
|
|
517
|
+
const getSignatureUsages = () => isPublic ? ["verify"] : ["sign"];
|
|
518
|
+
const getEncryptionUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
519
|
+
switch (alg) {
|
|
520
|
+
case "PS256":
|
|
521
|
+
case "PS384":
|
|
522
|
+
case "PS512":
|
|
523
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
|
|
524
|
+
keyUsages = getSignatureUsages();
|
|
525
|
+
break;
|
|
526
|
+
case "RS256":
|
|
527
|
+
case "RS384":
|
|
528
|
+
case "RS512":
|
|
529
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
|
|
530
|
+
keyUsages = getSignatureUsages();
|
|
531
|
+
break;
|
|
532
|
+
case "RSA-OAEP":
|
|
533
|
+
case "RSA-OAEP-256":
|
|
534
|
+
case "RSA-OAEP-384":
|
|
535
|
+
case "RSA-OAEP-512":
|
|
536
|
+
algorithm = {
|
|
537
|
+
name: "RSA-OAEP",
|
|
538
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
|
|
539
|
+
};
|
|
540
|
+
keyUsages = getEncryptionUsages();
|
|
541
|
+
break;
|
|
542
|
+
case "ES256":
|
|
543
|
+
case "ES384":
|
|
544
|
+
case "ES512": {
|
|
545
|
+
const curveMap = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
546
|
+
algorithm = { name: "ECDSA", namedCurve: curveMap[alg] };
|
|
547
|
+
keyUsages = getSignatureUsages();
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
case "ECDH-ES":
|
|
551
|
+
case "ECDH-ES+A128KW":
|
|
552
|
+
case "ECDH-ES+A192KW":
|
|
553
|
+
case "ECDH-ES+A256KW": {
|
|
554
|
+
const namedCurve = getNamedCurve2(keyData);
|
|
555
|
+
algorithm = namedCurve ? { name: "ECDH", namedCurve } : { name: "X25519" };
|
|
556
|
+
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
case "Ed25519":
|
|
560
|
+
case "EdDSA":
|
|
561
|
+
algorithm = { name: "Ed25519" };
|
|
562
|
+
keyUsages = getSignatureUsages();
|
|
563
|
+
break;
|
|
564
|
+
default:
|
|
565
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
591
566
|
}
|
|
592
|
-
|
|
593
|
-
return getLength(sequence.subarray(2 + num), index);
|
|
567
|
+
return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? (isPublic ? true : false), keyUsages);
|
|
594
568
|
};
|
|
595
|
-
var
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
return weakMap2.get(key);
|
|
599
|
-
}
|
|
600
|
-
const modulusLength = (_b = (_a = key.asymmetricKeyDetails) === null || _a === void 0 ? void 0 : _a.modulusLength) !== null && _b !== void 0 ? _b : getLengthOfSeqIndex(key.export({ format: "der", type: "pkcs1" }), key.type === "private" ? 1 : 0) - 1 << 3;
|
|
601
|
-
weakMap2.set(key, modulusLength);
|
|
602
|
-
return modulusLength;
|
|
569
|
+
var fromPKCS8 = (pem, alg, options) => {
|
|
570
|
+
const keyData = decodeBase64(pem.replace(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, ""));
|
|
571
|
+
return genericImport("pkcs8", keyData, alg, options);
|
|
603
572
|
};
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
573
|
+
|
|
574
|
+
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
575
|
+
function subtleMapping(jwk) {
|
|
576
|
+
let algorithm;
|
|
577
|
+
let keyUsages;
|
|
578
|
+
switch (jwk.kty) {
|
|
579
|
+
case "RSA": {
|
|
580
|
+
switch (jwk.alg) {
|
|
581
|
+
case "PS256":
|
|
582
|
+
case "PS384":
|
|
583
|
+
case "PS512":
|
|
584
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
585
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
586
|
+
break;
|
|
587
|
+
case "RS256":
|
|
588
|
+
case "RS384":
|
|
589
|
+
case "RS512":
|
|
590
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
591
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
592
|
+
break;
|
|
593
|
+
case "RSA-OAEP":
|
|
594
|
+
case "RSA-OAEP-256":
|
|
595
|
+
case "RSA-OAEP-384":
|
|
596
|
+
case "RSA-OAEP-512":
|
|
597
|
+
algorithm = {
|
|
598
|
+
name: "RSA-OAEP",
|
|
599
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
600
|
+
};
|
|
601
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
602
|
+
break;
|
|
603
|
+
default:
|
|
604
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
605
|
+
}
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
case "EC": {
|
|
609
|
+
switch (jwk.alg) {
|
|
610
|
+
case "ES256":
|
|
611
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
612
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
613
|
+
break;
|
|
614
|
+
case "ES384":
|
|
615
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
616
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
617
|
+
break;
|
|
618
|
+
case "ES512":
|
|
619
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
620
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
621
|
+
break;
|
|
622
|
+
case "ECDH-ES":
|
|
623
|
+
case "ECDH-ES+A128KW":
|
|
624
|
+
case "ECDH-ES+A192KW":
|
|
625
|
+
case "ECDH-ES+A256KW":
|
|
626
|
+
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
627
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
628
|
+
break;
|
|
629
|
+
default:
|
|
630
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
case "OKP": {
|
|
635
|
+
switch (jwk.alg) {
|
|
636
|
+
case "Ed25519":
|
|
637
|
+
case "EdDSA":
|
|
638
|
+
algorithm = { name: "Ed25519" };
|
|
639
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
640
|
+
break;
|
|
641
|
+
case "ECDH-ES":
|
|
642
|
+
case "ECDH-ES+A128KW":
|
|
643
|
+
case "ECDH-ES+A192KW":
|
|
644
|
+
case "ECDH-ES+A256KW":
|
|
645
|
+
algorithm = { name: jwk.crv };
|
|
646
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
647
|
+
break;
|
|
648
|
+
default:
|
|
649
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
650
|
+
}
|
|
651
|
+
break;
|
|
652
|
+
}
|
|
653
|
+
default:
|
|
654
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
607
655
|
}
|
|
656
|
+
return { algorithm, keyUsages };
|
|
657
|
+
}
|
|
658
|
+
var jwk_to_key_default = async (jwk) => {
|
|
659
|
+
if (!jwk.alg) {
|
|
660
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
661
|
+
}
|
|
662
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
663
|
+
const keyData = { ...jwk };
|
|
664
|
+
delete keyData.alg;
|
|
665
|
+
delete keyData.use;
|
|
666
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d ? false : true), jwk.key_ops ?? keyUsages);
|
|
608
667
|
};
|
|
609
668
|
|
|
610
|
-
// node_modules/jose/dist/
|
|
611
|
-
var import_crypto3 = require("crypto");
|
|
612
|
-
var import_buffer3 = require("buffer");
|
|
613
|
-
var fromPKCS8 = (pem) => (0, import_crypto3.createPrivateKey)({
|
|
614
|
-
key: import_buffer3.Buffer.from(pem.replace(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, ""), "base64"),
|
|
615
|
-
type: "pkcs8",
|
|
616
|
-
format: "der"
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
// node_modules/jose/dist/node/esm/runtime/flags.js
|
|
620
|
-
var [major, minor] = process.versions.node.split(".").map((str) => parseInt(str, 10));
|
|
621
|
-
var oneShotCallback = major >= 16 || major === 15 && minor >= 13;
|
|
622
|
-
var rsaPssParams = !("electron" in process.versions) && (major >= 17 || major === 16 && minor >= 9);
|
|
623
|
-
var jwkExport = major >= 16 || major === 15 && minor >= 9;
|
|
624
|
-
var jwkImport = major >= 16 || major === 15 && minor >= 12;
|
|
625
|
-
|
|
626
|
-
// node_modules/jose/dist/node/esm/key/import.js
|
|
669
|
+
// node_modules/jose/dist/webapi/key/import.js
|
|
627
670
|
async function importPKCS8(pkcs8, alg, options) {
|
|
628
671
|
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
629
672
|
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
@@ -631,50 +674,9 @@ async function importPKCS8(pkcs8, alg, options) {
|
|
|
631
674
|
return fromPKCS8(pkcs8, alg, options);
|
|
632
675
|
}
|
|
633
676
|
|
|
634
|
-
// node_modules/jose/dist/
|
|
635
|
-
var
|
|
636
|
-
if (
|
|
637
|
-
return;
|
|
638
|
-
if (!is_key_like_default(key)) {
|
|
639
|
-
throw new TypeError(withAlg(alg, key, ...types3, "Uint8Array"));
|
|
640
|
-
}
|
|
641
|
-
if (key.type !== "secret") {
|
|
642
|
-
throw new TypeError(`${types3.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
var asymmetricTypeCheck = (alg, key, usage) => {
|
|
646
|
-
if (!is_key_like_default(key)) {
|
|
647
|
-
throw new TypeError(withAlg(alg, key, ...types3));
|
|
648
|
-
}
|
|
649
|
-
if (key.type === "secret") {
|
|
650
|
-
throw new TypeError(`${types3.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
|
|
651
|
-
}
|
|
652
|
-
if (usage === "sign" && key.type === "public") {
|
|
653
|
-
throw new TypeError(`${types3.join(" or ")} instances for asymmetric algorithm signing must be of type "private"`);
|
|
654
|
-
}
|
|
655
|
-
if (usage === "decrypt" && key.type === "public") {
|
|
656
|
-
throw new TypeError(`${types3.join(" or ")} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
657
|
-
}
|
|
658
|
-
if (key.algorithm && usage === "verify" && key.type === "private") {
|
|
659
|
-
throw new TypeError(`${types3.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
660
|
-
}
|
|
661
|
-
if (key.algorithm && usage === "encrypt" && key.type === "private") {
|
|
662
|
-
throw new TypeError(`${types3.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
var checkKeyType = (alg, key, usage) => {
|
|
666
|
-
const symmetric = alg.startsWith("HS") || alg === "dir" || alg.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(alg);
|
|
667
|
-
if (symmetric) {
|
|
668
|
-
symmetricTypeCheck(alg, key);
|
|
669
|
-
} else {
|
|
670
|
-
asymmetricTypeCheck(alg, key, usage);
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
var check_key_type_default = checkKeyType;
|
|
674
|
-
|
|
675
|
-
// node_modules/jose/dist/node/esm/lib/validate_crit.js
|
|
676
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
677
|
-
if (joseHeader.crit !== void 0 && protectedHeader.crit === void 0) {
|
|
677
|
+
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
678
|
+
var validate_crit_default = (Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) => {
|
|
679
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
678
680
|
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
679
681
|
}
|
|
680
682
|
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
@@ -695,249 +697,524 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
|
|
|
695
697
|
}
|
|
696
698
|
if (joseHeader[parameter] === void 0) {
|
|
697
699
|
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
698
|
-
}
|
|
700
|
+
}
|
|
701
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
699
702
|
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
700
703
|
}
|
|
701
704
|
}
|
|
702
705
|
return new Set(protectedHeader.crit);
|
|
703
|
-
}
|
|
704
|
-
var validate_crit_default = validateCrit;
|
|
706
|
+
};
|
|
705
707
|
|
|
706
|
-
// node_modules/jose/dist/
|
|
707
|
-
function
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
case "PS512":
|
|
719
|
-
case "RS512":
|
|
720
|
-
case "ES512":
|
|
721
|
-
return "sha512";
|
|
722
|
-
case "EdDSA":
|
|
723
|
-
return void 0;
|
|
724
|
-
default:
|
|
725
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
726
|
-
}
|
|
708
|
+
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
709
|
+
function isJWK(key) {
|
|
710
|
+
return is_object_default(key) && typeof key.kty === "string";
|
|
711
|
+
}
|
|
712
|
+
function isPrivateJWK(key) {
|
|
713
|
+
return key.kty !== "oct" && typeof key.d === "string";
|
|
714
|
+
}
|
|
715
|
+
function isPublicJWK(key) {
|
|
716
|
+
return key.kty !== "oct" && typeof key.d === "undefined";
|
|
717
|
+
}
|
|
718
|
+
function isSecretJWK(key) {
|
|
719
|
+
return key.kty === "oct" && typeof key.k === "string";
|
|
727
720
|
}
|
|
728
721
|
|
|
729
|
-
// node_modules/jose/dist/
|
|
730
|
-
var
|
|
731
|
-
var
|
|
732
|
-
|
|
733
|
-
|
|
722
|
+
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
723
|
+
var cache;
|
|
724
|
+
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
725
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
726
|
+
let cached = cache.get(key);
|
|
727
|
+
if (cached?.[alg]) {
|
|
728
|
+
return cached[alg];
|
|
729
|
+
}
|
|
730
|
+
const cryptoKey = await jwk_to_key_default({ ...jwk, alg });
|
|
731
|
+
if (freeze)
|
|
732
|
+
Object.freeze(key);
|
|
733
|
+
if (!cached) {
|
|
734
|
+
cache.set(key, { [alg]: cryptoKey });
|
|
735
|
+
} else {
|
|
736
|
+
cached[alg] = cryptoKey;
|
|
737
|
+
}
|
|
738
|
+
return cryptoKey;
|
|
734
739
|
};
|
|
735
|
-
var
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
[
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
throw new TypeError("
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
740
|
+
var handleKeyObject = (keyObject, alg) => {
|
|
741
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
742
|
+
let cached = cache.get(keyObject);
|
|
743
|
+
if (cached?.[alg]) {
|
|
744
|
+
return cached[alg];
|
|
745
|
+
}
|
|
746
|
+
const isPublic = keyObject.type === "public";
|
|
747
|
+
const extractable = isPublic ? true : false;
|
|
748
|
+
let cryptoKey;
|
|
749
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
750
|
+
switch (alg) {
|
|
751
|
+
case "ECDH-ES":
|
|
752
|
+
case "ECDH-ES+A128KW":
|
|
753
|
+
case "ECDH-ES+A192KW":
|
|
754
|
+
case "ECDH-ES+A256KW":
|
|
755
|
+
break;
|
|
756
|
+
default:
|
|
757
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
758
|
+
}
|
|
759
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
760
|
+
}
|
|
761
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
762
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
763
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
764
|
+
}
|
|
765
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
766
|
+
isPublic ? "verify" : "sign"
|
|
767
|
+
]);
|
|
768
|
+
}
|
|
769
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
770
|
+
let hash;
|
|
771
|
+
switch (alg) {
|
|
772
|
+
case "RSA-OAEP":
|
|
773
|
+
hash = "SHA-1";
|
|
774
|
+
break;
|
|
775
|
+
case "RS256":
|
|
776
|
+
case "PS256":
|
|
777
|
+
case "RSA-OAEP-256":
|
|
778
|
+
hash = "SHA-256";
|
|
779
|
+
break;
|
|
780
|
+
case "RS384":
|
|
781
|
+
case "PS384":
|
|
782
|
+
case "RSA-OAEP-384":
|
|
783
|
+
hash = "SHA-384";
|
|
784
|
+
break;
|
|
785
|
+
case "RS512":
|
|
786
|
+
case "PS512":
|
|
787
|
+
case "RSA-OAEP-512":
|
|
788
|
+
hash = "SHA-512";
|
|
789
|
+
break;
|
|
790
|
+
default:
|
|
791
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
792
|
+
}
|
|
793
|
+
if (alg.startsWith("RSA-OAEP")) {
|
|
794
|
+
return keyObject.toCryptoKey({
|
|
795
|
+
name: "RSA-OAEP",
|
|
796
|
+
hash
|
|
797
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
798
|
+
}
|
|
799
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
800
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
801
|
+
hash
|
|
802
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
803
|
+
}
|
|
804
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
805
|
+
const nist = /* @__PURE__ */ new Map([
|
|
806
|
+
["prime256v1", "P-256"],
|
|
807
|
+
["secp384r1", "P-384"],
|
|
808
|
+
["secp521r1", "P-521"]
|
|
809
|
+
]);
|
|
810
|
+
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
811
|
+
if (!namedCurve) {
|
|
812
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
813
|
+
}
|
|
814
|
+
if (alg === "ES256" && namedCurve === "P-256") {
|
|
815
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
816
|
+
name: "ECDSA",
|
|
817
|
+
namedCurve
|
|
818
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
819
|
+
}
|
|
820
|
+
if (alg === "ES384" && namedCurve === "P-384") {
|
|
821
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
822
|
+
name: "ECDSA",
|
|
823
|
+
namedCurve
|
|
824
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
825
|
+
}
|
|
826
|
+
if (alg === "ES512" && namedCurve === "P-521") {
|
|
827
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
828
|
+
name: "ECDSA",
|
|
829
|
+
namedCurve
|
|
830
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
831
|
+
}
|
|
832
|
+
if (alg.startsWith("ECDH-ES")) {
|
|
833
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
834
|
+
name: "ECDH",
|
|
835
|
+
namedCurve
|
|
836
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (!cryptoKey) {
|
|
840
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
841
|
+
}
|
|
842
|
+
if (!cached) {
|
|
843
|
+
cache.set(keyObject, { [alg]: cryptoKey });
|
|
844
|
+
} else {
|
|
845
|
+
cached[alg] = cryptoKey;
|
|
846
|
+
}
|
|
847
|
+
return cryptoKey;
|
|
848
|
+
};
|
|
849
|
+
var normalize_key_default = async (key, alg) => {
|
|
850
|
+
if (key instanceof Uint8Array) {
|
|
851
|
+
return key;
|
|
852
|
+
}
|
|
853
|
+
if (isCryptoKey(key)) {
|
|
854
|
+
return key;
|
|
855
|
+
}
|
|
856
|
+
if (isKeyObject(key)) {
|
|
857
|
+
if (key.type === "secret") {
|
|
858
|
+
return key.export();
|
|
859
|
+
}
|
|
860
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
861
|
+
try {
|
|
862
|
+
return handleKeyObject(key, alg);
|
|
863
|
+
} catch (err) {
|
|
864
|
+
if (err instanceof TypeError) {
|
|
865
|
+
throw err;
|
|
767
866
|
}
|
|
768
|
-
} else if (key.asymmetricKeyType !== "rsa") {
|
|
769
|
-
throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be rsa or rsa-pss");
|
|
770
|
-
}
|
|
771
|
-
check_modulus_length_default(key, alg);
|
|
772
|
-
return { key, ...PSS };
|
|
773
|
-
case (!rsaPssParams && "PS256"):
|
|
774
|
-
case (!rsaPssParams && "PS384"):
|
|
775
|
-
case (!rsaPssParams && "PS512"):
|
|
776
|
-
if (key.asymmetricKeyType !== "rsa") {
|
|
777
|
-
throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be rsa");
|
|
778
867
|
}
|
|
779
|
-
check_modulus_length_default(key, alg);
|
|
780
|
-
return { key, ...PSS };
|
|
781
|
-
case "ES256":
|
|
782
|
-
case "ES256K":
|
|
783
|
-
case "ES384":
|
|
784
|
-
case "ES512": {
|
|
785
|
-
if (key.asymmetricKeyType !== "ec") {
|
|
786
|
-
throw new TypeError("Invalid key for this operation, its asymmetricKeyType must be ec");
|
|
787
|
-
}
|
|
788
|
-
const actual = get_named_curve_default(key);
|
|
789
|
-
const expected = ecCurveAlgMap.get(alg);
|
|
790
|
-
if (actual !== expected) {
|
|
791
|
-
throw new TypeError(`Invalid key curve for the algorithm, its curve must be ${expected}, got ${actual}`);
|
|
792
|
-
}
|
|
793
|
-
return { dsaEncoding: "ieee-p1363", key };
|
|
794
868
|
}
|
|
795
|
-
|
|
796
|
-
|
|
869
|
+
let jwk = key.export({ format: "jwk" });
|
|
870
|
+
return handleJWK(key, jwk, alg);
|
|
797
871
|
}
|
|
798
|
-
|
|
872
|
+
if (isJWK(key)) {
|
|
873
|
+
if (key.k) {
|
|
874
|
+
return decode(key.k);
|
|
875
|
+
}
|
|
876
|
+
return handleJWK(key, key, alg, true);
|
|
877
|
+
}
|
|
878
|
+
throw new Error("unreachable");
|
|
879
|
+
};
|
|
799
880
|
|
|
800
|
-
// node_modules/jose/dist/
|
|
801
|
-
var
|
|
802
|
-
var
|
|
881
|
+
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
882
|
+
var tag = (key) => key?.[Symbol.toStringTag];
|
|
883
|
+
var jwkMatchesOp = (alg, key, usage) => {
|
|
884
|
+
if (key.use !== void 0) {
|
|
885
|
+
let expected;
|
|
886
|
+
switch (usage) {
|
|
887
|
+
case "sign":
|
|
888
|
+
case "verify":
|
|
889
|
+
expected = "sig";
|
|
890
|
+
break;
|
|
891
|
+
case "encrypt":
|
|
892
|
+
case "decrypt":
|
|
893
|
+
expected = "enc";
|
|
894
|
+
break;
|
|
895
|
+
}
|
|
896
|
+
if (key.use !== expected) {
|
|
897
|
+
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
if (key.alg !== void 0 && key.alg !== alg) {
|
|
901
|
+
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
902
|
+
}
|
|
903
|
+
if (Array.isArray(key.key_ops)) {
|
|
904
|
+
let expectedKeyOp;
|
|
905
|
+
switch (true) {
|
|
906
|
+
case (usage === "sign" || usage === "verify"):
|
|
907
|
+
case alg === "dir":
|
|
908
|
+
case alg.includes("CBC-HS"):
|
|
909
|
+
expectedKeyOp = usage;
|
|
910
|
+
break;
|
|
911
|
+
case alg.startsWith("PBES2"):
|
|
912
|
+
expectedKeyOp = "deriveBits";
|
|
913
|
+
break;
|
|
914
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
915
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
916
|
+
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
917
|
+
} else {
|
|
918
|
+
expectedKeyOp = usage;
|
|
919
|
+
}
|
|
920
|
+
break;
|
|
921
|
+
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
922
|
+
expectedKeyOp = "wrapKey";
|
|
923
|
+
break;
|
|
924
|
+
case usage === "decrypt":
|
|
925
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
928
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
929
|
+
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
return true;
|
|
933
|
+
};
|
|
934
|
+
var symmetricTypeCheck = (alg, key, usage) => {
|
|
935
|
+
if (key instanceof Uint8Array)
|
|
936
|
+
return;
|
|
937
|
+
if (isJWK(key)) {
|
|
938
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
939
|
+
return;
|
|
940
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
941
|
+
}
|
|
942
|
+
if (!is_key_like_default(key)) {
|
|
943
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
944
|
+
}
|
|
945
|
+
if (key.type !== "secret") {
|
|
946
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
var asymmetricTypeCheck = (alg, key, usage) => {
|
|
950
|
+
if (isJWK(key)) {
|
|
951
|
+
switch (usage) {
|
|
952
|
+
case "decrypt":
|
|
953
|
+
case "sign":
|
|
954
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
955
|
+
return;
|
|
956
|
+
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
957
|
+
case "encrypt":
|
|
958
|
+
case "verify":
|
|
959
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
960
|
+
return;
|
|
961
|
+
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (!is_key_like_default(key)) {
|
|
965
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
966
|
+
}
|
|
967
|
+
if (key.type === "secret") {
|
|
968
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
969
|
+
}
|
|
970
|
+
if (key.type === "public") {
|
|
971
|
+
switch (usage) {
|
|
972
|
+
case "sign":
|
|
973
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
974
|
+
case "decrypt":
|
|
975
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
976
|
+
default:
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
if (key.type === "private") {
|
|
981
|
+
switch (usage) {
|
|
982
|
+
case "verify":
|
|
983
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
984
|
+
case "encrypt":
|
|
985
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
986
|
+
default:
|
|
987
|
+
break;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
var check_key_type_default = (alg, key, usage) => {
|
|
992
|
+
const symmetric = alg.startsWith("HS") || alg === "dir" || alg.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(alg) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(alg);
|
|
993
|
+
if (symmetric) {
|
|
994
|
+
symmetricTypeCheck(alg, key, usage);
|
|
995
|
+
} else {
|
|
996
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
997
|
+
}
|
|
998
|
+
};
|
|
803
999
|
|
|
804
|
-
// node_modules/jose/dist/
|
|
805
|
-
|
|
1000
|
+
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
1001
|
+
var subtle_dsa_default = (alg, algorithm) => {
|
|
1002
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
806
1003
|
switch (alg) {
|
|
807
1004
|
case "HS256":
|
|
808
|
-
return "sha256";
|
|
809
1005
|
case "HS384":
|
|
810
|
-
return "sha384";
|
|
811
1006
|
case "HS512":
|
|
812
|
-
return "
|
|
1007
|
+
return { hash, name: "HMAC" };
|
|
1008
|
+
case "PS256":
|
|
1009
|
+
case "PS384":
|
|
1010
|
+
case "PS512":
|
|
1011
|
+
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
1012
|
+
case "RS256":
|
|
1013
|
+
case "RS384":
|
|
1014
|
+
case "RS512":
|
|
1015
|
+
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
1016
|
+
case "ES256":
|
|
1017
|
+
case "ES384":
|
|
1018
|
+
case "ES512":
|
|
1019
|
+
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
1020
|
+
case "Ed25519":
|
|
1021
|
+
case "EdDSA":
|
|
1022
|
+
return { name: "Ed25519" };
|
|
813
1023
|
default:
|
|
814
1024
|
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
815
1025
|
}
|
|
816
|
-
}
|
|
1026
|
+
};
|
|
817
1027
|
|
|
818
|
-
// node_modules/jose/dist/
|
|
819
|
-
var
|
|
820
|
-
function getSignVerifyKey(alg, key, usage) {
|
|
1028
|
+
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
1029
|
+
var get_sign_verify_key_default = async (alg, key, usage) => {
|
|
821
1030
|
if (key instanceof Uint8Array) {
|
|
822
1031
|
if (!alg.startsWith("HS")) {
|
|
823
|
-
throw new TypeError(invalid_key_input_default(key,
|
|
1032
|
+
throw new TypeError(invalid_key_input_default(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
824
1033
|
}
|
|
825
|
-
return (
|
|
826
|
-
}
|
|
827
|
-
if (key instanceof import_crypto5.KeyObject) {
|
|
828
|
-
return key;
|
|
829
|
-
}
|
|
830
|
-
if (isCryptoKey(key)) {
|
|
831
|
-
checkSigCryptoKey(key, alg, usage);
|
|
832
|
-
return import_crypto5.KeyObject.from(key);
|
|
1034
|
+
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
833
1035
|
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
// node_modules/jose/dist/node/esm/runtime/sign.js
|
|
838
|
-
var oneShotSign;
|
|
839
|
-
if (crypto2.sign.length > 3) {
|
|
840
|
-
oneShotSign = (0, import_util.promisify)(crypto2.sign);
|
|
841
|
-
} else {
|
|
842
|
-
oneShotSign = crypto2.sign;
|
|
843
|
-
}
|
|
844
|
-
var sign2 = async (alg, key, data) => {
|
|
845
|
-
const keyObject = getSignVerifyKey(alg, key, "sign");
|
|
846
|
-
if (alg.startsWith("HS")) {
|
|
847
|
-
const hmac = crypto2.createHmac(hmacDigest(alg), keyObject);
|
|
848
|
-
hmac.update(data);
|
|
849
|
-
return hmac.digest();
|
|
850
|
-
}
|
|
851
|
-
return oneShotSign(dsaDigest(alg), data, keyForCrypto(alg, keyObject));
|
|
1036
|
+
checkSigCryptoKey(key, alg, usage);
|
|
1037
|
+
return key;
|
|
852
1038
|
};
|
|
853
|
-
var sign_default = sign2;
|
|
854
1039
|
|
|
855
|
-
// node_modules/jose/dist/
|
|
1040
|
+
// node_modules/jose/dist/webapi/lib/epoch.js
|
|
856
1041
|
var epoch_default = (date) => Math.floor(date.getTime() / 1e3);
|
|
857
1042
|
|
|
858
|
-
// node_modules/jose/dist/
|
|
1043
|
+
// node_modules/jose/dist/webapi/lib/secs.js
|
|
859
1044
|
var minute = 60;
|
|
860
1045
|
var hour = minute * 60;
|
|
861
1046
|
var day = hour * 24;
|
|
862
1047
|
var week = day * 7;
|
|
863
1048
|
var year = day * 365.25;
|
|
864
|
-
var REGEX = /^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)
|
|
1049
|
+
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
865
1050
|
var secs_default = (str) => {
|
|
866
1051
|
const matched = REGEX.exec(str);
|
|
867
|
-
if (!matched) {
|
|
1052
|
+
if (!matched || matched[4] && matched[1]) {
|
|
868
1053
|
throw new TypeError("Invalid time period format");
|
|
869
1054
|
}
|
|
870
|
-
const value = parseFloat(matched[
|
|
871
|
-
const unit = matched[
|
|
1055
|
+
const value = parseFloat(matched[2]);
|
|
1056
|
+
const unit = matched[3].toLowerCase();
|
|
1057
|
+
let numericDate;
|
|
872
1058
|
switch (unit) {
|
|
873
1059
|
case "sec":
|
|
874
1060
|
case "secs":
|
|
875
1061
|
case "second":
|
|
876
1062
|
case "seconds":
|
|
877
1063
|
case "s":
|
|
878
|
-
|
|
1064
|
+
numericDate = Math.round(value);
|
|
1065
|
+
break;
|
|
879
1066
|
case "minute":
|
|
880
1067
|
case "minutes":
|
|
881
1068
|
case "min":
|
|
882
1069
|
case "mins":
|
|
883
1070
|
case "m":
|
|
884
|
-
|
|
1071
|
+
numericDate = Math.round(value * minute);
|
|
1072
|
+
break;
|
|
885
1073
|
case "hour":
|
|
886
1074
|
case "hours":
|
|
887
1075
|
case "hr":
|
|
888
1076
|
case "hrs":
|
|
889
1077
|
case "h":
|
|
890
|
-
|
|
1078
|
+
numericDate = Math.round(value * hour);
|
|
1079
|
+
break;
|
|
891
1080
|
case "day":
|
|
892
1081
|
case "days":
|
|
893
1082
|
case "d":
|
|
894
|
-
|
|
1083
|
+
numericDate = Math.round(value * day);
|
|
1084
|
+
break;
|
|
895
1085
|
case "week":
|
|
896
1086
|
case "weeks":
|
|
897
1087
|
case "w":
|
|
898
|
-
|
|
1088
|
+
numericDate = Math.round(value * week);
|
|
1089
|
+
break;
|
|
899
1090
|
default:
|
|
900
|
-
|
|
1091
|
+
numericDate = Math.round(value * year);
|
|
1092
|
+
break;
|
|
901
1093
|
}
|
|
1094
|
+
if (matched[1] === "-" || matched[4] === "ago") {
|
|
1095
|
+
return -numericDate;
|
|
1096
|
+
}
|
|
1097
|
+
return numericDate;
|
|
902
1098
|
};
|
|
903
1099
|
|
|
904
|
-
// node_modules/jose/dist/
|
|
1100
|
+
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1101
|
+
function validateInput(label, input) {
|
|
1102
|
+
if (!Number.isFinite(input)) {
|
|
1103
|
+
throw new TypeError(`Invalid ${label} input`);
|
|
1104
|
+
}
|
|
1105
|
+
return input;
|
|
1106
|
+
}
|
|
1107
|
+
var JWTClaimsBuilder = class {
|
|
1108
|
+
#payload;
|
|
1109
|
+
constructor(payload) {
|
|
1110
|
+
if (!is_object_default(payload)) {
|
|
1111
|
+
throw new TypeError("JWT Claims Set MUST be an object");
|
|
1112
|
+
}
|
|
1113
|
+
this.#payload = structuredClone(payload);
|
|
1114
|
+
}
|
|
1115
|
+
data() {
|
|
1116
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
1117
|
+
}
|
|
1118
|
+
get iss() {
|
|
1119
|
+
return this.#payload.iss;
|
|
1120
|
+
}
|
|
1121
|
+
set iss(value) {
|
|
1122
|
+
this.#payload.iss = value;
|
|
1123
|
+
}
|
|
1124
|
+
get sub() {
|
|
1125
|
+
return this.#payload.sub;
|
|
1126
|
+
}
|
|
1127
|
+
set sub(value) {
|
|
1128
|
+
this.#payload.sub = value;
|
|
1129
|
+
}
|
|
1130
|
+
get aud() {
|
|
1131
|
+
return this.#payload.aud;
|
|
1132
|
+
}
|
|
1133
|
+
set aud(value) {
|
|
1134
|
+
this.#payload.aud = value;
|
|
1135
|
+
}
|
|
1136
|
+
set jti(value) {
|
|
1137
|
+
this.#payload.jti = value;
|
|
1138
|
+
}
|
|
1139
|
+
set nbf(value) {
|
|
1140
|
+
if (typeof value === "number") {
|
|
1141
|
+
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
1142
|
+
} else if (value instanceof Date) {
|
|
1143
|
+
this.#payload.nbf = validateInput("setNotBefore", epoch_default(value));
|
|
1144
|
+
} else {
|
|
1145
|
+
this.#payload.nbf = epoch_default(/* @__PURE__ */ new Date()) + secs_default(value);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
set exp(value) {
|
|
1149
|
+
if (typeof value === "number") {
|
|
1150
|
+
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
1151
|
+
} else if (value instanceof Date) {
|
|
1152
|
+
this.#payload.exp = validateInput("setExpirationTime", epoch_default(value));
|
|
1153
|
+
} else {
|
|
1154
|
+
this.#payload.exp = epoch_default(/* @__PURE__ */ new Date()) + secs_default(value);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
set iat(value) {
|
|
1158
|
+
if (typeof value === "undefined") {
|
|
1159
|
+
this.#payload.iat = epoch_default(/* @__PURE__ */ new Date());
|
|
1160
|
+
} else if (value instanceof Date) {
|
|
1161
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch_default(value));
|
|
1162
|
+
} else if (typeof value === "string") {
|
|
1163
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch_default(/* @__PURE__ */ new Date()) + secs_default(value));
|
|
1164
|
+
} else {
|
|
1165
|
+
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
// node_modules/jose/dist/webapi/lib/sign.js
|
|
1171
|
+
var sign_default = async (alg, key, data) => {
|
|
1172
|
+
const cryptoKey = await get_sign_verify_key_default(alg, key, "sign");
|
|
1173
|
+
check_key_length_default(alg, cryptoKey);
|
|
1174
|
+
const signature = await crypto.subtle.sign(subtle_dsa_default(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
1175
|
+
return new Uint8Array(signature);
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
// node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
905
1179
|
var FlattenedSign = class {
|
|
1180
|
+
#payload;
|
|
1181
|
+
#protectedHeader;
|
|
1182
|
+
#unprotectedHeader;
|
|
906
1183
|
constructor(payload) {
|
|
907
1184
|
if (!(payload instanceof Uint8Array)) {
|
|
908
1185
|
throw new TypeError("payload must be an instance of Uint8Array");
|
|
909
1186
|
}
|
|
910
|
-
this
|
|
1187
|
+
this.#payload = payload;
|
|
911
1188
|
}
|
|
912
1189
|
setProtectedHeader(protectedHeader) {
|
|
913
|
-
if (this
|
|
1190
|
+
if (this.#protectedHeader) {
|
|
914
1191
|
throw new TypeError("setProtectedHeader can only be called once");
|
|
915
1192
|
}
|
|
916
|
-
this
|
|
1193
|
+
this.#protectedHeader = protectedHeader;
|
|
917
1194
|
return this;
|
|
918
1195
|
}
|
|
919
1196
|
setUnprotectedHeader(unprotectedHeader) {
|
|
920
|
-
if (this
|
|
1197
|
+
if (this.#unprotectedHeader) {
|
|
921
1198
|
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
922
1199
|
}
|
|
923
|
-
this
|
|
1200
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
924
1201
|
return this;
|
|
925
1202
|
}
|
|
926
1203
|
async sign(key, options) {
|
|
927
|
-
if (!this
|
|
1204
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
928
1205
|
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
929
1206
|
}
|
|
930
|
-
if (!is_disjoint_default(this
|
|
1207
|
+
if (!is_disjoint_default(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
931
1208
|
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
932
1209
|
}
|
|
933
1210
|
const joseHeader = {
|
|
934
|
-
...this
|
|
935
|
-
...this
|
|
1211
|
+
...this.#protectedHeader,
|
|
1212
|
+
...this.#unprotectedHeader
|
|
936
1213
|
};
|
|
937
|
-
const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options
|
|
1214
|
+
const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
938
1215
|
let b64 = true;
|
|
939
1216
|
if (extensions.has("b64")) {
|
|
940
|
-
b64 = this.
|
|
1217
|
+
b64 = this.#protectedHeader.b64;
|
|
941
1218
|
if (typeof b64 !== "boolean") {
|
|
942
1219
|
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
943
1220
|
}
|
|
@@ -947,18 +1224,19 @@ var FlattenedSign = class {
|
|
|
947
1224
|
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
948
1225
|
}
|
|
949
1226
|
check_key_type_default(alg, key, "sign");
|
|
950
|
-
let payload = this
|
|
1227
|
+
let payload = this.#payload;
|
|
951
1228
|
if (b64) {
|
|
952
1229
|
payload = encoder.encode(encode(payload));
|
|
953
1230
|
}
|
|
954
1231
|
let protectedHeader;
|
|
955
|
-
if (this
|
|
956
|
-
protectedHeader = encoder.encode(encode(JSON.stringify(this
|
|
1232
|
+
if (this.#protectedHeader) {
|
|
1233
|
+
protectedHeader = encoder.encode(encode(JSON.stringify(this.#protectedHeader)));
|
|
957
1234
|
} else {
|
|
958
1235
|
protectedHeader = encoder.encode("");
|
|
959
1236
|
}
|
|
960
1237
|
const data = concat(protectedHeader, encoder.encode("."), payload);
|
|
961
|
-
const
|
|
1238
|
+
const k = await normalize_key_default(key, alg);
|
|
1239
|
+
const signature = await sign_default(alg, k, data);
|
|
962
1240
|
const jws = {
|
|
963
1241
|
signature: encode(signature),
|
|
964
1242
|
payload: ""
|
|
@@ -966,27 +1244,28 @@ var FlattenedSign = class {
|
|
|
966
1244
|
if (b64) {
|
|
967
1245
|
jws.payload = decoder.decode(payload);
|
|
968
1246
|
}
|
|
969
|
-
if (this
|
|
970
|
-
jws.header = this
|
|
1247
|
+
if (this.#unprotectedHeader) {
|
|
1248
|
+
jws.header = this.#unprotectedHeader;
|
|
971
1249
|
}
|
|
972
|
-
if (this
|
|
1250
|
+
if (this.#protectedHeader) {
|
|
973
1251
|
jws.protected = decoder.decode(protectedHeader);
|
|
974
1252
|
}
|
|
975
1253
|
return jws;
|
|
976
1254
|
}
|
|
977
1255
|
};
|
|
978
1256
|
|
|
979
|
-
// node_modules/jose/dist/
|
|
1257
|
+
// node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
980
1258
|
var CompactSign = class {
|
|
1259
|
+
#flattened;
|
|
981
1260
|
constructor(payload) {
|
|
982
|
-
this
|
|
1261
|
+
this.#flattened = new FlattenedSign(payload);
|
|
983
1262
|
}
|
|
984
1263
|
setProtectedHeader(protectedHeader) {
|
|
985
|
-
this.
|
|
1264
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
986
1265
|
return this;
|
|
987
1266
|
}
|
|
988
1267
|
async sign(key, options) {
|
|
989
|
-
const jws = await this.
|
|
1268
|
+
const jws = await this.#flattened.sign(key, options);
|
|
990
1269
|
if (jws.payload === void 0) {
|
|
991
1270
|
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
992
1271
|
}
|
|
@@ -994,67 +1273,49 @@ var CompactSign = class {
|
|
|
994
1273
|
}
|
|
995
1274
|
};
|
|
996
1275
|
|
|
997
|
-
// node_modules/jose/dist/
|
|
998
|
-
var
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
this._payload = payload;
|
|
1276
|
+
// node_modules/jose/dist/webapi/jwt/sign.js
|
|
1277
|
+
var SignJWT = class {
|
|
1278
|
+
#protectedHeader;
|
|
1279
|
+
#jwt;
|
|
1280
|
+
constructor(payload = {}) {
|
|
1281
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
1004
1282
|
}
|
|
1005
1283
|
setIssuer(issuer) {
|
|
1006
|
-
this.
|
|
1284
|
+
this.#jwt.iss = issuer;
|
|
1007
1285
|
return this;
|
|
1008
1286
|
}
|
|
1009
1287
|
setSubject(subject) {
|
|
1010
|
-
this.
|
|
1288
|
+
this.#jwt.sub = subject;
|
|
1011
1289
|
return this;
|
|
1012
1290
|
}
|
|
1013
1291
|
setAudience(audience) {
|
|
1014
|
-
this.
|
|
1292
|
+
this.#jwt.aud = audience;
|
|
1015
1293
|
return this;
|
|
1016
1294
|
}
|
|
1017
1295
|
setJti(jwtId) {
|
|
1018
|
-
this.
|
|
1296
|
+
this.#jwt.jti = jwtId;
|
|
1019
1297
|
return this;
|
|
1020
1298
|
}
|
|
1021
1299
|
setNotBefore(input) {
|
|
1022
|
-
|
|
1023
|
-
this._payload = { ...this._payload, nbf: input };
|
|
1024
|
-
} else {
|
|
1025
|
-
this._payload = { ...this._payload, nbf: epoch_default(/* @__PURE__ */ new Date()) + secs_default(input) };
|
|
1026
|
-
}
|
|
1300
|
+
this.#jwt.nbf = input;
|
|
1027
1301
|
return this;
|
|
1028
1302
|
}
|
|
1029
1303
|
setExpirationTime(input) {
|
|
1030
|
-
|
|
1031
|
-
this._payload = { ...this._payload, exp: input };
|
|
1032
|
-
} else {
|
|
1033
|
-
this._payload = { ...this._payload, exp: epoch_default(/* @__PURE__ */ new Date()) + secs_default(input) };
|
|
1034
|
-
}
|
|
1304
|
+
this.#jwt.exp = input;
|
|
1035
1305
|
return this;
|
|
1036
1306
|
}
|
|
1037
1307
|
setIssuedAt(input) {
|
|
1038
|
-
|
|
1039
|
-
this._payload = { ...this._payload, iat: epoch_default(/* @__PURE__ */ new Date()) };
|
|
1040
|
-
} else {
|
|
1041
|
-
this._payload = { ...this._payload, iat: input };
|
|
1042
|
-
}
|
|
1308
|
+
this.#jwt.iat = input;
|
|
1043
1309
|
return this;
|
|
1044
1310
|
}
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
|
-
// node_modules/jose/dist/node/esm/jwt/sign.js
|
|
1048
|
-
var SignJWT = class extends ProduceJWT {
|
|
1049
1311
|
setProtectedHeader(protectedHeader) {
|
|
1050
|
-
this
|
|
1312
|
+
this.#protectedHeader = protectedHeader;
|
|
1051
1313
|
return this;
|
|
1052
1314
|
}
|
|
1053
1315
|
async sign(key, options) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
if (Array.isArray((_a = this._protectedHeader) === null || _a === void 0 ? void 0 : _a.crit) && this._protectedHeader.crit.includes("b64") && this._protectedHeader.b64 === false) {
|
|
1316
|
+
const sig = new CompactSign(this.#jwt.data());
|
|
1317
|
+
sig.setProtectedHeader(this.#protectedHeader);
|
|
1318
|
+
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
|
|
1058
1319
|
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
1059
1320
|
}
|
|
1060
1321
|
return sig.sign(key, options);
|
|
@@ -1065,14 +1326,20 @@ var SignJWT = class extends ProduceJWT {
|
|
|
1065
1326
|
async function generateAuthToken({ apiKeyId, issuerId, privateKey, expirationTime }) {
|
|
1066
1327
|
const alg = "ES256";
|
|
1067
1328
|
const key = await importPKCS8(privateKey, alg);
|
|
1068
|
-
const
|
|
1329
|
+
const jwtBuilder = new SignJWT({}).setProtectedHeader({
|
|
1069
1330
|
// The algorithm used to sign the token (ECDSA with SHA-256)
|
|
1070
1331
|
alg,
|
|
1071
1332
|
// The ID of the private key used to sign the token
|
|
1072
1333
|
kid: apiKeyId,
|
|
1073
1334
|
// The type of the token (JWT)
|
|
1074
1335
|
typ: "JWT"
|
|
1075
|
-
}).
|
|
1336
|
+
}).setAudience("appstoreconnect-v1").setExpirationTime(expirationTime);
|
|
1337
|
+
if (issuerId) {
|
|
1338
|
+
jwtBuilder.setIssuer(issuerId);
|
|
1339
|
+
} else {
|
|
1340
|
+
jwtBuilder.setSubject("user");
|
|
1341
|
+
}
|
|
1342
|
+
const token = await jwtBuilder.sign(key);
|
|
1076
1343
|
return token;
|
|
1077
1344
|
}
|
|
1078
1345
|
|
|
@@ -1082,7 +1349,7 @@ var AppStoreConnectAPI = class {
|
|
|
1082
1349
|
/**
|
|
1083
1350
|
* Creates an instance of the AppStoreConnectAPI.
|
|
1084
1351
|
* @param options - The configuration options for the API.
|
|
1085
|
-
* @param options.issuerId - The issuer ID for generating JWT token.
|
|
1352
|
+
* @param options.issuerId - (Optional) The issuer ID for generating JWT token. Required for Team API keys, omit for Individual API keys.
|
|
1086
1353
|
* @param options.privateKeyId - The ID of the private key used for generating JWT token.
|
|
1087
1354
|
* @param options.privateKey - The content of the private key used for generating JWT token.
|
|
1088
1355
|
* @param options.fetchApi - (Optional) The FetchAPI implementation to use for API requests.
|
|
@@ -1105,10 +1372,11 @@ var AppStoreConnectAPI = class {
|
|
|
1105
1372
|
if (this.options.bearerToken) {
|
|
1106
1373
|
return this.options.bearerToken;
|
|
1107
1374
|
}
|
|
1108
|
-
if (this.options.privateKeyId && this.options.
|
|
1375
|
+
if (this.options.privateKeyId && this.options.privateKey) {
|
|
1109
1376
|
return await generateAuthToken({
|
|
1110
1377
|
apiKeyId: this.options.privateKeyId,
|
|
1111
1378
|
issuerId: this.options.issuerId,
|
|
1379
|
+
// Optional: undefined for Individual keys
|
|
1112
1380
|
privateKey: this.options.privateKey,
|
|
1113
1381
|
expirationTime: Math.floor(Date.now() / 1e3) + (this.options.expirationDuration ?? DEFAULT_EXPIRATION_DURATION_SECONDS)
|
|
1114
1382
|
});
|