unjwt 0.5.32 → 0.5.33

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.
@@ -1,12 +1,12 @@
1
- import { b as JWEEncryptOptions } from '../shared/unjwt.BU3IrsCv.mjs';
2
- export { d as JWEDecryptOptions, e as JWEDecryptResult, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.BU3IrsCv.mjs';
3
- import { X as JWTClaims, E as ExpiresIn, r as JWK_Symmetric, u as JWK_Private, t as JWK_Public, Z as JWTClaimValidationOptions, w as JWKSet } from '../shared/unjwt.CtHrClHc.mjs';
4
- export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.CtHrClHc.mjs';
1
+ import { b as JWEEncryptOptions, J as JWEHeaderParameters } from '../shared/unjwt.CMNtw8ek.mjs';
2
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.CMNtw8ek.mjs';
3
+ import { X as JWTClaims, E as ExpiresIn, r as JWK_Symmetric, u as JWK_Private, t as JWK_Public, Z as JWTClaimValidationOptions, w as JWKSet } from '../shared/unjwt.BCi3FEWr.mjs';
4
+ export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.BCi3FEWr.mjs';
5
5
  import { S as StrictOmit } from '../shared/unjwt.JdKqVANs.mjs';
6
6
  import { CookieSerializeOptions } from 'cookie-es';
7
7
  import { H3Event } from 'h3';
8
- import { c as JWSSignOptions } from '../shared/unjwt.BsLgL0DQ.mjs';
9
- export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BjP_dGnX.mjs';
8
+ import { c as JWSSignOptions, b as JWSProtectedHeader } from '../shared/unjwt.BqdNUKDr.mjs';
9
+ export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BYDTEWa-.mjs';
10
10
 
11
11
  interface SessionClaims extends Required<Pick<JWTClaims, "jti" | "iat">>, StrictOmit<JWTClaims, "jti" | "iat"> {
12
12
  }
@@ -61,6 +61,11 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
61
61
  error: any;
62
62
  config: SessionConfigJWE<T, MaxAge>;
63
63
  }) => void | Promise<void>;
64
+ onUnsealKeyLookup?: (args: {
65
+ header: JWEHeaderParameters;
66
+ event: H3Event;
67
+ config: SessionConfigJWE<T, MaxAge>;
68
+ }) => JWK_Symmetric | JWK_Private | Promise<JWK_Symmetric | JWK_Private>;
64
69
  }
65
70
  interface SessionConfigJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
66
71
  /** @deprecated use `key` instead */
@@ -130,7 +135,7 @@ declare function sealJWESession<T extends Record<string, any> = SessionClaims, M
130
135
  /**
131
136
  * Decrypt the JWE and return a Session-compatible object.
132
137
  */
133
- declare function unsealJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(_event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
138
+ declare function unsealJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
134
139
  /**
135
140
  * Clear the session (delete from context and drop cookie).
136
141
  */
@@ -175,6 +180,11 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
175
180
  error: any;
176
181
  config: SessionConfigJWS<T, MaxAge>;
177
182
  }) => void | Promise<void>;
183
+ onVerifyKeyLookup?: (args: {
184
+ header: JWSProtectedHeader;
185
+ event: H3Event;
186
+ config: SessionConfigJWS<T, MaxAge>;
187
+ }) => JWKSet | JWK_Symmetric | JWK_Public | Promise<JWKSet | JWK_Symmetric | JWK_Public>;
178
188
  }
179
189
  interface SessionConfigJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
180
190
  /**
@@ -241,11 +251,11 @@ declare function signJWSSession<T extends Record<string, any> = SessionClaims, M
241
251
  * - ensures jti & iat presence
242
252
  * - enforces maxAge if provided
243
253
  */
