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