moltspay 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +90 -4668
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +68 -4647
- package/dist/cli/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -1,4625 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
3
|
var __esm = (fn, res) => function __init() {
|
|
5
4
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
5
|
};
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// node_modules/tsup/assets/esm_shims.js
|
|
13
|
-
import path from "path";
|
|
14
|
-
import { fileURLToPath } from "url";
|
|
15
|
-
var init_esm_shims = __esm({
|
|
16
|
-
"node_modules/tsup/assets/esm_shims.js"() {
|
|
17
|
-
"use strict";
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
22
|
-
function concat(...buffers) {
|
|
23
|
-
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
24
|
-
const buf = new Uint8Array(size);
|
|
25
|
-
let i = 0;
|
|
26
|
-
for (const buffer of buffers) {
|
|
27
|
-
buf.set(buffer, i);
|
|
28
|
-
i += buffer.length;
|
|
29
|
-
}
|
|
30
|
-
return buf;
|
|
31
|
-
}
|
|
32
|
-
function writeUInt32BE(buf, value, offset) {
|
|
33
|
-
if (value < 0 || value >= MAX_INT32) {
|
|
34
|
-
throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
35
|
-
}
|
|
36
|
-
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
|
|
37
|
-
}
|
|
38
|
-
function uint64be(value) {
|
|
39
|
-
const high = Math.floor(value / MAX_INT32);
|
|
40
|
-
const low = value % MAX_INT32;
|
|
41
|
-
const buf = new Uint8Array(8);
|
|
42
|
-
writeUInt32BE(buf, high, 0);
|
|
43
|
-
writeUInt32BE(buf, low, 4);
|
|
44
|
-
return buf;
|
|
45
|
-
}
|
|
46
|
-
function uint32be(value) {
|
|
47
|
-
const buf = new Uint8Array(4);
|
|
48
|
-
writeUInt32BE(buf, value);
|
|
49
|
-
return buf;
|
|
50
|
-
}
|
|
51
|
-
function encode(string) {
|
|
52
|
-
const bytes = new Uint8Array(string.length);
|
|
53
|
-
for (let i = 0; i < string.length; i++) {
|
|
54
|
-
const code = string.charCodeAt(i);
|
|
55
|
-
if (code > 127) {
|
|
56
|
-
throw new TypeError("non-ASCII string encountered in encode()");
|
|
57
|
-
}
|
|
58
|
-
bytes[i] = code;
|
|
59
|
-
}
|
|
60
|
-
return bytes;
|
|
61
|
-
}
|
|
62
|
-
var encoder, decoder, MAX_INT32;
|
|
63
|
-
var init_buffer_utils = __esm({
|
|
64
|
-
"node_modules/jose/dist/webapi/lib/buffer_utils.js"() {
|
|
65
|
-
"use strict";
|
|
66
|
-
init_esm_shims();
|
|
67
|
-
encoder = new TextEncoder();
|
|
68
|
-
decoder = new TextDecoder();
|
|
69
|
-
MAX_INT32 = 2 ** 32;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// node_modules/jose/dist/webapi/lib/base64.js
|
|
74
|
-
function encodeBase64(input) {
|
|
75
|
-
if (Uint8Array.prototype.toBase64) {
|
|
76
|
-
return input.toBase64();
|
|
77
|
-
}
|
|
78
|
-
const CHUNK_SIZE = 32768;
|
|
79
|
-
const arr = [];
|
|
80
|
-
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
81
|
-
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
82
|
-
}
|
|
83
|
-
return btoa(arr.join(""));
|
|
84
|
-
}
|
|
85
|
-
function decodeBase64(encoded) {
|
|
86
|
-
if (Uint8Array.fromBase64) {
|
|
87
|
-
return Uint8Array.fromBase64(encoded);
|
|
88
|
-
}
|
|
89
|
-
const binary = atob(encoded);
|
|
90
|
-
const bytes = new Uint8Array(binary.length);
|
|
91
|
-
for (let i = 0; i < binary.length; i++) {
|
|
92
|
-
bytes[i] = binary.charCodeAt(i);
|
|
93
|
-
}
|
|
94
|
-
return bytes;
|
|
95
|
-
}
|
|
96
|
-
var init_base64 = __esm({
|
|
97
|
-
"node_modules/jose/dist/webapi/lib/base64.js"() {
|
|
98
|
-
"use strict";
|
|
99
|
-
init_esm_shims();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// node_modules/jose/dist/webapi/util/base64url.js
|
|
104
|
-
var base64url_exports = {};
|
|
105
|
-
__export(base64url_exports, {
|
|
106
|
-
decode: () => decode,
|
|
107
|
-
encode: () => encode2
|
|
108
|
-
});
|
|
109
|
-
function decode(input) {
|
|
110
|
-
if (Uint8Array.fromBase64) {
|
|
111
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
112
|
-
alphabet: "base64url"
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
let encoded = input;
|
|
116
|
-
if (encoded instanceof Uint8Array) {
|
|
117
|
-
encoded = decoder.decode(encoded);
|
|
118
|
-
}
|
|
119
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
120
|
-
try {
|
|
121
|
-
return decodeBase64(encoded);
|
|
122
|
-
} catch {
|
|
123
|
-
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function encode2(input) {
|
|
127
|
-
let unencoded = input;
|
|
128
|
-
if (typeof unencoded === "string") {
|
|
129
|
-
unencoded = encoder.encode(unencoded);
|
|
130
|
-
}
|
|
131
|
-
if (Uint8Array.prototype.toBase64) {
|
|
132
|
-
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
133
|
-
}
|
|
134
|
-
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
135
|
-
}
|
|
136
|
-
var init_base64url = __esm({
|
|
137
|
-
"node_modules/jose/dist/webapi/util/base64url.js"() {
|
|
138
|
-
"use strict";
|
|
139
|
-
init_esm_shims();
|
|
140
|
-
init_buffer_utils();
|
|
141
|
-
init_base64();
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// node_modules/jose/dist/webapi/util/errors.js
|
|
146
|
-
var errors_exports = {};
|
|
147
|
-
__export(errors_exports, {
|
|
148
|
-
JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
|
|
149
|
-
JOSEError: () => JOSEError,
|
|
150
|
-
JOSENotSupported: () => JOSENotSupported,
|
|
151
|
-
JWEDecryptionFailed: () => JWEDecryptionFailed,
|
|
152
|
-
JWEInvalid: () => JWEInvalid,
|
|
153
|
-
JWKInvalid: () => JWKInvalid,
|
|
154
|
-
JWKSInvalid: () => JWKSInvalid,
|
|
155
|
-
JWKSMultipleMatchingKeys: () => JWKSMultipleMatchingKeys,
|
|
156
|
-
JWKSNoMatchingKey: () => JWKSNoMatchingKey,
|
|
157
|
-
JWKSTimeout: () => JWKSTimeout,
|
|
158
|
-
JWSInvalid: () => JWSInvalid,
|
|
159
|
-
JWSSignatureVerificationFailed: () => JWSSignatureVerificationFailed,
|
|
160
|
-
JWTClaimValidationFailed: () => JWTClaimValidationFailed,
|
|
161
|
-
JWTExpired: () => JWTExpired,
|
|
162
|
-
JWTInvalid: () => JWTInvalid
|
|
163
|
-
});
|
|
164
|
-
var JOSEError, JWTClaimValidationFailed, JWTExpired, JOSEAlgNotAllowed, JOSENotSupported, JWEDecryptionFailed, JWEInvalid, JWSInvalid, JWTInvalid, JWKInvalid, JWKSInvalid, JWKSNoMatchingKey, JWKSMultipleMatchingKeys, JWKSTimeout, JWSSignatureVerificationFailed;
|
|
165
|
-
var init_errors = __esm({
|
|
166
|
-
"node_modules/jose/dist/webapi/util/errors.js"() {
|
|
167
|
-
"use strict";
|
|
168
|
-
init_esm_shims();
|
|
169
|
-
JOSEError = class extends Error {
|
|
170
|
-
static code = "ERR_JOSE_GENERIC";
|
|
171
|
-
code = "ERR_JOSE_GENERIC";
|
|
172
|
-
constructor(message2, options) {
|
|
173
|
-
super(message2, options);
|
|
174
|
-
this.name = this.constructor.name;
|
|
175
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
JWTClaimValidationFailed = class extends JOSEError {
|
|
179
|
-
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
180
|
-
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
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
|
-
JWTExpired = class extends JOSEError {
|
|
192
|
-
static code = "ERR_JWT_EXPIRED";
|
|
193
|
-
code = "ERR_JWT_EXPIRED";
|
|
194
|
-
claim;
|
|
195
|
-
reason;
|
|
196
|
-
payload;
|
|
197
|
-
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
198
|
-
super(message2, { cause: { claim, reason, payload } });
|
|
199
|
-
this.claim = claim;
|
|
200
|
-
this.reason = reason;
|
|
201
|
-
this.payload = payload;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
JOSEAlgNotAllowed = class extends JOSEError {
|
|
205
|
-
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
206
|
-
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
207
|
-
};
|
|
208
|
-
JOSENotSupported = class extends JOSEError {
|
|
209
|
-
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
210
|
-
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
211
|
-
};
|
|
212
|
-
JWEDecryptionFailed = class extends JOSEError {
|
|
213
|
-
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
214
|
-
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
215
|
-
constructor(message2 = "decryption operation failed", options) {
|
|
216
|
-
super(message2, options);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
JWEInvalid = class extends JOSEError {
|
|
220
|
-
static code = "ERR_JWE_INVALID";
|
|
221
|
-
code = "ERR_JWE_INVALID";
|
|
222
|
-
};
|
|
223
|
-
JWSInvalid = class extends JOSEError {
|
|
224
|
-
static code = "ERR_JWS_INVALID";
|
|
225
|
-
code = "ERR_JWS_INVALID";
|
|
226
|
-
};
|
|
227
|
-
JWTInvalid = class extends JOSEError {
|
|
228
|
-
static code = "ERR_JWT_INVALID";
|
|
229
|
-
code = "ERR_JWT_INVALID";
|
|
230
|
-
};
|
|
231
|
-
JWKInvalid = class extends JOSEError {
|
|
232
|
-
static code = "ERR_JWK_INVALID";
|
|
233
|
-
code = "ERR_JWK_INVALID";
|
|
234
|
-
};
|
|
235
|
-
JWKSInvalid = class extends JOSEError {
|
|
236
|
-
static code = "ERR_JWKS_INVALID";
|
|
237
|
-
code = "ERR_JWKS_INVALID";
|
|
238
|
-
};
|
|
239
|
-
JWKSNoMatchingKey = class extends JOSEError {
|
|
240
|
-
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
241
|
-
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
242
|
-
constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
|
|
243
|
-
super(message2, options);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
JWKSMultipleMatchingKeys = class extends JOSEError {
|
|
247
|
-
[Symbol.asyncIterator];
|
|
248
|
-
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
249
|
-
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
250
|
-
constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
251
|
-
super(message2, options);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
JWKSTimeout = class extends JOSEError {
|
|
255
|
-
static code = "ERR_JWKS_TIMEOUT";
|
|
256
|
-
code = "ERR_JWKS_TIMEOUT";
|
|
257
|
-
constructor(message2 = "request timed out", options) {
|
|
258
|
-
super(message2, options);
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
JWSSignatureVerificationFailed = class extends JOSEError {
|
|
262
|
-
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
263
|
-
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
264
|
-
constructor(message2 = "signature verification failed", options) {
|
|
265
|
-
super(message2, options);
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
// node_modules/jose/dist/webapi/lib/iv.js
|
|
272
|
-
function bitLength(alg) {
|
|
273
|
-
switch (alg) {
|
|
274
|
-
case "A128GCM":
|
|
275
|
-
case "A128GCMKW":
|
|
276
|
-
case "A192GCM":
|
|
277
|
-
case "A192GCMKW":
|
|
278
|
-
case "A256GCM":
|
|
279
|
-
case "A256GCMKW":
|
|
280
|
-
return 96;
|
|
281
|
-
case "A128CBC-HS256":
|
|
282
|
-
case "A192CBC-HS384":
|
|
283
|
-
case "A256CBC-HS512":
|
|
284
|
-
return 128;
|
|
285
|
-
default:
|
|
286
|
-
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
var generateIv;
|
|
290
|
-
var init_iv = __esm({
|
|
291
|
-
"node_modules/jose/dist/webapi/lib/iv.js"() {
|
|
292
|
-
"use strict";
|
|
293
|
-
init_esm_shims();
|
|
294
|
-
init_errors();
|
|
295
|
-
generateIv = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// node_modules/jose/dist/webapi/lib/check_iv_length.js
|
|
300
|
-
function checkIvLength(enc, iv) {
|
|
301
|
-
if (iv.length << 3 !== bitLength(enc)) {
|
|
302
|
-
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
var init_check_iv_length = __esm({
|
|
306
|
-
"node_modules/jose/dist/webapi/lib/check_iv_length.js"() {
|
|
307
|
-
"use strict";
|
|
308
|
-
init_esm_shims();
|
|
309
|
-
init_errors();
|
|
310
|
-
init_iv();
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
// node_modules/jose/dist/webapi/lib/check_cek_length.js
|
|
315
|
-
function checkCekLength(cek, expected) {
|
|
316
|
-
const actual = cek.byteLength << 3;
|
|
317
|
-
if (actual !== expected) {
|
|
318
|
-
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
var init_check_cek_length = __esm({
|
|
322
|
-
"node_modules/jose/dist/webapi/lib/check_cek_length.js"() {
|
|
323
|
-
"use strict";
|
|
324
|
-
init_esm_shims();
|
|
325
|
-
init_errors();
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
330
|
-
function getHashLength(hash) {
|
|
331
|
-
return parseInt(hash.name.slice(4), 10);
|
|
332
|
-
}
|
|
333
|
-
function getNamedCurve(alg) {
|
|
334
|
-
switch (alg) {
|
|
335
|
-
case "ES256":
|
|
336
|
-
return "P-256";
|
|
337
|
-
case "ES384":
|
|
338
|
-
return "P-384";
|
|
339
|
-
case "ES512":
|
|
340
|
-
return "P-521";
|
|
341
|
-
default:
|
|
342
|
-
throw new Error("unreachable");
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
function checkUsage(key, usage) {
|
|
346
|
-
if (usage && !key.usages.includes(usage)) {
|
|
347
|
-
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
function checkSigCryptoKey(key, alg, usage) {
|
|
351
|
-
switch (alg) {
|
|
352
|
-
case "HS256":
|
|
353
|
-
case "HS384":
|
|
354
|
-
case "HS512": {
|
|
355
|
-
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
356
|
-
throw unusable("HMAC");
|
|
357
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
358
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
359
|
-
if (actual !== expected)
|
|
360
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
case "RS256":
|
|
364
|
-
case "RS384":
|
|
365
|
-
case "RS512": {
|
|
366
|
-
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
367
|
-
throw unusable("RSASSA-PKCS1-v1_5");
|
|
368
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
369
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
370
|
-
if (actual !== expected)
|
|
371
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
case "PS256":
|
|
375
|
-
case "PS384":
|
|
376
|
-
case "PS512": {
|
|
377
|
-
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
378
|
-
throw unusable("RSA-PSS");
|
|
379
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
380
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
381
|
-
if (actual !== expected)
|
|
382
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
case "Ed25519":
|
|
386
|
-
case "EdDSA": {
|
|
387
|
-
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
388
|
-
throw unusable("Ed25519");
|
|
389
|
-
break;
|
|
390
|
-
}
|
|
391
|
-
case "ML-DSA-44":
|
|
392
|
-
case "ML-DSA-65":
|
|
393
|
-
case "ML-DSA-87": {
|
|
394
|
-
if (!isAlgorithm(key.algorithm, alg))
|
|
395
|
-
throw unusable(alg);
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
case "ES256":
|
|
399
|
-
case "ES384":
|
|
400
|
-
case "ES512": {
|
|
401
|
-
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
402
|
-
throw unusable("ECDSA");
|
|
403
|
-
const expected = getNamedCurve(alg);
|
|
404
|
-
const actual = key.algorithm.namedCurve;
|
|
405
|
-
if (actual !== expected)
|
|
406
|
-
throw unusable(expected, "algorithm.namedCurve");
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
default:
|
|
410
|
-
throw new TypeError("CryptoKey does not support this operation");
|
|
411
|
-
}
|
|
412
|
-
checkUsage(key, usage);
|
|
413
|
-
}
|
|
414
|
-
function checkEncCryptoKey(key, alg, usage) {
|
|
415
|
-
switch (alg) {
|
|
416
|
-
case "A128GCM":
|
|
417
|
-
case "A192GCM":
|
|
418
|
-
case "A256GCM": {
|
|
419
|
-
if (!isAlgorithm(key.algorithm, "AES-GCM"))
|
|
420
|
-
throw unusable("AES-GCM");
|
|
421
|
-
const expected = parseInt(alg.slice(1, 4), 10);
|
|
422
|
-
const actual = key.algorithm.length;
|
|
423
|
-
if (actual !== expected)
|
|
424
|
-
throw unusable(expected, "algorithm.length");
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
case "A128KW":
|
|
428
|
-
case "A192KW":
|
|
429
|
-
case "A256KW": {
|
|
430
|
-
if (!isAlgorithm(key.algorithm, "AES-KW"))
|
|
431
|
-
throw unusable("AES-KW");
|
|
432
|
-
const expected = parseInt(alg.slice(1, 4), 10);
|
|
433
|
-
const actual = key.algorithm.length;
|
|
434
|
-
if (actual !== expected)
|
|
435
|
-
throw unusable(expected, "algorithm.length");
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
case "ECDH": {
|
|
439
|
-
switch (key.algorithm.name) {
|
|
440
|
-
case "ECDH":
|
|
441
|
-
case "X25519":
|
|
442
|
-
break;
|
|
443
|
-
default:
|
|
444
|
-
throw unusable("ECDH or X25519");
|
|
445
|
-
}
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
case "PBES2-HS256+A128KW":
|
|
449
|
-
case "PBES2-HS384+A192KW":
|
|
450
|
-
case "PBES2-HS512+A256KW":
|
|
451
|
-
if (!isAlgorithm(key.algorithm, "PBKDF2"))
|
|
452
|
-
throw unusable("PBKDF2");
|
|
453
|
-
break;
|
|
454
|
-
case "RSA-OAEP":
|
|
455
|
-
case "RSA-OAEP-256":
|
|
456
|
-
case "RSA-OAEP-384":
|
|
457
|
-
case "RSA-OAEP-512": {
|
|
458
|
-
if (!isAlgorithm(key.algorithm, "RSA-OAEP"))
|
|
459
|
-
throw unusable("RSA-OAEP");
|
|
460
|
-
const expected = parseInt(alg.slice(9), 10) || 1;
|
|
461
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
462
|
-
if (actual !== expected)
|
|
463
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
default:
|
|
467
|
-
throw new TypeError("CryptoKey does not support this operation");
|
|
468
|
-
}
|
|
469
|
-
checkUsage(key, usage);
|
|
470
|
-
}
|
|
471
|
-
var unusable, isAlgorithm;
|
|
472
|
-
var init_crypto_key = __esm({
|
|
473
|
-
"node_modules/jose/dist/webapi/lib/crypto_key.js"() {
|
|
474
|
-
"use strict";
|
|
475
|
-
init_esm_shims();
|
|
476
|
-
unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
477
|
-
isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
482
|
-
function message(msg, actual, ...types) {
|
|
483
|
-
types = types.filter(Boolean);
|
|
484
|
-
if (types.length > 2) {
|
|
485
|
-
const last = types.pop();
|
|
486
|
-
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
487
|
-
} else if (types.length === 2) {
|
|
488
|
-
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
489
|
-
} else {
|
|
490
|
-
msg += `of type ${types[0]}.`;
|
|
491
|
-
}
|
|
492
|
-
if (actual == null) {
|
|
493
|
-
msg += ` Received ${actual}`;
|
|
494
|
-
} else if (typeof actual === "function" && actual.name) {
|
|
495
|
-
msg += ` Received function ${actual.name}`;
|
|
496
|
-
} else if (typeof actual === "object" && actual != null) {
|
|
497
|
-
if (actual.constructor?.name) {
|
|
498
|
-
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return msg;
|
|
502
|
-
}
|
|
503
|
-
var invalidKeyInput, withAlg;
|
|
504
|
-
var init_invalid_key_input = __esm({
|
|
505
|
-
"node_modules/jose/dist/webapi/lib/invalid_key_input.js"() {
|
|
506
|
-
"use strict";
|
|
507
|
-
init_esm_shims();
|
|
508
|
-
invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
509
|
-
withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
510
|
-
}
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
514
|
-
function assertCryptoKey(key) {
|
|
515
|
-
if (!isCryptoKey(key)) {
|
|
516
|
-
throw new Error("CryptoKey instance expected");
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
var isCryptoKey, isKeyObject, isKeyLike;
|
|
520
|
-
var init_is_key_like = __esm({
|
|
521
|
-
"node_modules/jose/dist/webapi/lib/is_key_like.js"() {
|
|
522
|
-
"use strict";
|
|
523
|
-
init_esm_shims();
|
|
524
|
-
isCryptoKey = (key) => {
|
|
525
|
-
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
526
|
-
return true;
|
|
527
|
-
try {
|
|
528
|
-
return key instanceof CryptoKey;
|
|
529
|
-
} catch {
|
|
530
|
-
return false;
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
534
|
-
isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
// node_modules/jose/dist/webapi/lib/decrypt.js
|
|
539
|
-
async function timingSafeEqual(a, b) {
|
|
540
|
-
if (!(a instanceof Uint8Array)) {
|
|
541
|
-
throw new TypeError("First argument must be a buffer");
|
|
542
|
-
}
|
|
543
|
-
if (!(b instanceof Uint8Array)) {
|
|
544
|
-
throw new TypeError("Second argument must be a buffer");
|
|
545
|
-
}
|
|
546
|
-
const algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
547
|
-
const key = await crypto.subtle.generateKey(algorithm, false, ["sign"]);
|
|
548
|
-
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
549
|
-
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
550
|
-
let out = 0;
|
|
551
|
-
let i = -1;
|
|
552
|
-
while (++i < 32) {
|
|
553
|
-
out |= aHmac[i] ^ bHmac[i];
|
|
554
|
-
}
|
|
555
|
-
return out === 0;
|
|
556
|
-
}
|
|
557
|
-
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
558
|
-
if (!(cek instanceof Uint8Array)) {
|
|
559
|
-
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
560
|
-
}
|
|
561
|
-
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
562
|
-
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["decrypt"]);
|
|
563
|
-
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
564
|
-
hash: `SHA-${keySize << 1}`,
|
|
565
|
-
name: "HMAC"
|
|
566
|
-
}, false, ["sign"]);
|
|
567
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
568
|
-
const expectedTag = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
569
|
-
let macCheckPassed;
|
|
570
|
-
try {
|
|
571
|
-
macCheckPassed = await timingSafeEqual(tag2, expectedTag);
|
|
572
|
-
} catch {
|
|
573
|
-
}
|
|
574
|
-
if (!macCheckPassed) {
|
|
575
|
-
throw new JWEDecryptionFailed();
|
|
576
|
-
}
|
|
577
|
-
let plaintext;
|
|
578
|
-
try {
|
|
579
|
-
plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
580
|
-
} catch {
|
|
581
|
-
}
|
|
582
|
-
if (!plaintext) {
|
|
583
|
-
throw new JWEDecryptionFailed();
|
|
584
|
-
}
|
|
585
|
-
return plaintext;
|
|
586
|
-
}
|
|
587
|
-
async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
588
|
-
let encKey;
|
|
589
|
-
if (cek instanceof Uint8Array) {
|
|
590
|
-
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["decrypt"]);
|
|
591
|
-
} else {
|
|
592
|
-
checkEncCryptoKey(cek, enc, "decrypt");
|
|
593
|
-
encKey = cek;
|
|
594
|
-
}
|
|
595
|
-
try {
|
|
596
|
-
return new Uint8Array(await crypto.subtle.decrypt({
|
|
597
|
-
additionalData: aad,
|
|
598
|
-
iv,
|
|
599
|
-
name: "AES-GCM",
|
|
600
|
-
tagLength: 128
|
|
601
|
-
}, encKey, concat(ciphertext, tag2)));
|
|
602
|
-
} catch {
|
|
603
|
-
throw new JWEDecryptionFailed();
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
async function decrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
607
|
-
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
608
|
-
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
609
|
-
}
|
|
610
|
-
if (!iv) {
|
|
611
|
-
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
612
|
-
}
|
|
613
|
-
if (!tag2) {
|
|
614
|
-
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
615
|
-
}
|
|
616
|
-
checkIvLength(enc, iv);
|
|
617
|
-
switch (enc) {
|
|
618
|
-
case "A128CBC-HS256":
|
|
619
|
-
case "A192CBC-HS384":
|
|
620
|
-
case "A256CBC-HS512":
|
|
621
|
-
if (cek instanceof Uint8Array)
|
|
622
|
-
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
623
|
-
return cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
624
|
-
case "A128GCM":
|
|
625
|
-
case "A192GCM":
|
|
626
|
-
case "A256GCM":
|
|
627
|
-
if (cek instanceof Uint8Array)
|
|
628
|
-
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
629
|
-
return gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
630
|
-
default:
|
|
631
|
-
throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
var init_decrypt = __esm({
|
|
635
|
-
"node_modules/jose/dist/webapi/lib/decrypt.js"() {
|
|
636
|
-
"use strict";
|
|
637
|
-
init_esm_shims();
|
|
638
|
-
init_buffer_utils();
|
|
639
|
-
init_check_iv_length();
|
|
640
|
-
init_check_cek_length();
|
|
641
|
-
init_errors();
|
|
642
|
-
init_crypto_key();
|
|
643
|
-
init_invalid_key_input();
|
|
644
|
-
init_is_key_like();
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
649
|
-
function isDisjoint(...headers) {
|
|
650
|
-
const sources = headers.filter(Boolean);
|
|
651
|
-
if (sources.length === 0 || sources.length === 1) {
|
|
652
|
-
return true;
|
|
653
|
-
}
|
|
654
|
-
let acc;
|
|
655
|
-
for (const header of sources) {
|
|
656
|
-
const parameters = Object.keys(header);
|
|
657
|
-
if (!acc || acc.size === 0) {
|
|
658
|
-
acc = new Set(parameters);
|
|
659
|
-
continue;
|
|
660
|
-
}
|
|
661
|
-
for (const parameter of parameters) {
|
|
662
|
-
if (acc.has(parameter)) {
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
|
-
acc.add(parameter);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
return true;
|
|
669
|
-
}
|
|
670
|
-
var init_is_disjoint = __esm({
|
|
671
|
-
"node_modules/jose/dist/webapi/lib/is_disjoint.js"() {
|
|
672
|
-
"use strict";
|
|
673
|
-
init_esm_shims();
|
|
674
|
-
}
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
678
|
-
function isObject(input) {
|
|
679
|
-
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
680
|
-
return false;
|
|
681
|
-
}
|
|
682
|
-
if (Object.getPrototypeOf(input) === null) {
|
|
683
|
-
return true;
|
|
684
|
-
}
|
|
685
|
-
let proto = input;
|
|
686
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
687
|
-
proto = Object.getPrototypeOf(proto);
|
|
688
|
-
}
|
|
689
|
-
return Object.getPrototypeOf(input) === proto;
|
|
690
|
-
}
|
|
691
|
-
var isObjectLike;
|
|
692
|
-
var init_is_object = __esm({
|
|
693
|
-
"node_modules/jose/dist/webapi/lib/is_object.js"() {
|
|
694
|
-
"use strict";
|
|
695
|
-
init_esm_shims();
|
|
696
|
-
isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
|
|
700
|
-
// node_modules/jose/dist/webapi/lib/aeskw.js
|
|
701
|
-
function checkKeySize(key, alg) {
|
|
702
|
-
if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
|
|
703
|
-
throw new TypeError(`Invalid key size for alg: ${alg}`);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
function getCryptoKey(key, alg, usage) {
|
|
707
|
-
if (key instanceof Uint8Array) {
|
|
708
|
-
return crypto.subtle.importKey("raw", key, "AES-KW", true, [usage]);
|
|
709
|
-
}
|
|
710
|
-
checkEncCryptoKey(key, alg, usage);
|
|
711
|
-
return key;
|
|
712
|
-
}
|
|
713
|
-
async function wrap(alg, key, cek) {
|
|
714
|
-
const cryptoKey = await getCryptoKey(key, alg, "wrapKey");
|
|
715
|
-
checkKeySize(cryptoKey, alg);
|
|
716
|
-
const cryptoKeyCek = await crypto.subtle.importKey("raw", cek, { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
717
|
-
return new Uint8Array(await crypto.subtle.wrapKey("raw", cryptoKeyCek, cryptoKey, "AES-KW"));
|
|
718
|
-
}
|
|
719
|
-
async function unwrap(alg, key, encryptedKey) {
|
|
720
|
-
const cryptoKey = await getCryptoKey(key, alg, "unwrapKey");
|
|
721
|
-
checkKeySize(cryptoKey, alg);
|
|
722
|
-
const cryptoKeyCek = await crypto.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
723
|
-
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
724
|
-
}
|
|
725
|
-
var init_aeskw = __esm({
|
|
726
|
-
"node_modules/jose/dist/webapi/lib/aeskw.js"() {
|
|
727
|
-
"use strict";
|
|
728
|
-
init_esm_shims();
|
|
729
|
-
init_crypto_key();
|
|
730
|
-
}
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
// node_modules/jose/dist/webapi/lib/digest.js
|
|
734
|
-
async function digest(algorithm, data) {
|
|
735
|
-
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
736
|
-
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
737
|
-
}
|
|
738
|
-
var init_digest = __esm({
|
|
739
|
-
"node_modules/jose/dist/webapi/lib/digest.js"() {
|
|
740
|
-
"use strict";
|
|
741
|
-
init_esm_shims();
|
|
742
|
-
}
|
|
743
|
-
});
|
|
744
|
-
|
|
745
|
-
// node_modules/jose/dist/webapi/lib/ecdhes.js
|
|
746
|
-
function lengthAndInput(input) {
|
|
747
|
-
return concat(uint32be(input.length), input);
|
|
748
|
-
}
|
|
749
|
-
async function concatKdf(Z, L, OtherInfo) {
|
|
750
|
-
const dkLen = L >> 3;
|
|
751
|
-
const hashLen = 32;
|
|
752
|
-
const reps = Math.ceil(dkLen / hashLen);
|
|
753
|
-
const dk = new Uint8Array(reps * hashLen);
|
|
754
|
-
for (let i = 1; i <= reps; i++) {
|
|
755
|
-
const hashInput = new Uint8Array(4 + Z.length + OtherInfo.length);
|
|
756
|
-
hashInput.set(uint32be(i), 0);
|
|
757
|
-
hashInput.set(Z, 4);
|
|
758
|
-
hashInput.set(OtherInfo, 4 + Z.length);
|
|
759
|
-
const hashResult = await digest("sha256", hashInput);
|
|
760
|
-
dk.set(hashResult, (i - 1) * hashLen);
|
|
761
|
-
}
|
|
762
|
-
return dk.slice(0, dkLen);
|
|
763
|
-
}
|
|
764
|
-
async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
|
|
765
|
-
checkEncCryptoKey(publicKey, "ECDH");
|
|
766
|
-
checkEncCryptoKey(privateKey, "ECDH", "deriveBits");
|
|
767
|
-
const algorithmID = lengthAndInput(encode(algorithm));
|
|
768
|
-
const partyUInfo = lengthAndInput(apu);
|
|
769
|
-
const partyVInfo = lengthAndInput(apv);
|
|
770
|
-
const suppPubInfo = uint32be(keyLength);
|
|
771
|
-
const suppPrivInfo = new Uint8Array();
|
|
772
|
-
const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
|
|
773
|
-
const Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
774
|
-
name: publicKey.algorithm.name,
|
|
775
|
-
public: publicKey
|
|
776
|
-
}, privateKey, getEcdhBitLength(publicKey)));
|
|
777
|
-
return concatKdf(Z, keyLength, otherInfo);
|
|
778
|
-
}
|
|
779
|
-
function getEcdhBitLength(publicKey) {
|
|
780
|
-
if (publicKey.algorithm.name === "X25519") {
|
|
781
|
-
return 256;
|
|
782
|
-
}
|
|
783
|
-
return Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3;
|
|
784
|
-
}
|
|
785
|
-
function allowed(key) {
|
|
786
|
-
switch (key.algorithm.namedCurve) {
|
|
787
|
-
case "P-256":
|
|
788
|
-
case "P-384":
|
|
789
|
-
case "P-521":
|
|
790
|
-
return true;
|
|
791
|
-
default:
|
|
792
|
-
return key.algorithm.name === "X25519";
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
var init_ecdhes = __esm({
|
|
796
|
-
"node_modules/jose/dist/webapi/lib/ecdhes.js"() {
|
|
797
|
-
"use strict";
|
|
798
|
-
init_esm_shims();
|
|
799
|
-
init_buffer_utils();
|
|
800
|
-
init_crypto_key();
|
|
801
|
-
init_digest();
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
|
|
805
|
-
// node_modules/jose/dist/webapi/lib/pbes2kw.js
|
|
806
|
-
function getCryptoKey2(key, alg) {
|
|
807
|
-
if (key instanceof Uint8Array) {
|
|
808
|
-
return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
|
|
809
|
-
"deriveBits"
|
|
810
|
-
]);
|
|
811
|
-
}
|
|
812
|
-
checkEncCryptoKey(key, alg, "deriveBits");
|
|
813
|
-
return key;
|
|
814
|
-
}
|
|
815
|
-
async function deriveKey2(p2s, alg, p2c, key) {
|
|
816
|
-
if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
|
|
817
|
-
throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
|
|
818
|
-
}
|
|
819
|
-
const salt = concatSalt(alg, p2s);
|
|
820
|
-
const keylen = parseInt(alg.slice(13, 16), 10);
|
|
821
|
-
const subtleAlg = {
|
|
822
|
-
hash: `SHA-${alg.slice(8, 11)}`,
|
|
823
|
-
iterations: p2c,
|
|
824
|
-
name: "PBKDF2",
|
|
825
|
-
salt
|
|
826
|
-
};
|
|
827
|
-
const cryptoKey = await getCryptoKey2(key, alg);
|
|
828
|
-
return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
|
|
829
|
-
}
|
|
830
|
-
async function wrap2(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
|
|
831
|
-
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
832
|
-
const encryptedKey = await wrap(alg.slice(-6), derived, cek);
|
|
833
|
-
return { encryptedKey, p2c, p2s: encode2(p2s) };
|
|
834
|
-
}
|
|
835
|
-
async function unwrap2(alg, key, encryptedKey, p2c, p2s) {
|
|
836
|
-
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
837
|
-
return unwrap(alg.slice(-6), derived, encryptedKey);
|
|
838
|
-
}
|
|
839
|
-
var concatSalt;
|
|
840
|
-
var init_pbes2kw = __esm({
|
|
841
|
-
"node_modules/jose/dist/webapi/lib/pbes2kw.js"() {
|
|
842
|
-
"use strict";
|
|
843
|
-
init_esm_shims();
|
|
844
|
-
init_base64url();
|
|
845
|
-
init_aeskw();
|
|
846
|
-
init_crypto_key();
|
|
847
|
-
init_buffer_utils();
|
|
848
|
-
init_errors();
|
|
849
|
-
concatSalt = (alg, p2sInput) => concat(encode(alg), Uint8Array.of(0), p2sInput);
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
|
|
853
|
-
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
854
|
-
function checkKeyLength(alg, key) {
|
|
855
|
-
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
856
|
-
const { modulusLength } = key.algorithm;
|
|
857
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
858
|
-
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
var init_check_key_length = __esm({
|
|
863
|
-
"node_modules/jose/dist/webapi/lib/check_key_length.js"() {
|
|
864
|
-
"use strict";
|
|
865
|
-
init_esm_shims();
|
|
866
|
-
}
|
|
867
|
-
});
|
|
868
|
-
|
|
869
|
-
// node_modules/jose/dist/webapi/lib/rsaes.js
|
|
870
|
-
async function encrypt(alg, key, cek) {
|
|
871
|
-
checkEncCryptoKey(key, alg, "encrypt");
|
|
872
|
-
checkKeyLength(alg, key);
|
|
873
|
-
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm(alg), key, cek));
|
|
874
|
-
}
|
|
875
|
-
async function decrypt2(alg, key, encryptedKey) {
|
|
876
|
-
checkEncCryptoKey(key, alg, "decrypt");
|
|
877
|
-
checkKeyLength(alg, key);
|
|
878
|
-
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm(alg), key, encryptedKey));
|
|
879
|
-
}
|
|
880
|
-
var subtleAlgorithm;
|
|
881
|
-
var init_rsaes = __esm({
|
|
882
|
-
"node_modules/jose/dist/webapi/lib/rsaes.js"() {
|
|
883
|
-
"use strict";
|
|
884
|
-
init_esm_shims();
|
|
885
|
-
init_crypto_key();
|
|
886
|
-
init_check_key_length();
|
|
887
|
-
init_errors();
|
|
888
|
-
subtleAlgorithm = (alg) => {
|
|
889
|
-
switch (alg) {
|
|
890
|
-
case "RSA-OAEP":
|
|
891
|
-
case "RSA-OAEP-256":
|
|
892
|
-
case "RSA-OAEP-384":
|
|
893
|
-
case "RSA-OAEP-512":
|
|
894
|
-
return "RSA-OAEP";
|
|
895
|
-
default:
|
|
896
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
|
|
902
|
-
// node_modules/jose/dist/webapi/lib/cek.js
|
|
903
|
-
function cekLength(alg) {
|
|
904
|
-
switch (alg) {
|
|
905
|
-
case "A128GCM":
|
|
906
|
-
return 128;
|
|
907
|
-
case "A192GCM":
|
|
908
|
-
return 192;
|
|
909
|
-
case "A256GCM":
|
|
910
|
-
case "A128CBC-HS256":
|
|
911
|
-
return 256;
|
|
912
|
-
case "A192CBC-HS384":
|
|
913
|
-
return 384;
|
|
914
|
-
case "A256CBC-HS512":
|
|
915
|
-
return 512;
|
|
916
|
-
default:
|
|
917
|
-
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
var generateCek;
|
|
921
|
-
var init_cek = __esm({
|
|
922
|
-
"node_modules/jose/dist/webapi/lib/cek.js"() {
|
|
923
|
-
"use strict";
|
|
924
|
-
init_esm_shims();
|
|
925
|
-
init_errors();
|
|
926
|
-
generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
// node_modules/jose/dist/webapi/lib/asn1.js
|
|
931
|
-
function parsePKCS8Header(state) {
|
|
932
|
-
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
933
|
-
parseLength(state);
|
|
934
|
-
expectTag(state, 2, "Expected version field");
|
|
935
|
-
const verLen = parseLength(state);
|
|
936
|
-
state.pos += verLen;
|
|
937
|
-
expectTag(state, 48, "Expected algorithm identifier");
|
|
938
|
-
const algIdLen = parseLength(state);
|
|
939
|
-
const algIdStart = state.pos;
|
|
940
|
-
return { algIdStart, algIdLength: algIdLen };
|
|
941
|
-
}
|
|
942
|
-
function parseSPKIHeader(state) {
|
|
943
|
-
expectTag(state, 48, "Invalid SPKI structure");
|
|
944
|
-
parseLength(state);
|
|
945
|
-
expectTag(state, 48, "Expected algorithm identifier");
|
|
946
|
-
const algIdLen = parseLength(state);
|
|
947
|
-
const algIdStart = state.pos;
|
|
948
|
-
return { algIdStart, algIdLength: algIdLen };
|
|
949
|
-
}
|
|
950
|
-
function spkiFromX509(buf) {
|
|
951
|
-
const state = createASN1State(buf);
|
|
952
|
-
expectTag(state, 48, "Invalid certificate structure");
|
|
953
|
-
parseLength(state);
|
|
954
|
-
expectTag(state, 48, "Invalid tbsCertificate structure");
|
|
955
|
-
parseLength(state);
|
|
956
|
-
if (buf[state.pos] === 160) {
|
|
957
|
-
skipElement(state, 6);
|
|
958
|
-
} else {
|
|
959
|
-
skipElement(state, 5);
|
|
960
|
-
}
|
|
961
|
-
const spkiStart = state.pos;
|
|
962
|
-
expectTag(state, 48, "Invalid SPKI structure");
|
|
963
|
-
const spkiContentLen = parseLength(state);
|
|
964
|
-
return buf.subarray(spkiStart, spkiStart + spkiContentLen + (state.pos - spkiStart));
|
|
965
|
-
}
|
|
966
|
-
function extractX509SPKI(x509) {
|
|
967
|
-
const derBytes = processPEMData(x509, /(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g);
|
|
968
|
-
return spkiFromX509(derBytes);
|
|
969
|
-
}
|
|
970
|
-
var formatPEM, genericExport, toSPKI, toPKCS8, bytesEqual, createASN1State, parseLength, skipElement, expectTag, getSubarray, parseAlgorithmOID, parseECAlgorithmIdentifier, genericImport, processPEMData, fromPKCS8, fromSPKI, fromX509;
|
|
971
|
-
var init_asn1 = __esm({
|
|
972
|
-
"node_modules/jose/dist/webapi/lib/asn1.js"() {
|
|
973
|
-
"use strict";
|
|
974
|
-
init_esm_shims();
|
|
975
|
-
init_invalid_key_input();
|
|
976
|
-
init_base64();
|
|
977
|
-
init_errors();
|
|
978
|
-
init_is_key_like();
|
|
979
|
-
formatPEM = (b64, descriptor) => {
|
|
980
|
-
const newlined = (b64.match(/.{1,64}/g) || []).join("\n");
|
|
981
|
-
return `-----BEGIN ${descriptor}-----
|
|
982
|
-
${newlined}
|
|
983
|
-
-----END ${descriptor}-----`;
|
|
984
|
-
};
|
|
985
|
-
genericExport = async (keyType, keyFormat, key) => {
|
|
986
|
-
if (isKeyObject(key)) {
|
|
987
|
-
if (key.type !== keyType) {
|
|
988
|
-
throw new TypeError(`key is not a ${keyType} key`);
|
|
989
|
-
}
|
|
990
|
-
return key.export({ format: "pem", type: keyFormat });
|
|
991
|
-
}
|
|
992
|
-
if (!isCryptoKey(key)) {
|
|
993
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject"));
|
|
994
|
-
}
|
|
995
|
-
if (!key.extractable) {
|
|
996
|
-
throw new TypeError("CryptoKey is not extractable");
|
|
997
|
-
}
|
|
998
|
-
if (key.type !== keyType) {
|
|
999
|
-
throw new TypeError(`key is not a ${keyType} key`);
|
|
1000
|
-
}
|
|
1001
|
-
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
1002
|
-
};
|
|
1003
|
-
toSPKI = (key) => genericExport("public", "spki", key);
|
|
1004
|
-
toPKCS8 = (key) => genericExport("private", "pkcs8", key);
|
|
1005
|
-
bytesEqual = (a, b) => {
|
|
1006
|
-
if (a.byteLength !== b.length)
|
|
1007
|
-
return false;
|
|
1008
|
-
for (let i = 0; i < a.byteLength; i++) {
|
|
1009
|
-
if (a[i] !== b[i])
|
|
1010
|
-
return false;
|
|
1011
|
-
}
|
|
1012
|
-
return true;
|
|
1013
|
-
};
|
|
1014
|
-
createASN1State = (data) => ({ data, pos: 0 });
|
|
1015
|
-
parseLength = (state) => {
|
|
1016
|
-
const first = state.data[state.pos++];
|
|
1017
|
-
if (first & 128) {
|
|
1018
|
-
const lengthOfLen = first & 127;
|
|
1019
|
-
let length = 0;
|
|
1020
|
-
for (let i = 0; i < lengthOfLen; i++) {
|
|
1021
|
-
length = length << 8 | state.data[state.pos++];
|
|
1022
|
-
}
|
|
1023
|
-
return length;
|
|
1024
|
-
}
|
|
1025
|
-
return first;
|
|
1026
|
-
};
|
|
1027
|
-
skipElement = (state, count = 1) => {
|
|
1028
|
-
if (count <= 0)
|
|
1029
|
-
return;
|
|
1030
|
-
state.pos++;
|
|
1031
|
-
const length = parseLength(state);
|
|
1032
|
-
state.pos += length;
|
|
1033
|
-
if (count > 1) {
|
|
1034
|
-
skipElement(state, count - 1);
|
|
1035
|
-
}
|
|
1036
|
-
};
|
|
1037
|
-
expectTag = (state, expectedTag, errorMessage) => {
|
|
1038
|
-
if (state.data[state.pos++] !== expectedTag) {
|
|
1039
|
-
throw new Error(errorMessage);
|
|
1040
|
-
}
|
|
1041
|
-
};
|
|
1042
|
-
getSubarray = (state, length) => {
|
|
1043
|
-
const result = state.data.subarray(state.pos, state.pos + length);
|
|
1044
|
-
state.pos += length;
|
|
1045
|
-
return result;
|
|
1046
|
-
};
|
|
1047
|
-
parseAlgorithmOID = (state) => {
|
|
1048
|
-
expectTag(state, 6, "Expected algorithm OID");
|
|
1049
|
-
const oidLen = parseLength(state);
|
|
1050
|
-
return getSubarray(state, oidLen);
|
|
1051
|
-
};
|
|
1052
|
-
parseECAlgorithmIdentifier = (state) => {
|
|
1053
|
-
const algOid = parseAlgorithmOID(state);
|
|
1054
|
-
if (bytesEqual(algOid, [43, 101, 110])) {
|
|
1055
|
-
return "X25519";
|
|
1056
|
-
}
|
|
1057
|
-
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
|
|
1058
|
-
throw new Error("Unsupported key algorithm");
|
|
1059
|
-
}
|
|
1060
|
-
expectTag(state, 6, "Expected curve OID");
|
|
1061
|
-
const curveOidLen = parseLength(state);
|
|
1062
|
-
const curveOid = getSubarray(state, curveOidLen);
|
|
1063
|
-
for (const { name, oid } of [
|
|
1064
|
-
{ name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
|
|
1065
|
-
{ name: "P-384", oid: [43, 129, 4, 0, 34] },
|
|
1066
|
-
{ name: "P-521", oid: [43, 129, 4, 0, 35] }
|
|
1067
|
-
]) {
|
|
1068
|
-
if (bytesEqual(curveOid, oid)) {
|
|
1069
|
-
return name;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
throw new Error("Unsupported named curve");
|
|
1073
|
-
};
|
|
1074
|
-
genericImport = async (keyFormat, keyData, alg, options) => {
|
|
1075
|
-
let algorithm;
|
|
1076
|
-
let keyUsages;
|
|
1077
|
-
const isPublic = keyFormat === "spki";
|
|
1078
|
-
const getSigUsages = () => isPublic ? ["verify"] : ["sign"];
|
|
1079
|
-
const getEncUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
1080
|
-
switch (alg) {
|
|
1081
|
-
case "PS256":
|
|
1082
|
-
case "PS384":
|
|
1083
|
-
case "PS512":
|
|
1084
|
-
algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
|
|
1085
|
-
keyUsages = getSigUsages();
|
|
1086
|
-
break;
|
|
1087
|
-
case "RS256":
|
|
1088
|
-
case "RS384":
|
|
1089
|
-
case "RS512":
|
|
1090
|
-
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
|
|
1091
|
-
keyUsages = getSigUsages();
|
|
1092
|
-
break;
|
|
1093
|
-
case "RSA-OAEP":
|
|
1094
|
-
case "RSA-OAEP-256":
|
|
1095
|
-
case "RSA-OAEP-384":
|
|
1096
|
-
case "RSA-OAEP-512":
|
|
1097
|
-
algorithm = {
|
|
1098
|
-
name: "RSA-OAEP",
|
|
1099
|
-
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
|
|
1100
|
-
};
|
|
1101
|
-
keyUsages = getEncUsages();
|
|
1102
|
-
break;
|
|
1103
|
-
case "ES256":
|
|
1104
|
-
case "ES384":
|
|
1105
|
-
case "ES512": {
|
|
1106
|
-
const curveMap = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
1107
|
-
algorithm = { name: "ECDSA", namedCurve: curveMap[alg] };
|
|
1108
|
-
keyUsages = getSigUsages();
|
|
1109
|
-
break;
|
|
1110
|
-
}
|
|
1111
|
-
case "ECDH-ES":
|
|
1112
|
-
case "ECDH-ES+A128KW":
|
|
1113
|
-
case "ECDH-ES+A192KW":
|
|
1114
|
-
case "ECDH-ES+A256KW": {
|
|
1115
|
-
try {
|
|
1116
|
-
const namedCurve = options.getNamedCurve(keyData);
|
|
1117
|
-
algorithm = namedCurve === "X25519" ? { name: "X25519" } : { name: "ECDH", namedCurve };
|
|
1118
|
-
} catch (cause) {
|
|
1119
|
-
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
1120
|
-
}
|
|
1121
|
-
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
1122
|
-
break;
|
|
1123
|
-
}
|
|
1124
|
-
case "Ed25519":
|
|
1125
|
-
case "EdDSA":
|
|
1126
|
-
algorithm = { name: "Ed25519" };
|
|
1127
|
-
keyUsages = getSigUsages();
|
|
1128
|
-
break;
|
|
1129
|
-
case "ML-DSA-44":
|
|
1130
|
-
case "ML-DSA-65":
|
|
1131
|
-
case "ML-DSA-87":
|
|
1132
|
-
algorithm = { name: alg };
|
|
1133
|
-
keyUsages = getSigUsages();
|
|
1134
|
-
break;
|
|
1135
|
-
default:
|
|
1136
|
-
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
1137
|
-
}
|
|
1138
|
-
return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? (isPublic ? true : false), keyUsages);
|
|
1139
|
-
};
|
|
1140
|
-
processPEMData = (pem, pattern) => {
|
|
1141
|
-
return decodeBase64(pem.replace(pattern, ""));
|
|
1142
|
-
};
|
|
1143
|
-
fromPKCS8 = (pem, alg, options) => {
|
|
1144
|
-
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
1145
|
-
let opts = options;
|
|
1146
|
-
if (alg?.startsWith?.("ECDH-ES")) {
|
|
1147
|
-
opts ||= {};
|
|
1148
|
-
opts.getNamedCurve = (keyData2) => {
|
|
1149
|
-
const state = createASN1State(keyData2);
|
|
1150
|
-
parsePKCS8Header(state);
|
|
1151
|
-
return parseECAlgorithmIdentifier(state);
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
return genericImport("pkcs8", keyData, alg, opts);
|
|
1155
|
-
};
|
|
1156
|
-
fromSPKI = (pem, alg, options) => {
|
|
1157
|
-
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
|
|
1158
|
-
let opts = options;
|
|
1159
|
-
if (alg?.startsWith?.("ECDH-ES")) {
|
|
1160
|
-
opts ||= {};
|
|
1161
|
-
opts.getNamedCurve = (keyData2) => {
|
|
1162
|
-
const state = createASN1State(keyData2);
|
|
1163
|
-
parseSPKIHeader(state);
|
|
1164
|
-
return parseECAlgorithmIdentifier(state);
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
return genericImport("spki", keyData, alg, opts);
|
|
1168
|
-
};
|
|
1169
|
-
fromX509 = (pem, alg, options) => {
|
|
1170
|
-
let spki;
|
|
1171
|
-
try {
|
|
1172
|
-
spki = extractX509SPKI(pem);
|
|
1173
|
-
} catch (cause) {
|
|
1174
|
-
throw new TypeError("Failed to parse the X.509 certificate", { cause });
|
|
1175
|
-
}
|
|
1176
|
-
return fromSPKI(formatPEM(encodeBase64(spki), "PUBLIC KEY"), alg, options);
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
|
-
|
|
1181
|
-
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
1182
|
-
function subtleMapping(jwk) {
|
|
1183
|
-
let algorithm;
|
|
1184
|
-
let keyUsages;
|
|
1185
|
-
switch (jwk.kty) {
|
|
1186
|
-
case "AKP": {
|
|
1187
|
-
switch (jwk.alg) {
|
|
1188
|
-
case "ML-DSA-44":
|
|
1189
|
-
case "ML-DSA-65":
|
|
1190
|
-
case "ML-DSA-87":
|
|
1191
|
-
algorithm = { name: jwk.alg };
|
|
1192
|
-
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
1193
|
-
break;
|
|
1194
|
-
default:
|
|
1195
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1196
|
-
}
|
|
1197
|
-
break;
|
|
1198
|
-
}
|
|
1199
|
-
case "RSA": {
|
|
1200
|
-
switch (jwk.alg) {
|
|
1201
|
-
case "PS256":
|
|
1202
|
-
case "PS384":
|
|
1203
|
-
case "PS512":
|
|
1204
|
-
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1205
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1206
|
-
break;
|
|
1207
|
-
case "RS256":
|
|
1208
|
-
case "RS384":
|
|
1209
|
-
case "RS512":
|
|
1210
|
-
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1211
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1212
|
-
break;
|
|
1213
|
-
case "RSA-OAEP":
|
|
1214
|
-
case "RSA-OAEP-256":
|
|
1215
|
-
case "RSA-OAEP-384":
|
|
1216
|
-
case "RSA-OAEP-512":
|
|
1217
|
-
algorithm = {
|
|
1218
|
-
name: "RSA-OAEP",
|
|
1219
|
-
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
1220
|
-
};
|
|
1221
|
-
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
1222
|
-
break;
|
|
1223
|
-
default:
|
|
1224
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1225
|
-
}
|
|
1226
|
-
break;
|
|
1227
|
-
}
|
|
1228
|
-
case "EC": {
|
|
1229
|
-
switch (jwk.alg) {
|
|
1230
|
-
case "ES256":
|
|
1231
|
-
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
1232
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1233
|
-
break;
|
|
1234
|
-
case "ES384":
|
|
1235
|
-
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
1236
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1237
|
-
break;
|
|
1238
|
-
case "ES512":
|
|
1239
|
-
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
1240
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1241
|
-
break;
|
|
1242
|
-
case "ECDH-ES":
|
|
1243
|
-
case "ECDH-ES+A128KW":
|
|
1244
|
-
case "ECDH-ES+A192KW":
|
|
1245
|
-
case "ECDH-ES+A256KW":
|
|
1246
|
-
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
1247
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1248
|
-
break;
|
|
1249
|
-
default:
|
|
1250
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1251
|
-
}
|
|
1252
|
-
break;
|
|
1253
|
-
}
|
|
1254
|
-
case "OKP": {
|
|
1255
|
-
switch (jwk.alg) {
|
|
1256
|
-
case "Ed25519":
|
|
1257
|
-
case "EdDSA":
|
|
1258
|
-
algorithm = { name: "Ed25519" };
|
|
1259
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1260
|
-
break;
|
|
1261
|
-
case "ECDH-ES":
|
|
1262
|
-
case "ECDH-ES+A128KW":
|
|
1263
|
-
case "ECDH-ES+A192KW":
|
|
1264
|
-
case "ECDH-ES+A256KW":
|
|
1265
|
-
algorithm = { name: jwk.crv };
|
|
1266
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1267
|
-
break;
|
|
1268
|
-
default:
|
|
1269
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1270
|
-
}
|
|
1271
|
-
break;
|
|
1272
|
-
}
|
|
1273
|
-
default:
|
|
1274
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
1275
|
-
}
|
|
1276
|
-
return { algorithm, keyUsages };
|
|
1277
|
-
}
|
|
1278
|
-
async function jwkToKey(jwk) {
|
|
1279
|
-
if (!jwk.alg) {
|
|
1280
|
-
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
1281
|
-
}
|
|
1282
|
-
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
1283
|
-
const keyData = { ...jwk };
|
|
1284
|
-
if (keyData.kty !== "AKP") {
|
|
1285
|
-
delete keyData.alg;
|
|
1286
|
-
}
|
|
1287
|
-
delete keyData.use;
|
|
1288
|
-
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
1289
|
-
}
|
|
1290
|
-
var init_jwk_to_key = __esm({
|
|
1291
|
-
"node_modules/jose/dist/webapi/lib/jwk_to_key.js"() {
|
|
1292
|
-
"use strict";
|
|
1293
|
-
init_esm_shims();
|
|
1294
|
-
init_errors();
|
|
1295
|
-
}
|
|
1296
|
-
});
|
|
1297
|
-
|
|
1298
|
-
// node_modules/jose/dist/webapi/key/import.js
|
|
1299
|
-
async function importSPKI(spki, alg, options) {
|
|
1300
|
-
if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) {
|
|
1301
|
-
throw new TypeError('"spki" must be SPKI formatted string');
|
|
1302
|
-
}
|
|
1303
|
-
return fromSPKI(spki, alg, options);
|
|
1304
|
-
}
|
|
1305
|
-
async function importX509(x509, alg, options) {
|
|
1306
|
-
if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) {
|
|
1307
|
-
throw new TypeError('"x509" must be X.509 formatted string');
|
|
1308
|
-
}
|
|
1309
|
-
return fromX509(x509, alg, options);
|
|
1310
|
-
}
|
|
1311
|
-
async function importPKCS8(pkcs8, alg, options) {
|
|
1312
|
-
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
1313
|
-
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
1314
|
-
}
|
|
1315
|
-
return fromPKCS8(pkcs8, alg, options);
|
|
1316
|
-
}
|
|
1317
|
-
async function importJWK(jwk, alg, options) {
|
|
1318
|
-
if (!isObject(jwk)) {
|
|
1319
|
-
throw new TypeError("JWK must be an object");
|
|
1320
|
-
}
|
|
1321
|
-
let ext;
|
|
1322
|
-
alg ??= jwk.alg;
|
|
1323
|
-
ext ??= options?.extractable ?? jwk.ext;
|
|
1324
|
-
switch (jwk.kty) {
|
|
1325
|
-
case "oct":
|
|
1326
|
-
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
1327
|
-
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
1328
|
-
}
|
|
1329
|
-
return decode(jwk.k);
|
|
1330
|
-
case "RSA":
|
|
1331
|
-
if ("oth" in jwk && jwk.oth !== void 0) {
|
|
1332
|
-
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
1333
|
-
}
|
|
1334
|
-
return jwkToKey({ ...jwk, alg, ext });
|
|
1335
|
-
case "AKP": {
|
|
1336
|
-
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
1337
|
-
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
1338
|
-
}
|
|
1339
|
-
if (alg !== void 0 && alg !== jwk.alg) {
|
|
1340
|
-
throw new TypeError("JWK alg and alg option value mismatch");
|
|
1341
|
-
}
|
|
1342
|
-
return jwkToKey({ ...jwk, ext });
|
|
1343
|
-
}
|
|
1344
|
-
case "EC":
|
|
1345
|
-
case "OKP":
|
|
1346
|
-
return jwkToKey({ ...jwk, alg, ext });
|
|
1347
|
-
default:
|
|
1348
|
-
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
var init_import = __esm({
|
|
1352
|
-
"node_modules/jose/dist/webapi/key/import.js"() {
|
|
1353
|
-
"use strict";
|
|
1354
|
-
init_esm_shims();
|
|
1355
|
-
init_base64url();
|
|
1356
|
-
init_asn1();
|
|
1357
|
-
init_jwk_to_key();
|
|
1358
|
-
init_errors();
|
|
1359
|
-
init_is_object();
|
|
1360
|
-
}
|
|
1361
|
-
});
|
|
1362
|
-
|
|
1363
|
-
// node_modules/jose/dist/webapi/lib/encrypt.js
|
|
1364
|
-
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
1365
|
-
if (!(cek instanceof Uint8Array)) {
|
|
1366
|
-
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
1367
|
-
}
|
|
1368
|
-
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
1369
|
-
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["encrypt"]);
|
|
1370
|
-
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
1371
|
-
hash: `SHA-${keySize << 1}`,
|
|
1372
|
-
name: "HMAC"
|
|
1373
|
-
}, false, ["sign"]);
|
|
1374
|
-
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
1375
|
-
iv,
|
|
1376
|
-
name: "AES-CBC"
|
|
1377
|
-
}, encKey, plaintext));
|
|
1378
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
1379
|
-
const tag2 = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
1380
|
-
return { ciphertext, tag: tag2, iv };
|
|
1381
|
-
}
|
|
1382
|
-
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
1383
|
-
let encKey;
|
|
1384
|
-
if (cek instanceof Uint8Array) {
|
|
1385
|
-
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
|
|
1386
|
-
} else {
|
|
1387
|
-
checkEncCryptoKey(cek, enc, "encrypt");
|
|
1388
|
-
encKey = cek;
|
|
1389
|
-
}
|
|
1390
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
1391
|
-
additionalData: aad,
|
|
1392
|
-
iv,
|
|
1393
|
-
name: "AES-GCM",
|
|
1394
|
-
tagLength: 128
|
|
1395
|
-
}, encKey, plaintext));
|
|
1396
|
-
const tag2 = encrypted.slice(-16);
|
|
1397
|
-
const ciphertext = encrypted.slice(0, -16);
|
|
1398
|
-
return { ciphertext, tag: tag2, iv };
|
|
1399
|
-
}
|
|
1400
|
-
async function encrypt2(enc, plaintext, cek, iv, aad) {
|
|
1401
|
-
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
1402
|
-
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
1403
|
-
}
|
|
1404
|
-
if (iv) {
|
|
1405
|
-
checkIvLength(enc, iv);
|
|
1406
|
-
} else {
|
|
1407
|
-
iv = generateIv(enc);
|
|
1408
|
-
}
|
|
1409
|
-
switch (enc) {
|
|
1410
|
-
case "A128CBC-HS256":
|
|
1411
|
-
case "A192CBC-HS384":
|
|
1412
|
-
case "A256CBC-HS512":
|
|
1413
|
-
if (cek instanceof Uint8Array) {
|
|
1414
|
-
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
1415
|
-
}
|
|
1416
|
-
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
1417
|
-
case "A128GCM":
|
|
1418
|
-
case "A192GCM":
|
|
1419
|
-
case "A256GCM":
|
|
1420
|
-
if (cek instanceof Uint8Array) {
|
|
1421
|
-
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
1422
|
-
}
|
|
1423
|
-
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
1424
|
-
default:
|
|
1425
|
-
throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
var init_encrypt = __esm({
|
|
1429
|
-
"node_modules/jose/dist/webapi/lib/encrypt.js"() {
|
|
1430
|
-
"use strict";
|
|
1431
|
-
init_esm_shims();
|
|
1432
|
-
init_buffer_utils();
|
|
1433
|
-
init_check_iv_length();
|
|
1434
|
-
init_check_cek_length();
|
|
1435
|
-
init_crypto_key();
|
|
1436
|
-
init_invalid_key_input();
|
|
1437
|
-
init_iv();
|
|
1438
|
-
init_errors();
|
|
1439
|
-
init_is_key_like();
|
|
1440
|
-
}
|
|
1441
|
-
});
|
|
1442
|
-
|
|
1443
|
-
// node_modules/jose/dist/webapi/lib/aesgcmkw.js
|
|
1444
|
-
async function wrap3(alg, key, cek, iv) {
|
|
1445
|
-
const jweAlgorithm = alg.slice(0, 7);
|
|
1446
|
-
const wrapped = await encrypt2(jweAlgorithm, cek, key, iv, new Uint8Array());
|
|
1447
|
-
return {
|
|
1448
|
-
encryptedKey: wrapped.ciphertext,
|
|
1449
|
-
iv: encode2(wrapped.iv),
|
|
1450
|
-
tag: encode2(wrapped.tag)
|
|
1451
|
-
};
|
|
1452
|
-
}
|
|
1453
|
-
async function unwrap3(alg, key, encryptedKey, iv, tag2) {
|
|
1454
|
-
const jweAlgorithm = alg.slice(0, 7);
|
|
1455
|
-
return decrypt(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array());
|
|
1456
|
-
}
|
|
1457
|
-
var init_aesgcmkw = __esm({
|
|
1458
|
-
"node_modules/jose/dist/webapi/lib/aesgcmkw.js"() {
|
|
1459
|
-
"use strict";
|
|
1460
|
-
init_esm_shims();
|
|
1461
|
-
init_encrypt();
|
|
1462
|
-
init_decrypt();
|
|
1463
|
-
init_base64url();
|
|
1464
|
-
}
|
|
1465
|
-
});
|
|
1466
|
-
|
|
1467
|
-
// node_modules/jose/dist/webapi/lib/decrypt_key_management.js
|
|
1468
|
-
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
1469
|
-
switch (alg) {
|
|
1470
|
-
case "dir": {
|
|
1471
|
-
if (encryptedKey !== void 0)
|
|
1472
|
-
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
1473
|
-
return key;
|
|
1474
|
-
}
|
|
1475
|
-
case "ECDH-ES":
|
|
1476
|
-
if (encryptedKey !== void 0)
|
|
1477
|
-
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
1478
|
-
case "ECDH-ES+A128KW":
|
|
1479
|
-
case "ECDH-ES+A192KW":
|
|
1480
|
-
case "ECDH-ES+A256KW": {
|
|
1481
|
-
if (!isObject(joseHeader.epk))
|
|
1482
|
-
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
1483
|
-
assertCryptoKey(key);
|
|
1484
|
-
if (!allowed(key))
|
|
1485
|
-
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
1486
|
-
const epk = await importJWK(joseHeader.epk, alg);
|
|
1487
|
-
assertCryptoKey(epk);
|
|
1488
|
-
let partyUInfo;
|
|
1489
|
-
let partyVInfo;
|
|
1490
|
-
if (joseHeader.apu !== void 0) {
|
|
1491
|
-
if (typeof joseHeader.apu !== "string")
|
|
1492
|
-
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
1493
|
-
try {
|
|
1494
|
-
partyUInfo = decode(joseHeader.apu);
|
|
1495
|
-
} catch {
|
|
1496
|
-
throw new JWEInvalid("Failed to base64url decode the apu");
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
if (joseHeader.apv !== void 0) {
|
|
1500
|
-
if (typeof joseHeader.apv !== "string")
|
|
1501
|
-
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
1502
|
-
try {
|
|
1503
|
-
partyVInfo = decode(joseHeader.apv);
|
|
1504
|
-
} catch {
|
|
1505
|
-
throw new JWEInvalid("Failed to base64url decode the apv");
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
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);
|
|
1509
|
-
if (alg === "ECDH-ES")
|
|
1510
|
-
return sharedSecret;
|
|
1511
|
-
if (encryptedKey === void 0)
|
|
1512
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1513
|
-
return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
|
|
1514
|
-
}
|
|
1515
|
-
case "RSA-OAEP":
|
|
1516
|
-
case "RSA-OAEP-256":
|
|
1517
|
-
case "RSA-OAEP-384":
|
|
1518
|
-
case "RSA-OAEP-512": {
|
|
1519
|
-
if (encryptedKey === void 0)
|
|
1520
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1521
|
-
assertCryptoKey(key);
|
|
1522
|
-
return decrypt2(alg, key, encryptedKey);
|
|
1523
|
-
}
|
|
1524
|
-
case "PBES2-HS256+A128KW":
|
|
1525
|
-
case "PBES2-HS384+A192KW":
|
|
1526
|
-
case "PBES2-HS512+A256KW": {
|
|
1527
|
-
if (encryptedKey === void 0)
|
|
1528
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1529
|
-
if (typeof joseHeader.p2c !== "number")
|
|
1530
|
-
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
1531
|
-
const p2cLimit = options?.maxPBES2Count || 1e4;
|
|
1532
|
-
if (joseHeader.p2c > p2cLimit)
|
|
1533
|
-
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
1534
|
-
if (typeof joseHeader.p2s !== "string")
|
|
1535
|
-
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
1536
|
-
let p2s;
|
|
1537
|
-
try {
|
|
1538
|
-
p2s = decode(joseHeader.p2s);
|
|
1539
|
-
} catch {
|
|
1540
|
-
throw new JWEInvalid("Failed to base64url decode the p2s");
|
|
1541
|
-
}
|
|
1542
|
-
return unwrap2(alg, key, encryptedKey, joseHeader.p2c, p2s);
|
|
1543
|
-
}
|
|
1544
|
-
case "A128KW":
|
|
1545
|
-
case "A192KW":
|
|
1546
|
-
case "A256KW": {
|
|
1547
|
-
if (encryptedKey === void 0)
|
|
1548
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1549
|
-
return unwrap(alg, key, encryptedKey);
|
|
1550
|
-
}
|
|
1551
|
-
case "A128GCMKW":
|
|
1552
|
-
case "A192GCMKW":
|
|
1553
|
-
case "A256GCMKW": {
|
|
1554
|
-
if (encryptedKey === void 0)
|
|
1555
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
1556
|
-
if (typeof joseHeader.iv !== "string")
|
|
1557
|
-
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
1558
|
-
if (typeof joseHeader.tag !== "string")
|
|
1559
|
-
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
1560
|
-
let iv;
|
|
1561
|
-
try {
|
|
1562
|
-
iv = decode(joseHeader.iv);
|
|
1563
|
-
} catch {
|
|
1564
|
-
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
1565
|
-
}
|
|
1566
|
-
let tag2;
|
|
1567
|
-
try {
|
|
1568
|
-
tag2 = decode(joseHeader.tag);
|
|
1569
|
-
} catch {
|
|
1570
|
-
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
1571
|
-
}
|
|
1572
|
-
return unwrap3(alg, key, encryptedKey, iv, tag2);
|
|
1573
|
-
}
|
|
1574
|
-
default: {
|
|
1575
|
-
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
var init_decrypt_key_management = __esm({
|
|
1580
|
-
"node_modules/jose/dist/webapi/lib/decrypt_key_management.js"() {
|
|
1581
|
-
"use strict";
|
|
1582
|
-
init_esm_shims();
|
|
1583
|
-
init_aeskw();
|
|
1584
|
-
init_ecdhes();
|
|
1585
|
-
init_pbes2kw();
|
|
1586
|
-
init_rsaes();
|
|
1587
|
-
init_base64url();
|
|
1588
|
-
init_errors();
|
|
1589
|
-
init_cek();
|
|
1590
|
-
init_import();
|
|
1591
|
-
init_is_object();
|
|
1592
|
-
init_aesgcmkw();
|
|
1593
|
-
init_is_key_like();
|
|
1594
|
-
}
|
|
1595
|
-
});
|
|
1596
|
-
|
|
1597
|
-
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1598
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1599
|
-
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
1600
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
1601
|
-
}
|
|
1602
|
-
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
1603
|
-
return /* @__PURE__ */ new Set();
|
|
1604
|
-
}
|
|
1605
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
1606
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
1607
|
-
}
|
|
1608
|
-
let recognized;
|
|
1609
|
-
if (recognizedOption !== void 0) {
|
|
1610
|
-
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1611
|
-
} else {
|
|
1612
|
-
recognized = recognizedDefault;
|
|
1613
|
-
}
|
|
1614
|
-
for (const parameter of protectedHeader.crit) {
|
|
1615
|
-
if (!recognized.has(parameter)) {
|
|
1616
|
-
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1617
|
-
}
|
|
1618
|
-
if (joseHeader[parameter] === void 0) {
|
|
1619
|
-
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1620
|
-
}
|
|
1621
|
-
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
1622
|
-
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
return new Set(protectedHeader.crit);
|
|
1626
|
-
}
|
|
1627
|
-
var init_validate_crit = __esm({
|
|
1628
|
-
"node_modules/jose/dist/webapi/lib/validate_crit.js"() {
|
|
1629
|
-
"use strict";
|
|
1630
|
-
init_esm_shims();
|
|
1631
|
-
init_errors();
|
|
1632
|
-
}
|
|
1633
|
-
});
|
|
1634
|
-
|
|
1635
|
-
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
1636
|
-
function validateAlgorithms(option, algorithms) {
|
|
1637
|
-
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
1638
|
-
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
1639
|
-
}
|
|
1640
|
-
if (!algorithms) {
|
|
1641
|
-
return void 0;
|
|
1642
|
-
}
|
|
1643
|
-
return new Set(algorithms);
|
|
1644
|
-
}
|
|
1645
|
-
var init_validate_algorithms = __esm({
|
|
1646
|
-
"node_modules/jose/dist/webapi/lib/validate_algorithms.js"() {
|
|
1647
|
-
"use strict";
|
|
1648
|
-
init_esm_shims();
|
|
1649
|
-
}
|
|
1650
|
-
});
|
|
1651
|
-
|
|
1652
|
-
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
1653
|
-
var isJWK, isPrivateJWK, isPublicJWK, isSecretJWK;
|
|
1654
|
-
var init_is_jwk = __esm({
|
|
1655
|
-
"node_modules/jose/dist/webapi/lib/is_jwk.js"() {
|
|
1656
|
-
"use strict";
|
|
1657
|
-
init_esm_shims();
|
|
1658
|
-
init_is_object();
|
|
1659
|
-
isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
1660
|
-
isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
1661
|
-
isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
1662
|
-
isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
1663
|
-
}
|
|
1664
|
-
});
|
|
1665
|
-
|
|
1666
|
-
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
1667
|
-
async function normalizeKey(key, alg) {
|
|
1668
|
-
if (key instanceof Uint8Array) {
|
|
1669
|
-
return key;
|
|
1670
|
-
}
|
|
1671
|
-
if (isCryptoKey(key)) {
|
|
1672
|
-
return key;
|
|
1673
|
-
}
|
|
1674
|
-
if (isKeyObject(key)) {
|
|
1675
|
-
if (key.type === "secret") {
|
|
1676
|
-
return key.export();
|
|
1677
|
-
}
|
|
1678
|
-
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
1679
|
-
try {
|
|
1680
|
-
return handleKeyObject(key, alg);
|
|
1681
|
-
} catch (err) {
|
|
1682
|
-
if (err instanceof TypeError) {
|
|
1683
|
-
throw err;
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
let jwk = key.export({ format: "jwk" });
|
|
1688
|
-
return handleJWK(key, jwk, alg);
|
|
1689
|
-
}
|
|
1690
|
-
if (isJWK(key)) {
|
|
1691
|
-
if (key.k) {
|
|
1692
|
-
return decode(key.k);
|
|
1693
|
-
}
|
|
1694
|
-
return handleJWK(key, key, alg, true);
|
|
1695
|
-
}
|
|
1696
|
-
throw new Error("unreachable");
|
|
1697
|
-
}
|
|
1698
|
-
var cache, handleJWK, handleKeyObject;
|
|
1699
|
-
var init_normalize_key = __esm({
|
|
1700
|
-
"node_modules/jose/dist/webapi/lib/normalize_key.js"() {
|
|
1701
|
-
"use strict";
|
|
1702
|
-
init_esm_shims();
|
|
1703
|
-
init_is_jwk();
|
|
1704
|
-
init_base64url();
|
|
1705
|
-
init_jwk_to_key();
|
|
1706
|
-
init_is_key_like();
|
|
1707
|
-
handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
1708
|
-
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1709
|
-
let cached = cache.get(key);
|
|
1710
|
-
if (cached?.[alg]) {
|
|
1711
|
-
return cached[alg];
|
|
1712
|
-
}
|
|
1713
|
-
const cryptoKey = await jwkToKey({ ...jwk, alg });
|
|
1714
|
-
if (freeze)
|
|
1715
|
-
Object.freeze(key);
|
|
1716
|
-
if (!cached) {
|
|
1717
|
-
cache.set(key, { [alg]: cryptoKey });
|
|
1718
|
-
} else {
|
|
1719
|
-
cached[alg] = cryptoKey;
|
|
1720
|
-
}
|
|
1721
|
-
return cryptoKey;
|
|
1722
|
-
};
|
|
1723
|
-
handleKeyObject = (keyObject, alg) => {
|
|
1724
|
-
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1725
|
-
let cached = cache.get(keyObject);
|
|
1726
|
-
if (cached?.[alg]) {
|
|
1727
|
-
return cached[alg];
|
|
1728
|
-
}
|
|
1729
|
-
const isPublic = keyObject.type === "public";
|
|
1730
|
-
const extractable = isPublic ? true : false;
|
|
1731
|
-
let cryptoKey;
|
|
1732
|
-
if (keyObject.asymmetricKeyType === "x25519") {
|
|
1733
|
-
switch (alg) {
|
|
1734
|
-
case "ECDH-ES":
|
|
1735
|
-
case "ECDH-ES+A128KW":
|
|
1736
|
-
case "ECDH-ES+A192KW":
|
|
1737
|
-
case "ECDH-ES+A256KW":
|
|
1738
|
-
break;
|
|
1739
|
-
default:
|
|
1740
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1741
|
-
}
|
|
1742
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1743
|
-
}
|
|
1744
|
-
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
1745
|
-
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
1746
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1747
|
-
}
|
|
1748
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1749
|
-
isPublic ? "verify" : "sign"
|
|
1750
|
-
]);
|
|
1751
|
-
}
|
|
1752
|
-
switch (keyObject.asymmetricKeyType) {
|
|
1753
|
-
case "ml-dsa-44":
|
|
1754
|
-
case "ml-dsa-65":
|
|
1755
|
-
case "ml-dsa-87": {
|
|
1756
|
-
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
1757
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1758
|
-
}
|
|
1759
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1760
|
-
isPublic ? "verify" : "sign"
|
|
1761
|
-
]);
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
if (keyObject.asymmetricKeyType === "rsa") {
|
|
1765
|
-
let hash;
|
|
1766
|
-
switch (alg) {
|
|
1767
|
-
case "RSA-OAEP":
|
|
1768
|
-
hash = "SHA-1";
|
|
1769
|
-
break;
|
|
1770
|
-
case "RS256":
|
|
1771
|
-
case "PS256":
|
|
1772
|
-
case "RSA-OAEP-256":
|
|
1773
|
-
hash = "SHA-256";
|
|
1774
|
-
break;
|
|
1775
|
-
case "RS384":
|
|
1776
|
-
case "PS384":
|
|
1777
|
-
case "RSA-OAEP-384":
|
|
1778
|
-
hash = "SHA-384";
|
|
1779
|
-
break;
|
|
1780
|
-
case "RS512":
|
|
1781
|
-
case "PS512":
|
|
1782
|
-
case "RSA-OAEP-512":
|
|
1783
|
-
hash = "SHA-512";
|
|
1784
|
-
break;
|
|
1785
|
-
default:
|
|
1786
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1787
|
-
}
|
|
1788
|
-
if (alg.startsWith("RSA-OAEP")) {
|
|
1789
|
-
return keyObject.toCryptoKey({
|
|
1790
|
-
name: "RSA-OAEP",
|
|
1791
|
-
hash
|
|
1792
|
-
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
1793
|
-
}
|
|
1794
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1795
|
-
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
1796
|
-
hash
|
|
1797
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1798
|
-
}
|
|
1799
|
-
if (keyObject.asymmetricKeyType === "ec") {
|
|
1800
|
-
const nist = /* @__PURE__ */ new Map([
|
|
1801
|
-
["prime256v1", "P-256"],
|
|
1802
|
-
["secp384r1", "P-384"],
|
|
1803
|
-
["secp521r1", "P-521"]
|
|
1804
|
-
]);
|
|
1805
|
-
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
1806
|
-
if (!namedCurve) {
|
|
1807
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1808
|
-
}
|
|
1809
|
-
if (alg === "ES256" && namedCurve === "P-256") {
|
|
1810
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1811
|
-
name: "ECDSA",
|
|
1812
|
-
namedCurve
|
|
1813
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1814
|
-
}
|
|
1815
|
-
if (alg === "ES384" && namedCurve === "P-384") {
|
|
1816
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1817
|
-
name: "ECDSA",
|
|
1818
|
-
namedCurve
|
|
1819
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1820
|
-
}
|
|
1821
|
-
if (alg === "ES512" && namedCurve === "P-521") {
|
|
1822
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1823
|
-
name: "ECDSA",
|
|
1824
|
-
namedCurve
|
|
1825
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1826
|
-
}
|
|
1827
|
-
if (alg.startsWith("ECDH-ES")) {
|
|
1828
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1829
|
-
name: "ECDH",
|
|
1830
|
-
namedCurve
|
|
1831
|
-
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
if (!cryptoKey) {
|
|
1835
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1836
|
-
}
|
|
1837
|
-
if (!cached) {
|
|
1838
|
-
cache.set(keyObject, { [alg]: cryptoKey });
|
|
1839
|
-
} else {
|
|
1840
|
-
cached[alg] = cryptoKey;
|
|
1841
|
-
}
|
|
1842
|
-
return cryptoKey;
|
|
1843
|
-
};
|
|
1844
|
-
}
|
|
1845
|
-
});
|
|
1846
|
-
|
|
1847
|
-
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
1848
|
-
function checkKeyType(alg, key, usage) {
|
|
1849
|
-
switch (alg.substring(0, 2)) {
|
|
1850
|
-
case "A1":
|
|
1851
|
-
case "A2":
|
|
1852
|
-
case "di":
|
|
1853
|
-
case "HS":
|
|
1854
|
-
case "PB":
|
|
1855
|
-
symmetricTypeCheck(alg, key, usage);
|
|
1856
|
-
break;
|
|
1857
|
-
default:
|
|
1858
|
-
asymmetricTypeCheck(alg, key, usage);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
var tag, jwkMatchesOp, symmetricTypeCheck, asymmetricTypeCheck;
|
|
1862
|
-
var init_check_key_type = __esm({
|
|
1863
|
-
"node_modules/jose/dist/webapi/lib/check_key_type.js"() {
|
|
1864
|
-
"use strict";
|
|
1865
|
-
init_esm_shims();
|
|
1866
|
-
init_invalid_key_input();
|
|
1867
|
-
init_is_key_like();
|
|
1868
|
-
init_is_jwk();
|
|
1869
|
-
tag = (key) => key?.[Symbol.toStringTag];
|
|
1870
|
-
jwkMatchesOp = (alg, key, usage) => {
|
|
1871
|
-
if (key.use !== void 0) {
|
|
1872
|
-
let expected;
|
|
1873
|
-
switch (usage) {
|
|
1874
|
-
case "sign":
|
|
1875
|
-
case "verify":
|
|
1876
|
-
expected = "sig";
|
|
1877
|
-
break;
|
|
1878
|
-
case "encrypt":
|
|
1879
|
-
case "decrypt":
|
|
1880
|
-
expected = "enc";
|
|
1881
|
-
break;
|
|
1882
|
-
}
|
|
1883
|
-
if (key.use !== expected) {
|
|
1884
|
-
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
if (key.alg !== void 0 && key.alg !== alg) {
|
|
1888
|
-
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
1889
|
-
}
|
|
1890
|
-
if (Array.isArray(key.key_ops)) {
|
|
1891
|
-
let expectedKeyOp;
|
|
1892
|
-
switch (true) {
|
|
1893
|
-
case (usage === "sign" || usage === "verify"):
|
|
1894
|
-
case alg === "dir":
|
|
1895
|
-
case alg.includes("CBC-HS"):
|
|
1896
|
-
expectedKeyOp = usage;
|
|
1897
|
-
break;
|
|
1898
|
-
case alg.startsWith("PBES2"):
|
|
1899
|
-
expectedKeyOp = "deriveBits";
|
|
1900
|
-
break;
|
|
1901
|
-
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
1902
|
-
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
1903
|
-
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
1904
|
-
} else {
|
|
1905
|
-
expectedKeyOp = usage;
|
|
1906
|
-
}
|
|
1907
|
-
break;
|
|
1908
|
-
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
1909
|
-
expectedKeyOp = "wrapKey";
|
|
1910
|
-
break;
|
|
1911
|
-
case usage === "decrypt":
|
|
1912
|
-
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
1913
|
-
break;
|
|
1914
|
-
}
|
|
1915
|
-
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
1916
|
-
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
return true;
|
|
1920
|
-
};
|
|
1921
|
-
symmetricTypeCheck = (alg, key, usage) => {
|
|
1922
|
-
if (key instanceof Uint8Array)
|
|
1923
|
-
return;
|
|
1924
|
-
if (isJWK(key)) {
|
|
1925
|
-
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1926
|
-
return;
|
|
1927
|
-
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`);
|
|
1928
|
-
}
|
|
1929
|
-
if (!isKeyLike(key)) {
|
|
1930
|
-
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
1931
|
-
}
|
|
1932
|
-
if (key.type !== "secret") {
|
|
1933
|
-
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
1934
|
-
}
|
|
1935
|
-
};
|
|
1936
|
-
asymmetricTypeCheck = (alg, key, usage) => {
|
|
1937
|
-
if (isJWK(key)) {
|
|
1938
|
-
switch (usage) {
|
|
1939
|
-
case "decrypt":
|
|
1940
|
-
case "sign":
|
|
1941
|
-
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1942
|
-
return;
|
|
1943
|
-
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
1944
|
-
case "encrypt":
|
|
1945
|
-
case "verify":
|
|
1946
|
-
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1947
|
-
return;
|
|
1948
|
-
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
if (!isKeyLike(key)) {
|
|
1952
|
-
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1953
|
-
}
|
|
1954
|
-
if (key.type === "secret") {
|
|
1955
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
1956
|
-
}
|
|
1957
|
-
if (key.type === "public") {
|
|
1958
|
-
switch (usage) {
|
|
1959
|
-
case "sign":
|
|
1960
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
1961
|
-
case "decrypt":
|
|
1962
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
if (key.type === "private") {
|
|
1966
|
-
switch (usage) {
|
|
1967
|
-
case "verify":
|
|
1968
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
1969
|
-
case "encrypt":
|
|
1970
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
};
|
|
1974
|
-
}
|
|
1975
|
-
});
|
|
1976
|
-
|
|
1977
|
-
// node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
1978
|
-
async function flattenedDecrypt(jwe, key, options) {
|
|
1979
|
-
if (!isObject(jwe)) {
|
|
1980
|
-
throw new JWEInvalid("Flattened JWE must be an object");
|
|
1981
|
-
}
|
|
1982
|
-
if (jwe.protected === void 0 && jwe.header === void 0 && jwe.unprotected === void 0) {
|
|
1983
|
-
throw new JWEInvalid("JOSE Header missing");
|
|
1984
|
-
}
|
|
1985
|
-
if (jwe.iv !== void 0 && typeof jwe.iv !== "string") {
|
|
1986
|
-
throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
1987
|
-
}
|
|
1988
|
-
if (typeof jwe.ciphertext !== "string") {
|
|
1989
|
-
throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
|
|
1990
|
-
}
|
|
1991
|
-
if (jwe.tag !== void 0 && typeof jwe.tag !== "string") {
|
|
1992
|
-
throw new JWEInvalid("JWE Authentication Tag incorrect type");
|
|
1993
|
-
}
|
|
1994
|
-
if (jwe.protected !== void 0 && typeof jwe.protected !== "string") {
|
|
1995
|
-
throw new JWEInvalid("JWE Protected Header incorrect type");
|
|
1996
|
-
}
|
|
1997
|
-
if (jwe.encrypted_key !== void 0 && typeof jwe.encrypted_key !== "string") {
|
|
1998
|
-
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
1999
|
-
}
|
|
2000
|
-
if (jwe.aad !== void 0 && typeof jwe.aad !== "string") {
|
|
2001
|
-
throw new JWEInvalid("JWE AAD incorrect type");
|
|
2002
|
-
}
|
|
2003
|
-
if (jwe.header !== void 0 && !isObject(jwe.header)) {
|
|
2004
|
-
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
2005
|
-
}
|
|
2006
|
-
if (jwe.unprotected !== void 0 && !isObject(jwe.unprotected)) {
|
|
2007
|
-
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
2008
|
-
}
|
|
2009
|
-
let parsedProt;
|
|
2010
|
-
if (jwe.protected) {
|
|
2011
|
-
try {
|
|
2012
|
-
const protectedHeader2 = decode(jwe.protected);
|
|
2013
|
-
parsedProt = JSON.parse(decoder.decode(protectedHeader2));
|
|
2014
|
-
} catch {
|
|
2015
|
-
throw new JWEInvalid("JWE Protected Header is invalid");
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
if (!isDisjoint(parsedProt, jwe.header, jwe.unprotected)) {
|
|
2019
|
-
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
2020
|
-
}
|
|
2021
|
-
const joseHeader = {
|
|
2022
|
-
...parsedProt,
|
|
2023
|
-
...jwe.header,
|
|
2024
|
-
...jwe.unprotected
|
|
2025
|
-
};
|
|
2026
|
-
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, parsedProt, joseHeader);
|
|
2027
|
-
if (joseHeader.zip !== void 0) {
|
|
2028
|
-
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
2029
|
-
}
|
|
2030
|
-
const { alg, enc } = joseHeader;
|
|
2031
|
-
if (typeof alg !== "string" || !alg) {
|
|
2032
|
-
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
2033
|
-
}
|
|
2034
|
-
if (typeof enc !== "string" || !enc) {
|
|
2035
|
-
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
2036
|
-
}
|
|
2037
|
-
const keyManagementAlgorithms = options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms);
|
|
2038
|
-
const contentEncryptionAlgorithms = options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms);
|
|
2039
|
-
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
|
|
2040
|
-
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
2041
|
-
}
|
|
2042
|
-
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
|
|
2043
|
-
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
2044
|
-
}
|
|
2045
|
-
let encryptedKey;
|
|
2046
|
-
if (jwe.encrypted_key !== void 0) {
|
|
2047
|
-
try {
|
|
2048
|
-
encryptedKey = decode(jwe.encrypted_key);
|
|
2049
|
-
} catch {
|
|
2050
|
-
throw new JWEInvalid("Failed to base64url decode the encrypted_key");
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
let resolvedKey = false;
|
|
2054
|
-
if (typeof key === "function") {
|
|
2055
|
-
key = await key(parsedProt, jwe);
|
|
2056
|
-
resolvedKey = true;
|
|
2057
|
-
}
|
|
2058
|
-
checkKeyType(alg === "dir" ? enc : alg, key, "decrypt");
|
|
2059
|
-
const k = await normalizeKey(key, alg);
|
|
2060
|
-
let cek;
|
|
2061
|
-
try {
|
|
2062
|
-
cek = await decryptKeyManagement(alg, k, encryptedKey, joseHeader, options);
|
|
2063
|
-
} catch (err) {
|
|
2064
|
-
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
2065
|
-
throw err;
|
|
2066
|
-
}
|
|
2067
|
-
cek = generateCek(enc);
|
|
2068
|
-
}
|
|
2069
|
-
let iv;
|
|
2070
|
-
let tag2;
|
|
2071
|
-
if (jwe.iv !== void 0) {
|
|
2072
|
-
try {
|
|
2073
|
-
iv = decode(jwe.iv);
|
|
2074
|
-
} catch {
|
|
2075
|
-
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
if (jwe.tag !== void 0) {
|
|
2079
|
-
try {
|
|
2080
|
-
tag2 = decode(jwe.tag);
|
|
2081
|
-
} catch {
|
|
2082
|
-
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
const protectedHeader = jwe.protected !== void 0 ? encode(jwe.protected) : new Uint8Array();
|
|
2086
|
-
let additionalData;
|
|
2087
|
-
if (jwe.aad !== void 0) {
|
|
2088
|
-
additionalData = concat(protectedHeader, encode("."), encode(jwe.aad));
|
|
2089
|
-
} else {
|
|
2090
|
-
additionalData = protectedHeader;
|
|
2091
|
-
}
|
|
2092
|
-
let ciphertext;
|
|
2093
|
-
try {
|
|
2094
|
-
ciphertext = decode(jwe.ciphertext);
|
|
2095
|
-
} catch {
|
|
2096
|
-
throw new JWEInvalid("Failed to base64url decode the ciphertext");
|
|
2097
|
-
}
|
|
2098
|
-
const plaintext = await decrypt(enc, cek, ciphertext, iv, tag2, additionalData);
|
|
2099
|
-
const result = { plaintext };
|
|
2100
|
-
if (jwe.protected !== void 0) {
|
|
2101
|
-
result.protectedHeader = parsedProt;
|
|
2102
|
-
}
|
|
2103
|
-
if (jwe.aad !== void 0) {
|
|
2104
|
-
try {
|
|
2105
|
-
result.additionalAuthenticatedData = decode(jwe.aad);
|
|
2106
|
-
} catch {
|
|
2107
|
-
throw new JWEInvalid("Failed to base64url decode the aad");
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
if (jwe.unprotected !== void 0) {
|
|
2111
|
-
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
2112
|
-
}
|
|
2113
|
-
if (jwe.header !== void 0) {
|
|
2114
|
-
result.unprotectedHeader = jwe.header;
|
|
2115
|
-
}
|
|
2116
|
-
if (resolvedKey) {
|
|
2117
|
-
return { ...result, key: k };
|
|
2118
|
-
}
|
|
2119
|
-
return result;
|
|
2120
|
-
}
|
|
2121
|
-
var init_decrypt2 = __esm({
|
|
2122
|
-
"node_modules/jose/dist/webapi/jwe/flattened/decrypt.js"() {
|
|
2123
|
-
"use strict";
|
|
2124
|
-
init_esm_shims();
|
|
2125
|
-
init_base64url();
|
|
2126
|
-
init_decrypt();
|
|
2127
|
-
init_errors();
|
|
2128
|
-
init_is_disjoint();
|
|
2129
|
-
init_is_object();
|
|
2130
|
-
init_decrypt_key_management();
|
|
2131
|
-
init_buffer_utils();
|
|
2132
|
-
init_cek();
|
|
2133
|
-
init_validate_crit();
|
|
2134
|
-
init_validate_algorithms();
|
|
2135
|
-
init_normalize_key();
|
|
2136
|
-
init_check_key_type();
|
|
2137
|
-
}
|
|
2138
|
-
});
|
|
2139
|
-
|
|
2140
|
-
// node_modules/jose/dist/webapi/jwe/compact/decrypt.js
|
|
2141
|
-
async function compactDecrypt(jwe, key, options) {
|
|
2142
|
-
if (jwe instanceof Uint8Array) {
|
|
2143
|
-
jwe = decoder.decode(jwe);
|
|
2144
|
-
}
|
|
2145
|
-
if (typeof jwe !== "string") {
|
|
2146
|
-
throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
|
|
2147
|
-
}
|
|
2148
|
-
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
|
|
2149
|
-
if (length !== 5) {
|
|
2150
|
-
throw new JWEInvalid("Invalid Compact JWE");
|
|
2151
|
-
}
|
|
2152
|
-
const decrypted = await flattenedDecrypt({
|
|
2153
|
-
ciphertext,
|
|
2154
|
-
iv: iv || void 0,
|
|
2155
|
-
protected: protectedHeader,
|
|
2156
|
-
tag: tag2 || void 0,
|
|
2157
|
-
encrypted_key: encryptedKey || void 0
|
|
2158
|
-
}, key, options);
|
|
2159
|
-
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
|
2160
|
-
if (typeof key === "function") {
|
|
2161
|
-
return { ...result, key: decrypted.key };
|
|
2162
|
-
}
|
|
2163
|
-
return result;
|
|
2164
|
-
}
|
|
2165
|
-
var init_decrypt3 = __esm({
|
|
2166
|
-
"node_modules/jose/dist/webapi/jwe/compact/decrypt.js"() {
|
|
2167
|
-
"use strict";
|
|
2168
|
-
init_esm_shims();
|
|
2169
|
-
init_decrypt2();
|
|
2170
|
-
init_errors();
|
|
2171
|
-
init_buffer_utils();
|
|
2172
|
-
}
|
|
2173
|
-
});
|
|
2174
|
-
|
|
2175
|
-
// node_modules/jose/dist/webapi/jwe/general/decrypt.js
|
|
2176
|
-
async function generalDecrypt(jwe, key, options) {
|
|
2177
|
-
if (!isObject(jwe)) {
|
|
2178
|
-
throw new JWEInvalid("General JWE must be an object");
|
|
2179
|
-
}
|
|
2180
|
-
if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(isObject)) {
|
|
2181
|
-
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
2182
|
-
}
|
|
2183
|
-
if (!jwe.recipients.length) {
|
|
2184
|
-
throw new JWEInvalid("JWE Recipients has no members");
|
|
2185
|
-
}
|
|
2186
|
-
for (const recipient of jwe.recipients) {
|
|
2187
|
-
try {
|
|
2188
|
-
return await flattenedDecrypt({
|
|
2189
|
-
aad: jwe.aad,
|
|
2190
|
-
ciphertext: jwe.ciphertext,
|
|
2191
|
-
encrypted_key: recipient.encrypted_key,
|
|
2192
|
-
header: recipient.header,
|
|
2193
|
-
iv: jwe.iv,
|
|
2194
|
-
protected: jwe.protected,
|
|
2195
|
-
tag: jwe.tag,
|
|
2196
|
-
unprotected: jwe.unprotected
|
|
2197
|
-
}, key, options);
|
|
2198
|
-
} catch {
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
throw new JWEDecryptionFailed();
|
|
2202
|
-
}
|
|
2203
|
-
var init_decrypt4 = __esm({
|
|
2204
|
-
"node_modules/jose/dist/webapi/jwe/general/decrypt.js"() {
|
|
2205
|
-
"use strict";
|
|
2206
|
-
init_esm_shims();
|
|
2207
|
-
init_decrypt2();
|
|
2208
|
-
init_errors();
|
|
2209
|
-
init_is_object();
|
|
2210
|
-
}
|
|
2211
|
-
});
|
|
2212
|
-
|
|
2213
|
-
// node_modules/jose/dist/webapi/lib/private_symbols.js
|
|
2214
|
-
var unprotected;
|
|
2215
|
-
var init_private_symbols = __esm({
|
|
2216
|
-
"node_modules/jose/dist/webapi/lib/private_symbols.js"() {
|
|
2217
|
-
"use strict";
|
|
2218
|
-
init_esm_shims();
|
|
2219
|
-
unprotected = /* @__PURE__ */ Symbol();
|
|
2220
|
-
}
|
|
2221
|
-
});
|
|
2222
|
-
|
|
2223
|
-
// node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
2224
|
-
async function keyToJWK(key) {
|
|
2225
|
-
if (isKeyObject(key)) {
|
|
2226
|
-
if (key.type === "secret") {
|
|
2227
|
-
key = key.export();
|
|
2228
|
-
} else {
|
|
2229
|
-
return key.export({ format: "jwk" });
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
if (key instanceof Uint8Array) {
|
|
2233
|
-
return {
|
|
2234
|
-
kty: "oct",
|
|
2235
|
-
k: encode2(key)
|
|
2236
|
-
};
|
|
2237
|
-
}
|
|
2238
|
-
if (!isCryptoKey(key)) {
|
|
2239
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
2240
|
-
}
|
|
2241
|
-
if (!key.extractable) {
|
|
2242
|
-
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
2243
|
-
}
|
|
2244
|
-
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
2245
|
-
if (jwk.kty === "AKP") {
|
|
2246
|
-
;
|
|
2247
|
-
jwk.alg = alg;
|
|
2248
|
-
}
|
|
2249
|
-
return jwk;
|
|
2250
|
-
}
|
|
2251
|
-
var init_key_to_jwk = __esm({
|
|
2252
|
-
"node_modules/jose/dist/webapi/lib/key_to_jwk.js"() {
|
|
2253
|
-
"use strict";
|
|
2254
|
-
init_esm_shims();
|
|
2255
|
-
init_invalid_key_input();
|
|
2256
|
-
init_base64url();
|
|
2257
|
-
init_is_key_like();
|
|
2258
|
-
}
|
|
2259
|
-
});
|
|
2260
|
-
|
|
2261
|
-
// node_modules/jose/dist/webapi/key/export.js
|
|
2262
|
-
async function exportSPKI(key) {
|
|
2263
|
-
return toSPKI(key);
|
|
2264
|
-
}
|
|
2265
|
-
async function exportPKCS8(key) {
|
|
2266
|
-
return toPKCS8(key);
|
|
2267
|
-
}
|
|
2268
|
-
async function exportJWK(key) {
|
|
2269
|
-
return keyToJWK(key);
|
|
2270
|
-
}
|
|
2271
|
-
var init_export = __esm({
|
|
2272
|
-
"node_modules/jose/dist/webapi/key/export.js"() {
|
|
2273
|
-
"use strict";
|
|
2274
|
-
init_esm_shims();
|
|
2275
|
-
init_asn1();
|
|
2276
|
-
init_key_to_jwk();
|
|
2277
|
-
}
|
|
2278
|
-
});
|
|
2279
|
-
|
|
2280
|
-
// node_modules/jose/dist/webapi/lib/encrypt_key_management.js
|
|
2281
|
-
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
2282
|
-
let encryptedKey;
|
|
2283
|
-
let parameters;
|
|
2284
|
-
let cek;
|
|
2285
|
-
switch (alg) {
|
|
2286
|
-
case "dir": {
|
|
2287
|
-
cek = key;
|
|
2288
|
-
break;
|
|
2289
|
-
}
|
|
2290
|
-
case "ECDH-ES":
|
|
2291
|
-
case "ECDH-ES+A128KW":
|
|
2292
|
-
case "ECDH-ES+A192KW":
|
|
2293
|
-
case "ECDH-ES+A256KW": {
|
|
2294
|
-
assertCryptoKey(key);
|
|
2295
|
-
if (!allowed(key)) {
|
|
2296
|
-
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
2297
|
-
}
|
|
2298
|
-
const { apu, apv } = providedParameters;
|
|
2299
|
-
let ephemeralKey;
|
|
2300
|
-
if (providedParameters.epk) {
|
|
2301
|
-
ephemeralKey = await normalizeKey(providedParameters.epk, alg);
|
|
2302
|
-
} else {
|
|
2303
|
-
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
2304
|
-
}
|
|
2305
|
-
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
2306
|
-
const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
2307
|
-
parameters = { epk: { x, crv, kty } };
|
|
2308
|
-
if (kty === "EC")
|
|
2309
|
-
parameters.epk.y = y;
|
|
2310
|
-
if (apu)
|
|
2311
|
-
parameters.apu = encode2(apu);
|
|
2312
|
-
if (apv)
|
|
2313
|
-
parameters.apv = encode2(apv);
|
|
2314
|
-
if (alg === "ECDH-ES") {
|
|
2315
|
-
cek = sharedSecret;
|
|
2316
|
-
break;
|
|
2317
|
-
}
|
|
2318
|
-
cek = providedCek || generateCek(enc);
|
|
2319
|
-
const kwAlg = alg.slice(-6);
|
|
2320
|
-
encryptedKey = await wrap(kwAlg, sharedSecret, cek);
|
|
2321
|
-
break;
|
|
2322
|
-
}
|
|
2323
|
-
case "RSA-OAEP":
|
|
2324
|
-
case "RSA-OAEP-256":
|
|
2325
|
-
case "RSA-OAEP-384":
|
|
2326
|
-
case "RSA-OAEP-512": {
|
|
2327
|
-
cek = providedCek || generateCek(enc);
|
|
2328
|
-
assertCryptoKey(key);
|
|
2329
|
-
encryptedKey = await encrypt(alg, key, cek);
|
|
2330
|
-
break;
|
|
2331
|
-
}
|
|
2332
|
-
case "PBES2-HS256+A128KW":
|
|
2333
|
-
case "PBES2-HS384+A192KW":
|
|
2334
|
-
case "PBES2-HS512+A256KW": {
|
|
2335
|
-
cek = providedCek || generateCek(enc);
|
|
2336
|
-
const { p2c, p2s } = providedParameters;
|
|
2337
|
-
({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, p2c, p2s));
|
|
2338
|
-
break;
|
|
2339
|
-
}
|
|
2340
|
-
case "A128KW":
|
|
2341
|
-
case "A192KW":
|
|
2342
|
-
case "A256KW": {
|
|
2343
|
-
cek = providedCek || generateCek(enc);
|
|
2344
|
-
encryptedKey = await wrap(alg, key, cek);
|
|
2345
|
-
break;
|
|
2346
|
-
}
|
|
2347
|
-
case "A128GCMKW":
|
|
2348
|
-
case "A192GCMKW":
|
|
2349
|
-
case "A256GCMKW": {
|
|
2350
|
-
cek = providedCek || generateCek(enc);
|
|
2351
|
-
const { iv } = providedParameters;
|
|
2352
|
-
({ encryptedKey, ...parameters } = await wrap3(alg, key, cek, iv));
|
|
2353
|
-
break;
|
|
2354
|
-
}
|
|
2355
|
-
default: {
|
|
2356
|
-
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
2357
|
-
}
|
|
2358
|
-
}
|
|
2359
|
-
return { cek, encryptedKey, parameters };
|
|
2360
|
-
}
|
|
2361
|
-
var init_encrypt_key_management = __esm({
|
|
2362
|
-
"node_modules/jose/dist/webapi/lib/encrypt_key_management.js"() {
|
|
2363
|
-
"use strict";
|
|
2364
|
-
init_esm_shims();
|
|
2365
|
-
init_aeskw();
|
|
2366
|
-
init_ecdhes();
|
|
2367
|
-
init_pbes2kw();
|
|
2368
|
-
init_rsaes();
|
|
2369
|
-
init_base64url();
|
|
2370
|
-
init_normalize_key();
|
|
2371
|
-
init_cek();
|
|
2372
|
-
init_errors();
|
|
2373
|
-
init_export();
|
|
2374
|
-
init_aesgcmkw();
|
|
2375
|
-
init_is_key_like();
|
|
2376
|
-
}
|
|
2377
|
-
});
|
|
2378
|
-
|
|
2379
|
-
// node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
2380
|
-
var FlattenedEncrypt;
|
|
2381
|
-
var init_encrypt2 = __esm({
|
|
2382
|
-
"node_modules/jose/dist/webapi/jwe/flattened/encrypt.js"() {
|
|
2383
|
-
"use strict";
|
|
2384
|
-
init_esm_shims();
|
|
2385
|
-
init_base64url();
|
|
2386
|
-
init_private_symbols();
|
|
2387
|
-
init_encrypt();
|
|
2388
|
-
init_encrypt_key_management();
|
|
2389
|
-
init_errors();
|
|
2390
|
-
init_is_disjoint();
|
|
2391
|
-
init_buffer_utils();
|
|
2392
|
-
init_validate_crit();
|
|
2393
|
-
init_normalize_key();
|
|
2394
|
-
init_check_key_type();
|
|
2395
|
-
FlattenedEncrypt = class {
|
|
2396
|
-
#plaintext;
|
|
2397
|
-
#protectedHeader;
|
|
2398
|
-
#sharedUnprotectedHeader;
|
|
2399
|
-
#unprotectedHeader;
|
|
2400
|
-
#aad;
|
|
2401
|
-
#cek;
|
|
2402
|
-
#iv;
|
|
2403
|
-
#keyManagementParameters;
|
|
2404
|
-
constructor(plaintext) {
|
|
2405
|
-
if (!(plaintext instanceof Uint8Array)) {
|
|
2406
|
-
throw new TypeError("plaintext must be an instance of Uint8Array");
|
|
2407
|
-
}
|
|
2408
|
-
this.#plaintext = plaintext;
|
|
2409
|
-
}
|
|
2410
|
-
setKeyManagementParameters(parameters) {
|
|
2411
|
-
if (this.#keyManagementParameters) {
|
|
2412
|
-
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
2413
|
-
}
|
|
2414
|
-
this.#keyManagementParameters = parameters;
|
|
2415
|
-
return this;
|
|
2416
|
-
}
|
|
2417
|
-
setProtectedHeader(protectedHeader) {
|
|
2418
|
-
if (this.#protectedHeader) {
|
|
2419
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
2420
|
-
}
|
|
2421
|
-
this.#protectedHeader = protectedHeader;
|
|
2422
|
-
return this;
|
|
2423
|
-
}
|
|
2424
|
-
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
2425
|
-
if (this.#sharedUnprotectedHeader) {
|
|
2426
|
-
throw new TypeError("setSharedUnprotectedHeader can only be called once");
|
|
2427
|
-
}
|
|
2428
|
-
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
2429
|
-
return this;
|
|
2430
|
-
}
|
|
2431
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
2432
|
-
if (this.#unprotectedHeader) {
|
|
2433
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
2434
|
-
}
|
|
2435
|
-
this.#unprotectedHeader = unprotectedHeader;
|
|
2436
|
-
return this;
|
|
2437
|
-
}
|
|
2438
|
-
setAdditionalAuthenticatedData(aad) {
|
|
2439
|
-
this.#aad = aad;
|
|
2440
|
-
return this;
|
|
2441
|
-
}
|
|
2442
|
-
setContentEncryptionKey(cek) {
|
|
2443
|
-
if (this.#cek) {
|
|
2444
|
-
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
2445
|
-
}
|
|
2446
|
-
this.#cek = cek;
|
|
2447
|
-
return this;
|
|
2448
|
-
}
|
|
2449
|
-
setInitializationVector(iv) {
|
|
2450
|
-
if (this.#iv) {
|
|
2451
|
-
throw new TypeError("setInitializationVector can only be called once");
|
|
2452
|
-
}
|
|
2453
|
-
this.#iv = iv;
|
|
2454
|
-
return this;
|
|
2455
|
-
}
|
|
2456
|
-
async encrypt(key, options) {
|
|
2457
|
-
if (!this.#protectedHeader && !this.#unprotectedHeader && !this.#sharedUnprotectedHeader) {
|
|
2458
|
-
throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
2459
|
-
}
|
|
2460
|
-
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, this.#sharedUnprotectedHeader)) {
|
|
2461
|
-
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
2462
|
-
}
|
|
2463
|
-
const joseHeader = {
|
|
2464
|
-
...this.#protectedHeader,
|
|
2465
|
-
...this.#unprotectedHeader,
|
|
2466
|
-
...this.#sharedUnprotectedHeader
|
|
2467
|
-
};
|
|
2468
|
-
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, this.#protectedHeader, joseHeader);
|
|
2469
|
-
if (joseHeader.zip !== void 0) {
|
|
2470
|
-
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
2471
|
-
}
|
|
2472
|
-
const { alg, enc } = joseHeader;
|
|
2473
|
-
if (typeof alg !== "string" || !alg) {
|
|
2474
|
-
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2475
|
-
}
|
|
2476
|
-
if (typeof enc !== "string" || !enc) {
|
|
2477
|
-
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
2478
|
-
}
|
|
2479
|
-
let encryptedKey;
|
|
2480
|
-
if (this.#cek && (alg === "dir" || alg === "ECDH-ES")) {
|
|
2481
|
-
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
2482
|
-
}
|
|
2483
|
-
checkKeyType(alg === "dir" ? enc : alg, key, "encrypt");
|
|
2484
|
-
let cek;
|
|
2485
|
-
{
|
|
2486
|
-
let parameters;
|
|
2487
|
-
const k = await normalizeKey(key, alg);
|
|
2488
|
-
({ cek, encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, this.#cek, this.#keyManagementParameters));
|
|
2489
|
-
if (parameters) {
|
|
2490
|
-
if (options && unprotected in options) {
|
|
2491
|
-
if (!this.#unprotectedHeader) {
|
|
2492
|
-
this.setUnprotectedHeader(parameters);
|
|
2493
|
-
} else {
|
|
2494
|
-
this.#unprotectedHeader = { ...this.#unprotectedHeader, ...parameters };
|
|
2495
|
-
}
|
|
2496
|
-
} else if (!this.#protectedHeader) {
|
|
2497
|
-
this.setProtectedHeader(parameters);
|
|
2498
|
-
} else {
|
|
2499
|
-
this.#protectedHeader = { ...this.#protectedHeader, ...parameters };
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2503
|
-
let additionalData;
|
|
2504
|
-
let protectedHeaderS;
|
|
2505
|
-
let protectedHeaderB;
|
|
2506
|
-
let aadMember;
|
|
2507
|
-
if (this.#protectedHeader) {
|
|
2508
|
-
protectedHeaderS = encode2(JSON.stringify(this.#protectedHeader));
|
|
2509
|
-
protectedHeaderB = encode(protectedHeaderS);
|
|
2510
|
-
} else {
|
|
2511
|
-
protectedHeaderS = "";
|
|
2512
|
-
protectedHeaderB = new Uint8Array();
|
|
2513
|
-
}
|
|
2514
|
-
if (this.#aad) {
|
|
2515
|
-
aadMember = encode2(this.#aad);
|
|
2516
|
-
const aadMemberBytes = encode(aadMember);
|
|
2517
|
-
additionalData = concat(protectedHeaderB, encode("."), aadMemberBytes);
|
|
2518
|
-
} else {
|
|
2519
|
-
additionalData = protectedHeaderB;
|
|
2520
|
-
}
|
|
2521
|
-
const { ciphertext, tag: tag2, iv } = await encrypt2(enc, this.#plaintext, cek, this.#iv, additionalData);
|
|
2522
|
-
const jwe = {
|
|
2523
|
-
ciphertext: encode2(ciphertext)
|
|
2524
|
-
};
|
|
2525
|
-
if (iv) {
|
|
2526
|
-
jwe.iv = encode2(iv);
|
|
2527
|
-
}
|
|
2528
|
-
if (tag2) {
|
|
2529
|
-
jwe.tag = encode2(tag2);
|
|
2530
|
-
}
|
|
2531
|
-
if (encryptedKey) {
|
|
2532
|
-
jwe.encrypted_key = encode2(encryptedKey);
|
|
2533
|
-
}
|
|
2534
|
-
if (aadMember) {
|
|
2535
|
-
jwe.aad = aadMember;
|
|
2536
|
-
}
|
|
2537
|
-
if (this.#protectedHeader) {
|
|
2538
|
-
jwe.protected = protectedHeaderS;
|
|
2539
|
-
}
|
|
2540
|
-
if (this.#sharedUnprotectedHeader) {
|
|
2541
|
-
jwe.unprotected = this.#sharedUnprotectedHeader;
|
|
2542
|
-
}
|
|
2543
|
-
if (this.#unprotectedHeader) {
|
|
2544
|
-
jwe.header = this.#unprotectedHeader;
|
|
2545
|
-
}
|
|
2546
|
-
return jwe;
|
|
2547
|
-
}
|
|
2548
|
-
};
|
|
2549
|
-
}
|
|
2550
|
-
});
|
|
2551
|
-
|
|
2552
|
-
// node_modules/jose/dist/webapi/jwe/general/encrypt.js
|
|
2553
|
-
var IndividualRecipient, GeneralEncrypt;
|
|
2554
|
-
var init_encrypt3 = __esm({
|
|
2555
|
-
"node_modules/jose/dist/webapi/jwe/general/encrypt.js"() {
|
|
2556
|
-
"use strict";
|
|
2557
|
-
init_esm_shims();
|
|
2558
|
-
init_encrypt2();
|
|
2559
|
-
init_private_symbols();
|
|
2560
|
-
init_errors();
|
|
2561
|
-
init_cek();
|
|
2562
|
-
init_is_disjoint();
|
|
2563
|
-
init_encrypt_key_management();
|
|
2564
|
-
init_base64url();
|
|
2565
|
-
init_validate_crit();
|
|
2566
|
-
init_normalize_key();
|
|
2567
|
-
init_check_key_type();
|
|
2568
|
-
IndividualRecipient = class {
|
|
2569
|
-
#parent;
|
|
2570
|
-
unprotectedHeader;
|
|
2571
|
-
keyManagementParameters;
|
|
2572
|
-
key;
|
|
2573
|
-
options;
|
|
2574
|
-
constructor(enc, key, options) {
|
|
2575
|
-
this.#parent = enc;
|
|
2576
|
-
this.key = key;
|
|
2577
|
-
this.options = options;
|
|
2578
|
-
}
|
|
2579
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
2580
|
-
if (this.unprotectedHeader) {
|
|
2581
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
2582
|
-
}
|
|
2583
|
-
this.unprotectedHeader = unprotectedHeader;
|
|
2584
|
-
return this;
|
|
2585
|
-
}
|
|
2586
|
-
setKeyManagementParameters(parameters) {
|
|
2587
|
-
if (this.keyManagementParameters) {
|
|
2588
|
-
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
2589
|
-
}
|
|
2590
|
-
this.keyManagementParameters = parameters;
|
|
2591
|
-
return this;
|
|
2592
|
-
}
|
|
2593
|
-
addRecipient(...args) {
|
|
2594
|
-
return this.#parent.addRecipient(...args);
|
|
2595
|
-
}
|
|
2596
|
-
encrypt(...args) {
|
|
2597
|
-
return this.#parent.encrypt(...args);
|
|
2598
|
-
}
|
|
2599
|
-
done() {
|
|
2600
|
-
return this.#parent;
|
|
2601
|
-
}
|
|
2602
|
-
};
|
|
2603
|
-
GeneralEncrypt = class {
|
|
2604
|
-
#plaintext;
|
|
2605
|
-
#recipients = [];
|
|
2606
|
-
#protectedHeader;
|
|
2607
|
-
#unprotectedHeader;
|
|
2608
|
-
#aad;
|
|
2609
|
-
constructor(plaintext) {
|
|
2610
|
-
this.#plaintext = plaintext;
|
|
2611
|
-
}
|
|
2612
|
-
addRecipient(key, options) {
|
|
2613
|
-
const recipient = new IndividualRecipient(this, key, { crit: options?.crit });
|
|
2614
|
-
this.#recipients.push(recipient);
|
|
2615
|
-
return recipient;
|
|
2616
|
-
}
|
|
2617
|
-
setProtectedHeader(protectedHeader) {
|
|
2618
|
-
if (this.#protectedHeader) {
|
|
2619
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
2620
|
-
}
|
|
2621
|
-
this.#protectedHeader = protectedHeader;
|
|
2622
|
-
return this;
|
|
2623
|
-
}
|
|
2624
|
-
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
2625
|
-
if (this.#unprotectedHeader) {
|
|
2626
|
-
throw new TypeError("setSharedUnprotectedHeader can only be called once");
|
|
2627
|
-
}
|
|
2628
|
-
this.#unprotectedHeader = sharedUnprotectedHeader;
|
|
2629
|
-
return this;
|
|
2630
|
-
}
|
|
2631
|
-
setAdditionalAuthenticatedData(aad) {
|
|
2632
|
-
this.#aad = aad;
|
|
2633
|
-
return this;
|
|
2634
|
-
}
|
|
2635
|
-
async encrypt() {
|
|
2636
|
-
if (!this.#recipients.length) {
|
|
2637
|
-
throw new JWEInvalid("at least one recipient must be added");
|
|
2638
|
-
}
|
|
2639
|
-
if (this.#recipients.length === 1) {
|
|
2640
|
-
const [recipient] = this.#recipients;
|
|
2641
|
-
const flattened = await new FlattenedEncrypt(this.#plaintext).setAdditionalAuthenticatedData(this.#aad).setProtectedHeader(this.#protectedHeader).setSharedUnprotectedHeader(this.#unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).encrypt(recipient.key, { ...recipient.options });
|
|
2642
|
-
const jwe2 = {
|
|
2643
|
-
ciphertext: flattened.ciphertext,
|
|
2644
|
-
iv: flattened.iv,
|
|
2645
|
-
recipients: [{}],
|
|
2646
|
-
tag: flattened.tag
|
|
2647
|
-
};
|
|
2648
|
-
if (flattened.aad)
|
|
2649
|
-
jwe2.aad = flattened.aad;
|
|
2650
|
-
if (flattened.protected)
|
|
2651
|
-
jwe2.protected = flattened.protected;
|
|
2652
|
-
if (flattened.unprotected)
|
|
2653
|
-
jwe2.unprotected = flattened.unprotected;
|
|
2654
|
-
if (flattened.encrypted_key)
|
|
2655
|
-
jwe2.recipients[0].encrypted_key = flattened.encrypted_key;
|
|
2656
|
-
if (flattened.header)
|
|
2657
|
-
jwe2.recipients[0].header = flattened.header;
|
|
2658
|
-
return jwe2;
|
|
2659
|
-
}
|
|
2660
|
-
let enc;
|
|
2661
|
-
for (let i = 0; i < this.#recipients.length; i++) {
|
|
2662
|
-
const recipient = this.#recipients[i];
|
|
2663
|
-
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, recipient.unprotectedHeader)) {
|
|
2664
|
-
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
2665
|
-
}
|
|
2666
|
-
const joseHeader = {
|
|
2667
|
-
...this.#protectedHeader,
|
|
2668
|
-
...this.#unprotectedHeader,
|
|
2669
|
-
...recipient.unprotectedHeader
|
|
2670
|
-
};
|
|
2671
|
-
const { alg } = joseHeader;
|
|
2672
|
-
if (typeof alg !== "string" || !alg) {
|
|
2673
|
-
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2674
|
-
}
|
|
2675
|
-
if (alg === "dir" || alg === "ECDH-ES") {
|
|
2676
|
-
throw new JWEInvalid('"dir" and "ECDH-ES" alg may only be used with a single recipient');
|
|
2677
|
-
}
|
|
2678
|
-
if (typeof joseHeader.enc !== "string" || !joseHeader.enc) {
|
|
2679
|
-
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
2680
|
-
}
|
|
2681
|
-
if (!enc) {
|
|
2682
|
-
enc = joseHeader.enc;
|
|
2683
|
-
} else if (enc !== joseHeader.enc) {
|
|
2684
|
-
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
|
|
2685
|
-
}
|
|
2686
|
-
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), recipient.options.crit, this.#protectedHeader, joseHeader);
|
|
2687
|
-
if (joseHeader.zip !== void 0) {
|
|
2688
|
-
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
const cek = generateCek(enc);
|
|
2692
|
-
const jwe = {
|
|
2693
|
-
ciphertext: "",
|
|
2694
|
-
recipients: []
|
|
2695
|
-
};
|
|
2696
|
-
for (let i = 0; i < this.#recipients.length; i++) {
|
|
2697
|
-
const recipient = this.#recipients[i];
|
|
2698
|
-
const target = {};
|
|
2699
|
-
jwe.recipients.push(target);
|
|
2700
|
-
if (i === 0) {
|
|
2701
|
-
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, {
|
|
2702
|
-
...recipient.options,
|
|
2703
|
-
[unprotected]: true
|
|
2704
|
-
});
|
|
2705
|
-
jwe.ciphertext = flattened.ciphertext;
|
|
2706
|
-
jwe.iv = flattened.iv;
|
|
2707
|
-
jwe.tag = flattened.tag;
|
|
2708
|
-
if (flattened.aad)
|
|
2709
|
-
jwe.aad = flattened.aad;
|
|
2710
|
-
if (flattened.protected)
|
|
2711
|
-
jwe.protected = flattened.protected;
|
|
2712
|
-
if (flattened.unprotected)
|
|
2713
|
-
jwe.unprotected = flattened.unprotected;
|
|
2714
|
-
target.encrypted_key = flattened.encrypted_key;
|
|
2715
|
-
if (flattened.header)
|
|
2716
|
-
target.header = flattened.header;
|
|
2717
|
-
continue;
|
|
2718
|
-
}
|
|
2719
|
-
const alg = recipient.unprotectedHeader?.alg || this.#protectedHeader?.alg || this.#unprotectedHeader?.alg;
|
|
2720
|
-
checkKeyType(alg === "dir" ? enc : alg, recipient.key, "encrypt");
|
|
2721
|
-
const k = await normalizeKey(recipient.key, alg);
|
|
2722
|
-
const { encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, cek, recipient.keyManagementParameters);
|
|
2723
|
-
target.encrypted_key = encode2(encryptedKey);
|
|
2724
|
-
if (recipient.unprotectedHeader || parameters)
|
|
2725
|
-
target.header = { ...recipient.unprotectedHeader, ...parameters };
|
|
2726
|
-
}
|
|
2727
|
-
return jwe;
|
|
2728
|
-
}
|
|
2729
|
-
};
|
|
2730
|
-
}
|
|
2731
|
-
});
|
|
2732
|
-
|
|
2733
|
-
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
2734
|
-
function subtleAlgorithm2(alg, algorithm) {
|
|
2735
|
-
const hash = `SHA-${alg.slice(-3)}`;
|
|
2736
|
-
switch (alg) {
|
|
2737
|
-
case "HS256":
|
|
2738
|
-
case "HS384":
|
|
2739
|
-
case "HS512":
|
|
2740
|
-
return { hash, name: "HMAC" };
|
|
2741
|
-
case "PS256":
|
|
2742
|
-
case "PS384":
|
|
2743
|
-
case "PS512":
|
|
2744
|
-
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
2745
|
-
case "RS256":
|
|
2746
|
-
case "RS384":
|
|
2747
|
-
case "RS512":
|
|
2748
|
-
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
2749
|
-
case "ES256":
|
|
2750
|
-
case "ES384":
|
|
2751
|
-
case "ES512":
|
|
2752
|
-
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
2753
|
-
case "Ed25519":
|
|
2754
|
-
case "EdDSA":
|
|
2755
|
-
return { name: "Ed25519" };
|
|
2756
|
-
case "ML-DSA-44":
|
|
2757
|
-
case "ML-DSA-65":
|
|
2758
|
-
case "ML-DSA-87":
|
|
2759
|
-
return { name: alg };
|
|
2760
|
-
default:
|
|
2761
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
2762
|
-
}
|
|
2763
|
-
}
|
|
2764
|
-
var init_subtle_dsa = __esm({
|
|
2765
|
-
"node_modules/jose/dist/webapi/lib/subtle_dsa.js"() {
|
|
2766
|
-
"use strict";
|
|
2767
|
-
init_esm_shims();
|
|
2768
|
-
init_errors();
|
|
2769
|
-
}
|
|
2770
|
-
});
|
|
2771
|
-
|
|
2772
|
-
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
2773
|
-
async function getSigKey(alg, key, usage) {
|
|
2774
|
-
if (key instanceof Uint8Array) {
|
|
2775
|
-
if (!alg.startsWith("HS")) {
|
|
2776
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
2777
|
-
}
|
|
2778
|
-
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
2779
|
-
}
|
|
2780
|
-
checkSigCryptoKey(key, alg, usage);
|
|
2781
|
-
return key;
|
|
2782
|
-
}
|
|
2783
|
-
var init_get_sign_verify_key = __esm({
|
|
2784
|
-
"node_modules/jose/dist/webapi/lib/get_sign_verify_key.js"() {
|
|
2785
|
-
"use strict";
|
|
2786
|
-
init_esm_shims();
|
|
2787
|
-
init_crypto_key();
|
|
2788
|
-
init_invalid_key_input();
|
|
2789
|
-
}
|
|
2790
|
-
});
|
|
2791
|
-
|
|
2792
|
-
// node_modules/jose/dist/webapi/lib/verify.js
|
|
2793
|
-
async function verify(alg, key, signature, data) {
|
|
2794
|
-
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
2795
|
-
checkKeyLength(alg, cryptoKey);
|
|
2796
|
-
const algorithm = subtleAlgorithm2(alg, cryptoKey.algorithm);
|
|
2797
|
-
try {
|
|
2798
|
-
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
2799
|
-
} catch {
|
|
2800
|
-
return false;
|
|
2801
|
-
}
|
|
2802
|
-
}
|
|
2803
|
-
var init_verify = __esm({
|
|
2804
|
-
"node_modules/jose/dist/webapi/lib/verify.js"() {
|
|
2805
|
-
"use strict";
|
|
2806
|
-
init_esm_shims();
|
|
2807
|
-
init_subtle_dsa();
|
|
2808
|
-
init_check_key_length();
|
|
2809
|
-
init_get_sign_verify_key();
|
|
2810
|
-
}
|
|
2811
|
-
});
|
|
2812
|
-
|
|
2813
|
-
// node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
2814
|
-
async function flattenedVerify(jws, key, options) {
|
|
2815
|
-
if (!isObject(jws)) {
|
|
2816
|
-
throw new JWSInvalid("Flattened JWS must be an object");
|
|
2817
|
-
}
|
|
2818
|
-
if (jws.protected === void 0 && jws.header === void 0) {
|
|
2819
|
-
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
2820
|
-
}
|
|
2821
|
-
if (jws.protected !== void 0 && typeof jws.protected !== "string") {
|
|
2822
|
-
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
2823
|
-
}
|
|
2824
|
-
if (jws.payload === void 0) {
|
|
2825
|
-
throw new JWSInvalid("JWS Payload missing");
|
|
2826
|
-
}
|
|
2827
|
-
if (typeof jws.signature !== "string") {
|
|
2828
|
-
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
2829
|
-
}
|
|
2830
|
-
if (jws.header !== void 0 && !isObject(jws.header)) {
|
|
2831
|
-
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
2832
|
-
}
|
|
2833
|
-
let parsedProt = {};
|
|
2834
|
-
if (jws.protected) {
|
|
2835
|
-
try {
|
|
2836
|
-
const protectedHeader = decode(jws.protected);
|
|
2837
|
-
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
2838
|
-
} catch {
|
|
2839
|
-
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
2840
|
-
}
|
|
2841
|
-
}
|
|
2842
|
-
if (!isDisjoint(parsedProt, jws.header)) {
|
|
2843
|
-
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
2844
|
-
}
|
|
2845
|
-
const joseHeader = {
|
|
2846
|
-
...parsedProt,
|
|
2847
|
-
...jws.header
|
|
2848
|
-
};
|
|
2849
|
-
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
2850
|
-
let b64 = true;
|
|
2851
|
-
if (extensions.has("b64")) {
|
|
2852
|
-
b64 = parsedProt.b64;
|
|
2853
|
-
if (typeof b64 !== "boolean") {
|
|
2854
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
2855
|
-
}
|
|
2856
|
-
}
|
|
2857
|
-
const { alg } = joseHeader;
|
|
2858
|
-
if (typeof alg !== "string" || !alg) {
|
|
2859
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2860
|
-
}
|
|
2861
|
-
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
2862
|
-
if (algorithms && !algorithms.has(alg)) {
|
|
2863
|
-
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
2864
|
-
}
|
|
2865
|
-
if (b64) {
|
|
2866
|
-
if (typeof jws.payload !== "string") {
|
|
2867
|
-
throw new JWSInvalid("JWS Payload must be a string");
|
|
2868
|
-
}
|
|
2869
|
-
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
|
|
2870
|
-
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
2871
|
-
}
|
|
2872
|
-
let resolvedKey = false;
|
|
2873
|
-
if (typeof key === "function") {
|
|
2874
|
-
key = await key(parsedProt, jws);
|
|
2875
|
-
resolvedKey = true;
|
|
2876
|
-
}
|
|
2877
|
-
checkKeyType(alg, key, "verify");
|
|
2878
|
-
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);
|
|
2879
|
-
let signature;
|
|
2880
|
-
try {
|
|
2881
|
-
signature = decode(jws.signature);
|
|
2882
|
-
} catch {
|
|
2883
|
-
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
2884
|
-
}
|
|
2885
|
-
const k = await normalizeKey(key, alg);
|
|
2886
|
-
const verified = await verify(alg, k, signature, data);
|
|
2887
|
-
if (!verified) {
|
|
2888
|
-
throw new JWSSignatureVerificationFailed();
|
|
2889
|
-
}
|
|
2890
|
-
let payload;
|
|
2891
|
-
if (b64) {
|
|
2892
|
-
try {
|
|
2893
|
-
payload = decode(jws.payload);
|
|
2894
|
-
} catch {
|
|
2895
|
-
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
2896
|
-
}
|
|
2897
|
-
} else if (typeof jws.payload === "string") {
|
|
2898
|
-
payload = encoder.encode(jws.payload);
|
|
2899
|
-
} else {
|
|
2900
|
-
payload = jws.payload;
|
|
2901
|
-
}
|
|
2902
|
-
const result = { payload };
|
|
2903
|
-
if (jws.protected !== void 0) {
|
|
2904
|
-
result.protectedHeader = parsedProt;
|
|
2905
|
-
}
|
|
2906
|
-
if (jws.header !== void 0) {
|
|
2907
|
-
result.unprotectedHeader = jws.header;
|
|
2908
|
-
}
|
|
2909
|
-
if (resolvedKey) {
|
|
2910
|
-
return { ...result, key: k };
|
|
2911
|
-
}
|
|
2912
|
-
return result;
|
|
2913
|
-
}
|
|
2914
|
-
var init_verify2 = __esm({
|
|
2915
|
-
"node_modules/jose/dist/webapi/jws/flattened/verify.js"() {
|
|
2916
|
-
"use strict";
|
|
2917
|
-
init_esm_shims();
|
|
2918
|
-
init_base64url();
|
|
2919
|
-
init_verify();
|
|
2920
|
-
init_errors();
|
|
2921
|
-
init_buffer_utils();
|
|
2922
|
-
init_is_disjoint();
|
|
2923
|
-
init_is_object();
|
|
2924
|
-
init_check_key_type();
|
|
2925
|
-
init_validate_crit();
|
|
2926
|
-
init_validate_algorithms();
|
|
2927
|
-
init_normalize_key();
|
|
2928
|
-
}
|
|
2929
|
-
});
|
|
2930
|
-
|
|
2931
|
-
// node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
2932
|
-
async function compactVerify(jws, key, options) {
|
|
2933
|
-
if (jws instanceof Uint8Array) {
|
|
2934
|
-
jws = decoder.decode(jws);
|
|
2935
|
-
}
|
|
2936
|
-
if (typeof jws !== "string") {
|
|
2937
|
-
throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
2938
|
-
}
|
|
2939
|
-
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
2940
|
-
if (length !== 3) {
|
|
2941
|
-
throw new JWSInvalid("Invalid Compact JWS");
|
|
2942
|
-
}
|
|
2943
|
-
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
|
2944
|
-
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
|
2945
|
-
if (typeof key === "function") {
|
|
2946
|
-
return { ...result, key: verified.key };
|
|
2947
|
-
}
|
|
2948
|
-
return result;
|
|
2949
|
-
}
|
|
2950
|
-
var init_verify3 = __esm({
|
|
2951
|
-
"node_modules/jose/dist/webapi/jws/compact/verify.js"() {
|
|
2952
|
-
"use strict";
|
|
2953
|
-
init_esm_shims();
|
|
2954
|
-
init_verify2();
|
|
2955
|
-
init_errors();
|
|
2956
|
-
init_buffer_utils();
|
|
2957
|
-
}
|
|
2958
|
-
});
|
|
2959
|
-
|
|
2960
|
-
// node_modules/jose/dist/webapi/jws/general/verify.js
|
|
2961
|
-
async function generalVerify(jws, key, options) {
|
|
2962
|
-
if (!isObject(jws)) {
|
|
2963
|
-
throw new JWSInvalid("General JWS must be an object");
|
|
2964
|
-
}
|
|
2965
|
-
if (!Array.isArray(jws.signatures) || !jws.signatures.every(isObject)) {
|
|
2966
|
-
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
2967
|
-
}
|
|
2968
|
-
for (const signature of jws.signatures) {
|
|
2969
|
-
try {
|
|
2970
|
-
return await flattenedVerify({
|
|
2971
|
-
header: signature.header,
|
|
2972
|
-
payload: jws.payload,
|
|
2973
|
-
protected: signature.protected,
|
|
2974
|
-
signature: signature.signature
|
|
2975
|
-
}, key, options);
|
|
2976
|
-
} catch {
|
|
2977
|
-
}
|
|
2978
|
-
}
|
|
2979
|
-
throw new JWSSignatureVerificationFailed();
|
|
2980
|
-
}
|
|
2981
|
-
var init_verify4 = __esm({
|
|
2982
|
-
"node_modules/jose/dist/webapi/jws/general/verify.js"() {
|
|
2983
|
-
"use strict";
|
|
2984
|
-
init_esm_shims();
|
|
2985
|
-
init_verify2();
|
|
2986
|
-
init_errors();
|
|
2987
|
-
init_is_object();
|
|
2988
|
-
}
|
|
2989
|
-
});
|
|
2990
|
-
|
|
2991
|
-
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
2992
|
-
function secs(str) {
|
|
2993
|
-
const matched = REGEX.exec(str);
|
|
2994
|
-
if (!matched || matched[4] && matched[1]) {
|
|
2995
|
-
throw new TypeError("Invalid time period format");
|
|
2996
|
-
}
|
|
2997
|
-
const value = parseFloat(matched[2]);
|
|
2998
|
-
const unit = matched[3].toLowerCase();
|
|
2999
|
-
let numericDate;
|
|
3000
|
-
switch (unit) {
|
|
3001
|
-
case "sec":
|
|
3002
|
-
case "secs":
|
|
3003
|
-
case "second":
|
|
3004
|
-
case "seconds":
|
|
3005
|
-
case "s":
|
|
3006
|
-
numericDate = Math.round(value);
|
|
3007
|
-
break;
|
|
3008
|
-
case "minute":
|
|
3009
|
-
case "minutes":
|
|
3010
|
-
case "min":
|
|
3011
|
-
case "mins":
|
|
3012
|
-
case "m":
|
|
3013
|
-
numericDate = Math.round(value * minute);
|
|
3014
|
-
break;
|
|
3015
|
-
case "hour":
|
|
3016
|
-
case "hours":
|
|
3017
|
-
case "hr":
|
|
3018
|
-
case "hrs":
|
|
3019
|
-
case "h":
|
|
3020
|
-
numericDate = Math.round(value * hour);
|
|
3021
|
-
break;
|
|
3022
|
-
case "day":
|
|
3023
|
-
case "days":
|
|
3024
|
-
case "d":
|
|
3025
|
-
numericDate = Math.round(value * day);
|
|
3026
|
-
break;
|
|
3027
|
-
case "week":
|
|
3028
|
-
case "weeks":
|
|
3029
|
-
case "w":
|
|
3030
|
-
numericDate = Math.round(value * week);
|
|
3031
|
-
break;
|
|
3032
|
-
default:
|
|
3033
|
-
numericDate = Math.round(value * year);
|
|
3034
|
-
break;
|
|
3035
|
-
}
|
|
3036
|
-
if (matched[1] === "-" || matched[4] === "ago") {
|
|
3037
|
-
return -numericDate;
|
|
3038
|
-
}
|
|
3039
|
-
return numericDate;
|
|
3040
|
-
}
|
|
3041
|
-
function validateInput(label, input) {
|
|
3042
|
-
if (!Number.isFinite(input)) {
|
|
3043
|
-
throw new TypeError(`Invalid ${label} input`);
|
|
3044
|
-
}
|
|
3045
|
-
return input;
|
|
3046
|
-
}
|
|
3047
|
-
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
3048
|
-
let payload;
|
|
3049
|
-
try {
|
|
3050
|
-
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
3051
|
-
} catch {
|
|
3052
|
-
}
|
|
3053
|
-
if (!isObject(payload)) {
|
|
3054
|
-
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
3055
|
-
}
|
|
3056
|
-
const { typ } = options;
|
|
3057
|
-
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
|
3058
|
-
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
|
|
3059
|
-
}
|
|
3060
|
-
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
3061
|
-
const presenceCheck = [...requiredClaims];
|
|
3062
|
-
if (maxTokenAge !== void 0)
|
|
3063
|
-
presenceCheck.push("iat");
|
|
3064
|
-
if (audience !== void 0)
|
|
3065
|
-
presenceCheck.push("aud");
|
|
3066
|
-
if (subject !== void 0)
|
|
3067
|
-
presenceCheck.push("sub");
|
|
3068
|
-
if (issuer !== void 0)
|
|
3069
|
-
presenceCheck.push("iss");
|
|
3070
|
-
for (const claim of new Set(presenceCheck.reverse())) {
|
|
3071
|
-
if (!(claim in payload)) {
|
|
3072
|
-
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
3073
|
-
}
|
|
3074
|
-
}
|
|
3075
|
-
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
3076
|
-
throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
|
|
3077
|
-
}
|
|
3078
|
-
if (subject && payload.sub !== subject) {
|
|
3079
|
-
throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
|
|
3080
|
-
}
|
|
3081
|
-
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
|
|
3082
|
-
throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
|
|
3083
|
-
}
|
|
3084
|
-
let tolerance;
|
|
3085
|
-
switch (typeof options.clockTolerance) {
|
|
3086
|
-
case "string":
|
|
3087
|
-
tolerance = secs(options.clockTolerance);
|
|
3088
|
-
break;
|
|
3089
|
-
case "number":
|
|
3090
|
-
tolerance = options.clockTolerance;
|
|
3091
|
-
break;
|
|
3092
|
-
case "undefined":
|
|
3093
|
-
tolerance = 0;
|
|
3094
|
-
break;
|
|
3095
|
-
default:
|
|
3096
|
-
throw new TypeError("Invalid clockTolerance option type");
|
|
3097
|
-
}
|
|
3098
|
-
const { currentDate } = options;
|
|
3099
|
-
const now = epoch(currentDate || /* @__PURE__ */ new Date());
|
|
3100
|
-
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
|
|
3101
|
-
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
|
|
3102
|
-
}
|
|
3103
|
-
if (payload.nbf !== void 0) {
|
|
3104
|
-
if (typeof payload.nbf !== "number") {
|
|
3105
|
-
throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
|
|
3106
|
-
}
|
|
3107
|
-
if (payload.nbf > now + tolerance) {
|
|
3108
|
-
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
|
|
3109
|
-
}
|
|
3110
|
-
}
|
|
3111
|
-
if (payload.exp !== void 0) {
|
|
3112
|
-
if (typeof payload.exp !== "number") {
|
|
3113
|
-
throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
|
|
3114
|
-
}
|
|
3115
|
-
if (payload.exp <= now - tolerance) {
|
|
3116
|
-
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
|
|
3117
|
-
}
|
|
3118
|
-
}
|
|
3119
|
-
if (maxTokenAge) {
|
|
3120
|
-
const age = now - payload.iat;
|
|
3121
|
-
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
3122
|
-
if (age - tolerance > max) {
|
|
3123
|
-
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
|
|
3124
|
-
}
|
|
3125
|
-
if (age < 0 - tolerance) {
|
|
3126
|
-
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
|
|
3127
|
-
}
|
|
3128
|
-
}
|
|
3129
|
-
return payload;
|
|
3130
|
-
}
|
|
3131
|
-
var epoch, minute, hour, day, week, year, REGEX, normalizeTyp, checkAudiencePresence, JWTClaimsBuilder;
|
|
3132
|
-
var init_jwt_claims_set = __esm({
|
|
3133
|
-
"node_modules/jose/dist/webapi/lib/jwt_claims_set.js"() {
|
|
3134
|
-
"use strict";
|
|
3135
|
-
init_esm_shims();
|
|
3136
|
-
init_errors();
|
|
3137
|
-
init_buffer_utils();
|
|
3138
|
-
init_is_object();
|
|
3139
|
-
epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
3140
|
-
minute = 60;
|
|
3141
|
-
hour = minute * 60;
|
|
3142
|
-
day = hour * 24;
|
|
3143
|
-
week = day * 7;
|
|
3144
|
-
year = day * 365.25;
|
|
3145
|
-
REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
3146
|
-
normalizeTyp = (value) => {
|
|
3147
|
-
if (value.includes("/")) {
|
|
3148
|
-
return value.toLowerCase();
|
|
3149
|
-
}
|
|
3150
|
-
return `application/${value.toLowerCase()}`;
|
|
3151
|
-
};
|
|
3152
|
-
checkAudiencePresence = (audPayload, audOption) => {
|
|
3153
|
-
if (typeof audPayload === "string") {
|
|
3154
|
-
return audOption.includes(audPayload);
|
|
3155
|
-
}
|
|
3156
|
-
if (Array.isArray(audPayload)) {
|
|
3157
|
-
return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
3158
|
-
}
|
|
3159
|
-
return false;
|
|
3160
|
-
};
|
|
3161
|
-
JWTClaimsBuilder = class {
|
|
3162
|
-
#payload;
|
|
3163
|
-
constructor(payload) {
|
|
3164
|
-
if (!isObject(payload)) {
|
|
3165
|
-
throw new TypeError("JWT Claims Set MUST be an object");
|
|
3166
|
-
}
|
|
3167
|
-
this.#payload = structuredClone(payload);
|
|
3168
|
-
}
|
|
3169
|
-
data() {
|
|
3170
|
-
return encoder.encode(JSON.stringify(this.#payload));
|
|
3171
|
-
}
|
|
3172
|
-
get iss() {
|
|
3173
|
-
return this.#payload.iss;
|
|
3174
|
-
}
|
|
3175
|
-
set iss(value) {
|
|
3176
|
-
this.#payload.iss = value;
|
|
3177
|
-
}
|
|
3178
|
-
get sub() {
|
|
3179
|
-
return this.#payload.sub;
|
|
3180
|
-
}
|
|
3181
|
-
set sub(value) {
|
|
3182
|
-
this.#payload.sub = value;
|
|
3183
|
-
}
|
|
3184
|
-
get aud() {
|
|
3185
|
-
return this.#payload.aud;
|
|
3186
|
-
}
|
|
3187
|
-
set aud(value) {
|
|
3188
|
-
this.#payload.aud = value;
|
|
3189
|
-
}
|
|
3190
|
-
set jti(value) {
|
|
3191
|
-
this.#payload.jti = value;
|
|
3192
|
-
}
|
|
3193
|
-
set nbf(value) {
|
|
3194
|
-
if (typeof value === "number") {
|
|
3195
|
-
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
3196
|
-
} else if (value instanceof Date) {
|
|
3197
|
-
this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
3198
|
-
} else {
|
|
3199
|
-
this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3202
|
-
set exp(value) {
|
|
3203
|
-
if (typeof value === "number") {
|
|
3204
|
-
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
3205
|
-
} else if (value instanceof Date) {
|
|
3206
|
-
this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
3207
|
-
} else {
|
|
3208
|
-
this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3211
|
-
set iat(value) {
|
|
3212
|
-
if (value === void 0) {
|
|
3213
|
-
this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
3214
|
-
} else if (value instanceof Date) {
|
|
3215
|
-
this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
3216
|
-
} else if (typeof value === "string") {
|
|
3217
|
-
this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
3218
|
-
} else {
|
|
3219
|
-
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
3220
|
-
}
|
|
3221
|
-
}
|
|
3222
|
-
};
|
|
3223
|
-
}
|
|
3224
|
-
});
|
|
3225
|
-
|
|
3226
|
-
// node_modules/jose/dist/webapi/jwt/verify.js
|
|
3227
|
-
async function jwtVerify(jwt, key, options) {
|
|
3228
|
-
const verified = await compactVerify(jwt, key, options);
|
|
3229
|
-
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
3230
|
-
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3231
|
-
}
|
|
3232
|
-
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
|
3233
|
-
const result = { payload, protectedHeader: verified.protectedHeader };
|
|
3234
|
-
if (typeof key === "function") {
|
|
3235
|
-
return { ...result, key: verified.key };
|
|
3236
|
-
}
|
|
3237
|
-
return result;
|
|
3238
|
-
}
|
|
3239
|
-
var init_verify5 = __esm({
|
|
3240
|
-
"node_modules/jose/dist/webapi/jwt/verify.js"() {
|
|
3241
|
-
"use strict";
|
|
3242
|
-
init_esm_shims();
|
|
3243
|
-
init_verify3();
|
|
3244
|
-
init_jwt_claims_set();
|
|
3245
|
-
init_errors();
|
|
3246
|
-
}
|
|
3247
|
-
});
|
|
3248
|
-
|
|
3249
|
-
// node_modules/jose/dist/webapi/jwt/decrypt.js
|
|
3250
|
-
async function jwtDecrypt(jwt, key, options) {
|
|
3251
|
-
const decrypted = await compactDecrypt(jwt, key, options);
|
|
3252
|
-
const payload = validateClaimsSet(decrypted.protectedHeader, decrypted.plaintext, options);
|
|
3253
|
-
const { protectedHeader } = decrypted;
|
|
3254
|
-
if (protectedHeader.iss !== void 0 && protectedHeader.iss !== payload.iss) {
|
|
3255
|
-
throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, "iss", "mismatch");
|
|
3256
|
-
}
|
|
3257
|
-
if (protectedHeader.sub !== void 0 && protectedHeader.sub !== payload.sub) {
|
|
3258
|
-
throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, "sub", "mismatch");
|
|
3259
|
-
}
|
|
3260
|
-
if (protectedHeader.aud !== void 0 && JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
|
|
3261
|
-
throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, "aud", "mismatch");
|
|
3262
|
-
}
|
|
3263
|
-
const result = { payload, protectedHeader };
|
|
3264
|
-
if (typeof key === "function") {
|
|
3265
|
-
return { ...result, key: decrypted.key };
|
|
3266
|
-
}
|
|
3267
|
-
return result;
|
|
3268
|
-
}
|
|
3269
|
-
var init_decrypt5 = __esm({
|
|
3270
|
-
"node_modules/jose/dist/webapi/jwt/decrypt.js"() {
|
|
3271
|
-
"use strict";
|
|
3272
|
-
init_esm_shims();
|
|
3273
|
-
init_decrypt3();
|
|
3274
|
-
init_jwt_claims_set();
|
|
3275
|
-
init_errors();
|
|
3276
|
-
}
|
|
3277
|
-
});
|
|
3278
|
-
|
|
3279
|
-
// node_modules/jose/dist/webapi/jwe/compact/encrypt.js
|
|
3280
|
-
var CompactEncrypt;
|
|
3281
|
-
var init_encrypt4 = __esm({
|
|
3282
|
-
"node_modules/jose/dist/webapi/jwe/compact/encrypt.js"() {
|
|
3283
|
-
"use strict";
|
|
3284
|
-
init_esm_shims();
|
|
3285
|
-
init_encrypt2();
|
|
3286
|
-
CompactEncrypt = class {
|
|
3287
|
-
#flattened;
|
|
3288
|
-
constructor(plaintext) {
|
|
3289
|
-
this.#flattened = new FlattenedEncrypt(plaintext);
|
|
3290
|
-
}
|
|
3291
|
-
setContentEncryptionKey(cek) {
|
|
3292
|
-
this.#flattened.setContentEncryptionKey(cek);
|
|
3293
|
-
return this;
|
|
3294
|
-
}
|
|
3295
|
-
setInitializationVector(iv) {
|
|
3296
|
-
this.#flattened.setInitializationVector(iv);
|
|
3297
|
-
return this;
|
|
3298
|
-
}
|
|
3299
|
-
setProtectedHeader(protectedHeader) {
|
|
3300
|
-
this.#flattened.setProtectedHeader(protectedHeader);
|
|
3301
|
-
return this;
|
|
3302
|
-
}
|
|
3303
|
-
setKeyManagementParameters(parameters) {
|
|
3304
|
-
this.#flattened.setKeyManagementParameters(parameters);
|
|
3305
|
-
return this;
|
|
3306
|
-
}
|
|
3307
|
-
async encrypt(key, options) {
|
|
3308
|
-
const jwe = await this.#flattened.encrypt(key, options);
|
|
3309
|
-
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
3310
|
-
}
|
|
3311
|
-
};
|
|
3312
|
-
}
|
|
3313
|
-
});
|
|
3314
|
-
|
|
3315
|
-
// node_modules/jose/dist/webapi/lib/sign.js
|
|
3316
|
-
async function sign(alg, key, data) {
|
|
3317
|
-
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
3318
|
-
checkKeyLength(alg, cryptoKey);
|
|
3319
|
-
const signature = await crypto.subtle.sign(subtleAlgorithm2(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
3320
|
-
return new Uint8Array(signature);
|
|
3321
|
-
}
|
|
3322
|
-
var init_sign = __esm({
|
|
3323
|
-
"node_modules/jose/dist/webapi/lib/sign.js"() {
|
|
3324
|
-
"use strict";
|
|
3325
|
-
init_esm_shims();
|
|
3326
|
-
init_subtle_dsa();
|
|
3327
|
-
init_check_key_length();
|
|
3328
|
-
init_get_sign_verify_key();
|
|
3329
|
-
}
|
|
3330
|
-
});
|
|
3331
|
-
|
|
3332
|
-
// node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
3333
|
-
var FlattenedSign;
|
|
3334
|
-
var init_sign2 = __esm({
|
|
3335
|
-
"node_modules/jose/dist/webapi/jws/flattened/sign.js"() {
|
|
3336
|
-
"use strict";
|
|
3337
|
-
init_esm_shims();
|
|
3338
|
-
init_base64url();
|
|
3339
|
-
init_sign();
|
|
3340
|
-
init_is_disjoint();
|
|
3341
|
-
init_errors();
|
|
3342
|
-
init_buffer_utils();
|
|
3343
|
-
init_check_key_type();
|
|
3344
|
-
init_validate_crit();
|
|
3345
|
-
init_normalize_key();
|
|
3346
|
-
FlattenedSign = class {
|
|
3347
|
-
#payload;
|
|
3348
|
-
#protectedHeader;
|
|
3349
|
-
#unprotectedHeader;
|
|
3350
|
-
constructor(payload) {
|
|
3351
|
-
if (!(payload instanceof Uint8Array)) {
|
|
3352
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
3353
|
-
}
|
|
3354
|
-
this.#payload = payload;
|
|
3355
|
-
}
|
|
3356
|
-
setProtectedHeader(protectedHeader) {
|
|
3357
|
-
if (this.#protectedHeader) {
|
|
3358
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
3359
|
-
}
|
|
3360
|
-
this.#protectedHeader = protectedHeader;
|
|
3361
|
-
return this;
|
|
3362
|
-
}
|
|
3363
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
3364
|
-
if (this.#unprotectedHeader) {
|
|
3365
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
3366
|
-
}
|
|
3367
|
-
this.#unprotectedHeader = unprotectedHeader;
|
|
3368
|
-
return this;
|
|
3369
|
-
}
|
|
3370
|
-
async sign(key, options) {
|
|
3371
|
-
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
3372
|
-
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
3373
|
-
}
|
|
3374
|
-
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
3375
|
-
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
3376
|
-
}
|
|
3377
|
-
const joseHeader = {
|
|
3378
|
-
...this.#protectedHeader,
|
|
3379
|
-
...this.#unprotectedHeader
|
|
3380
|
-
};
|
|
3381
|
-
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
3382
|
-
let b64 = true;
|
|
3383
|
-
if (extensions.has("b64")) {
|
|
3384
|
-
b64 = this.#protectedHeader.b64;
|
|
3385
|
-
if (typeof b64 !== "boolean") {
|
|
3386
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
3387
|
-
}
|
|
3388
|
-
}
|
|
3389
|
-
const { alg } = joseHeader;
|
|
3390
|
-
if (typeof alg !== "string" || !alg) {
|
|
3391
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
3392
|
-
}
|
|
3393
|
-
checkKeyType(alg, key, "sign");
|
|
3394
|
-
let payloadS;
|
|
3395
|
-
let payloadB;
|
|
3396
|
-
if (b64) {
|
|
3397
|
-
payloadS = encode2(this.#payload);
|
|
3398
|
-
payloadB = encode(payloadS);
|
|
3399
|
-
} else {
|
|
3400
|
-
payloadB = this.#payload;
|
|
3401
|
-
payloadS = "";
|
|
3402
|
-
}
|
|
3403
|
-
let protectedHeaderString;
|
|
3404
|
-
let protectedHeaderBytes;
|
|
3405
|
-
if (this.#protectedHeader) {
|
|
3406
|
-
protectedHeaderString = encode2(JSON.stringify(this.#protectedHeader));
|
|
3407
|
-
protectedHeaderBytes = encode(protectedHeaderString);
|
|
3408
|
-
} else {
|
|
3409
|
-
protectedHeaderString = "";
|
|
3410
|
-
protectedHeaderBytes = new Uint8Array();
|
|
3411
|
-
}
|
|
3412
|
-
const data = concat(protectedHeaderBytes, encode("."), payloadB);
|
|
3413
|
-
const k = await normalizeKey(key, alg);
|
|
3414
|
-
const signature = await sign(alg, k, data);
|
|
3415
|
-
const jws = {
|
|
3416
|
-
signature: encode2(signature),
|
|
3417
|
-
payload: payloadS
|
|
3418
|
-
};
|
|
3419
|
-
if (this.#unprotectedHeader) {
|
|
3420
|
-
jws.header = this.#unprotectedHeader;
|
|
3421
|
-
}
|
|
3422
|
-
if (this.#protectedHeader) {
|
|
3423
|
-
jws.protected = protectedHeaderString;
|
|
3424
|
-
}
|
|
3425
|
-
return jws;
|
|
3426
|
-
}
|
|
3427
|
-
};
|
|
3428
|
-
}
|
|
3429
|
-
});
|
|
3430
|
-
|
|
3431
|
-
// node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
3432
|
-
var CompactSign;
|
|
3433
|
-
var init_sign3 = __esm({
|
|
3434
|
-
"node_modules/jose/dist/webapi/jws/compact/sign.js"() {
|
|
3435
|
-
"use strict";
|
|
3436
|
-
init_esm_shims();
|
|
3437
|
-
init_sign2();
|
|
3438
|
-
CompactSign = class {
|
|
3439
|
-
#flattened;
|
|
3440
|
-
constructor(payload) {
|
|
3441
|
-
this.#flattened = new FlattenedSign(payload);
|
|
3442
|
-
}
|
|
3443
|
-
setProtectedHeader(protectedHeader) {
|
|
3444
|
-
this.#flattened.setProtectedHeader(protectedHeader);
|
|
3445
|
-
return this;
|
|
3446
|
-
}
|
|
3447
|
-
async sign(key, options) {
|
|
3448
|
-
const jws = await this.#flattened.sign(key, options);
|
|
3449
|
-
if (jws.payload === void 0) {
|
|
3450
|
-
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
3451
|
-
}
|
|
3452
|
-
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
3453
|
-
}
|
|
3454
|
-
};
|
|
3455
|
-
}
|
|
3456
|
-
});
|
|
3457
|
-
|
|
3458
|
-
// node_modules/jose/dist/webapi/jws/general/sign.js
|
|
3459
|
-
var IndividualSignature, GeneralSign;
|
|
3460
|
-
var init_sign4 = __esm({
|
|
3461
|
-
"node_modules/jose/dist/webapi/jws/general/sign.js"() {
|
|
3462
|
-
"use strict";
|
|
3463
|
-
init_esm_shims();
|
|
3464
|
-
init_sign2();
|
|
3465
|
-
init_errors();
|
|
3466
|
-
IndividualSignature = class {
|
|
3467
|
-
#parent;
|
|
3468
|
-
protectedHeader;
|
|
3469
|
-
unprotectedHeader;
|
|
3470
|
-
options;
|
|
3471
|
-
key;
|
|
3472
|
-
constructor(sig, key, options) {
|
|
3473
|
-
this.#parent = sig;
|
|
3474
|
-
this.key = key;
|
|
3475
|
-
this.options = options;
|
|
3476
|
-
}
|
|
3477
|
-
setProtectedHeader(protectedHeader) {
|
|
3478
|
-
if (this.protectedHeader) {
|
|
3479
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
3480
|
-
}
|
|
3481
|
-
this.protectedHeader = protectedHeader;
|
|
3482
|
-
return this;
|
|
3483
|
-
}
|
|
3484
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
3485
|
-
if (this.unprotectedHeader) {
|
|
3486
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
3487
|
-
}
|
|
3488
|
-
this.unprotectedHeader = unprotectedHeader;
|
|
3489
|
-
return this;
|
|
3490
|
-
}
|
|
3491
|
-
addSignature(...args) {
|
|
3492
|
-
return this.#parent.addSignature(...args);
|
|
3493
|
-
}
|
|
3494
|
-
sign(...args) {
|
|
3495
|
-
return this.#parent.sign(...args);
|
|
3496
|
-
}
|
|
3497
|
-
done() {
|
|
3498
|
-
return this.#parent;
|
|
3499
|
-
}
|
|
3500
|
-
};
|
|
3501
|
-
GeneralSign = class {
|
|
3502
|
-
#payload;
|
|
3503
|
-
#signatures = [];
|
|
3504
|
-
constructor(payload) {
|
|
3505
|
-
this.#payload = payload;
|
|
3506
|
-
}
|
|
3507
|
-
addSignature(key, options) {
|
|
3508
|
-
const signature = new IndividualSignature(this, key, options);
|
|
3509
|
-
this.#signatures.push(signature);
|
|
3510
|
-
return signature;
|
|
3511
|
-
}
|
|
3512
|
-
async sign() {
|
|
3513
|
-
if (!this.#signatures.length) {
|
|
3514
|
-
throw new JWSInvalid("at least one signature must be added");
|
|
3515
|
-
}
|
|
3516
|
-
const jws = {
|
|
3517
|
-
signatures: [],
|
|
3518
|
-
payload: ""
|
|
3519
|
-
};
|
|
3520
|
-
for (let i = 0; i < this.#signatures.length; i++) {
|
|
3521
|
-
const signature = this.#signatures[i];
|
|
3522
|
-
const flattened = new FlattenedSign(this.#payload);
|
|
3523
|
-
flattened.setProtectedHeader(signature.protectedHeader);
|
|
3524
|
-
flattened.setUnprotectedHeader(signature.unprotectedHeader);
|
|
3525
|
-
const { payload, ...rest } = await flattened.sign(signature.key, signature.options);
|
|
3526
|
-
if (i === 0) {
|
|
3527
|
-
jws.payload = payload;
|
|
3528
|
-
} else if (jws.payload !== payload) {
|
|
3529
|
-
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
3530
|
-
}
|
|
3531
|
-
jws.signatures.push(rest);
|
|
3532
|
-
}
|
|
3533
|
-
return jws;
|
|
3534
|
-
}
|
|
3535
|
-
};
|
|
3536
|
-
}
|
|
3537
|
-
});
|
|
3538
|
-
|
|
3539
|
-
// node_modules/jose/dist/webapi/jwt/sign.js
|
|
3540
|
-
var SignJWT;
|
|
3541
|
-
var init_sign5 = __esm({
|
|
3542
|
-
"node_modules/jose/dist/webapi/jwt/sign.js"() {
|
|
3543
|
-
"use strict";
|
|
3544
|
-
init_esm_shims();
|
|
3545
|
-
init_sign3();
|
|
3546
|
-
init_errors();
|
|
3547
|
-
init_jwt_claims_set();
|
|
3548
|
-
SignJWT = class {
|
|
3549
|
-
#protectedHeader;
|
|
3550
|
-
#jwt;
|
|
3551
|
-
constructor(payload = {}) {
|
|
3552
|
-
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3553
|
-
}
|
|
3554
|
-
setIssuer(issuer) {
|
|
3555
|
-
this.#jwt.iss = issuer;
|
|
3556
|
-
return this;
|
|
3557
|
-
}
|
|
3558
|
-
setSubject(subject) {
|
|
3559
|
-
this.#jwt.sub = subject;
|
|
3560
|
-
return this;
|
|
3561
|
-
}
|
|
3562
|
-
setAudience(audience) {
|
|
3563
|
-
this.#jwt.aud = audience;
|
|
3564
|
-
return this;
|
|
3565
|
-
}
|
|
3566
|
-
setJti(jwtId) {
|
|
3567
|
-
this.#jwt.jti = jwtId;
|
|
3568
|
-
return this;
|
|
3569
|
-
}
|
|
3570
|
-
setNotBefore(input) {
|
|
3571
|
-
this.#jwt.nbf = input;
|
|
3572
|
-
return this;
|
|
3573
|
-
}
|
|
3574
|
-
setExpirationTime(input) {
|
|
3575
|
-
this.#jwt.exp = input;
|
|
3576
|
-
return this;
|
|
3577
|
-
}
|
|
3578
|
-
setIssuedAt(input) {
|
|
3579
|
-
this.#jwt.iat = input;
|
|
3580
|
-
return this;
|
|
3581
|
-
}
|
|
3582
|
-
setProtectedHeader(protectedHeader) {
|
|
3583
|
-
this.#protectedHeader = protectedHeader;
|
|
3584
|
-
return this;
|
|
3585
|
-
}
|
|
3586
|
-
async sign(key, options) {
|
|
3587
|
-
const sig = new CompactSign(this.#jwt.data());
|
|
3588
|
-
sig.setProtectedHeader(this.#protectedHeader);
|
|
3589
|
-
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
|
|
3590
|
-
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3591
|
-
}
|
|
3592
|
-
return sig.sign(key, options);
|
|
3593
|
-
}
|
|
3594
|
-
};
|
|
3595
|
-
}
|
|
3596
|
-
});
|
|
3597
6
|
|
|
3598
|
-
// node_modules/
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
init_esm_shims();
|
|
3604
|
-
init_encrypt4();
|
|
3605
|
-
init_jwt_claims_set();
|
|
3606
|
-
EncryptJWT = class {
|
|
3607
|
-
#cek;
|
|
3608
|
-
#iv;
|
|
3609
|
-
#keyManagementParameters;
|
|
3610
|
-
#protectedHeader;
|
|
3611
|
-
#replicateIssuerAsHeader;
|
|
3612
|
-
#replicateSubjectAsHeader;
|
|
3613
|
-
#replicateAudienceAsHeader;
|
|
3614
|
-
#jwt;
|
|
3615
|
-
constructor(payload = {}) {
|
|
3616
|
-
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3617
|
-
}
|
|
3618
|
-
setIssuer(issuer) {
|
|
3619
|
-
this.#jwt.iss = issuer;
|
|
3620
|
-
return this;
|
|
3621
|
-
}
|
|
3622
|
-
setSubject(subject) {
|
|
3623
|
-
this.#jwt.sub = subject;
|
|
3624
|
-
return this;
|
|
3625
|
-
}
|
|
3626
|
-
setAudience(audience) {
|
|
3627
|
-
this.#jwt.aud = audience;
|
|
3628
|
-
return this;
|
|
3629
|
-
}
|
|
3630
|
-
setJti(jwtId) {
|
|
3631
|
-
this.#jwt.jti = jwtId;
|
|
3632
|
-
return this;
|
|
3633
|
-
}
|
|
3634
|
-
setNotBefore(input) {
|
|
3635
|
-
this.#jwt.nbf = input;
|
|
3636
|
-
return this;
|
|
3637
|
-
}
|
|
3638
|
-
setExpirationTime(input) {
|
|
3639
|
-
this.#jwt.exp = input;
|
|
3640
|
-
return this;
|
|
3641
|
-
}
|
|
3642
|
-
setIssuedAt(input) {
|
|
3643
|
-
this.#jwt.iat = input;
|
|
3644
|
-
return this;
|
|
3645
|
-
}
|
|
3646
|
-
setProtectedHeader(protectedHeader) {
|
|
3647
|
-
if (this.#protectedHeader) {
|
|
3648
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
3649
|
-
}
|
|
3650
|
-
this.#protectedHeader = protectedHeader;
|
|
3651
|
-
return this;
|
|
3652
|
-
}
|
|
3653
|
-
setKeyManagementParameters(parameters) {
|
|
3654
|
-
if (this.#keyManagementParameters) {
|
|
3655
|
-
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
3656
|
-
}
|
|
3657
|
-
this.#keyManagementParameters = parameters;
|
|
3658
|
-
return this;
|
|
3659
|
-
}
|
|
3660
|
-
setContentEncryptionKey(cek) {
|
|
3661
|
-
if (this.#cek) {
|
|
3662
|
-
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
3663
|
-
}
|
|
3664
|
-
this.#cek = cek;
|
|
3665
|
-
return this;
|
|
3666
|
-
}
|
|
3667
|
-
setInitializationVector(iv) {
|
|
3668
|
-
if (this.#iv) {
|
|
3669
|
-
throw new TypeError("setInitializationVector can only be called once");
|
|
3670
|
-
}
|
|
3671
|
-
this.#iv = iv;
|
|
3672
|
-
return this;
|
|
3673
|
-
}
|
|
3674
|
-
replicateIssuerAsHeader() {
|
|
3675
|
-
this.#replicateIssuerAsHeader = true;
|
|
3676
|
-
return this;
|
|
3677
|
-
}
|
|
3678
|
-
replicateSubjectAsHeader() {
|
|
3679
|
-
this.#replicateSubjectAsHeader = true;
|
|
3680
|
-
return this;
|
|
3681
|
-
}
|
|
3682
|
-
replicateAudienceAsHeader() {
|
|
3683
|
-
this.#replicateAudienceAsHeader = true;
|
|
3684
|
-
return this;
|
|
3685
|
-
}
|
|
3686
|
-
async encrypt(key, options) {
|
|
3687
|
-
const enc = new CompactEncrypt(this.#jwt.data());
|
|
3688
|
-
if (this.#protectedHeader && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
|
|
3689
|
-
this.#protectedHeader = {
|
|
3690
|
-
...this.#protectedHeader,
|
|
3691
|
-
iss: this.#replicateIssuerAsHeader ? this.#jwt.iss : void 0,
|
|
3692
|
-
sub: this.#replicateSubjectAsHeader ? this.#jwt.sub : void 0,
|
|
3693
|
-
aud: this.#replicateAudienceAsHeader ? this.#jwt.aud : void 0
|
|
3694
|
-
};
|
|
3695
|
-
}
|
|
3696
|
-
enc.setProtectedHeader(this.#protectedHeader);
|
|
3697
|
-
if (this.#iv) {
|
|
3698
|
-
enc.setInitializationVector(this.#iv);
|
|
3699
|
-
}
|
|
3700
|
-
if (this.#cek) {
|
|
3701
|
-
enc.setContentEncryptionKey(this.#cek);
|
|
3702
|
-
}
|
|
3703
|
-
if (this.#keyManagementParameters) {
|
|
3704
|
-
enc.setKeyManagementParameters(this.#keyManagementParameters);
|
|
3705
|
-
}
|
|
3706
|
-
return enc.encrypt(key, options);
|
|
3707
|
-
}
|
|
3708
|
-
};
|
|
3709
|
-
}
|
|
3710
|
-
});
|
|
3711
|
-
|
|
3712
|
-
// node_modules/jose/dist/webapi/jwk/thumbprint.js
|
|
3713
|
-
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
3714
|
-
let jwk;
|
|
3715
|
-
if (isJWK(key)) {
|
|
3716
|
-
jwk = key;
|
|
3717
|
-
} else if (isKeyLike(key)) {
|
|
3718
|
-
jwk = await exportJWK(key);
|
|
3719
|
-
} else {
|
|
3720
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
3721
|
-
}
|
|
3722
|
-
digestAlgorithm ??= "sha256";
|
|
3723
|
-
if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") {
|
|
3724
|
-
throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
|
|
3725
|
-
}
|
|
3726
|
-
let components;
|
|
3727
|
-
switch (jwk.kty) {
|
|
3728
|
-
case "AKP":
|
|
3729
|
-
check(jwk.alg, '"alg" (Algorithm) Parameter');
|
|
3730
|
-
check(jwk.pub, '"pub" (Public key) Parameter');
|
|
3731
|
-
components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
|
|
3732
|
-
break;
|
|
3733
|
-
case "EC":
|
|
3734
|
-
check(jwk.crv, '"crv" (Curve) Parameter');
|
|
3735
|
-
check(jwk.x, '"x" (X Coordinate) Parameter');
|
|
3736
|
-
check(jwk.y, '"y" (Y Coordinate) Parameter');
|
|
3737
|
-
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
3738
|
-
break;
|
|
3739
|
-
case "OKP":
|
|
3740
|
-
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
|
|
3741
|
-
check(jwk.x, '"x" (Public Key) Parameter');
|
|
3742
|
-
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
3743
|
-
break;
|
|
3744
|
-
case "RSA":
|
|
3745
|
-
check(jwk.e, '"e" (Exponent) Parameter');
|
|
3746
|
-
check(jwk.n, '"n" (Modulus) Parameter');
|
|
3747
|
-
components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
3748
|
-
break;
|
|
3749
|
-
case "oct":
|
|
3750
|
-
check(jwk.k, '"k" (Key Value) Parameter');
|
|
3751
|
-
components = { k: jwk.k, kty: jwk.kty };
|
|
3752
|
-
break;
|
|
3753
|
-
default:
|
|
3754
|
-
throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
|
|
3755
|
-
}
|
|
3756
|
-
const data = encode(JSON.stringify(components));
|
|
3757
|
-
return encode2(await digest(digestAlgorithm, data));
|
|
3758
|
-
}
|
|
3759
|
-
async function calculateJwkThumbprintUri(key, digestAlgorithm) {
|
|
3760
|
-
digestAlgorithm ??= "sha256";
|
|
3761
|
-
const thumbprint = await calculateJwkThumbprint(key, digestAlgorithm);
|
|
3762
|
-
return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;
|
|
3763
|
-
}
|
|
3764
|
-
var check;
|
|
3765
|
-
var init_thumbprint = __esm({
|
|
3766
|
-
"node_modules/jose/dist/webapi/jwk/thumbprint.js"() {
|
|
3767
|
-
"use strict";
|
|
3768
|
-
init_esm_shims();
|
|
3769
|
-
init_digest();
|
|
3770
|
-
init_base64url();
|
|
3771
|
-
init_errors();
|
|
3772
|
-
init_buffer_utils();
|
|
3773
|
-
init_is_key_like();
|
|
3774
|
-
init_is_jwk();
|
|
3775
|
-
init_export();
|
|
3776
|
-
init_invalid_key_input();
|
|
3777
|
-
check = (value, description) => {
|
|
3778
|
-
if (typeof value !== "string" || !value) {
|
|
3779
|
-
throw new JWKInvalid(`${description} missing or invalid`);
|
|
3780
|
-
}
|
|
3781
|
-
};
|
|
3782
|
-
}
|
|
3783
|
-
});
|
|
3784
|
-
|
|
3785
|
-
// node_modules/jose/dist/webapi/jwk/embedded.js
|
|
3786
|
-
async function EmbeddedJWK(protectedHeader, token) {
|
|
3787
|
-
const joseHeader = {
|
|
3788
|
-
...protectedHeader,
|
|
3789
|
-
...token?.header
|
|
3790
|
-
};
|
|
3791
|
-
if (!isObject(joseHeader.jwk)) {
|
|
3792
|
-
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
|
|
3793
|
-
}
|
|
3794
|
-
const key = await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg);
|
|
3795
|
-
if (key instanceof Uint8Array || key.type !== "public") {
|
|
3796
|
-
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
|
|
3797
|
-
}
|
|
3798
|
-
return key;
|
|
3799
|
-
}
|
|
3800
|
-
var init_embedded = __esm({
|
|
3801
|
-
"node_modules/jose/dist/webapi/jwk/embedded.js"() {
|
|
3802
|
-
"use strict";
|
|
3803
|
-
init_esm_shims();
|
|
3804
|
-
init_import();
|
|
3805
|
-
init_is_object();
|
|
3806
|
-
init_errors();
|
|
3807
|
-
}
|
|
3808
|
-
});
|
|
3809
|
-
|
|
3810
|
-
// node_modules/jose/dist/webapi/jwks/local.js
|
|
3811
|
-
function getKtyFromAlg(alg) {
|
|
3812
|
-
switch (typeof alg === "string" && alg.slice(0, 2)) {
|
|
3813
|
-
case "RS":
|
|
3814
|
-
case "PS":
|
|
3815
|
-
return "RSA";
|
|
3816
|
-
case "ES":
|
|
3817
|
-
return "EC";
|
|
3818
|
-
case "Ed":
|
|
3819
|
-
return "OKP";
|
|
3820
|
-
case "ML":
|
|
3821
|
-
return "AKP";
|
|
3822
|
-
default:
|
|
3823
|
-
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
3824
|
-
}
|
|
3825
|
-
}
|
|
3826
|
-
function isJWKSLike(jwks) {
|
|
3827
|
-
return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
|
|
3828
|
-
}
|
|
3829
|
-
function isJWKLike(key) {
|
|
3830
|
-
return isObject(key);
|
|
3831
|
-
}
|
|
3832
|
-
async function importWithAlgCache(cache2, jwk, alg) {
|
|
3833
|
-
const cached = cache2.get(jwk) || cache2.set(jwk, {}).get(jwk);
|
|
3834
|
-
if (cached[alg] === void 0) {
|
|
3835
|
-
const key = await importJWK({ ...jwk, ext: true }, alg);
|
|
3836
|
-
if (key instanceof Uint8Array || key.type !== "public") {
|
|
3837
|
-
throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
3838
|
-
}
|
|
3839
|
-
cached[alg] = key;
|
|
3840
|
-
}
|
|
3841
|
-
return cached[alg];
|
|
3842
|
-
}
|
|
3843
|
-
function createLocalJWKSet(jwks) {
|
|
3844
|
-
const set = new LocalJWKSet(jwks);
|
|
3845
|
-
const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
3846
|
-
Object.defineProperties(localJWKSet, {
|
|
3847
|
-
jwks: {
|
|
3848
|
-
value: () => structuredClone(set.jwks()),
|
|
3849
|
-
enumerable: false,
|
|
3850
|
-
configurable: false,
|
|
3851
|
-
writable: false
|
|
3852
|
-
}
|
|
3853
|
-
});
|
|
3854
|
-
return localJWKSet;
|
|
3855
|
-
}
|
|
3856
|
-
var LocalJWKSet;
|
|
3857
|
-
var init_local = __esm({
|
|
3858
|
-
"node_modules/jose/dist/webapi/jwks/local.js"() {
|
|
3859
|
-
"use strict";
|
|
3860
|
-
init_esm_shims();
|
|
3861
|
-
init_import();
|
|
3862
|
-
init_errors();
|
|
3863
|
-
init_is_object();
|
|
3864
|
-
LocalJWKSet = class {
|
|
3865
|
-
#jwks;
|
|
3866
|
-
#cached = /* @__PURE__ */ new WeakMap();
|
|
3867
|
-
constructor(jwks) {
|
|
3868
|
-
if (!isJWKSLike(jwks)) {
|
|
3869
|
-
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
3870
|
-
}
|
|
3871
|
-
this.#jwks = structuredClone(jwks);
|
|
3872
|
-
}
|
|
3873
|
-
jwks() {
|
|
3874
|
-
return this.#jwks;
|
|
3875
|
-
}
|
|
3876
|
-
async getKey(protectedHeader, token) {
|
|
3877
|
-
const { alg, kid } = { ...protectedHeader, ...token?.header };
|
|
3878
|
-
const kty = getKtyFromAlg(alg);
|
|
3879
|
-
const candidates = this.#jwks.keys.filter((jwk2) => {
|
|
3880
|
-
let candidate = kty === jwk2.kty;
|
|
3881
|
-
if (candidate && typeof kid === "string") {
|
|
3882
|
-
candidate = kid === jwk2.kid;
|
|
3883
|
-
}
|
|
3884
|
-
if (candidate && (typeof jwk2.alg === "string" || kty === "AKP")) {
|
|
3885
|
-
candidate = alg === jwk2.alg;
|
|
3886
|
-
}
|
|
3887
|
-
if (candidate && typeof jwk2.use === "string") {
|
|
3888
|
-
candidate = jwk2.use === "sig";
|
|
3889
|
-
}
|
|
3890
|
-
if (candidate && Array.isArray(jwk2.key_ops)) {
|
|
3891
|
-
candidate = jwk2.key_ops.includes("verify");
|
|
3892
|
-
}
|
|
3893
|
-
if (candidate) {
|
|
3894
|
-
switch (alg) {
|
|
3895
|
-
case "ES256":
|
|
3896
|
-
candidate = jwk2.crv === "P-256";
|
|
3897
|
-
break;
|
|
3898
|
-
case "ES384":
|
|
3899
|
-
candidate = jwk2.crv === "P-384";
|
|
3900
|
-
break;
|
|
3901
|
-
case "ES512":
|
|
3902
|
-
candidate = jwk2.crv === "P-521";
|
|
3903
|
-
break;
|
|
3904
|
-
case "Ed25519":
|
|
3905
|
-
case "EdDSA":
|
|
3906
|
-
candidate = jwk2.crv === "Ed25519";
|
|
3907
|
-
break;
|
|
3908
|
-
}
|
|
3909
|
-
}
|
|
3910
|
-
return candidate;
|
|
3911
|
-
});
|
|
3912
|
-
const { 0: jwk, length } = candidates;
|
|
3913
|
-
if (length === 0) {
|
|
3914
|
-
throw new JWKSNoMatchingKey();
|
|
3915
|
-
}
|
|
3916
|
-
if (length !== 1) {
|
|
3917
|
-
const error = new JWKSMultipleMatchingKeys();
|
|
3918
|
-
const _cached = this.#cached;
|
|
3919
|
-
error[Symbol.asyncIterator] = async function* () {
|
|
3920
|
-
for (const jwk2 of candidates) {
|
|
3921
|
-
try {
|
|
3922
|
-
yield await importWithAlgCache(_cached, jwk2, alg);
|
|
3923
|
-
} catch {
|
|
3924
|
-
}
|
|
3925
|
-
}
|
|
3926
|
-
};
|
|
3927
|
-
throw error;
|
|
3928
|
-
}
|
|
3929
|
-
return importWithAlgCache(this.#cached, jwk, alg);
|
|
3930
|
-
}
|
|
3931
|
-
};
|
|
3932
|
-
}
|
|
3933
|
-
});
|
|
3934
|
-
|
|
3935
|
-
// node_modules/jose/dist/webapi/jwks/remote.js
|
|
3936
|
-
function isCloudflareWorkers() {
|
|
3937
|
-
return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
|
|
3938
|
-
}
|
|
3939
|
-
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
3940
|
-
const response = await fetchImpl(url, {
|
|
3941
|
-
method: "GET",
|
|
3942
|
-
signal,
|
|
3943
|
-
redirect: "manual",
|
|
3944
|
-
headers
|
|
3945
|
-
}).catch((err) => {
|
|
3946
|
-
if (err.name === "TimeoutError") {
|
|
3947
|
-
throw new JWKSTimeout();
|
|
3948
|
-
}
|
|
3949
|
-
throw err;
|
|
3950
|
-
});
|
|
3951
|
-
if (response.status !== 200) {
|
|
3952
|
-
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
3953
|
-
}
|
|
3954
|
-
try {
|
|
3955
|
-
return await response.json();
|
|
3956
|
-
} catch {
|
|
3957
|
-
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
3958
|
-
}
|
|
3959
|
-
}
|
|
3960
|
-
function isFreshJwksCache(input, cacheMaxAge) {
|
|
3961
|
-
if (typeof input !== "object" || input === null) {
|
|
3962
|
-
return false;
|
|
3963
|
-
}
|
|
3964
|
-
if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) {
|
|
3965
|
-
return false;
|
|
3966
|
-
}
|
|
3967
|
-
if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) {
|
|
3968
|
-
return false;
|
|
3969
|
-
}
|
|
3970
|
-
return true;
|
|
3971
|
-
}
|
|
3972
|
-
function createRemoteJWKSet(url, options) {
|
|
3973
|
-
const set = new RemoteJWKSet(url, options);
|
|
3974
|
-
const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
|
|
3975
|
-
Object.defineProperties(remoteJWKSet, {
|
|
3976
|
-
coolingDown: {
|
|
3977
|
-
get: () => set.coolingDown(),
|
|
3978
|
-
enumerable: true,
|
|
3979
|
-
configurable: false
|
|
3980
|
-
},
|
|
3981
|
-
fresh: {
|
|
3982
|
-
get: () => set.fresh(),
|
|
3983
|
-
enumerable: true,
|
|
3984
|
-
configurable: false
|
|
3985
|
-
},
|
|
3986
|
-
reload: {
|
|
3987
|
-
value: () => set.reload(),
|
|
3988
|
-
enumerable: true,
|
|
3989
|
-
configurable: false,
|
|
3990
|
-
writable: false
|
|
3991
|
-
},
|
|
3992
|
-
reloading: {
|
|
3993
|
-
get: () => set.pendingFetch(),
|
|
3994
|
-
enumerable: true,
|
|
3995
|
-
configurable: false
|
|
3996
|
-
},
|
|
3997
|
-
jwks: {
|
|
3998
|
-
value: () => set.jwks(),
|
|
3999
|
-
enumerable: true,
|
|
4000
|
-
configurable: false,
|
|
4001
|
-
writable: false
|
|
4002
|
-
}
|
|
4003
|
-
});
|
|
4004
|
-
return remoteJWKSet;
|
|
4005
|
-
}
|
|
4006
|
-
var USER_AGENT, customFetch, jwksCache, RemoteJWKSet;
|
|
4007
|
-
var init_remote = __esm({
|
|
4008
|
-
"node_modules/jose/dist/webapi/jwks/remote.js"() {
|
|
4009
|
-
"use strict";
|
|
4010
|
-
init_esm_shims();
|
|
4011
|
-
init_errors();
|
|
4012
|
-
init_local();
|
|
4013
|
-
init_is_object();
|
|
4014
|
-
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
|
|
4015
|
-
const NAME = "jose";
|
|
4016
|
-
const VERSION = "v6.1.3";
|
|
4017
|
-
USER_AGENT = `${NAME}/${VERSION}`;
|
|
4018
|
-
}
|
|
4019
|
-
customFetch = /* @__PURE__ */ Symbol();
|
|
4020
|
-
jwksCache = /* @__PURE__ */ Symbol();
|
|
4021
|
-
RemoteJWKSet = class {
|
|
4022
|
-
#url;
|
|
4023
|
-
#timeoutDuration;
|
|
4024
|
-
#cooldownDuration;
|
|
4025
|
-
#cacheMaxAge;
|
|
4026
|
-
#jwksTimestamp;
|
|
4027
|
-
#pendingFetch;
|
|
4028
|
-
#headers;
|
|
4029
|
-
#customFetch;
|
|
4030
|
-
#local;
|
|
4031
|
-
#cache;
|
|
4032
|
-
constructor(url, options) {
|
|
4033
|
-
if (!(url instanceof URL)) {
|
|
4034
|
-
throw new TypeError("url must be an instance of URL");
|
|
4035
|
-
}
|
|
4036
|
-
this.#url = new URL(url.href);
|
|
4037
|
-
this.#timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
|
|
4038
|
-
this.#cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
|
|
4039
|
-
this.#cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
|
|
4040
|
-
this.#headers = new Headers(options?.headers);
|
|
4041
|
-
if (USER_AGENT && !this.#headers.has("User-Agent")) {
|
|
4042
|
-
this.#headers.set("User-Agent", USER_AGENT);
|
|
4043
|
-
}
|
|
4044
|
-
if (!this.#headers.has("accept")) {
|
|
4045
|
-
this.#headers.set("accept", "application/json");
|
|
4046
|
-
this.#headers.append("accept", "application/jwk-set+json");
|
|
4047
|
-
}
|
|
4048
|
-
this.#customFetch = options?.[customFetch];
|
|
4049
|
-
if (options?.[jwksCache] !== void 0) {
|
|
4050
|
-
this.#cache = options?.[jwksCache];
|
|
4051
|
-
if (isFreshJwksCache(options?.[jwksCache], this.#cacheMaxAge)) {
|
|
4052
|
-
this.#jwksTimestamp = this.#cache.uat;
|
|
4053
|
-
this.#local = createLocalJWKSet(this.#cache.jwks);
|
|
4054
|
-
}
|
|
4055
|
-
}
|
|
4056
|
-
}
|
|
4057
|
-
pendingFetch() {
|
|
4058
|
-
return !!this.#pendingFetch;
|
|
4059
|
-
}
|
|
4060
|
-
coolingDown() {
|
|
4061
|
-
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cooldownDuration : false;
|
|
4062
|
-
}
|
|
4063
|
-
fresh() {
|
|
4064
|
-
return typeof this.#jwksTimestamp === "number" ? Date.now() < this.#jwksTimestamp + this.#cacheMaxAge : false;
|
|
4065
|
-
}
|
|
4066
|
-
jwks() {
|
|
4067
|
-
return this.#local?.jwks();
|
|
4068
|
-
}
|
|
4069
|
-
async getKey(protectedHeader, token) {
|
|
4070
|
-
if (!this.#local || !this.fresh()) {
|
|
4071
|
-
await this.reload();
|
|
4072
|
-
}
|
|
4073
|
-
try {
|
|
4074
|
-
return await this.#local(protectedHeader, token);
|
|
4075
|
-
} catch (err) {
|
|
4076
|
-
if (err instanceof JWKSNoMatchingKey) {
|
|
4077
|
-
if (this.coolingDown() === false) {
|
|
4078
|
-
await this.reload();
|
|
4079
|
-
return this.#local(protectedHeader, token);
|
|
4080
|
-
}
|
|
4081
|
-
}
|
|
4082
|
-
throw err;
|
|
4083
|
-
}
|
|
4084
|
-
}
|
|
4085
|
-
async reload() {
|
|
4086
|
-
if (this.#pendingFetch && isCloudflareWorkers()) {
|
|
4087
|
-
this.#pendingFetch = void 0;
|
|
4088
|
-
}
|
|
4089
|
-
this.#pendingFetch ||= fetchJwks(this.#url.href, this.#headers, AbortSignal.timeout(this.#timeoutDuration), this.#customFetch).then((json) => {
|
|
4090
|
-
this.#local = createLocalJWKSet(json);
|
|
4091
|
-
if (this.#cache) {
|
|
4092
|
-
this.#cache.uat = Date.now();
|
|
4093
|
-
this.#cache.jwks = json;
|
|
4094
|
-
}
|
|
4095
|
-
this.#jwksTimestamp = Date.now();
|
|
4096
|
-
this.#pendingFetch = void 0;
|
|
4097
|
-
}).catch((err) => {
|
|
4098
|
-
this.#pendingFetch = void 0;
|
|
4099
|
-
throw err;
|
|
4100
|
-
});
|
|
4101
|
-
await this.#pendingFetch;
|
|
4102
|
-
}
|
|
4103
|
-
};
|
|
4104
|
-
}
|
|
4105
|
-
});
|
|
4106
|
-
|
|
4107
|
-
// node_modules/jose/dist/webapi/jwt/unsecured.js
|
|
4108
|
-
var UnsecuredJWT;
|
|
4109
|
-
var init_unsecured = __esm({
|
|
4110
|
-
"node_modules/jose/dist/webapi/jwt/unsecured.js"() {
|
|
4111
|
-
"use strict";
|
|
4112
|
-
init_esm_shims();
|
|
4113
|
-
init_base64url();
|
|
4114
|
-
init_buffer_utils();
|
|
4115
|
-
init_errors();
|
|
4116
|
-
init_jwt_claims_set();
|
|
4117
|
-
UnsecuredJWT = class {
|
|
4118
|
-
#jwt;
|
|
4119
|
-
constructor(payload = {}) {
|
|
4120
|
-
this.#jwt = new JWTClaimsBuilder(payload);
|
|
4121
|
-
}
|
|
4122
|
-
encode() {
|
|
4123
|
-
const header = encode2(JSON.stringify({ alg: "none" }));
|
|
4124
|
-
const payload = encode2(this.#jwt.data());
|
|
4125
|
-
return `${header}.${payload}.`;
|
|
4126
|
-
}
|
|
4127
|
-
setIssuer(issuer) {
|
|
4128
|
-
this.#jwt.iss = issuer;
|
|
4129
|
-
return this;
|
|
4130
|
-
}
|
|
4131
|
-
setSubject(subject) {
|
|
4132
|
-
this.#jwt.sub = subject;
|
|
4133
|
-
return this;
|
|
4134
|
-
}
|
|
4135
|
-
setAudience(audience) {
|
|
4136
|
-
this.#jwt.aud = audience;
|
|
4137
|
-
return this;
|
|
4138
|
-
}
|
|
4139
|
-
setJti(jwtId) {
|
|
4140
|
-
this.#jwt.jti = jwtId;
|
|
4141
|
-
return this;
|
|
4142
|
-
}
|
|
4143
|
-
setNotBefore(input) {
|
|
4144
|
-
this.#jwt.nbf = input;
|
|
4145
|
-
return this;
|
|
4146
|
-
}
|
|
4147
|
-
setExpirationTime(input) {
|
|
4148
|
-
this.#jwt.exp = input;
|
|
4149
|
-
return this;
|
|
4150
|
-
}
|
|
4151
|
-
setIssuedAt(input) {
|
|
4152
|
-
this.#jwt.iat = input;
|
|
4153
|
-
return this;
|
|
4154
|
-
}
|
|
4155
|
-
static decode(jwt, options) {
|
|
4156
|
-
if (typeof jwt !== "string") {
|
|
4157
|
-
throw new JWTInvalid("Unsecured JWT must be a string");
|
|
4158
|
-
}
|
|
4159
|
-
const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
|
|
4160
|
-
if (length !== 3 || signature !== "") {
|
|
4161
|
-
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
4162
|
-
}
|
|
4163
|
-
let header;
|
|
4164
|
-
try {
|
|
4165
|
-
header = JSON.parse(decoder.decode(decode(encodedHeader)));
|
|
4166
|
-
if (header.alg !== "none")
|
|
4167
|
-
throw new Error();
|
|
4168
|
-
} catch {
|
|
4169
|
-
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
4170
|
-
}
|
|
4171
|
-
const payload = validateClaimsSet(header, decode(encodedPayload), options);
|
|
4172
|
-
return { payload, header };
|
|
4173
|
-
}
|
|
4174
|
-
};
|
|
4175
|
-
}
|
|
4176
|
-
});
|
|
4177
|
-
|
|
4178
|
-
// node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
4179
|
-
function decodeProtectedHeader(token) {
|
|
4180
|
-
let protectedB64u;
|
|
4181
|
-
if (typeof token === "string") {
|
|
4182
|
-
const parts = token.split(".");
|
|
4183
|
-
if (parts.length === 3 || parts.length === 5) {
|
|
4184
|
-
;
|
|
4185
|
-
[protectedB64u] = parts;
|
|
4186
|
-
}
|
|
4187
|
-
} else if (typeof token === "object" && token) {
|
|
4188
|
-
if ("protected" in token) {
|
|
4189
|
-
protectedB64u = token.protected;
|
|
4190
|
-
} else {
|
|
4191
|
-
throw new TypeError("Token does not contain a Protected Header");
|
|
4192
|
-
}
|
|
4193
|
-
}
|
|
4194
|
-
try {
|
|
4195
|
-
if (typeof protectedB64u !== "string" || !protectedB64u) {
|
|
4196
|
-
throw new Error();
|
|
4197
|
-
}
|
|
4198
|
-
const result = JSON.parse(decoder.decode(decode(protectedB64u)));
|
|
4199
|
-
if (!isObject(result)) {
|
|
4200
|
-
throw new Error();
|
|
4201
|
-
}
|
|
4202
|
-
return result;
|
|
4203
|
-
} catch {
|
|
4204
|
-
throw new TypeError("Invalid Token or Protected Header formatting");
|
|
4205
|
-
}
|
|
4206
|
-
}
|
|
4207
|
-
var init_decode_protected_header = __esm({
|
|
4208
|
-
"node_modules/jose/dist/webapi/util/decode_protected_header.js"() {
|
|
4209
|
-
"use strict";
|
|
4210
|
-
init_esm_shims();
|
|
4211
|
-
init_base64url();
|
|
4212
|
-
init_buffer_utils();
|
|
4213
|
-
init_is_object();
|
|
4214
|
-
}
|
|
4215
|
-
});
|
|
4216
|
-
|
|
4217
|
-
// node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
4218
|
-
function decodeJwt(jwt) {
|
|
4219
|
-
if (typeof jwt !== "string")
|
|
4220
|
-
throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
4221
|
-
const { 1: payload, length } = jwt.split(".");
|
|
4222
|
-
if (length === 5)
|
|
4223
|
-
throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
|
|
4224
|
-
if (length !== 3)
|
|
4225
|
-
throw new JWTInvalid("Invalid JWT");
|
|
4226
|
-
if (!payload)
|
|
4227
|
-
throw new JWTInvalid("JWTs must contain a payload");
|
|
4228
|
-
let decoded;
|
|
4229
|
-
try {
|
|
4230
|
-
decoded = decode(payload);
|
|
4231
|
-
} catch {
|
|
4232
|
-
throw new JWTInvalid("Failed to base64url decode the payload");
|
|
4233
|
-
}
|
|
4234
|
-
let result;
|
|
4235
|
-
try {
|
|
4236
|
-
result = JSON.parse(decoder.decode(decoded));
|
|
4237
|
-
} catch {
|
|
4238
|
-
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
4239
|
-
}
|
|
4240
|
-
if (!isObject(result))
|
|
4241
|
-
throw new JWTInvalid("Invalid JWT Claims Set");
|
|
4242
|
-
return result;
|
|
4243
|
-
}
|
|
4244
|
-
var init_decode_jwt = __esm({
|
|
4245
|
-
"node_modules/jose/dist/webapi/util/decode_jwt.js"() {
|
|
4246
|
-
"use strict";
|
|
4247
|
-
init_esm_shims();
|
|
4248
|
-
init_base64url();
|
|
4249
|
-
init_buffer_utils();
|
|
4250
|
-
init_is_object();
|
|
4251
|
-
init_errors();
|
|
4252
|
-
}
|
|
4253
|
-
});
|
|
4254
|
-
|
|
4255
|
-
// node_modules/jose/dist/webapi/key/generate_key_pair.js
|
|
4256
|
-
function getModulusLengthOption(options) {
|
|
4257
|
-
const modulusLength = options?.modulusLength ?? 2048;
|
|
4258
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
4259
|
-
throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
|
|
4260
|
-
}
|
|
4261
|
-
return modulusLength;
|
|
4262
|
-
}
|
|
4263
|
-
async function generateKeyPair(alg, options) {
|
|
4264
|
-
let algorithm;
|
|
4265
|
-
let keyUsages;
|
|
4266
|
-
switch (alg) {
|
|
4267
|
-
case "PS256":
|
|
4268
|
-
case "PS384":
|
|
4269
|
-
case "PS512":
|
|
4270
|
-
algorithm = {
|
|
4271
|
-
name: "RSA-PSS",
|
|
4272
|
-
hash: `SHA-${alg.slice(-3)}`,
|
|
4273
|
-
publicExponent: Uint8Array.of(1, 0, 1),
|
|
4274
|
-
modulusLength: getModulusLengthOption(options)
|
|
4275
|
-
};
|
|
4276
|
-
keyUsages = ["sign", "verify"];
|
|
4277
|
-
break;
|
|
4278
|
-
case "RS256":
|
|
4279
|
-
case "RS384":
|
|
4280
|
-
case "RS512":
|
|
4281
|
-
algorithm = {
|
|
4282
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
4283
|
-
hash: `SHA-${alg.slice(-3)}`,
|
|
4284
|
-
publicExponent: Uint8Array.of(1, 0, 1),
|
|
4285
|
-
modulusLength: getModulusLengthOption(options)
|
|
4286
|
-
};
|
|
4287
|
-
keyUsages = ["sign", "verify"];
|
|
4288
|
-
break;
|
|
4289
|
-
case "RSA-OAEP":
|
|
4290
|
-
case "RSA-OAEP-256":
|
|
4291
|
-
case "RSA-OAEP-384":
|
|
4292
|
-
case "RSA-OAEP-512":
|
|
4293
|
-
algorithm = {
|
|
4294
|
-
name: "RSA-OAEP",
|
|
4295
|
-
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
|
|
4296
|
-
publicExponent: Uint8Array.of(1, 0, 1),
|
|
4297
|
-
modulusLength: getModulusLengthOption(options)
|
|
4298
|
-
};
|
|
4299
|
-
keyUsages = ["decrypt", "unwrapKey", "encrypt", "wrapKey"];
|
|
4300
|
-
break;
|
|
4301
|
-
case "ES256":
|
|
4302
|
-
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
4303
|
-
keyUsages = ["sign", "verify"];
|
|
4304
|
-
break;
|
|
4305
|
-
case "ES384":
|
|
4306
|
-
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
4307
|
-
keyUsages = ["sign", "verify"];
|
|
4308
|
-
break;
|
|
4309
|
-
case "ES512":
|
|
4310
|
-
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
4311
|
-
keyUsages = ["sign", "verify"];
|
|
4312
|
-
break;
|
|
4313
|
-
case "Ed25519":
|
|
4314
|
-
case "EdDSA": {
|
|
4315
|
-
keyUsages = ["sign", "verify"];
|
|
4316
|
-
algorithm = { name: "Ed25519" };
|
|
4317
|
-
break;
|
|
4318
|
-
}
|
|
4319
|
-
case "ML-DSA-44":
|
|
4320
|
-
case "ML-DSA-65":
|
|
4321
|
-
case "ML-DSA-87": {
|
|
4322
|
-
keyUsages = ["sign", "verify"];
|
|
4323
|
-
algorithm = { name: alg };
|
|
4324
|
-
break;
|
|
4325
|
-
}
|
|
4326
|
-
case "ECDH-ES":
|
|
4327
|
-
case "ECDH-ES+A128KW":
|
|
4328
|
-
case "ECDH-ES+A192KW":
|
|
4329
|
-
case "ECDH-ES+A256KW": {
|
|
4330
|
-
keyUsages = ["deriveBits"];
|
|
4331
|
-
const crv = options?.crv ?? "P-256";
|
|
4332
|
-
switch (crv) {
|
|
4333
|
-
case "P-256":
|
|
4334
|
-
case "P-384":
|
|
4335
|
-
case "P-521": {
|
|
4336
|
-
algorithm = { name: "ECDH", namedCurve: crv };
|
|
4337
|
-
break;
|
|
4338
|
-
}
|
|
4339
|
-
case "X25519":
|
|
4340
|
-
algorithm = { name: "X25519" };
|
|
4341
|
-
break;
|
|
4342
|
-
default:
|
|
4343
|
-
throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
|
|
4344
|
-
}
|
|
4345
|
-
break;
|
|
4346
|
-
}
|
|
4347
|
-
default:
|
|
4348
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
4349
|
-
}
|
|
4350
|
-
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
|
|
4351
|
-
}
|
|
4352
|
-
var init_generate_key_pair = __esm({
|
|
4353
|
-
"node_modules/jose/dist/webapi/key/generate_key_pair.js"() {
|
|
4354
|
-
"use strict";
|
|
4355
|
-
init_esm_shims();
|
|
4356
|
-
init_errors();
|
|
4357
|
-
}
|
|
4358
|
-
});
|
|
4359
|
-
|
|
4360
|
-
// node_modules/jose/dist/webapi/key/generate_secret.js
|
|
4361
|
-
async function generateSecret(alg, options) {
|
|
4362
|
-
let length;
|
|
4363
|
-
let algorithm;
|
|
4364
|
-
let keyUsages;
|
|
4365
|
-
switch (alg) {
|
|
4366
|
-
case "HS256":
|
|
4367
|
-
case "HS384":
|
|
4368
|
-
case "HS512":
|
|
4369
|
-
length = parseInt(alg.slice(-3), 10);
|
|
4370
|
-
algorithm = { name: "HMAC", hash: `SHA-${length}`, length };
|
|
4371
|
-
keyUsages = ["sign", "verify"];
|
|
4372
|
-
break;
|
|
4373
|
-
case "A128CBC-HS256":
|
|
4374
|
-
case "A192CBC-HS384":
|
|
4375
|
-
case "A256CBC-HS512":
|
|
4376
|
-
length = parseInt(alg.slice(-3), 10);
|
|
4377
|
-
return crypto.getRandomValues(new Uint8Array(length >> 3));
|
|
4378
|
-
case "A128KW":
|
|
4379
|
-
case "A192KW":
|
|
4380
|
-
case "A256KW":
|
|
4381
|
-
length = parseInt(alg.slice(1, 4), 10);
|
|
4382
|
-
algorithm = { name: "AES-KW", length };
|
|
4383
|
-
keyUsages = ["wrapKey", "unwrapKey"];
|
|
4384
|
-
break;
|
|
4385
|
-
case "A128GCMKW":
|
|
4386
|
-
case "A192GCMKW":
|
|
4387
|
-
case "A256GCMKW":
|
|
4388
|
-
case "A128GCM":
|
|
4389
|
-
case "A192GCM":
|
|
4390
|
-
case "A256GCM":
|
|
4391
|
-
length = parseInt(alg.slice(1, 4), 10);
|
|
4392
|
-
algorithm = { name: "AES-GCM", length };
|
|
4393
|
-
keyUsages = ["encrypt", "decrypt"];
|
|
4394
|
-
break;
|
|
4395
|
-
default:
|
|
4396
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
4397
|
-
}
|
|
4398
|
-
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
|
|
4399
|
-
}
|
|
4400
|
-
var init_generate_secret = __esm({
|
|
4401
|
-
"node_modules/jose/dist/webapi/key/generate_secret.js"() {
|
|
4402
|
-
"use strict";
|
|
4403
|
-
init_esm_shims();
|
|
4404
|
-
init_errors();
|
|
4405
|
-
}
|
|
4406
|
-
});
|
|
4407
|
-
|
|
4408
|
-
// node_modules/jose/dist/webapi/index.js
|
|
4409
|
-
var webapi_exports = {};
|
|
4410
|
-
__export(webapi_exports, {
|
|
4411
|
-
CompactEncrypt: () => CompactEncrypt,
|
|
4412
|
-
CompactSign: () => CompactSign,
|
|
4413
|
-
EmbeddedJWK: () => EmbeddedJWK,
|
|
4414
|
-
EncryptJWT: () => EncryptJWT,
|
|
4415
|
-
FlattenedEncrypt: () => FlattenedEncrypt,
|
|
4416
|
-
FlattenedSign: () => FlattenedSign,
|
|
4417
|
-
GeneralEncrypt: () => GeneralEncrypt,
|
|
4418
|
-
GeneralSign: () => GeneralSign,
|
|
4419
|
-
SignJWT: () => SignJWT,
|
|
4420
|
-
UnsecuredJWT: () => UnsecuredJWT,
|
|
4421
|
-
base64url: () => base64url_exports,
|
|
4422
|
-
calculateJwkThumbprint: () => calculateJwkThumbprint,
|
|
4423
|
-
calculateJwkThumbprintUri: () => calculateJwkThumbprintUri,
|
|
4424
|
-
compactDecrypt: () => compactDecrypt,
|
|
4425
|
-
compactVerify: () => compactVerify,
|
|
4426
|
-
createLocalJWKSet: () => createLocalJWKSet,
|
|
4427
|
-
createRemoteJWKSet: () => createRemoteJWKSet,
|
|
4428
|
-
cryptoRuntime: () => cryptoRuntime,
|
|
4429
|
-
customFetch: () => customFetch,
|
|
4430
|
-
decodeJwt: () => decodeJwt,
|
|
4431
|
-
decodeProtectedHeader: () => decodeProtectedHeader,
|
|
4432
|
-
errors: () => errors_exports,
|
|
4433
|
-
exportJWK: () => exportJWK,
|
|
4434
|
-
exportPKCS8: () => exportPKCS8,
|
|
4435
|
-
exportSPKI: () => exportSPKI,
|
|
4436
|
-
flattenedDecrypt: () => flattenedDecrypt,
|
|
4437
|
-
flattenedVerify: () => flattenedVerify,
|
|
4438
|
-
generalDecrypt: () => generalDecrypt,
|
|
4439
|
-
generalVerify: () => generalVerify,
|
|
4440
|
-
generateKeyPair: () => generateKeyPair,
|
|
4441
|
-
generateSecret: () => generateSecret,
|
|
4442
|
-
importJWK: () => importJWK,
|
|
4443
|
-
importPKCS8: () => importPKCS8,
|
|
4444
|
-
importSPKI: () => importSPKI,
|
|
4445
|
-
importX509: () => importX509,
|
|
4446
|
-
jwksCache: () => jwksCache,
|
|
4447
|
-
jwtDecrypt: () => jwtDecrypt,
|
|
4448
|
-
jwtVerify: () => jwtVerify
|
|
4449
|
-
});
|
|
4450
|
-
var cryptoRuntime;
|
|
4451
|
-
var init_webapi = __esm({
|
|
4452
|
-
"node_modules/jose/dist/webapi/index.js"() {
|
|
4453
|
-
"use strict";
|
|
4454
|
-
init_esm_shims();
|
|
4455
|
-
init_decrypt3();
|
|
4456
|
-
init_decrypt2();
|
|
4457
|
-
init_decrypt4();
|
|
4458
|
-
init_encrypt3();
|
|
4459
|
-
init_verify3();
|
|
4460
|
-
init_verify2();
|
|
4461
|
-
init_verify4();
|
|
4462
|
-
init_verify5();
|
|
4463
|
-
init_decrypt5();
|
|
4464
|
-
init_encrypt4();
|
|
4465
|
-
init_encrypt2();
|
|
4466
|
-
init_sign3();
|
|
4467
|
-
init_sign2();
|
|
4468
|
-
init_sign4();
|
|
4469
|
-
init_sign5();
|
|
4470
|
-
init_encrypt5();
|
|
4471
|
-
init_thumbprint();
|
|
4472
|
-
init_embedded();
|
|
4473
|
-
init_local();
|
|
4474
|
-
init_remote();
|
|
4475
|
-
init_unsecured();
|
|
4476
|
-
init_export();
|
|
4477
|
-
init_import();
|
|
4478
|
-
init_decode_protected_header();
|
|
4479
|
-
init_decode_jwt();
|
|
4480
|
-
init_errors();
|
|
4481
|
-
init_generate_key_pair();
|
|
4482
|
-
init_generate_secret();
|
|
4483
|
-
init_base64url();
|
|
4484
|
-
cryptoRuntime = "WebCryptoAPI";
|
|
4485
|
-
}
|
|
4486
|
-
});
|
|
4487
|
-
|
|
4488
|
-
// src/onramp/index.ts
|
|
4489
|
-
var onramp_exports = {};
|
|
4490
|
-
__export(onramp_exports, {
|
|
4491
|
-
generateOnrampUrl: () => generateOnrampUrl,
|
|
4492
|
-
printQRCode: () => printQRCode
|
|
4493
|
-
});
|
|
4494
|
-
import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
|
|
4495
|
-
import { join as join4 } from "path";
|
|
4496
|
-
import { homedir as homedir2 } from "os";
|
|
4497
|
-
function loadCredentials() {
|
|
4498
|
-
let apiKeyId = process.env.CDP_API_KEY_ID;
|
|
4499
|
-
let apiKeySecret = process.env.CDP_API_KEY_SECRET;
|
|
4500
|
-
if (!apiKeyId || !apiKeySecret) {
|
|
4501
|
-
const envPath = join4(homedir2(), ".moltspay", ".env");
|
|
4502
|
-
if (existsSync4(envPath)) {
|
|
4503
|
-
const envContent = readFileSync4(envPath, "utf-8");
|
|
4504
|
-
for (const line of envContent.split("\n")) {
|
|
4505
|
-
const [key, ...valueParts] = line.split("=");
|
|
4506
|
-
const value = valueParts.join("=").trim();
|
|
4507
|
-
if (key === "CDP_API_KEY_ID") apiKeyId = value;
|
|
4508
|
-
if (key === "CDP_API_KEY_SECRET") apiKeySecret = value;
|
|
4509
|
-
}
|
|
4510
|
-
}
|
|
4511
|
-
}
|
|
4512
|
-
if (!apiKeyId || !apiKeySecret) {
|
|
4513
|
-
return null;
|
|
4514
|
-
}
|
|
4515
|
-
return { apiKeyId, apiKeySecret };
|
|
4516
|
-
}
|
|
4517
|
-
async function getPublicIp() {
|
|
4518
|
-
const response = await fetch("https://api.ipify.org");
|
|
4519
|
-
if (!response.ok) {
|
|
4520
|
-
throw new Error("Failed to get public IP");
|
|
4521
|
-
}
|
|
4522
|
-
return (await response.text()).trim();
|
|
4523
|
-
}
|
|
4524
|
-
async function generateCdpJwt(credentials, method, path4) {
|
|
4525
|
-
const { SignJWT: SignJWT2, importJWK: importJWK2 } = await Promise.resolve().then(() => (init_webapi(), webapi_exports));
|
|
4526
|
-
const crypto2 = await import("crypto");
|
|
4527
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
4528
|
-
const nonce = crypto2.randomBytes(16).toString("hex");
|
|
4529
|
-
const uri = `${method} api.developer.coinbase.com${path4}`;
|
|
4530
|
-
const claims = {
|
|
4531
|
-
sub: credentials.apiKeyId,
|
|
4532
|
-
iss: "cdp",
|
|
4533
|
-
nbf: now,
|
|
4534
|
-
exp: now + 120,
|
|
4535
|
-
uri
|
|
4536
|
-
};
|
|
4537
|
-
const decoded = Buffer.from(credentials.apiKeySecret, "base64");
|
|
4538
|
-
const seed = decoded.subarray(0, 32);
|
|
4539
|
-
const publicKey = decoded.subarray(32);
|
|
4540
|
-
const jwk = {
|
|
4541
|
-
kty: "OKP",
|
|
4542
|
-
crv: "Ed25519",
|
|
4543
|
-
d: seed.toString("base64url"),
|
|
4544
|
-
x: publicKey.toString("base64url")
|
|
4545
|
-
};
|
|
4546
|
-
const key = await importJWK2(jwk, "EdDSA");
|
|
4547
|
-
return await new SignJWT2(claims).setProtectedHeader({ alg: "EdDSA", kid: credentials.apiKeyId, typ: "JWT", nonce }).sign(key);
|
|
4548
|
-
}
|
|
4549
|
-
async function getSessionToken(params) {
|
|
4550
|
-
const credentials = loadCredentials();
|
|
4551
|
-
if (!credentials) {
|
|
4552
|
-
throw new Error("CDP credentials not found. Set CDP_API_KEY_ID and CDP_API_KEY_SECRET.");
|
|
4553
|
-
}
|
|
4554
|
-
const path4 = "/onramp/v1/token";
|
|
4555
|
-
const jwt = await generateCdpJwt(credentials, "POST", path4);
|
|
4556
|
-
const response = await fetch(`${CDP_API_BASE}${path4}`, {
|
|
4557
|
-
method: "POST",
|
|
4558
|
-
headers: {
|
|
4559
|
-
"Authorization": `Bearer ${jwt}`,
|
|
4560
|
-
"Content-Type": "application/json"
|
|
4561
|
-
},
|
|
4562
|
-
body: JSON.stringify({
|
|
4563
|
-
addresses: [
|
|
4564
|
-
{
|
|
4565
|
-
address: params.address,
|
|
4566
|
-
blockchains: [params.chain]
|
|
4567
|
-
}
|
|
4568
|
-
],
|
|
4569
|
-
clientIp: params.clientIp
|
|
4570
|
-
})
|
|
4571
|
-
});
|
|
4572
|
-
if (!response.ok) {
|
|
4573
|
-
const errorText = await response.text();
|
|
4574
|
-
throw new Error(`CDP API error (${response.status}): ${errorText}`);
|
|
4575
|
-
}
|
|
4576
|
-
const result = await response.json();
|
|
4577
|
-
return {
|
|
4578
|
-
token: result.token,
|
|
4579
|
-
channelId: result.channel_id
|
|
4580
|
-
};
|
|
4581
|
-
}
|
|
4582
|
-
async function generateOnrampUrl(params) {
|
|
4583
|
-
const chain = params.chain || "base";
|
|
4584
|
-
const clientIp = await getPublicIp();
|
|
4585
|
-
const { token } = await getSessionToken({
|
|
4586
|
-
address: params.destinationAddress,
|
|
4587
|
-
chain,
|
|
4588
|
-
clientIp
|
|
4589
|
-
});
|
|
4590
|
-
const queryParams = new URLSearchParams({
|
|
4591
|
-
sessionToken: token,
|
|
4592
|
-
defaultAsset: "USDC",
|
|
4593
|
-
defaultNetwork: chain,
|
|
4594
|
-
presetFiatAmount: params.amount.toString()
|
|
4595
|
-
});
|
|
4596
|
-
return `https://pay.coinbase.com/buy/select-asset?${queryParams.toString()}`;
|
|
4597
|
-
}
|
|
4598
|
-
async function printQRCode(url) {
|
|
4599
|
-
const qrcodeModule = await import("qrcode-terminal");
|
|
4600
|
-
const qrcode = qrcodeModule.default || qrcodeModule;
|
|
4601
|
-
return new Promise((resolve2) => {
|
|
4602
|
-
qrcode.generate(url, { small: true }, (qr) => {
|
|
4603
|
-
console.log(qr);
|
|
4604
|
-
resolve2();
|
|
4605
|
-
});
|
|
4606
|
-
});
|
|
4607
|
-
}
|
|
4608
|
-
var CDP_API_BASE;
|
|
4609
|
-
var init_onramp = __esm({
|
|
4610
|
-
"src/onramp/index.ts"() {
|
|
7
|
+
// node_modules/tsup/assets/esm_shims.js
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
var init_esm_shims = __esm({
|
|
11
|
+
"node_modules/tsup/assets/esm_shims.js"() {
|
|
4611
12
|
"use strict";
|
|
4612
|
-
init_esm_shims();
|
|
4613
|
-
CDP_API_BASE = "https://api.developer.coinbase.com";
|
|
4614
13
|
}
|
|
4615
14
|
});
|
|
4616
15
|
|
|
4617
16
|
// src/cli/index.ts
|
|
4618
17
|
init_esm_shims();
|
|
4619
18
|
import { Command } from "commander";
|
|
4620
|
-
import { homedir as
|
|
4621
|
-
import { join as
|
|
4622
|
-
import { existsSync as
|
|
19
|
+
import { homedir as homedir2 } from "os";
|
|
20
|
+
import { join as join4, dirname, resolve } from "path";
|
|
21
|
+
import { existsSync as existsSync4, writeFileSync as writeFileSync2, readFileSync as readFileSync4, unlinkSync, mkdirSync as mkdirSync2 } from "fs";
|
|
4623
22
|
import { spawn } from "child_process";
|
|
4624
23
|
|
|
4625
24
|
// src/client/index.ts
|
|
@@ -6192,11 +1591,11 @@ var MoltsPayServer = class {
|
|
|
6192
1591
|
return false;
|
|
6193
1592
|
}
|
|
6194
1593
|
const normalizedIP = clientIP === "::1" ? "127.0.0.1" : clientIP.replace("::ffff:", "");
|
|
6195
|
-
const
|
|
6196
|
-
if (!
|
|
1594
|
+
const allowed = allowedIPs.includes(normalizedIP) || allowedIPs.includes(clientIP);
|
|
1595
|
+
if (!allowed) {
|
|
6197
1596
|
console.log(`[MoltsPay] /proxy denied for IP: ${clientIP} (normalized: ${normalizedIP})`);
|
|
6198
1597
|
}
|
|
6199
|
-
return
|
|
1598
|
+
return allowed;
|
|
6200
1599
|
}
|
|
6201
1600
|
/**
|
|
6202
1601
|
* POST /proxy - Handle payment for external services (moltspay-creators)
|
|
@@ -6411,13 +1810,25 @@ var MoltsPayServer = class {
|
|
|
6411
1810
|
}
|
|
6412
1811
|
};
|
|
6413
1812
|
|
|
1813
|
+
// src/onramp/index.ts
|
|
1814
|
+
init_esm_shims();
|
|
1815
|
+
async function printQRCode(url) {
|
|
1816
|
+
const qrcodeModule = await import("qrcode-terminal");
|
|
1817
|
+
const qrcode = qrcodeModule.default || qrcodeModule;
|
|
1818
|
+
return new Promise((resolve2) => {
|
|
1819
|
+
qrcode.generate(url, { small: true }, (qr) => {
|
|
1820
|
+
console.log(qr);
|
|
1821
|
+
resolve2();
|
|
1822
|
+
});
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
|
|
6414
1826
|
// src/cli/index.ts
|
|
6415
|
-
init_onramp();
|
|
6416
1827
|
import * as readline from "readline";
|
|
6417
1828
|
var program = new Command();
|
|
6418
|
-
var DEFAULT_CONFIG_DIR =
|
|
6419
|
-
var PID_FILE =
|
|
6420
|
-
if (!
|
|
1829
|
+
var DEFAULT_CONFIG_DIR = join4(homedir2(), ".moltspay");
|
|
1830
|
+
var PID_FILE = join4(DEFAULT_CONFIG_DIR, "server.pid");
|
|
1831
|
+
if (!existsSync4(DEFAULT_CONFIG_DIR)) {
|
|
6421
1832
|
mkdirSync2(DEFAULT_CONFIG_DIR, { recursive: true });
|
|
6422
1833
|
}
|
|
6423
1834
|
function prompt(question) {
|
|
@@ -6435,7 +1846,7 @@ function prompt(question) {
|
|
|
6435
1846
|
program.name("moltspay").description("MoltsPay - Payment infrastructure for AI Agents").version("1.0.0");
|
|
6436
1847
|
program.command("init").description("Initialize MoltsPay client (create wallet, set limits)").option("--chain <chain>", "Blockchain to use", "base").option("--max-per-tx <amount>", "Max amount per transaction").option("--max-per-day <amount>", "Max amount per day").option("--config-dir <dir>", "Config directory", DEFAULT_CONFIG_DIR).action(async (options) => {
|
|
6437
1848
|
console.log("\n\u{1F510} MoltsPay Client Setup\n");
|
|
6438
|
-
if (
|
|
1849
|
+
if (existsSync4(join4(options.configDir, "wallet.json"))) {
|
|
6439
1850
|
console.log('\u26A0\uFE0F Already initialized. Use "moltspay config" to update settings.');
|
|
6440
1851
|
console.log(` Config dir: ${options.configDir}`);
|
|
6441
1852
|
return;
|
|
@@ -6462,7 +1873,7 @@ program.command("init").description("Initialize MoltsPay client (create wallet,
|
|
|
6462
1873
|
console.log(`
|
|
6463
1874
|
\u{1F4C1} Config saved to: ${result.configDir}`);
|
|
6464
1875
|
console.log(`
|
|
6465
|
-
\u26A0\uFE0F IMPORTANT: Back up ${
|
|
1876
|
+
\u26A0\uFE0F IMPORTANT: Back up ${join4(result.configDir, "wallet.json")}`);
|
|
6466
1877
|
console.log(` This file contains your private key!
|
|
6467
1878
|
`);
|
|
6468
1879
|
console.log(`\u{1F4B0} Fund your wallet with USDC on ${chain} to start using services.
|
|
@@ -6525,12 +1936,22 @@ program.command("fund <amount>").description("Fund wallet with USDC via Coinbase
|
|
|
6525
1936
|
console.log(` Amount: $${amount.toFixed(2)}
|
|
6526
1937
|
`);
|
|
6527
1938
|
try {
|
|
6528
|
-
const
|
|
6529
|
-
const
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
1939
|
+
const ONRAMP_API = process.env.MOLTSPAY_ONRAMP_API || "https://moltspay.com/api/v1/onramp";
|
|
1940
|
+
const response = await fetch(`${ONRAMP_API}/create`, {
|
|
1941
|
+
method: "POST",
|
|
1942
|
+
headers: { "Content-Type": "application/json" },
|
|
1943
|
+
body: JSON.stringify({
|
|
1944
|
+
address: client.address,
|
|
1945
|
+
amount,
|
|
1946
|
+
chain
|
|
1947
|
+
})
|
|
6533
1948
|
});
|
|
1949
|
+
if (!response.ok) {
|
|
1950
|
+
const errorData = await response.json().catch(() => ({ error: "Server error" }));
|
|
1951
|
+
throw new Error(errorData.error || `Server returned ${response.status}`);
|
|
1952
|
+
}
|
|
1953
|
+
const result = await response.json();
|
|
1954
|
+
const { url } = result;
|
|
6534
1955
|
console.log(" Scan to pay (US debit card / Apple Pay):\n");
|
|
6535
1956
|
await printQRCode(url);
|
|
6536
1957
|
console.log("\n \u23F1\uFE0F QR code expires in 5 minutes\n");
|
|
@@ -6641,12 +2062,12 @@ program.command("list").description("List recent transactions").option("--days <
|
|
|
6641
2062
|
console.log(" (no transactions found)\n");
|
|
6642
2063
|
} else {
|
|
6643
2064
|
for (const tx of allTxns) {
|
|
6644
|
-
const
|
|
2065
|
+
const sign = tx.type === "IN" ? "+" : "-";
|
|
6645
2066
|
const color = tx.type === "IN" ? "\x1B[32m" : "\x1B[31m";
|
|
6646
2067
|
const reset = "\x1B[0m";
|
|
6647
2068
|
const date = new Date(tx.timestamp).toISOString().slice(5, 16).replace("T", " ");
|
|
6648
2069
|
const chainTag = chain === "all" ? `[${tx.chain.toUpperCase()}] ` : "";
|
|
6649
|
-
console.log(` ${color}${
|
|
2070
|
+
console.log(` ${color}${sign}${tx.amount.toFixed(2)} USDC${reset} | ${chainTag}${tx.type === "IN" ? "from" : "to"} ${tx.other.slice(0, 10)}...${tx.other.slice(-4)} | ${date}`);
|
|
6650
2071
|
}
|
|
6651
2072
|
const inTotal = allTxns.filter((t) => t.type === "IN").reduce((s, t) => s + t.amount, 0);
|
|
6652
2073
|
const outTotal = allTxns.filter((t) => t.type === "OUT").reduce((s, t) => s + t.amount, 0);
|
|
@@ -6710,14 +2131,14 @@ program.command("start <paths...>").description("Start MoltsPay server from skil
|
|
|
6710
2131
|
let manifestPath;
|
|
6711
2132
|
let skillDir;
|
|
6712
2133
|
let isSkillDir = false;
|
|
6713
|
-
if (
|
|
6714
|
-
manifestPath =
|
|
2134
|
+
if (existsSync4(join4(resolvedPath, "moltspay.services.json"))) {
|
|
2135
|
+
manifestPath = join4(resolvedPath, "moltspay.services.json");
|
|
6715
2136
|
skillDir = resolvedPath;
|
|
6716
2137
|
isSkillDir = true;
|
|
6717
|
-
} else if (
|
|
2138
|
+
} else if (existsSync4(resolvedPath) && resolvedPath.endsWith(".json")) {
|
|
6718
2139
|
manifestPath = resolvedPath;
|
|
6719
2140
|
skillDir = dirname(resolvedPath);
|
|
6720
|
-
} else if (
|
|
2141
|
+
} else if (existsSync4(resolvedPath)) {
|
|
6721
2142
|
console.error(`\u274C No moltspay.services.json found in: ${resolvedPath}`);
|
|
6722
2143
|
continue;
|
|
6723
2144
|
} else {
|
|
@@ -6726,25 +2147,25 @@ program.command("start <paths...>").description("Start MoltsPay server from skil
|
|
|
6726
2147
|
}
|
|
6727
2148
|
console.log(`\u{1F4E6} Loading: ${manifestPath}`);
|
|
6728
2149
|
try {
|
|
6729
|
-
const manifestContent = JSON.parse(
|
|
2150
|
+
const manifestContent = JSON.parse(readFileSync4(manifestPath, "utf-8"));
|
|
6730
2151
|
if (!provider) {
|
|
6731
2152
|
provider = manifestContent.provider;
|
|
6732
2153
|
}
|
|
6733
2154
|
let skillModule = null;
|
|
6734
2155
|
if (isSkillDir) {
|
|
6735
2156
|
let entryPoint = "index.js";
|
|
6736
|
-
const pkgJsonPath =
|
|
6737
|
-
if (
|
|
2157
|
+
const pkgJsonPath = join4(skillDir, "package.json");
|
|
2158
|
+
if (existsSync4(pkgJsonPath)) {
|
|
6738
2159
|
try {
|
|
6739
|
-
const pkgJson = JSON.parse(
|
|
2160
|
+
const pkgJson = JSON.parse(readFileSync4(pkgJsonPath, "utf-8"));
|
|
6740
2161
|
if (pkgJson.main) {
|
|
6741
2162
|
entryPoint = pkgJson.main;
|
|
6742
2163
|
}
|
|
6743
2164
|
} catch {
|
|
6744
2165
|
}
|
|
6745
2166
|
}
|
|
6746
|
-
const modulePath =
|
|
6747
|
-
if (
|
|
2167
|
+
const modulePath = join4(skillDir, entryPoint);
|
|
2168
|
+
if (existsSync4(modulePath)) {
|
|
6748
2169
|
try {
|
|
6749
2170
|
skillModule = await import(modulePath);
|
|
6750
2171
|
console.log(` \u2705 Loaded module: ${modulePath}`);
|
|
@@ -6822,7 +2243,7 @@ program.command("start <paths...>").description("Start MoltsPay server from skil
|
|
|
6822
2243
|
provider,
|
|
6823
2244
|
services: allServices
|
|
6824
2245
|
};
|
|
6825
|
-
const tempManifestPath =
|
|
2246
|
+
const tempManifestPath = join4(DEFAULT_CONFIG_DIR, "combined-manifest.json");
|
|
6826
2247
|
writeFileSync2(tempManifestPath, JSON.stringify(combinedManifest, null, 2));
|
|
6827
2248
|
console.log(`
|
|
6828
2249
|
\u{1F4CB} Combined manifest: ${allServices.length} services`);
|
|
@@ -6840,8 +2261,8 @@ program.command("start <paths...>").description("Start MoltsPay server from skil
|
|
|
6840
2261
|
server.listen(port);
|
|
6841
2262
|
const cleanup = () => {
|
|
6842
2263
|
try {
|
|
6843
|
-
if (
|
|
6844
|
-
if (
|
|
2264
|
+
if (existsSync4(PID_FILE)) unlinkSync(PID_FILE);
|
|
2265
|
+
if (existsSync4(tempManifestPath)) unlinkSync(tempManifestPath);
|
|
6845
2266
|
} catch {
|
|
6846
2267
|
}
|
|
6847
2268
|
};
|
|
@@ -6862,12 +2283,12 @@ program.command("start <paths...>").description("Start MoltsPay server from skil
|
|
|
6862
2283
|
}
|
|
6863
2284
|
});
|
|
6864
2285
|
program.command("stop").description("Stop the running MoltsPay server").action(async () => {
|
|
6865
|
-
if (!
|
|
2286
|
+
if (!existsSync4(PID_FILE)) {
|
|
6866
2287
|
console.log("\u274C No running server found (no PID file)");
|
|
6867
2288
|
process.exit(1);
|
|
6868
2289
|
}
|
|
6869
2290
|
try {
|
|
6870
|
-
const pidData = JSON.parse(
|
|
2291
|
+
const pidData = JSON.parse(readFileSync4(PID_FILE, "utf-8"));
|
|
6871
2292
|
const { pid, port, manifest } = pidData;
|
|
6872
2293
|
console.log(`
|
|
6873
2294
|
\u{1F6D1} Stopping MoltsPay Server
|
|
@@ -6892,7 +2313,7 @@ program.command("stop").description("Stop the running MoltsPay server").action(a
|
|
|
6892
2313
|
process.kill(pid, "SIGKILL");
|
|
6893
2314
|
} catch {
|
|
6894
2315
|
}
|
|
6895
|
-
if (
|
|
2316
|
+
if (existsSync4(PID_FILE)) {
|
|
6896
2317
|
unlinkSync(PID_FILE);
|
|
6897
2318
|
}
|
|
6898
2319
|
console.log("\u2705 Server stopped\n");
|
|
@@ -6923,11 +2344,11 @@ program.command("pay <server> <service> [params]").description("Pay for a servic
|
|
|
6923
2344
|
params.image_url = imagePath;
|
|
6924
2345
|
} else {
|
|
6925
2346
|
const filePath = resolve(imagePath);
|
|
6926
|
-
if (!
|
|
2347
|
+
if (!existsSync4(filePath)) {
|
|
6927
2348
|
console.error(`\u274C Image file not found: ${filePath}`);
|
|
6928
2349
|
process.exit(1);
|
|
6929
2350
|
}
|
|
6930
|
-
const imageData =
|
|
2351
|
+
const imageData = readFileSync4(filePath);
|
|
6931
2352
|
params.image_base64 = imageData.toString("base64");
|
|
6932
2353
|
}
|
|
6933
2354
|
}
|
|
@@ -6991,9 +2412,9 @@ program.command("pay <server> <service> [params]").description("Pay for a servic
|
|
|
6991
2412
|
program.command("validate <path>").description("Validate a moltspay.services.json file against the schema").action(async (inputPath) => {
|
|
6992
2413
|
const resolvedPath = resolve(inputPath);
|
|
6993
2414
|
let manifestPath;
|
|
6994
|
-
if (
|
|
6995
|
-
manifestPath =
|
|
6996
|
-
} else if (resolvedPath.endsWith(".json") &&
|
|
2415
|
+
if (existsSync4(join4(resolvedPath, "moltspay.services.json"))) {
|
|
2416
|
+
manifestPath = join4(resolvedPath, "moltspay.services.json");
|
|
2417
|
+
} else if (resolvedPath.endsWith(".json") && existsSync4(resolvedPath)) {
|
|
6997
2418
|
manifestPath = resolvedPath;
|
|
6998
2419
|
} else {
|
|
6999
2420
|
console.error(`\u274C Not found: ${resolvedPath}`);
|
|
@@ -7003,7 +2424,7 @@ program.command("validate <path>").description("Validate a moltspay.services.jso
|
|
|
7003
2424
|
\u{1F4CB} Validating: ${manifestPath}
|
|
7004
2425
|
`);
|
|
7005
2426
|
try {
|
|
7006
|
-
const content = JSON.parse(
|
|
2427
|
+
const content = JSON.parse(readFileSync4(manifestPath, "utf-8"));
|
|
7007
2428
|
const errors = [];
|
|
7008
2429
|
if (!content.provider) {
|
|
7009
2430
|
errors.push("Missing required field: provider");
|