@versini/auth-common 2.5.0 → 2.7.0

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.ts CHANGED
@@ -12,6 +12,7 @@ declare const JWT: {
12
12
  ALG: string;
13
13
  USER_ID_KEY: string;
14
14
  TOKEN_ID_KEY: string;
15
+ NONCE_KEY: string;
15
16
  ISSUER: string;
16
17
  };
17
18
  declare const JWT_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7\nw5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5\ni1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle\naMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+\nl0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE\nsjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81\nawIDAQAB\n-----END PUBLIC KEY-----";
@@ -19,6 +20,33 @@ declare const TOKEN_EXPIRATION: {
19
20
  ACCESS: string;
20
21
  ID: string;
21
22
  };
22
- declare const verifyAndExtractToken: (token: string, audience: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
23
23
 
24
- export { AUTH_TYPES, HEADERS, JWT, JWT_PUBLIC_KEY, TOKEN_EXPIRATION, verifyAndExtractToken };
24
+ declare const verifyAndExtractToken: (token: string) => Promise<jose.JWTVerifyResult<jose.JWTPayload> | undefined>;
25
+
26
+ /**
27
+ * Generate a PKCE code challenge from a code verifier.
28
+ *
29
+ * @param code_verifier
30
+ * @returns The base64 url encoded code challenge.
31
+ */
32
+ declare function generateCodeChallenge(code_verifier: string): Promise<string>;
33
+ /**
34
+ * Generate a PKCE challenge pair.
35
+ *
36
+ * @param length Length of the verifier (between 43-128). Defaults to 43.
37
+ * @returns PKCE challenge pair.
38
+ */
39
+ declare function pkceChallengePair(length?: number): Promise<{
40
+ code_verifier: string;
41
+ code_challenge: string;
42
+ }>;
43
+ /**
44
+ * Verify that a code_verifier produces the expected code challenge.
45
+ *
46
+ * @param code_verifier
47
+ * @param expectedChallenge The code challenge to verify.
48
+ * @returns True if challenges are equal. False otherwise.
49
+ */
50
+ declare function verifyChallenge(code_verifier: string, expectedChallenge: string): Promise<boolean>;
51
+
52
+ export { AUTH_TYPES, HEADERS, JWT, JWT_PUBLIC_KEY, TOKEN_EXPIRATION, generateCodeChallenge, pkceChallengePair, verifyAndExtractToken, verifyChallenge };
package/dist/index.js CHANGED
@@ -1,39 +1,62 @@
1
1
  /*!
2
- @versini/auth-common v2.5.0
2
+ @versini/auth-common v2.7.0
3
3
  © 2024 gizmette.com
4
4
  */
5
5
  try {
6
6
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
7
- version: "2.5.0",
8
- buildTime: "06/25/2024 05:52 PM EDT",
7
+ version: "2.7.0",
8
+ buildTime: "06/27/2024 12:17 PM EDT",
9
9
  homepage: "https://github.com/aversini/auth-client",
10
10
  license: "MIT"
11
11
  });
12
12
  } catch {
13
13
  }