244
- declare function verifyJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(_event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
254
+ declare function verifyJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
245
255
  /**
246
256
  * Destroy the session (context + cookie).
247
257
  */
248
258
  declare function clearJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
249
259
 
250
- export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
260
+ export { JWEEncryptOptions, JWEHeaderParameters, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
251
261
  export type { SessionClaims, SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate };
@@ -1,9 +1,9 @@
1
- export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.DyouTtLD.mjs';
1
+ export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.Dpl__ZAR.mjs';
2
2
  import { isEvent, setCookie } from 'h3';
3
3
  import { parse } from 'cookie-es';
4
- import { e as encrypt, d as decrypt } from '../shared/unjwt.KqQq9jpF.mjs';
4
+ import { e as encrypt, d as decrypt } from '../shared/unjwt.B-v62plj.mjs';
5
5
  import { p as computeExpiresInSeconds, q as isSymmetricJWK, u as isPrivateJWK, w as isPublicJWK } from '../shared/unjwt.Be8NxwFK.mjs';
6
- import { s as sign, v as verify } from '../shared/unjwt.DQVUT7FU.mjs';
6
+ import { s as sign, v as verify } from '../shared/unjwt.DdLN9vwI.mjs';
7
7
 
8
8
  /**
9
9
  * This is a fork of h3 library's session utility functions.
@@ -142,13 +142,7 @@ function getJWESessionToken(event, config) {
142
142
  token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
143
143
  }
144
144
  }
145
- if (!token) {
146
- const cookieHeader = _getReqHeader$1(event, "cookie");
147
- if (cookieHeader) {
148
- token = parse(String(cookieHeader))[sessionName];
149
- }
150
- }
151
- if (!token) {
145
+ if (config.cookie !== false) {
152
146
  const setCookie2 = _getResHeader$1(event, "set-cookie");
153
147
  if (typeof setCookie2 === "string") {
154
148
  token = findSetCookie$1(setCookie2, sessionName);
@@ -161,6 +155,12 @@ function getJWESessionToken(event, config) {
161
155
  }
162
156
  }
163
157
  }
158
+ if (!token) {
159
+ const cookieHeader = _getReqHeader$1(event, "cookie");
160
+ if (cookieHeader) {
161
+ token = parse(String(cookieHeader))[sessionName];
162
+ }
163
+ }
164
164
  return token;
165
165
  }
166
166
  function _getReqHeader$1(event, name) {
@@ -240,8 +240,12 @@ async function sealJWESession(event, config) {
240
240
  });
241
241
  return token;
242
242
  }
243
- async function unsealJWESession(_event, config, sealed) {
244
- const key = getDecryptKey(config.key || config.secret);
243
+ async function unsealJWESession(event, config, sealed) {
244
+ const key = config.hooks?.onUnsealKeyLookup ? (header) => config.hooks.onUnsealKeyLookup({
245
+ header,
246
+ event,
247
+ config
248
+ }) : getDecryptKey(config.key || config.secret);
245
249
  const alg = config.jwe?.encryptOptions?.alg;
246
250
  const enc = config.jwe?.encryptOptions?.enc;
247
251
  if (config.jwe?.encryptOptions?.protectedHeader?.typ && typeof config.jwe.encryptOptions.protectedHeader.typ === "string" && config.jwe.encryptOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
@@ -480,13 +484,7 @@ function getJWSSessionToken(event, config) {
480
484
  token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
481
485
  }
482
486
  }
483
- if (!token) {
484
- const cookieHeader = _getReqHeader(event, "cookie");
485
- if (cookieHeader) {
486
- token = parse(String(cookieHeader))[sessionName];
487
- }
488
- }
489
- if (!token) {
487
+ if (config.cookie !== false) {
490
488
  const setCookie2 = _getResHeader(event, "set-cookie");
491
489
  if (typeof setCookie2 === "string") {
492
490
  token = findSetCookie(setCookie2, sessionName);
@@ -499,6 +497,12 @@ function getJWSSessionToken(event, config) {
499
497
  }
500
498
  }
501
499
  }
500
+ if (!token) {
501
+ const cookieHeader = _getReqHeader(event, "cookie");
502
+ if (cookieHeader) {
503
+ token = parse(String(cookieHeader))[sessionName];
504
+ }
505
+ }
502
506
  return token;
503
507
  }
504
508
  function _getReqHeader(event, name) {
@@ -577,9 +581,13 @@ async function signJWSSession(event, config) {
577
581
  });
578
582
  return token;
579
583
  }
580
- async function verifyJWSSession(_event, config, token) {
584
+ async function verifyJWSSession(event, config, token) {
581
585
  const alg = config.jws?.signOptions?.alg;
582
- const jwk = getVerifyKey(config.key);
586
+ const jwk = config.hooks?.onVerifyKeyLookup ? (header) => config.hooks.onVerifyKeyLookup({
587
+ header,
588
+ event,
589
+ config
590
+ }) : getVerifyKey(config.key);
583
591
  let typ = void 0;
584
592
  if (config.jws?.signOptions?.protectedHeader?.typ && typeof config.jws.signOptions.protectedHeader.typ === "string" && config.jws.signOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
585
593
  typ = config.jws.signOptions.protectedHeader.typ;
@@ -1,8 +1,8 @@
1
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.BU3IrsCv.mjs';
2
- export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.CtHrClHc.mjs';
1
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.CMNtw8ek.mjs';
2
+ export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.BCi3FEWr.mjs';
3
3
  export { SessionClaims, SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
4
- export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BjP_dGnX.mjs';
4
+ export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BYDTEWa-.mjs';
5
5
  import '../shared/unjwt.JdKqVANs.mjs';
6
6
  import 'cookie-es';
7
7
  import 'h3';
8
- import '../shared/unjwt.BsLgL0DQ.mjs';
8
+ import '../shared/unjwt.BqdNUKDr.mjs';
@@ -1,7 +1,7 @@
1
- export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.DyouTtLD.mjs';
1
+ export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.Dpl__ZAR.mjs';
2
2
  export { clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
3
3
  import '../shared/unjwt.Be8NxwFK.mjs';
4
4
  import 'h3';
5
5
  import 'cookie-es';
6
- import '../shared/unjwt.KqQq9jpF.mjs';
7
- import '../shared/unjwt.DQVUT7FU.mjs';
6
+ import '../shared/unjwt.B-v62plj.mjs';
7
+ import '../shared/unjwt.DdLN9vwI.mjs';
@@ -1,12 +1,12 @@
1
- import { b as JWEEncryptOptions } from '../shared/unjwt.BU3IrsCv.mjs';
2
- export { d as JWEDecryptOptions, e as JWEDecryptResult, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.BU3IrsCv.mjs';
3
- import { X as JWTClaims, E as ExpiresIn, r as JWK_Symmetric, u as JWK_Private, t as JWK_Public, Z as JWTClaimValidationOptions, w as JWKSet } from '../shared/unjwt.CtHrClHc.mjs';
4
- export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.CtHrClHc.mjs';
1
+ import { b as JWEEncryptOptions, J as JWEHeaderParameters } from '../shared/unjwt.CMNtw8ek.mjs';
2
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.CMNtw8ek.mjs';
3
+ import { X as JWTClaims, E as ExpiresIn, r as JWK_Symmetric, u as JWK_Private, t as JWK_Public, Z as JWTClaimValidationOptions, w as JWKSet } from '../shared/unjwt.BCi3FEWr.mjs';
4
+ export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.BCi3FEWr.mjs';
5
5
  import { S as StrictOmit } from '../shared/unjwt.JdKqVANs.mjs';
6
6
  import { HTTPEvent } from 'h3';
7
7
  import { CookieSerializeOptions } from 'cookie-es';
8
- import { c as JWSSignOptions } from '../shared/unjwt.BsLgL0DQ.mjs';
9
- export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BjP_dGnX.mjs';
8
+ import { c as JWSSignOptions, b as JWSProtectedHeader } from '../shared/unjwt.BqdNUKDr.mjs';
9
+ export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BYDTEWa-.mjs';
10
10
 
11
11
  interface SessionClaims extends Required<Pick<JWTClaims, "jti" | "iat">>, StrictOmit<JWTClaims, "jti" | "iat"> {
12
12
  }
@@ -55,6 +55,11 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
55
55
  error: any;
56
56
  config: SessionConfigJWE<T, MaxAge>;
57
57
  }) => void | Promise<void>;
58
+ onUnsealKeyLookup?: (args: {
59
+ header: JWEHeaderParameters;
60
+ event: HTTPEvent;
61
+ config: SessionConfigJWE<T, MaxAge>;
62
+ }) => JWK_Symmetric | JWK_Private | Promise<JWK_Symmetric | JWK_Private>;
58
63
  }
59
64
  interface SessionConfigJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
60
65
  /** Shared secret used, string for PBES2 or Json Web Key (JWK) */
@@ -101,7 +106,7 @@ declare function sealJWESession<T extends Record<string, any> = SessionClaims, M
101
106
  /**
102
107
  * Decrypt the JWE and return a Session-compatible object.
103
108
  */
104
- declare function unsealJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(_event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
109
+ declare function unsealJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
105
110
  /**
106
111
  * Clear the session (delete from context and drop cookie).
107
112
  */
@@ -140,6 +145,11 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
140
145
  error: any;
141
146
  config: SessionConfigJWS<T, MaxAge>;
142
147
  }) => void | Promise<void>;
148
+ onVerifyKeyLookup?: (args: {
149
+ header: JWSProtectedHeader;
150
+ event: HTTPEvent;
151
+ config: SessionConfigJWS<T, MaxAge>;
152
+ }) => JWKSet | JWK_Symmetric | JWK_Public | Promise<JWKSet | JWK_Symmetric | JWK_Public>;
143
153
  }
