unjwt 0.5.38 → 0.5.39
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 +142 -666
- package/dist/_chunks/chunk.mjs +13 -0
- package/dist/_chunks/h3v1.mjs +598 -0
- package/dist/_chunks/index.d.mts +250 -0
- package/dist/_chunks/index2.d.mts +108 -0
- package/dist/_chunks/jwe.d.mts +43 -0
- package/dist/_chunks/jwe.mjs +132 -0
- package/dist/_chunks/jwk.d.mts +575 -0
- package/dist/_chunks/jwk.mjs +1592 -0
- package/dist/_chunks/jws.d.mts +46 -0
- package/dist/_chunks/jws.mjs +2069 -0
- package/dist/_chunks/utils.mjs +374 -0
- package/dist/adapters/h3.d.mts +3 -267
- package/dist/adapters/h3.mjs +3 -704
- package/dist/adapters/h3v1.d.mts +3 -8
- package/dist/adapters/h3v1.mjs +3 -7
- package/dist/adapters/h3v2.d.mts +145 -146
- package/dist/adapters/h3v2.mjs +505 -594
- package/dist/index.d.mts +6 -8
- package/dist/index.mjs +5 -4
- package/dist/jwe.d.mts +3 -4
- package/dist/jwe.mjs +4 -3
- package/dist/jwk.d.mts +3 -2
- package/dist/jwk.mjs +3 -2
- package/dist/jws.d.mts +3 -3
- package/dist/jws.mjs +4 -3
- package/dist/utils.d.mts +3 -3
- package/dist/utils.mjs +2 -1
- package/package.json +33 -31
- package/dist/shared/unjwt.4JQCoID_.d.mts +0 -161
- package/dist/shared/unjwt.B-v62plj.mjs +0 -249
- package/dist/shared/unjwt.BCi3FEWr.d.mts +0 -328
- package/dist/shared/unjwt.BYDTEWa-.d.mts +0 -269
- package/dist/shared/unjwt.Be8NxwFK.mjs +0 -438
- package/dist/shared/unjwt.BqdNUKDr.d.mts +0 -64
- package/dist/shared/unjwt.CMNtw8ek.d.mts +0 -155
- package/dist/shared/unjwt.Cy2MlkUe.d.mts +0 -174
- package/dist/shared/unjwt.D0_ccT7g.d.mts +0 -166
- package/dist/shared/unjwt.DdLN9vwI.mjs +0 -163
- package/dist/shared/unjwt.Dpl__ZAR.mjs +0 -2121
- package/dist/shared/unjwt.JdKqVANs.d.mts +0 -5
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk.mjs";
|
|
2
|
+
//#region src/core/utils/jwt.ts
|
|
3
|
+
/**
|
|
4
|
+
* Apply default typ/cty semantics shared by JWS & JWE.
|
|
5
|
+
* - If typ is undefined and payload is a non-Uint8Array object, set typ="JWT".
|
|
6
|
+
* - If typ is "JWT" and payload is a non-Uint8Array object, ensure cty defaults to "application/json".
|
|
7
|
+
*/
|
|
8
|
+
function applyTypCtyDefaults(header, payload) {
|
|
9
|
+
const isObjectPayload = typeof payload === "object" && payload !== null && !(payload instanceof Uint8Array);
|
|
10
|
+
if (header.typ === void 0 && isObjectPayload) header.typ = "JWT";
|
|
11
|
+
if (header.typ?.toLowerCase().includes("jwt") && isObjectPayload) header.cty ||= "application/json";
|
|
12
|
+
return header;
|
|
13
|
+
}
|
|
14
|
+
/** Returns true when headers indicate JSON content. */
|
|
15
|
+
function isJWTContent(header) {
|
|
16
|
+
if (!header) return false;
|
|
17
|
+
if (header.typ?.toLowerCase().includes("jwt")) return true;
|
|
18
|
+
const cty = header.cty?.toLowerCase();
|
|
19
|
+
return cty === "json" || cty === "application/json" || !!cty && cty.endsWith("+json");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Given a decoded string and JOSE headers, return an object if JSON, otherwise the string.
|
|
23
|
+
*/
|
|
24
|
+
function decodeMaybeJWTString(decodedString, header) {
|
|
25
|
+
if (isJWTContent(header)) {
|
|
26
|
+
if (decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]")) try {
|
|
27
|
+
return sanitizeObject(JSON.parse(decodedString));
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
return decodedString;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decode a payload that is represented as raw bytes into T | string, honoring forceUint8Array and headers.
|
|
34
|
+
*/
|
|
35
|
+
function decodePayloadFromBytes(bytes, header, forceUint8Array) {
|
|
36
|
+
if (forceUint8Array) return bytes;
|
|
37
|
+
return decodeMaybeJWTString(textDecoder.decode(bytes), header);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Decode a payload that is a Base64URL segment into T | string | Uint8Array based on flags and headers.
|
|
41
|
+
*/
|
|
42
|
+
function decodePayloadFromB64UrlSegment(payloadEncoded, header, forceUint8Array) {
|
|
43
|
+
if (forceUint8Array) return base64UrlDecode(payloadEncoded, false);
|
|
44
|
+
return decodeMaybeJWTString(base64UrlDecode(payloadEncoded), header);
|
|
45
|
+
}
|
|
46
|
+
/** Convert plaintext input to bytes, shared by JWS & JWE when preparing payload. */
|
|
47
|
+
function getPlaintextBytes(payload) {
|
|
48
|
+
if (payload instanceof Uint8Array) return payload;
|
|
49
|
+
if (typeof payload === "string") return textEncoder.encode(payload);
|
|
50
|
+
if (typeof payload === "object" && payload !== null) return textEncoder.encode(JSON.stringify(payload));
|
|
51
|
+
throw new TypeError("Plaintext must be a string, Uint8Array, or a JSON-serializable object.");
|
|
52
|
+
}
|
|
53
|
+
const TIME_CONSTANTS = Object.freeze({
|
|
54
|
+
s: 1,
|
|
55
|
+
second: 1,
|
|
56
|
+
seconds: 1,
|
|
57
|
+
m: 60,
|
|
58
|
+
minute: 60,
|
|
59
|
+
minutes: 60,
|
|
60
|
+
h: 3600,
|
|
61
|
+
hour: 3600,
|
|
62
|
+
hours: 3600,
|
|
63
|
+
D: 86400,
|
|
64
|
+
day: 86400,
|
|
65
|
+
days: 86400,
|
|
66
|
+
W: 604800,
|
|
67
|
+
week: 604800,
|
|
68
|
+
weeks: 604800,
|
|
69
|
+
M: 2592e3,
|
|
70
|
+
month: 2592e3,
|
|
71
|
+
months: 2592e3,
|
|
72
|
+
Y: 31536e3,
|
|
73
|
+
year: 31536e3,
|
|
74
|
+
years: 31536e3
|
|
75
|
+
});
|
|
76
|
+
const EXPIRES_IN_REGEX = /^(\d+)(s|second|seconds|m|minute|minutes|h|hour|hours|D|day|days|W|week|weeks|M|month|months|Y|year|years)?$/;
|
|
77
|
+
function computeExpiresInSeconds(expiresIn) {
|
|
78
|
+
if (typeof expiresIn === "number") {
|
|
79
|
+
if (!Number.isInteger(expiresIn) || expiresIn <= 0) throw new TypeError("If 'expiresIn' is a number, it must be a positive integer representing seconds.");
|
|
80
|
+
return expiresIn;
|
|
81
|
+
}
|
|
82
|
+
if (typeof expiresIn === "string") {
|
|
83
|
+
const match = expiresIn.match(EXPIRES_IN_REGEX);
|
|
84
|
+
if (!match || !match[1]) throw new TypeError("Invalid 'expiresIn' format. Must be a positive integer or a string like '10m', '2h', '7D', etc.");
|
|
85
|
+
return Number.parseInt(match[1], 10) * TIME_CONSTANTS[match[2] || "s"];
|
|
86
|
+
}
|
|
87
|
+
throw new TypeError("'expiresIn' must be a number or a string representing time duration.");
|
|
88
|
+
}
|
|
89
|
+
const computeMaxTokenAgeSeconds = computeExpiresInSeconds;
|
|
90
|
+
/** Optionally compute iat/exp when signing JWTs. */
|
|
91
|
+
function computeJwtTimeClaims(payload, headerTyp, expiresIn, currentDate = /* @__PURE__ */ new Date()) {
|
|
92
|
+
if (expiresIn === void 0 || !headerTyp?.toLowerCase().includes("jwt") || !(payload && typeof payload === "object") || payload instanceof Uint8Array || payload.exp) return;
|
|
93
|
+
const now = Math.round(currentDate.getTime() / 1e3);
|
|
94
|
+
const claims = { ...payload };
|
|
95
|
+
claims.iat ||= now;
|
|
96
|
+
claims.exp = claims.iat + computeExpiresInSeconds(expiresIn);
|
|
97
|
+
return claims;
|
|
98
|
+
}
|
|
99
|
+
/** Validate JWT claims under JWS verification rules (or custom JWE implementations). */
|
|
100
|
+
function validateJwtClaims(jwtClaims, options = {}) {
|
|
101
|
+
const clockTolerance = options.clockTolerance ?? 0;
|
|
102
|
+
const currentTime = Math.round((options.currentDate ?? /* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
103
|
+
const allRequiredClaims = new Set(options.requiredClaims || []);
|
|
104
|
+
const missingClaims = /* @__PURE__ */ new Set();
|
|
105
|
+
if (options.issuer) allRequiredClaims.add("iss");
|
|
106
|
+
if (options.audience) allRequiredClaims.add("aud");
|
|
107
|
+
if (options.subject) allRequiredClaims.add("sub");
|
|
108
|
+
if (options.maxTokenAge) allRequiredClaims.add("iat");
|
|
109
|
+
for (const claimName of allRequiredClaims) if (!(claimName in jwtClaims)) missingClaims.add(claimName);
|
|
110
|
+
if (missingClaims.size > 0) throw new Error(`Missing required JWT Claims: ${[...missingClaims].join(", ")}`);
|
|
111
|
+
if (options.issuer) {
|
|
112
|
+
const expectedIssuers = maybeArray(options.issuer);
|
|
113
|
+
if (!jwtClaims.iss || !expectedIssuers.includes(jwtClaims.iss)) throw new Error(`Invalid JWT "iss" (Issuer) Claim: Expected ${expectedIssuers.join(" or ")}, got ${jwtClaims.iss}`);
|
|
114
|
+
}
|
|
115
|
+
if (options.subject && jwtClaims.sub !== options.subject) throw new Error(`Invalid JWT "sub" (Subject) Claim: Expected ${options.subject}, got ${jwtClaims.sub}`);
|
|
116
|
+
if (options.audience) {
|
|
117
|
+
const expectedAudiences = maybeArray(options.audience);
|
|
118
|
+
const claimAudience = maybeArray(jwtClaims.aud || []);
|
|
119
|
+
if (!claimAudience.some((aud) => expectedAudiences.includes(aud))) throw new Error(`Invalid JWT "aud" (Audience) Claim: Expected ${expectedAudiences.join(" or ")}, got ${claimAudience.join(", ")}`);
|
|
120
|
+
}
|
|
121
|
+
if (typeof jwtClaims.nbf === "number" && jwtClaims.nbf > currentTime + clockTolerance) throw new Error(`JWT "nbf" (Not Before) Claim validation failed: Token is not yet valid (nbf: ${(/* @__PURE__ */ new Date(jwtClaims.nbf * 1e3)).toISOString()})`);
|
|
122
|
+
if (typeof jwtClaims.exp === "number" && jwtClaims.exp <= currentTime - clockTolerance) throw new Error(`JWT "exp" (Expiration Time) Claim validation failed: Token has expired (exp: ${(/* @__PURE__ */ new Date(jwtClaims.exp * 1e3)).toISOString()})`);
|
|
123
|
+
if (options.maxTokenAge) {
|
|
124
|
+
if (typeof jwtClaims.iat !== "number") throw new TypeError("JWT \"iat\" (Issued At) Claim must be a number when maxTokenAge is set.");
|
|
125
|
+
if (jwtClaims.iat > currentTime + clockTolerance) throw new Error(`JWT "iat" (Issued At) Claim validation failed: Token was issued in the future (iat: ${(/* @__PURE__ */ new Date(jwtClaims.iat * 1e3)).toISOString()})`);
|
|
126
|
+
if (jwtClaims.iat < currentTime - computeMaxTokenAgeSeconds(options.maxTokenAge) - clockTolerance) throw new Error(`JWT "iat" (Issued At) Claim validation failed: Token is too old (maxTokenAge: ${options.maxTokenAge}s, iat: ${(/* @__PURE__ */ new Date(jwtClaims.iat * 1e3)).toISOString()})`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const BASE_HEADER_PARAMS = [
|
|
130
|
+
"alg",
|
|
131
|
+
"typ",
|
|
132
|
+
"cty",
|
|
133
|
+
"kid",
|
|
134
|
+
"jwk",
|
|
135
|
+
"jku",
|
|
136
|
+
"x5c",
|
|
137
|
+
"x5t",
|
|
138
|
+
"x5u"
|
|
139
|
+
];
|
|
140
|
+
/** Validate critical headers in JWS semantics. */
|
|
141
|
+
function validateCriticalHeadersJWS(protectedHeader, requiredHeaders = []) {
|
|
142
|
+
if (!protectedHeader.crit) return;
|
|
143
|
+
const missingHeaderParams = /* @__PURE__ */ new Set();
|
|
144
|
+
const recognizedParams = new Set([
|
|
145
|
+
...requiredHeaders,
|
|
146
|
+
...BASE_HEADER_PARAMS,
|
|
147
|
+
"b64"
|
|
148
|
+
]);
|
|
149
|
+
for (const param of protectedHeader.crit) {
|
|
150
|
+
if (recognizedParams.has(param) && (param in protectedHeader || param === "b64")) continue;
|
|
151
|
+
missingHeaderParams.add(param);
|
|
152
|
+
}
|
|
153
|
+
if (missingHeaderParams.size > 0) throw new Error(`Missing critical header parameters: ${[...missingHeaderParams].join(", ")}`);
|
|
154
|
+
}
|
|
155
|
+
/** Validate critical headers in JWE semantics. */
|
|
156
|
+
function validateCriticalHeadersJWE(protectedHeader, understoodFromOptions) {
|
|
157
|
+
if (protectedHeader.crit && !understoodFromOptions) throw new Error(`Unprocessed critical header parameters: ${protectedHeader.crit.join(", ")}`);
|
|
158
|
+
if (!protectedHeader.crit) return;
|
|
159
|
+
const understoodParams = new Set([
|
|
160
|
+
...understoodFromOptions || [],
|
|
161
|
+
...BASE_HEADER_PARAMS,
|
|
162
|
+
"enc",
|
|
163
|
+
"iv",
|
|
164
|
+
"tag",
|
|
165
|
+
"p2s",
|
|
166
|
+
"p2c",
|
|
167
|
+
"epk",
|
|
168
|
+
"apu",
|
|
169
|
+
"apv"
|
|
170
|
+
]);
|
|
171
|
+
for (const critParam of protectedHeader.crit) {
|
|
172
|
+
if (!Object.prototype.hasOwnProperty.call(protectedHeader, critParam)) throw new Error(`Critical header parameter "${critParam}" listed in "crit" but not present in the protected header.`);
|
|
173
|
+
if (!understoodParams.has(critParam)) throw new Error(`Unprocessed critical header parameters: ${critParam}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/core/utils/sanitize.ts
|
|
178
|
+
/**
|
|
179
|
+
* Forked from unsecure@0.0.4
|
|
180
|
+
* Licensed under the MIT License.
|
|
181
|
+
*
|
|
182
|
+
* Source: https://github.com/sandros94/unsecure/blob/913ed5580c551153a19154b4916c67a8efb2be85/src/sanitize.ts
|
|
183
|
+
*/
|
|
184
|
+
/**
|
|
185
|
+
* Remove prototype-pollution vectors from a plain record in-place.
|
|
186
|
+
* This strips __proto__, prototype, and constructor own properties.
|
|
187
|
+
* Returns the same reference for convenience.
|
|
188
|
+
*/
|
|
189
|
+
function sanitizeObject(obj) {
|
|
190
|
+
if (!obj || typeof obj !== "object") return obj;
|
|
191
|
+
sanitizeKeys(obj);
|
|
192
|
+
return obj;
|
|
193
|
+
}
|
|
194
|
+
function sanitizeKeys(current, seen) {
|
|
195
|
+
if (Object.prototype.hasOwnProperty.call(current, "__proto__")) delete current["__proto__"];
|
|
196
|
+
if (Object.prototype.hasOwnProperty.call(current, "prototype")) delete current["prototype"];
|
|
197
|
+
if (Object.prototype.hasOwnProperty.call(current, "constructor")) delete current["constructor"];
|
|
198
|
+
const items = Array.isArray(current) ? current : Object.values(current);
|
|
199
|
+
for (const v of items) if (v && typeof v === "object") {
|
|
200
|
+
seen ??= /* @__PURE__ */ new WeakSet();
|
|
201
|
+
if (!seen.has(v)) {
|
|
202
|
+
seen.add(v);
|
|
203
|
+
sanitizeKeys(v, seen);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/core/utils/index.ts
|
|
209
|
+
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
210
|
+
applyTypCtyDefaults: () => applyTypCtyDefaults,
|
|
211
|
+
assertCryptoKey: () => assertCryptoKey,
|
|
212
|
+
base64Decode: () => base64Decode,
|
|
213
|
+
base64Encode: () => base64Encode,
|
|
214
|
+
base64UrlDecode: () => base64UrlDecode,
|
|
215
|
+
base64UrlEncode: () => base64UrlEncode,
|
|
216
|
+
computeExpiresInSeconds: () => computeExpiresInSeconds,
|
|
217
|
+
computeJwtTimeClaims: () => computeJwtTimeClaims,
|
|
218
|
+
computeMaxTokenAgeSeconds: () => computeMaxTokenAgeSeconds,
|
|
219
|
+
concatUint8Arrays: () => concatUint8Arrays,
|
|
220
|
+
decodeMaybeJWTString: () => decodeMaybeJWTString,
|
|
221
|
+
decodePayloadFromB64UrlSegment: () => decodePayloadFromB64UrlSegment,
|
|
222
|
+
decodePayloadFromBytes: () => decodePayloadFromBytes,
|
|
223
|
+
getPlaintextBytes: () => getPlaintextBytes,
|
|
224
|
+
isAsymmetricJWK: () => isAsymmetricJWK,
|
|
225
|
+
isCryptoKey: () => isCryptoKey,
|
|
226
|
+
isCryptoKeyPair: () => isCryptoKeyPair,
|
|
227
|
+
isJWK: () => isJWK,
|
|
228
|
+
isJWKSet: () => isJWKSet,
|
|
229
|
+
isJWTContent: () => isJWTContent,
|
|
230
|
+
isPrivateJWK: () => isPrivateJWK,
|
|
231
|
+
isPublicJWK: () => isPublicJWK,
|
|
232
|
+
isSymmetricJWK: () => isSymmetricJWK,
|
|
233
|
+
maybeArray: () => maybeArray,
|
|
234
|
+
randomBytes: () => randomBytes,
|
|
235
|
+
sanitizeObject: () => sanitizeObject,
|
|
236
|
+
textDecoder: () => textDecoder,
|
|
237
|
+
textEncoder: () => textEncoder,
|
|
238
|
+
validateCriticalHeadersJWE: () => validateCriticalHeadersJWE,
|
|
239
|
+
validateCriticalHeadersJWS: () => validateCriticalHeadersJWS,
|
|
240
|
+
validateJwtClaims: () => validateJwtClaims
|
|
241
|
+
});
|
|
242
|
+
const textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
243
|
+
const textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
244
|
+
const _Buffer = /* @__PURE__ */ (() => {
|
|
245
|
+
try {
|
|
246
|
+
return globalThis.Buffer;
|
|
247
|
+
} catch {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
})();
|
|
251
|
+
const _hasBuffer = typeof _Buffer?.from === "function";
|
|
252
|
+
const _hasToBase64 = !_hasBuffer && typeof Uint8Array.prototype.toBase64 === "function";
|
|
253
|
+
const _hasFromBase64 = !_hasBuffer && typeof Uint8Array.fromBase64 === "function";
|
|
254
|
+
const _b64UrlEncOpts = /* @__PURE__ */ Object.freeze({
|
|
255
|
+
alphabet: "base64url",
|
|
256
|
+
omitPadding: true
|
|
257
|
+
});
|
|
258
|
+
const _b64UrlDecOpts = /* @__PURE__ */ Object.freeze({ alphabet: "base64url" });
|
|
259
|
+
function _toBuffer(data) {
|
|
260
|
+
return data instanceof Uint8Array ? _Buffer.from(data.buffer, data.byteOffset, data.byteLength) : _Buffer.from(data);
|
|
261
|
+
}
|
|
262
|
+
function base64Encode(data) {
|
|
263
|
+
if (_hasBuffer) return _toBuffer(data).toString("base64");
|
|
264
|
+
const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
|
|
265
|
+
if (_hasToBase64) return encodedData.toBase64();
|
|
266
|
+
return btoa(String.fromCodePoint(...encodedData));
|
|
267
|
+
}
|
|
268
|
+
function base64UrlEncode(data) {
|
|
269
|
+
if (_hasBuffer) return _toBuffer(data).toString("base64url");
|
|
270
|
+
const encodedData = data instanceof Uint8Array ? data : textEncoder.encode(data);
|
|
271
|
+
if (_hasToBase64) return encodedData.toBase64(_b64UrlEncOpts);
|
|
272
|
+
return btoa(String.fromCodePoint(...encodedData)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
273
|
+
}
|
|
274
|
+
function base64Decode(str, toString) {
|
|
275
|
+
const decodeToString = toString !== false;
|
|
276
|
+
if (!str) return decodeToString ? "" : new Uint8Array(0);
|
|
277
|
+
if (_hasBuffer) {
|
|
278
|
+
const buf = _Buffer.from(str, "base64");
|
|
279
|
+
return decodeToString ? buf.toString("utf8") : new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
280
|
+
}
|
|
281
|
+
const data = _hasFromBase64 ? Uint8Array.fromBase64(str) : Uint8Array.from(atob(str), (b) => b.codePointAt(0));
|
|
282
|
+
return decodeToString ? textDecoder.decode(data) : data;
|
|
283
|
+
}
|
|
284
|
+
function base64UrlDecode(str, toString) {
|
|
285
|
+
const decodeToString = toString !== false;
|
|
286
|
+
if (!str) return decodeToString ? "" : new Uint8Array(0);
|
|
287
|
+
if (_hasBuffer) {
|
|
288
|
+
const buf = _Buffer.from(str, "base64url");
|
|
289
|
+
return decodeToString ? buf.toString("utf8") : new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
290
|
+
}
|
|
291
|
+
let data;
|
|
292
|
+
if (_hasFromBase64) data = Uint8Array.fromBase64(str, _b64UrlDecOpts);
|
|
293
|
+
else {
|
|
294
|
+
str = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
295
|
+
while (str.length % 4) str += "=";
|
|
296
|
+
data = Uint8Array.from(atob(str), (b) => b.codePointAt(0));
|
|
297
|
+
}
|
|
298
|
+
return decodeToString ? textDecoder.decode(data) : data;
|
|
299
|
+
}
|
|
300
|
+
function randomBytes(length) {
|
|
301
|
+
return crypto.getRandomValues(new Uint8Array(length));
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Concatenates multiple Uint8Arrays
|
|
305
|
+
* @param arrays Arrays to concatenate
|
|
306
|
+
* @returns Concatenated array
|
|
307
|
+
*/
|
|
308
|
+
function concatUint8Arrays(...arrays) {
|
|
309
|
+
const totalLength = arrays.reduce((length, arr) => length + arr.length, 0);
|
|
310
|
+
const result = new Uint8Array(totalLength);
|
|
311
|
+
let offset = 0;
|
|
312
|
+
for (const arr of arrays) {
|
|
313
|
+
result.set(arr, offset);
|
|
314
|
+
offset += arr.length;
|
|
315
|
+
}
|
|
316
|
+
return result;
|
|
317
|
+
}
|
|
318
|
+
function maybeArray(item) {
|
|
319
|
+
return Array.isArray(item) ? item : [item];
|
|
320
|
+
}
|
|
321
|
+
function isJWK(key) {
|
|
322
|
+
return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
|
|
323
|
+
}
|
|
324
|
+
function isJWKSet(key) {
|
|
325
|
+
return key && typeof key === "object" && "keys" in key && Array.isArray(key.keys);
|
|
326
|
+
}
|
|
327
|
+
function assertCryptoKey(key) {
|
|
328
|
+
if (!isCryptoKey(key)) throw new Error("CryptoKey instance expected");
|
|
329
|
+
}
|
|
330
|
+
function isCryptoKey(key) {
|
|
331
|
+
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
332
|
+
}
|
|
333
|
+
const isCryptoKeyPair = (key) => key && typeof key === "object" && isCryptoKey(key.publicKey) && isCryptoKey(key.privateKey);
|
|
334
|
+
/** Returns true if the JWK is a symmetric (oct) key. */
|
|
335
|
+
function isSymmetricJWK(key) {
|
|
336
|
+
return isJWK(key) && key.kty === "oct" && typeof key.k === "string";
|
|
337
|
+
}
|
|
338
|
+
/** Returns true if the JWK is an asymmetric (RSA, EC, OKP) key. */
|
|
339
|
+
function isAsymmetricJWK(key) {
|
|
340
|
+
return !isSymmetricJWK(key);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Type guard that checks if the provided JWK contains private key material.
|
|
344
|
+
* It relies purely on the presence of private components (e.g. "d"), not on the alg value.
|
|
345
|
+
*/
|
|
346
|
+
function isPrivateJWK(key) {
|
|
347
|
+
if (!isJWK(key)) return false;
|
|
348
|
+
if (key.kty === "EC") return typeof key.d === "string";
|
|
349
|
+
if (key.kty === "OKP") return typeof key.d === "string";
|
|
350
|
+
if (key.kty === "RSA") return typeof key.d === "string";
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Type guard that checks if the provided JWK is a public (asymmetric) key.
|
|
355
|
+
* This checks for the presence of public components and absence of private material.
|
|
356
|
+
*/
|
|
357
|
+
function isPublicJWK(key) {
|
|
358
|
+
if (!isJWK(key)) return false;
|
|
359
|
+
if (key.kty === "EC") {
|
|
360
|
+
const ec = key;
|
|
361
|
+
return typeof ec.x === "string" && typeof ec.y === "string" && typeof ec.d !== "string";
|
|
362
|
+
}
|
|
363
|
+
if (key.kty === "OKP") {
|
|
364
|
+
const okp = key;
|
|
365
|
+
return typeof okp.x === "string" && typeof okp.d !== "string";
|
|
366
|
+
}
|
|
367
|
+
if (key.kty === "RSA") {
|
|
368
|
+
const rsa = key;
|
|
369
|
+
return typeof rsa.n === "string" && typeof rsa.e === "string" && typeof rsa.d !== "string";
|
|
370
|
+
}
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
374
|
+
export { validateCriticalHeadersJWE as A, computeJwtTimeClaims as C, decodePayloadFromBytes as D, decodePayloadFromB64UrlSegment as E, validateJwtClaims as M, getPlaintextBytes as O, computeExpiresInSeconds as S, decodeMaybeJWTString as T, textDecoder as _, base64UrlEncode as a, sanitizeObject as b, isCryptoKey as c, isJWKSet as d, isPrivateJWK as f, randomBytes as g, maybeArray as h, base64UrlDecode as i, validateCriticalHeadersJWS as j, isJWTContent as k, isCryptoKeyPair as l, isSymmetricJWK as m, base64Decode as n, concatUint8Arrays as o, isPublicJWK as p, base64Encode as r, isAsymmetricJWK as s, assertCryptoKey as t, isJWK as u, textEncoder as v, computeMaxTokenAgeSeconds as w, applyTypCtyDefaults as x, utils_exports as y };
|
package/dist/adapters/h3.d.mts
CHANGED
|
@@ -1,267 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
import { S as StrictOmit } from '../shared/unjwt.JdKqVANs.mjs';
|
|
6
|
-
import { CookieSerializeOptions } from 'cookie-es';
|
|
7
|
-
import { H3Event } from 'h3';
|
|
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
|
-
|
|
11
|
-
interface SessionClaims extends Required<Pick<JWTClaims, "jti" | "iat">>, StrictOmit<JWTClaims, "jti" | "iat"> {
|
|
12
|
-
}
|
|
13
|
-
type SessionData<T extends Record<string, any> = SessionClaims> = StrictOmit<T, "jti" | "iat" | "exp">;
|
|
14
|
-
type SessionUpdate<T extends Record<string, any> = SessionClaims> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
15
|
-
interface SessionManager<T extends Record<string, any> = SessionClaims, ConfigMaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
16
|
-
readonly id: string | undefined;
|
|
17
|
-
readonly createdAt: number;
|
|
18
|
-
readonly expiresAt: ConfigMaxAge extends ExpiresIn ? number : "exp" extends keyof T ? T["exp"] : number | undefined;
|
|
19
|
-
readonly data: SessionData<T>;
|
|
20
|
-
readonly token: string | undefined;
|
|
21
|
-
update: (update: SessionUpdate<T>) => Promise<SessionManager<T, ConfigMaxAge> & {
|
|
22
|
-
readonly id: string;
|
|
23
|
-
}>;
|
|
24
|
-
clear: () => Promise<SessionManager<T, ConfigMaxAge>>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* This is a fork of h3 library's session utility functions.
|
|
29
|
-
* @source https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/src/utils/session.ts
|
|
30
|
-
* @license MIT https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/LICENSE
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
declare const kGetSessionPromise$1: unique symbol;
|
|
34
|
-
interface SessionJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
35
|
-
id: string | undefined;
|
|
36
|
-
createdAt: number;
|
|
37
|
-
expiresAt: MaxAge extends ExpiresIn ? number : T["exp"];
|
|
38
|
-
data: SessionData<T>;
|
|
39
|
-
[kGetSessionPromise$1]?: Promise<SessionJWE<T, MaxAge>>;
|
|
40
|
-
}
|
|
41
|
-
interface SessionHooksJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
42
|
-
onRead?: (args: {
|
|
43
|
-
session: SessionJWE<T, MaxAge>;
|
|
44
|
-
event: H3Event;
|
|
45
|
-
config: SessionConfigJWE<T, MaxAge>;
|
|
46
|
-
}) => void | Promise<void>;
|
|
47
|
-
onUpdate?: (args: {
|
|
48
|
-
session: SessionJWE<T, MaxAge>;
|
|
49
|
-
oldSession: SessionJWE<T, MaxAge>;
|
|
50
|
-
event: H3Event;
|
|
51
|
-
config: SessionConfigJWE<T, MaxAge>;
|
|
52
|
-
}) => void | Promise<void>;
|
|
53
|
-
onClear?: (args: {
|
|
54
|
-
session: SessionJWE<T, MaxAge> | undefined;
|
|
55
|
-
event: H3Event;
|
|
56
|
-
config: Partial<SessionConfigJWE<T, MaxAge>>;
|
|
57
|
-
}) => void | Promise<void>;
|
|
58
|
-
onExpire?: (args: {
|
|
59
|
-
event: H3Event;
|
|
60
|
-
error: Error;
|
|
61
|
-
config: SessionConfigJWE<T, MaxAge>;
|
|
62
|
-
}) => void | Promise<void>;
|
|
63
|
-
onError?: (args: {
|
|
64
|
-
event: H3Event;
|
|
65
|
-
error: any;
|
|
66
|
-
config: SessionConfigJWE<T, MaxAge>;
|
|
67
|
-
}) => void | Promise<void>;
|
|
68
|
-
onUnsealKeyLookup?: (args: {
|
|
69
|
-
header: JWEHeaderParameters;
|
|
70
|
-
event: H3Event;
|
|
71
|
-
config: SessionConfigJWE<T, MaxAge>;
|
|
72
|
-
}) => JWK_Symmetric | JWK_Private | Promise<JWK_Symmetric | JWK_Private>;
|
|
73
|
-
}
|
|
74
|
-
interface SessionConfigJWE<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
75
|
-
/** @deprecated use `key` instead */
|
|
76
|
-
secret?: string | JWK_Symmetric | {
|
|
77
|
-
privateKey: JWK_Private | JWK_Symmetric;
|
|
78
|
-
publicKey?: JWK_Public;
|
|
79
|
-
};
|
|
80
|
-
/** Shared key used, string for PBES2 or Json Web Key (JWK) */
|
|
81
|
-
key: string | JWK_Symmetric | JWK_Private | {
|
|
82
|
-
privateKey: JWK_Private | JWK_Symmetric;
|
|
83
|
-
publicKey?: JWK_Public;
|
|
84
|
-
};
|
|
85
|
-
/** Session lifetime in seconds (used to derive exp from iat) */
|
|
86
|
-
maxAge?: MaxAge;
|
|
87
|
-
/** Default is "h3" */
|
|
88
|
-
name?: string;
|
|
89
|
-
/** Default is secure, httpOnly, path="/" */
|
|
90
|
-
cookie?: false | CookieSerializeOptions;
|
|
91
|
-
/** Default is x-h3-session / x-{name}-session */
|
|
92
|
-
sessionHeader?: false | string;
|
|
93
|
-
/** Default is crypto.randomUUID */
|
|
94
|
-
generateId?: () => string;
|
|
95
|
-
/** JWE configuration overrides */
|
|
96
|
-
jwe?: {
|
|
97
|
-
encryptOptions?: Omit<JWEEncryptOptions, "expiresIn">;
|
|
98
|
-
decryptOptions?: JWTClaimValidationOptions;
|
|
99
|
-
};
|
|
100
|
-
hooks?: SessionHooksJWE<T, MaxAge>;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* @deprecated use `SessionConfigJWE` instead
|
|
104
|
-
*/
|
|
105
|
-
type SessionJWEConfig = SessionConfigJWE;
|
|
106
|
-
type CompatEvent$1 = {
|
|
107
|
-
request: {
|
|
108
|
-
headers: Headers;
|
|
109
|
-
};
|
|
110
|
-
context: any;
|
|
111
|
-
} | {
|
|
112
|
-
headers: Headers;
|
|
113
|
-
context: any;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Create a session manager for the current request.
|
|
117
|
-
*/
|
|
118
|
-
declare function useJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
119
|
-
/**
|
|
120
|
-
* Get (and lazily initialize) the session for the current request.
|
|
121
|
-
*/
|
|
122
|
-
declare function getJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<SessionJWE<T, MaxAge>>;
|
|
123
|
-
declare function getJWESessionToken<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): string | undefined;
|
|
124
|
-
/**
|
|
125
|
-
* Update the session (optionally mutating the session data) and re-issue the JWE token.
|
|
126
|
-
*/
|
|
127
|
-
declare function updateJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event, config: SessionConfigJWE<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWE<T, MaxAge>>;
|
|
128
|
-
/**
|
|
129
|
-
* Produce a JWE for the current session.
|
|
130
|
-
* Payload structure:
|
|
131
|
-
* {
|
|
132
|
-
* jti: string;
|
|
133
|
-
* iat: number; (seconds)
|
|
134
|
-
* exp?: number; (seconds)
|
|
135
|
-
* data: Record<string, any>;
|
|
136
|
-
* }
|
|
137
|
-
*/
|
|
138
|
-
declare function sealJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<string>;
|
|
139
|
-
/**
|
|
140
|
-
* Decrypt the JWE and return a Session-compatible object.
|
|
141
|
-
*/
|
|
142
|
-
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>>>;
|
|
143
|
-
/**
|
|
144
|
-
* Clear the session (delete from context and drop cookie).
|
|
145
|
-
*/
|
|
146
|
-
declare function clearJWESession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event, config: Partial<SessionConfigJWE<T, MaxAge>>): Promise<void>;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* This is a fork of h3 library's session utility functions.
|
|
150
|
-
* @source https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/src/utils/session.ts
|
|
151
|
-
* @license MIT https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/LICENSE
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
declare const kGetSessionPromise: unique symbol;
|
|
155
|
-
interface SessionJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
156
|
-
id: string | undefined;
|
|
157
|
-
createdAt: number;
|
|
158
|
-
expiresAt: MaxAge extends ExpiresIn ? number : T["exp"];
|
|
159
|
-
data: SessionData<T>;
|
|
160
|
-
[kGetSessionPromise]?: Promise<SessionJWS<T, MaxAge>>;
|
|
161
|
-
}
|
|
162
|
-
interface SessionHooksJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
163
|
-
onRead?: (args: {
|
|
164
|
-
session: SessionJWS<T, MaxAge>;
|
|
165
|
-
event: H3Event;
|
|
166
|
-
config: SessionConfigJWS<T, MaxAge>;
|
|
167
|
-
}) => void | Promise<void>;
|
|
168
|
-
onUpdate?: (args: {
|
|
169
|
-
session: SessionJWS<T, MaxAge>;
|
|
170
|
-
oldSession: SessionJWS<T, MaxAge>;
|
|
171
|
-
event: H3Event;
|
|
172
|
-
config: SessionConfigJWS<T, MaxAge>;
|
|
173
|
-
}) => void | Promise<void>;
|
|
174
|
-
onClear?: (args: {
|
|
175
|
-
session: SessionJWS<T, MaxAge> | undefined;
|
|
176
|
-
event: H3Event;
|
|
177
|
-
config: Partial<SessionConfigJWS<T, MaxAge>>;
|
|
178
|
-
}) => void | Promise<void>;
|
|
179
|
-
onExpire?: (args: {
|
|
180
|
-
event: H3Event;
|
|
181
|
-
error: Error;
|
|
182
|
-
config: SessionConfigJWS<T, MaxAge>;
|
|
183
|
-
}) => void | Promise<void>;
|
|
184
|
-
onError?: (args: {
|
|
185
|
-
event: H3Event;
|
|
186
|
-
error: any;
|
|
187
|
-
config: SessionConfigJWS<T, MaxAge>;
|
|
188
|
-
}) => void | Promise<void>;
|
|
189
|
-
onVerifyKeyLookup?: (args: {
|
|
190
|
-
header: JWSProtectedHeader;
|
|
191
|
-
event: H3Event;
|
|
192
|
-
config: SessionConfigJWS<T, MaxAge>;
|
|
193
|
-
}) => JWKSet | JWK_Symmetric | JWK_Public | Promise<JWKSet | JWK_Symmetric | JWK_Public>;
|
|
194
|
-
}
|
|
195
|
-
interface SessionConfigJWS<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> {
|
|
196
|
-
/**
|
|
197
|
-
* JWK (private for signing with RS/ES/PS, or symmetric oct) used for signing.
|
|
198
|
-
*/
|
|
199
|
-
key: JWK_Symmetric | {
|
|
200
|
-
privateKey: JWK_Private;
|
|
201
|
-
publicKey: JWK_Public | JWK_Public[] | JWKSet;
|
|
202
|
-
};
|
|
203
|
-
/** Session lifetime in seconds (sets exp = iat + maxAge) */
|
|
204
|
-
maxAge?: MaxAge;
|
|
205
|
-
/** Default cookie / header name base */
|
|
206
|
-
name?: string;
|
|
207
|
-
/** Cookie options (false to disable cookies) */
|
|
208
|
-
cookie?: false | CookieSerializeOptions;
|
|
209
|
-
/** Custom header (false to disable header lookup) */
|
|
210
|
-
sessionHeader?: false | string;
|
|
211
|
-
/** Custom ID generator (defaults to crypto.randomUUID) */
|
|
212
|
-
generateId?: () => string;
|
|
213
|
-
/** JWS customization */
|
|
214
|
-
jws?: {
|
|
215
|
-
signOptions?: Omit<JWSSignOptions, "expiresIn">;
|
|
216
|
-
verifyOptions?: JWTClaimValidationOptions;
|
|
217
|
-
};
|
|
218
|
-
hooks?: SessionHooksJWS<T, MaxAge>;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* @deprecated use `SessionConfigJWS` instead
|
|
222
|
-
*/
|
|
223
|
-
type SessionJWSConfig = SessionConfigJWS;
|
|
224
|
-
type CompatEvent = {
|
|
225
|
-
request: {
|
|
226
|
-
headers: Headers;
|
|
227
|
-
};
|
|
228
|
-
context: any;
|
|
229
|
-
} | {
|
|
230
|
-
headers: Headers;
|
|
231
|
-
context: any;
|
|
232
|
-
};
|
|
233
|
-
/**
|
|
234
|
-
* Create a session manager for the current request using JWS (signed only, not encrypted).
|
|
235
|
-
* NOTE: Contents are visible to clients (Base64URL-decoded JSON). Do not store secrets in session data.
|
|
236
|
-
*/
|
|
237
|
-
declare function useJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
238
|
-
/**
|
|
239
|
-
* Retrieve (and lazily initialize) the session.
|
|
240
|
-
*/
|
|
241
|
-
declare function getJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionJWS<T, MaxAge>>;
|
|
242
|
-
/**
|
|
243
|
-
* Update session data (if provided) and reissue JWS.
|
|
244
|
-
*/
|
|
245
|
-
declare function updateJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event, config: SessionConfigJWS<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWS<T, MaxAge>>;
|
|
246
|
-
/**
|
|
247
|
-
* Sign current session as a compact JWS.
|
|
248
|
-
* Payload claims:
|
|
249
|
-
* jti, iat, exp?, data, plus optional extraClaims (cannot override reserved)
|
|
250
|
-
*/
|
|
251
|
-
declare function signJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>): Promise<string>;
|
|
252
|
-
/**
|
|
253
|
-
* Verify and parse a compact JWS into a Session structure.
|
|
254
|
-
* Performs:
|
|
255
|
-
* - cryptographic signature verification
|
|
256
|
-
* - (optional) standard claim checks if validateJWT true
|
|
257
|
-
* - ensures jti & iat presence
|
|
258
|
-
* - enforces maxAge if provided
|
|
259
|
-
*/
|
|
260
|
-
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>>>;
|
|
261
|
-
/**
|
|
262
|
-
* Destroy the session (context + cookie).
|
|
263
|
-
*/
|
|
264
|
-
declare function clearJWSSession<T extends Record<string, any> = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined>(event: H3Event, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
|
|
265
|
-
|
|
266
|
-
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 };
|
|
267
|
-
export type { SessionClaims, SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate };
|
|
1
|
+
import { $ as JWK_RSA_ENC, A as JWKPEMAlgorithm, B as JWK_ECDH_ES, C as GenerateJWKOptions, D as GenerateKeyReturn, E as GenerateKeyOptions, F as JWK_AES_GCM_KW, G as JWK_OKP, H as JWK_EC_Private, I as JWK_AES_KW, J as JWK_OKP_SIGN, K as JWK_OKP_Private, L as JWK_Asymmetric, M as JWKSet, N as JWK_AES_CBC_HMAC, O as JWK, P as JWK_AES_GCM, Q as JWK_RSA, R as JWK_Asymmetric_Algorithm, S as DeriveKeyReturn, T as GenerateKeyAlgorithm, U as JWK_EC_Public, V as JWK_ECDSA, W as JWK_HMAC, X as JWK_Private, Y as JWK_PBES2, Z as JWK_Public, a as JWEDecryptOptions, at as JWK_Symmetric_Algorithm, b as ContentEncryptionAlgorithm, c as JWEHeaderParameters, ct as UnwrapKeyOptions, et as JWK_RSA_PSS, f as JWT, h as JoseHeaderParameters, i as importJWKFromPEM, it as JWK_Symmetric, j as JWKParameters, k as JWKAlgorithm, l as JWEKeyLookupFunction, lt as WrapKeyOptions, m as JWTClaims, n as exportJWKToPEM, nt as JWK_RSA_Public, o as JWEDecryptResult, ot as JWK_oct, p as JWTClaimValidationOptions, q as JWK_OKP_Public, r as generateJWK, rt as JWK_RSA_SIGN, s as JWEEncryptOptions, st as KeyManagementAlgorithm, t as deriveJWKFromPassword, tt as JWK_RSA_Private, u as JWEKeyManagementHeaderParameters, ut as WrapKeyResult, w as GenerateJWKReturn, x as DeriveKeyOptions, y as CompositeKey, z as JWK_EC } from "../_chunks/jwk.mjs";
|
|
2
|
+
import { C as SessionData, S as SessionClaims, T as SessionUpdate, _ as getJWESessionToken, a as clearJWSSession, b as updateJWESession, c as updateJWSSession, d as SessionConfigJWE, f as SessionHooksJWE, g as getJWESession, h as clearJWESession, i as SessionJWSConfig, l as useJWSSession, m as SessionJWEConfig, n as SessionHooksJWS, o as getJWSSession, p as SessionJWE, r as SessionJWS, s as signJWSSession, t as SessionConfigJWS, u as verifyJWSSession, v as sealJWESession, w as SessionManager, x as useJWESession, y as unsealJWESession } from "../_chunks/index.mjs";
|
|
3
|
+
export { CompositeKey, ContentEncryptionAlgorithm, DeriveKeyOptions, DeriveKeyReturn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, JWEDecryptOptions, JWEDecryptResult, JWEEncryptOptions, JWEHeaderParameters, JWEKeyLookupFunction, JWEKeyManagementHeaderParameters, JWK, JWKAlgorithm, 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_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, JWT, JWTClaimValidationOptions, JWTClaims, JoseHeaderParameters, KeyManagementAlgorithm, SessionClaims, SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate, UnwrapKeyOptions, WrapKeyOptions, WrapKeyResult, clearJWESession, clearJWSSession, deriveJWKFromPassword, exportJWKToPEM, generateJWK, getJWESession, getJWESessionToken, getJWSSession, importJWKFromPEM, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|