@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.
- package/README.md +11 -0
- package/dist/genation.cjs.js +1 -1
- package/dist/genation.cjs.js.map +1 -1
- package/dist/genation.es.js +511 -520
- 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 +12 -1
- package/package.json +1 -1
package/dist/genation.es.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
class N extends Error {
|
|
2
2
|
code;
|
|
3
3
|
cause;
|
|
4
|
-
constructor(
|
|
5
|
-
super(
|
|
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(
|
|
10
|
-
super(
|
|
9
|
+
constructor(t, r, n) {
|
|
10
|
+
super(t, r, n), this.name = "AuthError";
|
|
11
11
|
}
|
|
12
|
-
static invalidGrant(
|
|
13
|
-
return new g(
|
|
12
|
+
static invalidGrant(t = "Invalid authorization code or refresh token") {
|
|
13
|
+
return new g(t, "invalid_grant");
|
|
14
14
|
}
|
|
15
|
-
static accessDenied(
|
|
16
|
-
return new g(
|
|
15
|
+
static accessDenied(t = "User denied access") {
|
|
16
|
+
return new g(t, "access_denied");
|
|
17
17
|
}
|
|
18
|
-
static expiredToken(
|
|
19
|
-
return new g(
|
|
18
|
+
static expiredToken(t = "Token has expired") {
|
|
19
|
+
return new g(t, "expired_token");
|
|
20
20
|
}
|
|
21
|
-
static invalidState(
|
|
22
|
-
return new g(
|
|
21
|
+
static invalidState(t = "State mismatch, possible CSRF attack") {
|
|
22
|
+
return new g(t, "invalid_state");
|
|
23
23
|
}
|
|
24
|
-
static pkceVerificationFailed(
|
|
25
|
-
return new g(
|
|
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(
|
|
31
|
-
super(
|
|
30
|
+
constructor(t, r, n) {
|
|
31
|
+
super(t, "network_error", n), this.name = "NetworkError", this.status = r;
|
|
32
32
|
}
|
|
33
|
-
static fromResponse(
|
|
33
|
+
static fromResponse(t) {
|
|
34
34
|
return new S(
|
|
35
|
-
`HTTP ${
|
|
36
|
-
|
|
35
|
+
`HTTP ${t.status}: ${t.statusText}`,
|
|
36
|
+
t.status
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
class v extends N {
|
|
41
|
-
constructor(
|
|
42
|
-
super(
|
|
41
|
+
constructor(t) {
|
|
42
|
+
super(t, "config_error"), this.name = "ConfigError";
|
|
43
43
|
}
|
|
44
|
-
static missingField(
|
|
45
|
-
return new v(`Missing required config field: ${
|
|
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(
|
|
52
|
-
this.baseUrl =
|
|
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(
|
|
57
|
+
async request(t, r = {}) {
|
|
58
58
|
const { method: n = "GET", headers: s = {}, body: a, params: i } = r;
|
|
59
|
-
let c = `${this.baseUrl}${
|
|
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
|
|
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:
|
|
73
|
+
signal: h.signal
|
|
74
74
|
});
|
|
75
|
-
if (clearTimeout(
|
|
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(
|
|
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(
|
|
86
|
-
const s = `${this.baseUrl}${
|
|
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 $(
|
|
106
|
-
return btoa(String.fromCharCode(...
|
|
105
|
+
function $(e) {
|
|
106
|
+
return btoa(String.fromCharCode(...e)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
return crypto.getRandomValues(
|
|
108
|
+
function fe() {
|
|
109
|
+
const e = new Uint8Array(32);
|
|
110
|
+
return crypto.getRandomValues(e), $(e);
|
|
111
111
|
}
|
|
112
|
-
async function
|
|
113
|
-
const r = new TextEncoder().encode(
|
|
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
|
|
117
|
-
const
|
|
116
|
+
async function le() {
|
|
117
|
+
const e = fe(), t = await de(e);
|
|
118
118
|
return {
|
|
119
|
-
codeVerifier:
|
|
120
|
-
codeChallenge:
|
|
119
|
+
codeVerifier: e,
|
|
120
|
+
codeChallenge: t,
|
|
121
121
|
codeChallengeMethod: "S256"
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
-
function
|
|
125
|
-
const
|
|
126
|
-
return crypto.getRandomValues(
|
|
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
|
|
129
|
+
class ye {
|
|
130
130
|
storage;
|
|
131
|
-
constructor(
|
|
132
|
-
this.storage =
|
|
131
|
+
constructor(t) {
|
|
132
|
+
this.storage = t;
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
135
|
* Store token set
|
|
136
136
|
*/
|
|
137
|
-
async setTokens(
|
|
138
|
-
await this.storage.set(W, JSON.stringify(
|
|
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
|
|
145
|
-
if (!
|
|
144
|
+
const t = await this.storage.get(W);
|
|
145
|
+
if (!t) return null;
|
|
146
146
|
try {
|
|
147
|
-
return JSON.parse(
|
|
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
|
|
163
|
-
if (!
|
|
164
|
-
const r =
|
|
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(
|
|
171
|
-
await this.storage.set(k,
|
|
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
|
|
178
|
-
return
|
|
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(
|
|
184
|
-
await this.storage.set(I,
|
|
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
|
|
191
|
-
return
|
|
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
|
|
201
|
-
class
|
|
200
|
+
const ee = "https://mnnoheowoowbtpuoguul.supabase.co/auth/v1";
|
|
201
|
+
class me {
|
|
202
202
|
config;
|
|
203
203
|
http;
|
|
204
204
|
tokenManager;
|
|
205
|
-
constructor(
|
|
205
|
+
constructor(t, r) {
|
|
206
206
|
this.config = {
|
|
207
|
-
clientId:
|
|
208
|
-
clientSecret:
|
|
209
|
-
redirectUri:
|
|
210
|
-
scopes:
|
|
211
|
-
authUrl:
|
|
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
|
|
220
|
-
await this.tokenManager.setPKCE(
|
|
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:
|
|
227
|
-
code_challenge_method:
|
|
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(
|
|
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:
|
|
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
|
|
259
|
-
if (!
|
|
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:
|
|
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
|
|
277
|
-
if (
|
|
276
|
+
const t = await this.tokenManager.getTokens();
|
|
277
|
+
if (t)
|
|
278
278
|
try {
|
|
279
279
|
await this.http.postForm("/oauth/revoke", {
|
|
280
|
-
token:
|
|
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(
|
|
291
|
+
mapTokenResponse(t) {
|
|
292
292
|
return {
|
|
293
|
-
accessToken:
|
|
294
|
-
refreshToken:
|
|
295
|
-
tokenType:
|
|
296
|
-
expiresIn:
|
|
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:
|
|
298
|
+
scope: t.scope
|
|
299
299
|
};
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
const G = new TextEncoder(), _ = new TextDecoder();
|
|
303
|
-
function
|
|
304
|
-
const
|
|
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
|
|
306
|
+
for (const s of e)
|
|
307
307
|
r.set(s, n), n += s.length;
|
|
308
308
|
return r;
|
|
309
309
|
}
|
|
310
|
-
function J(
|
|
311
|
-
const
|
|
312
|
-
for (let r = 0; r <
|
|
313
|
-
const n =
|
|
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
|
-
|
|
316
|
+
t[r] = n;
|
|
317
317
|
}
|
|
318
|
-
return
|
|
318
|
+
return t;
|
|
319
319
|
}
|
|
320
|
-
function
|
|
320
|
+
function Se(e) {
|
|
321
321
|
if (Uint8Array.fromBase64)
|
|
322
|
-
return Uint8Array.fromBase64(
|
|
323
|
-
const
|
|
324
|
-
for (let n = 0; n <
|
|
325
|
-
r[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(
|
|
328
|
+
function C(e) {
|
|
329
329
|
if (Uint8Array.fromBase64)
|
|
330
|
-
return Uint8Array.fromBase64(typeof
|
|
330
|
+
return Uint8Array.fromBase64(typeof e == "string" ? e : _.decode(e), {
|
|
331
331
|
alphabet: "base64url"
|
|
332
332
|
});
|
|
333
|
-
let
|
|
334
|
-
|
|
333
|
+
let t = e;
|
|
334
|
+
t instanceof Uint8Array && (t = _.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/");
|
|
335
335
|
try {
|
|
336
|
-
return
|
|
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(
|
|
345
|
-
super(
|
|
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(
|
|
355
|
-
super(
|
|
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(
|
|
365
|
-
super(
|
|
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
|
|
376
|
+
class te extends l {
|
|
377
377
|
static code = "ERR_JWT_INVALID";
|
|
378
378
|
code = "ERR_JWT_INVALID";
|
|
379
379
|
}
|
|
380
|
-
class
|
|
380
|
+
class re extends l {
|
|
381
381
|
static code = "ERR_JWKS_INVALID";
|
|
382
382
|
code = "ERR_JWKS_INVALID";
|
|
383
383
|
}
|
|
384
|
-
class
|
|
384
|
+
class ne extends l {
|
|
385
385
|
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
386
386
|
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
387
|
-
constructor(
|
|
388
|
-
super(
|
|
387
|
+
constructor(t = "no applicable key found in the JSON Web Key Set", r) {
|
|
388
|
+
super(t, r);
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
|
-
class
|
|
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(
|
|
396
|
-
super(
|
|
395
|
+
constructor(t = "multiple matching keys found in the JSON Web Key Set", r) {
|
|
396
|
+
super(t, r);
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
|
-
class
|
|
399
|
+
class be extends l {
|
|
400
400
|
static code = "ERR_JWKS_TIMEOUT";
|
|
401
401
|
code = "ERR_JWKS_TIMEOUT";
|
|
402
|
-
constructor(
|
|
403
|
-
super(
|
|
402
|
+
constructor(t = "request timed out", r) {
|
|
403
|
+
super(t, r);
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
|
-
class
|
|
406
|
+
class Ee extends l {
|
|
407
407
|
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
408
408
|
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
409
|
-
constructor(
|
|
410
|
-
super(
|
|
409
|
+
constructor(t = "signature verification failed", r) {
|
|
410
|
+
super(t, r);
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
|
-
const m = (
|
|
414
|
-
function
|
|
415
|
-
return parseInt(
|
|
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
|
|
418
|
-
switch (
|
|
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
|
|
430
|
-
if (!
|
|
431
|
-
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${
|
|
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
|
|
434
|
-
switch (
|
|
433
|
+
function Te(e, t, r) {
|
|
434
|
+
switch (t) {
|
|
435
435
|
case "HS256":
|
|
436
436
|
case "HS384":
|
|
437
437
|
case "HS512": {
|
|
438
|
-
if (!A(
|
|
438
|
+
if (!A(e.algorithm, "HMAC"))
|
|
439
439
|
throw m("HMAC");
|
|
440
|
-
const n = parseInt(
|
|
441
|
-
if (
|
|
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(
|
|
448
|
+
if (!A(e.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
449
449
|
throw m("RSASSA-PKCS1-v1_5");
|
|
450
|
-
const n = parseInt(
|
|
451
|
-
if (
|
|
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(
|
|
458
|
+
if (!A(e.algorithm, "RSA-PSS"))
|
|
459
459
|
throw m("RSA-PSS");
|
|
460
|
-
const n = parseInt(
|
|
461
|
-
if (
|
|
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(
|
|
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(
|
|
475
|
-
throw m(
|
|
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(
|
|
481
|
+
if (!A(e.algorithm, "ECDSA"))
|
|
482
482
|
throw m("ECDSA");
|
|
483
|
-
const n =
|
|
484
|
-
if (
|
|
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
|
-
|
|
491
|
+
Ke(e, r);
|
|
492
492
|
}
|
|
493
|
-
function
|
|
493
|
+
function se(e, t, ...r) {
|
|
494
494
|
if (r = r.filter(Boolean), r.length > 2) {
|
|
495
495
|
const n = r.pop();
|
|
496
|
-
|
|
497
|
-
} else r.length === 2 ?
|
|
498
|
-
return
|
|
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
|
|
501
|
-
if (
|
|
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
|
|
504
|
+
return e instanceof CryptoKey;
|
|
505
505
|
} catch {
|
|
506
506
|
return !1;
|
|
507
507
|
}
|
|
508
|
-
},
|
|
509
|
-
function
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
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
|
|
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
|
|
529
|
-
function E(
|
|
530
|
-
if (!
|
|
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(
|
|
532
|
+
if (Object.getPrototypeOf(e) === null)
|
|
533
533
|
return !0;
|
|
534
|
-
let
|
|
535
|
-
for (; Object.getPrototypeOf(
|
|
536
|
-
|
|
537
|
-
return Object.getPrototypeOf(
|
|
538
|
-
}
|
|
539
|
-
function
|
|
540
|
-
if (
|
|
541
|
-
const { modulusLength: r } =
|
|
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(`${
|
|
543
|
+
throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
|
-
function
|
|
547
|
-
let
|
|
548
|
-
switch (
|
|
546
|
+
function Pe(e) {
|
|
547
|
+
let t, r;
|
|
548
|
+
switch (e.kty) {
|
|
549
549
|
case "AKP": {
|
|
550
|
-
switch (
|
|
550
|
+
switch (e.alg) {
|
|
551
551
|
case "ML-DSA-44":
|
|
552
552
|
case "ML-DSA-65":
|
|
553
553
|
case "ML-DSA-87":
|
|
554
|
-
|
|
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 (
|
|
562
|
+
switch (e.alg) {
|
|
563
563
|
case "PS256":
|
|
564
564
|
case "PS384":
|
|
565
565
|
case "PS512":
|
|
566
|
-
|
|
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
|
-
|
|
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
|
-
|
|
577
|
+
t = {
|
|
578
578
|
name: "RSA-OAEP",
|
|
579
|
-
hash: `SHA-${parseInt(
|
|
580
|
-
}, r =
|
|
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 (
|
|
588
|
+
switch (e.alg) {
|
|
589
589
|
case "ES256":
|
|
590
|
-
|
|
590
|
+
t = { name: "ECDSA", namedCurve: "P-256" }, r = e.d ? ["sign"] : ["verify"];
|
|
591
591
|
break;
|
|
592
592
|
case "ES384":
|
|
593
|
-
|
|
593
|
+
t = { name: "ECDSA", namedCurve: "P-384" }, r = e.d ? ["sign"] : ["verify"];
|
|
594
594
|
break;
|
|
595
595
|
case "ES512":
|
|
596
|
-
|
|
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
|
-
|
|
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 (
|
|
610
|
+
switch (e.alg) {
|
|
611
611
|
case "Ed25519":
|
|
612
612
|
case "EdDSA":
|
|
613
|
-
|
|
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
|
-
|
|
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:
|
|
629
|
+
return { algorithm: t, keyUsages: r };
|
|
630
630
|
}
|
|
631
|
-
async function R(
|
|
632
|
-
if (!
|
|
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:
|
|
635
|
-
return n.kty !== "AKP" && delete n.alg, delete n.use, crypto.subtle.importKey("jwk", n,
|
|
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
|
|
638
|
-
if (!E(
|
|
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 (
|
|
641
|
+
switch (t ??= e.alg, n ??= e.ext, e.kty) {
|
|
642
642
|
case "oct":
|
|
643
|
-
if (typeof
|
|
643
|
+
if (typeof e.k != "string" || !e.k)
|
|
644
644
|
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
645
|
-
return C(
|
|
645
|
+
return C(e.k);
|
|
646
646
|
case "RSA":
|
|
647
|
-
if ("oth" in
|
|
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({ ...
|
|
649
|
+
return R({ ...e, alg: t, ext: n });
|
|
650
650
|
case "AKP": {
|
|
651
|
-
if (typeof
|
|
651
|
+
if (typeof e.alg != "string" || !e.alg)
|
|
652
652
|
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
653
|
-
if (
|
|
653
|
+
if (t !== void 0 && t !== e.alg)
|
|
654
654
|
throw new TypeError("JWK alg and alg option value mismatch");
|
|
655
|
-
return R({ ...
|
|
655
|
+
return R({ ...e, ext: n });
|
|
656
656
|
}
|
|
657
657
|
case "EC":
|
|
658
658
|
case "OKP":
|
|
659
|
-
return R({ ...
|
|
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
|
|
664
|
+
function ke(e, t, r, n, s) {
|
|
665
665
|
if (s.crit !== void 0 && n?.crit === void 0)
|
|
666
|
-
throw new
|
|
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
|
|
670
|
+
throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
671
671
|
let a;
|
|
672
|
-
a =
|
|
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
|
|
677
|
+
throw new e(`Extension Header Parameter "${i}" is missing`);
|
|
678
678
|
if (a.get(i) && n[i] === void 0)
|
|
679
|
-
throw new
|
|
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 = (
|
|
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 (
|
|
685
|
+
const B = async (e, t, r, n = !1) => {
|
|
686
686
|
T ||= /* @__PURE__ */ new WeakMap();
|
|
687
|
-
let s = T.get(
|
|
687
|
+
let s = T.get(e);
|
|
688
688
|
if (s?.[r])
|
|
689
689
|
return s[r];
|
|
690
|
-
const a = await R({ ...
|
|
691
|
-
return n && Object.freeze(
|
|
692
|
-
}, Ue = (
|
|
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(
|
|
695
|
-
if (r?.[
|
|
696
|
-
return r[
|
|
697
|
-
const 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 (
|
|
700
|
-
switch (
|
|
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 =
|
|
709
|
+
a = e.toCryptoKey(e.asymmetricKeyType, s, n ? [] : ["deriveBits"]);
|
|
710
710
|
}
|
|
711
|
-
if (
|
|
712
|
-
if (
|
|
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 =
|
|
714
|
+
a = e.toCryptoKey(e.asymmetricKeyType, s, [
|
|
715
715
|
n ? "verify" : "sign"
|
|
716
716
|
]);
|
|
717
717
|
}
|
|
718
|
-
switch (
|
|
718
|
+
switch (e.asymmetricKeyType) {
|
|
719
719
|
case "ml-dsa-44":
|
|
720
720
|
case "ml-dsa-65":
|
|
721
721
|
case "ml-dsa-87": {
|
|
722
|
-
if (
|
|
722
|
+
if (t !== e.asymmetricKeyType.toUpperCase())
|
|
723
723
|
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
724
|
-
a =
|
|
724
|
+
a = e.toCryptoKey(e.asymmetricKeyType, s, [
|
|
725
725
|
n ? "verify" : "sign"
|
|
726
726
|
]);
|
|
727
727
|
}
|
|
728
728
|
}
|
|
729
|
-
if (
|
|
729
|
+
if (e.asymmetricKeyType === "rsa") {
|
|
730
730
|
let i;
|
|
731
|
-
switch (
|
|
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 (
|
|
754
|
-
return
|
|
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 =
|
|
759
|
-
name:
|
|
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 (
|
|
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(
|
|
768
|
+
])).get(e.asymmetricKeyDetails?.namedCurve);
|
|
769
769
|
if (!c)
|
|
770
770
|
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
771
|
-
|
|
771
|
+
t === "ES256" && c === "P-256" && (a = e.toCryptoKey({
|
|
772
772
|
name: "ECDSA",
|
|
773
773
|
namedCurve: c
|
|
774
|
-
}, s, [n ? "verify" : "sign"])),
|
|
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"])),
|
|
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"])),
|
|
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[
|
|
787
|
+
return r ? r[t] = a : T.set(e, { [t]: a }), a;
|
|
788
788
|
};
|
|
789
|
-
async function
|
|
790
|
-
if (
|
|
791
|
-
return
|
|
792
|
-
if (
|
|
793
|
-
if (
|
|
794
|
-
return
|
|
795
|
-
if ("toCryptoKey" in
|
|
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(
|
|
797
|
+
return Ue(e, t);
|
|
798
798
|
} catch (n) {
|
|
799
799
|
if (n instanceof TypeError)
|
|
800
800
|
throw n;
|
|
801
801
|
}
|
|
802
|
-
let r =
|
|
803
|
-
return B(
|
|
802
|
+
let r = e.export({ format: "jwk" });
|
|
803
|
+
return B(e, r, t);
|
|
804
804
|
}
|
|
805
|
-
if (L(
|
|
806
|
-
return
|
|
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 = (
|
|
810
|
-
if (
|
|
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 (
|
|
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 (
|
|
826
|
-
throw new TypeError(`Invalid key for this operation, its "alg" must be "${
|
|
827
|
-
if (Array.isArray(
|
|
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
|
|
832
|
-
case
|
|
831
|
+
case e === "dir":
|
|
832
|
+
case e.includes("CBC-HS"):
|
|
833
833
|
n = r;
|
|
834
834
|
break;
|
|
835
|
-
case
|
|
835
|
+
case e.startsWith("PBES2"):
|
|
836
836
|
n = "deriveBits";
|
|
837
837
|
break;
|
|
838
|
-
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(
|
|
839
|
-
!
|
|
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 =
|
|
845
|
+
n = e.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
846
846
|
break;
|
|
847
847
|
}
|
|
848
|
-
if (n &&
|
|
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
|
-
},
|
|
853
|
-
if (!(
|
|
854
|
-
if (L(
|
|
855
|
-
if (
|
|
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 (!
|
|
860
|
-
throw new TypeError(
|
|
861
|
-
if (
|
|
862
|
-
throw new TypeError(`${K(
|
|
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 = (
|
|
865
|
-
if (L(
|
|
864
|
+
}, Oe = (e, t, r) => {
|
|
865
|
+
if (L(t))
|
|
866
866
|
switch (r) {
|
|
867
867
|
case "decrypt":
|
|
868
868
|
case "sign":
|
|
869
|
-
if (
|
|
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 (
|
|
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 (!
|
|
879
|
-
throw new TypeError(
|
|
880
|
-
if (
|
|
881
|
-
throw new TypeError(`${K(
|
|
882
|
-
if (
|
|
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(
|
|
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(
|
|
887
|
+
throw new TypeError(`${K(t)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
888
888
|
}
|
|
889
|
-
if (
|
|
889
|
+
if (t.type === "private")
|
|
890
890
|
switch (r) {
|
|
891
891
|
case "verify":
|
|
892
|
-
throw new TypeError(`${K(
|
|
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(
|
|
894
|
+
throw new TypeError(`${K(t)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
895
895
|
}
|
|
896
896
|
};
|
|
897
|
-
function
|
|
898
|
-
switch (
|
|
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
|
-
|
|
904
|
+
Me(e, t, r);
|
|
905
905
|
break;
|
|
906
906
|
default:
|
|
907
|
-
Oe(
|
|
907
|
+
Oe(e, t, r);
|
|
908
908
|
}
|
|
909
909
|
}
|
|
910
|
-
function
|
|
911
|
-
const r = `SHA-${
|
|
912
|
-
switch (
|
|
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(
|
|
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:
|
|
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:
|
|
935
|
+
return { name: e };
|
|
936
936
|
default:
|
|
937
|
-
throw new w(`alg ${
|
|
937
|
+
throw new w(`alg ${e} is not supported either by JOSE or your javascript runtime`);
|
|
938
938
|
}
|
|
939
939
|
}
|
|
940
|
-
async function
|
|
941
|
-
if (
|
|
942
|
-
if (!
|
|
943
|
-
throw new TypeError(
|
|
944
|
-
return crypto.subtle.importKey("raw",
|
|
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
|
|
946
|
+
return Te(t, e, r), t;
|
|
947
947
|
}
|
|
948
|
-
async function
|
|
949
|
-
const s = await
|
|
950
|
-
|
|
951
|
-
const a =
|
|
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
|
|
959
|
-
if (!E(
|
|
958
|
+
async function Fe(e, t, r) {
|
|
959
|
+
if (!E(e))
|
|
960
960
|
throw new f("Flattened JWS must be an object");
|
|
961
|
-
if (
|
|
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 (
|
|
963
|
+
if (e.protected !== void 0 && typeof e.protected != "string")
|
|
964
964
|
throw new f("JWS Protected Header incorrect type");
|
|
965
|
-
if (
|
|
965
|
+
if (e.payload === void 0)
|
|
966
966
|
throw new f("JWS Payload missing");
|
|
967
|
-
if (typeof
|
|
967
|
+
if (typeof e.signature != "string")
|
|
968
968
|
throw new f("JWS Signature missing or incorrect type");
|
|
969
|
-
if (
|
|
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 (
|
|
972
|
+
if (e.protected)
|
|
973
973
|
try {
|
|
974
|
-
const P = C(
|
|
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 (!
|
|
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
|
-
...
|
|
984
|
-
}, a =
|
|
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
|
|
992
|
+
if (typeof e.payload != "string")
|
|
993
993
|
throw new f("JWS Payload must be a string");
|
|
994
|
-
} else if (typeof
|
|
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
|
|
997
|
-
typeof
|
|
998
|
-
const
|
|
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(
|
|
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
|
|
1006
|
-
if (!await
|
|
1007
|
-
throw new
|
|
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(
|
|
1011
|
+
b = C(e.payload);
|
|
1012
1012
|
} catch {
|
|
1013
1013
|
throw new f("Failed to base64url decode the payload");
|
|
1014
1014
|
}
|
|
1015
|
-
else typeof
|
|
1015
|
+
else typeof e.payload == "string" ? b = G.encode(e.payload) : b = e.payload;
|
|
1016
1016
|
const p = { payload: b };
|
|
1017
|
-
return
|
|
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
|
|
1020
|
-
if (
|
|
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 } =
|
|
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
|
|
1026
|
-
return typeof
|
|
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
|
|
1029
|
-
function q(
|
|
1030
|
-
const
|
|
1031
|
-
if (!
|
|
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(
|
|
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 *
|
|
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 *
|
|
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 *
|
|
1065
|
+
s = Math.round(r * ze);
|
|
1066
1066
|
break;
|
|
1067
1067
|
default:
|
|
1068
|
-
s = Math.round(r *
|
|
1068
|
+
s = Math.round(r * Be);
|
|
1069
1069
|
break;
|
|
1070
1070
|
}
|
|
1071
|
-
return
|
|
1071
|
+
return t[1] === "-" || t[4] === "ago" ? -s : s;
|
|
1072
1072
|
}
|
|
1073
|
-
const Y = (
|
|
1074
|
-
function
|
|
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(
|
|
1077
|
+
n = JSON.parse(_.decode(t));
|
|
1078
1078
|
} catch {
|
|
1079
1079
|
}
|
|
1080
1080
|
if (!E(n))
|
|
1081
|
-
throw new
|
|
1081
|
+
throw new te("JWT Claims Set must be a top-level JSON object");
|
|
1082
1082
|
const { typ: s } = r;
|
|
1083
|
-
if (s && (typeof
|
|
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:
|
|
1086
|
-
|
|
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 (
|
|
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 =
|
|
1111
|
-
if ((n.iat !== void 0 ||
|
|
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 (
|
|
1126
|
-
const p = b - n.iat, P = typeof
|
|
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
|
|
1135
|
-
const n = await
|
|
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
|
|
1138
|
-
const a = { payload:
|
|
1139
|
-
return typeof
|
|
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
|
|
1142
|
-
switch (typeof
|
|
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
|
|
1157
|
-
return
|
|
1156
|
+
function je(e) {
|
|
1157
|
+
return e && typeof e == "object" && Array.isArray(e.keys) && e.keys.every(et);
|
|
1158
1158
|
}
|
|
1159
|
-
function
|
|
1160
|
-
return E(
|
|
1159
|
+
function et(e) {
|
|
1160
|
+
return E(e);
|
|
1161
1161
|
}
|
|
1162
|
-
class
|
|
1162
|
+
class tt {
|
|
1163
1163
|
#r;
|
|
1164
1164
|
#i = /* @__PURE__ */ new WeakMap();
|
|
1165
|
-
constructor(
|
|
1166
|
-
if (!
|
|
1167
|
-
throw new
|
|
1168
|
-
this.#r = structuredClone(
|
|
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(
|
|
1174
|
-
const { alg: n, kid: s } = { ...
|
|
1175
|
-
let o = a ===
|
|
1176
|
-
if (o && typeof s == "string" && (o = s ===
|
|
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 =
|
|
1179
|
+
o = u.crv === "P-256";
|
|
1180
1180
|
break;
|
|
1181
1181
|
case "ES384":
|
|
1182
|
-
o =
|
|
1182
|
+
o = u.crv === "P-384";
|
|
1183
1183
|
break;
|
|
1184
1184
|
case "ES512":
|
|
1185
|
-
o =
|
|
1185
|
+
o = u.crv === "P-521";
|
|
1186
1186
|
break;
|
|
1187
1187
|
case "Ed25519":
|
|
1188
1188
|
case "EdDSA":
|
|
1189
|
-
o =
|
|
1189
|
+
o = u.crv === "Ed25519";
|
|
1190
1190
|
break;
|
|
1191
1191
|
}
|
|
1192
1192
|
return o;
|
|
1193
|
-
}), { 0: c, length:
|
|
1194
|
-
if (
|
|
1195
|
-
throw new
|
|
1196
|
-
if (
|
|
1197
|
-
const
|
|
1198
|
-
throw
|
|
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
|
-
},
|
|
1204
|
+
}, u;
|
|
1205
1205
|
}
|
|
1206
1206
|
return X(this.#i, c, n);
|
|
1207
1207
|
}
|
|
1208
1208
|
}
|
|
1209
|
-
async function X(
|
|
1210
|
-
const n =
|
|
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
|
|
1212
|
+
const s = await We({ ...t, ext: !0 }, r);
|
|
1213
1213
|
if (s instanceof Uint8Array || s.type !== "public")
|
|
1214
|
-
throw new
|
|
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(
|
|
1220
|
-
const
|
|
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(
|
|
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
|
|
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
|
|
1234
|
-
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (
|
|
1235
|
-
const
|
|
1236
|
-
async function
|
|
1237
|
-
const s = await n(
|
|
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:
|
|
1241
|
+
headers: t
|
|
1242
1242
|
}).catch((a) => {
|
|
1243
|
-
throw a.name === "TimeoutError" ? new
|
|
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
|
|
1254
|
-
function
|
|
1255
|
-
return !(typeof
|
|
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
|
|
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
|
-
#
|
|
1265
|
+
#u;
|
|
1266
1266
|
#s;
|
|
1267
1267
|
#a;
|
|
1268
|
-
constructor(
|
|
1269
|
-
if (!(
|
|
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(
|
|
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(
|
|
1285
|
+
async getKey(t, r) {
|
|
1286
1286
|
(!this.#s || !this.fresh()) && await this.reload();
|
|
1287
1287
|
try {
|
|
1288
|
-
return await this.#s(
|
|
1288
|
+
return await this.#s(t, r);
|
|
1289
1289
|
} catch (n) {
|
|
1290
|
-
if (n instanceof
|
|
1291
|
-
return await this.reload(), this.#s(
|
|
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 &&
|
|
1297
|
-
this.#s = Q(
|
|
1298
|
-
}).catch((
|
|
1299
|
-
throw this.#e = void 0,
|
|
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
|
|
1304
|
-
const r = new
|
|
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
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
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
|
|
1340
|
+
class ut {
|
|
1349
1341
|
store = /* @__PURE__ */ new Map();
|
|
1350
|
-
async get(
|
|
1351
|
-
return this.store.get(
|
|
1342
|
+
async get(t) {
|
|
1343
|
+
return this.store.get(t) ?? null;
|
|
1352
1344
|
}
|
|
1353
|
-
async set(
|
|
1354
|
-
this.store.set(
|
|
1345
|
+
async set(t, r) {
|
|
1346
|
+
this.store.set(t, r);
|
|
1355
1347
|
}
|
|
1356
|
-
async remove(
|
|
1357
|
-
this.store.delete(
|
|
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
|
|
1355
|
+
class j {
|
|
1364
1356
|
prefix;
|
|
1365
|
-
constructor(
|
|
1366
|
-
this.prefix =
|
|
1357
|
+
constructor(t = "genation") {
|
|
1358
|
+
this.prefix = t;
|
|
1367
1359
|
}
|
|
1368
|
-
getKey(
|
|
1369
|
-
return `${this.prefix}:${
|
|
1360
|
+
getKey(t) {
|
|
1361
|
+
return `${this.prefix}:${t}`;
|
|
1370
1362
|
}
|
|
1371
|
-
async get(
|
|
1372
|
-
return typeof window > "u" ? null : localStorage.getItem(this.getKey(
|
|
1363
|
+
async get(t) {
|
|
1364
|
+
return typeof window > "u" ? null : localStorage.getItem(this.getKey(t));
|
|
1373
1365
|
}
|
|
1374
|
-
async set(
|
|
1375
|
-
typeof window > "u" || localStorage.setItem(this.getKey(
|
|
1366
|
+
async set(t, r) {
|
|
1367
|
+
typeof window > "u" || localStorage.setItem(this.getKey(t), r);
|
|
1376
1368
|
}
|
|
1377
|
-
async remove(
|
|
1378
|
-
typeof window > "u" || localStorage.removeItem(this.getKey(
|
|
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(
|
|
1390
|
-
this.prefix =
|
|
1381
|
+
constructor(t = "genation") {
|
|
1382
|
+
this.prefix = t;
|
|
1391
1383
|
}
|
|
1392
|
-
getKey(
|
|
1393
|
-
return `${this.prefix}:${
|
|
1384
|
+
getKey(t) {
|
|
1385
|
+
return `${this.prefix}:${t}`;
|
|
1394
1386
|
}
|
|
1395
|
-
async get(
|
|
1396
|
-
return typeof window > "u" ? null : sessionStorage.getItem(this.getKey(
|
|
1387
|
+
async get(t) {
|
|
1388
|
+
return typeof window > "u" ? null : sessionStorage.getItem(this.getKey(t));
|
|
1397
1389
|
}
|
|
1398
|
-
async set(
|
|
1399
|
-
typeof window > "u" || sessionStorage.setItem(this.getKey(
|
|
1390
|
+
async set(t, r) {
|
|
1391
|
+
typeof window > "u" || sessionStorage.setItem(this.getKey(t), r);
|
|
1400
1392
|
}
|
|
1401
|
-
async remove(
|
|
1402
|
-
typeof window > "u" || sessionStorage.removeItem(this.getKey(
|
|
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
|
|
1412
|
-
switch (
|
|
1403
|
+
function ft(e = "localStorage") {
|
|
1404
|
+
switch (e) {
|
|
1413
1405
|
case "memory":
|
|
1414
|
-
return new
|
|
1406
|
+
return new ut();
|
|
1415
1407
|
case "localStorage":
|
|
1416
|
-
return new
|
|
1408
|
+
return new j();
|
|
1417
1409
|
case "sessionStorage":
|
|
1418
1410
|
return new ht();
|
|
1419
1411
|
default:
|
|
1420
|
-
return new
|
|
1412
|
+
return new j();
|
|
1421
1413
|
}
|
|
1422
1414
|
}
|
|
1423
|
-
function H(
|
|
1424
|
-
return Array.isArray(
|
|
1425
|
-
Object.entries(
|
|
1426
|
-
|
|
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
|
-
) :
|
|
1421
|
+
) : e;
|
|
1430
1422
|
}
|
|
1431
|
-
class
|
|
1423
|
+
class dt {
|
|
1432
1424
|
oauth;
|
|
1433
1425
|
tokenManager;
|
|
1434
|
-
|
|
1426
|
+
jwksUrl;
|
|
1435
1427
|
http;
|
|
1436
1428
|
httpServer;
|
|
1437
1429
|
listeners = /* @__PURE__ */ new Set();
|
|
1438
1430
|
initialized = !1;
|
|
1439
|
-
constructor(
|
|
1440
|
-
this.validateConfig(
|
|
1441
|
-
const r = typeof
|
|
1442
|
-
this.tokenManager = new
|
|
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(
|
|
1451
|
-
if (!
|
|
1452
|
-
if (!
|
|
1440
|
+
validateConfig(t) {
|
|
1441
|
+
if (!t.clientId) throw v.missingField("clientId");
|
|
1442
|
+
if (!t.clientSecret)
|
|
1453
1443
|
throw v.missingField("clientSecret");
|
|
1454
|
-
if (!
|
|
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(
|
|
1449
|
+
async emitAuthStateChange(t) {
|
|
1460
1450
|
const r = await this.getSession();
|
|
1461
1451
|
this.listeners.forEach((n) => {
|
|
1462
1452
|
try {
|
|
1463
|
-
n(
|
|
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(
|
|
1505
|
-
return this.listeners.add(
|
|
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(
|
|
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(
|
|
1559
|
-
const r = new URL(
|
|
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(
|
|
1631
|
-
const { payload: r } = await this.
|
|
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(
|
|
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() } =
|
|
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(
|
|
1644
|
+
async fetchUser(t) {
|
|
1655
1645
|
try {
|
|
1656
1646
|
const r = await this.http.request("/oauth/userinfo", {
|
|
1657
|
-
headers: { Authorization: `Bearer ${
|
|
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
|
|
1674
|
-
return new
|
|
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
|
-
|
|
1669
|
+
dt as GenationClient,
|
|
1680
1670
|
N as GenationError,
|
|
1681
|
-
|
|
1682
|
-
|
|
1671
|
+
j as LocalStorage,
|
|
1672
|
+
ut as MemoryStorage,
|
|
1683
1673
|
S as NetworkError,
|
|
1684
1674
|
ht as SessionStorage,
|
|
1685
|
-
|
|
1686
|
-
|
|
1675
|
+
lt as createClient,
|
|
1676
|
+
ft as createStorage,
|
|
1677
|
+
ct as verifyToken
|
|
1687
1678
|
};
|
|
1688
1679
|
//# sourceMappingURL=genation.es.js.map
|