unjwt 0.5.8 → 0.5.10

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.
Files changed (36) hide show
  1. package/dist/index.d.mts +5 -6
  2. package/dist/index.mjs +5 -5
  3. package/dist/jwe.d.mts +2 -3
  4. package/dist/jwe.mjs +4 -4
  5. package/dist/jwk.d.mts +2 -3
  6. package/dist/jwk.mjs +2 -2
  7. package/dist/jws.d.mts +2 -3
  8. package/dist/jws.mjs +4 -4
  9. package/dist/shared/unjwt.B1dfkZSt.mjs +161 -0
  10. package/dist/shared/{unjwt.DRUXIabl.mjs → unjwt.BrOta13J.mjs} +19 -8
  11. package/dist/shared/{unjwt.Ca03jPX3.mjs → unjwt.CEjyBwhK.mjs} +1 -1
  12. package/dist/shared/{unjwt.D9da8HQF.d.mts → unjwt.CN1C8TlR.d.mts} +90 -15
  13. package/dist/shared/unjwt.CUUg6g3N.d.mts +128 -0
  14. package/dist/shared/{unjwt.CrcUJklb.d.ts → unjwt.Cz90HQhy.d.mts} +11 -12
  15. package/dist/shared/{unjwt.B2olxeGL.mjs → unjwt.D0WA_yog.mjs} +22 -86
  16. package/dist/shared/{unjwt.8w7jp2aw.d.mts → unjwt.Dof5OLMV.d.mts} +28 -30
  17. package/dist/shared/{unjwt.w-IAnI15.d.ts → unjwt.igKyF5q2.d.mts} +13 -69
  18. package/dist/shared/unjwt.odifuYKu.mjs +297 -0
  19. package/dist/utils.d.mts +2 -2
  20. package/dist/utils.mjs +1 -1
  21. package/package.json +12 -11
  22. package/dist/index.d.ts +0 -6
  23. package/dist/jwe.d.ts +0 -3
  24. package/dist/jwk.d.ts +0 -3
  25. package/dist/jws.d.ts +0 -3
  26. package/dist/shared/unjwt.BHpknTpg.mjs +0 -93
  27. package/dist/shared/unjwt.BZCtr-eB.mjs +0 -277
  28. package/dist/shared/unjwt.BvIkEGGz.d.mts +0 -52
  29. package/dist/shared/unjwt.CbvzYE-m.d.mts +0 -58
  30. package/dist/shared/unjwt.CoSilGqk.d.ts +0 -189
  31. package/dist/shared/unjwt.D4DUiNeM.d.ts +0 -58
  32. package/dist/shared/unjwt.D9da8HQF.d.ts +0 -210
  33. package/dist/shared/unjwt.DH1p_WL8.d.mts +0 -221
  34. package/dist/shared/unjwt.D_Mabhgz.d.mts +0 -172
  35. package/dist/shared/unjwt.c10n3uM8.d.ts +0 -52
  36. package/dist/utils.d.ts +0 -2
@@ -1,5 +1,4 @@
1
- import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, x as JWK_PBES2, D as DeriveKeyOptions, c as DeriveKeyReturn, l as JWK_oct, m as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, e as WrapKeyResult, U as UnwrapKeyOptions, F as JWKPEMAlgorithm, n as JWKSet, C as CompositeKey, d as ContentEncryptionAlgorithm, E as JWKAlgorithm, J as JWKParameters, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm } from './unjwt.D9da8HQF.js';
2
- import { J as JoseHeaderParameters } from './unjwt.c10n3uM8.js';
1
+ import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, x as JWK_PBES2, D as DeriveKeyOptions, c as DeriveKeyReturn, l as JWK_oct, m as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, e as WrapKeyResult, U as UnwrapKeyOptions, F as JWKPEMAlgorithm, n as JWKSet, H as JoseHeaderParameters, C as CompositeKey, d as ContentEncryptionAlgorithm, E as JWKAlgorithm, J as JWKParameters, v as JWK_AES_CBC_HMAC, w as JWK_AES_GCM, u as JWK_AES_GCM_KW, t as JWK_AES_KW, B as JWK_Asymmetric_Algorithm, h as JWK_EC, y as JWK_ECDH_ES, r as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, z as JWK_ED, o as JWK_HMAC, k as JWK_RSA, s as JWK_RSA_ENC, q as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, p as JWK_RSA_SIGN, A as JWK_Symmetric_Algorithm } from './unjwt.CN1C8TlR.mjs';
3
2
 