14
- const P = crypto, D = (e) => e instanceof CryptoKey, A = new TextEncoder(), g = new TextDecoder();
15
- function V(...e) {
16
- const t = e.reduce((o, { length: i }) => o + i, 0), n = new Uint8Array(t);
14
+ const Ue = {
15
+ ID_TOKEN: "id_token",
16
+ ACCESS_TOKEN: "token",
17
+ ID_AND_ACCESS_TOKEN: "id_token token"
18
+ }, De = {
19
+ CLIENT_ID: "X-Auth-ClientId"
20
+ }, U = {
21
+ ALG: "RS256",
22
+ USER_ID_KEY: "_id",
23
+ TOKEN_ID_KEY: "__raw",
24
+ NONCE_KEY: "_nonce",
25
+ ISSUER: "gizmette.com"
26
+ }, X = `-----BEGIN PUBLIC KEY-----
27
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
28
+ w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
29
+ i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
30
+ aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
31
+ l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
32
+ sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
33
+ awIDAQAB
34
+ -----END PUBLIC KEY-----`, Ne = {
35
+ ACCESS: "5m",
36
+ ID: "90d"
37
+ }, O = crypto, V = (e) => e instanceof CryptoKey, g = new TextEncoder(), _ = new TextDecoder();
38
+ function j(...e) {
39
+ const t = e.reduce((a, { length: i }) => a + i, 0), n = new Uint8Array(t);
17
40
  let r = 0;
18
- for (const o of e)
19
- n.set(o, r), r += o.length;
41
+ for (const a of e)
42
+ n.set(a, r), r += a.length;
20
43
  return n;
21
44
  }
22
- const F = (e) => {
45
+ const Z = (e) => {
23
46
  const t = atob(e), n = new Uint8Array(t.length);
24
47
  for (let r = 0; r < t.length; r++)
25
48
  n[r] = t.charCodeAt(r);
26
49
  return n;
27
- }, C = (e) => {
50
+ }, R = (e) => {
28
51
  let t = e;
29
- t instanceof Uint8Array && (t = g.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
52
+ t instanceof Uint8Array && (t = _.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
30
53
  try {
31
- return F(t);
54
+ return Z(t);
32
55
  } catch {
33
56
  throw new TypeError("The input to be decoded is not correctly encoded.");
34
57
  }
35
58
  };
36
- class w extends Error {
59
+ class b extends Error {
37
60
  static get code() {
38
61
  return "ERR_JOSE_GENERIC";
39
62
  }
@@ -42,23 +65,23 @@ class w extends Error {
42
65
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (n = Error.captureStackTrace) == null || n.call(Error, this, this.constructor);
43
66
  }
44
67
  }
45
- class h extends w {
68
+ class h extends b {
46
69
  static get code() {
47
70
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
48
71
  }
49
- constructor(t, n, r = "unspecified", o = "unspecified") {
50
- super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = o, this.payload = n;
72
+ constructor(t, n, r = "unspecified", a = "unspecified") {
73
+ super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = a, this.payload = n;
51
74
  }
52
75
  }
53
- class O extends w {
76
+ class D extends b {
54
77
  static get code() {
55
78
  return "ERR_JWT_EXPIRED";
56
79
  }
57
- constructor(t, n, r = "unspecified", o = "unspecified") {
58
- super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = o, this.payload = n;
80
+ constructor(t, n, r = "unspecified", a = "unspecified") {
81
+ super(t), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = a, this.payload = n;
59
82
  }
60
83
  }
61
- class G extends w {
84
+ class ee extends b {
62
85
  constructor() {
63
86
  super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
64
87
  }
@@ -66,7 +89,7 @@ class G extends w {
66
89
  return "ERR_JOSE_ALG_NOT_ALLOWED";
67
90
  }
68
91
  }
69
- class I extends w {
92
+ class C extends b {
70
93
  constructor() {
71
94
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
72
95
  }
@@ -74,7 +97,7 @@ class I extends w {
74
97
  return "ERR_JOSE_NOT_SUPPORTED";
75
98
  }
76
99
  }
77
- class d extends w {
100
+ class u extends b {
78
101
  constructor() {
79
102
  super(...arguments), this.code = "ERR_JWS_INVALID";
80
103
  }
@@ -82,7 +105,7 @@ class d extends w {
82
105
  return "ERR_JWS_INVALID";
83
106
  }
84
107
  }
85
- class k extends w {
108
+ class B extends b {
86
109
  constructor() {
87
110
  super(...arguments), this.code = "ERR_JWT_INVALID";
88
111
  }
@@ -90,7 +113,7 @@ class k extends w {
90
113
  return "ERR_JWT_INVALID";
91
114
  }
92
115
  }
93
- class q extends w {
116
+ class te extends b {
94
117
  constructor() {
95
118
  super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
96
119
  }
@@ -98,16 +121,16 @@ class q extends w {
98
121
  return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
99
122
  }
100
123
  }
101
- function p(e, t = "algorithm.name") {
124
+ function m(e, t = "algorithm.name") {
102
125
  return new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);
103
126
  }
104
- function b(e, t) {
127
+ function A(e, t) {
105
128
  return e.name === t;
106
129
  }
107
- function T(e) {
130
+ function v(e) {
108
131
  return parseInt(e.name.slice(4), 10);
109
132
  }
110
- function Y(e) {
133
+ function re(e) {
111
134
  switch (e) {
112
135
  case "ES256":
113
136
  return "P-256";
@@ -119,7 +142,7 @@ function Y(e) {
119
142
  throw new Error("unreachable");
120
143
  }
121
144
  }
122
- function z(e, t) {
145
+ function ne(e, t) {
123
146
  if (t.length && !t.some((n) => e.usages.includes(n))) {
124
147
  let n = "CryptoKey does not support this operation, its usages must include ";
125
148
  if (t.length > 2) {
@@ -130,83 +153,83 @@ function z(e, t) {
130
153
  throw new TypeError(n);
131
154
  }
132
155
  }
133
- function Q(e, t, ...n) {
156
+ function ae(e, t, ...n) {
134
157
  switch (t) {
135
158
  case "HS256":
136
159
  case "HS384":
137
160
  case "HS512": {
138
- if (!b(e.algorithm, "HMAC"))
139
- throw p("HMAC");
161
+ if (!A(e.algorithm, "HMAC"))
162
+ throw m("HMAC");
140
163
  const r = parseInt(t.slice(2), 10);
141
- if (T(e.algorithm.hash) !== r)
142
- throw p(`SHA-${r}`, "algorithm.hash");
164
+ if (v(e.algorithm.hash) !== r)
165
+ throw m(`SHA-${r}`, "algorithm.hash");
143
166
  break;
144
167
  }
145
168
  case "RS256":
146
169
  case "RS384":
147
170
  case "RS512": {
148
- if (!b(e.algorithm, "RSASSA-PKCS1-v1_5"))
149
- throw p("RSASSA-PKCS1-v1_5");
171
+ if (!A(e.algorithm, "RSASSA-PKCS1-v1_5"))
172
+ throw m("RSASSA-PKCS1-v1_5");
150
173
  const r = parseInt(t.slice(2), 10);
151
- if (T(e.algorithm.hash) !== r)
152
- throw p(`SHA-${r}`, "algorithm.hash");
174
+ if (v(e.algorithm.hash) !== r)
175
+ throw m(`SHA-${r}`, "algorithm.hash");
153
176
  break;
154
177
  }
155
178
  case "PS256":
156
179
  case "PS384":
157
180
  case "PS512": {
158
- if (!b(e.algorithm, "RSA-PSS"))
159
- throw p("RSA-PSS");
181
+ if (!A(e.algorithm, "RSA-PSS"))
182
+ throw m("RSA-PSS");
160
183
  const r = parseInt(t.slice(2), 10);
161
- if (T(e.algorithm.hash) !== r)
162
- throw p(`SHA-${r}`, "algorithm.hash");
184
+ if (v(e.algorithm.hash) !== r)
185
+ throw m(`SHA-${r}`, "algorithm.hash");
163
186
  break;
164
187
  }
165
188
  case "EdDSA": {
166
189
  if (e.algorithm.name !== "Ed25519" && e.algorithm.name !== "Ed448")
167
- throw p("Ed25519 or Ed448");
190
+ throw m("Ed25519 or Ed448");
168
191
  break;
169
192
  }
170
193
  case "ES256":
171
194
  case "ES384":
172
195
  case "ES512": {
173
- if (!b(e.algorithm, "ECDSA"))
174
- throw p("ECDSA");
175
- const r = Y(t);
196
+ if (!A(e.algorithm, "ECDSA"))
197
+ throw m("ECDSA");
198
+ const r = re(t);
176
199
  if (e.algorithm.namedCurve !== r)
177
- throw p(r, "algorithm.namedCurve");
200
+ throw m(r, "algorithm.namedCurve");
178
201
  break;
179
202
  }
180
203
  default:
181
204
  throw new TypeError("CryptoKey does not support this operation");
182
205
  }
183
- z(e, n);
206
+ ne(e, n);
184
207
  }
185
- function L(e, t, ...n) {
208
+ function F(e, t, ...n) {
186
209
  var r;
187
210
  if (n.length > 2) {
188
- const o = n.pop();
189
- e += `one of type ${n.join(", ")}, or ${o}.`;
211
+ const a = n.pop();
212
+ e += `one of type ${n.join(", ")}, or ${a}.`;
190
213
  } else
191
214
  n.length === 2 ? e += `one of type ${n[0]} or ${n[1]}.` : e += `of type ${n[0]}.`;
192
215
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (r = t.constructor) != null && r.name && (e += ` Received an instance of ${t.constructor.name}`), e;
193
216
  }
194
- const J = (e, ...t) => L("Key must be ", e, ...t);
195
- function U(e, t, ...n) {
196
- return L(`Key for the ${e} algorithm must be `, t, ...n);
217
+ const N = (e, ...t) => F("Key must be ", e, ...t);
218
+ function G(e, t, ...n) {
219
+ return F(`Key for the ${e} algorithm must be `, t, ...n);
197
220
  }
198
- const $ = (e) => D(e), S = ["CryptoKey"], X = (...e) => {
221
+ const Y = (e) => V(e), w = ["CryptoKey"], oe = (...e) => {
199
222
  const t = e.filter(Boolean);
200
223
  if (t.length === 0 || t.length === 1)
201
224
  return !0;
202
225
  let n;
203
226
  for (const r of t) {
204
- const o = Object.keys(r);
227
+ const a = Object.keys(r);
205
228
  if (!n || n.size === 0) {
206
- n = new Set(o);
229
+ n = new Set(a);
207
230
  continue;
208
231
  }
209
- for (const i of o) {
232
+ for (const i of a) {
210
233
  if (n.has(i))
211
234
  return !1;
212
235
  n.add(i);
@@ -214,11 +237,11 @@ const $ = (e) => D(e), S = ["CryptoKey"], X = (...e) => {
214
237
  }
215
238
  return !0;
216
239
  };
217
- function j(e) {
240
+ function ie(e) {
218
241
  return typeof e == "object" && e !== null;
219
242
  }
220
- function R(e) {
221
- if (!j(e) || Object.prototype.toString.call(e) !== "[object Object]")
243
+ function x(e) {
244
+ if (!ie(e) || Object.prototype.toString.call(e) !== "[object Object]")
222
245
  return !1;
223
246
  if (Object.getPrototypeOf(e) === null)
224
247
  return !0;
@@ -227,51 +250,51 @@ function R(e) {
227
250
  t = Object.getPrototypeOf(t);
228
251
  return Object.getPrototypeOf(e) === t;
229
252
  }
230
- const Z = (e, t) => {
253
+ const ce = (e, t) => {
231
254
  if (e.startsWith("RS") || e.startsWith("PS")) {
232
255
  const { modulusLength: n } = t.algorithm;
233
256
  if (typeof n != "number" || n < 2048)
234
257
  throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
235
258
  }
236
- }, y = (e, t, n = 0) => {
259
+ }, S = (e, t, n = 0) => {
237
260
  n === 0 && (t.unshift(t.length), t.unshift(6));
238
261
  const r = e.indexOf(t[0], n);
239
262
  if (r === -1)
240
263
  return !1;
241
- const o = e.subarray(r, r + t.length);
242
- return o.length !== t.length ? !1 : o.every((i, a) => i === t[a]) || y(e, t, r + 1);
243
- }, K = (e) => {
264
+ const a = e.subarray(r, r + t.length);
265
+ return a.length !== t.length ? !1 : a.every((i, o) => i === t[o]) || S(e, t, r + 1);
266
+ }, W = (e) => {
244
267
  switch (!0) {
245
- case y(e, [42, 134, 72, 206, 61, 3, 1, 7]):
268
+ case S(e, [42, 134, 72, 206, 61, 3, 1, 7]):
246
269
  return "P-256";
247
- case y(e, [43, 129, 4, 0, 34]):
270
+ case S(e, [43, 129, 4, 0, 34]):
248
271
  return "P-384";
249
- case y(e, [43, 129, 4, 0, 35]):
272
+ case S(e, [43, 129, 4, 0, 35]):
250
273
  return "P-521";
251
- case y(e, [43, 101, 110]):
274
+ case S(e, [43, 101, 110]):
252
275
  return "X25519";
253
- case y(e, [43, 101, 111]):
276
+ case S(e, [43, 101, 111]):
254
277
  return "X448";
255
- case y(e, [43, 101, 112]):
278
+ case S(e, [43, 101, 112]):
256
279
  return "Ed25519";
257
- case y(e, [43, 101, 113]):
280
+ case S(e, [43, 101, 113]):
258
281
  return "Ed448";
259
282
  default:
260
- throw new I("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
283
+ throw new C("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
261
284
  }
262
- }, ee = async (e, t, n, r, o) => {
263
- let i, a;
285
+ }, se = async (e, t, n, r, a) => {
286
+ let i, o;
264
287
  const c = new Uint8Array(atob(n.replace(e, "")).split("").map((s) => s.charCodeAt(0)));
265
288
  switch (r) {
266
289
  case "PS256":
267
290
  case "PS384":
268
291
  case "PS512":
269
- i = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
292
+ i = { name: "RSA-PSS", hash: `SHA-${r.slice(-3)}` }, o = ["verify"];
270
293
  break;
271
294
  case "RS256":
272
295
  case "RS384":
273
296
  case "RS512":
274
- i = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, a = ["verify"];
297
+ i = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${r.slice(-3)}` }, o = ["verify"];
275
298
  break;
276
299
  case "RSA-OAEP":
277
300
  case "RSA-OAEP-256":
@@ -280,83 +303,83 @@ const Z = (e, t) => {
280
303
  i = {
281
304
  name: "RSA-OAEP",
282
305
  hash: `SHA-${parseInt(r.slice(-3), 10) || 1}`
283
- }, a = ["encrypt", "wrapKey"];
306
+ }, o = ["encrypt", "wrapKey"];
284
307
  break;
285
308
  case "ES256":
286
- i = { name: "ECDSA", namedCurve: "P-256" }, a = ["verify"];
309
+ i = { name: "ECDSA", namedCurve: "P-256" }, o = ["verify"];
287
310
  break;
288
311
  case "ES384":
289
- i = { name: "ECDSA", namedCurve: "P-384" }, a = ["verify"];
312
+ i = { name: "ECDSA", namedCurve: "P-384" }, o = ["verify"];
290
313
  break;
291
314
  case "ES512":
292
- i = { name: "ECDSA", namedCurve: "P-521" }, a = ["verify"];
315
+ i = { name: "ECDSA", namedCurve: "P-521" }, o = ["verify"];
293
316
  break;
294
317
  case "ECDH-ES":
295
318
  case "ECDH-ES+A128KW":
296
319
  case "ECDH-ES+A192KW":
297
320
  case "ECDH-ES+A256KW": {
298
- const s = K(c);
299
- i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, a = [];
321
+ const s = W(c);
322
+ i = s.startsWith("P-") ? { name: "ECDH", namedCurve: s } : { name: s }, o = [];
300
323
  break;
301
324
  }
302
325
  case "EdDSA":
303
- i = { name: K(c) }, a = ["verify"];
326
+ i = { name: W(c) }, o = ["verify"];
304
327
  break;
305
328
  default:
306
- throw new I('Invalid or unsupported "alg" (Algorithm) value');
329
+ throw new C('Invalid or unsupported "alg" (Algorithm) value');
307
330
  }
308
- return P.subtle.importKey(t, c, i, !1, a);
309
- }, te = (e, t, n) => ee(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
310
- async function re(e, t, n) {
331
+ return O.subtle.importKey(t, c, i, !1, o);
332
+ }, de = (e, t, n) => se(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
333
+ async function ue(e, t, n) {
311
334
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
312
335
  throw new TypeError('"spki" must be SPKI formatted string');
313
- return te(e, t);
336
+ return de(e, t);
314
337
  }
315
- const ne = (e, t) => {
338
+ const le = (e, t) => {
316
339
  if (!(t instanceof Uint8Array)) {
317
- if (!$(t))
318
- throw new TypeError(U(e, t, ...S, "Uint8Array"));
340
+ if (!Y(t))
341
+ throw new TypeError(G(e, t, ...w, "Uint8Array"));
319
342
  if (t.type !== "secret")
320
- throw new TypeError(`${S.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
343
+ throw new TypeError(`${w.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
321
344
  }
322
- }, oe = (e, t, n) => {
323
- if (!$(t))
324
- throw new TypeError(U(e, t, ...S));
345
+ }, fe = (e, t, n) => {
346
+ if (!Y(t))
347
+ throw new TypeError(G(e, t, ...w));
325
348
  if (t.type === "secret")
326
- throw new TypeError(`${S.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
349
+ throw new TypeError(`${w.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
327
350
  if (t.algorithm && n === "verify" && t.type === "private")
328
- throw new TypeError(`${S.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
351
+ throw new TypeError(`${w.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
329
352
  if (t.algorithm && n === "encrypt" && t.type === "private")
330
- throw new TypeError(`${S.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
331
- }, ae = (e, t, n) => {
332
- e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? ne(e, t) : oe(e, t, n);
353
+ throw new TypeError(`${w.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
354
+ }, he = (e, t, n) => {
355
+ e.startsWith("HS") || e === "dir" || e.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(e) ? le(e, t) : fe(e, t, n);
333
356
  };
334
- function ie(e, t, n, r, o) {
335
- if (o.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
357
+ function pe(e, t, n, r, a) {
358
+ if (a.crit !== void 0 && (r == null ? void 0 : r.crit) === void 0)
336
359
  throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
337
360
  if (!r || r.crit === void 0)
338
361
  return /* @__PURE__ */ new Set();
339
- if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((a) => typeof a != "string" || a.length === 0))
362
+ if (!Array.isArray(r.crit) || r.crit.length === 0 || r.crit.some((o) => typeof o != "string" || o.length === 0))
340
363
  throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
341
364
  let i;
342
365
  n !== void 0 ? i = new Map([...Object.entries(n), ...t.entries()]) : i = t;
343
- for (const a of r.crit) {
344
- if (!i.has(a))
345
- throw new I(`Extension Header Parameter "${a}" is not recognized`);
346
- if (o[a] === void 0)
347
- throw new e(`Extension Header Parameter "${a}" is missing`);
348
- if (i.get(a) && r[a] === void 0)
349
- throw new e(`Extension Header Parameter "${a}" MUST be integrity protected`);
366
+ for (const o of r.crit) {
367
+ if (!i.has(o))
368
+ throw new C(`Extension Header Parameter "${o}" is not recognized`);
369
+ if (a[o] === void 0)
370
+ throw new e(`Extension Header Parameter "${o}" is missing`);
371
+ if (i.get(o) && r[o] === void 0)
372
+ throw new e(`Extension Header Parameter "${o}" MUST be integrity protected`);
350
373
  }
351
374
  return new Set(r.crit);
352
375
  }
353
- const ce = (e, t) => {
376
+ const me = (e, t) => {
354
377
  if (t !== void 0 && (!Array.isArray(t) || t.some((n) => typeof n != "string")))
355
378
  throw new TypeError(`"${e}" option must be an array of strings`);
356
379
  if (t)
357
380
  return new Set(t);
358
381
  };
359
- function se(e, t) {
382
+ function ye(e, t) {
360
383
  const n = `SHA-${e.slice(-3)}`;
361
384
  switch (e) {
362
385
  case "HS256":
@@ -378,171 +401,171 @@ function se(e, t) {
378
401
  case "EdDSA":
379
402
  return { name: t.name };
380
403
  default:
381
- throw new I(`alg ${e} is not supported either by JOSE or your javascript runtime`);
404
+ throw new C(`alg ${e} is not supported either by JOSE or your javascript runtime`);
382
405
  }
383
406
  }
384
- function de(e, t, n) {
385
- if (D(t))
386
- return Q(t, e, n), t;
407
+ function Se(e, t, n) {
408
+ if (V(t))
409
+ return ae(t, e, n), t;
387
410
  if (t instanceof Uint8Array) {
388
411
  if (!e.startsWith("HS"))
389
- throw new TypeError(J(t, ...S));
390
- return P.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [n]);
412
+ throw new TypeError(N(t, ...w));
413
+ return O.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [n]);
391
414
  }
392
- throw new TypeError(J(t, ...S, "Uint8Array"));
415
+ throw new TypeError(N(t, ...w, "Uint8Array"));
393
416
  }
394
- const ue = async (e, t, n, r) => {
395
- const o = await de(e, t, "verify");
396
- Z(e, o);
397
- const i = se(e, o.algorithm);
417
+ const we = async (e, t, n, r) => {
418
+ const a = await Se(e, t, "verify");
419
+ ce(e, a);
420
+ const i = ye(e, a.algorithm);
398
421
  try {
399
- return await P.subtle.verify(i, o, n, r);
422
+ return await O.subtle.verify(i, a, n, r);
400
423
  } catch {
401
424
  return !1;
402
425
  }
403
426
  };
404
- async function fe(e, t, n) {
405
- if (!R(e))
406
- throw new d("Flattened JWS must be an object");
427
+ async function Ee(e, t, n) {
428
+ if (!x(e))
429
+ throw new u("Flattened JWS must be an object");
407
430
  if (e.protected === void 0 && e.header === void 0)
408
- throw new d('Flattened JWS must have either of the "protected" or "header" members');
431
+ throw new u('Flattened JWS must have either of the "protected" or "header" members');
409
432
  if (e.protected !== void 0 && typeof e.protected != "string")
410
- throw new d("JWS Protected Header incorrect type");
433
+ throw new u("JWS Protected Header incorrect type");
411
434
  if (e.payload === void 0)
412
- throw new d("JWS Payload missing");
435
+ throw new u("JWS Payload missing");
413
436
  if (typeof e.signature != "string")
414
- throw new d("JWS Signature missing or incorrect type");
415
- if (e.header !== void 0 && !R(e.header))
416
- throw new d("JWS Unprotected Header incorrect type");
437
+ throw new u("JWS Signature missing or incorrect type");
438
+ if (e.header !== void 0 && !x(e.header))
439
+ throw new u("JWS Unprotected Header incorrect type");
417
440
  let r = {};
418
441
  if (e.protected)
419
442
  try {
420
- const _ = C(e.protected);
421
- r = JSON.parse(g.decode(_));
443
+ const T = R(e.protected);
444
+ r = JSON.parse(_.decode(T));
422
445
  } catch {
423
- throw new d("JWS Protected Header is invalid");
446
+ throw new u("JWS Protected Header is invalid");
424
447
  }
425
- if (!X(r, e.header))
426
- throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
427
- const o = {
448
+ if (!oe(r, e.header))
449
+ throw new u("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
450
+ const a = {
428
451
  ...r,
429
452
  ...e.header
430
- }, i = ie(d, /* @__PURE__ */ new Map([["b64", !0]]), n == null ? void 0 : n.crit, r, o);
431
- let a = !0;
432
- if (i.has("b64") && (a = r.b64, typeof a != "boolean"))
433
- throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
434
- const { alg: c } = o;
453
+ }, i = pe(u, /* @__PURE__ */ new Map([["b64", !0]]), n == null ? void 0 : n.crit, r, a);
454
+ let o = !0;
455
+ if (i.has("b64") && (o = r.b64, typeof o != "boolean"))
456
+ throw new u('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
457
+ const { alg: c } = a;
435
458
  if (typeof c != "string" || !c)
436
- throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
437
- const s = n && ce("algorithms", n.algorithms);
459
+ throw new u('JWS "alg" (Algorithm) Header Parameter missing or invalid');
460
+ const s = n && me("algorithms", n.algorithms);
438
461
  if (s && !s.has(c))
439
- throw new G('"alg" (Algorithm) Header Parameter value not allowed');
440
- if (a) {
462
+ throw new ee('"alg" (Algorithm) Header Parameter value not allowed');
463
+ if (o) {
441
464
  if (typeof e.payload != "string")
442
- throw new d("JWS Payload must be a string");
465
+ throw new u("JWS Payload must be a string");
443
466
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
444
- throw new d("JWS Payload must be a string or an Uint8Array instance");
445
- let l = !1;
446
- typeof t == "function" && (t = await t(r, e), l = !0), ae(c, t, "verify");
447
- const E = V(A.encode(e.protected ?? ""), A.encode("."), typeof e.payload == "string" ? A.encode(e.payload) : e.payload);
467
+ throw new u("JWS Payload must be a string or an Uint8Array instance");
468
+ let p = !1;
469
+ typeof t == "function" && (t = await t(r, e), p = !0), he(c, t, "verify");
470
+ const E = j(g.encode(e.protected ?? ""), g.encode("."), typeof e.payload == "string" ? g.encode(e.payload) : e.payload);
448
471
  let f;
449
472
  try {
450
- f = C(e.signature);
473
+ f = R(e.signature);
451
474
  } catch {
452
- throw new d("Failed to base64url decode the signature");
475
+ throw new u("Failed to base64url decode the signature");
453
476
  }
454
- if (!await ue(c, t, f, E))
455
- throw new q();
456
- let m;
457
- if (a)
477
+ if (!await we(c, t, f, E))
478
+ throw new te();
479
+ let y;
480
+ if (o)
458
481
  try {
459
- m = C(e.payload);
482
+ y = R(e.payload);
460
483
  } catch {
461
- throw new d("Failed to base64url decode the payload");
484
+ throw new u("Failed to base64url decode the payload");
462
485
  }
463
486
  else
464
- typeof e.payload == "string" ? m = A.encode(e.payload) : m = e.payload;
465
- const u = { payload: m };
466
- return e.protected !== void 0 && (u.protectedHeader = r), e.header !== void 0 && (u.unprotectedHeader = e.header), l ? { ...u, key: t } : u;
467
- }
468
- async function he(e, t, n) {
469
- if (e instanceof Uint8Array && (e = g.decode(e)), typeof e != "string")
470
- throw new d("Compact JWS must be a string or Uint8Array");
471
- const { 0: r, 1: o, 2: i, length: a } = e.split(".");
472
- if (a !== 3)
473
- throw new d("Invalid Compact JWS");
474
- const c = await fe({ payload: o, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
487
+ typeof e.payload == "string" ? y = g.encode(e.payload) : y = e.payload;
488
+ const l = { payload: y };
489
+ return e.protected !== void 0 && (l.protectedHeader = r), e.header !== void 0 && (l.unprotectedHeader = e.header), p ? { ...l, key: t } : l;
490
+ }
491
+ async function be(e, t, n) {
492
+ if (e instanceof Uint8Array && (e = _.decode(e)), typeof e != "string")
493
+ throw new u("Compact JWS must be a string or Uint8Array");
494
+ const { 0: r, 1: a, 2: i, length: o } = e.split(".");
495
+ if (o !== 3)
496
+ throw new u("Invalid Compact JWS");
497
+ const c = await Ee({ payload: a, protected: r, signature: i }, t, n), s = { payload: c.payload, protectedHeader: c.protectedHeader };
475
498
  return typeof t == "function" ? { ...s, key: c.key } : s;
476
499
  }
477
- const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24, pe = v * 7, me = v * 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, W = (e) => {
478
- const t = ye.exec(e);
500
+ const ge = (e) => Math.floor(e.getTime() / 1e3), q = 60, z = q * 60, J = z * 24, Ae = J * 7, Ie = J * 365.25, _e = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, H = (e) => {
501
+ const t = _e.exec(e);
479
502
  if (!t || t[4] && t[1])
480
503
  throw new TypeError("Invalid time period format");
481
504
  const n = parseFloat(t[2]), r = t[3].toLowerCase();
482
- let o;
505
+ let a;
483
506
  switch (r) {
484
507
  case "sec":
485
508
  case "secs":
486
509
  case "second":
487
510
  case "seconds":
488
511
  case "s":
489
- o = Math.round(n);
512
+ a = Math.round(n);
490
513
  break;
491
514
  case "minute":
492
515
  case "minutes":
493
516
  case "min":
494
517
  case "mins":
495
518
  case "m":
496
- o = Math.round(n * M);
519
+ a = Math.round(n * q);
497
520
  break;
498
521
  case "hour":
499
522
  case "hours":
500
523
  case "hr":
501
524
  case "hrs":
502
525
  case "h":
503
- o = Math.round(n * B);
526
+ a = Math.round(n * z);
504
527
  break;
505
528
  case "day":
506
529
  case "days":
507
530
  case "d":
508
- o = Math.round(n * v);
531
+ a = Math.round(n * J);
509
532
  break;
510
533
  case "week":
511
534
  case "weeks":
512
535
  case "w":
513
- o = Math.round(n * pe);
536
+ a = Math.round(n * Ae);
514
537
  break;
515
538
  default:
516
- o = Math.round(n * me);
539
+ a = Math.round(n * Ie);
517
540
  break;
518
541
  }
519
- return t[1] === "-" || t[4] === "ago" ? -o : o;
520
- }, N = (e) => e.toLowerCase().replace(/^application\//, ""), Se = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Ee = (e, t, n = {}) => {
542
+ return t[1] === "-" || t[4] === "ago" ? -a : a;
543
+ }, $ = (e) => e.toLowerCase().replace(/^application\//, ""), Ce = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1, Te = (e, t, n = {}) => {
521
544
  let r;
522
545
  try {
523
- r = JSON.parse(g.decode(t));
546
+ r = JSON.parse(_.decode(t));
524
547
  } catch {
525
548
  }
526
- if (!R(r))
527
- throw new k("JWT Claims Set must be a top-level JSON object");
528
- const { typ: o } = n;
529
- if (o && (typeof e.typ != "string" || N(e.typ) !== N(o)))
549
+ if (!x(r))
550
+ throw new B("JWT Claims Set must be a top-level JSON object");
551
+ const { typ: a } = n;
552
+ if (a && (typeof e.typ != "string" || $(e.typ) !== $(a)))
530
553
  throw new h('unexpected "typ" JWT header value', r, "typ", "check_failed");
531
- const { requiredClaims: i = [], issuer: a, subject: c, audience: s, maxTokenAge: l } = n, E = [...i];
532
- l !== void 0 && E.push("iat"), s !== void 0 && E.push("aud"), c !== void 0 && E.push("sub"), a !== void 0 && E.push("iss");
533
- for (const u of new Set(E.reverse()))
534
- if (!(u in r))
535
- throw new h(`missing required "${u}" claim`, r, u, "missing");
536
- if (a && !(Array.isArray(a) ? a : [a]).includes(r.iss))
554
+ const { requiredClaims: i = [], issuer: o, subject: c, audience: s, maxTokenAge: p } = n, E = [...i];
555
+ p !== void 0 && E.push("iat"), s !== void 0 && E.push("aud"), c !== void 0 && E.push("sub"), o !== void 0 && E.push("iss");
556
+ for (const l of new Set(E.reverse()))
557
+ if (!(l in r))
558
+ throw new h(`missing required "${l}" claim`, r, l, "missing");
559
+ if (o && !(Array.isArray(o) ? o : [o]).includes(r.iss))
537
560
  throw new h('unexpected "iss" claim value', r, "iss", "check_failed");
538
561
  if (c && r.sub !== c)
539
562
  throw new h('unexpected "sub" claim value', r, "sub", "check_failed");
540
- if (s && !Se(r.aud, typeof s == "string" ? [s] : s))
563
+ if (s && !Ce(r.aud, typeof s == "string" ? [s] : s))
541
564
  throw new h('unexpected "aud" claim value', r, "aud", "check_failed");
542
565
  let f;
543
566
  switch (typeof n.clockTolerance) {
544
567
  case "string":
545
- f = W(n.clockTolerance);
568
+ f = H(n.clockTolerance);
546
569
  break;
547
570
  case "number":
548
571
  f = n.clockTolerance;
@@ -553,76 +576,103 @@ const le = (e) => Math.floor(e.getTime() / 1e3), M = 60, B = M * 60, v = B * 24,
553
576
  default:
554
577
  throw new TypeError("Invalid clockTolerance option type");
555
578
  }
556
- const { currentDate: x } = n, m = le(x || /* @__PURE__ */ new Date());
557
- if ((r.iat !== void 0 || l) && typeof r.iat != "number")
579
+ const { currentDate: K } = n, y = ge(K || /* @__PURE__ */ new Date());
580
+ if ((r.iat !== void 0 || p) && typeof r.iat != "number")
558
581
  throw new h('"iat" claim must be a number', r, "iat", "invalid");
559
582
  if (r.nbf !== void 0) {
560
583
  if (typeof r.nbf != "number")
561
584
  throw new h('"nbf" claim must be a number', r, "nbf", "invalid");
562
- if (r.nbf > m + f)
585
+ if (r.nbf > y + f)
563
586
  throw new h('"nbf" claim timestamp check failed', r, "nbf", "check_failed");
564
587
  }
565
588
  if (r.exp !== void 0) {
566
589
  if (typeof r.exp != "number")
567
590
  throw new h('"exp" claim must be a number', r, "exp", "invalid");
568
- if (r.exp <= m - f)
569
- throw new O('"exp" claim timestamp check failed', r, "exp", "check_failed");
570
- }
571
- if (l) {
572
- const u = m - r.iat, _ = typeof l == "number" ? l : W(l);
573
- if (u - f > _)
574
- throw new O('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
575
- if (u < 0 - f)
591
+ if (r.exp <= y - f)
592
+ throw new D('"exp" claim timestamp check failed', r, "exp", "check_failed");
593
+ }
594
+ if (p) {
595
+ const l = y - r.iat, T = typeof p == "number" ? p : H(p);
596
+ if (l - f > T)
597
+ throw new D('"iat" claim timestamp check failed (too far in the past)', r, "iat", "check_failed");
598
+ if (l < 0 - f)
576
599
  throw new h('"iat" claim timestamp check failed (it should be in the past)', r, "iat", "check_failed");
577
600
  }
578
601
  return r;
579
602
  };
580
- async function we(e, t, n) {
581
- var a;
582
- const r = await he(e, t, n);
583
- if ((a = r.protectedHeader.crit) != null && a.includes("b64") && r.protectedHeader.b64 === !1)
584
- throw new k("JWTs MUST NOT use unencoded payload");
585
- const i = { payload: Ee(r.protectedHeader, r.payload, n), protectedHeader: r.protectedHeader };
603
+ async function Re(e, t, n) {
604
+ var o;
605
+ const r = await be(e, t, n);
606
+ if ((o = r.protectedHeader.crit) != null && o.includes("b64") && r.protectedHeader.b64 === !1)
607
+ throw new B("JWTs MUST NOT use unencoded payload");
608
+ const i = { payload: Te(r.protectedHeader, r.payload, n), protectedHeader: r.protectedHeader };
586
609
  return typeof t == "function" ? { ...i, key: r.key } : i;
587
610
  }
588
- const be = {
589
- ID_TOKEN: "id_token",
590
- ACCESS_TOKEN: "token",
591
- ID_AND_ACCESS_TOKEN: "id_token token"
592
- }, ge = {
593
- CLIENT_ID: "X-Auth-ClientId"
594
- }, H = {
595
- ALG: "RS256",
596
- USER_ID_KEY: "_id",
597
- TOKEN_ID_KEY: "__raw",
598
- ISSUER: "gizmette.com"
599
- }, Ae = `-----BEGIN PUBLIC KEY-----
600
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
601
- w5PKyTYLGAI2I6SIIdpe6i6DOCbEkmDz7LdVsBqwNtVi8gvWYIj+8ol6rU3qu1v5
602
- i1Jd45GSK4kzkVdgCmQZbM5ak0KI99q5wsrAIzUd+LRJ2HRvWtr5IYdsIiXaQjle
603
- aMwPFOIcJH+rKfFgNcHLcaS5syp7zU1ANwZ+trgR+DifBr8TLVkBynmNeTyhDm2+
604
- l0haqjMk0UoNPPE8iYBWUHQJJE1Dqstj65d6Eh5g64Pao25y4cmYJbKjiblIGEkE
605
- sjqybA9mARAqh9k/eiIopecWSiffNQTwVQVd2I9ZH3BalhEXHlqFgrjz51kFqg81
606
- awIDAQAB
607
- -----END PUBLIC KEY-----`, Ie = {
608
- ACCESS: "5m",
609
- ID: "90d"
610
- }, _e = async (e, t) => {
611
+ const We = async (e) => {
611
612
  try {
612
- const n = H.ALG, o = await re(Ae, n);
613
- return await we(e, o, {
614
- issuer: H.ISSUER,
615
- audience: t
613
+ const t = U.ALG, r = await ue(X, t);
614
+ return await Re(e, r, {
615
+ issuer: U.ISSUER
616
616
  });
617
617
  } catch {
618
618
  return;
619
619
  }
620
620
  };
621
+ var d = [];
622
+ for (var P = 0; P < 256; ++P)
623
+ d.push((P + 256).toString(16).slice(1));
624
+ function ve(e, t = 0) {
625
+ 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();
626
+ }
627
+ var I, Pe = new Uint8Array(16);
628
+ function xe() {
629
+ if (!I && (I = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !I))
630
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
631
+ return I(Pe);
632
+ }
633
+ var Oe = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
634
+ const L = {
635
+ randomUUID: Oe
636
+ };
637
+ function k(e, t, n) {
638
+ if (L.randomUUID && !t && !e)
639
+ return L.randomUUID();
640
+ e = e || {};
641
+ var r = e.random || (e.rng || xe)();
642
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, ve(r);
643
+ }
644
+ const M = globalThis.crypto, Je = (e) => `${k()}${k()}`.slice(0, e), Ke = (e) => btoa(
645
+ [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
646
+ );
647
+ async function Q(e) {
648
+ if (!M.subtle)
649
+ throw new Error(
650
+ "crypto.subtle is available only in secure contexts (HTTPS)."
651
+ );
652
+ const t = new TextEncoder().encode(e), n = await M.subtle.digest("SHA-256", t);
653
+ return Ke(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
654
+ }
655
+ async function He(e) {
656
+ const t = e || 43;
657
+ if (t < 43 || t > 128)
658
+ throw `Expected a length between 43 and 128. Received ${e}.`;
659
+ const n = Je(t), r = await Q(n);
660
+ return {
661
+ code_verifier: n,
662
+ code_challenge: r
663
+ };
664
+ }
665
+ async function $e(e, t) {
666
+ return await Q(e) === t;
667
+ }
621
668
  export {
622
- be as AUTH_TYPES,
623
- ge as HEADERS,
624
- H as JWT,
625
- Ae as JWT_PUBLIC_KEY,
626
- Ie as TOKEN_EXPIRATION,
627
- _e as verifyAndExtractToken
669
+ Ue as AUTH_TYPES,
670
+ De as HEADERS,
671
+ U as JWT,
672
+ X as JWT_PUBLIC_KEY,
673
+ Ne as TOKEN_EXPIRATION,
674
+ Q as generateCodeChallenge,
675
+ He as pkceChallengePair,
676
+ We as verifyAndExtractToken,
677
+ $e as verifyChallenge
628
678
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-common",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -27,10 +27,13 @@
27
27
  "dev:types": "tsup --watch src",
28
28
  "dev": "npm-run-all clean --parallel dev:js dev:types",
29
29
  "lint": "biome lint src",
30
- "start": "static-server dist --port 5173"
30
+ "start": "static-server dist --port 5173",
31
+ "test:watch": "vitest",
32
+ "test": "vitest run"
31
33
  },
32
34
  "dependencies": {
33
- "jose": "5.4.1"
35
+ "jose": "5.4.1",
36
+ "uuid": "10.0.0"
34
37
  },
35
- "gitHead": "25c60a5226b6f9d95aa3a3fcdbbc8448181e937a"
38
+ "gitHead": "248f81efc43fef54c0c1ba2df2e7c6417081732d"
36
39
  }