@multi-agent-protocol/sdk 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.cjs +4533 -139
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +4533 -139
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -3,6 +3,4349 @@
|
|
|
3
3
|
var ulid = require('ulid');
|
|
4
4
|
var zod = require('zod');
|
|
5
5
|
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// ../../../node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
17
|
+
function concat(...buffers) {
|
|
18
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
19
|
+
const buf = new Uint8Array(size);
|
|
20
|
+
let i = 0;
|
|
21
|
+
for (const buffer of buffers) {
|
|
22
|
+
buf.set(buffer, i);
|
|
23
|
+
i += buffer.length;
|
|
24
|
+
}
|
|
25
|
+
return buf;
|
|
26
|
+
}
|
|
27
|
+
function writeUInt32BE(buf, value, offset) {
|
|
28
|
+
if (value < 0 || value >= MAX_INT32) {
|
|
29
|
+
throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
30
|
+
}
|
|
31
|
+
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
|
|
32
|
+
}
|
|
33
|
+
function uint64be(value) {
|
|
34
|
+
const high = Math.floor(value / MAX_INT32);
|
|
35
|
+
const low = value % MAX_INT32;
|
|
36
|
+
const buf = new Uint8Array(8);
|
|
37
|
+
writeUInt32BE(buf, high, 0);
|
|
38
|
+
writeUInt32BE(buf, low, 4);
|
|
39
|
+
return buf;
|
|
40
|
+
}
|
|
41
|
+
function uint32be(value) {
|
|
42
|
+
const buf = new Uint8Array(4);
|
|
43
|
+
writeUInt32BE(buf, value);
|
|
44
|
+
return buf;
|
|
45
|
+
}
|
|
46
|
+
function encode(string) {
|
|
47
|
+
const bytes = new Uint8Array(string.length);
|
|
48
|
+
for (let i = 0; i < string.length; i++) {
|
|
49
|
+
const code = string.charCodeAt(i);
|
|
50
|
+
if (code > 127) {
|
|
51
|
+
throw new TypeError("non-ASCII string encountered in encode()");
|
|
52
|
+
}
|
|
53
|
+
bytes[i] = code;
|
|
54
|
+
}
|
|
55
|
+
return bytes;
|
|
56
|
+
}
|
|
57
|
+
var encoder, decoder, MAX_INT32;
|
|
58
|
+
var init_buffer_utils = __esm({
|
|
59
|
+
"../../../node_modules/jose/dist/webapi/lib/buffer_utils.js"() {
|
|
60
|
+
encoder = new TextEncoder();
|
|
61
|
+
decoder = new TextDecoder();
|
|
62
|
+
MAX_INT32 = 2 ** 32;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// ../../../node_modules/jose/dist/webapi/lib/base64.js
|
|
67
|
+
function encodeBase64(input) {
|
|
68
|
+
if (Uint8Array.prototype.toBase64) {
|
|
69
|
+
return input.toBase64();
|
|
70
|
+
}
|
|
71
|
+
const CHUNK_SIZE = 32768;
|
|
72
|
+
const arr = [];
|
|
73
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
74
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
75
|
+
}
|
|
76
|
+
return btoa(arr.join(""));
|
|
77
|
+
}
|
|
78
|
+
function decodeBase64(encoded) {
|
|
79
|
+
if (Uint8Array.fromBase64) {
|
|
80
|
+
return Uint8Array.fromBase64(encoded);
|
|
81
|
+
}
|
|
82
|
+
const binary = atob(encoded);
|
|
83
|
+
const bytes = new Uint8Array(binary.length);
|
|
84
|
+
for (let i = 0; i < binary.length; i++) {
|
|
85
|
+
bytes[i] = binary.charCodeAt(i);
|
|
86
|
+
}
|
|
87
|
+
return bytes;
|
|
88
|
+
}
|
|
89
|
+
var init_base64 = __esm({
|
|
90
|
+
"../../../node_modules/jose/dist/webapi/lib/base64.js"() {
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ../../../node_modules/jose/dist/webapi/util/base64url.js
|
|
95
|
+
var base64url_exports = {};
|
|
96
|
+
__export(base64url_exports, {
|
|
97
|
+
decode: () => decode,
|
|
98
|
+
encode: () => encode2
|
|
99
|
+
});
|
|
100
|
+
function decode(input) {
|
|
101
|
+
if (Uint8Array.fromBase64) {
|
|
102
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
103
|
+
alphabet: "base64url"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
let encoded = input;
|
|
107
|
+
if (encoded instanceof Uint8Array) {
|
|
108
|
+
encoded = decoder.decode(encoded);
|
|
109
|
+
}
|
|
110
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
111
|
+
try {
|
|
112
|
+
return decodeBase64(encoded);
|
|
113
|
+
} catch {
|
|
114
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function encode2(input) {
|
|
118
|
+
let unencoded = input;
|
|
119
|
+
if (typeof unencoded === "string") {
|
|
120
|
+
unencoded = encoder.encode(unencoded);
|
|
121
|
+
}
|
|
122
|
+
if (Uint8Array.prototype.toBase64) {
|
|
123
|
+
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
124
|
+
}
|
|
125
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
126
|
+
}
|
|
127
|
+
var init_base64url = __esm({
|
|
128
|
+
"../../../node_modules/jose/dist/webapi/util/base64url.js"() {
|
|
129
|
+
init_buffer_utils();
|
|
130
|
+
init_base64();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ../../../node_modules/jose/dist/webapi/util/errors.js
|
|
135
|
+
var errors_exports = {};
|
|
136
|
+
__export(errors_exports, {
|
|
137
|
+
JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
|
|
138
|
+
JOSEError: () => JOSEError,
|
|
139
|
+
JOSENotSupported: () => JOSENotSupported,
|
|
140
|
+
JWEDecryptionFailed: () => JWEDecryptionFailed,
|
|
141
|
+
JWEInvalid: () => JWEInvalid,
|
|
142
|
+
JWKInvalid: () => JWKInvalid,
|
|
143
|
+
JWKSInvalid: () => JWKSInvalid,
|
|
144
|
+
JWKSMultipleMatchingKeys: () => JWKSMultipleMatchingKeys,
|
|
145
|
+
JWKSNoMatchingKey: () => JWKSNoMatchingKey,
|
|
146
|
+
JWKSTimeout: () => JWKSTimeout,
|
|
147
|
+
JWSInvalid: () => JWSInvalid,
|
|
148
|
+
JWSSignatureVerificationFailed: () => JWSSignatureVerificationFailed,
|
|
149
|
+
JWTClaimValidationFailed: () => JWTClaimValidationFailed,
|
|
150
|
+
JWTExpired: () => JWTExpired,
|
|
151
|
+
JWTInvalid: () => JWTInvalid
|
|
152
|
+
});
|
|
153
|
+
var JOSEError, JWTClaimValidationFailed, JWTExpired, JOSEAlgNotAllowed, JOSENotSupported, JWEDecryptionFailed, JWEInvalid, JWSInvalid, JWTInvalid, JWKInvalid, JWKSInvalid, JWKSNoMatchingKey, JWKSMultipleMatchingKeys, JWKSTimeout, JWSSignatureVerificationFailed;
|
|
154
|
+
var init_errors = __esm({
|
|
155
|
+
"../../../node_modules/jose/dist/webapi/util/errors.js"() {
|
|
156
|
+
JOSEError = class extends Error {
|
|
157
|
+
static code = "ERR_JOSE_GENERIC";
|
|
158
|
+
code = "ERR_JOSE_GENERIC";
|
|
159
|
+
constructor(message2, options) {
|
|
160
|
+
super(message2, options);
|
|
161
|
+
this.name = this.constructor.name;
|
|
162
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
JWTClaimValidationFailed = class extends JOSEError {
|
|
166
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
167
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
168
|
+
claim;
|
|
169
|
+
reason;
|
|
170
|
+
payload;
|
|
171
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
172
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
173
|
+
this.claim = claim;
|
|
174
|
+
this.reason = reason;
|
|
175
|
+
this.payload = payload;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
JWTExpired = class extends JOSEError {
|
|
179
|
+
static code = "ERR_JWT_EXPIRED";
|
|
180
|
+
code = "ERR_JWT_EXPIRED";
|
|
181
|
+
claim;
|
|
182
|
+
reason;
|
|
183
|
+
payload;
|
|
184
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
185
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
186
|
+
this.claim = claim;
|
|
187
|
+
this.reason = reason;
|
|
188
|
+
this.payload = payload;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
JOSEAlgNotAllowed = class extends JOSEError {
|
|
192
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
193
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
194
|
+
};
|
|
195
|
+
JOSENotSupported = class extends JOSEError {
|
|
196
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
197
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
198
|
+
};
|
|
199
|
+
JWEDecryptionFailed = class extends JOSEError {
|
|
200
|
+
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
201
|
+
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
202
|
+
constructor(message2 = "decryption operation failed", options) {
|
|
203
|
+
super(message2, options);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
JWEInvalid = class extends JOSEError {
|
|
207
|
+
static code = "ERR_JWE_INVALID";
|
|
208
|
+
code = "ERR_JWE_INVALID";
|
|
209
|
+
};
|
|
210
|
+
JWSInvalid = class extends JOSEError {
|
|
211
|
+
static code = "ERR_JWS_INVALID";
|
|
212
|
+
code = "ERR_JWS_INVALID";
|
|
213
|
+
};
|
|
214
|
+
JWTInvalid = class extends JOSEError {
|
|
215
|
+
static code = "ERR_JWT_INVALID";
|
|
216
|
+
code = "ERR_JWT_INVALID";
|
|
217
|
+
};
|
|
218
|
+
JWKInvalid = class extends JOSEError {
|
|
219
|
+
static code = "ERR_JWK_INVALID";
|
|
220
|
+
code = "ERR_JWK_INVALID";
|
|
221
|
+
};
|
|
222
|
+
JWKSInvalid = class extends JOSEError {
|
|
223
|
+
static code = "ERR_JWKS_INVALID";
|
|
224
|
+
code = "ERR_JWKS_INVALID";
|
|
225
|
+
};
|
|
226
|
+
JWKSNoMatchingKey = class extends JOSEError {
|
|
227
|
+
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
228
|
+
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
229
|
+
constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
|
|
230
|
+
super(message2, options);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
JWKSMultipleMatchingKeys = class extends JOSEError {
|
|
234
|
+
[Symbol.asyncIterator];
|
|
235
|
+
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
236
|
+
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
237
|
+
constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
238
|
+
super(message2, options);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
JWKSTimeout = class extends JOSEError {
|
|
242
|
+
static code = "ERR_JWKS_TIMEOUT";
|
|
243
|
+
code = "ERR_JWKS_TIMEOUT";
|
|
244
|
+
constructor(message2 = "request timed out", options) {
|
|
245
|
+
super(message2, options);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
JWSSignatureVerificationFailed = class extends JOSEError {
|
|
249
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
250
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
251
|
+
constructor(message2 = "signature verification failed", options) {
|
|
252
|
+
super(message2, options);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// ../../../node_modules/jose/dist/webapi/lib/iv.js
|
|
259
|
+
function bitLength(alg) {
|
|
260
|
+
switch (alg) {
|
|
261
|
+
case "A128GCM":
|
|
262
|
+
case "A128GCMKW":
|
|
263
|
+
case "A192GCM":
|
|
264
|
+
case "A192GCMKW":
|
|
265
|
+
case "A256GCM":
|
|
266
|
+
case "A256GCMKW":
|
|
267
|
+
return 96;
|
|
268
|
+
case "A128CBC-HS256":
|
|
269
|
+
case "A192CBC-HS384":
|
|
270
|
+
case "A256CBC-HS512":
|
|
271
|
+
return 128;
|
|
272
|
+
default:
|
|
273
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
var generateIv;
|
|
277
|
+
var init_iv = __esm({
|
|
278
|
+
"../../../node_modules/jose/dist/webapi/lib/iv.js"() {
|
|
279
|
+
init_errors();
|
|
280
|
+
generateIv = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// ../../../node_modules/jose/dist/webapi/lib/check_iv_length.js
|
|
285
|
+
function checkIvLength(enc, iv) {
|
|
286
|
+
if (iv.length << 3 !== bitLength(enc)) {
|
|
287
|
+
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
var init_check_iv_length = __esm({
|
|
291
|
+
"../../../node_modules/jose/dist/webapi/lib/check_iv_length.js"() {
|
|
292
|
+
init_errors();
|
|
293
|
+
init_iv();
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
// ../../../node_modules/jose/dist/webapi/lib/check_cek_length.js
|
|
298
|
+
function checkCekLength(cek, expected) {
|
|
299
|
+
const actual = cek.byteLength << 3;
|
|
300
|
+
if (actual !== expected) {
|
|
301
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
var init_check_cek_length = __esm({
|
|
305
|
+
"../../../node_modules/jose/dist/webapi/lib/check_cek_length.js"() {
|
|
306
|
+
init_errors();
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// ../../../node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
311
|
+
function getHashLength(hash) {
|
|
312
|
+
return parseInt(hash.name.slice(4), 10);
|
|
313
|
+
}
|
|
314
|
+
function getNamedCurve(alg) {
|
|
315
|
+
switch (alg) {
|
|
316
|
+
case "ES256":
|
|
317
|
+
return "P-256";
|
|
318
|
+
case "ES384":
|
|
319
|
+
return "P-384";
|
|
320
|
+
case "ES512":
|
|
321
|
+
return "P-521";
|
|
322
|
+
default:
|
|
323
|
+
throw new Error("unreachable");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function checkUsage(key, usage) {
|
|
327
|
+
if (usage && !key.usages.includes(usage)) {
|
|
328
|
+
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
332
|
+
switch (alg) {
|
|
333
|
+
case "HS256":
|
|
334
|
+
case "HS384":
|
|
335
|
+
case "HS512": {
|
|
336
|
+
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
337
|
+
throw unusable("HMAC");
|
|
338
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
339
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
340
|
+
if (actual !== expected)
|
|
341
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
case "RS256":
|
|
345
|
+
case "RS384":
|
|
346
|
+
case "RS512": {
|
|
347
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
348
|
+
throw unusable("RSASSA-PKCS1-v1_5");
|
|
349
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
350
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
351
|
+
if (actual !== expected)
|
|
352
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case "PS256":
|
|
356
|
+
case "PS384":
|
|
357
|
+
case "PS512": {
|
|
358
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
359
|
+
throw unusable("RSA-PSS");
|
|
360
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
361
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
362
|
+
if (actual !== expected)
|
|
363
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
case "Ed25519":
|
|
367
|
+
case "EdDSA": {
|
|
368
|
+
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
369
|
+
throw unusable("Ed25519");
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
case "ML-DSA-44":
|
|
373
|
+
case "ML-DSA-65":
|
|
374
|
+
case "ML-DSA-87": {
|
|
375
|
+
if (!isAlgorithm(key.algorithm, alg))
|
|
376
|
+
throw unusable(alg);
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
case "ES256":
|
|
380
|
+
case "ES384":
|
|
381
|
+
case "ES512": {
|
|
382
|
+
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
383
|
+
throw unusable("ECDSA");
|
|
384
|
+
const expected = getNamedCurve(alg);
|
|
385
|
+
const actual = key.algorithm.namedCurve;
|
|
386
|
+
if (actual !== expected)
|
|
387
|
+
throw unusable(expected, "algorithm.namedCurve");
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
default:
|
|
391
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
392
|
+
}
|
|
393
|
+
checkUsage(key, usage);
|
|
394
|
+
}
|
|
395
|
+
function checkEncCryptoKey(key, alg, usage) {
|
|
396
|
+
switch (alg) {
|
|
397
|
+
case "A128GCM":
|
|
398
|
+
case "A192GCM":
|
|
399
|
+
case "A256GCM": {
|
|
400
|
+
if (!isAlgorithm(key.algorithm, "AES-GCM"))
|
|
401
|
+
throw unusable("AES-GCM");
|
|
402
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
403
|
+
const actual = key.algorithm.length;
|
|
404
|
+
if (actual !== expected)
|
|
405
|
+
throw unusable(expected, "algorithm.length");
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case "A128KW":
|
|
409
|
+
case "A192KW":
|
|
410
|
+
case "A256KW": {
|
|
411
|
+
if (!isAlgorithm(key.algorithm, "AES-KW"))
|
|
412
|
+
throw unusable("AES-KW");
|
|
413
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
414
|
+
const actual = key.algorithm.length;
|
|
415
|
+
if (actual !== expected)
|
|
416
|
+
throw unusable(expected, "algorithm.length");
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
case "ECDH": {
|
|
420
|
+
switch (key.algorithm.name) {
|
|
421
|
+
case "ECDH":
|
|
422
|
+
case "X25519":
|
|
423
|
+
break;
|
|
424
|
+
default:
|
|
425
|
+
throw unusable("ECDH or X25519");
|
|
426
|
+
}
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
case "PBES2-HS256+A128KW":
|
|
430
|
+
case "PBES2-HS384+A192KW":
|
|
431
|
+
case "PBES2-HS512+A256KW":
|
|
432
|
+
if (!isAlgorithm(key.algorithm, "PBKDF2"))
|
|
433
|
+
throw unusable("PBKDF2");
|
|
434
|
+
break;
|
|
435
|
+
case "RSA-OAEP":
|
|
436
|
+
case "RSA-OAEP-256":
|
|
437
|
+
case "RSA-OAEP-384":
|
|
438
|
+
case "RSA-OAEP-512": {
|
|
439
|
+
if (!isAlgorithm(key.algorithm, "RSA-OAEP"))
|
|
440
|
+
throw unusable("RSA-OAEP");
|
|
441
|
+
const expected = parseInt(alg.slice(9), 10) || 1;
|
|
442
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
443
|
+
if (actual !== expected)
|
|
444
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
default:
|
|
448
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
449
|
+
}
|
|
450
|
+
checkUsage(key, usage);
|
|
451
|
+
}
|
|
452
|
+
var unusable, isAlgorithm;
|
|
453
|
+
var init_crypto_key = __esm({
|
|
454
|
+
"../../../node_modules/jose/dist/webapi/lib/crypto_key.js"() {
|
|
455
|
+
unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
456
|
+
isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// ../../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
461
|
+
function message(msg, actual, ...types) {
|
|
462
|
+
types = types.filter(Boolean);
|
|
463
|
+
if (types.length > 2) {
|
|
464
|
+
const last = types.pop();
|
|
465
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
466
|
+
} else if (types.length === 2) {
|
|
467
|
+
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
468
|
+
} else {
|
|
469
|
+
msg += `of type ${types[0]}.`;
|
|
470
|
+
}
|
|
471
|
+
if (actual == null) {
|
|
472
|
+
msg += ` Received ${actual}`;
|
|
473
|
+
} else if (typeof actual === "function" && actual.name) {
|
|
474
|
+
msg += ` Received function ${actual.name}`;
|
|
475
|
+
} else if (typeof actual === "object" && actual != null) {
|
|
476
|
+
if (actual.constructor?.name) {
|
|
477
|
+
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return msg;
|
|
481
|
+
}
|
|
482
|
+
var invalidKeyInput, withAlg;
|
|
483
|
+
var init_invalid_key_input = __esm({
|
|
484
|
+
"../../../node_modules/jose/dist/webapi/lib/invalid_key_input.js"() {
|
|
485
|
+
invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
486
|
+
withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// ../../../node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
491
|
+
function assertCryptoKey(key) {
|
|
492
|
+
if (!isCryptoKey(key)) {
|
|
493
|
+
throw new Error("CryptoKey instance expected");
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
var isCryptoKey, isKeyObject, isKeyLike;
|
|
497
|
+
var init_is_key_like = __esm({
|
|
498
|
+
"../../../node_modules/jose/dist/webapi/lib/is_key_like.js"() {
|
|
499
|
+
isCryptoKey = (key) => {
|
|
500
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
501
|
+
return true;
|
|
502
|
+
try {
|
|
503
|
+
return key instanceof CryptoKey;
|
|
504
|
+
} catch {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
509
|
+
isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// ../../../node_modules/jose/dist/webapi/lib/decrypt.js
|
|
514
|
+
async function timingSafeEqual(a, b) {
|
|
515
|
+
if (!(a instanceof Uint8Array)) {
|
|
516
|
+
throw new TypeError("First argument must be a buffer");
|
|
517
|
+
}
|
|
518
|
+
if (!(b instanceof Uint8Array)) {
|
|
519
|
+
throw new TypeError("Second argument must be a buffer");
|
|
520
|
+
}
|
|
521
|
+
const algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
522
|
+
const key = await crypto.subtle.generateKey(algorithm, false, ["sign"]);
|
|
523
|
+
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
524
|
+
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
525
|
+
let out = 0;
|
|
526
|
+
let i = -1;
|
|
527
|
+
while (++i < 32) {
|
|
528
|
+
out |= aHmac[i] ^ bHmac[i];
|
|
529
|
+
}
|
|
530
|
+
return out === 0;
|
|
531
|
+
}
|
|
532
|
+
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
533
|
+
if (!(cek instanceof Uint8Array)) {
|
|
534
|
+
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
535
|
+
}
|
|
536
|
+
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
537
|
+
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["decrypt"]);
|
|
538
|
+
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
539
|
+
hash: `SHA-${keySize << 1}`,
|
|
540
|
+
name: "HMAC"
|
|
541
|
+
}, false, ["sign"]);
|
|
542
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
543
|
+
const expectedTag = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
544
|
+
let macCheckPassed;
|
|
545
|
+
try {
|
|
546
|
+
macCheckPassed = await timingSafeEqual(tag2, expectedTag);
|
|
547
|
+
} catch {
|
|
548
|
+
}
|
|
549
|
+
if (!macCheckPassed) {
|
|
550
|
+
throw new JWEDecryptionFailed();
|
|
551
|
+
}
|
|
552
|
+
let plaintext;
|
|
553
|
+
try {
|
|
554
|
+
plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
555
|
+
} catch {
|
|
556
|
+
}
|
|
557
|
+
if (!plaintext) {
|
|
558
|
+
throw new JWEDecryptionFailed();
|
|
559
|
+
}
|
|
560
|
+
return plaintext;
|
|
561
|
+
}
|
|
562
|
+
async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
563
|
+
let encKey;
|
|
564
|
+
if (cek instanceof Uint8Array) {
|
|
565
|
+
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["decrypt"]);
|
|
566
|
+
} else {
|
|
567
|
+
checkEncCryptoKey(cek, enc, "decrypt");
|
|
568
|
+
encKey = cek;
|
|
569
|
+
}
|
|
570
|
+
try {
|
|
571
|
+
return new Uint8Array(await crypto.subtle.decrypt({
|
|
572
|
+
additionalData: aad,
|
|
573
|
+
iv,
|
|
574
|
+
name: "AES-GCM",
|
|
575
|
+
tagLength: 128
|
|
576
|
+
}, encKey, concat(ciphertext, tag2)));
|
|
577
|
+
} catch {
|
|
578
|
+
throw new JWEDecryptionFailed();
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
async function decrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
582
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
583
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
584
|
+
}
|
|
585
|
+
if (!iv) {
|
|
586
|
+
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
587
|
+
}
|
|
588
|
+
if (!tag2) {
|
|
589
|
+
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
590
|
+
}
|
|
591
|
+
checkIvLength(enc, iv);
|
|
592
|
+
switch (enc) {
|
|
593
|
+
case "A128CBC-HS256":
|
|
594
|
+
case "A192CBC-HS384":
|
|
595
|
+
case "A256CBC-HS512":
|
|
596
|
+
if (cek instanceof Uint8Array)
|
|
597
|
+
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
598
|
+
return cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
599
|
+
case "A128GCM":
|
|
600
|
+
case "A192GCM":
|
|
601
|
+
case "A256GCM":
|
|
602
|
+
if (cek instanceof Uint8Array)
|
|
603
|
+
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
604
|
+
return gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
605
|
+
default:
|
|
606
|
+
throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
var init_decrypt = __esm({
|
|
610
|
+
"../../../node_modules/jose/dist/webapi/lib/decrypt.js"() {
|
|
611
|
+
init_buffer_utils();
|
|
612
|
+
init_check_iv_length();
|
|
613
|
+
init_check_cek_length();
|
|
614
|
+
init_errors();
|
|
615
|
+
init_crypto_key();
|
|
616
|
+
init_invalid_key_input();
|
|
617
|
+
init_is_key_like();
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
// ../../../node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
622
|
+
function isDisjoint(...headers) {
|
|
623
|
+
const sources = headers.filter(Boolean);
|
|
624
|
+
if (sources.length === 0 || sources.length === 1) {
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
let acc;
|
|
628
|
+
for (const header of sources) {
|
|
629
|
+
const parameters = Object.keys(header);
|
|
630
|
+
if (!acc || acc.size === 0) {
|
|
631
|
+
acc = new Set(parameters);
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
for (const parameter of parameters) {
|
|
635
|
+
if (acc.has(parameter)) {
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
acc.add(parameter);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
var init_is_disjoint = __esm({
|
|
644
|
+
"../../../node_modules/jose/dist/webapi/lib/is_disjoint.js"() {
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
// ../../../node_modules/jose/dist/webapi/lib/is_object.js
|
|
649
|
+
function isObject(input) {
|
|
650
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
656
|
+
let proto = input;
|
|
657
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
658
|
+
proto = Object.getPrototypeOf(proto);
|
|
659
|
+
}
|
|
660
|
+
return Object.getPrototypeOf(input) === proto;
|
|
661
|
+
}
|
|
662
|
+
var isObjectLike;
|
|
663
|
+
var init_is_object = __esm({
|
|
664
|
+
"../../../node_modules/jose/dist/webapi/lib/is_object.js"() {
|
|
665
|
+
isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
// ../../../node_modules/jose/dist/webapi/lib/aeskw.js
|
|
670
|
+
function checkKeySize(key, alg) {
|
|
671
|
+
if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
|
|
672
|
+
throw new TypeError(`Invalid key size for alg: ${alg}`);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
function getCryptoKey(key, alg, usage) {
|
|
676
|
+
if (key instanceof Uint8Array) {
|
|
677
|
+
return crypto.subtle.importKey("raw", key, "AES-KW", true, [usage]);
|
|
678
|
+
}
|
|
679
|
+
checkEncCryptoKey(key, alg, usage);
|
|
680
|
+
return key;
|
|
681
|
+
}
|
|
682
|
+
async function wrap(alg, key, cek) {
|
|
683
|
+
const cryptoKey = await getCryptoKey(key, alg, "wrapKey");
|
|
684
|
+
checkKeySize(cryptoKey, alg);
|
|
685
|
+
const cryptoKeyCek = await crypto.subtle.importKey("raw", cek, { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
686
|
+
return new Uint8Array(await crypto.subtle.wrapKey("raw", cryptoKeyCek, cryptoKey, "AES-KW"));
|
|
687
|
+
}
|
|
688
|
+
async function unwrap(alg, key, encryptedKey) {
|
|
689
|
+
const cryptoKey = await getCryptoKey(key, alg, "unwrapKey");
|
|
690
|
+
checkKeySize(cryptoKey, alg);
|
|
691
|
+
const cryptoKeyCek = await crypto.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
692
|
+
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
693
|
+
}
|
|
694
|
+
var init_aeskw = __esm({
|
|
695
|
+
"../../../node_modules/jose/dist/webapi/lib/aeskw.js"() {
|
|
696
|
+
init_crypto_key();
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
// ../../../node_modules/jose/dist/webapi/lib/digest.js
|
|
701
|
+
async function digest(algorithm, data) {
|
|
702
|
+
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
703
|
+
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
704
|
+
}
|
|
705
|
+
var init_digest = __esm({
|
|
706
|
+
"../../../node_modules/jose/dist/webapi/lib/digest.js"() {
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
// ../../../node_modules/jose/dist/webapi/lib/ecdhes.js
|
|
711
|
+
function lengthAndInput(input) {
|
|
712
|
+
return concat(uint32be(input.length), input);
|
|
713
|
+
}
|
|
714
|
+
async function concatKdf(Z, L, OtherInfo) {
|
|
715
|
+
const dkLen = L >> 3;
|
|
716
|
+
const hashLen = 32;
|
|
717
|
+
const reps = Math.ceil(dkLen / hashLen);
|
|
718
|
+
const dk = new Uint8Array(reps * hashLen);
|
|
719
|
+
for (let i = 1; i <= reps; i++) {
|
|
720
|
+
const hashInput = new Uint8Array(4 + Z.length + OtherInfo.length);
|
|
721
|
+
hashInput.set(uint32be(i), 0);
|
|
722
|
+
hashInput.set(Z, 4);
|
|
723
|
+
hashInput.set(OtherInfo, 4 + Z.length);
|
|
724
|
+
const hashResult = await digest("sha256", hashInput);
|
|
725
|
+
dk.set(hashResult, (i - 1) * hashLen);
|
|
726
|
+
}
|
|
727
|
+
return dk.slice(0, dkLen);
|
|
728
|
+
}
|
|
729
|
+
async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
|
|
730
|
+
checkEncCryptoKey(publicKey, "ECDH");
|
|
731
|
+
checkEncCryptoKey(privateKey, "ECDH", "deriveBits");
|
|
732
|
+
const algorithmID = lengthAndInput(encode(algorithm));
|
|
733
|
+
const partyUInfo = lengthAndInput(apu);
|
|
734
|
+
const partyVInfo = lengthAndInput(apv);
|
|
735
|
+
const suppPubInfo = uint32be(keyLength);
|
|
736
|
+
const suppPrivInfo = new Uint8Array();
|
|
737
|
+
const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
|
|
738
|
+
const Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
739
|
+
name: publicKey.algorithm.name,
|
|
740
|
+
public: publicKey
|
|
741
|
+
}, privateKey, getEcdhBitLength(publicKey)));
|
|
742
|
+
return concatKdf(Z, keyLength, otherInfo);
|
|
743
|
+
}
|
|
744
|
+
function getEcdhBitLength(publicKey) {
|
|
745
|
+
if (publicKey.algorithm.name === "X25519") {
|
|
746
|
+
return 256;
|
|
747
|
+
}
|
|
748
|
+
return Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3;
|
|
749
|
+
}
|
|
750
|
+
function allowed(key) {
|
|
751
|
+
switch (key.algorithm.namedCurve) {
|
|
752
|
+
case "P-256":
|
|
753
|
+
case "P-384":
|
|
754
|
+
case "P-521":
|
|
755
|
+
return true;
|
|
756
|
+
default:
|
|
757
|
+
return key.algorithm.name === "X25519";
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
var init_ecdhes = __esm({
|
|
761
|
+
"../../../node_modules/jose/dist/webapi/lib/ecdhes.js"() {
|
|
762
|
+
init_buffer_utils();
|
|
763
|
+
init_crypto_key();
|
|
764
|
+
init_digest();
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
// ../../../node_modules/jose/dist/webapi/lib/pbes2kw.js
|
|
769
|
+
function getCryptoKey2(key, alg) {
|
|
770
|
+
if (key instanceof Uint8Array) {
|
|
771
|
+
return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
|
|
772
|
+
"deriveBits"
|
|
773
|
+
]);
|
|
774
|
+
}
|
|
775
|
+
checkEncCryptoKey(key, alg, "deriveBits");
|
|
776
|
+
return key;
|
|
777
|
+
}
|
|
778
|
+
async function deriveKey2(p2s, alg, p2c, key) {
|
|
779
|
+
if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
|
|
780
|
+
throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
|
|
781
|
+
}
|
|
782
|
+
const salt = concatSalt(alg, p2s);
|
|
783
|
+
const keylen = parseInt(alg.slice(13, 16), 10);
|
|
784
|
+
const subtleAlg = {
|
|
785
|
+
hash: `SHA-${alg.slice(8, 11)}`,
|
|
786
|
+
iterations: p2c,
|
|
787
|
+
name: "PBKDF2",
|
|
788
|
+
salt
|
|
789
|
+
};
|
|
790
|
+
const cryptoKey = await getCryptoKey2(key, alg);
|
|
791
|
+
return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
|
|
792
|
+
}
|
|
793
|
+
async function wrap2(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
|
|
794
|
+
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
795
|
+
const encryptedKey = await wrap(alg.slice(-6), derived, cek);
|
|
796
|
+
return { encryptedKey, p2c, p2s: encode2(p2s) };
|
|
797
|
+
}
|
|
798
|
+
async function unwrap2(alg, key, encryptedKey, p2c, p2s) {
|
|
799
|
+
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
800
|
+
return unwrap(alg.slice(-6), derived, encryptedKey);
|
|
801
|
+
}
|
|
802
|
+
var concatSalt;
|
|
803
|
+
var init_pbes2kw = __esm({
|
|
804
|
+
"../../../node_modules/jose/dist/webapi/lib/pbes2kw.js"() {
|
|
805
|
+
init_base64url();
|
|
806
|
+
init_aeskw();
|
|
807
|
+
init_crypto_key();
|
|
808
|
+
init_buffer_utils();
|
|
809
|
+
init_errors();
|
|
810
|
+
concatSalt = (alg, p2sInput) => concat(encode(alg), Uint8Array.of(0), p2sInput);
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// ../../../node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
815
|
+
function checkKeyLength(alg, key) {
|
|
816
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
817
|
+
const { modulusLength } = key.algorithm;
|
|
818
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
819
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
var init_check_key_length = __esm({
|
|
824
|
+
"../../../node_modules/jose/dist/webapi/lib/check_key_length.js"() {
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
// ../../../node_modules/jose/dist/webapi/lib/rsaes.js
|
|
829
|
+
async function encrypt(alg, key, cek) {
|
|
830
|
+
checkEncCryptoKey(key, alg, "encrypt");
|
|
831
|
+
checkKeyLength(alg, key);
|
|
832
|
+
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm(alg), key, cek));
|
|
833
|
+
}
|
|
834
|
+
async function decrypt2(alg, key, encryptedKey) {
|
|
835
|
+
checkEncCryptoKey(key, alg, "decrypt");
|
|
836
|
+
checkKeyLength(alg, key);
|
|
837
|
+
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm(alg), key, encryptedKey));
|
|
838
|
+
}
|
|
839
|
+
var subtleAlgorithm;
|
|
840
|
+
var init_rsaes = __esm({
|
|
841
|
+
"../../../node_modules/jose/dist/webapi/lib/rsaes.js"() {
|
|
842
|
+
init_crypto_key();
|
|
843
|
+
init_check_key_length();
|
|
844
|
+
init_errors();
|
|
845
|
+
subtleAlgorithm = (alg) => {
|
|
846
|
+
switch (alg) {
|
|
847
|
+
case "RSA-OAEP":
|
|
848
|
+
case "RSA-OAEP-256":
|
|
849
|
+
case "RSA-OAEP-384":
|
|
850
|
+
case "RSA-OAEP-512":
|
|
851
|
+
return "RSA-OAEP";
|
|
852
|
+
default:
|
|
853
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
// ../../../node_modules/jose/dist/webapi/lib/cek.js
|
|
860
|
+
function cekLength(alg) {
|
|
861
|
+
switch (alg) {
|
|
862
|
+
case "A128GCM":
|
|
863
|
+
return 128;
|
|
864
|
+
case "A192GCM":
|
|
865
|
+
return 192;
|
|
866
|
+
case "A256GCM":
|
|
867
|
+
case "A128CBC-HS256":
|
|
868
|
+
return 256;
|
|
869
|
+
case "A192CBC-HS384":
|
|
870
|
+
return 384;
|
|
871
|
+
case "A256CBC-HS512":
|
|
872
|
+
return 512;
|
|
873
|
+
default:
|
|
874
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
var generateCek;
|
|
878
|
+
var init_cek = __esm({
|
|
879
|
+
"../../../node_modules/jose/dist/webapi/lib/cek.js"() {
|
|
880
|
+
init_errors();
|
|
881
|
+
generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
// ../../../node_modules/jose/dist/webapi/lib/asn1.js
|
|
886
|
+
function parsePKCS8Header(state) {
|
|
887
|
+
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
888
|
+
parseLength(state);
|
|
889
|
+
expectTag(state, 2, "Expected version field");
|
|
890
|
+
const verLen = parseLength(state);
|
|
891
|
+
state.pos += verLen;
|
|
892
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
893
|
+
const algIdLen = parseLength(state);
|
|
894
|
+
const algIdStart = state.pos;
|
|
895
|
+
return { algIdStart, algIdLength: algIdLen };
|
|
896
|
+
}
|
|
897
|
+
function parseSPKIHeader(state) {
|
|
898
|
+
expectTag(state, 48, "Invalid SPKI structure");
|
|
899
|
+
parseLength(state);
|
|
900
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
901
|
+
const algIdLen = parseLength(state);
|
|
902
|
+
const algIdStart = state.pos;
|
|
903
|
+
return { algIdStart, algIdLength: algIdLen };
|
|
904
|
+
}
|
|
905
|
+
function spkiFromX509(buf) {
|
|
906
|
+
const state = createASN1State(buf);
|
|
907
|
+
expectTag(state, 48, "Invalid certificate structure");
|
|
908
|
+
parseLength(state);
|
|
909
|
+
expectTag(state, 48, "Invalid tbsCertificate structure");
|
|
910
|
+
parseLength(state);
|
|
911
|
+
if (buf[state.pos] === 160) {
|
|
912
|
+
skipElement(state, 6);
|
|
913
|
+
} else {
|
|
914
|
+
skipElement(state, 5);
|
|
915
|
+
}
|
|
916
|
+
const spkiStart = state.pos;
|
|
917
|
+
expectTag(state, 48, "Invalid SPKI structure");
|
|
918
|
+
const spkiContentLen = parseLength(state);
|
|
919
|
+
return buf.subarray(spkiStart, spkiStart + spkiContentLen + (state.pos - spkiStart));
|
|
920
|
+
}
|
|
921
|
+
function extractX509SPKI(x509) {
|
|
922
|
+
const derBytes = processPEMData(x509, /(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g);
|
|
923
|
+
return spkiFromX509(derBytes);
|
|
924
|
+
}
|
|
925
|
+
var formatPEM, genericExport, toSPKI, toPKCS8, bytesEqual, createASN1State, parseLength, skipElement, expectTag, getSubarray, parseAlgorithmOID, parseECAlgorithmIdentifier, genericImport, processPEMData, fromPKCS8, fromSPKI, fromX509;
|
|
926
|
+
var init_asn1 = __esm({
|
|
927
|
+
"../../../node_modules/jose/dist/webapi/lib/asn1.js"() {
|
|
928
|
+
init_invalid_key_input();
|
|
929
|
+
init_base64();
|
|
930
|
+
init_errors();
|
|
931
|
+
init_is_key_like();
|
|
932
|
+
formatPEM = (b64, descriptor) => {
|
|
933
|
+
const newlined = (b64.match(/.{1,64}/g) || []).join("\n");
|
|
934
|
+
return `-----BEGIN ${descriptor}-----
|
|
935
|
+
${newlined}
|
|
936
|
+
-----END ${descriptor}-----`;
|
|
937
|
+
};
|
|
938
|
+
genericExport = async (keyType, keyFormat, key) => {
|
|
939
|
+
if (isKeyObject(key)) {
|
|
940
|
+
if (key.type !== keyType) {
|
|
941
|
+
throw new TypeError(`key is not a ${keyType} key`);
|
|
942
|
+
}
|
|
943
|
+
return key.export({ format: "pem", type: keyFormat });
|
|
944
|
+
}
|
|
945
|
+
if (!isCryptoKey(key)) {
|
|
946
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject"));
|
|
947
|
+
}
|
|
948
|
+
if (!key.extractable) {
|
|
949
|
+
throw new TypeError("CryptoKey is not extractable");
|
|
950
|
+
}
|
|
951
|
+
if (key.type !== keyType) {
|
|
952
|
+
throw new TypeError(`key is not a ${keyType} key`);
|
|
953
|
+
}
|
|
954
|
+
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
955
|
+
};
|
|
956
|
+
toSPKI = (key) => genericExport("public", "spki", key);
|
|
957
|
+
toPKCS8 = (key) => genericExport("private", "pkcs8", key);
|
|
958
|
+
bytesEqual = (a, b) => {
|
|
959
|
+
if (a.byteLength !== b.length)
|
|
960
|
+
return false;
|
|
961
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
962
|
+
if (a[i] !== b[i])
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
return true;
|
|
966
|
+
};
|
|
967
|
+
createASN1State = (data) => ({ data, pos: 0 });
|
|
968
|
+
parseLength = (state) => {
|
|
969
|
+
const first = state.data[state.pos++];
|
|
970
|
+
if (first & 128) {
|
|
971
|
+
const lengthOfLen = first & 127;
|
|
972
|
+
let length = 0;
|
|
973
|
+
for (let i = 0; i < lengthOfLen; i++) {
|
|
974
|
+
length = length << 8 | state.data[state.pos++];
|
|
975
|
+
}
|
|
976
|
+
return length;
|
|
977
|
+
}
|
|
978
|
+
return first;
|
|
979
|
+
};
|
|
980
|
+
skipElement = (state, count = 1) => {
|
|
981
|
+
if (count <= 0)
|
|
982
|
+
return;
|
|
983
|
+
state.pos++;
|
|
984
|
+
const length = parseLength(state);
|
|
985
|
+
state.pos += length;
|
|
986
|
+
if (count > 1) {
|
|
987
|
+
skipElement(state, count - 1);
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
expectTag = (state, expectedTag, errorMessage) => {
|
|
991
|
+
if (state.data[state.pos++] !== expectedTag) {
|
|
992
|
+
throw new Error(errorMessage);
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
getSubarray = (state, length) => {
|
|
996
|
+
const result = state.data.subarray(state.pos, state.pos + length);
|
|
997
|
+
state.pos += length;
|
|
998
|
+
return result;
|
|
999
|
+
};
|
|
1000
|
+
parseAlgorithmOID = (state) => {
|
|
1001
|
+
expectTag(state, 6, "Expected algorithm OID");
|
|
1002
|
+
const oidLen = parseLength(state);
|
|
1003
|
+
return getSubarray(state, oidLen);
|
|
1004
|
+
};
|
|
1005
|
+
parseECAlgorithmIdentifier = (state) => {
|
|
1006
|
+
const algOid = parseAlgorithmOID(state);
|
|
1007
|
+
if (bytesEqual(algOid, [43, 101, 110])) {
|
|
1008
|
+
return "X25519";
|
|
1009
|
+
}
|
|
1010
|
+
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
|
|
1011
|
+
throw new Error("Unsupported key algorithm");
|
|
1012
|
+
}
|
|
1013
|
+
expectTag(state, 6, "Expected curve OID");
|
|
1014
|
+
const curveOidLen = parseLength(state);
|
|
1015
|
+
const curveOid = getSubarray(state, curveOidLen);
|
|
1016
|
+
for (const { name, oid } of [
|
|
1017
|
+
{ name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
|
|
1018
|
+
{ name: "P-384", oid: [43, 129, 4, 0, 34] },
|
|
1019
|
+
{ name: "P-521", oid: [43, 129, 4, 0, 35] }
|
|
1020
|
+
]) {
|
|
1021
|
+
if (bytesEqual(curveOid, oid)) {
|
|
1022
|
+
return name;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
throw new Error("Unsupported named curve");
|
|
1026
|
+
};
|
|
1027
|
+
genericImport = async (keyFormat, keyData, alg, options) => {
|
|
1028
|
+
let algorithm;
|
|
1029
|
+
let keyUsages;
|
|
1030
|
+
const isPublic = keyFormat === "spki";
|
|
1031
|
+
const getSigUsages = () => isPublic ? ["verify"] : ["sign"];
|
|
1032
|
+
const getEncUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
1033
|
+
switch (alg) {
|
|
1034
|
+
case "PS256":
|
|
1035
|
+
case "PS384":
|
|
1036
|
+
case "PS512":
|
|
1037
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
|
|
1038
|
+
keyUsages = getSigUsages();
|
|
1039
|
+
break;
|
|
1040
|
+
case "RS256":
|
|
1041
|
+
case "RS384":
|
|
1042
|
+
case "RS512":
|
|
1043
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
|
|
1044
|
+
keyUsages = getSigUsages();
|
|
1045
|
+
break;
|
|
1046
|
+
case "RSA-OAEP":
|
|
1047
|
+
case "RSA-OAEP-256":
|
|
1048
|
+
case "RSA-OAEP-384":
|
|
1049
|
+
case "RSA-OAEP-512":
|
|
1050
|
+
algorithm = {
|
|
1051
|
+
name: "RSA-OAEP",
|
|
1052
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
|
|
1053
|
+
};
|
|
1054
|
+
keyUsages = getEncUsages();
|
|
1055
|
+
break;
|
|
1056
|
+
case "ES256":
|
|
1057
|
+
case "ES384":
|
|
1058
|
+
case "ES512": {
|
|
1059
|
+
const curveMap = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
1060
|
+
algorithm = { name: "ECDSA", namedCurve: curveMap[alg] };
|
|
1061
|
+
keyUsages = getSigUsages();
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
case "ECDH-ES":
|
|
1065
|
+
case "ECDH-ES+A128KW":
|
|
1066
|
+
case "ECDH-ES+A192KW":
|
|
1067
|
+
case "ECDH-ES+A256KW": {
|
|
1068
|
+
try {
|
|
1069
|
+
const namedCurve = options.getNamedCurve(keyData);
|
|
1070
|
+
algorithm = namedCurve === "X25519" ? { name: "X25519" } : { name: "ECDH", namedCurve };
|
|
1071
|
+
} catch (cause) {
|
|
1072
|
+
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
1073
|
+
}
|
|
1074
|
+
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
1075
|
+
break;
|
|
1076
|
+
}
|
|
1077
|
+
case "Ed25519":
|
|
1078
|
+
case "EdDSA":
|
|
1079
|
+
algorithm = { name: "Ed25519" };
|
|
1080
|
+
keyUsages = getSigUsages();
|
|
1081
|
+
break;
|
|
1082
|
+
case "ML-DSA-44":
|
|
1083
|
+
case "ML-DSA-65":
|
|
1084
|
+
case "ML-DSA-87":
|
|
1085
|
+
algorithm = { name: alg };
|
|
1086
|
+
keyUsages = getSigUsages();
|
|
1087
|
+
break;
|
|
1088
|
+
default:
|
|
1089
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
1090
|
+
}
|
|
1091
|
+
return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? (isPublic ? true : false), keyUsages);
|
|
1092
|
+
};
|
|
1093
|
+
processPEMData = (pem, pattern) => {
|
|
1094
|
+
return decodeBase64(pem.replace(pattern, ""));
|
|
1095
|
+
};
|
|
1096
|
+
fromPKCS8 = (pem, alg, options) => {
|
|
1097
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
1098
|
+
let opts = options;
|
|
1099
|
+
if (alg?.startsWith?.("ECDH-ES")) {
|
|
1100
|
+
opts ||= {};
|
|
1101
|
+
opts.getNamedCurve = (keyData2) => {
|
|
1102
|
+
const state = createASN1State(keyData2);
|
|
1103
|
+
parsePKCS8Header(state);
|
|
1104
|
+
return parseECAlgorithmIdentifier(state);
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
return genericImport("pkcs8", keyData, alg, opts);
|
|
1108
|
+
};
|
|
1109
|
+
fromSPKI = (pem, alg, options) => {
|
|
1110
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
|
|
1111
|
+
let opts = options;
|
|
1112
|
+
if (alg?.startsWith?.("ECDH-ES")) {
|
|
1113
|
+
opts ||= {};
|
|
1114
|
+
opts.getNamedCurve = (keyData2) => {
|
|
1115
|
+
const state = createASN1State(keyData2);
|
|
1116
|
+
parseSPKIHeader(state);
|
|
1117
|
+
return parseECAlgorithmIdentifier(state);
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
return genericImport("spki", keyData, alg, opts);
|
|
1121
|
+
};
|
|
1122
|
+
fromX509 = (pem, alg, options) => {
|
|
1123
|
+
let spki;
|
|
1124
|
+
try {
|
|
1125
|
+
spki = extractX509SPKI(pem);
|
|
1126
|
+
} catch (cause) {
|
|
1127
|
+
throw new TypeError("Failed to parse the X.509 certificate", { cause });
|
|
1128
|
+
}
|
|
1129
|
+
return fromSPKI(formatPEM(encodeBase64(spki), "PUBLIC KEY"), alg, options);
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
|
|
1134
|
+
// ../../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
1135
|
+
function subtleMapping(jwk) {
|
|
1136
|
+
let algorithm;
|
|
1137
|
+
let keyUsages;
|
|
1138
|
+
switch (jwk.kty) {
|
|
1139
|
+
case "AKP": {
|
|
1140
|
+
switch (jwk.alg) {
|
|
1141
|
+
case "ML-DSA-44":
|
|
1142
|
+
case "ML-DSA-65":
|
|
1143
|
+
case "ML-DSA-87":
|
|
1144
|
+
algorithm = { name: jwk.alg };
|
|
1145
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
1146
|
+
break;
|
|
1147
|
+
default:
|
|
1148
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1149
|
+
}
|
|
1150
|
+
break;
|
|
1151
|
+
}
|
|
1152
|
+
case "RSA": {
|
|
1153
|
+
switch (jwk.alg) {
|
|
1154
|
+
case "PS256":
|
|
1155
|
+
case "PS384":
|
|
1156
|
+
case "PS512":
|
|
1157
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1158
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1159
|
+
break;
|
|
1160
|
+
case "RS256":
|
|
1161
|
+
case "RS384":
|
|
1162
|
+
case "RS512":
|
|
1163
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1164
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1165
|
+
break;
|
|
1166
|
+
case "RSA-OAEP":
|
|
1167
|
+
case "RSA-OAEP-256":
|
|
1168
|
+
case "RSA-OAEP-384":
|
|
1169
|
+
case "RSA-OAEP-512":
|
|
1170
|
+
algorithm = {
|
|
1171
|
+
name: "RSA-OAEP",
|
|
1172
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
1173
|
+
};
|
|
1174
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
1175
|
+
break;
|
|
1176
|
+
default:
|
|
1177
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1178
|
+
}
|
|
1179
|
+
break;
|
|
1180
|
+
}
|
|
1181
|
+
case "EC": {
|
|
1182
|
+
switch (jwk.alg) {
|
|
1183
|
+
case "ES256":
|
|
1184
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
1185
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1186
|
+
break;
|
|
1187
|
+
case "ES384":
|
|
1188
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
1189
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1190
|
+
break;
|
|
1191
|
+
case "ES512":
|
|
1192
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
1193
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1194
|
+
break;
|
|
1195
|
+
case "ECDH-ES":
|
|
1196
|
+
case "ECDH-ES+A128KW":
|
|
1197
|
+
case "ECDH-ES+A192KW":
|
|
1198
|
+
case "ECDH-ES+A256KW":
|
|
1199
|
+
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
1200
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1201
|
+
break;
|
|
1202
|
+
default:
|
|
1203
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1204
|
+
}
|
|
1205
|
+
break;
|
|
1206
|
+
}
|
|
1207
|
+
case "OKP": {
|
|
1208
|
+
switch (jwk.alg) {
|
|
1209
|
+
case "Ed25519":
|
|
1210
|
+
case "EdDSA":
|
|
1211
|
+
algorithm = { name: "Ed25519" };
|
|
1212
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1213
|
+
break;
|
|
1214
|
+
case "ECDH-ES":
|
|
1215
|
+
case "ECDH-ES+A128KW":
|
|
1216
|
+
case "ECDH-ES+A192KW":
|
|
1217
|
+
case "ECDH-ES+A256KW":
|
|
1218
|
+
algorithm = { name: jwk.crv };
|
|
1219
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1220
|
+
break;
|
|
1221
|
+
default:
|
|
1222
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1223
|
+
}
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
default:
|
|
1227
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
1228
|
+
}
|
|
1229
|
+
return { algorithm, keyUsages };
|
|
1230
|
+
}
|
|
1231
|
+
async function jwkToKey(jwk) {
|
|
1232
|
+
if (!jwk.alg) {
|
|
1233
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
1234
|
+
}
|
|
1235
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
1236
|
+
const keyData = { ...jwk };
|
|
1237
|
+
if (keyData.kty !== "AKP") {
|
|
1238
|
+
delete keyData.alg;
|
|
1239
|
+
}
|
|
1240
|
+
delete keyData.use;
|
|
1241
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
1242
|
+
}
|
|
1243
|
+
var init_jwk_to_key = __esm({
|
|
1244
|
+
"../../../node_modules/jose/dist/webapi/lib/jwk_to_key.js"() {
|
|
1245
|
+
init_errors();
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
// ../../../node_modules/jose/dist/webapi/key/import.js
|
|
1250
|
+
async function importSPKI(spki, alg, options) {
|
|
1251
|
+
if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) {
|
|
1252
|
+
throw new TypeError('"spki" must be SPKI formatted string');
|
|
1253
|
+
}
|
|
1254
|
+
return fromSPKI(spki, alg, options);
|
|
1255
|
+
}
|
|
1256
|
+
async function importX509(x509, alg, options) {
|
|
1257
|
+
if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) {
|
|
1258
|
+
throw new TypeError('"x509" must be X.509 formatted string');
|
|
1259
|
+
}
|
|
1260
|
+
return fromX509(x509, alg, options);
|
|
1261
|
+
}
|
|
1262
|
+
async function importPKCS8(pkcs8, alg, options) {
|
|
1263
|
+
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
1264
|
+
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
1265
|
+
}
|
|
1266
|
+
return fromPKCS8(pkcs8, alg, options);
|
|
1267
|
+
}
|
|
1268
|
+
async function importJWK(jwk, alg, options) {
|
|
1269
|
+
if (!isObject(jwk)) {
|
|
1270
|
+
throw new TypeError("JWK must be an object");
|
|
1271
|
+
}
|
|
1272
|
+
let ext;
|
|
1273
|
+
alg ??= jwk.alg;
|
|
1274
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
1275
|
+
switch (jwk.kty) {
|
|
1276
|
+
case "oct":
|
|
1277
|
+
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
1278
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
1279
|
+
}
|
|
1280
|
+
return decode(jwk.k);
|
|
1281
|
+
case "RSA":
|
|
1282
|
+
if ("oth" in jwk && jwk.oth !== void 0) {
|
|
1283
|
+
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
1284
|
+
}
|
|
1285
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
1286
|
+
case "AKP": {
|
|
1287
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
1288
|
+
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
1289
|
+
}
|
|
1290
|
+
if (alg !== void 0 && alg !== jwk.alg) {
|
|
1291
|
+
throw new TypeError("JWK alg and alg option value mismatch");
|
|
1292
|
+
}
|
|
1293
|
+
return jwkToKey({ ...jwk, ext });
|
|
1294
|
+
}
|
|
1295
|
+
case "EC":
|
|
1296
|
+
case "OKP":
|
|
1297
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
1298
|
+
default:
|
|
1299
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
var init_import = __esm({
|
|
1303
|
+
"../../../node_modules/jose/dist/webapi/key/import.js"() {
|
|
1304
|
+
init_base64url();
|
|
1305
|
+
init_asn1();
|
|
1306
|
+
init_jwk_to_key();
|
|
1307
|
+
init_errors();
|
|
1308
|
+
init_is_object();
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1312
|
+
// ../../../node_modules/jose/dist/webapi/lib/encrypt.js
|
|
1313
|
+
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
1314
|
+
if (!(cek instanceof Uint8Array)) {
|
|
1315
|
+
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
1316
|
+
}
|
|
1317
|
+
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
1318
|
+
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["encrypt"]);
|
|
1319
|
+
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
1320
|
+
hash: `SHA-${keySize << 1}`,
|
|
1321
|
+
name: "HMAC"
|
|
1322
|
+
}, false, ["sign"]);
|
|
1323
|
+
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
1324
|
+
iv,
|
|
1325
|
+
name: "AES-CBC"
|
|
1326
|
+
}, encKey, plaintext));
|
|
1327
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
1328
|
+
const tag2 = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
1329
|
+
return { ciphertext, tag: tag2, iv };
|
|
1330
|
+
}
|
|
1331
|
+
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
1332
|
+
let encKey;
|
|
1333
|
+
if (cek instanceof Uint8Array) {
|
|
1334
|
+
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
|
|
1335
|
+
} else {
|
|
1336
|
+
checkEncCryptoKey(cek, enc, "encrypt");
|
|
1337
|
+
encKey = cek;
|
|
1338
|
+
}
|
|
1339
|
+
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
1340
|
+
additionalData: aad,
|
|
1341
|
+
iv,
|
|
1342
|
+
name: "AES-GCM",
|
|
1343
|
+
tagLength: 128
|
|
1344
|
+
}, encKey, plaintext));
|
|
1345
|
+
const tag2 = encrypted.slice(-16);
|
|
1346
|
+
const ciphertext = encrypted.slice(0, -16);
|
|
1347
|
+
return { ciphertext, tag: tag2, iv };
|
|
1348
|
+
}
|
|
1349
|
+
async function encrypt2(enc, plaintext, cek, iv, aad) {
|
|
1350
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
1351
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
1352
|
+
}
|
|
1353
|
+
if (iv) {
|
|
1354
|
+
checkIvLength(enc, iv);
|
|
1355
|
+
} else {
|
|
1356
|
+
iv = generateIv(enc);
|
|
1357
|
+
}
|
|
1358
|
+
switch (enc) {
|
|
1359
|
+
case "A128CBC-HS256":
|
|
1360
|
+
case "A192CBC-HS384":
|
|
1361
|
+
case "A256CBC-HS512":
|
|
1362
|
+
if (cek instanceof Uint8Array) {
|
|
1363
|
+
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
1364
|
+
}
|
|
1365
|
+
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
1366
|
+
case "A128GCM":
|
|
1367
|
+
case "A192GCM":
|
|
1368
|
+
case "A256GCM":
|
|
1369
|
+
if (cek instanceof Uint8Array) {
|
|
1370
|
+
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
1371
|
+
}
|
|
1372
|
+
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
1373
|
+
default:
|
|
1374
|
+
throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
var init_encrypt = __esm({
|
|
1378
|
+
"../../../node_modules/jose/dist/webapi/lib/encrypt.js"() {
|
|
1379
|
+
init_buffer_utils();
|
|
1380
|
+
init_check_iv_length();
|
|
1381
|
+
init_check_cek_length();
|
|
1382
|
+
init_crypto_key();
|
|
1383
|
+
init_invalid_key_input();
|
|
1384
|
+
init_iv();
|
|
1385
|
+
init_errors();
|
|
1386
|
+
init_is_key_like();
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
|
|
1390
|
+
// ../../../node_modules/jose/dist/webapi/lib/aesgcmkw.js
|
|
1391
|
+
async function wrap3(alg, key, cek, iv) {
|
|
1392
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
1393
|
+
const wrapped = await encrypt2(jweAlgorithm, cek, key, iv, new Uint8Array());
|
|
1394
|
+
return {
|
|
1395
|
+
encryptedKey: wrapped.ciphertext,
|
|
1396
|
+
iv: encode2(wrapped.iv),
|
|
1397
|
+
tag: encode2(wrapped.tag)
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
async function unwrap3(alg, key, encryptedKey, iv, tag2) {
|
|
1401
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
1402
|
+
return decrypt(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array());
|
|
1403
|
+
}
|
|
1404
|
+
var init_aesgcmkw = __esm({
|
|
1405
|
+
"../../../node_modules/jose/dist/webapi/lib/aesgcmkw.js"() {
|
|
1406
|
+
init_encrypt();
|
|
1407
|
+
init_decrypt();
|
|
1408
|
+
init_base64url();
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
|
|
1412
|
+
// ../../../node_modules/jose/dist/webapi/lib/decrypt_key_management.js
|
|
1413
|
+
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
1414
|
+
switch (alg) {
|
|
1415
|
+
case "dir": {
|
|
1416
|
+
if (encryptedKey !== void 0)
|
|
1417
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
1418
|
+
return key;
|
|
1419
|
+
}
|
|
1420
|
+
case "ECDH-ES":
|
|
1421
|
+
if (encryptedKey !== void 0)
|
|
1422
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
1423
|
+
case "ECDH-ES+A128KW":
|
|
1424
|
+
case "ECDH-ES+A192KW":
|
|
1425
|
+
case "ECDH-ES+A256KW": {
|
|
1426
|
+
if (!isObject(joseHeader.epk))
|
|
1427
|
+
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
1428
|
+
assertCryptoKey(key);
|
|
1429
|
+
if (!allowed(key))
|
|
1430
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
1431
|
+
const epk = await importJWK(joseHeader.epk, alg);
|
|
1432
|
+
assertCryptoKey(epk);
|
|
1433
|
+
let partyUInfo;
|
|
1434
|
+
let partyVInfo;
|
|
1435
|
+
if (joseHeader.apu !== void 0) {
|
|
1436
|
+
if (typeof joseHeader.apu !== "string")
|
|
1437
|
+
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
1438
|
+
try {
|
|
1439
|
+
partyUInfo = decode(joseHeader.apu);
|
|
1440
|
+
} catch {
|
|
1441
|
+
throw new JWEInvalid("Failed to base64url decode the apu");
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
if (joseHeader.apv !== void 0) {
|
|
1445
|
+
if (typeof joseHeader.apv !== "string")
|
|
1446
|
+
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
1447
|
+
try {
|
|
1448
|
+
partyVInfo = decode(joseHeader.apv);
|
|
1449
|
+
} catch {
|
|
1450
|
+
throw new JWEInvalid("Failed to base64url decode the apv");
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
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);
|
|
1454
|
+
if (alg === "ECDH-ES")
|
|
1455
|
+
return sharedSecret;
|
|
1456
|
+
if (encryptedKey === void 0)
|
|
1457
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1458
|
+
return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
|
|
1459
|
+
}
|
|
1460
|
+
case "RSA-OAEP":
|
|
1461
|
+
case "RSA-OAEP-256":
|
|
1462
|
+
case "RSA-OAEP-384":
|
|
1463
|
+
case "RSA-OAEP-512": {
|
|
1464
|
+
if (encryptedKey === void 0)
|
|
1465
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1466
|
+
assertCryptoKey(key);
|
|
1467
|
+
return decrypt2(alg, key, encryptedKey);
|
|
1468
|
+
}
|
|
1469
|
+
case "PBES2-HS256+A128KW":
|
|
1470
|
+
case "PBES2-HS384+A192KW":
|
|
1471
|
+
case "PBES2-HS512+A256KW": {
|
|
1472
|
+
if (encryptedKey === void 0)
|
|
1473
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1474
|
+
if (typeof joseHeader.p2c !== "number")
|
|
1475
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
1476
|
+
const p2cLimit = options?.maxPBES2Count || 1e4;
|
|
1477
|
+
if (joseHeader.p2c > p2cLimit)
|
|
1478
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
1479
|
+
if (typeof joseHeader.p2s !== "string")
|
|
1480
|
+
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
1481
|
+
let p2s;
|
|
1482
|
+
try {
|
|
1483
|
+
p2s = decode(joseHeader.p2s);
|
|
1484
|
+
} catch {
|
|
1485
|
+
throw new JWEInvalid("Failed to base64url decode the p2s");
|
|
1486
|
+
}
|
|
1487
|
+
return unwrap2(alg, key, encryptedKey, joseHeader.p2c, p2s);
|
|
1488
|
+
}
|
|
1489
|
+
case "A128KW":
|
|
1490
|
+
case "A192KW":
|
|
1491
|
+
case "A256KW": {
|
|
1492
|
+
if (encryptedKey === void 0)
|
|
1493
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1494
|
+
return unwrap(alg, key, encryptedKey);
|
|
1495
|
+
}
|
|
1496
|
+
case "A128GCMKW":
|
|
1497
|
+
case "A192GCMKW":
|
|
1498
|
+
case "A256GCMKW": {
|
|
1499
|
+
if (encryptedKey === void 0)
|
|
1500
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1501
|
+
if (typeof joseHeader.iv !== "string")
|
|
1502
|
+
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
1503
|
+
if (typeof joseHeader.tag !== "string")
|
|
1504
|
+
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
1505
|
+
let iv;
|
|
1506
|
+
try {
|
|
1507
|
+
iv = decode(joseHeader.iv);
|
|
1508
|
+
} catch {
|
|
1509
|
+
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
1510
|
+
}
|
|
1511
|
+
let tag2;
|
|
1512
|
+
try {
|
|
1513
|
+
tag2 = decode(joseHeader.tag);
|
|
1514
|
+
} catch {
|
|
1515
|
+
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
1516
|
+
}
|
|
1517
|
+
return unwrap3(alg, key, encryptedKey, iv, tag2);
|
|
1518
|
+
}
|
|
1519
|
+
default: {
|
|
1520
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
var init_decrypt_key_management = __esm({
|
|
1525
|
+
"../../../node_modules/jose/dist/webapi/lib/decrypt_key_management.js"() {
|
|
1526
|
+
init_aeskw();
|
|
1527
|
+
init_ecdhes();
|
|
1528
|
+
init_pbes2kw();
|
|
1529
|
+
init_rsaes();
|
|
1530
|
+
init_base64url();
|
|
1531
|
+
init_errors();
|
|
1532
|
+
init_cek();
|
|
1533
|
+
init_import();
|
|
1534
|
+
init_is_object();
|
|
1535
|
+
init_aesgcmkw();
|
|
1536
|
+
init_is_key_like();
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
// ../../../node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1541
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1542
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
1543
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
1544
|
+
}
|
|
1545
|
+
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
1546
|
+
return /* @__PURE__ */ new Set();
|
|
1547
|
+
}
|
|
1548
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
1549
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
1550
|
+
}
|
|
1551
|
+
let recognized;
|
|
1552
|
+
if (recognizedOption !== void 0) {
|
|
1553
|
+
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1554
|
+
} else {
|
|
1555
|
+
recognized = recognizedDefault;
|
|
1556
|
+
}
|
|
1557
|
+
for (const parameter of protectedHeader.crit) {
|
|
1558
|
+
if (!recognized.has(parameter)) {
|
|
1559
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1560
|
+
}
|
|
1561
|
+
if (joseHeader[parameter] === void 0) {
|
|
1562
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1563
|
+
}
|
|
1564
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
1565
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
return new Set(protectedHeader.crit);
|
|
1569
|
+
}
|
|
1570
|
+
var init_validate_crit = __esm({
|
|
1571
|
+
"../../../node_modules/jose/dist/webapi/lib/validate_crit.js"() {
|
|
1572
|
+
init_errors();
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
|
|
1576
|
+
// ../../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
1577
|
+
function validateAlgorithms(option, algorithms) {
|
|
1578
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
1579
|
+
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
1580
|
+
}
|
|
1581
|
+
if (!algorithms) {
|
|
1582
|
+
return void 0;
|
|
1583
|
+
}
|
|
1584
|
+
return new Set(algorithms);
|
|
1585
|
+
}
|
|
1586
|
+
var init_validate_algorithms = __esm({
|
|
1587
|
+
"../../../node_modules/jose/dist/webapi/lib/validate_algorithms.js"() {
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1591
|
+
// ../../../node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
1592
|
+
var isJWK, isPrivateJWK, isPublicJWK, isSecretJWK;
|
|
1593
|
+
var init_is_jwk = __esm({
|
|
1594
|
+
"../../../node_modules/jose/dist/webapi/lib/is_jwk.js"() {
|
|
1595
|
+
init_is_object();
|
|
1596
|
+
isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
1597
|
+
isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
1598
|
+
isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
1599
|
+
isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
|
|
1603
|
+
// ../../../node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
1604
|
+
async function normalizeKey(key, alg) {
|
|
1605
|
+
if (key instanceof Uint8Array) {
|
|
1606
|
+
return key;
|
|
1607
|
+
}
|
|
1608
|
+
if (isCryptoKey(key)) {
|
|
1609
|
+
return key;
|
|
1610
|
+
}
|
|
1611
|
+
if (isKeyObject(key)) {
|
|
1612
|
+
if (key.type === "secret") {
|
|
1613
|
+
return key.export();
|
|
1614
|
+
}
|
|
1615
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
1616
|
+
try {
|
|
1617
|
+
return handleKeyObject(key, alg);
|
|
1618
|
+
} catch (err) {
|
|
1619
|
+
if (err instanceof TypeError) {
|
|
1620
|
+
throw err;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
let jwk = key.export({ format: "jwk" });
|
|
1625
|
+
return handleJWK(key, jwk, alg);
|
|
1626
|
+
}
|
|
1627
|
+
if (isJWK(key)) {
|
|
1628
|
+
if (key.k) {
|
|
1629
|
+
return decode(key.k);
|
|
1630
|
+
}
|
|
1631
|
+
return handleJWK(key, key, alg, true);
|
|
1632
|
+
}
|
|
1633
|
+
throw new Error("unreachable");
|
|
1634
|
+
}
|
|
1635
|
+
var cache, handleJWK, handleKeyObject;
|
|
1636
|
+
var init_normalize_key = __esm({
|
|
1637
|
+
"../../../node_modules/jose/dist/webapi/lib/normalize_key.js"() {
|
|
1638
|
+
init_is_jwk();
|
|
1639
|
+
init_base64url();
|
|
1640
|
+
init_jwk_to_key();
|
|
1641
|
+
init_is_key_like();
|
|
1642
|
+
handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
1643
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1644
|
+
let cached = cache.get(key);
|
|
1645
|
+
if (cached?.[alg]) {
|
|
1646
|
+
return cached[alg];
|
|
1647
|
+
}
|
|
1648
|
+
const cryptoKey = await jwkToKey({ ...jwk, alg });
|
|
1649
|
+
if (freeze)
|
|
1650
|
+
Object.freeze(key);
|
|
1651
|
+
if (!cached) {
|
|
1652
|
+
cache.set(key, { [alg]: cryptoKey });
|
|
1653
|
+
} else {
|
|
1654
|
+
cached[alg] = cryptoKey;
|
|
1655
|
+
}
|
|
1656
|
+
return cryptoKey;
|
|
1657
|
+
};
|
|
1658
|
+
handleKeyObject = (keyObject, alg) => {
|
|
1659
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1660
|
+
let cached = cache.get(keyObject);
|
|
1661
|
+
if (cached?.[alg]) {
|
|
1662
|
+
return cached[alg];
|
|
1663
|
+
}
|
|
1664
|
+
const isPublic = keyObject.type === "public";
|
|
1665
|
+
const extractable = isPublic ? true : false;
|
|
1666
|
+
let cryptoKey;
|
|
1667
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
1668
|
+
switch (alg) {
|
|
1669
|
+
case "ECDH-ES":
|
|
1670
|
+
case "ECDH-ES+A128KW":
|
|
1671
|
+
case "ECDH-ES+A192KW":
|
|
1672
|
+
case "ECDH-ES+A256KW":
|
|
1673
|
+
break;
|
|
1674
|
+
default:
|
|
1675
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1676
|
+
}
|
|
1677
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1678
|
+
}
|
|
1679
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
1680
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
1681
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1682
|
+
}
|
|
1683
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1684
|
+
isPublic ? "verify" : "sign"
|
|
1685
|
+
]);
|
|
1686
|
+
}
|
|
1687
|
+
switch (keyObject.asymmetricKeyType) {
|
|
1688
|
+
case "ml-dsa-44":
|
|
1689
|
+
case "ml-dsa-65":
|
|
1690
|
+
case "ml-dsa-87": {
|
|
1691
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
1692
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1693
|
+
}
|
|
1694
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1695
|
+
isPublic ? "verify" : "sign"
|
|
1696
|
+
]);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
1700
|
+
let hash;
|
|
1701
|
+
switch (alg) {
|
|
1702
|
+
case "RSA-OAEP":
|
|
1703
|
+
hash = "SHA-1";
|
|
1704
|
+
break;
|
|
1705
|
+
case "RS256":
|
|
1706
|
+
case "PS256":
|
|
1707
|
+
case "RSA-OAEP-256":
|
|
1708
|
+
hash = "SHA-256";
|
|
1709
|
+
break;
|
|
1710
|
+
case "RS384":
|
|
1711
|
+
case "PS384":
|
|
1712
|
+
case "RSA-OAEP-384":
|
|
1713
|
+
hash = "SHA-384";
|
|
1714
|
+
break;
|
|
1715
|
+
case "RS512":
|
|
1716
|
+
case "PS512":
|
|
1717
|
+
case "RSA-OAEP-512":
|
|
1718
|
+
hash = "SHA-512";
|
|
1719
|
+
break;
|
|
1720
|
+
default:
|
|
1721
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1722
|
+
}
|
|
1723
|
+
if (alg.startsWith("RSA-OAEP")) {
|
|
1724
|
+
return keyObject.toCryptoKey({
|
|
1725
|
+
name: "RSA-OAEP",
|
|
1726
|
+
hash
|
|
1727
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
1728
|
+
}
|
|
1729
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1730
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
1731
|
+
hash
|
|
1732
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1733
|
+
}
|
|
1734
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
1735
|
+
const nist = /* @__PURE__ */ new Map([
|
|
1736
|
+
["prime256v1", "P-256"],
|
|
1737
|
+
["secp384r1", "P-384"],
|
|
1738
|
+
["secp521r1", "P-521"]
|
|
1739
|
+
]);
|
|
1740
|
+
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
1741
|
+
if (!namedCurve) {
|
|
1742
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1743
|
+
}
|
|
1744
|
+
if (alg === "ES256" && namedCurve === "P-256") {
|
|
1745
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1746
|
+
name: "ECDSA",
|
|
1747
|
+
namedCurve
|
|
1748
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1749
|
+
}
|
|
1750
|
+
if (alg === "ES384" && namedCurve === "P-384") {
|
|
1751
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1752
|
+
name: "ECDSA",
|
|
1753
|
+
namedCurve
|
|
1754
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1755
|
+
}
|
|
1756
|
+
if (alg === "ES512" && namedCurve === "P-521") {
|
|
1757
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1758
|
+
name: "ECDSA",
|
|
1759
|
+
namedCurve
|
|
1760
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1761
|
+
}
|
|
1762
|
+
if (alg.startsWith("ECDH-ES")) {
|
|
1763
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
1764
|
+
name: "ECDH",
|
|
1765
|
+
namedCurve
|
|
1766
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
if (!cryptoKey) {
|
|
1770
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1771
|
+
}
|
|
1772
|
+
if (!cached) {
|
|
1773
|
+
cache.set(keyObject, { [alg]: cryptoKey });
|
|
1774
|
+
} else {
|
|
1775
|
+
cached[alg] = cryptoKey;
|
|
1776
|
+
}
|
|
1777
|
+
return cryptoKey;
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
|
|
1782
|
+
// ../../../node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
1783
|
+
function checkKeyType(alg, key, usage) {
|
|
1784
|
+
switch (alg.substring(0, 2)) {
|
|
1785
|
+
case "A1":
|
|
1786
|
+
case "A2":
|
|
1787
|
+
case "di":
|
|
1788
|
+
case "HS":
|
|
1789
|
+
case "PB":
|
|
1790
|
+
symmetricTypeCheck(alg, key, usage);
|
|
1791
|
+
break;
|
|
1792
|
+
default:
|
|
1793
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
var tag, jwkMatchesOp, symmetricTypeCheck, asymmetricTypeCheck;
|
|
1797
|
+
var init_check_key_type = __esm({
|
|
1798
|
+
"../../../node_modules/jose/dist/webapi/lib/check_key_type.js"() {
|
|
1799
|
+
init_invalid_key_input();
|
|
1800
|
+
init_is_key_like();
|
|
1801
|
+
init_is_jwk();
|
|
1802
|
+
tag = (key) => key?.[Symbol.toStringTag];
|
|
1803
|
+
jwkMatchesOp = (alg, key, usage) => {
|
|
1804
|
+
if (key.use !== void 0) {
|
|
1805
|
+
let expected;
|
|
1806
|
+
switch (usage) {
|
|
1807
|
+
case "sign":
|
|
1808
|
+
case "verify":
|
|
1809
|
+
expected = "sig";
|
|
1810
|
+
break;
|
|
1811
|
+
case "encrypt":
|
|
1812
|
+
case "decrypt":
|
|
1813
|
+
expected = "enc";
|
|
1814
|
+
break;
|
|
1815
|
+
}
|
|
1816
|
+
if (key.use !== expected) {
|
|
1817
|
+
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
if (key.alg !== void 0 && key.alg !== alg) {
|
|
1821
|
+
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
1822
|
+
}
|
|
1823
|
+
if (Array.isArray(key.key_ops)) {
|
|
1824
|
+
let expectedKeyOp;
|
|
1825
|
+
switch (true) {
|
|
1826
|
+
case (usage === "sign" || usage === "verify"):
|
|
1827
|
+
case alg === "dir":
|
|
1828
|
+
case alg.includes("CBC-HS"):
|
|
1829
|
+
expectedKeyOp = usage;
|
|
1830
|
+
break;
|
|
1831
|
+
case alg.startsWith("PBES2"):
|
|
1832
|
+
expectedKeyOp = "deriveBits";
|
|
1833
|
+
break;
|
|
1834
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
1835
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
1836
|
+
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
1837
|
+
} else {
|
|
1838
|
+
expectedKeyOp = usage;
|
|
1839
|
+
}
|
|
1840
|
+
break;
|
|
1841
|
+
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
1842
|
+
expectedKeyOp = "wrapKey";
|
|
1843
|
+
break;
|
|
1844
|
+
case usage === "decrypt":
|
|
1845
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
1846
|
+
break;
|
|
1847
|
+
}
|
|
1848
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
1849
|
+
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
return true;
|
|
1853
|
+
};
|
|
1854
|
+
symmetricTypeCheck = (alg, key, usage) => {
|
|
1855
|
+
if (key instanceof Uint8Array)
|
|
1856
|
+
return;
|
|
1857
|
+
if (isJWK(key)) {
|
|
1858
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1859
|
+
return;
|
|
1860
|
+
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`);
|
|
1861
|
+
}
|
|
1862
|
+
if (!isKeyLike(key)) {
|
|
1863
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
1864
|
+
}
|
|
1865
|
+
if (key.type !== "secret") {
|
|
1866
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
asymmetricTypeCheck = (alg, key, usage) => {
|
|
1870
|
+
if (isJWK(key)) {
|
|
1871
|
+
switch (usage) {
|
|
1872
|
+
case "decrypt":
|
|
1873
|
+
case "sign":
|
|
1874
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1875
|
+
return;
|
|
1876
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
1877
|
+
case "encrypt":
|
|
1878
|
+
case "verify":
|
|
1879
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1880
|
+
return;
|
|
1881
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
if (!isKeyLike(key)) {
|
|
1885
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1886
|
+
}
|
|
1887
|
+
if (key.type === "secret") {
|
|
1888
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
1889
|
+
}
|
|
1890
|
+
if (key.type === "public") {
|
|
1891
|
+
switch (usage) {
|
|
1892
|
+
case "sign":
|
|
1893
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
1894
|
+
case "decrypt":
|
|
1895
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
if (key.type === "private") {
|
|
1899
|
+
switch (usage) {
|
|
1900
|
+
case "verify":
|
|
1901
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
1902
|
+
case "encrypt":
|
|
1903
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1909
|
+
|
|
1910
|
+
// ../../../node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
1911
|
+
async function flattenedDecrypt(jwe, key, options) {
|
|
1912
|
+
if (!isObject(jwe)) {
|
|
1913
|
+
throw new JWEInvalid("Flattened JWE must be an object");
|
|
1914
|
+
}
|
|
1915
|
+
if (jwe.protected === void 0 && jwe.header === void 0 && jwe.unprotected === void 0) {
|
|
1916
|
+
throw new JWEInvalid("JOSE Header missing");
|
|
1917
|
+
}
|
|
1918
|
+
if (jwe.iv !== void 0 && typeof jwe.iv !== "string") {
|
|
1919
|
+
throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
1920
|
+
}
|
|
1921
|
+
if (typeof jwe.ciphertext !== "string") {
|
|
1922
|
+
throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
|
|
1923
|
+
}
|
|
1924
|
+
if (jwe.tag !== void 0 && typeof jwe.tag !== "string") {
|
|
1925
|
+
throw new JWEInvalid("JWE Authentication Tag incorrect type");
|
|
1926
|
+
}
|
|
1927
|
+
if (jwe.protected !== void 0 && typeof jwe.protected !== "string") {
|
|
1928
|
+
throw new JWEInvalid("JWE Protected Header incorrect type");
|
|
1929
|
+
}
|
|
1930
|
+
if (jwe.encrypted_key !== void 0 && typeof jwe.encrypted_key !== "string") {
|
|
1931
|
+
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
1932
|
+
}
|
|
1933
|
+
if (jwe.aad !== void 0 && typeof jwe.aad !== "string") {
|
|
1934
|
+
throw new JWEInvalid("JWE AAD incorrect type");
|
|
1935
|
+
}
|
|
1936
|
+
if (jwe.header !== void 0 && !isObject(jwe.header)) {
|
|
1937
|
+
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
1938
|
+
}
|
|
1939
|
+
if (jwe.unprotected !== void 0 && !isObject(jwe.unprotected)) {
|
|
1940
|
+
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
1941
|
+
}
|
|
1942
|
+
let parsedProt;
|
|
1943
|
+
if (jwe.protected) {
|
|
1944
|
+
try {
|
|
1945
|
+
const protectedHeader2 = decode(jwe.protected);
|
|
1946
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader2));
|
|
1947
|
+
} catch {
|
|
1948
|
+
throw new JWEInvalid("JWE Protected Header is invalid");
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
if (!isDisjoint(parsedProt, jwe.header, jwe.unprotected)) {
|
|
1952
|
+
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
1953
|
+
}
|
|
1954
|
+
const joseHeader = {
|
|
1955
|
+
...parsedProt,
|
|
1956
|
+
...jwe.header,
|
|
1957
|
+
...jwe.unprotected
|
|
1958
|
+
};
|
|
1959
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, parsedProt, joseHeader);
|
|
1960
|
+
if (joseHeader.zip !== void 0) {
|
|
1961
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
1962
|
+
}
|
|
1963
|
+
const { alg, enc } = joseHeader;
|
|
1964
|
+
if (typeof alg !== "string" || !alg) {
|
|
1965
|
+
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
1966
|
+
}
|
|
1967
|
+
if (typeof enc !== "string" || !enc) {
|
|
1968
|
+
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
1969
|
+
}
|
|
1970
|
+
const keyManagementAlgorithms = options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms);
|
|
1971
|
+
const contentEncryptionAlgorithms = options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms);
|
|
1972
|
+
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
|
|
1973
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
1974
|
+
}
|
|
1975
|
+
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
|
|
1976
|
+
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
1977
|
+
}
|
|
1978
|
+
let encryptedKey;
|
|
1979
|
+
if (jwe.encrypted_key !== void 0) {
|
|
1980
|
+
try {
|
|
1981
|
+
encryptedKey = decode(jwe.encrypted_key);
|
|
1982
|
+
} catch {
|
|
1983
|
+
throw new JWEInvalid("Failed to base64url decode the encrypted_key");
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
let resolvedKey = false;
|
|
1987
|
+
if (typeof key === "function") {
|
|
1988
|
+
key = await key(parsedProt, jwe);
|
|
1989
|
+
resolvedKey = true;
|
|
1990
|
+
}
|
|
1991
|
+
checkKeyType(alg === "dir" ? enc : alg, key, "decrypt");
|
|
1992
|
+
const k = await normalizeKey(key, alg);
|
|
1993
|
+
let cek;
|
|
1994
|
+
try {
|
|
1995
|
+
cek = await decryptKeyManagement(alg, k, encryptedKey, joseHeader, options);
|
|
1996
|
+
} catch (err) {
|
|
1997
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
1998
|
+
throw err;
|
|
1999
|
+
}
|
|
2000
|
+
cek = generateCek(enc);
|
|
2001
|
+
}
|
|
2002
|
+
let iv;
|
|
2003
|
+
let tag2;
|
|
2004
|
+
if (jwe.iv !== void 0) {
|
|
2005
|
+
try {
|
|
2006
|
+
iv = decode(jwe.iv);
|
|
2007
|
+
} catch {
|
|
2008
|
+
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if (jwe.tag !== void 0) {
|
|
2012
|
+
try {
|
|
2013
|
+
tag2 = decode(jwe.tag);
|
|
2014
|
+
} catch {
|
|
2015
|
+
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
const protectedHeader = jwe.protected !== void 0 ? encode(jwe.protected) : new Uint8Array();
|
|
2019
|
+
let additionalData;
|
|
2020
|
+
if (jwe.aad !== void 0) {
|
|
2021
|
+
additionalData = concat(protectedHeader, encode("."), encode(jwe.aad));
|
|
2022
|
+
} else {
|
|
2023
|
+
additionalData = protectedHeader;
|
|
2024
|
+
}
|
|
2025
|
+
let ciphertext;
|
|
2026
|
+
try {
|
|
2027
|
+
ciphertext = decode(jwe.ciphertext);
|
|
2028
|
+
} catch {
|
|
2029
|
+
throw new JWEInvalid("Failed to base64url decode the ciphertext");
|
|
2030
|
+
}
|
|
2031
|
+
const plaintext = await decrypt(enc, cek, ciphertext, iv, tag2, additionalData);
|
|
2032
|
+
const result = { plaintext };
|
|
2033
|
+
if (jwe.protected !== void 0) {
|
|
2034
|
+
result.protectedHeader = parsedProt;
|
|
2035
|
+
}
|
|
2036
|
+
if (jwe.aad !== void 0) {
|
|
2037
|
+
try {
|
|
2038
|
+
result.additionalAuthenticatedData = decode(jwe.aad);
|
|
2039
|
+
} catch {
|
|
2040
|
+
throw new JWEInvalid("Failed to base64url decode the aad");
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
if (jwe.unprotected !== void 0) {
|
|
2044
|
+
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
2045
|
+
}
|
|
2046
|
+
if (jwe.header !== void 0) {
|
|
2047
|
+
result.unprotectedHeader = jwe.header;
|
|
2048
|
+
}
|
|
2049
|
+
if (resolvedKey) {
|
|
2050
|
+
return { ...result, key: k };
|
|
2051
|
+
}
|
|
2052
|
+
return result;
|
|
2053
|
+
}
|
|
2054
|
+
var init_decrypt2 = __esm({
|
|
2055
|
+
"../../../node_modules/jose/dist/webapi/jwe/flattened/decrypt.js"() {
|
|
2056
|
+
init_base64url();
|
|
2057
|
+
init_decrypt();
|
|
2058
|
+
init_errors();
|
|
2059
|
+
init_is_disjoint();
|
|
2060
|
+
init_is_object();
|
|
2061
|
+
init_decrypt_key_management();
|
|
2062
|
+
init_buffer_utils();
|
|
2063
|
+
init_cek();
|
|
2064
|
+
init_validate_crit();
|
|
2065
|
+
init_validate_algorithms();
|
|
2066
|
+
init_normalize_key();
|
|
2067
|
+
init_check_key_type();
|
|
2068
|
+
}
|
|
2069
|
+
});
|
|
2070
|
+
|
|
2071
|
+
// ../../../node_modules/jose/dist/webapi/jwe/compact/decrypt.js
|
|
2072
|
+
async function compactDecrypt(jwe, key, options) {
|
|
2073
|
+
if (jwe instanceof Uint8Array) {
|
|
2074
|
+
jwe = decoder.decode(jwe);
|
|
2075
|
+
}
|
|
2076
|
+
if (typeof jwe !== "string") {
|
|
2077
|
+
throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
|
|
2078
|
+
}
|
|
2079
|
+
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
|
|
2080
|
+
if (length !== 5) {
|
|
2081
|
+
throw new JWEInvalid("Invalid Compact JWE");
|
|
2082
|
+
}
|
|
2083
|
+
const decrypted = await flattenedDecrypt({
|
|
2084
|
+
ciphertext,
|
|
2085
|
+
iv: iv || void 0,
|
|
2086
|
+
protected: protectedHeader,
|
|
2087
|
+
tag: tag2 || void 0,
|
|
2088
|
+
encrypted_key: encryptedKey || void 0
|
|
2089
|
+
}, key, options);
|
|
2090
|
+
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
|
2091
|
+
if (typeof key === "function") {
|
|
2092
|
+
return { ...result, key: decrypted.key };
|
|
2093
|
+
}
|
|
2094
|
+
return result;
|
|
2095
|
+
}
|
|
2096
|
+
var init_decrypt3 = __esm({
|
|
2097
|
+
"../../../node_modules/jose/dist/webapi/jwe/compact/decrypt.js"() {
|
|
2098
|
+
init_decrypt2();
|
|
2099
|
+
init_errors();
|
|
2100
|
+
init_buffer_utils();
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
|
|
2104
|
+
// ../../../node_modules/jose/dist/webapi/jwe/general/decrypt.js
|
|
2105
|
+
async function generalDecrypt(jwe, key, options) {
|
|
2106
|
+
if (!isObject(jwe)) {
|
|
2107
|
+
throw new JWEInvalid("General JWE must be an object");
|
|
2108
|
+
}
|
|
2109
|
+
if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(isObject)) {
|
|
2110
|
+
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
2111
|
+
}
|
|
2112
|
+
if (!jwe.recipients.length) {
|
|
2113
|
+
throw new JWEInvalid("JWE Recipients has no members");
|
|
2114
|
+
}
|
|
2115
|
+
for (const recipient of jwe.recipients) {
|
|
2116
|
+
try {
|
|
2117
|
+
return await flattenedDecrypt({
|
|
2118
|
+
aad: jwe.aad,
|
|
2119
|
+
ciphertext: jwe.ciphertext,
|
|
2120
|
+
encrypted_key: recipient.encrypted_key,
|
|
2121
|
+
header: recipient.header,
|
|
2122
|
+
iv: jwe.iv,
|
|
2123
|
+
protected: jwe.protected,
|
|
2124
|
+
tag: jwe.tag,
|
|
2125
|
+
unprotected: jwe.unprotected
|
|
2126
|
+
}, key, options);
|
|
2127
|
+
} catch {
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
throw new JWEDecryptionFailed();
|
|
2131
|
+
}
|
|
2132
|
+
var init_decrypt4 = __esm({
|
|
2133
|
+
"../../../node_modules/jose/dist/webapi/jwe/general/decrypt.js"() {
|
|
2134
|
+
init_decrypt2();
|
|
2135
|
+
init_errors();
|
|
2136
|
+
init_is_object();
|
|
2137
|
+
}
|
|
2138
|
+
});
|
|
2139
|
+
|
|
2140
|
+
// ../../../node_modules/jose/dist/webapi/lib/private_symbols.js
|
|
2141
|
+
var unprotected;
|
|
2142
|
+
var init_private_symbols = __esm({
|
|
2143
|
+
"../../../node_modules/jose/dist/webapi/lib/private_symbols.js"() {
|
|
2144
|
+
unprotected = /* @__PURE__ */ Symbol();
|
|
2145
|
+
}
|
|
2146
|
+
});
|
|
2147
|
+
|
|
2148
|
+
// ../../../node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
2149
|
+
async function keyToJWK(key) {
|
|
2150
|
+
if (isKeyObject(key)) {
|
|
2151
|
+
if (key.type === "secret") {
|
|
2152
|
+
key = key.export();
|
|
2153
|
+
} else {
|
|
2154
|
+
return key.export({ format: "jwk" });
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
if (key instanceof Uint8Array) {
|
|
2158
|
+
return {
|
|
2159
|
+
kty: "oct",
|
|
2160
|
+
k: encode2(key)
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
if (!isCryptoKey(key)) {
|
|
2164
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
2165
|
+
}
|
|
2166
|
+
if (!key.extractable) {
|
|
2167
|
+
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
2168
|
+
}
|
|
2169
|
+
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
2170
|
+
if (jwk.kty === "AKP") {
|
|
2171
|
+
jwk.alg = alg;
|
|
2172
|
+
}
|
|
2173
|
+
return jwk;
|
|
2174
|
+
}
|
|
2175
|
+
var init_key_to_jwk = __esm({
|
|
2176
|
+
"../../../node_modules/jose/dist/webapi/lib/key_to_jwk.js"() {
|
|
2177
|
+
init_invalid_key_input();
|
|
2178
|
+
init_base64url();
|
|
2179
|
+
init_is_key_like();
|
|
2180
|
+
}
|
|
2181
|
+
});
|
|
2182
|
+
|
|
2183
|
+
// ../../../node_modules/jose/dist/webapi/key/export.js
|
|
2184
|
+
async function exportSPKI(key) {
|
|
2185
|
+
return toSPKI(key);
|
|
2186
|
+
}
|
|
2187
|
+
async function exportPKCS8(key) {
|
|
2188
|
+
return toPKCS8(key);
|
|
2189
|
+
}
|
|
2190
|
+
async function exportJWK(key) {
|
|
2191
|
+
return keyToJWK(key);
|
|
2192
|
+
}
|
|
2193
|
+
var init_export = __esm({
|
|
2194
|
+
"../../../node_modules/jose/dist/webapi/key/export.js"() {
|
|
2195
|
+
init_asn1();
|
|
2196
|
+
init_key_to_jwk();
|
|
2197
|
+
}
|
|
2198
|
+
});
|
|
2199
|
+
|
|
2200
|
+
// ../../../node_modules/jose/dist/webapi/lib/encrypt_key_management.js
|
|
2201
|
+
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
2202
|
+
let encryptedKey;
|
|
2203
|
+
let parameters;
|
|
2204
|
+
let cek;
|
|
2205
|
+
switch (alg) {
|
|
2206
|
+
case "dir": {
|
|
2207
|
+
cek = key;
|
|
2208
|
+
break;
|
|
2209
|
+
}
|
|
2210
|
+
case "ECDH-ES":
|
|
2211
|
+
case "ECDH-ES+A128KW":
|
|
2212
|
+
case "ECDH-ES+A192KW":
|
|
2213
|
+
case "ECDH-ES+A256KW": {
|
|
2214
|
+
assertCryptoKey(key);
|
|
2215
|
+
if (!allowed(key)) {
|
|
2216
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
2217
|
+
}
|
|
2218
|
+
const { apu, apv } = providedParameters;
|
|
2219
|
+
let ephemeralKey;
|
|
2220
|
+
if (providedParameters.epk) {
|
|
2221
|
+
ephemeralKey = await normalizeKey(providedParameters.epk, alg);
|
|
2222
|
+
} else {
|
|
2223
|
+
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
2224
|
+
}
|
|
2225
|
+
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
2226
|
+
const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
2227
|
+
parameters = { epk: { x, crv, kty } };
|
|
2228
|
+
if (kty === "EC")
|
|
2229
|
+
parameters.epk.y = y;
|
|
2230
|
+
if (apu)
|
|
2231
|
+
parameters.apu = encode2(apu);
|
|
2232
|
+
if (apv)
|
|
2233
|
+
parameters.apv = encode2(apv);
|
|
2234
|
+
if (alg === "ECDH-ES") {
|
|
2235
|
+
cek = sharedSecret;
|
|
2236
|
+
break;
|
|
2237
|
+
}
|
|
2238
|
+
cek = providedCek || generateCek(enc);
|
|
2239
|
+
const kwAlg = alg.slice(-6);
|
|
2240
|
+
encryptedKey = await wrap(kwAlg, sharedSecret, cek);
|
|
2241
|
+
break;
|
|
2242
|
+
}
|
|
2243
|
+
case "RSA-OAEP":
|
|
2244
|
+
case "RSA-OAEP-256":
|
|
2245
|
+
case "RSA-OAEP-384":
|
|
2246
|
+
case "RSA-OAEP-512": {
|
|
2247
|
+
cek = providedCek || generateCek(enc);
|
|
2248
|
+
assertCryptoKey(key);
|
|
2249
|
+
encryptedKey = await encrypt(alg, key, cek);
|
|
2250
|
+
break;
|
|
2251
|
+
}
|
|
2252
|
+
case "PBES2-HS256+A128KW":
|
|
2253
|
+
case "PBES2-HS384+A192KW":
|
|
2254
|
+
case "PBES2-HS512+A256KW": {
|
|
2255
|
+
cek = providedCek || generateCek(enc);
|
|
2256
|
+
const { p2c, p2s } = providedParameters;
|
|
2257
|
+
({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, p2c, p2s));
|
|
2258
|
+
break;
|
|
2259
|
+
}
|
|
2260
|
+
case "A128KW":
|
|
2261
|
+
case "A192KW":
|
|
2262
|
+
case "A256KW": {
|
|
2263
|
+
cek = providedCek || generateCek(enc);
|
|
2264
|
+
encryptedKey = await wrap(alg, key, cek);
|
|
2265
|
+
break;
|
|
2266
|
+
}
|
|
2267
|
+
case "A128GCMKW":
|
|
2268
|
+
case "A192GCMKW":
|
|
2269
|
+
case "A256GCMKW": {
|
|
2270
|
+
cek = providedCek || generateCek(enc);
|
|
2271
|
+
const { iv } = providedParameters;
|
|
2272
|
+
({ encryptedKey, ...parameters } = await wrap3(alg, key, cek, iv));
|
|
2273
|
+
break;
|
|
2274
|
+
}
|
|
2275
|
+
default: {
|
|
2276
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
return { cek, encryptedKey, parameters };
|
|
2280
|
+
}
|
|
2281
|
+
var init_encrypt_key_management = __esm({
|
|
2282
|
+
"../../../node_modules/jose/dist/webapi/lib/encrypt_key_management.js"() {
|
|
2283
|
+
init_aeskw();
|
|
2284
|
+
init_ecdhes();
|
|
2285
|
+
init_pbes2kw();
|
|
2286
|
+
init_rsaes();
|
|
2287
|
+
init_base64url();
|
|
2288
|
+
init_normalize_key();
|
|
2289
|
+
init_cek();
|
|
2290
|
+
init_errors();
|
|
2291
|
+
init_export();
|
|
2292
|
+
init_aesgcmkw();
|
|
2293
|
+
init_is_key_like();
|
|
2294
|
+
}
|
|
2295
|
+
});
|
|
2296
|
+
|
|
2297
|
+
// ../../../node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
2298
|
+
var FlattenedEncrypt;
|
|
2299
|
+
var init_encrypt2 = __esm({
|
|
2300
|
+
"../../../node_modules/jose/dist/webapi/jwe/flattened/encrypt.js"() {
|
|
2301
|
+
init_base64url();
|
|
2302
|
+
init_private_symbols();
|
|
2303
|
+
init_encrypt();
|
|
2304
|
+
init_encrypt_key_management();
|
|
2305
|
+
init_errors();
|
|
2306
|
+
init_is_disjoint();
|
|
2307
|
+
init_buffer_utils();
|
|
2308
|
+
init_validate_crit();
|
|
2309
|
+
init_normalize_key();
|
|
2310
|
+
init_check_key_type();
|
|
2311
|
+
FlattenedEncrypt = class {
|
|
2312
|
+
#plaintext;
|
|
2313
|
+
#protectedHeader;
|
|
2314
|
+
#sharedUnprotectedHeader;
|
|
2315
|
+
#unprotectedHeader;
|
|
2316
|
+
#aad;
|
|
2317
|
+
#cek;
|
|
2318
|
+
#iv;
|
|
2319
|
+
#keyManagementParameters;
|
|
2320
|
+
constructor(plaintext) {
|
|
2321
|
+
if (!(plaintext instanceof Uint8Array)) {
|
|
2322
|
+
throw new TypeError("plaintext must be an instance of Uint8Array");
|
|
2323
|
+
}
|
|
2324
|
+
this.#plaintext = plaintext;
|
|
2325
|
+
}
|
|
2326
|
+
setKeyManagementParameters(parameters) {
|
|
2327
|
+
if (this.#keyManagementParameters) {
|
|
2328
|
+
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
2329
|
+
}
|
|
2330
|
+
this.#keyManagementParameters = parameters;
|
|
2331
|
+
return this;
|
|
2332
|
+
}
|
|
2333
|
+
setProtectedHeader(protectedHeader) {
|
|
2334
|
+
if (this.#protectedHeader) {
|
|
2335
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
2336
|
+
}
|
|
2337
|
+
this.#protectedHeader = protectedHeader;
|
|
2338
|
+
return this;
|
|
2339
|
+
}
|
|
2340
|
+
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
2341
|
+
if (this.#sharedUnprotectedHeader) {
|
|
2342
|
+
throw new TypeError("setSharedUnprotectedHeader can only be called once");
|
|
2343
|
+
}
|
|
2344
|
+
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
2345
|
+
return this;
|
|
2346
|
+
}
|
|
2347
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
2348
|
+
if (this.#unprotectedHeader) {
|
|
2349
|
+
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
2350
|
+
}
|
|
2351
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
2352
|
+
return this;
|
|
2353
|
+
}
|
|
2354
|
+
setAdditionalAuthenticatedData(aad) {
|
|
2355
|
+
this.#aad = aad;
|
|
2356
|
+
return this;
|
|
2357
|
+
}
|
|
2358
|
+
setContentEncryptionKey(cek) {
|
|
2359
|
+
if (this.#cek) {
|
|
2360
|
+
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
2361
|
+
}
|
|
2362
|
+
this.#cek = cek;
|
|
2363
|
+
return this;
|
|
2364
|
+
}
|
|
2365
|
+
setInitializationVector(iv) {
|
|
2366
|
+
if (this.#iv) {
|
|
2367
|
+
throw new TypeError("setInitializationVector can only be called once");
|
|
2368
|
+
}
|
|
2369
|
+
this.#iv = iv;
|
|
2370
|
+
return this;
|
|
2371
|
+
}
|
|
2372
|
+
async encrypt(key, options) {
|
|
2373
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader && !this.#sharedUnprotectedHeader) {
|
|
2374
|
+
throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
2375
|
+
}
|
|
2376
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, this.#sharedUnprotectedHeader)) {
|
|
2377
|
+
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
2378
|
+
}
|
|
2379
|
+
const joseHeader = {
|
|
2380
|
+
...this.#protectedHeader,
|
|
2381
|
+
...this.#unprotectedHeader,
|
|
2382
|
+
...this.#sharedUnprotectedHeader
|
|
2383
|
+
};
|
|
2384
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, this.#protectedHeader, joseHeader);
|
|
2385
|
+
if (joseHeader.zip !== void 0) {
|
|
2386
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
2387
|
+
}
|
|
2388
|
+
const { alg, enc } = joseHeader;
|
|
2389
|
+
if (typeof alg !== "string" || !alg) {
|
|
2390
|
+
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2391
|
+
}
|
|
2392
|
+
if (typeof enc !== "string" || !enc) {
|
|
2393
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
2394
|
+
}
|
|
2395
|
+
let encryptedKey;
|
|
2396
|
+
if (this.#cek && (alg === "dir" || alg === "ECDH-ES")) {
|
|
2397
|
+
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
2398
|
+
}
|
|
2399
|
+
checkKeyType(alg === "dir" ? enc : alg, key, "encrypt");
|
|
2400
|
+
let cek;
|
|
2401
|
+
{
|
|
2402
|
+
let parameters;
|
|
2403
|
+
const k = await normalizeKey(key, alg);
|
|
2404
|
+
({ cek, encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, this.#cek, this.#keyManagementParameters));
|
|
2405
|
+
if (parameters) {
|
|
2406
|
+
if (options && unprotected in options) {
|
|
2407
|
+
if (!this.#unprotectedHeader) {
|
|
2408
|
+
this.setUnprotectedHeader(parameters);
|
|
2409
|
+
} else {
|
|
2410
|
+
this.#unprotectedHeader = { ...this.#unprotectedHeader, ...parameters };
|
|
2411
|
+
}
|
|
2412
|
+
} else if (!this.#protectedHeader) {
|
|
2413
|
+
this.setProtectedHeader(parameters);
|
|
2414
|
+
} else {
|
|
2415
|
+
this.#protectedHeader = { ...this.#protectedHeader, ...parameters };
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
let additionalData;
|
|
2420
|
+
let protectedHeaderS;
|
|
2421
|
+
let protectedHeaderB;
|
|
2422
|
+
let aadMember;
|
|
2423
|
+
if (this.#protectedHeader) {
|
|
2424
|
+
protectedHeaderS = encode2(JSON.stringify(this.#protectedHeader));
|
|
2425
|
+
protectedHeaderB = encode(protectedHeaderS);
|
|
2426
|
+
} else {
|
|
2427
|
+
protectedHeaderS = "";
|
|
2428
|
+
protectedHeaderB = new Uint8Array();
|
|
2429
|
+
}
|
|
2430
|
+
if (this.#aad) {
|
|
2431
|
+
aadMember = encode2(this.#aad);
|
|
2432
|
+
const aadMemberBytes = encode(aadMember);
|
|
2433
|
+
additionalData = concat(protectedHeaderB, encode("."), aadMemberBytes);
|
|
2434
|
+
} else {
|
|
2435
|
+
additionalData = protectedHeaderB;
|
|
2436
|
+
}
|
|
2437
|
+
const { ciphertext, tag: tag2, iv } = await encrypt2(enc, this.#plaintext, cek, this.#iv, additionalData);
|
|
2438
|
+
const jwe = {
|
|
2439
|
+
ciphertext: encode2(ciphertext)
|
|
2440
|
+
};
|
|
2441
|
+
if (iv) {
|
|
2442
|
+
jwe.iv = encode2(iv);
|
|
2443
|
+
}
|
|
2444
|
+
if (tag2) {
|
|
2445
|
+
jwe.tag = encode2(tag2);
|
|
2446
|
+
}
|
|
2447
|
+
if (encryptedKey) {
|
|
2448
|
+
jwe.encrypted_key = encode2(encryptedKey);
|
|
2449
|
+
}
|
|
2450
|
+
if (aadMember) {
|
|
2451
|
+
jwe.aad = aadMember;
|
|
2452
|
+
}
|
|
2453
|
+
if (this.#protectedHeader) {
|
|
2454
|
+
jwe.protected = protectedHeaderS;
|
|
2455
|
+
}
|
|
2456
|
+
if (this.#sharedUnprotectedHeader) {
|
|
2457
|
+
jwe.unprotected = this.#sharedUnprotectedHeader;
|
|
2458
|
+
}
|
|
2459
|
+
if (this.#unprotectedHeader) {
|
|
2460
|
+
jwe.header = this.#unprotectedHeader;
|
|
2461
|
+
}
|
|
2462
|
+
return jwe;
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
}
|
|
2466
|
+
});
|
|
2467
|
+
|
|
2468
|
+
// ../../../node_modules/jose/dist/webapi/jwe/general/encrypt.js
|
|
2469
|
+
var IndividualRecipient, GeneralEncrypt;
|
|
2470
|
+
var init_encrypt3 = __esm({
|
|
2471
|
+
"../../../node_modules/jose/dist/webapi/jwe/general/encrypt.js"() {
|
|
2472
|
+
init_encrypt2();
|
|
2473
|
+
init_private_symbols();
|
|
2474
|
+
init_errors();
|
|
2475
|
+
init_cek();
|
|
2476
|
+
init_is_disjoint();
|
|
2477
|
+
init_encrypt_key_management();
|
|
2478
|
+
init_base64url();
|
|
2479
|
+
init_validate_crit();
|
|
2480
|
+
init_normalize_key();
|
|
2481
|
+
init_check_key_type();
|
|
2482
|
+
IndividualRecipient = class {
|
|
2483
|
+
#parent;
|
|
2484
|
+
unprotectedHeader;
|
|
2485
|
+
keyManagementParameters;
|
|
2486
|
+
key;
|
|
2487
|
+
options;
|
|
2488
|
+
constructor(enc, key, options) {
|
|
2489
|
+
this.#parent = enc;
|
|
2490
|
+
this.key = key;
|
|
2491
|
+
this.options = options;
|
|
2492
|
+
}
|
|
2493
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
2494
|
+
if (this.unprotectedHeader) {
|
|
2495
|
+
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
2496
|
+
}
|
|
2497
|
+
this.unprotectedHeader = unprotectedHeader;
|
|
2498
|
+
return this;
|
|
2499
|
+
}
|
|
2500
|
+
setKeyManagementParameters(parameters) {
|
|
2501
|
+
if (this.keyManagementParameters) {
|
|
2502
|
+
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
2503
|
+
}
|
|
2504
|
+
this.keyManagementParameters = parameters;
|
|
2505
|
+
return this;
|
|
2506
|
+
}
|
|
2507
|
+
addRecipient(...args) {
|
|
2508
|
+
return this.#parent.addRecipient(...args);
|
|
2509
|
+
}
|
|
2510
|
+
encrypt(...args) {
|
|
2511
|
+
return this.#parent.encrypt(...args);
|
|
2512
|
+
}
|
|
2513
|
+
done() {
|
|
2514
|
+
return this.#parent;
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
GeneralEncrypt = class {
|
|
2518
|
+
#plaintext;
|
|
2519
|
+
#recipients = [];
|
|
2520
|
+
#protectedHeader;
|
|
2521
|
+
#unprotectedHeader;
|
|
2522
|
+
#aad;
|
|
2523
|
+
constructor(plaintext) {
|
|
2524
|
+
this.#plaintext = plaintext;
|
|
2525
|
+
}
|
|
2526
|
+
addRecipient(key, options) {
|
|
2527
|
+
const recipient = new IndividualRecipient(this, key, { crit: options?.crit });
|
|
2528
|
+
this.#recipients.push(recipient);
|
|
2529
|
+
return recipient;
|
|
2530
|
+
}
|
|
2531
|
+
setProtectedHeader(protectedHeader) {
|
|
2532
|
+
if (this.#protectedHeader) {
|
|
2533
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
2534
|
+
}
|
|
2535
|
+
this.#protectedHeader = protectedHeader;
|
|
2536
|
+
return this;
|
|
2537
|
+
}
|
|
2538
|
+
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
2539
|
+
if (this.#unprotectedHeader) {
|
|
2540
|
+
throw new TypeError("setSharedUnprotectedHeader can only be called once");
|
|
2541
|
+
}
|
|
2542
|
+
this.#unprotectedHeader = sharedUnprotectedHeader;
|
|
2543
|
+
return this;
|
|
2544
|
+
}
|
|
2545
|
+
setAdditionalAuthenticatedData(aad) {
|
|
2546
|
+
this.#aad = aad;
|
|
2547
|
+
return this;
|
|
2548
|
+
}
|
|
2549
|
+
async encrypt() {
|
|
2550
|
+
if (!this.#recipients.length) {
|
|
2551
|
+
throw new JWEInvalid("at least one recipient must be added");
|
|
2552
|
+
}
|
|
2553
|
+
if (this.#recipients.length === 1) {
|
|
2554
|
+
const [recipient] = this.#recipients;
|
|
2555
|
+
const flattened = await new FlattenedEncrypt(this.#plaintext).setAdditionalAuthenticatedData(this.#aad).setProtectedHeader(this.#protectedHeader).setSharedUnprotectedHeader(this.#unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).encrypt(recipient.key, { ...recipient.options });
|
|
2556
|
+
const jwe2 = {
|
|
2557
|
+
ciphertext: flattened.ciphertext,
|
|
2558
|
+
iv: flattened.iv,
|
|
2559
|
+
recipients: [{}],
|
|
2560
|
+
tag: flattened.tag
|
|
2561
|
+
};
|
|
2562
|
+
if (flattened.aad)
|
|
2563
|
+
jwe2.aad = flattened.aad;
|
|
2564
|
+
if (flattened.protected)
|
|
2565
|
+
jwe2.protected = flattened.protected;
|
|
2566
|
+
if (flattened.unprotected)
|
|
2567
|
+
jwe2.unprotected = flattened.unprotected;
|
|
2568
|
+
if (flattened.encrypted_key)
|
|
2569
|
+
jwe2.recipients[0].encrypted_key = flattened.encrypted_key;
|
|
2570
|
+
if (flattened.header)
|
|
2571
|
+
jwe2.recipients[0].header = flattened.header;
|
|
2572
|
+
return jwe2;
|
|
2573
|
+
}
|
|
2574
|
+
let enc;
|
|
2575
|
+
for (let i = 0; i < this.#recipients.length; i++) {
|
|
2576
|
+
const recipient = this.#recipients[i];
|
|
2577
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, recipient.unprotectedHeader)) {
|
|
2578
|
+
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
2579
|
+
}
|
|
2580
|
+
const joseHeader = {
|
|
2581
|
+
...this.#protectedHeader,
|
|
2582
|
+
...this.#unprotectedHeader,
|
|
2583
|
+
...recipient.unprotectedHeader
|
|
2584
|
+
};
|
|
2585
|
+
const { alg } = joseHeader;
|
|
2586
|
+
if (typeof alg !== "string" || !alg) {
|
|
2587
|
+
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2588
|
+
}
|
|
2589
|
+
if (alg === "dir" || alg === "ECDH-ES") {
|
|
2590
|
+
throw new JWEInvalid('"dir" and "ECDH-ES" alg may only be used with a single recipient');
|
|
2591
|
+
}
|
|
2592
|
+
if (typeof joseHeader.enc !== "string" || !joseHeader.enc) {
|
|
2593
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
2594
|
+
}
|
|
2595
|
+
if (!enc) {
|
|
2596
|
+
enc = joseHeader.enc;
|
|
2597
|
+
} else if (enc !== joseHeader.enc) {
|
|
2598
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
|
|
2599
|
+
}
|
|
2600
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), recipient.options.crit, this.#protectedHeader, joseHeader);
|
|
2601
|
+
if (joseHeader.zip !== void 0) {
|
|
2602
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
const cek = generateCek(enc);
|
|
2606
|
+
const jwe = {
|
|
2607
|
+
ciphertext: "",
|
|
2608
|
+
recipients: []
|
|
2609
|
+
};
|
|
2610
|
+
for (let i = 0; i < this.#recipients.length; i++) {
|
|
2611
|
+
const recipient = this.#recipients[i];
|
|
2612
|
+
const target = {};
|
|
2613
|
+
jwe.recipients.push(target);
|
|
2614
|
+
if (i === 0) {
|
|
2615
|
+
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, {
|
|
2616
|
+
...recipient.options,
|
|
2617
|
+
[unprotected]: true
|
|
2618
|
+
});
|
|
2619
|
+
jwe.ciphertext = flattened.ciphertext;
|
|
2620
|
+
jwe.iv = flattened.iv;
|
|
2621
|
+
jwe.tag = flattened.tag;
|
|
2622
|
+
if (flattened.aad)
|
|
2623
|
+
jwe.aad = flattened.aad;
|
|
2624
|
+
if (flattened.protected)
|
|
2625
|
+
jwe.protected = flattened.protected;
|
|
2626
|
+
if (flattened.unprotected)
|
|
2627
|
+
jwe.unprotected = flattened.unprotected;
|
|
2628
|
+
target.encrypted_key = flattened.encrypted_key;
|
|
2629
|
+
if (flattened.header)
|
|
2630
|
+
target.header = flattened.header;
|
|
2631
|
+
continue;
|
|
2632
|
+
}
|
|
2633
|
+
const alg = recipient.unprotectedHeader?.alg || this.#protectedHeader?.alg || this.#unprotectedHeader?.alg;
|
|
2634
|
+
checkKeyType(alg === "dir" ? enc : alg, recipient.key, "encrypt");
|
|
2635
|
+
const k = await normalizeKey(recipient.key, alg);
|
|
2636
|
+
const { encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, cek, recipient.keyManagementParameters);
|
|
2637
|
+
target.encrypted_key = encode2(encryptedKey);
|
|
2638
|
+
if (recipient.unprotectedHeader || parameters)
|
|
2639
|
+
target.header = { ...recipient.unprotectedHeader, ...parameters };
|
|
2640
|
+
}
|
|
2641
|
+
return jwe;
|
|
2642
|
+
}
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
});
|
|
2646
|
+
|
|
2647
|
+
// ../../../node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
2648
|
+
function subtleAlgorithm2(alg, algorithm) {
|
|
2649
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
2650
|
+
switch (alg) {
|
|
2651
|
+
case "HS256":
|
|
2652
|
+
case "HS384":
|
|
2653
|
+
case "HS512":
|
|
2654
|
+
return { hash, name: "HMAC" };
|
|
2655
|
+
case "PS256":
|
|
2656
|
+
case "PS384":
|
|
2657
|
+
case "PS512":
|
|
2658
|
+
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
2659
|
+
case "RS256":
|
|
2660
|
+
case "RS384":
|
|
2661
|
+
case "RS512":
|
|
2662
|
+
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
2663
|
+
case "ES256":
|
|
2664
|
+
case "ES384":
|
|
2665
|
+
case "ES512":
|
|
2666
|
+
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
2667
|
+
case "Ed25519":
|
|
2668
|
+
case "EdDSA":
|
|
2669
|
+
return { name: "Ed25519" };
|
|
2670
|
+
case "ML-DSA-44":
|
|
2671
|
+
case "ML-DSA-65":
|
|
2672
|
+
case "ML-DSA-87":
|
|
2673
|
+
return { name: alg };
|
|
2674
|
+
default:
|
|
2675
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
var init_subtle_dsa = __esm({
|
|
2679
|
+
"../../../node_modules/jose/dist/webapi/lib/subtle_dsa.js"() {
|
|
2680
|
+
init_errors();
|
|
2681
|
+
}
|
|
2682
|
+
});
|
|
2683
|
+
|
|
2684
|
+
// ../../../node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
2685
|
+
async function getSigKey(alg, key, usage) {
|
|
2686
|
+
if (key instanceof Uint8Array) {
|
|
2687
|
+
if (!alg.startsWith("HS")) {
|
|
2688
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
2689
|
+
}
|
|
2690
|
+
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
2691
|
+
}
|
|
2692
|
+
checkSigCryptoKey(key, alg, usage);
|
|
2693
|
+
return key;
|
|
2694
|
+
}
|
|
2695
|
+
var init_get_sign_verify_key = __esm({
|
|
2696
|
+
"../../../node_modules/jose/dist/webapi/lib/get_sign_verify_key.js"() {
|
|
2697
|
+
init_crypto_key();
|
|
2698
|
+
init_invalid_key_input();
|
|
2699
|
+
}
|
|
2700
|
+
});
|
|
2701
|
+
|
|
2702
|
+
// ../../../node_modules/jose/dist/webapi/lib/verify.js
|
|
2703
|
+
async function verify(alg, key, signature, data) {
|
|
2704
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
2705
|
+
checkKeyLength(alg, cryptoKey);
|
|
2706
|
+
const algorithm = subtleAlgorithm2(alg, cryptoKey.algorithm);
|
|
2707
|
+
try {
|
|
2708
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
2709
|
+
} catch {
|
|
2710
|
+
return false;
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
var init_verify = __esm({
|
|
2714
|
+
"../../../node_modules/jose/dist/webapi/lib/verify.js"() {
|
|
2715
|
+
init_subtle_dsa();
|
|
2716
|
+
init_check_key_length();
|
|
2717
|
+
init_get_sign_verify_key();
|
|
2718
|
+
}
|
|
2719
|
+
});
|
|
2720
|
+
|
|
2721
|
+
// ../../../node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
2722
|
+
async function flattenedVerify(jws, key, options) {
|
|
2723
|
+
if (!isObject(jws)) {
|
|
2724
|
+
throw new JWSInvalid("Flattened JWS must be an object");
|
|
2725
|
+
}
|
|
2726
|
+
if (jws.protected === void 0 && jws.header === void 0) {
|
|
2727
|
+
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
2728
|
+
}
|
|
2729
|
+
if (jws.protected !== void 0 && typeof jws.protected !== "string") {
|
|
2730
|
+
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
2731
|
+
}
|
|
2732
|
+
if (jws.payload === void 0) {
|
|
2733
|
+
throw new JWSInvalid("JWS Payload missing");
|
|
2734
|
+
}
|
|
2735
|
+
if (typeof jws.signature !== "string") {
|
|
2736
|
+
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
2737
|
+
}
|
|
2738
|
+
if (jws.header !== void 0 && !isObject(jws.header)) {
|
|
2739
|
+
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
2740
|
+
}
|
|
2741
|
+
let parsedProt = {};
|
|
2742
|
+
if (jws.protected) {
|
|
2743
|
+
try {
|
|
2744
|
+
const protectedHeader = decode(jws.protected);
|
|
2745
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
2746
|
+
} catch {
|
|
2747
|
+
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
if (!isDisjoint(parsedProt, jws.header)) {
|
|
2751
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
2752
|
+
}
|
|
2753
|
+
const joseHeader = {
|
|
2754
|
+
...parsedProt,
|
|
2755
|
+
...jws.header
|
|
2756
|
+
};
|
|
2757
|
+
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
2758
|
+
let b64 = true;
|
|
2759
|
+
if (extensions.has("b64")) {
|
|
2760
|
+
b64 = parsedProt.b64;
|
|
2761
|
+
if (typeof b64 !== "boolean") {
|
|
2762
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
const { alg } = joseHeader;
|
|
2766
|
+
if (typeof alg !== "string" || !alg) {
|
|
2767
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2768
|
+
}
|
|
2769
|
+
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
2770
|
+
if (algorithms && !algorithms.has(alg)) {
|
|
2771
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
2772
|
+
}
|
|
2773
|
+
if (b64) {
|
|
2774
|
+
if (typeof jws.payload !== "string") {
|
|
2775
|
+
throw new JWSInvalid("JWS Payload must be a string");
|
|
2776
|
+
}
|
|
2777
|
+
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
|
|
2778
|
+
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
2779
|
+
}
|
|
2780
|
+
let resolvedKey = false;
|
|
2781
|
+
if (typeof key === "function") {
|
|
2782
|
+
key = await key(parsedProt, jws);
|
|
2783
|
+
resolvedKey = true;
|
|
2784
|
+
}
|
|
2785
|
+
checkKeyType(alg, key, "verify");
|
|
2786
|
+
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);
|
|
2787
|
+
let signature;
|
|
2788
|
+
try {
|
|
2789
|
+
signature = decode(jws.signature);
|
|
2790
|
+
} catch {
|
|
2791
|
+
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
2792
|
+
}
|
|
2793
|
+
const k = await normalizeKey(key, alg);
|
|
2794
|
+
const verified = await verify(alg, k, signature, data);
|
|
2795
|
+
if (!verified) {
|
|
2796
|
+
throw new JWSSignatureVerificationFailed();
|
|
2797
|
+
}
|
|
2798
|
+
let payload;
|
|
2799
|
+
if (b64) {
|
|
2800
|
+
try {
|
|
2801
|
+
payload = decode(jws.payload);
|
|
2802
|
+
} catch {
|
|
2803
|
+
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
2804
|
+
}
|
|
2805
|
+
} else if (typeof jws.payload === "string") {
|
|
2806
|
+
payload = encoder.encode(jws.payload);
|
|
2807
|
+
} else {
|
|
2808
|
+
payload = jws.payload;
|
|
2809
|
+
}
|
|
2810
|
+
const result = { payload };
|
|
2811
|
+
if (jws.protected !== void 0) {
|
|
2812
|
+
result.protectedHeader = parsedProt;
|
|
2813
|
+
}
|
|
2814
|
+
if (jws.header !== void 0) {
|
|
2815
|
+
result.unprotectedHeader = jws.header;
|
|
2816
|
+
}
|
|
2817
|
+
if (resolvedKey) {
|
|
2818
|
+
return { ...result, key: k };
|
|
2819
|
+
}
|
|
2820
|
+
return result;
|
|
2821
|
+
}
|
|
2822
|
+
var init_verify2 = __esm({
|
|
2823
|
+
"../../../node_modules/jose/dist/webapi/jws/flattened/verify.js"() {
|
|
2824
|
+
init_base64url();
|
|
2825
|
+
init_verify();
|
|
2826
|
+
init_errors();
|
|
2827
|
+
init_buffer_utils();
|
|
2828
|
+
init_is_disjoint();
|
|
2829
|
+
init_is_object();
|
|
2830
|
+
init_check_key_type();
|
|
2831
|
+
init_validate_crit();
|
|
2832
|
+
init_validate_algorithms();
|
|
2833
|
+
init_normalize_key();
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
|
|
2837
|
+
// ../../../node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
2838
|
+
async function compactVerify(jws, key, options) {
|
|
2839
|
+
if (jws instanceof Uint8Array) {
|
|
2840
|
+
jws = decoder.decode(jws);
|
|
2841
|
+
}
|
|
2842
|
+
if (typeof jws !== "string") {
|
|
2843
|
+
throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
2844
|
+
}
|
|
2845
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
2846
|
+
if (length !== 3) {
|
|
2847
|
+
throw new JWSInvalid("Invalid Compact JWS");
|
|
2848
|
+
}
|
|
2849
|
+
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
|
2850
|
+
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
|
2851
|
+
if (typeof key === "function") {
|
|
2852
|
+
return { ...result, key: verified.key };
|
|
2853
|
+
}
|
|
2854
|
+
return result;
|
|
2855
|
+
}
|
|
2856
|
+
var init_verify3 = __esm({
|
|
2857
|
+
"../../../node_modules/jose/dist/webapi/jws/compact/verify.js"() {
|
|
2858
|
+
init_verify2();
|
|
2859
|
+
init_errors();
|
|
2860
|
+
init_buffer_utils();
|
|
2861
|
+
}
|
|
2862
|
+
});
|
|
2863
|
+
|
|
2864
|
+
// ../../../node_modules/jose/dist/webapi/jws/general/verify.js
|
|
2865
|
+
async function generalVerify(jws, key, options) {
|
|
2866
|
+
if (!isObject(jws)) {
|
|
2867
|
+
throw new JWSInvalid("General JWS must be an object");
|
|
2868
|
+
}
|
|
2869
|
+
if (!Array.isArray(jws.signatures) || !jws.signatures.every(isObject)) {
|
|
2870
|
+
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
2871
|
+
}
|
|
2872
|
+
for (const signature of jws.signatures) {
|
|
2873
|
+
try {
|
|
2874
|
+
return await flattenedVerify({
|
|
2875
|
+
header: signature.header,
|
|
2876
|
+
payload: jws.payload,
|
|
2877
|
+
protected: signature.protected,
|
|
2878
|
+
signature: signature.signature
|
|
2879
|
+
}, key, options);
|
|
2880
|
+
} catch {
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
throw new JWSSignatureVerificationFailed();
|
|
2884
|
+
}
|
|
2885
|
+
var init_verify4 = __esm({
|
|
2886
|
+
"../../../node_modules/jose/dist/webapi/jws/general/verify.js"() {
|
|
2887
|
+
init_verify2();
|
|
2888
|
+
init_errors();
|
|
2889
|
+
init_is_object();
|
|
2890
|
+
}
|
|
2891
|
+
});
|
|
2892
|
+
|
|
2893
|
+
// ../../../node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
2894
|
+
function secs(str) {
|
|
2895
|
+
const matched = REGEX.exec(str);
|
|
2896
|
+
if (!matched || matched[4] && matched[1]) {
|
|
2897
|
+
throw new TypeError("Invalid time period format");
|
|
2898
|
+
}
|
|
2899
|
+
const value = parseFloat(matched[2]);
|
|
2900
|
+
const unit = matched[3].toLowerCase();
|
|
2901
|
+
let numericDate;
|
|
2902
|
+
switch (unit) {
|
|
2903
|
+
case "sec":
|
|
2904
|
+
case "secs":
|
|
2905
|
+
case "second":
|
|
2906
|
+
case "seconds":
|
|
2907
|
+
case "s":
|
|
2908
|
+
numericDate = Math.round(value);
|
|
2909
|
+
break;
|
|
2910
|
+
case "minute":
|
|
2911
|
+
case "minutes":
|
|
2912
|
+
case "min":
|
|
2913
|
+
case "mins":
|
|
2914
|
+
case "m":
|
|
2915
|
+
numericDate = Math.round(value * minute);
|
|
2916
|
+
break;
|
|
2917
|
+
case "hour":
|
|
2918
|
+
case "hours":
|
|
2919
|
+
case "hr":
|
|
2920
|
+
case "hrs":
|
|
2921
|
+
case "h":
|
|
2922
|
+
numericDate = Math.round(value * hour);
|
|
2923
|
+
break;
|
|
2924
|
+
case "day":
|
|
2925
|
+
case "days":
|
|
2926
|
+
case "d":
|
|
2927
|
+
numericDate = Math.round(value * day);
|
|
2928
|
+
break;
|
|
2929
|
+
case "week":
|
|
2930
|
+
case "weeks":
|
|
2931
|
+
case "w":
|
|
2932
|
+
numericDate = Math.round(value * week);
|
|
2933
|
+
break;
|
|
2934
|
+
default:
|
|
2935
|
+
numericDate = Math.round(value * year);
|
|
2936
|
+
break;
|
|
2937
|
+
}
|
|
2938
|
+
if (matched[1] === "-" || matched[4] === "ago") {
|
|
2939
|
+
return -numericDate;
|
|
2940
|
+
}
|
|
2941
|
+
return numericDate;
|
|
2942
|
+
}
|
|
2943
|
+
function validateInput(label, input) {
|
|
2944
|
+
if (!Number.isFinite(input)) {
|
|
2945
|
+
throw new TypeError(`Invalid ${label} input`);
|
|
2946
|
+
}
|
|
2947
|
+
return input;
|
|
2948
|
+
}
|
|
2949
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
2950
|
+
let payload;
|
|
2951
|
+
try {
|
|
2952
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
2953
|
+
} catch {
|
|
2954
|
+
}
|
|
2955
|
+
if (!isObject(payload)) {
|
|
2956
|
+
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
2957
|
+
}
|
|
2958
|
+
const { typ } = options;
|
|
2959
|
+
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
|
2960
|
+
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
|
|
2961
|
+
}
|
|
2962
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
2963
|
+
const presenceCheck = [...requiredClaims];
|
|
2964
|
+
if (maxTokenAge !== void 0)
|
|
2965
|
+
presenceCheck.push("iat");
|
|
2966
|
+
if (audience !== void 0)
|
|
2967
|
+
presenceCheck.push("aud");
|
|
2968
|
+
if (subject !== void 0)
|
|
2969
|
+
presenceCheck.push("sub");
|
|
2970
|
+
if (issuer !== void 0)
|
|
2971
|
+
presenceCheck.push("iss");
|
|
2972
|
+
for (const claim of new Set(presenceCheck.reverse())) {
|
|
2973
|
+
if (!(claim in payload)) {
|
|
2974
|
+
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
2978
|
+
throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
|
|
2979
|
+
}
|
|
2980
|
+
if (subject && payload.sub !== subject) {
|
|
2981
|
+
throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
|
|
2982
|
+
}
|
|
2983
|
+
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
|
|
2984
|
+
throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
|
|
2985
|
+
}
|
|
2986
|
+
let tolerance;
|
|
2987
|
+
switch (typeof options.clockTolerance) {
|
|
2988
|
+
case "string":
|
|
2989
|
+
tolerance = secs(options.clockTolerance);
|
|
2990
|
+
break;
|
|
2991
|
+
case "number":
|
|
2992
|
+
tolerance = options.clockTolerance;
|
|
2993
|
+
break;
|
|
2994
|
+
case "undefined":
|
|
2995
|
+
tolerance = 0;
|
|
2996
|
+
break;
|
|
2997
|
+
default:
|
|
2998
|
+
throw new TypeError("Invalid clockTolerance option type");
|
|
2999
|
+
}
|
|
3000
|
+
const { currentDate } = options;
|
|
3001
|
+
const now = epoch(currentDate || /* @__PURE__ */ new Date());
|
|
3002
|
+
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
|
|
3003
|
+
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
|
|
3004
|
+
}
|
|
3005
|
+
if (payload.nbf !== void 0) {
|
|
3006
|
+
if (typeof payload.nbf !== "number") {
|
|
3007
|
+
throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
|
|
3008
|
+
}
|
|
3009
|
+
if (payload.nbf > now + tolerance) {
|
|
3010
|
+
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
if (payload.exp !== void 0) {
|
|
3014
|
+
if (typeof payload.exp !== "number") {
|
|
3015
|
+
throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
|
|
3016
|
+
}
|
|
3017
|
+
if (payload.exp <= now - tolerance) {
|
|
3018
|
+
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
if (maxTokenAge) {
|
|
3022
|
+
const age = now - payload.iat;
|
|
3023
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
3024
|
+
if (age - tolerance > max) {
|
|
3025
|
+
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
|
|
3026
|
+
}
|
|
3027
|
+
if (age < 0 - tolerance) {
|
|
3028
|
+
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
return payload;
|
|
3032
|
+
}
|
|
3033
|
+
var epoch, minute, hour, day, week, year, REGEX, normalizeTyp, checkAudiencePresence, JWTClaimsBuilder;
|
|
3034
|
+
var init_jwt_claims_set = __esm({
|
|
3035
|
+
"../../../node_modules/jose/dist/webapi/lib/jwt_claims_set.js"() {
|
|
3036
|
+
init_errors();
|
|
3037
|
+
init_buffer_utils();
|
|
3038
|
+
init_is_object();
|
|
3039
|
+
epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
3040
|
+
minute = 60;
|
|
3041
|
+
hour = minute * 60;
|
|
3042
|
+
day = hour * 24;
|
|
3043
|
+
week = day * 7;
|
|
3044
|
+
year = day * 365.25;
|
|
3045
|
+
REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
3046
|
+
normalizeTyp = (value) => {
|
|
3047
|
+
if (value.includes("/")) {
|
|
3048
|
+
return value.toLowerCase();
|
|
3049
|
+
}
|
|
3050
|
+
return `application/${value.toLowerCase()}`;
|
|
3051
|
+
};
|
|
3052
|
+
checkAudiencePresence = (audPayload, audOption) => {
|
|
3053
|
+
if (typeof audPayload === "string") {
|
|
3054
|
+
return audOption.includes(audPayload);
|
|
3055
|
+
}
|
|
3056
|
+
if (Array.isArray(audPayload)) {
|
|
3057
|
+
return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
3058
|
+
}
|
|
3059
|
+
return false;
|
|
3060
|
+
};
|
|
3061
|
+
JWTClaimsBuilder = class {
|
|
3062
|
+
#payload;
|
|
3063
|
+
constructor(payload) {
|
|
3064
|
+
if (!isObject(payload)) {
|
|
3065
|
+
throw new TypeError("JWT Claims Set MUST be an object");
|
|
3066
|
+
}
|
|
3067
|
+
this.#payload = structuredClone(payload);
|
|
3068
|
+
}
|
|
3069
|
+
data() {
|
|
3070
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
3071
|
+
}
|
|
3072
|
+
get iss() {
|
|
3073
|
+
return this.#payload.iss;
|
|
3074
|
+
}
|
|
3075
|
+
set iss(value) {
|
|
3076
|
+
this.#payload.iss = value;
|
|
3077
|
+
}
|
|
3078
|
+
get sub() {
|
|
3079
|
+
return this.#payload.sub;
|
|
3080
|
+
}
|
|
3081
|
+
set sub(value) {
|
|
3082
|
+
this.#payload.sub = value;
|
|
3083
|
+
}
|
|
3084
|
+
get aud() {
|
|
3085
|
+
return this.#payload.aud;
|
|
3086
|
+
}
|
|
3087
|
+
set aud(value) {
|
|
3088
|
+
this.#payload.aud = value;
|
|
3089
|
+
}
|
|
3090
|
+
set jti(value) {
|
|
3091
|
+
this.#payload.jti = value;
|
|
3092
|
+
}
|
|
3093
|
+
set nbf(value) {
|
|
3094
|
+
if (typeof value === "number") {
|
|
3095
|
+
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
3096
|
+
} else if (value instanceof Date) {
|
|
3097
|
+
this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
3098
|
+
} else {
|
|
3099
|
+
this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
set exp(value) {
|
|
3103
|
+
if (typeof value === "number") {
|
|
3104
|
+
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
3105
|
+
} else if (value instanceof Date) {
|
|
3106
|
+
this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
3107
|
+
} else {
|
|
3108
|
+
this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
set iat(value) {
|
|
3112
|
+
if (value === void 0) {
|
|
3113
|
+
this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
3114
|
+
} else if (value instanceof Date) {
|
|
3115
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
3116
|
+
} else if (typeof value === "string") {
|
|
3117
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
3118
|
+
} else {
|
|
3119
|
+
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
};
|
|
3123
|
+
}
|
|
3124
|
+
});
|
|
3125
|
+
|
|
3126
|
+
// ../../../node_modules/jose/dist/webapi/jwt/verify.js
|
|
3127
|
+
async function jwtVerify(jwt, key, options) {
|
|
3128
|
+
const verified = await compactVerify(jwt, key, options);
|
|
3129
|
+
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
3130
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3131
|
+
}
|
|
3132
|
+
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
|
3133
|
+
const result = { payload, protectedHeader: verified.protectedHeader };
|
|
3134
|
+
if (typeof key === "function") {
|
|
3135
|
+
return { ...result, key: verified.key };
|
|
3136
|
+
}
|
|
3137
|
+
return result;
|
|
3138
|
+
}
|
|
3139
|
+
var init_verify5 = __esm({
|
|
3140
|
+
"../../../node_modules/jose/dist/webapi/jwt/verify.js"() {
|
|
3141
|
+
init_verify3();
|
|
3142
|
+
init_jwt_claims_set();
|
|
3143
|
+
init_errors();
|
|
3144
|
+
}
|
|
3145
|
+
});
|
|
3146
|
+
|
|
3147
|
+
// ../../../node_modules/jose/dist/webapi/jwt/decrypt.js
|
|
3148
|
+
async function jwtDecrypt(jwt, key, options) {
|
|
3149
|
+
const decrypted = await compactDecrypt(jwt, key, options);
|
|
3150
|
+
const payload = validateClaimsSet(decrypted.protectedHeader, decrypted.plaintext, options);
|
|
3151
|
+
const { protectedHeader } = decrypted;
|
|
3152
|
+
if (protectedHeader.iss !== void 0 && protectedHeader.iss !== payload.iss) {
|
|
3153
|
+
throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, "iss", "mismatch");
|
|
3154
|
+
}
|
|
3155
|
+
if (protectedHeader.sub !== void 0 && protectedHeader.sub !== payload.sub) {
|
|
3156
|
+
throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, "sub", "mismatch");
|
|
3157
|
+
}
|
|
3158
|
+
if (protectedHeader.aud !== void 0 && JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
|
|
3159
|
+
throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, "aud", "mismatch");
|
|
3160
|
+
}
|
|
3161
|
+
const result = { payload, protectedHeader };
|
|
3162
|
+
if (typeof key === "function") {
|
|
3163
|
+
return { ...result, key: decrypted.key };
|
|
3164
|
+
}
|
|
3165
|
+
return result;
|
|
3166
|
+
}
|
|
3167
|
+
var init_decrypt5 = __esm({
|
|
3168
|
+
"../../../node_modules/jose/dist/webapi/jwt/decrypt.js"() {
|
|
3169
|
+
init_decrypt3();
|
|
3170
|
+
init_jwt_claims_set();
|
|
3171
|
+
init_errors();
|
|
3172
|
+
}
|
|
3173
|
+
});
|
|
3174
|
+
|
|
3175
|
+
// ../../../node_modules/jose/dist/webapi/jwe/compact/encrypt.js
|
|
3176
|
+
var CompactEncrypt;
|
|
3177
|
+
var init_encrypt4 = __esm({
|
|
3178
|
+
"../../../node_modules/jose/dist/webapi/jwe/compact/encrypt.js"() {
|
|
3179
|
+
init_encrypt2();
|
|
3180
|
+
CompactEncrypt = class {
|
|
3181
|
+
#flattened;
|
|
3182
|
+
constructor(plaintext) {
|
|
3183
|
+
this.#flattened = new FlattenedEncrypt(plaintext);
|
|
3184
|
+
}
|
|
3185
|
+
setContentEncryptionKey(cek) {
|
|
3186
|
+
this.#flattened.setContentEncryptionKey(cek);
|
|
3187
|
+
return this;
|
|
3188
|
+
}
|
|
3189
|
+
setInitializationVector(iv) {
|
|
3190
|
+
this.#flattened.setInitializationVector(iv);
|
|
3191
|
+
return this;
|
|
3192
|
+
}
|
|
3193
|
+
setProtectedHeader(protectedHeader) {
|
|
3194
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
3195
|
+
return this;
|
|
3196
|
+
}
|
|
3197
|
+
setKeyManagementParameters(parameters) {
|
|
3198
|
+
this.#flattened.setKeyManagementParameters(parameters);
|
|
3199
|
+
return this;
|
|
3200
|
+
}
|
|
3201
|
+
async encrypt(key, options) {
|
|
3202
|
+
const jwe = await this.#flattened.encrypt(key, options);
|
|
3203
|
+
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
3204
|
+
}
|
|
3205
|
+
};
|
|
3206
|
+
}
|
|
3207
|
+
});
|
|
3208
|
+
|
|
3209
|
+
// ../../../node_modules/jose/dist/webapi/lib/sign.js
|
|
3210
|
+
async function sign(alg, key, data) {
|
|
3211
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
3212
|
+
checkKeyLength(alg, cryptoKey);
|
|
3213
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm2(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
3214
|
+
return new Uint8Array(signature);
|
|
3215
|
+
}
|
|
3216
|
+
var init_sign = __esm({
|
|
3217
|
+
"../../../node_modules/jose/dist/webapi/lib/sign.js"() {
|
|
3218
|
+
init_subtle_dsa();
|
|
3219
|
+
init_check_key_length();
|
|
3220
|
+
init_get_sign_verify_key();
|
|
3221
|
+
}
|
|
3222
|
+
});
|
|
3223
|
+
|
|
3224
|
+
// ../../../node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
3225
|
+
var FlattenedSign;
|
|
3226
|
+
var init_sign2 = __esm({
|
|
3227
|
+
"../../../node_modules/jose/dist/webapi/jws/flattened/sign.js"() {
|
|
3228
|
+
init_base64url();
|
|
3229
|
+
init_sign();
|
|
3230
|
+
init_is_disjoint();
|
|
3231
|
+
init_errors();
|
|
3232
|
+
init_buffer_utils();
|
|
3233
|
+
init_check_key_type();
|
|
3234
|
+
init_validate_crit();
|
|
3235
|
+
init_normalize_key();
|
|
3236
|
+
FlattenedSign = class {
|
|
3237
|
+
#payload;
|
|
3238
|
+
#protectedHeader;
|
|
3239
|
+
#unprotectedHeader;
|
|
3240
|
+
constructor(payload) {
|
|
3241
|
+
if (!(payload instanceof Uint8Array)) {
|
|
3242
|
+
throw new TypeError("payload must be an instance of Uint8Array");
|
|
3243
|
+
}
|
|
3244
|
+
this.#payload = payload;
|
|
3245
|
+
}
|
|
3246
|
+
setProtectedHeader(protectedHeader) {
|
|
3247
|
+
if (this.#protectedHeader) {
|
|
3248
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
3249
|
+
}
|
|
3250
|
+
this.#protectedHeader = protectedHeader;
|
|
3251
|
+
return this;
|
|
3252
|
+
}
|
|
3253
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
3254
|
+
if (this.#unprotectedHeader) {
|
|
3255
|
+
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
3256
|
+
}
|
|
3257
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
3258
|
+
return this;
|
|
3259
|
+
}
|
|
3260
|
+
async sign(key, options) {
|
|
3261
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
3262
|
+
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
3263
|
+
}
|
|
3264
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
3265
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
3266
|
+
}
|
|
3267
|
+
const joseHeader = {
|
|
3268
|
+
...this.#protectedHeader,
|
|
3269
|
+
...this.#unprotectedHeader
|
|
3270
|
+
};
|
|
3271
|
+
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
3272
|
+
let b64 = true;
|
|
3273
|
+
if (extensions.has("b64")) {
|
|
3274
|
+
b64 = this.#protectedHeader.b64;
|
|
3275
|
+
if (typeof b64 !== "boolean") {
|
|
3276
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
3277
|
+
}
|
|
3278
|
+
}
|
|
3279
|
+
const { alg } = joseHeader;
|
|
3280
|
+
if (typeof alg !== "string" || !alg) {
|
|
3281
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
3282
|
+
}
|
|
3283
|
+
checkKeyType(alg, key, "sign");
|
|
3284
|
+
let payloadS;
|
|
3285
|
+
let payloadB;
|
|
3286
|
+
if (b64) {
|
|
3287
|
+
payloadS = encode2(this.#payload);
|
|
3288
|
+
payloadB = encode(payloadS);
|
|
3289
|
+
} else {
|
|
3290
|
+
payloadB = this.#payload;
|
|
3291
|
+
payloadS = "";
|
|
3292
|
+
}
|
|
3293
|
+
let protectedHeaderString;
|
|
3294
|
+
let protectedHeaderBytes;
|
|
3295
|
+
if (this.#protectedHeader) {
|
|
3296
|
+
protectedHeaderString = encode2(JSON.stringify(this.#protectedHeader));
|
|
3297
|
+
protectedHeaderBytes = encode(protectedHeaderString);
|
|
3298
|
+
} else {
|
|
3299
|
+
protectedHeaderString = "";
|
|
3300
|
+
protectedHeaderBytes = new Uint8Array();
|
|
3301
|
+
}
|
|
3302
|
+
const data = concat(protectedHeaderBytes, encode("."), payloadB);
|
|
3303
|
+
const k = await normalizeKey(key, alg);
|
|
3304
|
+
const signature = await sign(alg, k, data);
|
|
3305
|
+
const jws = {
|
|
3306
|
+
signature: encode2(signature),
|
|
3307
|
+
payload: payloadS
|
|
3308
|
+
};
|
|
3309
|
+
if (this.#unprotectedHeader) {
|
|
3310
|
+
jws.header = this.#unprotectedHeader;
|
|
3311
|
+
}
|
|
3312
|
+
if (this.#protectedHeader) {
|
|
3313
|
+
jws.protected = protectedHeaderString;
|
|
3314
|
+
}
|
|
3315
|
+
return jws;
|
|
3316
|
+
}
|
|
3317
|
+
};
|
|
3318
|
+
}
|
|
3319
|
+
});
|
|
3320
|
+
|
|
3321
|
+
// ../../../node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
3322
|
+
var CompactSign;
|
|
3323
|
+
var init_sign3 = __esm({
|
|
3324
|
+
"../../../node_modules/jose/dist/webapi/jws/compact/sign.js"() {
|
|
3325
|
+
init_sign2();
|
|
3326
|
+
CompactSign = class {
|
|
3327
|
+
#flattened;
|
|
3328
|
+
constructor(payload) {
|
|
3329
|
+
this.#flattened = new FlattenedSign(payload);
|
|
3330
|
+
}
|
|
3331
|
+
setProtectedHeader(protectedHeader) {
|
|
3332
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
3333
|
+
return this;
|
|
3334
|
+
}
|
|
3335
|
+
async sign(key, options) {
|
|
3336
|
+
const jws = await this.#flattened.sign(key, options);
|
|
3337
|
+
if (jws.payload === void 0) {
|
|
3338
|
+
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
3339
|
+
}
|
|
3340
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
}
|
|
3344
|
+
});
|
|
3345
|
+
|
|
3346
|
+
// ../../../node_modules/jose/dist/webapi/jws/general/sign.js
|
|
3347
|
+
var IndividualSignature, GeneralSign;
|
|
3348
|
+
var init_sign4 = __esm({
|
|
3349
|
+
"../../../node_modules/jose/dist/webapi/jws/general/sign.js"() {
|
|
3350
|
+
init_sign2();
|
|
3351
|
+
init_errors();
|
|
3352
|
+
IndividualSignature = class {
|
|
3353
|
+
#parent;
|
|
3354
|
+
protectedHeader;
|
|
3355
|
+
unprotectedHeader;
|
|
3356
|
+
options;
|
|
3357
|
+
key;
|
|
3358
|
+
constructor(sig, key, options) {
|
|
3359
|
+
this.#parent = sig;
|
|
3360
|
+
this.key = key;
|
|
3361
|
+
this.options = options;
|
|
3362
|
+
}
|
|
3363
|
+
setProtectedHeader(protectedHeader) {
|
|
3364
|
+
if (this.protectedHeader) {
|
|
3365
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
3366
|
+
}
|
|
3367
|
+
this.protectedHeader = protectedHeader;
|
|
3368
|
+
return this;
|
|
3369
|
+
}
|
|
3370
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
3371
|
+
if (this.unprotectedHeader) {
|
|
3372
|
+
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
3373
|
+
}
|
|
3374
|
+
this.unprotectedHeader = unprotectedHeader;
|
|
3375
|
+
return this;
|
|
3376
|
+
}
|
|
3377
|
+
addSignature(...args) {
|
|
3378
|
+
return this.#parent.addSignature(...args);
|
|
3379
|
+
}
|
|
3380
|
+
sign(...args) {
|
|
3381
|
+
return this.#parent.sign(...args);
|
|
3382
|
+
}
|
|
3383
|
+
done() {
|
|
3384
|
+
return this.#parent;
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
GeneralSign = class {
|
|
3388
|
+
#payload;
|
|
3389
|
+
#signatures = [];
|
|
3390
|
+
constructor(payload) {
|
|
3391
|
+
this.#payload = payload;
|
|
3392
|
+
}
|
|
3393
|
+
addSignature(key, options) {
|
|
3394
|
+
const signature = new IndividualSignature(this, key, options);
|
|
3395
|
+
this.#signatures.push(signature);
|
|
3396
|
+
return signature;
|
|
3397
|
+
}
|
|
3398
|
+
async sign() {
|
|
3399
|
+
if (!this.#signatures.length) {
|
|
3400
|
+
throw new JWSInvalid("at least one signature must be added");
|
|
3401
|
+
}
|
|
3402
|
+
const jws = {
|
|
3403
|
+
signatures: [],
|
|
3404
|
+
payload: ""
|
|
3405
|
+
};
|
|
3406
|
+
for (let i = 0; i < this.#signatures.length; i++) {
|
|
3407
|
+
const signature = this.#signatures[i];
|
|
3408
|
+
const flattened = new FlattenedSign(this.#payload);
|
|
3409
|
+
flattened.setProtectedHeader(signature.protectedHeader);
|
|
3410
|
+
flattened.setUnprotectedHeader(signature.unprotectedHeader);
|
|
3411
|
+
const { payload, ...rest } = await flattened.sign(signature.key, signature.options);
|
|
3412
|
+
if (i === 0) {
|
|
3413
|
+
jws.payload = payload;
|
|
3414
|
+
} else if (jws.payload !== payload) {
|
|
3415
|
+
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
3416
|
+
}
|
|
3417
|
+
jws.signatures.push(rest);
|
|
3418
|
+
}
|
|
3419
|
+
return jws;
|
|
3420
|
+
}
|
|
3421
|
+
};
|
|
3422
|
+
}
|
|
3423
|
+
});
|
|
3424
|
+
|
|
3425
|
+
// ../../../node_modules/jose/dist/webapi/jwt/sign.js
|
|
3426
|
+
var SignJWT;
|
|
3427
|
+
var init_sign5 = __esm({
|
|
3428
|
+
"../../../node_modules/jose/dist/webapi/jwt/sign.js"() {
|
|
3429
|
+
init_sign3();
|
|
3430
|
+
init_errors();
|
|
3431
|
+
init_jwt_claims_set();
|
|
3432
|
+
SignJWT = class {
|
|
3433
|
+
#protectedHeader;
|
|
3434
|
+
#jwt;
|
|
3435
|
+
constructor(payload = {}) {
|
|
3436
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3437
|
+
}
|
|
3438
|
+
setIssuer(issuer) {
|
|
3439
|
+
this.#jwt.iss = issuer;
|
|
3440
|
+
return this;
|
|
3441
|
+
}
|
|
3442
|
+
setSubject(subject) {
|
|
3443
|
+
this.#jwt.sub = subject;
|
|
3444
|
+
return this;
|
|
3445
|
+
}
|
|
3446
|
+
setAudience(audience) {
|
|
3447
|
+
this.#jwt.aud = audience;
|
|
3448
|
+
return this;
|
|
3449
|
+
}
|
|
3450
|
+
setJti(jwtId) {
|
|
3451
|
+
this.#jwt.jti = jwtId;
|
|
3452
|
+
return this;
|
|
3453
|
+
}
|
|
3454
|
+
setNotBefore(input) {
|
|
3455
|
+
this.#jwt.nbf = input;
|
|
3456
|
+
return this;
|
|
3457
|
+
}
|
|
3458
|
+
setExpirationTime(input) {
|
|
3459
|
+
this.#jwt.exp = input;
|
|
3460
|
+
return this;
|
|
3461
|
+
}
|
|
3462
|
+
setIssuedAt(input) {
|
|
3463
|
+
this.#jwt.iat = input;
|
|
3464
|
+
return this;
|
|
3465
|
+
}
|
|
3466
|
+
setProtectedHeader(protectedHeader) {
|
|
3467
|
+
this.#protectedHeader = protectedHeader;
|
|
3468
|
+
return this;
|
|
3469
|
+
}
|
|
3470
|
+
async sign(key, options) {
|
|
3471
|
+
const sig = new CompactSign(this.#jwt.data());
|
|
3472
|
+
sig.setProtectedHeader(this.#protectedHeader);
|
|
3473
|
+
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
|
|
3474
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3475
|
+
}
|
|
3476
|
+
return sig.sign(key, options);
|
|
3477
|
+
}
|
|
3478
|
+
};
|
|
3479
|
+
}
|
|
3480
|
+
});
|
|
3481
|
+
|
|
3482
|
+
// ../../../node_modules/jose/dist/webapi/jwt/encrypt.js
|
|
3483
|
+
var EncryptJWT;
|
|
3484
|
+
var init_encrypt5 = __esm({
|
|
3485
|
+
"../../../node_modules/jose/dist/webapi/jwt/encrypt.js"() {
|
|
3486
|
+
init_encrypt4();
|
|
3487
|
+
init_jwt_claims_set();
|
|
3488
|
+
EncryptJWT = class {
|
|
3489
|
+
#cek;
|
|
3490
|
+
#iv;
|
|
3491
|
+
#keyManagementParameters;
|
|
3492
|
+
#protectedHeader;
|
|
3493
|
+
#replicateIssuerAsHeader;
|
|
3494
|
+
#replicateSubjectAsHeader;
|
|
3495
|
+
#replicateAudienceAsHeader;
|
|
3496
|
+
#jwt;
|
|
3497
|
+
constructor(payload = {}) {
|
|
3498
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3499
|
+
}
|
|
3500
|
+
setIssuer(issuer) {
|
|
3501
|
+
this.#jwt.iss = issuer;
|
|
3502
|
+
return this;
|
|
3503
|
+
}
|
|
3504
|
+
setSubject(subject) {
|
|
3505
|
+
this.#jwt.sub = subject;
|
|
3506
|
+
return this;
|
|
3507
|
+
}
|
|
3508
|
+
setAudience(audience) {
|
|
3509
|
+
this.#jwt.aud = audience;
|
|
3510
|
+
return this;
|
|
3511
|
+
}
|
|
3512
|
+
setJti(jwtId) {
|
|
3513
|
+
this.#jwt.jti = jwtId;
|
|
3514
|
+
return this;
|
|
3515
|
+
}
|
|
3516
|
+
setNotBefore(input) {
|
|
3517
|
+
this.#jwt.nbf = input;
|
|
3518
|
+
return this;
|
|
3519
|
+
}
|
|
3520
|
+
setExpirationTime(input) {
|
|
3521
|
+
this.#jwt.exp = input;
|
|
3522
|
+
return this;
|
|
3523
|
+
}
|
|
3524
|
+
setIssuedAt(input) {
|
|
3525
|
+
this.#jwt.iat = input;
|
|
3526
|
+
return this;
|
|
3527
|
+
}
|
|
3528
|
+
setProtectedHeader(protectedHeader) {
|
|
3529
|
+
if (this.#protectedHeader) {
|
|
3530
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
3531
|
+
}
|
|
3532
|
+
this.#protectedHeader = protectedHeader;
|
|
3533
|
+
return this;
|
|
3534
|
+
}
|
|
3535
|
+
setKeyManagementParameters(parameters) {
|
|
3536
|
+
if (this.#keyManagementParameters) {
|
|
3537
|
+
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
3538
|
+
}
|
|
3539
|
+
this.#keyManagementParameters = parameters;
|
|
3540
|
+
return this;
|
|
3541
|
+
}
|
|
3542
|
+
setContentEncryptionKey(cek) {
|
|
3543
|
+
if (this.#cek) {
|
|
3544
|
+
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
3545
|
+
}
|
|
3546
|
+
this.#cek = cek;
|
|
3547
|
+
return this;
|
|
3548
|
+
}
|
|
3549
|
+
setInitializationVector(iv) {
|
|
3550
|
+
if (this.#iv) {
|
|
3551
|
+
throw new TypeError("setInitializationVector can only be called once");
|
|
3552
|
+
}
|
|
3553
|
+
this.#iv = iv;
|
|
3554
|
+
return this;
|
|
3555
|
+
}
|
|
3556
|
+
replicateIssuerAsHeader() {
|
|
3557
|
+
this.#replicateIssuerAsHeader = true;
|
|
3558
|
+
return this;
|
|
3559
|
+
}
|
|
3560
|
+
replicateSubjectAsHeader() {
|
|
3561
|
+
this.#replicateSubjectAsHeader = true;
|
|
3562
|
+
return this;
|
|
3563
|
+
}
|
|
3564
|
+
replicateAudienceAsHeader() {
|
|
3565
|
+
this.#replicateAudienceAsHeader = true;
|
|
3566
|
+
return this;
|
|
3567
|
+
}
|
|
3568
|
+
async encrypt(key, options) {
|
|
3569
|
+
const enc = new CompactEncrypt(this.#jwt.data());
|
|
3570
|
+
if (this.#protectedHeader && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
|
|
3571
|
+
this.#protectedHeader = {
|
|
3572
|
+
...this.#protectedHeader,
|
|
3573
|
+
iss: this.#replicateIssuerAsHeader ? this.#jwt.iss : void 0,
|
|
3574
|
+
sub: this.#replicateSubjectAsHeader ? this.#jwt.sub : void 0,
|
|
3575
|
+
aud: this.#replicateAudienceAsHeader ? this.#jwt.aud : void 0
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3578
|
+
enc.setProtectedHeader(this.#protectedHeader);
|
|
3579
|
+
if (this.#iv) {
|
|
3580
|
+
enc.setInitializationVector(this.#iv);
|
|
3581
|
+
}
|
|
3582
|
+
if (this.#cek) {
|
|
3583
|
+
enc.setContentEncryptionKey(this.#cek);
|
|
3584
|
+
}
|
|
3585
|
+
if (this.#keyManagementParameters) {
|
|
3586
|
+
enc.setKeyManagementParameters(this.#keyManagementParameters);
|
|
3587
|
+
}
|
|
3588
|
+
return enc.encrypt(key, options);
|
|
3589
|
+
}
|
|
3590
|
+
};
|
|
3591
|
+
}
|
|
3592
|
+
});
|
|
3593
|
+
|
|
3594
|
+
// ../../../node_modules/jose/dist/webapi/jwk/thumbprint.js
|
|
3595
|
+
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
3596
|
+
let jwk;
|
|
3597
|
+
if (isJWK(key)) {
|
|
3598
|
+
jwk = key;
|
|
3599
|
+
} else if (isKeyLike(key)) {
|
|
3600
|
+
jwk = await exportJWK(key);
|
|
3601
|
+
} else {
|
|
3602
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
3603
|
+
}
|
|
3604
|
+
digestAlgorithm ??= "sha256";
|
|
3605
|
+
if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") {
|
|
3606
|
+
throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
|
|
3607
|
+
}
|
|
3608
|
+
let components;
|
|
3609
|
+
switch (jwk.kty) {
|
|
3610
|
+
case "AKP":
|
|
3611
|
+
check(jwk.alg, '"alg" (Algorithm) Parameter');
|
|
3612
|
+
check(jwk.pub, '"pub" (Public key) Parameter');
|
|
3613
|
+
components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
|
|
3614
|
+
break;
|
|
3615
|
+
case "EC":
|
|
3616
|
+
check(jwk.crv, '"crv" (Curve) Parameter');
|
|
3617
|
+
check(jwk.x, '"x" (X Coordinate) Parameter');
|
|
3618
|
+
check(jwk.y, '"y" (Y Coordinate) Parameter');
|
|
3619
|
+
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
3620
|
+
break;
|
|
3621
|
+
case "OKP":
|
|
3622
|
+
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
|
|
3623
|
+
check(jwk.x, '"x" (Public Key) Parameter');
|
|
3624
|
+
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
3625
|
+
break;
|
|
3626
|
+
case "RSA":
|
|
3627
|
+
check(jwk.e, '"e" (Exponent) Parameter');
|
|
3628
|
+
check(jwk.n, '"n" (Modulus) Parameter');
|
|
3629
|
+
components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
3630
|
+
break;
|
|
3631
|
+
case "oct":
|
|
3632
|
+
check(jwk.k, '"k" (Key Value) Parameter');
|
|
3633
|
+
components = { k: jwk.k, kty: jwk.kty };
|
|
3634
|
+
break;
|
|
3635
|
+
default:
|
|
3636
|
+
throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
|
|
3637
|
+
}
|
|
3638
|
+
const data = encode(JSON.stringify(components));
|
|
3639
|
+
return encode2(await digest(digestAlgorithm, data));
|
|
3640
|
+
}
|
|
3641
|
+
async function calculateJwkThumbprintUri(key, digestAlgorithm) {
|
|
3642
|
+
digestAlgorithm ??= "sha256";
|
|
3643
|
+
const thumbprint = await calculateJwkThumbprint(key, digestAlgorithm);
|
|
3644
|
+
return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;
|
|
3645
|
+
}
|
|
3646
|
+
var check;
|
|
3647
|
+
var init_thumbprint = __esm({
|
|
3648
|
+
"../../../node_modules/jose/dist/webapi/jwk/thumbprint.js"() {
|
|
3649
|
+
init_digest();
|
|
3650
|
+
init_base64url();
|
|
3651
|
+
init_errors();
|
|
3652
|
+
init_buffer_utils();
|
|
3653
|
+
init_is_key_like();
|
|
3654
|
+
init_is_jwk();
|
|
3655
|
+
init_export();
|
|
3656
|
+
init_invalid_key_input();
|
|
3657
|
+
check = (value, description) => {
|
|
3658
|
+
if (typeof value !== "string" || !value) {
|
|
3659
|
+
throw new JWKInvalid(`${description} missing or invalid`);
|
|
3660
|
+
}
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
});
|
|
3664
|
+
|
|
3665
|
+
// ../../../node_modules/jose/dist/webapi/jwk/embedded.js
|
|
3666
|
+
async function EmbeddedJWK(protectedHeader, token) {
|
|
3667
|
+
const joseHeader = {
|
|
3668
|
+
...protectedHeader,
|
|
3669
|
+
...token?.header
|
|
3670
|
+
};
|
|
3671
|
+
if (!isObject(joseHeader.jwk)) {
|
|
3672
|
+
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
|
|
3673
|
+
}
|
|
3674
|
+
const key = await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg);
|
|
3675
|
+
if (key instanceof Uint8Array || key.type !== "public") {
|
|
3676
|
+
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
|
|
3677
|
+
}
|
|
3678
|
+
return key;
|
|
3679
|
+
}
|
|
3680
|
+
var init_embedded = __esm({
|
|
3681
|
+
"../../../node_modules/jose/dist/webapi/jwk/embedded.js"() {
|
|
3682
|
+
init_import();
|
|
3683
|
+
init_is_object();
|
|
3684
|
+
init_errors();
|
|
3685
|
+
}
|
|
3686
|
+
});
|
|
3687
|
+
|
|
3688
|
+
// ../../../node_modules/jose/dist/webapi/jwks/local.js
|
|
3689
|
+
function getKtyFromAlg(alg) {
|
|
3690
|
+
switch (typeof alg === "string" && alg.slice(0, 2)) {
|
|
3691
|
+
case "RS":
|
|
3692
|
+
case "PS":
|
|
3693
|
+
return "RSA";
|
|
3694
|
+
case "ES":
|
|
3695
|
+
return "EC";
|
|
3696
|
+
case "Ed":
|
|
3697
|
+
return "OKP";
|
|
3698
|
+
case "ML":
|
|
3699
|
+
return "AKP";
|
|
3700
|
+
default:
|
|
3701
|
+
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
function isJWKSLike(jwks) {
|
|
3705
|
+
return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
|
|
3706
|
+
}
|
|
3707
|
+
function isJWKLike(key) {
|
|
3708
|
+
return isObject(key);
|
|
3709
|
+
}
|
|
3710
|
+
async function importWithAlgCache(cache2, jwk, alg) {
|
|
3711
|
+
const cached = cache2.get(jwk) || cache2.set(jwk, {}).get(jwk);
|
|
3712
|
+
if (cached[alg] === void 0) {
|
|
3713
|
+
const key = await importJWK({ ...jwk, ext: true }, alg);
|
|
3714
|
+
if (key instanceof Uint8Array || key.type !== "public") {
|
|
3715
|
+
throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
3716
|
+
}
|
|
3717
|
+
cached[alg] = key;
|
|
3718
|
+
}
|
|
3719
|
+
return cached[alg];
|
|
3720
|
+
}
|
|
3721
|
+
function createLocalJWKSet(jwks) {
|
|
3722
|
+
const set = new LocalJWKSet(jwks);
|
|
3723
|
+
const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
3724
|
+
Object.defineProperties(localJWKSet, {
|
|
3725
|
+
jwks: {
|
|
3726
|
+
value: () => structuredClone(set.jwks()),
|
|
3727
|
+
enumerable: false,
|
|
3728
|
+
configurable: false,
|
|
3729
|
+
writable: false
|
|
3730
|
+
}
|
|
3731
|
+
});
|
|
3732
|
+
return localJWKSet;
|
|
3733
|
+
}
|
|
3734
|
+
var LocalJWKSet;
|
|
3735
|
+
var init_local = __esm({
|
|
3736
|
+
"../../../node_modules/jose/dist/webapi/jwks/local.js"() {
|
|
3737
|
+
init_import();
|
|
3738
|
+
init_errors();
|
|
3739
|
+
init_is_object();
|
|
3740
|
+
LocalJWKSet = class {
|
|
3741
|
+
#jwks;
|
|
3742
|
+
#cached = /* @__PURE__ */ new WeakMap();
|
|
3743
|
+
constructor(jwks) {
|
|
3744
|
+
if (!isJWKSLike(jwks)) {
|
|
3745
|
+
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
3746
|
+
}
|
|
3747
|
+
this.#jwks = structuredClone(jwks);
|
|
3748
|
+
}
|
|
3749
|
+
jwks() {
|
|
3750
|
+
return this.#jwks;
|
|
3751
|
+
}
|
|
3752
|
+
async getKey(protectedHeader, token) {
|
|
3753
|
+
const { alg, kid } = { ...protectedHeader, ...token?.header };
|
|
3754
|
+
const kty = getKtyFromAlg(alg);
|
|
3755
|
+
const candidates = this.#jwks.keys.filter((jwk2) => {
|
|
3756
|
+
let candidate = kty === jwk2.kty;
|
|
3757
|
+
if (candidate && typeof kid === "string") {
|
|
3758
|
+
candidate = kid === jwk2.kid;
|
|
3759
|
+
}
|
|
3760
|
+
if (candidate && (typeof jwk2.alg === "string" || kty === "AKP")) {
|
|
3761
|
+
candidate = alg === jwk2.alg;
|
|
3762
|
+
}
|
|
3763
|
+
if (candidate && typeof jwk2.use === "string") {
|
|
3764
|
+
candidate = jwk2.use === "sig";
|
|
3765
|
+
}
|
|
3766
|
+
if (candidate && Array.isArray(jwk2.key_ops)) {
|
|
3767
|
+
candidate = jwk2.key_ops.includes("verify");
|
|
3768
|
+
}
|
|
3769
|
+
if (candidate) {
|
|
3770
|
+
switch (alg) {
|
|
3771
|
+
case "ES256":
|
|
3772
|
+
candidate = jwk2.crv === "P-256";
|
|
3773
|
+
break;
|
|
3774
|
+
case "ES384":
|
|
3775
|
+
candidate = jwk2.crv === "P-384";
|
|
3776
|
+
break;
|
|
3777
|
+
case "ES512":
|
|
3778
|
+
candidate = jwk2.crv === "P-521";
|
|
3779
|
+
break;
|
|
3780
|
+
case "Ed25519":
|
|
3781
|
+
case "EdDSA":
|
|
3782
|
+
candidate = jwk2.crv === "Ed25519";
|
|
3783
|
+
break;
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
return candidate;
|
|
3787
|
+
});
|
|
3788
|
+
const { 0: jwk, length } = candidates;
|
|
3789
|
+
if (length === 0) {
|
|
3790
|
+
throw new JWKSNoMatchingKey();
|
|
3791
|
+
}
|
|
3792
|
+
if (length !== 1) {
|
|
3793
|
+
const error = new JWKSMultipleMatchingKeys();
|
|
3794
|
+
const _cached = this.#cached;
|
|
3795
|
+
error[Symbol.asyncIterator] = async function* () {
|
|
3796
|
+
for (const jwk2 of candidates) {
|
|
3797
|
+
try {
|
|
3798
|
+
yield await importWithAlgCache(_cached, jwk2, alg);
|
|
3799
|
+
} catch {
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
};
|
|
3803
|
+
throw error;
|
|
3804
|
+
}
|
|
3805
|
+
return importWithAlgCache(this.#cached, jwk, alg);
|
|
3806
|
+
}
|
|
3807
|
+
};
|
|
3808
|
+
}
|
|
3809
|
+
});
|
|
3810
|
+
|
|
3811
|
+
// ../../../node_modules/jose/dist/webapi/jwks/remote.js
|
|
3812
|
+
function isCloudflareWorkers() {
|
|
3813
|
+
return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
|
|
3814
|
+
}
|
|
3815
|
+
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
3816
|
+
const response = await fetchImpl(url, {
|
|
3817
|
+
method: "GET",
|
|
3818
|
+
signal,
|
|
3819
|
+
redirect: "manual",
|
|
3820
|
+
headers
|
|
3821
|
+
}).catch((err) => {
|
|
3822
|
+
if (err.name === "TimeoutError") {
|
|
3823
|
+
throw new JWKSTimeout();
|
|
3824
|
+
}
|
|
3825
|
+
throw err;
|
|
3826
|
+
});
|
|
3827
|
+
if (response.status !== 200) {
|
|
3828
|
+
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
3829
|
+
}
|
|
3830
|
+
try {
|
|
3831
|
+
return await response.json();
|
|
3832
|
+
} catch {
|
|
3833
|
+
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
function isFreshJwksCache(input, cacheMaxAge) {
|
|
3837
|
+
if (typeof input !== "object" || input === null) {
|
|
3838
|
+
return false;
|
|
3839
|
+
}
|
|
3840
|
+
if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) {
|
|
3841
|
+
return false;
|
|
3842
|
+
}
|
|
3843
|
+
if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) {
|
|
3844
|
+
return false;
|
|
3845
|
+
}
|
|
3846
|
+
return true;
|
|
3847
|
+
}
|
|
3848
|
+
function createRemoteJWKSet(url, options) {
|
|
3849
|
+
const set = new RemoteJWKSet(url, options);
|
|
3850
|
+
const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
3851
|
+
Object.defineProperties(remoteJWKSet, {
|
|
3852
|
+
coolingDown: {
|
|
3853
|
+
get: () => set.coolingDown(),
|
|
3854
|
+
enumerable: true,
|
|
3855
|
+
configurable: false
|
|
3856
|
+
},
|
|
3857
|
+
fresh: {
|
|
3858
|
+
get: () => set.fresh(),
|
|
3859
|
+
enumerable: true,
|
|
3860
|
+
configurable: false
|
|
3861
|
+
},
|
|
3862
|
+
reload: {
|
|
3863
|
+
value: () => set.reload(),
|
|
3864
|
+
enumerable: true,
|
|
3865
|
+
configurable: false,
|
|
3866
|
+
writable: false
|
|
3867
|
+
},
|
|
3868
|
+
reloading: {
|
|
3869
|
+
get: () => set.pendingFetch(),
|
|
3870
|
+
enumerable: true,
|
|
3871
|
+
configurable: false
|
|
3872
|
+
},
|
|
3873
|
+
jwks: {
|
|
3874
|
+
value: () => set.jwks(),
|
|
3875
|
+
enumerable: true,
|
|
3876
|
+
configurable: false,
|
|
3877
|
+
writable: false
|
|
3878
|
+
}
|
|
3879
|
+
});
|
|
3880
|
+
return remoteJWKSet;
|
|
3881
|
+
}
|
|
3882
|
+
var USER_AGENT, customFetch, jwksCache, RemoteJWKSet;
|
|
3883
|
+
var init_remote = __esm({
|
|
3884
|
+
"../../../node_modules/jose/dist/webapi/jwks/remote.js"() {
|
|
3885
|
+
init_errors();
|
|
3886
|
+
init_local();
|
|
3887
|
+
init_is_object();
|
|
3888
|
+
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
|
|
3889
|
+
const NAME = "jose";
|
|
3890
|
+
const VERSION = "v6.1.3";
|
|
3891
|
+
USER_AGENT = `${NAME}/${VERSION}`;
|
|
3892
|
+
}
|
|
3893
|
+
customFetch = /* @__PURE__ */ Symbol();
|
|
3894
|
+
jwksCache = /* @__PURE__ */ Symbol();
|
|
3895
|
+
RemoteJWKSet = class {
|
|
3896
|
+
#url;
|
|
3897
|
+
#timeoutDuration;
|
|
3898
|
+
#cooldownDuration;
|
|
3899
|
+
#cacheMaxAge;
|
|
3900
|
+
#jwksTimestamp;
|
|
3901
|
+
#pendingFetch;
|
|
3902
|
+
#headers;
|
|
3903
|
+
#customFetch;
|
|
3904
|
+
#local;
|
|
3905
|
+
#cache;
|
|
3906
|
+
constructor(url, options) {
|
|
3907
|
+
if (!(url instanceof URL)) {
|
|
3908
|
+
throw new TypeError("url must be an instance of URL");
|
|
3909
|
+
}
|
|
3910
|
+
this.#url = new URL(url.href);
|
|
3911
|
+
this.#timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
|
|
3912
|
+
this.#cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
|
|
3913
|
+
this.#cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
|
|
3914
|
+
this.#headers = new Headers(options?.headers);
|
|
3915
|
+
if (USER_AGENT && !this.#headers.has("User-Agent")) {
|
|
3916
|
+
this.#headers.set("User-Agent", USER_AGENT);
|
|
3917
|
+
}
|
|
3918
|
+
if (!this.#headers.has("accept")) {
|
|
3919
|
+
this.#headers.set("accept", "application/json");
|
|
3920
|
+
this.#headers.append("accept", "application/jwk-set+json");
|
|
3921
|
+
}
|
|
3922
|
+
this.#customFetch = options?.[customFetch];
|
|
3923
|
+
if (options?.[jwksCache] !== void 0) {
|
|
3924
|
+
this.#cache = options?.[jwksCache];
|
|
3925
|
+
if (isFreshJwksCache(options?.[jwksCache], this.#cacheMaxAge)) {
|
|
3926
|
+
this.#jwksTimestamp = this.#cache.uat;
|
|
3927
|
+
this.#local = createLocalJWKSet(this.#cache.jwks);
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
pendingFetch() {
|
|
3932
|
+
return !!this.#pendingFetch;
|
|
3933
|
+
}
|
|
3934
|
+
coolingDown() {
|
|
3935
|
+
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cooldownDuration : false;
|
|
3936
|
+
}
|
|
3937
|
+
fresh() {
|
|
3938
|
+
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cacheMaxAge : false;
|
|
3939
|
+
}
|
|
3940
|
+
jwks() {
|
|
3941
|
+
return this.#local?.jwks();
|
|
3942
|
+
}
|
|
3943
|
+
async getKey(protectedHeader, token) {
|
|
3944
|
+
if (!this.#local || !this.fresh()) {
|
|
3945
|
+
await this.reload();
|
|
3946
|
+
}
|
|
3947
|
+
try {
|
|
3948
|
+
return await this.#local(protectedHeader, token);
|
|
3949
|
+
} catch (err) {
|
|
3950
|
+
if (err instanceof JWKSNoMatchingKey) {
|
|
3951
|
+
if (this.coolingDown() === false) {
|
|
3952
|
+
await this.reload();
|
|
3953
|
+
return this.#local(protectedHeader, token);
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
throw err;
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
async reload() {
|
|
3960
|
+
if (this.#pendingFetch && isCloudflareWorkers()) {
|
|
3961
|
+
this.#pendingFetch = void 0;
|
|
3962
|
+
}
|
|
3963
|
+
this.#pendingFetch ||= fetchJwks(this.#url.href, this.#headers, AbortSignal.timeout(this.#timeoutDuration), this.#customFetch).then((json) => {
|
|
3964
|
+
this.#local = createLocalJWKSet(json);
|
|
3965
|
+
if (this.#cache) {
|
|
3966
|
+
this.#cache.uat = Date.now();
|
|
3967
|
+
this.#cache.jwks = json;
|
|
3968
|
+
}
|
|
3969
|
+
this.#jwksTimestamp = Date.now();
|
|
3970
|
+
this.#pendingFetch = void 0;
|
|
3971
|
+
}).catch((err) => {
|
|
3972
|
+
this.#pendingFetch = void 0;
|
|
3973
|
+
throw err;
|
|
3974
|
+
});
|
|
3975
|
+
await this.#pendingFetch;
|
|
3976
|
+
}
|
|
3977
|
+
};
|
|
3978
|
+
}
|
|
3979
|
+
});
|
|
3980
|
+
|
|
3981
|
+
// ../../../node_modules/jose/dist/webapi/jwt/unsecured.js
|
|
3982
|
+
var UnsecuredJWT;
|
|
3983
|
+
var init_unsecured = __esm({
|
|
3984
|
+
"../../../node_modules/jose/dist/webapi/jwt/unsecured.js"() {
|
|
3985
|
+
init_base64url();
|
|
3986
|
+
init_buffer_utils();
|
|
3987
|
+
init_errors();
|
|
3988
|
+
init_jwt_claims_set();
|
|
3989
|
+
UnsecuredJWT = class {
|
|
3990
|
+
#jwt;
|
|
3991
|
+
constructor(payload = {}) {
|
|
3992
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3993
|
+
}
|
|
3994
|
+
encode() {
|
|
3995
|
+
const header = encode2(JSON.stringify({ alg: "none" }));
|
|
3996
|
+
const payload = encode2(this.#jwt.data());
|
|
3997
|
+
return `${header}.${payload}.`;
|
|
3998
|
+
}
|
|
3999
|
+
setIssuer(issuer) {
|
|
4000
|
+
this.#jwt.iss = issuer;
|
|
4001
|
+
return this;
|
|
4002
|
+
}
|
|
4003
|
+
setSubject(subject) {
|
|
4004
|
+
this.#jwt.sub = subject;
|
|
4005
|
+
return this;
|
|
4006
|
+
}
|
|
4007
|
+
setAudience(audience) {
|
|
4008
|
+
this.#jwt.aud = audience;
|
|
4009
|
+
return this;
|
|
4010
|
+
}
|
|
4011
|
+
setJti(jwtId) {
|
|
4012
|
+
this.#jwt.jti = jwtId;
|
|
4013
|
+
return this;
|
|
4014
|
+
}
|
|
4015
|
+
setNotBefore(input) {
|
|
4016
|
+
this.#jwt.nbf = input;
|
|
4017
|
+
return this;
|
|
4018
|
+
}
|
|
4019
|
+
setExpirationTime(input) {
|
|
4020
|
+
this.#jwt.exp = input;
|
|
4021
|
+
return this;
|
|
4022
|
+
}
|
|
4023
|
+
setIssuedAt(input) {
|
|
4024
|
+
this.#jwt.iat = input;
|
|
4025
|
+
return this;
|
|
4026
|
+
}
|
|
4027
|
+
static decode(jwt, options) {
|
|
4028
|
+
if (typeof jwt !== "string") {
|
|
4029
|
+
throw new JWTInvalid("Unsecured JWT must be a string");
|
|
4030
|
+
}
|
|
4031
|
+
const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
|
|
4032
|
+
if (length !== 3 || signature !== "") {
|
|
4033
|
+
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
4034
|
+
}
|
|
4035
|
+
let header;
|
|
4036
|
+
try {
|
|
4037
|
+
header = JSON.parse(decoder.decode(decode(encodedHeader)));
|
|
4038
|
+
if (header.alg !== "none")
|
|
4039
|
+
throw new Error();
|
|
4040
|
+
} catch {
|
|
4041
|
+
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
4042
|
+
}
|
|
4043
|
+
const payload = validateClaimsSet(header, decode(encodedPayload), options);
|
|
4044
|
+
return { payload, header };
|
|
4045
|
+
}
|
|
4046
|
+
};
|
|
4047
|
+
}
|
|
4048
|
+
});
|
|
4049
|
+
|
|
4050
|
+
// ../../../node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
4051
|
+
function decodeProtectedHeader(token) {
|
|
4052
|
+
let protectedB64u;
|
|
4053
|
+
if (typeof token === "string") {
|
|
4054
|
+
const parts = token.split(".");
|
|
4055
|
+
if (parts.length === 3 || parts.length === 5) {
|
|
4056
|
+
[protectedB64u] = parts;
|
|
4057
|
+
}
|
|
4058
|
+
} else if (typeof token === "object" && token) {
|
|
4059
|
+
if ("protected" in token) {
|
|
4060
|
+
protectedB64u = token.protected;
|
|
4061
|
+
} else {
|
|
4062
|
+
throw new TypeError("Token does not contain a Protected Header");
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
try {
|
|
4066
|
+
if (typeof protectedB64u !== "string" || !protectedB64u) {
|
|
4067
|
+
throw new Error();
|
|
4068
|
+
}
|
|
4069
|
+
const result = JSON.parse(decoder.decode(decode(protectedB64u)));
|
|
4070
|
+
if (!isObject(result)) {
|
|
4071
|
+
throw new Error();
|
|
4072
|
+
}
|
|
4073
|
+
return result;
|
|
4074
|
+
} catch {
|
|
4075
|
+
throw new TypeError("Invalid Token or Protected Header formatting");
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
var init_decode_protected_header = __esm({
|
|
4079
|
+
"../../../node_modules/jose/dist/webapi/util/decode_protected_header.js"() {
|
|
4080
|
+
init_base64url();
|
|
4081
|
+
init_buffer_utils();
|
|
4082
|
+
init_is_object();
|
|
4083
|
+
}
|
|
4084
|
+
});
|
|
4085
|
+
|
|
4086
|
+
// ../../../node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
4087
|
+
function decodeJwt(jwt) {
|
|
4088
|
+
if (typeof jwt !== "string")
|
|
4089
|
+
throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
4090
|
+
const { 1: payload, length } = jwt.split(".");
|
|
4091
|
+
if (length === 5)
|
|
4092
|
+
throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
|
|
4093
|
+
if (length !== 3)
|
|
4094
|
+
throw new JWTInvalid("Invalid JWT");
|
|
4095
|
+
if (!payload)
|
|
4096
|
+
throw new JWTInvalid("JWTs must contain a payload");
|
|
4097
|
+
let decoded;
|
|
4098
|
+
try {
|
|
4099
|
+
decoded = decode(payload);
|
|
4100
|
+
} catch {
|
|
4101
|
+
throw new JWTInvalid("Failed to base64url decode the payload");
|
|
4102
|
+
}
|
|
4103
|
+
let result;
|
|
4104
|
+
try {
|
|
4105
|
+
result = JSON.parse(decoder.decode(decoded));
|
|
4106
|
+
} catch {
|
|
4107
|
+
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
4108
|
+
}
|
|
4109
|
+
if (!isObject(result))
|
|
4110
|
+
throw new JWTInvalid("Invalid JWT Claims Set");
|
|
4111
|
+
return result;
|
|
4112
|
+
}
|
|
4113
|
+
var init_decode_jwt = __esm({
|
|
4114
|
+
"../../../node_modules/jose/dist/webapi/util/decode_jwt.js"() {
|
|
4115
|
+
init_base64url();
|
|
4116
|
+
init_buffer_utils();
|
|
4117
|
+
init_is_object();
|
|
4118
|
+
init_errors();
|
|
4119
|
+
}
|
|
4120
|
+
});
|
|
4121
|
+
|
|
4122
|
+
// ../../../node_modules/jose/dist/webapi/key/generate_key_pair.js
|
|
4123
|
+
function getModulusLengthOption(options) {
|
|
4124
|
+
const modulusLength = options?.modulusLength ?? 2048;
|
|
4125
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
4126
|
+
throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
|
|
4127
|
+
}
|
|
4128
|
+
return modulusLength;
|
|
4129
|
+
}
|
|
4130
|
+
async function generateKeyPair(alg, options) {
|
|
4131
|
+
let algorithm;
|
|
4132
|
+
let keyUsages;
|
|
4133
|
+
switch (alg) {
|
|
4134
|
+
case "PS256":
|
|
4135
|
+
case "PS384":
|
|
4136
|
+
case "PS512":
|
|
4137
|
+
algorithm = {
|
|
4138
|
+
name: "RSA-PSS",
|
|
4139
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
4140
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
4141
|
+
modulusLength: getModulusLengthOption(options)
|
|
4142
|
+
};
|
|
4143
|
+
keyUsages = ["sign", "verify"];
|
|
4144
|
+
break;
|
|
4145
|
+
case "RS256":
|
|
4146
|
+
case "RS384":
|
|
4147
|
+
case "RS512":
|
|
4148
|
+
algorithm = {
|
|
4149
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
4150
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
4151
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
4152
|
+
modulusLength: getModulusLengthOption(options)
|
|
4153
|
+
};
|
|
4154
|
+
keyUsages = ["sign", "verify"];
|
|
4155
|
+
break;
|
|
4156
|
+
case "RSA-OAEP":
|
|
4157
|
+
case "RSA-OAEP-256":
|
|
4158
|
+
case "RSA-OAEP-384":
|
|
4159
|
+
case "RSA-OAEP-512":
|
|
4160
|
+
algorithm = {
|
|
4161
|
+
name: "RSA-OAEP",
|
|
4162
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
|
|
4163
|
+
publicExponent: Uint8Array.of(1, 0, 1),
|
|
4164
|
+
modulusLength: getModulusLengthOption(options)
|
|
4165
|
+
};
|
|
4166
|
+
keyUsages = ["decrypt", "unwrapKey", "encrypt", "wrapKey"];
|
|
4167
|
+
break;
|
|
4168
|
+
case "ES256":
|
|
4169
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
4170
|
+
keyUsages = ["sign", "verify"];
|
|
4171
|
+
break;
|
|
4172
|
+
case "ES384":
|
|
4173
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
4174
|
+
keyUsages = ["sign", "verify"];
|
|
4175
|
+
break;
|
|
4176
|
+
case "ES512":
|
|
4177
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
4178
|
+
keyUsages = ["sign", "verify"];
|
|
4179
|
+
break;
|
|
4180
|
+
case "Ed25519":
|
|
4181
|
+
case "EdDSA": {
|
|
4182
|
+
keyUsages = ["sign", "verify"];
|
|
4183
|
+
algorithm = { name: "Ed25519" };
|
|
4184
|
+
break;
|
|
4185
|
+
}
|
|
4186
|
+
case "ML-DSA-44":
|
|
4187
|
+
case "ML-DSA-65":
|
|
4188
|
+
case "ML-DSA-87": {
|
|
4189
|
+
keyUsages = ["sign", "verify"];
|
|
4190
|
+
algorithm = { name: alg };
|
|
4191
|
+
break;
|
|
4192
|
+
}
|
|
4193
|
+
case "ECDH-ES":
|
|
4194
|
+
case "ECDH-ES+A128KW":
|
|
4195
|
+
case "ECDH-ES+A192KW":
|
|
4196
|
+
case "ECDH-ES+A256KW": {
|
|
4197
|
+
keyUsages = ["deriveBits"];
|
|
4198
|
+
const crv = options?.crv ?? "P-256";
|
|
4199
|
+
switch (crv) {
|
|
4200
|
+
case "P-256":
|
|
4201
|
+
case "P-384":
|
|
4202
|
+
case "P-521": {
|
|
4203
|
+
algorithm = { name: "ECDH", namedCurve: crv };
|
|
4204
|
+
break;
|
|
4205
|
+
}
|
|
4206
|
+
case "X25519":
|
|
4207
|
+
algorithm = { name: "X25519" };
|
|
4208
|
+
break;
|
|
4209
|
+
default:
|
|
4210
|
+
throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
|
|
4211
|
+
}
|
|
4212
|
+
break;
|
|
4213
|
+
}
|
|
4214
|
+
default:
|
|
4215
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
4216
|
+
}
|
|
4217
|
+
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
|
|
4218
|
+
}
|
|
4219
|
+
var init_generate_key_pair = __esm({
|
|
4220
|
+
"../../../node_modules/jose/dist/webapi/key/generate_key_pair.js"() {
|
|
4221
|
+
init_errors();
|
|
4222
|
+
}
|
|
4223
|
+
});
|
|
4224
|
+
|
|
4225
|
+
// ../../../node_modules/jose/dist/webapi/key/generate_secret.js
|
|
4226
|
+
async function generateSecret(alg, options) {
|
|
4227
|
+
let length;
|
|
4228
|
+
let algorithm;
|
|
4229
|
+
let keyUsages;
|
|
4230
|
+
switch (alg) {
|
|
4231
|
+
case "HS256":
|
|
4232
|
+
case "HS384":
|
|
4233
|
+
case "HS512":
|
|
4234
|
+
length = parseInt(alg.slice(-3), 10);
|
|
4235
|
+
algorithm = { name: "HMAC", hash: `SHA-${length}`, length };
|
|
4236
|
+
keyUsages = ["sign", "verify"];
|
|
4237
|
+
break;
|
|
4238
|
+
case "A128CBC-HS256":
|
|
4239
|
+
case "A192CBC-HS384":
|
|
4240
|
+
case "A256CBC-HS512":
|
|
4241
|
+
length = parseInt(alg.slice(-3), 10);
|
|
4242
|
+
return crypto.getRandomValues(new Uint8Array(length >> 3));
|
|
4243
|
+
case "A128KW":
|
|
4244
|
+
case "A192KW":
|
|
4245
|
+
case "A256KW":
|
|
4246
|
+
length = parseInt(alg.slice(1, 4), 10);
|
|
4247
|
+
algorithm = { name: "AES-KW", length };
|
|
4248
|
+
keyUsages = ["wrapKey", "unwrapKey"];
|
|
4249
|
+
break;
|
|
4250
|
+
case "A128GCMKW":
|
|
4251
|
+
case "A192GCMKW":
|
|
4252
|
+
case "A256GCMKW":
|
|
4253
|
+
case "A128GCM":
|
|
4254
|
+
case "A192GCM":
|
|
4255
|
+
case "A256GCM":
|
|
4256
|
+
length = parseInt(alg.slice(1, 4), 10);
|
|
4257
|
+
algorithm = { name: "AES-GCM", length };
|
|
4258
|
+
keyUsages = ["encrypt", "decrypt"];
|
|
4259
|
+
break;
|
|
4260
|
+
default:
|
|
4261
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
4262
|
+
}
|
|
4263
|
+
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
|
|
4264
|
+
}
|
|
4265
|
+
var init_generate_secret = __esm({
|
|
4266
|
+
"../../../node_modules/jose/dist/webapi/key/generate_secret.js"() {
|
|
4267
|
+
init_errors();
|
|
4268
|
+
}
|
|
4269
|
+
});
|
|
4270
|
+
|
|
4271
|
+
// ../../../node_modules/jose/dist/webapi/index.js
|
|
4272
|
+
var webapi_exports = {};
|
|
4273
|
+
__export(webapi_exports, {
|
|
4274
|
+
CompactEncrypt: () => CompactEncrypt,
|
|
4275
|
+
CompactSign: () => CompactSign,
|
|
4276
|
+
EmbeddedJWK: () => EmbeddedJWK,
|
|
4277
|
+
EncryptJWT: () => EncryptJWT,
|
|
4278
|
+
FlattenedEncrypt: () => FlattenedEncrypt,
|
|
4279
|
+
FlattenedSign: () => FlattenedSign,
|
|
4280
|
+
GeneralEncrypt: () => GeneralEncrypt,
|
|
4281
|
+
GeneralSign: () => GeneralSign,
|
|
4282
|
+
SignJWT: () => SignJWT,
|
|
4283
|
+
UnsecuredJWT: () => UnsecuredJWT,
|
|
4284
|
+
base64url: () => base64url_exports,
|
|
4285
|
+
calculateJwkThumbprint: () => calculateJwkThumbprint,
|
|
4286
|
+
calculateJwkThumbprintUri: () => calculateJwkThumbprintUri,
|
|
4287
|
+
compactDecrypt: () => compactDecrypt,
|
|
4288
|
+
compactVerify: () => compactVerify,
|
|
4289
|
+
createLocalJWKSet: () => createLocalJWKSet,
|
|
4290
|
+
createRemoteJWKSet: () => createRemoteJWKSet,
|
|
4291
|
+
cryptoRuntime: () => cryptoRuntime,
|
|
4292
|
+
customFetch: () => customFetch,
|
|
4293
|
+
decodeJwt: () => decodeJwt,
|
|
4294
|
+
decodeProtectedHeader: () => decodeProtectedHeader,
|
|
4295
|
+
errors: () => errors_exports,
|
|
4296
|
+
exportJWK: () => exportJWK,
|
|
4297
|
+
exportPKCS8: () => exportPKCS8,
|
|
4298
|
+
exportSPKI: () => exportSPKI,
|
|
4299
|
+
flattenedDecrypt: () => flattenedDecrypt,
|
|
4300
|
+
flattenedVerify: () => flattenedVerify,
|
|
4301
|
+
generalDecrypt: () => generalDecrypt,
|
|
4302
|
+
generalVerify: () => generalVerify,
|
|
4303
|
+
generateKeyPair: () => generateKeyPair,
|
|
4304
|
+
generateSecret: () => generateSecret,
|
|
4305
|
+
importJWK: () => importJWK,
|
|
4306
|
+
importPKCS8: () => importPKCS8,
|
|
4307
|
+
importSPKI: () => importSPKI,
|
|
4308
|
+
importX509: () => importX509,
|
|
4309
|
+
jwksCache: () => jwksCache,
|
|
4310
|
+
jwtDecrypt: () => jwtDecrypt,
|
|
4311
|
+
jwtVerify: () => jwtVerify
|
|
4312
|
+
});
|
|
4313
|
+
var cryptoRuntime;
|
|
4314
|
+
var init_webapi = __esm({
|
|
4315
|
+
"../../../node_modules/jose/dist/webapi/index.js"() {
|
|
4316
|
+
init_decrypt3();
|
|
4317
|
+
init_decrypt2();
|
|
4318
|
+
init_decrypt4();
|
|
4319
|
+
init_encrypt3();
|
|
4320
|
+
init_verify3();
|
|
4321
|
+
init_verify2();
|
|
4322
|
+
init_verify4();
|
|
4323
|
+
init_verify5();
|
|
4324
|
+
init_decrypt5();
|
|
4325
|
+
init_encrypt4();
|
|
4326
|
+
init_encrypt2();
|
|
4327
|
+
init_sign3();
|
|
4328
|
+
init_sign2();
|
|
4329
|
+
init_sign4();
|
|
4330
|
+
init_sign5();
|
|
4331
|
+
init_encrypt5();
|
|
4332
|
+
init_thumbprint();
|
|
4333
|
+
init_embedded();
|
|
4334
|
+
init_local();
|
|
4335
|
+
init_remote();
|
|
4336
|
+
init_unsecured();
|
|
4337
|
+
init_export();
|
|
4338
|
+
init_import();
|
|
4339
|
+
init_decode_protected_header();
|
|
4340
|
+
init_decode_jwt();
|
|
4341
|
+
init_errors();
|
|
4342
|
+
init_generate_key_pair();
|
|
4343
|
+
init_generate_secret();
|
|
4344
|
+
init_base64url();
|
|
4345
|
+
cryptoRuntime = "WebCryptoAPI";
|
|
4346
|
+
}
|
|
4347
|
+
});
|
|
4348
|
+
|
|
6
4349
|
// src/types/index.ts
|
|
7
4350
|
var EVENT_TYPES = {
|
|
8
4351
|
// Trajectory events
|
|
@@ -586,8 +4929,8 @@ function createErrorResponse(id, error) {
|
|
|
586
4929
|
var MAPRequestError = class _MAPRequestError extends Error {
|
|
587
4930
|
code;
|
|
588
4931
|
data;
|
|
589
|
-
constructor(code,
|
|
590
|
-
super(
|
|
4932
|
+
constructor(code, message2, data) {
|
|
4933
|
+
super(message2);
|
|
591
4934
|
this.name = "MAPRequestError";
|
|
592
4935
|
this.code = code;
|
|
593
4936
|
this.data = data;
|
|
@@ -3144,7 +7487,7 @@ var MessageRouterImpl = class {
|
|
|
3144
7487
|
throw new Error(`Target agent not found: ${params.to}`);
|
|
3145
7488
|
}
|
|
3146
7489
|
}
|
|
3147
|
-
const
|
|
7490
|
+
const message2 = {
|
|
3148
7491
|
id: ulid.ulid(),
|
|
3149
7492
|
from: params.from,
|
|
3150
7493
|
to: params.to,
|
|
@@ -3157,17 +7500,17 @@ var MessageRouterImpl = class {
|
|
|
3157
7500
|
};
|
|
3158
7501
|
this.eventBus.emit({
|
|
3159
7502
|
type: "message.sent",
|
|
3160
|
-
data: { message },
|
|
7503
|
+
data: { message: message2 },
|
|
3161
7504
|
source: { agentId: params.from }
|
|
3162
7505
|
});
|
|
3163
|
-
this.deliverToAgent(params.to,
|
|
3164
|
-
return
|
|
7506
|
+
this.deliverToAgent(params.to, message2);
|
|
7507
|
+
return message2;
|
|
3165
7508
|
}
|
|
3166
7509
|
/**
|
|
3167
7510
|
* Broadcast message to all agents in a scope.
|
|
3168
7511
|
*/
|
|
3169
7512
|
sendToScope(params) {
|
|
3170
|
-
const
|
|
7513
|
+
const message2 = {
|
|
3171
7514
|
id: ulid.ulid(),
|
|
3172
7515
|
from: params.from,
|
|
3173
7516
|
to: params.scopeId,
|
|
@@ -3177,7 +7520,7 @@ var MessageRouterImpl = class {
|
|
|
3177
7520
|
};
|
|
3178
7521
|
this.eventBus.emit({
|
|
3179
7522
|
type: "message.sent",
|
|
3180
|
-
data: { message, scopeId: params.scopeId },
|
|
7523
|
+
data: { message: message2, scopeId: params.scopeId },
|
|
3181
7524
|
source: { agentId: params.from, scopeId: params.scopeId }
|
|
3182
7525
|
});
|
|
3183
7526
|
const members = this.scopes.getMembers(params.scopeId, {
|
|
@@ -3187,9 +7530,9 @@ var MessageRouterImpl = class {
|
|
|
3187
7530
|
if (params.excludeSender && agentId === params.from) {
|
|
3188
7531
|
continue;
|
|
3189
7532
|
}
|
|
3190
|
-
this.deliverToAgent(agentId,
|
|
7533
|
+
this.deliverToAgent(agentId, message2);
|
|
3191
7534
|
}
|
|
3192
|
-
return
|
|
7535
|
+
return message2;
|
|
3193
7536
|
}
|
|
3194
7537
|
/**
|
|
3195
7538
|
* Set the delivery handler callback.
|
|
@@ -3239,32 +7582,32 @@ var MessageRouterImpl = class {
|
|
|
3239
7582
|
/**
|
|
3240
7583
|
* Deliver a message to an agent, queuing if offline.
|
|
3241
7584
|
*/
|
|
3242
|
-
deliverToAgent(agentId,
|
|
7585
|
+
deliverToAgent(agentId, message2) {
|
|
3243
7586
|
const agent = this.agents.get(agentId);
|
|
3244
7587
|
const isOnline = agent && agent.state !== "stopped";
|
|
3245
7588
|
if (isOnline && this.deliveryHandler) {
|
|
3246
|
-
this.deliveryHandler(agentId,
|
|
7589
|
+
this.deliveryHandler(agentId, message2);
|
|
3247
7590
|
this.eventBus.emit({
|
|
3248
7591
|
type: "message.delivered",
|
|
3249
|
-
data: { message, agentId }
|
|
7592
|
+
data: { message: message2, agentId }
|
|
3250
7593
|
});
|
|
3251
7594
|
} else if (this.queueOptions.enabled) {
|
|
3252
|
-
this.queueMessage(agentId,
|
|
7595
|
+
this.queueMessage(agentId, message2);
|
|
3253
7596
|
}
|
|
3254
7597
|
}
|
|
3255
7598
|
/**
|
|
3256
7599
|
* Queue a message for later delivery.
|
|
3257
7600
|
* @returns true if message was queued, false if dropped
|
|
3258
7601
|
*/
|
|
3259
|
-
queueMessage(agentId,
|
|
7602
|
+
queueMessage(agentId, message2) {
|
|
3260
7603
|
if (this.queueStore.getTotalSize() >= this.queueOptions.maxTotal) {
|
|
3261
7604
|
this.queueStore.expireOld();
|
|
3262
7605
|
if (this.queueStore.getTotalSize() >= this.queueOptions.maxTotal) {
|
|
3263
7606
|
this.eventBus.emit({
|
|
3264
7607
|
type: "message.dropped",
|
|
3265
7608
|
data: {
|
|
3266
|
-
messageId:
|
|
3267
|
-
from:
|
|
7609
|
+
messageId: message2.id,
|
|
7610
|
+
from: message2.from,
|
|
3268
7611
|
to: agentId,
|
|
3269
7612
|
reason: "queue_full",
|
|
3270
7613
|
queueSize: this.queueStore.getTotalSize(),
|
|
@@ -3278,8 +7621,8 @@ var MessageRouterImpl = class {
|
|
|
3278
7621
|
this.eventBus.emit({
|
|
3279
7622
|
type: "message.dropped",
|
|
3280
7623
|
data: {
|
|
3281
|
-
messageId:
|
|
3282
|
-
from:
|
|
7624
|
+
messageId: message2.id,
|
|
7625
|
+
from: message2.from,
|
|
3283
7626
|
to: agentId,
|
|
3284
7627
|
reason: "agent_queue_full",
|
|
3285
7628
|
agentQueueSize: this.queueStore.getQueueSize(agentId),
|
|
@@ -3288,10 +7631,10 @@ var MessageRouterImpl = class {
|
|
|
3288
7631
|
});
|
|
3289
7632
|
return false;
|
|
3290
7633
|
}
|
|
3291
|
-
const ttlMs =
|
|
7634
|
+
const ttlMs = message2.ttlMs ?? this.queueOptions.defaultTtlMs;
|
|
3292
7635
|
const now = Date.now();
|
|
3293
7636
|
const queuedMessage = {
|
|
3294
|
-
message,
|
|
7637
|
+
message: message2,
|
|
3295
7638
|
targetAgentId: agentId,
|
|
3296
7639
|
queuedAt: now,
|
|
3297
7640
|
expiresAt: now + ttlMs,
|
|
@@ -3300,7 +7643,7 @@ var MessageRouterImpl = class {
|
|
|
3300
7643
|
this.queueStore.enqueue(queuedMessage);
|
|
3301
7644
|
this.eventBus.emit({
|
|
3302
7645
|
type: "message.queued",
|
|
3303
|
-
data: { messageId:
|
|
7646
|
+
data: { messageId: message2.id, agentId, expiresAt: queuedMessage.expiresAt }
|
|
3304
7647
|
});
|
|
3305
7648
|
return true;
|
|
3306
7649
|
}
|
|
@@ -3404,94 +7747,113 @@ function toScope(scopeId) {
|
|
|
3404
7747
|
}
|
|
3405
7748
|
|
|
3406
7749
|
// src/server/messages/handlers.ts
|
|
7750
|
+
function resolveRouteTarget(to) {
|
|
7751
|
+
if (typeof to === "string") {
|
|
7752
|
+
return { type: "string", value: to };
|
|
7753
|
+
}
|
|
7754
|
+
if (Array.isArray(to)) {
|
|
7755
|
+
return to.map((item) => resolveRouteTarget(item));
|
|
7756
|
+
}
|
|
7757
|
+
if (to && typeof to === "object") {
|
|
7758
|
+
const obj = to;
|
|
7759
|
+
if (typeof obj.agent === "string" && !obj.system) {
|
|
7760
|
+
return { type: "agent", id: obj.agent };
|
|
7761
|
+
}
|
|
7762
|
+
if (Array.isArray(obj.agents)) {
|
|
7763
|
+
return { type: "agents", ids: obj.agents };
|
|
7764
|
+
}
|
|
7765
|
+
if (typeof obj.scope === "string") {
|
|
7766
|
+
return { type: "scope", id: obj.scope };
|
|
7767
|
+
}
|
|
7768
|
+
if (obj.broadcast === true) {
|
|
7769
|
+
return { type: "broadcast" };
|
|
7770
|
+
}
|
|
7771
|
+
if (typeof obj.role === "string") {
|
|
7772
|
+
if (typeof obj.within === "string") {
|
|
7773
|
+
return { type: "scope", id: obj.within };
|
|
7774
|
+
}
|
|
7775
|
+
return { type: "broadcast" };
|
|
7776
|
+
}
|
|
7777
|
+
if (obj.system === true) {
|
|
7778
|
+
return { type: "broadcast" };
|
|
7779
|
+
}
|
|
7780
|
+
if (typeof obj.system === "string" && typeof obj.agent === "string") {
|
|
7781
|
+
return { type: "agent", id: obj.agent };
|
|
7782
|
+
}
|
|
7783
|
+
if (typeof obj.participant === "string") {
|
|
7784
|
+
return { type: "agent", id: obj.participant };
|
|
7785
|
+
}
|
|
7786
|
+
if (obj.participants === "all" || obj.participants === "agents") {
|
|
7787
|
+
return { type: "broadcast" };
|
|
7788
|
+
}
|
|
7789
|
+
if (obj.parent || obj.children || obj.ancestors || obj.descendants || obj.siblings) {
|
|
7790
|
+
return { type: "broadcast" };
|
|
7791
|
+
}
|
|
7792
|
+
}
|
|
7793
|
+
return { type: "string", value: String(to) };
|
|
7794
|
+
}
|
|
3407
7795
|
function createMessageHandlers(options) {
|
|
3408
7796
|
const { messages, scopes, agents, turns } = options;
|
|
7797
|
+
function sendToAgent(from, to, params) {
|
|
7798
|
+
return messages.sendToAgent({
|
|
7799
|
+
from,
|
|
7800
|
+
to,
|
|
7801
|
+
payload: params.payload,
|
|
7802
|
+
replyTo: params.replyTo,
|
|
7803
|
+
priority: params.priority,
|
|
7804
|
+
ttlMs: params.ttlMs,
|
|
7805
|
+
messageType: params.messageType
|
|
7806
|
+
});
|
|
7807
|
+
}
|
|
7808
|
+
function sendToScope(from, scopeId, params) {
|
|
7809
|
+
return messages.sendToScope({
|
|
7810
|
+
from,
|
|
7811
|
+
scopeId,
|
|
7812
|
+
payload: params.payload,
|
|
7813
|
+
excludeSender: true,
|
|
7814
|
+
messageType: params.messageType
|
|
7815
|
+
});
|
|
7816
|
+
}
|
|
7817
|
+
function resolveStringAddress(from, to, params) {
|
|
7818
|
+
if (isAddress(to)) {
|
|
7819
|
+
if (isScopeAddress(to)) {
|
|
7820
|
+
const message3 = sendToScope(from, extractId(to), params);
|
|
7821
|
+
return { messageId: message3.id };
|
|
7822
|
+
} else {
|
|
7823
|
+
const message3 = sendToAgent(from, extractId(to), params);
|
|
7824
|
+
return { messageId: message3.id };
|
|
7825
|
+
}
|
|
7826
|
+
}
|
|
7827
|
+
const scope = scopes.get(to);
|
|
7828
|
+
const agent = agents?.get(to);
|
|
7829
|
+
if (scope && agent) {
|
|
7830
|
+
throw new Error(
|
|
7831
|
+
`Ambiguous address "${to}" matches both an agent and a scope. Use "agent:${to}" or "scope:${to}" to disambiguate.`
|
|
7832
|
+
);
|
|
7833
|
+
}
|
|
7834
|
+
if (scope) {
|
|
7835
|
+
const message3 = sendToScope(from, to, params);
|
|
7836
|
+
return { messageId: message3.id };
|
|
7837
|
+
}
|
|
7838
|
+
const message2 = sendToAgent(from, to, params);
|
|
7839
|
+
return { messageId: message2.id };
|
|
7840
|
+
}
|
|
3409
7841
|
return {
|
|
3410
7842
|
"map/send": async (params, ctx) => {
|
|
3411
|
-
const
|
|
7843
|
+
const sendParams = params;
|
|
7844
|
+
const { to: rawTo, meta } = sendParams;
|
|
3412
7845
|
const from = ctx.session.agentIds[0] ?? ctx.session.id;
|
|
7846
|
+
const target = resolveRouteTarget(rawTo);
|
|
3413
7847
|
let result;
|
|
3414
|
-
if (Array.isArray(
|
|
7848
|
+
if (Array.isArray(target)) {
|
|
3415
7849
|
const results = [];
|
|
3416
|
-
for (const
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
const message = messages.sendToScope({
|
|
3420
|
-
from,
|
|
3421
|
-
scopeId,
|
|
3422
|
-
payload,
|
|
3423
|
-
excludeSender: true,
|
|
3424
|
-
messageType
|
|
3425
|
-
});
|
|
3426
|
-
results.push(message.id);
|
|
3427
|
-
} else {
|
|
3428
|
-
const agentId = isAgentAddress(recipient) ? extractId(recipient) : recipient;
|
|
3429
|
-
const message = messages.sendToAgent({
|
|
3430
|
-
from,
|
|
3431
|
-
to: agentId,
|
|
3432
|
-
payload,
|
|
3433
|
-
replyTo,
|
|
3434
|
-
priority,
|
|
3435
|
-
ttlMs,
|
|
3436
|
-
messageType
|
|
3437
|
-
});
|
|
3438
|
-
results.push(message.id);
|
|
3439
|
-
}
|
|
7850
|
+
for (const t of target) {
|
|
7851
|
+
const { messageId } = routeSingle(from, t, sendParams);
|
|
7852
|
+
results.push(messageId);
|
|
3440
7853
|
}
|
|
3441
7854
|
result = { messageId: results[0], delivered: results };
|
|
3442
|
-
} else if (isAddress(to)) {
|
|
3443
|
-
if (isScopeAddress(to)) {
|
|
3444
|
-
const scopeId = extractId(to);
|
|
3445
|
-
const message = messages.sendToScope({
|
|
3446
|
-
from,
|
|
3447
|
-
scopeId,
|
|
3448
|
-
payload,
|
|
3449
|
-
excludeSender: true,
|
|
3450
|
-
messageType
|
|
3451
|
-
});
|
|
3452
|
-
result = { messageId: message.id };
|
|
3453
|
-
} else {
|
|
3454
|
-
const agentId = extractId(to);
|
|
3455
|
-
const message = messages.sendToAgent({
|
|
3456
|
-
from,
|
|
3457
|
-
to: agentId,
|
|
3458
|
-
payload,
|
|
3459
|
-
replyTo,
|
|
3460
|
-
priority,
|
|
3461
|
-
ttlMs,
|
|
3462
|
-
messageType
|
|
3463
|
-
});
|
|
3464
|
-
result = { messageId: message.id };
|
|
3465
|
-
}
|
|
3466
7855
|
} else {
|
|
3467
|
-
|
|
3468
|
-
const agent = agents?.get(to);
|
|
3469
|
-
if (scope && agent) {
|
|
3470
|
-
throw new Error(
|
|
3471
|
-
`Ambiguous address "${to}" matches both an agent and a scope. Use "agent:${to}" or "scope:${to}" to disambiguate.`
|
|
3472
|
-
);
|
|
3473
|
-
}
|
|
3474
|
-
if (scope) {
|
|
3475
|
-
const message = messages.sendToScope({
|
|
3476
|
-
from,
|
|
3477
|
-
scopeId: to,
|
|
3478
|
-
payload,
|
|
3479
|
-
excludeSender: true,
|
|
3480
|
-
messageType
|
|
3481
|
-
});
|
|
3482
|
-
result = { messageId: message.id };
|
|
3483
|
-
} else {
|
|
3484
|
-
const message = messages.sendToAgent({
|
|
3485
|
-
from,
|
|
3486
|
-
to,
|
|
3487
|
-
payload,
|
|
3488
|
-
replyTo,
|
|
3489
|
-
priority,
|
|
3490
|
-
ttlMs,
|
|
3491
|
-
messageType
|
|
3492
|
-
});
|
|
3493
|
-
result = { messageId: message.id };
|
|
3494
|
-
}
|
|
7856
|
+
result = routeSingle(from, target, sendParams);
|
|
3495
7857
|
}
|
|
3496
7858
|
if (turns && meta?.mail?.conversationId) {
|
|
3497
7859
|
try {
|
|
@@ -3499,7 +7861,7 @@ function createMessageHandlers(options) {
|
|
|
3499
7861
|
conversationId: meta.mail.conversationId,
|
|
3500
7862
|
participant: from,
|
|
3501
7863
|
contentType: "data",
|
|
3502
|
-
content: payload,
|
|
7864
|
+
content: sendParams.payload,
|
|
3503
7865
|
messageId: result.messageId,
|
|
3504
7866
|
threadId: meta.mail.threadId,
|
|
3505
7867
|
inReplyTo: meta.mail.inReplyTo,
|
|
@@ -3513,7 +7875,7 @@ function createMessageHandlers(options) {
|
|
|
3513
7875
|
"map/send/scope": async (params, ctx) => {
|
|
3514
7876
|
const { scopeId, payload, excludeSender, includeDescendants, messageType } = params;
|
|
3515
7877
|
const from = ctx.session.agentIds[0] ?? ctx.session.id;
|
|
3516
|
-
const
|
|
7878
|
+
const message2 = messages.sendToScope({
|
|
3517
7879
|
from,
|
|
3518
7880
|
scopeId,
|
|
3519
7881
|
payload,
|
|
@@ -3521,9 +7883,41 @@ function createMessageHandlers(options) {
|
|
|
3521
7883
|
includeDescendants,
|
|
3522
7884
|
messageType
|
|
3523
7885
|
});
|
|
3524
|
-
return { messageId:
|
|
7886
|
+
return { messageId: message2.id };
|
|
3525
7887
|
}
|
|
3526
7888
|
};
|
|
7889
|
+
function routeSingle(from, target, params) {
|
|
7890
|
+
switch (target.type) {
|
|
7891
|
+
case "agent": {
|
|
7892
|
+
const message2 = sendToAgent(from, target.id, params);
|
|
7893
|
+
return { messageId: message2.id };
|
|
7894
|
+
}
|
|
7895
|
+
case "agents": {
|
|
7896
|
+
const results = [];
|
|
7897
|
+
for (const agentId of target.ids) {
|
|
7898
|
+
const message2 = sendToAgent(from, agentId, params);
|
|
7899
|
+
results.push(message2.id);
|
|
7900
|
+
}
|
|
7901
|
+
return { messageId: results[0] };
|
|
7902
|
+
}
|
|
7903
|
+
case "scope": {
|
|
7904
|
+
const message2 = sendToScope(from, target.id, params);
|
|
7905
|
+
return { messageId: message2.id };
|
|
7906
|
+
}
|
|
7907
|
+
case "broadcast": {
|
|
7908
|
+
const message2 = messages.sendToAgent({
|
|
7909
|
+
from,
|
|
7910
|
+
to: "*",
|
|
7911
|
+
payload: params.payload,
|
|
7912
|
+
messageType: params.messageType
|
|
7913
|
+
});
|
|
7914
|
+
return { messageId: message2.id };
|
|
7915
|
+
}
|
|
7916
|
+
case "string": {
|
|
7917
|
+
return resolveStringAddress(from, target.value, params);
|
|
7918
|
+
}
|
|
7919
|
+
}
|
|
7920
|
+
}
|
|
3527
7921
|
}
|
|
3528
7922
|
|
|
3529
7923
|
// src/server/mail/stores/in-memory-conversation.ts
|
|
@@ -5058,13 +9452,13 @@ var RouterConnectionImpl = class {
|
|
|
5058
9452
|
/**
|
|
5059
9453
|
* Handle an incoming message.
|
|
5060
9454
|
*/
|
|
5061
|
-
async handleMessage(
|
|
5062
|
-
if (this.isRequest(
|
|
5063
|
-
await this.handleRequest(
|
|
5064
|
-
} else if (this.isNotification(
|
|
9455
|
+
async handleMessage(message2) {
|
|
9456
|
+
if (this.isRequest(message2)) {
|
|
9457
|
+
await this.handleRequest(message2);
|
|
9458
|
+
} else if (this.isNotification(message2)) {
|
|
5065
9459
|
if (this._notificationHandler) {
|
|
5066
9460
|
try {
|
|
5067
|
-
const msg =
|
|
9461
|
+
const msg = message2;
|
|
5068
9462
|
this._notificationHandler(msg.method, msg.params);
|
|
5069
9463
|
} catch {
|
|
5070
9464
|
}
|
|
@@ -5074,14 +9468,14 @@ var RouterConnectionImpl = class {
|
|
|
5074
9468
|
/**
|
|
5075
9469
|
* Check if a message is a notification (method but no id).
|
|
5076
9470
|
*/
|
|
5077
|
-
isNotification(
|
|
5078
|
-
return typeof
|
|
9471
|
+
isNotification(message2) {
|
|
9472
|
+
return typeof message2 === "object" && message2 !== null && "jsonrpc" in message2 && message2.jsonrpc === "2.0" && "method" in message2 && !("id" in message2);
|
|
5079
9473
|
}
|
|
5080
9474
|
/**
|
|
5081
9475
|
* Check if a message is a request.
|
|
5082
9476
|
*/
|
|
5083
|
-
isRequest(
|
|
5084
|
-
return typeof
|
|
9477
|
+
isRequest(message2) {
|
|
9478
|
+
return typeof message2 === "object" && message2 !== null && "jsonrpc" in message2 && message2.jsonrpc === "2.0" && "id" in message2 && "method" in message2;
|
|
5085
9479
|
}
|
|
5086
9480
|
/**
|
|
5087
9481
|
* Handle a JSON-RPC request.
|
|
@@ -5157,10 +9551,10 @@ var RouterConnectionImpl = class {
|
|
|
5157
9551
|
/**
|
|
5158
9552
|
* Send a message to the stream.
|
|
5159
9553
|
*/
|
|
5160
|
-
async sendMessage(
|
|
9554
|
+
async sendMessage(message2) {
|
|
5161
9555
|
const writer = this.stream.writable.getWriter();
|
|
5162
9556
|
try {
|
|
5163
|
-
await writer.write(
|
|
9557
|
+
await writer.write(message2);
|
|
5164
9558
|
} finally {
|
|
5165
9559
|
writer.releaseLock();
|
|
5166
9560
|
}
|
|
@@ -5791,8 +10185,8 @@ function createCredentialHandlers(options) {
|
|
|
5791
10185
|
throw new Error("Missing required parameter: resource");
|
|
5792
10186
|
}
|
|
5793
10187
|
const token = getTokenFromSession(ctx);
|
|
5794
|
-
const
|
|
5795
|
-
if (!
|
|
10188
|
+
const check2 = broker.checkPermission(token, scope, resource);
|
|
10189
|
+
if (!check2.valid) {
|
|
5796
10190
|
if (eventBus) {
|
|
5797
10191
|
eventBus.emit({
|
|
5798
10192
|
type: "credential.denied",
|
|
@@ -5803,12 +10197,12 @@ function createCredentialHandlers(options) {
|
|
|
5803
10197
|
},
|
|
5804
10198
|
scope,
|
|
5805
10199
|
resource,
|
|
5806
|
-
reason:
|
|
10200
|
+
reason: check2.error
|
|
5807
10201
|
},
|
|
5808
10202
|
source: { agentId: token.agentId }
|
|
5809
10203
|
});
|
|
5810
10204
|
}
|
|
5811
|
-
throw new Error(
|
|
10205
|
+
throw new Error(check2.error ?? "Permission denied");
|
|
5812
10206
|
}
|
|
5813
10207
|
const credential = await broker.getCredential(token, scope, resource);
|
|
5814
10208
|
if (eventBus) {
|
|
@@ -6160,8 +10554,8 @@ var AUTH_ERRORS = {
|
|
|
6160
10554
|
var AuthenticationError = class extends Error {
|
|
6161
10555
|
code;
|
|
6162
10556
|
authErrorCode;
|
|
6163
|
-
constructor(
|
|
6164
|
-
super(
|
|
10557
|
+
constructor(message2, authErrorCode = "auth_required") {
|
|
10558
|
+
super(message2);
|
|
6165
10559
|
this.name = "AuthenticationError";
|
|
6166
10560
|
this.code = AUTH_ERRORS.UNAUTHORIZED;
|
|
6167
10561
|
this.authErrorCode = authErrorCode;
|
|
@@ -6294,7 +10688,7 @@ var joseModule = null;
|
|
|
6294
10688
|
async function getJose() {
|
|
6295
10689
|
if (!joseModule) {
|
|
6296
10690
|
try {
|
|
6297
|
-
joseModule = await
|
|
10691
|
+
joseModule = await Promise.resolve().then(() => (init_webapi(), webapi_exports));
|
|
6298
10692
|
} catch {
|
|
6299
10693
|
throw new Error(
|
|
6300
10694
|
'JWTAuthenticator requires the "jose" package. Install it with: npm install jose'
|
|
@@ -8018,8 +12412,8 @@ var PERMISSION_ERRORS = {
|
|
|
8018
12412
|
FORBIDDEN: -32e3};
|
|
8019
12413
|
var PermissionDeniedError = class extends Error {
|
|
8020
12414
|
code;
|
|
8021
|
-
constructor(
|
|
8022
|
-
super(
|
|
12415
|
+
constructor(message2) {
|
|
12416
|
+
super(message2);
|
|
8023
12417
|
this.name = "PermissionDeniedError";
|
|
8024
12418
|
this.code = PERMISSION_ERRORS.FORBIDDEN;
|
|
8025
12419
|
}
|
|
@@ -9098,10 +13492,10 @@ var FederatedMessageRouter = class {
|
|
|
9098
13492
|
this.gateway = options.gateway;
|
|
9099
13493
|
this.agents = options.agents;
|
|
9100
13494
|
this.gateway.onPeerMessage(this.handlePeerMessage.bind(this));
|
|
9101
|
-
this.local.onDeliver((
|
|
13495
|
+
this.local.onDeliver((message2) => {
|
|
9102
13496
|
for (const handler of this.deliveryHandlers) {
|
|
9103
13497
|
try {
|
|
9104
|
-
handler(
|
|
13498
|
+
handler(message2);
|
|
9105
13499
|
} catch (error) {
|
|
9106
13500
|
console.error("FederatedMessageRouter delivery handler error:", error);
|
|
9107
13501
|
}
|
|
@@ -9185,7 +13579,7 @@ var FederatedMessageRouter = class {
|
|
|
9185
13579
|
if (!parsed) {
|
|
9186
13580
|
throw new Error(`Invalid remote agent ID: ${params.to}`);
|
|
9187
13581
|
}
|
|
9188
|
-
const
|
|
13582
|
+
const message2 = {
|
|
9189
13583
|
id: this.generateMessageId(),
|
|
9190
13584
|
from: params.from,
|
|
9191
13585
|
to: params.to,
|
|
@@ -9197,7 +13591,7 @@ var FederatedMessageRouter = class {
|
|
|
9197
13591
|
const envelope = this.gateway.createEnvelope(parsed.systemId, {
|
|
9198
13592
|
type: "message",
|
|
9199
13593
|
message: {
|
|
9200
|
-
...
|
|
13594
|
+
...message2,
|
|
9201
13595
|
// Translate the target to original ID for the remote system
|
|
9202
13596
|
to: parsed.originalId
|
|
9203
13597
|
}
|
|
@@ -9205,7 +13599,7 @@ var FederatedMessageRouter = class {
|
|
|
9205
13599
|
this.gateway.routeToPeer(parsed.systemId, envelope).catch((err) => {
|
|
9206
13600
|
console.error(`Failed to route message to ${parsed.systemId}:`, err);
|
|
9207
13601
|
});
|
|
9208
|
-
return
|
|
13602
|
+
return message2;
|
|
9209
13603
|
}
|
|
9210
13604
|
/**
|
|
9211
13605
|
* Handle incoming peer messages.
|
|
@@ -9215,19 +13609,19 @@ var FederatedMessageRouter = class {
|
|
|
9215
13609
|
if (payload.type !== "message" || !payload.message) {
|
|
9216
13610
|
return;
|
|
9217
13611
|
}
|
|
9218
|
-
const
|
|
9219
|
-
const localAgent = this.agents.get(
|
|
13612
|
+
const message2 = payload.message;
|
|
13613
|
+
const localAgent = this.agents.get(message2.to);
|
|
9220
13614
|
if (!localAgent) {
|
|
9221
|
-
console.warn(`Received federated message for unknown agent: ${
|
|
13615
|
+
console.warn(`Received federated message for unknown agent: ${message2.to}`);
|
|
9222
13616
|
return;
|
|
9223
13617
|
}
|
|
9224
13618
|
const federatedMessage = {
|
|
9225
|
-
...
|
|
9226
|
-
from: formatFederatedId(from, "agent",
|
|
13619
|
+
...message2,
|
|
13620
|
+
from: formatFederatedId(from, "agent", message2.from),
|
|
9227
13621
|
metadata: {
|
|
9228
|
-
...
|
|
13622
|
+
...message2.metadata ?? {},
|
|
9229
13623
|
_federatedFrom: from,
|
|
9230
|
-
_originalFrom:
|
|
13624
|
+
_originalFrom: message2.from
|
|
9231
13625
|
}
|
|
9232
13626
|
};
|
|
9233
13627
|
for (const handler of this.deliveryHandlers) {
|
|
@@ -9249,15 +13643,15 @@ var FederatedMessageRouter = class {
|
|
|
9249
13643
|
// src/server/federation/handlers.ts
|
|
9250
13644
|
var FederationError = class extends Error {
|
|
9251
13645
|
code;
|
|
9252
|
-
constructor(
|
|
9253
|
-
super(
|
|
13646
|
+
constructor(message2, code = -32e3) {
|
|
13647
|
+
super(message2);
|
|
9254
13648
|
this.name = "FederationError";
|
|
9255
13649
|
this.code = code;
|
|
9256
13650
|
}
|
|
9257
13651
|
};
|
|
9258
13652
|
var FederationPermissionError = class extends FederationError {
|
|
9259
|
-
constructor(
|
|
9260
|
-
super(
|
|
13653
|
+
constructor(message2 = "Federation operations require gateway role") {
|
|
13654
|
+
super(message2, -32003);
|
|
9261
13655
|
this.name = "FederationPermissionError";
|
|
9262
13656
|
}
|
|
9263
13657
|
};
|