unjwt 0.8.3 → 0.8.5

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.
Files changed (54) hide show
  1. package/README.md +3 -9
  2. package/dist/_chunks/algorithms.mjs +1541 -0
  3. package/dist/_chunks/{_codec-jwe.d.mts → codec-jwe.d.mts} +40 -9
  4. package/dist/_chunks/{_codec-jws.mjs → codec-jws.mjs} +148 -95
  5. package/dist/_chunks/cookie.mjs +50 -0
  6. package/dist/_chunks/digest.mjs +10 -3
  7. package/dist/_chunks/error.d.mts +103 -0
  8. package/dist/_chunks/export.mjs +97 -0
  9. package/dist/_chunks/index.d.mts +5 -103
  10. package/dist/_chunks/index2.d.mts +206 -12
  11. package/dist/_chunks/index3.d.mts +12 -109
  12. package/dist/_chunks/{jwe.d.mts → index4.d.mts} +3 -1
  13. package/dist/_chunks/{jws.d.mts → index5.d.mts} +6 -2
  14. package/dist/_chunks/index6.d.mts +113 -0
  15. package/dist/_chunks/jwe.mjs +208 -74
  16. package/dist/_chunks/jwk.mjs +214 -2237
  17. package/dist/_chunks/jws.mjs +289 -202
  18. package/dist/_chunks/jwt.d.mts +2 -1
  19. package/dist/_chunks/{_jwt-internal.mjs → jwt.mjs} +124 -68
  20. package/dist/_chunks/libs/unsecure.d.mts +35 -25
  21. package/dist/_chunks/libs/unsecure.mjs +148 -302
  22. package/dist/_chunks/{_internal.d.mts → limits.d.mts} +1 -1
  23. package/dist/_chunks/payload.mjs +23 -0
  24. package/dist/_chunks/wrap.mjs +209 -0
  25. package/dist/adapters/elysia/index.d.mts +4 -4
  26. package/dist/adapters/elysia/index.mjs +5 -3
  27. package/dist/adapters/h3/index.d.mts +13 -13
  28. package/dist/adapters/h3/index.mjs +8 -10
  29. package/dist/adapters/h3v1/index.d.mts +5 -5
  30. package/dist/adapters/h3v1/index.mjs +6 -8
  31. package/dist/core/internal.mjs +1 -1
  32. package/dist/core/{jwe.d.mts → jwe/index.d.mts} +5 -4
  33. package/dist/core/jwe/index.mjs +5 -0
  34. package/dist/core/jwk/index.d.mts +6 -0
  35. package/dist/core/jwk/index.mjs +7 -0
  36. package/dist/core/{jws.d.mts → jws/index.d.mts} +5 -4
  37. package/dist/core/jws/index.mjs +5 -0
  38. package/dist/dpop/index.d.mts +73 -0
  39. package/dist/dpop/index.mjs +296 -0
  40. package/dist/error.d.mts +3 -0
  41. package/dist/error.mjs +20 -0
  42. package/dist/index.d.mts +10 -9
  43. package/dist/index.mjs +7 -3
  44. package/dist/session/index.d.mts +4 -4
  45. package/dist/session/index.mjs +6 -46
  46. package/dist/utils/index.d.mts +7 -0
  47. package/dist/{core/utils → utils}/index.mjs +4 -3
  48. package/package.json +22 -10
  49. package/dist/core/jwe.mjs +0 -5
  50. package/dist/core/jwk.d.mts +0 -207
  51. package/dist/core/jwk.mjs +0 -4
  52. package/dist/core/jws.mjs +0 -5
  53. package/dist/core/utils/index.d.mts +0 -6
  54. /package/dist/_chunks/{_cookie-attributes.d.mts → cookie-attributes.d.mts} +0 -0
