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