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