unjwt 0.7.1 → 0.7.3

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,4 +1,4 @@
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";
1
+ import { 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, StrictOmit, UnwrapKeyOptions, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
2
2
  import { deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, importFromPEM, importPEM } from "../../core/jwk.mjs";
3
3
  import { H3Event, HTTPEvent } from "h3";
4
4
  import { CookieSerializeOptions } from "cookie-es";
@@ -15,6 +15,10 @@ interface SessionManager<T extends Record<string, any> = SessionClaims, ConfigMa
15
15
  clear: () => Promise<SessionManager<T, ConfigMaxAge>>;
16
16
  }
17
17
  declare const kGetSessionPromise$1: unique symbol;
18
+ /**
19
+ * In-memory session state for the current request, mirroring the claims of
20
+ * the underlying compact JWE token.
21
+ */
18
22
  interface SessionJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
19
23
  /** Session ID — mirrors the JWT `jti` claim. `undefined` until the session is persisted. */
20
24
  id: string | undefined;
@@ -22,11 +26,23 @@ interface SessionJWE<T extends Record<string, any> = SessionClaims, MaxAge exten
22
26
  createdAt: number;
23
27
  /** Session expiry time in ms — mirrors the JWT `exp` claim (seconds). */
24
28
  expiresAt: MaxAge extends ExpiresIn ? number : T["exp"];
29
+ /** Session data — carried in the token payload, spread at the top level. */
25
30
  data: SessionData<T>;
31
+ /** The current compact JWE token. `undefined` until the session is persisted. */
26
32
  token: string | undefined;
27
33
  [kGetSessionPromise$1]?: Promise<SessionJWE<T, MaxAge>>;
28
34
  }
