@versini/auth-common 4.1.0 → 4.1.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 (2) hide show
  1. package/dist/index.js +379 -317
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,28 +1,28 @@
1
1
  /*!
2
- @versini/auth-common v4.1.0
2
+ @versini/auth-common v4.1.2
3
3
  © 2024 gizmette.com
4
4
  */
5
5
  try {
6
6
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
7
- version: "4.1.0",
8
- buildTime: "09/01/2024 04:15 PM EDT",
7
+ version: "4.1.2",
8
+ buildTime: "09/19/2024 02:34 PM EDT",
9
9
  homepage: "https://github.com/aversini/auth-client",
10
10
  license: "MIT"
11
11
  });
12
12
  } catch {
13
13
  }
14
- const et = {
14
+ const ct = {
15
15
  ID_TOKEN: "id_token",
16
16
  ACCESS_TOKEN: "token",
17
17
  ID_AND_ACCESS_TOKEN: "id_token token",
18
18
  CODE: "code",
19
19
  REFRESH_TOKEN: "refresh_token",
20
20
  PASSKEY: "passkey"
21
- }, tt = {
21
+ }, st = {
22
22
  CLIENT_ID: "X-Auth-ClientId"
23
- }, ne = {
23
+ }, se = {
24
24
  ACCESS_TOKEN: "access_token"
25
- }, R = {
25
+ }, W = {
26
26
  ALG: "RS256",
27
27
  USER_ID_KEY: "sub",
28
28
  USERNAME_KEY: "username",
@@ -35,7 +35,7 @@ const et = {
35
35
  SCOPES_KEY: "scopes",
36
36
  CLIENT_ID_KEY: "aud",
37
37
  ISSUER: "gizmette.com"
38
- }, ae = `-----BEGIN PUBLIC KEY-----
38
+ }, ue = `-----BEGIN PUBLIC KEY-----
39
39
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
40
40
  w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
41
41
  i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
@@ -43,33 +43,33 @@ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
43
43
  l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
44
44
  sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
45
45
  awIDAQAB
46
- -----END PUBLIC KEY-----`, rt = {
46
+ -----END PUBLIC KEY-----`, ut = {
47
47
  ACCESS: "5m",
48
48
  ID: "90d",
49
49
  REFRESH: "90d"
50
- }, nt = {
50
+ }, dt = {
51
51
  CODE: "code",
52
52
  LOGOUT: "logout",
53
53
  LOGIN: "login",
54
54
  REFRESH: "refresh"
55
- }, O = crypto, G = (e) => e instanceof CryptoKey, _ = new TextEncoder(), C = new TextDecoder();
56
- function oe(...e) {
57
- const t = e.reduce((a, { length: o }) => a + o, 0), r = new Uint8Array(t);
55
+ }, D = crypto, Q = (e) => e instanceof CryptoKey, I = new TextEncoder(), P = new TextDecoder();
56
+ function de(...e) {
57
+ const t = e.reduce((o, { length: a }) => o + a, 0), r = new Uint8Array(t);
58
58
  let n = 0;
59
- for (const a of e)
60
- r.set(a, n), n += a.length;
59
+ for (const o of e)
60
+ r.set(o, n), n += o.length;
61
61
  return r;
62
62
  }
63
- const ie = (e) => {
63
+ const fe = (e) => {
64
64
  const t = atob(e), r = new Uint8Array(t.length);
65
65
  for (let n = 0; n < t.length; n++)
66
66
  r[n] = t.charCodeAt(n);
67
67
  return r;
68
- }, b = (e) => {
68
+ }, g = (e) => {
69
69
  let t = e;
70
- t instanceof Uint8Array && (t = C.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
70
+ t instanceof Uint8Array && (t = P.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
71
71
  try {
72
- return ie(t);
72
+ return fe(t);
73
73
  } catch {
74
74
  throw new TypeError("The input to be decoded is not correctly encoded.");
75
75
  }
@@ -87,19 +87,19 @@ class h extends A {
87
87
  static get code() {
88
88
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
89
89
  }
90
- constructor(t, r, n = "unspecified", a = "unspecified") {
91
- super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = n, this.reason = a, this.payload = r;
90
+ constructor(t, r, n = "unspecified", o = "unspecified") {
91
+ super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = n, this.reason = o, this.payload = r;
92
92
  }
93
93
  }
94
- class $ extends A {
94
+ class B extends A {
95
95
  static get code() {
96
96
  return "ERR_JWT_EXPIRED";
97
97
  }
98
- constructor(t, r, n = "unspecified", a = "unspecified") {
99
- super(t), this.code = "ERR_JWT_EXPIRED", this.claim = n, this.reason = a, this.payload = r;
98
+ constructor(t, r, n = "unspecified", o = "unspecified") {
99
+ super(t), this.code = "ERR_JWT_EXPIRED", this.claim = n, this.reason = o, this.payload = r;
100
100
  }
101
101
  }
102
- class ce extends A {
102
+ class le extends A {
103
103
  constructor() {
104
104
  super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
105
105
  }
@@ -107,7 +107,7 @@ class ce extends A {
107
107
  return "ERR_JOSE_ALG_NOT_ALLOWED";
108
108
  }
109
109
  }
110
- class w extends A {
110
+ class p extends A {
111
111
  constructor() {
112
112
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
113
113
  }
@@ -115,7 +115,7 @@ class w extends A {
115
115
  return "ERR_JOSE_NOT_SUPPORTED";
116
116
  }
117
117
  }
118
- class u extends A {
118
+ class d extends A {
119
119
  constructor() {
120
120
  super(...arguments), this.code = "ERR_JWS_INVALID";
121
121
  }
@@ -131,7 +131,7 @@ class S extends A {
131
131
  return "ERR_JWT_INVALID";
132
132
  }
133
133
  }
134
- class se extends A {
134
+ class he extends A {
135
135
  constructor() {
136
136
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
137
137
  }
@@ -139,16 +139,16 @@ class se extends A {
139
139
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
140
140
  }
141
141
  }
142
- function m(e, t = "algorithm.name") {
142
+ function y(e, t = "algorithm.name") {
143
143
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
144
144
  }
145
- function v(e, t) {
145
+ function R(e, t) {
146
146
  return e.name === t;
147
147
  }
148
- function W(e) {
148
+ function N(e) {
149
149
  return parseInt(e.name.slice(4), 10);
150
150
  }
151
- function de(e) {
151
+ function pe(e) {
152
152
  switch (e) {
153
153
  case "ES256":
154
154
  return "P-256";
@@ -160,7 +160,7 @@ function de(e) {
160
160
  throw new Error("unreachable");
161
161
  }
162
162
  }
163
- function ue(e, t) {
163
+ function me(e, t) {
164
164
  if (t.length && !t.some((r) => e.usages.includes(r))) {
165
165
  let r = "CryptoKey does not support this operation, its usages must include ";
166
166
  if (t.length > 2) {
@@ -170,94 +170,94 @@ function ue(e, t) {
170
170
  throw new TypeError(r);
171
171
  }
172
172
  }
173
- function le(e, t, ...r) {
173
+ function ye(e, t, ...r) {
174
174
  switch (t) {
175
175
  case "HS256":
176
176
  case "HS384":
177
177
  case "HS512": {
178
- if (!v(e.algorithm, "HMAC"))
179
- throw m("HMAC");
178
+ if (!R(e.algorithm, "HMAC"))
179
+ throw y("HMAC");
180
180
  const n = parseInt(t.slice(2), 10);
181
- if (W(e.algorithm.hash) !== n)
182
- throw m(`SHA-${n}`, "algorithm.hash");
181
+ if (N(e.algorithm.hash) !== n)
182
+ throw y(`SHA-${n}`, "algorithm.hash");
183
183
  break;
184
184
  }
185
185
  case "RS256":
186
186
  case "RS384":
187
187
  case "RS512": {
188
- if (!v(e.algorithm, "RSASSA-PKCS1-v1_5"))
189
- throw m("RSASSA-PKCS1-v1_5");
188
+ if (!R(e.algorithm, "RSASSA-PKCS1-v1_5"))
189
+ throw y("RSASSA-PKCS1-v1_5");
190
190
  const n = parseInt(t.slice(2), 10);
191
- if (W(e.algorithm.hash) !== n)
192
- throw m(`SHA-${n}`, "algorithm.hash");
191
+ if (N(e.algorithm.hash) !== n)
192
+ throw y(`SHA-${n}`, "algorithm.hash");
193
193
  break;
194
194
  }
195
195
  case "PS256":
196
196
  case "PS384":
197
197
  case "PS512": {
198
- if (!v(e.algorithm, "RSA-PSS"))
199
- throw m("RSA-PSS");
198
+ if (!R(e.algorithm, "RSA-PSS"))
199
+ throw y("RSA-PSS");
200
200
  const n = parseInt(t.slice(2), 10);
201
- if (W(e.algorithm.hash) !== n)
202
- throw m(`SHA-${n}`, "algorithm.hash");
201
+ if (N(e.algorithm.hash) !== n)
202
+ throw y(`SHA-${n}`, "algorithm.hash");
203
203
  break;
204
204
  }
205
205
  case "EdDSA": {
206
206
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
207
- throw m("Ed25519 or Ed448");
207
+ throw y("Ed25519 or Ed448");
208
208
  break;
209
209
  }
210
210
  case "ES256":
211
211
  case "ES384":
212
212
  case "ES512": {
213
- if (!v(e.algorithm, "ECDSA"))
214
- throw m("ECDSA");
215
- const n = de(t);
213
+ if (!R(e.algorithm, "ECDSA"))
214
+ throw y("ECDSA");
215
+ const n = pe(t);
216
216
  if (e.algorithm.namedCurve !== n)
217
- throw m(n, "algorithm.namedCurve");
217
+ throw y(n, "algorithm.namedCurve");
218
218
  break;
219
219
  }
220
220
  default:
221
221
  throw new TypeError("CryptoKey does not support this operation");
222
222
  }
223
- ue(e, r);
223
+ me(e, r);
224
224
  }
225
- function q(e, t, ...r) {
225
+ function Z(e, t, ...r) {
226
226
  var n;
227
- if (r.length > 2) {
228
- const a = r.pop();
229
- e += `one of type ${r.join(", ")}, or ${a}.`;
227
+ if (r = r.filter(Boolean), r.length > 2) {
228
+ const o = r.pop();
229
+ e += `one of type ${r.join(", ")}, or ${o}.`;
230
230
  } else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
231
231
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (n = t.constructor) != null && n.name && (e += ` Received an instance of ${t.constructor.name}`), e;
232
232
  }
233
- const L = (e, ...t) => q("Key must be ", e, ...t);
234
- function z(e, t, ...r) {
235
- return q(`Key for the ${e} algorithm must be `, t, ...r);
233
+ const V = (e, ...t) => Z("Key must be ", e, ...t);
234
+ function j(e, t, ...r) {
235
+ return Z(`Key for the ${e} algorithm must be `, t, ...r);
236
236
  }
237
- const X = (e) => G(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", P = ["CryptoKey"], fe = (...e) => {
237
+ const ee = (e) => Q(e) ? !0 : (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", x = ["CryptoKey"], Se = (...e) => {
238
238
  const t = e.filter(Boolean);
239
239
  if (t.length === 0 || t.length === 1)
240
240
  return !0;
241
241
  let r;
242
242
  for (const n of t) {
243
- const a = Object.keys(n);
243
+ const o = Object.keys(n);
244
244
  if (!r || r.size === 0) {
245
- r = new Set(a);
245
+ r = new Set(o);
246
246
  continue;
247
247
  }
248
- for (const o of a) {
249
- if (r.has(o))
248
+ for (const a of o) {
249
+ if (r.has(a))
250
250
  return !1;
251
- r.add(o);
251
+ r.add(a);
252
252
  }
253
253
  }
254
254
  return !0;
255
255
  };
256
- function he(e) {
256
+ function Ee(e) {
257
257
  return typeof e == "object" && e !== null;
258
258
  }
259
- function K(e) {
260
- if (!he(e) || Object.prototype.toString.call(e) !== "[object Object]")
259
+ function _(e) {
260
+ if (!Ee(e) || Object.prototype.toString.call(e) !== "[object Object]")
261
261
  return !1;
262
262
  if (Object.getPrototypeOf(e) === null)
263
263
  return !0;
@@ -266,14 +266,26 @@ function K(e) {
266
266
  t = Object.getPrototypeOf(t);
267
267
  return Object.getPrototypeOf(e) === t;
268
268
  }
269
- const pe = (e, t) => {
269
+ const we = (e, t) => {
270
270
  if (e.startsWith("RS") || e.startsWith("PS")) {
271
271
  const { modulusLength: r } = t.algorithm;
272
272
  if (typeof r != "number" || r < 2048)
273
273
  throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
274
274
  }
275
275
  };
276
- function me(e) {
276
+ function K(e) {
277
+ return _(e) && typeof e.kty == "string";
278
+ }
279
+ function ge(e) {
280
+ return e.kty !== "oct" && typeof e.d == "string";
281
+ }
282
+ function be(e) {
283
+ return e.kty !== "oct" && typeof e.d > "u";
284
+ }
285
+ function Ae(e) {
286
+ return K(e) && e.kty === "oct" && typeof e.k == "string";
287
+ }
288
+ function Ce(e) {
277
289
  let t, r;
278
290
  switch (e.kty) {
279
291
  case "RSA": {
@@ -298,7 +310,7 @@ function me(e) {
298
310
  }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
299
311
  break;
300
312
  default:
301
- throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
313
+ throw new p('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
302
314
  }
303
315
  break;
304
316
  }
@@ -320,7 +332,7 @@ function me(e) {
320
332
  t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
321
333
  break;
322
334
  default:
323
- throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
335
+ throw new p('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
324
336
  }
325
337
  break;
326
338
  }
@@ -336,168 +348,218 @@ function me(e) {
336
348
  t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
337
349
  break;
338
350
  default:
339
- throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
351
+ throw new p('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
340
352
  }
341
353
  break;
342
354
  }
343
355
  default:
344
- throw new w('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
356
+ throw new p('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
345
357
  }
346
358
  return { algorithm: t, keyUsages: r };
347
359
  }
348
- const Se = async (e) => {
360
+ const te = async (e) => {
349
361
  if (!e.alg)
350
362
  throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
351
- const { algorithm: t, keyUsages: r } = me(e), n = [
363
+ const { algorithm: t, keyUsages: r } = Ce(e), n = [
352
364
  t,
353
365
  e.ext ?? !1,
354
366
  e.key_ops ?? r
355
- ], a = { ...e };
356
- return delete a.alg, delete a.use, O.subtle.importKey("jwk", a, ...n);
357
- }, Q = (e) => b(e);
358
- let D, J;
359
- const Z = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", j = async (e, t, r, n) => {
367
+ ], o = { ...e };
368
+ return delete o.alg, delete o.use, D.subtle.importKey("jwk", o, ...n);
369
+ }, re = (e) => g(e);
370
+ let C, v;
371
+ const ne = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", J = async (e, t, r, n, o = !1) => {
360
372
  let a = e.get(t);
361
373
  if (a != null && a[n])
362
374
  return a[n];
363
- const o = await Se({ ...r, alg: n });
364
- return a ? a[n] = o : e.set(t, { [n]: o }), o;
365
- }, ye = (e, t) => {
366
- if (Z(e)) {
375
+ const i = await te({ ...r, alg: n });
376
+ return o && Object.freeze(t), a ? a[n] = i : e.set(t, { [n]: i }), i;
377
+ }, ve = (e, t) => {
378
+ if (ne(e)) {
367
379
  let r = e.export({ format: "jwk" });
368
- return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? Q(r.k) : (J || (J = /* @__PURE__ */ new WeakMap()), j(J, e, r, t));
380
+ return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? re(r.k) : (v || (v = /* @__PURE__ */ new WeakMap()), J(v, e, r, t));
369
381
  }
370
- return e;
371
- }, Ee = (e, t) => {
372
- if (Z(e)) {
382
+ return K(e) ? e.k ? g(e.k) : (v || (v = /* @__PURE__ */ new WeakMap()), J(v, e, e, t, !0)) : e;
383
+ }, Te = (e, t) => {
384
+ if (ne(e)) {
373
385
  let r = e.export({ format: "jwk" });
374
- return r.k ? Q(r.k) : (D || (D = /* @__PURE__ */ new WeakMap()), j(D, e, r, t));
386
+ return r.k ? re(r.k) : (C || (C = /* @__PURE__ */ new WeakMap()), J(C, e, r, t));
375
387
  }
376
- return e;
377
- }, we = { normalizePublicKey: ye, normalizePrivateKey: Ee }, E = (e, t, r = 0) => {
388
+ return K(e) ? e.k ? g(e.k) : (C || (C = /* @__PURE__ */ new WeakMap()), J(C, e, e, t, !0)) : e;
389
+ }, _e = { normalizePublicKey: ve, normalizePrivateKey: Te }, w = (e, t, r = 0) => {
378
390
  r === 0 && (t.unshift(t.length), t.unshift(6));
379
391
  const n = e.indexOf(t[0], r);
380
392
  if (n === -1)
381
393
  return !1;
382
- const a = e.subarray(n, n + t.length);
383
- return a.length !== t.length ? !1 : a.every((o, i) => o === t[i]) || E(e, t, n + 1);
384
- }, k = (e) => {
394
+ const o = e.subarray(n, n + t.length);
395
+ return o.length !== t.length ? !1 : o.every((a, i) => a === t[i]) || w(e, t, n + 1);
396
+ }, F = (e) => {
385
397
  switch (!0) {
386
- case E(e, [42, 134, 72, 206, 61, 3, 1, 7]):
398
+ case w(e, [42, 134, 72, 206, 61, 3, 1, 7]):
387
399
  return "P-256";
388
- case E(e, [43, 129, 4, 0, 34]):
400
+ case w(e, [43, 129, 4, 0, 34]):
389
401
  return "P-384";
390
- case E(e, [43, 129, 4, 0, 35]):
402
+ case w(e, [43, 129, 4, 0, 35]):
391
403
  return "P-521";
392
- case E(e, [43, 101, 110]):
404
+ case w(e, [43, 101, 110]):
393
405
  return "X25519";
394
- case E(e, [43, 101, 111]):
406
+ case w(e, [43, 101, 111]):
395
407
  return "X448";
396
- case E(e, [43, 101, 112]):
408
+ case w(e, [43, 101, 112]):
397
409
  return "Ed25519";
398
- case E(e, [43, 101, 113]):
410
+ case w(e, [43, 101, 113]):
399
411
  return "Ed448";
400
412
  default:
401
- throw new w("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
413
+ throw new p("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
402
414
  }
403
- }, ge = async (e, t, r, n, a) => {
404
- let o, i;
415
+ }, Ke = async (e, t, r, n, o) => {
416
+ let a, i;
405
417
  const c = new Uint8Array(atob(r.replace(e, "")).split("").map((s) => s.charCodeAt(0)));
406
418
  switch (n) {
407
419
  case "PS256":
408
420
  case "PS384":
409
421
  case "PS512":
410
- o = { name: "RSA-PSS", hash: `SHA-${n.slice(-3)}` }, i = ["verify"];
422
+ a = { name: "RSA-PSS", hash: `SHA-${n.slice(-3)}` }, i = ["verify"];
411
423
  break;
412
424
  case "RS256":
413
425
  case "RS384":
414
426
  case "RS512":
415
- o = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${n.slice(-3)}` }, i = ["verify"];
427
+ a = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${n.slice(-3)}` }, i = ["verify"];
416
428
  break;
417
429
  case "RSA-OAEP":
418
430
  case "RSA-OAEP-256":
419
431
  case "RSA-OAEP-384":
420
432
  case "RSA-OAEP-512":
421
- o = {
433
+ a = {
422
434
  name: "RSA-OAEP",
423
435
  hash: `SHA-${parseInt(n.slice(-3), 10) || 1}`
424
436
  }, i = ["encrypt", "wrapKey"];
425
437
  break;
426
438
  case "ES256":
427
- o = { name: "ECDSA", namedCurve: "P-256" }, i = ["verify"];
439
+ a = { name: "ECDSA", namedCurve: "P-256" }, i = ["verify"];
428
440
  break;
429
441
  case "ES384":
430
- o = { name: "ECDSA", namedCurve: "P-384" }, i = ["verify"];
442
+ a = { name: "ECDSA", namedCurve: "P-384" }, i = ["verify"];
431
443
  break;
432
444
  case "ES512":
433
- o = { name: "ECDSA", namedCurve: "P-521" }, i = ["verify"];
445
+ a = { name: "ECDSA", namedCurve: "P-521" }, i = ["verify"];
434
446
  break;
435
447
  case "ECDH-ES":
436
448
  case "ECDH-ES+A128KW":
437
449
  case "ECDH-ES+A192KW":
438
450
  case "ECDH-ES+A256KW": {
439
- const s = k(c);
440
- o = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, i = [];
451
+ const s = F(c);
452
+ a = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, i = [];
441
453
  break;
442
454
  }
443
455
  case "EdDSA":
444
- o = { name: k(c) }, i = ["verify"];
456
+ a = { name: F(c) }, i = ["verify"];
445
457
  break;
446
458
  default:
447
- throw new w('Invalid or unsupported "alg" (Algorithm) value');
459
+ throw new p('Invalid or unsupported "alg" (Algorithm) value');
448
460
  }
449
- return O.subtle.importKey(t, c, o, !1, i);
450
- }, Ae = (e, t, r) => ge(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
451
- async function be(e, t, r) {
461
+ return D.subtle.importKey(t, c, a, !1, i);
462
+ }, Pe = (e, t, r) => Ke(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
463
+ async function Ie(e, t, r) {
452
464
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
453
465
  throw new TypeError('"spki" must be SPKI formatted string');
454
- return Ae(e, t);
466
+ return Pe(e, t);
467
+ }
468
+ async function Re(e, t) {
469
+ if (!_(e))
470
+ throw new TypeError("JWK must be an object");
471
+ switch (t || (t = e.alg), e.kty) {
472
+ case "oct":
473
+ if (typeof e.k != "string" || !e.k)
474
+ throw new TypeError('missing "k" (Key Value) Parameter value');
475
+ return g(e.k);
476
+ case "RSA":
477
+ if (e.oth !== void 0)
478
+ throw new p('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
479
+ case "EC":
480
+ case "OKP":
481
+ return te({ ...e, alg: t });
482
+ default:
483
+ throw new p('Unsupported "kty" (Key Type) Parameter value');
484
+ }
455
485
  }
456
- const I = (e) => e == null ? void 0 : e[Symbol.toStringTag], Ce = (e, t) => {
486
+ const T = (e) => e == null ? void 0 : e[Symbol.toStringTag], $ = (e, t, r) => {
487
+ var n, o;
488
+ if (t.use !== void 0 && t.use !== "sig")
489
+ throw new TypeError("Invalid key for this operation, when present its use must be sig");
490
+ if (t.key_ops !== void 0 && ((o = (n = t.key_ops).includes) == null ? void 0 : o.call(n, r)) !== !0)
491
+ throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${r}`);
492
+ if (t.alg !== void 0 && t.alg !== e)
493
+ throw new TypeError(`Invalid key for this operation, when present its alg must be ${e}`);
494
+ return !0;
495
+ }, Oe = (e, t, r, n) => {
457
496
  if (!(t instanceof Uint8Array)) {
458
- if (!X(t))
459
- throw new TypeError(z(e, t, ...P, "Uint8Array"));
497
+ if (n && K(t)) {
498
+ if (Ae(t) && $(e, t, r))
499
+ return;
500
+ 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');
501
+ }
502
+ if (!ee(t))
503
+ throw new TypeError(j(e, t, ...x, "Uint8Array", n ? "JSON Web Key" : null));
460
504
  if (t.type !== "secret")
461
- throw new TypeError(`${I(t)} instances for symmetric algorithms must be of type "secret"`);
462
- }
463
- }, _e = (e, t, r) => {
464
- if (!X(t))
465
- throw new TypeError(z(e, t, ...P));
505
+ throw new TypeError(`${T(t)} instances for symmetric algorithms must be of type "secret"`);
506
+ }
507
+ }, We = (e, t, r, n) => {
508
+ if (n && K(t))
509
+ switch (r) {
510
+ case "sign":
511
+ if (ge(t) && $(e, t, r))
512
+ return;
513
+ throw new TypeError("JSON Web Key for this operation be a private JWK");
514
+ case "verify":
515
+ if (be(t) && $(e, t, r))
516
+ return;
517
+ throw new TypeError("JSON Web Key for this operation be a public JWK");
518
+ }
519
+ if (!ee(t))
520
+ throw new TypeError(j(e, t, ...x, n ? "JSON Web Key" : null));
466
521
  if (t.type === "secret")
467
- throw new TypeError(`${I(t)} instances for asymmetric algorithms must not be of type "secret"`);
522
+ throw new TypeError(`${T(t)} instances for asymmetric algorithms must not be of type "secret"`);
523
+ if (r === "sign" && t.type === "public")
524
+ throw new TypeError(`${T(t)} instances for asymmetric algorithm signing must be of type "private"`);
525
+ if (r === "decrypt" && t.type === "public")
526
+ throw new TypeError(`${T(t)} instances for asymmetric algorithm decryption must be of type "private"`);
468
527
  if (t.algorithm && r === "verify" && t.type === "private")
469
- throw new TypeError(`${I(t)} instances for asymmetric algorithm verifying must be of type "public"`);
528
+ throw new TypeError(`${T(t)} instances for asymmetric algorithm verifying must be of type "public"`);
470
529
  if (t.algorithm && r === "encrypt" && t.type === "private")
471
- throw new TypeError(`${I(t)} instances for asymmetric algorithm encryption must be of type "public"`);
472
- }, ve = (e, t, r) => {
473
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? Ce(e, t) : _e(e, t, r);
530
+ throw new TypeError(`${T(t)} instances for asymmetric algorithm encryption must be of type "public"`);
474
531
  };
475
- function Te(e, t, r, n, a) {
476
- if (a.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
532
+ function oe(e, t, r, n) {
533
+ t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ? Oe(t, r, n, e) : We(t, r, n, e);
534
+ }
535
+ oe.bind(void 0, !1);
536
+ const Y = oe.bind(void 0, !0);
537
+ function xe(e, t, r, n, o) {
538
+ if (o.crit !== void 0 && (n == null ? void 0 : n.crit) === void 0)
477
539
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
478
540
  if (!n || n.crit === void 0)
479
541
  return /* @__PURE__ */ new Set();
480
542
  if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((i) => typeof i != "string" || i.length === 0))
481
543
  throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
482
- let o;
483
- r !== void 0 ? o = new Map([...Object.entries(r), ...t.entries()]) : o = t;
544
+ let a;
545
+ r !== void 0 ? a = new Map([...Object.entries(r), ...t.entries()]) : a = t;
484
546
  for (const i of n.crit) {
485
- if (!o.has(i))
486
- throw new w(`Extension Header Parameter "${i}" is not recognized`);
487
- if (a[i] === void 0)
547
+ if (!a.has(i))
548
+ throw new p(`Extension Header Parameter "${i}" is not recognized`);
549
+ if (o[i] === void 0)
488
550
  throw new e(`Extension Header Parameter "${i}" is missing`);
489
- if (o.get(i) && n[i] === void 0)
551
+ if (a.get(i) && n[i] === void 0)
490
552
  throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`);
491
553
  }
492
554
  return new Set(n.crit);
493
555
  }
494
- const Ie = (e, t) => {
556
+ const Je = (e, t) => {
495
557
  if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
496
558
  throw new TypeError(`"${e}" option must be an array of strings`);
497
559
  if (t)
498
560
  return new Set(t);
499
561
  };
500
- function Re(e, t) {
562
+ function De(e, t) {
501
563
  const r = `SHA-${e.slice(-3)}`;
502
564
  switch (e) {
503
565
  case "HS256":
@@ -519,214 +581,214 @@ function Re(e, t) {
519
581
  case "EdDSA":
520
582
  return { name: t.name };
521
583
  default:
522
- throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);
584
+ throw new p(`alg ${e} is not supported either by JOSE or your javascript runtime`);
523
585
  }
524
586
  }
525
- async function Pe(e, t, r) {
526
- if (t = await we.normalizePublicKey(t, e), G(t))
527
- return le(t, e, r), t;
587
+ async function He(e, t, r) {
588
+ if (t = await _e.normalizePublicKey(t, e), Q(t))
589
+ return ye(t, e, r), t;
528
590
  if (t instanceof Uint8Array) {
529
591
  if (!e.startsWith("HS"))
530
- throw new TypeError(L(t, ...P));
531
- return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
592
+ throw new TypeError(V(t, ...x));
593
+ return D.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
532
594
  }
533
- throw new TypeError(L(t, ...P, "Uint8Array"));
595
+ throw new TypeError(V(t, ...x, "Uint8Array", "JSON Web Key"));
534
596
  }
535
- const Ke = async (e, t, r, n) => {
536
- const a = await Pe(e, t, "verify");
537
- pe(e, a);
538
- const o = Re(e, a.algorithm);
597
+ const Ne = async (e, t, r, n) => {
598
+ const o = await He(e, t, "verify");
599
+ we(e, o);
600
+ const a = De(e, o.algorithm);
539
601
  try {
540
- return await O.subtle.verify(o, a, r, n);
602
+ return await D.subtle.verify(a, o, r, n);
541
603
  } catch {
542
604
  return !1;
543
605
  }
544
606
  };
545
- async function Oe(e, t, r) {
546
- if (!K(e))
547
- throw new u("Flattened JWS must be an object");
607
+ async function Ue(e, t, r) {
608
+ if (!_(e))
609
+ throw new d("Flattened JWS must be an object");
548
610
  if (e.protected === void 0 && e.header === void 0)
549
- throw new u('Flattened JWS must have either of the "protected" or "header" members');
611
+ throw new d('Flattened JWS must have either of the "protected" or "header" members');
550
612
  if (e.protected !== void 0 && typeof e.protected != "string")
551
- throw new u("JWS Protected Header incorrect type");
613
+ throw new d("JWS Protected Header incorrect type");
552
614
  if (e.payload === void 0)
553
- throw new u("JWS Payload missing");
615
+ throw new d("JWS Payload missing");
554
616
  if (typeof e.signature != "string")
555
- throw new u("JWS Signature missing or incorrect type");
556
- if (e.header !== void 0 && !K(e.header))
557
- throw new u("JWS Unprotected Header incorrect type");
617
+ throw new d("JWS Signature missing or incorrect type");
618
+ if (e.header !== void 0 && !_(e.header))
619
+ throw new d("JWS Unprotected Header incorrect type");
558
620
  let n = {};
559
621
  if (e.protected)
560
622
  try {
561
- const x = b(e.protected);
562
- n = JSON.parse(C.decode(x));
623
+ const H = g(e.protected);
624
+ n = JSON.parse(P.decode(H));
563
625
  } catch {
564
- throw new u("JWS Protected Header is invalid");
626
+ throw new d("JWS Protected Header is invalid");
565
627
  }
566
- if (!fe(n, e.header))
567
- throw new u("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
568
- const a = {
628
+ if (!Se(n, e.header))
629
+ throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
630
+ const o = {
569
631
  ...n,
570
632
  ...e.header
571
- }, o = Te(u, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, a);
633
+ }, a = xe(d, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, n, o);
572
634
  let i = !0;
573
- if (o.has("b64") && (i = n.b64, typeof i != "boolean"))
574
- throw new u('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
575
- const { alg: c } = a;
635
+ if (a.has("b64") && (i = n.b64, typeof i != "boolean"))
636
+ throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
637
+ const { alg: c } = o;
576
638
  if (typeof c != "string" || !c)
577
- throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
578
- const s = r && Ie("algorithms", r.algorithms);
639
+ throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
640
+ const s = r && Je("algorithms", r.algorithms);
579
641
  if (s && !s.has(c))
580
- throw new ce('"alg" (Algorithm) Header Parameter value not allowed');
642
+ throw new le('"alg" (Algorithm) Header Parameter value not allowed');
581
643
  if (i) {
582
644
  if (typeof e.payload != "string")
583
- throw new u("JWS Payload must be a string");
645
+ throw new d("JWS Payload must be a string");
584
646
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
585
- throw new u("JWS Payload must be a string or an Uint8Array instance");
586
- let p = !1;
587
- typeof t == "function" && (t = await t(n, e), p = !0), ve(c, t, "verify");
588
- const g = oe(_.encode(e.protected ?? ""), _.encode("."), typeof e.payload == "string" ? _.encode(e.payload) : e.payload);
589
- let f;
647
+ throw new d("JWS Payload must be a string or an Uint8Array instance");
648
+ let m = !1;
649
+ typeof t == "function" ? (t = await t(n, e), m = !0, Y(c, t, "verify"), K(t) && (t = await Re(t, c))) : Y(c, t, "verify");
650
+ const b = de(I.encode(e.protected ?? ""), I.encode("."), typeof e.payload == "string" ? I.encode(e.payload) : e.payload);
651
+ let l;
590
652
  try {
591
- f = b(e.signature);
653
+ l = g(e.signature);
592
654
  } catch {
593
- throw new u("Failed to base64url decode the signature");
655
+ throw new d("Failed to base64url decode the signature");
594
656
  }
595
- if (!await Ke(c, t, f, g))
596
- throw new se();
597
- let y;
657
+ if (!await Ne(c, t, l, b))
658
+ throw new he();
659
+ let E;
598
660
  if (i)
599
661
  try {
600
- y = b(e.payload);
662
+ E = g(e.payload);
601
663
  } catch {
602
- throw new u("Failed to base64url decode the payload");
664
+ throw new d("Failed to base64url decode the payload");
603
665
  }
604
- else typeof e.payload == "string" ? y = _.encode(e.payload) : y = e.payload;
605
- const l = { payload: y };
606
- return e.protected !== void 0 && (l.protectedHeader = n), e.header !== void 0 && (l.unprotectedHeader = e.header), p ? { ...l, key: t } : l;
607
- }
608
- async function xe(e, t, r) {
609
- if (e instanceof Uint8Array && (e = C.decode(e)), typeof e != "string")
610
- throw new u("Compact JWS must be a string or Uint8Array");
611
- const { 0: n, 1: a, 2: o, length: i } = e.split(".");
666
+ else typeof e.payload == "string" ? E = I.encode(e.payload) : E = e.payload;
667
+ const f = { payload: E };
668
+ return e.protected !== void 0 && (f.protectedHeader = n), e.header !== void 0 && (f.unprotectedHeader = e.header), m ? { ...f, key: t } : f;
669
+ }
670
+ async function $e(e, t, r) {
671
+ if (e instanceof Uint8Array && (e = P.decode(e)), typeof e != "string")
672
+ throw new d("Compact JWS must be a string or Uint8Array");
673
+ const { 0: n, 1: o, 2: a, length: i } = e.split(".");
612
674
  if (i !== 3)
613
- throw new u("Invalid Compact JWS");
614
- const c = await Oe({ payload: a, protected: n, signature: o }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
675
+ throw new d("Invalid Compact JWS");
676
+ const c = await Ue({ payload: o, protected: n, signature: a }, t, r), s = { payload: c.payload, protectedHeader: c.protectedHeader };
615
677
  return typeof t == "function" ? { ...s, key: c.key } : s;
616
678
  }
617
- const We = (e) => Math.floor(e.getTime() / 1e3), ee = 60, te = ee * 60, N = te * 24, De = N * 7, Je = N * 365.25, He = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, M = (e) => {
618
- const t = He.exec(e);
679
+ const Le = (e) => Math.floor(e.getTime() / 1e3), ae = 60, ie = ae * 60, L = ie * 24, Me = L * 7, Be = L * 365.25, Ve = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, k = (e) => {
680
+ const t = Ve.exec(e);
619
681
  if (!t || t[4] && t[1])
620
682
  throw new TypeError("Invalid time period format");
621
683
  const r = parseFloat(t[2]), n = t[3].toLowerCase();
622
- let a;
684
+ let o;
623
685
  switch (n) {
624
686
  case "sec":
625
687
  case "secs":
626
688
  case "second":
627
689
  case "seconds":
628
690
  case "s":
629
- a = Math.round(r);
691
+ o = Math.round(r);
630
692
  break;
631
693
  case "minute":
632
694
  case "minutes":
633
695
  case "min":
634
696
  case "mins":
635
697
  case "m":
636
- a = Math.round(r * ee);
698
+ o = Math.round(r * ae);
637
699
  break;
638
700
  case "hour":
639
701
  case "hours":
640
702
  case "hr":
641
703
  case "hrs":
642
704
  case "h":
643
- a = Math.round(r * te);
705
+ o = Math.round(r * ie);
644
706
  break;
645
707
  case "day":
646
708
  case "days":
647
709
  case "d":
648
- a = Math.round(r * N);
710
+ o = Math.round(r * L);
649
711
  break;
650
712
  case "week":
651
713
  case "weeks":
652
714
  case "w":
653
- a = Math.round(r * De);
715
+ o = Math.round(r * Me);
654
716
  break;
655
717
  default:
656
- a = Math.round(r * Je);
718
+ o = Math.round(r * Be);
657
719
  break;
658
720
  }
659
- return t[1] === "-" || t[4] === "ago" ? -a : a;
660
- }, B = (e) => e.toLowerCase().replace(/^application\//, ""), Ne = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Ue = (e, t, r = {}) => {
721
+ return t[1] === "-" || t[4] === "ago" ? -o : o;
722
+ }, G = (e) => e.toLowerCase().replace(/^application\//, ""), Fe = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Ye = (e, t, r = {}) => {
661
723
  let n;
662
724
  try {
663
- n = JSON.parse(C.decode(t));
725
+ n = JSON.parse(P.decode(t));
664
726
  } catch {
665
727
  }
666
- if (!K(n))
728
+ if (!_(n))
667
729
  throw new S("JWT Claims Set must be a top-level JSON object");
668
- const { typ: a } = r;
669
- if (a && (typeof e.typ != "string" || B(e.typ) !== B(a)))
730
+ const { typ: o } = r;
731
+ if (o && (typeof e.typ != "string" || G(e.typ) !== G(o)))
670
732
  throw new h('unexpected "typ" JWT header value', n, "typ", "check_failed");
671
- const { requiredClaims: o = [], issuer: i, subject: c, audience: s, maxTokenAge: p } = r, g = [...o];
672
- p !== void 0 && g.push("iat"), s !== void 0 && g.push("aud"), c !== void 0 && g.push("sub"), i !== void 0 && g.push("iss");
673
- for (const l of new Set(g.reverse()))
674
- if (!(l in n))
675
- throw new h(`missing required "${l}" claim`, n, l, "missing");
733
+ const { requiredClaims: a = [], issuer: i, subject: c, audience: s, maxTokenAge: m } = r, b = [...a];
734
+ m !== void 0 && b.push("iat"), s !== void 0 && b.push("aud"), c !== void 0 && b.push("sub"), i !== void 0 && b.push("iss");
735
+ for (const f of new Set(b.reverse()))
736
+ if (!(f in n))
737
+ throw new h(`missing required "${f}" claim`, n, f, "missing");
676
738
  if (i && !(Array.isArray(i) ? i : [i]).includes(n.iss))
677
739
  throw new h('unexpected "iss" claim value', n, "iss", "check_failed");
678
740
  if (c && n.sub !== c)
679
741
  throw new h('unexpected "sub" claim value', n, "sub", "check_failed");
680
- if (s && !Ne(n.aud, typeof s == "string" ? [s] : s))
742
+ if (s && !Fe(n.aud, typeof s == "string" ? [s] : s))
681
743
  throw new h('unexpected "aud" claim value', n, "aud", "check_failed");
682
- let f;
744
+ let l;
683
745
  switch (typeof r.clockTolerance) {
684
746
  case "string":
685
- f = M(r.clockTolerance);
747
+ l = k(r.clockTolerance);
686
748
  break;
687
749
  case "number":
688
- f = r.clockTolerance;
750
+ l = r.clockTolerance;
689
751
  break;
690
752
  case "undefined":
691
- f = 0;
753
+ l = 0;
692
754
  break;
693
755
  default:
694
756
  throw new TypeError("Invalid clockTolerance option type");
695
757
  }
696
- const { currentDate: U } = r, y = We(U || /* @__PURE__ */ new Date());
697
- if ((n.iat !== void 0 || p) && typeof n.iat != "number")
758
+ const { currentDate: M } = r, E = Le(M || /* @__PURE__ */ new Date());
759
+ if ((n.iat !== void 0 || m) && typeof n.iat != "number")
698
760
  throw new h('"iat" claim must be a number', n, "iat", "invalid");
699
761
  if (n.nbf !== void 0) {
700
762
  if (typeof n.nbf != "number")
701
763
  throw new h('"nbf" claim must be a number', n, "nbf", "invalid");
702
- if (n.nbf > y + f)
764
+ if (n.nbf > E + l)
703
765
  throw new h('"nbf" claim timestamp check failed', n, "nbf", "check_failed");
704
766
  }
705
767
  if (n.exp !== void 0) {
706
768
  if (typeof n.exp != "number")
707
769
  throw new h('"exp" claim must be a number', n, "exp", "invalid");
708
- if (n.exp <= y - f)
709
- throw new $('"exp" claim timestamp check failed', n, "exp", "check_failed");
710
- }
711
- if (p) {
712
- const l = y - n.iat, x = typeof p == "number" ? p : M(p);
713
- if (l - f > x)
714
- throw new $('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
715
- if (l < 0 - f)
770
+ if (n.exp <= E - l)
771
+ throw new B('"exp" claim timestamp check failed', n, "exp", "check_failed");
772
+ }
773
+ if (m) {
774
+ const f = E - n.iat, H = typeof m == "number" ? m : k(m);
775
+ if (f - l > H)
776
+ throw new B('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
777
+ if (f < 0 - l)
716
778
  throw new h('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
717
779
  }
718
780
  return n;
719
781
  };
720
- async function $e(e, t, r) {
782
+ async function ke(e, t, r) {
721
783
  var i;
722
- const n = await xe(e, t, r);
784
+ const n = await $e(e, t, r);
723
785
  if ((i = n.protectedHeader.crit) != null && i.includes("b64") && n.protectedHeader.b64 === !1)
724
786
  throw new S("JWTs MUST NOT use unencoded payload");
725
- const o = { payload: Ue(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
726
- return typeof t == "function" ? { ...o, key: n.key } : o;
787
+ const a = { payload: Ye(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
788
+ return typeof t == "function" ? { ...a, key: n.key } : a;
727
789
  }
728
- const Le = b;
729
- function ke(e) {
790
+ const Ge = g;
791
+ function qe(e) {
730
792
  if (typeof e != "string")
731
793
  throw new S("JWTs must use Compact JWS serialization, JWT must be a string");
732
794
  const { 1: t, length: r } = e.split(".");
@@ -738,134 +800,134 @@ function ke(e) {
738
800
  throw new S("JWTs must contain a payload");
739
801
  let n;
740
802
  try {
741
- n = Le(t);
803
+ n = Ge(t);
742
804
  } catch {
743
805
  throw new S("Failed to base64url decode the payload");
744
806
  }
745
- let a;
807
+ let o;
746
808
  try {
747
- a = JSON.parse(C.decode(n));
809
+ o = JSON.parse(P.decode(n));
748
810
  } catch {
749
811
  throw new S("Failed to parse the decoded payload as JSON");
750
812
  }
751
- if (!K(a))
813
+ if (!_(o))
752
814
  throw new S("Invalid JWT Claims Set");
753
- return a;
815
+ return o;
754
816
  }
755
- const Me = async (e) => {
817
+ const ze = async (e) => {
756
818
  try {
757
- const t = R.ALG, n = await be(ae, t);
758
- return await $e(e, n, {
759
- issuer: R.ISSUER
819
+ const t = W.ALG, n = await Ie(ue, t);
820
+ return await ke(e, n, {
821
+ issuer: W.ISSUER
760
822
  });
761
823
  } catch {
762
824
  return;
763
825
  }
764
- }, at = (e) => {
826
+ }, ft = (e) => {
765
827
  try {
766
- return ke(e);
828
+ return qe(e);
767
829
  } catch {
768
830
  return;
769
831
  }
770
832
  };
771
- var d = [];
772
- for (var H = 0; H < 256; ++H)
773
- d.push((H + 256).toString(16).slice(1));
774
- function Be(e, t = 0) {
775
- return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
776
- }
777
- var T, Fe = new Uint8Array(16);
778
- function Ye() {
779
- if (!T && (T = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !T))
833
+ var u = [];
834
+ for (var U = 0; U < 256; ++U)
835
+ u.push((U + 256).toString(16).slice(1));
836
+ function Xe(e, t = 0) {
837
+ return (u[e[t + 0]] + u[e[t + 1]] + u[e[t + 2]] + u[e[t + 3]] + "-" + u[e[t + 4]] + u[e[t + 5]] + "-" + u[e[t + 6]] + u[e[t + 7]] + "-" + u[e[t + 8]] + u[e[t + 9]] + "-" + u[e[t + 10]] + u[e[t + 11]] + u[e[t + 12]] + u[e[t + 13]] + u[e[t + 14]] + u[e[t + 15]]).toLowerCase();
838
+ }
839
+ var O, Qe = new Uint8Array(16);
840
+ function Ze() {
841
+ if (!O && (O = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !O))
780
842
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
781
- return T(Fe);
843
+ return O(Qe);
782
844
  }
783
- var Ve = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
784
- const F = {
785
- randomUUID: Ve
845
+ var je = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
846
+ const q = {
847
+ randomUUID: je
786
848
  };
787
- function Y(e, t, r) {
788
- if (F.randomUUID && !t && !e)
789
- return F.randomUUID();
849
+ function z(e, t, r) {
850
+ if (q.randomUUID && !t && !e)
851
+ return q.randomUUID();
790
852
  e = e || {};
791
- var n = e.random || (e.rng || Ye)();
792
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Be(n);
853
+ var n = e.random || (e.rng || Ze)();
854
+ return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, Xe(n);
793
855
  }
794
- const V = globalThis.crypto, Ge = (e) => `${Y()}${Y()}`.slice(0, e), qe = (e) => btoa(
856
+ const X = globalThis.crypto, et = (e) => `${z()}${z()}`.slice(0, e), tt = (e) => btoa(
795
857
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
796
858
  );
797
- async function re(e) {
798
- if (!V.subtle)
859
+ async function ce(e) {
860
+ if (!X.subtle)
799
861
  throw new Error(
800
862
  "crypto.subtle is available only in secure contexts (HTTPS)."
801
863
  );
802
- const t = new TextEncoder().encode(e), r = await V.subtle.digest("SHA-256", t);
803
- return qe(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
864
+ const t = new TextEncoder().encode(e), r = await X.subtle.digest("SHA-256", t);
865
+ return tt(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
804
866
  }
805
- async function ot(e) {
867
+ async function lt(e) {
806
868
  const t = e || 43;
807
869
  if (t < 43 || t > 128)
808
870
  throw `Expected a length between 43 and 128. Received ${e}.`;
809
- const r = Ge(t), n = await re(r);
871
+ const r = et(t), n = await ce(r);
810
872
  return {
811
873
  code_verifier: r,
812
874
  code_challenge: n
813
875
  };
814
876
  }
815
- async function it(e, t) {
816
- return t === await re(e);
877
+ async function ht(e, t) {
878
+ return t === await ce(e);
817
879
  }
818
- const ze = /^Bearer (.+)$/i, Xe = (e) => {
880
+ const rt = /^Bearer (.+)$/i, nt = (e) => {
819
881
  if (typeof (e == null ? void 0 : e.authorization) != "string")
820
882
  return;
821
- const t = e.authorization.match(ze);
883
+ const t = e.authorization.match(rt);
822
884
  if (t)
823
885
  return t[1];
824
- }, Qe = (e, t) => {
886
+ }, ot = (e, t) => {
825
887
  const r = e == null ? void 0 : e.cookie;
826
888
  if (typeof r != "string")
827
889
  return;
828
- const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), a = r.match(n);
829
- if (a)
830
- return a[1];
831
- }, Ze = (e) => {
832
- const t = e == null ? void 0 : e[ne.ACCESS_TOKEN];
890
+ const n = new RegExp(`auth.${t}=(.+?)(?:;|$)`), o = r.match(n);
891
+ if (o)
892
+ return o[1];
893
+ }, at = (e) => {
894
+ const t = e == null ? void 0 : e[se.ACCESS_TOKEN];
833
895
  if (typeof t == "string")
834
896
  return t;
835
- }, ct = ({ headers: e, body: t, clientId: r }) => {
836
- const n = Xe(e), a = Qe(e, r);
837
- return Ze(t) || a || n || "";
838
- }, st = async (e, t) => {
839
- var a;
840
- const r = await Me(e);
841
- if (!r || !Array.isArray((a = r.payload) == null ? void 0 : a[R.SCOPES_KEY]))
897
+ }, pt = ({ headers: e, body: t, clientId: r }) => {
898
+ const n = nt(e), o = ot(e, r);
899
+ return at(t) || o || n || "";
900
+ }, mt = async (e, t) => {
901
+ var o;
902
+ const r = await ze(e);
903
+ if (!r || !Array.isArray((o = r.payload) == null ? void 0 : o[W.SCOPES_KEY]))
842
904
  return !1;
843
- const n = r.payload[R.SCOPES_KEY];
844
- return Array.isArray(t) ? t.every((o) => n.includes(o)) : Object.keys(t).some(
845
- (o) => t[o].every((i) => n.includes(i))
905
+ const n = r.payload[W.SCOPES_KEY];
906
+ return Array.isArray(t) ? t.every((a) => n.includes(a)) : Object.keys(t).some(
907
+ (a) => t[a].every((i) => n.includes(i))
846
908
  );
847
- }, je = (e, t) => {
909
+ }, it = (e, t) => {
848
910
  const r = e == null ? void 0 : e.cookie;
849
911
  if (typeof r != "string")
850
912
  return;
851
- const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), a = r.match(n);
852
- if (a)
853
- return a[1];
854
- }, dt = ({ headers: e, clientId: t }) => je(e, t) || "";
913
+ const n = new RegExp(`auth.${t}.session=(.+?)(?:;|$)`), o = r.match(n);
914
+ if (o)
915
+ return o[1];
916
+ }, yt = ({ headers: e, clientId: t }) => it(e, t) || "";
855
917
  export {
856
- nt as API_TYPE,
857
- et as AUTH_TYPES,
858
- ne as BODY,
859
- tt as HEADERS,
860
- R as JWT,
861
- ae as JWT_PUBLIC_KEY,
862
- rt as TOKEN_EXPIRATION,
863
- at as decodeToken,
864
- re as generateCodeChallenge,
865
- dt as getSession,
866
- ct as getToken,
867
- st as isGranted,
868
- ot as pkceChallengePair,
869
- Me as verifyAndExtractToken,
870
- it as verifyChallenge
918
+ dt as API_TYPE,
919
+ ct as AUTH_TYPES,
920
+ se as BODY,
921
+ st as HEADERS,
922
+ W as JWT,
923
+ ue as JWT_PUBLIC_KEY,
924
+ ut as TOKEN_EXPIRATION,
925
+ ft as decodeToken,
926
+ ce as generateCodeChallenge,
927
+ yt as getSession,
928
+ pt as getToken,
929
+ mt as isGranted,
930
+ lt as pkceChallengePair,
931
+ ze as verifyAndExtractToken,
932
+ ht as verifyChallenge
871
933
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-common",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -33,8 +33,8 @@
33
33
  "test:coverage": "vitest run --coverage"
34
34
  },
35
35
  "dependencies": {
36
- "jose": "5.7.0",
36
+ "jose": "5.9.2",
37
37
  "uuid": "10.0.0"
38
38
  },
39
- "gitHead": "74132e69a7def29f79c3d6a089611972dbfdfb63"
39
+ "gitHead": "9ed19e1974850fb97bbd510a24b85fc2b46b8383"
40
40
  }