@@ -0,0 +1,296 @@
1
+ import { JWTError, isJWTError } from "../error.mjs";
2
+ import { assertPlainObject, base64UrlParse, base64UrlStringify, isCryptoKey, isPlainObject, isPrivateJWK } from "../_chunks/jwt.mjs";
3
+ import { JWS_ALG_CTX, asJWTError, assertCompactToken, checkAlgAllowed, decodeProtectedHeader, jwkTokey, thumbprint } from "../_chunks/algorithms.mjs";
4
+ import { digestUrl, inferJWSAllowedAlgorithms, isJWSAlgorithm } from "../_chunks/digest.mjs";
5
+ import { sign, verify } from "../_chunks/jws.mjs";
6
+ import { exportJWK } from "../_chunks/export.mjs";
7
+ function assertDPoPAlgorithm(value, code) {
8
+ if (typeof value !== "string" || !isJWSAlgorithm(value) || value.startsWith("HS")) throw new JWTError("DPoP requires a supported asymmetric signing algorithm.", code);
9
+ }
10
+ function assertNonce(value, code) {
11
+ if (typeof value !== "string" || !/^[\x21\x23-\x5B\x5D-\x7E]+$/.test(value)) throw new JWTError("DPoP nonce must contain printable ASCII excluding space, quotes and backslash.", code);
12
+ }
13
+ function assertMethod(value, code) {
14
+ if (typeof value !== "string" || !/^[!#$%&'*+.^_`|~\da-z-]+$/i.test(value)) throw new JWTError("DPoP method must be a non-empty HTTP method token.", code);
15
+ }
16
+ function assertIdentifier(value, code) {
17
+ if (typeof value !== "string" || value.length === 0) throw new JWTError("DPoP jti must be a non-empty string unique to this proof.", code);
18
+ }
19
+ function assertNumericDate(value, options) {
20
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new JWTError(`DPoP ${options.claim} must be a finite, non-negative NumericDate.`, options.code);
21
+ }
22
+ function assertAccessToken(value) {
23
+ if (typeof value !== "string" || !/^[\x00-\x7F]+$/.test(value)) throw new JWTError("DPoP accessToken.token must be a non-empty ASCII string.", "ERR_INVALID_OPTION");
24
+ }
25
+ function isSHA256Digest(value) {
26
+ return typeof value === "string" && /^[\w-]{42}[AEIMQUYcgkosw048]$/.test(value);
27
+ }
28
+ async function accessTokenHash(token) {
29
+ assertAccessToken(token);
30
+ try {
31
+ return await digestUrl(token);
32
+ } catch (cause) {
33
+ throw new JWTError("DPoP access token hashing failed.", "ERR_DPOP_INVALID", cause);
34
+ }
35
+ }
36
+ const PRIVATE_MEMBERS = [
37
+ "d",
38
+ "p",
39
+ "q",
40
+ "dp",
41
+ "dq",
42
+ "qi",
43
+ "oth",
44
+ "k"
45
+ ];
46
+ function resolveProofAlgorithm(pair, options) {
47
+ let algorithm = options.algorithm;
48
+ if (algorithm === void 0) {
49
+ if (!isPlainObject(pair) || !isPrivateJWK(pair.privateKey) || !isPlainObject(pair.publicKey)) throw new JWTError("DPoP algorithm inference requires an asymmetric JWK pair; provide algorithm for CryptoKey pairs.", "ERR_INVALID_OPTION");
50
+ algorithm = pair.privateKey.alg === void 0 ? pair.publicKey.alg : pair.privateKey.alg;
51
+ if (algorithm === void 0) {
52
+ const candidates = inferJWSAllowedAlgorithms(pair.privateKey);
53
+ if (candidates?.length !== 1) throw new JWTError("DPoP signing algorithm is ambiguous; provide algorithm or JWK alg metadata.", "ERR_INVALID_OPTION");
54
+ algorithm = candidates[0];
55
+ }
56
+ }
57
+ assertDPoPAlgorithm(algorithm, "ERR_INVALID_OPTION");
58
+ return algorithm;
59
+ }
60
+ async function publicKeyForProof(pair, algorithm) {
61
+ if (!isPlainObject(pair)) throw new JWTError("DPoP keyPair must supply privateKey and publicKey.", "ERR_INVALID_OPTION");
62
+ const { privateKey, publicKey } = pair;
63
+ if (isCryptoKey(privateKey) && isCryptoKey(publicKey)) {
64
+ if (privateKey.type !== "private" || publicKey.type !== "public" || !publicKey.extractable) throw new JWTError("DPoP requires a private signing key and an extractable public key.", "ERR_INVALID_OPTION");
65
+ if (!inferJWSAllowedAlgorithms(publicKey)?.includes(algorithm)) throw new JWTError("DPoP public key is incompatible with the signing algorithm.", "ERR_INVALID_OPTION");
66
+ return projectPublicKey(await exportJWK(publicKey), {
67
+ algorithm,
68
+ code: "ERR_INVALID_OPTION"
69
+ });
70
+ }
71
+ if (!isPrivateJWK(privateKey) || isCryptoKey(publicKey)) throw new JWTError("DPoP keyPair must be a CryptoKey pair or an asymmetric JWK pair.", "ERR_INVALID_OPTION");
72
+ const jwk = projectPublicKey(publicKey, {
73
+ algorithm,
74
+ code: "ERR_INVALID_OPTION"
75
+ });
76
+ if (isPlainObject(publicKey) && publicKey.alg !== void 0) {
77
+ assertDPoPAlgorithm(publicKey.alg, "ERR_INVALID_OPTION");
78
+ if (!inferJWSAllowedAlgorithms(publicKey)?.includes(algorithm)) throw new JWTError("DPoP public JWK alg does not match the signing algorithm.", "ERR_INVALID_OPTION");
79
+ }
80
+ return jwk;
81
+ }
82
+ function projectPublicKey(value, options) {
83
+ if (!isPlainObject(value) || PRIVATE_MEMBERS.some((member) => Object.hasOwn(value, member))) throw new JWTError("DPoP jwk must be a public asymmetric JWK without private members.", options.code);
84
+ const members = value.kty === "RSA" ? ["n", "e"] : value.kty === "EC" ? [
85
+ "crv",
86
+ "x",
87
+ "y"
88
+ ] : value.kty === "OKP" ? ["crv", "x"] : void 0;
89
+ if (!members || members.some((name) => typeof value[name] !== "string" || value[name].length === 0)) throw new JWTError("DPoP jwk is missing required asymmetric public key members.", options.code);
90
+ if (members.some((name) => name !== "crv" && !isCanonicalBase64Url(value[name]))) throw new JWTError("DPoP jwk members must be canonical unpadded base64url.", options.code);
91
+ const key = Object.fromEntries([["kty", value.kty], ...members.map((name) => [name, value[name]])]);
92
+ if (!(value.kty === "RSA" ? /^(?:RS|PS)(?:256|384|512)$/.test(options.algorithm) : inferJWSAllowedAlgorithms(key)?.includes(options.algorithm))) throw new JWTError("DPoP jwk is incompatible with the signing algorithm.", options.code);
93
+ return key;
94
+ }
95
+ function isCanonicalBase64Url(value) {
96
+ if (typeof value !== "string") return false;
97
+ try {
98
+ return base64UrlStringify(base64UrlParse(value, { returnAs: "bytes" })) === value;
99
+ } catch {
100
+ return false;
101
+ }
102
+ }
103
+ function normalizeTargetURI(value, options) {
104
+ const uri = typeof value === "string" ? value.split(/[?#]/, 1)[0] : value;
105
+ const authority = typeof uri === "string" ? /^https?:\/\/([^/]+)/i.exec(uri)?.[1] : void 0;
106
+ if (typeof uri !== "string" || authority === void 0 || /[@%]/.test(authority) || /[\x00-\x20\x7F\\]/.test(uri) || /%(?![\da-f]{2})/i.test(uri)) throw new JWTError("DPoP htu must be an absolute HTTP(S) URI without credentials or escapes in its authority.", options.code);
107
+ const origin = uri.slice(0, uri.indexOf("://") + 3 + authority.length);
108
+ const path = uri.slice(origin.length).replace(/%[\da-f]{2}/gi, (escape) => {
109
+ const character = String.fromCharCode(Number.parseInt(escape.slice(1), 16));
110
+ return /^[\w.~-]$/.test(character) ? character : escape.toUpperCase();
111
+ });
112
+ try {
113
+ return new URL(origin + path).href;
114
+ } catch (cause) {
115
+ throw new JWTError("DPoP htu must be a valid absolute HTTP(S) URI.", options.code, cause);
116
+ }
117
+ }
118
+ function validateVerifyOptions(target, options) {
119
+ assertPlainObject(options, "options");
120
+ if (typeof target !== "object" || target === null) throw new JWTError("DPoP target requires method and url.", "ERR_INVALID_OPTION");
121
+ const { method, url } = target;
122
+ assertMethod(method, "ERR_INVALID_OPTION");
123
+ const uri = normalizeTargetURI(url, { code: "ERR_INVALID_OPTION" });
124
+ const { algorithms: allowed, maxTokenAge, clockTolerance, currentDate, nonce, accessToken, consumeProof } = options;
125
+ const algorithms = [];
126
+ for (const algorithm of Array.isArray(allowed) ? allowed : []) {
127
+ assertDPoPAlgorithm(algorithm, "ERR_INVALID_OPTION");
128
+ algorithms.push(algorithm);
129
+ }
130
+ if (algorithms.length === 0) throw new JWTError("DPoP algorithms must be a non-empty asymmetric algorithm allowlist.", "ERR_INVALID_OPTION");
131
+ const tolerance = clockTolerance === void 0 ? 0 : clockTolerance;
132
+ if (typeof tolerance !== "number" || !Number.isFinite(tolerance) || tolerance < 0 || typeof maxTokenAge !== "number" || !Number.isFinite(maxTokenAge) || maxTokenAge <= 0) throw new JWTError("DPoP maxTokenAge must be positive finite seconds and clockTolerance non-negative finite seconds.", "ERR_INVALID_OPTION");
133
+ const date = currentDate === void 0 ? /* @__PURE__ */ new Date() : currentDate;
134
+ const time = date instanceof Date ? date.getTime() : NaN;
135
+ if (!Number.isFinite(time)) throw new JWTError("DPoP currentDate must be a valid Date.", "ERR_INVALID_OPTION");
136
+ if (nonce !== void 0) assertNonce(nonce, "ERR_INVALID_OPTION");
137
+ let binding;
138
+ if (accessToken !== void 0) {
139
+ assertPlainObject(accessToken, "accessToken");
140
+ const { token, thumbprint } = accessToken;
141
+ assertAccessToken(token);
142
+ if (!isSHA256Digest(thumbprint)) throw new JWTError("DPoP accessToken.thumbprint must be a SHA-256 JWK thumbprint.", "ERR_INVALID_OPTION");
143
+ binding = {
144
+ token,
145
+ thumbprint
146
+ };
147
+ }
148
+ if (consumeProof !== void 0 && typeof consumeProof !== "function") throw new JWTError("DPoP consumeProof must be a function.", "ERR_INVALID_OPTION");
149
+ return {
150
+ now: time / 1e3,
151
+ tolerance,
152
+ maxTokenAge,
153
+ method,
154
+ uri,
155
+ algorithms,
156
+ nonce,
157
+ accessToken: binding,
158
+ consumeProof
159
+ };
160
+ }
161
+ function validateProofClaims(payload, context) {
162
+ const code = "ERR_DPOP_CLAIM_INVALID";
163
+ assertIdentifier(payload.jti, code);
164
+ assertNumericDate(payload.iat, {
165
+ claim: "iat",
166
+ code
167
+ });
168
+ assertMethod(payload.htm, code);
169
+ if (payload.htm !== context.method || normalizeTargetURI(payload.htu, { code }) !== context.uri) throw new JWTError("DPoP proof does not match the request method and URI.", code);
170
+ if (payload.nonce !== void 0) assertNonce(payload.nonce, code);
171
+ if (payload.ath !== void 0 && !isSHA256Digest(payload.ath)) throw new JWTError("DPoP ath must be a base64url SHA-256 access token hash.", code);
172
+ if (payload.iat > context.now + context.tolerance || payload.iat < context.now - context.maxTokenAge - context.tolerance) throw new JWTError("DPoP iat is outside the accepted proof age window.", code);
173
+ }
174
+ function assertExpectedNonce(payload, expected) {
175
+ if (expected !== void 0 && payload.nonce !== expected) throw new JWTError("DPoP nonce is missing or does not match the expected nonce.", "ERR_DPOP_NONCE_INVALID");
176
+ }
177
+ async function consumeValidatedProof(result, consumeProof) {
178
+ let accepted;
179
+ try {
180
+ accepted = await consumeProof({
181
+ payload: structuredClone(result.payload),
182
+ thumbprint: result.thumbprint
183
+ });
184
+ } catch (cause) {
185
+ throw new JWTError("DPoP replay consumption failed.", "ERR_DPOP_REPLAY", cause);
186
+ }
187
+ if (accepted !== true) throw new JWTError("DPoP proof was rejected by replay consumption.", "ERR_DPOP_REPLAY");
188
+ }
189
+ function asProofError(error) {
190
+ if (!(error instanceof JWTError)) return new JWTError("DPoP proof verification failed.", "ERR_DPOP_INVALID", error);
191
+ if (error.code.startsWith("ERR_DPOP_")) return error;
192
+ const code = error.code.startsWith("ERR_JWT_") ? "ERR_DPOP_CLAIM_INVALID" : "ERR_DPOP_INVALID";
193
+ return new JWTError(error.message, code, error);
194
+ }
195
+ async function createDPoPProof(target, options) {
196
+ try {
197
+ assertPlainObject(options, "options");
198
+ if (typeof target !== "object" || target === null) throw new JWTError("DPoP target requires method and url.", "ERR_INVALID_OPTION");
199
+ assertMethod(target.method, "ERR_INVALID_OPTION");
200
+ const jti = options.jti === void 0 ? crypto.randomUUID() : options.jti;
201
+ const iat = options.iat === void 0 ? Math.floor(Date.now() / 1e3) : options.iat;
202
+ assertIdentifier(jti, "ERR_INVALID_OPTION");
203
+ assertNumericDate(iat, {
204
+ claim: "iat",
205
+ code: "ERR_INVALID_OPTION"
206
+ });
207
+ const algorithm = resolveProofAlgorithm(options.keyPair, { algorithm: options.algorithm });
208
+ const payload = {
209
+ jti,
210
+ iat,
211
+ htm: target.method,
212
+ htu: normalizeTargetURI(target.url, { code: "ERR_INVALID_OPTION" })
213
+ };
214
+ for (const claim of ["exp", "nbf"]) {
215
+ const value = options[claim];
216
+ if (value !== void 0) {
217
+ assertNumericDate(value, {
218
+ claim,
219
+ code: "ERR_INVALID_OPTION"
220
+ });
221
+ payload[claim] = value;
222
+ }
223
+ }
224
+ if (options.nonce !== void 0) {
225
+ assertNonce(options.nonce, "ERR_INVALID_OPTION");
226
+ payload.nonce = options.nonce;
227
+ }
228
+ if (options.accessToken !== void 0) {
229
+ assertPlainObject(options.accessToken, "accessToken");
230
+ payload.ath = await accessTokenHash(options.accessToken.token);
231
+ }
232
+ const signingOptions = {
233
+ alg: algorithm,
234
+ protectedHeader: {
235
+ typ: "dpop+jwt",
236
+ jwk: await publicKeyForProof(options.keyPair, algorithm)
237
+ }
238
+ };
239
+ const privateKey = options.keyPair.privateKey;
240
+ return await (isCryptoKey(privateKey) ? sign(payload, privateKey, signingOptions) : sign(payload, privateKey, signingOptions));
241
+ } catch (cause) {
242
+ if (cause instanceof JWTError) throw cause;
243
+ throw new JWTError("DPoP proof creation failed.", "ERR_DPOP_INVALID", cause);
244
+ }
245
+ }
246
+ async function verifyDPoPProof(proof, target, options) {
247
+ let context;
248
+ try {
249
+ context = validateVerifyOptions(target, options);
250
+ } catch (cause) {
251
+ throw asJWTError(cause, {
252
+ code: "ERR_INVALID_OPTION",
253
+ message: "DPoP verification options are invalid."
254
+ });
255
+ }
256
+ let result;
257
+ try {
258
+ result = await authenticateProof(proof, context);
259
+ } catch (cause) {
260
+ throw asProofError(cause);
261
+ }
262
+ if (context.consumeProof) await consumeValidatedProof(result, context.consumeProof);
263
+ return result;
264
+ }
265
+ async function authenticateProof(proof, context) {
266
+ assertCompactToken(proof, "JWS");
267
+ const header = decodeProtectedHeader(proof.split(".")[0], "JWS");
268
+ assertDPoPAlgorithm(header.alg, "ERR_DPOP_INVALID");
269
+ if (header.b64 === false) throw new JWTError("DPoP JWT payloads must use base64url encoding.", "ERR_DPOP_INVALID");
270
+ const jwk = projectPublicKey(header.jwk, {
271
+ algorithm: header.alg,
272
+ code: "ERR_DPOP_INVALID"
273
+ });
274
+ const algError = checkAlgAllowed(header.alg, jwk, {
275
+ ctx: JWS_ALG_CTX,
276
+ algorithms: context.algorithms
277
+ });
278
+ if (algError) throw algError;
279
+ const key = await jwkTokey(jwk, { alg: header.alg });
280
+ const { payload } = await verify(proof, key, {
281
+ algorithms: context.algorithms,
282
+ typ: "dpop+jwt",
283
+ currentDate: /* @__PURE__ */ new Date(context.now * 1e3),
284
+ clockTolerance: context.tolerance
285
+ });
286
+ validateProofClaims(payload, context);
287
+ const keyThumbprint = await thumbprint(jwk);
288
+ const { accessToken } = context;
289
+ if (accessToken && (keyThumbprint !== accessToken.thumbprint || payload.ath !== await accessTokenHash(accessToken.token))) throw new JWTError("DPoP access token hash or public key binding does not match.", "ERR_DPOP_CLAIM_INVALID");
290
+ assertExpectedNonce(payload, context.nonce);
291
+ return {
292
+ payload,
293
+ thumbprint: keyThumbprint
294
+ };
295
+ }
296
+ export { JWTError, createDPoPProof, isJWTError, verifyDPoPProof };
@@ -0,0 +1,3 @@
1
+ import { UnsecureError, UnsecureErrorCode } from "./_chunks/libs/unsecure.mjs";
2
+ import { JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, isJWTError, isUnsecureError } from "./_chunks/error.mjs";
3
+ export { JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, UnsecureError, type UnsecureErrorCode, isJWTError, isUnsecureError };
package/dist/error.mjs ADDED
@@ -0,0 +1,20 @@
1
+ import { UnsecureError } from "./_chunks/libs/unsecure.mjs";
2
+ var JWTError = class extends Error {
3
+ code;
4
+ cause;
5
+ constructor(message, code, cause) {
6
+ super(message);
7
+ this.name = "JWTError";
8
+ this.code = code;
9
+ this.cause = cause;
10
+ }
11
+ };
12
+ function isJWTError(error, code) {
13
+ if (!(error instanceof JWTError)) return false;
14
+ return code === void 0 || error.code === code;
15
+ }
16
+ function isUnsecureError(error, code) {
17
+ if (!(error instanceof UnsecureError)) return false;
18
+ return code === void 0 || error.code === code;
19
+ }
20
+ export { JWTError, UnsecureError, isJWTError, isUnsecureError };
package/dist/index.d.mts CHANGED
@@ -1,11 +1,12 @@
1
- import { BytesSource, DecodeOptions, DecodeReturnAs, UnsecureError, UnsecureErrorCode, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "./_chunks/libs/unsecure.mjs";
2
- import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, 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, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTError, JWTErrorCauseMap, JWTErrorCode, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, KnownJWTErrorCode, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, StrictOmit, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor, isJWTError, isUnsecureError } from "./_chunks/index.mjs";
3
- import { thumbprint } from "./_chunks/index2.mjs";
1
+ import { BytesSource, UnsecureError, UnsecureErrorCode, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "./_chunks/libs/unsecure.mjs";
2
+ import { JWTError, JWTErrorCauseMap, JWTErrorCode, KnownJWTErrorCode, isJWTError, isUnsecureError } from "./_chunks/error.mjs";
3
+ import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, 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, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, StrictOmit, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "./_chunks/index.mjs";
4
+ import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, toPublicJWK, unwrapKey, wrapKey } from "./_chunks/index2.mjs";
5
+ import { thumbprint } from "./_chunks/index3.mjs";
4
6
  import { DigestHash, digestUrl } from "./_chunks/digest.mjs";
5
- import { WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, toPublicJWK, unwrapKey, wrapKey } from "./core/jwk.mjs";
6
7
  import { computeDurationInSeconds, isJWTContent, validateJwtClaims } from "./_chunks/jwt.mjs";
7
- import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "./_chunks/jwe.mjs";
8
- import { DEFAULT_JOSE_LIMITS } from "./_chunks/_internal.mjs";
9
- import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "./_chunks/jws.mjs";
10
- import { ComputeJwtTimeClaimsOptions, DecodePayloadOptions, InferAlgorithmsOptions, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isPrivateJWK, isPublicJWK, isSymmetricJWK, maybeArray, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "./_chunks/index3.mjs";
11
- export { type BytesSource, type CompositeKey, ComputeJwtTimeClaimsOptions, type ContentEncryptionAlgorithm, DEFAULT_JOSE_LIMITS, type DecodeOptions, DecodePayloadOptions, type DecodeReturnAs, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type DigestHash, 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 ImportedPEMJWK, type InferAlgorithmsOptions, 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 JWEKeyLookup, 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_Algorithm, 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 JWSHashedAlgorithm, type JWSHeaderParameters, type JWSKeyLookup, 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 JWTConfirmation, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type KnownJWTErrorCode, type MaxTokenAge, type NotBeforeIn, type PEMType, type PayloadOf, type StrictOmit, type ToPublicJWKReturn, UnsecureError, type UnsecureErrorCode, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, WeakMapJWKCache, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, clearJWKCache, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, configureJWKCache, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, decrypt, decryptMulti, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, digestUrl, encrypt, encryptMulti, exportJWK, exportKey, exportPEM, generalToFlattened, generalToFlattenedJWS, generateJWK, generateKey, getJWKsFromSet, getPlaintextBytes, importKey, importPEM, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, sign, signMulti, textDecoder, textEncoder, thumbprint, toPublicJWK, unwrapKey, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims, verify, verifyMulti, verifyMultiAll, wrapKey };
8
+ import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "./_chunks/index4.mjs";
9
+ import { DEFAULT_JOSE_LIMITS } from "./_chunks/limits.mjs";
10
+ import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "./_chunks/index5.mjs";
11
+ import { Base64ParseOptions, ComputeJwtTimeClaimsOptions, DecodeOptions, DecodePayloadOptions, DecodeReturnAs, InferAlgorithmsOptions, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isPrivateJWK, isPublicJWK, isSymmetricJWK, maybeArray, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "./_chunks/index6.mjs";
12
+ export { type Base64ParseOptions, type BytesSource, type CompositeKey, ComputeJwtTimeClaimsOptions, type ContentEncryptionAlgorithm, DEFAULT_JOSE_LIMITS, DecodeOptions, DecodePayloadOptions, type DecodeReturnAs, type DeriveJWKOptions, type DeriveJWKReturn, type DeriveKeyOptions, type DeriveKeyReturn, type DigestHash, 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 ImportedPEMJWK, type InferAlgorithmsOptions, 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 JWEKeyLookup, 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_Algorithm, 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 JWSHashedAlgorithm, type JWSHeaderParameters, type JWSKeyLookup, 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 JWTConfirmation, JWTError, type JWTErrorCauseMap, type JWTErrorCode, type JWTTimeClaimOptions, type JoseHeaderParameters, type KeyManagementAlgorithm, type KeyWrapAlgorithmOf, type KeyWrappingAlgorithm, type KnownJWTErrorCode, type MaxTokenAge, type NotBeforeIn, type PEMType, type PayloadOf, type StrictOmit, type ToPublicJWKReturn, UnsecureError, type UnsecureErrorCode, type UnwrapKeyOptions, type UnwrapKeyResult, type UnwrappingKeyFor, WeakMapJWKCache, type WrapKeyOptions, type WrapKeyResult, type WrappingKeyFor, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, clearJWKCache, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, configureJWKCache, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, decrypt, decryptMulti, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, digestUrl, encrypt, encryptMulti, exportJWK, exportKey, exportPEM, generalToFlattened, generalToFlattenedJWS, generateJWK, generateKey, getJWKsFromSet, getPlaintextBytes, importKey, importPEM, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, sign, signMulti, textDecoder, textEncoder, thumbprint, toPublicJWK, unwrapKey, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims, verify, verifyMulti, verifyMultiAll, wrapKey };
package/dist/index.mjs CHANGED
@@ -1,8 +1,12 @@
1
1
  import { UnsecureError, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "./_chunks/libs/unsecure.mjs";
2
- import { JWTError, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, concatUint8Arrays, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, validateJwtClaims } from "./_chunks/_jwt-internal.mjs";
2
+ import { JWTError, isJWTError, isUnsecureError } from "./error.mjs";
3
+ import { assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, concatUint8Arrays, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, maybeArray, validateJwtClaims } from "./_chunks/jwt.mjs";
4
+ import { DEFAULT_JOSE_LIMITS, WeakMapJWKCache, clearJWKCache, configureJWKCache, getJWKsFromSet, importKey, thumbprint } from "./_chunks/algorithms.mjs";
3
5
  import { digestUrl, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms } from "./_chunks/digest.mjs";
4
- import { DEFAULT_JOSE_LIMITS, WeakMapJWKCache, clearJWKCache, configureJWKCache, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportJWK, exportKey, exportPEM, generateJWK, generateKey, getJWKsFromSet, importKey, importPEM, thumbprint, toPublicJWK, unwrapKey, wrapKey } from "./_chunks/jwk.mjs";
5
6
  import { generalToFlattenedJWS, sign, signMulti, verify, verifyMulti, verifyMultiAll } from "./_chunks/jws.mjs";
6
7
  import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "./_chunks/jwe.mjs";
7
- import { applyTypCtyDefaults, assertCritShape, computeJwtTimeClaims, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "./core/utils/index.mjs";
8
+ import { unwrapKey, wrapKey } from "./_chunks/wrap.mjs";
9
+ import { exportJWK, exportKey, toPublicJWK } from "./_chunks/export.mjs";
10
+ import { deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, exportPEM, generateJWK, generateKey, importPEM } from "./_chunks/jwk.mjs";
11
+ import { applyTypCtyDefaults, assertCritShape, computeJwtTimeClaims, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "./utils/index.mjs";
8
12
  export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, WeakMapJWKCache, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, clearJWKCache, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, configureJWKCache, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, decrypt, decryptMulti, deriveJWKFromPassword, deriveKeyFromPassword, deriveSharedSecret, digestUrl, encrypt, encryptMulti, exportJWK, exportKey, exportPEM, generalToFlattened, generalToFlattenedJWS, generateJWK, generateKey, getJWKsFromSet, getPlaintextBytes, importKey, importPEM, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isJWTError, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, sign, signMulti, textDecoder, textEncoder, thumbprint, toPublicJWK, unwrapKey, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims, verify, verifyMulti, verifyMultiAll, wrapKey };
@@ -1,8 +1,8 @@
1
- import { CookieJar, JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionDriver, SessionEncryptOptions, SessionHandedToken, SessionIssueOptions, SessionManager, SessionRecord, SessionRequestEvent, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions, WebSessionEvent } from "../_chunks/_codec-jwe.mjs";
2
- import { CookieAttributes } from "../_chunks/_cookie-attributes.mjs";
1
+ import { CookieJar, JWESessionConfig, JWESessionHooks, JWSSessionConfig, JWSSessionHooks, OpenedSessionState, SessionClaims, SessionData, SessionDecryptOptions, SessionDefinition, SessionDriver, SessionEncryptOptions, SessionHandedToken, SessionIssueOptions, SessionManager, SessionRecord, SessionRequestEvent, SessionSignOptions, SessionState, SessionUpdate, SessionUpdateTrigger, SessionVerifyOptions, WebSessionEvent } from "../_chunks/codec-jwe.mjs";
2
+ import { CookieAttributes } from "../_chunks/cookie-attributes.mjs";
3
3
  import { CompositeKey, ContentEncryptionAlgorithm, DeriveJWKOptions, DeriveJWKReturn, DeriveKeyOptions, DeriveKeyReturn, Duration, ECDHEphemeralKeyInput, ExpiresIn, GenerateJWKOptions, GenerateJWKReturn, GenerateKeyAlgorithm, GenerateKeyOptions, GenerateKeyReturn, GeneratedJWKMap, GeneratedKeyMap, ImportedKey, ImportedKeyMap, ImportedPEMJWK, JOSEConsumerOptions, JOSELimits, JOSEPayload, JOSEPayloadMode, JOSEPayloadTypeMap, JWEAsymmetricPrivateJWK, JWEAsymmetricPublicJWK, JWEDecryptJWK, JWEDecryptOptions, JWEDecryptResult, JWEEncryptJWK, JWEEncryptOptions, JWEFlattenedSerialization, JWEGeneralRecipient, JWEGeneralSerialization, JWEHeaderParameters, JWEKeyLookup, JWEKeyManagementHeaderParameters, JWELibraryHeaderName, JWEMultiDecryptKey, JWEMultiDecryptOptions, JWEMultiDecryptResult, JWEMultiEncryptOptions, JWEMultiRecipient, JWEProtectedHeader, JWK, JWKAlgorithm, JWKCacheAdapter, JWKLookupFunction, JWKLookupFunctionHeader, JWKMetadata, JWKPEMAlgorithm, JWKParameters, JWKSet, JWK_AES_Algorithm, 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, JWSHashedAlgorithm, JWSHeaderParameters, JWSKeyLookup, JWSMultiSignOptions, JWSMultiSigner, JWSMultiVerifyAllOptions, JWSMultiVerifyOptions, JWSMultiVerifyOutcome, JWSMultiVerifyResult, JWSProtectedHeader, JWSSignJWK, JWSSignOptions, JWSVerifyJWK, JWSVerifyOptions, JWSVerifyResult, JWT, JWTClaimValidationOptions, JWTClaims, JWTConfirmation, JWTTimeClaimOptions, JoseHeaderParameters, KeyManagementAlgorithm, KeyWrapAlgorithmOf, KeyWrappingAlgorithm, MaxTokenAge, NotBeforeIn, PEMType, PayloadOf, ToPublicJWKReturn, UnwrapKeyOptions, UnwrapKeyResult, UnwrappingKeyFor, WrapKeyOptions, WrapKeyResult, WrappingKeyFor } from "../_chunks/index.mjs";
4
- import { thumbprint } from "../_chunks/index2.mjs";
5
- import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../core/jwk.mjs";
4
+ import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, toPublicJWK } from "../_chunks/index2.mjs";
5
+ import { thumbprint } from "../_chunks/index3.mjs";
6
6
  /** Session state for the current request, mirroring the claims of its JWS token. */
7
7
  interface SessionJWS<T extends SessionRecord = SessionClaims, MaxAge extends ExpiresIn | undefined = ExpiresIn | undefined> extends SessionState<T, MaxAge> {}
8
8
  /** JWS session hooks; `onRead`, `onExpire` and `onError` are mutually exclusive per token. */
@@ -1,48 +1,8 @@
1
- import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM, thumbprint, toPublicJWK } from "../_chunks/jwk.mjs";
2
- import { createJWECodec, createJWSCodec, defineSession, invalidConfigError, setCookieName, setCookieValues } from "../_chunks/_codec-jws.mjs";
3
- import { parse, parseSetCookie, serialize } from "../_chunks/libs/cookie-es.mjs";
4
- function webCookieJar(request, headers) {
5
- let cookies;
6
- const jar = { read: (name) => (cookies ||= requestCookies(request))[name] };
7
- if (headers) {
8
- jar.written = (name) => setCookieValues(headers.getSetCookie())[name];
9
- jar.write = (name, value, attrs) => {
10
- setCookie(headers, {
11
- name,
12
- value,
13
- ...attrs
14
- });
15
- };
16
- }
17
- return jar;
18
- }
19
- function requestCookies(request) {
20
- const header = request.get("cookie");
21
- return header ? parse(header) : Object.create(null);
22
- }
23
- function setCookie(headers, cookie) {
24
- const line = serialize({
25
- path: "/",
26
- ...cookie
27
- });
28
- const key = cookieKey(cookie);
29
- const kept = headers.getSetCookie().filter((existing) => {
30
- const parsed = parseSetCookie(existing);
31
- return parsed ? cookieKey(parsed) !== key : setCookieName(existing) !== cookie.name;
32
- });
33
- headers.delete("set-cookie");
34
- for (const existing of kept) headers.append("set-cookie", existing);
35
- headers.append("set-cookie", line);
36
- }
37
- function cookieKey(cookie) {
38
- const domain = (cookie.domain || "").replace(/^\./, "").toLowerCase();
39
- return [
40
- cookie.name,
41
- domain,
42
- cookie.path || "/",
43
- cookie.partitioned ? "1" : "0"
44
- ].join(";");
45
- }
1
+ import { thumbprint } from "../_chunks/algorithms.mjs";
2
+ import { toPublicJWK } from "../_chunks/export.mjs";
3
+ import { deriveJWKFromPassword, exportPEM, generateJWK, importPEM } from "../_chunks/jwk.mjs";
4
+ import { createJWECodec, createJWSCodec, defineSession, invalidConfigError } from "../_chunks/codec-jws.mjs";
5
+ import { webCookieJar } from "../_chunks/cookie.mjs";
46
6
  const PREFIX = "[unjwt/session]";
47
7
  const SESSIONS = /* @__PURE__ */ new WeakMap();
48
8
  const webSessionDriver = {
@@ -53,7 +13,7 @@ const webSessionDriver = {
53
13
  return sessionsOf(event.req ? webRequest(event.req) : event);
54
14
  },
55
15
  header: (event, name) => isHanded(event) ? void 0 : requestHeaders(event).get(name),
56
- cookies: (event) => isHanded(event) ? { read: () => void 0 } : webCookieJar(requestHeaders(event), event.res?.headers),
16
+ cookies: (event) => isHanded(event) ? { read: () => void 0 } : webCookieJar(requestHeaders(event), event.res),
57
17
  handed: (event) => isHanded(event) ? { token: event.token } : void 0
58
18
  };
59
19
  function isHanded(event) {
@@ -0,0 +1,7 @@
1
+ import { BytesSource, UnsecureError, UnsecureErrorCode, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "../_chunks/libs/unsecure.mjs";
2
+ import { isUnsecureError } from "../_chunks/error.mjs";
3
+ import { StrictOmit } from "../_chunks/index.mjs";
4
+ import { DigestHash, digestUrl } from "../_chunks/digest.mjs";
5
+ import { computeDurationInSeconds, isJWTContent, validateJwtClaims } from "../_chunks/jwt.mjs";
6
+ import { Base64ParseOptions, ComputeJwtTimeClaimsOptions, DecodeOptions, DecodePayloadOptions, DecodeReturnAs, InferAlgorithmsOptions, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isPrivateJWK, isPublicJWK, isSymmetricJWK, maybeArray, validateCriticalHeadersJWE, validateCriticalHeadersJWS } from "../_chunks/index6.mjs";
7
+ export { type Base64ParseOptions, type BytesSource, ComputeJwtTimeClaimsOptions, DecodeOptions, DecodePayloadOptions, type DecodeReturnAs, type DigestHash, type InferAlgorithmsOptions, type StrictOmit, UnsecureError, type UnsecureErrorCode, applyTypCtyDefaults, assertCritShape, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims, concatUint8Arrays, decodePayloadFromB64UrlSegment, decodePayloadFromBytes, digestUrl, getPlaintextBytes, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder, validateCriticalHeadersJWE, validateCriticalHeadersJWS, validateJwtClaims };
@@ -1,6 +1,7 @@
1
- import { UnsecureError, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "../../_chunks/libs/unsecure.mjs";
2
- import { applyTypDefault, assertCritShape as assertCritShape$1, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims as computeJwtTimeClaims$1, concatUint8Arrays, getPlaintextBytes as getPlaintextBytes$1, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, isUnsecureError, maybeArray, parsePayloadBytes, parsePayloadSegment, validateCriticalHeadersJWE as validateCriticalHeadersJWE$1, validateCriticalHeadersJWS as validateCriticalHeadersJWS$1, validateJwtClaims } from "../../_chunks/_jwt-internal.mjs";
3
- import { digestUrl, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms } from "../../_chunks/digest.mjs";
1
+ import { UnsecureError, safeJsonParse, sanitizeObject, sanitizeObjectCopy, secureRandomBytes, textDecoder, textEncoder } from "../_chunks/libs/unsecure.mjs";
2
+ import { isUnsecureError } from "../error.mjs";
3
+ import { applyTypDefault, assertCritShape as assertCritShape$1, assertCryptoKey, base64Decode, base64Encode, base64Parse, base64Stringify, base64UrlDecode, base64UrlEncode, base64UrlParse, base64UrlStringify, computeDurationInSeconds, computeJwtTimeClaims as computeJwtTimeClaims$1, concatUint8Arrays, getPlaintextBytes as getPlaintextBytes$1, isAsymmetricJWK, isCryptoKey, isCryptoKeyPair, isJWK, isJWKSet, isJWTContent, isPrivateJWK, isPublicJWK, isSymmetricJWK, maybeArray, parsePayloadBytes, parsePayloadSegment, validateCriticalHeadersJWE as validateCriticalHeadersJWE$1, validateCriticalHeadersJWS as validateCriticalHeadersJWS$1, validateJwtClaims } from "../_chunks/jwt.mjs";
4
+ import { digestUrl, inferJWEAllowedAlgorithms, inferJWSAllowedAlgorithms } from "../_chunks/digest.mjs";
4
5
  const applyTypCtyDefaults = applyTypDefault;
5
6
  const decodePayloadFromBytes = parsePayloadBytes;
6
7
  const decodePayloadFromB64UrlSegment = parsePayloadSegment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "description": "A collection of JWT utilities based on the Web Crypto API.",
5
5
  "keywords": [
6
6
  "auth",
@@ -40,6 +40,9 @@
40
40
  "sideEffects": false,
41
41
  "main": "./dist/index.mjs",
42
42
  "module": "./dist/index.mjs",
43
+ "browser": {
44
+ "buffer": false
45
+ },
43
46
  "types": "./dist/index.d.mts",
44
47
  "exports": {
45
48
  ".": {
@@ -47,25 +50,33 @@
47
50
  "default": "./dist/index.mjs"
48
51
  },
49
52
  "./jwk": {
50
- "types": "./dist/core/jwk.d.mts",
51
- "default": "./dist/core/jwk.mjs"
53
+ "types": "./dist/core/jwk/index.d.mts",
54
+ "default": "./dist/core/jwk/index.mjs"
52
55
  },
53
56
  "./jws": {
54
- "types": "./dist/core/jws.d.mts",
55
- "default": "./dist/core/jws.mjs"
57
+ "types": "./dist/core/jws/index.d.mts",
58
+ "default": "./dist/core/jws/index.mjs"
56
59
  },
57
60
  "./jwe": {
58
- "types": "./dist/core/jwe.d.mts",
59
- "default": "./dist/core/jwe.mjs"
61
+ "types": "./dist/core/jwe/index.d.mts",
62
+ "default": "./dist/core/jwe/index.mjs"
60
63
  },
61
64
  "./utils": {
62
- "types": "./dist/core/utils/index.d.mts",
63
- "default": "./dist/core/utils/index.mjs"
65
+ "types": "./dist/utils/index.d.mts",
66
+ "default": "./dist/utils/index.mjs"
67
+ },
68
+ "./error": {
69
+ "types": "./dist/error.d.mts",
70
+ "default": "./dist/error.mjs"
64
71
  },
65
72
  "./session": {
66
73
  "types": "./dist/session/index.d.mts",
67
74
  "default": "./dist/session/index.mjs"
68
75
  },
76
+ "./dpop": {
77
+ "types": "./dist/dpop/index.d.mts",
78
+ "default": "./dist/dpop/index.mjs"
79
+ },
69
80
  "./internal": {
70
81
  "types": "./dist/core/internal.d.mts",
71
82
  "default": "./dist/core/internal.mjs"
@@ -105,7 +116,7 @@
105
116
  "simple-git-hooks": "^2.14.0",
106
117
  "supertest": "^7.3.1",
107
118
  "typescript": "^7.0.2",
108
- "unsecure": "^0.3.2",
119
+ "unsecure": "^0.3.4",
109
120
  "vitest": "^5.0.4"
110
121
  },
111
122
  "peerDependencies": {
@@ -142,6 +153,7 @@
142
153
  "dev:nitro": "pnpm --dir playgrounds/nitro dev",
143
154
  "dev:prepare": "obuild --stub && pnpm --dir playgrounds/nuxt-4 prepare && pnpm simple-git-hooks",
144
155
  "lint": "oxlint --deny-warnings . && oxfmt --check .",
156
+ "size": "vitest run test/bundle.test.ts --reporter=./test/_size-reporter.ts",
145
157
  "fmt": "automd && oxlint --fix . && oxfmt .",
146
158
  "test": "vitest run --slowTestThreshold=1000",
147
159
  "test:coverage": "vitest run --coverage --slowTestThreshold=1000",
package/dist/core/jwe.mjs DELETED
@@ -1,5 +0,0 @@
1
- import { UnsecureError } from "../_chunks/libs/unsecure.mjs";
2
- import { JWTError, isJWTError, isUnsecureError } from "../_chunks/_jwt-internal.mjs";
3
- import { DEFAULT_JOSE_LIMITS } from "../_chunks/jwk.mjs";
4
- import { decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened } from "../_chunks/jwe.mjs";
5
- export { DEFAULT_JOSE_LIMITS, JWTError, UnsecureError, decrypt, decryptMulti, encrypt, encryptMulti, generalToFlattened, isJWTError, isUnsecureError };