unjwt 0.5.1 → 0.5.2

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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, B as JWKAlgorithm, E as JWKPEMAlgorithm, J as JWKParameters, u as JWK_AES_CBC_HMAC, v as JWK_AES_GCM, t as JWK_AES_GCM_KW, s as JWK_AES_KW, A as JWK_Asymmetric_Algorithm, h as JWK_EC, x as JWK_ECDH_ES, q as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, y as JWK_ED, n as JWK_HMAC, w as JWK_PBES2, k as JWK_RSA, r as JWK_RSA_ENC, p as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, o as JWK_RSA_SIGN, z as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CxhGjEAX.mjs';
2
2
  export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.Cd9nTEWg.mjs';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.BG_R52ey.mjs';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.kiNPBQh0.mjs';
4
4
  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.DQIYSlHj.mjs';
5
- export { i as utils } from './shared/unjwt.B4fFiy1c.mjs';
5
+ export { i as utils } from './shared/unjwt.BJEchXrM.mjs';
6
6
  export { j as jwk } from './shared/unjwt.D1J1DelP.mjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { C as CompositeKey, d as ContentEncryptionAlgorithm, D as DeriveKeyOptions, c as DeriveKeyReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, m as JWK, B as JWKAlgorithm, E as JWKPEMAlgorithm, J as JWKParameters, u as JWK_AES_CBC_HMAC, v as JWK_AES_GCM, t as JWK_AES_GCM_KW, s as JWK_AES_KW, A as JWK_Asymmetric_Algorithm, h as JWK_EC, x as JWK_ECDH_ES, q as JWK_ECDSA, g as JWK_EC_Private, f as JWK_EC_Public, y as JWK_ED, n as JWK_HMAC, w as JWK_PBES2, k as JWK_RSA, r as JWK_RSA_ENC, p as JWK_RSA_PSS, j as JWK_RSA_Private, i as JWK_RSA_Public, o as JWK_RSA_SIGN, z as JWK_Symmetric_Algorithm, l as JWK_oct, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, e as WrapKeyResult } from './shared/unjwt.CxhGjEAX.js';
2
2
  export { b as JWT, a as JWTClaims, J as JoseHeaderParameters } from './shared/unjwt.BISJ5yt1.js';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.CVKbKOFy.js';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, j as jws } from './shared/unjwt.TbszLNOP.js';
4
4
  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.B0XDPf8a.js';
5
- export { i as utils } from './shared/unjwt.DqmNvXMd.js';
5
+ export { i as utils } from './shared/unjwt.B5N3dPN9.js';
6
6
  export { j as jwk } from './shared/unjwt.WvWb2zNM.js';
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { i as utils } from './shared/unjwt.DHdDAH0L.mjs';
2
- export { j as jwe } from './shared/unjwt.Ce72NmIz.mjs';
3
- export { j as jwk } from './shared/unjwt.1gbuWbc6.mjs';
4
- export { j as jws } from './shared/unjwt.BxqF-n1S.mjs';
5
- import './shared/unjwt.C9Xhi7hE.mjs';
1
+ export { i as utils } from './shared/unjwt.DOI5UE8K.mjs';
2
+ export { j as jwe } from './shared/unjwt.ByclPbtq.mjs';
3
+ export { j as jwk } from './shared/unjwt.ZsOShfhX.mjs';
4
+ export { j as jws } from './shared/unjwt.COPr8ebc.mjs';
5
+ import './shared/unjwt.z_U3fRJ-.mjs';
package/dist/jwe.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import './shared/unjwt.1gbuWbc6.mjs';
2
- import './shared/unjwt.DHdDAH0L.mjs';
3
- export { d as decrypt, e as encrypt } from './shared/unjwt.Ce72NmIz.mjs';
4
- import './shared/unjwt.C9Xhi7hE.mjs';
1
+ import './shared/unjwt.ZsOShfhX.mjs';
2
+ import './shared/unjwt.DOI5UE8K.mjs';
3
+ export { d as decrypt, e as encrypt } from './shared/unjwt.ByclPbtq.mjs';
4
+ import './shared/unjwt.z_U3fRJ-.mjs';
package/dist/jwk.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import './shared/unjwt.DHdDAH0L.mjs';
2
- export { o as deriveKeyFromPassword, s as exportJWKToPEM, p as exportKey, n as generateKey, r as importJWKFromPEM, i as importKey, l as unwrapKey, q as wrapKey } from './shared/unjwt.1gbuWbc6.mjs';
1
+ import './shared/unjwt.DOI5UE8K.mjs';
2
+ export { o as deriveKeyFromPassword, s as exportJWKToPEM, p as exportKey, n as generateKey, r as importJWKFromPEM, i as importKey, l as unwrapKey, q as wrapKey } from './shared/unjwt.ZsOShfhX.mjs';
package/dist/jws.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './shared/unjwt.CxhGjEAX.mjs';
2
2
  import './shared/unjwt.Cd9nTEWg.mjs';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.BG_R52ey.mjs';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.kiNPBQh0.mjs';