35
+ /**
36
+ * Lifecycle hooks for JWE sessions. `onRead`, `onExpire`, and `onError` are
37
+ * mutually exclusive per incoming token — `onRead` fires only when a session
38
+ * was successfully established from it.
39
+ */
29
40
  interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent | H3Event = HTTPEvent | H3Event> {
41
+ /**
42
+ * Fires when an incoming token was decrypted and the session established.
43
+ * May fire more than once per request when `useJWESession` is called
44
+ * concurrently in the same handler — dedupe via `session.id` if needed.
45
+ */
30
46
  onRead?: (args: {
31
47
  session: SessionJWE<T, MaxAge> & {
32
48
  id: string;
@@ -35,20 +51,23 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
35
51
  event: TEvent;
36
52
  config: SessionConfigJWE<T, MaxAge, TEvent>;
37
53
  }) => void | Promise<void>;
54
+ /** Fires after a new token was sealed — including pure token refreshes (update with no data). */
38
55
  onUpdate?: (args: {
39
- /** Session after it has been updated.. */session: SessionJWE<T, MaxAge> & {
56
+ /** Session after the update. */session: SessionJWE<T, MaxAge> & {
40
57
  id: string;
41
58
  token: string;
42
- }; /** Snapshot of the session before was updated. */
59
+ }; /** Deep-copied snapshot of the session before the update. */
43
60
  oldSession: SessionJWE<T, MaxAge>;
44
61
  event: TEvent;
45
62
  config: SessionConfigJWE<T, MaxAge, TEvent>;
46
63
  }) => void | Promise<void>;
64
+ /** Fires when the session is cleared. */
47
65
  onClear?: (args: {
48
- oldSession: SessionJWE<T, MaxAge> | undefined;
66
+ /** Last known session before clearing, if any. */oldSession: SessionJWE<T, MaxAge> | undefined;
49
67
  event: TEvent;
50
68
  config: SessionConfigJWE<T, MaxAge, TEvent>;
51
69
  }) => void | Promise<void>;
70
+ /** Fires when the incoming token is expired. Receives the expired token's decoded claims. */
52
71
  onExpire?: (args: {
53
72
  session: {
54
73
  id: string | undefined;
@@ -60,6 +79,7 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
60
79
  error: Error;
61
80
  config: SessionConfigJWE<T, MaxAge, TEvent>;
62
81
  }) => void | Promise<void>;
82
+ /** Fires on read-path failures other than expiry, and on write-path seal failures. */
63
83
  onError?: (args: {
64
84
  /**
65
85
  * The session involved in the error.
@@ -69,56 +89,82 @@ interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge
69
89
  error: any;
70
90
  config: SessionConfigJWE<T, MaxAge, TEvent>;
71
91
  }) => void | Promise<void>;
92
+ /** Resolve the decryption key for the incoming token from its protected header (e.g. by `kid`). */
72
93
  onUnsealKeyLookup?: (args: {
73
94
  header: JWEHeaderParameters;
74
95
  event: TEvent;
75
96
  config: SessionConfigJWE<T, MaxAge, TEvent>;
76
97
  }) => JWEDecryptJWK | Promise<JWEDecryptJWK>;
77
98
  }
99
+ /**
100
+ * Configuration for a JWE-backed (encrypted) session.
101
+ */
78
102
  interface SessionConfigJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent | H3Event = HTTPEvent | H3Event> {
79
- /** Shared secret used, string for PBES2 or Json Web Key (JWK) */
103
+ /**
104
+ * Secret used for sealing — a password string (PBES2), a symmetric JWK, or
105
+ * an asymmetric pair: the public key seals, the private key unseals.
106
+ */
80
107
  key: string | JWEEncryptJWK | {
81
108
  privateKey: JWEAsymmetricPrivateJWK;
82
109
  publicKey?: JWEAsymmetricPublicJWK;
83
110
  };
84
- /** Session lifetime in seconds (used to derive exp from iat) */
111
+ /**
112
+ * Session lifetime in seconds — sets `exp = iat + maxAge` in the token and
113
+ * drives the cookie expiry. Without it the library writes no `exp` — though
114
+ * an `exp` key in the session data is then carried into the token as its
115
+ * actual expiry claim.
116
+ */
85
117
  maxAge?: MaxAge;
86
- /** Default is "h3" */
118
+ /** Session name — drives the cookie name and the default session header. Default `"h3-jwe"`. */
87
119
  name?: string;
88
- /** Default is secure, httpOnly, path="/" */
120
+ /** Cookie options (`false` to disable). Defaults: `path="/"`, `secure`, `httpOnly: true`. */
89
121
  cookie?: false | (CookieSerializeOptions & {
90
122
  chunkMaxLength?: number;
91
123
  });
92
- /** Default is x-h3-session / x-{name}-session */
124
+ /** Request header to read the token from (`false` to disable). Default `x-<name>-session`. */
93
125
  sessionHeader?: false | string;
94
- /** Default is crypto.randomUUID */
126
+ /** Session ID (`jti`) generator. Default `crypto.randomUUID`. */
95
127
  generateId?: () => string;
96
- /** JWE configuration overrides */
128
+ /** JWE encrypt/decrypt overrides. Set `encryptOptions.alg` and `enc` to pin the session algorithms — unsealing then accepts only them. */
97
129
  jwe?: {
98
130
  encryptOptions?: Omit<JWEEncryptOptions, "expiresIn">;
99
131
  decryptOptions?: JWTClaimValidationOptions;
100
132
  };
133
+ /** Lifecycle hooks — see {@link SessionHooksJWE}. */
101
134
  hooks?: SessionHooksJWE<T, MaxAge, TEvent>;
102
135
  }
103
136
  /**
104
- * Create a session manager for the current request.
137
+ * Create a session manager for the current request using JWE (encrypted).
105
138
  */
106
139
  declare function useJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<SessionManager<T, MaxAge>>;
107
140
  /**
108
- * Get the session for the current request.
141
+ * Get (and lazily initialize) the session for the current request.
109
142
  */
110
143
  declare function getJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<SessionJWE<T, MaxAge>>;
144
+ /**
145
+ * Read the raw session token for the request. The session header (default
146
+ * `x-<name>-session`, `Bearer ` prefix stripped) takes precedence, then a
147
+ * freshly-minted token on the response's `Set-Cookie`, then the session cookie.
148
+ */
111
149
  declare function getJWESessionToken<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): string | undefined;
112
150
  /**
113
- * Update the session data for the current request.
151
+ * Update the session data (if provided) and reissue the JWE token.
114
152
  */
115
153
  declare function updateJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>, update?: SessionUpdate<T>): Promise<SessionJWE<T, MaxAge>>;
116
154
  /**
117
- * Produce a JWE for the current session.
155
+ * Seal the current session as a compact JWE.
156
+ * Payload: `session.data` spread at the top level, plus the reserved claims
157
+ * `jti`, `iat`, and `exp` (when `maxAge` is set), which overwrite any
158
+ * same-named keys in the session data.
118
159
  */
119
160
  declare function sealJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<string>;
120
161
  /**
121
- * Decrypt the JWE and return a Session-compatible object.
162
+ * Decrypt and parse a compact JWE into a Session structure.
163
+ * Performs:
164
+ * - authenticated decryption
165
+ * - claim validation (always on): `jti` & `iat` required, `exp` honoured
166
+ * - `typ` header check and alg/enc pinning when configured
167
+ * - `maxAge` enforced as `maxTokenAge` when provided
122
168
  */
123
169
  declare function unsealJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
124
170
  /**
@@ -126,6 +172,10 @@ declare function unsealJWESession<T extends Record<string, any> = SessionClaims,
126
172
  */
127
173
  declare function clearJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<void>;
128
174
  declare const kGetSessionPromise: unique symbol;
175
+ /**
176
+ * In-memory session state for the current request, mirroring the claims of
177
+ * the underlying compact JWS token.
178
+ */
129
179
  interface SessionJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
130
180
  /** Session ID — mirrors the JWT `jti` claim. `undefined` until the session is persisted. */
131
181
  id: string | undefined;
@@ -133,11 +183,23 @@ interface SessionJWS<T extends Record<string, any> = SessionClaims, MaxAge exten
133
183
  createdAt: number;
134
184
  /** Session expiry time in ms — mirrors the JWT `exp` claim (seconds). */
135
185
  expiresAt: MaxAge extends ExpiresIn ? number : T["exp"];
186
+ /** Session data — carried in the token payload, spread at the top level. */
136
187
  data: SessionData<T>;
188
+ /** The current compact JWS token. `undefined` until the session is persisted. */
137
189
  token: string | undefined;
138
190
  [kGetSessionPromise]?: Promise<SessionJWS<T, MaxAge>>;
139
191
  }
192
+ /**
193
+ * Lifecycle hooks for JWS sessions. `onRead`, `onExpire`, and `onError` are
194
+ * mutually exclusive per incoming token — `onRead` fires only when a session
195
+ * was successfully established from it.
196
+ */
140
197
  interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> {
198
+ /**
199
+ * Fires when an incoming token was verified and the session established.
200
+ * May fire more than once per request when `useJWSSession` is called
201
+ * concurrently in the same handler — dedupe via `session.id` if needed.
202
+ */
141
203
  onRead?: (args: {
142
204
  session: SessionJWS<T, MaxAge> & {
143
205
  id: string;
@@ -146,20 +208,23 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
146
208
  event: TEvent;
147
209
  config: SessionConfigJWS<T, MaxAge, TEvent>;
148
210
  }) => void | Promise<void>;
211
+ /** Fires after a new token was signed — including pure token refreshes (update with no data). */
149
212
  onUpdate?: (args: {
150
- /** Session after it has been updated.. */session: SessionJWS<T, MaxAge> & {
213
+ /** Session after the update. */session: SessionJWS<T, MaxAge> & {
151
214
  id: string;
152
215
  token: string;
153
- }; /** Snapshot of the session before was updated. */
216
+ }; /** Deep-copied snapshot of the session before the update. */
154
217
  oldSession: SessionJWS<T, MaxAge>;
155
218
  event: TEvent;
156
219
  config: SessionConfigJWS<T, MaxAge, TEvent>;
157
220
  }) => void | Promise<void>;
221
+ /** Fires when the session is cleared. */
158
222
  onClear?: (args: {
159
- oldSession: SessionJWS<T, MaxAge> | undefined;
223
+ /** Last known session before clearing, if any. */oldSession: SessionJWS<T, MaxAge> | undefined;
160
224
  event: TEvent;
161
225
  config: SessionConfigJWS<T, MaxAge, TEvent>;
162
226
  }) => void | Promise<void>;
227
+ /** Fires when the incoming token is expired. Receives the expired token's decoded claims. */
163
228
  onExpire?: (args: {
164
229
  session: {
165
230
  id: string | undefined;
@@ -171,6 +236,7 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
171
236
  error: Error;
172
237
  config: SessionConfigJWS<T, MaxAge, TEvent>;
173
238
  }) => void | Promise<void>;
239
+ /** Fires on read-path failures other than expiry, and on write-path sign failures. */
174
240
  onError?: (args: {
175
241
  /**
176
242
  * The session involved in the error.
@@ -180,34 +246,88 @@ interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge
180
246
  error: any;
181
247
  config: SessionConfigJWS<T, MaxAge, TEvent>;
182
248
  }) => void | Promise<void>;
249
+ /** Resolve the verification key(s) for the incoming token from its protected header (e.g. by `kid`). */
183
250
  onVerifyKeyLookup?: (args: {
184
251
  header: JWKLookupFunctionHeader;
185
252
  event: TEvent;
186
253
  config: SessionConfigJWS<T, MaxAge, TEvent>;
187
254
  }) => JWKSet | JWSVerifyJWK | Promise<JWKSet | JWSVerifyJWK>;
188
255
  }
256
+ /**
257
+ * Configuration for a JWS-backed (signed, not encrypted) session.
258
+ */
189
259
  interface SessionConfigJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> {
260
+ /**
261
+ * JWK used for signing — a symmetric `oct` (HS*) key, or an asymmetric pair:
262
+ * the private key signs, the public side verifies (single JWK, array, or
263
+ * JWKSet for rotation).
264
+ */
190
265
  key: JWK_oct<JWK_HMAC> | {
191
266
  privateKey: JWSAsymmetricPrivateJWK;
192
267
  publicKey: JWSAsymmetricPublicJWK | JWSAsymmetricPublicJWK[] | JWKSet;
193
268
  };
269
+ /**
270
+ * Session lifetime in seconds — sets `exp = iat + maxAge` in the token and
271
+ * drives the cookie expiry. Without it the library writes no `exp` — though
272
+ * an `exp` key in the session data is then carried into the token as its
273
+ * actual expiry claim.
274
+ */
194
275
  maxAge?: MaxAge;
276
+ /** Session name — drives the cookie name and the default session header. Default `"h3-jws"`. */
195
277
  name?: string;
278
+ /** Cookie options (`false` to disable). Defaults: `path="/"`, `secure`, `httpOnly: false` — the JWS payload is client-readable by design. */
196
279
  cookie?: false | (CookieSerializeOptions & {
197
280
  chunkMaxLength?: number;
198
281
  });
282
+ /** Request header to read the token from (`false` to disable). Default `x-<name>-session`. */
199
283
  sessionHeader?: false | string;
284
+ /** Session ID (`jti`) generator. Default `crypto.randomUUID`. */
200
285
  generateId?: () => string;
286
+ /** JWS sign/verify overrides. Set `signOptions.alg` to pin the session algorithm — verification then accepts only it. */
201
287
  jws?: {
202
288
  signOptions?: Omit<JWSSignOptions, "expiresIn">;
203
289
  verifyOptions?: JWTClaimValidationOptions;
204
290
  };
291
+ /** Lifecycle hooks — see {@link SessionHooksJWS}. */
205
292
  hooks?: SessionHooksJWS<T, MaxAge, TEvent>;
206
293
  }
294
+ /**
295
+ * Create a session manager for the current request using JWS (signed only, not encrypted).
296
+ * NOTE: Contents are visible to clients (Base64URL-decoded JSON). Do not store secrets in session data.
297
+ */
207
298
  declare function useJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<SessionManager<T, MaxAge>>;
299
+ /**
300
+ * Get (and lazily initialize) the session for the current request.
301
+ */
208
302
  declare function getJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<SessionJWS<T, MaxAge>>;
303
+ /**
304
+ * Read the raw session token for the request. The session header (default
305
+ * `x-<name>-session`, `Bearer ` prefix stripped) takes precedence, then a
306
+ * freshly-minted token on the response's `Set-Cookie`, then the session cookie.
307
+ */
308
+ declare function getJWSSessionToken<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): string | undefined;
309
+ /**
310
+ * Update the session data (if provided) and reissue the JWS token.
311
+ */
209
312
  declare function updateJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>, update?: SessionUpdate<T>): Promise<SessionJWS<T, MaxAge>>;
313
+ /**
314
+ * Sign the current session as a compact JWS.
315
+ * Payload: `session.data` spread at the top level, plus the reserved claims
316
+ * `jti`, `iat`, and `exp` (when `maxAge` is set), which overwrite any
317
+ * same-named keys in the session data.
318
+ */
210
319
  declare function signJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<string>;
320
+ /**
321
+ * Verify and parse a compact JWS into a Session structure.
322
+ * Performs:
323
+ * - cryptographic signature verification
324
+ * - claim validation (always on): `jti` & `iat` required, `exp` honoured
325
+ * - `typ` header check and algorithm pinning when configured
326
+ * - `maxAge` enforced as `maxTokenAge` when provided
327
+ */
211
328
  declare function verifyJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
329
+ /**
330
+ * Clear the session (delete from context and drop cookie).
331
+ */
212
332
  declare function clearJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<void>;
213
- 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 };
333
+ export { type CompositeKey, type ContentEncryptionAlgorithm, type DeriveKeyOptions, type DeriveKeyReturn, type Duration, type ExpiresIn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type JOSEPayload, type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyManagementHeaderParameters, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHeaderParameters, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, type JWT, type JWTClaimValidationOptions, type JWTClaims, type JoseHeaderParameters, type KeyManagementAlgorithm, type MaxTokenAge, type NotBeforeIn, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionData, type SessionHooksJWE, type SessionHooksJWS, type SessionJWE, type SessionJWS, type SessionManager, type SessionUpdate, type UnwrapKeyOptions, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, clearJWESession, clearJWSSession, deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, importFromPEM, importPEM, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
@@ -1,7 +1,8 @@
1
- import { D as JWTError, O as isJWTError, c as isPrivateJWK, l as isPublicJWK, p as computeDurationInSeconds, u as isSymmetricJWK } from "../../_chunks/utils.mjs";
2
- import { c as exportPEM, g as importPEM, i as deriveJWKFromPassword, l as exportToPEM, m as importFromPEM, u as generateJWK } from "../../_chunks/jwk.mjs";
3
- import { n as verify, t as sign } from "../../_chunks/jws.mjs";
4
- import { n as encrypt, t as decrypt } from "../../_chunks/jwe.mjs";
1
+ import { JWTError, computeDurationInSeconds, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK } from "../../_chunks/utils.mjs";
2
+ import { sanitizeObjectCopy } from "../../_chunks/libs/unsecure.mjs";
3
+ import { deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, importFromPEM, importPEM } from "../../_chunks/jwk.mjs";
4
+ import { sign, verify } from "../../_chunks/jws.mjs";
5
+ import { decrypt, encrypt } from "../../_chunks/jwe.mjs";
5
6
  import { getChunkedCookie, getEventContext, setChunkedCookie } from "h3";
6
7
  import { NullProtoObj } from "rou3";
7
8
  const kGetSessionPromise$1 = Symbol("h3_jwe_getSession");
@@ -158,11 +159,11 @@ async function updateJWESession(event, config, update) {
158
159
  if (config.cookie !== false && !canWriteCookie) throw new Error("[unjwt/h3] Cannot update session on read-only event.");
159
160
  const sessionName = config.name || DEFAULT_NAME$1;
160
161
  const session = getEventContext(event).sessions?.[sessionName] || await getJWESession(event, config);
161
- if (typeof update === "function") update = update(session.data);
162
162
  const oldSession = {
163
163
  ...session,
164
- data: { ...session.data }
164
+ data: sanitizeObjectCopy(session.data)
165
165
  };
166
+ if (typeof update === "function") update = update(session.data);
166
167
  if (update) Object.assign(session.data, update);
167
168
  const now = config.jwe?.encryptOptions?.currentDate?.getTime() ?? Date.now();
168
169
  const createdAt = now - now % 1e3;
@@ -178,7 +179,8 @@ async function updateJWESession(event, config, update) {
178
179
  Object.assign(session, {
179
180
  id: oldSession.id,
180
181
  createdAt: oldSession.createdAt,
181
- expiresAt: oldSession.expiresAt
182
+ expiresAt: oldSession.expiresAt,
183
+ data: oldSession.data
182
184
  });
183
185
  session.token = oldSession.token;
184
186
  await config.hooks?.onError?.({
@@ -239,7 +241,7 @@ async function unsealJWESession(event, config, sealed) {
239
241
  if (config.jwe?.encryptOptions?.protectedHeader?.typ && typeof config.jwe.encryptOptions.protectedHeader.typ === "string" && config.jwe.encryptOptions.protectedHeader.typ.toLowerCase().includes("jwt")) typ = config.jwe.encryptOptions.protectedHeader.typ;
240
242
  const { payload } = await decrypt(sealed, key, {
241
243
  ...config.jwe?.decryptOptions,
242
- requiredClaims: [...new Set([
244
+ requiredClaims: [.../* @__PURE__ */ new Set([
243
245
  ...config.jwe?.decryptOptions?.requiredClaims || [],
244
246
  "jti",
245
247
  "iat"
@@ -273,7 +275,7 @@ async function clearJWESession(event, config) {
273
275
  if (session && session[kGetSessionPromise$1]) session = await session[kGetSessionPromise$1];
274
276
  const oldSession = session ? {
275
277
  ...session,
276
- data: { ...session.data }
278
+ data: sanitizeObjectCopy(session.data)
277
279
  } : void 0;
278
280
  if (context.sessions?.[sessionName]) delete context.sessions[sessionName];
279
281
  if (config.cookie !== false && canWriteCookie) setChunkedCookie(event, sessionName, "", {
@@ -472,11 +474,11 @@ async function updateJWSSession(event, config, update) {
472
474
  if (config.cookie !== false && !canWriteCookie) throw new Error("[unjwt/h3] Cannot update session on read-only event.");
473
475
  const sessionName = config.name || DEFAULT_NAME;
474
476
  const session = getEventContext(event).sessions?.[sessionName] || await getJWSSession(event, config);
475
- if (typeof update === "function") update = update(session.data);
476
477
  const oldSession = {
477
478
  ...session,
478
- data: { ...session.data }
479
+ data: sanitizeObjectCopy(session.data)
479
480
  };
481
+ if (typeof update === "function") update = update(session.data);
480
482
  if (update) Object.assign(session.data, update);
481
483
  const now = config.jws?.signOptions?.currentDate?.getTime() ?? Date.now();
482
484
  const createdAt = now - now % 1e3;
@@ -492,7 +494,8 @@ async function updateJWSSession(event, config, update) {
492
494
  Object.assign(session, {
493
495
  id: oldSession.id,
494
496
  createdAt: oldSession.createdAt,
495
- expiresAt: oldSession.expiresAt
497
+ expiresAt: oldSession.expiresAt,
498
+ data: oldSession.data
496
499
  });
497
500
  session.token = oldSession.token;
498
501
  await config.hooks?.onError?.({
@@ -553,7 +556,7 @@ async function verifyJWSSession(event, config, token) {
553
556
  if (config.jws?.signOptions?.protectedHeader?.typ && typeof config.jws.signOptions.protectedHeader.typ === "string" && config.jws.signOptions.protectedHeader.typ.toLowerCase().includes("jwt")) typ = config.jws.signOptions.protectedHeader.typ;
554
557
  const { payload } = await verify(token, jwk, {
555
558
  ...config.jws?.verifyOptions,
556
- requiredClaims: [...new Set([
559
+ requiredClaims: [.../* @__PURE__ */ new Set([
557
560
  ...config.jws?.verifyOptions?.requiredClaims || [],
558
561
  "jti",
559
562
  "iat"
@@ -584,7 +587,7 @@ async function clearJWSSession(event, config) {
584
587
  if (session && session[kGetSessionPromise]) session = await session[kGetSessionPromise];
585
588
  const oldSession = session ? {
586
589
  ...session,
587
- data: { ...session.data }
590
+ data: sanitizeObjectCopy(session.data)
588
591
  } : void 0;
589
592
  if (context.sessions?.[sessionName]) delete context.sessions[sessionName];
590
593
  if (config.cookie !== false && canWriteCookie) setChunkedCookie(event, sessionName, "", {
@@ -636,4 +639,4 @@ function findSetCookie(setCookie, name) {
636
639
  const match = setCookie.match(regex);
637
640
  return match ? match[1] : void 0;
638
641
  }
639
- export { clearJWESession, clearJWSSession, deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, importFromPEM, importPEM, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
642
+ export { clearJWESession, clearJWSSession, deriveJWKFromPassword, exportPEM, exportToPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, getJWSSessionToken, importFromPEM, importPEM, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
@@ -1,3 +1,3 @@
1
- import { G as isJWTError, H as JWTError, U as JWTErrorCauseMap, W as JWTErrorCode, _ as JWEMultiDecryptOptions, a as JWEAsymmetricPrivateJWK, b as JWEMultiRecipient, c as JWEDecryptOptions, d as JWEEncryptOptions, f as JWEFlattenedSerialization, g as JWEKeyManagementHeaderParameters, h as JWEHeaderParameters, l as JWEDecryptResult, m as JWEGeneralSerialization, o as JWEAsymmetricPublicJWK, p as JWEGeneralRecipient, s as JWEDecryptJWK, u as JWEEncryptJWK, v as JWEMultiDecryptResult, x as JWEProtectedHeader, y as JWEMultiEncryptOptions } from "../_chunks/index.mjs";
2
- import { a as generalToFlattened, i as encryptMulti, n as encrypt, r as decryptMulti, t as decrypt } from "../_chunks/jwe.mjs";
3
- export { JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWTError, JWTErrorCauseMap, JWTErrorCode, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError };
1
+ import { JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWTError, JWTErrorCauseMap, JWTErrorCode, isJWTError } from "../_chunks/index.mjs";
2
+ import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "../_chunks/jwe.mjs";
3
+ export { type JWEAsymmetricPrivateJWK, type JWEAsymmetricPublicJWK, type JWEDecryptJWK, type JWEDecryptOptions, type JWEDecryptResult, type JWEEncryptJWK, type JWEEncryptOptions, type JWEFlattenedSerialization, type JWEGeneralRecipient, type JWEGeneralSerialization, type JWEHeaderParameters, type JWEKeyManagementHeaderParameters, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, JWTError, type JWTErrorCauseMap, type JWTErrorCode, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError };
package/dist/core/jwe.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { D as JWTError, O as isJWTError } from "../_chunks/utils.mjs";
2
- import { a as generalToFlattened, i as encryptMulti, n as encrypt, r as decryptMulti, t as decrypt } from "../_chunks/jwe.mjs";
1
+ import { JWTError, isJWTError } from "../_chunks/utils.mjs";
2
+ import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "../_chunks/jwe.mjs";
3
3
  export { JWTError, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError };
@@ -1,4 +1,4 @@
1
- import { $ as DeriveKeyOptions, At as JWK_PBES2, Bt as JWK_Symmetric, Ct as JWK_EC_Private, Dt as JWK_OKP_Private, Et as JWK_OKP, Ft as JWK_RSA_ENC, G as isJWTError, Gt as UnwrappingKeyFor, H as JWTError, Ht as JWK_oct, It as JWK_RSA_PSS, Jt as WrappingKeyFor, Kt as WrapKeyOptions, Lt as JWK_RSA_Private, Mt as JWK_Private, Nt as JWK_Public, Ot as JWK_OKP_Public, Pt as JWK_RSA, Q as ContentEncryptionAlgorithm, Rt as JWK_RSA_Public, St as JWK_ECDSA, Tt as JWK_HMAC, U as JWTErrorCauseMap, Ut as KeyManagementAlgorithm, Vt as JWK_Symmetric_Algorithm, W as JWTErrorCode, Wt as UnwrapKeyOptions, X as JoseHeaderParameters, Z as CompositeKey, _t as JWK_AES_KW, at as GenerateKeyReturn, bt as JWK_EC, ct as JWKCacheAdapter, dt as JWKPEMAlgorithm, et as DeriveKeyReturn, ft as JWKParameters, gt as JWK_AES_GCM_KW, ht as JWK_AES_GCM, it as GenerateKeyOptions, jt as JWK_Pair, kt as JWK_OKP_SIGN, lt as JWKLookupFunction, mt as JWK_AES_CBC_HMAC, nt as GenerateJWKReturn, ot as JWK, pt as JWKSet, qt as WrapKeyResult, rt as GenerateKeyAlgorithm, st as JWKAlgorithm, tt as GenerateJWKOptions, ut as JWKLookupFunctionHeader, vt as JWK_Asymmetric, wt as JWK_EC_Public, xt as JWK_ECDH_ES, yt as JWK_Asymmetric_Algorithm, zt as JWK_RSA_SIGN } from "../_chunks/index.mjs";
1
+ import { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, 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, JWTError, JWTErrorCauseMap, JWTErrorCode, JoseHeaderParameters, KeyManagementAlgorithm, UnwrapKeyOptions, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, isJWTError } from "../_chunks/index.mjs";
2
2
  /**
3
3
  * Generates a cryptographic key for the specified JWA algorithm.
4
4
  *
@@ -28,6 +28,7 @@ import { $ as DeriveKeyOptions, At as JWK_PBES2, Bt as JWK_Symmetric, Ct as JWK_
28
28
  * @param options
29
29
  * - `toJWK?` — when `true`, return JWK / JWK pair instead of `CryptoKey` / `CryptoKeyPair`.
30
30
  * - `extractable?` — forwarded to `crypto.subtle.generateKey`. Defaults to `true`.
31
+ * Ignored when `toJWK` is set — the JWK output requires exporting the intermediate key.
31
32
  * - `keyUsage?` — override the default usages derived from `alg`.
32
33
  * - `modulusLength?` — RSA only; defaults to `2048`.
33
34
  * - `publicExponent?` — RSA only; defaults to `0x010001`.
@@ -64,7 +65,6 @@ declare function generateKey<TAlg extends GenerateKeyAlgorithm, TOptions extends
64
65
  * `"A128GCM"`, `"A256CBC-HS512"`). PBES2, `"dir"`, and `"none"` are
65
66
  * not accepted.
66
67
  * @param options
67
- * - `extractable?` — forwarded to `crypto.subtle.generateKey`. Defaults to `true`.
68
68
  * - `keyUsage?` — override the default usages derived from `alg`.
69
69
  * - `modulusLength?` — RSA only; defaults to `2048`.
70
70
  * - `publicExponent?` — RSA only; defaults to `0x010001`.
@@ -109,12 +109,11 @@ declare function deriveKeyFromPassword<TAlg extends JWK_PBES2, TOptions extends
109
109
  * - `salt` — PBKDF2 salt input (`p2s`). Must be at least 8 octets (RFC 7518 §4.8.1.1).
110
110
  * - `iterations` — PBKDF2 iteration count (`p2c`). Must be a positive integer.
111
111
  * - `keyUsage?` — defaults to `["wrapKey", "unwrapKey"]`.
112
- * - `extractable?` — forwarded to `crypto.subtle.importKey`. Defaults to `false`.
113
112
  * - JWK metadata (`kid`, `use`, `x5c`, `x5t`, `x5t#S256`, `x5u`) is merged onto the
114
113
  * result. `alg`, `kty`, `key_ops`, and `ext` are managed by the library and cannot
115
114
  * be overridden here.
116
115
  */
117
- declare function deriveJWKFromPassword(password: string | Uint8Array<ArrayBuffer>, alg: JWK_PBES2, options: Omit<DeriveKeyOptions, "toJWK"> & Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">): Promise<JWK_oct>;
116
+ declare function deriveJWKFromPassword(password: string | Uint8Array<ArrayBuffer>, alg: JWK_PBES2, options: Omit<DeriveKeyOptions, "toJWK" | "extractable"> & Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">): Promise<JWK_oct>;
118
117
  /**
119
118
  * Default JWK import cache backed by a WeakMap.
120
119
  *
@@ -248,9 +247,12 @@ declare function unwrapKey<TAlg extends KeyManagementAlgorithm>(alg: TAlg, wrapp
248
247
  * the key's intended algorithm and for setting the `alg` field on the resulting JWK.
249
248
  * @param options
250
249
  * - `pemType?` — explicit PEM type; inferred from the label when omitted.
251
- * - `extractable?` — forwarded to `crypto.subtle.importKey`. Defaults to `false` for private
252
- * keys and `true` for public keys.
253
250
  * - `jwkParams?` — additional JWK properties merged into the result (e.g. `kid`, `use`).
251
+ *
252
+ * The returned JWK always contains the key material in plain JavaScript — non-extractable
253
+ * import is impossible for a PEM → JWK conversion (JWK export requires an extractable key).
254
+ * To obtain a non-extractable `CryptoKey`, pass the result to
255
+ * `importKey(jwk, { extractable: false })`.
254
256
  * `alg`, `kty`, `key_ops`, and `ext` are reserved and cannot be overridden here.
255
257
  * @throws `JWTError("ERR_JWK_INVALID")` if the PEM type cannot be inferred (no recognised label
256
258
  * and no `options.pemType`), or if the label does not match the requested/inferred type.
@@ -266,8 +268,7 @@ declare function unwrapKey<TAlg extends KeyManagementAlgorithm>(alg: TAlg, wrapp
266
268
  * ```
267
269
  */
268
270
  declare function importPEM<T extends JWK>(pem: string, alg: JWKPEMAlgorithm, options?: {
269
- /** PEM type. Inferred from the PEM label when omitted. */pemType?: "pkcs8" | "spki" | "x509"; /** Passed to `crypto.subtle.importKey`. Defaults to `false` for private keys, `true` otherwise. */
270
- extractable?: boolean; /** Additional JWK properties merged into the exported key (e.g. `kid`). */
271
+ /** PEM type. Inferred from the PEM label when omitted. */pemType?: "pkcs8" | "spki" | "x509"; /** Additional JWK properties merged into the exported key (e.g. `kid`). */
271
272
  jwkParams?: Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
272
273
  }): Promise<T>;
273
274
  /**
@@ -275,7 +276,6 @@ declare function importPEM<T extends JWK>(pem: string, alg: JWKPEMAlgorithm, opt
275
276
  * is now inferred from the PEM label by default.
276
277
  */
277
278
  declare function importFromPEM<T extends JWK>(pem: string, pemType: "pkcs8" | "spki" | "x509", alg: JWKPEMAlgorithm, options?: {
278
- extractable?: boolean;
279
279
  jwkParams?: Omit<JWKParameters, "alg" | "kty" | "key_ops" | "ext">;
280
280
  }): Promise<T>;
281
281
  /**
@@ -384,4 +384,4 @@ declare function getJWKFromSet(jwkSet: JWKSet, kidOrProtectedHeader: string | (J
384
384
  * @returns An array of matching JWKs.
385
385
  */
386
386
  declare function getJWKsFromSet(jwkSet: JWKSet, filter?: (jwk: JWK) => boolean): JWK[];
387
- export { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, 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, JWTError, type JWTErrorCauseMap, type JWTErrorCode, KeyManagementAlgorithm, UnwrapKeyOptions, UnwrappingKeyFor, WeakMapJWKCache, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportKey, exportPEM, exportToPEM, generateJWK, generateKey, getJWKFromSet, getJWKsFromSet, importFromPEM, importKey, importPEM, isJWTError, unwrapKey, wrapKey };
387
+ export { type CompositeKey, type ContentEncryptionAlgorithm, type DeriveKeyOptions, type DeriveKeyReturn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKPEMAlgorithm, type JWKParameters, type JWKSet, type JWK_AES_CBC_HMAC, type JWK_AES_GCM, type JWK_AES_GCM_KW, type JWK_AES_KW, type JWK_Asymmetric, type JWK_Asymmetric_Algorithm, type JWK_EC, type JWK_ECDH_ES, type JWK_ECDSA, type JWK_EC_Private, type JWK_EC_Public, type JWK_HMAC, type JWK_OKP, type JWK_OKP_Private, type JWK_OKP_Public, type JWK_OKP_SIGN, type JWK_PBES2, type JWK_Pair, type JWK_Private, type JWK_Public, type JWK_RSA, type JWK_RSA_ENC, type JWK_RSA_PSS, type JWK_RSA_Private, type JWK_RSA_Public, type JWK_RSA_SIGN, type JWK_Symmetric, type JWK_Symmetric_Algorithm, type JWK_oct, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type KeyManagementAlgorithm, type UnwrapKeyOptions, type UnwrappingKeyFor, WeakMapJWKCache, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportKey, exportPEM, exportToPEM, generateJWK, generateKey, getJWKFromSet, getJWKsFromSet, importFromPEM, importKey, importPEM, isJWTError, unwrapKey, wrapKey };
package/dist/core/jwk.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { D as JWTError, O as isJWTError } from "../_chunks/utils.mjs";
2
- import { _ as unwrapKey, a as deriveKeyFromPassword, c as exportPEM, d as generateKey, f as getJWKFromSet, g as importPEM, h as importKey, i as deriveJWKFromPassword, l as exportToPEM, m as importFromPEM, n as clearJWKCache, o as deriveSharedSecret, p as getJWKsFromSet, r as configureJWKCache, s as exportKey, t as WeakMapJWKCache, u as generateJWK, v as wrapKey } from "../_chunks/jwk.mjs";
1
+ import { JWTError, isJWTError } from "../_chunks/utils.mjs";
2
+ import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportKey, exportPEM, exportToPEM, generateJWK, generateKey, getJWKFromSet, getJWKsFromSet, importFromPEM, importKey, importPEM, unwrapKey, wrapKey } from "../_chunks/jwk.mjs";
3
3
  export { JWTError, WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportKey, exportPEM, exportToPEM, generateJWK, generateKey, getJWKFromSet, getJWKsFromSet, importFromPEM, importKey, importPEM, isJWTError, unwrapKey, wrapKey };
@@ -1,3 +1,3 @@
1
- import { A as JWSMultiSigner, B as JWSVerifyResult, C as JWSAsymmetricPrivateJWK, D as JWSGeneralSignature, E as JWSGeneralSerialization, F as JWSProtectedHeader, G as isJWTError, H as JWTError, I as JWSSignJWK, L as JWSSignOptions, M as JWSMultiVerifyOptions, N as JWSMultiVerifyOutcome, O as JWSHeaderParameters, P as JWSMultiVerifyResult, R as JWSVerifyJWK, S as JWSAlgorithm, T as JWSFlattenedSerialization, U as JWTErrorCauseMap, W as JWTErrorCode, j as JWSMultiVerifyAllOptions, k as JWSMultiSignOptions, w as JWSAsymmetricPublicJWK, z as JWSVerifyOptions } from "../_chunks/index.mjs";
2
- import { a as verifyMulti, i as signMulti, n as verify, o as verifyMultiAll, r as generalToFlattenedJWS, t as sign } from "../_chunks/jws.mjs";
3
- export { JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHeaderParameters, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWTError, JWTErrorCauseMap, JWTErrorCode, generalToFlattenedJWS, isJWTError, sign, signMulti, verify, verifyMulti, verifyMultiAll };
1
+ import { JWSAlgorithm, JWSAsymmetricPrivateJWK, JWSAsymmetricPublicJWK, JWSFlattenedSerialization, JWSGeneralSerialization, JWSGeneralSignature, JWSHeaderParameters, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWTError, JWTErrorCauseMap, JWTErrorCode, isJWTError } from "../_chunks/index.mjs";
2
+ import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "../_chunks/jws.mjs";
3
+ export { type JWSAlgorithm, type JWSAsymmetricPrivateJWK, type JWSAsymmetricPublicJWK, type JWSFlattenedSerialization, type JWSGeneralSerialization, type JWSGeneralSignature, type JWSHeaderParameters, type JWSMultiSignOptions, type JWSMultiSigner, type JWSMultiVerifyAllOptions, type JWSMultiVerifyOptions, type JWSMultiVerifyOutcome, type JWSMultiVerifyResult, type JWSProtectedHeader, type JWSSignJWK, type JWSSignOptions, type JWSVerifyJWK, type JWSVerifyOptions, type JWSVerifyResult, JWTError, type JWTErrorCauseMap, type JWTErrorCode, generalToFlattenedJWS, isJWTError, sign, signMulti, verify, verifyMulti, verifyMultiAll };
package/dist/core/jws.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { D as JWTError, O as isJWTError } from "../_chunks/utils.mjs";
2
- import { a as verifyMulti, i as signMulti, n as verify, o as verifyMultiAll, r as generalToFlattenedJWS, t as sign } from "../_chunks/jws.mjs";
1
+ import { JWTError, isJWTError } from "../_chunks/utils.mjs";
2
+ import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "../_chunks/jws.mjs";
3
3
  export { JWTError, generalToFlattenedJWS, isJWTError, sign, signMulti, verify, verifyMulti, verifyMultiAll };