4
3
  /**
5
4
  * This is a fork of Jose library's utility functions.
@@ -31,7 +30,7 @@ declare function generateKey<TAlg extends GenerateKeyAlgorithm, TOptions extends
31
30
  * @param options Configuration options including salt and iterations.
32
31
  * @returns A Promise resolving to the derived key (CryptoKey) or its JWK_oct representation.
33
32
  */
34
- declare function deriveKeyFromPassword<TAlg extends JWK_PBES2, TOptions extends DeriveKeyOptions>(password: string | Uint8Array, alg: TAlg, options: TOptions): Promise<DeriveKeyReturn<TOptions>>;
33
+ declare function deriveKeyFromPassword<TAlg extends JWK_PBES2, TOptions extends DeriveKeyOptions>(password: string | Uint8Array<ArrayBuffer>, alg: TAlg, options: TOptions): Promise<DeriveKeyReturn<TOptions>>;
35
34
  /**
36
35
  * Imports a key from various formats (CryptoKey, JWK, Uint8Array).
37
36
  *
@@ -44,11 +43,11 @@ declare function deriveKeyFromPassword<TAlg extends JWK_PBES2, TOptions extends
44
43
  * @param alg The algorithm hint, required when importing asymmetric JWKs.
45
44
  * @returns A Promise resolving to the imported key as CryptoKey or Uint8Array.
46
45
  */
47
- declare function importKey(key: string): Promise<Uint8Array>;
48
- declare function importKey(key: Uint8Array): Promise<Uint8Array>;
46
+ declare function importKey(key: string): Promise<Uint8Array<ArrayBuffer>>;
47
+ declare function importKey(key: Uint8Array<ArrayBuffer>): Promise<Uint8Array<ArrayBuffer>>;
49
48
  declare function importKey(key: CryptoKey): Promise<CryptoKey>;
50
- declare function importKey(key: JWK_oct): Promise<Uint8Array>;
51
- declare function importKey(key: CryptoKey | JWK | Uint8Array | string, alg?: string): Promise<CryptoKey | Uint8Array>;
49
+ declare function importKey(key: JWK_oct): Promise<Uint8Array<ArrayBuffer>>;
50
+ declare function importKey(key: CryptoKey | JWK | Uint8Array<ArrayBuffer> | string, alg?: string): Promise<CryptoKey | Uint8Array<ArrayBuffer>>;
52
51
  /**
53
52
  * Exports a CryptoKey to a JWK (JSON Web Key) format.
54
53
  *
@@ -56,7 +55,7 @@ declare function importKey(key: CryptoKey | JWK | Uint8Array | string, alg?: str
56
55
  * @param jwk Optional partial JWK to merge with the exported key, allowing overrides.
57
56
  * @returns A Promise resolving to the exported JWK.
58
57
  */
59
- declare function exportKey(key: CryptoKey, jwk?: Partial<JWK>): Promise<JWK>;
58
+ declare function exportKey<T extends JWK>(key: CryptoKey, jwk?: Partial<JWK>): Promise<T>;
60
59
  /**
61
60
  * Wraps a Content Encryption Key (CEK) using the specified algorithm and wrapping key.
62
61
  *
@@ -66,7 +65,7 @@ declare function exportKey(key: CryptoKey, jwk?: Partial<JWK>): Promise<JWK>;
66
65
  * @param options Additional options required by certain algorithms (e.g., p2s, p2c for PBES2).
67
66
  * @returns A Promise resolving to an object containing the wrapped key and any necessary parameters (iv, tag, epk, etc.).
68
67
  */
69
- declare function wrapKey(alg: KeyManagementAlgorithm, keyToWrap: CryptoKey | Uint8Array, wrappingKey: CryptoKey | JWK | string | Uint8Array, options?: WrapKeyOptions): Promise<WrapKeyResult>;
68
+ declare function wrapKey(alg: KeyManagementAlgorithm, keyToWrap: CryptoKey | Uint8Array<ArrayBuffer>, wrappingKey: CryptoKey | JWK | string | Uint8Array<ArrayBuffer>, options?: WrapKeyOptions): Promise<WrapKeyResult>;
70
69
  /**
71
70
  * Unwraps a Content Encryption Key (CEK) using the specified algorithm and unwrapping key.
72
71
  *
@@ -76,9 +75,9 @@ declare function wrapKey(alg: KeyManagementAlgorithm, keyToWrap: CryptoKey | Uin
76
75
  * @param options Additional options required by certain algorithms (e.g., iv, tag, p2s, p2c, epk).
77
76
  * @returns A Promise resolving to the unwrapped key (CEK) as a CryptoKey or Uint8Array.
78
77
  */
