@solvapay/server 1.0.0-preview.9 → 1.0.1-preview.2
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/LICENSE.md +21 -0
- package/README.md +87 -46
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/edge.d.ts +2598 -329
- package/dist/edge.js +1006 -296
- package/dist/index.cjs +3601 -2757
- package/dist/index.d.cts +2740 -382
- package/dist/index.d.ts +2740 -382
- package/dist/index.js +1063 -295
- package/dist/webapi-K5XBCEO6.js +3775 -0
- package/package.json +18 -13
- package/dist/chunk-R5U7XKVJ.js +0 -16
- package/dist/esm-5GYCIXIY.js +0 -3475
|
@@ -0,0 +1,3775 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/base64url.js
|
|
6
|
+
var base64url_exports = {};
|
|
7
|
+
__export(base64url_exports, {
|
|
8
|
+
decode: () => decode,
|
|
9
|
+
encode: () => encode2
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
13
|
+
var encoder = new TextEncoder();
|
|
14
|
+
var decoder = new TextDecoder();
|
|
15
|
+
var MAX_INT32 = 2 ** 32;
|
|
16
|
+
function concat(...buffers) {
|
|
17
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
18
|
+
const buf = new Uint8Array(size);
|
|
19
|
+
let i = 0;
|
|
20
|
+
for (const buffer of buffers) {
|
|
21
|
+
buf.set(buffer, i);
|
|
22
|
+
i += buffer.length;
|
|
23
|
+
}
|
|
24
|
+
return buf;
|
|
25
|
+
}
|
|
26
|
+
function writeUInt32BE(buf, value, offset) {
|
|
27
|
+
if (value < 0 || value >= MAX_INT32) {
|
|
28
|
+
throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
29
|
+
}
|
|
30
|
+
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
|
|
31
|
+
}
|
|
32
|
+
function uint64be(value) {
|
|
33
|
+
const high = Math.floor(value / MAX_INT32);
|
|
34
|
+
const low = value % MAX_INT32;
|
|
35
|
+
const buf = new Uint8Array(8);
|
|
36
|
+
writeUInt32BE(buf, high, 0);
|
|
37
|
+
writeUInt32BE(buf, low, 4);
|
|
38
|
+
return buf;
|
|
39
|
+
}
|
|
40
|
+
function uint32be(value) {
|
|
41
|
+
const buf = new Uint8Array(4);
|
|
42
|
+
writeUInt32BE(buf, value);
|
|
43
|
+
return buf;
|
|
44
|
+
}
|
|
45
|
+
function encode(string) {
|
|
46
|
+
const bytes = new Uint8Array(string.length);
|
|
47
|
+
for (let i = 0; i < string.length; i++) {
|
|
48
|
+
const code = string.charCodeAt(i);
|
|
49
|
+
if (code > 127) {
|
|
50
|
+
throw new TypeError("non-ASCII string encountered in encode()");
|
|
51
|
+
}
|
|
52
|
+
bytes[i] = code;
|
|
53
|
+
}
|
|
54
|
+
return bytes;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/base64.js
|
|
58
|
+
function encodeBase64(input) {
|
|
59
|
+
if (Uint8Array.prototype.toBase64) {
|
|
60
|
+
return input.toBase64();
|
|
61
|
+
}
|
|
62
|
+
const CHUNK_SIZE = 32768;
|
|
63
|
+
const arr = [];
|
|
64
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
65
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
66
|
+
}
|
|
67
|
+
return btoa(arr.join(""));
|
|
68
|
+
}
|
|
69
|
+
function decodeBase64(encoded) {
|
|
70
|
+
if (Uint8Array.fromBase64) {
|
|
71
|
+
return Uint8Array.fromBase64(encoded);
|
|
72
|
+
}
|
|
73
|
+
const binary = atob(encoded);
|
|
74
|
+
const bytes = new Uint8Array(binary.length);
|
|
75
|
+
for (let i = 0; i < binary.length; i++) {
|
|
76
|
+
bytes[i] = binary.charCodeAt(i);
|
|
77
|
+
}
|
|
78
|
+
return bytes;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/base64url.js
|
|
82
|
+
function decode(input) {
|
|
83
|
+
if (Uint8Array.fromBase64) {
|
|
84
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
85
|
+
alphabet: "base64url"
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
let encoded = input;
|
|
89
|
+
if (encoded instanceof Uint8Array) {
|
|
90
|
+
encoded = decoder.decode(encoded);
|
|
91
|
+
}
|
|
92
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
93
|
+
try {
|
|
94
|
+
return decodeBase64(encoded);
|
|
95
|
+
} catch {
|
|
96
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function encode2(input) {
|
|
100
|
+
let unencoded = input;
|
|
101
|
+
if (typeof unencoded === "string") {
|
|
102
|
+
unencoded = encoder.encode(unencoded);
|
|
103
|
+
}
|
|
104
|
+
if (Uint8Array.prototype.toBase64) {
|
|
105
|
+
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
106
|
+
}
|
|
107
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
111
|
+
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
112
|
+
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
113
|
+
function getHashLength(hash) {
|
|
114
|
+
return parseInt(hash.name.slice(4), 10);
|
|
115
|
+
}
|
|
116
|
+
function checkHashLength(algorithm, expected) {
|
|
117
|
+
const actual = getHashLength(algorithm.hash);
|
|
118
|
+
if (actual !== expected)
|
|
119
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
120
|
+
}
|
|
121
|
+
function getNamedCurve(alg) {
|
|
122
|
+
switch (alg) {
|
|
123
|
+
case "ES256":
|
|
124
|
+
return "P-256";
|
|
125
|
+
case "ES384":
|
|
126
|
+
return "P-384";
|
|
127
|
+
case "ES512":
|
|
128
|
+
return "P-521";
|
|
129
|
+
default:
|
|
130
|
+
throw new Error("unreachable");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function checkUsage(key, usage) {
|
|
134
|
+
if (usage && !key.usages.includes(usage)) {
|
|
135
|
+
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
139
|
+
switch (alg) {
|
|
140
|
+
case "HS256":
|
|
141
|
+
case "HS384":
|
|
142
|
+
case "HS512": {
|
|
143
|
+
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
144
|
+
throw unusable("HMAC");
|
|
145
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case "RS256":
|
|
149
|
+
case "RS384":
|
|
150
|
+
case "RS512": {
|
|
151
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
152
|
+
throw unusable("RSASSA-PKCS1-v1_5");
|
|
153
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "PS256":
|
|
157
|
+
case "PS384":
|
|
158
|
+
case "PS512": {
|
|
159
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
160
|
+
throw unusable("RSA-PSS");
|
|
161
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case "Ed25519":
|
|
165
|
+
case "EdDSA": {
|
|
166
|
+
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
167
|
+
throw unusable("Ed25519");
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case "ML-DSA-44":
|
|
171
|
+
case "ML-DSA-65":
|
|
172
|
+
case "ML-DSA-87": {
|
|
173
|
+
if (!isAlgorithm(key.algorithm, alg))
|
|
174
|
+
throw unusable(alg);
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case "ES256":
|
|
178
|
+
case "ES384":
|
|
179
|
+
case "ES512": {
|
|
180
|
+
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
181
|
+
throw unusable("ECDSA");
|
|
182
|
+
const expected = getNamedCurve(alg);
|
|
183
|
+
const actual = key.algorithm.namedCurve;
|
|
184
|
+
if (actual !== expected)
|
|
185
|
+
throw unusable(expected, "algorithm.namedCurve");
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
default:
|
|
189
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
190
|
+
}
|
|
191
|
+
checkUsage(key, usage);
|
|
192
|
+
}
|
|
193
|
+
function checkEncCryptoKey(key, alg, usage) {
|
|
194
|
+
switch (alg) {
|
|
195
|
+
case "A128GCM":
|
|
196
|
+
case "A192GCM":
|
|
197
|
+
case "A256GCM": {
|
|
198
|
+
if (!isAlgorithm(key.algorithm, "AES-GCM"))
|
|
199
|
+
throw unusable("AES-GCM");
|
|
200
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
201
|
+
const actual = key.algorithm.length;
|
|
202
|
+
if (actual !== expected)
|
|
203
|
+
throw unusable(expected, "algorithm.length");
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
case "A128KW":
|
|
207
|
+
case "A192KW":
|
|
208
|
+
case "A256KW": {
|
|
209
|
+
if (!isAlgorithm(key.algorithm, "AES-KW"))
|
|
210
|
+
throw unusable("AES-KW");
|
|
211
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
212
|
+
const actual = key.algorithm.length;
|
|
213
|
+
if (actual !== expected)
|
|
214
|
+
throw unusable(expected, "algorithm.length");
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "ECDH": {
|
|
218
|
+
switch (key.algorithm.name) {
|
|
219
|
+
case "ECDH":
|
|
220
|
+
case "X25519":
|
|
221
|
+
break;
|
|
222
|
+
default:
|
|
223
|
+
throw unusable("ECDH or X25519");
|
|
224
|
+
}
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case "PBES2-HS256+A128KW":
|
|
228
|
+
case "PBES2-HS384+A192KW":
|
|
229
|
+
case "PBES2-HS512+A256KW":
|
|
230
|
+
if (!isAlgorithm(key.algorithm, "PBKDF2"))
|
|
231
|
+
throw unusable("PBKDF2");
|
|
232
|
+
break;
|
|
233
|
+
case "RSA-OAEP":
|
|
234
|
+
case "RSA-OAEP-256":
|
|
235
|
+
case "RSA-OAEP-384":
|
|
236
|
+
case "RSA-OAEP-512": {
|
|
237
|
+
if (!isAlgorithm(key.algorithm, "RSA-OAEP"))
|
|
238
|
+
throw unusable("RSA-OAEP");
|
|
239
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(9), 10) || 1);
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
default:
|
|
243
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
244
|
+
}
|
|
245
|
+
checkUsage(key, usage);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
249
|
+
function message(msg, actual, ...types) {
|
|
250
|
+
types = types.filter(Boolean);
|
|
251
|
+
if (types.length > 2) {
|
|
252
|
+
const last = types.pop();
|
|
253
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
254
|
+
} else if (types.length === 2) {
|
|
255
|
+
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
256
|
+
} else {
|
|
257
|
+
msg += `of type ${types[0]}.`;
|
|
258
|
+
}
|
|
259
|
+
if (actual == null) {
|
|
260
|
+
msg += ` Received ${actual}`;
|
|
261
|
+
} else if (typeof actual === "function" && actual.name) {
|
|
262
|
+
msg += ` Received function ${actual.name}`;
|
|
263
|
+
} else if (typeof actual === "object" && actual != null) {
|
|
264
|
+
if (actual.constructor?.name) {
|
|
265
|
+
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return msg;
|
|
269
|
+
}
|
|
270
|
+
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
271
|
+
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
272
|
+
|
|
273
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/errors.js
|
|
274
|
+
var errors_exports = {};
|
|
275
|
+
__export(errors_exports, {
|
|
276
|
+
JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
|
|
277
|
+
JOSEError: () => JOSEError,
|
|
278
|
+
JOSENotSupported: () => JOSENotSupported,
|
|
279
|
+
JWEDecryptionFailed: () => JWEDecryptionFailed,
|
|
280
|
+
JWEInvalid: () => JWEInvalid,
|
|
281
|
+
JWKInvalid: () => JWKInvalid,
|
|
282
|
+
JWKSInvalid: () => JWKSInvalid,
|
|
283
|
+
JWKSMultipleMatchingKeys: () => JWKSMultipleMatchingKeys,
|
|
284
|
+
JWKSNoMatchingKey: () => JWKSNoMatchingKey,
|
|
285
|
+
JWKSTimeout: () => JWKSTimeout,
|
|
286
|
+
JWSInvalid: () => JWSInvalid,
|
|
287
|
+
JWSSignatureVerificationFailed: () => JWSSignatureVerificationFailed,
|
|
288
|
+
JWTClaimValidationFailed: () => JWTClaimValidationFailed,
|
|
289
|
+
JWTExpired: () => JWTExpired,
|
|
290
|
+
JWTInvalid: () => JWTInvalid
|
|
291
|
+
});
|
|
292
|
+
var JOSEError = class extends Error {
|
|
293
|
+
static code = "ERR_JOSE_GENERIC";
|
|
294
|
+
code = "ERR_JOSE_GENERIC";
|
|
295
|
+
constructor(message2, options) {
|
|
296
|
+
super(message2, options);
|
|
297
|
+
this.name = this.constructor.name;
|
|
298
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
302
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
303
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
304
|
+
claim;
|
|
305
|
+
reason;
|
|
306
|
+
payload;
|
|
307
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
308
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
309
|
+
this.claim = claim;
|
|
310
|
+
this.reason = reason;
|
|
311
|
+
this.payload = payload;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
var JWTExpired = class extends JOSEError {
|
|
315
|
+
static code = "ERR_JWT_EXPIRED";
|
|
316
|
+
code = "ERR_JWT_EXPIRED";
|
|
317
|
+
claim;
|
|
318
|
+
reason;
|
|
319
|
+
payload;
|
|
320
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
321
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
322
|
+
this.claim = claim;
|
|
323
|
+
this.reason = reason;
|
|
324
|
+
this.payload = payload;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
328
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
329
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
330
|
+
};
|
|
331
|
+
var JOSENotSupported = class extends JOSEError {
|
|
332
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
333
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
334
|
+
};
|
|
335
|
+
var JWEDecryptionFailed = class extends JOSEError {
|
|
336
|
+
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
337
|
+
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
338
|
+
constructor(message2 = "decryption operation failed", options) {
|
|
339
|
+
super(message2, options);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
var JWEInvalid = class extends JOSEError {
|
|
343
|
+
static code = "ERR_JWE_INVALID";
|
|
344
|
+
code = "ERR_JWE_INVALID";
|
|
345
|
+
};
|
|
346
|
+
var JWSInvalid = class extends JOSEError {
|
|
347
|
+
static code = "ERR_JWS_INVALID";
|
|
348
|
+
code = "ERR_JWS_INVALID";
|
|
349
|
+
};
|
|
350
|
+
var JWTInvalid = class extends JOSEError {
|
|
351
|
+
static code = "ERR_JWT_INVALID";
|
|
352
|
+
code = "ERR_JWT_INVALID";
|
|
353
|
+
};
|
|
354
|
+
var JWKInvalid = class extends JOSEError {
|
|
355
|
+
static code = "ERR_JWK_INVALID";
|
|
356
|
+
code = "ERR_JWK_INVALID";
|
|
357
|
+
};
|
|
358
|
+
var JWKSInvalid = class extends JOSEError {
|
|
359
|
+
static code = "ERR_JWKS_INVALID";
|
|
360
|
+
code = "ERR_JWKS_INVALID";
|
|
361
|
+
};
|
|
362
|
+
var JWKSNoMatchingKey = class extends JOSEError {
|
|
363
|
+
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
364
|
+
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
365
|
+
constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
|
|
366
|
+
super(message2, options);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
var JWKSMultipleMatchingKeys = class extends JOSEError {
|
|
370
|
+
[Symbol.asyncIterator];
|
|
371
|
+
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
372
|
+
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
373
|
+
constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
374
|
+
super(message2, options);
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
var JWKSTimeout = class extends JOSEError {
|
|
378
|
+
static code = "ERR_JWKS_TIMEOUT";
|
|
379
|
+
code = "ERR_JWKS_TIMEOUT";
|
|
380
|
+
constructor(message2 = "request timed out", options) {
|
|
381
|
+
super(message2, options);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
385
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
386
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
387
|
+
constructor(message2 = "signature verification failed", options) {
|
|
388
|
+
super(message2, options);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
393
|
+
function assertCryptoKey(key) {
|
|
394
|
+
if (!isCryptoKey(key)) {
|
|
395
|
+
throw new Error("CryptoKey instance expected");
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
var isCryptoKey = (key) => {
|
|
399
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
400
|
+
return true;
|
|
401
|
+
try {
|
|
402
|
+
return key instanceof CryptoKey;
|
|
403
|
+
} catch {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
408
|
+
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
409
|
+
|
|
410
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/content_encryption.js
|
|
411
|
+
function cekLength(alg) {
|
|
412
|
+
switch (alg) {
|
|
413
|
+
case "A128GCM":
|
|
414
|
+
return 128;
|
|
415
|
+
case "A192GCM":
|
|
416
|
+
return 192;
|
|
417
|
+
case "A256GCM":
|
|
418
|
+
case "A128CBC-HS256":
|
|
419
|
+
return 256;
|
|
420
|
+
case "A192CBC-HS384":
|
|
421
|
+
return 384;
|
|
422
|
+
case "A256CBC-HS512":
|
|
423
|
+
return 512;
|
|
424
|
+
default:
|
|
425
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
var generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
429
|
+
function checkCekLength(cek, expected) {
|
|
430
|
+
const actual = cek.byteLength << 3;
|
|
431
|
+
if (actual !== expected) {
|
|
432
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function ivBitLength(alg) {
|
|
436
|
+
switch (alg) {
|
|
437
|
+
case "A128GCM":
|
|
438
|
+
case "A128GCMKW":
|
|
439
|
+
case "A192GCM":
|
|
440
|
+
case "A192GCMKW":
|
|
441
|
+
case "A256GCM":
|
|
442
|
+
case "A256GCMKW":
|
|
443
|
+
return 96;
|
|
444
|
+
case "A128CBC-HS256":
|
|
445
|
+
case "A192CBC-HS384":
|
|
446
|
+
case "A256CBC-HS512":
|
|
447
|
+
return 128;
|
|
448
|
+
default:
|
|
449
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
var generateIv = (alg) => crypto.getRandomValues(new Uint8Array(ivBitLength(alg) >> 3));
|
|
453
|
+
function checkIvLength(enc, iv) {
|
|
454
|
+
if (iv.length << 3 !== ivBitLength(enc)) {
|
|
455
|
+
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
async function cbcKeySetup(enc, cek, usage) {
|
|
459
|
+
if (!(cek instanceof Uint8Array)) {
|
|
460
|
+
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
461
|
+
}
|
|
462
|
+
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
463
|
+
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, [usage]);
|
|
464
|
+
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
465
|
+
hash: `SHA-${keySize << 1}`,
|
|
466
|
+
name: "HMAC"
|
|
467
|
+
}, false, ["sign"]);
|
|
468
|
+
return { encKey, macKey, keySize };
|
|
469
|
+
}
|
|
470
|
+
async function cbcHmacTag(macKey, macData, keySize) {
|
|
471
|
+
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
472
|
+
}
|
|
473
|
+
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
474
|
+
const { encKey, macKey, keySize } = await cbcKeySetup(enc, cek, "encrypt");
|
|
475
|
+
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
476
|
+
iv,
|
|
477
|
+
name: "AES-CBC"
|
|
478
|
+
}, encKey, plaintext));
|
|
479
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
480
|
+
const tag2 = await cbcHmacTag(macKey, macData, keySize);
|
|
481
|
+
return { ciphertext, tag: tag2, iv };
|
|
482
|
+
}
|
|
483
|
+
async function timingSafeEqual(a, b) {
|
|
484
|
+
if (!(a instanceof Uint8Array)) {
|
|
485
|
+
throw new TypeError("First argument must be a buffer");
|
|
486
|
+
}
|
|
487
|
+
if (!(b instanceof Uint8Array)) {
|
|
488
|
+
throw new TypeError("Second argument must be a buffer");
|
|
489
|
+
}
|
|
490
|
+
const algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
491
|
+
const key = await crypto.subtle.generateKey(algorithm, false, ["sign"]);
|
|
492
|
+
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
493
|
+
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
494
|
+
let out = 0;
|
|
495
|
+
let i = -1;
|
|
496
|
+
while (++i < 32) {
|
|
497
|
+
out |= aHmac[i] ^ bHmac[i];
|
|
498
|
+
}
|
|
499
|
+
return out === 0;
|
|
500
|
+
}
|
|
501
|
+
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
502
|
+
const { encKey, macKey, keySize } = await cbcKeySetup(enc, cek, "decrypt");
|
|
503
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
504
|
+
const expectedTag = await cbcHmacTag(macKey, macData, keySize);
|
|
505
|
+
let macCheckPassed;
|
|
506
|
+
try {
|
|
507
|
+
macCheckPassed = await timingSafeEqual(tag2, expectedTag);
|
|
508
|
+
} catch {
|
|
509
|
+
}
|
|
510
|
+
if (!macCheckPassed) {
|
|
511
|
+
throw new JWEDecryptionFailed();
|
|
512
|
+
}
|
|
513
|
+
let plaintext;
|
|
514
|
+
try {
|
|
515
|
+
plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
516
|
+
} catch {
|
|
517
|
+
}
|
|
518
|
+
if (!plaintext) {
|
|
519
|
+
throw new JWEDecryptionFailed();
|
|
520
|
+
}
|
|
521
|
+
return plaintext;
|
|
522
|
+
}
|
|
523
|
+
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
524
|
+
let encKey;
|
|
525
|
+
if (cek instanceof Uint8Array) {
|
|
526
|
+
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
|
|
527
|
+
} else {
|
|
528
|
+
checkEncCryptoKey(cek, enc, "encrypt");
|
|
529
|
+
encKey = cek;
|
|
530
|
+
}
|
|
531
|
+
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
532
|
+
additionalData: aad,
|
|
533
|
+
iv,
|
|
534
|
+
name: "AES-GCM",
|
|
535
|
+
tagLength: 128
|
|
536
|
+
}, encKey, plaintext));
|
|
537
|
+
const tag2 = encrypted.slice(-16);
|
|
538
|
+
const ciphertext = encrypted.slice(0, -16);
|
|
539
|
+
return { ciphertext, tag: tag2, iv };
|
|
540
|
+
}
|
|
541
|
+
async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
542
|
+
let encKey;
|
|
543
|
+
if (cek instanceof Uint8Array) {
|
|
544
|
+
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["decrypt"]);
|
|
545
|
+
} else {
|
|
546
|
+
checkEncCryptoKey(cek, enc, "decrypt");
|
|
547
|
+
encKey = cek;
|
|
548
|
+
}
|
|
549
|
+
try {
|
|
550
|
+
return new Uint8Array(await crypto.subtle.decrypt({
|
|
551
|
+
additionalData: aad,
|
|
552
|
+
iv,
|
|
553
|
+
name: "AES-GCM",
|
|
554
|
+
tagLength: 128
|
|
555
|
+
}, encKey, concat(ciphertext, tag2)));
|
|
556
|
+
} catch {
|
|
557
|
+
throw new JWEDecryptionFailed();
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
var unsupportedEnc = "Unsupported JWE Content Encryption Algorithm";
|
|
561
|
+
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
562
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
563
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
564
|
+
}
|
|
565
|
+
if (iv) {
|
|
566
|
+
checkIvLength(enc, iv);
|
|
567
|
+
} else {
|
|
568
|
+
iv = generateIv(enc);
|
|
569
|
+
}
|
|
570
|
+
switch (enc) {
|
|
571
|
+
case "A128CBC-HS256":
|
|
572
|
+
case "A192CBC-HS384":
|
|
573
|
+
case "A256CBC-HS512":
|
|
574
|
+
if (cek instanceof Uint8Array) {
|
|
575
|
+
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
576
|
+
}
|
|
577
|
+
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
578
|
+
case "A128GCM":
|
|
579
|
+
case "A192GCM":
|
|
580
|
+
case "A256GCM":
|
|
581
|
+
if (cek instanceof Uint8Array) {
|
|
582
|
+
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
583
|
+
}
|
|
584
|
+
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
585
|
+
default:
|
|
586
|
+
throw new JOSENotSupported(unsupportedEnc);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
async function decrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
590
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
591
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
592
|
+
}
|
|
593
|
+
if (!iv) {
|
|
594
|
+
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
595
|
+
}
|
|
596
|
+
if (!tag2) {
|
|
597
|
+
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
598
|
+
}
|
|
599
|
+
checkIvLength(enc, iv);
|
|
600
|
+
switch (enc) {
|
|
601
|
+
case "A128CBC-HS256":
|
|
602
|
+
case "A192CBC-HS384":
|
|
603
|
+
case "A256CBC-HS512":
|
|
604
|
+
if (cek instanceof Uint8Array)
|
|
605
|
+
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
606
|
+
return cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
607
|
+
case "A128GCM":
|
|
608
|
+
case "A192GCM":
|
|
609
|
+
case "A256GCM":
|
|
610
|
+
if (cek instanceof Uint8Array)
|
|
611
|
+
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
612
|
+
return gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
613
|
+
default:
|
|
614
|
+
throw new JOSENotSupported(unsupportedEnc);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/helpers.js
|
|
619
|
+
var unprotected = /* @__PURE__ */ Symbol();
|
|
620
|
+
function assertNotSet(value, name) {
|
|
621
|
+
if (value) {
|
|
622
|
+
throw new TypeError(`${name} can only be called once`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
626
|
+
try {
|
|
627
|
+
return decode(value);
|
|
628
|
+
} catch {
|
|
629
|
+
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
async function digest(algorithm, data) {
|
|
633
|
+
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
634
|
+
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/type_checks.js
|
|
638
|
+
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
639
|
+
function isObject(input) {
|
|
640
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
let proto = input;
|
|
647
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
648
|
+
proto = Object.getPrototypeOf(proto);
|
|
649
|
+
}
|
|
650
|
+
return Object.getPrototypeOf(input) === proto;
|
|
651
|
+
}
|
|
652
|
+
function isDisjoint(...headers) {
|
|
653
|
+
const sources = headers.filter(Boolean);
|
|
654
|
+
if (sources.length === 0 || sources.length === 1) {
|
|
655
|
+
return true;
|
|
656
|
+
}
|
|
657
|
+
let acc;
|
|
658
|
+
for (const header of sources) {
|
|
659
|
+
const parameters = Object.keys(header);
|
|
660
|
+
if (!acc || acc.size === 0) {
|
|
661
|
+
acc = new Set(parameters);
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
for (const parameter of parameters) {
|
|
665
|
+
if (acc.has(parameter)) {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
acc.add(parameter);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
674
|
+
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
675
|
+
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
676
|
+
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
677
|
+
|
|
678
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/aeskw.js
|
|
679
|
+
function checkKeySize(key, alg) {
|
|
680
|
+
if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
|
|
681
|
+
throw new TypeError(`Invalid key size for alg: ${alg}`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
function getCryptoKey(key, alg, usage) {
|
|
685
|
+
if (key instanceof Uint8Array) {
|
|
686
|
+
return crypto.subtle.importKey("raw", key, "AES-KW", true, [usage]);
|
|
687
|
+
}
|
|
688
|
+
checkEncCryptoKey(key, alg, usage);
|
|
689
|
+
return key;
|
|
690
|
+
}
|
|
691
|
+
async function wrap(alg, key, cek) {
|
|
692
|
+
const cryptoKey = await getCryptoKey(key, alg, "wrapKey");
|
|
693
|
+
checkKeySize(cryptoKey, alg);
|
|
694
|
+
const cryptoKeyCek = await crypto.subtle.importKey("raw", cek, { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
695
|
+
return new Uint8Array(await crypto.subtle.wrapKey("raw", cryptoKeyCek, cryptoKey, "AES-KW"));
|
|
696
|
+
}
|
|
697
|
+
async function unwrap(alg, key, encryptedKey) {
|
|
698
|
+
const cryptoKey = await getCryptoKey(key, alg, "unwrapKey");
|
|
699
|
+
checkKeySize(cryptoKey, alg);
|
|
700
|
+
const cryptoKeyCek = await crypto.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
701
|
+
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/ecdhes.js
|
|
705
|
+
function lengthAndInput(input) {
|
|
706
|
+
return concat(uint32be(input.length), input);
|
|
707
|
+
}
|
|
708
|
+
async function concatKdf(Z, L, OtherInfo) {
|
|
709
|
+
const dkLen = L >> 3;
|
|
710
|
+
const hashLen = 32;
|
|
711
|
+
const reps = Math.ceil(dkLen / hashLen);
|
|
712
|
+
const dk = new Uint8Array(reps * hashLen);
|
|
713
|
+
for (let i = 1; i <= reps; i++) {
|
|
714
|
+
const hashInput = new Uint8Array(4 + Z.length + OtherInfo.length);
|
|
715
|
+
hashInput.set(uint32be(i), 0);
|
|
716
|
+
hashInput.set(Z, 4);
|
|
717
|
+
hashInput.set(OtherInfo, 4 + Z.length);
|
|
718
|
+
const hashResult = await digest("sha256", hashInput);
|
|
719
|
+
dk.set(hashResult, (i - 1) * hashLen);
|
|
720
|
+
}
|
|
721
|
+
return dk.slice(0, dkLen);
|
|
722
|
+
}
|
|
723
|
+
async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
|
|
724
|
+
checkEncCryptoKey(publicKey, "ECDH");
|
|
725
|
+
checkEncCryptoKey(privateKey, "ECDH", "deriveBits");
|
|
726
|
+
const algorithmID = lengthAndInput(encode(algorithm));
|
|
727
|
+
const partyUInfo = lengthAndInput(apu);
|
|
728
|
+
const partyVInfo = lengthAndInput(apv);
|
|
729
|
+
const suppPubInfo = uint32be(keyLength);
|
|
730
|
+
const suppPrivInfo = new Uint8Array();
|
|
731
|
+
const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
|
|
732
|
+
const Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
733
|
+
name: publicKey.algorithm.name,
|
|
734
|
+
public: publicKey
|
|
735
|
+
}, privateKey, getEcdhBitLength(publicKey)));
|
|
736
|
+
return concatKdf(Z, keyLength, otherInfo);
|
|
737
|
+
}
|
|
738
|
+
function getEcdhBitLength(publicKey) {
|
|
739
|
+
if (publicKey.algorithm.name === "X25519") {
|
|
740
|
+
return 256;
|
|
741
|
+
}
|
|
742
|
+
return Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3;
|
|
743
|
+
}
|
|
744
|
+
function allowed(key) {
|
|
745
|
+
switch (key.algorithm.namedCurve) {
|
|
746
|
+
case "P-256":
|
|
747
|
+
case "P-384":
|
|
748
|
+
case "P-521":
|
|
749
|
+
return true;
|
|
750
|
+
default:
|
|
751
|
+
return key.algorithm.name === "X25519";
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/pbes2kw.js
|
|
756
|
+
function getCryptoKey2(key, alg) {
|
|
757
|
+
if (key instanceof Uint8Array) {
|
|
758
|
+
return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
|
|
759
|
+
"deriveBits"
|
|
760
|
+
]);
|
|
761
|
+
}
|
|
762
|
+
checkEncCryptoKey(key, alg, "deriveBits");
|
|
763
|
+
return key;
|
|
764
|
+
}
|
|
765
|
+
var concatSalt = (alg, p2sInput) => concat(encode(alg), Uint8Array.of(0), p2sInput);
|
|
766
|
+
async function deriveKey2(p2s, alg, p2c, key) {
|
|
767
|
+
if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
|
|
768
|
+
throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
|
|
769
|
+
}
|
|
770
|
+
const salt = concatSalt(alg, p2s);
|
|
771
|
+
const keylen = parseInt(alg.slice(13, 16), 10);
|
|
772
|
+
const subtleAlg = {
|
|
773
|
+
hash: `SHA-${alg.slice(8, 11)}`,
|
|
774
|
+
iterations: p2c,
|
|
775
|
+
name: "PBKDF2",
|
|
776
|
+
salt
|
|
777
|
+
};
|
|
778
|
+
const cryptoKey = await getCryptoKey2(key, alg);
|
|
779
|
+
return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
|
|
780
|
+
}
|
|
781
|
+
async function wrap2(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
|
|
782
|
+
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
783
|
+
const encryptedKey = await wrap(alg.slice(-6), derived, cek);
|
|
784
|
+
return { encryptedKey, p2c, p2s: encode2(p2s) };
|
|
785
|
+
}
|
|
786
|
+
async function unwrap2(alg, key, encryptedKey, p2c, p2s) {
|
|
787
|
+
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
788
|
+
return unwrap(alg.slice(-6), derived, encryptedKey);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/signing.js
|
|
792
|
+
function checkKeyLength(alg, key) {
|
|
793
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
794
|
+
const { modulusLength } = key.algorithm;
|
|
795
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
796
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
801
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
802
|
+
switch (alg) {
|
|
803
|
+
case "HS256":
|
|
804
|
+
case "HS384":
|
|
805
|
+
case "HS512":
|
|
806
|
+
return { hash, name: "HMAC" };
|
|
807
|
+
case "PS256":
|
|
808
|
+
case "PS384":
|
|
809
|
+
case "PS512":
|
|
810
|
+
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
811
|
+
case "RS256":
|
|
812
|
+
case "RS384":
|
|
813
|
+
case "RS512":
|
|
814
|
+
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
815
|
+
case "ES256":
|
|
816
|
+
case "ES384":
|
|
817
|
+
case "ES512":
|
|
818
|
+
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
819
|
+
case "Ed25519":
|
|
820
|
+
case "EdDSA":
|
|
821
|
+
return { name: "Ed25519" };
|
|
822
|
+
case "ML-DSA-44":
|
|
823
|
+
case "ML-DSA-65":
|
|
824
|
+
case "ML-DSA-87":
|
|
825
|
+
return { name: alg };
|
|
826
|
+
default:
|
|
827
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
async function getSigKey(alg, key, usage) {
|
|
831
|
+
if (key instanceof Uint8Array) {
|
|
832
|
+
if (!alg.startsWith("HS")) {
|
|
833
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
834
|
+
}
|
|
835
|
+
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
836
|
+
}
|
|
837
|
+
checkSigCryptoKey(key, alg, usage);
|
|
838
|
+
return key;
|
|
839
|
+
}
|
|
840
|
+
async function sign(alg, key, data) {
|
|
841
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
842
|
+
checkKeyLength(alg, cryptoKey);
|
|
843
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
844
|
+
return new Uint8Array(signature);
|
|
845
|
+
}
|
|
846
|
+
async function verify(alg, key, signature, data) {
|
|
847
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
848
|
+
checkKeyLength(alg, cryptoKey);
|
|
849
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
850
|
+
try {
|
|
851
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
852
|
+
} catch {
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/rsaes.js
|
|
858
|
+
var subtleAlgorithm2 = (alg) => {
|
|
859
|
+
switch (alg) {
|
|
860
|
+
case "RSA-OAEP":
|
|
861
|
+
case "RSA-OAEP-256":
|
|
862
|
+
case "RSA-OAEP-384":
|
|
863
|
+
case "RSA-OAEP-512":
|
|
864
|
+
return "RSA-OAEP";
|
|
865
|
+
default:
|
|
866
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
async function encrypt2(alg, key, cek) {
|
|
870
|
+
checkEncCryptoKey(key, alg, "encrypt");
|
|
871
|
+
checkKeyLength(alg, key);
|
|
872
|
+
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm2(alg), key, cek));
|
|
873
|
+
}
|
|
874
|
+
async function decrypt2(alg, key, encryptedKey) {
|
|
875
|
+
checkEncCryptoKey(key, alg, "decrypt");
|
|
876
|
+
checkKeyLength(alg, key);
|
|
877
|
+
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm2(alg), key, encryptedKey));
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
881
|
+
var unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
|
|
882
|
+
function subtleMapping(jwk) {
|
|
883
|
+
let algorithm;
|
|
884
|
+
let keyUsages;
|
|
885
|
+
switch (jwk.kty) {
|
|
886
|
+
case "AKP": {
|
|
887
|
+
switch (jwk.alg) {
|
|
888
|
+
case "ML-DSA-44":
|
|
889
|
+
case "ML-DSA-65":
|
|
890
|
+
case "ML-DSA-87":
|
|
891
|
+
algorithm = { name: jwk.alg };
|
|
892
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
893
|
+
break;
|
|
894
|
+
default:
|
|
895
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
896
|
+
}
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
case "RSA": {
|
|
900
|
+
switch (jwk.alg) {
|
|
901
|
+
case "PS256":
|
|
902
|
+
case "PS384":
|
|
903
|
+
case "PS512":
|
|
904
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
905
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
906
|
+
break;
|
|
907
|
+
case "RS256":
|
|
908
|
+
case "RS384":
|
|
909
|
+
case "RS512":
|
|
910
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
911
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
912
|
+
break;
|
|
913
|
+
case "RSA-OAEP":
|
|
914
|
+
case "RSA-OAEP-256":
|
|
915
|
+
case "RSA-OAEP-384":
|
|
916
|
+
case "RSA-OAEP-512":
|
|
917
|
+
algorithm = {
|
|
918
|
+
name: "RSA-OAEP",
|
|
919
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
920
|
+
};
|
|
921
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
922
|
+
break;
|
|
923
|
+
default:
|
|
924
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
925
|
+
}
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
928
|
+
case "EC": {
|
|
929
|
+
switch (jwk.alg) {
|
|
930
|
+
case "ES256":
|
|
931
|
+
case "ES384":
|
|
932
|
+
case "ES512":
|
|
933
|
+
algorithm = {
|
|
934
|
+
name: "ECDSA",
|
|
935
|
+
namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
|
|
936
|
+
};
|
|
937
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
938
|
+
break;
|
|
939
|
+
case "ECDH-ES":
|
|
940
|
+
case "ECDH-ES+A128KW":
|
|
941
|
+
case "ECDH-ES+A192KW":
|
|
942
|
+
case "ECDH-ES+A256KW":
|
|
943
|
+
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
944
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
945
|
+
break;
|
|
946
|
+
default:
|
|
947
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
948
|
+
}
|
|
949
|
+
break;
|
|
950
|
+
}
|
|
951
|
+
case "OKP": {
|
|
952
|
+
switch (jwk.alg) {
|
|
953
|
+
case "Ed25519":
|
|
954
|
+
case "EdDSA":
|
|
955
|
+
algorithm = { name: "Ed25519" };
|
|
956
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
957
|
+
break;
|
|
958
|
+
case "ECDH-ES":
|
|
959
|
+
case "ECDH-ES+A128KW":
|
|
960
|
+
case "ECDH-ES+A192KW":
|
|
961
|
+
case "ECDH-ES+A256KW":
|
|
962
|
+
algorithm = { name: jwk.crv };
|
|
963
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
964
|
+
break;
|
|
965
|
+
default:
|
|
966
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
967
|
+
}
|
|
968
|
+
break;
|
|
969
|
+
}
|
|
970
|
+
default:
|
|
971
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
972
|
+
}
|
|
973
|
+
return { algorithm, keyUsages };
|
|
974
|
+
}
|
|
975
|
+
async function jwkToKey(jwk) {
|
|
976
|
+
if (!jwk.alg) {
|
|
977
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
978
|
+
}
|
|
979
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
980
|
+
const keyData = { ...jwk };
|
|
981
|
+
if (keyData.kty !== "AKP") {
|
|
982
|
+
delete keyData.alg;
|
|
983
|
+
}
|
|
984
|
+
delete keyData.use;
|
|
985
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
989
|
+
var unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
990
|
+
var cache;
|
|
991
|
+
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
992
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
993
|
+
let cached = cache.get(key);
|
|
994
|
+
if (cached?.[alg]) {
|
|
995
|
+
return cached[alg];
|
|
996
|
+
}
|
|
997
|
+
const cryptoKey = await jwkToKey({ ...jwk, alg });
|
|
998
|
+
if (freeze)
|
|
999
|
+
Object.freeze(key);
|
|
1000
|
+
if (!cached) {
|
|
1001
|
+
cache.set(key, { [alg]: cryptoKey });
|
|
1002
|
+
} else {
|
|
1003
|
+
cached[alg] = cryptoKey;
|
|
1004
|
+
}
|
|
1005
|
+
return cryptoKey;
|
|
1006
|
+
};
|
|
1007
|
+
var handleKeyObject = (keyObject, alg) => {
|
|
1008
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1009
|
+
let cached = cache.get(keyObject);
|
|
1010
|
+
if (cached?.[alg]) {
|
|
1011
|
+
return cached[alg];
|
|
1012
|
+
}
|
|
1013
|
+
const isPublic = keyObject.type === "public";
|
|
1014
|
+
const extractable = isPublic ? true : false;
|
|
1015
|
+
let cryptoKey;
|
|
1016
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
1017
|
+
switch (alg) {
|
|
1018
|
+
case "ECDH-ES":
|
|
1019
|
+
case "ECDH-ES+A128KW":
|
|
1020
|
+
case "ECDH-ES+A192KW":
|
|
1021
|
+
case "ECDH-ES+A256KW":
|
|
1022
|
+
break;
|
|
1023
|
+
default:
|
|
1024
|
+
throw new TypeError(unusableForAlg);
|
|
1025
|
+
}
|
|
1026
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1027
|
+
}
|
|
1028
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
1029
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
1030
|
+
throw new TypeError(unusableForAlg);
|
|
1031
|
+
}
|
|
1032
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1033
|
+
isPublic ? "verify" : "sign"
|
|
1034
|
+
]);
|
|
1035
|
+
}
|
|
1036
|
+
switch (keyObject.asymmetricKeyType) {
|
|
1037
|
+
case "ml-dsa-44":
|
|
1038
|
+
case "ml-dsa-65":
|
|
1039
|
+
case "ml-dsa-87": {
|
|
1040
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
1041
|
+
throw new TypeError(unusableForAlg);
|
|
1042
|
+
}
|
|
1043
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1044
|
+
isPublic ? "verify" : "sign"
|
|
1045
|
+
]);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
1049
|
+
let hash;
|
|
1050
|
+
switch (alg) {
|
|
1051
|
+
case "RSA-OAEP":
|
|
1052
|
+
hash = "SHA-1";
|
|
1053
|
+
break;
|
|
1054
|
+
case "RS256":
|
|
1055
|
+
case "PS256":
|
|
1056
|
+
case "RSA-OAEP-256":
|
|
1057
|
+
hash = "SHA-256";
|
|
1058
|
+
break;
|
|
1059
|
+
case "RS384":
|
|
1060
|
+
case "PS384":
|
|
1061
|
+
case "RSA-OAEP-384":
|
|
1062
|
+
hash = "SHA-384";
|
|
1063
|
+
break;
|
|
1064
|
+
case "RS512":
|
|
1065
|
+
case "PS512":
|
|
1066
|
+
case "RSA-OAEP-512":
|
|
1067
|
+
hash = "SHA-512";
|
|
1068
|
+
break;
|
|
1069
|
+
default:
|
|
1070
|
+
throw new TypeError(unusableForAlg);
|
|
1071
|
+
}
|
|
1072
|
+
if (alg.startsWith("RSA-OAEP")) {
|
|
1073
|
+
return keyObject.toCryptoKey({
|
|
1074
|
+
name: "RSA-OAEP",
|
|
1075
|
+
hash
|
|
1076
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
1077
|
+
}
|
|
1078
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1079
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
1080
|
+
hash
|
|
1081
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1082
|
+
}
|
|
1083
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
1084
|
+
const nist = /* @__PURE__ */ new Map([
|
|
1085
|
+
["prime256v1", "P-256"],
|
|
1086
|
+
["secp384r1", "P-384"],
|
|
1087
|
+
["secp521r1", "P-521"]
|
|
1088
|
+
]);
|
|
1089
|
+
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
1090
|
+
if (!namedCurve) {
|
|
1091
|
+
throw new TypeError(unusableForAlg);
|
|
1092
|
+
}
|
|
1093
|
+
const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
1094
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
|
|
1095
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1096
|
+
name: "ECDSA",
|
|
1097
|
+
namedCurve
|
|
1098
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1099
|
+
}
|
|
1100
|
+
if (alg.startsWith("ECDH-ES")) {
|
|
1101
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1102
|
+
name: "ECDH",
|
|
1103
|
+
namedCurve
|
|
1104
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
if (!cryptoKey) {
|
|
1108
|
+
throw new TypeError(unusableForAlg);
|
|
1109
|
+
}
|
|
1110
|
+
if (!cached) {
|
|
1111
|
+
cache.set(keyObject, { [alg]: cryptoKey });
|
|
1112
|
+
} else {
|
|
1113
|
+
cached[alg] = cryptoKey;
|
|
1114
|
+
}
|
|
1115
|
+
return cryptoKey;
|
|
1116
|
+
};
|
|
1117
|
+
async function normalizeKey(key, alg) {
|
|
1118
|
+
if (key instanceof Uint8Array) {
|
|
1119
|
+
return key;
|
|
1120
|
+
}
|
|
1121
|
+
if (isCryptoKey(key)) {
|
|
1122
|
+
return key;
|
|
1123
|
+
}
|
|
1124
|
+
if (isKeyObject(key)) {
|
|
1125
|
+
if (key.type === "secret") {
|
|
1126
|
+
return key.export();
|
|
1127
|
+
}
|
|
1128
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
1129
|
+
try {
|
|
1130
|
+
return handleKeyObject(key, alg);
|
|
1131
|
+
} catch (err) {
|
|
1132
|
+
if (err instanceof TypeError) {
|
|
1133
|
+
throw err;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
let jwk = key.export({ format: "jwk" });
|
|
1138
|
+
return handleJWK(key, jwk, alg);
|
|
1139
|
+
}
|
|
1140
|
+
if (isJWK(key)) {
|
|
1141
|
+
if (key.k) {
|
|
1142
|
+
return decode(key.k);
|
|
1143
|
+
}
|
|
1144
|
+
return handleJWK(key, key, alg, true);
|
|
1145
|
+
}
|
|
1146
|
+
throw new Error("unreachable");
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/asn1.js
|
|
1150
|
+
var formatPEM = (b64, descriptor) => {
|
|
1151
|
+
const newlined = (b64.match(/.{1,64}/g) || []).join("\n");
|
|
1152
|
+
return `-----BEGIN ${descriptor}-----
|
|
1153
|
+
${newlined}
|
|
1154
|
+
-----END ${descriptor}-----`;
|
|
1155
|
+
};
|
|
1156
|
+
var genericExport = async (keyType, keyFormat, key) => {
|
|
1157
|
+
if (isKeyObject(key)) {
|
|
1158
|
+
if (key.type !== keyType) {
|
|
1159
|
+
throw new TypeError(`key is not a ${keyType} key`);
|
|
1160
|
+
}
|
|
1161
|
+
return key.export({ format: "pem", type: keyFormat });
|
|
1162
|
+
}
|
|
1163
|
+
if (!isCryptoKey(key)) {
|
|
1164
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject"));
|
|
1165
|
+
}
|
|
1166
|
+
if (!key.extractable) {
|
|
1167
|
+
throw new TypeError("CryptoKey is not extractable");
|
|
1168
|
+
}
|
|
1169
|
+
if (key.type !== keyType) {
|
|
1170
|
+
throw new TypeError(`key is not a ${keyType} key`);
|
|
1171
|
+
}
|
|
1172
|
+
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
1173
|
+
};
|
|
1174
|
+
var toSPKI = (key) => genericExport("public", "spki", key);
|
|
1175
|
+
var toPKCS8 = (key) => genericExport("private", "pkcs8", key);
|
|
1176
|
+
var bytesEqual = (a, b) => {
|
|
1177
|
+
if (a.byteLength !== b.length)
|
|
1178
|
+
return false;
|
|
1179
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
1180
|
+
if (a[i] !== b[i])
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
return true;
|
|
1184
|
+
};
|
|
1185
|
+
var createASN1State = (data) => ({ data, pos: 0 });
|
|
1186
|
+
var parseLength = (state) => {
|
|
1187
|
+
const first = state.data[state.pos++];
|
|
1188
|
+
if (first & 128) {
|
|
1189
|
+
const lengthOfLen = first & 127;
|
|
1190
|
+
let length = 0;
|
|
1191
|
+
for (let i = 0; i < lengthOfLen; i++) {
|
|
1192
|
+
length = length << 8 | state.data[state.pos++];
|
|
1193
|
+
}
|
|
1194
|
+
return length;
|
|
1195
|
+
}
|
|
1196
|
+
return first;
|
|
1197
|
+
};
|
|
1198
|
+
var skipElement = (state, count = 1) => {
|
|
1199
|
+
if (count <= 0)
|
|
1200
|
+
return;
|
|
1201
|
+
state.pos++;
|
|
1202
|
+
const length = parseLength(state);
|
|
1203
|
+
state.pos += length;
|
|
1204
|
+
if (count > 1) {
|
|
1205
|
+
skipElement(state, count - 1);
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
var expectTag = (state, expectedTag, errorMessage) => {
|
|
1209
|
+
if (state.data[state.pos++] !== expectedTag) {
|
|
1210
|
+
throw new Error(errorMessage);
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
var getSubarray = (state, length) => {
|
|
1214
|
+
const result = state.data.subarray(state.pos, state.pos + length);
|
|
1215
|
+
state.pos += length;
|
|
1216
|
+
return result;
|
|
1217
|
+
};
|
|
1218
|
+
var parseAlgorithmOID = (state) => {
|
|
1219
|
+
expectTag(state, 6, "Expected algorithm OID");
|
|
1220
|
+
const oidLen = parseLength(state);
|
|
1221
|
+
return getSubarray(state, oidLen);
|
|
1222
|
+
};
|
|
1223
|
+
function parsePKCS8Header(state) {
|
|
1224
|
+
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
1225
|
+
parseLength(state);
|
|
1226
|
+
expectTag(state, 2, "Expected version field");
|
|
1227
|
+
const verLen = parseLength(state);
|
|
1228
|
+
state.pos += verLen;
|
|
1229
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
1230
|
+
const algIdLen = parseLength(state);
|
|
1231
|
+
const algIdStart = state.pos;
|
|
1232
|
+
return { algIdStart, algIdLength: algIdLen };
|
|
1233
|
+
}
|
|
1234
|
+
function parseSPKIHeader(state) {
|
|
1235
|
+
expectTag(state, 48, "Invalid SPKI structure");
|
|
1236
|
+
parseLength(state);
|
|
1237
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
1238
|
+
const algIdLen = parseLength(state);
|
|
1239
|
+
const algIdStart = state.pos;
|
|
1240
|
+
return { algIdStart, algIdLength: algIdLen };
|
|
1241
|
+
}
|
|
1242
|
+
var parseECAlgorithmIdentifier = (state) => {
|
|
1243
|
+
const algOid = parseAlgorithmOID(state);
|
|
1244
|
+
if (bytesEqual(algOid, [43, 101, 110])) {
|
|
1245
|
+
return "X25519";
|
|
1246
|
+
}
|
|
1247
|
+
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
|
|
1248
|
+
throw new Error("Unsupported key algorithm");
|
|
1249
|
+
}
|
|
1250
|
+
expectTag(state, 6, "Expected curve OID");
|
|
1251
|
+
const curveOidLen = parseLength(state);
|
|
1252
|
+
const curveOid = getSubarray(state, curveOidLen);
|
|
1253
|
+
for (const { name, oid } of [
|
|
1254
|
+
{ name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
|
|
1255
|
+
{ name: "P-384", oid: [43, 129, 4, 0, 34] },
|
|
1256
|
+
{ name: "P-521", oid: [43, 129, 4, 0, 35] }
|
|
1257
|
+
]) {
|
|
1258
|
+
if (bytesEqual(curveOid, oid)) {
|
|
1259
|
+
return name;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
throw new Error("Unsupported named curve");
|
|
1263
|
+
};
|
|
1264
|
+
var genericImport = async (keyFormat, keyData, alg, options) => {
|
|
1265
|
+
let algorithm;
|
|
1266
|
+
let keyUsages;
|
|
1267
|
+
const isPublic = keyFormat === "spki";
|
|
1268
|
+
const getSigUsages = () => isPublic ? ["verify"] : ["sign"];
|
|
1269
|
+
const getEncUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
1270
|
+
switch (alg) {
|
|
1271
|
+
case "PS256":
|
|
1272
|
+
case "PS384":
|
|
1273
|
+
case "PS512":
|
|
1274
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
|
|
1275
|
+
keyUsages = getSigUsages();
|
|
1276
|
+
break;
|
|
1277
|
+
case "RS256":
|
|
1278
|
+
case "RS384":
|
|
1279
|
+
case "RS512":
|
|
1280
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
|
|
1281
|
+
keyUsages = getSigUsages();
|
|
1282
|
+
break;
|
|
1283
|
+
case "RSA-OAEP":
|
|
1284
|
+
case "RSA-OAEP-256":
|
|
1285
|
+
case "RSA-OAEP-384":
|
|
1286
|
+
case "RSA-OAEP-512":
|
|
1287
|
+
algorithm = {
|
|
1288
|
+
name: "RSA-OAEP",
|
|
1289
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
|
|
1290
|
+
};
|
|
1291
|
+
keyUsages = getEncUsages();
|
|
1292
|
+
break;
|
|
1293
|
+
case "ES256":
|
|
1294
|
+
case "ES384":
|
|
1295
|
+
case "ES512": {
|
|
1296
|
+
const curveMap = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
1297
|
+
algorithm = { name: "ECDSA", namedCurve: curveMap[alg] };
|
|
1298
|
+
keyUsages = getSigUsages();
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
case "ECDH-ES":
|
|
1302
|
+
case "ECDH-ES+A128KW":
|
|
1303
|
+
case "ECDH-ES+A192KW":
|
|
1304
|
+
case "ECDH-ES+A256KW": {
|
|
1305
|
+
try {
|
|
1306
|
+
const namedCurve = options.getNamedCurve(keyData);
|
|
1307
|
+
algorithm = namedCurve === "X25519" ? { name: "X25519" } : { name: "ECDH", namedCurve };
|
|
1308
|
+
} catch (cause) {
|
|
1309
|
+
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
1310
|
+
}
|
|
1311
|
+
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
1312
|
+
break;
|
|
1313
|
+
}
|
|
1314
|
+
case "Ed25519":
|
|
1315
|
+
case "EdDSA":
|
|
1316
|
+
algorithm = { name: "Ed25519" };
|
|
1317
|
+
keyUsages = getSigUsages();
|
|
1318
|
+
break;
|
|
1319
|
+
case "ML-DSA-44":
|
|
1320
|
+
case "ML-DSA-65":
|
|
1321
|
+
case "ML-DSA-87":
|
|
1322
|
+
algorithm = { name: alg };
|
|
1323
|
+
keyUsages = getSigUsages();
|
|
1324
|
+
break;
|
|
1325
|
+
default:
|
|
1326
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
1327
|
+
}
|
|
1328
|
+
return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? (isPublic ? true : false), keyUsages);
|
|
1329
|
+
};
|
|
1330
|
+
var processPEMData = (pem, pattern) => {
|
|
1331
|
+
return decodeBase64(pem.replace(pattern, ""));
|
|
1332
|
+
};
|
|
1333
|
+
var fromPKCS8 = (pem, alg, options) => {
|
|
1334
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
1335
|
+
let opts = options;
|
|
1336
|
+
if (alg?.startsWith?.("ECDH-ES")) {
|
|
1337
|
+
opts ||= {};
|
|
1338
|
+
opts.getNamedCurve = (keyData2) => {
|
|
1339
|
+
const state = createASN1State(keyData2);
|
|
1340
|
+
parsePKCS8Header(state);
|
|
1341
|
+
return parseECAlgorithmIdentifier(state);
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
return genericImport("pkcs8", keyData, alg, opts);
|
|
1345
|
+
};
|
|
1346
|
+
var fromSPKI = (pem, alg, options) => {
|
|
1347
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
|
|
1348
|
+
let opts = options;
|
|
1349
|
+
if (alg?.startsWith?.("ECDH-ES")) {
|
|
1350
|
+
opts ||= {};
|
|
1351
|
+
opts.getNamedCurve = (keyData2) => {
|
|
1352
|
+
const state = createASN1State(keyData2);
|
|
1353
|
+
parseSPKIHeader(state);
|
|
1354
|
+
return parseECAlgorithmIdentifier(state);
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
return genericImport("spki", keyData, alg, opts);
|
|
1358
|
+
};
|
|
1359
|
+
function spkiFromX509(buf) {
|
|
1360
|
+
const state = createASN1State(buf);
|
|
1361
|
+
expectTag(state, 48, "Invalid certificate structure");
|
|
1362
|
+
parseLength(state);
|
|
1363
|
+
expectTag(state, 48, "Invalid tbsCertificate structure");
|
|
1364
|
+
parseLength(state);
|
|
1365
|
+
if (buf[state.pos] === 160) {
|
|
1366
|
+
skipElement(state, 6);
|
|
1367
|
+
} else {
|
|
1368
|
+
skipElement(state, 5);
|
|
1369
|
+
}
|
|
1370
|
+
const spkiStart = state.pos;
|
|
1371
|
+
expectTag(state, 48, "Invalid SPKI structure");
|
|
1372
|
+
const spkiContentLen = parseLength(state);
|
|
1373
|
+
return buf.subarray(spkiStart, spkiStart + spkiContentLen + (state.pos - spkiStart));
|
|
1374
|
+
}
|
|
1375
|
+
function extractX509SPKI(x509) {
|
|
1376
|
+
const derBytes = processPEMData(x509, /(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g);
|
|
1377
|
+
return spkiFromX509(derBytes);
|
|
1378
|
+
}
|
|
1379
|
+
var fromX509 = (pem, alg, options) => {
|
|
1380
|
+
let spki;
|
|
1381
|
+
try {
|
|
1382
|
+
spki = extractX509SPKI(pem);
|
|
1383
|
+
} catch (cause) {
|
|
1384
|
+
throw new TypeError("Failed to parse the X.509 certificate", { cause });
|
|
1385
|
+
}
|
|
1386
|
+
return fromSPKI(formatPEM(encodeBase64(spki), "PUBLIC KEY"), alg, options);
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/import.js
|
|
1390
|
+
async function importSPKI(spki, alg, options) {
|
|
1391
|
+
if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) {
|
|
1392
|
+
throw new TypeError('"spki" must be SPKI formatted string');
|
|
1393
|
+
}
|
|
1394
|
+
return fromSPKI(spki, alg, options);
|
|
1395
|
+
}
|
|
1396
|
+
async function importX509(x509, alg, options) {
|
|
1397
|
+
if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) {
|
|
1398
|
+
throw new TypeError('"x509" must be X.509 formatted string');
|
|
1399
|
+
}
|
|
1400
|
+
return fromX509(x509, alg, options);
|
|
1401
|
+
}
|
|
1402
|
+
async function importPKCS8(pkcs8, alg, options) {
|
|
1403
|
+
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
1404
|
+
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
1405
|
+
}
|
|
1406
|
+
return fromPKCS8(pkcs8, alg, options);
|
|
1407
|
+
}
|
|
1408
|
+
async function importJWK(jwk, alg, options) {
|
|
1409
|
+
if (!isObject(jwk)) {
|
|
1410
|
+
throw new TypeError("JWK must be an object");
|
|
1411
|
+
}
|
|
1412
|
+
let ext;
|
|
1413
|
+
alg ??= jwk.alg;
|
|
1414
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
1415
|
+
switch (jwk.kty) {
|
|
1416
|
+
case "oct":
|
|
1417
|
+
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
1418
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
1419
|
+
}
|
|
1420
|
+
return decode(jwk.k);
|
|
1421
|
+
case "RSA":
|
|
1422
|
+
if ("oth" in jwk && jwk.oth !== void 0) {
|
|
1423
|
+
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
1424
|
+
}
|
|
1425
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
1426
|
+
case "AKP": {
|
|
1427
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
1428
|
+
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
1429
|
+
}
|
|
1430
|
+
if (alg !== void 0 && alg !== jwk.alg) {
|
|
1431
|
+
throw new TypeError("JWK alg and alg option value mismatch");
|
|
1432
|
+
}
|
|
1433
|
+
return jwkToKey({ ...jwk, ext });
|
|
1434
|
+
}
|
|
1435
|
+
case "EC":
|
|
1436
|
+
case "OKP":
|
|
1437
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
1438
|
+
default:
|
|
1439
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
1444
|
+
async function keyToJWK(key) {
|
|
1445
|
+
if (isKeyObject(key)) {
|
|
1446
|
+
if (key.type === "secret") {
|
|
1447
|
+
key = key.export();
|
|
1448
|
+
} else {
|
|
1449
|
+
return key.export({ format: "jwk" });
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
if (key instanceof Uint8Array) {
|
|
1453
|
+
return {
|
|
1454
|
+
kty: "oct",
|
|
1455
|
+
k: encode2(key)
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
if (!isCryptoKey(key)) {
|
|
1459
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
1460
|
+
}
|
|
1461
|
+
if (!key.extractable) {
|
|
1462
|
+
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
1463
|
+
}
|
|
1464
|
+
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
1465
|
+
if (jwk.kty === "AKP") {
|
|
1466
|
+
;
|
|
1467
|
+
jwk.alg = alg;
|
|
1468
|
+
}
|
|
1469
|
+
return jwk;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/export.js
|
|
1473
|
+
async function exportSPKI(key) {
|
|
1474
|
+
return toSPKI(key);
|
|
1475
|
+
}
|
|
1476
|
+
async function exportPKCS8(key) {
|
|
1477
|
+
return toPKCS8(key);
|
|
1478
|
+
}
|
|
1479
|
+
async function exportJWK(key) {
|
|
1480
|
+
return keyToJWK(key);
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/aesgcmkw.js
|
|
1484
|
+
async function wrap3(alg, key, cek, iv) {
|
|
1485
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
1486
|
+
const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array());
|
|
1487
|
+
return {
|
|
1488
|
+
encryptedKey: wrapped.ciphertext,
|
|
1489
|
+
iv: encode2(wrapped.iv),
|
|
1490
|
+
tag: encode2(wrapped.tag)
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
async function unwrap3(alg, key, encryptedKey, iv, tag2) {
|
|
1494
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
1495
|
+
return decrypt(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array());
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/key_management.js
|
|
1499
|
+
var unsupportedAlgHeader = 'Invalid or unsupported "alg" (JWE Algorithm) header value';
|
|
1500
|
+
function assertEncryptedKey(encryptedKey) {
|
|
1501
|
+
if (encryptedKey === void 0)
|
|
1502
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1503
|
+
}
|
|
1504
|
+
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
1505
|
+
switch (alg) {
|
|
1506
|
+
case "dir": {
|
|
1507
|
+
if (encryptedKey !== void 0)
|
|
1508
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
1509
|
+
return key;
|
|
1510
|
+
}
|
|
1511
|
+
case "ECDH-ES":
|
|
1512
|
+
if (encryptedKey !== void 0)
|
|
1513
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
1514
|
+
case "ECDH-ES+A128KW":
|
|
1515
|
+
case "ECDH-ES+A192KW":
|
|
1516
|
+
case "ECDH-ES+A256KW": {
|
|
1517
|
+
if (!isObject(joseHeader.epk))
|
|
1518
|
+
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
1519
|
+
assertCryptoKey(key);
|
|
1520
|
+
if (!allowed(key))
|
|
1521
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
1522
|
+
const epk = await importJWK(joseHeader.epk, alg);
|
|
1523
|
+
assertCryptoKey(epk);
|
|
1524
|
+
let partyUInfo;
|
|
1525
|
+
let partyVInfo;
|
|
1526
|
+
if (joseHeader.apu !== void 0) {
|
|
1527
|
+
if (typeof joseHeader.apu !== "string")
|
|
1528
|
+
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
1529
|
+
partyUInfo = decodeBase64url(joseHeader.apu, "apu", JWEInvalid);
|
|
1530
|
+
}
|
|
1531
|
+
if (joseHeader.apv !== void 0) {
|
|
1532
|
+
if (typeof joseHeader.apv !== "string")
|
|
1533
|
+
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
1534
|
+
partyVInfo = decodeBase64url(joseHeader.apv, "apv", JWEInvalid);
|
|
1535
|
+
}
|
|
1536
|
+
const sharedSecret = await deriveKey(epk, key, alg === "ECDH-ES" ? joseHeader.enc : alg, alg === "ECDH-ES" ? cekLength(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
1537
|
+
if (alg === "ECDH-ES")
|
|
1538
|
+
return sharedSecret;
|
|
1539
|
+
assertEncryptedKey(encryptedKey);
|
|
1540
|
+
return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
|
|
1541
|
+
}
|
|
1542
|
+
case "RSA-OAEP":
|
|
1543
|
+
case "RSA-OAEP-256":
|
|
1544
|
+
case "RSA-OAEP-384":
|
|
1545
|
+
case "RSA-OAEP-512": {
|
|
1546
|
+
assertEncryptedKey(encryptedKey);
|
|
1547
|
+
assertCryptoKey(key);
|
|
1548
|
+
return decrypt2(alg, key, encryptedKey);
|
|
1549
|
+
}
|
|
1550
|
+
case "PBES2-HS256+A128KW":
|
|
1551
|
+
case "PBES2-HS384+A192KW":
|
|
1552
|
+
case "PBES2-HS512+A256KW": {
|
|
1553
|
+
assertEncryptedKey(encryptedKey);
|
|
1554
|
+
if (typeof joseHeader.p2c !== "number")
|
|
1555
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
1556
|
+
const p2cLimit = options?.maxPBES2Count || 1e4;
|
|
1557
|
+
if (joseHeader.p2c > p2cLimit)
|
|
1558
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
1559
|
+
if (typeof joseHeader.p2s !== "string")
|
|
1560
|
+
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
1561
|
+
let p2s;
|
|
1562
|
+
p2s = decodeBase64url(joseHeader.p2s, "p2s", JWEInvalid);
|
|
1563
|
+
return unwrap2(alg, key, encryptedKey, joseHeader.p2c, p2s);
|
|
1564
|
+
}
|
|
1565
|
+
case "A128KW":
|
|
1566
|
+
case "A192KW":
|
|
1567
|
+
case "A256KW": {
|
|
1568
|
+
assertEncryptedKey(encryptedKey);
|
|
1569
|
+
return unwrap(alg, key, encryptedKey);
|
|
1570
|
+
}
|
|
1571
|
+
case "A128GCMKW":
|
|
1572
|
+
case "A192GCMKW":
|
|
1573
|
+
case "A256GCMKW": {
|
|
1574
|
+
assertEncryptedKey(encryptedKey);
|
|
1575
|
+
if (typeof joseHeader.iv !== "string")
|
|
1576
|
+
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
1577
|
+
if (typeof joseHeader.tag !== "string")
|
|
1578
|
+
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
1579
|
+
let iv;
|
|
1580
|
+
iv = decodeBase64url(joseHeader.iv, "iv", JWEInvalid);
|
|
1581
|
+
let tag2;
|
|
1582
|
+
tag2 = decodeBase64url(joseHeader.tag, "tag", JWEInvalid);
|
|
1583
|
+
return unwrap3(alg, key, encryptedKey, iv, tag2);
|
|
1584
|
+
}
|
|
1585
|
+
default: {
|
|
1586
|
+
throw new JOSENotSupported(unsupportedAlgHeader);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
1591
|
+
let encryptedKey;
|
|
1592
|
+
let parameters;
|
|
1593
|
+
let cek;
|
|
1594
|
+
switch (alg) {
|
|
1595
|
+
case "dir": {
|
|
1596
|
+
cek = key;
|
|
1597
|
+
break;
|
|
1598
|
+
}
|
|
1599
|
+
case "ECDH-ES":
|
|
1600
|
+
case "ECDH-ES+A128KW":
|
|
1601
|
+
case "ECDH-ES+A192KW":
|
|
1602
|
+
case "ECDH-ES+A256KW": {
|
|
1603
|
+
assertCryptoKey(key);
|
|
1604
|
+
if (!allowed(key)) {
|
|
1605
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
1606
|
+
}
|
|
1607
|
+
const { apu, apv } = providedParameters;
|
|
1608
|
+
let ephemeralKey;
|
|
1609
|
+
if (providedParameters.epk) {
|
|
1610
|
+
ephemeralKey = await normalizeKey(providedParameters.epk, alg);
|
|
1611
|
+
} else {
|
|
1612
|
+
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
1613
|
+
}
|
|
1614
|
+
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
1615
|
+
const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
1616
|
+
parameters = { epk: { x, crv, kty } };
|
|
1617
|
+
if (kty === "EC")
|
|
1618
|
+
parameters.epk.y = y;
|
|
1619
|
+
if (apu)
|
|
1620
|
+
parameters.apu = encode2(apu);
|
|
1621
|
+
if (apv)
|
|
1622
|
+
parameters.apv = encode2(apv);
|
|
1623
|
+
if (alg === "ECDH-ES") {
|
|
1624
|
+
cek = sharedSecret;
|
|
1625
|
+
break;
|
|
1626
|
+
}
|
|
1627
|
+
cek = providedCek || generateCek(enc);
|
|
1628
|
+
const kwAlg = alg.slice(-6);
|
|
1629
|
+
encryptedKey = await wrap(kwAlg, sharedSecret, cek);
|
|
1630
|
+
break;
|
|
1631
|
+
}
|
|
1632
|
+
case "RSA-OAEP":
|
|
1633
|
+
case "RSA-OAEP-256":
|
|
1634
|
+
case "RSA-OAEP-384":
|
|
1635
|
+
case "RSA-OAEP-512": {
|
|
1636
|
+
cek = providedCek || generateCek(enc);
|
|
1637
|
+
assertCryptoKey(key);
|
|
1638
|
+
encryptedKey = await encrypt2(alg, key, cek);
|
|
1639
|
+
break;
|
|
1640
|
+
}
|
|
1641
|
+
case "PBES2-HS256+A128KW":
|
|
1642
|
+
case "PBES2-HS384+A192KW":
|
|
1643
|
+
case "PBES2-HS512+A256KW": {
|
|
1644
|
+
cek = providedCek || generateCek(enc);
|
|
1645
|
+
const { p2c, p2s } = providedParameters;
|
|
1646
|
+
({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, p2c, p2s));
|
|
1647
|
+
break;
|
|
1648
|
+
}
|
|
1649
|
+
case "A128KW":
|
|
1650
|
+
case "A192KW":
|
|
1651
|
+
case "A256KW": {
|
|
1652
|
+
cek = providedCek || generateCek(enc);
|
|
1653
|
+
encryptedKey = await wrap(alg, key, cek);
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
case "A128GCMKW":
|
|
1657
|
+
case "A192GCMKW":
|
|
1658
|
+
case "A256GCMKW": {
|
|
1659
|
+
cek = providedCek || generateCek(enc);
|
|
1660
|
+
const { iv } = providedParameters;
|
|
1661
|
+
({ encryptedKey, ...parameters } = await wrap3(alg, key, cek, iv));
|
|
1662
|
+
break;
|
|
1663
|
+
}
|
|
1664
|
+
default: {
|
|
1665
|
+
throw new JOSENotSupported(unsupportedAlgHeader);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
return { cek, encryptedKey, parameters };
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1672
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1673
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
1674
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
1675
|
+
}
|
|
1676
|
+
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
1677
|
+
return /* @__PURE__ */ new Set();
|
|
1678
|
+
}
|
|
1679
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
1680
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
1681
|
+
}
|
|
1682
|
+
let recognized;
|
|
1683
|
+
if (recognizedOption !== void 0) {
|
|
1684
|
+
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1685
|
+
} else {
|
|
1686
|
+
recognized = recognizedDefault;
|
|
1687
|
+
}
|
|
1688
|
+
for (const parameter of protectedHeader.crit) {
|
|
1689
|
+
if (!recognized.has(parameter)) {
|
|
1690
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1691
|
+
}
|
|
1692
|
+
if (joseHeader[parameter] === void 0) {
|
|
1693
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1694
|
+
}
|
|
1695
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
1696
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return new Set(protectedHeader.crit);
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
1703
|
+
function validateAlgorithms(option, algorithms) {
|
|
1704
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
1705
|
+
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
1706
|
+
}
|
|
1707
|
+
if (!algorithms) {
|
|
1708
|
+
return void 0;
|
|
1709
|
+
}
|
|
1710
|
+
return new Set(algorithms);
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
1714
|
+
var tag = (key) => key?.[Symbol.toStringTag];
|
|
1715
|
+
var jwkMatchesOp = (alg, key, usage) => {
|
|
1716
|
+
if (key.use !== void 0) {
|
|
1717
|
+
let expected;
|
|
1718
|
+
switch (usage) {
|
|
1719
|
+
case "sign":
|
|
1720
|
+
case "verify":
|
|
1721
|
+
expected = "sig";
|
|
1722
|
+
break;
|
|
1723
|
+
case "encrypt":
|
|
1724
|
+
case "decrypt":
|
|
1725
|
+
expected = "enc";
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
if (key.use !== expected) {
|
|
1729
|
+
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
if (key.alg !== void 0 && key.alg !== alg) {
|
|
1733
|
+
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
1734
|
+
}
|
|
1735
|
+
if (Array.isArray(key.key_ops)) {
|
|
1736
|
+
let expectedKeyOp;
|
|
1737
|
+
switch (true) {
|
|
1738
|
+
case (usage === "sign" || usage === "verify"):
|
|
1739
|
+
case alg === "dir":
|
|
1740
|
+
case alg.includes("CBC-HS"):
|
|
1741
|
+
expectedKeyOp = usage;
|
|
1742
|
+
break;
|
|
1743
|
+
case alg.startsWith("PBES2"):
|
|
1744
|
+
expectedKeyOp = "deriveBits";
|
|
1745
|
+
break;
|
|
1746
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
1747
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
1748
|
+
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
1749
|
+
} else {
|
|
1750
|
+
expectedKeyOp = usage;
|
|
1751
|
+
}
|
|
1752
|
+
break;
|
|
1753
|
+
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
1754
|
+
expectedKeyOp = "wrapKey";
|
|
1755
|
+
break;
|
|
1756
|
+
case usage === "decrypt":
|
|
1757
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
1758
|
+
break;
|
|
1759
|
+
}
|
|
1760
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
1761
|
+
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
return true;
|
|
1765
|
+
};
|
|
1766
|
+
var symmetricTypeCheck = (alg, key, usage) => {
|
|
1767
|
+
if (key instanceof Uint8Array)
|
|
1768
|
+
return;
|
|
1769
|
+
if (isJWK(key)) {
|
|
1770
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1771
|
+
return;
|
|
1772
|
+
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`);
|
|
1773
|
+
}
|
|
1774
|
+
if (!isKeyLike(key)) {
|
|
1775
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
1776
|
+
}
|
|
1777
|
+
if (key.type !== "secret") {
|
|
1778
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
var asymmetricTypeCheck = (alg, key, usage) => {
|
|
1782
|
+
if (isJWK(key)) {
|
|
1783
|
+
switch (usage) {
|
|
1784
|
+
case "decrypt":
|
|
1785
|
+
case "sign":
|
|
1786
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1787
|
+
return;
|
|
1788
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
1789
|
+
case "encrypt":
|
|
1790
|
+
case "verify":
|
|
1791
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1792
|
+
return;
|
|
1793
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
if (!isKeyLike(key)) {
|
|
1797
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1798
|
+
}
|
|
1799
|
+
if (key.type === "secret") {
|
|
1800
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
1801
|
+
}
|
|
1802
|
+
if (key.type === "public") {
|
|
1803
|
+
switch (usage) {
|
|
1804
|
+
case "sign":
|
|
1805
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
1806
|
+
case "decrypt":
|
|
1807
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
if (key.type === "private") {
|
|
1811
|
+
switch (usage) {
|
|
1812
|
+
case "verify":
|
|
1813
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
1814
|
+
case "encrypt":
|
|
1815
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
};
|
|
1819
|
+
function checkKeyType(alg, key, usage) {
|
|
1820
|
+
switch (alg.substring(0, 2)) {
|
|
1821
|
+
case "A1":
|
|
1822
|
+
case "A2":
|
|
1823
|
+
case "di":
|
|
1824
|
+
case "HS":
|
|
1825
|
+
case "PB":
|
|
1826
|
+
symmetricTypeCheck(alg, key, usage);
|
|
1827
|
+
break;
|
|
1828
|
+
default:
|
|
1829
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/deflate.js
|
|
1834
|
+
function supported(name) {
|
|
1835
|
+
if (typeof globalThis[name] === "undefined") {
|
|
1836
|
+
throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
async function compress(input) {
|
|
1840
|
+
supported("CompressionStream");
|
|
1841
|
+
const cs = new CompressionStream("deflate-raw");
|
|
1842
|
+
const writer = cs.writable.getWriter();
|
|
1843
|
+
writer.write(input).catch(() => {
|
|
1844
|
+
});
|
|
1845
|
+
writer.close().catch(() => {
|
|
1846
|
+
});
|
|
1847
|
+
const chunks = [];
|
|
1848
|
+
const reader = cs.readable.getReader();
|
|
1849
|
+
for (; ; ) {
|
|
1850
|
+
const { value, done } = await reader.read();
|
|
1851
|
+
if (done)
|
|
1852
|
+
break;
|
|
1853
|
+
chunks.push(value);
|
|
1854
|
+
}
|
|
1855
|
+
return concat(...chunks);
|
|
1856
|
+
}
|
|
1857
|
+
async function decompress(input, maxLength) {
|
|
1858
|
+
supported("DecompressionStream");
|
|
1859
|
+
const ds = new DecompressionStream("deflate-raw");
|
|
1860
|
+
const writer = ds.writable.getWriter();
|
|
1861
|
+
writer.write(input).catch(() => {
|
|
1862
|
+
});
|
|
1863
|
+
writer.close().catch(() => {
|
|
1864
|
+
});
|
|
1865
|
+
const chunks = [];
|
|
1866
|
+
let length = 0;
|
|
1867
|
+
const reader = ds.readable.getReader();
|
|
1868
|
+
for (; ; ) {
|
|
1869
|
+
const { value, done } = await reader.read();
|
|
1870
|
+
if (done)
|
|
1871
|
+
break;
|
|
1872
|
+
chunks.push(value);
|
|
1873
|
+
length += value.byteLength;
|
|
1874
|
+
if (maxLength !== Infinity && length > maxLength) {
|
|
1875
|
+
throw new JWEInvalid("Decompressed plaintext exceeded the configured limit");
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
return concat(...chunks);
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
1882
|
+
async function flattenedDecrypt(jwe, key, options) {
|
|
1883
|
+
if (!isObject(jwe)) {
|
|
1884
|
+
throw new JWEInvalid("Flattened JWE must be an object");
|
|
1885
|
+
}
|
|
1886
|
+
if (jwe.protected === void 0 && jwe.header === void 0 && jwe.unprotected === void 0) {
|
|
1887
|
+
throw new JWEInvalid("JOSE Header missing");
|
|
1888
|
+
}
|
|
1889
|
+
if (jwe.iv !== void 0 && typeof jwe.iv !== "string") {
|
|
1890
|
+
throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
1891
|
+
}
|
|
1892
|
+
if (typeof jwe.ciphertext !== "string") {
|
|
1893
|
+
throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
|
|
1894
|
+
}
|
|
1895
|
+
if (jwe.tag !== void 0 && typeof jwe.tag !== "string") {
|
|
1896
|
+
throw new JWEInvalid("JWE Authentication Tag incorrect type");
|
|
1897
|
+
}
|
|
1898
|
+
if (jwe.protected !== void 0 && typeof jwe.protected !== "string") {
|
|
1899
|
+
throw new JWEInvalid("JWE Protected Header incorrect type");
|
|
1900
|
+
}
|
|
1901
|
+
if (jwe.encrypted_key !== void 0 && typeof jwe.encrypted_key !== "string") {
|
|
1902
|
+
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
1903
|
+
}
|
|
1904
|
+
if (jwe.aad !== void 0 && typeof jwe.aad !== "string") {
|
|
1905
|
+
throw new JWEInvalid("JWE AAD incorrect type");
|
|
1906
|
+
}
|
|
1907
|
+
if (jwe.header !== void 0 && !isObject(jwe.header)) {
|
|
1908
|
+
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
1909
|
+
}
|
|
1910
|
+
if (jwe.unprotected !== void 0 && !isObject(jwe.unprotected)) {
|
|
1911
|
+
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
1912
|
+
}
|
|
1913
|
+
let parsedProt;
|
|
1914
|
+
if (jwe.protected) {
|
|
1915
|
+
try {
|
|
1916
|
+
const protectedHeader2 = decode(jwe.protected);
|
|
1917
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader2));
|
|
1918
|
+
} catch {
|
|
1919
|
+
throw new JWEInvalid("JWE Protected Header is invalid");
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
if (!isDisjoint(parsedProt, jwe.header, jwe.unprotected)) {
|
|
1923
|
+
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
1924
|
+
}
|
|
1925
|
+
const joseHeader = {
|
|
1926
|
+
...parsedProt,
|
|
1927
|
+
...jwe.header,
|
|
1928
|
+
...jwe.unprotected
|
|
1929
|
+
};
|
|
1930
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, parsedProt, joseHeader);
|
|
1931
|
+
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF") {
|
|
1932
|
+
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
1933
|
+
}
|
|
1934
|
+
if (joseHeader.zip !== void 0 && !parsedProt?.zip) {
|
|
1935
|
+
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
1936
|
+
}
|
|
1937
|
+
const { alg, enc } = joseHeader;
|
|
1938
|
+
if (typeof alg !== "string" || !alg) {
|
|
1939
|
+
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
1940
|
+
}
|
|
1941
|
+
if (typeof enc !== "string" || !enc) {
|
|
1942
|
+
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
1943
|
+
}
|
|
1944
|
+
const keyManagementAlgorithms = options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms);
|
|
1945
|
+
const contentEncryptionAlgorithms = options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms);
|
|
1946
|
+
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
|
|
1947
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
1948
|
+
}
|
|
1949
|
+
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
|
|
1950
|
+
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
1951
|
+
}
|
|
1952
|
+
let encryptedKey;
|
|
1953
|
+
if (jwe.encrypted_key !== void 0) {
|
|
1954
|
+
encryptedKey = decodeBase64url(jwe.encrypted_key, "encrypted_key", JWEInvalid);
|
|
1955
|
+
}
|
|
1956
|
+
let resolvedKey = false;
|
|
1957
|
+
if (typeof key === "function") {
|
|
1958
|
+
key = await key(parsedProt, jwe);
|
|
1959
|
+
resolvedKey = true;
|
|
1960
|
+
}
|
|
1961
|
+
checkKeyType(alg === "dir" ? enc : alg, key, "decrypt");
|
|
1962
|
+
const k = await normalizeKey(key, alg);
|
|
1963
|
+
let cek;
|
|
1964
|
+
try {
|
|
1965
|
+
cek = await decryptKeyManagement(alg, k, encryptedKey, joseHeader, options);
|
|
1966
|
+
} catch (err) {
|
|
1967
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
1968
|
+
throw err;
|
|
1969
|
+
}
|
|
1970
|
+
cek = generateCek(enc);
|
|
1971
|
+
}
|
|
1972
|
+
let iv;
|
|
1973
|
+
let tag2;
|
|
1974
|
+
if (jwe.iv !== void 0) {
|
|
1975
|
+
iv = decodeBase64url(jwe.iv, "iv", JWEInvalid);
|
|
1976
|
+
}
|
|
1977
|
+
if (jwe.tag !== void 0) {
|
|
1978
|
+
tag2 = decodeBase64url(jwe.tag, "tag", JWEInvalid);
|
|
1979
|
+
}
|
|
1980
|
+
const protectedHeader = jwe.protected !== void 0 ? encode(jwe.protected) : new Uint8Array();
|
|
1981
|
+
let additionalData;
|
|
1982
|
+
if (jwe.aad !== void 0) {
|
|
1983
|
+
additionalData = concat(protectedHeader, encode("."), encode(jwe.aad));
|
|
1984
|
+
} else {
|
|
1985
|
+
additionalData = protectedHeader;
|
|
1986
|
+
}
|
|
1987
|
+
const ciphertext = decodeBase64url(jwe.ciphertext, "ciphertext", JWEInvalid);
|
|
1988
|
+
const plaintext = await decrypt(enc, cek, ciphertext, iv, tag2, additionalData);
|
|
1989
|
+
const result = { plaintext };
|
|
1990
|
+
if (joseHeader.zip === "DEF") {
|
|
1991
|
+
const maxDecompressedLength = options?.maxDecompressedLength ?? 25e4;
|
|
1992
|
+
if (maxDecompressedLength === 0) {
|
|
1993
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
1994
|
+
}
|
|
1995
|
+
if (maxDecompressedLength !== Infinity && (!Number.isSafeInteger(maxDecompressedLength) || maxDecompressedLength < 1)) {
|
|
1996
|
+
throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
|
|
1997
|
+
}
|
|
1998
|
+
result.plaintext = await decompress(plaintext, maxDecompressedLength).catch((cause) => {
|
|
1999
|
+
if (cause instanceof JWEInvalid)
|
|
2000
|
+
throw cause;
|
|
2001
|
+
throw new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
if (jwe.protected !== void 0) {
|
|
2005
|
+
result.protectedHeader = parsedProt;
|
|
2006
|
+
}
|
|
2007
|
+
if (jwe.aad !== void 0) {
|
|
2008
|
+
result.additionalAuthenticatedData = decodeBase64url(jwe.aad, "aad", JWEInvalid);
|
|
2009
|
+
}
|
|
2010
|
+
if (jwe.unprotected !== void 0) {
|
|
2011
|
+
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
2012
|
+
}
|
|
2013
|
+
if (jwe.header !== void 0) {
|
|
2014
|
+
result.unprotectedHeader = jwe.header;
|
|
2015
|
+
}
|
|
2016
|
+
if (resolvedKey) {
|
|
2017
|
+
return { ...result, key: k };
|
|
2018
|
+
}
|
|
2019
|
+
return result;
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwe/compact/decrypt.js
|
|
2023
|
+
async function compactDecrypt(jwe, key, options) {
|
|
2024
|
+
if (jwe instanceof Uint8Array) {
|
|
2025
|
+
jwe = decoder.decode(jwe);
|
|
2026
|
+
}
|
|
2027
|
+
if (typeof jwe !== "string") {
|
|
2028
|
+
throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
|
|
2029
|
+
}
|
|
2030
|
+
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
|
|
2031
|
+
if (length !== 5) {
|
|
2032
|
+
throw new JWEInvalid("Invalid Compact JWE");
|
|
2033
|
+
}
|
|
2034
|
+
const decrypted = await flattenedDecrypt({
|
|
2035
|
+
ciphertext,
|
|
2036
|
+
iv: iv || void 0,
|
|
2037
|
+
protected: protectedHeader,
|
|
2038
|
+
tag: tag2 || void 0,
|
|
2039
|
+
encrypted_key: encryptedKey || void 0
|
|
2040
|
+
}, key, options);
|
|
2041
|
+
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
|
2042
|
+
if (typeof key === "function") {
|
|
2043
|
+
return { ...result, key: decrypted.key };
|
|
2044
|
+
}
|
|
2045
|
+
return result;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwe/general/decrypt.js
|
|
2049
|
+
async function generalDecrypt(jwe, key, options) {
|
|
2050
|
+
if (!isObject(jwe)) {
|
|
2051
|
+
throw new JWEInvalid("General JWE must be an object");
|
|
2052
|
+
}
|
|
2053
|
+
if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(isObject)) {
|
|
2054
|
+
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
2055
|
+
}
|
|
2056
|
+
if (!jwe.recipients.length) {
|
|
2057
|
+
throw new JWEInvalid("JWE Recipients has no members");
|
|
2058
|
+
}
|
|
2059
|
+
for (const recipient of jwe.recipients) {
|
|
2060
|
+
try {
|
|
2061
|
+
return await flattenedDecrypt({
|
|
2062
|
+
aad: jwe.aad,
|
|
2063
|
+
ciphertext: jwe.ciphertext,
|
|
2064
|
+
encrypted_key: recipient.encrypted_key,
|
|
2065
|
+
header: recipient.header,
|
|
2066
|
+
iv: jwe.iv,
|
|
2067
|
+
protected: jwe.protected,
|
|
2068
|
+
tag: jwe.tag,
|
|
2069
|
+
unprotected: jwe.unprotected
|
|
2070
|
+
}, key, options);
|
|
2071
|
+
} catch {
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
throw new JWEDecryptionFailed();
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
2078
|
+
var FlattenedEncrypt = class {
|
|
2079
|
+
#plaintext;
|
|
2080
|
+
#protectedHeader;
|
|
2081
|
+
#sharedUnprotectedHeader;
|
|
2082
|
+
#unprotectedHeader;
|
|
2083
|
+
#aad;
|
|
2084
|
+
#cek;
|
|
2085
|
+
#iv;
|
|
2086
|
+
#keyManagementParameters;
|
|
2087
|
+
constructor(plaintext) {
|
|
2088
|
+
if (!(plaintext instanceof Uint8Array)) {
|
|
2089
|
+
throw new TypeError("plaintext must be an instance of Uint8Array");
|
|
2090
|
+
}
|
|
2091
|
+
this.#plaintext = plaintext;
|
|
2092
|
+
}
|
|
2093
|
+
setKeyManagementParameters(parameters) {
|
|
2094
|
+
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
2095
|
+
this.#keyManagementParameters = parameters;
|
|
2096
|
+
return this;
|
|
2097
|
+
}
|
|
2098
|
+
setProtectedHeader(protectedHeader) {
|
|
2099
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2100
|
+
this.#protectedHeader = protectedHeader;
|
|
2101
|
+
return this;
|
|
2102
|
+
}
|
|
2103
|
+
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
2104
|
+
assertNotSet(this.#sharedUnprotectedHeader, "setSharedUnprotectedHeader");
|
|
2105
|
+
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
2106
|
+
return this;
|
|
2107
|
+
}
|
|
2108
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
2109
|
+
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
2110
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
2111
|
+
return this;
|
|
2112
|
+
}
|
|
2113
|
+
setAdditionalAuthenticatedData(aad) {
|
|
2114
|
+
this.#aad = aad;
|
|
2115
|
+
return this;
|
|
2116
|
+
}
|
|
2117
|
+
setContentEncryptionKey(cek) {
|
|
2118
|
+
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
2119
|
+
this.#cek = cek;
|
|
2120
|
+
return this;
|
|
2121
|
+
}
|
|
2122
|
+
setInitializationVector(iv) {
|
|
2123
|
+
assertNotSet(this.#iv, "setInitializationVector");
|
|
2124
|
+
this.#iv = iv;
|
|
2125
|
+
return this;
|
|
2126
|
+
}
|
|
2127
|
+
async encrypt(key, options) {
|
|
2128
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader && !this.#sharedUnprotectedHeader) {
|
|
2129
|
+
throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
2130
|
+
}
|
|
2131
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, this.#sharedUnprotectedHeader)) {
|
|
2132
|
+
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
2133
|
+
}
|
|
2134
|
+
const joseHeader = {
|
|
2135
|
+
...this.#protectedHeader,
|
|
2136
|
+
...this.#unprotectedHeader,
|
|
2137
|
+
...this.#sharedUnprotectedHeader
|
|
2138
|
+
};
|
|
2139
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, this.#protectedHeader, joseHeader);
|
|
2140
|
+
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF") {
|
|
2141
|
+
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
2142
|
+
}
|
|
2143
|
+
if (joseHeader.zip !== void 0 && !this.#protectedHeader?.zip) {
|
|
2144
|
+
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
2145
|
+
}
|
|
2146
|
+
const { alg, enc } = joseHeader;
|
|
2147
|
+
if (typeof alg !== "string" || !alg) {
|
|
2148
|
+
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2149
|
+
}
|
|
2150
|
+
if (typeof enc !== "string" || !enc) {
|
|
2151
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
2152
|
+
}
|
|
2153
|
+
let encryptedKey;
|
|
2154
|
+
if (this.#cek && (alg === "dir" || alg === "ECDH-ES")) {
|
|
2155
|
+
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
2156
|
+
}
|
|
2157
|
+
checkKeyType(alg === "dir" ? enc : alg, key, "encrypt");
|
|
2158
|
+
let cek;
|
|
2159
|
+
{
|
|
2160
|
+
let parameters;
|
|
2161
|
+
const k = await normalizeKey(key, alg);
|
|
2162
|
+
({ cek, encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, this.#cek, this.#keyManagementParameters));
|
|
2163
|
+
if (parameters) {
|
|
2164
|
+
if (options && unprotected in options) {
|
|
2165
|
+
if (!this.#unprotectedHeader) {
|
|
2166
|
+
this.setUnprotectedHeader(parameters);
|
|
2167
|
+
} else {
|
|
2168
|
+
this.#unprotectedHeader = { ...this.#unprotectedHeader, ...parameters };
|
|
2169
|
+
}
|
|
2170
|
+
} else if (!this.#protectedHeader) {
|
|
2171
|
+
this.setProtectedHeader(parameters);
|
|
2172
|
+
} else {
|
|
2173
|
+
this.#protectedHeader = { ...this.#protectedHeader, ...parameters };
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
let additionalData;
|
|
2178
|
+
let protectedHeaderS;
|
|
2179
|
+
let protectedHeaderB;
|
|
2180
|
+
let aadMember;
|
|
2181
|
+
if (this.#protectedHeader) {
|
|
2182
|
+
protectedHeaderS = encode2(JSON.stringify(this.#protectedHeader));
|
|
2183
|
+
protectedHeaderB = encode(protectedHeaderS);
|
|
2184
|
+
} else {
|
|
2185
|
+
protectedHeaderS = "";
|
|
2186
|
+
protectedHeaderB = new Uint8Array();
|
|
2187
|
+
}
|
|
2188
|
+
if (this.#aad) {
|
|
2189
|
+
aadMember = encode2(this.#aad);
|
|
2190
|
+
const aadMemberBytes = encode(aadMember);
|
|
2191
|
+
additionalData = concat(protectedHeaderB, encode("."), aadMemberBytes);
|
|
2192
|
+
} else {
|
|
2193
|
+
additionalData = protectedHeaderB;
|
|
2194
|
+
}
|
|
2195
|
+
let plaintext = this.#plaintext;
|
|
2196
|
+
if (joseHeader.zip === "DEF") {
|
|
2197
|
+
plaintext = await compress(plaintext).catch((cause) => {
|
|
2198
|
+
throw new JWEInvalid("Failed to compress plaintext", { cause });
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2201
|
+
const { ciphertext, tag: tag2, iv } = await encrypt(enc, plaintext, cek, this.#iv, additionalData);
|
|
2202
|
+
const jwe = {
|
|
2203
|
+
ciphertext: encode2(ciphertext)
|
|
2204
|
+
};
|
|
2205
|
+
if (iv) {
|
|
2206
|
+
jwe.iv = encode2(iv);
|
|
2207
|
+
}
|
|
2208
|
+
if (tag2) {
|
|
2209
|
+
jwe.tag = encode2(tag2);
|
|
2210
|
+
}
|
|
2211
|
+
if (encryptedKey) {
|
|
2212
|
+
jwe.encrypted_key = encode2(encryptedKey);
|
|
2213
|
+
}
|
|
2214
|
+
if (aadMember) {
|
|
2215
|
+
jwe.aad = aadMember;
|
|
2216
|
+
}
|
|
2217
|
+
if (this.#protectedHeader) {
|
|
2218
|
+
jwe.protected = protectedHeaderS;
|
|
2219
|
+
}
|
|
2220
|
+
if (this.#sharedUnprotectedHeader) {
|
|
2221
|
+
jwe.unprotected = this.#sharedUnprotectedHeader;
|
|
2222
|
+
}
|
|
2223
|
+
if (this.#unprotectedHeader) {
|
|
2224
|
+
jwe.header = this.#unprotectedHeader;
|
|
2225
|
+
}
|
|
2226
|
+
return jwe;
|
|
2227
|
+
}
|
|
2228
|
+
};
|
|
2229
|
+
|
|
2230
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwe/general/encrypt.js
|
|
2231
|
+
var IndividualRecipient = class {
|
|
2232
|
+
#parent;
|
|
2233
|
+
unprotectedHeader;
|
|
2234
|
+
keyManagementParameters;
|
|
2235
|
+
key;
|
|
2236
|
+
options;
|
|
2237
|
+
constructor(enc, key, options) {
|
|
2238
|
+
this.#parent = enc;
|
|
2239
|
+
this.key = key;
|
|
2240
|
+
this.options = options;
|
|
2241
|
+
}
|
|
2242
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
2243
|
+
assertNotSet(this.unprotectedHeader, "setUnprotectedHeader");
|
|
2244
|
+
this.unprotectedHeader = unprotectedHeader;
|
|
2245
|
+
return this;
|
|
2246
|
+
}
|
|
2247
|
+
setKeyManagementParameters(parameters) {
|
|
2248
|
+
assertNotSet(this.keyManagementParameters, "setKeyManagementParameters");
|
|
2249
|
+
this.keyManagementParameters = parameters;
|
|
2250
|
+
return this;
|
|
2251
|
+
}
|
|
2252
|
+
addRecipient(...args) {
|
|
2253
|
+
return this.#parent.addRecipient(...args);
|
|
2254
|
+
}
|
|
2255
|
+
encrypt(...args) {
|
|
2256
|
+
return this.#parent.encrypt(...args);
|
|
2257
|
+
}
|
|
2258
|
+
done() {
|
|
2259
|
+
return this.#parent;
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
var GeneralEncrypt = class {
|
|
2263
|
+
#plaintext;
|
|
2264
|
+
#recipients = [];
|
|
2265
|
+
#protectedHeader;
|
|
2266
|
+
#unprotectedHeader;
|
|
2267
|
+
#aad;
|
|
2268
|
+
constructor(plaintext) {
|
|
2269
|
+
this.#plaintext = plaintext;
|
|
2270
|
+
}
|
|
2271
|
+
addRecipient(key, options) {
|
|
2272
|
+
const recipient = new IndividualRecipient(this, key, { crit: options?.crit });
|
|
2273
|
+
this.#recipients.push(recipient);
|
|
2274
|
+
return recipient;
|
|
2275
|
+
}
|
|
2276
|
+
setProtectedHeader(protectedHeader) {
|
|
2277
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2278
|
+
this.#protectedHeader = protectedHeader;
|
|
2279
|
+
return this;
|
|
2280
|
+
}
|
|
2281
|
+
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
2282
|
+
assertNotSet(this.#unprotectedHeader, "setSharedUnprotectedHeader");
|
|
2283
|
+
this.#unprotectedHeader = sharedUnprotectedHeader;
|
|
2284
|
+
return this;
|
|
2285
|
+
}
|
|
2286
|
+
setAdditionalAuthenticatedData(aad) {
|
|
2287
|
+
this.#aad = aad;
|
|
2288
|
+
return this;
|
|
2289
|
+
}
|
|
2290
|
+
async encrypt() {
|
|
2291
|
+
if (!this.#recipients.length) {
|
|
2292
|
+
throw new JWEInvalid("at least one recipient must be added");
|
|
2293
|
+
}
|
|
2294
|
+
if (this.#recipients.length === 1) {
|
|
2295
|
+
const [recipient] = this.#recipients;
|
|
2296
|
+
const flattened = await new FlattenedEncrypt(this.#plaintext).setAdditionalAuthenticatedData(this.#aad).setProtectedHeader(this.#protectedHeader).setSharedUnprotectedHeader(this.#unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).encrypt(recipient.key, { ...recipient.options });
|
|
2297
|
+
const jwe2 = {
|
|
2298
|
+
ciphertext: flattened.ciphertext,
|
|
2299
|
+
iv: flattened.iv,
|
|
2300
|
+
recipients: [{}],
|
|
2301
|
+
tag: flattened.tag
|
|
2302
|
+
};
|
|
2303
|
+
if (flattened.aad)
|
|
2304
|
+
jwe2.aad = flattened.aad;
|
|
2305
|
+
if (flattened.protected)
|
|
2306
|
+
jwe2.protected = flattened.protected;
|
|
2307
|
+
if (flattened.unprotected)
|
|
2308
|
+
jwe2.unprotected = flattened.unprotected;
|
|
2309
|
+
if (flattened.encrypted_key)
|
|
2310
|
+
jwe2.recipients[0].encrypted_key = flattened.encrypted_key;
|
|
2311
|
+
if (flattened.header)
|
|
2312
|
+
jwe2.recipients[0].header = flattened.header;
|
|
2313
|
+
return jwe2;
|
|
2314
|
+
}
|
|
2315
|
+
let enc;
|
|
2316
|
+
for (let i = 0; i < this.#recipients.length; i++) {
|
|
2317
|
+
const recipient = this.#recipients[i];
|
|
2318
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, recipient.unprotectedHeader)) {
|
|
2319
|
+
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
2320
|
+
}
|
|
2321
|
+
const joseHeader = {
|
|
2322
|
+
...this.#protectedHeader,
|
|
2323
|
+
...this.#unprotectedHeader,
|
|
2324
|
+
...recipient.unprotectedHeader
|
|
2325
|
+
};
|
|
2326
|
+
const { alg } = joseHeader;
|
|
2327
|
+
if (typeof alg !== "string" || !alg) {
|
|
2328
|
+
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2329
|
+
}
|
|
2330
|
+
if (alg === "dir" || alg === "ECDH-ES") {
|
|
2331
|
+
throw new JWEInvalid('"dir" and "ECDH-ES" alg may only be used with a single recipient');
|
|
2332
|
+
}
|
|
2333
|
+
if (typeof joseHeader.enc !== "string" || !joseHeader.enc) {
|
|
2334
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
2335
|
+
}
|
|
2336
|
+
if (!enc) {
|
|
2337
|
+
enc = joseHeader.enc;
|
|
2338
|
+
} else if (enc !== joseHeader.enc) {
|
|
2339
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
|
|
2340
|
+
}
|
|
2341
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), recipient.options.crit, this.#protectedHeader, joseHeader);
|
|
2342
|
+
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF") {
|
|
2343
|
+
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
2344
|
+
}
|
|
2345
|
+
if (joseHeader.zip !== void 0 && !this.#protectedHeader?.zip) {
|
|
2346
|
+
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
const cek = generateCek(enc);
|
|
2350
|
+
const jwe = {
|
|
2351
|
+
ciphertext: "",
|
|
2352
|
+
recipients: []
|
|
2353
|
+
};
|
|
2354
|
+
for (let i = 0; i < this.#recipients.length; i++) {
|
|
2355
|
+
const recipient = this.#recipients[i];
|
|
2356
|
+
const target = {};
|
|
2357
|
+
jwe.recipients.push(target);
|
|
2358
|
+
if (i === 0) {
|
|
2359
|
+
const flattened = await new FlattenedEncrypt(this.#plaintext).setAdditionalAuthenticatedData(this.#aad).setContentEncryptionKey(cek).setProtectedHeader(this.#protectedHeader).setSharedUnprotectedHeader(this.#unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).setKeyManagementParameters(recipient.keyManagementParameters).encrypt(recipient.key, {
|
|
2360
|
+
...recipient.options,
|
|
2361
|
+
[unprotected]: true
|
|
2362
|
+
});
|
|
2363
|
+
jwe.ciphertext = flattened.ciphertext;
|
|
2364
|
+
jwe.iv = flattened.iv;
|
|
2365
|
+
jwe.tag = flattened.tag;
|
|
2366
|
+
if (flattened.aad)
|
|
2367
|
+
jwe.aad = flattened.aad;
|
|
2368
|
+
if (flattened.protected)
|
|
2369
|
+
jwe.protected = flattened.protected;
|
|
2370
|
+
if (flattened.unprotected)
|
|
2371
|
+
jwe.unprotected = flattened.unprotected;
|
|
2372
|
+
target.encrypted_key = flattened.encrypted_key;
|
|
2373
|
+
if (flattened.header)
|
|
2374
|
+
target.header = flattened.header;
|
|
2375
|
+
continue;
|
|
2376
|
+
}
|
|
2377
|
+
const alg = recipient.unprotectedHeader?.alg || this.#protectedHeader?.alg || this.#unprotectedHeader?.alg;
|
|
2378
|
+
checkKeyType(alg === "dir" ? enc : alg, recipient.key, "encrypt");
|
|
2379
|
+
const k = await normalizeKey(recipient.key, alg);
|
|
2380
|
+
const { encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, cek, recipient.keyManagementParameters);
|
|
2381
|
+
target.encrypted_key = encode2(encryptedKey);
|
|
2382
|
+
if (recipient.unprotectedHeader || parameters)
|
|
2383
|
+
target.header = { ...recipient.unprotectedHeader, ...parameters };
|
|
2384
|
+
}
|
|
2385
|
+
return jwe;
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
|
|
2389
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
2390
|
+
async function flattenedVerify(jws, key, options) {
|
|
2391
|
+
if (!isObject(jws)) {
|
|
2392
|
+
throw new JWSInvalid("Flattened JWS must be an object");
|
|
2393
|
+
}
|
|
2394
|
+
if (jws.protected === void 0 && jws.header === void 0) {
|
|
2395
|
+
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
2396
|
+
}
|
|
2397
|
+
if (jws.protected !== void 0 && typeof jws.protected !== "string") {
|
|
2398
|
+
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
2399
|
+
}
|
|
2400
|
+
if (jws.payload === void 0) {
|
|
2401
|
+
throw new JWSInvalid("JWS Payload missing");
|
|
2402
|
+
}
|
|
2403
|
+
if (typeof jws.signature !== "string") {
|
|
2404
|
+
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
2405
|
+
}
|
|
2406
|
+
if (jws.header !== void 0 && !isObject(jws.header)) {
|
|
2407
|
+
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
2408
|
+
}
|
|
2409
|
+
let parsedProt = {};
|
|
2410
|
+
if (jws.protected) {
|
|
2411
|
+
try {
|
|
2412
|
+
const protectedHeader = decode(jws.protected);
|
|
2413
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
2414
|
+
} catch {
|
|
2415
|
+
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
if (!isDisjoint(parsedProt, jws.header)) {
|
|
2419
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
2420
|
+
}
|
|
2421
|
+
const joseHeader = {
|
|
2422
|
+
...parsedProt,
|
|
2423
|
+
...jws.header
|
|
2424
|
+
};
|
|
2425
|
+
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
2426
|
+
let b64 = true;
|
|
2427
|
+
if (extensions.has("b64")) {
|
|
2428
|
+
b64 = parsedProt.b64;
|
|
2429
|
+
if (typeof b64 !== "boolean") {
|
|
2430
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
const { alg } = joseHeader;
|
|
2434
|
+
if (typeof alg !== "string" || !alg) {
|
|
2435
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2436
|
+
}
|
|
2437
|
+
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
2438
|
+
if (algorithms && !algorithms.has(alg)) {
|
|
2439
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
2440
|
+
}
|
|
2441
|
+
if (b64) {
|
|
2442
|
+
if (typeof jws.payload !== "string") {
|
|
2443
|
+
throw new JWSInvalid("JWS Payload must be a string");
|
|
2444
|
+
}
|
|
2445
|
+
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
|
|
2446
|
+
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
2447
|
+
}
|
|
2448
|
+
let resolvedKey = false;
|
|
2449
|
+
if (typeof key === "function") {
|
|
2450
|
+
key = await key(parsedProt, jws);
|
|
2451
|
+
resolvedKey = true;
|
|
2452
|
+
}
|
|
2453
|
+
checkKeyType(alg, key, "verify");
|
|
2454
|
+
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);
|
|
2455
|
+
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
2456
|
+
const k = await normalizeKey(key, alg);
|
|
2457
|
+
const verified = await verify(alg, k, signature, data);
|
|
2458
|
+
if (!verified) {
|
|
2459
|
+
throw new JWSSignatureVerificationFailed();
|
|
2460
|
+
}
|
|
2461
|
+
let payload;
|
|
2462
|
+
if (b64) {
|
|
2463
|
+
payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
2464
|
+
} else if (typeof jws.payload === "string") {
|
|
2465
|
+
payload = encoder.encode(jws.payload);
|
|
2466
|
+
} else {
|
|
2467
|
+
payload = jws.payload;
|
|
2468
|
+
}
|
|
2469
|
+
const result = { payload };
|
|
2470
|
+
if (jws.protected !== void 0) {
|
|
2471
|
+
result.protectedHeader = parsedProt;
|
|
2472
|
+
}
|
|
2473
|
+
if (jws.header !== void 0) {
|
|
2474
|
+
result.unprotectedHeader = jws.header;
|
|
2475
|
+
}
|
|
2476
|
+
if (resolvedKey) {
|
|
2477
|
+
return { ...result, key: k };
|
|
2478
|
+
}
|
|
2479
|
+
return result;
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
2483
|
+
async function compactVerify(jws, key, options) {
|
|
2484
|
+
if (jws instanceof Uint8Array) {
|
|
2485
|
+
jws = decoder.decode(jws);
|
|
2486
|
+
}
|
|
2487
|
+
if (typeof jws !== "string") {
|
|
2488
|
+
throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
2489
|
+
}
|
|
2490
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
2491
|
+
if (length !== 3) {
|
|
2492
|
+
throw new JWSInvalid("Invalid Compact JWS");
|
|
2493
|
+
}
|
|
2494
|
+
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
|
2495
|
+
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
|
2496
|
+
if (typeof key === "function") {
|
|
2497
|
+
return { ...result, key: verified.key };
|
|
2498
|
+
}
|
|
2499
|
+
return result;
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/general/verify.js
|
|
2503
|
+
async function generalVerify(jws, key, options) {
|
|
2504
|
+
if (!isObject(jws)) {
|
|
2505
|
+
throw new JWSInvalid("General JWS must be an object");
|
|
2506
|
+
}
|
|
2507
|
+
if (!Array.isArray(jws.signatures) || !jws.signatures.every(isObject)) {
|
|
2508
|
+
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
2509
|
+
}
|
|
2510
|
+
for (const signature of jws.signatures) {
|
|
2511
|
+
try {
|
|
2512
|
+
return await flattenedVerify({
|
|
2513
|
+
header: signature.header,
|
|
2514
|
+
payload: jws.payload,
|
|
2515
|
+
protected: signature.protected,
|
|
2516
|
+
signature: signature.signature
|
|
2517
|
+
}, key, options);
|
|
2518
|
+
} catch {
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
throw new JWSSignatureVerificationFailed();
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
2525
|
+
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
2526
|
+
var minute = 60;
|
|
2527
|
+
var hour = minute * 60;
|
|
2528
|
+
var day = hour * 24;
|
|
2529
|
+
var week = day * 7;
|
|
2530
|
+
var year = day * 365.25;
|
|
2531
|
+
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
2532
|
+
function secs(str) {
|
|
2533
|
+
const matched = REGEX.exec(str);
|
|
2534
|
+
if (!matched || matched[4] && matched[1]) {
|
|
2535
|
+
throw new TypeError("Invalid time period format");
|
|
2536
|
+
}
|
|
2537
|
+
const value = parseFloat(matched[2]);
|
|
2538
|
+
const unit = matched[3].toLowerCase();
|
|
2539
|
+
let numericDate;
|
|
2540
|
+
switch (unit) {
|
|
2541
|
+
case "sec":
|
|
2542
|
+
case "secs":
|
|
2543
|
+
case "second":
|
|
2544
|
+
case "seconds":
|
|
2545
|
+
case "s":
|
|
2546
|
+
numericDate = Math.round(value);
|
|
2547
|
+
break;
|
|
2548
|
+
case "minute":
|
|
2549
|
+
case "minutes":
|
|
2550
|
+
case "min":
|
|
2551
|
+
case "mins":
|
|
2552
|
+
case "m":
|
|
2553
|
+
numericDate = Math.round(value * minute);
|
|
2554
|
+
break;
|
|
2555
|
+
case "hour":
|
|
2556
|
+
case "hours":
|
|
2557
|
+
case "hr":
|
|
2558
|
+
case "hrs":
|
|
2559
|
+
case "h":
|
|
2560
|
+
numericDate = Math.round(value * hour);
|
|
2561
|
+
break;
|
|
2562
|
+
case "day":
|
|
2563
|
+
case "days":
|
|
2564
|
+
case "d":
|
|
2565
|
+
numericDate = Math.round(value * day);
|
|
2566
|
+
break;
|
|
2567
|
+
case "week":
|
|
2568
|
+
case "weeks":
|
|
2569
|
+
case "w":
|
|
2570
|
+
numericDate = Math.round(value * week);
|
|
2571
|
+
break;
|
|
2572
|
+
default:
|
|
2573
|
+
numericDate = Math.round(value * year);
|
|
2574
|
+
break;
|
|
2575
|
+
}
|
|
2576
|
+
if (matched[1] === "-" || matched[4] === "ago") {
|
|
2577
|
+
return -numericDate;
|
|
2578
|
+
}
|
|
2579
|
+
return numericDate;
|
|
2580
|
+
}
|
|
2581
|
+
function validateInput(label, input) {
|
|
2582
|
+
if (!Number.isFinite(input)) {
|
|
2583
|
+
throw new TypeError(`Invalid ${label} input`);
|
|
2584
|
+
}
|
|
2585
|
+
return input;
|
|
2586
|
+
}
|
|
2587
|
+
var normalizeTyp = (value) => {
|
|
2588
|
+
if (value.includes("/")) {
|
|
2589
|
+
return value.toLowerCase();
|
|
2590
|
+
}
|
|
2591
|
+
return `application/${value.toLowerCase()}`;
|
|
2592
|
+
};
|
|
2593
|
+
var checkAudiencePresence = (audPayload, audOption) => {
|
|
2594
|
+
if (typeof audPayload === "string") {
|
|
2595
|
+
return audOption.includes(audPayload);
|
|
2596
|
+
}
|
|
2597
|
+
if (Array.isArray(audPayload)) {
|
|
2598
|
+
return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
2599
|
+
}
|
|
2600
|
+
return false;
|
|
2601
|
+
};
|
|
2602
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
2603
|
+
let payload;
|
|
2604
|
+
try {
|
|
2605
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
2606
|
+
} catch {
|
|
2607
|
+
}
|
|
2608
|
+
if (!isObject(payload)) {
|
|
2609
|
+
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
2610
|
+
}
|
|
2611
|
+
const { typ } = options;
|
|
2612
|
+
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
|
2613
|
+
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
|
|
2614
|
+
}
|
|
2615
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
2616
|
+
const presenceCheck = [...requiredClaims];
|
|
2617
|
+
if (maxTokenAge !== void 0)
|
|
2618
|
+
presenceCheck.push("iat");
|
|
2619
|
+
if (audience !== void 0)
|
|
2620
|
+
presenceCheck.push("aud");
|
|
2621
|
+
if (subject !== void 0)
|
|
2622
|
+
presenceCheck.push("sub");
|
|
2623
|
+
if (issuer !== void 0)
|
|
2624
|
+
presenceCheck.push("iss");
|
|
2625
|
+
for (const claim of new Set(presenceCheck.reverse())) {
|
|
2626
|
+
if (!(claim in payload)) {
|
|
2627
|
+
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
2631
|
+
throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
|
|
2632
|
+
}
|
|
2633
|
+
if (subject && payload.sub !== subject) {
|
|
2634
|
+
throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
|
|
2635
|
+
}
|
|
2636
|
+
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
|
|
2637
|
+
throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
|
|
2638
|
+
}
|
|
2639
|
+
let tolerance;
|
|
2640
|
+
switch (typeof options.clockTolerance) {
|
|
2641
|
+
case "string":
|
|
2642
|
+
tolerance = secs(options.clockTolerance);
|
|
2643
|
+
break;
|
|
2644
|
+
case "number":
|
|
2645
|
+
tolerance = options.clockTolerance;
|
|
2646
|
+
break;
|
|
2647
|
+
case "undefined":
|
|
2648
|
+
tolerance = 0;
|
|
2649
|
+
break;
|
|
2650
|
+
default:
|
|
2651
|
+
throw new TypeError("Invalid clockTolerance option type");
|
|
2652
|
+
}
|
|
2653
|
+
const { currentDate } = options;
|
|
2654
|
+
const now = epoch(currentDate || /* @__PURE__ */ new Date());
|
|
2655
|
+
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
|
|
2656
|
+
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
|
|
2657
|
+
}
|
|
2658
|
+
if (payload.nbf !== void 0) {
|
|
2659
|
+
if (typeof payload.nbf !== "number") {
|
|
2660
|
+
throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
|
|
2661
|
+
}
|
|
2662
|
+
if (payload.nbf > now + tolerance) {
|
|
2663
|
+
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
if (payload.exp !== void 0) {
|
|
2667
|
+
if (typeof payload.exp !== "number") {
|
|
2668
|
+
throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
|
|
2669
|
+
}
|
|
2670
|
+
if (payload.exp <= now - tolerance) {
|
|
2671
|
+
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
if (maxTokenAge) {
|
|
2675
|
+
const age = now - payload.iat;
|
|
2676
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
2677
|
+
if (age - tolerance > max) {
|
|
2678
|
+
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
|
|
2679
|
+
}
|
|
2680
|
+
if (age < 0 - tolerance) {
|
|
2681
|
+
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
return payload;
|
|
2685
|
+
}
|
|
2686
|
+
var JWTClaimsBuilder = class {
|
|
2687
|
+
#payload;
|
|
2688
|
+
constructor(payload) {
|
|
2689
|
+
if (!isObject(payload)) {
|
|
2690
|
+
throw new TypeError("JWT Claims Set MUST be an object");
|
|
2691
|
+
}
|
|
2692
|
+
this.#payload = structuredClone(payload);
|
|
2693
|
+
}
|
|
2694
|
+
data() {
|
|
2695
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
2696
|
+
}
|
|
2697
|
+
get iss() {
|
|
2698
|
+
return this.#payload.iss;
|
|
2699
|
+
}
|
|
2700
|
+
set iss(value) {
|
|
2701
|
+
this.#payload.iss = value;
|
|
2702
|
+
}
|
|
2703
|
+
get sub() {
|
|
2704
|
+
return this.#payload.sub;
|
|
2705
|
+
}
|
|
2706
|
+
set sub(value) {
|
|
2707
|
+
this.#payload.sub = value;
|
|
2708
|
+
}
|
|
2709
|
+
get aud() {
|
|
2710
|
+
return this.#payload.aud;
|
|
2711
|
+
}
|
|
2712
|
+
set aud(value) {
|
|
2713
|
+
this.#payload.aud = value;
|
|
2714
|
+
}
|
|
2715
|
+
set jti(value) {
|
|
2716
|
+
this.#payload.jti = value;
|
|
2717
|
+
}
|
|
2718
|
+
set nbf(value) {
|
|
2719
|
+
if (typeof value === "number") {
|
|
2720
|
+
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
2721
|
+
} else if (value instanceof Date) {
|
|
2722
|
+
this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
2723
|
+
} else {
|
|
2724
|
+
this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
set exp(value) {
|
|
2728
|
+
if (typeof value === "number") {
|
|
2729
|
+
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
2730
|
+
} else if (value instanceof Date) {
|
|
2731
|
+
this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
2732
|
+
} else {
|
|
2733
|
+
this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
set iat(value) {
|
|
2737
|
+
if (value === void 0) {
|
|
2738
|
+
this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
2739
|
+
} else if (value instanceof Date) {
|
|
2740
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
2741
|
+
} else if (typeof value === "string") {
|
|
2742
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
2743
|
+
} else {
|
|
2744
|
+
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
};
|
|
2748
|
+
|
|
2749
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/verify.js
|
|
2750
|
+
async function jwtVerify(jwt, key, options) {
|
|
2751
|
+
const verified = await compactVerify(jwt, key, options);
|
|
2752
|
+
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
2753
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
2754
|
+
}
|
|
2755
|
+
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
|
2756
|
+
const result = { payload, protectedHeader: verified.protectedHeader };
|
|
2757
|
+
if (typeof key === "function") {
|
|
2758
|
+
return { ...result, key: verified.key };
|
|
2759
|
+
}
|
|
2760
|
+
return result;
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/decrypt.js
|
|
2764
|
+
async function jwtDecrypt(jwt, key, options) {
|
|
2765
|
+
const decrypted = await compactDecrypt(jwt, key, options);
|
|
2766
|
+
const payload = validateClaimsSet(decrypted.protectedHeader, decrypted.plaintext, options);
|
|
2767
|
+
const { protectedHeader } = decrypted;
|
|
2768
|
+
if (protectedHeader.iss !== void 0 && protectedHeader.iss !== payload.iss) {
|
|
2769
|
+
throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, "iss", "mismatch");
|
|
2770
|
+
}
|
|
2771
|
+
if (protectedHeader.sub !== void 0 && protectedHeader.sub !== payload.sub) {
|
|
2772
|
+
throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, "sub", "mismatch");
|
|
2773
|
+
}
|
|
2774
|
+
if (protectedHeader.aud !== void 0 && JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
|
|
2775
|
+
throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, "aud", "mismatch");
|
|
2776
|
+
}
|
|
2777
|
+
const result = { payload, protectedHeader };
|
|
2778
|
+
if (typeof key === "function") {
|
|
2779
|
+
return { ...result, key: decrypted.key };
|
|
2780
|
+
}
|
|
2781
|
+
return result;
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwe/compact/encrypt.js
|
|
2785
|
+
var CompactEncrypt = class {
|
|
2786
|
+
#flattened;
|
|
2787
|
+
constructor(plaintext) {
|
|
2788
|
+
this.#flattened = new FlattenedEncrypt(plaintext);
|
|
2789
|
+
}
|
|
2790
|
+
setContentEncryptionKey(cek) {
|
|
2791
|
+
this.#flattened.setContentEncryptionKey(cek);
|
|
2792
|
+
return this;
|
|
2793
|
+
}
|
|
2794
|
+
setInitializationVector(iv) {
|
|
2795
|
+
this.#flattened.setInitializationVector(iv);
|
|
2796
|
+
return this;
|
|
2797
|
+
}
|
|
2798
|
+
setProtectedHeader(protectedHeader) {
|
|
2799
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
2800
|
+
return this;
|
|
2801
|
+
}
|
|
2802
|
+
setKeyManagementParameters(parameters) {
|
|
2803
|
+
this.#flattened.setKeyManagementParameters(parameters);
|
|
2804
|
+
return this;
|
|
2805
|
+
}
|
|
2806
|
+
async encrypt(key, options) {
|
|
2807
|
+
const jwe = await this.#flattened.encrypt(key, options);
|
|
2808
|
+
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2811
|
+
|
|
2812
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
2813
|
+
var FlattenedSign = class {
|
|
2814
|
+
#payload;
|
|
2815
|
+
#protectedHeader;
|
|
2816
|
+
#unprotectedHeader;
|
|
2817
|
+
constructor(payload) {
|
|
2818
|
+
if (!(payload instanceof Uint8Array)) {
|
|
2819
|
+
throw new TypeError("payload must be an instance of Uint8Array");
|
|
2820
|
+
}
|
|
2821
|
+
this.#payload = payload;
|
|
2822
|
+
}
|
|
2823
|
+
setProtectedHeader(protectedHeader) {
|
|
2824
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2825
|
+
this.#protectedHeader = protectedHeader;
|
|
2826
|
+
return this;
|
|
2827
|
+
}
|
|
2828
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
2829
|
+
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
2830
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
2831
|
+
return this;
|
|
2832
|
+
}
|
|
2833
|
+
async sign(key, options) {
|
|
2834
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
2835
|
+
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
2836
|
+
}
|
|
2837
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
2838
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
2839
|
+
}
|
|
2840
|
+
const joseHeader = {
|
|
2841
|
+
...this.#protectedHeader,
|
|
2842
|
+
...this.#unprotectedHeader
|
|
2843
|
+
};
|
|
2844
|
+
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
2845
|
+
let b64 = true;
|
|
2846
|
+
if (extensions.has("b64")) {
|
|
2847
|
+
b64 = this.#protectedHeader.b64;
|
|
2848
|
+
if (typeof b64 !== "boolean") {
|
|
2849
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
const { alg } = joseHeader;
|
|
2853
|
+
if (typeof alg !== "string" || !alg) {
|
|
2854
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2855
|
+
}
|
|
2856
|
+
checkKeyType(alg, key, "sign");
|
|
2857
|
+
let payloadS;
|
|
2858
|
+
let payloadB;
|
|
2859
|
+
if (b64) {
|
|
2860
|
+
payloadS = encode2(this.#payload);
|
|
2861
|
+
payloadB = encode(payloadS);
|
|
2862
|
+
} else {
|
|
2863
|
+
payloadB = this.#payload;
|
|
2864
|
+
payloadS = "";
|
|
2865
|
+
}
|
|
2866
|
+
let protectedHeaderString;
|
|
2867
|
+
let protectedHeaderBytes;
|
|
2868
|
+
if (this.#protectedHeader) {
|
|
2869
|
+
protectedHeaderString = encode2(JSON.stringify(this.#protectedHeader));
|
|
2870
|
+
protectedHeaderBytes = encode(protectedHeaderString);
|
|
2871
|
+
} else {
|
|
2872
|
+
protectedHeaderString = "";
|
|
2873
|
+
protectedHeaderBytes = new Uint8Array();
|
|
2874
|
+
}
|
|
2875
|
+
const data = concat(protectedHeaderBytes, encode("."), payloadB);
|
|
2876
|
+
const k = await normalizeKey(key, alg);
|
|
2877
|
+
const signature = await sign(alg, k, data);
|
|
2878
|
+
const jws = {
|
|
2879
|
+
signature: encode2(signature),
|
|
2880
|
+
payload: payloadS
|
|
2881
|
+
};
|
|
2882
|
+
if (this.#unprotectedHeader) {
|
|
2883
|
+
jws.header = this.#unprotectedHeader;
|
|
2884
|
+
}
|
|
2885
|
+
if (this.#protectedHeader) {
|
|
2886
|
+
jws.protected = protectedHeaderString;
|
|
2887
|
+
}
|
|
2888
|
+
return jws;
|
|
2889
|
+
}
|
|
2890
|
+
};
|
|
2891
|
+
|
|
2892
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
2893
|
+
var CompactSign = class {
|
|
2894
|
+
#flattened;
|
|
2895
|
+
constructor(payload) {
|
|
2896
|
+
this.#flattened = new FlattenedSign(payload);
|
|
2897
|
+
}
|
|
2898
|
+
setProtectedHeader(protectedHeader) {
|
|
2899
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
2900
|
+
return this;
|
|
2901
|
+
}
|
|
2902
|
+
async sign(key, options) {
|
|
2903
|
+
const jws = await this.#flattened.sign(key, options);
|
|
2904
|
+
if (jws.payload === void 0) {
|
|
2905
|
+
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
2906
|
+
}
|
|
2907
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
2908
|
+
}
|
|
2909
|
+
};
|
|
2910
|
+
|
|
2911
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jws/general/sign.js
|
|
2912
|
+
var IndividualSignature = class {
|
|
2913
|
+
#parent;
|
|
2914
|
+
protectedHeader;
|
|
2915
|
+
unprotectedHeader;
|
|
2916
|
+
options;
|
|
2917
|
+
key;
|
|
2918
|
+
constructor(sig, key, options) {
|
|
2919
|
+
this.#parent = sig;
|
|
2920
|
+
this.key = key;
|
|
2921
|
+
this.options = options;
|
|
2922
|
+
}
|
|
2923
|
+
setProtectedHeader(protectedHeader) {
|
|
2924
|
+
assertNotSet(this.protectedHeader, "setProtectedHeader");
|
|
2925
|
+
this.protectedHeader = protectedHeader;
|
|
2926
|
+
return this;
|
|
2927
|
+
}
|
|
2928
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
2929
|
+
assertNotSet(this.unprotectedHeader, "setUnprotectedHeader");
|
|
2930
|
+
this.unprotectedHeader = unprotectedHeader;
|
|
2931
|
+
return this;
|
|
2932
|
+
}
|
|
2933
|
+
addSignature(...args) {
|
|
2934
|
+
return this.#parent.addSignature(...args);
|
|
2935
|
+
}
|
|
2936
|
+
sign(...args) {
|
|
2937
|
+
return this.#parent.sign(...args);
|
|
2938
|
+
}
|
|
2939
|
+
done() {
|
|
2940
|
+
return this.#parent;
|
|
2941
|
+
}
|
|
2942
|
+
};
|
|
2943
|
+
var GeneralSign = class {
|
|
2944
|
+
#payload;
|
|
2945
|
+
#signatures = [];
|
|
2946
|
+
constructor(payload) {
|
|
2947
|
+
this.#payload = payload;
|
|
2948
|
+
}
|
|
2949
|
+
addSignature(key, options) {
|
|
2950
|
+
const signature = new IndividualSignature(this, key, options);
|
|
2951
|
+
this.#signatures.push(signature);
|
|
2952
|
+
return signature;
|
|
2953
|
+
}
|
|
2954
|
+
async sign() {
|
|
2955
|
+
if (!this.#signatures.length) {
|
|
2956
|
+
throw new JWSInvalid("at least one signature must be added");
|
|
2957
|
+
}
|
|
2958
|
+
const jws = {
|
|
2959
|
+
signatures: [],
|
|
2960
|
+
payload: ""
|
|
2961
|
+
};
|
|
2962
|
+
for (let i = 0; i < this.#signatures.length; i++) {
|
|
2963
|
+
const signature = this.#signatures[i];
|
|
2964
|
+
const flattened = new FlattenedSign(this.#payload);
|
|
2965
|
+
flattened.setProtectedHeader(signature.protectedHeader);
|
|
2966
|
+
flattened.setUnprotectedHeader(signature.unprotectedHeader);
|
|
2967
|
+
const { payload, ...rest } = await flattened.sign(signature.key, signature.options);
|
|
2968
|
+
if (i === 0) {
|
|
2969
|
+
jws.payload = payload;
|
|
2970
|
+
} else if (jws.payload !== payload) {
|
|
2971
|
+
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
2972
|
+
}
|
|
2973
|
+
jws.signatures.push(rest);
|
|
2974
|
+
}
|
|
2975
|
+
return jws;
|
|
2976
|
+
}
|
|
2977
|
+
};
|
|
2978
|
+
|
|
2979
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/sign.js
|
|
2980
|
+
var SignJWT = class {
|
|
2981
|
+
#protectedHeader;
|
|
2982
|
+
#jwt;
|
|
2983
|
+
constructor(payload = {}) {
|
|
2984
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
2985
|
+
}
|
|
2986
|
+
setIssuer(issuer) {
|
|
2987
|
+
this.#jwt.iss = issuer;
|
|
2988
|
+
return this;
|
|
2989
|
+
}
|
|
2990
|
+
setSubject(subject) {
|
|
2991
|
+
this.#jwt.sub = subject;
|
|
2992
|
+
return this;
|
|
2993
|
+
}
|
|
2994
|
+
setAudience(audience) {
|
|
2995
|
+
this.#jwt.aud = audience;
|
|
2996
|
+
return this;
|
|
2997
|
+
}
|
|
2998
|
+
setJti(jwtId) {
|
|
2999
|
+
this.#jwt.jti = jwtId;
|
|
3000
|
+
return this;
|
|
3001
|
+
}
|
|
3002
|
+
setNotBefore(input) {
|
|
3003
|
+
this.#jwt.nbf = input;
|
|
3004
|
+
return this;
|
|
3005
|
+
}
|
|
3006
|
+
setExpirationTime(input) {
|
|
3007
|
+
this.#jwt.exp = input;
|
|
3008
|
+
return this;
|
|
3009
|
+
}
|
|
3010
|
+
setIssuedAt(input) {
|
|
3011
|
+
this.#jwt.iat = input;
|
|
3012
|
+
return this;
|
|
3013
|
+
}
|
|
3014
|
+
setProtectedHeader(protectedHeader) {
|
|
3015
|
+
this.#protectedHeader = protectedHeader;
|
|
3016
|
+
return this;
|
|
3017
|
+
}
|
|
3018
|
+
async sign(key, options) {
|
|
3019
|
+
const sig = new CompactSign(this.#jwt.data());
|
|
3020
|
+
sig.setProtectedHeader(this.#protectedHeader);
|
|
3021
|
+
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
|
|
3022
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3023
|
+
}
|
|
3024
|
+
return sig.sign(key, options);
|
|
3025
|
+
}
|
|
3026
|
+
};
|
|
3027
|
+
|
|
3028
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/encrypt.js
|
|
3029
|
+
var EncryptJWT = class {
|
|
3030
|
+
#cek;
|
|
3031
|
+
#iv;
|
|
3032
|
+
#keyManagementParameters;
|
|
3033
|
+
#protectedHeader;
|
|
3034
|
+
#replicateIssuerAsHeader;
|
|
3035
|
+
#replicateSubjectAsHeader;
|
|
3036
|
+
#replicateAudienceAsHeader;
|
|
3037
|
+
#jwt;
|
|
3038
|
+
constructor(payload = {}) {
|
|
3039
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3040
|
+
}
|
|
3041
|
+
setIssuer(issuer) {
|
|
3042
|
+
this.#jwt.iss = issuer;
|
|
3043
|
+
return this;
|
|
3044
|
+
}
|
|
3045
|
+
setSubject(subject) {
|
|
3046
|
+
this.#jwt.sub = subject;
|
|
3047
|
+
return this;
|
|
3048
|
+
}
|
|
3049
|
+
setAudience(audience) {
|
|
3050
|
+
this.#jwt.aud = audience;
|
|
3051
|
+
return this;
|
|
3052
|
+
}
|
|
3053
|
+
setJti(jwtId) {
|
|
3054
|
+
this.#jwt.jti = jwtId;
|
|
3055
|
+
return this;
|
|
3056
|
+
}
|
|
3057
|
+
setNotBefore(input) {
|
|
3058
|
+
this.#jwt.nbf = input;
|
|
3059
|
+
return this;
|
|
3060
|
+
}
|
|
3061
|
+
setExpirationTime(input) {
|
|
3062
|
+
this.#jwt.exp = input;
|
|
3063
|
+
return this;
|
|
3064
|
+
}
|
|
3065
|
+
setIssuedAt(input) {
|
|
3066
|
+
this.#jwt.iat = input;
|
|
3067
|
+
return this;
|
|
3068
|
+
}
|
|
3069
|
+
setProtectedHeader(protectedHeader) {
|
|
3070
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
3071
|
+
this.#protectedHeader = protectedHeader;
|
|
3072
|
+
return this;
|
|
3073
|
+
}
|
|
3074
|
+
setKeyManagementParameters(parameters) {
|
|
3075
|
+
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
3076
|
+
this.#keyManagementParameters = parameters;
|
|
3077
|
+
return this;
|
|
3078
|
+
}
|
|
3079
|
+
setContentEncryptionKey(cek) {
|
|
3080
|
+
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
3081
|
+
this.#cek = cek;
|
|
3082
|
+
return this;
|
|
3083
|
+
}
|
|
3084
|
+
setInitializationVector(iv) {
|
|
3085
|
+
assertNotSet(this.#iv, "setInitializationVector");
|
|
3086
|
+
this.#iv = iv;
|
|
3087
|
+
return this;
|
|
3088
|
+
}
|
|
3089
|
+
replicateIssuerAsHeader() {
|
|
3090
|
+
this.#replicateIssuerAsHeader = true;
|
|
3091
|
+
return this;
|
|
3092
|
+
}
|
|
3093
|
+
replicateSubjectAsHeader() {
|
|
3094
|
+
this.#replicateSubjectAsHeader = true;
|
|
3095
|
+
return this;
|
|
3096
|
+
}
|
|
3097
|
+
replicateAudienceAsHeader() {
|
|
3098
|
+
this.#replicateAudienceAsHeader = true;
|
|
3099
|
+
return this;
|
|
3100
|
+
}
|
|
3101
|
+
async encrypt(key, options) {
|
|
3102
|
+
const enc = new CompactEncrypt(this.#jwt.data());
|
|
3103
|
+
if (this.#protectedHeader && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
|
|
3104
|
+
this.#protectedHeader = {
|
|
3105
|
+
...this.#protectedHeader,
|
|
3106
|
+
iss: this.#replicateIssuerAsHeader ? this.#jwt.iss : void 0,
|
|
3107
|
+
sub: this.#replicateSubjectAsHeader ? this.#jwt.sub : void 0,
|
|
3108
|
+
aud: this.#replicateAudienceAsHeader ? this.#jwt.aud : void 0
|
|
3109
|
+
};
|
|
3110
|
+
}
|
|
3111
|
+
enc.setProtectedHeader(this.#protectedHeader);
|
|
3112
|
+
if (this.#iv) {
|
|
3113
|
+
enc.setInitializationVector(this.#iv);
|
|
3114
|
+
}
|
|
3115
|
+
if (this.#cek) {
|
|
3116
|
+
enc.setContentEncryptionKey(this.#cek);
|
|
3117
|
+
}
|
|
3118
|
+
if (this.#keyManagementParameters) {
|
|
3119
|
+
enc.setKeyManagementParameters(this.#keyManagementParameters);
|
|
3120
|
+
}
|
|
3121
|
+
return enc.encrypt(key, options);
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
|
|
3125
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwk/thumbprint.js
|
|
3126
|
+
var check = (value, description) => {
|
|
3127
|
+
if (typeof value !== "string" || !value) {
|
|
3128
|
+
throw new JWKInvalid(`${description} missing or invalid`);
|
|
3129
|
+
}
|
|
3130
|
+
};
|
|
3131
|
+
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
3132
|
+
let jwk;
|
|
3133
|
+
if (isJWK(key)) {
|
|
3134
|
+
jwk = key;
|
|
3135
|
+
} else if (isKeyLike(key)) {
|
|
3136
|
+
jwk = await exportJWK(key);
|
|
3137
|
+
} else {
|
|
3138
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
3139
|
+
}
|
|
3140
|
+
digestAlgorithm ??= "sha256";
|
|
3141
|
+
if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") {
|
|
3142
|
+
throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
|
|
3143
|
+
}
|
|
3144
|
+
let components;
|
|
3145
|
+
switch (jwk.kty) {
|
|
3146
|
+
case "AKP":
|
|
3147
|
+
check(jwk.alg, '"alg" (Algorithm) Parameter');
|
|
3148
|
+
check(jwk.pub, '"pub" (Public key) Parameter');
|
|
3149
|
+
components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
|
|
3150
|
+
break;
|
|
3151
|
+
case "EC":
|
|
3152
|
+
check(jwk.crv, '"crv" (Curve) Parameter');
|
|
3153
|
+
check(jwk.x, '"x" (X Coordinate) Parameter');
|
|
3154
|
+
check(jwk.y, '"y" (Y Coordinate) Parameter');
|
|
3155
|
+
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
3156
|
+
break;
|
|
3157
|
+
case "OKP":
|
|
3158
|
+
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
|
|
3159
|
+
check(jwk.x, '"x" (Public Key) Parameter');
|
|
3160
|
+
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
3161
|
+
break;
|
|
3162
|
+
case "RSA":
|
|
3163
|
+
check(jwk.e, '"e" (Exponent) Parameter');
|
|
3164
|
+
check(jwk.n, '"n" (Modulus) Parameter');
|
|
3165
|
+
components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
3166
|
+
break;
|
|
3167
|
+
case "oct":
|
|
3168
|
+
check(jwk.k, '"k" (Key Value) Parameter');
|
|
3169
|
+
components = { k: jwk.k, kty: jwk.kty };
|
|
3170
|
+
break;
|
|
3171
|
+
default:
|
|
3172
|
+
throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
|
|
3173
|
+
}
|
|
3174
|
+
const data = encode(JSON.stringify(components));
|
|
3175
|
+
return encode2(await digest(digestAlgorithm, data));
|
|
3176
|
+
}
|
|
3177
|
+
async function calculateJwkThumbprintUri(key, digestAlgorithm) {
|
|
3178
|
+
digestAlgorithm ??= "sha256";
|
|
3179
|
+
const thumbprint = await calculateJwkThumbprint(key, digestAlgorithm);
|
|
3180
|
+
return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwk/embedded.js
|
|
3184
|
+
async function EmbeddedJWK(protectedHeader, token) {
|
|
3185
|
+
const joseHeader = {
|
|
3186
|
+
...protectedHeader,
|
|
3187
|
+
...token?.header
|
|
3188
|
+
};
|
|
3189
|
+
if (!isObject(joseHeader.jwk)) {
|
|
3190
|
+
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
|
|
3191
|
+
}
|
|
3192
|
+
const key = await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg);
|
|
3193
|
+
if (key instanceof Uint8Array || key.type !== "public") {
|
|
3194
|
+
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
|
|
3195
|
+
}
|
|
3196
|
+
return key;
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwks/local.js
|
|
3200
|
+
function getKtyFromAlg(alg) {
|
|
3201
|
+
switch (typeof alg === "string" && alg.slice(0, 2)) {
|
|
3202
|
+
case "RS":
|
|
3203
|
+
case "PS":
|
|
3204
|
+
return "RSA";
|
|
3205
|
+
case "ES":
|
|
3206
|
+
return "EC";
|
|
3207
|
+
case "Ed":
|
|
3208
|
+
return "OKP";
|
|
3209
|
+
case "ML":
|
|
3210
|
+
return "AKP";
|
|
3211
|
+
default:
|
|
3212
|
+
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
function isJWKSLike(jwks) {
|
|
3216
|
+
return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
|
|
3217
|
+
}
|
|
3218
|
+
function isJWKLike(key) {
|
|
3219
|
+
return isObject(key);
|
|
3220
|
+
}
|
|
3221
|
+
var LocalJWKSet = class {
|
|
3222
|
+
#jwks;
|
|
3223
|
+
#cached = /* @__PURE__ */ new WeakMap();
|
|
3224
|
+
constructor(jwks) {
|
|
3225
|
+
if (!isJWKSLike(jwks)) {
|
|
3226
|
+
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
3227
|
+
}
|
|
3228
|
+
this.#jwks = structuredClone(jwks);
|
|
3229
|
+
}
|
|
3230
|
+
jwks() {
|
|
3231
|
+
return this.#jwks;
|
|
3232
|
+
}
|
|
3233
|
+
async getKey(protectedHeader, token) {
|
|
3234
|
+
const { alg, kid } = { ...protectedHeader, ...token?.header };
|
|
3235
|
+
const kty = getKtyFromAlg(alg);
|
|
3236
|
+
const candidates = this.#jwks.keys.filter((jwk2) => {
|
|
3237
|
+
let candidate = kty === jwk2.kty;
|
|
3238
|
+
if (candidate && typeof kid === "string") {
|
|
3239
|
+
candidate = kid === jwk2.kid;
|
|
3240
|
+
}
|
|
3241
|
+
if (candidate && (typeof jwk2.alg === "string" || kty === "AKP")) {
|
|
3242
|
+
candidate = alg === jwk2.alg;
|
|
3243
|
+
}
|
|
3244
|
+
if (candidate && typeof jwk2.use === "string") {
|
|
3245
|
+
candidate = jwk2.use === "sig";
|
|
3246
|
+
}
|
|
3247
|
+
if (candidate && Array.isArray(jwk2.key_ops)) {
|
|
3248
|
+
candidate = jwk2.key_ops.includes("verify");
|
|
3249
|
+
}
|
|
3250
|
+
if (candidate) {
|
|
3251
|
+
switch (alg) {
|
|
3252
|
+
case "ES256":
|
|
3253
|
+
candidate = jwk2.crv === "P-256";
|
|
3254
|
+
break;
|
|
3255
|
+
case "ES384":
|
|
3256
|
+
candidate = jwk2.crv === "P-384";
|
|
3257
|
+
break;
|
|
3258
|
+
case "ES512":
|
|
3259
|
+
candidate = jwk2.crv === "P-521";
|
|
3260
|
+
break;
|
|
3261
|
+
case "Ed25519":
|
|
3262
|
+
case "EdDSA":
|
|
3263
|
+
candidate = jwk2.crv === "Ed25519";
|
|
3264
|
+
break;
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
return candidate;
|
|
3268
|
+
});
|
|
3269
|
+
const { 0: jwk, length } = candidates;
|
|
3270
|
+
if (length === 0) {
|
|
3271
|
+
throw new JWKSNoMatchingKey();
|
|
3272
|
+
}
|
|
3273
|
+
if (length !== 1) {
|
|
3274
|
+
const error = new JWKSMultipleMatchingKeys();
|
|
3275
|
+
const _cached = this.#cached;
|
|
3276
|
+
error[Symbol.asyncIterator] = async function* () {
|
|
3277
|
+
for (const jwk2 of candidates) {
|
|
3278
|
+
try {
|
|
3279
|
+
yield await importWithAlgCache(_cached, jwk2, alg);
|
|
3280
|
+
} catch {
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
};
|
|
3284
|
+
throw error;
|
|
3285
|
+
}
|
|
3286
|
+
return importWithAlgCache(this.#cached, jwk, alg);
|
|
3287
|
+
}
|
|
3288
|
+
};
|
|
3289
|
+
async function importWithAlgCache(cache2, jwk, alg) {
|
|
3290
|
+
const cached = cache2.get(jwk) || cache2.set(jwk, {}).get(jwk);
|
|
3291
|
+
if (cached[alg] === void 0) {
|
|
3292
|
+
const key = await importJWK({ ...jwk, ext: true }, alg);
|
|
3293
|
+
if (key instanceof Uint8Array || key.type !== "public") {
|
|
3294
|
+
throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
3295
|
+
}
|
|
3296
|
+
cached[alg] = key;
|
|
3297
|
+
}
|
|
3298
|
+
return cached[alg];
|
|
3299
|
+
}
|
|
3300
|
+
function createLocalJWKSet(jwks) {
|
|
3301
|
+
const set = new LocalJWKSet(jwks);
|
|
3302
|
+
const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
3303
|
+
Object.defineProperties(localJWKSet, {
|
|
3304
|
+
jwks: {
|
|
3305
|
+
value: () => structuredClone(set.jwks()),
|
|
3306
|
+
enumerable: false,
|
|
3307
|
+
configurable: false,
|
|
3308
|
+
writable: false
|
|
3309
|
+
}
|
|
3310
|
+
});
|
|
3311
|
+
return localJWKSet;
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwks/remote.js
|
|
3315
|
+
function isCloudflareWorkers() {
|
|
3316
|
+
return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
|
|
3317
|
+
}
|
|
3318
|
+
var USER_AGENT;
|
|
3319
|
+
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
|
|
3320
|
+
const NAME = "jose";
|
|
3321
|
+
const VERSION = "v6.2.2";
|
|
3322
|
+
USER_AGENT = `${NAME}/${VERSION}`;
|
|
3323
|
+
}
|
|
3324
|
+
var customFetch = /* @__PURE__ */ Symbol();
|
|
3325
|
+
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
3326
|
+
const response = await fetchImpl(url, {
|
|
3327
|
+
method: "GET",
|
|
3328
|
+
signal,
|
|
3329
|
+
redirect: "manual",
|
|
3330
|
+
headers
|
|
3331
|
+
}).catch((err) => {
|
|
3332
|
+
if (err.name === "TimeoutError") {
|
|
3333
|
+
throw new JWKSTimeout();
|
|
3334
|
+
}
|
|
3335
|
+
throw err;
|
|
3336
|
+
});
|
|
3337
|
+
if (response.status !== 200) {
|
|
3338
|
+
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
3339
|
+
}
|
|
3340
|
+
try {
|
|
3341
|
+
return await response.json();
|
|
3342
|
+
} catch {
|
|
3343
|
+
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
var jwksCache = /* @__PURE__ */ Symbol();
|
|
3347
|
+
function isFreshJwksCache(input, cacheMaxAge) {
|
|
3348
|
+
if (typeof input !== "object" || input === null) {
|
|
3349
|
+
return false;
|
|
3350
|
+
}
|
|
3351
|
+
if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) {
|
|
3352
|
+
return false;
|
|
3353
|
+
}
|
|
3354
|
+
if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) {
|
|
3355
|
+
return false;
|
|
3356
|
+
}
|
|
3357
|
+
return true;
|
|
3358
|
+
}
|
|
3359
|
+
var RemoteJWKSet = class {
|
|
3360
|
+
#url;
|
|
3361
|
+
#timeoutDuration;
|
|
3362
|
+
#cooldownDuration;
|
|
3363
|
+
#cacheMaxAge;
|
|
3364
|
+
#jwksTimestamp;
|
|
3365
|
+
#pendingFetch;
|
|
3366
|
+
#headers;
|
|
3367
|
+
#customFetch;
|
|
3368
|
+
#local;
|
|
3369
|
+
#cache;
|
|
3370
|
+
constructor(url, options) {
|
|
3371
|
+
if (!(url instanceof URL)) {
|
|
3372
|
+
throw new TypeError("url must be an instance of URL");
|
|
3373
|
+
}
|
|
3374
|
+
this.#url = new URL(url.href);
|
|
3375
|
+
this.#timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
|
|
3376
|
+
this.#cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
|
|
3377
|
+
this.#cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
|
|
3378
|
+
this.#headers = new Headers(options?.headers);
|
|
3379
|
+
if (USER_AGENT && !this.#headers.has("User-Agent")) {
|
|
3380
|
+
this.#headers.set("User-Agent", USER_AGENT);
|
|
3381
|
+
}
|
|
3382
|
+
if (!this.#headers.has("accept")) {
|
|
3383
|
+
this.#headers.set("accept", "application/json");
|
|
3384
|
+
this.#headers.append("accept", "application/jwk-set+json");
|
|
3385
|
+
}
|
|
3386
|
+
this.#customFetch = options?.[customFetch];
|
|
3387
|
+
if (options?.[jwksCache] !== void 0) {
|
|
3388
|
+
this.#cache = options?.[jwksCache];
|
|
3389
|
+
if (isFreshJwksCache(options?.[jwksCache], this.#cacheMaxAge)) {
|
|
3390
|
+
this.#jwksTimestamp = this.#cache.uat;
|
|
3391
|
+
this.#local = createLocalJWKSet(this.#cache.jwks);
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
}
|
|
3395
|
+
pendingFetch() {
|
|
3396
|
+
return !!this.#pendingFetch;
|
|
3397
|
+
}
|
|
3398
|
+
coolingDown() {
|
|
3399
|
+
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cooldownDuration : false;
|
|
3400
|
+
}
|
|
3401
|
+
fresh() {
|
|
3402
|
+
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cacheMaxAge : false;
|
|
3403
|
+
}
|
|
3404
|
+
jwks() {
|
|
3405
|
+
return this.#local?.jwks();
|
|
3406
|
+
}
|
|
3407
|
+
async getKey(protectedHeader, token) {
|
|
3408
|
+
if (!this.#local || !this.fresh()) {
|
|
3409
|
+
await this.reload();
|
|
3410
|
+
}
|
|
3411
|
+
try {
|
|
3412
|
+
return await this.#local(protectedHeader, token);
|
|
3413
|
+
} catch (err) {
|
|
3414
|
+
if (err instanceof JWKSNoMatchingKey) {
|
|
3415
|
+
if (this.coolingDown() === false) {
|
|
3416
|
+
await this.reload();
|
|
3417
|
+
return this.#local(protectedHeader, token);
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
throw err;
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
async reload() {
|
|
3424
|
+
if (this.#pendingFetch && isCloudflareWorkers()) {
|
|
3425
|
+
this.#pendingFetch = void 0;
|
|
3426
|
+
}
|
|
3427
|
+
this.#pendingFetch ||= fetchJwks(this.#url.href, this.#headers, AbortSignal.timeout(this.#timeoutDuration), this.#customFetch).then((json) => {
|
|
3428
|
+
this.#local = createLocalJWKSet(json);
|
|
3429
|
+
if (this.#cache) {
|
|
3430
|
+
this.#cache.uat = Date.now();
|
|
3431
|
+
this.#cache.jwks = json;
|
|
3432
|
+
}
|
|
3433
|
+
this.#jwksTimestamp = Date.now();
|
|
3434
|
+
this.#pendingFetch = void 0;
|
|
3435
|
+
}).catch((err) => {
|
|
3436
|
+
this.#pendingFetch = void 0;
|
|
3437
|
+
throw err;
|
|
3438
|
+
});
|
|
3439
|
+
await this.#pendingFetch;
|
|
3440
|
+
}
|
|
3441
|
+
};
|
|
3442
|
+
function createRemoteJWKSet(url, options) {
|
|
3443
|
+
const set = new RemoteJWKSet(url, options);
|
|
3444
|
+
const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
3445
|
+
Object.defineProperties(remoteJWKSet, {
|
|
3446
|
+
coolingDown: {
|
|
3447
|
+
get: () => set.coolingDown(),
|
|
3448
|
+
enumerable: true,
|
|
3449
|
+
configurable: false
|
|
3450
|
+
},
|
|
3451
|
+
fresh: {
|
|
3452
|
+
get: () => set.fresh(),
|
|
3453
|
+
enumerable: true,
|
|
3454
|
+
configurable: false
|
|
3455
|
+
},
|
|
3456
|
+
reload: {
|
|
3457
|
+
value: () => set.reload(),
|
|
3458
|
+
enumerable: true,
|
|
3459
|
+
configurable: false,
|
|
3460
|
+
writable: false
|
|
3461
|
+
},
|
|
3462
|
+
reloading: {
|
|
3463
|
+
get: () => set.pendingFetch(),
|
|
3464
|
+
enumerable: true,
|
|
3465
|
+
configurable: false
|
|
3466
|
+
},
|
|
3467
|
+
jwks: {
|
|
3468
|
+
value: () => set.jwks(),
|
|
3469
|
+
enumerable: true,
|
|
3470
|
+
configurable: false,
|
|
3471
|
+
writable: false
|
|
3472
|
+
}
|
|
3473
|
+
});
|
|
3474
|
+
return remoteJWKSet;
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/jwt/unsecured.js
|
|
3478
|
+
var UnsecuredJWT = class {
|
|
3479
|
+
#jwt;
|
|
3480
|
+
constructor(payload = {}) {
|
|
3481
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3482
|
+
}
|
|
3483
|
+
encode() {
|
|
3484
|
+
const header = encode2(JSON.stringify({ alg: "none" }));
|
|
3485
|
+
const payload = encode2(this.#jwt.data());
|
|
3486
|
+
return `${header}.${payload}.`;
|
|
3487
|
+
}
|
|
3488
|
+
setIssuer(issuer) {
|
|
3489
|
+
this.#jwt.iss = issuer;
|
|
3490
|
+
return this;
|
|
3491
|
+
}
|
|
3492
|
+
setSubject(subject) {
|
|
3493
|
+
this.#jwt.sub = subject;
|
|
3494
|
+
return this;
|
|
3495
|
+
}
|
|
3496
|
+
setAudience(audience) {
|
|
3497
|
+
this.#jwt.aud = audience;
|
|
3498
|
+
return this;
|
|
3499
|
+
}
|
|
3500
|
+
setJti(jwtId) {
|
|
3501
|
+
this.#jwt.jti = jwtId;
|
|
3502
|
+
return this;
|
|
3503
|
+
}
|
|
3504
|
+
setNotBefore(input) {
|
|
3505
|
+
this.#jwt.nbf = input;
|
|
3506
|
+
return this;
|
|
3507
|
+
}
|
|
3508
|
+
setExpirationTime(input) {
|
|
3509
|
+
this.#jwt.exp = input;
|
|
3510
|
+
return this;
|
|
3511
|
+
}
|
|
3512
|
+
setIssuedAt(input) {
|
|
3513
|
+
this.#jwt.iat = input;
|
|
3514
|
+
return this;
|
|
3515
|
+
}
|
|
3516
|
+
static decode(jwt, options) {
|
|
3517
|
+
if (typeof jwt !== "string") {
|
|
3518
|
+
throw new JWTInvalid("Unsecured JWT must be a string");
|
|
3519
|
+
}
|
|
3520
|
+
const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
|
|
3521
|
+
if (length !== 3 || signature !== "") {
|
|
3522
|
+
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
3523
|
+
}
|
|
3524
|
+
let header;
|
|
3525
|
+
try {
|
|
3526
|
+
header = JSON.parse(decoder.decode(decode(encodedHeader)));
|
|
3527
|
+
if (header.alg !== "none")
|
|
3528
|
+
throw new Error();
|
|
3529
|
+
} catch {
|
|
3530
|
+
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
3531
|
+
}
|
|
3532
|
+
const payload = validateClaimsSet(header, decode(encodedPayload), options);
|
|
3533
|
+
return { payload, header };
|
|
3534
|
+
}
|
|
3535
|
+
};
|
|
3536
|
+
|
|
3537
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
3538
|
+
function decodeProtectedHeader(token) {
|
|
3539
|
+
let protectedB64u;
|
|
3540
|
+
if (typeof token === "string") {
|
|
3541
|
+
const parts = token.split(".");
|
|
3542
|
+
if (parts.length === 3 || parts.length === 5) {
|
|
3543
|
+
;
|
|
3544
|
+
[protectedB64u] = parts;
|
|
3545
|
+
}
|
|
3546
|
+
} else if (typeof token === "object" && token) {
|
|
3547
|
+
if ("protected" in token) {
|
|
3548
|
+
protectedB64u = token.protected;
|
|
3549
|
+
} else {
|
|
3550
|
+
throw new TypeError("Token does not contain a Protected Header");
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
try {
|
|
3554
|
+
if (typeof protectedB64u !== "string" || !protectedB64u) {
|
|
3555
|
+
throw new Error();
|
|
3556
|
+
}
|
|
3557
|
+
const result = JSON.parse(decoder.decode(decode(protectedB64u)));
|
|
3558
|
+
if (!isObject(result)) {
|
|
3559
|
+
throw new Error();
|
|
3560
|
+
}
|
|
3561
|
+
return result;
|
|
3562
|
+
} catch {
|
|
3563
|
+
throw new TypeError("Invalid Token or Protected Header formatting");
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
3568
|
+
function decodeJwt(jwt) {
|
|
3569
|
+
if (typeof jwt !== "string")
|
|
3570
|
+
throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
3571
|
+
const { 1: payload, length } = jwt.split(".");
|
|
3572
|
+
if (length === 5)
|
|
3573
|
+
throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
|
|
3574
|
+
if (length !== 3)
|
|
3575
|
+
throw new JWTInvalid("Invalid JWT");
|
|
3576
|
+
if (!payload)
|
|
3577
|
+
throw new JWTInvalid("JWTs must contain a payload");
|
|
3578
|
+
let decoded;
|
|
3579
|
+
try {
|
|
3580
|
+
decoded = decode(payload);
|
|
3581
|
+
} catch {
|
|
3582
|
+
throw new JWTInvalid("Failed to base64url decode the payload");
|
|
3583
|
+
}
|
|
3584
|
+
let result;
|
|
3585
|
+
try {
|
|
3586
|
+
result = JSON.parse(decoder.decode(decoded));
|
|
3587
|
+
} catch {
|
|
3588
|
+
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
3589
|
+
}
|
|
3590
|
+
if (!isObject(result))
|
|
3591
|
+
throw new JWTInvalid("Invalid JWT Claims Set");
|
|
3592
|
+
return result;
|
|
3593
|
+
}
|
|
3594
|
+
|
|
3595
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/generate_key_pair.js
|
|
3596
|
+
function getModulusLengthOption(options) {
|
|
3597
|
+
const modulusLength = options?.modulusLength ?? 2048;
|
|
3598
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
3599
|
+
throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
|
|
3600
|
+
}
|
|
3601
|
+
return modulusLength;
|
|
3602
|
+
}
|
|
3603
|
+
async function generateKeyPair(alg, options) {
|
|
3604
|
+
let algorithm;
|
|
3605
|
+
let keyUsages;
|
|
3606
|
+
switch (alg) {
|
|
3607
|
+
case "PS256":
|
|
3608
|
+
case "PS384":
|
|
3609
|
+
case "PS512":
|
|
3610
|
+
algorithm = {
|
|
3611
|
+
name: "RSA-PSS",
|
|
3612
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
3613
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
3614
|
+
modulusLength: getModulusLengthOption(options)
|
|
3615
|
+
};
|
|
3616
|
+
keyUsages = ["sign", "verify"];
|
|
3617
|
+
break;
|
|
3618
|
+
case "RS256":
|
|
3619
|
+
case "RS384":
|
|
3620
|
+
case "RS512":
|
|
3621
|
+
algorithm = {
|
|
3622
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
3623
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
3624
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
3625
|
+
modulusLength: getModulusLengthOption(options)
|
|
3626
|
+
};
|
|
3627
|
+
keyUsages = ["sign", "verify"];
|
|
3628
|
+
break;
|
|
3629
|
+
case "RSA-OAEP":
|
|
3630
|
+
case "RSA-OAEP-256":
|
|
3631
|
+
case "RSA-OAEP-384":
|
|
3632
|
+
case "RSA-OAEP-512":
|
|
3633
|
+
algorithm = {
|
|
3634
|
+
name: "RSA-OAEP",
|
|
3635
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
|
|
3636
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
3637
|
+
modulusLength: getModulusLengthOption(options)
|
|
3638
|
+
};
|
|
3639
|
+
keyUsages = ["decrypt", "unwrapKey", "encrypt", "wrapKey"];
|
|
3640
|
+
break;
|
|
3641
|
+
case "ES256":
|
|
3642
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
3643
|
+
keyUsages = ["sign", "verify"];
|
|
3644
|
+
break;
|
|
3645
|
+
case "ES384":
|
|
3646
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
3647
|
+
keyUsages = ["sign", "verify"];
|
|
3648
|
+
break;
|
|
3649
|
+
case "ES512":
|
|
3650
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
3651
|
+
keyUsages = ["sign", "verify"];
|
|
3652
|
+
break;
|
|
3653
|
+
case "Ed25519":
|
|
3654
|
+
case "EdDSA": {
|
|
3655
|
+
keyUsages = ["sign", "verify"];
|
|
3656
|
+
algorithm = { name: "Ed25519" };
|
|
3657
|
+
break;
|
|
3658
|
+
}
|
|
3659
|
+
case "ML-DSA-44":
|
|
3660
|
+
case "ML-DSA-65":
|
|
3661
|
+
case "ML-DSA-87": {
|
|
3662
|
+
keyUsages = ["sign", "verify"];
|
|
3663
|
+
algorithm = { name: alg };
|
|
3664
|
+
break;
|
|
3665
|
+
}
|
|
3666
|
+
case "ECDH-ES":
|
|
3667
|
+
case "ECDH-ES+A128KW":
|
|
3668
|
+
case "ECDH-ES+A192KW":
|
|
3669
|
+
case "ECDH-ES+A256KW": {
|
|
3670
|
+
keyUsages = ["deriveBits"];
|
|
3671
|
+
const crv = options?.crv ?? "P-256";
|
|
3672
|
+
switch (crv) {
|
|
3673
|
+
case "P-256":
|
|
3674
|
+
case "P-384":
|
|
3675
|
+
case "P-521": {
|
|
3676
|
+
algorithm = { name: "ECDH", namedCurve: crv };
|
|
3677
|
+
break;
|
|
3678
|
+
}
|
|
3679
|
+
case "X25519":
|
|
3680
|
+
algorithm = { name: "X25519" };
|
|
3681
|
+
break;
|
|
3682
|
+
default:
|
|
3683
|
+
throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
|
|
3684
|
+
}
|
|
3685
|
+
break;
|
|
3686
|
+
}
|
|
3687
|
+
default:
|
|
3688
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
3689
|
+
}
|
|
3690
|
+
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
|
|
3691
|
+
}
|
|
3692
|
+
|
|
3693
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/key/generate_secret.js
|
|
3694
|
+
async function generateSecret(alg, options) {
|
|
3695
|
+
let length;
|
|
3696
|
+
let algorithm;
|
|
3697
|
+
let keyUsages;
|
|
3698
|
+
switch (alg) {
|
|
3699
|
+
case "HS256":
|
|
3700
|
+
case "HS384":
|
|
3701
|
+
case "HS512":
|
|
3702
|
+
length = parseInt(alg.slice(-3), 10);
|
|
3703
|
+
algorithm = { name: "HMAC", hash: `SHA-${length}`, length };
|
|
3704
|
+
keyUsages = ["sign", "verify"];
|
|
3705
|
+
break;
|
|
3706
|
+
case "A128CBC-HS256":
|
|
3707
|
+
case "A192CBC-HS384":
|
|
3708
|
+
case "A256CBC-HS512":
|
|
3709
|
+
length = parseInt(alg.slice(-3), 10);
|
|
3710
|
+
return crypto.getRandomValues(new Uint8Array(length >> 3));
|
|
3711
|
+
case "A128KW":
|
|
3712
|
+
case "A192KW":
|
|
3713
|
+
case "A256KW":
|
|
3714
|
+
length = parseInt(alg.slice(1, 4), 10);
|
|
3715
|
+
algorithm = { name: "AES-KW", length };
|
|
3716
|
+
keyUsages = ["wrapKey", "unwrapKey"];
|
|
3717
|
+
break;
|
|
3718
|
+
case "A128GCMKW":
|
|
3719
|
+
case "A192GCMKW":
|
|
3720
|
+
case "A256GCMKW":
|
|
3721
|
+
case "A128GCM":
|
|
3722
|
+
case "A192GCM":
|
|
3723
|
+
case "A256GCM":
|
|
3724
|
+
length = parseInt(alg.slice(1, 4), 10);
|
|
3725
|
+
algorithm = { name: "AES-GCM", length };
|
|
3726
|
+
keyUsages = ["encrypt", "decrypt"];
|
|
3727
|
+
break;
|
|
3728
|
+
default:
|
|
3729
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
3730
|
+
}
|
|
3731
|
+
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
// ../../node_modules/.pnpm/jose@6.2.2/node_modules/jose/dist/webapi/index.js
|
|
3735
|
+
var cryptoRuntime = "WebCryptoAPI";
|
|
3736
|
+
export {
|
|
3737
|
+
CompactEncrypt,
|
|
3738
|
+
CompactSign,
|
|
3739
|
+
EmbeddedJWK,
|
|
3740
|
+
EncryptJWT,
|
|
3741
|
+
FlattenedEncrypt,
|
|
3742
|
+
FlattenedSign,
|
|
3743
|
+
GeneralEncrypt,
|
|
3744
|
+
GeneralSign,
|
|
3745
|
+
SignJWT,
|
|
3746
|
+
UnsecuredJWT,
|
|
3747
|
+
base64url_exports as base64url,
|
|
3748
|
+
calculateJwkThumbprint,
|
|
3749
|
+
calculateJwkThumbprintUri,
|
|
3750
|
+
compactDecrypt,
|
|
3751
|
+
compactVerify,
|
|
3752
|
+
createLocalJWKSet,
|
|
3753
|
+
createRemoteJWKSet,
|
|
3754
|
+
cryptoRuntime,
|
|
3755
|
+
customFetch,
|
|
3756
|
+
decodeJwt,
|
|
3757
|
+
decodeProtectedHeader,
|
|
3758
|
+
errors_exports as errors,
|
|
3759
|
+
exportJWK,
|
|
3760
|
+
exportPKCS8,
|
|
3761
|
+
exportSPKI,
|
|
3762
|
+
flattenedDecrypt,
|
|
3763
|
+
flattenedVerify,
|
|
3764
|
+
generalDecrypt,
|
|
3765
|
+
generalVerify,
|
|
3766
|
+
generateKeyPair,
|
|
3767
|
+
generateSecret,
|
|
3768
|
+
importJWK,
|
|
3769
|
+
importPKCS8,
|
|
3770
|
+
importSPKI,
|
|
3771
|
+
importX509,
|
|
3772
|
+
jwksCache,
|
|
3773
|
+
jwtDecrypt,
|
|
3774
|
+
jwtVerify
|
|
3775
|
+
};
|