144
154
  interface SessionConfigJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
145
155
  key: JWK_Symmetric | {
@@ -164,8 +174,8 @@ declare function getJWSSession<T extends Record<string, any> = SessionClaims, Ma
164
174
  declare function getJWSSessionToken<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): string | undefined;
165
175
  declare function updateJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWS<T, MaxAge>>;
166
176
  declare function signJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<string>;
167
- declare function verifyJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(_event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
177
+ declare function verifyJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
168
178
  declare function clearJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: HTTPEvent, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
169
179
 
170
- export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
180
+ export { JWEEncryptOptions, JWEHeaderParameters, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
171
181
  export type { SessionClaims, SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWS, SessionManager, SessionUpdate };
@@ -1,9 +1,9 @@
1
- export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.DyouTtLD.mjs';
1
+ export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.Dpl__ZAR.mjs';
2
2
  import { getEventContext, getChunkedCookie, setChunkedCookie } from 'h3';
3
3
  import { NullProtoObj } from 'rou3';
4
- import { e as encrypt, d as decrypt } from '../shared/unjwt.KqQq9jpF.mjs';
4
+ import { e as encrypt, d as decrypt } from '../shared/unjwt.B-v62plj.mjs';
5
5
  import { p as computeExpiresInSeconds, q as isSymmetricJWK, u as isPrivateJWK, w as isPublicJWK } from '../shared/unjwt.Be8NxwFK.mjs';
6
- import { s as sign, v as verify } from '../shared/unjwt.DQVUT7FU.mjs';
6
+ import { s as sign, v as verify } from '../shared/unjwt.DdLN9vwI.mjs';
7
7
 
8
8
  const kGetSessionPromise$1 = Symbol("h3_jwe_getSession");
9
9
  const DEFAULT_NAME$1 = "h3-jwe";
@@ -130,15 +130,15 @@ function getJWESessionToken(event, config) {
130
130
  token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
131
131
  }
132
132
  }
133
- if (!token) {
134
- token = getChunkedCookie(event, sessionName);
135
- }
136
- if (!token && hasWritableResponse$1(event)) {
133
+ if (config.cookie !== false && hasWritableResponse$1(event)) {
137
134
  const setCookie = event.res.headers.get("set-cookie");
138
135
  if (typeof setCookie === "string") {
139
136
  token = findSetCookie$1(setCookie, sessionName);
140
137
  }
141
138
  }
139
+ if (!token) {
140
+ token = getChunkedCookie(event, sessionName);
141
+ }
142
142
  return token;
143
143
  }
144
144
  async function updateJWESession(event, config, update) {
@@ -199,8 +199,12 @@ async function sealJWESession(event, config) {
199
199
  });
200
200
  return token;
201
201
  }