package/dist/jws.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './shared/unjwt.CxhGjEAX.js';
2
2
  import './shared/unjwt.BISJ5yt1.js';
3
- export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.CVKbKOFy.js';
3
+ export { J as JWSAlgorithm, a as JWSHeaderParameters, b as JWSProtectedHeader, c as JWSSignOptions, e as JWSVerifyOptions, d as JWSVerifyResult, s as sign, v as verify } from './shared/unjwt.TbszLNOP.js';
package/dist/jws.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import './shared/unjwt.1gbuWbc6.mjs';
2
- import './shared/unjwt.DHdDAH0L.mjs';
3
- import './shared/unjwt.C9Xhi7hE.mjs';
4
- export { s as sign, v as verify } from './shared/unjwt.BxqF-n1S.mjs';
1
+ import './shared/unjwt.ZsOShfhX.mjs';
2
+ import './shared/unjwt.DOI5UE8K.mjs';
3
+ import './shared/unjwt.z_U3fRJ-.mjs';
4
+ export { s as sign, v as verify } from './shared/unjwt.COPr8ebc.mjs';
@@ -15,6 +15,7 @@ declare function randomBytes(length: Readonly<number>): Uint8Array;
15
15
  * @returns Concatenated array
16
16
  */
17
17
  declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
18
+ declare function maybeArray<T>(item: T | T[]): T[];
18
19
  declare function isJWK(key: any): key is JWK;
19
20
  declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
20
21
  declare function isCryptoKey(key: unknown): key is CryptoKey;
@@ -29,6 +30,7 @@ declare const index_concatUint8Arrays: typeof concatUint8Arrays;
29
30
  declare const index_isCryptoKey: typeof isCryptoKey;
30
31
  declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
31
32
  declare const index_isJWK: typeof isJWK;
33
+ declare const index_maybeArray: typeof maybeArray;
32
34
  declare const index_randomBytes: typeof randomBytes;
33
35
  declare const index_textDecoder: typeof textDecoder;
34
36
  declare const index_textEncoder: typeof textEncoder;
@@ -43,10 +45,11 @@ declare namespace index {
43
45
  index_isCryptoKey as isCryptoKey,
44
46
  index_isCryptoKeyPair as isCryptoKeyPair,
45
47
  index_isJWK as isJWK,
48
+ index_maybeArray as maybeArray,
46
49
  index_randomBytes as randomBytes,
47
50
  index_textDecoder as textDecoder,
48
51
  index_textEncoder as textEncoder,
49
52
  };
50
53
  }
51
54
 
52
- export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, assertCryptoKey as h, index as i, isCryptoKey as j, isCryptoKeyPair as k, randomBytes as r, textEncoder as t };
55
+ export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, assertCryptoKey as h, index as i, isCryptoKey as j, isCryptoKeyPair as k, maybeArray as m, randomBytes as r, textEncoder as t };
@@ -15,6 +15,7 @@ declare function randomBytes(length: Readonly<number>): Uint8Array;
15
15
  * @returns Concatenated array
16
16
  */
17
17
  declare function concatUint8Arrays(...arrays: Readonly<Uint8Array[]>): Uint8Array;
18
+ declare function maybeArray<T>(item: T | T[]): T[];
18
19
  declare function isJWK(key: any): key is JWK;
19
20
  declare function assertCryptoKey(key: unknown): asserts key is CryptoKey;
20
21
  declare function isCryptoKey(key: unknown): key is CryptoKey;
@@ -29,6 +30,7 @@ declare const index_concatUint8Arrays: typeof concatUint8Arrays;
29
30
  declare const index_isCryptoKey: typeof isCryptoKey;
30
31
  declare const index_isCryptoKeyPair: typeof isCryptoKeyPair;