79
- declare function unwrapKey<T extends boolean | undefined = undefined>(alg: KeyManagementAlgorithm, wrappedKey: Uint8Array, unwrappingKey: CryptoKey | JWK | string | Uint8Array, options?: UnwrapKeyOptions & {
78
+ declare function unwrapKey<T extends boolean | undefined = undefined>(alg: KeyManagementAlgorithm, wrappedKey: Uint8Array<ArrayBuffer>, unwrappingKey: CryptoKey | JWK | string | Uint8Array<ArrayBuffer>, options?: UnwrapKeyOptions & {
80
79
  returnAs?: T;
81
- }): Promise<T extends false ? Uint8Array : CryptoKey>;
80
+ }): Promise<T extends false ? Uint8Array<ArrayBuffer> : CryptoKey>;
82
81
  /**
83
82
  * Imports a key from a PEM-encoded string and converts it to a JWK.
84
83
  *
@@ -90,7 +89,7 @@ declare function unwrapKey<T extends boolean | undefined = undefined>(alg: KeyMa
90
89
  * @param jwkExtras Additional properties to merge into the resulting JWK.
91
90
  * @returns A Promise resolving to the imported key as a JWK.
92
91
  */
93
- declare function importJWKFromPEM(pem: string, pemType: "pkcs8" | "spki" | "x509", alg: JWKPEMAlgorithm, importOptions?: KeyImportOptions, jwkExtras?: Partial<JWK>): Promise<JWK>;
92
+ declare function importJWKFromPEM<T extends JWK>(pem: string, pemType: "pkcs8" | "spki" | "x509", alg: JWKPEMAlgorithm, importOptions?: KeyImportOptions, jwkExtras?: Partial<JWK>): Promise<T>;
94
93
  /**
95
94
  * Exports a JWK to a PEM-encoded string.
96
95
  *
@@ -1,6 +1,6 @@
1
- import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.DRUXIabl.mjs';
2
- import { f as concatUint8Arrays, t as textEncoder, g as assertCryptoKey, b as base64UrlEncode, h as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.BHpknTpg.mjs';
3
- import { c as checkKeyLength } from './unjwt.Ca03jPX3.mjs';
1
+ import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.BrOta13J.mjs';
2
+ import { k as concatUint8Arrays, t as textEncoder, l as assertCryptoKey, d as base64UrlEncode, m as isCryptoKey, a as isJWK, f as base64UrlDecode, r as randomBytes, b as applyTypCtyDefaults, c as computeJwtTimeClaims, n as getPlaintextBytes, o as decodePayloadFromBytes, p as validateCriticalHeadersJWE } from './unjwt.odifuYKu.mjs';
3
+ import { c as checkKeyLength } from './unjwt.CEjyBwhK.mjs';
4
4
 
5
5
  function lengthAndInput(input) {
6
6
  return concatUint8Arrays(uint32be(input.length), input);
@@ -218,7 +218,6 @@ async function encrypt(payload, key, options = {}) {
218
218
  if (!enc) {
219
219
  enc = isJWK(key) && "enc" in key ? key.enc : "A128GCM";
220
220
  }
221
- const plaintextBytes = getPlaintextBytes(payload);
222
221
  const jweKeyManagementParams = {};
223
222
  if (keyManagementIV) jweKeyManagementParams.iv = keyManagementIV;
224
223
  if (p2s) jweKeyManagementParams.p2s = p2s;
@@ -252,13 +251,15 @@ async function encrypt(payload, key, options = {}) {
252
251
  alg,
253
252
  enc
254
253
  };
255
- if (jweProtectedHeader.typ === void 0 && typeof payload === "object" && !(payload instanceof Uint8Array)) {
256
- jweProtectedHeader.typ = "JWT";
257
- }
258
- if (jweProtectedHeader.typ === "JWT" && typeof payload === "object" && !(payload instanceof Uint8Array)) {
259
- jweProtectedHeader.cty ||= "json";
260
- }
261
- const protectedHeaderSerialized = JSON.stringify(jweProtectedHeader);
254
+ const protectedHeader = applyTypCtyDefaults(jweProtectedHeader, payload);
255
+ const computedPayload = computeJwtTimeClaims(
256
+ payload,
257
+ protectedHeader.typ,
258
+ options.expiresIn,
259
+ options.currentDate
260
+ );
261
+ const plaintextBytes = getPlaintextBytes(computedPayload || payload);
262
+ const protectedHeaderSerialized = JSON.stringify(protectedHeader);
262
263
  const protectedHeaderEncoded = base64UrlEncode(protectedHeaderSerialized);
263
264
  const aadBytes = textEncoder.encode(protectedHeaderEncoded);
264
265
  const contentIVBytes = providedContentIV ?? generateIV(enc);
@@ -345,7 +346,7 @@ async function decrypt(jwe, key, options) {
345
346
  keyUsage: options?.keyUsage,
346
347
  extractable: options?.extractable,
347
348
  returnAs: false
348
- // Returning CEK as Uint8Array
349
+ // Returning CEK as Uint8Array<ArrayBuffer>
349
350
  };
350
351
  const cekBytes = await unwrapKey(
351
352
  alg,
@@ -362,66 +363,15 @@ async function decrypt(jwe, key, options) {
362
363
  contentAuthTagBytes,
363
364
  aadBytes
364
365
  );
365
- let payload;
366
- if (options?.forceUint8Array) {
367
- payload = plaintextBytes;
368
- } else {
369
- const decodedString = textDecoder.decode(plaintextBytes);
370
- const cty = protectedHeader.cty?.toLowerCase();
371
- const isJsonOutput = protectedHeader.typ === "JWT" || cty === "json" || cty === "application/json" || cty && cty.endsWith("+json");
372
- if (isJsonOutput) {
373
- if (decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]")) {
374
- try {
375
- payload = JSON.parse(decodedString);
376
- } catch {
377
- payload = decodedString;
378
- }
379
- } else {
380
- payload = decodedString;
381
- }
382
- } else {
383
- payload = decodedString;
384
- }
385
- }
386
- if (options?.critical && protectedHeader.crit) {
387
- const understoodParams = /* @__PURE__ */ new Set([
388
- ...options.critical || [],
389
- // JWE specific standard headers:
390
- "alg",
391
- "enc",
392
- "typ",
393
- "cty",
394
- "kid",
395
- "jwk",
396
- "jku",
397
- "x5c",
398
- "x5t",
399
- "x5u",
400
- "iv",
401
- "tag",
402
- "p2s",
403
- "p2c",
404
- "epk",
405
- "apu",
406
- "apv"
407
- ]);
408
- for (const critParam of protectedHeader.crit) {
409
- if (!Object.prototype.hasOwnProperty.call(protectedHeader, critParam)) {
410
- throw new Error(
411
- `Critical header parameter "${critParam}" listed in "crit" but not present in the protected header.`
412
- );
413
- }
414
- if (!understoodParams.has(critParam)) {
415
- throw new Error(
416
- `Critical header parameter not understood: ${critParam}`
417
- );
418
- }
419
- }
420
- } else if (!options?.critical && protectedHeader.crit) {
421
- throw new Error(
422
- `Unprocessed critical header parameters: ${protectedHeader.crit.join(", ")}`
423
- );
424
- }
366
+ const payload = decodePayloadFromBytes(
367
+ plaintextBytes,
368
+ protectedHeader,
369
+ options?.forceUint8Array
370
+ );
371
+ validateCriticalHeadersJWE(protectedHeader, [
372
+ ...options?.critical || [],
373
+ ...options?.requiredHeaders || []
374
+ ]);
425
375
  return {
426
376
  payload,
427
377
  protectedHeader,
@@ -429,20 +379,6 @@ async function decrypt(jwe, key, options) {
429
379
  aad: aadBytes
430
380
  };
431
381
  }
