unjwt 0.7.0 → 0.7.1

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.
@@ -27,8 +27,12 @@ type JWKLookupFunctionHeader = {
27
27
  *
28
28
  * Returning a `string` is meaningful for JWE only (PBES2 password); for JWS
29
29
  * a string return is encoded to bytes and used as a raw symmetric key.
30
+ *
31
+ * The optional `TReturn` generic lets callers who always hand back a specific
32
+ * key shape (e.g. a `JWK_EC_Public<"ES256">`) preserve that narrowing all the
33
+ * way into the `verify` / `decrypt` key resolution path.
30
34
  */
31
- type JWKLookupFunction = (header: JWKLookupFunctionHeader, token: string) => CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer> | Promise<CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>>;
35
+ type JWKLookupFunction<TReturn = CryptoKey | JWK | JWKSet | string | Uint8Array<ArrayBuffer>> = (header: JWKLookupFunctionHeader, token: string) => TReturn | Promise<TReturn>;
32
36
  /**
33
37
  * Interface for custom JWK import cache implementations.
34
38
  *
@@ -77,22 +81,7 @@ interface GenerateKeyOptions {
77
81
  */
78
82
  toJWK?: boolean;
79
83
  }
80
- type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? TAlg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC ? {
81
- privateKey: JWK_RSA_Private;
82
- publicKey: JWK_RSA_Public;
83
- } : TAlg extends JWK_ECDSA ? {
84
- privateKey: JWK_EC_Private;
85
- publicKey: JWK_EC_Public;
86
- } : TAlg extends JWK_ECDH_ES ? {
87
- privateKey: JWK_EC_Private;
88
- publicKey: JWK_EC_Public;
89
- } | {
90
- privateKey: JWK_OKP_Private;
91
- publicKey: JWK_OKP_Public;
92
- } : TAlg extends JWK_OKP_SIGN ? {
93
- privateKey: JWK_OKP_Private;
94
- publicKey: JWK_OKP_Public;
95
- } : never : TAlg extends JWK_AES_CBC_HMAC | JWK_Symmetric_Algorithm ? JWK_oct : never;
84
+ type GenerateKeyReturnJWK<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_Asymmetric_Algorithm ? JWK_Pair<TAlg> : TAlg extends JWK_AES_CBC_HMAC | JWK_Symmetric_Algorithm ? JWK_oct<TAlg> : never;
96
85
  type GenerateKeyReturnCrypto<TAlg extends GenerateKeyAlgorithm> = TAlg extends JWK_AES_CBC_HMAC ? Uint8Array<ArrayBuffer> : TAlg extends JWK_Asymmetric_Algorithm ? CryptoKeyPair : CryptoKey;
97
86
  type GenerateKeyReturn<TAlg extends GenerateKeyAlgorithm, TOptions extends GenerateKeyOptions> = TOptions["toJWK"] extends true ? GenerateKeyReturnJWK<TAlg> : GenerateKeyReturnCrypto<TAlg>;
98
87
  type GenerateJWKOptions = Omit<GenerateKeyOptions, "toJWK">;
@@ -114,9 +103,27 @@ interface DeriveKeyOptions {
114
103
  */
115
104
  toJWK?: boolean;
116
105
  }
117
- type DeriveKeyReturn<TOptions extends DeriveKeyOptions> = TOptions["toJWK"] extends true ? JWK_oct : TOptions["toJWK"] extends object ? JWK_oct : CryptoKey;
106
+ /** PBES2 → AES-KW alg that ends up stamped on the derived JWK's `alg`. */
107
+ type DerivedJWKAlg<TAlg extends JWK_PBES2> = TAlg extends "PBES2-HS256+A128KW" ? "A128KW" : TAlg extends "PBES2-HS384+A192KW" ? "A192KW" : TAlg extends "PBES2-HS512+A256KW" ? "A256KW" : JWK_AES_KW;
108
+ type DeriveKeyReturn<TOptions extends DeriveKeyOptions, TAlg extends JWK_PBES2 = JWK_PBES2> = TOptions["toJWK"] extends true ? JWK_oct<DerivedJWKAlg<TAlg>> : TOptions["toJWK"] extends object ? JWK_oct<DerivedJWKAlg<TAlg>> : CryptoKey;
118
109
  type KeyManagementAlgorithm = JWK_RSA_ENC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_PBES2 | JWK_ECDH_ES | "dir";
119
110
  type ContentEncryptionAlgorithm = JWK_AES_GCM | JWK_AES_CBC_HMAC;
111
+ /**
112
+ * Keys admissible as the `wrappingKey` argument of {@link wrapKey}, narrowed
113
+ * by the key management algorithm. Mirrors the runtime branches in
114
+ * `jwk.wrapKey` and the inference in `inferJWEAllowedAlgorithms`.
115
+ *
116
+ * - `dir` accepts any symmetric JWK (the key _is_ the CEK).
117
+ * - AES-GCMKW tolerates a JWK whose `alg` is the bare `A*GCM` counterpart —
118
+ * matches the `jweAlgsFromOctJWK` aliasing rule.
119
+ */
120
+ type WrappingKeyFor<A extends KeyManagementAlgorithm> = A extends JWK_RSA_ENC ? CryptoKey | JWK_RSA_Public<A> : A extends JWK_ECDH_ES ? CryptoKey | JWK_EC_Public<A> | JWK_OKP_Public<A> : A extends JWK_PBES2 ? string | Uint8Array<ArrayBuffer> | JWK_oct<A> : A extends JWK_AES_KW ? CryptoKey | JWK_oct<A> : A extends JWK_AES_GCM_KW ? CryptoKey | JWK_oct<A | `A${"128" | "192" | "256"}GCM`> : A extends "dir" ? CryptoKey | JWK_oct | Uint8Array<ArrayBuffer> : never;
121
+ /**
122
+ * Keys admissible as the `unwrappingKey` argument of {@link unwrapKey}.
123
+ * The private-side counterpart of {@link WrappingKeyFor} — symmetric branches
124
+ * are identical; asymmetric branches use the `_Private` variants.
125
+ */
126
+ type UnwrappingKeyFor<A extends KeyManagementAlgorithm> = A extends JWK_RSA_ENC ? CryptoKey | JWK_RSA_Private<A> : A extends JWK_ECDH_ES ? CryptoKey | JWK_EC_Private<A> | JWK_OKP_Private<A> : A extends JWK_PBES2 ? string | Uint8Array<ArrayBuffer> | JWK_oct<A> : A extends JWK_AES_KW ? CryptoKey | JWK_oct<A> : A extends JWK_AES_GCM_KW ? CryptoKey | JWK_oct<A | `A${"128" | "192" | "256"}GCM`> : A extends "dir" ? CryptoKey | JWK_oct | Uint8Array<ArrayBuffer> : never;
120
127
  /** Options for the wrapKey function. */