31
32
  declare const index_isJWK: typeof isJWK;
33
+ declare const index_maybeArray: typeof maybeArray;
32
34
  declare const index_randomBytes: typeof randomBytes;
33
35
  declare const index_textDecoder: typeof textDecoder;
34
36
  declare const index_textEncoder: typeof textEncoder;
@@ -43,10 +45,11 @@ declare namespace index {
43
45
  index_isCryptoKey as isCryptoKey,
44
46
  index_isCryptoKeyPair as isCryptoKeyPair,
45
47
  index_isJWK as isJWK,
48
+ index_maybeArray as maybeArray,
46
49
  index_randomBytes as randomBytes,
47
50
  index_textDecoder as textDecoder,
48
51
  index_textEncoder as textEncoder,
49
52
  };
50
53
  }
51
54
 
52
- export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, assertCryptoKey as h, index as i, isCryptoKey as j, isCryptoKeyPair as k, randomBytes as r, textEncoder as t };
55
+ export { textDecoder as a, base64Encode as b, base64UrlEncode as c, base64Decode as d, base64UrlDecode as e, concatUint8Arrays as f, isJWK as g, assertCryptoKey as h, index as i, isCryptoKey as j, isCryptoKeyPair as k, maybeArray as m, randomBytes as r, textEncoder as t };
@@ -1,6 +1,6 @@
1
- import { a as checkEncCryptoKey, u as uint32be, g as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, b as bitLengthCEK, d as jwkTokey, i as importKey, f as generateIV, h as encrypt$1, l as unwrapKey, m as decrypt$1 } from './unjwt.1gbuWbc6.mjs';
2
- import { e as concatUint8Arrays, t as textEncoder, f as assertCryptoKey, b as base64UrlEncode, g as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.DHdDAH0L.mjs';
3
- import { c as checkKeyLength } from './unjwt.C9Xhi7hE.mjs';
1
+ import { a as checkEncCryptoKey, u as uint32be, g as generateCEK, e as encryptIV, w as wrap, k as keyToJWK, b as bitLengthCEK, d as jwkTokey, i as importKey, f as generateIV, h as encrypt$1, l as unwrapKey, m as decrypt$1 } from './unjwt.ZsOShfhX.mjs';
2
+ import { e as concatUint8Arrays, t as textEncoder, f as assertCryptoKey, b as base64UrlEncode, g as isCryptoKey, a as isJWK, d as base64UrlDecode, r as randomBytes, c as textDecoder } from './unjwt.DOI5UE8K.mjs';
3
+ import { c as checkKeyLength } from './unjwt.z_U3fRJ-.mjs';
4
4
 
5
5
  function lengthAndInput(input) {
6
6
  return concatUint8Arrays(uint32be(input.length), input);
@@ -1,6 +1,6 @@
1
- import { i as importKey } from './unjwt.1gbuWbc6.mjs';
2
- import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode } from './unjwt.DHdDAH0L.mjs';
3
- import { s as sign$1, v as verify$1 } from './unjwt.C9Xhi7hE.mjs';
1
+ import { i as importKey } from './unjwt.ZsOShfhX.mjs';
2
+ import { a as isJWK, b as base64UrlEncode, t as textEncoder, c as textDecoder, d as base64UrlDecode, m as maybeArray } from './unjwt.DOI5UE8K.mjs';
3
+ import { s as sign$1, v as verify$1 } from './unjwt.z_U3fRJ-.mjs';
4
4
 
5
5
  async function sign(payload, key, options = {}) {
6
6
  const { protectedHeader: additionalProtectedHeader } = options;
@@ -48,7 +48,7 @@ async function sign(payload, key, options = {}) {
48
48
  const signatureEncoded = base64UrlEncode(signatureBytes);
49
49
  return `${signingInputString}.${signatureEncoded}`;
50
50
  }
51
- async function verify(jws, key, options) {
51
+ async function verify(jws, key, options = {}) {
52
52
  const parts = jws.split(".");
53
53
  if (parts.length !== 3) {
54
54
  throw new Error("Invalid JWS: Must contain three parts separated by dots.");
@@ -69,9 +69,14 @@ async function verify(jws, key, options) {
69
69
  );
70
70
  }
71
71
  const alg = protectedHeader.alg;
72
- if (options?.algorithms && !options.algorithms.includes(alg)) {
72
+ if (options.algorithms && !options.algorithms.includes(alg)) {
73
73
  throw new Error(`Algorithm not allowed: ${alg}`);
74
74
  }
75
+ if (options.typ && protectedHeader.typ !== options.typ) {
76
+ throw new Error(
77
+ `Invalid JWS: "typ" (Type) Header Parameter mismatch. Expected "${options.typ}", got "${protectedHeader.typ}".`
78
+ );
79
+ }
75
80
  let signatureBytes;
76
81
  try {
77
82
  signatureBytes = base64UrlDecode(signatureEncoded, false);
@@ -97,13 +102,13 @@ async function verify(jws, key, options) {
97
102
  let payload;
98
103
  try {
99
104
  if (useB64) {
100
- if (options?.forceUint8Array) {
105
+ if (options.forceUint8Array) {
101
106
  payload = base64UrlDecode(payloadEncoded, false);
102
107
  } else {
103
108
  const cty = protectedHeader.cty?.toLowerCase();
104
109
  const isJsonOutput = protectedHeader.typ === "JWT" || cty === "json" || cty === "application/json" || cty && cty.endsWith("+json");
110
+ const decodedString = base64UrlDecode(payloadEncoded);
105
111
  if (isJsonOutput) {
106
- const decodedString = base64UrlDecode(payloadEncoded, true);
107
112
  if (decodedString.startsWith("{") && decodedString.endsWith("}") || decodedString.startsWith("[") && decodedString.endsWith("]")) {
108
113
  try {
109
114
  payload = JSON.parse(decodedString);
@@ -114,21 +119,23 @@ async function verify(jws, key, options) {
114
119
  payload = decodedString;
115
120
  }
116
121
  } else {
117
- payload = base64UrlDecode(payloadEncoded);
122
+ payload = decodedString;
118
123
  }
119
124
  }
120
125
  } else {
121
- payload = textEncoder.encode(payloadEncoded);
126
+ payload = options.forceUint8Array ? textEncoder.encode(payloadEncoded) : payloadEncoded;
122
127
  }
123
128
  } catch (error_) {
124
129
  throw new Error(
125
130
  `Invalid JWS: Payload decoding failed (${error_ instanceof Error ? error_.message : error_})`
126
131
  );
127
132
  }
128
- if (options?.critical && protectedHeader.crit) {
133
+ if (protectedHeader.crit) {
134
+ const missingHeaderParams = /* @__PURE__ */ new Set();
129
135
  const recognizedParams = /* @__PURE__ */ new Set([
130
- ...Object.keys(protectedHeader),
131
136
  ...options.critical || [],
137
+ // TODO: remove deprecated option
138
+ ...options.requiredHeaders || [],
132
139
  "alg",
133
140
  "typ",
134
141
  "cty",
@@ -140,17 +147,88 @@ async function verify(jws, key, options) {
140
147
  "x5u",
141
148
  "b64"
142
149
  ]);
143
- for (const critParam of protectedHeader.crit) {
144
- if (!recognizedParams.has(critParam)) {
150
+ for (const param of protectedHeader.crit) {
151
+ if (recognizedParams.has(param) && (param in protectedHeader || param === "b64")) {
152
+ continue;
153
+ }
154
+ missingHeaderParams.add(param);
155
+ }
156
+ if (missingHeaderParams.size > 0) {
157
+ throw new Error(
158
+ `Missing critical header parameters: ${[...missingHeaderParams].join(", ")}`
159
+ );
160
+ }
161
+ }
162
+ if (payload && typeof payload === "object" && !options.forceUint8Array) {
163
+ const jwtClaims = payload;
164
+ const clockTolerance = (options.clockTolerance ?? 0) * 1e3;
165
+ const currentDate = options.currentDate ?? /* @__PURE__ */ new Date();
166
+ const currentTime = currentDate.getTime();
167
+ const allRequiredClaims = new Set(options.requiredClaims || []);
168
+ const missingClaims = /* @__PURE__ */ new Set();
169
+ if (options.issuer) allRequiredClaims.add("iss");
170
+ if (options.audience) allRequiredClaims.add("aud");
171
+ if (options.subject) allRequiredClaims.add("sub");
172
+ if (options.maxTokenAge) allRequiredClaims.add("iat");
173
+ for (const claimName of allRequiredClaims) {
174
+ if (!(claimName in jwtClaims)) {
175
+ missingClaims.add(claimName);
176
+ }
177
+ }
178
+ if (missingClaims.size > 0) {
179
+ throw new Error(
180
+ `Missing required JWT Claims: ${[...missingClaims].join(", ")}`
181
+ );
182
+ }
183
+ if (options.issuer) {
184
+ const expectedIssuers = maybeArray(options.issuer);
185
+ if (!jwtClaims.iss || !expectedIssuers.includes(jwtClaims.iss)) {
145
186
  throw new Error(
146
- `Critical header parameter not understood: ${critParam}`
187
+ `Invalid JWT "iss" (Issuer) Claim: Expected ${expectedIssuers.join(" or ")}, got ${jwtClaims.iss}`
188
+ );
189
+ }
190
+ }
191
+ if (options.subject && jwtClaims.sub !== options.subject) {
192
+ throw new Error(
193
+ `Invalid JWT "sub" (Subject) Claim: Expected ${options.subject}, got ${jwtClaims.sub}`
194
+ );
195
+ }
196
+ if (options.audience) {
197
+ const expectedAudiences = maybeArray(options.audience);
198
+ const claimAudience = maybeArray(jwtClaims.aud || []);
199
+ if (!claimAudience.some((aud) => expectedAudiences.includes(aud))) {
200
+ throw new Error(
201
+ `Invalid JWT "aud" (Audience) Claim: Expected ${expectedAudiences.join(" or ")}, got ${claimAudience.join(", ")}`
202
+ );
203
+ }
204
+ }
205
+ if (typeof jwtClaims.nbf === "number" && jwtClaims.nbf * 1e3 > currentTime + clockTolerance) {
206
+ throw new Error(
207
+ `JWT "nbf" (Not Before) Claim validation failed: Token is not yet valid (nbf: ${new Date(jwtClaims.nbf * 1e3).toISOString()})`
208
+ );
209
+ }
210
+ if (typeof jwtClaims.exp === "number" && jwtClaims.exp * 1e3 <= currentTime - clockTolerance) {
211
+ throw new Error(
212
+ `JWT "exp" (Expiration Time) Claim validation failed: Token has expired (exp: ${new Date(jwtClaims.exp * 1e3).toISOString()})`
213
+ );
214
+ }
215
+ if (options.maxTokenAge) {
216
+ if (typeof jwtClaims.iat !== "number") {
217
+ throw new TypeError(
218
+ 'JWT "iat" (Issued At) Claim must be a number when maxTokenAge is set.'
219
+ );
220
+ }
221
+ if (jwtClaims.iat * 1e3 > currentTime + clockTolerance) {
222
+ throw new Error(
223
+ `JWT "iat" (Issued At) Claim validation failed: Token was issued in the future (iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
224
+ );
225
+ }
226
+ if (jwtClaims.iat * 1e3 < currentTime - options.maxTokenAge * 1e3 - clockTolerance) {
227
+ throw new Error(
228
+ `JWT "iat" (Issued At) Claim validation failed: Token is too old (maxTokenAge: ${options.maxTokenAge}s, iat: ${new Date(jwtClaims.iat * 1e3).toISOString()})`
147
229
  );
148
230
  }
149
231
  }
150
- } else if (!options?.critical && protectedHeader.crit) {
151
- throw new Error(
152
- `Unprocessed critical header parameters: ${protectedHeader.crit.join(", ")}`
153
- );
154
232
  }
155
233
  return {
156
234
  payload,
@@ -51,6 +51,9 @@ function concatUint8Arrays(...arrays) {
51
51
  }
52
52
  return result;
53
53
  }
54
+ function maybeArray(item) {
55
+ return Array.isArray(item) ? item : [item];
56
+ }
54
57
  function isJWK(key) {
55
58
  return typeof key === "object" && key !== null && "kty" in key && typeof key.kty === "string";
56
59
  }
@@ -75,9 +78,10 @@ const index = {
75
78
  isCryptoKey: isCryptoKey,
76
79
  isCryptoKeyPair: isCryptoKeyPair,
77
80
  isJWK: isJWK,
81
+ maybeArray: maybeArray,
78
82
  randomBytes: randomBytes,
79
83
  textDecoder: textDecoder,
80
84
  textEncoder: textEncoder
81
85
  };
82
86
 
83
- export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, concatUint8Arrays as e, assertCryptoKey as f, isCryptoKey as g, base64Decode as h, index as i, base64Encode as j, isCryptoKeyPair as k, randomBytes as r, textEncoder as t };
87
+ export { isJWK as a, base64UrlEncode as b, textDecoder as c, base64UrlDecode as d, concatUint8Arrays as e, assertCryptoKey as f, isCryptoKey as g, base64Decode as h, index as i, base64Encode as j, isCryptoKeyPair as k, maybeArray as m, randomBytes as r, textEncoder as t };
@@ -43,10 +43,63 @@ interface JWSVerifyResult<T = JWTClaims | Uint8Array | string> {
43
43
  interface JWSVerifyOptions {
44
44
  /** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
45
45
  algorithms?: JWSAlgorithm[];
46
- /** List of critical header parameters that must be understood and processed. */
47
- critical?: string[];
48
46
  /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
49
47
  forceUint8Array?: boolean;
48
+ /** List of critical header parameters that must be understood and processed. */
49
+ requiredHeaders?: string[];
50
+ /**
51
+ * Expected JWT "aud" (Audience) Claim value(s).
52
+ *
53
+ * This option makes the JWT "aud" (Audience) Claim presence required.
54
+ */
55
+ audience?: string | string[];
56
+ /**
57
+ * Clock skew tolerance (in seconds) for validating JWT claims.
58
+ *
59
+ * Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
60
+ * validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
61
+ */
62
+ clockTolerance?: number;
63
+ /**
64
+ * Expected JWT "iss" (Issuer) Claim value(s).
65
+ *
66
+ * This option makes the JWT "iss" (Issuer) Claim presence required.
67
+ */
68
+ issuer?: string | string[];
69
+ /**
70
+ * Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
71
+ *
72
+ * This option makes the JWT "iat" (Issued At) Claim presence required.
73
+ */
74
+ maxTokenAge?: number;
75
+ /**
76
+ * Expected JWT "sub" (Subject) Claim value.
77
+ *
78
+ * This option makes the JWT "sub" (Subject) Claim presence required.
79
+ */
80
+ subject?: string;
81
+ /**
82
+ * Expected JWT "typ" (Type) Header Parameter value.
83
+ *
84
+ * This option makes the JWT "typ" (Type) Header Parameter presence required.
85
+ */
86
+ typ?: string;
87
+ /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
88
+ currentDate?: Date;
89
+ /**
90
+ * Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
91
+ * the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
92
+ * {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
93
+ * the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
94
+ * the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
95
+ * present.
96
+ */
97
+ requiredClaims?: string[];
98
+ /**
99
+ * List of critical header parameters that must be understood and processed.
100
+ * @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
101
+ */
102
+ critical?: string[];
50
103
  }
51
104
 
52
105
  /**
@@ -1,4 +1,4 @@
1
- import { g as isCryptoKey, e as concatUint8Arrays, b as base64UrlEncode, h as base64Decode, j as base64Encode, t as textEncoder, r as randomBytes, a as isJWK, d as base64UrlDecode } from './unjwt.DHdDAH0L.mjs';
1
+ import { g as isCryptoKey, e as concatUint8Arrays, b as base64UrlEncode, h as base64Decode, j as base64Encode, t as textEncoder, r as randomBytes, a as isJWK, d as base64UrlDecode } from './unjwt.DOI5UE8K.mjs';
2
2
 
3
3
  /**
4
4
  * This is a fork of Jose library's utility functions.
@@ -43,10 +43,63 @@ interface JWSVerifyResult<T = JWTClaims | Uint8Array | string> {
43
43
  interface JWSVerifyOptions {
44
44
  /** List of allowed algorithms. If provided, the JWS `alg` must be in this list. */
45
45
  algorithms?: JWSAlgorithm[];
46
- /** List of critical header parameters that must be understood and processed. */
47
- critical?: string[];
48
46
  /** If true, forces the payload to be returned as a Uint8Array, otherwise type is inferred. */
49
47
  forceUint8Array?: boolean;
48
+ /** List of critical header parameters that must be understood and processed. */
49
+ requiredHeaders?: string[];
50
+ /**
51
+ * Expected JWT "aud" (Audience) Claim value(s).
52
+ *
53
+ * This option makes the JWT "aud" (Audience) Claim presence required.
54
+ */
55
+ audience?: string | string[];
56
+ /**
57
+ * Clock skew tolerance (in seconds) for validating JWT claims.
58
+ *
59
+ * Used when validating the JWT "nbf" (Not Before) and "exp" (Expiration Time) claims, and when
60
+ * validating the "iat" (Issued At) claim if the {@link maxTokenAge `maxTokenAge` option} is set.
61
+ */
62
+ clockTolerance?: number;
63
+ /**
64
+ * Expected JWT "iss" (Issuer) Claim value(s).
65
+ *
66
+ * This option makes the JWT "iss" (Issuer) Claim presence required.
67
+ */
68
+ issuer?: string | string[];
69
+ /**
70
+ * Maximum time elapsed (in seconds) from the JWT "iat" (Issued At) Claim value.
71
+ *
72
+ * This option makes the JWT "iat" (Issued At) Claim presence required.
73
+ */
74
+ maxTokenAge?: number;
75
+ /**
76
+ * Expected JWT "sub" (Subject) Claim value.
77
+ *
78
+ * This option makes the JWT "sub" (Subject) Claim presence required.
79
+ */
80
+ subject?: string;
81
+ /**
82
+ * Expected JWT "typ" (Type) Header Parameter value.
83
+ *
84
+ * This option makes the JWT "typ" (Type) Header Parameter presence required.
85
+ */
86
+ typ?: string;
87
+ /** Date to use when comparing NumericDate claims, defaults to `new Date()`. */
88
+ currentDate?: Date;
89
+ /**
90
+ * Array of required Claim Names that must be present in the JWT Claims Set. Default is that: if
91
+ * the {@link issuer `issuer` option} is set, then JWT "iss" (Issuer) Claim must be present; if the
92
+ * {@link audience `audience` option} is set, then JWT "aud" (Audience) Claim must be present; if
93
+ * the {@link subject `subject` option} is set, then JWT "sub" (Subject) Claim must be present; if
94
+ * the {@link maxTokenAge `maxTokenAge` option} is set, then JWT "iat" (Issued At) Claim must be
95
+ * present.
96
+ */
97
+ requiredClaims?: string[];
98
+ /**
99
+ * List of critical header parameters that must be understood and processed.
100
+ * @deprecated use {@link requiredHeaders `recognizedHeaders` option} instead.
101
+ */
102
+ critical?: string[];
50
103
  }
51
104
 
52
105
  /**
@@ -1,4 +1,4 @@
1
- import { c as checkSigCryptoKey } from './unjwt.1gbuWbc6.mjs';
1
+ import { c as checkSigCryptoKey } from './unjwt.ZsOShfhX.mjs';
2
2
 
3
3
  /**
4
4
  * This is a fork of Jose library's utility functions.
package/dist/utils.d.mts CHANGED
@@ -1,2 +1,2 @@
1
1
  import './shared/unjwt.CxhGjEAX.mjs';
2
- export { h as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, j as isCryptoKey, k as isCryptoKeyPair, g as isJWK, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.B4fFiy1c.mjs';
2
+ export { h as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, j as isCryptoKey, k as isCryptoKeyPair, g as isJWK, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.BJEchXrM.mjs';
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import './shared/unjwt.CxhGjEAX.js';
2
- export { h as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, j as isCryptoKey, k as isCryptoKeyPair, g as isJWK, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.DqmNvXMd.js';
2
+ export { h as assertCryptoKey, d as base64Decode, b as base64Encode, e as base64UrlDecode, c as base64UrlEncode, f as concatUint8Arrays, j as isCryptoKey, k as isCryptoKeyPair, g as isJWK, m as maybeArray, r as randomBytes, a as textDecoder, t as textEncoder } from './shared/unjwt.B5N3dPN9.js';
package/dist/utils.mjs CHANGED
@@ -1 +1 @@
1
- export { f as assertCryptoKey, h as base64Decode, j as base64Encode, d as base64UrlDecode, b as base64UrlEncode, e as concatUint8Arrays, g as isCryptoKey, k as isCryptoKeyPair, a as isJWK, r as randomBytes, c as textDecoder, t as textEncoder } from './shared/unjwt.DHdDAH0L.mjs';
1
+ export { f as assertCryptoKey, h as base64Decode, j as base64Encode, d as base64UrlDecode, b as base64UrlEncode, e as concatUint8Arrays, g as isCryptoKey, k as isCryptoKeyPair, a as isJWK, m as maybeArray, r as randomBytes, c as textDecoder, t as textEncoder } from './shared/unjwt.DOI5UE8K.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unjwt",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Low-level JWT utilities",
5
5
  "repository": "sandros94/unjwt",
6
6
  "license": "MIT",