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