@rio.js/enterprise 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -0
- package/dist/adapter-factory-BTRALCLD-kJBwe70v.mjs +836 -0
- package/dist/better-auth-CStoaWiq.d.mts +10 -0
- package/dist/better-auth-CqfhQJYE.mjs +558 -0
- package/dist/better-auth.d.mts +2 -0
- package/dist/better-auth.mjs +17 -0
- package/dist/bun-sqlite-dialect-2R9nCsVF-DFs6tpGr.mjs +155 -0
- package/dist/client--1_AEBPu-8Ae9icC9.mjs +125 -0
- package/dist/client.d.mts +17 -0
- package/dist/client.mjs +381 -0
- package/dist/db-BVXTgOd3.mjs +681 -0
- package/dist/db-BadqSwVl.d.mts +9542 -0
- package/dist/db-schema.final-DWleoQm0.mjs +785 -0
- package/dist/db.d.mts +2 -0
- package/dist/db.mjs +3 -0
- package/dist/dialect-C6_pK3V9-CPJHWkYR.mjs +72 -0
- package/dist/dist-CygcgJYk.mjs +422 -0
- package/dist/env-DwlNAN_D-C1zHd0cf-Cdlw8sNp.mjs +289 -0
- package/dist/esm-C5TuvtGn.mjs +15816 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +17 -0
- package/dist/init-D8lwWc90.mjs +27 -0
- package/dist/json-oFuWgANh-O1U6k3bL.mjs +3811 -0
- package/dist/kysely-adapter-D_seG51p.mjs +297 -0
- package/dist/memory-adapter-CY-oDozb.mjs +215 -0
- package/dist/misc-CbURQDlR-sLtUwwQY.mjs +7 -0
- package/dist/node-sqlite-dialect-CdC7L-ji-QLbJGmDc.mjs +155 -0
- package/dist/parser-bL7W2mQ0-YdTgjtji.mjs +140 -0
- package/dist/plugins-BNFht2HW.mjs +23358 -0
- package/dist/plugins.d.mts +1 -0
- package/dist/plugins.mjs +13 -0
- package/dist/react--VZQu7s1.mjs +560 -0
- package/dist/react.d.mts +1 -0
- package/dist/react.mjs +6 -0
- package/dist/server.d.mts +10 -0
- package/dist/server.mjs +45 -0
- package/dist/social-providers-DNfE9Ak7-Be5zMAEe.mjs +2920 -0
- package/dist/social-providers.d.mts +1 -0
- package/dist/social-providers.mjs +6 -0
- package/dist/verify-CN5Qc0e-.mjs +1183 -0
- package/package.json +98 -0
|
@@ -0,0 +1,1183 @@
|
|
|
1
|
+
//#region ../better-auth/dist/base64-uVkQFxSP.mjs
|
|
2
|
+
function getAlphabet(urlSafe) {
|
|
3
|
+
return urlSafe ? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4
|
+
}
|
|
5
|
+
function base64Encode(data, alphabet, padding) {
|
|
6
|
+
let result = "";
|
|
7
|
+
let buffer = 0;
|
|
8
|
+
let shift = 0;
|
|
9
|
+
for (const byte of data) {
|
|
10
|
+
buffer = buffer << 8 | byte;
|
|
11
|
+
shift += 8;
|
|
12
|
+
while (shift >= 6) {
|
|
13
|
+
shift -= 6;
|
|
14
|
+
result += alphabet[buffer >> shift & 63];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (shift > 0) result += alphabet[buffer << 6 - shift & 63];
|
|
18
|
+
if (padding) {
|
|
19
|
+
const padCount = (4 - result.length % 4) % 4;
|
|
20
|
+
result += "=".repeat(padCount);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
function base64Decode(data, alphabet) {
|
|
25
|
+
const decodeMap = /* @__PURE__ */ new Map();
|
|
26
|
+
for (let i = 0; i < alphabet.length; i++) decodeMap.set(alphabet[i], i);
|
|
27
|
+
const result = [];
|
|
28
|
+
let buffer = 0;
|
|
29
|
+
let bitsCollected = 0;
|
|
30
|
+
for (const char of data) {
|
|
31
|
+
if (char === "=") break;
|
|
32
|
+
const value = decodeMap.get(char);
|
|
33
|
+
if (value === void 0) throw new Error(`Invalid Base64 character: ${char}`);
|
|
34
|
+
buffer = buffer << 6 | value;
|
|
35
|
+
bitsCollected += 6;
|
|
36
|
+
if (bitsCollected >= 8) {
|
|
37
|
+
bitsCollected -= 8;
|
|
38
|
+
result.push(buffer >> bitsCollected & 255);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return Uint8Array.from(result);
|
|
42
|
+
}
|
|
43
|
+
const base64 = {
|
|
44
|
+
encode(data, options = {}) {
|
|
45
|
+
const alphabet = getAlphabet(false);
|
|
46
|
+
return base64Encode(typeof data === "string" ? new TextEncoder().encode(data) : new Uint8Array(data), alphabet, options.padding ?? true);
|
|
47
|
+
},
|
|
48
|
+
decode(data) {
|
|
49
|
+
if (typeof data !== "string") data = new TextDecoder().decode(data);
|
|
50
|
+
const alphabet = getAlphabet(data.includes("-") || data.includes("_"));
|
|
51
|
+
return base64Decode(data, alphabet);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const base64Url = {
|
|
55
|
+
encode(data, options = {}) {
|
|
56
|
+
const alphabet = getAlphabet(true);
|
|
57
|
+
return base64Encode(typeof data === "string" ? new TextEncoder().encode(data) : new Uint8Array(data), alphabet, options.padding ?? true);
|
|
58
|
+
},
|
|
59
|
+
decode(data) {
|
|
60
|
+
return base64Decode(data, getAlphabet(data.includes("-") || data.includes("_")));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
66
|
+
const encoder = new TextEncoder();
|
|
67
|
+
const decoder = new TextDecoder();
|
|
68
|
+
const MAX_INT32 = 2 ** 32;
|
|
69
|
+
function concat(...buffers) {
|
|
70
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
71
|
+
const buf = new Uint8Array(size);
|
|
72
|
+
let i = 0;
|
|
73
|
+
for (const buffer of buffers) {
|
|
74
|
+
buf.set(buffer, i);
|
|
75
|
+
i += buffer.length;
|
|
76
|
+
}
|
|
77
|
+
return buf;
|
|
78
|
+
}
|
|
79
|
+
function writeUInt32BE(buf, value, offset) {
|
|
80
|
+
if (value < 0 || value >= MAX_INT32) throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
81
|
+
buf.set([
|
|
82
|
+
value >>> 24,
|
|
83
|
+
value >>> 16,
|
|
84
|
+
value >>> 8,
|
|
85
|
+
value & 255
|
|
86
|
+
], offset);
|
|
87
|
+
}
|
|
88
|
+
function uint64be(value) {
|
|
89
|
+
const high = Math.floor(value / MAX_INT32);
|
|
90
|
+
const low = value % MAX_INT32;
|
|
91
|
+
const buf = new Uint8Array(8);
|
|
92
|
+
writeUInt32BE(buf, high, 0);
|
|
93
|
+
writeUInt32BE(buf, low, 4);
|
|
94
|
+
return buf;
|
|
95
|
+
}
|
|
96
|
+
function uint32be(value) {
|
|
97
|
+
const buf = new Uint8Array(4);
|
|
98
|
+
writeUInt32BE(buf, value);
|
|
99
|
+
return buf;
|
|
100
|
+
}
|
|
101
|
+
function encode(string) {
|
|
102
|
+
const bytes = new Uint8Array(string.length);
|
|
103
|
+
for (let i = 0; i < string.length; i++) {
|
|
104
|
+
const code = string.charCodeAt(i);
|
|
105
|
+
if (code > 127) throw new TypeError("non-ASCII string encountered in encode()");
|
|
106
|
+
bytes[i] = code;
|
|
107
|
+
}
|
|
108
|
+
return bytes;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/base64.js
|
|
113
|
+
function encodeBase64(input) {
|
|
114
|
+
if (Uint8Array.prototype.toBase64) return input.toBase64();
|
|
115
|
+
const CHUNK_SIZE = 32768;
|
|
116
|
+
const arr = [];
|
|
117
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
118
|
+
return btoa(arr.join(""));
|
|
119
|
+
}
|
|
120
|
+
function decodeBase64(encoded) {
|
|
121
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
|
|
122
|
+
const binary = atob(encoded);
|
|
123
|
+
const bytes = new Uint8Array(binary.length);
|
|
124
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
125
|
+
return bytes;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/util/base64url.js
|
|
130
|
+
function decode(input) {
|
|
131
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
|
|
132
|
+
let encoded = input;
|
|
133
|
+
if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
|
|
134
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
135
|
+
try {
|
|
136
|
+
return decodeBase64(encoded);
|
|
137
|
+
} catch {
|
|
138
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function encode$1(input) {
|
|
142
|
+
let unencoded = input;
|
|
143
|
+
if (typeof unencoded === "string") unencoded = encoder.encode(unencoded);
|
|
144
|
+
if (Uint8Array.prototype.toBase64) return unencoded.toBase64({
|
|
145
|
+
alphabet: "base64url",
|
|
146
|
+
omitPadding: true
|
|
147
|
+
});
|
|
148
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/util/errors.js
|
|
153
|
+
var JOSEError = class extends Error {
|
|
154
|
+
static code = "ERR_JOSE_GENERIC";
|
|
155
|
+
code = "ERR_JOSE_GENERIC";
|
|
156
|
+
constructor(message$1, options) {
|
|
157
|
+
super(message$1, options);
|
|
158
|
+
this.name = this.constructor.name;
|
|
159
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
163
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
164
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
165
|
+
claim;
|
|
166
|
+
reason;
|
|
167
|
+
payload;
|
|
168
|
+
constructor(message$1, payload, claim = "unspecified", reason = "unspecified") {
|
|
169
|
+
super(message$1, { cause: {
|
|
170
|
+
claim,
|
|
171
|
+
reason,
|
|
172
|
+
payload
|
|
173
|
+
} });
|
|
174
|
+
this.claim = claim;
|
|
175
|
+
this.reason = reason;
|
|
176
|
+
this.payload = payload;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var JWTExpired = class extends JOSEError {
|
|
180
|
+
static code = "ERR_JWT_EXPIRED";
|
|
181
|
+
code = "ERR_JWT_EXPIRED";
|
|
182
|
+
claim;
|
|
183
|
+
reason;
|
|
184
|
+
payload;
|
|
185
|
+
constructor(message$1, payload, claim = "unspecified", reason = "unspecified") {
|
|
186
|
+
super(message$1, { cause: {
|
|
187
|
+
claim,
|
|
188
|
+
reason,
|
|
189
|
+
payload
|
|
190
|
+
} });
|
|
191
|
+
this.claim = claim;
|
|
192
|
+
this.reason = reason;
|
|
193
|
+
this.payload = payload;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
197
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
198
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
199
|
+
};
|
|
200
|
+
var JOSENotSupported = class extends JOSEError {
|
|
201
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
202
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
203
|
+
};
|
|
204
|
+
var JWEDecryptionFailed = class extends JOSEError {
|
|
205
|
+
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
206
|
+
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
207
|
+
constructor(message$1 = "decryption operation failed", options) {
|
|
208
|
+
super(message$1, options);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
var JWEInvalid = class extends JOSEError {
|
|
212
|
+
static code = "ERR_JWE_INVALID";
|
|
213
|
+
code = "ERR_JWE_INVALID";
|
|
214
|
+
};
|
|
215
|
+
var JWSInvalid = class extends JOSEError {
|
|
216
|
+
static code = "ERR_JWS_INVALID";
|
|
217
|
+
code = "ERR_JWS_INVALID";
|
|
218
|
+
};
|
|
219
|
+
var JWTInvalid = class extends JOSEError {
|
|
220
|
+
static code = "ERR_JWT_INVALID";
|
|
221
|
+
code = "ERR_JWT_INVALID";
|
|
222
|
+
};
|
|
223
|
+
var JWKInvalid = class extends JOSEError {
|
|
224
|
+
static code = "ERR_JWK_INVALID";
|
|
225
|
+
code = "ERR_JWK_INVALID";
|
|
226
|
+
};
|
|
227
|
+
var JWKSInvalid = class extends JOSEError {
|
|
228
|
+
static code = "ERR_JWKS_INVALID";
|
|
229
|
+
code = "ERR_JWKS_INVALID";
|
|
230
|
+
};
|
|
231
|
+
var JWKSNoMatchingKey = class extends JOSEError {
|
|
232
|
+
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
233
|
+
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
234
|
+
constructor(message$1 = "no applicable key found in the JSON Web Key Set", options) {
|
|
235
|
+
super(message$1, options);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
var JWKSMultipleMatchingKeys = class extends JOSEError {
|
|
239
|
+
[Symbol.asyncIterator];
|
|
240
|
+
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
241
|
+
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
242
|
+
constructor(message$1 = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
243
|
+
super(message$1, options);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var JWKSTimeout = class extends JOSEError {
|
|
247
|
+
static code = "ERR_JWKS_TIMEOUT";
|
|
248
|
+
code = "ERR_JWKS_TIMEOUT";
|
|
249
|
+
constructor(message$1 = "request timed out", options) {
|
|
250
|
+
super(message$1, options);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
254
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
255
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
256
|
+
constructor(message$1 = "signature verification failed", options) {
|
|
257
|
+
super(message$1, options);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
263
|
+
const unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
264
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
265
|
+
function getHashLength(hash) {
|
|
266
|
+
return parseInt(hash.name.slice(4), 10);
|
|
267
|
+
}
|
|
268
|
+
function getNamedCurve(alg) {
|
|
269
|
+
switch (alg) {
|
|
270
|
+
case "ES256": return "P-256";
|
|
271
|
+
case "ES384": return "P-384";
|
|
272
|
+
case "ES512": return "P-521";
|
|
273
|
+
default: throw new Error("unreachable");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function checkUsage(key, usage) {
|
|
277
|
+
if (usage && !key.usages.includes(usage)) throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
278
|
+
}
|
|
279
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
280
|
+
switch (alg) {
|
|
281
|
+
case "HS256":
|
|
282
|
+
case "HS384":
|
|
283
|
+
case "HS512": {
|
|
284
|
+
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
285
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
286
|
+
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case "RS256":
|
|
290
|
+
case "RS384":
|
|
291
|
+
case "RS512": {
|
|
292
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
293
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
294
|
+
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case "PS256":
|
|
298
|
+
case "PS384":
|
|
299
|
+
case "PS512": {
|
|
300
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
301
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
302
|
+
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
case "Ed25519":
|
|
306
|
+
case "EdDSA":
|
|
307
|
+
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
308
|
+
break;
|
|
309
|
+
case "ML-DSA-44":
|
|
310
|
+
case "ML-DSA-65":
|
|
311
|
+
case "ML-DSA-87":
|
|
312
|
+
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
313
|
+
break;
|
|
314
|
+
case "ES256":
|
|
315
|
+
case "ES384":
|
|
316
|
+
case "ES512": {
|
|
317
|
+
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
318
|
+
const expected = getNamedCurve(alg);
|
|
319
|
+
if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
default: throw new TypeError("CryptoKey does not support this operation");
|
|
323
|
+
}
|
|
324
|
+
checkUsage(key, usage);
|
|
325
|
+
}
|
|
326
|
+
function checkEncCryptoKey(key, alg, usage) {
|
|
327
|
+
switch (alg) {
|
|
328
|
+
case "A128GCM":
|
|
329
|
+
case "A192GCM":
|
|
330
|
+
case "A256GCM": {
|
|
331
|
+
if (!isAlgorithm(key.algorithm, "AES-GCM")) throw unusable("AES-GCM");
|
|
332
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
333
|
+
if (key.algorithm.length !== expected) throw unusable(expected, "algorithm.length");
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
case "A128KW":
|
|
337
|
+
case "A192KW":
|
|
338
|
+
case "A256KW": {
|
|
339
|
+
if (!isAlgorithm(key.algorithm, "AES-KW")) throw unusable("AES-KW");
|
|
340
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
341
|
+
if (key.algorithm.length !== expected) throw unusable(expected, "algorithm.length");
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
case "ECDH":
|
|
345
|
+
switch (key.algorithm.name) {
|
|
346
|
+
case "ECDH":
|
|
347
|
+
case "X25519": break;
|
|
348
|
+
default: throw unusable("ECDH or X25519");
|
|
349
|
+
}
|
|
350
|
+
break;
|
|
351
|
+
case "PBES2-HS256+A128KW":
|
|
352
|
+
case "PBES2-HS384+A192KW":
|
|
353
|
+
case "PBES2-HS512+A256KW":
|
|
354
|
+
if (!isAlgorithm(key.algorithm, "PBKDF2")) throw unusable("PBKDF2");
|
|
355
|
+
break;
|
|
356
|
+
case "RSA-OAEP":
|
|
357
|
+
case "RSA-OAEP-256":
|
|
358
|
+
case "RSA-OAEP-384":
|
|
359
|
+
case "RSA-OAEP-512": {
|
|
360
|
+
if (!isAlgorithm(key.algorithm, "RSA-OAEP")) throw unusable("RSA-OAEP");
|
|
361
|
+
const expected = parseInt(alg.slice(9), 10) || 1;
|
|
362
|
+
if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
default: throw new TypeError("CryptoKey does not support this operation");
|
|
366
|
+
}
|
|
367
|
+
checkUsage(key, usage);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
372
|
+
function message(msg, actual, ...types) {
|
|
373
|
+
types = types.filter(Boolean);
|
|
374
|
+
if (types.length > 2) {
|
|
375
|
+
const last = types.pop();
|
|
376
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
377
|
+
} else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
378
|
+
else msg += `of type ${types[0]}.`;
|
|
379
|
+
if (actual == null) msg += ` Received ${actual}`;
|
|
380
|
+
else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
|
|
381
|
+
else if (typeof actual === "object" && actual != null) {
|
|
382
|
+
if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
|
|
383
|
+
}
|
|
384
|
+
return msg;
|
|
385
|
+
}
|
|
386
|
+
const invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
387
|
+
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
388
|
+
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
391
|
+
function assertCryptoKey(key) {
|
|
392
|
+
if (!isCryptoKey(key)) throw new Error("CryptoKey instance expected");
|
|
393
|
+
}
|
|
394
|
+
const isCryptoKey = (key) => {
|
|
395
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
396
|
+
try {
|
|
397
|
+
return key instanceof CryptoKey;
|
|
398
|
+
} catch {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
const isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
403
|
+
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
404
|
+
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
407
|
+
function isDisjoint(...headers) {
|
|
408
|
+
const sources = headers.filter(Boolean);
|
|
409
|
+
if (sources.length === 0 || sources.length === 1) return true;
|
|
410
|
+
let acc;
|
|
411
|
+
for (const header of sources) {
|
|
412
|
+
const parameters = Object.keys(header);
|
|
413
|
+
if (!acc || acc.size === 0) {
|
|
414
|
+
acc = new Set(parameters);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
for (const parameter of parameters) {
|
|
418
|
+
if (acc.has(parameter)) return false;
|
|
419
|
+
acc.add(parameter);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/is_object.js
|
|
427
|
+
const isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
428
|
+
function isObject(input) {
|
|
429
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
430
|
+
if (Object.getPrototypeOf(input) === null) return true;
|
|
431
|
+
let proto = input;
|
|
432
|
+
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
433
|
+
return Object.getPrototypeOf(input) === proto;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
438
|
+
function checkKeyLength(alg, key) {
|
|
439
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
440
|
+
const { modulusLength } = key.algorithm;
|
|
441
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
447
|
+
function subtleMapping(jwk) {
|
|
448
|
+
let algorithm;
|
|
449
|
+
let keyUsages;
|
|
450
|
+
switch (jwk.kty) {
|
|
451
|
+
case "AKP":
|
|
452
|
+
switch (jwk.alg) {
|
|
453
|
+
case "ML-DSA-44":
|
|
454
|
+
case "ML-DSA-65":
|
|
455
|
+
case "ML-DSA-87":
|
|
456
|
+
algorithm = { name: jwk.alg };
|
|
457
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
458
|
+
break;
|
|
459
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
case "RSA":
|
|
463
|
+
switch (jwk.alg) {
|
|
464
|
+
case "PS256":
|
|
465
|
+
case "PS384":
|
|
466
|
+
case "PS512":
|
|
467
|
+
algorithm = {
|
|
468
|
+
name: "RSA-PSS",
|
|
469
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
470
|
+
};
|
|
471
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
472
|
+
break;
|
|
473
|
+
case "RS256":
|
|
474
|
+
case "RS384":
|
|
475
|
+
case "RS512":
|
|
476
|
+
algorithm = {
|
|
477
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
478
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
479
|
+
};
|
|
480
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
481
|
+
break;
|
|
482
|
+
case "RSA-OAEP":
|
|
483
|
+
case "RSA-OAEP-256":
|
|
484
|
+
case "RSA-OAEP-384":
|
|
485
|
+
case "RSA-OAEP-512":
|
|
486
|
+
algorithm = {
|
|
487
|
+
name: "RSA-OAEP",
|
|
488
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
489
|
+
};
|
|
490
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
491
|
+
break;
|
|
492
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
493
|
+
}
|
|
494
|
+
break;
|
|
495
|
+
case "EC":
|
|
496
|
+
switch (jwk.alg) {
|
|
497
|
+
case "ES256":
|
|
498
|
+
algorithm = {
|
|
499
|
+
name: "ECDSA",
|
|
500
|
+
namedCurve: "P-256"
|
|
501
|
+
};
|
|
502
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
503
|
+
break;
|
|
504
|
+
case "ES384":
|
|
505
|
+
algorithm = {
|
|
506
|
+
name: "ECDSA",
|
|
507
|
+
namedCurve: "P-384"
|
|
508
|
+
};
|
|
509
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
510
|
+
break;
|
|
511
|
+
case "ES512":
|
|
512
|
+
algorithm = {
|
|
513
|
+
name: "ECDSA",
|
|
514
|
+
namedCurve: "P-521"
|
|
515
|
+
};
|
|
516
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
517
|
+
break;
|
|
518
|
+
case "ECDH-ES":
|
|
519
|
+
case "ECDH-ES+A128KW":
|
|
520
|
+
case "ECDH-ES+A192KW":
|
|
521
|
+
case "ECDH-ES+A256KW":
|
|
522
|
+
algorithm = {
|
|
523
|
+
name: "ECDH",
|
|
524
|
+
namedCurve: jwk.crv
|
|
525
|
+
};
|
|
526
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
527
|
+
break;
|
|
528
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
529
|
+
}
|
|
530
|
+
break;
|
|
531
|
+
case "OKP":
|
|
532
|
+
switch (jwk.alg) {
|
|
533
|
+
case "Ed25519":
|
|
534
|
+
case "EdDSA":
|
|
535
|
+
algorithm = { name: "Ed25519" };
|
|
536
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
537
|
+
break;
|
|
538
|
+
case "ECDH-ES":
|
|
539
|
+
case "ECDH-ES+A128KW":
|
|
540
|
+
case "ECDH-ES+A192KW":
|
|
541
|
+
case "ECDH-ES+A256KW":
|
|
542
|
+
algorithm = { name: jwk.crv };
|
|
543
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
544
|
+
break;
|
|
545
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
|
|
546
|
+
}
|
|
547
|
+
break;
|
|
548
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
|
|
549
|
+
}
|
|
550
|
+
return {
|
|
551
|
+
algorithm,
|
|
552
|
+
keyUsages
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
async function jwkToKey(jwk) {
|
|
556
|
+
if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
|
|
557
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
558
|
+
const keyData = { ...jwk };
|
|
559
|
+
if (keyData.kty !== "AKP") delete keyData.alg;
|
|
560
|
+
delete keyData.use;
|
|
561
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/key/import.js
|
|
566
|
+
async function importJWK(jwk, alg, options) {
|
|
567
|
+
if (!isObject(jwk)) throw new TypeError("JWK must be an object");
|
|
568
|
+
let ext;
|
|
569
|
+
alg ??= jwk.alg;
|
|
570
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
571
|
+
switch (jwk.kty) {
|
|
572
|
+
case "oct":
|
|
573
|
+
if (typeof jwk.k !== "string" || !jwk.k) throw new TypeError("missing \"k\" (Key Value) Parameter value");
|
|
574
|
+
return decode(jwk.k);
|
|
575
|
+
case "RSA":
|
|
576
|
+
if ("oth" in jwk && jwk.oth !== void 0) throw new JOSENotSupported("RSA JWK \"oth\" (Other Primes Info) Parameter value is not supported");
|
|
577
|
+
return jwkToKey({
|
|
578
|
+
...jwk,
|
|
579
|
+
alg,
|
|
580
|
+
ext
|
|
581
|
+
});
|
|
582
|
+
case "AKP":
|
|
583
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) throw new TypeError("missing \"alg\" (Algorithm) Parameter value");
|
|
584
|
+
if (alg !== void 0 && alg !== jwk.alg) throw new TypeError("JWK alg and alg option value mismatch");
|
|
585
|
+
return jwkToKey({
|
|
586
|
+
...jwk,
|
|
587
|
+
ext
|
|
588
|
+
});
|
|
589
|
+
case "EC":
|
|
590
|
+
case "OKP": return jwkToKey({
|
|
591
|
+
...jwk,
|
|
592
|
+
alg,
|
|
593
|
+
ext
|
|
594
|
+
});
|
|
595
|
+
default: throw new JOSENotSupported("Unsupported \"kty\" (Key Type) Parameter value");
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
601
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
602
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
|
|
603
|
+
if (!protectedHeader || protectedHeader.crit === void 0) return /* @__PURE__ */ new Set();
|
|
604
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
|
|
605
|
+
let recognized;
|
|
606
|
+
if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
607
|
+
else recognized = recognizedDefault;
|
|
608
|
+
for (const parameter of protectedHeader.crit) {
|
|
609
|
+
if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
610
|
+
if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
611
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
612
|
+
}
|
|
613
|
+
return new Set(protectedHeader.crit);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
618
|
+
function validateAlgorithms(option, algorithms) {
|
|
619
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
|
|
620
|
+
if (!algorithms) return;
|
|
621
|
+
return new Set(algorithms);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
//#endregion
|
|
625
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
626
|
+
const isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
627
|
+
const isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
628
|
+
const isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
629
|
+
const isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
630
|
+
|
|
631
|
+
//#endregion
|
|
632
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
633
|
+
let cache;
|
|
634
|
+
const handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
635
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
636
|
+
let cached = cache.get(key);
|
|
637
|
+
if (cached?.[alg]) return cached[alg];
|
|
638
|
+
const cryptoKey = await jwkToKey({
|
|
639
|
+
...jwk,
|
|
640
|
+
alg
|
|
641
|
+
});
|
|
642
|
+
if (freeze) Object.freeze(key);
|
|
643
|
+
if (!cached) cache.set(key, { [alg]: cryptoKey });
|
|
644
|
+
else cached[alg] = cryptoKey;
|
|
645
|
+
return cryptoKey;
|
|
646
|
+
};
|
|
647
|
+
const handleKeyObject = (keyObject, alg) => {
|
|
648
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
649
|
+
let cached = cache.get(keyObject);
|
|
650
|
+
if (cached?.[alg]) return cached[alg];
|
|
651
|
+
const isPublic = keyObject.type === "public";
|
|
652
|
+
const extractable = isPublic ? true : false;
|
|
653
|
+
let cryptoKey;
|
|
654
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
655
|
+
switch (alg) {
|
|
656
|
+
case "ECDH-ES":
|
|
657
|
+
case "ECDH-ES+A128KW":
|
|
658
|
+
case "ECDH-ES+A192KW":
|
|
659
|
+
case "ECDH-ES+A256KW": break;
|
|
660
|
+
default: throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
661
|
+
}
|
|
662
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
663
|
+
}
|
|
664
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
665
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
666
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
667
|
+
}
|
|
668
|
+
switch (keyObject.asymmetricKeyType) {
|
|
669
|
+
case "ml-dsa-44":
|
|
670
|
+
case "ml-dsa-65":
|
|
671
|
+
case "ml-dsa-87":
|
|
672
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
673
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
674
|
+
}
|
|
675
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
676
|
+
let hash;
|
|
677
|
+
switch (alg) {
|
|
678
|
+
case "RSA-OAEP":
|
|
679
|
+
hash = "SHA-1";
|
|
680
|
+
break;
|
|
681
|
+
case "RS256":
|
|
682
|
+
case "PS256":
|
|
683
|
+
case "RSA-OAEP-256":
|
|
684
|
+
hash = "SHA-256";
|
|
685
|
+
break;
|
|
686
|
+
case "RS384":
|
|
687
|
+
case "PS384":
|
|
688
|
+
case "RSA-OAEP-384":
|
|
689
|
+
hash = "SHA-384";
|
|
690
|
+
break;
|
|
691
|
+
case "RS512":
|
|
692
|
+
case "PS512":
|
|
693
|
+
case "RSA-OAEP-512":
|
|
694
|
+
hash = "SHA-512";
|
|
695
|
+
break;
|
|
696
|
+
default: throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
697
|
+
}
|
|
698
|
+
if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
|
|
699
|
+
name: "RSA-OAEP",
|
|
700
|
+
hash
|
|
701
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
702
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
703
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
704
|
+
hash
|
|
705
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
706
|
+
}
|
|
707
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
708
|
+
const namedCurve = new Map([
|
|
709
|
+
["prime256v1", "P-256"],
|
|
710
|
+
["secp384r1", "P-384"],
|
|
711
|
+
["secp521r1", "P-521"]
|
|
712
|
+
]).get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
713
|
+
if (!namedCurve) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
714
|
+
if (alg === "ES256" && namedCurve === "P-256") cryptoKey = keyObject.toCryptoKey({
|
|
715
|
+
name: "ECDSA",
|
|
716
|
+
namedCurve
|
|
717
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
718
|
+
if (alg === "ES384" && namedCurve === "P-384") cryptoKey = keyObject.toCryptoKey({
|
|
719
|
+
name: "ECDSA",
|
|
720
|
+
namedCurve
|
|
721
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
722
|
+
if (alg === "ES512" && namedCurve === "P-521") cryptoKey = keyObject.toCryptoKey({
|
|
723
|
+
name: "ECDSA",
|
|
724
|
+
namedCurve
|
|
725
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
726
|
+
if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
|
|
727
|
+
name: "ECDH",
|
|
728
|
+
namedCurve
|
|
729
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
730
|
+
}
|
|
731
|
+
if (!cryptoKey) throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
732
|
+
if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
|
|
733
|
+
else cached[alg] = cryptoKey;
|
|
734
|
+
return cryptoKey;
|
|
735
|
+
};
|
|
736
|
+
async function normalizeKey(key, alg) {
|
|
737
|
+
if (key instanceof Uint8Array) return key;
|
|
738
|
+
if (isCryptoKey(key)) return key;
|
|
739
|
+
if (isKeyObject(key)) {
|
|
740
|
+
if (key.type === "secret") return key.export();
|
|
741
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
|
|
742
|
+
return handleKeyObject(key, alg);
|
|
743
|
+
} catch (err) {
|
|
744
|
+
if (err instanceof TypeError) throw err;
|
|
745
|
+
}
|
|
746
|
+
return handleJWK(key, key.export({ format: "jwk" }), alg);
|
|
747
|
+
}
|
|
748
|
+
if (isJWK(key)) {
|
|
749
|
+
if (key.k) return decode(key.k);
|
|
750
|
+
return handleJWK(key, key, alg, true);
|
|
751
|
+
}
|
|
752
|
+
throw new Error("unreachable");
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
757
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
|
758
|
+
const jwkMatchesOp = (alg, key, usage) => {
|
|
759
|
+
if (key.use !== void 0) {
|
|
760
|
+
let expected;
|
|
761
|
+
switch (usage) {
|
|
762
|
+
case "sign":
|
|
763
|
+
case "verify":
|
|
764
|
+
expected = "sig";
|
|
765
|
+
break;
|
|
766
|
+
case "encrypt":
|
|
767
|
+
case "decrypt":
|
|
768
|
+
expected = "enc";
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
772
|
+
}
|
|
773
|
+
if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
774
|
+
if (Array.isArray(key.key_ops)) {
|
|
775
|
+
let expectedKeyOp;
|
|
776
|
+
switch (true) {
|
|
777
|
+
case usage === "sign" || usage === "verify":
|
|
778
|
+
case alg === "dir":
|
|
779
|
+
case alg.includes("CBC-HS"):
|
|
780
|
+
expectedKeyOp = usage;
|
|
781
|
+
break;
|
|
782
|
+
case alg.startsWith("PBES2"):
|
|
783
|
+
expectedKeyOp = "deriveBits";
|
|
784
|
+
break;
|
|
785
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
786
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
787
|
+
else expectedKeyOp = usage;
|
|
788
|
+
break;
|
|
789
|
+
case usage === "encrypt" && alg.startsWith("RSA"):
|
|
790
|
+
expectedKeyOp = "wrapKey";
|
|
791
|
+
break;
|
|
792
|
+
case usage === "decrypt":
|
|
793
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
797
|
+
}
|
|
798
|
+
return true;
|
|
799
|
+
};
|
|
800
|
+
const symmetricTypeCheck = (alg, key, usage) => {
|
|
801
|
+
if (key instanceof Uint8Array) return;
|
|
802
|
+
if (isJWK(key)) {
|
|
803
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
804
|
+
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`);
|
|
805
|
+
}
|
|
806
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
807
|
+
if (key.type !== "secret") throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
808
|
+
};
|
|
809
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
810
|
+
if (isJWK(key)) switch (usage) {
|
|
811
|
+
case "decrypt":
|
|
812
|
+
case "sign":
|
|
813
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
814
|
+
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
815
|
+
case "encrypt":
|
|
816
|
+
case "verify":
|
|
817
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
818
|
+
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
819
|
+
}
|
|
820
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
821
|
+
if (key.type === "secret") throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
822
|
+
if (key.type === "public") switch (usage) {
|
|
823
|
+
case "sign": throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
824
|
+
case "decrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
825
|
+
}
|
|
826
|
+
if (key.type === "private") switch (usage) {
|
|
827
|
+
case "verify": throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
828
|
+
case "encrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
function checkKeyType(alg, key, usage) {
|
|
832
|
+
switch (alg.substring(0, 2)) {
|
|
833
|
+
case "A1":
|
|
834
|
+
case "A2":
|
|
835
|
+
case "di":
|
|
836
|
+
case "HS":
|
|
837
|
+
case "PB":
|
|
838
|
+
symmetricTypeCheck(alg, key, usage);
|
|
839
|
+
break;
|
|
840
|
+
default: asymmetricTypeCheck(alg, key, usage);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
846
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
847
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
848
|
+
switch (alg) {
|
|
849
|
+
case "HS256":
|
|
850
|
+
case "HS384":
|
|
851
|
+
case "HS512": return {
|
|
852
|
+
hash,
|
|
853
|
+
name: "HMAC"
|
|
854
|
+
};
|
|
855
|
+
case "PS256":
|
|
856
|
+
case "PS384":
|
|
857
|
+
case "PS512": return {
|
|
858
|
+
hash,
|
|
859
|
+
name: "RSA-PSS",
|
|
860
|
+
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
861
|
+
};
|
|
862
|
+
case "RS256":
|
|
863
|
+
case "RS384":
|
|
864
|
+
case "RS512": return {
|
|
865
|
+
hash,
|
|
866
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
867
|
+
};
|
|
868
|
+
case "ES256":
|
|
869
|
+
case "ES384":
|
|
870
|
+
case "ES512": return {
|
|
871
|
+
hash,
|
|
872
|
+
name: "ECDSA",
|
|
873
|
+
namedCurve: algorithm.namedCurve
|
|
874
|
+
};
|
|
875
|
+
case "Ed25519":
|
|
876
|
+
case "EdDSA": return { name: "Ed25519" };
|
|
877
|
+
case "ML-DSA-44":
|
|
878
|
+
case "ML-DSA-65":
|
|
879
|
+
case "ML-DSA-87": return { name: alg };
|
|
880
|
+
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
//#endregion
|
|
885
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
886
|
+
async function getSigKey(alg, key, usage) {
|
|
887
|
+
if (key instanceof Uint8Array) {
|
|
888
|
+
if (!alg.startsWith("HS")) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
889
|
+
return crypto.subtle.importKey("raw", key, {
|
|
890
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
891
|
+
name: "HMAC"
|
|
892
|
+
}, false, [usage]);
|
|
893
|
+
}
|
|
894
|
+
checkSigCryptoKey(key, alg, usage);
|
|
895
|
+
return key;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/verify.js
|
|
900
|
+
async function verify(alg, key, signature, data) {
|
|
901
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
902
|
+
checkKeyLength(alg, cryptoKey);
|
|
903
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
904
|
+
try {
|
|
905
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
906
|
+
} catch {
|
|
907
|
+
return false;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
//#endregion
|
|
912
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
913
|
+
async function flattenedVerify(jws, key, options) {
|
|
914
|
+
if (!isObject(jws)) throw new JWSInvalid("Flattened JWS must be an object");
|
|
915
|
+
if (jws.protected === void 0 && jws.header === void 0) throw new JWSInvalid("Flattened JWS must have either of the \"protected\" or \"header\" members");
|
|
916
|
+
if (jws.protected !== void 0 && typeof jws.protected !== "string") throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
917
|
+
if (jws.payload === void 0) throw new JWSInvalid("JWS Payload missing");
|
|
918
|
+
if (typeof jws.signature !== "string") throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
919
|
+
if (jws.header !== void 0 && !isObject(jws.header)) throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
920
|
+
let parsedProt = {};
|
|
921
|
+
if (jws.protected) try {
|
|
922
|
+
const protectedHeader = decode(jws.protected);
|
|
923
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
924
|
+
} catch {
|
|
925
|
+
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
926
|
+
}
|
|
927
|
+
if (!isDisjoint(parsedProt, jws.header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
928
|
+
const joseHeader = {
|
|
929
|
+
...parsedProt,
|
|
930
|
+
...jws.header
|
|
931
|
+
};
|
|
932
|
+
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
933
|
+
let b64 = true;
|
|
934
|
+
if (extensions.has("b64")) {
|
|
935
|
+
b64 = parsedProt.b64;
|
|
936
|
+
if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
937
|
+
}
|
|
938
|
+
const { alg } = joseHeader;
|
|
939
|
+
if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
940
|
+
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
941
|
+
if (algorithms && !algorithms.has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
|
|
942
|
+
if (b64) {
|
|
943
|
+
if (typeof jws.payload !== "string") throw new JWSInvalid("JWS Payload must be a string");
|
|
944
|
+
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
945
|
+
let resolvedKey = false;
|
|
946
|
+
if (typeof key === "function") {
|
|
947
|
+
key = await key(parsedProt, jws);
|
|
948
|
+
resolvedKey = true;
|
|
949
|
+
}
|
|
950
|
+
checkKeyType(alg, key, "verify");
|
|
951
|
+
const data = concat(jws.protected !== void 0 ? encode(jws.protected) : new Uint8Array(), encode("."), typeof jws.payload === "string" ? b64 ? encode(jws.payload) : encoder.encode(jws.payload) : jws.payload);
|
|
952
|
+
let signature;
|
|
953
|
+
try {
|
|
954
|
+
signature = decode(jws.signature);
|
|
955
|
+
} catch {
|
|
956
|
+
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
957
|
+
}
|
|
958
|
+
const k = await normalizeKey(key, alg);
|
|
959
|
+
if (!await verify(alg, k, signature, data)) throw new JWSSignatureVerificationFailed();
|
|
960
|
+
let payload;
|
|
961
|
+
if (b64) try {
|
|
962
|
+
payload = decode(jws.payload);
|
|
963
|
+
} catch {
|
|
964
|
+
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
965
|
+
}
|
|
966
|
+
else if (typeof jws.payload === "string") payload = encoder.encode(jws.payload);
|
|
967
|
+
else payload = jws.payload;
|
|
968
|
+
const result = { payload };
|
|
969
|
+
if (jws.protected !== void 0) result.protectedHeader = parsedProt;
|
|
970
|
+
if (jws.header !== void 0) result.unprotectedHeader = jws.header;
|
|
971
|
+
if (resolvedKey) return {
|
|
972
|
+
...result,
|
|
973
|
+
key: k
|
|
974
|
+
};
|
|
975
|
+
return result;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
//#endregion
|
|
979
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
980
|
+
async function compactVerify(jws, key, options) {
|
|
981
|
+
if (jws instanceof Uint8Array) jws = decoder.decode(jws);
|
|
982
|
+
if (typeof jws !== "string") throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
983
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
984
|
+
if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
|
|
985
|
+
const verified = await flattenedVerify({
|
|
986
|
+
payload,
|
|
987
|
+
protected: protectedHeader,
|
|
988
|
+
signature
|
|
989
|
+
}, key, options);
|
|
990
|
+
const result = {
|
|
991
|
+
payload: verified.payload,
|
|
992
|
+
protectedHeader: verified.protectedHeader
|
|
993
|
+
};
|
|
994
|
+
if (typeof key === "function") return {
|
|
995
|
+
...result,
|
|
996
|
+
key: verified.key
|
|
997
|
+
};
|
|
998
|
+
return result;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
//#endregion
|
|
1002
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1003
|
+
const epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
1004
|
+
const minute = 60;
|
|
1005
|
+
const hour = minute * 60;
|
|
1006
|
+
const day = hour * 24;
|
|
1007
|
+
const week = day * 7;
|
|
1008
|
+
const year = day * 365.25;
|
|
1009
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
1010
|
+
function secs(str) {
|
|
1011
|
+
const matched = REGEX.exec(str);
|
|
1012
|
+
if (!matched || matched[4] && matched[1]) throw new TypeError("Invalid time period format");
|
|
1013
|
+
const value = parseFloat(matched[2]);
|
|
1014
|
+
const unit = matched[3].toLowerCase();
|
|
1015
|
+
let numericDate;
|
|
1016
|
+
switch (unit) {
|
|
1017
|
+
case "sec":
|
|
1018
|
+
case "secs":
|
|
1019
|
+
case "second":
|
|
1020
|
+
case "seconds":
|
|
1021
|
+
case "s":
|
|
1022
|
+
numericDate = Math.round(value);
|
|
1023
|
+
break;
|
|
1024
|
+
case "minute":
|
|
1025
|
+
case "minutes":
|
|
1026
|
+
case "min":
|
|
1027
|
+
case "mins":
|
|
1028
|
+
case "m":
|
|
1029
|
+
numericDate = Math.round(value * minute);
|
|
1030
|
+
break;
|
|
1031
|
+
case "hour":
|
|
1032
|
+
case "hours":
|
|
1033
|
+
case "hr":
|
|
1034
|
+
case "hrs":
|
|
1035
|
+
case "h":
|
|
1036
|
+
numericDate = Math.round(value * hour);
|
|
1037
|
+
break;
|
|
1038
|
+
case "day":
|
|
1039
|
+
case "days":
|
|
1040
|
+
case "d":
|
|
1041
|
+
numericDate = Math.round(value * day);
|
|
1042
|
+
break;
|
|
1043
|
+
case "week":
|
|
1044
|
+
case "weeks":
|
|
1045
|
+
case "w":
|
|
1046
|
+
numericDate = Math.round(value * week);
|
|
1047
|
+
break;
|
|
1048
|
+
default:
|
|
1049
|
+
numericDate = Math.round(value * year);
|
|
1050
|
+
break;
|
|
1051
|
+
}
|
|
1052
|
+
if (matched[1] === "-" || matched[4] === "ago") return -numericDate;
|
|
1053
|
+
return numericDate;
|
|
1054
|
+
}
|
|
1055
|
+
function validateInput(label, input) {
|
|
1056
|
+
if (!Number.isFinite(input)) throw new TypeError(`Invalid ${label} input`);
|
|
1057
|
+
return input;
|
|
1058
|
+
}
|
|
1059
|
+
const normalizeTyp = (value) => {
|
|
1060
|
+
if (value.includes("/")) return value.toLowerCase();
|
|
1061
|
+
return `application/${value.toLowerCase()}`;
|
|
1062
|
+
};
|
|
1063
|
+
const checkAudiencePresence = (audPayload, audOption) => {
|
|
1064
|
+
if (typeof audPayload === "string") return audOption.includes(audPayload);
|
|
1065
|
+
if (Array.isArray(audPayload)) return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
1066
|
+
return false;
|
|
1067
|
+
};
|
|
1068
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
1069
|
+
let payload;
|
|
1070
|
+
try {
|
|
1071
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
1072
|
+
} catch {}
|
|
1073
|
+
if (!isObject(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
1074
|
+
const { typ } = options;
|
|
1075
|
+
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", "check_failed");
|
|
1076
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
1077
|
+
const presenceCheck = [...requiredClaims];
|
|
1078
|
+
if (maxTokenAge !== void 0) presenceCheck.push("iat");
|
|
1079
|
+
if (audience !== void 0) presenceCheck.push("aud");
|
|
1080
|
+
if (subject !== void 0) presenceCheck.push("sub");
|
|
1081
|
+
if (issuer !== void 0) presenceCheck.push("iss");
|
|
1082
|
+
for (const claim of new Set(presenceCheck.reverse())) if (!(claim in payload)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
1083
|
+
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) throw new JWTClaimValidationFailed("unexpected \"iss\" claim value", payload, "iss", "check_failed");
|
|
1084
|
+
if (subject && payload.sub !== subject) throw new JWTClaimValidationFailed("unexpected \"sub\" claim value", payload, "sub", "check_failed");
|
|
1085
|
+
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) throw new JWTClaimValidationFailed("unexpected \"aud\" claim value", payload, "aud", "check_failed");
|
|
1086
|
+
let tolerance;
|
|
1087
|
+
switch (typeof options.clockTolerance) {
|
|
1088
|
+
case "string":
|
|
1089
|
+
tolerance = secs(options.clockTolerance);
|
|
1090
|
+
break;
|
|
1091
|
+
case "number":
|
|
1092
|
+
tolerance = options.clockTolerance;
|
|
1093
|
+
break;
|
|
1094
|
+
case "undefined":
|
|
1095
|
+
tolerance = 0;
|
|
1096
|
+
break;
|
|
1097
|
+
default: throw new TypeError("Invalid clockTolerance option type");
|
|
1098
|
+
}
|
|
1099
|
+
const { currentDate } = options;
|
|
1100
|
+
const now = epoch(currentDate || /* @__PURE__ */ new Date());
|
|
1101
|
+
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") throw new JWTClaimValidationFailed("\"iat\" claim must be a number", payload, "iat", "invalid");
|
|
1102
|
+
if (payload.nbf !== void 0) {
|
|
1103
|
+
if (typeof payload.nbf !== "number") throw new JWTClaimValidationFailed("\"nbf\" claim must be a number", payload, "nbf", "invalid");
|
|
1104
|
+
if (payload.nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", "check_failed");
|
|
1105
|
+
}
|
|
1106
|
+
if (payload.exp !== void 0) {
|
|
1107
|
+
if (typeof payload.exp !== "number") throw new JWTClaimValidationFailed("\"exp\" claim must be a number", payload, "exp", "invalid");
|
|
1108
|
+
if (payload.exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", "check_failed");
|
|
1109
|
+
}
|
|
1110
|
+
if (maxTokenAge) {
|
|
1111
|
+
const age = now - payload.iat;
|
|
1112
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
1113
|
+
if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", "check_failed");
|
|
1114
|
+
if (age < 0 - tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", "check_failed");
|
|
1115
|
+
}
|
|
1116
|
+
return payload;
|
|
1117
|
+
}
|
|
1118
|
+
var JWTClaimsBuilder = class {
|
|
1119
|
+
#payload;
|
|
1120
|
+
constructor(payload) {
|
|
1121
|
+
if (!isObject(payload)) throw new TypeError("JWT Claims Set MUST be an object");
|
|
1122
|
+
this.#payload = structuredClone(payload);
|
|
1123
|
+
}
|
|
1124
|
+
data() {
|
|
1125
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
1126
|
+
}
|
|
1127
|
+
get iss() {
|
|
1128
|
+
return this.#payload.iss;
|
|
1129
|
+
}
|
|
1130
|
+
set iss(value) {
|
|
1131
|
+
this.#payload.iss = value;
|
|
1132
|
+
}
|
|
1133
|
+
get sub() {
|
|
1134
|
+
return this.#payload.sub;
|
|
1135
|
+
}
|
|
1136
|
+
set sub(value) {
|
|
1137
|
+
this.#payload.sub = value;
|
|
1138
|
+
}
|
|
1139
|
+
get aud() {
|
|
1140
|
+
return this.#payload.aud;
|
|
1141
|
+
}
|
|
1142
|
+
set aud(value) {
|
|
1143
|
+
this.#payload.aud = value;
|
|
1144
|
+
}
|
|
1145
|
+
set jti(value) {
|
|
1146
|
+
this.#payload.jti = value;
|
|
1147
|
+
}
|
|
1148
|
+
set nbf(value) {
|
|
1149
|
+
if (typeof value === "number") this.#payload.nbf = validateInput("setNotBefore", value);
|
|
1150
|
+
else if (value instanceof Date) this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
1151
|
+
else this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1152
|
+
}
|
|
1153
|
+
set exp(value) {
|
|
1154
|
+
if (typeof value === "number") this.#payload.exp = validateInput("setExpirationTime", value);
|
|
1155
|
+
else if (value instanceof Date) this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
1156
|
+
else this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1157
|
+
}
|
|
1158
|
+
set iat(value) {
|
|
1159
|
+
if (value === void 0) this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
1160
|
+
else if (value instanceof Date) this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
1161
|
+
else if (typeof value === "string") this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
1162
|
+
else this.#payload.iat = validateInput("setIssuedAt", value);
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
//#endregion
|
|
1167
|
+
//#region ../../node_modules/.pnpm/jose@6.1.2/node_modules/jose/dist/webapi/jwt/verify.js
|
|
1168
|
+
async function jwtVerify(jwt, key, options) {
|
|
1169
|
+
const verified = await compactVerify(jwt, key, options);
|
|
1170
|
+
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
1171
|
+
const result = {
|
|
1172
|
+
payload: validateClaimsSet(verified.protectedHeader, verified.payload, options),
|
|
1173
|
+
protectedHeader: verified.protectedHeader
|
|
1174
|
+
};
|
|
1175
|
+
if (typeof key === "function") return {
|
|
1176
|
+
...result,
|
|
1177
|
+
key: verified.key
|
|
1178
|
+
};
|
|
1179
|
+
return result;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
//#endregion
|
|
1183
|
+
export { JWKSTimeout as A, uint32be as B, JOSENotSupported as C, JWKSInvalid as D, JWKInvalid as E, decode as F, base64 as H, encode$1 as I, concat as L, JWTClaimValidationFailed as M, JWTExpired as N, JWKSMultipleMatchingKeys as O, JWTInvalid as P, decoder as R, JOSEError as S, JWEInvalid as T, base64Url as U, uint64be as V, isKeyLike as _, subtleAlgorithm as a, checkEncCryptoKey as b, isJWK as c, importJWK as d, checkKeyLength as f, isCryptoKey as g, assertCryptoKey as h, getSigKey as i, JWSInvalid as j, JWKSNoMatchingKey as k, validateAlgorithms as l, isDisjoint as m, JWTClaimsBuilder as n, checkKeyType as o, isObject as p, validateClaimsSet as r, normalizeKey as s, jwtVerify as t, validateCrit as u, isKeyObject as v, JWEDecryptionFailed as w, JOSEAlgNotAllowed as x, invalidKeyInput as y, encode as z };
|