unjwt 0.5.14 → 0.5.15

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 CHANGED
@@ -111,7 +111,7 @@ Creates a JWS token.
111
111
  - `key`: The signing key (`CryptoKey`, `JWK`, or `Uint8Array` for symmetric keys).
112
112
  - `options`:
113
113
  - `alg`: (Required) The JWS algorithm (e.g., `"HS256"`, `"RS256"`, `"ES256"`, `"PS256"`).
114
- - `protectedHeader`: An object for additional JWS Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `b64`). If `payload` is an object and `typ` is not set, it defaults to `"at+jwt"`. The `b64` parameter ([RFC7797 section-3](https://datatracker.ietf.org/doc/html/rfc7797#section-3)) controls payload encoding (defaults to `true`, meaning Base64URL encoded).
114
+ - `protectedHeader`: An object for additional JWS Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `b64`). If `payload` is an object and `typ` is not set, it defaults to `"JWT"`. The `b64` parameter ([RFC7797 section-3](https://datatracker.ietf.org/doc/html/rfc7797#section-3)) controls payload encoding (defaults to `true`, meaning Base64URL encoded).
115
115
  - `expiresIn`: Sets an expiration time in seconds (e.g., `3600` for 1 hour). If `iat` is missing it will be set to the current time. If `exp` is missing it will be set to `iat + expiresIn`. This is only applied if `payload` is a JWT.
116
116
  - `currentDate`: The current date for computing `expiresIn` option. Defaults to `new Date()`.
117
117
 
@@ -155,6 +155,7 @@ Verifies a JWS token.
155
155
  A `KeyLookupFunction` has the signature `(header: JWSProtectedHeader, jws: string) => Promise<CryptoKey | JWK | JWKSet | Uint8Array> | CryptoKey | JWK | JWKSet | Uint8Array`.
156
156
  - `options` (optional):
157
157
  - `algorithms`: An array of allowed JWS `alg` values. If not provided, the `alg` from the JWS header is used.
158
+ - `validateJWT`: Unless false, will parse payload as JWT and validate claims if applicable (typ includes "jwt", case insensitive). Default `undefined`.
158
159
  - `critical`: An array of JWS header parameter names that the application understands and processes.
159
160
 
160
161
  Returns a `Promise<JWSVerifyResult<T>>` which is an object `{ payload: T, protectedHeader: JWSProtectedHeader }`.
@@ -170,7 +171,7 @@ const secret = "supersecretkey";
170
171
 
171
172
  const { payload, protectedHeader } = await verify(token, secret);
172
173
  console.log(payload); // { message: "My important data" }
173
- console.log(protectedHeader); // { alg: "HS256", typ: "at+jwt" }
174
+ console.log(protectedHeader); // { alg: "HS256", typ: "JWT" }
174
175
  ```
175
176
 
176
177
  **Example (RS256 with key lookup):**
@@ -210,7 +211,7 @@ Encrypts data to produce a JWE token.
210
211
  - `options`:
211
212
  - `alg`: (Required) The JWE Key Management algorithm (e.g., `"A128KW"`, `"RSA-OAEP-256"`, `"PBES2-HS256+A128KW"`, `"ECDH-ES+A128KW"`), defaults depends on the key provided.
212
213
  - `enc`: (Required) The JWE Content Encryption algorithm (e.g., `"A128GCM"`, `"A256CBC-HS512"`), defaults depends on the key provided.
213
- - `protectedHeader`: An object for JWE Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `apu`, `apv`, `p2s`, `p2c`). If `payload` is an object and `typ` is not set, it defaults to `"at+jwt"`.
214
+ - `protectedHeader`: An object for JWE Protected Header parameters (e.g., `kid`, `typ`, `cty`, `crit`, `apu`, `apv`, `p2s`, `p2c`). If `payload` is an object and `typ` is not set, it defaults to `"JWT"`.
214
215
  - `cek`: (Optional) Provide your own Content Encryption Key (`CryptoKey` or `Uint8Array`).
215
216
  - `contentEncryptionIV`: (Optional) Provide your own Initialization Vector for content encryption (`Uint8Array`).
216
217
  - Other algorithm-specific options like `p2s`, `p2c` (for PBES2), `keyManagementIV`, `ecdhPartyUInfo`, `ecdhPartyVInfo`.
@@ -259,6 +260,7 @@ Decrypts a JWE token.
259
260
  A `JWEKeyLookupFunction` has the signature `(header: JWEHeaderParameters) => Promise<CryptoKey | JWK | string | Uint8Array> | CryptoKey | JWK | string | Uint8Array`.
260
261
  - `options` (optional):
261
262
  - `algorithms`: Array of allowed JWE Key Management `alg` values.
263
+ - `validateJWT`: Unless false, will parse payload as JWT and validate claims if applicable (typ includes "jwt", case insensitive). Default `undefined`.
262
264
  - `encryptionAlgorithms`: Array of allowed JWE Content Encryption `enc` values.
263
265
  - `critical`: Array of JWE header parameter names that the application understands.
264
266
  - `unwrappedKeyAlgorithm`: (For `unwrapKey` internally) Algorithm details for the CEK after unwrapping.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, r as JWK, M as JWKAlgorithm, N as JWKPEMAlgorithm, J as JWKParameters, s as JWKSet, A as JWK_AES_CBC_HMAC, B as JWK_AES_GCM, z as JWK_AES_GCM_KW, y as JWK_AES_KW, L as JWK_Asymmetric_Algorithm, h as JWK_EC, F as JWK_ECDH_ES, w as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, t as JWK_HMAC, n as JWK_OKP, m as JWK_OKP_Private, l as JWK_OKP_Public, H as JWK_OKP_SIGN, E as JWK_PBES2, q as JWK_Private, p as JWK_Public, k as JWK_RSA, x as JWK_RSA_ENC, v as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, u as JWK_RSA_SIGN, I as JWK_Symmetric_Algorithm, o as JWK_oct, Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims, O as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.BsgIQHVD.mjs';
2
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.qWts1U9J.mjs';
3
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.Cf7vmOhS.mjs';
4
- export { i as utils } from './shared/unjwt.BYaxDvLV.mjs';
2
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.Bw4pzdE0.mjs';
3
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, j as jwe } from './shared/unjwt.BeWVYyaf.mjs';
4
+ export { i as utils } from './shared/unjwt.CfL4cArP.mjs';
5
5
  export { j as jwk } from './shared/unjwt.C6b_GyXm.mjs';
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { i as utils } from './shared/unjwt.BEjwP_9W.mjs';
2
- export { j as jwe } from './shared/unjwt.B8wnSUll.mjs';
3
- export { j as jwk } from './shared/unjwt.BVlHlXdP.mjs';
4
- export { j as jws } from './shared/unjwt.skuKf53c.mjs';
5
- import './shared/unjwt.BaB7HUR1.mjs';
1
+ export { i as utils } from './shared/unjwt.CRHfsi7v.mjs';
2
+ export { j as jwe } from './shared/unjwt.BZ3B0Ak8.mjs';
3
+ export { j as jwk } from './shared/unjwt.D1MC63Yb.mjs';
4
+ export { j as jws } from './shared/unjwt.u3h40Nr-.mjs';
5
+ import './shared/unjwt.BpusjhPR.mjs';
package/dist/jwe.d.mts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims, O as JoseHeaderParameters } from './shared/unjwt.BsgIQHVD.mjs';
2
- export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.Cf7vmOhS.mjs';
2
+ export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters, g as decrypt, f as encrypt } from './shared/unjwt.BeWVYyaf.mjs';
package/dist/jwe.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import './shared/unjwt.BVlHlXdP.mjs';
2
- import './shared/unjwt.BEjwP_9W.mjs';
3
- export { d as decrypt, e as encrypt } from './shared/unjwt.B8wnSUll.mjs';
4
- import './shared/unjwt.BaB7HUR1.mjs';
1
+ import './shared/unjwt.D1MC63Yb.mjs';
2
+ import './shared/unjwt.CRHfsi7v.mjs';
3
+ export { d as decrypt, e as encrypt } from './shared/unjwt.BZ3B0Ak8.mjs';
4
+ import './shared/unjwt.BpusjhPR.mjs';
package/dist/jwk.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import './shared/unjwt.BEjwP_9W.mjs';
2
- export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.BVlHlXdP.mjs';
1
+ import './shared/unjwt.CRHfsi7v.mjs';
2
+ export { p as deriveKeyFromPassword, t as exportJWKToPEM, q as exportKey, o as generateKey, g as getJWKFromSet, s as importJWKFromPEM, i as importKey, m as unwrapKey, r as wrapKey } from './shared/unjwt.D1MC63Yb.mjs';
package/dist/jws.d.mts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { Q as JWT, R as JWTClaimValidationOptions, P as JWTClaims, O as JoseHeaderParameters } from './shared/unjwt.BsgIQHVD.mjs';
2
- export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.qWts1U9J.mjs';
2
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, f as JWSKeyLookupFunction, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.Bw4pzdE0.mjs';
package/dist/jws.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import './shared/unjwt.BVlHlXdP.mjs';
2
- import './shared/unjwt.BEjwP_9W.mjs';
3
- import './shared/unjwt.BaB7HUR1.mjs';
4
- export { s as sign, v as verify } from './shared/unjwt.skuKf53c.mjs';
1
+ import './shared/unjwt.D1MC63Yb.mjs';
2
+ import './shared/unjwt.CRHfsi7v.mjs';
3
+ import './shared/unjwt.BpusjhPR.mjs';
4
+ export { s as sign, v as verify } from './shared/unjwt.u3h40Nr-.mjs';
@@ -1,6 +1,6 @@
1
- import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.BVlHlXdP.mjs';
2
- import { k as concatUint8Arrays, t as textEncoder, l as assertCryptoKey, d as base64UrlEncode, m as isCryptoKey, a as isJWK, s as sanitizeObject, f as base64UrlDecode, r as randomBytes, b as applyTypCtyDefaults, c as computeJwtTimeClaims, n as getPlaintextBytes, o as decodePayloadFromBytes, p as validateCriticalHeadersJWE } from './unjwt.BEjwP_9W.mjs';
3
- import { c as checkKeyLength } from './unjwt.BaB7HUR1.mjs';
1
+ import { a as checkEncCryptoKey, u as uint32be, b as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, d as bitLengthCEK, f as jwkTokey, i as importKey, h as generateIV, l as encrypt$1, m as unwrapKey, n as decrypt$1 } from './unjwt.D1MC63Yb.mjs';
2
+ import { k as concatUint8Arrays, t as textEncoder, l as assertCryptoKey, d as base64UrlEncode, m as isCryptoKey, a as isJWK, s as sanitizeObject, f as base64UrlDecode, r as randomBytes, b as applyTypCtyDefaults, c as computeJwtTimeClaims, n as getPlaintextBytes, o as decodePayloadFromBytes, p as validateCriticalHeadersJWE, j as validateJwtClaims } from './unjwt.CRHfsi7v.mjs';
3
+ import { c as checkKeyLength } from './unjwt.BpusjhPR.mjs';
4
4
 
5
5
  function lengthAndInput(input) {
6
6
  return concatUint8Arrays(uint32be(input.length), input);
@@ -293,7 +293,7 @@ async function encrypt(payload, key, options = {}) {
293
293
  ];
294
294
  return jweParts.join(".");
295
295
  }
296
- async function decrypt(jwe, key, options) {
296
+ async function decrypt(jwe, key, options = {}) {
297
297
  const parts = jwe.split(".");
298
298
  if (parts.length !== 5) {
299
299
  throw new Error(
@@ -375,6 +375,9 @@ async function decrypt(jwe, key, options) {
375
375
  ...options?.critical || [],
376
376
  ...options?.requiredHeaders || []
377
377
  ]);
378
+ if (payload && typeof payload === "object" && options.validateJWT !== false && (options.validateJWT === true || protectedHeader.typ?.toLowerCase().includes("jwt")) && !options.forceUint8Array && !(payload instanceof Uint8Array)) {
379
+ validateJwtClaims(payload, options);
380
+ }
378
381
  return {
379
382
  payload,
380
383
  protectedHeader,
@@ -72,7 +72,7 @@ interface JWEEncryptOptions {
72
72
  enc?: ContentEncryptionAlgorithm;
73
73
  /** Date to use when computing NumericDate claims, defaults to `new Date()`. */
74
74
  currentDate?: Date;
75
- /** Time at which the JWT should expire, if no `exp` was already provided (only when typ is "at+jwt"). */
75
+ /** Time at which the JWT should expire, if no `exp` was already provided (only when typ is "JWT" or explicitly parsing JWT). */
76
76
  expiresIn?: number;
77
77
  /** Additional JWE Protected Header parameters. */
78
78
  protectedHeader?: Omit<JWEHeaderParameters, "alg" | "enc" | "iv" | "tag" | "p2s" | "p2c" | "apu" | "apv">;
@@ -119,6 +119,8 @@ interface JWEDecryptOptions extends JWTClaimValidationOptions {
119
119
  extractable?: boolean;
120
120
  /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred based on JWE headers. */
121
121
  forceUint8Array?: boolean;
122
+ /** Unless false, will parse payload as JWT and validate claims if applicable (typ "JWT"). */
123
+ validateJWT?: boolean;
122
124
  }
123
125
  /**
124
126
  * Result of a JWE decryption operation.
@@ -1,4 +1,4 @@
1
- import { c as checkSigCryptoKey } from './unjwt.BVlHlXdP.mjs';
1
+ import { c as checkSigCryptoKey } from './unjwt.D1MC63Yb.mjs';
2
2
 
3
3
  /**
4
4
  * This is a fork of Jose library's utility functions.
@@ -27,7 +27,7 @@ interface JWSSignOptions {
27
27
  alg?: JWSAlgorithm;
28
28
  /**
29
29
  * Additional protected header parameters. `alg` is automatically included.
30
- * `typ` defaults to "at+jwt" if not provided.
30
+ * `typ` defaults to "JWT" if not provided and payload is an object.
31
31
  */
32
32
  protectedHeader?: JWSHeaderParameters;
33
33
  /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
@@ -50,6 +50,8 @@ interface JWSVerifyOptions extends JWTClaimValidationOptions {
50
50
  algorithms?: JWSAlgorithm[];
51
51
  /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
52
52
  forceUint8Array?: boolean;
53
+ /** Unless false, will parse payload as JWT and validate claims if applicable (typ "JWT"). */
54
+ validateJWT?: boolean;
53
55
  }
54
56
  /**
55
57
  * Key lookup function for JWS verification.
@@ -1,22 +1,21 @@
1
1
  function applyTypCtyDefaults(header, payload) {
2
2
  const isObjectPayload = typeof payload === "object" && payload !== null && !(payload instanceof Uint8Array);
3
3
  if (header.typ === void 0 && isObjectPayload) {
4
- header.typ = "at+jwt";
4
+ header.typ = "JWT";
5
5
  }
6
- if ((header.typ === "at+jwt" || header.typ === "JWT") && isObjectPayload) {
6
+ if (header.typ?.toLowerCase().includes("jwt") && isObjectPayload) {
7
7
  header.cty ||= "application/json";
8
8
  }
9
9
  return header;
10
10
  }
11
- function isJsonContent(header) {
11
+ function isJWTContent(header) {
12
12
  if (!header) return false;
13
- if (header.typ === "at+jwt") return true;
14
- if (header.typ === "JWT") return true;
13
+ if (header.typ?.toLowerCase().includes("jwt")) return true;
15
14
  const cty = header.cty?.toLowerCase();
16
15
  return cty === "json" || cty === "application/json" || !!cty && cty.endsWith("+json");
17
16
  }
18
- function decodeMaybeJsonString(decodedString, header) {
19
- if (isJsonContent(header)) {
17
+ function decodeMaybeJWTString(decodedString, header) {
18
+ if (isJWTContent(header)) {
20
19
  const looksLikeJson = decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]");
21
20
  if (looksLikeJson) {
22
21
  try {
@@ -31,12 +30,12 @@ function decodeMaybeJsonString(decodedString, header) {
31
30
  function decodePayloadFromBytes(bytes, header, forceUint8Array) {
32
31
  if (forceUint8Array) return bytes;
33
32
  const decodedString = textDecoder.decode(bytes);
34
- return decodeMaybeJsonString(decodedString, header);
33
+ return decodeMaybeJWTString(decodedString, header);
35
34
  }
36
35
  function decodePayloadFromB64UrlSegment(payloadEncoded, header, forceUint8Array) {
37
36
  if (forceUint8Array) return base64UrlDecode(payloadEncoded, false);
38
37
  const decodedString = base64UrlDecode(payloadEncoded);
39
- return decodeMaybeJsonString(decodedString, header);
38
+ return decodeMaybeJWTString(decodedString, header);
40
39
  }
41
40
  function getPlaintextBytes(payload) {
42
41
  if (payload instanceof Uint8Array) return payload;
@@ -48,13 +47,13 @@ function getPlaintextBytes(payload) {
48
47
  );
49
48
  }
50
49
  function computeJwtTimeClaims(payload, headerTyp, expiresIn, currentDate = /* @__PURE__ */ new Date()) {
51
- if (expiresIn === void 0 || headerTyp !== "at+jwt" && headerTyp !== "JWT" || !(payload && typeof payload === "object") || payload instanceof Uint8Array || payload.exp) {
50
+ if (expiresIn === void 0 || !headerTyp?.toLowerCase().includes("jwt") || !(payload && typeof payload === "object") || payload instanceof Uint8Array || payload.exp) {
52
51
  return void 0;
53
52
  }
54
53
  const now = Math.round(currentDate.getTime() / 1e3);
55
54
  const claims = { ...payload };
56
55
  claims.iat ||= now;
57
- claims.exp = now + expiresIn;
56
+ claims.exp = claims.iat + expiresIn;
58
57
  return claims;
59
58
  }
60
59
  function validateJwtClaims(jwtClaims, options = {}) {
@@ -362,7 +361,7 @@ const index = {
362
361
  base64UrlEncode: base64UrlEncode,
363
362
  computeJwtTimeClaims: computeJwtTimeClaims,
364
363
  concatUint8Arrays: concatUint8Arrays,
365
- decodeMaybeJsonString: decodeMaybeJsonString,
364
+ decodeMaybeJWTString: decodeMaybeJWTString,
366
365
  decodePayloadFromB64UrlSegment: decodePayloadFromB64UrlSegment,
367
366
  decodePayloadFromBytes: decodePayloadFromBytes,
368
367
  getPlaintextBytes: getPlaintextBytes,
@@ -371,7 +370,7 @@ const index = {
371
370
  isCryptoKeyPair: isCryptoKeyPair,
372
371
  isJWK: isJWK,
373
372
  isJWKSet: isJWKSet,
374
- isJsonContent: isJsonContent,
373
+ isJWTContent: isJWTContent,
375
374
  isPrivateJWK: isPrivateJWK,
376
375
  isPublicJWK: isPublicJWK,
377
376
  isSymmetricJWK: isSymmetricJWK,
@@ -385,4 +384,4 @@ const index = {
385
384
  validateJwtClaims: validateJwtClaims
386
385
  };
387
386
 
388
- export { isPrivateJWK as A, isPublicJWK as B, isJsonContent as C, decodeMaybeJsonString as D, isJWK as a, applyTypCtyDefaults as b, computeJwtTimeClaims as c, base64UrlEncode as d, textDecoder as e, base64UrlDecode as f, isJWKSet as g, decodePayloadFromB64UrlSegment as h, index as i, validateJwtClaims as j, concatUint8Arrays as k, assertCryptoKey as l, isCryptoKey as m, getPlaintextBytes as n, decodePayloadFromBytes as o, validateCriticalHeadersJWE as p, base64Decode as q, randomBytes as r, sanitizeObject as s, textEncoder as t, base64Encode as u, validateCriticalHeadersJWS as v, maybeArray as w, isCryptoKeyPair as x, isSymmetricJWK as y, isAsymmetricJWK as z };
387
+ export { isPrivateJWK as A, isPublicJWK as B, isJWTContent as C, decodeMaybeJWTString as D, isJWK as a, applyTypCtyDefaults as b, computeJwtTimeClaims as c, base64UrlEncode as d, textDecoder as e, base64UrlDecode as f, isJWKSet as g, decodePayloadFromB64UrlSegment as h, index as i, validateJwtClaims as j, concatUint8Arrays as k, assertCryptoKey as l, isCryptoKey as m, getPlaintextBytes as n, decodePayloadFromBytes as o, validateCriticalHeadersJWE as p, base64Decode as q, randomBytes as r, sanitizeObject as s, textEncoder as t, base64Encode as u, validateCriticalHeadersJWS as v, maybeArray as w, isCryptoKeyPair as x, isSymmetricJWK as y, isAsymmetricJWK as z };
@@ -2,22 +2,22 @@ import { P as JWTClaims, R as JWTClaimValidationOptions, r as JWK, s as JWKSet,
2
2
 
3
3
  /**
4
4
  * Apply default typ/cty semantics shared by JWS & JWE.
5
- * - If typ is undefined and payload is a non-Uint8Array object, set typ="at+jwt".
6
- * - If typ is "at+jwt" and payload is a non-Uint8Array object, ensure cty defaults to "application/json".
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
7
  */
8
8
  declare function applyTypCtyDefaults<T extends {
9
9
  typ?: string;
10
10
  cty?: string;
11
11
  }>(header: T, payload: unknown): T;
12
12
  /** Returns true when headers indicate JSON content. */
13
- declare function isJsonContent(header: {
13
+ declare function isJWTContent(header: {
14
14
  typ?: string;
15
15
  cty?: string;
16
16
  } | undefined): boolean;
17
17
  /**
18
18
  * Given a decoded string and JOSE headers, return an object if JSON, otherwise the string.
19
19
  */
20
- declare function decodeMaybeJsonString<T = unknown>(decodedString: string, header: {
20
+ declare function decodeMaybeJWTString<T = unknown>(decodedString: string, header: {
21
21
  typ?: string;
22
22
  cty?: string;
23
23
  } | undefined): T | string;
@@ -107,7 +107,7 @@ declare const index_base64UrlDecode: typeof base64UrlDecode;
107
107
  declare const index_base64UrlEncode: typeof base64UrlEncode;
108
108
  declare const index_computeJwtTimeClaims: typeof computeJwtTimeClaims;
109
109
  declare const index_concatUint8Arrays: typeof concatUint8Arrays;
110
- declare const index_decodeMaybeJsonString: typeof decodeMaybeJsonString;
110
+ declare const index_decodeMaybeJWTString: typeof decodeMaybeJWTString;
111
111
  declare const index_decodePayloadFromB64UrlSegment: typeof decodePayloadFromB64UrlSegment;
112
112
  declare const index_decodePayloadFromBytes: typeof decodePayloadFromBytes;
113
113
  declare const index_getPlaintextBytes: typeof getPlaintextBytes;
@@ -116,7 +116,7 @@ declare const index_isCryptoKey: typeof isCryptoKey;
116
116
  declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
117
117
  declare const index_isJWK: typeof isJWK;
118
118
  declare const index_isJWKSet: typeof isJWKSet;
119
- declare const index_isJsonContent: typeof isJsonContent;
119
+ declare const index_isJWTContent: typeof isJWTContent;
120
120
  declare const index_isPrivateJWK: typeof isPrivateJWK;
121
121
  declare const index_isPublicJWK: typeof isPublicJWK;
122
122
  declare const index_isSymmetricJWK: typeof isSymmetricJWK;
@@ -138,7 +138,7 @@ declare namespace index {
138
138
  index_base64UrlEncode as base64UrlEncode,
139
139
  index_computeJwtTimeClaims as computeJwtTimeClaims,
140
140
  index_concatUint8Arrays as concatUint8Arrays,
141
- index_decodeMaybeJsonString as decodeMaybeJsonString,
141
+ index_decodeMaybeJWTString as decodeMaybeJWTString,
142
142
  index_decodePayloadFromB64UrlSegment as decodePayloadFromB64UrlSegment,
143
143
  index_decodePayloadFromBytes as decodePayloadFromBytes,
144
144
  index_getPlaintextBytes as getPlaintextBytes,
@@ -147,7 +147,7 @@ declare namespace index {
147
147
  index_isCryptoKeyPair as isCryptoKeyPair,
148
148
  index_isJWK as isJWK,
149
149
  index_isJWKSet as isJWKSet,
150
- index_isJsonContent as isJsonContent,
150
+ index_isJWTContent as isJWTContent,
151
151
  index_isPrivateJWK as isPrivateJWK,
152
152
  index_isPublicJWK as isPublicJWK,
153
153
  index_isSymmetricJWK as isSymmetricJWK,
@@ -162,4 +162,4 @@ declare namespace index {
162
162
  };
163
163
  }
164
164
 
165
- export { validateJwtClaims as A, validateCriticalHeadersJWS as B, validateCriticalHeadersJWE as C, sanitizeObject as D, textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, isSymmetricJWK as n, isAsymmetricJWK as o, isPrivateJWK as p, isPublicJWK as q, randomBytes as r, applyTypCtyDefaults as s, textEncoder as t, isJsonContent as u, decodeMaybeJsonString as v, decodePayloadFromBytes as w, decodePayloadFromB64UrlSegment as x, getPlaintextBytes as y, computeJwtTimeClaims as z };
165
+ export { validateJwtClaims as A, validateCriticalHeadersJWS as B, validateCriticalHeadersJWE as C, sanitizeObject as D, textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, isJWKSet as h, index as i, assertCryptoKey as j, isCryptoKey as k, isCryptoKeyPair as l, maybeArray as m, isSymmetricJWK as n, isAsymmetricJWK as o, isPrivateJWK as p, isPublicJWK as q, randomBytes as r, applyTypCtyDefaults as s, textEncoder as t, isJWTContent as u, decodeMaybeJWTString as v, decodePayloadFromBytes as w, decodePayloadFromB64UrlSegment as x, getPlaintextBytes as y, computeJwtTimeClaims as z };
@@ -1,4 +1,4 @@
1
- import { m as isCryptoKey, k as concatUint8Arrays, d as base64UrlEncode, q as base64Decode, u as base64Encode, s as sanitizeObject, t as textEncoder, r as randomBytes, a as isJWK, f as base64UrlDecode, g as isJWKSet } from './unjwt.BEjwP_9W.mjs';
1
+ import { m as isCryptoKey, k as concatUint8Arrays, d as base64UrlEncode, q as base64Decode, u as base64Encode, s as sanitizeObject, t as textEncoder, r as randomBytes, a as isJWK, f as base64UrlDecode, g as isJWKSet } from './unjwt.CRHfsi7v.mjs';
2
2
 
3
3
  /**
4
4
  * This is a fork of Jose library's utility functions.
@@ -1,6 +1,6 @@
1
- import { i as importKey, g as getJWKFromSet } from './unjwt.BVlHlXdP.mjs';
2
- import { s as sanitizeObject, a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, e as textDecoder, f as base64UrlDecode, g as isJWKSet, h as decodePayloadFromB64UrlSegment, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './unjwt.BEjwP_9W.mjs';
3
- import { s as sign$1, v as verify$1 } from './unjwt.BaB7HUR1.mjs';
1
+ import { i as importKey, g as getJWKFromSet } from './unjwt.D1MC63Yb.mjs';
2
+ import { s as sanitizeObject, a as isJWK, b as applyTypCtyDefaults, c as computeJwtTimeClaims, d as base64UrlEncode, t as textEncoder, e as textDecoder, f as base64UrlDecode, g as isJWKSet, h as decodePayloadFromB64UrlSegment, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './unjwt.CRHfsi7v.mjs';
3
+ import { s as sign$1, v as verify$1 } from './unjwt.BpusjhPR.mjs';
4
4
 
5
5
  async function sign(payload, key, options = {}) {
6
6
  const { protectedHeader: additionalProtectedHeader } = options;
@@ -130,7 +130,7 @@ async function verify(jws, key, options = {}) {
130
130
  ...options.critical || [],
131
131
  ...options.requiredHeaders || []
132
132
  ]);
133
- if (payload && typeof payload === "object" && (protectedHeader.typ === "at+jwt" || protectedHeader.typ === "JWT") && !options.forceUint8Array) {
133
+ if (payload && typeof payload === "object" && options.validateJWT !== false && (options.validateJWT === true || protectedHeader.typ?.toLowerCase().includes("jwt")) && !options.forceUint8Array && !(payload instanceof Uint8Array)) {
134
134
  validateJwtClaims(payload, options);
135
135
  }
136
136
  return {
package/dist/utils.d.mts CHANGED
@@ -1,2 +1,2 @@
1
1
  import './shared/unjwt.BsgIQHVD.mjs';
2
- export { s as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, z as computeJwtTimeClaims, f as concatUint8Arrays, v as decodeMaybeJsonString, x as decodePayloadFromB64UrlSegment, w as decodePayloadFromBytes, y as getPlaintextBytes, o as isAsymmetricJWK, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, u as isJsonContent, p as isPrivateJWK, q as isPublicJWK, n as isSymmetricJWK, m as maybeArray, r as randomBytes, D as sanitizeObject, a as textDecoder, t as textEncoder, C as validateCriticalHeadersJWE, B as validateCriticalHeadersJWS, A as validateJwtClaims } from './shared/unjwt.BYaxDvLV.mjs';
2
+ export { s as applyTypCtyDefaults, j as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, z as computeJwtTimeClaims, f as concatUint8Arrays, v as decodeMaybeJWTString, x as decodePayloadFromB64UrlSegment, w as decodePayloadFromBytes, y as getPlaintextBytes, o as isAsymmetricJWK, k as isCryptoKey, l as isCryptoKeyPair, g as isJWK, h as isJWKSet, u as isJWTContent, p as isPrivateJWK, q as isPublicJWK, n as isSymmetricJWK, m as maybeArray, r as randomBytes, D as sanitizeObject, a as textDecoder, t as textEncoder, C as validateCriticalHeadersJWE, B as validateCriticalHeadersJWS, A as validateJwtClaims } from './shared/unjwt.CfL4cArP.mjs';
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode, u as base64Encode, f as base64UrlDecode, d as base64UrlEncode, c as computeJwtTimeClaims, k as concatUint8Arrays, D as decodeMaybeJsonString, h as decodePayloadFromB64UrlSegment, o as decodePayloadFromBytes, n as getPlaintextBytes, z as isAsymmetricJWK, m as isCryptoKey, x as isCryptoKeyPair, a as isJWK, g as isJWKSet, C as isJsonContent, A as isPrivateJWK, B as isPublicJWK, y as isSymmetricJWK, w as maybeArray, r as randomBytes, s as sanitizeObject, e as textDecoder, t as textEncoder, p as validateCriticalHeadersJWE, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './shared/unjwt.BEjwP_9W.mjs';
1
+ export { b as applyTypCtyDefaults, l as assertCryptoKey, q as base64Decode, u as base64Encode, f as base64UrlDecode, d as base64UrlEncode, c as computeJwtTimeClaims, k as concatUint8Arrays, D as decodeMaybeJWTString, h as decodePayloadFromB64UrlSegment, o as decodePayloadFromBytes, n as getPlaintextBytes, z as isAsymmetricJWK, m as isCryptoKey, x as isCryptoKeyPair, a as isJWK, g as isJWKSet, C as isJWTContent, A as isPrivateJWK, B as isPublicJWK, y as isSymmetricJWK, w as maybeArray, r as randomBytes, s as sanitizeObject, e as textDecoder, t as textEncoder, p as validateCriticalHeadersJWE, v as validateCriticalHeadersJWS, j as validateJwtClaims } from './shared/unjwt.CRHfsi7v.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.5.14",
3
+ "version": "0.5.15",
4
4
  "description": "Low-level JWT utilities",
5
5
  "repository": "sandros94/unjwt",
6
6
  "license": "MIT",
@@ -47,20 +47,21 @@
47
47
  "release": "pnpm test && pnpm prepack && changelogen --release --push --publish",
48
48
  "test": "pnpm lint && pnpm test:types && vitest run --slowTestThreshold=500",
49
49
  "test:coverage": "pnpm lint && pnpm test:types && vitest run --coverage --slowTestThreshold=500",
50
- "test:types": "tsc --noEmit --skipLibCheck"
50
+ "test:types": "tsc --noEmit --skipLibCheck",
51
+ "bench": "vitest bench --run"
51
52
  },
52
53
  "devDependencies": {
53
- "@types/node": "^22.13.14",
54
+ "@types/node": "^22",
54
55
  "@vitest/coverage-v8": "^3.2.4",
55
- "automd": "^0.4.0",
56
+ "automd": "^0.4.2",
56
57
  "changelogen": "^0.6.2",
57
- "eslint": "^9.34.0",
58
+ "eslint": "^9.36.0",
58
59
  "eslint-config-unjs": "^0.5.0",
59
- "jose": "^6.0.13",
60
+ "jose": "^6.1.0",
60
61
  "prettier": "^3.6.2",
61
62
  "typescript": "^5.9.2",
62
63
  "unbuild": "^3.6.1",
63
64
  "vitest": "^3.2.4"
64
65
  },
65
- "packageManager": "pnpm@10.15.0"
66
+ "packageManager": "pnpm@10.17.1"
66
67
  }