121
128
  interface WrapKeyOptions {
122
129
  /** Initialization Vector for AES-GCMKW. Generated if not provided. */
@@ -211,8 +218,15 @@ interface UnwrapKeyOptions {
211
218
  * Copyright (c) 2018 Filip Skokan.
212
219
  * LICENSE: https://github.com/panva/jose/blob/v6.0.10/LICENSE.md
213
220
  */
214
- /** Generic JSON Web Key Parameters. */
215
- interface JWKParameters {
221
+ /**
222
+ * Generic JSON Web Key Parameters.
223
+ *
224
+ * The `Alg` type parameter constrains the JWK's `alg` field. Each concrete JWK
225
+ * interface below tightens `Alg` to the algorithm family admissible for that key
226
+ * type — e.g. a `JWK_oct<JWK_HMAC>` can only hold `"HS256" | "HS384" | "HS512"`
227
+ * in `alg`.
228
+ */
229
+ interface JWKParameters<Alg extends string = string> {
216
230
  /** JWK "kty" (Key Type) Parameter */
217
231
  kty: string;
218
232
  /**
@@ -220,7 +234,7 @@ interface JWKParameters {
220
234
  *
221
235
  * @see {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}
222
236
  */
223
- alg?: string;
237
+ alg?: Alg;
224
238
  /** JWK "key_ops" (Key Operations) Parameter */
225
239
  key_ops?: KeyUsage[];
226
240
  /** JWK "ext" (Extractable) Parameter */
@@ -245,7 +259,7 @@ interface JWKParameters {
245
259
  enc?: ContentEncryptionAlgorithm;
246
260
  }
247
261
  /** Public EC JSON Web Keys */
248
- interface JWK_EC_Public extends JWKParameters {
262
+ interface JWK_EC_Public<Alg extends JWK_ECDSA | JWK_ECDH_ES | (string & {}) = string> extends JWKParameters<Alg> {
249
263
  /** EC JWK "kty" (Key Type) Parameter */
250
264
  kty: "EC";
251
265
  /** EC JWK "crv" (Curve) Parameter */
@@ -256,14 +270,14 @@ interface JWK_EC_Public extends JWKParameters {
256
270
  y: string;
257
271
  }
258
272
  /** Private EC JSON Web Keys */
259
- interface JWK_EC_Private extends JWK_EC_Public {
273
+ interface JWK_EC_Private<Alg extends JWK_ECDSA | JWK_ECDH_ES | (string & {}) = string> extends JWK_EC_Public<Alg> {
260
274
  /** EC JWK "d" (ECC Private Key) Parameter */
261
275
  d: string;
262
276
  }
263
277
  /** EC JSON Web Keys */
264
- type JWK_EC = JWK_EC_Public | JWK_EC_Private;
278
+ type JWK_EC<Alg extends JWK_ECDSA | JWK_ECDH_ES | (string & {}) = string> = JWK_EC_Public<Alg> | JWK_EC_Private<Alg>;
265
279
  /** Public RSA JSON Web Keys */
266
- interface JWK_RSA_Public extends JWKParameters {
280
+ interface JWK_RSA_Public<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC | (string & {}) = string> extends JWKParameters<Alg> {
267
281
  /** RSA JWK "kty" (Key Type) Parameter */
268
282
  kty: "RSA";
269
283
  /** RSA JWK "e" (Exponent) Parameter */
@@ -273,7 +287,7 @@ interface JWK_RSA_Public extends JWKParameters {
273
287
  oth?: RsaOtherPrimesInfo[];
274
288
  }
275
289
  /** Private RSA JSON Web Keys */
276
- interface JWK_RSA_Private extends JWK_RSA_Public {
290
+ interface JWK_RSA_Private<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC | (string & {}) = string> extends JWK_RSA_Public<Alg> {
277
291
  /** RSA JWK "d" (Private Exponent) Parameter */
278
292
  d: string;
279
293
  /** RSA JWK "dp" (First Factor CRT Exponent) Parameter */
@@ -288,9 +302,9 @@ interface JWK_RSA_Private extends JWK_RSA_Public {
288
302
  qi: string;
289
303
  }
290
304
  /** RSA JSON Web Keys */
291
- type JWK_RSA = JWK_RSA_Public | JWK_RSA_Private;
305
+ type JWK_RSA<Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC | (string & {}) = string> = JWK_RSA_Public<Alg> | JWK_RSA_Private<Alg>;
292
306
  /** Public ED JSON Web Keys */
293
- interface JWK_OKP_Public extends JWKParameters {
307
+ interface JWK_OKP_Public<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES | (string & {}) = string> extends JWKParameters<Alg> {
294
308
  /** ED JWK "kty" (Key Type) Parameter */
295
309
  kty: "OKP";
296
310
  /** ED JWK "crv" (Curve) Parameter */
@@ -299,48 +313,78 @@ interface JWK_OKP_Public extends JWKParameters {
299
313
  x: string;
300
314
  }
301
315
  /** Private ED JSON Web Keys */
302
- interface JWK_OKP_Private extends JWK_OKP_Public {
316
+ interface JWK_OKP_Private<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES | (string & {}) = string> extends JWK_OKP_Public<Alg> {
303
317
  /** ED JWK "d" (Private Key) Parameter */
304
318
  d: string;
305
319
  }
306
320
  /** OKP JSON Web Keys */
307
- type JWK_OKP = JWK_OKP_Public | JWK_OKP_Private;
321
+ type JWK_OKP<Alg extends JWK_OKP_SIGN | JWK_ECDH_ES | (string & {}) = string> = JWK_OKP_Public<Alg> | JWK_OKP_Private<Alg>;
308
322
  /** oct JSON Web Keys */
309
- interface JWK_oct extends JWKParameters {
323
+ interface JWK_oct<Alg extends JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir" | (string & {}) = string> extends JWKParameters<Alg> {
310
324
  /** Oct JWK "k" (Key Value) Parameter */
311
325
  k: string;
312
326
  }
313
327
  /** Symmetric JSON Web Keys */
314
- type JWK_Symmetric = JWK_oct;
328
+ type JWK_Symmetric<Alg extends JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir" | (string & {}) = string> = JWK_oct<Alg>;
315
329
  /** Asymmetric JSON Web Keys */
316
- type JWK_Asymmetric = JWK_RSA | JWK_EC | JWK_OKP;
330
+ type JWK_Asymmetric<Alg extends string = string> = JWK_RSA<Alg> | JWK_EC<Alg> | JWK_OKP<Alg>;
317
331
  /** Public JSON Web Keys */
318
- type JWK_Public = JWK_RSA_Public | JWK_EC_Public | JWK_OKP_Public;
332
+ type JWK_Public<Alg extends string = string> = JWK_RSA_Public<Alg> | JWK_EC_Public<Alg> | JWK_OKP_Public<Alg>;
319
333
  /** Private JSON Web Keys */
320
- type JWK_Private = JWK_RSA_Private | JWK_EC_Private | JWK_OKP_Private;
334
+ type JWK_Private<Alg extends string = string> = JWK_RSA_Private<Alg> | JWK_EC_Private<Alg> | JWK_OKP_Private<Alg>;
321
335
  /**
322
336
  * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP" and "oct" key types are supported.
323
337
  */
324
- type JWK = JWK_oct | JWK_RSA | JWK_EC | JWK_OKP;
338
+ type JWK<Alg extends string = string> = JWK_oct<Alg> | JWK_RSA<Alg> | JWK_EC<Alg> | JWK_OKP<Alg>;
325
339
  /**
326
- * A pair of public and private JSON Web Keys.
340
+ * A pair of public and private JSON Web Keys, narrowed by `Alg` when that
341
+ * uniquely identifies the key family:
342
+ *
343
+ * - `JWK_Pair<"RS256">` → RSA pair only
344
+ * - `JWK_Pair<"ES256">` → EC pair only
345
+ * - `JWK_Pair<"ECDH-ES+A256KW">` → EC pair **or** OKP pair (curve decides at runtime)
346
+ * - `JWK_Pair<"Ed25519">` / `JWK_Pair<"EdDSA">` → OKP pair only
347
+ *
348
+ * The final branch is a generic fallback (`Alg = string`, or any custom /
349
+ * forward-compat algorithm that doesn't match a known family) — it yields
350
+ * the permissive three-branch union.
327
351
  */
328
- type JWK_Pair = {
329
- publicKey: JWK_RSA_Public;
330
- privateKey: JWK_RSA_Private;
352
+ type JWK_Pair<Alg extends string = string> = Alg extends JWK_RSA_SIGN | JWK_RSA_PSS | JWK_RSA_ENC ? {
353
+ publicKey: JWK_RSA_Public<Alg>;
354
+ privateKey: JWK_RSA_Private<Alg>;
355
+ } : Alg extends JWK_ECDSA ? {
356
+ publicKey: JWK_EC_Public<Alg>;
357
+ privateKey: JWK_EC_Private<Alg>;
358
+ } : Alg extends JWK_ECDH_ES ? {
359
+ publicKey: JWK_EC_Public<Alg>;
360
+ privateKey: JWK_EC_Private<Alg>;
331
361
  } | {
332
- publicKey: JWK_EC_Public;
333
- privateKey: JWK_EC_Private;
362
+ publicKey: JWK_OKP_Public<Alg>;
363
+ privateKey: JWK_OKP_Private<Alg>;
364
+ } : Alg extends JWK_OKP_SIGN ? {
365
+ publicKey: JWK_OKP_Public<Alg>;
366
+ privateKey: JWK_OKP_Private<Alg>;
367
+ } : {
368
+ publicKey: JWK_RSA_Public<Alg>;
369
+ privateKey: JWK_RSA_Private<Alg>;
370
+ } | {
371
+ publicKey: JWK_EC_Public<Alg>;
372
+ privateKey: JWK_EC_Private<Alg>;
334
373
  } | {
335
- publicKey: JWK_OKP_Public;
336
- privateKey: JWK_OKP_Private;
374
+ publicKey: JWK_OKP_Public<Alg>;
375
+ privateKey: JWK_OKP_Private<Alg>;
337
376
  };
338
377
  /**
339
378
  * JSON Web Key Set ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK Set}). "RSA", "EC" and "oct" key types are supported.
379
+ *
380
+ * The optional `T` generic preserves the precise key tuple when constructed
381
+ * in TS — e.g. `JWKSet<[JWK_oct<"HS256">, JWK_EC_Public<"ES256">]>` — while the
382
+ * default `JWK[]` keeps the permissive behavior expected for JWKS fetched from
383
+ * external sources (runtime trials each candidate).
340
384
  */
341
- interface JWKSet {
385
+ interface JWKSet<T extends readonly JWK[] = JWK[]> {
342
386
  /** JWK Set "keys" Parameter */
343
- keys: JWK[];
387
+ keys: T;
344
388
  [parameter: string]: unknown;
345
389
  }
346
390
  /** JWK Key Algorithms */
@@ -512,6 +556,32 @@ declare function isJWTError(error: unknown): error is JWTError;
512
556
  type StrictOmit<T, K extends keyof T | (string & {}) | (number & {}) | (symbol & {})> = { [P in keyof T as P extends K ? never : P]: T[P] };
513
557
  /** JWS Signing Algorithm Identifier. */
514
558
  type JWSAlgorithm = JWK_HMAC | JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_OKP_SIGN;
559
+ /**
560
+ * Asymmetric private JWKs admissible as a signing key. RSA keys carry a
561
+ * signing `alg` (RS* or PS*); EC keys carry an ECDSA alg; OKP keys carry an Ed
562
+ * signing alg.
563
+ */
564
+ type JWSAsymmetricPrivateJWK = JWK_RSA_Private<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Private<JWK_ECDSA> | JWK_OKP_Private<JWK_OKP_SIGN>;
565
+ /**
566
+ * Asymmetric public JWKs admissible as a verification key. RSA keys carry a
567
+ * signing `alg` (RS* or PS*); EC keys carry an ECDSA alg; OKP keys carry an Ed
568
+ * signing alg.
569
+ */
570
+ type JWSAsymmetricPublicJWK = JWK_RSA_Public<JWK_RSA_SIGN | JWK_RSA_PSS> | JWK_EC_Public<JWK_ECDSA> | JWK_OKP_Public<JWK_OKP_SIGN>;
571
+ /**
572
+ * JWKs admissible as the `key` argument of {@link sign}. HMAC oct keys carry a
573
+ * {@link JWK_HMAC} alg; asymmetric private keys carry their family's signing alg.
574
+ * A JWK whose `alg` points at a non-signing family (e.g. `"RSA-OAEP"`) is
575
+ * rejected at the type level.
576
+ */
577
+ type JWSSignJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPrivateJWK;
578
+ /**
579
+ * JWKs admissible as a `key` for {@link verify}. HMAC oct keys carry a
580
+ * {@link JWK_HMAC} alg; asymmetric public keys carry their family's signing alg.
581
+ * A JWK whose `alg` points at a non-signing family (e.g. `"RSA-OAEP"`) is
582
+ * rejected at the type level.
583
+ */
584
+ type JWSVerifyJWK = JWK_oct<JWK_HMAC> | JWSAsymmetricPublicJWK;
515
585
  /** Recognized JWS Header Parameters, any other Header Members may also be present. */
516
586
  interface JWSHeaderParameters extends JoseHeaderParameters {
517
587
  /** JWS "alg" (Algorithm) Header Parameter */
@@ -635,7 +705,7 @@ type JWSGeneralSignature = Pick<JWSFlattenedSerialization, "protected" | "header
635
705
  */
636
706
  interface JWSMultiSigner {
637
707
  /** Signing key (JWK-first; `alg` inferred from `key.alg`). */
638
- key: JWK;
708
+ key: JWSSignJWK;
639
709
  /**
640
710
  * Extra per-signer JWS Protected Header parameters (RFC 7515 §7.2.1).
641
711
  * `alg` is always derived from the JWK and cannot be set here. `b64`
@@ -710,6 +780,33 @@ type JWSMultiVerifyOutcome<T extends JOSEPayload = JOSEPayload> = {
710
780
  protectedHeader?: JWSProtectedHeader;
711
781
  signerHeader?: JWSHeaderParameters;
712
782
  };
783
+ /**
784
+ * Algorithms admissible on an `oct` JWK used for JWE key management. Mirrors
785
+ * the runtime aliasing table in `jweAlgsFromOctJWK` — HMAC algs intentionally
786
+ * excluded (they don't resolve to any JWE `alg`).
787
+ */
788
+ type _JWEOctAlg = JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW | JWK_AES_CBC_HMAC | JWK_PBES2 | "dir";
789
+ /**
790
+ * Asymmetric public JWKs admissible for JWE encryption. RSA keys carry an
791
+ * RSA-OAEP alg; EC/OKP keys carry an ECDH-ES alg.
792
+ */
793
+ type JWEAsymmetricPublicJWK = JWK_RSA_Public<JWK_RSA_ENC> | JWK_EC_Public<JWK_ECDH_ES> | JWK_OKP_Public<JWK_ECDH_ES>;
794
+ /**
795
+ * Asymmetric private JWKs admissible for JWE decryption. RSA keys carry an
796
+ * RSA-OAEP alg; EC/OKP keys carry an ECDH-ES alg.
797
+ */
798
+ type JWEAsymmetricPrivateJWK = JWK_RSA_Private<JWK_RSA_ENC> | JWK_EC_Private<JWK_ECDH_ES> | JWK_OKP_Private<JWK_ECDH_ES>;
799
+ /**
800
+ * JWKs admissible as the `key` argument of {@link encrypt}. A JWK whose `alg`
801
+ * points at a non-JWE family (e.g. `"HS256"`, `"RS256"`) is rejected at the
802
+ * type level.
803
+ */
804
+ type JWEEncryptJWK = JWK_oct<_JWEOctAlg> | JWEAsymmetricPublicJWK;
805
+ /**
806
+ * JWKs admissible as a `key` for {@link decrypt}. A JWK whose `alg` points at
807
+ * a non-JWE family (e.g. `"HS256"`, `"RS256"`) is rejected at the type level.
808
+ */
809
+ type JWEDecryptJWK = JWK_oct<_JWEOctAlg> | JWEAsymmetricPrivateJWK;
713
810
  /** Recognized JWE Header Parameters, any other Header Members may also be present. */
714
811
  interface JWEHeaderParameters extends JoseHeaderParameters {
715
812
  /**
@@ -946,7 +1043,7 @@ interface JWEGeneralRecipient {
946
1043
  */
947
1044
  interface JWEMultiRecipient {
948
1045
  /** Recipient key (JWK-first; `alg` inferred if absent from JWK). */
949
- key: JWK;
1046
+ key: JWEEncryptJWK;
950
1047
  /**
951
1048
  * Extra per-recipient JWE Unprotected Header parameters (RFC 7516 §7.2.1).
952
1049
  * Excludes fields the library writes automatically: `alg`, `enc`, `iv`,
@@ -1019,4 +1116,4 @@ type ExpiresIn = Duration;
1019
1116
  type NotBeforeIn = Duration;
1020
1117
  /** Duration for `maxTokenAge` validation on {@link verify} / {@link decrypt}. */
1021
1118
  type MaxTokenAge = Duration;
1022
- export { JWKAlgorithm as $, JWSSignOptions as A, JWK_RSA_Public as At, JWTClaimValidationOptions as B, JWSMultiSignOptions as C, JWK_Pair as Ct, JWSMultiVerifyOutcome as D, JWK_RSA_ENC as Dt, JWSMultiVerifyOptions as E, JWK_RSA as Et, JWTErrorCauseMap as F, KeyManagementAlgorithm as Ft, DeriveKeyOptions as G, JoseHeaderParameters as H, JWTErrorCode as I, UnwrapKeyOptions as It, GenerateJWKReturn as J, DeriveKeyReturn as K, isJWTError as L, WrapKeyOptions as Lt, JWSVerifyResult as M, JWK_Symmetric as Mt, StrictOmit as N, JWK_Symmetric_Algorithm as Nt, JWSMultiVerifyResult as O, JWK_RSA_PSS as Ot, JWTError as P, JWK_oct as Pt, JWK as Q, JOSEPayload as R, WrapKeyResult as Rt, JWSHeaderParameters as S, JWK_PBES2 as St, JWSMultiVerifyAllOptions as T, JWK_Public as Tt, CompositeKey as U, JWTClaims as V, ContentEncryptionAlgorithm as W, GenerateKeyOptions as X, GenerateKeyAlgorithm as Y, GenerateKeyReturn as Z, JWEProtectedHeader as _, JWK_HMAC as _t, JWEDecryptOptions as a, JWKSet as at, JWSGeneralSerialization as b, JWK_OKP_Public as bt, JWEFlattenedSerialization as c, JWK_AES_GCM_KW as ct, JWEHeaderParameters as d, JWK_Asymmetric_Algorithm as dt, JWKCacheAdapter as et, JWEKeyManagementHeaderParameters as f, JWK_EC as ft, JWEMultiRecipient as g, JWK_EC_Public as gt, JWEMultiEncryptOptions as h, JWK_EC_Private as ht, NotBeforeIn as i, JWKParameters as it, JWSVerifyOptions as j, JWK_RSA_SIGN as jt, JWSProtectedHeader as k, JWK_RSA_Private as kt, JWEGeneralRecipient as l, JWK_AES_KW as lt, JWEMultiDecryptResult as m, JWK_ECDSA as mt, ExpiresIn as n, JWKLookupFunctionHeader as nt, JWEDecryptResult as o, JWK_AES_CBC_HMAC as ot, JWEMultiDecryptOptions as p, JWK_ECDH_ES as pt, GenerateJWKOptions as q, MaxTokenAge as r, JWKPEMAlgorithm as rt, JWEEncryptOptions as s, JWK_AES_GCM as st, Duration as t, JWKLookupFunction as tt, JWEGeneralSerialization as u, JWK_Asymmetric as ut, JWSAlgorithm as v, JWK_OKP as vt, JWSMultiSigner as w, JWK_Private as wt, JWSGeneralSignature as x, JWK_OKP_SIGN as xt, JWSFlattenedSerialization as y, JWK_OKP_Private as yt, JWT as z };
1119
+ export { DeriveKeyOptions as $, JWSMultiSigner as A, JWK_PBES2 as At, JWSVerifyResult as B, JWK_Symmetric as Bt, JWSAsymmetricPrivateJWK as C, JWK_EC_Private as Ct, JWSGeneralSignature as D, JWK_OKP_Private as Dt, JWSGeneralSerialization as E, JWK_OKP as Et, JWSProtectedHeader as F, JWK_RSA_ENC as Ft, isJWTError as G, UnwrappingKeyFor as Gt, JWTError as H, JWK_oct as Ht, JWSSignJWK as I, JWK_RSA_PSS as It, JWTClaimValidationOptions as J, WrappingKeyFor as Jt, JOSEPayload as K, WrapKeyOptions as Kt, JWSSignOptions as L, JWK_RSA_Private as Lt, JWSMultiVerifyOptions as M, JWK_Private as Mt, JWSMultiVerifyOutcome as N, JWK_Public as Nt, JWSHeaderParameters as O, JWK_OKP_Public as Ot, JWSMultiVerifyResult as P, JWK_RSA as Pt, ContentEncryptionAlgorithm as Q, JWSVerifyJWK as R, JWK_RSA_Public as Rt, JWSAlgorithm as S, JWK_ECDSA as St, JWSFlattenedSerialization as T, JWK_HMAC as Tt, JWTErrorCauseMap as U, KeyManagementAlgorithm as Ut, StrictOmit as V, JWK_Symmetric_Algorithm as Vt, JWTErrorCode as W, UnwrapKeyOptions as Wt, JoseHeaderParameters as X, JWTClaims as Y, CompositeKey as Z, JWEMultiDecryptOptions as _, JWK_AES_KW as _t, JWEAsymmetricPrivateJWK as a, GenerateKeyReturn as at, JWEMultiRecipient as b, JWK_EC as bt, JWEDecryptOptions as c, JWKCacheAdapter as ct, JWEEncryptOptions as d, JWKPEMAlgorithm as dt, DeriveKeyReturn as et, JWEFlattenedSerialization as f, JWKParameters as ft, JWEKeyManagementHeaderParameters as g, JWK_AES_GCM_KW as gt, JWEHeaderParameters as h, JWK_AES_GCM as ht, NotBeforeIn as i, GenerateKeyOptions as it, JWSMultiVerifyAllOptions as j, JWK_Pair as jt, JWSMultiSignOptions as k, JWK_OKP_SIGN as kt, JWEDecryptResult as l, JWKLookupFunction as lt, JWEGeneralSerialization as m, JWK_AES_CBC_HMAC as mt, ExpiresIn as n, GenerateJWKReturn as nt, JWEAsymmetricPublicJWK as o, JWK as ot, JWEGeneralRecipient as p, JWKSet as pt, JWT as q, WrapKeyResult as qt, MaxTokenAge as r, GenerateKeyAlgorithm as rt, JWEDecryptJWK as s, JWKAlgorithm as st, Duration as t, GenerateJWKOptions as tt, JWEEncryptJWK as u, JWKLookupFunctionHeader as ut, JWEMultiDecryptResult as v, JWK_Asymmetric as vt, JWSAsymmetricPublicJWK as w, JWK_EC_Public as wt, JWEProtectedHeader as x, JWK_ECDH_ES as xt, JWEMultiEncryptOptions as y, JWK_Asymmetric_Algorithm as yt, JWSVerifyOptions as z, JWK_RSA_SIGN as zt };
@@ -1,4 +1,4 @@
1
- import { Ft as KeyManagementAlgorithm, Mt as JWK_Symmetric, Q as JWK, R as JOSEPayload, W as ContentEncryptionAlgorithm, a as JWEDecryptOptions, at as JWKSet, c as JWEFlattenedSerialization, g as JWEMultiRecipient, h as JWEMultiEncryptOptions, m as JWEMultiDecryptResult, o as JWEDecryptResult, p as JWEMultiDecryptOptions, s as JWEEncryptOptions, tt as JWKLookupFunction, u as JWEGeneralSerialization, wt as JWK_Private } from "./index.mjs";
1
+ import { K as JOSEPayload, Q as ContentEncryptionAlgorithm, Ut as KeyManagementAlgorithm, _ as JWEMultiDecryptOptions, b as JWEMultiRecipient, c as JWEDecryptOptions, d as JWEEncryptOptions, f as JWEFlattenedSerialization, l as JWEDecryptResult, lt as JWKLookupFunction, m as JWEGeneralSerialization, pt as JWKSet, s as JWEDecryptJWK, u as JWEEncryptJWK, v as JWEMultiDecryptResult, y as JWEMultiEncryptOptions } from "./index.mjs";
2
2
  /**
3
3
  * Encrypt a payload to multiple recipients using JWE General JSON Serialization
4
4
  * (RFC 7516 §7.2.1).
@@ -29,7 +29,7 @@ declare function encryptMulti(payload: JOSEPayload, recipients: JWEMultiRecipien
29
29
  *
30
30
  * For compact (string) tokens, use {@link decrypt}.
31
31
  */
32
- declare function decryptMulti<T extends JOSEPayload = JOSEPayload>(jwe: JWEGeneralSerialization | JWEFlattenedSerialization, keyOrLookup: CryptoKey | JWKSet | JWK_Private | JWK_Symmetric | string | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWEMultiDecryptOptions): Promise<JWEMultiDecryptResult<T>>;
32
+ declare function decryptMulti<T extends JOSEPayload = JOSEPayload>(jwe: JWEGeneralSerialization | JWEFlattenedSerialization, keyOrLookup: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWEMultiDecryptOptions): Promise<JWEMultiDecryptResult<T>>;
33
33
  /**
34
34
  * Convert a {@link JWEGeneralSerialization} with exactly one recipient into
35
35
  * the {@link JWEFlattenedSerialization} form (RFC 7516 §7.2.2). Throws
@@ -53,8 +53,10 @@ declare function generalToFlattened(jwe: JWEGeneralSerialization): JWEFlattenedS
53
53
  * @param options JWE encryption options, including `alg` (key management algorithm) and `enc` (content encryption algorithm).
54
54
  * @returns A Promise resolving to the JWE Compact Serialization string.
55
55
  */
56
- declare function encrypt(payload: JOSEPayload, key: JWK | string | Uint8Array<ArrayBuffer>, options?: JWEEncryptOptions): Promise<string>;
57
- declare function encrypt(payload: JOSEPayload, key: CryptoKey | JWK_Symmetric | Uint8Array<ArrayBuffer>, options: JWEEncryptOptions & {
56
+ declare function encrypt(payload: JOSEPayload, key: JWEEncryptJWK | string | Uint8Array<ArrayBuffer>, options?: JWEEncryptOptions): Promise<string>;
57
+ declare function encrypt(payload: JOSEPayload, key: CryptoKey | Extract<JWEEncryptJWK, {
58
+ kty: "oct";
59
+ }> | Uint8Array<ArrayBuffer>, options: JWEEncryptOptions & {
58
60
  alg: "dir";
59
61
  enc: ContentEncryptionAlgorithm;
60
62
  }): Promise<string>;
@@ -62,7 +64,7 @@ declare function encrypt(payload: JOSEPayload, key: CryptoKey, options: JWEEncry
62
64
  alg: KeyManagementAlgorithm;
63
65
  enc: ContentEncryptionAlgorithm;
64
66
  }): Promise<string>;
65
- declare function encrypt(payload: JOSEPayload, key: CryptoKey | JWK | string | Uint8Array<ArrayBuffer>, options: JWEEncryptOptions & {
67
+ declare function encrypt(payload: JOSEPayload, key: CryptoKey | JWEEncryptJWK | string | Uint8Array<ArrayBuffer>, options: JWEEncryptOptions & {
66
68
  alg: KeyManagementAlgorithm;
67
69
  enc: ContentEncryptionAlgorithm;
68
70
  }): Promise<string>;
@@ -75,8 +77,8 @@ declare function encrypt(payload: JOSEPayload, key: CryptoKey | JWK | string | U
75
77
  * @returns A Promise resolving to an object containing the decrypted plaintext, protected header, CEK, and AAD.
76
78
  * @throws If JWE is invalid, decryption fails, or options are not met.
77
79
  */
78
- declare function decrypt<T extends JOSEPayload>(jwe: string, key: CryptoKey | JWKSet | JWK_Private | JWK_Symmetric | string | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
79
- declare function decrypt(jwe: string, key: CryptoKey | JWKSet | JWK_Private | JWK_Symmetric | string | Uint8Array<ArrayBuffer> | JWKLookupFunction, options: JWEDecryptOptions & {
80
+ declare function decrypt<T extends JOSEPayload>(jwe: string, key: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWEDecryptOptions): Promise<JWEDecryptResult<T>>;
81
+ declare function decrypt(jwe: string, key: CryptoKey | JWKSet | JWEDecryptJWK | string | Uint8Array<ArrayBuffer> | JWKLookupFunction, options: JWEDecryptOptions & {
80
82
  forceUint8Array: true;
81
83
  }): Promise<JWEDecryptResult<Uint8Array<ArrayBuffer>>>;
82
84
  export { generalToFlattened as a, encryptMulti as i, encrypt as n, decryptMulti as r, decrypt as t };
@@ -1,4 +1,4 @@
1
- import { A as JWSSignOptions, C as JWSMultiSignOptions, D as JWSMultiVerifyOutcome, E as JWSMultiVerifyOptions, M as JWSVerifyResult, Mt as JWK_Symmetric, O as JWSMultiVerifyResult, R as JOSEPayload, T as JWSMultiVerifyAllOptions, Tt as JWK_Public, at as JWKSet, b as JWSGeneralSerialization, j as JWSVerifyOptions, tt as JWKLookupFunction, v as JWSAlgorithm, w as JWSMultiSigner, wt as JWK_Private, y as JWSFlattenedSerialization } from "./index.mjs";
1
+ import { A as JWSMultiSigner, B as JWSVerifyResult, E as JWSGeneralSerialization, I as JWSSignJWK, K as JOSEPayload, L as JWSSignOptions, M as JWSMultiVerifyOptions, N as JWSMultiVerifyOutcome, P as JWSMultiVerifyResult, R as JWSVerifyJWK, S as JWSAlgorithm, T as JWSFlattenedSerialization, j as JWSMultiVerifyAllOptions, k as JWSMultiSignOptions, lt as JWKLookupFunction, pt as JWKSet, z as JWSVerifyOptions } from "./index.mjs";
2
2
  /**
3
3
  * Sign a payload with multiple signers using JWS General JSON Serialization
4
4
  * (RFC 7515 §7.2.1).
@@ -30,7 +30,7 @@ declare function signMulti(payload: JOSEPayload, signers: JWSMultiSigner[], opti
30
30
  *
31
31
  * For compact (string) tokens, use {@link verify}.
32
32
  */
33
- declare function verifyMulti<T extends JOSEPayload = JOSEPayload>(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyOrLookup: CryptoKey | JWKSet | JWK_Public | JWK_Symmetric | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSMultiVerifyOptions): Promise<JWSMultiVerifyResult<T>>;
33
+ declare function verifyMulti<T extends JOSEPayload = JOSEPayload>(jws: JWSGeneralSerialization | JWSFlattenedSerialization, keyOrLookup: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSMultiVerifyOptions): Promise<JWSMultiVerifyResult<T>>;
34
34
  /**
35
35
  * Verify every signature in a JWS independently and return a per-signature
36
36
  * outcome array — the caller applies their own policy (all-must-verify,
@@ -91,7 +91,7 @@ declare function generalToFlattenedJWS(jws: JWSGeneralSerialization): JWSFlatten
91
91
  * @param options Signing options, including the algorithm (`alg`) and protected header parameters.
92
92
  * @returns A Promise resolving to the JWS Compact Serialization string.
93
93
  */
94
- declare function sign(payload: JOSEPayload, key: JWK_Symmetric | JWK_Private, options?: JWSSignOptions): Promise<string>;
94
+ declare function sign(payload: JOSEPayload, key: JWSSignJWK, options?: JWSSignOptions): Promise<string>;
95
95
  declare function sign(payload: JOSEPayload, key: CryptoKey | Uint8Array<ArrayBuffer>, options: JWSSignOptions & {
96
96
  alg: JWSAlgorithm;
97
97
  }): Promise<string>;
@@ -104,8 +104,8 @@ declare function sign(payload: JOSEPayload, key: CryptoKey | Uint8Array<ArrayBuf
104
104
  * @returns A Promise resolving to an object containing the verified payload and protected header.
105
105
  * @throws If the JWS is invalid, signature verification fails, or options are not met.
106
106
  */
107
- declare function verify<T extends JOSEPayload>(jws: string, key: CryptoKey | JWKSet | JWK_Public | JWK_Symmetric | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
108
- declare function verify(jws: string, key: CryptoKey | JWKSet | JWK_Public | JWK_Symmetric | Uint8Array<ArrayBuffer> | JWKLookupFunction, options: JWSVerifyOptions & {
107
+ declare function verify<T extends JOSEPayload>(jws: string, key: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options?: JWSVerifyOptions): Promise<JWSVerifyResult<T>>;
108
+ declare function verify(jws: string, key: CryptoKey | JWKSet | JWSVerifyJWK | Uint8Array<ArrayBuffer> | JWKLookupFunction, options: JWSVerifyOptions & {
109
109
  forceUint8Array: true;
110
110
  }): Promise<JWSVerifyResult<Uint8Array<ArrayBuffer>>>;
111
111
  export { verifyMulti as a, signMulti as i, verify as n, verifyMultiAll as o, generalToFlattenedJWS as r, sign as t };
@@ -61,22 +61,22 @@ declare function sanitizeObjectCopy<T extends Record<string, unknown> | undefine
61
61
  * Base64 encoding. Accepts `string` or raw bytes; throws `TypeError` on
62
62
  * `null`/`undefined`. Empty strings and empty `Uint8Array` return `""`.
63
63
  */
64
- declare function base64Encode(data: Uint8Array<ArrayBuffer> | string): string;
64
+ declare function base64Encode(data: Uint8Array | string): string;
65
65
  /**
66
66
  * Base64 URL-safe encoding (no padding). Accepts `string` or raw bytes;
67
67
  * throws `TypeError` on `null`/`undefined`. Empty inputs return `""`.
68
68
  */
69
- declare function base64UrlEncode(data: Uint8Array<ArrayBuffer> | string): string;
70
- declare function base64Decode<T extends DecodeReturnAs>(data: string | Uint8Array<ArrayBuffer>, options: {
69
+ declare function base64UrlEncode(data: Uint8Array | string): string;
70
+ declare function base64Decode<T extends DecodeReturnAs>(data: string | Uint8Array, options: {
71
71
  returnAs: T;
72
72
  }): T extends "string" ? string : Uint8Array<ArrayBuffer>;
73
73
  declare function base64Decode(data: string): string;
74
- declare function base64Decode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
75
- declare function base64UrlDecode<T extends DecodeReturnAs>(data: string | Uint8Array<ArrayBuffer>, options: {
74
+ declare function base64Decode(data: Uint8Array): Uint8Array<ArrayBuffer>;
75
+ declare function base64UrlDecode<T extends DecodeReturnAs>(data: string | Uint8Array, options: {
76
76
  returnAs: T;
77
77
  }): T extends "string" ? string : Uint8Array<ArrayBuffer>;
78
78
  declare function base64UrlDecode(data: string): string;
79
- declare function base64UrlDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
79
+ declare function base64UrlDecode(data: Uint8Array): Uint8Array<ArrayBuffer>;
80
80
  /**
81
81
  * Hex encoding. Accepts `string` or raw bytes; throws `TypeError` on
82
82
  * `null`/`undefined`. Empty strings and empty `Uint8Array` return `""`.
@@ -82,19 +82,24 @@ const _b64UrlEncOpts = /* @__PURE__ */ Object.freeze({
82
82
  omitPadding: true
83
83
  });
84
84
  const _b64UrlDecOpts = /* @__PURE__ */ Object.freeze({ alphabet: "base64url" });
85
+ function _bytesToBase64Fallback(bytes) {
86
+ let binary = "";
87
+ for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
88
+ return btoa(binary);
89
+ }
85
90
  function base64Encode(data) {
86
91
  if (data == null) throw new TypeError("base64Encode: data must be a string or Uint8Array.");
87
92
  if (_hasBuffer) return _toBuffer(data).toString("base64");
88
93
  const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
89
94
  if (_hasToBase64) return encodedData.toBase64();
90
- return btoa(String.fromCodePoint(...encodedData));
95
+ return _bytesToBase64Fallback(encodedData);
91
96
  }
92
97
  function base64UrlEncode(data) {
93
98
  if (data == null) throw new TypeError("base64UrlEncode: data must be a string or Uint8Array.");
94
99
  if (_hasBuffer) return _toBuffer(data).toString("base64url");
95
100
  const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
96
101
  if (_hasToBase64) return encodedData.toBase64(_b64UrlEncOpts);
97
- return btoa(String.fromCodePoint(...encodedData)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
102
+ return _bytesToBase64Fallback(encodedData).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
98
103
  }
99
104
  function base64Decode(data, options) {
100
105
  if (data == null) throw new TypeError("base64Decode: data must be a string or Uint8Array.");
@@ -104,7 +109,7 @@ function base64Decode(data, options) {
104
109
  if (!str) return decodeToString ? "" : new Uint8Array(0);
105
110
  if (_hasBuffer) {
106
111
  const buf = _Buffer.from(str, "base64");
107
- return decodeToString ? buf.toString("utf8") : new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
112
+ return decodeToString ? buf.toString("utf8") : new Uint8Array(buf);
108
113
  }
109
114
  const decoded = _hasFromBase64 ? Uint8Array.fromBase64(str) : Uint8Array.from(atob(str), (b) => b.codePointAt(0));
110
115
  return decodeToString ? textDecoder.decode(decoded) : decoded;
@@ -117,7 +122,7 @@ function base64UrlDecode(data, options) {
117
122
  if (!str) return decodeToString ? "" : new Uint8Array(0);
118
123
  if (_hasBuffer) {
119
124
  const buf = _Buffer.from(str, "base64url");
120
- return decodeToString ? buf.toString("utf8") : new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
125
+ return decodeToString ? buf.toString("utf8") : new Uint8Array(buf);
121
126
  }
122
127
  let decoded;
123
128
  if (_hasFromBase64) decoded = Uint8Array.fromBase64(str, _b64UrlDecOpts);
@@ -1,4 +1,4 @@
1
- import { $ as JWKAlgorithm, A as JWSSignOptions, At as JWK_RSA_Public, B as JWTClaimValidationOptions, C as JWSMultiSignOptions, Ct as JWK_Pair, D as JWSMultiVerifyOutcome, Dt as JWK_RSA_ENC, E as JWSMultiVerifyOptions, Et as JWK_RSA, Ft as KeyManagementAlgorithm, G as DeriveKeyOptions, H as JoseHeaderParameters, It as UnwrapKeyOptions, J as GenerateJWKReturn, K as DeriveKeyReturn, Lt as WrapKeyOptions, M as JWSVerifyResult, Mt as JWK_Symmetric, N as StrictOmit, Nt as JWK_Symmetric_Algorithm, O as JWSMultiVerifyResult, Ot as JWK_RSA_PSS, Pt as JWK_oct, Q as JWK, R as JOSEPayload, Rt as WrapKeyResult, S as JWSHeaderParameters, St as JWK_PBES2, T as JWSMultiVerifyAllOptions, Tt as JWK_Public, U as CompositeKey, V as JWTClaims, W as ContentEncryptionAlgorithm, X as GenerateKeyOptions, Y as GenerateKeyAlgorithm, Z as GenerateKeyReturn, _ as JWEProtectedHeader, _t as JWK_HMAC, a as JWEDecryptOptions, at as JWKSet, b as JWSGeneralSerialization, bt as JWK_OKP_Public, c as JWEFlattenedSerialization, ct as JWK_AES_GCM_KW, d as JWEHeaderParameters, dt as JWK_Asymmetric_Algorithm, et as JWKCacheAdapter, f as JWEKeyManagementHeaderParameters, ft as JWK_EC, g as JWEMultiRecipient, gt as JWK_EC_Public, h as JWEMultiEncryptOptions, ht as JWK_EC_Private, i as NotBeforeIn, it as JWKParameters, j as JWSVerifyOptions, jt as JWK_RSA_SIGN, k as JWSProtectedHeader, kt as JWK_RSA_Private, l as JWEGeneralRecipient, lt as JWK_AES_KW, m as JWEMultiDecryptResult, mt as JWK_ECDSA, n as ExpiresIn, nt as JWKLookupFunctionHeader, o as JWEDecryptResult, ot as JWK_AES_CBC_HMAC, p as JWEMultiDecryptOptions, pt as JWK_ECDH_ES, q as GenerateJWKOptions, r as MaxTokenAge, rt as JWKPEMAlgorithm, s as JWEEncryptOptions, st as JWK_AES_GCM, t as Duration, tt as JWKLookupFunction, u as JWEGeneralSerialization, ut as JWK_Asymmetric, v as JWSAlgorithm, vt as JWK_OKP, w as JWSMultiSigner, wt as JWK_Private, x as JWSGeneralSignature, xt as JWK_OKP_SIGN, y as JWSFlattenedSerialization, yt as JWK_OKP_Private, z as JWT } from "../../_chunks/index.mjs";
1
+ import { $ as DeriveKeyOptions, A as JWSMultiSigner, At as JWK_PBES2, B as JWSVerifyResult, Bt as JWK_Symmetric, C as JWSAsymmetricPrivateJWK, Ct as JWK_EC_Private, D as JWSGeneralSignature, Dt as JWK_OKP_Private, E as JWSGeneralSerialization, Et as JWK_OKP, F as JWSProtectedHeader, Ft as JWK_RSA_ENC, Gt as UnwrappingKeyFor, Ht as JWK_oct, I as JWSSignJWK, It as JWK_RSA_PSS, J as JWTClaimValidationOptions, Jt as WrappingKeyFor, K as JOSEPayload, Kt as WrapKeyOptions, L as JWSSignOptions, Lt as JWK_RSA_Private, M as JWSMultiVerifyOptions, Mt as JWK_Private, N as JWSMultiVerifyOutcome, Nt as JWK_Public, O as JWSHeaderParameters, Ot as JWK_OKP_Public, P as JWSMultiVerifyResult, Pt as JWK_RSA, Q as ContentEncryptionAlgorithm, R as JWSVerifyJWK, Rt as JWK_RSA_Public, S as JWSAlgorithm, St as JWK_ECDSA, T as JWSFlattenedSerialization, Tt as JWK_HMAC, Ut as KeyManagementAlgorithm, V as StrictOmit, Vt as JWK_Symmetric_Algorithm, Wt as UnwrapKeyOptions, X as JoseHeaderParameters, Y as JWTClaims, Z as CompositeKey, _ as JWEMultiDecryptOptions, _t as JWK_AES_KW, a as JWEAsymmetricPrivateJWK, at as GenerateKeyReturn, b as JWEMultiRecipient, bt as JWK_EC, c as JWEDecryptOptions, ct as JWKCacheAdapter, d as JWEEncryptOptions, dt as JWKPEMAlgorithm, et as DeriveKeyReturn, f as JWEFlattenedSerialization, ft as JWKParameters, g as JWEKeyManagementHeaderParameters, gt as JWK_AES_GCM_KW, h as JWEHeaderParameters, ht as JWK_AES_GCM, i as NotBeforeIn, it as GenerateKeyOptions, j as JWSMultiVerifyAllOptions, jt as JWK_Pair, k as JWSMultiSignOptions, kt as JWK_OKP_SIGN, l as JWEDecryptResult, lt as JWKLookupFunction, m as JWEGeneralSerialization, mt as JWK_AES_CBC_HMAC, n as ExpiresIn, nt as GenerateJWKReturn, o as JWEAsymmetricPublicJWK, ot as JWK, p as JWEGeneralRecipient, pt as JWKSet, q as JWT, qt as WrapKeyResult, r as MaxTokenAge, rt as GenerateKeyAlgorithm, s as JWEDecryptJWK, st as JWKAlgorithm, t as Duration, tt as GenerateJWKOptions, u as JWEEncryptJWK, ut as JWKLookupFunctionHeader, v as JWEMultiDecryptResult, vt as JWK_Asymmetric, w as JWSAsymmetricPublicJWK, wt as JWK_EC_Public, x as JWEProtectedHeader, xt as JWK_ECDH_ES, y as JWEMultiEncryptOptions, yt as JWK_Asymmetric_Algorithm, z as JWSVerifyOptions, zt as JWK_RSA_SIGN } from "../../_chunks/index.mjs";
2
2
  import { deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, importFromPEM, importPEM } from "../../core/jwk.mjs";
3
3
  import { H3Event } from "h3";
4
4
  import { CookieSerializeOptions } from "cookie-es";
@@ -80,13 +80,13 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
80
80
  header: JWEHeaderParameters;
81
81
  event: TEvent;
82
82
  config: SessionConfigJWE<T, MaxAge, TEvent>;
83
- }) => JWK_Symmetric | JWK_Private | Promise<JWK_Symmetric | JWK_Private>;
83
+ }) => JWEDecryptJWK | Promise<JWEDecryptJWK>;
84
84
  }
85
85
  interface SessionConfigJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends CompatEvent$1 | H3Event = CompatEvent$1 | H3Event> {
86
86
  /** Shared key used, string for PBES2 or Json Web Key (JWK) */
87
- key: string | JWK_Symmetric | JWK_Private | {
88
- privateKey: JWK_Private | JWK_Symmetric;
89
- publicKey?: JWK_Public;
87
+ key: string | JWEEncryptJWK | {
88
+ privateKey: JWEAsymmetricPrivateJWK;
89
+ publicKey?: JWEAsymmetricPublicJWK;
90
90
  };
91
91
  /** Session lifetime in seconds (used to derive exp from iat) */
92
92
  maxAge?: MaxAge;
@@ -208,15 +208,15 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
208
208
  header: JWKLookupFunctionHeader;
209
209
  event: TEvent;
210
210
  config: SessionConfigJWS<T, MaxAge, TEvent>;
211
- }) => JWKSet | JWK_Symmetric | JWK_Public | Promise<JWKSet | JWK_Symmetric | JWK_Public>;
211
+ }) => JWKSet | JWSVerifyJWK | Promise<JWKSet | JWSVerifyJWK>;
212
212
  }
213
213
  interface SessionConfigJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends CompatEvent | H3Event = CompatEvent | H3Event> {
214
214
  /**
215
215
  * JWK (private for signing with RS/ES/PS, or symmetric oct) used for signing.
216
216
  */
217
- key: JWK_Symmetric | {
218
- privateKey: JWK_Private;
219
- publicKey: JWK_Public | JWK_Public[] | JWKSet;
217
+ key: JWK_oct<JWK_HMAC> | {
218
+ privateKey: JWSAsymmetricPrivateJWK;
219
+ publicKey: JWSAsymmetricPublicJWK | JWSAsymmetricPublicJWK[] | JWKSet;
220
220
  };
221
221
  /** Session lifetime in seconds (sets exp = iat + maxAge) */
222
222
  maxAge?: MaxAge;
@@ -279,4 +279,4 @@ declare function verifyJWSSession<T extends Record<string, any> = SessionClaims,
279
279
  * Destroy the session (context + cookie).
280
280
  */
281
281
  declare function clearJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends CompatEvent | H3Event = CompatEvent | H3Event>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<void>;
282
- export { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, Duration, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, JOSEPayload, JWEDecryptOptions, JWEDecryptResult, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHeaderParameters, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignOptions, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JoseHeaderParameters, KeyManagementAlgorithm, MaxTokenAge, NotBeforeIn, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionData, type SessionHooksJWE, type SessionHooksJWS, type SessionJWE, type SessionJWS, type SessionManager, type SessionUpdate, UnwrapKeyOptions, WrapKeyOptions, WrapKeyResult, clearJWESession, clearJWSSession, deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, importFromPEM, importPEM, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
282
+ export { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, Duration, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, JOSEPayload, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_CBC_HMAC, JWK_AES_GCM, JWK_AES_GCM_KW, JWK_AES_KW, JWK_Asymmetric, JWK_Asymmetric_Algorithm, JWK_EC, JWK_ECDH_ES, JWK_ECDSA, JWK_EC_Private, JWK_EC_Public, JWK_HMAC, JWK_OKP, JWK_OKP_Private, JWK_OKP_Public, JWK_OKP_SIGN, JWK_PBES2, JWK_Pair, JWK_Private, JWK_Public, JWK_RSA, JWK_RSA_ENC, JWK_RSA_PSS, JWK_RSA_Private, JWK_RSA_Public, JWK_RSA_SIGN, JWK_Symmetric, JWK_Symmetric_Algorithm, JWK_oct, JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHeaderParameters, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JoseHeaderParameters, KeyManagementAlgorithm, MaxTokenAge, NotBeforeIn, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionData, type SessionHooksJWE, type SessionHooksJWS, type SessionJWE, type SessionJWS, type SessionManager, type SessionUpdate, UnwrapKeyOptions, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, clearJWESession, clearJWSSession, deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, importFromPEM, importPEM, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
@@ -307,8 +307,8 @@ function getEncryptKey(key) {
307
307
  if (!key) throw new Error("Session: JWE key is required.");
308
308
  let _key;
309
309
  if (typeof key === "string") _key = key;
310
- else if (isSymmetricJWK(key) || isPrivateJWK(key)) _key = key;
311
- else if ("publicKey" in key && isPublicJWK(key.publicKey)) _key = key.publicKey;
310
+ else if (isSymmetricJWK(key)) _key = key;
311
+ else if ("publicKey" in key && key.publicKey && isPublicJWK(key.publicKey)) _key = key.publicKey;
312
312
  else if ("privateKey" in key && isPrivateJWK(key.privateKey)) _key = key.privateKey;
313
313
  if (!_key) throw new Error("Session: Invalid JWE key. It must be a password string or valid JWK.", { cause: key });
314
314
  return _key;