@versini/auth-common 4.6.0 → 4.6.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +37 -37
  2. package/dist/index.js +268 -260
  3. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -46,35 +46,6 @@ declare const API_TYPE: {
46
46
  GOOGLE: string;
47
47
  };
48
48
 
49
- declare const verifyAndExtractToken: (token: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
50
- declare const decodeToken: (token: string) => jose.JWTPayload | undefined;
51
-
52
- /**
53
- * Generate a PKCE code challenge from a code verifier.
54
- *
55
- * @param code_verifier
56
- * @returns The base64 url encoded code challenge.
57
- */
58
- declare function generateCodeChallenge(code_verifier: string): Promise<string>;
59
- /**
60
- * Generate a PKCE challenge pair.
61
- *
62
- * @param length Length of the verifier (between 43-128). Defaults to 43.
63
- * @returns PKCE challenge pair.
64
- */
65
- declare function pkceChallengePair(length?: number): Promise<{
66
- code_verifier: string;
67
- code_challenge: string;
68
- }>;
69
- /**
70
- * Verify that a code_verifier produces the expected code challenge.
71
- *
72
- * @param code_verifier
73
- * @param expectedChallenge The code challenge to verify.
74
- * @returns True if challenges are equal. False otherwise.
75
- */
76
- declare function verifyChallenge(code_verifier: string, expectedChallenge: string): Promise<boolean>;
77
-
78
49
  type BodyLike = Record<string, unknown> & {
79
50
  access_token?: string;
80
51
  };
@@ -102,6 +73,19 @@ type GetToken = {
102
73
  };
103
74
  declare const getToken: ({ headers, body, clientId }: GetToken) => string;
104
75
 
76
+ /**
77
+ * Get a Session Id from a request.
78
+ *
79
+ * @param headers An object containing the request headers, usually `req.headers`.
80
+ * @param clientId The client ID to use.
81
+ *
82
+ */
83
+ type GetSessionProps = {
84
+ clientId: string;
85
+ headers: HeadersLike;
86
+ };
87
+ declare const getSession: ({ headers, clientId }: GetSessionProps) => string;
88
+
105
89
  type ScopesGrants = {
106
90
  [key: string]: string[];
107
91
  } | string[];
@@ -177,16 +161,32 @@ declare const isGranted: (token: string, scopes: ScopesGrants) => Promise<boolea
177
161
  declare const isGrantedSync: (token: string, scopes: ScopesGrants) => boolean;
178
162
 
179
163
  /**
180
- * Get a Session Id from a request.
164
+ * Generate a PKCE code challenge from a code verifier.
181
165
  *
182
- * @param headers An object containing the request headers, usually `req.headers`.
183
- * @param clientId The client ID to use.
166
+ * @param code_verifier
167
+ * @returns The base64 url encoded code challenge.
168
+ */
169
+ declare function generateCodeChallenge(code_verifier: string): Promise<string>;
170
+ /**
171
+ * Generate a PKCE challenge pair.
184
172
  *
173
+ * @param length Length of the verifier (between 43-128). Defaults to 43.
174
+ * @returns PKCE challenge pair.
185
175
  */
186
- type GetSessionProps = {
187
- clientId: string;
188
- headers: HeadersLike;
189
- };
190
- declare const getSession: ({ headers, clientId }: GetSessionProps) => string;
176
+ declare function pkceChallengePair(length?: number): Promise<{
177
+ code_verifier: string;
178
+ code_challenge: string;
179
+ }>;
180
+ /**
181
+ * Verify that a code_verifier produces the expected code challenge.
182
+ *
183
+ * @param code_verifier
184
+ * @param expectedChallenge The code challenge to verify.
185
+ * @returns True if challenges are equal. False otherwise.
186
+ */
187
+ declare function verifyChallenge(code_verifier: string, expectedChallenge: string): Promise<boolean>;
188
+
189
+ declare const verifyAndExtractToken: (token: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
190
+ declare const decodeToken: (token: string) => jose.JWTPayload | undefined;
191
191
 
192
192
  export { API_TYPE, AUTH_TYPES, BODY, type BodyLike, HEADERS, type HeadersLike, JWT, JWT_PUBLIC_KEY, type ScopesGrants, TOKEN_EXPIRATION, decodeToken, generateCodeChallenge, getSession, getToken, isGranted, isGrantedSync, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
package/dist/index.js CHANGED
@@ -1,17 +1,13 @@
1
- /*!
2
- @versini/auth-common v4.6.0
3
- © 2025 gizmette.com
4
- */
5
1
  try {
6
2
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
7
- version: "4.6.0",
8
- buildTime: "11/23/2025 02:59 PM EST",
3
+ version: "4.6.2",
4
+ buildTime: "01/23/2026 08:36 PM EST",
9
5
  homepage: "https://github.com/aversini/auth-client",
10
6
  license: "MIT"
11
7
  });
12
8
  } catch {
13
9
  }
14
- const it = {
10
+ const ct = {
15
11
  ID_TOKEN: "id_token",
16
12
  ACCESS_TOKEN: "token",
17
13
  ID_AND_ACCESS_TOKEN: "id_token token",
@@ -20,10 +16,10 @@ const it = {
20
16
  PASSKEY: "passkey",
21
17
  AUTH0: "auth0",
22
18
  GOOGLE: "google"
23
- }, st = {
19
+ }, dt = {
24
20
  CLIENT_ID: "X-Auth-ClientId",
25
21
  AUTH_TYPE: "X-Auth-Type"
26
- }, ae = {
22
+ }, oe = {
27
23
  ACCESS_TOKEN: "access_token"
28
24
  }, y = {
29
25
  ALG: "RS256",
@@ -39,7 +35,7 @@ const it = {
39
35
  SCOPE_KEY: "scope",
40
36
  CLIENT_ID_KEY: "aud",
41
37
  ISSUER: "gizmette.com"
42
- }, oe = `-----BEGIN PUBLIC KEY-----
38
+ }, ie = `-----BEGIN PUBLIC KEY-----
43
39
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
44
40
  w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
45
41
  i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
@@ -47,24 +43,61 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
47
43
  l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
48
44
  sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
49
45
  awIDAQAB
50
- -----END PUBLIC KEY-----`, ct = {
46
+ -----END PUBLIC KEY-----`, ut = {
51
47
  ACCESS: "5m",
52
48
  ID: "90d",
53
49
  REFRESH: "90d"
54
- }, dt = {
50
+ }, ft = {
55
51
  CODE: "code",
56
52
  LOGOUT: "logout",
57
53
  LOGIN: "login",
58
54
  REFRESH: "refresh",
59
55
  GOOGLE: "google"
60
- }, R = new TextEncoder(), v = new TextDecoder();
61
- function ie(...e) {
56
+ }, se = (e, t) => {
57
+ const r = e?.cookie;
58
+ if (typeof r != "string")
59
+ return;
60
+ const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
61
+ if (a)
62
+ return a[1];
63
+ }, lt = ({ headers: e, clientId: t }) => se(e, t) || "", ce = /^Bearer (.+)$/i, de = (e) => {
64
+ if (typeof e?.authorization != "string")
65
+ return;
66
+ const t = e.authorization.match(ce);
67
+ if (t)
68
+ return t[1];
69
+ }, ue = (e, t) => {
70
+ const r = e?.cookie;
71
+ if (typeof r != "string")
72
+ return;
73
+ const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
74
+ if (a)
75
+ return a[1];
76
+ }, fe = (e) => {
77
+ const t = e?.[oe.ACCESS_TOKEN];
78
+ if (typeof t == "string")
79
+ return t;
80
+ }, pt = ({ headers: e, body: t, clientId: r }) => {
81
+ const n = de(e), a = ue(e, r);
82
+ return fe(t) || a || n || "";
83
+ }, N = new TextEncoder(), v = new TextDecoder();
84
+ function le(...e) {
62
85
  const t = e.reduce((a, { length: o }) => a + o, 0), r = new Uint8Array(t);
63
86
  let n = 0;
64
87
  for (const a of e)
65
88
  r.set(a, n), n += a.length;
66
89
  return r;
67
90
  }
91
+ function D(e) {
92
+ const t = new Uint8Array(e.length);
93
+ for (let r = 0; r < e.length; r++) {
94
+ const n = e.charCodeAt(r);
95
+ if (n > 127)
96
+ throw new TypeError("non-ASCII string encountered in encode()");
97
+ t[r] = n;
98
+ }
99
+ return t;
100
+ }
68
101
  function G(e) {
69
102
  if (Uint8Array.fromBase64)
70
103
  return Uint8Array.fromBase64(e);
@@ -79,7 +112,7 @@ function T(e) {
79
112
  alphabet: "base64url"
80
113
  });
81
114
  let t = e;
82
- t instanceof Uint8Array && (t = v.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
115
+ t instanceof Uint8Array && (t = v.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/");
83
116
  try {
84
117
  return G(t);
85
118
  } catch {
@@ -103,7 +136,7 @@ class p extends A {
103
136
  super(t, { cause: { claim: n, reason: a, payload: r } }), this.claim = n, this.reason = a, this.payload = r;
104
137
  }
105
138
  }
106
- class U extends A {
139
+ class M extends A {
107
140
  static code = "ERR_JWT_EXPIRED";
108
141
  code = "ERR_JWT_EXPIRED";
109
142
  claim;
@@ -113,7 +146,7 @@ class U extends A {
113
146
  super(t, { cause: { claim: n, reason: a, payload: r } }), this.claim = n, this.reason = a, this.payload = r;
114
147
  }
115
148
  }
116
- class se extends A {
149
+ class pe extends A {
117
150
  static code = "ERR_JOSE_ALG_NOT_ALLOWED";
118
151
  code = "ERR_JOSE_ALG_NOT_ALLOWED";
119
152
  }
@@ -129,23 +162,18 @@ class S extends A {
129
162
  static code = "ERR_JWT_INVALID";
130
163
  code = "ERR_JWT_INVALID";
131
164
  }
132
- class ce extends A {
165
+ class he extends A {
133
166
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
134
167
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
135
168
  constructor(t = "signature verification failed", r) {
136
169
  super(t, r);
137
170
  }
138
171
  }
139
- function h(e, t = "algorithm.name") {
140
- return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
141
- }
142
- function b(e, t) {
143
- return e.name === t;
144
- }
145
- function W(e) {
172
+ const h = (e, t = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`), b = (e, t) => e.name === t;
173
+ function x(e) {
146
174
  return parseInt(e.name.slice(4), 10);
147
175
  }
148
- function de(e) {
176
+ function ye(e) {
149
177
  switch (e) {
150
178
  case "ES256":
151
179
  return "P-256";
@@ -157,11 +185,11 @@ function de(e) {
157
185
  throw new Error("unreachable");
158
186
  }
159
187
  }
160
- function ue(e, t) {
188
+ function me(e, t) {
161
189
  if (!e.usages.includes(t))
162
190
  throw new TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`);
163
191
  }
164
- function fe(e, t, r) {
192
+ function Se(e, t, r) {
165
193
  switch (t) {
166
194
  case "HS256":
167
195
  case "HS384":
@@ -169,7 +197,7 @@ function fe(e, t, r) {
169
197
  if (!b(e.algorithm, "HMAC"))
170
198
  throw h("HMAC");
171
199
  const n = parseInt(t.slice(2), 10);
172
- if (W(e.algorithm.hash) !== n)
200
+ if (x(e.algorithm.hash) !== n)
173
201
  throw h(`SHA-${n}`, "algorithm.hash");
174
202
  break;
175
203
  }
@@ -179,7 +207,7 @@ function fe(e, t, r) {
179
207
  if (!b(e.algorithm, "RSASSA-PKCS1-v1_5"))
180
208
  throw h("RSASSA-PKCS1-v1_5");
181
209
  const n = parseInt(t.slice(2), 10);
182
- if (W(e.algorithm.hash) !== n)
210
+ if (x(e.algorithm.hash) !== n)
183
211
  throw h(`SHA-${n}`, "algorithm.hash");
184
212
  break;
185
213
  }
@@ -189,7 +217,7 @@ function fe(e, t, r) {
189
217
  if (!b(e.algorithm, "RSA-PSS"))
190
218
  throw h("RSA-PSS");
191
219
  const n = parseInt(t.slice(2), 10);
192
- if (W(e.algorithm.hash) !== n)
220
+ if (x(e.algorithm.hash) !== n)
193
221
  throw h(`SHA-${n}`, "algorithm.hash");
194
222
  break;
195
223
  }
@@ -211,7 +239,7 @@ function fe(e, t, r) {
211
239
  case "ES512": {
212
240
  if (!b(e.algorithm, "ECDSA"))
213
241
  throw h("ECDSA");
214
- const n = de(t);
242
+ const n = ye(t);
215
243
  if (e.algorithm.namedCurve !== n)
216
244
  throw h(n, "algorithm.namedCurve");
217
245
  break;
@@ -219,26 +247,25 @@ function fe(e, t, r) {
219
247
  default:
220
248
  throw new TypeError("CryptoKey does not support this operation");
221
249
  }
222
- ue(e, r);
250
+ me(e, r);
223
251
  }
224
- function V(e, t, ...r) {
252
+ function q(e, t, ...r) {
225
253
  if (r = r.filter(Boolean), r.length > 2) {
226
254
  const n = r.pop();
227
255
  e += `one of type ${r.join(", ")}, or ${n}.`;
228
256
  } else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
229
257
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && t.constructor?.name && (e += ` Received an instance of ${t.constructor.name}`), e;
230
258
  }
231
- const le = (e, ...t) => V("Key must be ", e, ...t);
232
- function q(e, t, ...r) {
233
- return V(`Key for the ${e} algorithm must be `, t, ...r);
234
- }
235
- function z(e) {
236
- return e?.[Symbol.toStringTag] === "CryptoKey";
237
- }
238
- function X(e) {
239
- return e?.[Symbol.toStringTag] === "KeyObject";
240
- }
241
- const Q = (e) => z(e) || X(e), pe = (...e) => {
259
+ const Ee = (e, ...t) => q("Key must be ", e, ...t), z = (e, t, ...r) => q(`Key for the ${e} algorithm must be `, t, ...r), X = (e) => {
260
+ if (e?.[Symbol.toStringTag] === "CryptoKey")
261
+ return !0;
262
+ try {
263
+ return e instanceof CryptoKey;
264
+ } catch {
265
+ return !1;
266
+ }
267
+ }, Q = (e) => e?.[Symbol.toStringTag] === "KeyObject", Z = (e) => X(e) || Q(e);
268
+ function we(...e) {
242
269
  const t = e.filter(Boolean);
243
270
  if (t.length === 0 || t.length === 1)
244
271
  return !0;
@@ -256,12 +283,10 @@ const Q = (e) => z(e) || X(e), pe = (...e) => {
256
283
  }
257
284
  }
258
285
  return !0;
259
- };
260
- function he(e) {
261
- return typeof e == "object" && e !== null;
262
286
  }
263
- const P = (e) => {
264
- if (!he(e) || Object.prototype.toString.call(e) !== "[object Object]")
287
+ const Ae = (e) => typeof e == "object" && e !== null;
288
+ function P(e) {
289
+ if (!Ae(e) || Object.prototype.toString.call(e) !== "[object Object]")
265
290
  return !1;
266
291
  if (Object.getPrototypeOf(e) === null)
267
292
  return !0;
@@ -269,20 +294,22 @@ const P = (e) => {
269
294
  for (; Object.getPrototypeOf(t) !== null; )
270
295
  t = Object.getPrototypeOf(t);
271
296
  return Object.getPrototypeOf(e) === t;
272
- }, ye = (e, t) => {
297
+ }
298
+ function ge(e, t) {
273
299
  if (e.startsWith("RS") || e.startsWith("PS")) {
274
300
  const { modulusLength: r } = t.algorithm;
275
301
  if (typeof r != "number" || r < 2048)
276
302
  throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
277
303
  }
278
- }, x = (e, t) => {
304
+ }
305
+ const W = (e, t) => {
279
306
  if (e.byteLength !== t.length)
280
307
  return !1;
281
308
  for (let r = 0; r < e.byteLength; r++)
282
309
  if (e[r] !== t[r])
283
310
  return !1;
284
311
  return !0;
285
- }, me = (e) => ({ data: e, pos: 0 }), O = (e) => {
312
+ }, be = (e) => ({ data: e, pos: 0 }), R = (e) => {
286
313
  const t = e.data[e.pos++];
287
314
  if (t & 128) {
288
315
  const r = t & 127;
@@ -292,39 +319,39 @@ const P = (e) => {
292
319
  return n;
293
320
  }
294
321
  return t;
295
- }, D = (e, t, r) => {
322
+ }, O = (e, t, r) => {
296
323
  if (e.data[e.pos++] !== t)
297
324
  throw new Error(r);
298
- }, Z = (e, t) => {
325
+ }, j = (e, t) => {
299
326
  const r = e.data.subarray(e.pos, e.pos + t);
300
327
  return e.pos += t, r;
301
- }, Se = (e) => {
302
- D(e, 6, "Expected algorithm OID");
303
- const t = O(e);
304
- return Z(e, t);
328
+ }, Ce = (e) => {
329
+ O(e, 6, "Expected algorithm OID");
330
+ const t = R(e);
331
+ return j(e, t);
305
332
  };
306
- function Ee(e) {
307
- D(e, 48, "Invalid SPKI structure"), O(e), D(e, 48, "Expected algorithm identifier");
308
- const t = O(e);
333
+ function Ke(e) {
334
+ O(e, 48, "Invalid SPKI structure"), R(e), O(e, 48, "Expected algorithm identifier");
335
+ const t = R(e);
309
336
  return { algIdStart: e.pos, algIdLength: t };
310
337
  }
311
- const we = (e) => {
312
- const t = Se(e);
313
- if (x(t, [43, 101, 110]))
338
+ const ve = (e) => {
339
+ const t = Ce(e);
340
+ if (W(t, [43, 101, 110]))
314
341
  return "X25519";
315
- if (!x(t, [42, 134, 72, 206, 61, 2, 1]))
342
+ if (!W(t, [42, 134, 72, 206, 61, 2, 1]))
316
343
  throw new Error("Unsupported key algorithm");
317
- D(e, 6, "Expected curve OID");
318
- const r = O(e), n = Z(e, r);
344
+ O(e, 6, "Expected curve OID");
345
+ const r = R(e), n = j(e, r);
319
346
  for (const { name: a, oid: o } of [
320
347
  { name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
321
348
  { name: "P-384", oid: [43, 129, 4, 0, 34] },
322
349
  { name: "P-521", oid: [43, 129, 4, 0, 35] }
323
350
  ])
324
- if (x(n, o))
351
+ if (W(n, o))
325
352
  return a;
326
353
  throw new Error("Unsupported named curve");
327
- }, Ae = async (e, t, r, n) => {
354
+ }, Te = async (e, t, r, n) => {
328
355
  let a, o;
329
356
  const i = () => ["verify"], s = () => ["encrypt", "wrapKey"];
330
357
  switch (r) {
@@ -379,15 +406,15 @@ const we = (e) => {
379
406
  throw new E('Invalid or unsupported "alg" (Algorithm) value');
380
407
  }
381
408
  return crypto.subtle.importKey(e, t, a, n?.extractable ?? !0, o);
382
- }, ge = (e, t) => G(e.replace(t, "")), be = (e, t, r) => {
383
- const n = ge(e, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
409
+ }, Pe = (e, t) => G(e.replace(t, "")), _e = (e, t, r) => {
410
+ const n = Pe(e, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
384
411
  let a = r;
385
412
  return t?.startsWith?.("ECDH-ES") && (a ||= {}, a.getNamedCurve = (o) => {
386
- const i = me(o);
387
- return Ee(i), we(i);
388
- }), Ae("spki", n, t, a);
413
+ const i = be(o);
414
+ return Ke(i), ve(i);
415
+ }), Te("spki", n, t, a);
389
416
  };
390
- function Ce(e) {
417
+ function Ie(e) {
391
418
  let t, r;
392
419
  switch (e.kty) {
393
420
  case "AKP": {
@@ -472,18 +499,18 @@ function Ce(e) {
472
499
  }
473
500
  return { algorithm: t, keyUsages: r };
474
501
  }
475
- const Ke = async (e) => {
502
+ async function Re(e) {
476
503
  if (!e.alg)
477
504
  throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
478
- const { algorithm: t, keyUsages: r } = Ce(e), n = { ...e };
505
+ const { algorithm: t, keyUsages: r } = Ie(e), n = { ...e };
479
506
  return n.kty !== "AKP" && delete n.alg, delete n.use, crypto.subtle.importKey("jwk", n, t, e.ext ?? !(e.d || e.priv), e.key_ops ?? r);
480
- };
481
- async function ve(e, t, r) {
507
+ }
508
+ async function Oe(e, t, r) {
482
509
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
483
510
  throw new TypeError('"spki" must be SPKI formatted string');
484
- return be(e, t, r);
511
+ return _e(e, t, r);
485
512
  }
486
- const Te = (e, t, r, n, a) => {
513
+ function De(e, t, r, n, a) {
487
514
  if (a.crit !== void 0 && n?.crit === void 0)
488
515
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
489
516
  if (!n || n.crit === void 0)
@@ -501,33 +528,23 @@ const Te = (e, t, r, n, a) => {
501
528
  throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`);
502
529
  }
503
530
  return new Set(n.crit);
504
- }, Pe = (e, t) => {
531
+ }
532
+ function xe(e, t) {
505
533
  if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
506
534
  throw new TypeError(`"${e}" option must be an array of strings`);
507
535
  if (t)
508
536
  return new Set(t);
509
- };
510
- function L(e) {
511
- return P(e) && typeof e.kty == "string";
512
- }
513
- function _e(e) {
514
- return e.kty !== "oct" && (e.kty === "AKP" && typeof e.priv == "string" || typeof e.d == "string");
515
- }
516
- function Ie(e) {
517
- return e.kty !== "oct" && typeof e.d > "u" && typeof e.priv > "u";
518
- }
519
- function Re(e) {
520
- return e.kty === "oct" && typeof e.k == "string";
521
537
  }
538
+ const L = (e) => P(e) && typeof e.kty == "string", We = (e) => e.kty !== "oct" && (e.kty === "AKP" && typeof e.priv == "string" || typeof e.d == "string"), He = (e) => e.kty !== "oct" && e.d === void 0 && e.priv === void 0, Je = (e) => e.kty === "oct" && typeof e.k == "string";
522
539
  let K;
523
- const M = async (e, t, r, n = !1) => {
540
+ const $ = async (e, t, r, n = !1) => {
524
541
  K ||= /* @__PURE__ */ new WeakMap();
525
542
  let a = K.get(e);
526
543
  if (a?.[r])
527
544
  return a[r];
528
- const o = await Ke({ ...t, alg: r });
545
+ const o = await Re({ ...t, alg: r });
529
546
  return n && Object.freeze(e), a ? a[r] = o : K.set(e, { [r]: o }), o;
530
- }, Oe = (e, t) => {
547
+ }, Le = (e, t) => {
531
548
  K ||= /* @__PURE__ */ new WeakMap();
532
549
  let r = K.get(e);
533
550
  if (r?.[t])
@@ -623,26 +640,28 @@ const M = async (e, t, r, n = !1) => {
623
640
  if (!o)
624
641
  throw new TypeError("given KeyObject instance cannot be used for this algorithm");
625
642
  return r ? r[t] = o : K.set(e, { [t]: o }), o;
626
- }, De = async (e, t) => {
627
- if (e instanceof Uint8Array || z(e))
643
+ };
644
+ async function Ue(e, t) {
645
+ if (e instanceof Uint8Array || X(e))
628
646
  return e;
629
- if (X(e)) {
647
+ if (Q(e)) {
630
648
  if (e.type === "secret")
631
649
  return e.export();
632
650
  if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
633
651
  try {
634
- return Oe(e, t);
652
+ return Le(e, t);
635
653
  } catch (n) {
636
654
  if (n instanceof TypeError)
637
655
  throw n;
638
656
  }
639
657
  let r = e.export({ format: "jwk" });
640
- return M(e, r, t);
658
+ return $(e, r, t);
641
659
  }
642
660
  if (L(e))
643
- return e.k ? T(e.k) : M(e, e, t, !0);
661
+ return e.k ? T(e.k) : $(e, e, t, !0);
644
662
  throw new Error("unreachable");
645
- }, C = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
663
+ }
664
+ const C = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
646
665
  if (t.use !== void 0) {
647
666
  let n;
648
667
  switch (r) {
@@ -685,34 +704,34 @@ const M = async (e, t, r, n = !1) => {
685
704
  throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`);
686
705
  }
687
706
  return !0;
688
- }, We = (e, t, r) => {
707
+ }, Ne = (e, t, r) => {
689
708
  if (!(t instanceof Uint8Array)) {
690
709
  if (L(t)) {
691
- if (Re(t) && J(e, t, r))
710
+ if (Je(t) && J(e, t, r))
692
711
  return;
693
712
  throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
694
713
  }
695
- if (!Q(t))
696
- throw new TypeError(q(e, t, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
714
+ if (!Z(t))
715
+ throw new TypeError(z(e, t, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
697
716
  if (t.type !== "secret")
698
717
  throw new TypeError(`${C(t)} instances for symmetric algorithms must be of type "secret"`);
699
718
  }
700
- }, xe = (e, t, r) => {
719
+ }, Me = (e, t, r) => {
701
720
  if (L(t))
702
721
  switch (r) {
703
722
  case "decrypt":
704
723
  case "sign":
705
- if (_e(t) && J(e, t, r))
724
+ if (We(t) && J(e, t, r))
706
725
  return;
707
- throw new TypeError("JSON Web Key for this operation be a private JWK");
726
+ throw new TypeError("JSON Web Key for this operation must be a private JWK");
708
727
  case "encrypt":
709
728
  case "verify":
710
- if (Ie(t) && J(e, t, r))
729
+ if (He(t) && J(e, t, r))
711
730
  return;
712
- throw new TypeError("JSON Web Key for this operation be a public JWK");
731
+ throw new TypeError("JSON Web Key for this operation must be a public JWK");
713
732
  }
714
- if (!Q(t))
715
- throw new TypeError(q(e, t, "CryptoKey", "KeyObject", "JSON Web Key"));
733
+ if (!Z(t))
734
+ throw new TypeError(z(e, t, "CryptoKey", "KeyObject", "JSON Web Key"));
716
735
  if (t.type === "secret")
717
736
  throw new TypeError(`${C(t)} instances for asymmetric algorithms must not be of type "secret"`);
718
737
  if (t.type === "public")
@@ -729,9 +748,21 @@ const M = async (e, t, r, n = !1) => {
729
748
  case "encrypt":
730
749
  throw new TypeError(`${C(t)} instances for asymmetric algorithm encryption must be of type "public"`);
731
750
  }
732
- }, He = (e, t, r) => {
733
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(e) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(e) ? We(e, t, r) : xe(e, t, r);
734
- }, Je = (e, t) => {
751
+ };
752
+ function $e(e, t, r) {
753
+ switch (e.substring(0, 2)) {
754
+ case "A1":
755
+ case "A2":
756
+ case "di":
757
+ case "HS":
758
+ case "PB":
759
+ Ne(e, t, r);
760
+ break;
761
+ default:
762
+ Me(e, t, r);
763
+ }
764
+ }
765
+ function ke(e, t) {
735
766
  const r = `SHA-${e.slice(-3)}`;
736
767
  switch (e) {
737
768
  case "HS256":
@@ -760,24 +791,26 @@ const M = async (e, t, r, n = !1) => {
760
791
  default:
761
792
  throw new E(`alg ${e} is not supported either by JOSE or your javascript runtime`);
762
793
  }
763
- }, Le = async (e, t, r) => {
794
+ }
795
+ async function Be(e, t, r) {
764
796
  if (t instanceof Uint8Array) {
765
797
  if (!e.startsWith("HS"))
766
- throw new TypeError(le(t, "CryptoKey", "KeyObject", "JSON Web Key"));
798
+ throw new TypeError(Ee(t, "CryptoKey", "KeyObject", "JSON Web Key"));
767
799
  return crypto.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
768
800
  }
769
- return fe(t, e, r), t;
770
- }, Ne = async (e, t, r, n) => {
771
- const a = await Le(e, t, "verify");
772
- ye(e, a);
773
- const o = Je(e, a.algorithm);
801
+ return Se(t, e, r), t;
802
+ }
803
+ async function Ye(e, t, r, n) {
804
+ const a = await Be(e, t, "verify");
805
+ ge(e, a);
806
+ const o = ke(e, a.algorithm);
774
807
  try {
775
808
  return await crypto.subtle.verify(o, a, r, n);
776
809
  } catch {
777
810
  return !1;
778
811
  }
779
- };
780
- async function Ue(e, t, r) {
812
+ }
813
+ async function Fe(e, t, r) {
781
814
  if (!P(e))
782
815
  throw new d("Flattened JWS must be an object");
783
816
  if (e.protected === void 0 && e.header === void 0)
@@ -793,43 +826,43 @@ async function Ue(e, t, r) {
793
826
  let n = {};
794
827
  if (e.protected)
795
828
  try {
796
- const ne = T(e.protected);
797
- n = JSON.parse(v.decode(ne));
829
+ const ae = T(e.protected);
830
+ n = JSON.parse(v.decode(ae));
798
831
  } catch {
799
832
  throw new d("JWS Protected Header is invalid");
800
833
  }
801
- if (!pe(n, e.header))
834
+ if (!we(n, e.header))
802
835
  throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
803
836
  const a = {
804
837
  ...n,
805
838
  ...e.header
806
- }, o = Te(d, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
839
+ }, o = De(d, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
807
840
  let i = !0;
808
841
  if (o.has("b64") && (i = n.b64, typeof i != "boolean"))
809
842
  throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
810
843
  const { alg: s } = a;
811
844
  if (typeof s != "string" || !s)
812
845
  throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
813
- const u = r && Pe("algorithms", r.algorithms);
846
+ const u = r && xe("algorithms", r.algorithms);
814
847
  if (u && !u.has(s))
815
- throw new se('"alg" (Algorithm) Header Parameter value not allowed');
848
+ throw new pe('"alg" (Algorithm) Header Parameter value not allowed');
816
849
  if (i) {
817
850
  if (typeof e.payload != "string")
818
851
  throw new d("JWS Payload must be a string");
819
852
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
820
853
  throw new d("JWS Payload must be a string or an Uint8Array instance");
821
854
  let m = !1;
822
- typeof t == "function" && (t = await t(n, e), m = !0), He(s, t, "verify");
823
- const w = ie(R.encode(e.protected ?? ""), R.encode("."), typeof e.payload == "string" ? R.encode(e.payload) : e.payload);
855
+ typeof t == "function" && (t = await t(n, e), m = !0), $e(s, t, "verify");
856
+ const w = le(e.protected !== void 0 ? D(e.protected) : new Uint8Array(), D("."), typeof e.payload == "string" ? i ? D(e.payload) : N.encode(e.payload) : e.payload);
824
857
  let l;
825
858
  try {
826
859
  l = T(e.signature);
827
860
  } catch {
828
861
  throw new d("Failed to base64url decode the signature");
829
862
  }
830
- const _ = await De(t, s);
831
- if (!await Ne(s, _, l, w))
832
- throw new ce();
863
+ const _ = await Ue(t, s);
864
+ if (!await Ye(s, _, l, w))
865
+ throw new he();
833
866
  let f;
834
867
  if (i)
835
868
  try {
@@ -837,21 +870,22 @@ async function Ue(e, t, r) {
837
870
  } catch {
838
871
  throw new d("Failed to base64url decode the payload");
839
872
  }
840
- else typeof e.payload == "string" ? f = R.encode(e.payload) : f = e.payload;
873
+ else typeof e.payload == "string" ? f = N.encode(e.payload) : f = e.payload;
841
874
  const g = { payload: f };
842
875
  return e.protected !== void 0 && (g.protectedHeader = n), e.header !== void 0 && (g.unprotectedHeader = e.header), m ? { ...g, key: _ } : g;
843
876
  }
844
- async function Me(e, t, r) {
877
+ async function Ve(e, t, r) {
845
878
  if (e instanceof Uint8Array && (e = v.decode(e)), typeof e != "string")
846
879
  throw new d("Compact JWS must be a string or Uint8Array");
847
880
  const { 0: n, 1: a, 2: o, length: i } = e.split(".");
848
881
  if (i !== 3)
849
882
  throw new d("Invalid Compact JWS");
850
- const s = await Ue({ payload: a, protected: n, signature: o }, t, r), u = { payload: s.payload, protectedHeader: s.protectedHeader };
883
+ const s = await Fe({ payload: a, protected: n, signature: o }, t, r), u = { payload: s.payload, protectedHeader: s.protectedHeader };
851
884
  return typeof t == "function" ? { ...u, key: s.key } : u;
852
885
  }
853
- const $e = (e) => Math.floor(e.getTime() / 1e3), j = 60, ee = j * 60, N = ee * 24, ke = N * 7, Be = N * 365.25, Ye = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, $ = (e) => {
854
- const t = Ye.exec(e);
886
+ const Ge = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, U = te * 24, qe = U * 7, ze = U * 365.25, Xe = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
887
+ function k(e) {
888
+ const t = Xe.exec(e);
855
889
  if (!t || t[4] && t[1])
856
890
  throw new TypeError("Invalid time period format");
857
891
  const r = parseFloat(t[2]), n = t[3].toLowerCase();
@@ -869,32 +903,33 @@ const $e = (e) => Math.floor(e.getTime() / 1e3), j = 60, ee = j * 60, N = ee * 2
869
903
  case "min":
870
904
  case "mins":
871
905
  case "m":
872
- a = Math.round(r * j);
906
+ a = Math.round(r * ee);
873
907
  break;
874
908
  case "hour":
875
909
  case "hours":
876
910
  case "hr":
877
911
  case "hrs":
878
912
  case "h":
879
- a = Math.round(r * ee);
913
+ a = Math.round(r * te);
880
914
  break;
881
915
  case "day":
882
916
  case "days":
883
917
  case "d":
884
- a = Math.round(r * N);
918
+ a = Math.round(r * U);
885
919
  break;
886
920
  case "week":
887
921
  case "weeks":
888
922
  case "w":
889
- a = Math.round(r * ke);
923
+ a = Math.round(r * qe);
890
924
  break;
891
925
  default:
892
- a = Math.round(r * Be);
926
+ a = Math.round(r * ze);
893
927
  break;
894
928
  }
895
929
  return t[1] === "-" || t[4] === "ago" ? -a : a;
896
- }, k = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`, Fe = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
897
- function Ge(e, t, r = {}) {
930
+ }
931
+ const B = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`, Qe = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
932
+ function Ze(e, t, r = {}) {
898
933
  let n;
899
934
  try {
900
935
  n = JSON.parse(v.decode(t));
@@ -903,7 +938,7 @@ function Ge(e, t, r = {}) {
903
938
  if (!P(n))
904
939
  throw new S("JWT Claims Set must be a top-level JSON object");
905
940
  const { typ: a } = r;
906
- if (a && (typeof e.typ != "string" || k(e.typ) !== k(a)))
941
+ if (a && (typeof e.typ != "string" || B(e.typ) !== B(a)))
907
942
  throw new p('unexpected "typ" JWT header value', n, "typ", "check_failed");
908
943
  const { requiredClaims: o = [], issuer: i, subject: s, audience: u, maxTokenAge: m } = r, w = [...o];
909
944
  m !== void 0 && w.push("iat"), u !== void 0 && w.push("aud"), s !== void 0 && w.push("sub"), i !== void 0 && w.push("iss");
@@ -914,12 +949,12 @@ function Ge(e, t, r = {}) {
914
949
  throw new p('unexpected "iss" claim value', n, "iss", "check_failed");
915
950
  if (s && n.sub !== s)
916
951
  throw new p('unexpected "sub" claim value', n, "sub", "check_failed");
917
- if (u && !Fe(n.aud, typeof u == "string" ? [u] : u))
952
+ if (u && !Qe(n.aud, typeof u == "string" ? [u] : u))
918
953
  throw new p('unexpected "aud" claim value', n, "aud", "check_failed");
919
954
  let l;
920
955
  switch (typeof r.clockTolerance) {
921
956
  case "string":
922
- l = $(r.clockTolerance);
957
+ l = k(r.clockTolerance);
923
958
  break;
924
959
  case "number":
925
960
  l = r.clockTolerance;
@@ -930,7 +965,7 @@ function Ge(e, t, r = {}) {
930
965
  default:
931
966
  throw new TypeError("Invalid clockTolerance option type");
932
967
  }
933
- const { currentDate: _ } = r, I = $e(_ || /* @__PURE__ */ new Date());
968
+ const { currentDate: _ } = r, I = Ge(_ || /* @__PURE__ */ new Date());
934
969
  if ((n.iat !== void 0 || m) && typeof n.iat != "number")
935
970
  throw new p('"iat" claim must be a number', n, "iat", "invalid");
936
971
  if (n.nbf !== void 0) {
@@ -943,25 +978,25 @@ function Ge(e, t, r = {}) {
943
978
  if (typeof n.exp != "number")
944
979
  throw new p('"exp" claim must be a number', n, "exp", "invalid");
945
980
  if (n.exp <= I - l)
946
- throw new U('"exp" claim timestamp check failed', n, "exp", "check_failed");
981
+ throw new M('"exp" claim timestamp check failed', n, "exp", "check_failed");
947
982
  }
948
983
  if (m) {
949
- const f = I - n.iat, g = typeof m == "number" ? m : $(m);
984
+ const f = I - n.iat, g = typeof m == "number" ? m : k(m);
950
985
  if (f - l > g)
951
- throw new U('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
986
+ throw new M('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
952
987
  if (f < 0 - l)
953
988
  throw new p('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
954
989
  }
955
990
  return n;
956
991
  }
957
- async function Ve(e, t, r) {
958
- const n = await Me(e, t, r);
992
+ async function je(e, t, r) {
993
+ const n = await Ve(e, t, r);
959
994
  if (n.protectedHeader.crit?.includes("b64") && n.protectedHeader.b64 === !1)
960
995
  throw new S("JWTs MUST NOT use unencoded payload");
961
- const o = { payload: Ge(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
996
+ const o = { payload: Ze(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
962
997
  return typeof t == "function" ? { ...o, key: n.key } : o;
963
998
  }
964
- function te(e) {
999
+ function re(e) {
965
1000
  if (typeof e != "string")
966
1001
  throw new S("JWTs must use Compact JWS serialization, JWT must be a string");
967
1002
  const { 1: t, length: r } = e.split(".");
@@ -987,146 +1022,119 @@ function te(e) {
987
1022
  throw new S("Invalid JWT Claims Set");
988
1023
  return a;
989
1024
  }
990
- const qe = async (e) => {
1025
+ const et = async (e) => {
991
1026
  try {
992
- const t = y.ALG, n = await ve(oe, t);
993
- return await Ve(e, n, {
1027
+ const t = y.ALG, n = await Oe(ie, t);
1028
+ return await je(e, n, {
994
1029
  issuer: y.ISSUER
995
1030
  });
996
1031
  } catch {
997
1032
  return;
998
1033
  }
999
- }, ut = (e) => {
1034
+ }, ht = (e) => {
1000
1035
  try {
1001
- return te(e);
1036
+ return re(e);
1002
1037
  } catch {
1003
1038
  return;
1004
1039
  }
1040
+ }, yt = async (e, t) => {
1041
+ const r = await et(e);
1042
+ if (!r || !r.payload)
1043
+ return !1;
1044
+ let n = [];
1045
+ if (Array.isArray(r.payload[y.SCOPES_KEY]))
1046
+ n = r.payload[y.SCOPES_KEY];
1047
+ else if (typeof r.payload[y.SCOPE_KEY] == "string")
1048
+ n = r.payload[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
1049
+ else
1050
+ return !1;
1051
+ return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
1052
+ (a) => t[a].every((o) => n.includes(o))
1053
+ );
1054
+ }, mt = (e, t) => {
1055
+ try {
1056
+ const r = re(e);
1057
+ if (!r)
1058
+ return !1;
1059
+ let n = [];
1060
+ if (Array.isArray(r[y.SCOPES_KEY]))
1061
+ n = r[y.SCOPES_KEY];
1062
+ else if (typeof r[y.SCOPE_KEY] == "string")
1063
+ n = r[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
1064
+ else
1065
+ return !1;
1066
+ return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
1067
+ (a) => t[a].every((o) => n.includes(o))
1068
+ );
1069
+ } catch {
1070
+ return !1;
1071
+ }
1005
1072
  }, c = [];
1006
1073
  for (let e = 0; e < 256; ++e)
1007
1074
  c.push((e + 256).toString(16).slice(1));
1008
- function ze(e, t = 0) {
1075
+ function tt(e, t = 0) {
1009
1076
  return (c[e[t + 0]] + c[e[t + 1]] + c[e[t + 2]] + c[e[t + 3]] + "-" + c[e[t + 4]] + c[e[t + 5]] + "-" + c[e[t + 6]] + c[e[t + 7]] + "-" + c[e[t + 8]] + c[e[t + 9]] + "-" + c[e[t + 10]] + c[e[t + 11]] + c[e[t + 12]] + c[e[t + 13]] + c[e[t + 14]] + c[e[t + 15]]).toLowerCase();
1010
1077
  }
1011
1078
  let H;
1012
- const Xe = new Uint8Array(16);
1013
- function Qe() {
1079
+ const rt = new Uint8Array(16);
1080
+ function nt() {
1014
1081
  if (!H) {
1015
1082
  if (typeof crypto > "u" || !crypto.getRandomValues)
1016
1083
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1017
1084
  H = crypto.getRandomValues.bind(crypto);
1018
1085
  }
1019
- return H(Xe);
1086
+ return H(rt);
1020
1087
  }
1021
- const Ze = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), B = { randomUUID: Ze };
1022
- function Y(e, t, r) {
1023
- if (B.randomUUID && !e)
1024
- return B.randomUUID();
1088
+ const at = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Y = { randomUUID: at };
1089
+ function ot(e, t, r) {
1025
1090
  e = e || {};
1026
- const n = e.random ?? e.rng?.() ?? Qe();
1091
+ const n = e.random ?? e.rng?.() ?? nt();
1027
1092
  if (n.length < 16)
1028
1093
  throw new Error("Random bytes length must be >= 16");
1029
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, ze(n);
1094
+ return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, tt(n);
1095
+ }
1096
+ function F(e, t, r) {
1097
+ return Y.randomUUID && !e ? Y.randomUUID() : ot(e);
1030
1098
  }
1031
- const F = globalThis.crypto, je = (e) => `${Y()}${Y()}`.slice(0, e), et = (e) => btoa(
1099
+ const V = globalThis.crypto, it = (e) => `${F()}${F()}`.slice(0, e), st = (e) => btoa(
1032
1100
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
1033
1101
  );
1034
- async function re(e) {
1035
- if (!F.subtle)
1102
+ async function ne(e) {
1103
+ if (!V.subtle)
1036
1104
  throw new Error(
1037
1105
  "crypto.subtle is available only in secure contexts (HTTPS)."
1038
1106
  );
1039
- const t = new TextEncoder().encode(e), r = await F.subtle.digest("SHA-256", t);
1040
- return et(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1107
+ const t = new TextEncoder().encode(e), r = await V.subtle.digest("SHA-256", t);
1108
+ return st(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1041
1109
  }
1042
- async function ft(e) {
1110
+ async function St(e) {
1043
1111
  const t = e || 43;
1044
1112
  if (t < 43 || t > 128)
1045
1113
  throw `Expected a length between 43 and 128. Received ${e}.`;
1046
- const r = je(t), n = await re(r);
1114
+ const r = it(t), n = await ne(r);
1047
1115
  return {
1048
1116
  code_verifier: r,
1049
1117
  code_challenge: n
1050
1118
  };
1051
1119
  }
1052
- async function lt(e, t) {
1053
- return t === await re(e);
1120
+ async function Et(e, t) {
1121
+ return t === await ne(e);
1054
1122
  }
1055
- const tt = /^Bearer (.+)$/i, rt = (e) => {
1056
- if (typeof e?.authorization != "string")
1057
- return;
1058
- const t = e.authorization.match(tt);
1059
- if (t)
1060
- return t[1];
1061
- }, nt = (e, t) => {
1062
- const r = e?.cookie;
1063
- if (typeof r != "string")
1064
- return;
1065
- const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
1066
- if (a)
1067
- return a[1];
1068
- }, at = (e) => {
1069
- const t = e?.[ae.ACCESS_TOKEN];
1070
- if (typeof t == "string")
1071
- return t;
1072
- }, pt = ({ headers: e, body: t, clientId: r }) => {
1073
- const n = rt(e), a = nt(e, r);
1074
- return at(t) || a || n || "";
1075
- }, ht = async (e, t) => {
1076
- const r = await qe(e);
1077
- if (!r || !r.payload)
1078
- return !1;
1079
- let n = [];
1080
- if (Array.isArray(r.payload[y.SCOPES_KEY]))
1081
- n = r.payload[y.SCOPES_KEY];
1082
- else if (typeof r.payload[y.SCOPE_KEY] == "string")
1083
- n = r.payload[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
1084
- else
1085
- return !1;
1086
- return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
1087
- (a) => t[a].every((o) => n.includes(o))
1088
- );
1089
- }, yt = (e, t) => {
1090
- try {
1091
- const r = te(e);
1092
- if (!r)
1093
- return !1;
1094
- let n = [];
1095
- if (Array.isArray(r[y.SCOPES_KEY]))
1096
- n = r[y.SCOPES_KEY];
1097
- else if (typeof r[y.SCOPE_KEY] == "string")
1098
- n = r[y.SCOPE_KEY].split(" ").filter((o) => o.trim() !== "");
1099
- else
1100
- return !1;
1101
- return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
1102
- (a) => t[a].every((o) => n.includes(o))
1103
- );
1104
- } catch {
1105
- return !1;
1106
- }
1107
- }, ot = (e, t) => {
1108
- const r = e?.cookie;
1109
- if (typeof r != "string")
1110
- return;
1111
- const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
1112
- if (a)
1113
- return a[1];
1114
- }, mt = ({ headers: e, clientId: t }) => ot(e, t) || "";
1115
1123
  export {
1116
- dt as API_TYPE,
1117
- it as AUTH_TYPES,
1118
- ae as BODY,
1119
- st as HEADERS,
1124
+ ft as API_TYPE,
1125
+ ct as AUTH_TYPES,
1126
+ oe as BODY,
1127
+ dt as HEADERS,
1120
1128
  y as JWT,
1121
- oe as JWT_PUBLIC_KEY,
1122
- ct as TOKEN_EXPIRATION,
1123
- ut as decodeToken,
1124
- re as generateCodeChallenge,
1125
- mt as getSession,
1129
+ ie as JWT_PUBLIC_KEY,
1130
+ ut as TOKEN_EXPIRATION,
1131
+ ht as decodeToken,
1132
+ ne as generateCodeChallenge,
1133
+ lt as getSession,
1126
1134
  pt as getToken,
1127
- ht as isGranted,
1128
- yt as isGrantedSync,
1129
- ft as pkceChallengePair,
1130
- qe as verifyAndExtractToken,
1131
- lt as verifyChallenge
1135
+ yt as isGranted,
1136
+ mt as isGrantedSync,
1137
+ St as pkceChallengePair,
1138
+ et as verifyAndExtractToken,
1139
+ Et as verifyChallenge
1132
1140
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-common",
3
- "version": "4.6.0",
3
+ "version": "4.6.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -34,8 +34,8 @@
34
34
  "test:coverage": "vitest run --coverage"
35
35
  },
36
36
  "dependencies": {
37
- "jose": "6.1.0",
38
- "uuid": "11.1.0"
37
+ "jose": "6.1.3",
38
+ "uuid": "13.0.0"
39
39
  },
40
- "gitHead": "08365bc6d187fe1379f4f86fb6ec730cc9129ddf"
40
+ "gitHead": "78e93181feacb67a6de1628448ae7a22fddfdf34"
41
41
  }