202
- async function unsealJWESession(_event, config, sealed) {
203
- const key = getDecryptKey(config.key);
202
+ async function unsealJWESession(event, config, sealed) {
203
+ const key = config.hooks?.onUnsealKeyLookup ? (header) => config.hooks.onUnsealKeyLookup({
204
+ header,
205
+ event,
206
+ config
207
+ }) : getDecryptKey(config.key);
204
208
  const alg = config.jwe?.encryptOptions?.alg;
205
209
  const enc = config.jwe?.encryptOptions?.enc;
206
210
  if (config.jwe?.encryptOptions?.protectedHeader?.typ && typeof config.jwe.encryptOptions.protectedHeader.typ === "string" && config.jwe.encryptOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
@@ -432,15 +436,15 @@ function getJWSSessionToken(event, config) {
432
436
  token = headerValue.startsWith("Bearer ") ? headerValue.slice(7).trim() : headerValue;
433
437
  }
434
438
  }
435
- if (!token) {
436
- token = getChunkedCookie(event, sessionName);
437
- }
438
- if (!token && hasWritableResponse(event)) {
439
+ if (config.cookie !== false && hasWritableResponse(event)) {
439
440
  const setCookie = event.res.headers.get("set-cookie");
440
441
  if (typeof setCookie === "string") {
441
442
  token = findSetCookie(setCookie, sessionName);
442
443
  }
443
444
  }
445
+ if (!token) {
446
+ token = getChunkedCookie(event, sessionName);
447
+ }
444
448
  return token;
445
449
  }
446
450
  async function updateJWSSession(event, config, update) {
@@ -502,9 +506,13 @@ async function signJWSSession(event, config) {
502
506
  });
503
507
  return token;
504
508
  }
505
- async function verifyJWSSession(_event, config, token) {
506
- const jwk = getVerifyKey(config.key);
509
+ async function verifyJWSSession(event, config, token) {
507
510
  const alg = config.jws?.signOptions?.alg;
511
+ const jwk = config.hooks?.onVerifyKeyLookup ? (header) => config.hooks.onVerifyKeyLookup({
512
+ header,
513
+ event,
514
+ config
515
+ }) : getVerifyKey(config.key);
508
516
  let typ;
509
517
  if (config.jws?.signOptions?.protectedHeader?.typ && typeof config.jws.signOptions.protectedHeader.typ === "string" && config.jws.signOptions.protectedHeader.typ.toLowerCase().includes("jwt")) {
510
518
  typ = config.jws.signOptions.protectedHeader.typ;
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, E as ExpiresIn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, M as MaxTokenAge, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.CtHrClHc.mjs';
2
- export { i as utils } from './shared/unjwt.CkkdXjZD.mjs';
3
- export { j as jwe } from './shared/unjwt.B9nv94SS.mjs';
4
- export { j as jwk } from './shared/unjwt.BjP_dGnX.mjs';
5
- export { j as jws } from './shared/unjwt.C5jNR_1K.mjs';
6
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult } from './shared/unjwt.BsLgL0DQ.mjs';
7
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from './shared/unjwt.BU3IrsCv.mjs';
1
+ export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, E as ExpiresIn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, M as MaxTokenAge, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.BCi3FEWr.mjs';
2
+ export { i as utils } from './shared/unjwt.Cy2MlkUe.mjs';
3
+ export { j as jwe } from './shared/unjwt.4JQCoID_.mjs';
4
+ export { j as jwk } from './shared/unjwt.BYDTEWa-.mjs';
5
+ export { j as jws } from './shared/unjwt.D0_ccT7g.mjs';
6
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult } from './shared/unjwt.BqdNUKDr.mjs';
7
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from './shared/unjwt.CMNtw8ek.mjs';
8
8
  import './shared/unjwt.JdKqVANs.mjs';
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  export { i as utils } from './shared/unjwt.Be8NxwFK.mjs';
2
- export { j as jwe } from './shared/unjwt.KqQq9jpF.mjs';
3
- export { j as jwk } from './shared/unjwt.DyouTtLD.mjs';
4
- export { j as jws } from './shared/unjwt.DQVUT7FU.mjs';
2
+ export { j as jwe } from './shared/unjwt.B-v62plj.mjs';
3
+ export { j as jwk } from './shared/unjwt.Dpl__ZAR.mjs';
4
+ export { j as jws } from './shared/unjwt.DdLN9vwI.mjs';
package/dist/jwe.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.CtHrClHc.mjs';
2
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from './shared/unjwt.BU3IrsCv.mjs';
3
- export { d as decrypt, e as encrypt } from './shared/unjwt.B9nv94SS.mjs';
1
+ export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.BCi3FEWr.mjs';
2
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from './shared/unjwt.CMNtw8ek.mjs';
3
+ export { d as decrypt, e as encrypt } from './shared/unjwt.4JQCoID_.mjs';
4
4
  import './shared/unjwt.JdKqVANs.mjs';
package/dist/jwe.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import './shared/unjwt.DyouTtLD.mjs';
1
+ import './shared/unjwt.Dpl__ZAR.mjs';
2
2
  import './shared/unjwt.Be8NxwFK.mjs';
3
- export { d as decrypt, e as encrypt } from './shared/unjwt.KqQq9jpF.mjs';
3
+ export { d as decrypt, e as encrypt } from './shared/unjwt.B-v62plj.mjs';
package/dist/jwk.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.CtHrClHc.mjs';
2
- export { d as deriveJWKFromPassword, b as deriveKeyFromPassword, e as exportJWKToPEM, f as exportKey, g as generateJWK, a as generateKey, h as getJWKFromSet, i as importJWKFromPEM, c as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.BjP_dGnX.mjs';
1
+ export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.BCi3FEWr.mjs';
2
+ export { d as deriveJWKFromPassword, b as deriveKeyFromPassword, e as exportJWKToPEM, f as exportKey, g as generateJWK, a as generateKey, h as getJWKFromSet, i as importJWKFromPEM, c as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.BYDTEWa-.mjs';
package/dist/jwk.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  import './shared/unjwt.Be8NxwFK.mjs';
2
- export { k as deriveJWKFromPassword, m as deriveKeyFromPassword, h as exportJWKToPEM, n as exportKey, c as generateJWK, l as generateKey, b as getJWKFromSet, f as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.DyouTtLD.mjs';
2
+ export { k as deriveJWKFromPassword, m as deriveKeyFromPassword, h as exportJWKToPEM, n as exportKey, c as generateJWK, l as generateKey, b as getJWKFromSet, f as importJWKFromPEM, i as importKey, u as unwrapKey, w as wrapKey } from './shared/unjwt.Dpl__ZAR.mjs';
package/dist/jws.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.CtHrClHc.mjs';
2
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult } from './shared/unjwt.BsLgL0DQ.mjs';
3
- export { s as sign, v as verify } from './shared/unjwt.C5jNR_1K.mjs';
1
+ export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './shared/unjwt.BCi3FEWr.mjs';
2
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult } from './shared/unjwt.BqdNUKDr.mjs';
3
+ export { s as sign, v as verify } from './shared/unjwt.D0_ccT7g.mjs';
package/dist/jws.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import './shared/unjwt.DyouTtLD.mjs';
1
+ import './shared/unjwt.Dpl__ZAR.mjs';
2
2
  import './shared/unjwt.Be8NxwFK.mjs';
3
- export { s as sign, v as verify } from './shared/unjwt.DQVUT7FU.mjs';
3
+ export { s as sign, v as verify } from './shared/unjwt.DdLN9vwI.mjs';
@@ -1,5 +1,5 @@
1
- import { X as JWTClaims, v as JWK, K as KeyManagementAlgorithm, f as ContentEncryptionAlgorithm, r as JWK_Symmetric, u as JWK_Private, C as CompositeKey, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, V as JoseHeaderParameters, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './unjwt.CtHrClHc.mjs';
2
- import { b as JWEEncryptOptions, c as JWEKeyLookupFunction, d as JWEDecryptOptions, e as JWEDecryptResult, J as JWEHeaderParameters, a as JWEKeyManagementHeaderParameters } from './unjwt.BU3IrsCv.mjs';
1
+ import { X as JWTClaims, v as JWK, K as KeyManagementAlgorithm, f as ContentEncryptionAlgorithm, r as JWK_Symmetric, u as JWK_Private, C as CompositeKey, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, V as JoseHeaderParameters, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './unjwt.BCi3FEWr.mjs';
2
+ import { b as JWEEncryptOptions, c as JWEKeyLookupFunction, d as JWEDecryptOptions, e as JWEDecryptResult, J as JWEHeaderParameters, a as JWEKeyManagementHeaderParameters } from './unjwt.CMNtw8ek.mjs';
3
3
 
4
4
  /**
5
5
  * Encrypts a payload to produce a JWE Compact Serialization string.
@@ -1,4 +1,4 @@
1
- import { i as importKey, e as encryptKey, g as generateIV, a as encrypt$1, u as unwrapKey, d as decrypt$1 } from './unjwt.DyouTtLD.mjs';
1
+ import { i as importKey, e as encryptKey, g as generateIV, a as encrypt$1, u as unwrapKey, d as decrypt$1 } from './unjwt.Dpl__ZAR.mjs';
2
2
  import { r as randomBytes, a as isJWK, s as sanitizeObject, b as applyTypCtyDefaults, c as computeJwtTimeClaims, g as getPlaintextBytes, d as base64UrlEncode, t as textEncoder, e as base64UrlDecode, f as decodePayloadFromBytes, v as validateCriticalHeadersJWE, h as validateJwtClaims, j as isCryptoKeyPair, k as isCryptoKey } from './unjwt.Be8NxwFK.mjs';
3
3
 
4
4
  async function encrypt(payload, key, options = {}) {
@@ -16,7 +16,7 @@ async function encrypt(payload, key, options = {}) {
16
16
  if (typeof key === "string" || key instanceof Uint8Array) {
17
17
  alg = "PBES2-HS256+A128KW";
18
18
  } else if (isJWK(key)) {
19
- alg = key.alg;
19
+ alg = key.alg === "A128GCM" || key.alg === "A192GCM" || key.alg === "A256GCM" ? `${key.alg}KW` : key.alg;
20
20
  }
21
21
  }
22
22
  if (!alg) {
@@ -59,6 +59,8 @@ async function encrypt(payload, key, options = {}) {
59
59
  const jweProtectedHeader = sanitizeObject({
60
60
  ...baseProtectedHeader,
61
61
  ...keyManagementHeaderParams,
62
+ ...isJWK(key) && key.kid ? { kid: key.kid } : {},
63
+ // Include kid if available
62
64
  alg,
63
65
  enc
64
66
  });
@@ -236,13 +236,13 @@ type JWK_RSA_PSS = "PS256" | "PS384" | "PS512";
236
236
  type JWK_ECDSA = "ES256" | "ES384" | "ES512";
237
237
  type JWK_RSA_ENC = "RSA-OAEP" | "RSA-OAEP-256" | "RSA-OAEP-384" | "RSA-OAEP-512";
238
238
  type JWK_AES_KW = "A128KW" | "A192KW" | "A256KW";
239
- type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
240
239
  type JWK_AES_CBC_HMAC = "A128CBC-HS256" | "A192CBC-HS384" | "A256CBC-HS512";
241
240
  type JWK_AES_GCM = "A128GCM" | "A192GCM" | "A256GCM";
241
+ type JWK_AES_GCM_KW = "A128GCMKW" | "A192GCMKW" | "A256GCMKW";
242
242
  type JWK_PBES2 = "PBES2-HS256+A128KW" | "PBES2-HS384+A192KW" | "PBES2-HS512+A256KW";
243
243
  type JWK_ECDH_ES = "ECDH-ES" | "ECDH-ES+A128KW" | "ECDH-ES+A192KW" | "ECDH-ES+A256KW";
244
244
  type JWK_OKP_SIGN = "Ed25519" | "EdDSA";
245
- type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM;
245
+ type JWK_Symmetric_Algorithm = JWK_HMAC | JWK_AES_KW | JWK_AES_GCM | JWK_AES_GCM_KW;
246
246
  type JWK_Asymmetric_Algorithm = JWK_RSA_SIGN | JWK_RSA_PSS | JWK_ECDSA | JWK_RSA_ENC | JWK_OKP_SIGN | JWK_ECDH_ES;
247
247
  type JWKAlgorithm = JWK_Symmetric_Algorithm | JWK_Asymmetric_Algorithm | JWK_AES_CBC_HMAC | JWK_PBES2 | JWK_ECDH_ES | ("none" | "dir");
248
248
  type JWKPEMAlgorithm = JWK_RSA_PSS | JWK_RSA_SIGN | JWK_RSA_ENC | JWK_ECDSA | JWK_ECDH_ES | JWK_OKP_SIGN;
@@ -325,4 +325,4 @@ interface JWTClaimValidationOptions {
325
325
  type ExpiresIn = number | `${number}` | `${number}${"s" | "second" | "seconds" | "m" | "minute" | "minutes" | "h" | "hour" | "hours" | "D" | "day" | "days" | "W" | "week" | "weeks" | "M" | "month" | "months" | "Y" | "year" | "years"}`;
326
326
  type MaxTokenAge = ExpiresIn;
327
327
 
328
- export type { JWK_ECDSA as A, JWK_RSA_ENC as B, CompositeKey as C, DeriveKeyOptions as D, ExpiresIn as E, JWK_AES_KW as F, GenerateKeyAlgorithm as G, JWK_AES_GCM_KW as H, JWK_AES_CBC_HMAC as I, JWKParameters as J, KeyManagementAlgorithm as K, JWK_AES_GCM as L, MaxTokenAge as M, JWK_PBES2 as N, JWK_ECDH_ES as O, JWK_OKP_SIGN as P, JWK_Symmetric_Algorithm as Q, JWK_Asymmetric_Algorithm as R, JWKAlgorithm as S, JWKPEMAlgorithm as T, UnwrapKeyOptions as U, JoseHeaderParameters as V, WrapKeyOptions as W, JWTClaims as X, JWT as Y, JWTClaimValidationOptions as Z, GenerateKeyOptions as a, GenerateKeyReturn as b, GenerateJWKOptions as c, GenerateJWKReturn as d, DeriveKeyReturn as e, ContentEncryptionAlgorithm as f, WrapKeyResult as g, JWK_EC_Public as h, JWK_EC_Private as i, JWK_EC as j, JWK_RSA_Public as k, JWK_RSA_Private as l, JWK_RSA as m, JWK_OKP_Public as n, JWK_OKP_Private as o, JWK_OKP as p, JWK_oct as q, JWK_Symmetric as r, JWK_Asymmetric as s, JWK_Public as t, JWK_Private as u, JWK as v, JWKSet as w, JWK_HMAC as x, JWK_RSA_SIGN as y, JWK_RSA_PSS as z };
328
+ export type { JWK_ECDSA as A, JWK_RSA_ENC as B, CompositeKey as C, DeriveKeyOptions as D, ExpiresIn as E, JWK_AES_KW as F, GenerateKeyAlgorithm as G, JWK_AES_CBC_HMAC as H, JWK_AES_GCM as I, JWKParameters as J, KeyManagementAlgorithm as K, JWK_AES_GCM_KW as L, MaxTokenAge as M, JWK_PBES2 as N, JWK_ECDH_ES as O, JWK_OKP_SIGN as P, JWK_Symmetric_Algorithm as Q, JWK_Asymmetric_Algorithm as R, JWKAlgorithm as S, JWKPEMAlgorithm as T, UnwrapKeyOptions as U, JoseHeaderParameters as V, WrapKeyOptions as W, JWTClaims as X, JWT as Y, JWTClaimValidationOptions as Z, GenerateKeyOptions as a, GenerateKeyReturn as b, GenerateJWKOptions as c, GenerateJWKReturn as d, DeriveKeyReturn as e, ContentEncryptionAlgorithm as f, WrapKeyResult as g, JWK_EC_Public as h, JWK_EC_Private as i, JWK_EC as j, JWK_RSA_Public as k, JWK_RSA_Private as l, JWK_RSA as m, JWK_OKP_Public as n, JWK_OKP_Private as o, JWK_OKP as p, JWK_oct as q, JWK_Symmetric as r, JWK_Asymmetric as s, JWK_Public as t, JWK_Private as u, JWK as v, JWKSet as w, JWK_HMAC as x, JWK_RSA_SIGN as y, JWK_RSA_PSS as z };
@@ -1,4 +1,4 @@
1
- import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, J as JWKParameters, c as GenerateJWKOptions, d as GenerateJWKReturn, N as JWK_PBES2, D as DeriveKeyOptions, e as DeriveKeyReturn, q as JWK_oct, v as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, g as WrapKeyResult, U as UnwrapKeyOptions, T as JWKPEMAlgorithm, w as JWKSet, V as JoseHeaderParameters, C as CompositeKey, f as ContentEncryptionAlgorithm, S as JWKAlgorithm, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims } from './unjwt.CtHrClHc.mjs';
1
+ import { G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, J as JWKParameters, c as GenerateJWKOptions, d as GenerateJWKReturn, N as JWK_PBES2, D as DeriveKeyOptions, e as DeriveKeyReturn, q as JWK_oct, v as JWK, K as KeyManagementAlgorithm, W as WrapKeyOptions, g as WrapKeyResult, U as UnwrapKeyOptions, T as JWKPEMAlgorithm, w as JWKSet, V as JoseHeaderParameters, C as CompositeKey, f as ContentEncryptionAlgorithm, S as JWKAlgorithm, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims } from './unjwt.BCi3FEWr.mjs';
2
2
 
3
3
  /**
4
4
  * This is a fork of Jose library's utility functions.
@@ -1,4 +1,4 @@
1
- import { x as JWK_HMAC, y as JWK_RSA_SIGN, z as JWK_RSA_PSS, A as JWK_ECDSA, V as JoseHeaderParameters, E as ExpiresIn, v as JWK, w as JWKSet, Z as JWTClaimValidationOptions, X as JWTClaims } from './unjwt.CtHrClHc.mjs';
1
+ import { x as JWK_HMAC, y as JWK_RSA_SIGN, z as JWK_RSA_PSS, A as JWK_ECDSA, V as JoseHeaderParameters, E as ExpiresIn, v as JWK, w as JWKSet, Z as JWTClaimValidationOptions, X as JWTClaims } from './unjwt.BCi3FEWr.mjs';
2
2
 
3
3
  type JWS_SIGN_EXTRA = "Ed25519" | "EdDSA";
4
4
  /** JWS Signing Algorithm Identifier. */
@@ -1,4 +1,4 @@
1
- import { K as KeyManagementAlgorithm, f as ContentEncryptionAlgorithm, E as ExpiresIn, V as JoseHeaderParameters, h as JWK_EC_Public, i as JWK_EC_Private, v as JWK, Z as JWTClaimValidationOptions, X as JWTClaims } from './unjwt.CtHrClHc.mjs';
1
+ import { K as KeyManagementAlgorithm, f as ContentEncryptionAlgorithm, E as ExpiresIn, V as JoseHeaderParameters, h as JWK_EC_Public, i as JWK_EC_Private, v as JWK, Z as JWTClaimValidationOptions, X as JWTClaims } from './unjwt.BCi3FEWr.mjs';
2
2
  import { S as StrictOmit } from './unjwt.JdKqVANs.mjs';
3
3
 
4
4
  /** Recognized JWE Header Parameters, any other Header Members may also be present. */
@@ -1,4 +1,4 @@
1
- import { E as ExpiresIn, X as JWTClaims, Z as JWTClaimValidationOptions, v as JWK, w as JWKSet, q as JWK_oct, u as JWK_Private, t as JWK_Public } from './unjwt.CtHrClHc.mjs';
1
+ import { E as ExpiresIn, X as JWTClaims, Z as JWTClaimValidationOptions, v as JWK, w as JWKSet, q as JWK_oct, u as JWK_Private, t as JWK_Public } from './unjwt.BCi3FEWr.mjs';
2
2
  import { S as StrictOmit } from './unjwt.JdKqVANs.mjs';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
- import { X as JWTClaims, r as JWK_Symmetric, u as JWK_Private, t as JWK_Public, w as JWKSet, C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './unjwt.CtHrClHc.mjs';
2
- import { c as JWSSignOptions, J as JWSAlgorithm, f as JWSKeyLookupFunction, e as JWSVerifyOptions, d as JWSVerifyResult, a as JWSHeaderParameters, b as JWSProtectedHeader } from './unjwt.BsLgL0DQ.mjs';
1
+ import { X as JWTClaims, r as JWK_Symmetric, u as JWK_Private, t as JWK_Public, w as JWKSet, C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, H as JWK_AES_CBC_HMAC, I as JWK_AES_GCM, L as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from './unjwt.BCi3FEWr.mjs';
2
+ import { c as JWSSignOptions, J as JWSAlgorithm, f as JWSKeyLookupFunction, e as JWSVerifyOptions, d as JWSVerifyResult, a as JWSHeaderParameters, b as JWSProtectedHeader } from './unjwt.BqdNUKDr.mjs';
3
3
 
4
4
  /**
5
5
  * Creates a JWS (JSON Web Signature) in Compact Serialization format.
@@ -1,4 +1,4 @@
1
- import { i as importKey, s as sign$1, b as getJWKFromSet, v as verify$1 } from './unjwt.DyouTtLD.mjs';
1
+ import { i as importKey, s as sign$1, b as getJWKFromSet, v as verify$1 } from './unjwt.Dpl__ZAR.mjs';
2
2
  import { s as sanitizeObject, a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, l as textDecoder, e as base64UrlDecode, m as isJWKSet, n as decodePayloadFromB64UrlSegment, o as validateCriticalHeadersJWS, h as validateJwtClaims } from './unjwt.Be8NxwFK.mjs';
3
3
 
4
4
  async function sign(payload, key, options = {}) {
@@ -18,7 +18,7 @@ async function sign(payload, key, options = {}) {
18
18
  const signingKey = await importKey(key, alg);
19
19
  const protectedHeader = {
20
20
  ...safeAdditionalHeader,
21
- ...isJWK(key) && key.kid ? { kid: safeAdditionalHeader?.kid || key.kid } : {},
21
+ ...isJWK(key) && key.kid ? { kid: key.kid } : {},
22
22
  // Include kid if available
23
23
  alg,
24
24
  typ: safeAdditionalHeader?.typ
@@ -2010,10 +2010,14 @@ function getGenerateKeyParams(alg, options) {
2010
2010
  // AES GCM Encryption
2011
2011
  case "A128GCM":
2012
2012
  case "A192GCM":
2013
- case "A256GCM": {
2014
- const length = Number.parseInt(alg.slice(1, 4), 10);
2013
+ case "A256GCM":
2014
+ case "A128GCMKW":
2015
+ case "A192GCMKW":
2016
+ case "A256GCMKW": {
2017
+ const baseAlg = alg.replace("KW", "");
2018
+ const length = Number.parseInt(baseAlg.slice(1, 4), 10);
2015
2019
  algorithm = { name: "AES-GCM", length };
2016
- keyUsages = defaultKeyUsage ?? ["encrypt", "decrypt"];
2020
+ keyUsages = defaultKeyUsage ?? (alg.endsWith("KW") ? ["wrapKey", "unwrapKey"] : ["encrypt", "decrypt"]);
2017
2021
  break;
2018
2022
  }
2019
2023
  // ECDSA Signatures
package/dist/utils.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import './shared/unjwt.CtHrClHc.mjs';
1
+ import './shared/unjwt.BCi3FEWr.mjs';
2
2
  export { S as StrictOmit } from './shared/unjwt.JdKqVANs.mjs';
3
- export { s as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, z as computeExpiresInSeconds, B as computeJwtTimeClaims, A as computeMaxTokenAgeSeconds, f as concatUint8Arrays, v as decodeMaybeJWTString, x as decodePayloadFromB64UrlSegment, w as decodePayloadFromBytes, y as getPlaintextBytes, o as isAsymmetricJWK, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, u as isJWTContent, p as isPrivateJWK, q as isPublicJWK, n as isSymmetricJWK, m as maybeArray, r as randomBytes, F as sanitizeObject, a as textDecoder, t as textEncoder, E as validateCriticalHeadersJWE, D as validateCriticalHeadersJWS, C as validateJwtClaims } from './shared/unjwt.CkkdXjZD.mjs';
3
+ export { s as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, z as computeExpiresInSeconds, B as computeJwtTimeClaims, A as computeMaxTokenAgeSeconds, f as concatUint8Arrays, v as decodeMaybeJWTString, x as decodePayloadFromB64UrlSegment, w as decodePayloadFromBytes, y as getPlaintextBytes, o as isAsymmetricJWK, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, u as isJWTContent, p as isPrivateJWK, q as isPublicJWK, n as isSymmetricJWK, m as maybeArray, r as randomBytes, F as sanitizeObject, a as textDecoder, t as textEncoder, E as validateCriticalHeadersJWE, D as validateCriticalHeadersJWS, C as validateJwtClaims } from './shared/unjwt.Cy2MlkUe.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.5.32",
3
+ "version": "0.5.33",
4
4
  "description": "Low-level JWT utilities",
5
5
  "repository": "sandros94/unjwt",
6
6
  "license": "MIT",
@@ -65,7 +65,7 @@
65
65
  "devDependencies": {
66
66
  "@types/node": "^22",
67
67
  "@types/supertest": "^6.0.3",
68
- "@vitest/coverage-v8": "^3.2.4",
68
+ "@vitest/coverage-v8": "^4.0.14",
69
69
  "automd": "^0.4.2",
70
70
  "changelogen": "^0.6.2",
71
71
  "cookie-esv1": "npm:cookie-es@^1.2.2",
@@ -79,7 +79,7 @@
79
79
  "supertest": "^7.1.4",
80
80
  "typescript": "^5.9.2",
81
81
  "unbuild": "^3.6.1",
82
- "vitest": "^3.2.4"
82
+ "vitest": "^4.0.14"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "cookie-es": "^1.2.2 || ^2.0.0",