432
- function getPlaintextBytes(payload) {
433
- if (payload instanceof Uint8Array) {
434
- return payload;
435
- }
436
- if (typeof payload === "string") {
437
- return textEncoder.encode(payload);
438
- }
439
- if (typeof payload === "object" && payload !== null) {
440
- return textEncoder.encode(JSON.stringify(payload));
441
- }
442
- throw new TypeError(
443
- "Plaintext must be a string, Uint8Array, or a JSON-serializable object."
444
- );
445
- }
446
382
 
447
383
  const jwe = {
448
384
  __proto__: null,
@@ -1,5 +1,4 @@
1
- import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, f as JWK_EC_Public, m as JWK } from './unjwt.D9da8HQF.mjs';
2
- import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.BvIkEGGz.mjs';
1
+ import { K as KeyManagementAlgorithm, d as ContentEncryptionAlgorithm, H as JoseHeaderParameters, f as JWK_EC_Public, m as JWK, M as JWTClaimValidationOptions, I as JWTClaims } from './unjwt.CN1C8TlR.mjs';
3
2
 
4
3
  /** Recognized JWE Header Parameters, any other Header Members may also be present. */
5
4
  interface JWEHeaderParameters extends JoseHeaderParameters {
@@ -44,8 +43,8 @@ interface JWEHeaderParameters extends JoseHeaderParameters {
44
43
  }
45
44
  /** Recognized JWE Key Management-related Header Parameters. */
46
45
  interface JWEKeyManagementHeaderParameters {
47
- apu?: Uint8Array;
48
- apv?: Uint8Array;
46
+ apu?: Uint8Array<ArrayBuffer>;
47
+ apv?: Uint8Array<ArrayBuffer>;
49
48
  /**
50
49
  * For Internal use only
51
50
  */
@@ -53,11 +52,11 @@ interface JWEKeyManagementHeaderParameters {
53
52
  /**
54
53
  * For Internal use only
55
54
  */
56
- p2s?: Uint8Array;
55
+ p2s?: Uint8Array<ArrayBuffer>;
57
56
  /**
58
57
  * For Internal use only
59
58
  */
60
- iv?: Uint8Array;
59
+ iv?: Uint8Array<ArrayBuffer>;
61
60
  /**
62
61
  * For Internal use only
63
62
  */
@@ -71,48 +70,47 @@ interface JWEEncryptOptions {
71
70
  alg?: KeyManagementAlgorithm;
72
71
  /** JWE "enc" (Encryption Algorithm) Header Parameter. Content Encryption Algorithm. */
73
72
  enc?: ContentEncryptionAlgorithm;
73
+ /** Date to use when computing NumericDate claims, defaults to `new Date()`. */
74
+ currentDate?: Date;
75
+ /** Time at which the JWT should expire, if no `exp` was already provided (only when typ is JWT). */
76
+ expiresIn?: number;
74
77
  /** Additional JWE Protected Header parameters. */
75
78
  protectedHeader?: Omit<JWEHeaderParameters, "alg" | "enc" | "iv" | "tag" | "p2s" | "p2c" | "apu" | "apv">;
76
79
  /** Initialization Vector for AES-GCMKW key wrapping. Generated if not provided. */
77
- keyManagementIV?: Uint8Array;
80
+ keyManagementIV?: Uint8Array<ArrayBuffer>;
78
81
  /** PBES2 Salt value (p2s). Required for PBES2 algorithms. */
79
- p2s?: Uint8Array;
82
+ p2s?: Uint8Array<ArrayBuffer>;
80
83
  /** PBES2 Iteration count (p2c). Required for PBES2 algorithms. */
81
84
  p2c?: number;
82
85
  /** ECDH-ES Agreement PartyUInfo. */
83
- ecdhPartyUInfo?: Uint8Array;
86
+ ecdhPartyUInfo?: Uint8Array<ArrayBuffer>;
84
87
  /** ECDH-ES Agreement PartyVInfo. */
85
- ecdhPartyVInfo?: Uint8Array;
88
+ ecdhPartyVInfo?: Uint8Array<ArrayBuffer>;
86
89
  /**
87
90
  * Content Encryption Key (CEK) to use.
88
91
  * If provided, it will be used directly. Otherwise, a CEK will be generated.
89
92
  */
90
- cek?: Uint8Array;
93
+ cek?: Uint8Array<ArrayBuffer>;
91
94
  /**
92
95
  * Initialization Vector for content encryption.
93
96
  * If provided, it will be used. Otherwise, one will be generated.
94
97
  */
95
- contentEncryptionIV?: Uint8Array;
98
+ contentEncryptionIV?: Uint8Array<ArrayBuffer>;
96
99
  }
97
100
  /**
98
101
  * Key lookup function for JWE decryption.
99
102
  * @param header The JWE Protected Header.
100
103
  * @returns The key material (CryptoKey, JWK, password string, or raw Uint8Array) or a Promise resolving to it.
101
104
  */
102
- type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array | Promise<CryptoKey | JWK | string | Uint8Array>;
105
+ type JWEKeyLookupFunction = (header: JWEHeaderParameters, token: string) => CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | string | Uint8Array<ArrayBuffer>>;
103
106
  /**
104
107
  * JWE (JSON Web Encryption) decryption options
105
108
  */
106
- interface JWEDecryptOptions {
109
+ interface JWEDecryptOptions extends JWTClaimValidationOptions {
107
110
  /** A list of allowed JWE "alg" (Algorithm) Header Parameter values for key management. */
108
111
  algorithms?: KeyManagementAlgorithm[];
109
112
  /** A list of allowed JWE "enc" (Encryption Algorithm) Header Parameter values for content encryption. */
110
113
  encryptionAlgorithms?: ContentEncryptionAlgorithm[];
111
- /**
112
- * Critical Header Parameters to be understood and processed.
113
- * If the JWE contains critical headers not in this list (and not inherently understood by the library), decryption will fail.
114
- */
115
- critical?: string[];
116
114
  /** Algorithm to import the unwrapped CEK as (e.g., { name: 'AES-GCM' }). Defaults based on 'enc'. */
117
115
  unwrappedKeyAlgorithm?: Parameters<typeof crypto.subtle.importKey>[2];
118
116
  /** Key usages for the unwrapped CEK. Defaults based on 'enc' (typically ['encrypt', 'decrypt']). */
@@ -125,15 +123,15 @@ interface JWEDecryptOptions {
125
123
  /**
126
124
  * Result of a JWE decryption operation.
127
125
  */
128
- interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
126
+ interface JWEDecryptResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> {
129
127
  /** The decrypted payload. */
130
128
  payload: T;
131
129
  /** The JWE Protected Header. */
132
130
  protectedHeader: JWEHeaderParameters;
133
131
  /** The Content Encryption Key (CEK) used for decryption, as Uint8Array. */
134
- cek: Uint8Array;
132
+ cek: Uint8Array<ArrayBuffer>;
135
133
  /** The Additional Authenticated Data (AAD) used, as Uint8Array. */
136
- aad: Uint8Array;
134
+ aad: Uint8Array<ArrayBuffer>;
137
135
  }
138
136
 
139
137
  /**
@@ -144,17 +142,17 @@ interface JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims
144
142
  * @param options JWE encryption options, including `alg` (key management algorithm) and `enc` (content encryption algorithm).
145
143
  * @returns A Promise resolving to the JWE Compact Serialization string.
146
144
  */
147
- declare function encrypt(payload: JWTClaims, key: JWK | string | Uint8Array, options?: JWEEncryptOptions): Promise<string>;
148
- declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: JWK | string | Uint8Array, options?: JWEEncryptOptions): Promise<string>;
145
+ declare function encrypt(payload: JWTClaims, key: JWK | string | Uint8Array<ArrayBuffer>, options?: JWEEncryptOptions): Promise<string>;
146
+ declare function encrypt(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: JWK | string | Uint8Array<ArrayBuffer>, options?: JWEEncryptOptions): Promise<string>;
149
147
  declare function encrypt(payload: JWTClaims, key: CryptoKey, options: JWEEncryptOptions & {
150
148
  alg: KeyManagementAlgorithm;
151
149
  enc: ContentEncryptionAlgorithm;
152
150
  }): Promise<string>;
153
- declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWEEncryptOptions & {
151
+ declare function encrypt(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey, options: JWEEncryptOptions & {
154
152
  alg: KeyManagementAlgorithm;
155
153
  enc: ContentEncryptionAlgorithm;
156
154
  }): Promise<string>;
157
- declare function encrypt(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | string | Uint8Array, options: JWEEncryptOptions & {
155
+ declare function encrypt(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey | JWK | string | Uint8Array<ArrayBuffer>, options: JWEEncryptOptions & {
158
156
  alg: KeyManagementAlgorithm;
159
157
  enc: ContentEncryptionAlgorithm;
160
158
  }): Promise<string>;
@@ -167,13 +165,13 @@ declare function encrypt(payload: string | Uint8Array | Record<string, any>, key
167
165
  * @returns A Promise resolving to an object containing the decrypted plaintext, protected header, CEK, and AAD.
168
166
  * @throws If JWE is invalid, decryption fails, or options are not met.
169
167
  */
170
- declare function decrypt<T extends JWTClaims | Uint8Array | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
171
- declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array | JWEKeyLookupFunction, options: JWEDecryptOptions & {
168
+ declare function decrypt<T extends JWTClaims | Uint8Array<ArrayBuffer> | string>(jwe: string, key: CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
169
+ declare function decrypt(jwe: string, key: CryptoKey | JWK | string | Uint8Array<ArrayBuffer> | JWEKeyLookupFunction, options: JWEDecryptOptions & {
172
170
  forceUint8Array: true;
173
- }): Promise<JWEDecryptResult<Uint8Array>>;
171
+ }): Promise<JWEDecryptResult<Uint8Array<ArrayBuffer>>>;
174
172
 
175
173
  type jwe_JWEDecryptOptions = JWEDecryptOptions;
176
- type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWEDecryptResult<T>;
174
+ type jwe_JWEDecryptResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> = JWEDecryptResult<T>;
177
175
  type jwe_JWEEncryptOptions = JWEEncryptOptions;
178
176
  type jwe_JWEHeaderParameters = JWEHeaderParameters;
179
177
  type jwe_JWEKeyLookupFunction = JWEKeyLookupFunction;
@@ -1,5 +1,4 @@
1
- import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, m as JWK, n as JWKSet } from './unjwt.D9da8HQF.js';
2
- import { J as JoseHeaderParameters, a as JWTClaims } from './unjwt.c10n3uM8.js';
1
+ import { o as JWK_HMAC, p as JWK_RSA_SIGN, q as JWK_RSA_PSS, r as JWK_ECDSA, H as JoseHeaderParameters, m as JWK, n as JWKSet, M as JWTClaimValidationOptions, I as JWTClaims } from './unjwt.CN1C8TlR.mjs';
3
2
 
4
3
  type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
5
4
  /** JWS Signing Algorithm Identifier. */
@@ -39,73 +38,18 @@ interface JWSSignOptions {
39
38
  expiresIn?: number;
40
39
  }
41
40
  /** Result of JWS verification */
42
- interface JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> {
41
+ interface JWSVerifyResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> {
43
42
  /** The decoded and verified payload. */
44
43
  payload: T;
45
44
  /** The JWS Protected Header. */
46
45
  protectedHeader: JWSProtectedHeader;
47
46
  }
48
47
  /** Options for JWS verification */
49
- interface JWSVerifyOptions {
48
+ interface JWSVerifyOptions extends JWTClaimValidationOptions {
50
49
  /** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
51
50
  algorithms?: JWSAlgorithm[];
52
51
  /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
53
52
  forceUint8Array?: boolean;
54
- /**
55
- * Expected JWT "aud" (Audience) Claim value(s).
56
- *
57
- * This option makes the JWT "aud" (Audience) Claim presence required.
58
- */
59
- audience?: string | string[];
60
- /**
61
- * Clock skew tolerance (in seconds) for validating JWT claims.
62
- *
63
- * Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
64
- * validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
65
- */
66
- clockTolerance?: number;
67
- /**
68
- * Expected JWT "iss" (Issuer) Claim value(s).
69
- *
70
- * This option makes the JWT "iss" (Issuer) Claim presence required.
71
- */
72
- issuer?: string | string[];
73
- /**
74
- * Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
75
- *
76
- * This option makes the JWT "iat" (Issued At) Claim presence required.
77
- */
78
- maxTokenAge?: number;
79
- /**
80
- * Expected JWT "sub" (Subject) Claim value.
81
- *
82
- * This option makes the JWT "sub" (Subject) Claim presence required.
83
- */
84
- subject?: string;
85
- /**
86
- * Expected JWT "typ" (Type) Header Parameter value.
87
- *
88
- * This option makes the JWT "typ" (Type) Header Parameter presence required.
89
- */
90
- typ?: string;
91
- /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
92
- currentDate?: Date;
93
- /** List of critical header parameters that must be understood and processed. */
94
- requiredHeaders?: string[];
95
- /**
96
- * Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
97
- * the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
98
- * {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
99
- * the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
100
- * the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
101
- * present.
102
- */
103
- requiredClaims?: string[];
104
- /**
105
- * List of critical header parameters that must be understood and processed.
106
- * @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
107
- */
108
- critical?: string[];
109
53
  }
110
54
  /**
111
55
  * Key lookup function for JWS verification.
@@ -113,7 +57,7 @@ interface JWSVerifyOptions {
113
57
  * @param token The JWS token.
114
58
  * @returns The key material (CryptoKey, JWK, or raw Uint8Array) or a Promise resolving to it.
115
59
  */
116
- type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array | Promise<CryptoKey | JWK | JWKSet | Uint8Array>;
60
+ type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer>>;
117
61
 
118
62
  /**
119
63
  * Creates a JWS (JSON Web Signature) in Compact Serialization format.
@@ -124,20 +68,20 @@ type JWSKeyLookupFunction = (header: JWSProtectedHeader, token: string) => Crypt
124
68
  * @returns A Promise resolving to the JWS Compact Serialization string.
125
69
  */
126
70
  declare function sign(payload: JWTClaims, key: JWK, options?: JWSSignOptions): Promise<string>;
127
- declare function sign(payload: string | Uint8Array | Record<string, any>, key: JWK, options?: JWSSignOptions): Promise<string>;
71
+ declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: JWK, options?: JWSSignOptions): Promise<string>;
128
72
  declare function sign(payload: JWTClaims, key: CryptoKey, options: JWSSignOptions & {
129
73
  alg: JWSAlgorithm;
130
74
  }): Promise<string>;
131
- declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
75
+ declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey, options: JWSSignOptions & {
132
76
  alg: JWSAlgorithm;
133
77
  }): Promise<string>;
134
- declare function sign(payload: JWTClaims, key: Uint8Array, options: JWSSignOptions & {
78
+ declare function sign(payload: JWTClaims, key: Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
135
79
  alg: JWSAlgorithm;
136
80
  }): Promise<string>;
137
- declare function sign(payload: string | Uint8Array | Record<string, any>, key: Uint8Array, options: JWSSignOptions & {
81
+ declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
138
82
  alg: JWSAlgorithm;
139
83
  }): Promise<string>;
140
- declare function sign(payload: string | Uint8Array | Record<string, any>, key: CryptoKey | JWK | Uint8Array, options: JWSSignOptions & {
84
+ declare function sign(payload: string | Uint8Array<ArrayBuffer> | Record<string, any>, key: CryptoKey | JWK | Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
141
85
  alg: JWSAlgorithm;
142
86
  }): Promise<string>;
143
87
  /**
@@ -149,10 +93,10 @@ declare function sign(payload: string | Uint8Array | Record<string, any>, key: C
149
93
  * @returns A Promise resolving to an object containing the verified payload and protected header.
150
94
  * @throws If the JWS is invalid, signature verification fails, or options are not met.
151
95
  */
152
- declare function verify<T extends JWTClaims | Uint8Array | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
153
- declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array | JWSKeyLookupFunction, options: JWSVerifyOptions & {
96
+ declare function verify<T extends JWTClaims | Uint8Array<ArrayBuffer> | string>(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer> | JWSKeyLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
97
+ declare function verify(jws: string, key: CryptoKey | JWK | JWKSet | Uint8Array<ArrayBuffer> | JWSKeyLookupFunction, options: JWSVerifyOptions & {
154
98
  forceUint8Array: true;
155
- }): Promise<JWSVerifyResult<Uint8Array>>;
99
+ }): Promise<JWSVerifyResult<Uint8Array<ArrayBuffer>>>;
156
100
 
157
101
  type jws_JWSAlgorithm = JWSAlgorithm;
158
102
  type jws_JWSHeaderParameters = JWSHeaderParameters;
@@ -160,7 +104,7 @@ type jws_JWSKeyLookupFunction = JWSKeyLookupFunction;
160
104
  type jws_JWSProtectedHeader = JWSProtectedHeader;
161
105
  type jws_JWSSignOptions = JWSSignOptions;
162
106
  type jws_JWSVerifyOptions = JWSVerifyOptions;
163
- type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array | string = JWTClaims | Uint8Array | string> = JWSVerifyResult<T>;
107
+ type jws_JWSVerifyResult<T extends JWTClaims | Uint8Array<ArrayBuffer> | string = JWTClaims | Uint8Array<ArrayBuffer> | string> = JWSVerifyResult<T>;
164
108
  declare const jws_sign: typeof sign;
165
109
  declare const jws_verify: typeof verify;
166
110
  declare namespace jws {