unjwt 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/THIRD-PARTY-LICENSES.md.gz +0 -0
- package/dist/_chunks/_codec-jwe.d.mts +170 -0
- package/dist/_chunks/_codec-jws.mjs +878 -0
- package/dist/_chunks/_internal.d.mts +7 -0
- package/dist/_chunks/_jwt-internal.mjs +388 -0
- package/dist/_chunks/algorithms.mjs +186 -0
- package/dist/_chunks/index.d.mts +512 -818
- package/dist/_chunks/index2.d.mts +11 -0
- package/dist/_chunks/index3.d.mts +108 -0
- package/dist/_chunks/jwe.d.mts +43 -66
- package/dist/_chunks/jwe.mjs +384 -252
- package/dist/_chunks/jwk.mjs +1390 -622
- package/dist/_chunks/jws.d.mts +48 -103
- package/dist/_chunks/jws.mjs +372 -184
- package/dist/_chunks/jwt.d.mts +56 -0
- package/dist/_chunks/libs/unsecure.d.mts +164 -85
- package/dist/_chunks/libs/unsecure.mjs +390 -123
- package/dist/adapters/elysia/index.d.mts +33 -171
- package/dist/adapters/elysia/index.mjs +106 -575
- package/dist/adapters/h3v1/index.d.mts +59 -344
- package/dist/adapters/h3v1/index.mjs +114 -619
- package/dist/adapters/h3v2/index.d.mts +58 -326
- package/dist/adapters/h3v2/index.mjs +108 -611
- package/dist/core/internal.d.mts +2 -0
- package/dist/core/internal.mjs +1 -0
- package/dist/core/jwe.d.mts +4 -2
- package/dist/core/jwe.mjs +4 -2
- package/dist/core/jwk.d.mts +183 -371
- package/dist/core/jwk.mjs +4 -3
- package/dist/core/jws.d.mts +4 -2
- package/dist/core/jws.mjs +4 -2
- package/dist/core/utils/index.d.mts +5 -155
- package/dist/core/utils/index.mjs +12 -3
- package/dist/index.d.mts +8 -4
- package/dist/index.mjs +6 -3
- package/package.json +39 -36
- package/dist/_chunks/_internal.mjs +0 -88
- package/dist/_chunks/utils.mjs +0 -390
|
@@ -1,333 +1,65 @@
|
|
|
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,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, 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, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, MaxTokenAge, NotBeforeIn, PayloadOf, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../../_chunks/index.mjs";
|
|
2
|
+
import { JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, SessionClaims, SessionData, SessionDecryptOptions, SessionEncryptOptions, SessionIssueOptions, SessionManager, SessionRecord, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions } from "../../_chunks/_codec-jwe.mjs";
|
|
3
|
+
import { thumbprint } from "../../_chunks/index2.mjs";
|
|
4
|
+
import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM } from "../../core/jwk.mjs";
|
|
5
|
+
import { HTTPEvent } from "h3";
|
|
4
6
|
import { CookieSerializeOptions } from "cookie-es";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
interface
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
update: (update?: SessionUpdate<T>) => Promise<SessionManager<T, ConfigMaxAge>>;
|
|
15
|
-
clear: () => Promise<SessionManager<T, ConfigMaxAge>>;
|
|
16
|
-
}
|
|
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
|
-
*/
|
|
22
|
-
interface SessionJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
23
|
-
/** Session ID — mirrors the JWT `jti` claim. `undefined` until the session is persisted. */
|
|
24
|
-
id: string | undefined;
|
|
25
|
-
/** Session creation time in ms — mirrors the JWT `iat` claim (seconds). */
|
|
26
|
-
createdAt: number;
|
|
27
|
-
/** Session expiry time in ms — mirrors the JWT `exp` claim (seconds). */
|
|
28
|
-
expiresAt: MaxAge extends ExpiresIn ? number : T["exp"];
|
|
29
|
-
/** Session data — carried in the token payload, spread at the top level. */
|
|
30
|
-
data: SessionData<T>;
|
|
31
|
-
/** The current compact JWE token. `undefined` until the session is persisted. */
|
|
32
|
-
token: string | undefined;
|
|
33
|
-
[kGetSessionPromise$1]?: Promise<SessionJWE<T, MaxAge>>;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
46
|
-
onRead?: (args: {
|
|
47
|
-
session: SessionJWE<T, MaxAge> & {
|
|
48
|
-
id: string;
|
|
49
|
-
token: string;
|
|
50
|
-
};
|
|
51
|
-
event: TEvent;
|
|
52
|
-
config: SessionConfigJWE<T, MaxAge, TEvent>;
|
|
53
|
-
}) => void | Promise<void>;
|
|
54
|
-
/** Fires after a new token was sealed — including pure token refreshes (update with no data). */
|
|
55
|
-
onUpdate?: (args: {
|
|
56
|
-
/** Session after the update. */session: SessionJWE<T, MaxAge> & {
|
|
57
|
-
id: string;
|
|
58
|
-
token: string;
|
|
59
|
-
}; /** Deep-copied snapshot of the session before the update. */
|
|
60
|
-
oldSession: SessionJWE<T, MaxAge>;
|
|
61
|
-
event: TEvent;
|
|
62
|
-
config: SessionConfigJWE<T, MaxAge, TEvent>;
|
|
63
|
-
}) => void | Promise<void>;
|
|
64
|
-
/** Fires when the session is cleared. */
|
|
65
|
-
onClear?: (args: {
|
|
66
|
-
/** Last known session before clearing, if any. */oldSession: SessionJWE<T, MaxAge> | undefined;
|
|
67
|
-
event: TEvent;
|
|
68
|
-
config: SessionConfigJWE<T, MaxAge, TEvent>;
|
|
69
|
-
}) => void | Promise<void>;
|
|
70
|
-
/** Fires when the incoming token is expired. Receives the expired token's decoded claims. */
|
|
71
|
-
onExpire?: (args: {
|
|
72
|
-
session: {
|
|
73
|
-
id: string | undefined;
|
|
74
|
-
createdAt: number | undefined;
|
|
75
|
-
expiresAt: number | undefined;
|
|
76
|
-
token: string;
|
|
77
|
-
};
|
|
78
|
-
event: TEvent;
|
|
79
|
-
error: Error;
|
|
80
|
-
config: SessionConfigJWE<T, MaxAge, TEvent>;
|
|
81
|
-
}) => void | Promise<void>;
|
|
82
|
-
/** Fires on read-path failures other than expiry, and on write-path seal failures. */
|
|
83
|
-
onError?: (args: {
|
|
84
|
-
/**
|
|
85
|
-
* The session involved in the error.
|
|
86
|
-
*/
|
|
87
|
-
session: SessionJWE<T, MaxAge>;
|
|
88
|
-
event: TEvent;
|
|
89
|
-
error: any;
|
|
90
|
-
config: SessionConfigJWE<T, MaxAge, TEvent>;
|
|
91
|
-
}) => void | Promise<void>;
|
|
92
|
-
/** Resolve the decryption key for the incoming token from its protected header (e.g. by `kid`). */
|
|
93
|
-
onUnsealKeyLookup?: (args: {
|
|
94
|
-
header: JWEHeaderParameters;
|
|
95
|
-
event: TEvent;
|
|
96
|
-
config: SessionConfigJWE<T, MaxAge, TEvent>;
|
|
97
|
-
}) => JWEDecryptJWK | Promise<JWEDecryptJWK>;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Configuration for a JWE-backed (encrypted) session.
|
|
101
|
-
*/
|
|
102
|
-
interface SessionConfigJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent | H3Event = HTTPEvent | H3Event> {
|
|
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
|
-
*/
|
|
107
|
-
key: string | JWEEncryptJWK | {
|
|
108
|
-
privateKey: JWEAsymmetricPrivateJWK;
|
|
109
|
-
publicKey?: JWEAsymmetricPublicJWK;
|
|
110
|
-
};
|
|
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
|
-
*/
|
|
117
|
-
maxAge?: MaxAge;
|
|
118
|
-
/** Session name — drives the cookie name and the default session header. Default `"h3-jwe"`. */
|
|
7
|
+
/** Session state for the current request, mirroring the claims of its JWE token. */
|
|
8
|
+
interface SessionJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
9
|
+
/** JWE session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token. */
|
|
10
|
+
interface SessionHooksJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWESessionHooks<SessionJWE<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
11
|
+
event: TEvent;
|
|
12
|
+
}, SessionConfigJWE<T, MaxAge, TEvent>> {}
|
|
13
|
+
/** Configuration for a JWE-backed (encrypted) session. */
|
|
14
|
+
interface SessionConfigJWE<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWESessionConfig<MaxAge, CookieSerializeOptions> {
|
|
15
|
+
/** Cookie and session-header name. Default `"h3-jwe"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
119
16
|
name?: string;
|
|
120
|
-
/** Cookie options (`false` to disable). Defaults: `path="/"`, `secure`, `httpOnly: true`. */
|
|
121
|
-
cookie?: false | (CookieSerializeOptions & {
|
|
122
|
-
chunkMaxLength?: number;
|
|
123
|
-
});
|
|
124
|
-
/** Request header to read the token from (`false` to disable). Default `x-<name>-session`. */
|
|
125
|
-
sessionHeader?: false | string;
|
|
126
|
-
/** Session ID (`jti`) generator. Default `crypto.randomUUID`. */
|
|
127
|
-
generateId?: () => string;
|
|
128
|
-
/** JWE encrypt/decrypt overrides. Set `encryptOptions.alg` and `enc` to pin the session algorithms — unsealing then accepts only them. */
|
|
129
|
-
jwe?: {
|
|
130
|
-
encryptOptions?: Omit<JWEEncryptOptions, "expiresIn">;
|
|
131
|
-
decryptOptions?: JWTClaimValidationOptions;
|
|
132
|
-
};
|
|
133
|
-
/** Lifecycle hooks — see {@link SessionHooksJWE}. */
|
|
134
17
|
hooks?: SessionHooksJWE<T, MaxAge, TEvent>;
|
|
135
18
|
}
|
|
136
|
-
/**
|
|
137
|
-
|
|
138
|
-
*/
|
|
139
|
-
declare function
|
|
140
|
-
/**
|
|
141
|
-
|
|
142
|
-
*/
|
|
143
|
-
declare function
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
*/
|
|
160
|
-
|
|
161
|
-
/**
|
|
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
|
|
168
|
-
*/
|
|
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>>>;
|
|
170
|
-
/**
|
|
171
|
-
* Clear the session (delete from context and drop cookie).
|
|
172
|
-
*/
|
|
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>;
|
|
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
|
-
*/
|
|
179
|
-
interface SessionJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
180
|
-
/** Session ID — mirrors the JWT `jti` claim. `undefined` until the session is persisted. */
|
|
181
|
-
id: string | undefined;
|
|
182
|
-
/** Session creation time in ms — mirrors the JWT `iat` claim (seconds). */
|
|
183
|
-
createdAt: number;
|
|
184
|
-
/** Session expiry time in ms — mirrors the JWT `exp` claim (seconds). */
|
|
185
|
-
expiresAt: MaxAge extends ExpiresIn ? number : T["exp"];
|
|
186
|
-
/** Session data — carried in the token payload, spread at the top level. */
|
|
187
|
-
data: SessionData<T>;
|
|
188
|
-
/** The current compact JWS token. `undefined` until the session is persisted. */
|
|
189
|
-
token: string | undefined;
|
|
190
|
-
[kGetSessionPromise]?: Promise<SessionJWS<T, MaxAge>>;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
203
|
-
onRead?: (args: {
|
|
204
|
-
session: SessionJWS<T, MaxAge> & {
|
|
205
|
-
id: string;
|
|
206
|
-
token: string;
|
|
207
|
-
};
|
|
208
|
-
event: TEvent;
|
|
209
|
-
config: SessionConfigJWS<T, MaxAge, TEvent>;
|
|
210
|
-
}) => void | Promise<void>;
|
|
211
|
-
/** Fires after a new token was signed — including pure token refreshes (update with no data). */
|
|
212
|
-
onUpdate?: (args: {
|
|
213
|
-
/** Session after the update. */session: SessionJWS<T, MaxAge> & {
|
|
214
|
-
id: string;
|
|
215
|
-
token: string;
|
|
216
|
-
}; /** Deep-copied snapshot of the session before the update. */
|
|
217
|
-
oldSession: SessionJWS<T, MaxAge>;
|
|
218
|
-
event: TEvent;
|
|
219
|
-
config: SessionConfigJWS<T, MaxAge, TEvent>;
|
|
220
|
-
}) => void | Promise<void>;
|
|
221
|
-
/** Fires when the session is cleared. */
|
|
222
|
-
onClear?: (args: {
|
|
223
|
-
/** Last known session before clearing, if any. */oldSession: SessionJWS<T, MaxAge> | undefined;
|
|
224
|
-
event: TEvent;
|
|
225
|
-
config: SessionConfigJWS<T, MaxAge, TEvent>;
|
|
226
|
-
}) => void | Promise<void>;
|
|
227
|
-
/** Fires when the incoming token is expired. Receives the expired token's decoded claims. */
|
|
228
|
-
onExpire?: (args: {
|
|
229
|
-
session: {
|
|
230
|
-
id: string | undefined;
|
|
231
|
-
createdAt: number | undefined;
|
|
232
|
-
expiresAt: number | undefined;
|
|
233
|
-
token: string;
|
|
234
|
-
};
|
|
235
|
-
event: TEvent;
|
|
236
|
-
error: Error;
|
|
237
|
-
config: SessionConfigJWS<T, MaxAge, TEvent>;
|
|
238
|
-
}) => void | Promise<void>;
|
|
239
|
-
/** Fires on read-path failures other than expiry, and on write-path sign failures. */
|
|
240
|
-
onError?: (args: {
|
|
241
|
-
/**
|
|
242
|
-
* The session involved in the error.
|
|
243
|
-
*/
|
|
244
|
-
session: SessionJWS<T, MaxAge>;
|
|
245
|
-
event: TEvent;
|
|
246
|
-
error: any;
|
|
247
|
-
config: SessionConfigJWS<T, MaxAge, TEvent>;
|
|
248
|
-
}) => void | Promise<void>;
|
|
249
|
-
/** Resolve the verification key(s) for the incoming token from its protected header (e.g. by `kid`). */
|
|
250
|
-
onVerifyKeyLookup?: (args: {
|
|
251
|
-
header: JWKLookupFunctionHeader;
|
|
252
|
-
event: TEvent;
|
|
253
|
-
config: SessionConfigJWS<T, MaxAge, TEvent>;
|
|
254
|
-
}) => JWKSet | JWSVerifyJWK | Promise<JWKSet | JWSVerifyJWK>;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Configuration for a JWS-backed (signed, not encrypted) session.
|
|
258
|
-
*/
|
|
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
|
-
*/
|
|
265
|
-
key: JWK_oct<JWK_HMAC> | {
|
|
266
|
-
privateKey: JWSAsymmetricPrivateJWK;
|
|
267
|
-
publicKey: JWSAsymmetricPublicJWK | JWSAsymmetricPublicJWK[] | JWKSet;
|
|
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
|
-
*/
|
|
275
|
-
maxAge?: MaxAge;
|
|
276
|
-
/** Session name — drives the cookie name and the default session header. Default `"h3-jws"`. */
|
|
19
|
+
/** Create a JWE (encrypted) session manager for the request. */
|
|
20
|
+
export declare function useJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<SessionManager<T, MaxAge>>;
|
|
21
|
+
/** Get (and lazily initialize) the session for the current request. */
|
|
22
|
+
export declare function getJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<SessionJWE<T, MaxAge>>;
|
|
23
|
+
/** Read the raw session token: cookie first, then the session header (default `x-<name>-session`, optional `Bearer`). */
|
|
24
|
+
export declare function getJWESessionToken<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): string | undefined;
|
|
25
|
+
/** Update the session data (if provided) and reissue the JWE; `options.maxAge` overrides this token's lifetime. */
|
|
26
|
+
export declare function updateJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>, update?: SessionUpdate<T>, options?: SessionIssueOptions): Promise<SessionJWE<T, MaxAge> & {
|
|
27
|
+
id: string;
|
|
28
|
+
token: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** Seal the session as a compact JWE without writing a cookie; fresh `jti` if no ID, no token source needed. */
|
|
31
|
+
export declare function sealJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<string>;
|
|
32
|
+
/** Decrypt a compact JWE into a session, checking `typ`, pinned `alg`/`enc`, `jti`/`iat` and `exp` (required with `maxAge`). */
|
|
33
|
+
export declare function unsealJWESession<T extends SessionRecord = 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>>>;
|
|
34
|
+
/** Drop the session cookie and leave an empty session for the rest of the request. */
|
|
35
|
+
export declare function clearJWESession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWE<T, MaxAge, TEvent>): Promise<void>;
|
|
36
|
+
/** Session state for the current request, mirroring the claims of its JWS token. */
|
|
37
|
+
interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
|
|
38
|
+
/** JWS session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token. */
|
|
39
|
+
interface SessionHooksJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWSSessionHooks<SessionJWS<T, MaxAge>, SessionManager<T, MaxAge>, {
|
|
40
|
+
event: TEvent;
|
|
41
|
+
}, SessionConfigJWS<T, MaxAge, TEvent>> {}
|
|
42
|
+
/** Configuration for a JWS-backed (signed, not encrypted) session. */
|
|
43
|
+
interface SessionConfigJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent> extends JWSSessionConfig<MaxAge, CookieSerializeOptions> {
|
|
44
|
+
/** Cookie and session-header name. Default `"h3-jws"`; a `.<digits>` suffix throws `ERR_SESSION_CONFIG_INVALID`. */
|
|
277
45
|
name?: string;
|
|
278
|
-
/** Cookie options (`false` to disable). Defaults: `path="/"`, `secure`, `httpOnly: false` — the JWS payload is client-readable by design. */
|
|
279
|
-
cookie?: false | (CookieSerializeOptions & {
|
|
280
|
-
chunkMaxLength?: number;
|
|
281
|
-
});
|
|
282
|
-
/** Request header to read the token from (`false` to disable). Default `x-<name>-session`. */
|
|
283
|
-
sessionHeader?: false | string;
|
|
284
|
-
/** Session ID (`jti`) generator. Default `crypto.randomUUID`. */
|
|
285
|
-
generateId?: () => string;
|
|
286
|
-
/** JWS sign/verify overrides. Set `signOptions.alg` to pin the session algorithm — verification then accepts only it. */
|
|
287
|
-
jws?: {
|
|
288
|
-
signOptions?: Omit<JWSSignOptions, "expiresIn">;
|
|
289
|
-
verifyOptions?: JWTClaimValidationOptions;
|
|
290
|
-
};
|
|
291
|
-
/** Lifecycle hooks — see {@link SessionHooksJWS}. */
|
|
292
46
|
hooks?: SessionHooksJWS<T, MaxAge, TEvent>;
|
|
293
47
|
}
|
|
294
|
-
/**
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
*/
|
|
308
|
-
declare function
|
|
309
|
-
/**
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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>;
|
|
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 };
|
|
48
|
+
/** Create a JWS (signed, not encrypted) session manager for the request; clients can read its data. */
|
|
49
|
+
export declare function useJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<SessionManager<T, MaxAge>>;
|
|
50
|
+
/** Get (and lazily initialize) the session for the current request. */
|
|
51
|
+
export declare function getJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<SessionJWS<T, MaxAge>>;
|
|
52
|
+
/** Read the raw session token: cookie first, then the session header (default `x-<name>-session`, optional `Bearer`). */
|
|
53
|
+
export declare function getJWSSessionToken<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): string | undefined;
|
|
54
|
+
/** Update the session data (if provided) and reissue the JWS; `options.maxAge` overrides this token's lifetime. */
|
|
55
|
+
export declare function updateJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>, update?: SessionUpdate<T>, options?: SessionIssueOptions): Promise<SessionJWS<T, MaxAge> & {
|
|
56
|
+
id: string;
|
|
57
|
+
token: string;
|
|
58
|
+
}>;
|
|
59
|
+
/** Sign the session as a compact JWS without writing a cookie; fresh `jti` if no ID, no token source needed. */
|
|
60
|
+
export declare function signJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<string>;
|
|
61
|
+
/** Verify a compact JWS into a session, checking `typ`, pinned `alg`, `jti`/`iat` and `exp` (required with `maxAge`). */
|
|
62
|
+
export declare function verifyJWSSession<T extends SessionRecord = 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>>>;
|
|
63
|
+
/** Drop the session cookie and leave an empty session for the rest of the request. */
|
|
64
|
+
export declare function clearJWSSession<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined, TEvent extends HTTPEvent = HTTPEvent>(event: TEvent, config: SessionConfigJWS<T, MaxAge, TEvent>): Promise<void>;
|
|
65
|
+
export { type CompositeKey, type ContentEncryptionAlgorithm, type DeriveKeyOptions, type DeriveKeyReturn, type Duration, type ECDHEphemeralKeyInput, type ExpiresIn, type GenerateJWKOptions, type GenerateJWKReturn, type GenerateKeyAlgorithm, type GenerateKeyOptions, type GenerateKeyReturn, type GeneratedJWKMap, type GeneratedKeyMap, type ImportedKey, type ImportedKeyMap, type JOSEConsumerOptions, type JOSELimits, type JOSEPayload, type JOSEPayloadMode, type JOSEPayloadTypeMap, 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 JWELibraryHeaderName, type JWEMultiDecryptKey, type JWEMultiDecryptOptions, type JWEMultiDecryptResult, type JWEMultiEncryptOptions, type JWEMultiRecipient, type JWEProtectedHeader, type JWK, type JWKAlgorithm, type JWKCacheAdapter, type JWKLookupFunction, type JWKLookupFunctionHeader, type JWKMetadata, 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 JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type MaxTokenAge, type NotBeforeIn, type PayloadOf, type SessionClaims, type SessionConfigJWE, type SessionConfigJWS, type SessionData, type SessionDecryptOptions, type SessionEncryptOptions, type SessionHooksJWE, type SessionHooksJWS, type SessionIssueOptions, type SessionJWE, type SessionJWS, type SessionManager, type SessionSignOptions, type SessionUpdate, type SessionUpdateTrigger, type SessionVerifyOptions, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint };
|