@genation/sdk 0.2.10 → 0.2.11

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.
@@ -1,67 +1,67 @@
1
1
  class N extends Error {
2
2
  code;
3
3
  cause;
4
- constructor(e, r, n) {
5
- super(e), this.name = "GenationError", this.code = r, this.cause = n;
4
+ constructor(t, r, n) {
5
+ super(t), this.name = "GenationError", this.code = r, this.cause = n;
6
6
  }
7
7
  }
8
8
  class g extends N {
9
- constructor(e, r, n) {
10
- super(e, r, n), this.name = "AuthError";
9
+ constructor(t, r, n) {
10
+ super(t, r, n), this.name = "AuthError";
11
11
  }
12
- static invalidGrant(e = "Invalid authorization code or refresh token") {
13
- return new g(e, "invalid_grant");
12
+ static invalidGrant(t = "Invalid authorization code or refresh token") {
13
+ return new g(t, "invalid_grant");
14
14
  }
15
- static accessDenied(e = "User denied access") {
16
- return new g(e, "access_denied");
15
+ static accessDenied(t = "User denied access") {
16
+ return new g(t, "access_denied");
17
17
  }
18
- static expiredToken(e = "Token has expired") {
19
- return new g(e, "expired_token");
18
+ static expiredToken(t = "Token has expired") {
19
+ return new g(t, "expired_token");
20
20
  }
21
- static invalidState(e = "State mismatch, possible CSRF attack") {
22
- return new g(e, "invalid_state");
21
+ static invalidState(t = "State mismatch, possible CSRF attack") {
22
+ return new g(t, "invalid_state");
23
23
  }
24
- static pkceVerificationFailed(e = "PKCE verification failed") {
25
- return new g(e, "pkce_verification_failed");
24
+ static pkceVerificationFailed(t = "PKCE verification failed") {
25
+ return new g(t, "pkce_verification_failed");
26
26
  }
27
27
  }
28
28
  class S extends N {
29
29
  status;
30
- constructor(e, r, n) {
31
- super(e, "network_error", n), this.name = "NetworkError", this.status = r;
30
+ constructor(t, r, n) {
31
+ super(t, "network_error", n), this.name = "NetworkError", this.status = r;
32
32
  }
33
- static fromResponse(e) {
33
+ static fromResponse(t) {
34
34
  return new S(
35
- `HTTP ${e.status}: ${e.statusText}`,
36
- e.status
35
+ `HTTP ${t.status}: ${t.statusText}`,
36
+ t.status
37
37
  );
38
38
  }
39
39
  }
40
40
  class v extends N {
41
- constructor(e) {
42
- super(e, "config_error"), this.name = "ConfigError";
41
+ constructor(t) {
42
+ super(t, "config_error"), this.name = "ConfigError";
43
43
  }
44
- static missingField(e) {
45
- return new v(`Missing required config field: ${e}`);
44
+ static missingField(t) {
45
+ return new v(`Missing required config field: ${t}`);
46
46
  }
47
47
  }
48
48
  class D {
49
49
  baseUrl;
50
50
  timeout;
51
- constructor(e) {
52
- this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.timeout = e.timeout ?? 3e4;
51
+ constructor(t) {
52
+ this.baseUrl = t.baseUrl.replace(/\/$/, ""), this.timeout = t.timeout ?? 3e4;
53
53
  }
54
54
  /**
55
55
  * Make an HTTP request
56
56
  */
57
- async request(e, r = {}) {
57
+ async request(t, r = {}) {
58
58
  const { method: n = "GET", headers: s = {}, body: a, params: i } = r;
59
- let c = `${this.baseUrl}${e}`;
59
+ let c = `${this.baseUrl}${t}`;
60
60
  if (i) {
61
61
  const o = new URLSearchParams(i);
62
62
  c += `?${o.toString()}`;
63
63
  }
64
- const u = new AbortController(), h = setTimeout(() => u.abort(), this.timeout);
64
+ const h = new AbortController(), u = setTimeout(() => h.abort(), this.timeout);
65
65
  try {
66
66
  const o = await fetch(c, {
67
67
  method: n,
@@ -70,20 +70,20 @@ class D {
70
70
  ...s
71
71
  },
72
72
  body: a ? JSON.stringify(a) : void 0,
73
- signal: u.signal
73
+ signal: h.signal
74
74
  });
75
- if (clearTimeout(h), !o.ok)
75
+ if (clearTimeout(u), !o.ok)
76
76
  throw S.fromResponse(o);
77
77
  return await o.json();
78
78
  } catch (o) {
79
- throw clearTimeout(h), o instanceof S ? o : o instanceof Error && o.name === "AbortError" ? new S("Request timeout", void 0, o) : new S("Network request failed", void 0, o);
79
+ throw clearTimeout(u), o instanceof S ? o : o instanceof Error && o.name === "AbortError" ? new S("Request timeout", void 0, o) : new S("Network request failed", void 0, o);
80
80
  }
81
81
  }
82
82
  /**
83
83
  * POST request with form data (for OAuth token exchange)
84
84
  */
85
- async postForm(e, r, n = {}) {
86
- const s = `${this.baseUrl}${e}`, a = new AbortController(), i = setTimeout(() => a.abort(), this.timeout);
85
+ async postForm(t, r, n = {}) {
86
+ const s = `${this.baseUrl}${t}`, a = new AbortController(), i = setTimeout(() => a.abort(), this.timeout);
87
87
  try {
88
88
  const c = await fetch(s, {
89
89
  method: "POST",
@@ -102,49 +102,49 @@ class D {
102
102
  }
103
103
  }
104
104
  }
105
- function $(t) {
106
- return btoa(String.fromCharCode(...t)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
105
+ function $(e) {
106
+ return btoa(String.fromCharCode(...e)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
107
107
  }
108
- function he() {
109
- const t = new Uint8Array(32);
110
- return crypto.getRandomValues(t), $(t);
108
+ function fe() {
109
+ const e = new Uint8Array(32);
110
+ return crypto.getRandomValues(e), $(e);
111
111
  }
112
- async function ue(t) {
113
- const r = new TextEncoder().encode(t), n = await crypto.subtle.digest("SHA-256", r);
112
+ async function de(e) {
113
+ const r = new TextEncoder().encode(e), n = await crypto.subtle.digest("SHA-256", r);
114
114
  return $(new Uint8Array(n));
115
115
  }
116
- async function fe() {
117
- const t = he(), e = await ue(t);
116
+ async function le() {
117
+ const e = fe(), t = await de(e);
118
118
  return {
119
- codeVerifier: t,
120
- codeChallenge: e,
119
+ codeVerifier: e,
120
+ codeChallenge: t,
121
121
  codeChallengeMethod: "S256"
122
122
  };
123
123
  }
124
- function de() {
125
- const t = new Uint8Array(16);
126
- return crypto.getRandomValues(t), $(t);
124
+ function pe() {
125
+ const e = new Uint8Array(16);
126
+ return crypto.getRandomValues(e), $(e);
127
127
  }
128
128
  const W = "tokens", k = "pkce", I = "state";
129
- class le {
129
+ class ye {
130
130
  storage;
131
- constructor(e) {
132
- this.storage = e;
131
+ constructor(t) {
132
+ this.storage = t;
133
133
  }
134
134
  /**
135
135
  * Store token set
136
136
  */
137
- async setTokens(e) {
138
- await this.storage.set(W, JSON.stringify(e));
137
+ async setTokens(t) {
138
+ await this.storage.set(W, JSON.stringify(t));
139
139
  }
140
140
  /**
141
141
  * Get stored tokens
142
142
  */
143
143
  async getTokens() {
144
- const e = await this.storage.get(W);
145
- if (!e) return null;
144
+ const t = await this.storage.get(W);
145
+ if (!t) return null;
146
146
  try {
147
- return JSON.parse(e);
147
+ return JSON.parse(t);
148
148
  } catch {
149
149
  return null;
150
150
  }
@@ -159,36 +159,36 @@ class le {
159
159
  * Check if access token is expired
160
160
  */
161
161
  async isTokenExpired() {
162
- const e = await this.getTokens();
163
- if (!e) return !0;
164
- const r = e.issuedAt + e.expiresIn * 1e3;
162
+ const t = await this.getTokens();
163
+ if (!t) return !0;
164
+ const r = t.issuedAt + t.expiresIn * 1e3;
165
165
  return Date.now() > r - 6e4;
166
166
  }
167
167
  /**
168
168
  * Store PKCE verifier for later validation
169
169
  */
170
- async setPKCE(e) {
171
- await this.storage.set(k, e);
170
+ async setPKCE(t) {
171
+ await this.storage.set(k, t);
172
172
  }
173
173
  /**
174
174
  * Get and clear stored PKCE verifier
175
175
  */
176
176
  async consumePKCE() {
177
- const e = await this.storage.get(k);
178
- return e && await this.storage.remove(k), e;
177
+ const t = await this.storage.get(k);
178
+ return t && await this.storage.remove(k), t;
179
179
  }
180
180
  /**
181
181
  * Store state for CSRF validation
182
182
  */
183
- async setState(e) {
184
- await this.storage.set(I, e);
183
+ async setState(t) {
184
+ await this.storage.set(I, t);
185
185
  }
186
186
  /**
187
187
  * Get and clear stored state
188
188
  */
189
189
  async consumeState() {
190
- const e = await this.storage.get(I);
191
- return e && await this.storage.remove(I), e;
190
+ const t = await this.storage.get(I);
191
+ return t && await this.storage.remove(I), t;
192
192
  }
193
193
  /**
194
194
  * Clear all auth-related data
@@ -197,18 +197,18 @@ class le {
197
197
  await this.storage.clear();
198
198
  }
199
199
  }
200
- const pe = "https://mnnoheowoowbtpuoguul.supabase.co/auth/v1";
201
- class ye {
200
+ const ee = "https://mnnoheowoowbtpuoguul.supabase.co/auth/v1";
201
+ class me {
202
202
  config;
203
203
  http;
204
204
  tokenManager;
205
- constructor(e, r) {
205
+ constructor(t, r) {
206
206
  this.config = {
207
- clientId: e.clientId,
208
- clientSecret: e.clientSecret,
209
- redirectUri: e.redirectUri,
210
- scopes: e.scopes,
211
- authUrl: e.authUrl ?? pe
207
+ clientId: t.clientId,
208
+ clientSecret: t.clientSecret,
209
+ redirectUri: t.redirectUri,
210
+ scopes: t.scopes,
211
+ authUrl: t.authUrl ?? ee
212
212
  }, this.http = new D({ baseUrl: this.config.authUrl }), this.tokenManager = r;
213
213
  }
214
214
  /**
@@ -216,22 +216,22 @@ class ye {
216
216
  * Stores PKCE verifier and state for later validation
217
217
  */
218
218
  async getAuthorizationUrl() {
219
- const e = await fe(), r = de();
220
- await this.tokenManager.setPKCE(e.codeVerifier), await this.tokenManager.setState(r);
219
+ const t = await le(), r = pe();
220
+ await this.tokenManager.setPKCE(t.codeVerifier), await this.tokenManager.setState(r);
221
221
  const n = new URLSearchParams({
222
222
  response_type: "code",
223
223
  client_id: this.config.clientId,
224
224
  redirect_uri: this.config.redirectUri,
225
225
  state: r,
226
- code_challenge: e.codeChallenge,
227
- code_challenge_method: e.codeChallengeMethod
226
+ code_challenge: t.codeChallenge,
227
+ code_challenge_method: t.codeChallengeMethod
228
228
  });
229
229
  return this.config.scopes && this.config.scopes.length > 0 && n.append("scope", this.config.scopes.join(" ")), `${this.config.authUrl}/oauth/authorize?${n.toString()}`;
230
230
  }
231
231
  /**
232
232
  * Exchange authorization code for tokens
233
233
  */
234
- async exchangeCode(e, r) {
234
+ async exchangeCode(t, r) {
235
235
  const n = await this.tokenManager.consumeState();
236
236
  if (!n || n !== r)
237
237
  throw g.invalidState();
@@ -242,7 +242,7 @@ class ye {
242
242
  "/oauth/token",
243
243
  {
244
244
  grant_type: "authorization_code",
245
- code: e,
245
+ code: t,
246
246
  redirect_uri: this.config.redirectUri,
247
247
  client_id: this.config.clientId,
248
248
  client_secret: this.config.clientSecret,
@@ -255,14 +255,14 @@ class ye {
255
255
  * Refresh access token using refresh token
256
256
  */
257
257
  async refreshToken() {
258
- const e = await this.tokenManager.getTokens();
259
- if (!e?.refreshToken)
258
+ const t = await this.tokenManager.getTokens();
259
+ if (!t?.refreshToken)
260
260
  throw g.invalidGrant("No refresh token available");
261
261
  const r = await this.http.postForm(
262
262
  "/oauth/token",
263
263
  {
264
264
  grant_type: "refresh_token",
265
- refresh_token: e.refreshToken,
265
+ refresh_token: t.refreshToken,
266
266
  client_id: this.config.clientId,
267
267
  client_secret: this.config.clientSecret
268
268
  }
@@ -273,11 +273,11 @@ class ye {
273
273
  * Revoke current tokens
274
274
  */
275
275
  async revokeToken() {
276
- const e = await this.tokenManager.getTokens();
277
- if (e)
276
+ const t = await this.tokenManager.getTokens();
277
+ if (t)
278
278
  try {
279
279
  await this.http.postForm("/oauth/revoke", {
280
- token: e.accessToken,
280
+ token: t.accessToken,
281
281
  client_id: this.config.clientId,
282
282
  client_secret: this.config.clientSecret
283
283
  });
@@ -288,52 +288,52 @@ class ye {
288
288
  /**
289
289
  * Map OAuth token response to TokenSet
290
290
  */
291
- mapTokenResponse(e) {
291
+ mapTokenResponse(t) {
292
292
  return {
293
- accessToken: e.access_token,
294
- refreshToken: e.refresh_token,
295
- tokenType: e.token_type,
296
- expiresIn: e.expires_in,
293
+ accessToken: t.access_token,
294
+ refreshToken: t.refresh_token,
295
+ tokenType: t.token_type,
296
+ expiresIn: t.expires_in,
297
297
  issuedAt: Date.now(),
298
- scope: e.scope
298
+ scope: t.scope
299
299
  };
300
300
  }
301
301
  }
302
302
  const G = new TextEncoder(), _ = new TextDecoder();
303
- function me(...t) {
304
- const e = t.reduce((s, { length: a }) => s + a, 0), r = new Uint8Array(e);
303
+ function we(...e) {
304
+ const t = e.reduce((s, { length: a }) => s + a, 0), r = new Uint8Array(t);
305
305
  let n = 0;
306
- for (const s of t)
306
+ for (const s of e)
307
307
  r.set(s, n), n += s.length;
308
308
  return r;
309
309
  }
310
- function J(t) {
311
- const e = new Uint8Array(t.length);
312
- for (let r = 0; r < t.length; r++) {
313
- const n = t.charCodeAt(r);
310
+ function J(e) {
311
+ const t = new Uint8Array(e.length);
312
+ for (let r = 0; r < e.length; r++) {
313
+ const n = e.charCodeAt(r);
314
314
  if (n > 127)
315
315
  throw new TypeError("non-ASCII string encountered in encode()");
316
- e[r] = n;
316
+ t[r] = n;
317
317
  }
318
- return e;
318
+ return t;
319
319
  }
320
- function we(t) {
320
+ function Se(e) {
321
321
  if (Uint8Array.fromBase64)
322
- return Uint8Array.fromBase64(t);
323
- const e = atob(t), r = new Uint8Array(e.length);
324
- for (let n = 0; n < e.length; n++)
325
- r[n] = e.charCodeAt(n);
322
+ return Uint8Array.fromBase64(e);
323
+ const t = atob(e), r = new Uint8Array(t.length);
324
+ for (let n = 0; n < t.length; n++)
325
+ r[n] = t.charCodeAt(n);
326
326
  return r;
327
327
  }
328
- function C(t) {
328
+ function C(e) {
329
329
  if (Uint8Array.fromBase64)
330
- return Uint8Array.fromBase64(typeof t == "string" ? t : _.decode(t), {
330
+ return Uint8Array.fromBase64(typeof e == "string" ? e : _.decode(e), {
331
331
  alphabet: "base64url"
332
332
  });
333
- let e = t;
334
- e instanceof Uint8Array && (e = _.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/");
333
+ let t = e;
334
+ t instanceof Uint8Array && (t = _.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/");
335
335
  try {
336
- return we(e);
336
+ return Se(t);
337
337
  } catch {
338
338
  throw new TypeError("The input to be decoded is not correctly encoded.");
339
339
  }
@@ -341,8 +341,8 @@ function C(t) {
341
341
  class l extends Error {
342
342
  static code = "ERR_JOSE_GENERIC";
343
343
  code = "ERR_JOSE_GENERIC";
344
- constructor(e, r) {
345
- super(e, r), this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
344
+ constructor(t, r) {
345
+ super(t, r), this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
346
346
  }
347
347
  }
348
348
  class y extends l {
@@ -351,8 +351,8 @@ class y extends l {
351
351
  claim;
352
352
  reason;
353
353
  payload;
354
- constructor(e, r, n = "unspecified", s = "unspecified") {
355
- super(e, { cause: { claim: n, reason: s, payload: r } }), this.claim = n, this.reason = s, this.payload = r;
354
+ constructor(t, r, n = "unspecified", s = "unspecified") {
355
+ super(t, { cause: { claim: n, reason: s, payload: r } }), this.claim = n, this.reason = s, this.payload = r;
356
356
  }
357
357
  }
358
358
  class z extends l {
@@ -361,8 +361,8 @@ class z extends l {
361
361
  claim;
362
362
  reason;
363
363
  payload;
364
- constructor(e, r, n = "unspecified", s = "unspecified") {
365
- super(e, { cause: { claim: n, reason: s, payload: r } }), this.claim = n, this.reason = s, this.payload = r;
364
+ constructor(t, r, n = "unspecified", s = "unspecified") {
365
+ super(t, { cause: { claim: n, reason: s, payload: r } }), this.claim = n, this.reason = s, this.payload = r;
366
366
  }
367
367
  }
368
368
  class w extends l {
@@ -373,49 +373,49 @@ class f extends l {
373
373
  static code = "ERR_JWS_INVALID";
374
374
  code = "ERR_JWS_INVALID";
375
375
  }
376
- class j extends l {
376
+ class te extends l {
377
377
  static code = "ERR_JWT_INVALID";
378
378
  code = "ERR_JWT_INVALID";
379
379
  }
380
- class ee extends l {
380
+ class re extends l {
381
381
  static code = "ERR_JWKS_INVALID";
382
382
  code = "ERR_JWKS_INVALID";
383
383
  }
384
- class te extends l {
384
+ class ne extends l {
385
385
  static code = "ERR_JWKS_NO_MATCHING_KEY";
386
386
  code = "ERR_JWKS_NO_MATCHING_KEY";
387
- constructor(e = "no applicable key found in the JSON Web Key Set", r) {
388
- super(e, r);
387
+ constructor(t = "no applicable key found in the JSON Web Key Set", r) {
388
+ super(t, r);
389
389
  }
390
390
  }
391
- class Se extends l {
391
+ class ge extends l {
392
392
  [Symbol.asyncIterator];
393
393
  static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
394
394
  code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
395
- constructor(e = "multiple matching keys found in the JSON Web Key Set", r) {
396
- super(e, r);
395
+ constructor(t = "multiple matching keys found in the JSON Web Key Set", r) {
396
+ super(t, r);
397
397
  }
398
398
  }
399
- class ge extends l {
399
+ class be extends l {
400
400
  static code = "ERR_JWKS_TIMEOUT";
401
401
  code = "ERR_JWKS_TIMEOUT";
402
- constructor(e = "request timed out", r) {
403
- super(e, r);
402
+ constructor(t = "request timed out", r) {
403
+ super(t, r);
404
404
  }
405
405
  }
406
- class be extends l {
406
+ class Ee extends l {
407
407
  static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
408
408
  code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
409
- constructor(e = "signature verification failed", r) {
410
- super(e, r);
409
+ constructor(t = "signature verification failed", r) {
410
+ super(t, r);
411
411
  }
412
412
  }
413
- const m = (t, e = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`), A = (t, e) => t.name === e;
414
- function U(t) {
415
- return parseInt(t.name.slice(4), 10);
413
+ const m = (e, t = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`), A = (e, t) => e.name === t;
414
+ function x(e) {
415
+ return parseInt(e.name.slice(4), 10);
416
416
  }
417
- function Ee(t) {
418
- switch (t) {
417
+ function Ae(e) {
418
+ switch (e) {
419
419
  case "ES256":
420
420
  return "P-256";
421
421
  case "ES384":
@@ -426,92 +426,92 @@ function Ee(t) {
426
426
  throw new Error("unreachable");
427
427
  }
428
428
  }
429
- function Ae(t, e) {
430
- if (!t.usages.includes(e))
431
- throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`);
429
+ function Ke(e, t) {
430
+ if (!e.usages.includes(t))
431
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`);
432
432
  }
433
- function Ke(t, e, r) {
434
- switch (e) {
433
+ function Te(e, t, r) {
434
+ switch (t) {
435
435
  case "HS256":
436
436
  case "HS384":
437
437
  case "HS512": {
438
- if (!A(t.algorithm, "HMAC"))
438
+ if (!A(e.algorithm, "HMAC"))
439
439
  throw m("HMAC");
440
- const n = parseInt(e.slice(2), 10);
441
- if (U(t.algorithm.hash) !== n)
440
+ const n = parseInt(t.slice(2), 10);
441
+ if (x(e.algorithm.hash) !== n)
442
442
  throw m(`SHA-${n}`, "algorithm.hash");
443
443
  break;
444
444
  }
445
445
  case "RS256":
446
446
  case "RS384":
447
447
  case "RS512": {
448
- if (!A(t.algorithm, "RSASSA-PKCS1-v1_5"))
448
+ if (!A(e.algorithm, "RSASSA-PKCS1-v1_5"))
449
449
  throw m("RSASSA-PKCS1-v1_5");
450
- const n = parseInt(e.slice(2), 10);
451
- if (U(t.algorithm.hash) !== n)
450
+ const n = parseInt(t.slice(2), 10);
451
+ if (x(e.algorithm.hash) !== n)
452
452
  throw m(`SHA-${n}`, "algorithm.hash");
453
453
  break;
454
454
  }
455
455
  case "PS256":
456
456
  case "PS384":
457
457
  case "PS512": {
458
- if (!A(t.algorithm, "RSA-PSS"))
458
+ if (!A(e.algorithm, "RSA-PSS"))
459
459
  throw m("RSA-PSS");
460
- const n = parseInt(e.slice(2), 10);
461
- if (U(t.algorithm.hash) !== n)
460
+ const n = parseInt(t.slice(2), 10);
461
+ if (x(e.algorithm.hash) !== n)
462
462
  throw m(`SHA-${n}`, "algorithm.hash");
463
463
  break;
464
464
  }
465
465
  case "Ed25519":
466
466
  case "EdDSA": {
467
- if (!A(t.algorithm, "Ed25519"))
467
+ if (!A(e.algorithm, "Ed25519"))
468
468
  throw m("Ed25519");
469
469
  break;
470
470
  }
471
471
  case "ML-DSA-44":
472
472
  case "ML-DSA-65":
473
473
  case "ML-DSA-87": {
474
- if (!A(t.algorithm, e))
475
- throw m(e);
474
+ if (!A(e.algorithm, t))
475
+ throw m(t);
476
476
  break;
477
477
  }
478
478
  case "ES256":
479
479
  case "ES384":
480
480
  case "ES512": {
481
- if (!A(t.algorithm, "ECDSA"))
481
+ if (!A(e.algorithm, "ECDSA"))
482
482
  throw m("ECDSA");
483
- const n = Ee(e);
484
- if (t.algorithm.namedCurve !== n)
483
+ const n = Ae(t);
484
+ if (e.algorithm.namedCurve !== n)
485
485
  throw m(n, "algorithm.namedCurve");
486
486
  break;
487
487
  }
488
488
  default:
489
489
  throw new TypeError("CryptoKey does not support this operation");
490
490
  }
491
- Ae(t, r);
491
+ Ke(e, r);
492
492
  }
493
- function re(t, e, ...r) {
493
+ function se(e, t, ...r) {
494
494
  if (r = r.filter(Boolean), r.length > 2) {
495
495
  const n = r.pop();
496
- t += `one of type ${r.join(", ")}, or ${n}.`;
497
- } else r.length === 2 ? t += `one of type ${r[0]} or ${r[1]}.` : t += `of type ${r[0]}.`;
498
- return e == null ? t += ` Received ${e}` : typeof e == "function" && e.name ? t += ` Received function ${e.name}` : typeof e == "object" && e != null && e.constructor?.name && (t += ` Received an instance of ${e.constructor.name}`), t;
496
+ e += `one of type ${r.join(", ")}, or ${n}.`;
497
+ } else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
498
+ 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;
499
499
  }
500
- const Te = (t, ...e) => re("Key must be ", t, ...e), ne = (t, e, ...r) => re(`Key for the ${t} algorithm must be `, e, ...r), se = (t) => {
501
- if (t?.[Symbol.toStringTag] === "CryptoKey")
500
+ const ve = (e, ...t) => se("Key must be ", e, ...t), ae = (e, t, ...r) => se(`Key for the ${e} algorithm must be `, t, ...r), ie = (e) => {
501
+ if (e?.[Symbol.toStringTag] === "CryptoKey")
502
502
  return !0;
503
503
  try {
504
- return t instanceof CryptoKey;
504
+ return e instanceof CryptoKey;
505
505
  } catch {
506
506
  return !1;
507
507
  }
508
- }, ae = (t) => t?.[Symbol.toStringTag] === "KeyObject", ie = (t) => se(t) || ae(t);
509
- function ve(...t) {
510
- const e = t.filter(Boolean);
511
- if (e.length === 0 || e.length === 1)
508
+ }, oe = (e) => e?.[Symbol.toStringTag] === "KeyObject", ce = (e) => ie(e) || oe(e);
509
+ function Ce(...e) {
510
+ const t = e.filter(Boolean);
511
+ if (t.length === 0 || t.length === 1)
512
512
  return !0;
513
513
  let r;
514
- for (const n of e) {
514
+ for (const n of t) {
515
515
  const s = Object.keys(n);
516
516
  if (!r || r.size === 0) {
517
517
  r = new Set(s);
@@ -525,33 +525,33 @@ function ve(...t) {
525
525
  }
526
526
  return !0;
527
527
  }
528
- const Ce = (t) => typeof t == "object" && t !== null;
529
- function E(t) {
530
- if (!Ce(t) || Object.prototype.toString.call(t) !== "[object Object]")
528
+ const _e = (e) => typeof e == "object" && e !== null;
529
+ function E(e) {
530
+ if (!_e(e) || Object.prototype.toString.call(e) !== "[object Object]")
531
531
  return !1;
532
- if (Object.getPrototypeOf(t) === null)
532
+ if (Object.getPrototypeOf(e) === null)
533
533
  return !0;
534
- let e = t;
535
- for (; Object.getPrototypeOf(e) !== null; )
536
- e = Object.getPrototypeOf(e);
537
- return Object.getPrototypeOf(t) === e;
538
- }
539
- function _e(t, e) {
540
- if (t.startsWith("RS") || t.startsWith("PS")) {
541
- const { modulusLength: r } = e.algorithm;
534
+ let t = e;
535
+ for (; Object.getPrototypeOf(t) !== null; )
536
+ t = Object.getPrototypeOf(t);
537
+ return Object.getPrototypeOf(e) === t;
538
+ }
539
+ function Re(e, t) {
540
+ if (e.startsWith("RS") || e.startsWith("PS")) {
541
+ const { modulusLength: r } = t.algorithm;
542
542
  if (typeof r != "number" || r < 2048)
543
- throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`);
543
+ throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
544
544
  }
545
545
  }
546
- function Re(t) {
547
- let e, r;
548
- switch (t.kty) {
546
+ function Pe(e) {
547
+ let t, r;
548
+ switch (e.kty) {
549
549
  case "AKP": {
550
- switch (t.alg) {
550
+ switch (e.alg) {
551
551
  case "ML-DSA-44":
552
552
  case "ML-DSA-65":
553
553
  case "ML-DSA-87":
554
- e = { name: t.alg }, r = t.priv ? ["sign"] : ["verify"];
554
+ t = { name: e.alg }, r = e.priv ? ["sign"] : ["verify"];
555
555
  break;
556
556
  default:
557
557
  throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
@@ -559,25 +559,25 @@ function Re(t) {
559
559
  break;
560
560
  }
561
561
  case "RSA": {
562
- switch (t.alg) {
562
+ switch (e.alg) {
563
563
  case "PS256":
564
564
  case "PS384":
565
565
  case "PS512":
566
- e = { name: "RSA-PSS", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
566
+ t = { name: "RSA-PSS", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
567
567
  break;
568
568
  case "RS256":
569
569
  case "RS384":
570
570
  case "RS512":
571
- e = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
571
+ t = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
572
572
  break;
573
573
  case "RSA-OAEP":
574
574
  case "RSA-OAEP-256":
575
575
  case "RSA-OAEP-384":
576
576
  case "RSA-OAEP-512":
577
- e = {
577
+ t = {
578
578
  name: "RSA-OAEP",
579
- hash: `SHA-${parseInt(t.alg.slice(-3), 10) || 1}`
580
- }, r = t.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
579
+ hash: `SHA-${parseInt(e.alg.slice(-3), 10) || 1}`
580
+ }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
581
581
  break;
582
582
  default:
583
583
  throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
@@ -585,21 +585,21 @@ function Re(t) {
585
585
  break;
586
586
  }
587
587
  case "EC": {
588
- switch (t.alg) {
588
+ switch (e.alg) {
589
589
  case "ES256":
590
- e = { name: "ECDSA", namedCurve: "P-256" }, r = t.d ? ["sign"] : ["verify"];
590
+ t = { name: "ECDSA", namedCurve: "P-256" }, r = e.d ? ["sign"] : ["verify"];
591
591
  break;
592
592
  case "ES384":
593
- e = { name: "ECDSA", namedCurve: "P-384" }, r = t.d ? ["sign"] : ["verify"];
593
+ t = { name: "ECDSA", namedCurve: "P-384" }, r = e.d ? ["sign"] : ["verify"];
594
594
  break;
595
595
  case "ES512":
596
- e = { name: "ECDSA", namedCurve: "P-521" }, r = t.d ? ["sign"] : ["verify"];
596
+ t = { name: "ECDSA", namedCurve: "P-521" }, r = e.d ? ["sign"] : ["verify"];
597
597
  break;
598
598
  case "ECDH-ES":
599
599
  case "ECDH-ES+A128KW":
600
600
  case "ECDH-ES+A192KW":
601
601
  case "ECDH-ES+A256KW":
602
- e = { name: "ECDH", namedCurve: t.crv }, r = t.d ? ["deriveBits"] : [];
602
+ t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
603
603
  break;
604
604
  default:
605
605
  throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
@@ -607,16 +607,16 @@ function Re(t) {
607
607
  break;
608
608
  }
609
609
  case "OKP": {
610
- switch (t.alg) {
610
+ switch (e.alg) {
611
611
  case "Ed25519":
612
612
  case "EdDSA":
613
- e = { name: "Ed25519" }, r = t.d ? ["sign"] : ["verify"];
613
+ t = { name: "Ed25519" }, r = e.d ? ["sign"] : ["verify"];
614
614
  break;
615
615
  case "ECDH-ES":
616
616
  case "ECDH-ES+A128KW":
617
617
  case "ECDH-ES+A192KW":
618
618
  case "ECDH-ES+A256KW":
619
- e = { name: t.crv }, r = t.d ? ["deriveBits"] : [];
619
+ t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
620
620
  break;
621
621
  default:
622
622
  throw new w('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
@@ -626,78 +626,78 @@ function Re(t) {
626
626
  default:
627
627
  throw new w('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
628
628
  }
629
- return { algorithm: e, keyUsages: r };
629
+ return { algorithm: t, keyUsages: r };
630
630
  }
631
- async function R(t) {
632
- if (!t.alg)
631
+ async function R(e) {
632
+ if (!e.alg)
633
633
  throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
634
- const { algorithm: e, keyUsages: r } = Re(t), n = { ...t };
635
- return n.kty !== "AKP" && delete n.alg, delete n.use, crypto.subtle.importKey("jwk", n, e, t.ext ?? !(t.d || t.priv), t.key_ops ?? r);
634
+ const { algorithm: t, keyUsages: r } = Pe(e), n = { ...e };
635
+ 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);
636
636
  }
637
- async function Pe(t, e, r) {
638
- if (!E(t))
637
+ async function We(e, t, r) {
638
+ if (!E(e))
639
639
  throw new TypeError("JWK must be an object");
640
640
  let n;
641
- switch (e ??= t.alg, n ??= t.ext, t.kty) {
641
+ switch (t ??= e.alg, n ??= e.ext, e.kty) {
642
642
  case "oct":
643
- if (typeof t.k != "string" || !t.k)
643
+ if (typeof e.k != "string" || !e.k)
644
644
  throw new TypeError('missing "k" (Key Value) Parameter value');
645
- return C(t.k);
645
+ return C(e.k);
646
646
  case "RSA":
647
- if ("oth" in t && t.oth !== void 0)
647
+ if ("oth" in e && e.oth !== void 0)
648
648
  throw new w('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
649
- return R({ ...t, alg: e, ext: n });
649
+ return R({ ...e, alg: t, ext: n });
650
650
  case "AKP": {
651
- if (typeof t.alg != "string" || !t.alg)
651
+ if (typeof e.alg != "string" || !e.alg)
652
652
  throw new TypeError('missing "alg" (Algorithm) Parameter value');
653
- if (e !== void 0 && e !== t.alg)
653
+ if (t !== void 0 && t !== e.alg)
654
654
  throw new TypeError("JWK alg and alg option value mismatch");
655
- return R({ ...t, ext: n });
655
+ return R({ ...e, ext: n });
656
656
  }
657
657
  case "EC":
658
658
  case "OKP":
659
- return R({ ...t, alg: e, ext: n });
659
+ return R({ ...e, alg: t, ext: n });
660
660
  default:
661
661
  throw new w('Unsupported "kty" (Key Type) Parameter value');
662
662
  }
663
663
  }
664
- function We(t, e, r, n, s) {
664
+ function ke(e, t, r, n, s) {
665
665
  if (s.crit !== void 0 && n?.crit === void 0)
666
- throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');
666
+ throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
667
667
  if (!n || n.crit === void 0)
668
668
  return /* @__PURE__ */ new Set();
669
669
  if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((i) => typeof i != "string" || i.length === 0))
670
- throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
670
+ throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
671
671
  let a;
672
- a = e;
672
+ a = t;
673
673
  for (const i of n.crit) {
674
674
  if (!a.has(i))
675
675
  throw new w(`Extension Header Parameter "${i}" is not recognized`);
676
676
  if (s[i] === void 0)
677
- throw new t(`Extension Header Parameter "${i}" is missing`);
677
+ throw new e(`Extension Header Parameter "${i}" is missing`);
678
678
  if (a.get(i) && n[i] === void 0)
679
- throw new t(`Extension Header Parameter "${i}" MUST be integrity protected`);
679
+ throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`);
680
680
  }
681
681
  return new Set(n.crit);
682
682
  }
683
- const L = (t) => E(t) && typeof t.kty == "string", ke = (t) => t.kty !== "oct" && (t.kty === "AKP" && typeof t.priv == "string" || typeof t.d == "string"), Ie = (t) => t.kty !== "oct" && t.d === void 0 && t.priv === void 0, Je = (t) => t.kty === "oct" && typeof t.k == "string";
683
+ const L = (e) => E(e) && typeof e.kty == "string", Ie = (e) => e.kty !== "oct" && (e.kty === "AKP" && typeof e.priv == "string" || typeof e.d == "string"), Je = (e) => e.kty !== "oct" && e.d === void 0 && e.priv === void 0, xe = (e) => e.kty === "oct" && typeof e.k == "string";
684
684
  let T;
685
- const B = async (t, e, r, n = !1) => {
685
+ const B = async (e, t, r, n = !1) => {
686
686
  T ||= /* @__PURE__ */ new WeakMap();
687
- let s = T.get(t);
687
+ let s = T.get(e);
688
688
  if (s?.[r])
689
689
  return s[r];
690
- const a = await R({ ...e, alg: r });
691
- return n && Object.freeze(t), s ? s[r] = a : T.set(t, { [r]: a }), a;
692
- }, Ue = (t, e) => {
690
+ const a = await R({ ...t, alg: r });
691
+ return n && Object.freeze(e), s ? s[r] = a : T.set(e, { [r]: a }), a;
692
+ }, Ue = (e, t) => {
693
693
  T ||= /* @__PURE__ */ new WeakMap();
694
- let r = T.get(t);
695
- if (r?.[e])
696
- return r[e];
697
- const n = t.type === "public", s = !!n;
694
+ let r = T.get(e);
695
+ if (r?.[t])
696
+ return r[t];
697
+ const n = e.type === "public", s = !!n;
698
698
  let a;
699
- if (t.asymmetricKeyType === "x25519") {
700
- switch (e) {
699
+ if (e.asymmetricKeyType === "x25519") {
700
+ switch (t) {
701
701
  case "ECDH-ES":
702
702
  case "ECDH-ES+A128KW":
703
703
  case "ECDH-ES+A192KW":
@@ -706,29 +706,29 @@ const B = async (t, e, r, n = !1) => {
706
706
  default:
707
707
  throw new TypeError("given KeyObject instance cannot be used for this algorithm");
708
708
  }
709
- a = t.toCryptoKey(t.asymmetricKeyType, s, n ? [] : ["deriveBits"]);
709
+ a = e.toCryptoKey(e.asymmetricKeyType, s, n ? [] : ["deriveBits"]);
710
710
  }
711
- if (t.asymmetricKeyType === "ed25519") {
712
- if (e !== "EdDSA" && e !== "Ed25519")
711
+ if (e.asymmetricKeyType === "ed25519") {
712
+ if (t !== "EdDSA" && t !== "Ed25519")
713
713
  throw new TypeError("given KeyObject instance cannot be used for this algorithm");
714
- a = t.toCryptoKey(t.asymmetricKeyType, s, [
714
+ a = e.toCryptoKey(e.asymmetricKeyType, s, [
715
715
  n ? "verify" : "sign"
716
716
  ]);
717
717
  }
718
- switch (t.asymmetricKeyType) {
718
+ switch (e.asymmetricKeyType) {
719
719
  case "ml-dsa-44":
720
720
  case "ml-dsa-65":
721
721
  case "ml-dsa-87": {
722
- if (e !== t.asymmetricKeyType.toUpperCase())
722
+ if (t !== e.asymmetricKeyType.toUpperCase())
723
723
  throw new TypeError("given KeyObject instance cannot be used for this algorithm");
724
- a = t.toCryptoKey(t.asymmetricKeyType, s, [
724
+ a = e.toCryptoKey(e.asymmetricKeyType, s, [
725
725
  n ? "verify" : "sign"
726
726
  ]);
727
727
  }
728
728
  }
729
- if (t.asymmetricKeyType === "rsa") {
729
+ if (e.asymmetricKeyType === "rsa") {
730
730
  let i;
731
- switch (e) {
731
+ switch (t) {
732
732
  case "RSA-OAEP":
733
733
  i = "SHA-1";
734
734
  break;
@@ -750,64 +750,64 @@ const B = async (t, e, r, n = !1) => {
750
750
  default:
751
751
  throw new TypeError("given KeyObject instance cannot be used for this algorithm");
752
752
  }
753
- if (e.startsWith("RSA-OAEP"))
754
- return t.toCryptoKey({
753
+ if (t.startsWith("RSA-OAEP"))
754
+ return e.toCryptoKey({
755
755
  name: "RSA-OAEP",
756
756
  hash: i
757
757
  }, s, n ? ["encrypt"] : ["decrypt"]);
758
- a = t.toCryptoKey({
759
- name: e.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
758
+ a = e.toCryptoKey({
759
+ name: t.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
760
760
  hash: i
761
761
  }, s, [n ? "verify" : "sign"]);
762
762
  }
763
- if (t.asymmetricKeyType === "ec") {
763
+ if (e.asymmetricKeyType === "ec") {
764
764
  const c = (/* @__PURE__ */ new Map([
765
765
  ["prime256v1", "P-256"],
766
766
  ["secp384r1", "P-384"],
767
767
  ["secp521r1", "P-521"]
768
- ])).get(t.asymmetricKeyDetails?.namedCurve);
768
+ ])).get(e.asymmetricKeyDetails?.namedCurve);
769
769
  if (!c)
770
770
  throw new TypeError("given KeyObject instance cannot be used for this algorithm");
771
- e === "ES256" && c === "P-256" && (a = t.toCryptoKey({
771
+ t === "ES256" && c === "P-256" && (a = e.toCryptoKey({
772
772
  name: "ECDSA",
773
773
  namedCurve: c
774
- }, s, [n ? "verify" : "sign"])), e === "ES384" && c === "P-384" && (a = t.toCryptoKey({
774
+ }, s, [n ? "verify" : "sign"])), t === "ES384" && c === "P-384" && (a = e.toCryptoKey({
775
775
  name: "ECDSA",
776
776
  namedCurve: c
777
- }, s, [n ? "verify" : "sign"])), e === "ES512" && c === "P-521" && (a = t.toCryptoKey({
777
+ }, s, [n ? "verify" : "sign"])), t === "ES512" && c === "P-521" && (a = e.toCryptoKey({
778
778
  name: "ECDSA",
779
779
  namedCurve: c
780
- }, s, [n ? "verify" : "sign"])), e.startsWith("ECDH-ES") && (a = t.toCryptoKey({
780
+ }, s, [n ? "verify" : "sign"])), t.startsWith("ECDH-ES") && (a = e.toCryptoKey({
781
781
  name: "ECDH",
782
782
  namedCurve: c
783
783
  }, s, n ? [] : ["deriveBits"]));
784
784
  }
785
785
  if (!a)
786
786
  throw new TypeError("given KeyObject instance cannot be used for this algorithm");
787
- return r ? r[e] = a : T.set(t, { [e]: a }), a;
787
+ return r ? r[t] = a : T.set(e, { [t]: a }), a;
788
788
  };
789
- async function xe(t, e) {
790
- if (t instanceof Uint8Array || se(t))
791
- return t;
792
- if (ae(t)) {
793
- if (t.type === "secret")
794
- return t.export();
795
- if ("toCryptoKey" in t && typeof t.toCryptoKey == "function")
789
+ async function De(e, t) {
790
+ if (e instanceof Uint8Array || ie(e))
791
+ return e;
792
+ if (oe(e)) {
793
+ if (e.type === "secret")
794
+ return e.export();
795
+ if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
796
796
  try {
797
- return Ue(t, e);
797
+ return Ue(e, t);
798
798
  } catch (n) {
799
799
  if (n instanceof TypeError)
800
800
  throw n;
801
801
  }
802
- let r = t.export({ format: "jwk" });
803
- return B(t, r, e);
802
+ let r = e.export({ format: "jwk" });
803
+ return B(e, r, t);
804
804
  }
805
- if (L(t))
806
- return t.k ? C(t.k) : B(t, t, e, !0);
805
+ if (L(e))
806
+ return e.k ? C(e.k) : B(e, e, t, !0);
807
807
  throw new Error("unreachable");
808
808
  }
809
- const K = (t) => t?.[Symbol.toStringTag], O = (t, e, r) => {
810
- if (e.use !== void 0) {
809
+ const K = (e) => e?.[Symbol.toStringTag], M = (e, t, r) => {
810
+ if (t.use !== void 0) {
811
811
  let n;
812
812
  switch (r) {
813
813
  case "sign":
@@ -819,97 +819,97 @@ const K = (t) => t?.[Symbol.toStringTag], O = (t, e, r) => {
819
819
  n = "enc";
820
820
  break;
821
821
  }
822
- if (e.use !== n)
822
+ if (t.use !== n)
823
823
  throw new TypeError(`Invalid key for this operation, its "use" must be "${n}" when present`);
824
824
  }
825
- if (e.alg !== void 0 && e.alg !== t)
826
- throw new TypeError(`Invalid key for this operation, its "alg" must be "${t}" when present`);
827
- if (Array.isArray(e.key_ops)) {
825
+ if (t.alg !== void 0 && t.alg !== e)
826
+ throw new TypeError(`Invalid key for this operation, its "alg" must be "${e}" when present`);
827
+ if (Array.isArray(t.key_ops)) {
828
828
  let n;
829
829
  switch (!0) {
830
830
  case r === "verify":
831
- case t === "dir":
832
- case t.includes("CBC-HS"):
831
+ case e === "dir":
832
+ case e.includes("CBC-HS"):
833
833
  n = r;
834
834
  break;
835
- case t.startsWith("PBES2"):
835
+ case e.startsWith("PBES2"):
836
836
  n = "deriveBits";
837
837
  break;
838
- case /^A\d{3}(?:GCM)?(?:KW)?$/.test(t):
839
- !t.includes("GCM") && t.endsWith("KW") ? n = "unwrapKey" : n = r;
838
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(e):
839
+ !e.includes("GCM") && e.endsWith("KW") ? n = "unwrapKey" : n = r;
840
840
  break;
841
841
  case r === "encrypt":
842
842
  n = "wrapKey";
843
843
  break;
844
844
  case r === "decrypt":
845
- n = t.startsWith("RSA") ? "unwrapKey" : "deriveBits";
845
+ n = e.startsWith("RSA") ? "unwrapKey" : "deriveBits";
846
846
  break;
847
847
  }
848
- if (n && e.key_ops?.includes?.(n) === !1)
848
+ if (n && t.key_ops?.includes?.(n) === !1)
849
849
  throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`);
850
850
  }
851
851
  return !0;
852
- }, De = (t, e, r) => {
853
- if (!(e instanceof Uint8Array)) {
854
- if (L(e)) {
855
- if (Je(e) && O(t, e, r))
852
+ }, Me = (e, t, r) => {
853
+ if (!(t instanceof Uint8Array)) {
854
+ if (L(t)) {
855
+ if (xe(t) && M(e, t, r))
856
856
  return;
857
857
  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');
858
858
  }
859
- if (!ie(e))
860
- throw new TypeError(ne(t, e, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
861
- if (e.type !== "secret")
862
- throw new TypeError(`${K(e)} instances for symmetric algorithms must be of type "secret"`);
859
+ if (!ce(t))
860
+ throw new TypeError(ae(e, t, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
861
+ if (t.type !== "secret")
862
+ throw new TypeError(`${K(t)} instances for symmetric algorithms must be of type "secret"`);
863
863
  }
864
- }, Oe = (t, e, r) => {
865
- if (L(e))
864
+ }, Oe = (e, t, r) => {
865
+ if (L(t))
866
866
  switch (r) {
867
867
  case "decrypt":
868
868
  case "sign":
869
- if (ke(e) && O(t, e, r))
869
+ if (Ie(t) && M(e, t, r))
870
870
  return;
871
871
  throw new TypeError("JSON Web Key for this operation must be a private JWK");
872
872
  case "encrypt":
873
873
  case "verify":
874
- if (Ie(e) && O(t, e, r))
874
+ if (Je(t) && M(e, t, r))
875
875
  return;
876
876
  throw new TypeError("JSON Web Key for this operation must be a public JWK");
877
877
  }
878
- if (!ie(e))
879
- throw new TypeError(ne(t, e, "CryptoKey", "KeyObject", "JSON Web Key"));
880
- if (e.type === "secret")
881
- throw new TypeError(`${K(e)} instances for asymmetric algorithms must not be of type "secret"`);
882
- if (e.type === "public")
878
+ if (!ce(t))
879
+ throw new TypeError(ae(e, t, "CryptoKey", "KeyObject", "JSON Web Key"));
880
+ if (t.type === "secret")
881
+ throw new TypeError(`${K(t)} instances for asymmetric algorithms must not be of type "secret"`);
882
+ if (t.type === "public")
883
883
  switch (r) {
884
884
  case "sign":
885
- throw new TypeError(`${K(e)} instances for asymmetric algorithm signing must be of type "private"`);
885
+ throw new TypeError(`${K(t)} instances for asymmetric algorithm signing must be of type "private"`);
886
886
  case "decrypt":
887
- throw new TypeError(`${K(e)} instances for asymmetric algorithm decryption must be of type "private"`);
887
+ throw new TypeError(`${K(t)} instances for asymmetric algorithm decryption must be of type "private"`);
888
888
  }
889
- if (e.type === "private")
889
+ if (t.type === "private")
890
890
  switch (r) {
891
891
  case "verify":
892
- throw new TypeError(`${K(e)} instances for asymmetric algorithm verifying must be of type "public"`);
892
+ throw new TypeError(`${K(t)} instances for asymmetric algorithm verifying must be of type "public"`);
893
893
  case "encrypt":
894
- throw new TypeError(`${K(e)} instances for asymmetric algorithm encryption must be of type "public"`);
894
+ throw new TypeError(`${K(t)} instances for asymmetric algorithm encryption must be of type "public"`);
895
895
  }
896
896
  };
897
- function Me(t, e, r) {
898
- switch (t.substring(0, 2)) {
897
+ function He(e, t, r) {
898
+ switch (e.substring(0, 2)) {
899
899
  case "A1":
900
900
  case "A2":
901
901
  case "di":
902
902
  case "HS":
903
903
  case "PB":
904
- De(t, e, r);
904
+ Me(e, t, r);
905
905
  break;
906
906
  default:
907
- Oe(t, e, r);
907
+ Oe(e, t, r);
908
908
  }
909
909
  }
910
- function He(t, e) {
911
- const r = `SHA-${t.slice(-3)}`;
912
- switch (t) {
910
+ function Ne(e, t) {
911
+ const r = `SHA-${e.slice(-3)}`;
912
+ switch (e) {
913
913
  case "HS256":
914
914
  case "HS384":
915
915
  case "HS512":
@@ -917,7 +917,7 @@ function He(t, e) {
917
917
  case "PS256":
918
918
  case "PS384":
919
919
  case "PS512":
920
- return { hash: r, name: "RSA-PSS", saltLength: parseInt(t.slice(-3), 10) >> 3 };
920
+ return { hash: r, name: "RSA-PSS", saltLength: parseInt(e.slice(-3), 10) >> 3 };
921
921
  case "RS256":
922
922
  case "RS384":
923
923
  case "RS512":
@@ -925,63 +925,63 @@ function He(t, e) {
925
925
  case "ES256":
926
926
  case "ES384":
927
927
  case "ES512":
928
- return { hash: r, name: "ECDSA", namedCurve: e.namedCurve };
928
+ return { hash: r, name: "ECDSA", namedCurve: t.namedCurve };
929
929
  case "Ed25519":
930
930
  case "EdDSA":
931
931
  return { name: "Ed25519" };
932
932
  case "ML-DSA-44":
933
933
  case "ML-DSA-65":
934
934
  case "ML-DSA-87":
935
- return { name: t };
935
+ return { name: e };
936
936
  default:
937
- throw new w(`alg ${t} is not supported either by JOSE or your javascript runtime`);
937
+ throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);
938
938
  }
939
939
  }
940
- async function Ne(t, e, r) {
941
- if (e instanceof Uint8Array) {
942
- if (!t.startsWith("HS"))
943
- throw new TypeError(Te(e, "CryptoKey", "KeyObject", "JSON Web Key"));
944
- return crypto.subtle.importKey("raw", e, { hash: `SHA-${t.slice(-3)}`, name: "HMAC" }, !1, [r]);
940
+ async function $e(e, t, r) {
941
+ if (t instanceof Uint8Array) {
942
+ if (!e.startsWith("HS"))
943
+ throw new TypeError(ve(t, "CryptoKey", "KeyObject", "JSON Web Key"));
944
+ return crypto.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
945
945
  }
946
- return Ke(e, t, r), e;
946
+ return Te(t, e, r), t;
947
947
  }
948
- async function $e(t, e, r, n) {
949
- const s = await Ne(t, e, "verify");
950
- _e(t, s);
951
- const a = He(t, s.algorithm);
948
+ async function Le(e, t, r, n) {
949
+ const s = await $e(e, t, "verify");
950
+ Re(e, s);
951
+ const a = Ne(e, s.algorithm);
952
952
  try {
953
953
  return await crypto.subtle.verify(a, s, r, n);
954
954
  } catch {
955
955
  return !1;
956
956
  }
957
957
  }
958
- async function Le(t, e, r) {
959
- if (!E(t))
958
+ async function Fe(e, t, r) {
959
+ if (!E(e))
960
960
  throw new f("Flattened JWS must be an object");
961
- if (t.protected === void 0 && t.header === void 0)
961
+ if (e.protected === void 0 && e.header === void 0)
962
962
  throw new f('Flattened JWS must have either of the "protected" or "header" members');
963
- if (t.protected !== void 0 && typeof t.protected != "string")
963
+ if (e.protected !== void 0 && typeof e.protected != "string")
964
964
  throw new f("JWS Protected Header incorrect type");
965
- if (t.payload === void 0)
965
+ if (e.payload === void 0)
966
966
  throw new f("JWS Payload missing");
967
- if (typeof t.signature != "string")
967
+ if (typeof e.signature != "string")
968
968
  throw new f("JWS Signature missing or incorrect type");
969
- if (t.header !== void 0 && !E(t.header))
969
+ if (e.header !== void 0 && !E(e.header))
970
970
  throw new f("JWS Unprotected Header incorrect type");
971
971
  let n = {};
972
- if (t.protected)
972
+ if (e.protected)
973
973
  try {
974
- const P = C(t.protected);
974
+ const P = C(e.protected);
975
975
  n = JSON.parse(_.decode(P));
976
976
  } catch {
977
977
  throw new f("JWS Protected Header is invalid");
978
978
  }
979
- if (!ve(n, t.header))
979
+ if (!Ce(n, e.header))
980
980
  throw new f("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
981
981
  const s = {
982
982
  ...n,
983
- ...t.header
984
- }, a = We(f, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, s);
983
+ ...e.header
984
+ }, a = ke(f, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, s);
985
985
  let i = !0;
986
986
  if (a.has("b64") && (i = n.b64, typeof i != "boolean"))
987
987
  throw new f('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
@@ -989,48 +989,48 @@ async function Le(t, e, r) {
989
989
  if (typeof c != "string" || !c)
990
990
  throw new f('JWS "alg" (Algorithm) Header Parameter missing or invalid');
991
991
  if (i) {
992
- if (typeof t.payload != "string")
992
+ if (typeof e.payload != "string")
993
993
  throw new f("JWS Payload must be a string");
994
- } else if (typeof t.payload != "string" && !(t.payload instanceof Uint8Array))
994
+ } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
995
995
  throw new f("JWS Payload must be a string or an Uint8Array instance");
996
- let u = !1;
997
- typeof e == "function" && (e = await e(n, t), u = !0), Me(c, e, "verify");
998
- const h = me(t.protected !== void 0 ? J(t.protected) : new Uint8Array(), J("."), typeof t.payload == "string" ? i ? J(t.payload) : G.encode(t.payload) : t.payload);
996
+ let h = !1;
997
+ typeof t == "function" && (t = await t(n, e), h = !0), He(c, t, "verify");
998
+ const u = we(e.protected !== void 0 ? J(e.protected) : new Uint8Array(), J("."), typeof e.payload == "string" ? i ? J(e.payload) : G.encode(e.payload) : e.payload);
999
999
  let o;
1000
1000
  try {
1001
- o = C(t.signature);
1001
+ o = C(e.signature);
1002
1002
  } catch {
1003
1003
  throw new f("Failed to base64url decode the signature");
1004
1004
  }
1005
- const d = await xe(e, c);
1006
- if (!await $e(c, d, o, h))
1007
- throw new be();
1005
+ const d = await De(t, c);
1006
+ if (!await Le(c, d, o, u))
1007
+ throw new Ee();
1008
1008
  let b;
1009
1009
  if (i)
1010
1010
  try {
1011
- b = C(t.payload);
1011
+ b = C(e.payload);
1012
1012
  } catch {
1013
1013
  throw new f("Failed to base64url decode the payload");
1014
1014
  }
1015
- else typeof t.payload == "string" ? b = G.encode(t.payload) : b = t.payload;
1015
+ else typeof e.payload == "string" ? b = G.encode(e.payload) : b = e.payload;
1016
1016
  const p = { payload: b };
1017
- return t.protected !== void 0 && (p.protectedHeader = n), t.header !== void 0 && (p.unprotectedHeader = t.header), u ? { ...p, key: d } : p;
1017
+ return e.protected !== void 0 && (p.protectedHeader = n), e.header !== void 0 && (p.unprotectedHeader = e.header), h ? { ...p, key: d } : p;
1018
1018
  }
1019
- async function Fe(t, e, r) {
1020
- if (t instanceof Uint8Array && (t = _.decode(t)), typeof t != "string")
1019
+ async function Ve(e, t, r) {
1020
+ if (e instanceof Uint8Array && (e = _.decode(e)), typeof e != "string")
1021
1021
  throw new f("Compact JWS must be a string or Uint8Array");
1022
- const { 0: n, 1: s, 2: a, length: i } = t.split(".");
1022
+ const { 0: n, 1: s, 2: a, length: i } = e.split(".");
1023
1023
  if (i !== 3)
1024
1024
  throw new f("Invalid Compact JWS");
1025
- const c = await Le({ payload: s, protected: n, signature: a }, e, r), u = { payload: c.payload, protectedHeader: c.protectedHeader };
1026
- return typeof e == "function" ? { ...u, key: c.key } : u;
1025
+ const c = await Fe({ payload: s, protected: n, signature: a }, t, r), h = { payload: c.payload, protectedHeader: c.protectedHeader };
1026
+ return typeof t == "function" ? { ...h, key: c.key } : h;
1027
1027
  }
1028
- const Ve = (t) => Math.floor(t.getTime() / 1e3), oe = 60, ce = oe * 60, F = ce * 24, Ge = F * 7, ze = F * 365.25, Be = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
1029
- function q(t) {
1030
- const e = Be.exec(t);
1031
- if (!e || e[4] && e[1])
1028
+ const Ge = (e) => Math.floor(e.getTime() / 1e3), ue = 60, he = ue * 60, F = he * 24, ze = F * 7, Be = F * 365.25, qe = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
1029
+ function q(e) {
1030
+ const t = qe.exec(e);
1031
+ if (!t || t[4] && t[1])
1032
1032
  throw new TypeError("Invalid time period format");
1033
- const r = parseFloat(e[2]), n = e[3].toLowerCase();
1033
+ const r = parseFloat(t[2]), n = t[3].toLowerCase();
1034
1034
  let s;
1035
1035
  switch (n) {
1036
1036
  case "sec":
@@ -1045,14 +1045,14 @@ function q(t) {
1045
1045
  case "min":
1046
1046
  case "mins":
1047
1047
  case "m":
1048
- s = Math.round(r * oe);
1048
+ s = Math.round(r * ue);
1049
1049
  break;
1050
1050
  case "hour":
1051
1051
  case "hours":
1052
1052
  case "hr":
1053
1053
  case "hrs":
1054
1054
  case "h":
1055
- s = Math.round(r * ce);
1055
+ s = Math.round(r * he);
1056
1056
  break;
1057
1057
  case "day":
1058
1058
  case "days":
@@ -1062,28 +1062,28 @@ function q(t) {
1062
1062
  case "week":
1063
1063
  case "weeks":
1064
1064
  case "w":
1065
- s = Math.round(r * Ge);
1065
+ s = Math.round(r * ze);
1066
1066
  break;
1067
1067
  default:
1068
- s = Math.round(r * ze);
1068
+ s = Math.round(r * Be);
1069
1069
  break;
1070
1070
  }
1071
- return e[1] === "-" || e[4] === "ago" ? -s : s;
1071
+ return t[1] === "-" || t[4] === "ago" ? -s : s;
1072
1072
  }
1073
- const Y = (t) => t.includes("/") ? t.toLowerCase() : `application/${t.toLowerCase()}`, qe = (t, e) => typeof t == "string" ? e.includes(t) : Array.isArray(t) ? e.some(Set.prototype.has.bind(new Set(t))) : !1;
1074
- function Ye(t, e, r = {}) {
1073
+ const Y = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`, Ye = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
1074
+ function Xe(e, t, r = {}) {
1075
1075
  let n;
1076
1076
  try {
1077
- n = JSON.parse(_.decode(e));
1077
+ n = JSON.parse(_.decode(t));
1078
1078
  } catch {
1079
1079
  }
1080
1080
  if (!E(n))
1081
- throw new j("JWT Claims Set must be a top-level JSON object");
1081
+ throw new te("JWT Claims Set must be a top-level JSON object");
1082
1082
  const { typ: s } = r;
1083
- if (s && (typeof t.typ != "string" || Y(t.typ) !== Y(s)))
1083
+ if (s && (typeof e.typ != "string" || Y(e.typ) !== Y(s)))
1084
1084
  throw new y('unexpected "typ" JWT header value', n, "typ", "check_failed");
1085
- const { requiredClaims: a = [], issuer: i, subject: c, audience: u, maxTokenAge: h } = r, o = [...a];
1086
- h !== void 0 && o.push("iat"), u !== void 0 && o.push("aud"), c !== void 0 && o.push("sub"), i !== void 0 && o.push("iss");
1085
+ const { requiredClaims: a = [], issuer: i, subject: c, audience: h, maxTokenAge: u } = r, o = [...a];
1086
+ u !== void 0 && o.push("iat"), h !== void 0 && o.push("aud"), c !== void 0 && o.push("sub"), i !== void 0 && o.push("iss");
1087
1087
  for (const p of new Set(o.reverse()))
1088
1088
  if (!(p in n))
1089
1089
  throw new y(`missing required "${p}" claim`, n, p, "missing");
@@ -1091,7 +1091,7 @@ function Ye(t, e, r = {}) {
1091
1091
  throw new y('unexpected "iss" claim value', n, "iss", "check_failed");
1092
1092
  if (c && n.sub !== c)
1093
1093
  throw new y('unexpected "sub" claim value', n, "sub", "check_failed");
1094
- if (u && !qe(n.aud, typeof u == "string" ? [u] : u))
1094
+ if (h && !Ye(n.aud, typeof h == "string" ? [h] : h))
1095
1095
  throw new y('unexpected "aud" claim value', n, "aud", "check_failed");
1096
1096
  let d;
1097
1097
  switch (typeof r.clockTolerance) {
@@ -1107,8 +1107,8 @@ function Ye(t, e, r = {}) {
1107
1107
  default:
1108
1108
  throw new TypeError("Invalid clockTolerance option type");
1109
1109
  }
1110
- const { currentDate: V } = r, b = Ve(V || /* @__PURE__ */ new Date());
1111
- if ((n.iat !== void 0 || h) && typeof n.iat != "number")
1110
+ const { currentDate: V } = r, b = Ge(V || /* @__PURE__ */ new Date());
1111
+ if ((n.iat !== void 0 || u) && typeof n.iat != "number")
1112
1112
  throw new y('"iat" claim must be a number', n, "iat", "invalid");
1113
1113
  if (n.nbf !== void 0) {
1114
1114
  if (typeof n.nbf != "number")
@@ -1122,8 +1122,8 @@ function Ye(t, e, r = {}) {
1122
1122
  if (n.exp <= b - d)
1123
1123
  throw new z('"exp" claim timestamp check failed', n, "exp", "check_failed");
1124
1124
  }
1125
- if (h) {
1126
- const p = b - n.iat, P = typeof h == "number" ? h : q(h);
1125
+ if (u) {
1126
+ const p = b - n.iat, P = typeof u == "number" ? u : q(u);
1127
1127
  if (p - d > P)
1128
1128
  throw new z('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
1129
1129
  if (p < 0 - d)
@@ -1131,15 +1131,15 @@ function Ye(t, e, r = {}) {
1131
1131
  }
1132
1132
  return n;
1133
1133
  }
1134
- async function Xe(t, e, r) {
1135
- const n = await Fe(t, e, r);
1134
+ async function Qe(e, t, r) {
1135
+ const n = await Ve(e, t, r);
1136
1136
  if (n.protectedHeader.crit?.includes("b64") && n.protectedHeader.b64 === !1)
1137
- throw new j("JWTs MUST NOT use unencoded payload");
1138
- const a = { payload: Ye(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
1139
- return typeof e == "function" ? { ...a, key: n.key } : a;
1137
+ throw new te("JWTs MUST NOT use unencoded payload");
1138
+ const a = { payload: Xe(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
1139
+ return typeof t == "function" ? { ...a, key: n.key } : a;
1140
1140
  }
1141
- function Qe(t) {
1142
- switch (typeof t == "string" && t.slice(0, 2)) {
1141
+ function Ze(e) {
1142
+ switch (typeof e == "string" && e.slice(0, 2)) {
1143
1143
  case "RS":
1144
1144
  case "PS":
1145
1145
  return "RSA";
@@ -1153,94 +1153,94 @@ function Qe(t) {
1153
1153
  throw new w('Unsupported "alg" value for a JSON Web Key Set');
1154
1154
  }
1155
1155
  }
1156
- function Ze(t) {
1157
- return t && typeof t == "object" && Array.isArray(t.keys) && t.keys.every(je);
1156
+ function je(e) {
1157
+ return e && typeof e == "object" && Array.isArray(e.keys) && e.keys.every(et);
1158
1158
  }
1159
- function je(t) {
1160
- return E(t);
1159
+ function et(e) {
1160
+ return E(e);
1161
1161
  }
1162
- class et {
1162
+ class tt {
1163
1163
  #r;
1164
1164
  #i = /* @__PURE__ */ new WeakMap();
1165
- constructor(e) {
1166
- if (!Ze(e))
1167
- throw new ee("JSON Web Key Set malformed");
1168
- this.#r = structuredClone(e);
1165
+ constructor(t) {
1166
+ if (!je(t))
1167
+ throw new re("JSON Web Key Set malformed");
1168
+ this.#r = structuredClone(t);
1169
1169
  }
1170
1170
  jwks() {
1171
1171
  return this.#r;
1172
1172
  }
1173
- async getKey(e, r) {
1174
- const { alg: n, kid: s } = { ...e, ...r?.header }, a = Qe(n), i = this.#r.keys.filter((h) => {
1175
- let o = a === h.kty;
1176
- if (o && typeof s == "string" && (o = s === h.kid), o && (typeof h.alg == "string" || a === "AKP") && (o = n === h.alg), o && typeof h.use == "string" && (o = h.use === "sig"), o && Array.isArray(h.key_ops) && (o = h.key_ops.includes("verify")), o)
1173
+ async getKey(t, r) {
1174
+ const { alg: n, kid: s } = { ...t, ...r?.header }, a = Ze(n), i = this.#r.keys.filter((u) => {
1175
+ let o = a === u.kty;
1176
+ if (o && typeof s == "string" && (o = s === u.kid), o && (typeof u.alg == "string" || a === "AKP") && (o = n === u.alg), o && typeof u.use == "string" && (o = u.use === "sig"), o && Array.isArray(u.key_ops) && (o = u.key_ops.includes("verify")), o)
1177
1177
  switch (n) {
1178
1178
  case "ES256":
1179
- o = h.crv === "P-256";
1179
+ o = u.crv === "P-256";
1180
1180
  break;
1181
1181
  case "ES384":
1182
- o = h.crv === "P-384";
1182
+ o = u.crv === "P-384";
1183
1183
  break;
1184
1184
  case "ES512":
1185
- o = h.crv === "P-521";
1185
+ o = u.crv === "P-521";
1186
1186
  break;
1187
1187
  case "Ed25519":
1188
1188
  case "EdDSA":
1189
- o = h.crv === "Ed25519";
1189
+ o = u.crv === "Ed25519";
1190
1190
  break;
1191
1191
  }
1192
1192
  return o;
1193
- }), { 0: c, length: u } = i;
1194
- if (u === 0)
1195
- throw new te();
1196
- if (u !== 1) {
1197
- const h = new Se(), o = this.#i;
1198
- throw h[Symbol.asyncIterator] = async function* () {
1193
+ }), { 0: c, length: h } = i;
1194
+ if (h === 0)
1195
+ throw new ne();
1196
+ if (h !== 1) {
1197
+ const u = new ge(), o = this.#i;
1198
+ throw u[Symbol.asyncIterator] = async function* () {
1199
1199
  for (const d of i)
1200
1200
  try {
1201
1201
  yield await X(o, d, n);
1202
1202
  } catch {
1203
1203
  }
1204
- }, h;
1204
+ }, u;
1205
1205
  }
1206
1206
  return X(this.#i, c, n);
1207
1207
  }
1208
1208
  }
1209
- async function X(t, e, r) {
1210
- const n = t.get(e) || t.set(e, {}).get(e);
1209
+ async function X(e, t, r) {
1210
+ const n = e.get(t) || e.set(t, {}).get(t);
1211
1211
  if (n[r] === void 0) {
1212
- const s = await Pe({ ...e, ext: !0 }, r);
1212
+ const s = await We({ ...t, ext: !0 }, r);
1213
1213
  if (s instanceof Uint8Array || s.type !== "public")
1214
- throw new ee("JSON Web Key Set members must be public keys");
1214
+ throw new re("JSON Web Key Set members must be public keys");
1215
1215
  n[r] = s;
1216
1216
  }
1217
1217
  return n[r];
1218
1218
  }
1219
- function Q(t) {
1220
- const e = new et(t), r = async (n, s) => e.getKey(n, s);
1219
+ function Q(e) {
1220
+ const t = new tt(e), r = async (n, s) => t.getKey(n, s);
1221
1221
  return Object.defineProperties(r, {
1222
1222
  jwks: {
1223
- value: () => structuredClone(e.jwks()),
1223
+ value: () => structuredClone(t.jwks()),
1224
1224
  enumerable: !1,
1225
1225
  configurable: !1,
1226
1226
  writable: !1
1227
1227
  }
1228
1228
  }), r;
1229
1229
  }
1230
- function tt() {
1230
+ function rt() {
1231
1231
  return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
1232
1232
  }
1233
- let M;
1234
- (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (M = "jose/v6.1.3");
1235
- const rt = /* @__PURE__ */ Symbol();
1236
- async function nt(t, e, r, n = fetch) {
1237
- const s = await n(t, {
1233
+ let O;
1234
+ (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (O = "jose/v6.1.3");
1235
+ const nt = /* @__PURE__ */ Symbol();
1236
+ async function st(e, t, r, n = fetch) {
1237
+ const s = await n(e, {
1238
1238
  method: "GET",
1239
1239
  signal: r,
1240
1240
  redirect: "manual",
1241
- headers: e
1241
+ headers: t
1242
1242
  }).catch((a) => {
1243
- throw a.name === "TimeoutError" ? new ge() : a;
1243
+ throw a.name === "TimeoutError" ? new be() : a;
1244
1244
  });
1245
1245
  if (s.status !== 200)
1246
1246
  throw new l("Expected 200 OK from the JSON Web Key Set HTTP response");
@@ -1250,11 +1250,11 @@ async function nt(t, e, r, n = fetch) {
1250
1250
  throw new l("Failed to parse the JSON Web Key Set HTTP response as JSON");
1251
1251
  }
1252
1252
  }
1253
- const x = /* @__PURE__ */ Symbol();
1254
- function st(t, e) {
1255
- return !(typeof t != "object" || t === null || !("uat" in t) || typeof t.uat != "number" || Date.now() - t.uat >= e || !("jwks" in t) || !E(t.jwks) || !Array.isArray(t.jwks.keys) || !Array.prototype.every.call(t.jwks.keys, E));
1253
+ const U = /* @__PURE__ */ Symbol();
1254
+ function at(e, t) {
1255
+ return !(typeof e != "object" || e === null || !("uat" in e) || typeof e.uat != "number" || Date.now() - e.uat >= t || !("jwks" in e) || !E(e.jwks) || !Array.isArray(e.jwks.keys) || !Array.prototype.every.call(e.jwks.keys, E));
1256
1256
  }
1257
- class at {
1257
+ class it {
1258
1258
  #r;
1259
1259
  #i;
1260
1260
  #c;
@@ -1262,13 +1262,13 @@ class at {
1262
1262
  #n;
1263
1263
  #e;
1264
1264
  #t;
1265
- #h;
1265
+ #u;
1266
1266
  #s;
1267
1267
  #a;
1268
- constructor(e, r) {
1269
- if (!(e instanceof URL))
1268
+ constructor(t, r) {
1269
+ if (!(t instanceof URL))
1270
1270
  throw new TypeError("url must be an instance of URL");
1271
- this.#r = new URL(e.href), this.#i = typeof r?.timeoutDuration == "number" ? r?.timeoutDuration : 5e3, this.#c = typeof r?.cooldownDuration == "number" ? r?.cooldownDuration : 3e4, this.#o = typeof r?.cacheMaxAge == "number" ? r?.cacheMaxAge : 6e5, this.#t = new Headers(r?.headers), M && !this.#t.has("User-Agent") && this.#t.set("User-Agent", M), this.#t.has("accept") || (this.#t.set("accept", "application/json"), this.#t.append("accept", "application/jwk-set+json")), this.#h = r?.[rt], r?.[x] !== void 0 && (this.#a = r?.[x], st(r?.[x], this.#o) && (this.#n = this.#a.uat, this.#s = Q(this.#a.jwks)));
1271
+ this.#r = new URL(t.href), this.#i = typeof r?.timeoutDuration == "number" ? r?.timeoutDuration : 5e3, this.#c = typeof r?.cooldownDuration == "number" ? r?.cooldownDuration : 3e4, this.#o = typeof r?.cacheMaxAge == "number" ? r?.cacheMaxAge : 6e5, this.#t = new Headers(r?.headers), O && !this.#t.has("User-Agent") && this.#t.set("User-Agent", O), this.#t.has("accept") || (this.#t.set("accept", "application/json"), this.#t.append("accept", "application/jwk-set+json")), this.#u = r?.[nt], r?.[U] !== void 0 && (this.#a = r?.[U], at(r?.[U], this.#o) && (this.#n = this.#a.uat, this.#s = Q(this.#a.jwks)));
1272
1272
  }
1273
1273
  pendingFetch() {
1274
1274
  return !!this.#e;
@@ -1282,26 +1282,26 @@ class at {
1282
1282
  jwks() {
1283
1283
  return this.#s?.jwks();
1284
1284
  }
1285
- async getKey(e, r) {
1285
+ async getKey(t, r) {
1286
1286
  (!this.#s || !this.fresh()) && await this.reload();
1287
1287
  try {
1288
- return await this.#s(e, r);
1288
+ return await this.#s(t, r);
1289
1289
  } catch (n) {
1290
- if (n instanceof te && this.coolingDown() === !1)
1291
- return await this.reload(), this.#s(e, r);
1290
+ if (n instanceof ne && this.coolingDown() === !1)
1291
+ return await this.reload(), this.#s(t, r);
1292
1292
  throw n;
1293
1293
  }
1294
1294
  }
1295
1295
  async reload() {
1296
- this.#e && tt() && (this.#e = void 0), this.#e ||= nt(this.#r.href, this.#t, AbortSignal.timeout(this.#i), this.#h).then((e) => {
1297
- this.#s = Q(e), this.#a && (this.#a.uat = Date.now(), this.#a.jwks = e), this.#n = Date.now(), this.#e = void 0;
1298
- }).catch((e) => {
1299
- throw this.#e = void 0, e;
1296
+ this.#e && rt() && (this.#e = void 0), this.#e ||= st(this.#r.href, this.#t, AbortSignal.timeout(this.#i), this.#u).then((t) => {
1297
+ this.#s = Q(t), this.#a && (this.#a.uat = Date.now(), this.#a.jwks = t), this.#n = Date.now(), this.#e = void 0;
1298
+ }).catch((t) => {
1299
+ throw this.#e = void 0, t;
1300
1300
  }), await this.#e;
1301
1301
  }
1302
1302
  }
1303
- function it(t, e) {
1304
- const r = new at(t, e), n = async (s, a) => r.getKey(s, a);
1303
+ function ot(e, t) {
1304
+ const r = new it(e, t), n = async (s, a) => r.getKey(s, a);
1305
1305
  return Object.defineProperties(n, {
1306
1306
  coolingDown: {
1307
1307
  get: () => r.coolingDown(),
@@ -1332,50 +1332,42 @@ function it(t, e) {
1332
1332
  }
1333
1333
  }), n;
1334
1334
  }
1335
- class ot {
1336
- jwksUrl;
1337
- JWKS;
1338
- constructor(e) {
1339
- this.jwksUrl = e, this.JWKS = it(new URL(this.jwksUrl));
1340
- }
1341
- /**
1342
- * Verify a JWT against the JWKS
1343
- */
1344
- async verify(e) {
1345
- return Xe(e, this.JWKS);
1346
- }
1335
+ const Z = /* @__PURE__ */ new Map();
1336
+ async function ct(e, t = `${ee}/.well-known/jwks.json`) {
1337
+ let r = Z.get(t);
1338
+ return r || (r = ot(new URL(t)), Z.set(t, r)), Qe(e, r);
1347
1339
  }
1348
- class ct {
1340
+ class ut {
1349
1341
  store = /* @__PURE__ */ new Map();
1350
- async get(e) {
1351
- return this.store.get(e) ?? null;
1342
+ async get(t) {
1343
+ return this.store.get(t) ?? null;
1352
1344
  }
1353
- async set(e, r) {
1354
- this.store.set(e, r);
1345
+ async set(t, r) {
1346
+ this.store.set(t, r);
1355
1347
  }
1356
- async remove(e) {
1357
- this.store.delete(e);
1348
+ async remove(t) {
1349
+ this.store.delete(t);
1358
1350
  }
1359
1351
  async clear() {
1360
1352
  this.store.clear();
1361
1353
  }
1362
1354
  }
1363
- class Z {
1355
+ class j {
1364
1356
  prefix;
1365
- constructor(e = "genation") {
1366
- this.prefix = e;
1357
+ constructor(t = "genation") {
1358
+ this.prefix = t;
1367
1359
  }
1368
- getKey(e) {
1369
- return `${this.prefix}:${e}`;
1360
+ getKey(t) {
1361
+ return `${this.prefix}:${t}`;
1370
1362
  }
1371
- async get(e) {
1372
- return typeof window > "u" ? null : localStorage.getItem(this.getKey(e));
1363
+ async get(t) {
1364
+ return typeof window > "u" ? null : localStorage.getItem(this.getKey(t));
1373
1365
  }
1374
- async set(e, r) {
1375
- typeof window > "u" || localStorage.setItem(this.getKey(e), r);
1366
+ async set(t, r) {
1367
+ typeof window > "u" || localStorage.setItem(this.getKey(t), r);
1376
1368
  }
1377
- async remove(e) {
1378
- typeof window > "u" || localStorage.removeItem(this.getKey(e));
1369
+ async remove(t) {
1370
+ typeof window > "u" || localStorage.removeItem(this.getKey(t));
1379
1371
  }
1380
1372
  async clear() {
1381
1373
  if (typeof window > "u") return;
@@ -1386,20 +1378,20 @@ class Z {
1386
1378
  }
1387
1379
  class ht {
1388
1380
  prefix;
1389
- constructor(e = "genation") {
1390
- this.prefix = e;
1381
+ constructor(t = "genation") {
1382
+ this.prefix = t;
1391
1383
  }
1392
- getKey(e) {
1393
- return `${this.prefix}:${e}`;
1384
+ getKey(t) {
1385
+ return `${this.prefix}:${t}`;
1394
1386
  }
1395
- async get(e) {
1396
- return typeof window > "u" ? null : sessionStorage.getItem(this.getKey(e));
1387
+ async get(t) {
1388
+ return typeof window > "u" ? null : sessionStorage.getItem(this.getKey(t));
1397
1389
  }
1398
- async set(e, r) {
1399
- typeof window > "u" || sessionStorage.setItem(this.getKey(e), r);
1390
+ async set(t, r) {
1391
+ typeof window > "u" || sessionStorage.setItem(this.getKey(t), r);
1400
1392
  }
1401
- async remove(e) {
1402
- typeof window > "u" || sessionStorage.removeItem(this.getKey(e));
1393
+ async remove(t) {
1394
+ typeof window > "u" || sessionStorage.removeItem(this.getKey(t));
1403
1395
  }
1404
1396
  async clear() {
1405
1397
  if (typeof window > "u") return;
@@ -1408,59 +1400,57 @@ class ht {
1408
1400
  ).forEach((r) => sessionStorage.removeItem(r));
1409
1401
  }
1410
1402
  }
1411
- function ut(t = "localStorage") {
1412
- switch (t) {
1403
+ function ft(e = "localStorage") {
1404
+ switch (e) {
1413
1405
  case "memory":
1414
- return new ct();
1406
+ return new ut();
1415
1407
  case "localStorage":
1416
- return new Z();
1408
+ return new j();
1417
1409
  case "sessionStorage":
1418
1410
  return new ht();
1419
1411
  default:
1420
- return new Z();
1412
+ return new j();
1421
1413
  }
1422
1414
  }
1423
- function H(t) {
1424
- return Array.isArray(t) ? t.map(H) : typeof t == "object" && t !== null ? Object.fromEntries(
1425
- Object.entries(t).map(([e, r]) => [
1426
- e.replace(/_([a-z])/g, (n, s) => s.toUpperCase()),
1415
+ function H(e) {
1416
+ return Array.isArray(e) ? e.map(H) : typeof e == "object" && e !== null ? Object.fromEntries(
1417
+ Object.entries(e).map(([t, r]) => [
1418
+ t.replace(/_([a-z])/g, (n, s) => s.toUpperCase()),
1427
1419
  H(r)
1428
1420
  ])
1429
- ) : t;
1421
+ ) : e;
1430
1422
  }
1431
- class ft {
1423
+ class dt {
1432
1424
  oauth;
1433
1425
  tokenManager;
1434
- tokenVerifier;
1426
+ jwksUrl;
1435
1427
  http;
1436
1428
  httpServer;
1437
1429
  listeners = /* @__PURE__ */ new Set();
1438
1430
  initialized = !1;
1439
- constructor(e) {
1440
- this.validateConfig(e);
1441
- const r = typeof e.storage == "object" ? e.storage : ut(e.storage), n = e.authUrl ?? "https://mnnoheowoowbtpuoguul.supabase.co/auth/v1";
1442
- this.tokenManager = new le(r), this.oauth = new ye(e, this.tokenManager), this.tokenVerifier = new ot(
1443
- `${n}/.well-known/jwks.json`
1444
- ), this.http = new D({
1431
+ constructor(t) {
1432
+ this.validateConfig(t);
1433
+ const r = typeof t.storage == "object" ? t.storage : ft(t.storage), n = t.authUrl ?? "https://mnnoheowoowbtpuoguul.supabase.co/auth/v1";
1434
+ this.tokenManager = new ye(r), this.oauth = new me(t, this.tokenManager), this.jwksUrl = `${n}/.well-known/jwks.json`, this.http = new D({
1445
1435
  baseUrl: n
1446
1436
  }), this.httpServer = new D({
1447
1437
  baseUrl: "https://ff-api.genation.ai/api/v2/client"
1448
1438
  });
1449
1439
  }
1450
- validateConfig(e) {
1451
- if (!e.clientId) throw v.missingField("clientId");
1452
- if (!e.clientSecret)
1440
+ validateConfig(t) {
1441
+ if (!t.clientId) throw v.missingField("clientId");
1442
+ if (!t.clientSecret)
1453
1443
  throw v.missingField("clientSecret");
1454
- if (!e.redirectUri) throw v.missingField("redirectUri");
1444
+ if (!t.redirectUri) throw v.missingField("redirectUri");
1455
1445
  }
1456
1446
  /**
1457
1447
  * Emit auth state change event to all listeners
1458
1448
  */
1459
- async emitAuthStateChange(e) {
1449
+ async emitAuthStateChange(t) {
1460
1450
  const r = await this.getSession();
1461
1451
  this.listeners.forEach((n) => {
1462
1452
  try {
1463
- n(e, r);
1453
+ n(t, r);
1464
1454
  } catch (s) {
1465
1455
  console.error("Error in auth state change callback:", s);
1466
1456
  }
@@ -1501,15 +1491,15 @@ class ft {
1501
1491
  * subscription.unsubscribe();
1502
1492
  * ```
1503
1493
  */
1504
- onAuthStateChange(e) {
1505
- return this.listeners.add(e), this.initialized ? setTimeout(() => {
1494
+ onAuthStateChange(t) {
1495
+ return this.listeners.add(t), this.initialized ? setTimeout(() => {
1506
1496
  this.emitAuthStateChange("INITIAL_SESSION");
1507
1497
  }, 0) : (this.initialized = !0, setTimeout(() => {
1508
1498
  this.emitAuthStateChange("INITIAL_SESSION");
1509
1499
  }, 0)), {
1510
1500
  subscription: {
1511
1501
  unsubscribe: () => {
1512
- this.listeners.delete(e);
1502
+ this.listeners.delete(t);
1513
1503
  }
1514
1504
  }
1515
1505
  };
@@ -1555,8 +1545,8 @@ class ft {
1555
1545
  * }
1556
1546
  * ```
1557
1547
  */
1558
- async handleCallback(e) {
1559
- const r = new URL(e), n = r.searchParams.get("code"), s = r.searchParams.get("state");
1548
+ async handleCallback(t) {
1549
+ const r = new URL(t), n = r.searchParams.get("code"), s = r.searchParams.get("state");
1560
1550
  if (!n || !s)
1561
1551
  throw new Error("Missing code or state");
1562
1552
  const a = await this.oauth.exchangeCode(n, s);
@@ -1627,8 +1617,8 @@ class ft {
1627
1617
  * @returns Decoded token payload if valid
1628
1618
  * @throws Error if token is invalid
1629
1619
  */
1630
- async verifyToken(e) {
1631
- const { payload: r } = await this.tokenVerifier.verify(e);
1620
+ async verifyToken(t) {
1621
+ const { payload: r } = await ct(t, this.jwksUrl);
1632
1622
  return r;
1633
1623
  }
1634
1624
  /**
@@ -1638,11 +1628,11 @@ class ft {
1638
1628
  * @param options.expiresAfter - Query licenses that are expired after the given date, default set to today to get all valid licenses (unexpired licenses)
1639
1629
  * @returns The licenses
1640
1630
  */
1641
- async getLicenses(e = {}) {
1631
+ async getLicenses(t = {}) {
1642
1632
  const r = await this.getSession();
1643
1633
  if (!r)
1644
1634
  return null;
1645
- const n = r.accessToken, { expiresAfter: s = /* @__PURE__ */ new Date() } = e, a = await this.httpServer.request("/licenses", {
1635
+ const n = r.accessToken, { expiresAfter: s = /* @__PURE__ */ new Date() } = t, a = await this.httpServer.request("/licenses", {
1646
1636
  headers: { Authorization: `Bearer ${n}` },
1647
1637
  params: { expiresAfter: s.toISOString() }
1648
1638
  });
@@ -1651,10 +1641,10 @@ class ft {
1651
1641
  /**
1652
1642
  * Fetch user info from auth server
1653
1643
  */
1654
- async fetchUser(e) {
1644
+ async fetchUser(t) {
1655
1645
  try {
1656
1646
  const r = await this.http.request("/oauth/userinfo", {
1657
- headers: { Authorization: `Bearer ${e}` }
1647
+ headers: { Authorization: `Bearer ${t}` }
1658
1648
  });
1659
1649
  return {
1660
1650
  sub: r.sub,
@@ -1670,19 +1660,20 @@ class ft {
1670
1660
  }
1671
1661
  }
1672
1662
  }
1673
- function dt(t) {
1674
- return new ft(t);
1663
+ function lt(e) {
1664
+ return new dt(e);
1675
1665
  }
1676
1666
  export {
1677
1667
  g as AuthError,
1678
1668
  v as ConfigError,
1679
- ft as GenationClient,
1669
+ dt as GenationClient,
1680
1670
  N as GenationError,
1681
- Z as LocalStorage,
1682
- ct as MemoryStorage,
1671
+ j as LocalStorage,
1672
+ ut as MemoryStorage,
1683
1673
  S as NetworkError,
1684
1674
  ht as SessionStorage,
1685
- dt as createClient,
1686
- ut as createStorage
1675
+ lt as createClient,
1676
+ ft as createStorage,
1677
+ ct as verifyToken
1687
1678
  };
1688
1679
  //# sourceMappingURL=genation.es.js.map