@meshagent/meshagent-ts-auth 0.51.6 → 0.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -3
- package/dist/browser/ma-auth.global.js +1034 -2153
- package/package.json +2 -2
|
@@ -2976,7 +2976,7 @@ meshagent.auth = (() => {
|
|
|
2976
2976
|
this.url = url;
|
|
2977
2977
|
this.name = name;
|
|
2978
2978
|
}
|
|
2979
|
-
static unpack(header,
|
|
2979
|
+
static unpack(header, _payload3) {
|
|
2980
2980
|
return new _LinkContent({
|
|
2981
2981
|
url: header["url"],
|
|
2982
2982
|
name: header["name"]
|
|
@@ -3023,7 +3023,7 @@ meshagent.auth = (() => {
|
|
|
3023
3023
|
constructor({ text }) {
|
|
3024
3024
|
this.text = text;
|
|
3025
3025
|
}
|
|
3026
|
-
static unpack(header,
|
|
3026
|
+
static unpack(header, _payload3) {
|
|
3027
3027
|
return new _TextContent({
|
|
3028
3028
|
text: header["text"]
|
|
3029
3029
|
});
|
|
@@ -3043,7 +3043,7 @@ meshagent.auth = (() => {
|
|
|
3043
3043
|
constructor({ json }) {
|
|
3044
3044
|
this.json = json;
|
|
3045
3045
|
}
|
|
3046
|
-
static unpack(header,
|
|
3046
|
+
static unpack(header, _payload3) {
|
|
3047
3047
|
return new _JsonContent({ json: header["json"] });
|
|
3048
3048
|
}
|
|
3049
3049
|
pack() {
|
|
@@ -3062,7 +3062,7 @@ meshagent.auth = (() => {
|
|
|
3062
3062
|
this.text = text;
|
|
3063
3063
|
this.code = code;
|
|
3064
3064
|
}
|
|
3065
|
-
static unpack(header,
|
|
3065
|
+
static unpack(header, _payload3) {
|
|
3066
3066
|
const rawCode = header["code"];
|
|
3067
3067
|
let code;
|
|
3068
3068
|
if (typeof rawCode === "number" && Number.isInteger(rawCode)) {
|
|
@@ -3091,7 +3091,7 @@ meshagent.auth = (() => {
|
|
|
3091
3091
|
};
|
|
3092
3092
|
exports.ErrorContent = ErrorContent;
|
|
3093
3093
|
var EmptyContent = class _EmptyContent {
|
|
3094
|
-
static unpack(_header,
|
|
3094
|
+
static unpack(_header, _payload3) {
|
|
3095
3095
|
return new _EmptyContent();
|
|
3096
3096
|
}
|
|
3097
3097
|
pack() {
|
|
@@ -3113,7 +3113,7 @@ meshagent.auth = (() => {
|
|
|
3113
3113
|
this.statusCode = method === "close" ? statusCode ?? ControlCloseStatus.NORMAL : statusCode;
|
|
3114
3114
|
this.message = message2;
|
|
3115
3115
|
}
|
|
3116
|
-
static unpack(header,
|
|
3116
|
+
static unpack(header, _payload3) {
|
|
3117
3117
|
const method = header["method"];
|
|
3118
3118
|
if (method !== "open" && method !== "close") {
|
|
3119
3119
|
throw new Error(`Invalid control method: ${method}`);
|
|
@@ -5172,9 +5172,9 @@ meshagent.auth = (() => {
|
|
|
5172
5172
|
let r = decoder2.arr[decoder2.pos++];
|
|
5173
5173
|
let num = r & BITS6;
|
|
5174
5174
|
let mult = 64;
|
|
5175
|
-
const
|
|
5175
|
+
const sign = (r & BIT7) > 0 ? -1 : 1;
|
|
5176
5176
|
if ((r & BIT8) === 0) {
|
|
5177
|
-
return
|
|
5177
|
+
return sign * num;
|
|
5178
5178
|
}
|
|
5179
5179
|
const len = decoder2.arr.length;
|
|
5180
5180
|
while (decoder2.pos < len) {
|
|
@@ -5182,7 +5182,7 @@ meshagent.auth = (() => {
|
|
|
5182
5182
|
num = num + (r & BITS7) * mult;
|
|
5183
5183
|
mult *= 128;
|
|
5184
5184
|
if (r < BIT8) {
|
|
5185
|
-
return
|
|
5185
|
+
return sign * num;
|
|
5186
5186
|
}
|
|
5187
5187
|
if (num > MAX_SAFE_INTEGER) {
|
|
5188
5188
|
throw errorIntegerOutOfRange;
|
|
@@ -21998,8 +21998,8 @@ ${err.toString()}`);
|
|
|
21998
21998
|
const remainder = negative ? -(number % denominator) : number % denominator;
|
|
21999
21999
|
const integerPart = (0, bigint_js_1.bigIntToNumber)(quotient);
|
|
22000
22000
|
const fractionPart = `${remainder}`.padStart(scale, "0");
|
|
22001
|
-
const
|
|
22002
|
-
return +`${
|
|
22001
|
+
const sign = negative && integerPart === 0 ? "-" : "";
|
|
22002
|
+
return +`${sign}${integerPart}.${fractionPart}`;
|
|
22003
22003
|
}
|
|
22004
22004
|
return (0, bigint_js_1.bigIntToNumber)(number);
|
|
22005
22005
|
}
|
|
@@ -23444,14 +23444,14 @@ ${err.toString()}`);
|
|
|
23444
23444
|
function uint16ToFloat64(h) {
|
|
23445
23445
|
const expo = (h & 31744) >> 10;
|
|
23446
23446
|
const sigf = (h & 1023) / 1024;
|
|
23447
|
-
const
|
|
23447
|
+
const sign = Math.pow(-1, (h & 32768) >> 15);
|
|
23448
23448
|
switch (expo) {
|
|
23449
23449
|
case 31:
|
|
23450
|
-
return
|
|
23450
|
+
return sign * (sigf ? Number.NaN : 1 / 0);
|
|
23451
23451
|
case 0:
|
|
23452
|
-
return
|
|
23452
|
+
return sign * (sigf ? 6103515625e-14 * sigf : 0);
|
|
23453
23453
|
}
|
|
23454
|
-
return
|
|
23454
|
+
return sign * Math.pow(2, expo - 15) * (1 + sigf);
|
|
23455
23455
|
}
|
|
23456
23456
|
exports.uint16ToFloat64 = uint16ToFloat64;
|
|
23457
23457
|
function float64ToUint16(d) {
|
|
@@ -23459,7 +23459,7 @@ ${err.toString()}`);
|
|
|
23459
23459
|
return 32256;
|
|
23460
23460
|
}
|
|
23461
23461
|
f64[0] = d;
|
|
23462
|
-
const
|
|
23462
|
+
const sign = (u32[1] & 2147483648) >> 16 & 65535;
|
|
23463
23463
|
let expo = u32[1] & 2146435072, sigf = 0;
|
|
23464
23464
|
if (expo >= 1089470464) {
|
|
23465
23465
|
if (u32[0] > 0) {
|
|
@@ -23476,7 +23476,7 @@ ${err.toString()}`);
|
|
|
23476
23476
|
expo = expo - 1056964608 >> 10;
|
|
23477
23477
|
sigf = (u32[1] & 1048575) + 512 >> 10;
|
|
23478
23478
|
}
|
|
23479
|
-
return
|
|
23479
|
+
return sign | expo | sigf & 65535;
|
|
23480
23480
|
}
|
|
23481
23481
|
exports.float64ToUint16 = float64ToUint16;
|
|
23482
23482
|
}
|
|
@@ -36342,116 +36342,74 @@ return true;`);
|
|
|
36342
36342
|
|
|
36343
36343
|
// ../node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
36344
36344
|
function concat(...buffers) {
|
|
36345
|
-
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
36346
|
-
const buf = new Uint8Array(size);
|
|
36345
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0), buf = new Uint8Array(size);
|
|
36347
36346
|
let i = 0;
|
|
36348
|
-
for (const buffer of buffers)
|
|
36349
|
-
buf.set(buffer, i);
|
|
36350
|
-
i += buffer.length;
|
|
36351
|
-
}
|
|
36347
|
+
for (const buffer of buffers)
|
|
36348
|
+
buf.set(buffer, i), i += buffer.length;
|
|
36352
36349
|
return buf;
|
|
36353
36350
|
}
|
|
36354
36351
|
function writeUInt32BE(buf, value, offset) {
|
|
36355
|
-
if (value < 0 || value >= MAX_INT32)
|
|
36352
|
+
if (value < 0 || value >= MAX_INT32)
|
|
36356
36353
|
throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
36357
|
-
}
|
|
36358
36354
|
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
|
|
36359
36355
|
}
|
|
36360
36356
|
function uint64be(value) {
|
|
36361
|
-
const high = Math.floor(value / MAX_INT32);
|
|
36362
|
-
|
|
36363
|
-
const buf = new Uint8Array(8);
|
|
36364
|
-
writeUInt32BE(buf, high, 0);
|
|
36365
|
-
writeUInt32BE(buf, low, 4);
|
|
36366
|
-
return buf;
|
|
36357
|
+
const high = Math.floor(value / MAX_INT32), low = value % MAX_INT32, buf = new Uint8Array(8);
|
|
36358
|
+
return writeUInt32BE(buf, high, 0), writeUInt32BE(buf, low, 4), buf;
|
|
36367
36359
|
}
|
|
36368
36360
|
function uint32be(value) {
|
|
36369
36361
|
const buf = new Uint8Array(4);
|
|
36370
|
-
writeUInt32BE(buf, value);
|
|
36371
|
-
return buf;
|
|
36362
|
+
return writeUInt32BE(buf, value), buf;
|
|
36372
36363
|
}
|
|
36373
36364
|
function encode(string) {
|
|
36365
|
+
if (typeof string == "string" && string.length >= 128) {
|
|
36366
|
+
if (NON_ASCII.test(string))
|
|
36367
|
+
throw new TypeError("non-ASCII string encountered in encode()");
|
|
36368
|
+
return encoder.encode(string);
|
|
36369
|
+
}
|
|
36374
36370
|
const bytes = new Uint8Array(string.length);
|
|
36375
36371
|
for (let i = 0; i < string.length; i++) {
|
|
36376
36372
|
const code = string.charCodeAt(i);
|
|
36377
|
-
if (code > 127)
|
|
36373
|
+
if (code > 127)
|
|
36378
36374
|
throw new TypeError("non-ASCII string encountered in encode()");
|
|
36379
|
-
}
|
|
36380
36375
|
bytes[i] = code;
|
|
36381
36376
|
}
|
|
36382
36377
|
return bytes;
|
|
36383
36378
|
}
|
|
36384
|
-
|
|
36379
|
+
function encodeBase64(input, url = false) {
|
|
36380
|
+
if (Uint8Array.prototype.toBase64)
|
|
36381
|
+
return input.toBase64({ alphabet: url ? "base64url" : "base64", omitPadding: url });
|
|
36382
|
+
const CHUNK_SIZE = 32768, arr = [];
|
|
36383
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE)
|
|
36384
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
36385
|
+
const encoded = btoa(arr.join(""));
|
|
36386
|
+
return url ? encoded.replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_") : encoded;
|
|
36387
|
+
}
|
|
36388
|
+
function decodeBase64(encoded, url = false) {
|
|
36389
|
+
if (Uint8Array.fromBase64)
|
|
36390
|
+
return Uint8Array.fromBase64(encoded, { alphabet: url ? "base64url" : "base64" });
|
|
36391
|
+
if (url) {
|
|
36392
|
+
if (encoded.includes("+") || encoded.includes("/"))
|
|
36393
|
+
throw new TypeError("Invalid base64url");
|
|
36394
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
36395
|
+
}
|
|
36396
|
+
const binary = atob(encoded), bytes = new Uint8Array(binary.length);
|
|
36397
|
+
for (let i = 0; i < binary.length; i++)
|
|
36398
|
+
bytes[i] = binary.charCodeAt(i);
|
|
36399
|
+
return bytes;
|
|
36400
|
+
}
|
|
36401
|
+
async function digest(algorithm, data) {
|
|
36402
|
+
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
36403
|
+
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
36404
|
+
}
|
|
36405
|
+
var encoder, decoder, strictDecoder, MAX_INT32, NON_ASCII;
|
|
36385
36406
|
var init_buffer_utils = __esm({
|
|
36386
36407
|
"../node_modules/jose/dist/webapi/lib/buffer_utils.js"() {
|
|
36387
36408
|
encoder = new TextEncoder();
|
|
36388
36409
|
decoder = new TextDecoder();
|
|
36389
36410
|
strictDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
36390
36411
|
MAX_INT32 = 2 ** 32;
|
|
36391
|
-
|
|
36392
|
-
});
|
|
36393
|
-
|
|
36394
|
-
// ../node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
36395
|
-
function checkUsage(key, usage) {
|
|
36396
|
-
if (usage && !key.usages.includes(usage)) {
|
|
36397
|
-
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
36398
|
-
}
|
|
36399
|
-
}
|
|
36400
|
-
function checkModulusLength(alg, key) {
|
|
36401
|
-
const { modulusLength } = key.algorithm;
|
|
36402
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
36403
|
-
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
36404
|
-
}
|
|
36405
|
-
}
|
|
36406
|
-
function checkCryptoKey(key, expected, usage) {
|
|
36407
|
-
const algorithm = key.algorithm;
|
|
36408
|
-
if (algorithm.name !== expected.name) {
|
|
36409
|
-
throw unusable(expected.name);
|
|
36410
|
-
}
|
|
36411
|
-
if (expected.hash && algorithm.hash?.name !== expected.hash) {
|
|
36412
|
-
throw unusable(expected.hash, "algorithm.hash");
|
|
36413
|
-
}
|
|
36414
|
-
if (expected.namedCurve && algorithm.namedCurve !== expected.namedCurve) {
|
|
36415
|
-
throw unusable(expected.namedCurve, "algorithm.namedCurve");
|
|
36416
|
-
}
|
|
36417
|
-
if (expected.length !== void 0 && algorithm.length !== expected.length) {
|
|
36418
|
-
throw unusable(expected.length, "algorithm.length");
|
|
36419
|
-
}
|
|
36420
|
-
checkUsage(key, usage);
|
|
36421
|
-
}
|
|
36422
|
-
var unusable;
|
|
36423
|
-
var init_crypto_key = __esm({
|
|
36424
|
-
"../node_modules/jose/dist/webapi/lib/crypto_key.js"() {
|
|
36425
|
-
unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
36426
|
-
}
|
|
36427
|
-
});
|
|
36428
|
-
|
|
36429
|
-
// ../node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
36430
|
-
function message(msg, actual, ...types) {
|
|
36431
|
-
if (types.length > 2) {
|
|
36432
|
-
const last = types.pop();
|
|
36433
|
-
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
36434
|
-
} else if (types.length === 2) {
|
|
36435
|
-
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
36436
|
-
} else {
|
|
36437
|
-
msg += `of type ${types[0]}.`;
|
|
36438
|
-
}
|
|
36439
|
-
if (actual == null) {
|
|
36440
|
-
msg += ` Received ${actual}`;
|
|
36441
|
-
} else if (typeof actual === "function" && actual.name) {
|
|
36442
|
-
msg += ` Received function ${actual.name}`;
|
|
36443
|
-
} else if (typeof actual === "object" && actual != null) {
|
|
36444
|
-
if (actual.constructor?.name) {
|
|
36445
|
-
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
36446
|
-
}
|
|
36447
|
-
}
|
|
36448
|
-
return msg;
|
|
36449
|
-
}
|
|
36450
|
-
var invalidKeyInput, withAlg;
|
|
36451
|
-
var init_invalid_key_input = __esm({
|
|
36452
|
-
"../node_modules/jose/dist/webapi/lib/invalid_key_input.js"() {
|
|
36453
|
-
invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
36454
|
-
withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
36412
|
+
NON_ASCII = /[^\x00-\x7f]/;
|
|
36455
36413
|
}
|
|
36456
36414
|
});
|
|
36457
36415
|
|
|
@@ -36481,8 +36439,7 @@ return true;`);
|
|
|
36481
36439
|
constructor(message2, options) {
|
|
36482
36440
|
super(message2, options);
|
|
36483
36441
|
__publicField(this, "code", "ERR_JOSE_GENERIC");
|
|
36484
|
-
this.name = this.constructor.name;
|
|
36485
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
36442
|
+
this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
|
|
36486
36443
|
}
|
|
36487
36444
|
};
|
|
36488
36445
|
__publicField(JOSEError, "code", "ERR_JOSE_GENERIC");
|
|
@@ -36493,9 +36450,7 @@ return true;`);
|
|
|
36493
36450
|
__publicField(this, "claim");
|
|
36494
36451
|
__publicField(this, "reason");
|
|
36495
36452
|
__publicField(this, "payload");
|
|
36496
|
-
this.claim = claim;
|
|
36497
|
-
this.reason = reason;
|
|
36498
|
-
this.payload = payload;
|
|
36453
|
+
this.claim = claim, this.reason = reason, this.payload = payload;
|
|
36499
36454
|
}
|
|
36500
36455
|
};
|
|
36501
36456
|
__publicField(JWTClaimValidationFailed, "code", "ERR_JWT_CLAIM_VALIDATION_FAILED");
|
|
@@ -36506,9 +36461,7 @@ return true;`);
|
|
|
36506
36461
|
__publicField(this, "claim");
|
|
36507
36462
|
__publicField(this, "reason");
|
|
36508
36463
|
__publicField(this, "payload");
|
|
36509
|
-
this.claim = claim;
|
|
36510
|
-
this.reason = reason;
|
|
36511
|
-
this.payload = payload;
|
|
36464
|
+
this.claim = claim, this.reason = reason, this.payload = payload;
|
|
36512
36465
|
}
|
|
36513
36466
|
};
|
|
36514
36467
|
__publicField(JWTExpired, "code", "ERR_JWT_EXPIRED");
|
|
@@ -36601,187 +36554,6 @@ return true;`);
|
|
|
36601
36554
|
}
|
|
36602
36555
|
});
|
|
36603
36556
|
|
|
36604
|
-
// ../node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
36605
|
-
function assertCryptoKey(key) {
|
|
36606
|
-
if (!isCryptoKey(key)) {
|
|
36607
|
-
throw new Error("CryptoKey instance expected");
|
|
36608
|
-
}
|
|
36609
|
-
}
|
|
36610
|
-
var isCryptoKey, isKeyObject, isKeyLike;
|
|
36611
|
-
var init_is_key_like = __esm({
|
|
36612
|
-
"../node_modules/jose/dist/webapi/lib/is_key_like.js"() {
|
|
36613
|
-
isCryptoKey = (key) => {
|
|
36614
|
-
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
36615
|
-
return true;
|
|
36616
|
-
try {
|
|
36617
|
-
return key instanceof CryptoKey;
|
|
36618
|
-
} catch {
|
|
36619
|
-
return false;
|
|
36620
|
-
}
|
|
36621
|
-
};
|
|
36622
|
-
isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
36623
|
-
isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
36624
|
-
}
|
|
36625
|
-
});
|
|
36626
|
-
|
|
36627
|
-
// ../node_modules/jose/dist/webapi/lib/content_encryption.js
|
|
36628
|
-
function checkCekLength(cek, expected) {
|
|
36629
|
-
const actual = cek.byteLength << 3;
|
|
36630
|
-
if (actual !== expected) {
|
|
36631
|
-
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
36632
|
-
}
|
|
36633
|
-
}
|
|
36634
|
-
function checkIvLength(enc, iv) {
|
|
36635
|
-
if (iv.length << 3 !== enc.ivBits) {
|
|
36636
|
-
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
36637
|
-
}
|
|
36638
|
-
}
|
|
36639
|
-
async function cbcKeySetup(enc, cek, usage) {
|
|
36640
|
-
if (!(cek instanceof Uint8Array)) {
|
|
36641
|
-
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
36642
|
-
}
|
|
36643
|
-
const keySize = enc.cekBits >> 1;
|
|
36644
|
-
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, [usage]);
|
|
36645
|
-
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
36646
|
-
hash: `SHA-${keySize << 1}`,
|
|
36647
|
-
name: "HMAC"
|
|
36648
|
-
}, false, ["sign"]);
|
|
36649
|
-
return [encKey, macKey, keySize];
|
|
36650
|
-
}
|
|
36651
|
-
async function cbcHmacTag(macKey, macData, keySize) {
|
|
36652
|
-
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
36653
|
-
}
|
|
36654
|
-
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
36655
|
-
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "encrypt");
|
|
36656
|
-
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
36657
|
-
iv,
|
|
36658
|
-
name: "AES-CBC"
|
|
36659
|
-
}, encKey, plaintext));
|
|
36660
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
|
|
36661
|
-
const tag2 = await cbcHmacTag(macKey, macData, keySize);
|
|
36662
|
-
return { ciphertext, tag: tag2, iv };
|
|
36663
|
-
}
|
|
36664
|
-
async function timingSafeEqual(a, b) {
|
|
36665
|
-
const algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
36666
|
-
const key = await crypto.subtle.generateKey(algorithm, false, ["sign", "verify"]);
|
|
36667
|
-
const aHmac = await crypto.subtle.sign(algorithm, key, a);
|
|
36668
|
-
return crypto.subtle.verify(algorithm, key, aHmac, b);
|
|
36669
|
-
}
|
|
36670
|
-
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
36671
|
-
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "decrypt");
|
|
36672
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
|
|
36673
|
-
const expectedTag = await cbcHmacTag(macKey, macData, keySize);
|
|
36674
|
-
try {
|
|
36675
|
-
if (await timingSafeEqual(tag2, expectedTag)) {
|
|
36676
|
-
return new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
36677
|
-
}
|
|
36678
|
-
} catch {
|
|
36679
|
-
}
|
|
36680
|
-
throw new JWEDecryptionFailed();
|
|
36681
|
-
}
|
|
36682
|
-
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
36683
|
-
const encKey = cek instanceof Uint8Array ? await crypto.subtle.importKey("raw", cek, "AES-GCM", false, [
|
|
36684
|
-
"encrypt"
|
|
36685
|
-
]) : (checkCryptoKey(cek, enc.subtle, "encrypt"), cek);
|
|
36686
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
36687
|
-
additionalData: aad,
|
|
36688
|
-
iv,
|
|
36689
|
-
name: "AES-GCM",
|
|
36690
|
-
tagLength: 128
|
|
36691
|
-
}, encKey, plaintext));
|
|
36692
|
-
const tag2 = encrypted.slice(-16);
|
|
36693
|
-
const ciphertext = encrypted.slice(0, -16);
|
|
36694
|
-
return { ciphertext, tag: tag2, iv };
|
|
36695
|
-
}
|
|
36696
|
-
async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
36697
|
-
const encKey = cek instanceof Uint8Array ? await crypto.subtle.importKey("raw", cek, "AES-GCM", false, [
|
|
36698
|
-
"decrypt"
|
|
36699
|
-
]) : (checkCryptoKey(cek, enc.subtle, "decrypt"), cek);
|
|
36700
|
-
try {
|
|
36701
|
-
return new Uint8Array(await crypto.subtle.decrypt({
|
|
36702
|
-
additionalData: aad,
|
|
36703
|
-
iv,
|
|
36704
|
-
name: "AES-GCM",
|
|
36705
|
-
tagLength: 128
|
|
36706
|
-
}, encKey, concat(ciphertext, tag2)));
|
|
36707
|
-
} catch {
|
|
36708
|
-
throw new JWEDecryptionFailed();
|
|
36709
|
-
}
|
|
36710
|
-
}
|
|
36711
|
-
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
36712
|
-
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
36713
|
-
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
36714
|
-
}
|
|
36715
|
-
if (iv) {
|
|
36716
|
-
checkIvLength(enc, iv);
|
|
36717
|
-
} else {
|
|
36718
|
-
iv = generateIv(enc);
|
|
36719
|
-
}
|
|
36720
|
-
if (cek instanceof Uint8Array) {
|
|
36721
|
-
checkCekLength(cek, enc.cekBits);
|
|
36722
|
-
}
|
|
36723
|
-
return enc.cbc ? cbcEncrypt(enc, plaintext, cek, iv, aad) : gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
36724
|
-
}
|
|
36725
|
-
async function decrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
36726
|
-
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
36727
|
-
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
36728
|
-
}
|
|
36729
|
-
if (!iv) {
|
|
36730
|
-
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
36731
|
-
}
|
|
36732
|
-
if (!tag2) {
|
|
36733
|
-
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
36734
|
-
}
|
|
36735
|
-
if (!enc.cbc && tag2.length !== 16) {
|
|
36736
|
-
throw new JWEInvalid("Invalid Authentication Tag length");
|
|
36737
|
-
}
|
|
36738
|
-
checkIvLength(enc, iv);
|
|
36739
|
-
if (cek instanceof Uint8Array) {
|
|
36740
|
-
checkCekLength(cek, enc.cekBits);
|
|
36741
|
-
}
|
|
36742
|
-
return enc.cbc ? cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) : gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
36743
|
-
}
|
|
36744
|
-
var generateCek, generateIv;
|
|
36745
|
-
var init_content_encryption = __esm({
|
|
36746
|
-
"../node_modules/jose/dist/webapi/lib/content_encryption.js"() {
|
|
36747
|
-
init_buffer_utils();
|
|
36748
|
-
init_crypto_key();
|
|
36749
|
-
init_invalid_key_input();
|
|
36750
|
-
init_errors();
|
|
36751
|
-
init_is_key_like();
|
|
36752
|
-
generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
|
|
36753
|
-
generateIv = (enc) => crypto.getRandomValues(new Uint8Array(enc.ivBits >> 3));
|
|
36754
|
-
}
|
|
36755
|
-
});
|
|
36756
|
-
|
|
36757
|
-
// ../node_modules/jose/dist/webapi/lib/base64.js
|
|
36758
|
-
function encodeBase64(input) {
|
|
36759
|
-
if (Uint8Array.prototype.toBase64) {
|
|
36760
|
-
return input.toBase64();
|
|
36761
|
-
}
|
|
36762
|
-
const CHUNK_SIZE = 32768;
|
|
36763
|
-
const arr = [];
|
|
36764
|
-
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
36765
|
-
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
36766
|
-
}
|
|
36767
|
-
return btoa(arr.join(""));
|
|
36768
|
-
}
|
|
36769
|
-
function decodeBase64(encoded) {
|
|
36770
|
-
if (Uint8Array.fromBase64) {
|
|
36771
|
-
return Uint8Array.fromBase64(encoded);
|
|
36772
|
-
}
|
|
36773
|
-
const binary = atob(encoded);
|
|
36774
|
-
const bytes = new Uint8Array(binary.length);
|
|
36775
|
-
for (let i = 0; i < binary.length; i++) {
|
|
36776
|
-
bytes[i] = binary.charCodeAt(i);
|
|
36777
|
-
}
|
|
36778
|
-
return bytes;
|
|
36779
|
-
}
|
|
36780
|
-
var init_base64 = __esm({
|
|
36781
|
-
"../node_modules/jose/dist/webapi/lib/base64.js"() {
|
|
36782
|
-
}
|
|
36783
|
-
});
|
|
36784
|
-
|
|
36785
36557
|
// ../node_modules/jose/dist/webapi/util/base64url.js
|
|
36786
36558
|
var base64url_exports = {};
|
|
36787
36559
|
__export(base64url_exports, {
|
|
@@ -36789,58 +36561,31 @@ return true;`);
|
|
|
36789
36561
|
encode: () => encode2
|
|
36790
36562
|
});
|
|
36791
36563
|
function decode(input) {
|
|
36792
|
-
if (Uint8Array.fromBase64) {
|
|
36793
|
-
try {
|
|
36794
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
36795
|
-
alphabet: "base64url"
|
|
36796
|
-
});
|
|
36797
|
-
} catch (cause) {
|
|
36798
|
-
throw new TypeError(invalid, { cause });
|
|
36799
|
-
}
|
|
36800
|
-
}
|
|
36801
|
-
let encoded = input;
|
|
36802
|
-
if (encoded instanceof Uint8Array) {
|
|
36803
|
-
encoded = decoder.decode(encoded);
|
|
36804
|
-
}
|
|
36805
|
-
if (encoded.includes("+") || encoded.includes("/")) {
|
|
36806
|
-
throw new TypeError(invalid);
|
|
36807
|
-
}
|
|
36808
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
36809
36564
|
try {
|
|
36810
|
-
return decodeBase64(
|
|
36811
|
-
} catch {
|
|
36812
|
-
throw new TypeError(invalid);
|
|
36565
|
+
return decodeBase64(typeof input == "string" ? input : decoder.decode(input), true);
|
|
36566
|
+
} catch (cause) {
|
|
36567
|
+
throw new TypeError(invalid, { cause });
|
|
36813
36568
|
}
|
|
36814
36569
|
}
|
|
36815
36570
|
function encode2(input) {
|
|
36816
|
-
|
|
36817
|
-
if (typeof unencoded === "string") {
|
|
36818
|
-
unencoded = encoder.encode(unencoded);
|
|
36819
|
-
}
|
|
36820
|
-
if (Uint8Array.prototype.toBase64) {
|
|
36821
|
-
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
36822
|
-
}
|
|
36823
|
-
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
36571
|
+
return encodeBase64(typeof input == "string" ? encoder.encode(input) : input, true);
|
|
36824
36572
|
}
|
|
36825
36573
|
var invalid;
|
|
36826
36574
|
var init_base64url = __esm({
|
|
36827
36575
|
"../node_modules/jose/dist/webapi/util/base64url.js"() {
|
|
36828
36576
|
init_buffer_utils();
|
|
36829
|
-
init_base64();
|
|
36830
36577
|
invalid = "The input to be decoded is not correctly encoded.";
|
|
36831
36578
|
}
|
|
36832
36579
|
});
|
|
36833
36580
|
|
|
36834
|
-
// ../node_modules/jose/dist/webapi/lib/
|
|
36581
|
+
// ../node_modules/jose/dist/webapi/lib/validate.js
|
|
36835
36582
|
function assertUint8Array(input, label) {
|
|
36836
|
-
if (!(input instanceof Uint8Array))
|
|
36583
|
+
if (!(input instanceof Uint8Array))
|
|
36837
36584
|
throw new TypeError(`${label} must be an instance of Uint8Array`);
|
|
36838
|
-
}
|
|
36839
36585
|
}
|
|
36840
36586
|
function isObject(input) {
|
|
36841
|
-
if (typeof input
|
|
36587
|
+
if (typeof input != "object" || input === null || Object.prototype.toString.call(input) !== "[object Object]")
|
|
36842
36588
|
return false;
|
|
36843
|
-
}
|
|
36844
36589
|
const prototype = Object.getPrototypeOf(input);
|
|
36845
36590
|
return prototype === null || Object.getPrototypeOf(prototype) === null;
|
|
36846
36591
|
}
|
|
@@ -36849,28 +36594,18 @@ return true;`);
|
|
|
36849
36594
|
}
|
|
36850
36595
|
function isDisjoint(...headers) {
|
|
36851
36596
|
const parameters = /* @__PURE__ */ new Set();
|
|
36852
|
-
for (const header of headers)
|
|
36853
|
-
if (
|
|
36854
|
-
|
|
36855
|
-
|
|
36856
|
-
|
|
36857
|
-
|
|
36597
|
+
for (const header of headers)
|
|
36598
|
+
if (header)
|
|
36599
|
+
for (const parameter of Object.keys(header)) {
|
|
36600
|
+
if (parameters.has(parameter))
|
|
36601
|
+
return false;
|
|
36602
|
+
parameters.add(parameter);
|
|
36858
36603
|
}
|
|
36859
|
-
parameters.add(parameter);
|
|
36860
|
-
}
|
|
36861
|
-
}
|
|
36862
36604
|
return true;
|
|
36863
36605
|
}
|
|
36864
|
-
var init_type_checks = __esm({
|
|
36865
|
-
"../node_modules/jose/dist/webapi/lib/type_checks.js"() {
|
|
36866
|
-
}
|
|
36867
|
-
});
|
|
36868
|
-
|
|
36869
|
-
// ../node_modules/jose/dist/webapi/lib/helpers.js
|
|
36870
36606
|
function assertNotSet(value, name) {
|
|
36871
|
-
if (value !== void 0)
|
|
36607
|
+
if (value !== void 0)
|
|
36872
36608
|
throw new TypeError(`${name} can only be called once`);
|
|
36873
|
-
}
|
|
36874
36609
|
}
|
|
36875
36610
|
function decodeBase64url(value, label, ErrorClass) {
|
|
36876
36611
|
try {
|
|
@@ -36886,10 +36621,6 @@ return true;`);
|
|
|
36886
36621
|
throw new ErrorClass(`The ${label} is not a valid base64url string`);
|
|
36887
36622
|
}
|
|
36888
36623
|
}
|
|
36889
|
-
async function digest(algorithm, data) {
|
|
36890
|
-
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
36891
|
-
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
36892
|
-
}
|
|
36893
36624
|
function parseJoseHeader(b64, ErrorClass, message2) {
|
|
36894
36625
|
let parsed;
|
|
36895
36626
|
try {
|
|
@@ -36897,208 +36628,311 @@ return true;`);
|
|
|
36897
36628
|
} catch {
|
|
36898
36629
|
throw new ErrorClass(message2);
|
|
36899
36630
|
}
|
|
36900
|
-
if (!isObject(parsed))
|
|
36631
|
+
if (!isObject(parsed))
|
|
36901
36632
|
throw new ErrorClass(message2);
|
|
36902
|
-
}
|
|
36903
36633
|
return parsed;
|
|
36904
36634
|
}
|
|
36905
|
-
|
|
36906
|
-
|
|
36907
|
-
|
|
36908
|
-
|
|
36909
|
-
|
|
36910
|
-
|
|
36911
|
-
|
|
36912
|
-
|
|
36913
|
-
|
|
36914
|
-
|
|
36915
|
-
|
|
36916
|
-
|
|
36917
|
-
|
|
36918
|
-
|
|
36635
|
+
function validateAlgorithms(option, algorithms) {
|
|
36636
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s != "string")))
|
|
36637
|
+
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
36638
|
+
return algorithms === void 0 ? void 0 : new Set(algorithms);
|
|
36639
|
+
}
|
|
36640
|
+
function validateCritDuplicates(Err, protectedHeader) {
|
|
36641
|
+
const { crit } = protectedHeader ?? {};
|
|
36642
|
+
if (Array.isArray(crit) && new Set(crit).size !== crit.length)
|
|
36643
|
+
throw new Err('"crit" (Critical) Header Parameter MUST NOT contain duplicate values');
|
|
36644
|
+
}
|
|
36645
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
36646
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0)
|
|
36647
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
36648
|
+
if (!protectedHeader || protectedHeader.crit === void 0)
|
|
36649
|
+
return [];
|
|
36650
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input != "string" || input.length === 0))
|
|
36651
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
36652
|
+
const recognized = recognizedOption === void 0 ? recognizedDefault : { __proto__: null, ...recognizedOption, ...recognizedDefault };
|
|
36653
|
+
for (const parameter of protectedHeader.crit) {
|
|
36654
|
+
if (!(parameter in recognized))
|
|
36655
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
36656
|
+
if (!Object.hasOwn(joseHeader, parameter) || joseHeader[parameter] === void 0)
|
|
36657
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
36658
|
+
if (recognized[parameter] && (!Object.hasOwn(protectedHeader, parameter) || protectedHeader[parameter] === void 0))
|
|
36659
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
36919
36660
|
}
|
|
36920
|
-
|
|
36921
|
-
|
|
36661
|
+
return protectedHeader.crit;
|
|
36662
|
+
}
|
|
36663
|
+
function validateB64(protectedHeader, extensions) {
|
|
36664
|
+
if (extensions.includes("b64")) {
|
|
36665
|
+
const b64 = protectedHeader.b64;
|
|
36666
|
+
if (typeof b64 != "boolean")
|
|
36667
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
36668
|
+
return b64;
|
|
36922
36669
|
}
|
|
36923
|
-
|
|
36924
|
-
|
|
36925
|
-
|
|
36926
|
-
|
|
36927
|
-
|
|
36670
|
+
return true;
|
|
36671
|
+
}
|
|
36672
|
+
function serializeJoseHeader(Err, header) {
|
|
36673
|
+
let serialized, parsed;
|
|
36674
|
+
try {
|
|
36675
|
+
serialized = JSON.stringify(header), parsed = JSON.parse(serialized);
|
|
36676
|
+
} catch (cause) {
|
|
36677
|
+
throw new Err("JOSE Header is not valid JSON", { cause });
|
|
36928
36678
|
}
|
|
36929
|
-
|
|
36930
|
-
|
|
36679
|
+
if (!isObject(parsed))
|
|
36680
|
+
throw new Err("JOSE Header is not a JSON object");
|
|
36681
|
+
return [parsed, serialized];
|
|
36931
36682
|
}
|
|
36932
|
-
var
|
|
36933
|
-
|
|
36683
|
+
var JWS_RECOGNIZED, JWE_RECOGNIZED;
|
|
36684
|
+
var init_validate2 = __esm({
|
|
36685
|
+
"../node_modules/jose/dist/webapi/lib/validate.js"() {
|
|
36934
36686
|
init_errors();
|
|
36687
|
+
init_base64url();
|
|
36688
|
+
init_buffer_utils();
|
|
36689
|
+
JWS_RECOGNIZED = { __proto__: null, b64: true };
|
|
36690
|
+
JWE_RECOGNIZED = { __proto__: null };
|
|
36935
36691
|
}
|
|
36936
36692
|
});
|
|
36937
36693
|
|
|
36938
|
-
// ../node_modules/jose/dist/webapi/lib/
|
|
36694
|
+
// ../node_modules/jose/dist/webapi/lib/key.js
|
|
36695
|
+
async function prepareKey(entry, key, usage) {
|
|
36696
|
+
const { alg, secret } = entry, privateKey = usage === "decrypt" || usage === "sign";
|
|
36697
|
+
if (secret && key instanceof Uint8Array)
|
|
36698
|
+
return key;
|
|
36699
|
+
let normalized, keyObject;
|
|
36700
|
+
if (isObject(key)) {
|
|
36701
|
+
if (normalized = normalizeJwk(key), typeof normalized.kty != "string")
|
|
36702
|
+
throw invalidKeyType(alg, key, secret);
|
|
36703
|
+
if (!(secret ? normalized.kty === "oct" && typeof normalized.k == "string" : normalized.kty !== "oct" && (privateKey ? normalized.kty === "AKP" && typeof normalized.priv == "string" || typeof normalized.d == "string" : normalized.d === void 0 && normalized.priv === void 0)))
|
|
36704
|
+
throw new TypeError(secret ? 'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present' : `JSON Web Key for this operation must be a ${privateKey ? "private" : "public"} JWK`);
|
|
36705
|
+
if (jwkMatchesOp(entry, normalized, usage), normalized.kty === "oct")
|
|
36706
|
+
return decode(normalized.k);
|
|
36707
|
+
if (!Object.isFrozen(key)) {
|
|
36708
|
+
const { key_ops } = key;
|
|
36709
|
+
Array.isArray(key_ops) && Object.freeze(key_ops), Object.freeze(key);
|
|
36710
|
+
}
|
|
36711
|
+
} else {
|
|
36712
|
+
if (!isKeyLike(key))
|
|
36713
|
+
throw invalidKeyType(alg, key, secret);
|
|
36714
|
+
const expectedType = secret ? "secret" : privateKey ? "private" : "public";
|
|
36715
|
+
if (key.type !== expectedType && (secret || ["secret", "public", "private"].includes(key.type)))
|
|
36716
|
+
throw new TypeError(`${tag(key)} instances must be of type "${expectedType}" for the ${alg} algorithm`);
|
|
36717
|
+
if (isCryptoKey(key))
|
|
36718
|
+
return key;
|
|
36719
|
+
if (keyObject = key, keyObject.type === "secret")
|
|
36720
|
+
return keyObject.export();
|
|
36721
|
+
}
|
|
36722
|
+
cache || (cache = /* @__PURE__ */ new WeakMap());
|
|
36723
|
+
const cacheKey = key;
|
|
36724
|
+
let cached = cache.get(cacheKey);
|
|
36725
|
+
if (cached?.[alg])
|
|
36726
|
+
return cached[alg];
|
|
36727
|
+
if (cached || cache.set(cacheKey, cached = {}), keyObject && typeof keyObject.toCryptoKey == "function") {
|
|
36728
|
+
const isPublic = keyObject.type === "public", crv = nist[keyObject.asymmetricKeyDetails?.namedCurve], params = entry.resolve?.({ crv, asymmetricKeyType: keyObject.asymmetricKeyType }) ?? entry.subtle;
|
|
36729
|
+
return cached[alg] = keyObject.toCryptoKey(params, isPublic, entry.usages[isPublic ? 0 : 1]);
|
|
36730
|
+
}
|
|
36731
|
+
return normalized ?? (normalized = keyObject.export({ format: "jwk" })), normalized.alg = alg, cached[alg] = await jwkToKey(entry, normalized);
|
|
36732
|
+
}
|
|
36733
|
+
function assertCryptoKey(key) {
|
|
36734
|
+
if (!isCryptoKey(key))
|
|
36735
|
+
throw new Error("CryptoKey instance expected");
|
|
36736
|
+
}
|
|
36737
|
+
function message(msg, actual, ...types) {
|
|
36738
|
+
if (types.length > 2) {
|
|
36739
|
+
const last = types.pop();
|
|
36740
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
36741
|
+
} else types.length === 2 ? msg += `one of type ${types[0]} or ${types[1]}.` : msg += `of type ${types[0]}.`;
|
|
36742
|
+
return actual == null ? msg += ` Received ${actual}` : typeof actual == "function" && actual.name ? msg += ` Received function ${actual.name}` : typeof actual == "object" && actual != null && actual.constructor?.name && (msg += ` Received an instance of ${actual.constructor.name}`), msg;
|
|
36743
|
+
}
|
|
36744
|
+
function invalidKeyType(alg, actual, secret) {
|
|
36745
|
+
const types = ["CryptoKey", "KeyObject", "JSON Web Key"];
|
|
36746
|
+
return secret && types.push("Uint8Array"), new TypeError(message(`Key for the ${alg} algorithm must be `, actual, ...types));
|
|
36747
|
+
}
|
|
36748
|
+
function checkUsage(key, usage) {
|
|
36749
|
+
if (usage && !key.usages.includes(usage))
|
|
36750
|
+
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
36751
|
+
}
|
|
36752
|
+
function checkModulusLength(alg, key) {
|
|
36753
|
+
const { modulusLength } = key.algorithm;
|
|
36754
|
+
if (typeof modulusLength != "number" || modulusLength < 2048)
|
|
36755
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
36756
|
+
}
|
|
36757
|
+
function checkCryptoKey(key, expected, usage) {
|
|
36758
|
+
const algorithm = key.algorithm;
|
|
36759
|
+
if (algorithm.name !== expected.name)
|
|
36760
|
+
throw unusable(expected.name);
|
|
36761
|
+
if (expected.hash && algorithm.hash?.name !== expected.hash)
|
|
36762
|
+
throw unusable(expected.hash, "algorithm.hash");
|
|
36763
|
+
if (expected.namedCurve && algorithm.namedCurve !== expected.namedCurve)
|
|
36764
|
+
throw unusable(expected.namedCurve, "algorithm.namedCurve");
|
|
36765
|
+
if (expected.length !== void 0 && algorithm.length !== expected.length)
|
|
36766
|
+
throw unusable(expected.length, "algorithm.length");
|
|
36767
|
+
checkUsage(key, usage);
|
|
36768
|
+
}
|
|
36939
36769
|
function snapshotJwk(jwk) {
|
|
36940
36770
|
return { __proto__: null, ...jwk };
|
|
36941
36771
|
}
|
|
36942
36772
|
function normalizeJwk(jwk) {
|
|
36943
36773
|
const normalized = snapshotJwk(jwk);
|
|
36944
|
-
if (normalized.ext !== void 0 && typeof normalized.ext
|
|
36774
|
+
if (normalized.ext !== void 0 && typeof normalized.ext != "boolean")
|
|
36945
36775
|
throw new TypeError('"ext" (Extractable) Parameter must be a boolean');
|
|
36946
|
-
}
|
|
36947
36776
|
if (normalized.key_ops !== void 0) {
|
|
36948
|
-
const value = normalized.key_ops;
|
|
36949
|
-
|
|
36950
|
-
if (!keyOps || keyOps.some((operation) => typeof operation !== "string") || new Set(keyOps).size !== keyOps.length) {
|
|
36777
|
+
const value = normalized.key_ops, keyOps = Array.isArray(value) ? [...value] : void 0;
|
|
36778
|
+
if (!keyOps || keyOps.some((operation) => typeof operation != "string") || new Set(keyOps).size !== keyOps.length)
|
|
36951
36779
|
throw new TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');
|
|
36952
|
-
}
|
|
36953
36780
|
normalized.key_ops = keyOps;
|
|
36954
36781
|
}
|
|
36955
36782
|
return normalized;
|
|
36956
36783
|
}
|
|
36957
|
-
|
|
36958
|
-
"
|
|
36959
|
-
|
|
36960
|
-
|
|
36961
|
-
|
|
36962
|
-
// ../node_modules/jose/dist/webapi/lib/key.js
|
|
36963
|
-
function checkKeyType(entry, key, usage) {
|
|
36964
|
-
const { alg, secret } = entry;
|
|
36965
|
-
const privateKey = usage === "decrypt" || usage === "sign";
|
|
36966
|
-
if (secret && key instanceof Uint8Array)
|
|
36967
|
-
return [BYTES, key];
|
|
36968
|
-
if (isObject(key)) {
|
|
36969
|
-
const normalized = normalizeJwk(key);
|
|
36970
|
-
if (typeof normalized.kty !== "string") {
|
|
36971
|
-
throw new TypeError(secret ? withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array") : withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
36972
|
-
}
|
|
36973
|
-
const valid = secret ? normalized.kty === "oct" && typeof normalized.k === "string" : normalized.kty !== "oct" && (privateKey ? normalized.kty === "AKP" && typeof normalized.priv === "string" || typeof normalized.d === "string" : normalized.d === void 0 && normalized.priv === void 0);
|
|
36974
|
-
if (!valid) {
|
|
36975
|
-
throw new TypeError(secret ? `JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present` : `JSON Web Key for this operation must be a ${privateKey ? "private" : "public"} JWK`);
|
|
36976
|
-
}
|
|
36977
|
-
jwkMatchesOp(entry, normalized, usage);
|
|
36978
|
-
return [JWK, key, normalized];
|
|
36979
|
-
}
|
|
36980
|
-
if (!isKeyLike(key)) {
|
|
36981
|
-
throw new TypeError(secret ? withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array") : withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
36982
|
-
}
|
|
36983
|
-
if (secret) {
|
|
36984
|
-
if (key.type !== "secret") {
|
|
36985
|
-
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
36986
|
-
}
|
|
36987
|
-
} else {
|
|
36988
|
-
if (key.type === "secret") {
|
|
36989
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
36990
|
-
}
|
|
36991
|
-
const expectedType = privateKey ? "private" : "public";
|
|
36992
|
-
if ((key.type === "public" || key.type === "private") && key.type !== expectedType) {
|
|
36993
|
-
const operation = usage === "sign" ? "signing" : usage === "verify" ? "verifying" : `${usage.slice(0, -1)}tion`;
|
|
36994
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm ${operation} must be of type "${expectedType}"`);
|
|
36995
|
-
}
|
|
36996
|
-
}
|
|
36997
|
-
return isCryptoKey(key) ? [CRYPTO, key] : [KEYOBJECT, key];
|
|
36784
|
+
function validateExtractableOption(extractable) {
|
|
36785
|
+
if (extractable !== void 0 && typeof extractable != "boolean")
|
|
36786
|
+
throw new TypeError('"extractable" option must be a boolean');
|
|
36787
|
+
return extractable;
|
|
36998
36788
|
}
|
|
36999
|
-
function
|
|
37000
|
-
|
|
37001
|
-
|
|
37002
|
-
|
|
37003
|
-
|
|
37004
|
-
entry[alg] = value;
|
|
37005
|
-
} else {
|
|
37006
|
-
cache.set(key, { [alg]: value });
|
|
37007
|
-
}
|
|
37008
|
-
}
|
|
37009
|
-
return value ?? entry?.[alg];
|
|
36789
|
+
async function jwkToKey(entry, jwk, extractable) {
|
|
36790
|
+
if (!entry.kty.includes(jwk.kty))
|
|
36791
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
36792
|
+
const algorithm = entry.resolve?.({ kty: jwk.kty, crv: jwk.crv }) ?? entry.subtle, isPrivate = !!(jwk.d || jwk.priv), keyData = { ...jwk, ext: extractable ?? jwk.ext };
|
|
36793
|
+
return keyData.kty !== "AKP" && delete keyData.alg, delete keyData.use, crypto.subtle.importKey("jwk", keyData, algorithm, keyData.ext ?? !isPrivate, jwk.key_ops ?? entry.usages[isPrivate ? 1 : 0]);
|
|
37010
36794
|
}
|
|
37011
|
-
async function
|
|
37012
|
-
|
|
37013
|
-
switch (tagged[0]) {
|
|
37014
|
-
case BYTES:
|
|
37015
|
-
case CRYPTO:
|
|
37016
|
-
return tagged[1];
|
|
37017
|
-
case JWK: {
|
|
37018
|
-
const key2 = tagged[1];
|
|
37019
|
-
const normalized = tagged[2];
|
|
37020
|
-
if (normalized.kty === "oct") {
|
|
37021
|
-
return decode(normalized.k);
|
|
37022
|
-
}
|
|
37023
|
-
if (!Object.isFrozen(key2)) {
|
|
37024
|
-
const { key_ops } = key2;
|
|
37025
|
-
if (Array.isArray(key_ops))
|
|
37026
|
-
Object.freeze(key_ops);
|
|
37027
|
-
Object.freeze(key2);
|
|
37028
|
-
}
|
|
37029
|
-
return handleJWK(key2, normalized, entry);
|
|
37030
|
-
}
|
|
37031
|
-
case KEYOBJECT: {
|
|
37032
|
-
const keyObject = tagged[1];
|
|
37033
|
-
if (keyObject.type === "secret") {
|
|
37034
|
-
return keyObject.export();
|
|
37035
|
-
}
|
|
37036
|
-
if ("toCryptoKey" in keyObject && typeof keyObject.toCryptoKey === "function") {
|
|
37037
|
-
return handleKeyObject(keyObject, entry);
|
|
37038
|
-
}
|
|
37039
|
-
return handleJWK(keyObject, keyObject.export({ format: "jwk" }), entry);
|
|
37040
|
-
}
|
|
37041
|
-
}
|
|
36795
|
+
async function rawKey(key, expected, usage, extractable = false) {
|
|
36796
|
+
return key instanceof Uint8Array && (key = await crypto.subtle.importKey("raw", key, expected, extractable, [usage])), checkCryptoKey(key, expected, usage), key;
|
|
37042
36797
|
}
|
|
37043
|
-
var tag, jwkMatchesOp,
|
|
36798
|
+
var tag, jwkMatchesOp, cache, nist, isCryptoKey, isKeyObject, isKeyLike, invalidKeyInput, unusable;
|
|
37044
36799
|
var init_key = __esm({
|
|
37045
36800
|
"../node_modules/jose/dist/webapi/lib/key.js"() {
|
|
37046
|
-
|
|
37047
|
-
init_is_key_like();
|
|
37048
|
-
init_type_checks();
|
|
36801
|
+
init_validate2();
|
|
37049
36802
|
init_base64url();
|
|
37050
|
-
|
|
37051
|
-
init_jwk_metadata();
|
|
36803
|
+
init_errors();
|
|
37052
36804
|
tag = (key) => key[Symbol.toStringTag];
|
|
37053
36805
|
jwkMatchesOp = (entry, key, usage) => {
|
|
37054
36806
|
const { alg } = entry;
|
|
37055
36807
|
if (key.use !== void 0) {
|
|
37056
36808
|
const expected = usage === "sign" || usage === "verify" ? "sig" : "enc";
|
|
37057
|
-
if (key.use !== expected)
|
|
36809
|
+
if (key.use !== expected)
|
|
37058
36810
|
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
37059
|
-
}
|
|
37060
36811
|
}
|
|
37061
|
-
if (key.alg !== void 0 && key.alg !== alg)
|
|
36812
|
+
if (key.alg !== void 0 && key.alg !== alg)
|
|
37062
36813
|
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
37063
|
-
}
|
|
37064
36814
|
if (Array.isArray(key.key_ops)) {
|
|
37065
36815
|
const expectedKeyOp = usage === "encrypt" || usage === "decrypt" ? entry.ops?.[usage === "encrypt" ? 0 : 1] : usage;
|
|
37066
|
-
if (expectedKeyOp && !key.key_ops.includes(expectedKeyOp))
|
|
36816
|
+
if (expectedKeyOp && !key.key_ops.includes(expectedKeyOp))
|
|
37067
36817
|
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
37068
|
-
}
|
|
37069
36818
|
}
|
|
37070
36819
|
};
|
|
37071
|
-
BYTES = 0;
|
|
37072
|
-
CRYPTO = 1;
|
|
37073
|
-
KEYOBJECT = 2;
|
|
37074
|
-
JWK = 3;
|
|
37075
36820
|
nist = {
|
|
37076
36821
|
__proto__: null,
|
|
37077
36822
|
prime256v1: "P-256",
|
|
37078
36823
|
secp384r1: "P-384",
|
|
37079
36824
|
secp521r1: "P-521"
|
|
37080
36825
|
};
|
|
37081
|
-
|
|
37082
|
-
|
|
37083
|
-
|
|
37084
|
-
|
|
37085
|
-
return
|
|
37086
|
-
|
|
37087
|
-
|
|
37088
|
-
|
|
37089
|
-
const crv = nist[keyObject.asymmetricKeyDetails?.namedCurve];
|
|
37090
|
-
const params = entry.resolve?.({ crv, asymmetricKeyType }) ?? entry.subtle;
|
|
37091
|
-
return cached(keyObject, entry.alg, keyObject.toCryptoKey(params, isPublic, usages));
|
|
36826
|
+
isCryptoKey = (key) => {
|
|
36827
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
36828
|
+
return true;
|
|
36829
|
+
try {
|
|
36830
|
+
return key instanceof CryptoKey;
|
|
36831
|
+
} catch {
|
|
36832
|
+
return false;
|
|
36833
|
+
}
|
|
37092
36834
|
};
|
|
36835
|
+
isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
36836
|
+
isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
36837
|
+
invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
36838
|
+
unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
36839
|
+
}
|
|
36840
|
+
});
|
|
36841
|
+
|
|
36842
|
+
// ../node_modules/jose/dist/webapi/lib/content_encryption.js
|
|
36843
|
+
function checkCekLength(cek, expected) {
|
|
36844
|
+
const actual = cek.byteLength << 3;
|
|
36845
|
+
if (actual !== expected)
|
|
36846
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
36847
|
+
}
|
|
36848
|
+
function checkIvLength(enc, iv) {
|
|
36849
|
+
if (iv.length << 3 !== enc.ivBits)
|
|
36850
|
+
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
36851
|
+
}
|
|
36852
|
+
async function cbcKeySetup(enc, cek, usage) {
|
|
36853
|
+
if (!(cek instanceof Uint8Array))
|
|
36854
|
+
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
36855
|
+
const keySize = enc.cekBits >> 1, encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, [usage]), macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
36856
|
+
hash: `SHA-${keySize << 1}`,
|
|
36857
|
+
name: "HMAC"
|
|
36858
|
+
}, false, ["sign"]);
|
|
36859
|
+
return [encKey, macKey, keySize];
|
|
36860
|
+
}
|
|
36861
|
+
async function cbcHmacTag(macKey, macData, keySize) {
|
|
36862
|
+
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
36863
|
+
}
|
|
36864
|
+
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
36865
|
+
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "encrypt"), ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
36866
|
+
iv,
|
|
36867
|
+
name: "AES-CBC"
|
|
36868
|
+
}, encKey, plaintext)), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), tag2 = await cbcHmacTag(macKey, macData, keySize);
|
|
36869
|
+
return { ciphertext, tag: tag2, iv };
|
|
36870
|
+
}
|
|
36871
|
+
async function timingSafeEqual(a, b) {
|
|
36872
|
+
const algorithm = { name: "HMAC", hash: "SHA-256" }, key = await crypto.subtle.generateKey(algorithm, false, ["sign", "verify"]), aHmac = await crypto.subtle.sign(algorithm, key, a);
|
|
36873
|
+
return crypto.subtle.verify(algorithm, key, aHmac, b);
|
|
36874
|
+
}
|
|
36875
|
+
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
36876
|
+
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "decrypt"), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), expectedTag = await cbcHmacTag(macKey, macData, keySize);
|
|
36877
|
+
try {
|
|
36878
|
+
if (await timingSafeEqual(tag2, expectedTag))
|
|
36879
|
+
return new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
36880
|
+
} catch {
|
|
36881
|
+
}
|
|
36882
|
+
throw new JWEDecryptionFailed();
|
|
36883
|
+
}
|
|
36884
|
+
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
36885
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array))
|
|
36886
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
36887
|
+
if (iv ? checkIvLength(enc, iv) : iv = generateIv(enc), cek instanceof Uint8Array && checkCekLength(cek, enc.cekBits), enc.cbc)
|
|
36888
|
+
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
36889
|
+
const encKey = await rawKey(cek, enc.subtle, "encrypt"), encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
36890
|
+
additionalData: aad,
|
|
36891
|
+
iv,
|
|
36892
|
+
name: "AES-GCM",
|
|
36893
|
+
tagLength: 128
|
|
36894
|
+
}, encKey, plaintext));
|
|
36895
|
+
return { ciphertext: encrypted.subarray(0, -16), tag: encrypted.subarray(-16), iv };
|
|
36896
|
+
}
|
|
36897
|
+
async function decrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
36898
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array))
|
|
36899
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
36900
|
+
if (!iv)
|
|
36901
|
+
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
36902
|
+
if (!tag2)
|
|
36903
|
+
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
36904
|
+
if (!enc.cbc && tag2.length !== 16)
|
|
36905
|
+
throw new JWEInvalid("Invalid Authentication Tag length");
|
|
36906
|
+
if (checkIvLength(enc, iv), cek instanceof Uint8Array && checkCekLength(cek, enc.cekBits), enc.cbc)
|
|
36907
|
+
return cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
36908
|
+
const encKey = await rawKey(cek, enc.subtle, "decrypt");
|
|
36909
|
+
try {
|
|
36910
|
+
return new Uint8Array(await crypto.subtle.decrypt({
|
|
36911
|
+
additionalData: aad,
|
|
36912
|
+
iv,
|
|
36913
|
+
name: "AES-GCM",
|
|
36914
|
+
tagLength: 128
|
|
36915
|
+
}, encKey, concat(ciphertext, tag2)));
|
|
36916
|
+
} catch {
|
|
36917
|
+
throw new JWEDecryptionFailed();
|
|
36918
|
+
}
|
|
36919
|
+
}
|
|
36920
|
+
var generateCek, generateIv;
|
|
36921
|
+
var init_content_encryption = __esm({
|
|
36922
|
+
"../node_modules/jose/dist/webapi/lib/content_encryption.js"() {
|
|
36923
|
+
init_buffer_utils();
|
|
36924
|
+
init_key();
|
|
36925
|
+
init_errors();
|
|
36926
|
+
generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
|
|
36927
|
+
generateIv = (enc) => crypto.getRandomValues(new Uint8Array(enc.ivBits >> 3));
|
|
37093
36928
|
}
|
|
37094
36929
|
});
|
|
37095
36930
|
|
|
37096
36931
|
// ../node_modules/jose/dist/webapi/lib/key_descriptor.js
|
|
37097
36932
|
function table(entries) {
|
|
37098
36933
|
const out = { __proto__: null };
|
|
37099
|
-
for (const alg in entries)
|
|
36934
|
+
for (const alg in entries)
|
|
37100
36935
|
out[alg] = { ...entries[alg], alg };
|
|
37101
|
-
}
|
|
37102
36936
|
return out;
|
|
37103
36937
|
}
|
|
37104
36938
|
var init_key_descriptor = __esm({
|
|
@@ -37110,22 +36944,22 @@ return true;`);
|
|
|
37110
36944
|
function rsaes(bits) {
|
|
37111
36945
|
return {
|
|
37112
36946
|
kty: ["RSA"],
|
|
36947
|
+
mode: "key-encryption",
|
|
37113
36948
|
subtle: { name: "RSA-OAEP", hash: `SHA-${bits}` },
|
|
37114
36949
|
usages: wrap,
|
|
37115
36950
|
ops: ["wrapKey", "unwrapKey"]
|
|
37116
36951
|
};
|
|
37117
36952
|
}
|
|
37118
|
-
function ecdh() {
|
|
36953
|
+
function ecdh(mode) {
|
|
37119
36954
|
return {
|
|
37120
36955
|
kty: ["EC", "OKP"],
|
|
36956
|
+
mode,
|
|
37121
36957
|
subtle: { name: "ECDH" },
|
|
37122
36958
|
resolve: ({ kty, crv, asymmetricKeyType }) => {
|
|
37123
|
-
if (crv === "X25519" || asymmetricKeyType === "x25519")
|
|
36959
|
+
if (crv === "X25519" || asymmetricKeyType === "x25519")
|
|
37124
36960
|
return { name: "X25519" };
|
|
37125
|
-
|
|
37126
|
-
if (kty === "OKP") {
|
|
36961
|
+
if (kty === "OKP")
|
|
37127
36962
|
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
37128
|
-
}
|
|
37129
36963
|
return { name: "ECDH", namedCurve: crv };
|
|
37130
36964
|
},
|
|
37131
36965
|
usages: derive,
|
|
@@ -37135,6 +36969,7 @@ return true;`);
|
|
|
37135
36969
|
function aeskw(bits, gcm = false) {
|
|
37136
36970
|
return {
|
|
37137
36971
|
kty: ["oct"],
|
|
36972
|
+
mode: "key-wrapping",
|
|
37138
36973
|
secret: true,
|
|
37139
36974
|
subtle: { name: gcm ? "AES-GCM" : "AES-KW", length: bits },
|
|
37140
36975
|
usages: none,
|
|
@@ -37144,6 +36979,7 @@ return true;`);
|
|
|
37144
36979
|
function pbes2() {
|
|
37145
36980
|
return {
|
|
37146
36981
|
kty: ["oct"],
|
|
36982
|
+
mode: "key-wrapping",
|
|
37147
36983
|
secret: true,
|
|
37148
36984
|
subtle: { name: "PBKDF2" },
|
|
37149
36985
|
usages: none,
|
|
@@ -37166,10 +37002,13 @@ return true;`);
|
|
|
37166
37002
|
throw new JOSENotSupported(`Invalid or unsupported "${parameter}" (JWE ${name}) header value`);
|
|
37167
37003
|
}
|
|
37168
37004
|
function jweAlgorithm(alg) {
|
|
37169
|
-
return (typeof alg
|
|
37005
|
+
return (typeof alg == "string" ? JWE[alg] : void 0) ?? unsupported("alg", "Algorithm");
|
|
37006
|
+
}
|
|
37007
|
+
function isJWECEKTransport(algorithm) {
|
|
37008
|
+
return algorithm.mode === "key-wrapping" || algorithm.mode === "key-encryption" || algorithm.mode === "key-agreement-with-key-wrapping";
|
|
37170
37009
|
}
|
|
37171
37010
|
function jweEncryption(enc) {
|
|
37172
|
-
return (typeof enc
|
|
37011
|
+
return (typeof enc == "string" ? ENC[enc] : void 0) ?? unsupported("enc", "Encryption Algorithm");
|
|
37173
37012
|
}
|
|
37174
37013
|
var wrap, derive, none, JWE, contentOps, ENC;
|
|
37175
37014
|
var init_jwe_algorithms = __esm({
|
|
@@ -37185,6 +37024,7 @@ return true;`);
|
|
|
37185
37024
|
JWE = table({
|
|
37186
37025
|
dir: {
|
|
37187
37026
|
kty: ["oct"],
|
|
37027
|
+
mode: "direct-encryption",
|
|
37188
37028
|
secret: true,
|
|
37189
37029
|
subtle: { name: "AES-GCM" },
|
|
37190
37030
|
usages: none,
|
|
@@ -37194,10 +37034,10 @@ return true;`);
|
|
|
37194
37034
|
"RSA-OAEP-256": rsaes(256),
|
|
37195
37035
|
"RSA-OAEP-384": rsaes(384),
|
|
37196
37036
|
"RSA-OAEP-512": rsaes(512),
|
|
37197
|
-
"ECDH-ES": ecdh(),
|
|
37198
|
-
"ECDH-ES+A128KW": ecdh(),
|
|
37199
|
-
"ECDH-ES+A192KW": ecdh(),
|
|
37200
|
-
"ECDH-ES+A256KW": ecdh(),
|
|
37037
|
+
"ECDH-ES": ecdh("direct-key-agreement"),
|
|
37038
|
+
"ECDH-ES+A128KW": ecdh("key-agreement-with-key-wrapping"),
|
|
37039
|
+
"ECDH-ES+A192KW": ecdh("key-agreement-with-key-wrapping"),
|
|
37040
|
+
"ECDH-ES+A256KW": ecdh("key-agreement-with-key-wrapping"),
|
|
37201
37041
|
A128KW: aeskw(128),
|
|
37202
37042
|
A192KW: aeskw(192),
|
|
37203
37043
|
A256KW: aeskw(256),
|
|
@@ -37222,68 +37062,39 @@ return true;`);
|
|
|
37222
37062
|
|
|
37223
37063
|
// ../node_modules/jose/dist/webapi/lib/key_management.js
|
|
37224
37064
|
function checkEcdhCryptoKey(key, usage) {
|
|
37225
|
-
if (key.algorithm.name !== "ECDH" && key.algorithm.name !== "X25519")
|
|
37065
|
+
if (key.algorithm.name !== "ECDH" && key.algorithm.name !== "X25519")
|
|
37226
37066
|
throw new TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");
|
|
37227
|
-
}
|
|
37228
37067
|
checkUsage(key, usage);
|
|
37229
37068
|
}
|
|
37230
|
-
async function aeskwCryptoKey(key, alg, usage) {
|
|
37231
|
-
const expected = jweAlgorithm(alg).subtle;
|
|
37232
|
-
const cryptoKey = key instanceof Uint8Array ? await crypto.subtle.importKey("raw", key, "AES-KW", true, [
|
|
37233
|
-
usage
|
|
37234
|
-
]) : key;
|
|
37235
|
-
checkCryptoKey(cryptoKey, expected, usage);
|
|
37236
|
-
return cryptoKey;
|
|
37237
|
-
}
|
|
37238
37069
|
async function aeskwWrap(alg, key, cek) {
|
|
37239
|
-
const cryptoKey = await
|
|
37240
|
-
const cryptoKeyCek = await crypto.subtle.importKey("raw", cek, { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
37070
|
+
const cryptoKey = await rawKey(key, jweAlgorithm(alg).subtle, "wrapKey", true), cryptoKeyCek = await crypto.subtle.importKey("raw", cek, { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
37241
37071
|
return new Uint8Array(await crypto.subtle.wrapKey("raw", cryptoKeyCek, cryptoKey, "AES-KW"));
|
|
37242
37072
|
}
|
|
37243
37073
|
async function aeskwUnwrap(alg, key, encryptedKey) {
|
|
37244
|
-
const cryptoKey = await
|
|
37245
|
-
const cryptoKeyCek = await crypto.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
37074
|
+
const cryptoKey = await rawKey(key, jweAlgorithm(alg).subtle, "unwrapKey", true), cryptoKeyCek = await crypto.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
37246
37075
|
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
37247
37076
|
}
|
|
37248
37077
|
function checkRsaKey(alg, key, usage) {
|
|
37249
|
-
checkCryptoKey(key, jweAlgorithm(alg).subtle, usage);
|
|
37250
|
-
checkModulusLength(alg, key);
|
|
37251
|
-
}
|
|
37252
|
-
function pbes2CryptoKey(key, alg) {
|
|
37253
|
-
if (key instanceof Uint8Array) {
|
|
37254
|
-
return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
|
|
37255
|
-
"deriveBits"
|
|
37256
|
-
]);
|
|
37257
|
-
}
|
|
37258
|
-
checkCryptoKey(key, jweAlgorithm(alg).subtle, "deriveBits");
|
|
37259
|
-
return key;
|
|
37078
|
+
checkCryptoKey(key, jweAlgorithm(alg).subtle, usage), checkModulusLength(alg, key);
|
|
37260
37079
|
}
|
|
37261
37080
|
async function deriveKey(p2s, alg, p2c, key) {
|
|
37262
|
-
if (!(p2s instanceof Uint8Array) || p2s.length < 8)
|
|
37081
|
+
if (!(p2s instanceof Uint8Array) || p2s.length < 8)
|
|
37263
37082
|
throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
|
|
37264
|
-
|
|
37265
|
-
if (!Number.isSafeInteger(p2c) || Math.sign(p2c) !== 1) {
|
|
37083
|
+
if (!Number.isSafeInteger(p2c) || Math.sign(p2c) !== 1)
|
|
37266
37084
|
throw new JWEInvalid("PBES2 Count Input must be a positive integer");
|
|
37267
|
-
|
|
37268
|
-
const salt = concat(encode(alg), Uint8Array.of(0), p2s);
|
|
37269
|
-
const keylen = parseInt(alg.slice(13, 16), 10);
|
|
37270
|
-
const subtleAlg = {
|
|
37085
|
+
const salt = concat(encode(alg), Uint8Array.of(0), p2s), keylen = parseInt(alg.slice(13, 16), 10), subtleAlg = {
|
|
37271
37086
|
hash: `SHA-${alg.slice(8, 11)}`,
|
|
37272
37087
|
iterations: p2c,
|
|
37273
37088
|
name: "PBKDF2",
|
|
37274
37089
|
salt
|
|
37275
|
-
};
|
|
37276
|
-
const cryptoKey = await pbes2CryptoKey(key, alg);
|
|
37090
|
+
}, cryptoKey = await rawKey(key, jweAlgorithm(alg).subtle, "deriveBits");
|
|
37277
37091
|
return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
|
|
37278
37092
|
}
|
|
37279
37093
|
function lengthAndInput(input) {
|
|
37280
37094
|
return concat(uint32be(input.length), input);
|
|
37281
37095
|
}
|
|
37282
37096
|
async function concatKdf(Z, L, OtherInfo) {
|
|
37283
|
-
const dkLen = L >> 3;
|
|
37284
|
-
const hashLen = 32;
|
|
37285
|
-
const reps = Math.ceil(dkLen / hashLen);
|
|
37286
|
-
const dk = new Uint8Array(reps * hashLen);
|
|
37097
|
+
const dkLen = L >> 3, hashLen = 32, reps = Math.ceil(dkLen / hashLen), dk = new Uint8Array(reps * hashLen);
|
|
37287
37098
|
for (let i = 1; i <= reps; i++) {
|
|
37288
37099
|
const hashResult = await digest("sha256", concat(uint32be(i), Z, OtherInfo));
|
|
37289
37100
|
dk.set(hashResult, (i - 1) * hashLen);
|
|
@@ -37291,10 +37102,8 @@ return true;`);
|
|
|
37291
37102
|
return dk.slice(0, dkLen);
|
|
37292
37103
|
}
|
|
37293
37104
|
async function ecdhesDeriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
|
|
37294
|
-
checkEcdhCryptoKey(publicKey);
|
|
37295
|
-
|
|
37296
|
-
const otherInfo = concat(lengthAndInput(encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
|
|
37297
|
-
const Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
37105
|
+
checkEcdhCryptoKey(publicKey), checkEcdhCryptoKey(privateKey, "deriveBits");
|
|
37106
|
+
const otherInfo = concat(lengthAndInput(encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength)), Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
37298
37107
|
name: publicKey.algorithm.name,
|
|
37299
37108
|
public: publicKey
|
|
37300
37109
|
}, privateKey, publicKey.algorithm.name === "X25519" ? 256 : Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3));
|
|
@@ -37303,8 +37112,23 @@ return true;`);
|
|
|
37303
37112
|
function assertEcdhKey(key) {
|
|
37304
37113
|
assertCryptoKey(key);
|
|
37305
37114
|
const curve = key.algorithm.namedCurve;
|
|
37306
|
-
if (curve !== "P-256" && curve !== "P-384" && curve !== "P-521" && key.algorithm.name !== "X25519")
|
|
37115
|
+
if (curve !== "P-256" && curve !== "P-384" && curve !== "P-521" && key.algorithm.name !== "X25519")
|
|
37307
37116
|
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
37117
|
+
}
|
|
37118
|
+
function partyInfo(joseHeader, name) {
|
|
37119
|
+
const value = joseHeader[name];
|
|
37120
|
+
if (value !== void 0) {
|
|
37121
|
+
if (typeof value != "string")
|
|
37122
|
+
throw new JWEInvalid(`JOSE Header "${name}" (Agreement Party${name === "apu" ? "U" : "V"}Info) invalid`);
|
|
37123
|
+
return decodeBase64url(value, name, JWEInvalid);
|
|
37124
|
+
}
|
|
37125
|
+
}
|
|
37126
|
+
function checkPartyInfo(apu, apv) {
|
|
37127
|
+
if (!(apu === void 0 || apv === void 0 || apu.byteLength !== apv.byteLength)) {
|
|
37128
|
+
for (let i = 0; i < apu.byteLength; i++)
|
|
37129
|
+
if (apu[i] !== apv[i])
|
|
37130
|
+
return;
|
|
37131
|
+
throw new JWEInvalid('JOSE Header "apu" and "apv" values must be distinct');
|
|
37308
37132
|
}
|
|
37309
37133
|
}
|
|
37310
37134
|
function assertEncryptedKey(encryptedKey) {
|
|
@@ -37315,300 +37139,158 @@ return true;`);
|
|
|
37315
37139
|
if (encryptedKey !== void 0)
|
|
37316
37140
|
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
37317
37141
|
}
|
|
37318
|
-
|
|
37319
|
-
|
|
37320
|
-
|
|
37321
|
-
|
|
37322
|
-
|
|
37323
|
-
}
|
|
37324
|
-
|
|
37142
|
+
function validateMaxPBES2Count(value) {
|
|
37143
|
+
if (value !== void 0 && value !== 1 / 0 && (!Number.isSafeInteger(value) || value < 1))
|
|
37144
|
+
throw new TypeError("maxPBES2Count must be a positive safe integer or Infinity");
|
|
37145
|
+
}
|
|
37146
|
+
async function decryptKeyManagement(entry, enc, key, encryptedKey, joseHeader, maxPBES2Count) {
|
|
37147
|
+
const { alg } = entry, mode = entry.mode;
|
|
37148
|
+
if (mode === "direct-encryption")
|
|
37149
|
+
return assertNoEncryptedKey(encryptedKey), key;
|
|
37150
|
+
const direct = mode === "direct-key-agreement";
|
|
37151
|
+
switch (direct ? assertNoEncryptedKey(encryptedKey) : assertEncryptedKey(encryptedKey), entry.subtle.name) {
|
|
37325
37152
|
case "ECDH": {
|
|
37326
|
-
|
|
37327
|
-
|
|
37328
|
-
|
|
37329
|
-
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
37153
|
+
const { epk } = joseHeader;
|
|
37154
|
+
if (!isObject(epk) || ["d", "k", "p", "q", "dp", "dq", "qi", "oth", "priv"].some((parameter) => Object.hasOwn(epk, parameter)))
|
|
37155
|
+
throw new JWEInvalid('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');
|
|
37330
37156
|
assertEcdhKey(key);
|
|
37331
|
-
const
|
|
37332
|
-
|
|
37333
|
-
|
|
37334
|
-
if (
|
|
37335
|
-
if (typeof joseHeader.apu !== "string")
|
|
37336
|
-
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
37337
|
-
partyUInfo = decodeBase64url(joseHeader.apu, "apu", JWEInvalid);
|
|
37338
|
-
}
|
|
37339
|
-
if (joseHeader.apv !== void 0) {
|
|
37340
|
-
if (typeof joseHeader.apv !== "string")
|
|
37341
|
-
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
37342
|
-
partyVInfo = decodeBase64url(joseHeader.apv, "apv", JWEInvalid);
|
|
37343
|
-
}
|
|
37344
|
-
const sharedSecret = await ecdhesDeriveKey(epk, key, alg === "ECDH-ES" ? enc.alg : alg, alg === "ECDH-ES" ? enc.cekBits : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
37345
|
-
if (alg === "ECDH-ES")
|
|
37157
|
+
const ephemeralPublicKey = await jwkToKey(entry, epk), partyUInfo = partyInfo(joseHeader, "apu"), partyVInfo = partyInfo(joseHeader, "apv");
|
|
37158
|
+
checkPartyInfo(partyUInfo, partyVInfo);
|
|
37159
|
+
const sharedSecret = await ecdhesDeriveKey(ephemeralPublicKey, key, direct ? enc.alg : alg, direct ? enc.cekBits : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
37160
|
+
if (direct)
|
|
37346
37161
|
return sharedSecret;
|
|
37347
|
-
|
|
37348
|
-
|
|
37349
|
-
}
|
|
37350
|
-
case "RSA-OAEP": {
|
|
37351
|
-
assertEncryptedKey(encryptedKey);
|
|
37352
|
-
assertCryptoKey(key);
|
|
37353
|
-
checkRsaKey(alg, key, "decrypt");
|
|
37354
|
-
return new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP", key, encryptedKey));
|
|
37162
|
+
key = sharedSecret;
|
|
37163
|
+
break;
|
|
37355
37164
|
}
|
|
37165
|
+
case "RSA-OAEP":
|
|
37166
|
+
return assertCryptoKey(key), checkRsaKey(alg, key, "decrypt"), new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP", key, encryptedKey));
|
|
37356
37167
|
case "PBKDF2": {
|
|
37357
|
-
|
|
37358
|
-
|
|
37359
|
-
|
|
37360
|
-
const p2cLimit = maxPBES2Count
|
|
37168
|
+
if (typeof joseHeader.p2c != "number")
|
|
37169
|
+
throw new JWEInvalid('JOSE Header "p2c" (PBES2 Count) missing or invalid');
|
|
37170
|
+
validateMaxPBES2Count(maxPBES2Count);
|
|
37171
|
+
const p2cLimit = maxPBES2Count ?? 1e4;
|
|
37361
37172
|
if (joseHeader.p2c > p2cLimit)
|
|
37362
|
-
throw new JWEInvalid(
|
|
37363
|
-
if (typeof joseHeader.p2s
|
|
37364
|
-
throw new JWEInvalid(
|
|
37173
|
+
throw new JWEInvalid('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');
|
|
37174
|
+
if (typeof joseHeader.p2s != "string")
|
|
37175
|
+
throw new JWEInvalid('JOSE Header "p2s" (PBES2 Salt) missing or invalid');
|
|
37365
37176
|
const p2s = decodeBase64url(joseHeader.p2s, "p2s", JWEInvalid);
|
|
37366
|
-
|
|
37367
|
-
|
|
37368
|
-
}
|
|
37369
|
-
case "AES-KW": {
|
|
37370
|
-
assertEncryptedKey(encryptedKey);
|
|
37371
|
-
return aeskwUnwrap(alg, key, encryptedKey);
|
|
37177
|
+
key = await deriveKey(p2s, alg, joseHeader.p2c, key);
|
|
37178
|
+
break;
|
|
37372
37179
|
}
|
|
37373
37180
|
case "AES-GCM": {
|
|
37374
|
-
|
|
37375
|
-
|
|
37376
|
-
|
|
37377
|
-
|
|
37378
|
-
|
|
37379
|
-
|
|
37380
|
-
|
|
37381
|
-
|
|
37382
|
-
|
|
37181
|
+
if (typeof joseHeader.iv != "string")
|
|
37182
|
+
throw new JWEInvalid('JOSE Header "iv" (Initialization Vector) missing or invalid');
|
|
37183
|
+
if (typeof joseHeader.tag != "string")
|
|
37184
|
+
throw new JWEInvalid('JOSE Header "tag" (Authentication Tag) missing or invalid');
|
|
37185
|
+
const iv = decodeBase64url(joseHeader.iv, "iv", JWEInvalid), tag2 = decodeBase64url(joseHeader.tag, "tag", JWEInvalid);
|
|
37186
|
+
if (iv.byteLength !== 12)
|
|
37187
|
+
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
37188
|
+
if (tag2.byteLength !== 16)
|
|
37189
|
+
throw new JWEInvalid("Invalid Authentication Tag length");
|
|
37383
37190
|
return decrypt(jweEncryption(alg.slice(0, -2)), key, encryptedKey, iv, tag2, new Uint8Array());
|
|
37384
37191
|
}
|
|
37385
37192
|
}
|
|
37193
|
+
return aeskwUnwrap(alg.slice(-6), key, encryptedKey);
|
|
37386
37194
|
}
|
|
37387
|
-
async function encryptKeyManagement(
|
|
37388
|
-
|
|
37389
|
-
|
|
37390
|
-
|
|
37391
|
-
|
|
37392
|
-
if (
|
|
37195
|
+
async function encryptKeyManagement(entry, enc, inputKey, joseHeader, providedCek, providedParameters = {}) {
|
|
37196
|
+
const { alg, mode } = entry, transport = isJWECEKTransport(entry);
|
|
37197
|
+
if (providedCek !== void 0 && !transport)
|
|
37198
|
+
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
37199
|
+
let key = await prepareKey(mode === "direct-encryption" ? enc : entry, inputKey, "encrypt");
|
|
37200
|
+
if (mode === "direct-encryption")
|
|
37393
37201
|
return [key, void 0, void 0];
|
|
37202
|
+
const cek = transport ? providedCek ?? generateCek(enc) : void 0;
|
|
37203
|
+
cek && checkCekLength(cek, enc.cekBits);
|
|
37204
|
+
let encryptedKey, parameters;
|
|
37394
37205
|
switch (entry.subtle.name) {
|
|
37395
37206
|
case "ECDH": {
|
|
37396
37207
|
assertEcdhKey(key);
|
|
37397
|
-
const { apu, apv } = providedParameters;
|
|
37398
|
-
|
|
37399
|
-
|
|
37400
|
-
|
|
37401
|
-
if (apv !== void 0) {
|
|
37402
|
-
assertUint8Array(apv, '"apv"');
|
|
37403
|
-
}
|
|
37208
|
+
const { apu: providedApu, apv: providedApv } = providedParameters;
|
|
37209
|
+
providedApu !== void 0 && assertUint8Array(providedApu, '"apu"'), providedApv !== void 0 && assertUint8Array(providedApv, '"apv"');
|
|
37210
|
+
const apu = providedApu ?? partyInfo(joseHeader, "apu"), apv = providedApv ?? partyInfo(joseHeader, "apv");
|
|
37211
|
+
checkPartyInfo(apu, apv);
|
|
37404
37212
|
let ephemeralKey;
|
|
37405
|
-
|
|
37406
|
-
ephemeralKey = await prepareKey(entry, providedParameters.epk, "decrypt");
|
|
37407
|
-
} else {
|
|
37408
|
-
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
37409
|
-
}
|
|
37213
|
+
providedParameters.epk !== void 0 ? ephemeralKey = await prepareKey(entry, providedParameters.epk, "decrypt") : ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
37410
37214
|
const subtle = crypto.subtle;
|
|
37411
37215
|
let exportableEpk = ephemeralKey;
|
|
37412
37216
|
if (!exportableEpk.extractable) {
|
|
37413
|
-
if (typeof subtle.getPublicKey
|
|
37217
|
+
if (typeof subtle.getPublicKey != "function")
|
|
37414
37218
|
throw new TypeError('CryptoKey for "epk" must be extractable');
|
|
37415
|
-
}
|
|
37416
37219
|
exportableEpk = await subtle.getPublicKey(ephemeralKey, []);
|
|
37417
37220
|
}
|
|
37418
|
-
const { x, y, crv, kty } = await subtle.exportKey("jwk", exportableEpk);
|
|
37419
|
-
|
|
37420
|
-
|
|
37421
|
-
|
|
37422
|
-
parameters.epk.y = y;
|
|
37423
|
-
if (apu)
|
|
37424
|
-
parameters.apu = encode2(apu);
|
|
37425
|
-
if (apv)
|
|
37426
|
-
parameters.apv = encode2(apv);
|
|
37427
|
-
if (alg === "ECDH-ES") {
|
|
37428
|
-
cek = sharedSecret;
|
|
37429
|
-
break;
|
|
37430
|
-
}
|
|
37431
|
-
cek = providedCek || generateCek(enc);
|
|
37432
|
-
const kwAlg = alg.slice(-6);
|
|
37433
|
-
encryptedKey = await aeskwWrap(kwAlg, sharedSecret, cek);
|
|
37221
|
+
const { x, y, crv, kty } = await subtle.exportKey("jwk", exportableEpk), direct = mode === "direct-key-agreement", sharedSecret = await ecdhesDeriveKey(key, ephemeralKey, direct ? enc.alg : alg, direct ? enc.cekBits : parseInt(alg.slice(-5, -2), 10), apu, apv), epk = { x, crv, kty };
|
|
37222
|
+
if (kty === "EC" && (epk.y = y), parameters = { epk }, providedApu !== void 0 && (parameters.apu = encode2(providedApu)), providedApv !== void 0 && (parameters.apv = encode2(providedApv)), direct)
|
|
37223
|
+
return [sharedSecret, void 0, parameters];
|
|
37224
|
+
key = sharedSecret;
|
|
37434
37225
|
break;
|
|
37435
37226
|
}
|
|
37436
37227
|
case "RSA-OAEP": {
|
|
37437
|
-
|
|
37438
|
-
assertCryptoKey(key);
|
|
37439
|
-
checkRsaKey(alg, key, "encrypt");
|
|
37440
|
-
encryptedKey = new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP", key, cek));
|
|
37228
|
+
assertCryptoKey(key), checkRsaKey(alg, key, "encrypt"), encryptedKey = new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP", key, cek));
|
|
37441
37229
|
break;
|
|
37442
37230
|
}
|
|
37443
37231
|
case "PBKDF2": {
|
|
37444
|
-
cek = providedCek || generateCek(enc);
|
|
37445
37232
|
const { p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16)) } = providedParameters;
|
|
37446
|
-
|
|
37447
|
-
encryptedKey = await aeskwWrap(alg.slice(-6), derived, cek);
|
|
37448
|
-
parameters = { p2c, p2s: encode2(p2s) };
|
|
37449
|
-
break;
|
|
37450
|
-
}
|
|
37451
|
-
case "AES-KW": {
|
|
37452
|
-
cek = providedCek || generateCek(enc);
|
|
37453
|
-
encryptedKey = await aeskwWrap(alg, key, cek);
|
|
37233
|
+
key = await deriveKey(p2s, alg, p2c, key), parameters = { p2c, p2s: encode2(p2s) };
|
|
37454
37234
|
break;
|
|
37455
37235
|
}
|
|
37456
37236
|
case "AES-GCM": {
|
|
37457
|
-
|
|
37458
|
-
|
|
37237
|
+
const iv = providedParameters.iv === void 0 ? crypto.getRandomValues(new Uint8Array(12)) : providedParameters.iv;
|
|
37238
|
+
if (!(iv instanceof Uint8Array))
|
|
37239
|
+
throw new TypeError('"iv" must be an instance of Uint8Array');
|
|
37459
37240
|
const wrapped = await encrypt(jweEncryption(alg.slice(0, -2)), cek, key, iv, new Uint8Array());
|
|
37460
|
-
encryptedKey = wrapped.ciphertext;
|
|
37461
|
-
parameters = { iv: encode2(wrapped.iv), tag: encode2(wrapped.tag) };
|
|
37462
|
-
break;
|
|
37241
|
+
encryptedKey = wrapped.ciphertext, parameters = { iv: encode2(wrapped.iv), tag: encode2(wrapped.tag) };
|
|
37463
37242
|
}
|
|
37464
37243
|
}
|
|
37244
|
+
if (encryptedKey ?? (encryptedKey = await aeskwWrap(alg.slice(-6), key, cek)), !(encryptedKey instanceof Uint8Array) || !encryptedKey.byteLength)
|
|
37245
|
+
throw new TypeError("JWE key management algorithm did not produce an Encrypted Key");
|
|
37465
37246
|
return [cek, encryptedKey, parameters];
|
|
37466
37247
|
}
|
|
37467
37248
|
var init_key_management = __esm({
|
|
37468
37249
|
"../node_modules/jose/dist/webapi/lib/key_management.js"() {
|
|
37469
37250
|
init_base64url();
|
|
37470
37251
|
init_key();
|
|
37471
|
-
init_jwk_to_key();
|
|
37472
37252
|
init_jwe_algorithms();
|
|
37473
37253
|
init_errors();
|
|
37474
|
-
|
|
37475
|
-
init_content_encryption();
|
|
37476
|
-
init_type_checks();
|
|
37477
|
-
init_crypto_key();
|
|
37254
|
+
init_validate2();
|
|
37478
37255
|
init_buffer_utils();
|
|
37479
|
-
|
|
37480
|
-
}
|
|
37481
|
-
});
|
|
37482
|
-
|
|
37483
|
-
// ../node_modules/jose/dist/webapi/lib/options.js
|
|
37484
|
-
function validateAlgorithms(option, algorithms) {
|
|
37485
|
-
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
37486
|
-
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
37487
|
-
}
|
|
37488
|
-
if (!algorithms) {
|
|
37489
|
-
return void 0;
|
|
37490
|
-
}
|
|
37491
|
-
return new Set(algorithms);
|
|
37492
|
-
}
|
|
37493
|
-
function validateCritDuplicates(Err, protectedHeader) {
|
|
37494
|
-
const { crit } = protectedHeader ?? {};
|
|
37495
|
-
if (Array.isArray(crit) && new Set(crit).size !== crit.length) {
|
|
37496
|
-
throw new Err('"crit" (Critical) Header Parameter MUST NOT contain duplicate values');
|
|
37497
|
-
}
|
|
37498
|
-
}
|
|
37499
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
37500
|
-
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
37501
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
37502
|
-
}
|
|
37503
|
-
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
37504
|
-
return [];
|
|
37505
|
-
}
|
|
37506
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
37507
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
37508
|
-
}
|
|
37509
|
-
const recognized = recognizedOption === void 0 ? recognizedDefault : { __proto__: null, ...recognizedOption, ...recognizedDefault };
|
|
37510
|
-
for (const parameter of protectedHeader.crit) {
|
|
37511
|
-
if (!(parameter in recognized)) {
|
|
37512
|
-
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
37513
|
-
}
|
|
37514
|
-
if (!Object.hasOwn(joseHeader, parameter) || joseHeader[parameter] === void 0) {
|
|
37515
|
-
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
37516
|
-
}
|
|
37517
|
-
if (recognized[parameter] && (!Object.hasOwn(protectedHeader, parameter) || protectedHeader[parameter] === void 0)) {
|
|
37518
|
-
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
37519
|
-
}
|
|
37520
|
-
}
|
|
37521
|
-
return protectedHeader.crit;
|
|
37522
|
-
}
|
|
37523
|
-
function validateB64(protectedHeader, extensions) {
|
|
37524
|
-
if (extensions.includes("b64")) {
|
|
37525
|
-
const b64 = protectedHeader.b64;
|
|
37526
|
-
if (typeof b64 !== "boolean") {
|
|
37527
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
37528
|
-
}
|
|
37529
|
-
return b64;
|
|
37530
|
-
}
|
|
37531
|
-
return true;
|
|
37532
|
-
}
|
|
37533
|
-
function serializeJoseHeader(Err, header) {
|
|
37534
|
-
let serialized;
|
|
37535
|
-
let parsed;
|
|
37536
|
-
try {
|
|
37537
|
-
serialized = JSON.stringify(header);
|
|
37538
|
-
parsed = JSON.parse(serialized);
|
|
37539
|
-
} catch (cause) {
|
|
37540
|
-
throw new Err("JOSE Header is not valid JSON", { cause });
|
|
37541
|
-
}
|
|
37542
|
-
if (!isObject(parsed)) {
|
|
37543
|
-
throw new Err("JOSE Header is not a JSON object");
|
|
37544
|
-
}
|
|
37545
|
-
return [parsed, serialized];
|
|
37546
|
-
}
|
|
37547
|
-
var JWS_RECOGNIZED, JWE_RECOGNIZED;
|
|
37548
|
-
var init_options = __esm({
|
|
37549
|
-
"../node_modules/jose/dist/webapi/lib/options.js"() {
|
|
37550
|
-
init_errors();
|
|
37551
|
-
init_type_checks();
|
|
37552
|
-
JWS_RECOGNIZED = { __proto__: null, b64: true };
|
|
37553
|
-
JWE_RECOGNIZED = { __proto__: null };
|
|
37256
|
+
init_content_encryption();
|
|
37554
37257
|
}
|
|
37555
37258
|
});
|
|
37556
37259
|
|
|
37557
37260
|
// ../node_modules/jose/dist/webapi/lib/deflate.js
|
|
37558
37261
|
function validateZip(joseHeader, protectedHeader) {
|
|
37559
|
-
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF")
|
|
37262
|
+
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF")
|
|
37560
37263
|
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
37561
|
-
|
|
37562
|
-
if (joseHeader.zip !== void 0 && !protectedHeader?.zip) {
|
|
37264
|
+
if (joseHeader.zip !== void 0 && !protectedHeader?.zip)
|
|
37563
37265
|
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
37564
|
-
}
|
|
37565
37266
|
}
|
|
37566
37267
|
function supported(name) {
|
|
37567
|
-
if (typeof globalThis[name]
|
|
37268
|
+
if (typeof globalThis[name] > "u")
|
|
37568
37269
|
throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
|
|
37569
|
-
}
|
|
37570
37270
|
}
|
|
37571
|
-
async function
|
|
37572
|
-
|
|
37573
|
-
const cs = new CompressionStream("deflate-raw");
|
|
37574
|
-
const writer = cs.writable.getWriter();
|
|
37271
|
+
async function transform(stream, input, maxLength = 1 / 0) {
|
|
37272
|
+
const writer = stream.writable.getWriter();
|
|
37575
37273
|
writer.write(input).catch(() => {
|
|
37576
|
-
})
|
|
37577
|
-
writer.close().catch(() => {
|
|
37578
|
-
});
|
|
37579
|
-
const chunks = [];
|
|
37580
|
-
const reader = cs.readable.getReader();
|
|
37581
|
-
for (; ; ) {
|
|
37582
|
-
const { value, done } = await reader.read();
|
|
37583
|
-
if (done)
|
|
37584
|
-
break;
|
|
37585
|
-
chunks.push(value);
|
|
37586
|
-
}
|
|
37587
|
-
return concat(...chunks);
|
|
37588
|
-
}
|
|
37589
|
-
async function decompress(input, maxLength) {
|
|
37590
|
-
supported("DecompressionStream");
|
|
37591
|
-
const ds = new DecompressionStream("deflate-raw");
|
|
37592
|
-
const writer = ds.writable.getWriter();
|
|
37593
|
-
writer.write(input).catch(() => {
|
|
37594
|
-
});
|
|
37595
|
-
writer.close().catch(() => {
|
|
37274
|
+
}), writer.close().catch(() => {
|
|
37596
37275
|
});
|
|
37597
37276
|
const chunks = [];
|
|
37598
37277
|
let length = 0;
|
|
37599
|
-
const reader =
|
|
37278
|
+
const reader = stream.readable.getReader();
|
|
37600
37279
|
for (; ; ) {
|
|
37601
37280
|
const { value, done } = await reader.read();
|
|
37602
37281
|
if (done)
|
|
37603
37282
|
break;
|
|
37604
|
-
chunks.push(value)
|
|
37605
|
-
length += value.byteLength;
|
|
37606
|
-
if (maxLength !== Infinity && length > maxLength) {
|
|
37283
|
+
if (chunks.push(value), length += value.byteLength, maxLength !== 1 / 0 && length > maxLength)
|
|
37607
37284
|
throw new JWEInvalid("Decompressed plaintext exceeded the configured limit");
|
|
37608
|
-
}
|
|
37609
37285
|
}
|
|
37610
37286
|
return concat(...chunks);
|
|
37611
37287
|
}
|
|
37288
|
+
async function compress(input) {
|
|
37289
|
+
return supported("CompressionStream"), transform(new CompressionStream("deflate-raw"), input);
|
|
37290
|
+
}
|
|
37291
|
+
async function decompress(input, maxLength) {
|
|
37292
|
+
return supported("DecompressionStream"), transform(new DecompressionStream("deflate-raw"), input, maxLength);
|
|
37293
|
+
}
|
|
37612
37294
|
var init_deflate = __esm({
|
|
37613
37295
|
"../node_modules/jose/dist/webapi/lib/deflate.js"() {
|
|
37614
37296
|
init_errors();
|
|
@@ -37618,55 +37300,41 @@ return true;`);
|
|
|
37618
37300
|
|
|
37619
37301
|
// ../node_modules/jose/dist/webapi/lib/jwe_decrypt.js
|
|
37620
37302
|
function snapshotSharedJWE(jwe) {
|
|
37621
|
-
const { aad, ciphertext, iv, protected: encodedProtected, tag: tag2, unprotected
|
|
37622
|
-
if (iv !== void 0 && typeof iv
|
|
37303
|
+
const { aad, ciphertext, iv, protected: encodedProtected, tag: tag2, unprotected } = jwe;
|
|
37304
|
+
if (iv !== void 0 && (typeof iv != "string" || !iv))
|
|
37623
37305
|
throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
37624
|
-
|
|
37625
|
-
if (typeof ciphertext !== "string") {
|
|
37306
|
+
if (typeof ciphertext != "string")
|
|
37626
37307
|
throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
|
|
37627
|
-
|
|
37628
|
-
if (tag2 !== void 0 && typeof tag2 !== "string") {
|
|
37308
|
+
if (tag2 !== void 0 && (typeof tag2 != "string" || !tag2))
|
|
37629
37309
|
throw new JWEInvalid("JWE Authentication Tag incorrect type");
|
|
37630
|
-
|
|
37631
|
-
if (encodedProtected !== void 0 && typeof encodedProtected !== "string") {
|
|
37310
|
+
if (encodedProtected !== void 0 && typeof encodedProtected != "string")
|
|
37632
37311
|
throw new JWEInvalid("JWE Protected Header incorrect type");
|
|
37633
|
-
|
|
37634
|
-
if (aad !== void 0 && (typeof aad !== "string" || !aad)) {
|
|
37312
|
+
if (aad !== void 0 && (typeof aad != "string" || !aad))
|
|
37635
37313
|
throw new JWEInvalid("JWE AAD incorrect type");
|
|
37636
|
-
|
|
37637
|
-
if (unprotected2 !== void 0 && !isObject(unprotected2)) {
|
|
37314
|
+
if (unprotected !== void 0 && !isObject(unprotected))
|
|
37638
37315
|
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
37639
|
-
}
|
|
37640
37316
|
return {
|
|
37641
37317
|
aad,
|
|
37642
37318
|
ciphertext,
|
|
37643
37319
|
iv,
|
|
37644
37320
|
protected: encodedProtected,
|
|
37645
37321
|
tag: tag2,
|
|
37646
|
-
unprotected:
|
|
37322
|
+
unprotected: unprotected === void 0 ? void 0 : { ...unprotected }
|
|
37647
37323
|
};
|
|
37648
37324
|
}
|
|
37649
37325
|
function snapshotRecipientJWE(recipient) {
|
|
37650
|
-
let header;
|
|
37651
|
-
let headerAlg;
|
|
37326
|
+
let header, headerAlg;
|
|
37652
37327
|
try {
|
|
37653
37328
|
const { header: inputHeader } = recipient;
|
|
37654
37329
|
if (isObject(inputHeader)) {
|
|
37655
37330
|
headerAlg = inputHeader.alg;
|
|
37656
37331
|
const parameters = Object.keys(inputHeader);
|
|
37657
|
-
|
|
37658
|
-
headerAlg = void 0;
|
|
37659
|
-
header = Object.fromEntries(parameters.map((parameter) => [
|
|
37332
|
+
parameters.includes("alg") || (headerAlg = void 0), header = Object.fromEntries(parameters.map((parameter) => [
|
|
37660
37333
|
parameter,
|
|
37661
37334
|
parameter === "alg" ? headerAlg : inputHeader[parameter]
|
|
37662
37335
|
]));
|
|
37663
|
-
} else
|
|
37336
|
+
} else
|
|
37664
37337
|
header = inputHeader;
|
|
37665
|
-
}
|
|
37666
|
-
} catch (error) {
|
|
37667
|
-
return [void 0, headerAlg, error];
|
|
37668
|
-
}
|
|
37669
|
-
try {
|
|
37670
37338
|
const { encrypted_key: encryptedKey } = recipient;
|
|
37671
37339
|
return [{ encrypted_key: encryptedKey, header }, headerAlg];
|
|
37672
37340
|
} catch (error) {
|
|
@@ -37675,54 +37343,24 @@ return true;`);
|
|
|
37675
37343
|
}
|
|
37676
37344
|
function checkRecipient(jwe) {
|
|
37677
37345
|
const { encrypted_key: encryptedKey, header } = jwe;
|
|
37678
|
-
if (encryptedKey !== void 0 && typeof encryptedKey
|
|
37346
|
+
if (encryptedKey !== void 0 && typeof encryptedKey != "string")
|
|
37679
37347
|
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
37680
|
-
|
|
37681
|
-
|
|
37682
|
-
|
|
37683
|
-
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
37684
|
-
}
|
|
37685
|
-
}
|
|
37686
|
-
if (jwe.protected === void 0 && header === void 0 && jwe.unprotected === void 0) {
|
|
37348
|
+
if (header !== void 0 && !isObject(header))
|
|
37349
|
+
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
37350
|
+
if (jwe.protected === void 0 && header === void 0 && jwe.unprotected === void 0)
|
|
37687
37351
|
throw new JWEInvalid("JOSE Header missing");
|
|
37688
|
-
}
|
|
37689
37352
|
}
|
|
37690
37353
|
function shareJWE(jwe) {
|
|
37691
37354
|
const { protected: encodedProtected, ciphertext, iv, tag: tag2, aad } = jwe;
|
|
37692
37355
|
let parsedProt;
|
|
37693
|
-
|
|
37694
|
-
parsedProt = parseJoseHeader(encodedProtected, JWEInvalid, "JWE Protected Header is invalid");
|
|
37695
|
-
}
|
|
37696
|
-
const protectedHeader = encodedProtected !== void 0 ? encode(encodedProtected) : new Uint8Array();
|
|
37697
|
-
return [
|
|
37356
|
+
return encodedProtected !== void 0 && (parsedProt = parseJoseHeader(encodedProtected, JWEInvalid, "JWE Protected Header is invalid")), [
|
|
37698
37357
|
parsedProt,
|
|
37699
37358
|
decodeBase64url(ciphertext, "ciphertext", JWEInvalid),
|
|
37700
37359
|
iv !== void 0 ? decodeBase64url(iv, "iv", JWEInvalid) : void 0,
|
|
37701
37360
|
tag2 !== void 0 ? decodeBase64url(tag2, "tag", JWEInvalid) : void 0,
|
|
37702
|
-
aad !== void 0 ?
|
|
37361
|
+
encodeBase64url((encodedProtected ?? "") + (aad !== void 0 ? `.${aad}` : ""), "aad", JWEInvalid)
|
|
37703
37362
|
];
|
|
37704
37363
|
}
|
|
37705
|
-
function decryptResult(jwe, decrypted) {
|
|
37706
|
-
const [plaintext, parsedProt, key, resolvedKey] = decrypted;
|
|
37707
|
-
const { protected: encodedProtected, aad, unprotected: unprotected2, header } = jwe;
|
|
37708
|
-
const result = { plaintext };
|
|
37709
|
-
if (encodedProtected !== void 0) {
|
|
37710
|
-
result.protectedHeader = parsedProt;
|
|
37711
|
-
}
|
|
37712
|
-
if (aad !== void 0) {
|
|
37713
|
-
result.additionalAuthenticatedData = decodeBase64url(aad, "aad", JWEInvalid);
|
|
37714
|
-
}
|
|
37715
|
-
if (unprotected2 !== void 0) {
|
|
37716
|
-
result.sharedUnprotectedHeader = unprotected2;
|
|
37717
|
-
}
|
|
37718
|
-
if (header !== void 0) {
|
|
37719
|
-
result.unprotectedHeader = header;
|
|
37720
|
-
}
|
|
37721
|
-
if (resolvedKey) {
|
|
37722
|
-
return { ...result, key };
|
|
37723
|
-
}
|
|
37724
|
-
return result;
|
|
37725
|
-
}
|
|
37726
37364
|
function prepareDecrypt(options) {
|
|
37727
37365
|
return [
|
|
37728
37366
|
options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms),
|
|
@@ -37732,121 +37370,112 @@ return true;`);
|
|
|
37732
37370
|
options?.maxDecompressedLength
|
|
37733
37371
|
];
|
|
37734
37372
|
}
|
|
37735
|
-
async function
|
|
37736
|
-
const [parsedProt] = token;
|
|
37737
|
-
const { header, unprotected: unprotected2 } = jwe;
|
|
37373
|
+
async function decryptJWE(jwe, shared, key, token = shareJWE(jwe)) {
|
|
37374
|
+
const [parsedProt, ciphertext, iv, tag2, additionalData] = token, { header, unprotected, aad } = jwe;
|
|
37738
37375
|
let joseHeader;
|
|
37739
|
-
if (header !== void 0 ||
|
|
37740
|
-
if (!isDisjoint(parsedProt, header,
|
|
37376
|
+
if (header !== void 0 || unprotected !== void 0) {
|
|
37377
|
+
if (!isDisjoint(parsedProt, header, unprotected))
|
|
37741
37378
|
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
37742
|
-
}
|
|
37743
|
-
|
|
37744
|
-
} else {
|
|
37379
|
+
joseHeader = { ...parsedProt, ...header, ...unprotected };
|
|
37380
|
+
} else
|
|
37745
37381
|
joseHeader = parsedProt ?? {};
|
|
37746
|
-
}
|
|
37747
|
-
|
|
37748
|
-
}
|
|
37749
|
-
async function decryptRecipientCore(jwe, token, shared, key, joseHeader) {
|
|
37750
|
-
const [keyManagementAlgorithms, contentEncryptionAlgorithms, crit, maxPBES2Count, maxDecompressedLength] = shared;
|
|
37751
|
-
const [parsedProt, ciphertext, iv, tag2, additionalData] = token;
|
|
37752
|
-
const { encrypted_key: encodedKey } = jwe;
|
|
37753
|
-
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, parsedProt, joseHeader);
|
|
37754
|
-
validateZip(joseHeader, parsedProt);
|
|
37382
|
+
const [keyManagementAlgorithms, contentEncryptionAlgorithms, crit, maxPBES2Count, maxDecompressedLength] = shared, { encrypted_key: encodedKey } = jwe;
|
|
37383
|
+
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, parsedProt, joseHeader), validateZip(joseHeader, parsedProt);
|
|
37755
37384
|
const { alg, enc } = joseHeader;
|
|
37756
|
-
if (typeof alg
|
|
37385
|
+
if (typeof alg != "string" || !alg)
|
|
37757
37386
|
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
37758
|
-
|
|
37759
|
-
if (
|
|
37387
|
+
const selected = JWE[alg];
|
|
37388
|
+
if (encodedKey === "" && (!selected || !isJWECEKTransport(selected)))
|
|
37389
|
+
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
37390
|
+
const integrated = selected?.mode === "integrated-encryption";
|
|
37391
|
+
if (!integrated && (typeof enc != "string" || !enc))
|
|
37760
37392
|
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
37761
|
-
|
|
37762
|
-
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
|
|
37393
|
+
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2"))
|
|
37763
37394
|
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
37395
|
+
let encEntry;
|
|
37396
|
+
if (integrated) {
|
|
37397
|
+
if (enc !== void 0)
|
|
37398
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must not be present for integrated encryption');
|
|
37399
|
+
if (iv?.byteLength)
|
|
37400
|
+
throw new JWEInvalid("JWE Initialization Vector must be empty for integrated encryption");
|
|
37401
|
+
if (tag2?.byteLength)
|
|
37402
|
+
throw new JWEInvalid("JWE Authentication Tag must be empty for integrated encryption");
|
|
37403
|
+
} else {
|
|
37404
|
+
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc))
|
|
37405
|
+
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
37406
|
+
encEntry = jweEncryption(enc);
|
|
37764
37407
|
}
|
|
37765
|
-
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
|
|
37766
|
-
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
37767
|
-
}
|
|
37768
|
-
const encEntry = jweEncryption(enc);
|
|
37769
37408
|
let encryptedKey;
|
|
37770
|
-
if (encodedKey !== void 0)
|
|
37771
|
-
|
|
37772
|
-
|
|
37773
|
-
|
|
37774
|
-
|
|
37775
|
-
|
|
37776
|
-
|
|
37777
|
-
}
|
|
37778
|
-
const algEntry = jweAlgorithm(alg);
|
|
37779
|
-
const k = await prepareKey(alg === "dir" ? encEntry : algEntry, key, "decrypt");
|
|
37780
|
-
let cek;
|
|
37781
|
-
try {
|
|
37782
|
-
cek = await decryptKeyManagement(alg, encEntry, k, encryptedKey, joseHeader, maxPBES2Count);
|
|
37783
|
-
if (encodedKey !== void 0 && cek instanceof Uint8Array && cek.byteLength << 3 !== encEntry.cekBits) {
|
|
37784
|
-
cek = generateCek(encEntry);
|
|
37409
|
+
if (encodedKey !== void 0)
|
|
37410
|
+
try {
|
|
37411
|
+
encryptedKey = decodeBase64url(encodedKey, "encrypted_key", JWEInvalid);
|
|
37412
|
+
} catch (error) {
|
|
37413
|
+
if (!selected || !isJWECEKTransport(selected))
|
|
37414
|
+
throw error;
|
|
37415
|
+
encryptedKey = new Uint8Array();
|
|
37785
37416
|
}
|
|
37786
|
-
|
|
37787
|
-
|
|
37788
|
-
|
|
37417
|
+
let resolvedKey = false;
|
|
37418
|
+
typeof key == "function" && (key = await key(parsedProt, jwe), resolvedKey = true);
|
|
37419
|
+
const algEntry = selected ?? jweAlgorithm(alg);
|
|
37420
|
+
isJWECEKTransport(algEntry) && encryptedKey === void 0 && (encryptedKey = new Uint8Array());
|
|
37421
|
+
const k = await prepareKey(algEntry.mode === "direct-encryption" ? encEntry : algEntry, key, "decrypt");
|
|
37422
|
+
let plaintext;
|
|
37423
|
+
if (algEntry.mode === "integrated-encryption")
|
|
37424
|
+
plaintext = await algEntry.decrypt(k, encryptedKey, ciphertext, additionalData, parsedProt, joseHeader);
|
|
37425
|
+
else {
|
|
37426
|
+
const encryption = encEntry;
|
|
37427
|
+
let cek;
|
|
37428
|
+
try {
|
|
37429
|
+
cek = await decryptKeyManagement(algEntry, encryption, k, encryptedKey, joseHeader, maxPBES2Count), isJWECEKTransport(algEntry) && cek instanceof Uint8Array && cek.byteLength << 3 !== encryption.cekBits && (cek = generateCek(encryption));
|
|
37430
|
+
} catch (err) {
|
|
37431
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported)
|
|
37432
|
+
throw err;
|
|
37433
|
+
cek = generateCek(encryption);
|
|
37789
37434
|
}
|
|
37790
|
-
|
|
37435
|
+
plaintext = await decrypt(encryption, cek, ciphertext, iv, tag2, additionalData);
|
|
37791
37436
|
}
|
|
37792
|
-
let plaintext = await decrypt(encEntry, cek, ciphertext, iv, tag2, additionalData);
|
|
37793
37437
|
if (joseHeader.zip === "DEF") {
|
|
37794
37438
|
const decompressionLimit = maxDecompressedLength ?? 25e4;
|
|
37795
|
-
if (decompressionLimit === 0)
|
|
37439
|
+
if (decompressionLimit === 0)
|
|
37796
37440
|
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
37797
|
-
|
|
37798
|
-
if (decompressionLimit !== Infinity && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1)) {
|
|
37441
|
+
if (decompressionLimit !== 1 / 0 && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1))
|
|
37799
37442
|
throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
|
|
37800
|
-
}
|
|
37801
37443
|
plaintext = await decompress(plaintext, decompressionLimit).catch((cause) => {
|
|
37802
|
-
|
|
37803
|
-
throw cause;
|
|
37804
|
-
throw new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
37444
|
+
throw cause instanceof JWEInvalid ? cause : new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
37805
37445
|
});
|
|
37806
37446
|
}
|
|
37807
|
-
return
|
|
37808
|
-
|
|
37809
|
-
|
|
37810
|
-
|
|
37447
|
+
return {
|
|
37448
|
+
plaintext,
|
|
37449
|
+
...parsedProt && { protectedHeader: parsedProt },
|
|
37450
|
+
...aad !== void 0 && {
|
|
37451
|
+
additionalAuthenticatedData: decodeBase64url(aad, "aad", JWEInvalid)
|
|
37452
|
+
},
|
|
37453
|
+
...unprotected && { sharedUnprotectedHeader: unprotected },
|
|
37454
|
+
...header && { unprotectedHeader: header },
|
|
37455
|
+
...resolvedKey && { key: k }
|
|
37456
|
+
};
|
|
37811
37457
|
}
|
|
37812
37458
|
async function decryptCompact(jwe, shared, key) {
|
|
37813
|
-
if (jwe instanceof Uint8Array)
|
|
37814
|
-
jwe = decoder.decode(jwe);
|
|
37815
|
-
}
|
|
37816
|
-
if (typeof jwe !== "string") {
|
|
37459
|
+
if (jwe instanceof Uint8Array && (jwe = decoder.decode(jwe)), typeof jwe != "string")
|
|
37817
37460
|
throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
|
|
37818
|
-
}
|
|
37819
37461
|
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
|
|
37820
|
-
if (length !== 5)
|
|
37462
|
+
if (length !== 5)
|
|
37821
37463
|
throw new JWEInvalid("Invalid Compact JWE");
|
|
37822
|
-
|
|
37823
|
-
const flattened = {
|
|
37464
|
+
return decryptJWE({
|
|
37824
37465
|
ciphertext,
|
|
37825
37466
|
iv: iv || void 0,
|
|
37826
37467
|
protected: protectedHeader,
|
|
37827
37468
|
tag: tag2 || void 0,
|
|
37828
37469
|
encrypted_key: encryptedKey || void 0
|
|
37829
|
-
};
|
|
37830
|
-
const parsedProt = parseJoseHeader(protectedHeader, JWEInvalid, "JWE Protected Header is invalid");
|
|
37831
|
-
const protectedBytes = encode(protectedHeader);
|
|
37832
|
-
const token = [
|
|
37833
|
-
parsedProt,
|
|
37834
|
-
decodeBase64url(ciphertext, "ciphertext", JWEInvalid),
|
|
37835
|
-
iv ? decodeBase64url(iv, "iv", JWEInvalid) : void 0,
|
|
37836
|
-
tag2 ? decodeBase64url(tag2, "tag", JWEInvalid) : void 0,
|
|
37837
|
-
protectedBytes
|
|
37838
|
-
];
|
|
37839
|
-
return decryptRecipientCore(flattened, token, shared, key, parsedProt);
|
|
37470
|
+
}, shared, key);
|
|
37840
37471
|
}
|
|
37841
37472
|
var init_jwe_decrypt = __esm({
|
|
37842
37473
|
"../node_modules/jose/dist/webapi/lib/jwe_decrypt.js"() {
|
|
37843
37474
|
init_content_encryption();
|
|
37844
|
-
|
|
37475
|
+
init_validate2();
|
|
37845
37476
|
init_errors();
|
|
37846
|
-
init_type_checks();
|
|
37847
37477
|
init_key_management();
|
|
37848
37478
|
init_buffer_utils();
|
|
37849
|
-
init_options();
|
|
37850
37479
|
init_key();
|
|
37851
37480
|
init_jwe_algorithms();
|
|
37852
37481
|
init_deflate();
|
|
@@ -37855,12 +37484,7 @@ return true;`);
|
|
|
37855
37484
|
|
|
37856
37485
|
// ../node_modules/jose/dist/webapi/jwe/compact/decrypt.js
|
|
37857
37486
|
async function compactDecrypt(jwe, key, options) {
|
|
37858
|
-
|
|
37859
|
-
const result = { plaintext: decrypted[0], protectedHeader: decrypted[1] };
|
|
37860
|
-
if (typeof key === "function") {
|
|
37861
|
-
return { ...result, key: decrypted[2] };
|
|
37862
|
-
}
|
|
37863
|
-
return result;
|
|
37487
|
+
return decryptCompact(jwe, prepareDecrypt(options), key);
|
|
37864
37488
|
}
|
|
37865
37489
|
var init_decrypt = __esm({
|
|
37866
37490
|
"../node_modules/jose/dist/webapi/jwe/compact/decrypt.js"() {
|
|
@@ -37870,208 +37494,124 @@ return true;`);
|
|
|
37870
37494
|
|
|
37871
37495
|
// ../node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
37872
37496
|
async function flattenedDecrypt(jwe, key, options) {
|
|
37873
|
-
if (!isObject(jwe))
|
|
37497
|
+
if (!isObject(jwe))
|
|
37874
37498
|
throw new JWEInvalid("Flattened JWE must be an object");
|
|
37875
|
-
|
|
37876
|
-
const shared = snapshotSharedJWE(jwe);
|
|
37877
|
-
const [recipient, , error] = snapshotRecipientJWE(jwe);
|
|
37499
|
+
const shared = snapshotSharedJWE(jwe), [recipient, , error] = snapshotRecipientJWE(jwe);
|
|
37878
37500
|
if (!recipient)
|
|
37879
37501
|
throw error;
|
|
37880
37502
|
const snapshot = { ...shared, ...recipient };
|
|
37881
|
-
checkRecipient(snapshot);
|
|
37882
|
-
return decryptResult(snapshot, await decryptJWE(snapshot, prepareDecrypt(options), key));
|
|
37503
|
+
return checkRecipient(snapshot), decryptJWE(snapshot, prepareDecrypt(options), key);
|
|
37883
37504
|
}
|
|
37884
37505
|
var init_decrypt2 = __esm({
|
|
37885
37506
|
"../node_modules/jose/dist/webapi/jwe/flattened/decrypt.js"() {
|
|
37886
37507
|
init_errors();
|
|
37887
|
-
|
|
37508
|
+
init_validate2();
|
|
37888
37509
|
init_jwe_decrypt();
|
|
37889
37510
|
}
|
|
37890
37511
|
});
|
|
37891
37512
|
|
|
37892
37513
|
// ../node_modules/jose/dist/webapi/jwe/general/decrypt.js
|
|
37893
37514
|
async function generalDecrypt(jwe, key, options) {
|
|
37894
|
-
if (!isObject(jwe))
|
|
37515
|
+
if (!isObject(jwe))
|
|
37895
37516
|
throw new JWEInvalid("General JWE must be an object");
|
|
37896
|
-
}
|
|
37897
37517
|
const inputRecipients = jwe.recipients;
|
|
37898
|
-
if (!Array.isArray(inputRecipients))
|
|
37518
|
+
if (!Array.isArray(inputRecipients))
|
|
37899
37519
|
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
37900
|
-
}
|
|
37901
37520
|
const recipients = Array.from(inputRecipients);
|
|
37902
|
-
if (!recipients.every(isObject))
|
|
37521
|
+
if (!recipients.every(isObject))
|
|
37903
37522
|
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
37904
|
-
|
|
37905
|
-
if (!recipients.length) {
|
|
37523
|
+
if (!recipients.length)
|
|
37906
37524
|
throw new JWEInvalid("JWE Recipients has no members");
|
|
37907
|
-
|
|
37908
|
-
let shared;
|
|
37909
|
-
let sharedJwe;
|
|
37910
|
-
let token;
|
|
37525
|
+
let shared, sharedJwe, token;
|
|
37911
37526
|
try {
|
|
37912
|
-
shared = prepareDecrypt(options);
|
|
37913
|
-
sharedJwe = snapshotSharedJWE(jwe);
|
|
37914
|
-
token = shareJWE(sharedJwe);
|
|
37527
|
+
shared = prepareDecrypt(options), sharedJwe = snapshotSharedJWE(jwe), token = shareJWE(sharedJwe);
|
|
37915
37528
|
} catch {
|
|
37916
37529
|
throw new JWEDecryptionFailed();
|
|
37917
37530
|
}
|
|
37918
37531
|
const recipientSnapshots = recipients.map((recipient) => snapshotRecipientJWE(recipient));
|
|
37919
|
-
if (recipients.length > 1)
|
|
37532
|
+
if (recipients.length > 1)
|
|
37920
37533
|
for (const [, headerAlg] of recipientSnapshots) {
|
|
37921
|
-
const alg = token[0]?.alg ?? headerAlg ?? sharedJwe.unprotected?.alg;
|
|
37922
|
-
if (
|
|
37534
|
+
const alg = token[0]?.alg ?? headerAlg ?? sharedJwe.unprotected?.alg, algEntry = typeof alg == "string" ? JWE[alg] : void 0;
|
|
37535
|
+
if (algEntry && !isJWECEKTransport(algEntry))
|
|
37923
37536
|
throw new JWEInvalid(`"${alg}" alg may only have a single recipient`);
|
|
37924
|
-
}
|
|
37925
37537
|
}
|
|
37926
|
-
|
|
37927
|
-
|
|
37928
|
-
|
|
37929
|
-
|
|
37930
|
-
|
|
37931
|
-
|
|
37932
|
-
|
|
37933
|
-
return decryptResult(flattened, await decryptRecipient(flattened, token, shared, key));
|
|
37934
|
-
} catch {
|
|
37935
|
-
}
|
|
37936
|
-
}
|
|
37538
|
+
for (const [recipient] of recipientSnapshots)
|
|
37539
|
+
if (recipient)
|
|
37540
|
+
try {
|
|
37541
|
+
const flattened = { ...sharedJwe, ...recipient };
|
|
37542
|
+
return checkRecipient(flattened), await decryptJWE(flattened, shared, key, token);
|
|
37543
|
+
} catch {
|
|
37544
|
+
}
|
|
37937
37545
|
throw new JWEDecryptionFailed();
|
|
37938
37546
|
}
|
|
37939
37547
|
var init_decrypt3 = __esm({
|
|
37940
37548
|
"../node_modules/jose/dist/webapi/jwe/general/decrypt.js"() {
|
|
37941
37549
|
init_jwe_decrypt();
|
|
37942
37550
|
init_errors();
|
|
37943
|
-
|
|
37551
|
+
init_validate2();
|
|
37552
|
+
init_jwe_algorithms();
|
|
37944
37553
|
}
|
|
37945
37554
|
});
|
|
37946
37555
|
|
|
37947
37556
|
// ../node_modules/jose/dist/webapi/lib/jwe_encrypt.js
|
|
37948
37557
|
function checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader) {
|
|
37949
|
-
if (!isDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader))
|
|
37558
|
+
if (!isDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader))
|
|
37950
37559
|
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
37951
|
-
}
|
|
37952
37560
|
}
|
|
37953
|
-
function checkEncryptHeaders(input) {
|
|
37561
|
+
function checkEncryptHeaders(input, options, sharedHeadersNormalized = false) {
|
|
37562
|
+
if (!input[1] && !input[2] && !input[3])
|
|
37563
|
+
throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
37564
|
+
options !== void 0 && (input[8] = options?.crit);
|
|
37954
37565
|
let [, protectedHeader, unprotectedHeader, sharedUnprotectedHeader, aad, cek, iv, keyManagementParameters, crit] = input;
|
|
37955
|
-
if (aad !== void 0)
|
|
37956
|
-
assertUint8Array(aad, "JWE Additional Authenticated Data");
|
|
37957
|
-
}
|
|
37958
|
-
if (cek !== void 0) {
|
|
37959
|
-
assertUint8Array(cek, "JWE Content Encryption Key");
|
|
37960
|
-
}
|
|
37961
|
-
if (iv !== void 0) {
|
|
37962
|
-
assertUint8Array(iv, "JWE Initialization Vector");
|
|
37963
|
-
}
|
|
37964
|
-
if (protectedHeader !== void 0) {
|
|
37965
|
-
protectedHeader = serializeJoseHeader(JWEInvalid, protectedHeader)[0];
|
|
37966
|
-
input[1] = protectedHeader;
|
|
37967
|
-
}
|
|
37968
|
-
if (unprotectedHeader !== void 0) {
|
|
37969
|
-
unprotectedHeader = serializeJoseHeader(JWEInvalid, unprotectedHeader)[0];
|
|
37970
|
-
input[2] = unprotectedHeader;
|
|
37971
|
-
}
|
|
37972
|
-
if (sharedUnprotectedHeader !== void 0) {
|
|
37973
|
-
sharedUnprotectedHeader = serializeJoseHeader(JWEInvalid, sharedUnprotectedHeader)[0];
|
|
37974
|
-
input[3] = sharedUnprotectedHeader;
|
|
37975
|
-
}
|
|
37976
|
-
if (keyManagementParameters !== void 0 && !isObject(keyManagementParameters)) {
|
|
37566
|
+
if (aad !== void 0 && assertUint8Array(aad, "JWE Additional Authenticated Data"), cek !== void 0 && assertUint8Array(cek, "JWE Content Encryption Key"), iv !== void 0 && assertUint8Array(iv, "JWE Initialization Vector"), !sharedHeadersNormalized && protectedHeader !== void 0 && (protectedHeader = serializeJoseHeader(JWEInvalid, protectedHeader)[0], input[1] = protectedHeader), unprotectedHeader !== void 0 && (unprotectedHeader = serializeJoseHeader(JWEInvalid, unprotectedHeader)[0], input[2] = unprotectedHeader), !sharedHeadersNormalized && sharedUnprotectedHeader !== void 0 && (sharedUnprotectedHeader = serializeJoseHeader(JWEInvalid, sharedUnprotectedHeader)[0], input[3] = sharedUnprotectedHeader), keyManagementParameters !== void 0 && !isObject(keyManagementParameters))
|
|
37977
37567
|
throw new TypeError("JWE Key Management Parameters must be an object");
|
|
37978
|
-
}
|
|
37979
37568
|
checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader);
|
|
37980
37569
|
const joseHeader = {
|
|
37981
37570
|
...protectedHeader,
|
|
37982
37571
|
...unprotectedHeader,
|
|
37983
37572
|
...sharedUnprotectedHeader
|
|
37984
37573
|
};
|
|
37985
|
-
validateCritDuplicates(JWEInvalid, protectedHeader);
|
|
37986
|
-
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, protectedHeader, joseHeader);
|
|
37987
|
-
validateZip(joseHeader, protectedHeader);
|
|
37574
|
+
validateCritDuplicates(JWEInvalid, protectedHeader), validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, protectedHeader, joseHeader), validateZip(joseHeader, protectedHeader);
|
|
37988
37575
|
const { alg, enc } = joseHeader;
|
|
37989
|
-
if (typeof alg
|
|
37576
|
+
if (typeof alg != "string" || !alg)
|
|
37990
37577
|
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
37991
|
-
|
|
37992
|
-
if (
|
|
37578
|
+
const algEntry = JWE[alg];
|
|
37579
|
+
if (algEntry?.mode === "integrated-encryption") {
|
|
37580
|
+
if (enc !== void 0)
|
|
37581
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must not be present for integrated encryption');
|
|
37582
|
+
if (cek !== void 0)
|
|
37583
|
+
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
37584
|
+
if (iv !== void 0)
|
|
37585
|
+
throw new TypeError(`setInitializationVector cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
37586
|
+
return [joseHeader, void 0, algEntry];
|
|
37587
|
+
}
|
|
37588
|
+
if (typeof enc != "string" || !enc)
|
|
37993
37589
|
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
37994
|
-
|
|
37995
|
-
return [joseHeader, alg, enc, jweEncryption(enc)];
|
|
37590
|
+
return [joseHeader, jweEncryption(enc), algEntry];
|
|
37996
37591
|
}
|
|
37997
37592
|
async function encryptJWE(input, checked, key) {
|
|
37998
|
-
const [joseHeader,
|
|
37999
|
-
|
|
38000
|
-
|
|
38001
|
-
let
|
|
38002
|
-
|
|
38003
|
-
|
|
38004
|
-
}
|
|
38005
|
-
const algEntry = jweAlgorithm(alg);
|
|
38006
|
-
const k = await prepareKey(alg === "dir" ? encEntry : algEntry, key, "encrypt");
|
|
38007
|
-
const [cek, encryptedKey, parameters] = await encryptKeyManagement(alg, encEntry, k, providedCek, keyManagementParameters);
|
|
38008
|
-
if (parameters) {
|
|
38009
|
-
if (unprotectedParameters) {
|
|
38010
|
-
unprotectedHeader = unprotectedHeader ? { ...unprotectedHeader, ...parameters } : parameters;
|
|
38011
|
-
} else {
|
|
38012
|
-
protectedHeader = protectedHeader ? { ...protectedHeader, ...parameters } : parameters;
|
|
38013
|
-
}
|
|
38014
|
-
checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader);
|
|
38015
|
-
}
|
|
38016
|
-
let protectedHeaderS;
|
|
38017
|
-
let protectedHeaderB;
|
|
38018
|
-
if (protectedHeader) {
|
|
38019
|
-
protectedHeaderS = encode2(JSON.stringify(protectedHeader));
|
|
38020
|
-
protectedHeaderB = encode(protectedHeaderS);
|
|
38021
|
-
} else {
|
|
38022
|
-
protectedHeaderS = "";
|
|
38023
|
-
protectedHeaderB = new Uint8Array();
|
|
38024
|
-
}
|
|
38025
|
-
let additionalData;
|
|
38026
|
-
let aadMember;
|
|
38027
|
-
if (aad?.byteLength) {
|
|
38028
|
-
aadMember = encode2(aad);
|
|
38029
|
-
additionalData = concat(protectedHeaderB, encode("."), encode(aadMember));
|
|
38030
|
-
} else {
|
|
38031
|
-
additionalData = protectedHeaderB;
|
|
38032
|
-
}
|
|
37593
|
+
const [joseHeader, encEntry, selected] = checked, [inputPlaintext, inputProtectedHeader, inputUnprotectedHeader, sharedUnprotectedHeader, aad, providedCek, inputIv, keyManagementParameters, , unprotectedParameters] = input;
|
|
37594
|
+
let protectedHeader = inputProtectedHeader, unprotectedHeader = inputUnprotectedHeader;
|
|
37595
|
+
const algEntry = selected ?? jweAlgorithm(joseHeader.alg);
|
|
37596
|
+
let encryptedKey, parameters, cek;
|
|
37597
|
+
algEntry.mode === "integrated-encryption" ? cek = await prepareKey(algEntry, key, "encrypt") : [cek, encryptedKey, parameters] = await encryptKeyManagement(algEntry, encEntry, key, joseHeader, providedCek, keyManagementParameters), parameters && (unprotectedParameters ? unprotectedHeader = unprotectedHeader ? { ...unprotectedHeader, ...parameters } : parameters : protectedHeader = protectedHeader ? { ...protectedHeader, ...parameters } : parameters, checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader));
|
|
37598
|
+
const protectedHeaderS = protectedHeader ? encode2(JSON.stringify(protectedHeader)) : "", aadMember = aad?.byteLength ? encode2(aad) : void 0, additionalData = encode(aadMember ? `${protectedHeaderS}.${aadMember}` : protectedHeaderS);
|
|
38033
37599
|
let plaintext = inputPlaintext;
|
|
38034
|
-
|
|
38035
|
-
|
|
38036
|
-
|
|
38037
|
-
|
|
38038
|
-
}
|
|
38039
|
-
const { ciphertext, tag: tag2, iv } = await encrypt(encEntry, plaintext, cek, inputIv, additionalData);
|
|
37600
|
+
joseHeader.zip === "DEF" && (plaintext = await compress(plaintext).catch((cause) => {
|
|
37601
|
+
throw new JWEInvalid("Failed to compress plaintext", { cause });
|
|
37602
|
+
}));
|
|
37603
|
+
let ciphertext, tag2, iv;
|
|
37604
|
+
algEntry.mode === "integrated-encryption" ? [encryptedKey, ciphertext] = await algEntry.encrypt(cek, plaintext, additionalData, protectedHeader, joseHeader, keyManagementParameters) : { ciphertext, tag: tag2, iv } = await encrypt(encEntry, plaintext, cek, inputIv, additionalData);
|
|
38040
37605
|
const jwe = {
|
|
38041
37606
|
ciphertext: encode2(ciphertext)
|
|
38042
37607
|
};
|
|
38043
|
-
|
|
38044
|
-
jwe.iv = encode2(iv);
|
|
38045
|
-
}
|
|
38046
|
-
if (tag2) {
|
|
38047
|
-
jwe.tag = encode2(tag2);
|
|
38048
|
-
}
|
|
38049
|
-
if (encryptedKey) {
|
|
38050
|
-
jwe.encrypted_key = encode2(encryptedKey);
|
|
38051
|
-
}
|
|
38052
|
-
if (aadMember) {
|
|
38053
|
-
jwe.aad = aadMember;
|
|
38054
|
-
}
|
|
38055
|
-
if (protectedHeader) {
|
|
38056
|
-
jwe.protected = protectedHeaderS;
|
|
38057
|
-
}
|
|
38058
|
-
if (sharedUnprotectedHeader) {
|
|
38059
|
-
jwe.unprotected = sharedUnprotectedHeader;
|
|
38060
|
-
}
|
|
38061
|
-
if (unprotectedHeader) {
|
|
38062
|
-
jwe.header = unprotectedHeader;
|
|
38063
|
-
}
|
|
38064
|
-
return jwe;
|
|
37608
|
+
return iv && (jwe.iv = encode2(iv)), tag2 && (jwe.tag = encode2(tag2)), encryptedKey?.byteLength && (jwe.encrypted_key = encode2(encryptedKey)), aadMember && (jwe.aad = aadMember), protectedHeader && (jwe.protected = protectedHeaderS), sharedUnprotectedHeader && (jwe.unprotected = sharedUnprotectedHeader), unprotectedHeader && (jwe.header = unprotectedHeader), jwe;
|
|
38065
37609
|
}
|
|
38066
37610
|
async function createJWE(input, key, options) {
|
|
38067
|
-
|
|
38068
|
-
|
|
38069
|
-
|
|
38070
|
-
|
|
38071
|
-
input[8] = options?.crit;
|
|
38072
|
-
input[9] = options ? unprotected in options : false;
|
|
38073
|
-
}
|
|
38074
|
-
return encryptJWE(input, checkEncryptHeaders(input), key);
|
|
37611
|
+
return encryptJWE(input, checkEncryptHeaders(input, options), key);
|
|
37612
|
+
}
|
|
37613
|
+
function compactJWE(jwe) {
|
|
37614
|
+
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
38075
37615
|
}
|
|
38076
37616
|
var init_jwe_encrypt = __esm({
|
|
38077
37617
|
"../node_modules/jose/dist/webapi/lib/jwe_encrypt.js"() {
|
|
@@ -38079,56 +37619,36 @@ return true;`);
|
|
|
38079
37619
|
init_content_encryption();
|
|
38080
37620
|
init_key_management();
|
|
38081
37621
|
init_errors();
|
|
38082
|
-
|
|
37622
|
+
init_validate2();
|
|
38083
37623
|
init_buffer_utils();
|
|
38084
|
-
init_options();
|
|
38085
37624
|
init_key();
|
|
38086
37625
|
init_jwe_algorithms();
|
|
38087
37626
|
init_deflate();
|
|
38088
|
-
init_helpers();
|
|
38089
37627
|
}
|
|
38090
37628
|
});
|
|
38091
37629
|
|
|
38092
37630
|
// ../node_modules/jose/dist/webapi/jwe/general/encrypt.js
|
|
38093
|
-
function copyOptionalMembers(flattened, jwe, recipient) {
|
|
38094
|
-
const { aad, protected: protectedHeader, unprotected: unprotected2, header } = flattened;
|
|
38095
|
-
if (aad)
|
|
38096
|
-
jwe.aad = aad;
|
|
38097
|
-
if (protectedHeader)
|
|
38098
|
-
jwe.protected = protectedHeader;
|
|
38099
|
-
if (unprotected2)
|
|
38100
|
-
jwe.unprotected = unprotected2;
|
|
38101
|
-
if (header)
|
|
38102
|
-
recipient.header = header;
|
|
38103
|
-
}
|
|
38104
37631
|
var _parent, IndividualRecipient, _plaintext, _recipients, _protectedHeader, _unprotectedHeader, _aad, GeneralEncrypt;
|
|
38105
37632
|
var init_encrypt = __esm({
|
|
38106
37633
|
"../node_modules/jose/dist/webapi/jwe/general/encrypt.js"() {
|
|
38107
|
-
|
|
37634
|
+
init_validate2();
|
|
38108
37635
|
init_errors();
|
|
38109
37636
|
init_content_encryption();
|
|
38110
|
-
init_key_management();
|
|
38111
37637
|
init_base64url();
|
|
38112
37638
|
init_jwe_encrypt();
|
|
38113
|
-
|
|
37639
|
+
init_key_management();
|
|
38114
37640
|
init_jwe_algorithms();
|
|
38115
|
-
init_type_checks();
|
|
38116
37641
|
IndividualRecipient = class {
|
|
38117
37642
|
constructor(enc, key, crit) {
|
|
38118
37643
|
__privateAdd(this, _parent);
|
|
38119
37644
|
__publicField(this, "state");
|
|
38120
|
-
__privateSet(this, _parent, enc);
|
|
38121
|
-
this.state = [void 0, void 0, key, crit];
|
|
37645
|
+
__privateSet(this, _parent, enc), this.state = [void 0, void 0, key, crit];
|
|
38122
37646
|
}
|
|
38123
37647
|
setUnprotectedHeader(unprotectedHeader) {
|
|
38124
|
-
assertNotSet(this.state[0], "setUnprotectedHeader");
|
|
38125
|
-
this.state[0] = unprotectedHeader;
|
|
38126
|
-
return this;
|
|
37648
|
+
return assertNotSet(this.state[0], "setUnprotectedHeader"), this.state[0] = unprotectedHeader, this;
|
|
38127
37649
|
}
|
|
38128
37650
|
setKeyManagementParameters(parameters) {
|
|
38129
|
-
assertNotSet(this.state[1], "setKeyManagementParameters");
|
|
38130
|
-
this.state[1] = parameters;
|
|
38131
|
-
return this;
|
|
37651
|
+
return assertNotSet(this.state[1], "setKeyManagementParameters"), this.state[1] = parameters, this;
|
|
38132
37652
|
}
|
|
38133
37653
|
addRecipient(...args) {
|
|
38134
37654
|
return __privateGet(this, _parent).addRecipient(...args);
|
|
@@ -38152,62 +37672,26 @@ return true;`);
|
|
|
38152
37672
|
}
|
|
38153
37673
|
addRecipient(key, options) {
|
|
38154
37674
|
const recipient = new IndividualRecipient(this, key, options?.crit);
|
|
38155
|
-
__privateGet(this, _recipients).push(recipient);
|
|
38156
|
-
return recipient;
|
|
37675
|
+
return __privateGet(this, _recipients).push(recipient), recipient;
|
|
38157
37676
|
}
|
|
38158
37677
|
setProtectedHeader(protectedHeader) {
|
|
38159
|
-
assertNotSet(__privateGet(this, _protectedHeader), "setProtectedHeader");
|
|
38160
|
-
__privateSet(this, _protectedHeader, protectedHeader);
|
|
38161
|
-
return this;
|
|
37678
|
+
return assertNotSet(__privateGet(this, _protectedHeader), "setProtectedHeader"), __privateSet(this, _protectedHeader, protectedHeader), this;
|
|
38162
37679
|
}
|
|
38163
37680
|
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
38164
|
-
assertNotSet(__privateGet(this, _unprotectedHeader), "setSharedUnprotectedHeader");
|
|
38165
|
-
__privateSet(this, _unprotectedHeader, sharedUnprotectedHeader);
|
|
38166
|
-
return this;
|
|
37681
|
+
return assertNotSet(__privateGet(this, _unprotectedHeader), "setSharedUnprotectedHeader"), __privateSet(this, _unprotectedHeader, sharedUnprotectedHeader), this;
|
|
38167
37682
|
}
|
|
38168
37683
|
setAdditionalAuthenticatedData(aad) {
|
|
38169
|
-
__privateSet(this, _aad, aad);
|
|
38170
|
-
return this;
|
|
37684
|
+
return __privateSet(this, _aad, aad), this;
|
|
38171
37685
|
}
|
|
38172
37686
|
async encrypt() {
|
|
38173
|
-
if (!__privateGet(this, _recipients).length)
|
|
37687
|
+
if (!__privateGet(this, _recipients).length)
|
|
38174
37688
|
throw new JWEInvalid("at least one recipient must be added");
|
|
38175
|
-
}
|
|
38176
37689
|
assertUint8Array(__privateGet(this, _plaintext), "plaintext");
|
|
38177
|
-
|
|
38178
|
-
|
|
38179
|
-
|
|
38180
|
-
|
|
38181
|
-
|
|
38182
|
-
unprotectedHeader,
|
|
38183
|
-
__privateGet(this, _unprotectedHeader),
|
|
38184
|
-
__privateGet(this, _aad),
|
|
38185
|
-
void 0,
|
|
38186
|
-
void 0,
|
|
38187
|
-
keyManagementParameters,
|
|
38188
|
-
crit,
|
|
38189
|
-
false
|
|
38190
|
-
], key);
|
|
38191
|
-
const jwe2 = {
|
|
38192
|
-
ciphertext: flattened.ciphertext,
|
|
38193
|
-
iv: flattened.iv,
|
|
38194
|
-
recipients: [{}],
|
|
38195
|
-
tag: flattened.tag
|
|
38196
|
-
};
|
|
38197
|
-
if (flattened.encrypted_key)
|
|
38198
|
-
jwe2.recipients[0].encrypted_key = flattened.encrypted_key;
|
|
38199
|
-
copyOptionalMembers(flattened, jwe2, jwe2.recipients[0]);
|
|
38200
|
-
return jwe2;
|
|
38201
|
-
}
|
|
38202
|
-
let enc;
|
|
38203
|
-
let protectedHeader = __privateGet(this, _protectedHeader);
|
|
38204
|
-
let sharedUnprotectedHeader = __privateGet(this, _unprotectedHeader);
|
|
38205
|
-
const inputs = [];
|
|
38206
|
-
const checked = [];
|
|
38207
|
-
for (let i = 0; i < __privateGet(this, _recipients).length; i++) {
|
|
38208
|
-
const recipient = __privateGet(this, _recipients)[i];
|
|
38209
|
-
const [unprotectedHeader, keyManagementParameters, , crit] = recipient.state;
|
|
38210
|
-
const input = [
|
|
37690
|
+
const multiple = __privateGet(this, _recipients).length > 1;
|
|
37691
|
+
let enc, protectedHeader = __privateGet(this, _protectedHeader), sharedUnprotectedHeader = __privateGet(this, _unprotectedHeader);
|
|
37692
|
+
const recipients = [];
|
|
37693
|
+
for (const recipient of __privateGet(this, _recipients)) {
|
|
37694
|
+
const [unprotectedHeader, keyManagementParameters, key, crit] = recipient.state, input = [
|
|
38211
37695
|
__privateGet(this, _plaintext),
|
|
38212
37696
|
protectedHeader,
|
|
38213
37697
|
unprotectedHeader,
|
|
@@ -38217,55 +37701,35 @@ return true;`);
|
|
|
38217
37701
|
void 0,
|
|
38218
37702
|
keyManagementParameters,
|
|
38219
37703
|
crit,
|
|
38220
|
-
|
|
38221
|
-
];
|
|
38222
|
-
|
|
38223
|
-
|
|
38224
|
-
|
|
38225
|
-
|
|
38226
|
-
|
|
38227
|
-
|
|
38228
|
-
|
|
38229
|
-
if (headers[1] === "dir" || headers[1] === "ECDH-ES") {
|
|
38230
|
-
throw new JWEInvalid(`"${headers[1]}" alg may only have a single recipient`);
|
|
38231
|
-
}
|
|
38232
|
-
if (!enc) {
|
|
38233
|
-
enc = headers[2];
|
|
38234
|
-
} else if (enc !== headers[2]) {
|
|
37704
|
+
multiple
|
|
37705
|
+
], headers = checkEncryptHeaders(input, void 0, recipients.length > 0);
|
|
37706
|
+
recipients.length || (protectedHeader = input[1], sharedUnprotectedHeader = input[3]), recipients.push([input, headers, key]);
|
|
37707
|
+
const [{ alg, enc: recipientEnc }, , algEntry] = headers;
|
|
37708
|
+
if (multiple && algEntry && !isJWECEKTransport(algEntry))
|
|
37709
|
+
throw new JWEInvalid(`"${alg}" alg may only have a single recipient`);
|
|
37710
|
+
if (!enc)
|
|
37711
|
+
enc = recipientEnc;
|
|
37712
|
+
else if (enc !== recipientEnc)
|
|
38235
37713
|
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
|
|
38236
|
-
}
|
|
38237
37714
|
}
|
|
38238
|
-
const
|
|
38239
|
-
|
|
38240
|
-
|
|
38241
|
-
|
|
37715
|
+
for (const [, headers] of recipients)
|
|
37716
|
+
headers[2] ?? (headers[2] = jweAlgorithm(headers[0].alg));
|
|
37717
|
+
const [firstInput, firstHeaders, firstKey] = recipients[0], cek = multiple ? generateCek(firstHeaders[1]) : void 0;
|
|
37718
|
+
firstInput[5] = cek;
|
|
37719
|
+
const { encrypted_key, header, ...shared } = await encryptJWE(firstInput, firstHeaders, firstKey), jwe = {
|
|
37720
|
+
...shared,
|
|
37721
|
+
recipients: [{}]
|
|
38242
37722
|
};
|
|
38243
|
-
|
|
38244
|
-
|
|
38245
|
-
const [,
|
|
38246
|
-
|
|
38247
|
-
|
|
38248
|
-
if (i === 0) {
|
|
38249
|
-
inputs[0][5] = cek;
|
|
38250
|
-
const flattened = await encryptJWE(inputs[0], checked[0], key);
|
|
38251
|
-
jwe.ciphertext = flattened.ciphertext;
|
|
38252
|
-
jwe.iv = flattened.iv;
|
|
38253
|
-
jwe.tag = flattened.tag;
|
|
38254
|
-
target.encrypted_key = flattened.encrypted_key;
|
|
38255
|
-
copyOptionalMembers(flattened, jwe, target);
|
|
38256
|
-
continue;
|
|
38257
|
-
}
|
|
38258
|
-
const [, alg, , encEntry] = checked[i];
|
|
38259
|
-
const unprotectedHeader = inputs[i][2];
|
|
38260
|
-
const k = await prepareKey(jweAlgorithm(alg), key, "encrypt");
|
|
38261
|
-
const [, encryptedKey, parameters] = await encryptKeyManagement(alg, encEntry, k, cek, keyManagementParameters);
|
|
38262
|
-
target.encrypted_key = encode2(encryptedKey);
|
|
37723
|
+
encrypted_key && (jwe.recipients[0].encrypted_key = encrypted_key), header && (jwe.recipients[0].header = header);
|
|
37724
|
+
for (let i = 1; i < recipients.length; i++) {
|
|
37725
|
+
const [input, [joseHeader, encEntry, algEntry], key] = recipients[i], unprotectedHeader = input[2], [, encryptedKey, parameters] = await encryptKeyManagement(algEntry, encEntry, key, joseHeader, cek, input[7]), target = {
|
|
37726
|
+
encrypted_key: encode2(encryptedKey)
|
|
37727
|
+
};
|
|
38263
37728
|
if (unprotectedHeader || parameters) {
|
|
38264
|
-
const
|
|
38265
|
-
|
|
38266
|
-
checkDisjoint(inputs[i][1], header, inputs[i][3]);
|
|
38267
|
-
target.header = header;
|
|
37729
|
+
const header2 = { ...unprotectedHeader, ...parameters };
|
|
37730
|
+
parameters && checkDisjoint(input[1], header2, input[3]), target.header = header2;
|
|
38268
37731
|
}
|
|
37732
|
+
jwe.recipients.push(target);
|
|
38269
37733
|
}
|
|
38270
37734
|
return jwe;
|
|
38271
37735
|
}
|
|
@@ -38278,45 +37742,13 @@ return true;`);
|
|
|
38278
37742
|
}
|
|
38279
37743
|
});
|
|
38280
37744
|
|
|
38281
|
-
// ../node_modules/jose/dist/webapi/lib/signing.js
|
|
38282
|
-
async function getSigKey(entry, key, usage) {
|
|
38283
|
-
if (key instanceof Uint8Array) {
|
|
38284
|
-
return crypto.subtle.importKey("raw", key, entry.subtle, false, [
|
|
38285
|
-
usage
|
|
38286
|
-
]);
|
|
38287
|
-
}
|
|
38288
|
-
checkCryptoKey(key, entry.subtle, usage);
|
|
38289
|
-
if (entry.minRsaBits)
|
|
38290
|
-
checkModulusLength(entry.alg, key);
|
|
38291
|
-
return key;
|
|
38292
|
-
}
|
|
38293
|
-
async function sign(entry, key, data) {
|
|
38294
|
-
const cryptoKey = await getSigKey(entry, key, "sign");
|
|
38295
|
-
const signature = await crypto.subtle.sign(entry.signing, cryptoKey, data);
|
|
38296
|
-
return new Uint8Array(signature);
|
|
38297
|
-
}
|
|
38298
|
-
async function verify(entry, key, signature, data) {
|
|
38299
|
-
const cryptoKey = await getSigKey(entry, key, "verify");
|
|
38300
|
-
try {
|
|
38301
|
-
return await crypto.subtle.verify(entry.signing, cryptoKey, signature, data);
|
|
38302
|
-
} catch {
|
|
38303
|
-
return false;
|
|
38304
|
-
}
|
|
38305
|
-
}
|
|
38306
|
-
var init_signing = __esm({
|
|
38307
|
-
"../node_modules/jose/dist/webapi/lib/signing.js"() {
|
|
38308
|
-
init_crypto_key();
|
|
38309
|
-
}
|
|
38310
|
-
});
|
|
38311
|
-
|
|
38312
37745
|
// ../node_modules/jose/dist/webapi/lib/jws_algorithms.js
|
|
38313
37746
|
function hmac(bits) {
|
|
38314
37747
|
const subtle = { name: "HMAC", hash: `SHA-${bits}` };
|
|
38315
37748
|
return { kty: ["oct"], secret: true, subtle, signing: subtle, usages: sig };
|
|
38316
37749
|
}
|
|
38317
37750
|
function rsa(bits, saltLength) {
|
|
38318
|
-
const
|
|
38319
|
-
const subtle = { name, hash: `SHA-${bits}` };
|
|
37751
|
+
const subtle = { name: saltLength ? "RSA-PSS" : "RSASSA-PKCS1-v1_5", hash: `SHA-${bits}` };
|
|
38320
37752
|
return {
|
|
38321
37753
|
kty: ["RSA"],
|
|
38322
37754
|
subtle,
|
|
@@ -38345,8 +37777,7 @@ return true;`);
|
|
|
38345
37777
|
};
|
|
38346
37778
|
}
|
|
38347
37779
|
function mldsa(bits) {
|
|
38348
|
-
const
|
|
38349
|
-
const subtle = { name };
|
|
37780
|
+
const subtle = { name: `ML-DSA-${bits}` };
|
|
38350
37781
|
return {
|
|
38351
37782
|
kty: ["AKP"],
|
|
38352
37783
|
subtle,
|
|
@@ -38355,10 +37786,9 @@ return true;`);
|
|
|
38355
37786
|
};
|
|
38356
37787
|
}
|
|
38357
37788
|
function jwsAlgorithm(alg) {
|
|
38358
|
-
const entry = typeof alg
|
|
38359
|
-
if (!entry)
|
|
37789
|
+
const entry = typeof alg == "string" ? JWS[alg] : void 0;
|
|
37790
|
+
if (!entry)
|
|
38360
37791
|
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
38361
|
-
}
|
|
38362
37792
|
return entry;
|
|
38363
37793
|
}
|
|
38364
37794
|
var sig, JWS;
|
|
@@ -38391,70 +37821,32 @@ return true;`);
|
|
|
38391
37821
|
|
|
38392
37822
|
// ../node_modules/jose/dist/webapi/lib/jws_verify.js
|
|
38393
37823
|
function snapshotJws(jws, sharedPayload) {
|
|
38394
|
-
const encodedProtected = jws.protected;
|
|
38395
|
-
const inputHeader = jws.header;
|
|
38396
|
-
const header = isObject(inputHeader) ? { ...inputHeader } : inputHeader;
|
|
37824
|
+
const encodedProtected = jws.protected, inputHeader = jws.header, header = isObject(inputHeader) ? { ...inputHeader } : inputHeader;
|
|
38397
37825
|
let payload = sharedPayload ? sharedPayload[0] : jws.payload;
|
|
38398
|
-
|
|
38399
|
-
|
|
38400
|
-
|
|
38401
|
-
|
|
38402
|
-
|
|
38403
|
-
|
|
38404
|
-
|
|
38405
|
-
|
|
38406
|
-
|
|
37826
|
+
!sharedPayload && payload instanceof Uint8Array && (payload = new Uint8Array(payload));
|
|
37827
|
+
const signature = jws.signature, snapshot = { payload, signature };
|
|
37828
|
+
if (encodedProtected !== void 0 && (snapshot.protected = encodedProtected), inputHeader !== void 0 && (snapshot.header = header), encodedProtected === void 0 && header === void 0)
|
|
37829
|
+
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
37830
|
+
if (encodedProtected !== void 0 && typeof encodedProtected != "string")
|
|
37831
|
+
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
37832
|
+
if (payload === void 0)
|
|
37833
|
+
throw new JWSInvalid("JWS Payload missing");
|
|
37834
|
+
if (typeof signature != "string")
|
|
37835
|
+
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
37836
|
+
if (header !== void 0 && !isObject(header))
|
|
37837
|
+
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
38407
37838
|
return snapshot;
|
|
38408
37839
|
}
|
|
38409
|
-
function verifyResult(jws, verified) {
|
|
38410
|
-
const [payload, parsedProt, , key, resolvedKey] = verified;
|
|
38411
|
-
const result = { payload };
|
|
38412
|
-
if (jws.protected !== void 0) {
|
|
38413
|
-
result.protectedHeader = parsedProt;
|
|
38414
|
-
}
|
|
38415
|
-
if (jws.header !== void 0) {
|
|
38416
|
-
result.unprotectedHeader = jws.header;
|
|
38417
|
-
}
|
|
38418
|
-
if (resolvedKey) {
|
|
38419
|
-
return { ...result, key };
|
|
38420
|
-
}
|
|
38421
|
-
return result;
|
|
38422
|
-
}
|
|
38423
37840
|
function prepareVerify(options) {
|
|
38424
37841
|
return [options && validateAlgorithms("algorithms", options.algorithms), options?.crit];
|
|
38425
37842
|
}
|
|
38426
|
-
function parseProtectedHeader(encodedProtected
|
|
38427
|
-
return
|
|
38428
|
-
}
|
|
38429
|
-
function validateJwsHeaders(parsedProt, joseHeader, shared) {
|
|
38430
|
-
const b64 = validateB64(parsedProt, validateCrit(JWSInvalid, JWS_RECOGNIZED, shared[1], parsedProt, joseHeader));
|
|
38431
|
-
const alg = joseHeader.alg;
|
|
38432
|
-
if (typeof alg !== "string" || !alg) {
|
|
38433
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
38434
|
-
}
|
|
38435
|
-
if (shared[0] && !shared[0].has(alg)) {
|
|
38436
|
-
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
38437
|
-
}
|
|
38438
|
-
return [b64, alg];
|
|
38439
|
-
}
|
|
38440
|
-
function parseJwsHeaders(encodedProtected, header, shared, parsedProtected) {
|
|
38441
|
-
const parsedProt = parseProtectedHeader(encodedProtected, parsedProtected);
|
|
38442
|
-
let joseHeader;
|
|
38443
|
-
if (header !== void 0) {
|
|
38444
|
-
if (!isDisjoint(parsedProt, header)) {
|
|
38445
|
-
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
38446
|
-
}
|
|
38447
|
-
joseHeader = { ...parsedProt, ...header };
|
|
38448
|
-
} else {
|
|
38449
|
-
joseHeader = parsedProt;
|
|
38450
|
-
}
|
|
38451
|
-
return [parsedProt, joseHeader, ...validateJwsHeaders(parsedProt, joseHeader, shared)];
|
|
37843
|
+
function parseProtectedHeader(encodedProtected) {
|
|
37844
|
+
return encodedProtected === void 0 ? {} : parseJoseHeader(encodedProtected, JWSInvalid, "JWS Protected Header is invalid");
|
|
38452
37845
|
}
|
|
38453
37846
|
function encodeJsonUnencodedPayload(payload) {
|
|
38454
37847
|
const invalid2 = /[\p{Cs}\p{Cn}]/u.exec(payload)?.[0];
|
|
38455
|
-
if (invalid2 !== void 0)
|
|
37848
|
+
if (invalid2 !== void 0)
|
|
38456
37849
|
throw new JWSInvalid(/\p{Cs}/u.test(invalid2) ? "JWS Payload must be a well-formed Unicode string" : "JWS Payload must not contain unassigned Unicode code points");
|
|
38457
|
-
}
|
|
38458
37850
|
return encoder.encode(payload);
|
|
38459
37851
|
}
|
|
38460
37852
|
function encodeCompactUnencodedPayload(payload) {
|
|
@@ -38464,73 +37856,56 @@ return true;`);
|
|
|
38464
37856
|
throw new JWSInvalid("JWS Compact Serialization payload must use only ASCII characters");
|
|
38465
37857
|
}
|
|
38466
37858
|
}
|
|
38467
|
-
async function verifyPrepared(jws, shared, key, encodedProtected, parsedProt, alg, signingPayload) {
|
|
38468
|
-
let resolvedKey = false;
|
|
38469
|
-
if (typeof key === "function") {
|
|
38470
|
-
key = await key(parsedProt, jws);
|
|
38471
|
-
resolvedKey = true;
|
|
38472
|
-
}
|
|
38473
|
-
const b64 = typeof signingPayload === "string";
|
|
38474
|
-
const entry = jwsAlgorithm(alg);
|
|
38475
|
-
const data = concat(encodedProtected !== void 0 ? encode(encodedProtected) : new Uint8Array(), encode("."), b64 ? shared[2] ?? (shared[2] = encodeBase64url(signingPayload, "payload", JWSInvalid)) : signingPayload);
|
|
38476
|
-
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
38477
|
-
const k = await prepareKey(entry, key, "verify");
|
|
38478
|
-
if (!await verify(entry, k, signature, data)) {
|
|
38479
|
-
throw new JWSSignatureVerificationFailed();
|
|
38480
|
-
}
|
|
38481
|
-
const payload = b64 ? decodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload;
|
|
38482
|
-
return [payload, parsedProt, b64, k, resolvedKey];
|
|
38483
|
-
}
|
|
38484
37859
|
async function verifySignature(jws, shared, key, encodeUnencodedPayload, parsedProtected) {
|
|
38485
|
-
const { protected: encodedProtected, header, payload: inputPayload } = jws;
|
|
38486
|
-
|
|
37860
|
+
const { protected: encodedProtected, header, payload: inputPayload } = jws, parsedProt = parsedProtected ?? parseProtectedHeader(encodedProtected);
|
|
37861
|
+
if (!isDisjoint(parsedProt, header))
|
|
37862
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
37863
|
+
const joseHeader = { ...parsedProt, ...header }, b64 = validateB64(parsedProt, validateCrit(JWSInvalid, JWS_RECOGNIZED, shared[1], parsedProt, joseHeader)), { alg } = joseHeader;
|
|
37864
|
+
if (typeof alg != "string" || !alg)
|
|
37865
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
37866
|
+
if (shared[0] && !shared[0].has(alg))
|
|
37867
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
38487
37868
|
if (b64) {
|
|
38488
|
-
if (typeof inputPayload
|
|
37869
|
+
if (typeof inputPayload != "string")
|
|
38489
37870
|
throw new JWSInvalid("JWS Payload must be a string");
|
|
38490
|
-
|
|
38491
|
-
} else if (typeof inputPayload !== "string" && !(inputPayload instanceof Uint8Array)) {
|
|
37871
|
+
} else if (typeof inputPayload != "string" && !(inputPayload instanceof Uint8Array))
|
|
38492
37872
|
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
37873
|
+
const signingPayload = b64 || typeof inputPayload != "string" ? inputPayload : encodeUnencodedPayload(inputPayload);
|
|
37874
|
+
let resolvedKey = false;
|
|
37875
|
+
typeof key == "function" && (key = await key(parsedProt, jws), resolvedKey = true);
|
|
37876
|
+
const entry = jwsAlgorithm(alg), data = concat(encodedProtected !== void 0 ? encode(encodedProtected) : new Uint8Array(), encode("."), typeof signingPayload == "string" ? shared[2] ?? (shared[2] = encodeBase64url(signingPayload, "payload", JWSInvalid)) : signingPayload), signature = decodeBase64url(jws.signature, "signature", JWSInvalid), k = await prepareKey(entry, key, "verify"), cryptoKey = await rawKey(k, entry.subtle, "verify");
|
|
37877
|
+
entry.minRsaBits && checkModulusLength(entry.alg, cryptoKey);
|
|
37878
|
+
let verified = false;
|
|
37879
|
+
try {
|
|
37880
|
+
verified = await crypto.subtle.verify(entry.signing, cryptoKey, signature, data);
|
|
37881
|
+
} catch {
|
|
38493
37882
|
}
|
|
38494
|
-
|
|
38495
|
-
|
|
37883
|
+
if (!verified)
|
|
37884
|
+
throw new JWSSignatureVerificationFailed();
|
|
37885
|
+
const result = { payload: typeof signingPayload == "string" ? decodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload };
|
|
37886
|
+
return encodedProtected !== void 0 && (result.protectedHeader = parsedProt), header !== void 0 && (result.unprotectedHeader = header), resolvedKey ? [{ ...result, key: k }, b64] : [result, b64];
|
|
38496
37887
|
}
|
|
38497
37888
|
async function verifyCompact(jws, shared, key) {
|
|
38498
|
-
if (jws instanceof Uint8Array)
|
|
38499
|
-
jws = decoder.decode(jws);
|
|
38500
|
-
}
|
|
38501
|
-
if (typeof jws !== "string") {
|
|
37889
|
+
if (jws instanceof Uint8Array && (jws = decoder.decode(jws)), typeof jws != "string")
|
|
38502
37890
|
throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
38503
|
-
}
|
|
38504
37891
|
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
38505
|
-
if (length !== 3)
|
|
37892
|
+
if (length !== 3)
|
|
38506
37893
|
throw new JWSInvalid("Invalid Compact JWS");
|
|
38507
|
-
}
|
|
38508
|
-
const compactJws = { payload, protected: protectedHeader, signature };
|
|
38509
|
-
const parsedProt = parseProtectedHeader(protectedHeader);
|
|
38510
|
-
const [b64, alg] = validateJwsHeaders(parsedProt, parsedProt, shared);
|
|
38511
|
-
const signingPayload = b64 ? payload : encodeCompactUnencodedPayload(payload);
|
|
38512
|
-
return verifyPrepared(compactJws, shared, key, protectedHeader, parsedProt, alg, signingPayload);
|
|
37894
|
+
return verifySignature({ payload, protected: protectedHeader, signature }, shared, key, encodeCompactUnencodedPayload);
|
|
38513
37895
|
}
|
|
38514
37896
|
var init_jws_verify = __esm({
|
|
38515
37897
|
"../node_modules/jose/dist/webapi/lib/jws_verify.js"() {
|
|
38516
|
-
init_signing();
|
|
38517
37898
|
init_jws_algorithms();
|
|
38518
37899
|
init_errors();
|
|
38519
37900
|
init_buffer_utils();
|
|
38520
|
-
|
|
38521
|
-
init_type_checks();
|
|
38522
|
-
init_options();
|
|
37901
|
+
init_validate2();
|
|
38523
37902
|
init_key();
|
|
38524
37903
|
}
|
|
38525
37904
|
});
|
|
38526
37905
|
|
|
38527
37906
|
// ../node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
38528
37907
|
async function compactVerify(jws, key, options) {
|
|
38529
|
-
const
|
|
38530
|
-
const result = { payload: verified[0], protectedHeader: verified[1] };
|
|
38531
|
-
if (typeof key === "function") {
|
|
38532
|
-
return { ...result, key: verified[3] };
|
|
38533
|
-
}
|
|
37908
|
+
const [result] = await verifyCompact(jws, prepareVerify(options), key);
|
|
38534
37909
|
return result;
|
|
38535
37910
|
}
|
|
38536
37911
|
var init_verify = __esm({
|
|
@@ -38541,31 +37916,15 @@ return true;`);
|
|
|
38541
37916
|
|
|
38542
37917
|
// ../node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
38543
37918
|
async function flattenedVerify(jws, key, options) {
|
|
38544
|
-
if (!isObject(jws))
|
|
37919
|
+
if (!isObject(jws))
|
|
38545
37920
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
38546
|
-
|
|
38547
|
-
|
|
38548
|
-
if (snapshot.protected === void 0 && snapshot.header === void 0) {
|
|
38549
|
-
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
38550
|
-
}
|
|
38551
|
-
if (snapshot.protected !== void 0 && typeof snapshot.protected !== "string") {
|
|
38552
|
-
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
38553
|
-
}
|
|
38554
|
-
if (snapshot.payload === void 0) {
|
|
38555
|
-
throw new JWSInvalid("JWS Payload missing");
|
|
38556
|
-
}
|
|
38557
|
-
if (typeof snapshot.signature !== "string") {
|
|
38558
|
-
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
38559
|
-
}
|
|
38560
|
-
if (snapshot.header !== void 0 && !isObject(snapshot.header)) {
|
|
38561
|
-
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
38562
|
-
}
|
|
38563
|
-
return verifyResult(snapshot, await verifySignature(snapshot, prepareVerify(options), key, encodeJsonUnencodedPayload));
|
|
37921
|
+
const snapshot = snapshotJws(jws), [result] = await verifySignature(snapshot, prepareVerify(options), key, encodeJsonUnencodedPayload);
|
|
37922
|
+
return result;
|
|
38564
37923
|
}
|
|
38565
37924
|
var init_verify2 = __esm({
|
|
38566
37925
|
"../node_modules/jose/dist/webapi/jws/flattened/verify.js"() {
|
|
38567
37926
|
init_errors();
|
|
38568
|
-
|
|
37927
|
+
init_validate2();
|
|
38569
37928
|
init_jws_verify();
|
|
38570
37929
|
}
|
|
38571
37930
|
});
|
|
@@ -38573,39 +37932,25 @@ return true;`);
|
|
|
38573
37932
|
// ../node_modules/jose/dist/webapi/jws/general/verify.js
|
|
38574
37933
|
function snapshotSignature(signature, payload) {
|
|
38575
37934
|
try {
|
|
38576
|
-
const jws = snapshotJws(signature, [payload]);
|
|
38577
|
-
const { protected: encodedProtected, header, signature: encodedSignature } = jws;
|
|
38578
|
-
if (encodedProtected === void 0 && header === void 0)
|
|
38579
|
-
return void 0;
|
|
38580
|
-
if (encodedProtected !== void 0 && typeof encodedProtected !== "string")
|
|
38581
|
-
return void 0;
|
|
38582
|
-
if (typeof encodedSignature !== "string")
|
|
38583
|
-
return void 0;
|
|
38584
|
-
if (header !== void 0 && !isObject(header))
|
|
38585
|
-
return void 0;
|
|
38586
|
-
const protectedHeader = parseProtectedHeader(encodedProtected);
|
|
38587
|
-
const { b64, crit } = protectedHeader;
|
|
37935
|
+
const jws = snapshotJws(signature, [payload]), protectedHeader = parseProtectedHeader(jws.protected), { b64, crit } = protectedHeader;
|
|
38588
37936
|
return [
|
|
38589
37937
|
jws,
|
|
38590
37938
|
protectedHeader,
|
|
38591
|
-
Array.isArray(crit) && crit.includes("b64") ? typeof b64
|
|
37939
|
+
Array.isArray(crit) && crit.includes("b64") ? typeof b64 == "boolean" ? b64 ? 1 : 2 : 0 : 1
|
|
38592
37940
|
];
|
|
38593
37941
|
} catch {
|
|
38594
|
-
return
|
|
37942
|
+
return;
|
|
38595
37943
|
}
|
|
38596
37944
|
}
|
|
38597
37945
|
async function generalVerify(jws, key, options) {
|
|
38598
|
-
if (!isObject(jws))
|
|
37946
|
+
if (!isObject(jws))
|
|
38599
37947
|
throw new JWSInvalid("General JWS must be an object");
|
|
38600
|
-
}
|
|
38601
37948
|
const { signatures, payload: inputPayload } = jws;
|
|
38602
|
-
if (!Array.isArray(signatures))
|
|
37949
|
+
if (!Array.isArray(signatures))
|
|
38603
37950
|
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
38604
|
-
}
|
|
38605
37951
|
const signatureEntries = Array.from(signatures);
|
|
38606
|
-
if (!signatureEntries.every(isObject))
|
|
37952
|
+
if (!signatureEntries.every(isObject))
|
|
38607
37953
|
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
38608
|
-
}
|
|
38609
37954
|
let shared;
|
|
38610
37955
|
try {
|
|
38611
37956
|
if (inputPayload === void 0)
|
|
@@ -38614,28 +37959,24 @@ return true;`);
|
|
|
38614
37959
|
} catch {
|
|
38615
37960
|
throw new JWSSignatureVerificationFailed();
|
|
38616
37961
|
}
|
|
38617
|
-
const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload;
|
|
38618
|
-
const candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
|
|
37962
|
+
const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload, candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
|
|
38619
37963
|
let modes = 0;
|
|
38620
|
-
for (const [, , mode] of candidates)
|
|
38621
|
-
modes |= mode
|
|
38622
|
-
if (modes === 3) {
|
|
37964
|
+
for (const [, , mode] of candidates)
|
|
37965
|
+
if (modes |= mode, modes === 3)
|
|
38623
37966
|
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
38624
|
-
|
|
38625
|
-
}
|
|
38626
|
-
for (const candidate of candidates) {
|
|
37967
|
+
for (const candidate of candidates)
|
|
38627
37968
|
try {
|
|
38628
|
-
|
|
37969
|
+
const [result] = await verifySignature(candidate[0], shared, key, encodeJsonUnencodedPayload, candidate[1]);
|
|
37970
|
+
return result;
|
|
38629
37971
|
} catch {
|
|
38630
37972
|
}
|
|
38631
|
-
}
|
|
38632
37973
|
throw new JWSSignatureVerificationFailed();
|
|
38633
37974
|
}
|
|
38634
37975
|
var init_verify3 = __esm({
|
|
38635
37976
|
"../node_modules/jose/dist/webapi/jws/general/verify.js"() {
|
|
38636
37977
|
init_jws_verify();
|
|
38637
37978
|
init_errors();
|
|
38638
|
-
|
|
37979
|
+
init_validate2();
|
|
38639
37980
|
}
|
|
38640
37981
|
});
|
|
38641
37982
|
|
|
@@ -38644,54 +37985,35 @@ return true;`);
|
|
|
38644
37985
|
throw new TypeError("Invalid time period format");
|
|
38645
37986
|
}
|
|
38646
37987
|
function secs(str) {
|
|
38647
|
-
|
|
38648
|
-
invalidDuration();
|
|
38649
|
-
}
|
|
37988
|
+
typeof str != "string" && invalidDuration();
|
|
38650
37989
|
const matched = REGEX.exec(str);
|
|
38651
|
-
|
|
38652
|
-
|
|
38653
|
-
|
|
38654
|
-
const value = parseFloat(matched[2]);
|
|
38655
|
-
const numericDate2 = Math.round(value * multipliers[matched[3][0].toLowerCase()]);
|
|
38656
|
-
if (!Number.isFinite(numericDate2)) {
|
|
38657
|
-
invalidDuration();
|
|
38658
|
-
}
|
|
38659
|
-
if (matched[1] === "-" || matched[4] === "ago") {
|
|
38660
|
-
return -numericDate2;
|
|
38661
|
-
}
|
|
38662
|
-
return numericDate2;
|
|
37990
|
+
(!matched || matched[4] && matched[1]) && invalidDuration();
|
|
37991
|
+
const value = parseFloat(matched[2]), numericDate2 = Math.round(value * multipliers[matched[3][0].toLowerCase()]);
|
|
37992
|
+
return Number.isFinite(numericDate2) || invalidDuration(), matched[1] === "-" || matched[4] === "ago" ? -numericDate2 : numericDate2;
|
|
38663
37993
|
}
|
|
38664
37994
|
function validateInput(label, input) {
|
|
38665
|
-
if (!Number.isFinite(input))
|
|
37995
|
+
if (!Number.isFinite(input))
|
|
38666
37996
|
throw new TypeError(`Invalid ${label} input`);
|
|
38667
|
-
}
|
|
38668
37997
|
return input;
|
|
38669
37998
|
}
|
|
38670
37999
|
function validateStringClaim(claim, value) {
|
|
38671
|
-
if (typeof value
|
|
38000
|
+
if (typeof value != "string")
|
|
38672
38001
|
throw new TypeError(`"${claim}" claim must be a string`);
|
|
38673
|
-
}
|
|
38674
38002
|
}
|
|
38675
38003
|
function validateAudienceClaim(value) {
|
|
38676
|
-
if (typeof value
|
|
38004
|
+
if (typeof value != "string" && (!Array.isArray(value) || Array.from(value).some((member) => typeof member != "string")))
|
|
38677
38005
|
throw new TypeError('"aud" claim must be a string or an array of strings');
|
|
38678
|
-
}
|
|
38679
38006
|
}
|
|
38680
38007
|
function numericDate(value, label) {
|
|
38681
|
-
|
|
38682
|
-
return validateInput(label, value);
|
|
38683
|
-
if (value instanceof Date)
|
|
38684
|
-
return validateInput(label, epoch(value));
|
|
38685
|
-
return epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
38008
|
+
return typeof value == "number" ? validateInput(label, value) : value instanceof Date ? validateInput(label, epoch(value)) : epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
38686
38009
|
}
|
|
38687
38010
|
function validateNumericDate(payload, claim, required = false) {
|
|
38688
38011
|
const value = payload[claim];
|
|
38689
|
-
if (value === void 0 && !required)
|
|
38690
|
-
|
|
38691
|
-
|
|
38692
|
-
|
|
38012
|
+
if (!(value === void 0 && !required)) {
|
|
38013
|
+
if (typeof value != "number")
|
|
38014
|
+
throw new JWTClaimValidationFailed(`"${claim}" claim must be a number`, payload, claim, "invalid");
|
|
38015
|
+
return value;
|
|
38693
38016
|
}
|
|
38694
|
-
return value;
|
|
38695
38017
|
}
|
|
38696
38018
|
function unexpectedClaim(payload, claim) {
|
|
38697
38019
|
throw new JWTClaimValidationFailed(`unexpected "${claim}" claim value`, payload, claim, checkFailed);
|
|
@@ -38702,72 +38024,39 @@ return true;`);
|
|
|
38702
38024
|
payload = JSON.parse(strictDecoder.decode(encodedPayload));
|
|
38703
38025
|
} catch {
|
|
38704
38026
|
}
|
|
38705
|
-
if (!isObject(payload))
|
|
38027
|
+
if (!isObject(payload))
|
|
38706
38028
|
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
38707
|
-
}
|
|
38708
38029
|
const { typ } = options;
|
|
38709
|
-
if (typ !== void 0 && (typeof protectedHeader.typ
|
|
38030
|
+
if (typ !== void 0 && (typeof protectedHeader.typ != "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ)))
|
|
38710
38031
|
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", checkFailed);
|
|
38711
|
-
}
|
|
38712
|
-
|
|
38713
|
-
const
|
|
38714
|
-
|
|
38715
|
-
presenceCheck.push("iat");
|
|
38716
|
-
if (audience !== void 0)
|
|
38717
|
-
presenceCheck.push("aud");
|
|
38718
|
-
if (subject !== void 0)
|
|
38719
|
-
presenceCheck.push("sub");
|
|
38720
|
-
if (issuer !== void 0)
|
|
38721
|
-
presenceCheck.push("iss");
|
|
38722
|
-
for (const claim of new Set(presenceCheck.reverse())) {
|
|
38723
|
-
if (!Object.hasOwn(payload, claim)) {
|
|
38032
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options, presenceCheck = [...requiredClaims];
|
|
38033
|
+
maxTokenAge !== void 0 && presenceCheck.push("iat"), audience !== void 0 && presenceCheck.push("aud"), subject !== void 0 && presenceCheck.push("sub"), issuer !== void 0 && presenceCheck.push("iss");
|
|
38034
|
+
for (const claim of new Set(presenceCheck.reverse()))
|
|
38035
|
+
if (!Object.hasOwn(payload, claim))
|
|
38724
38036
|
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
38725
|
-
|
|
38726
|
-
}
|
|
38727
|
-
if (issuer !== void 0 && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
38728
|
-
unexpectedClaim(payload, "iss");
|
|
38729
|
-
}
|
|
38730
|
-
if (subject !== void 0 && payload.sub !== subject) {
|
|
38731
|
-
unexpectedClaim(payload, "sub");
|
|
38732
|
-
}
|
|
38733
|
-
if (audience !== void 0 && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
|
|
38734
|
-
unexpectedClaim(payload, "aud");
|
|
38735
|
-
}
|
|
38037
|
+
issuer !== void 0 && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss) && unexpectedClaim(payload, "iss"), subject !== void 0 && payload.sub !== subject && unexpectedClaim(payload, "sub"), audience !== void 0 && !checkAudiencePresence(payload.aud, typeof audience == "string" ? [audience] : audience) && unexpectedClaim(payload, "aud");
|
|
38736
38038
|
const { clockTolerance } = options;
|
|
38737
38039
|
let tolerance = 0;
|
|
38738
|
-
if (typeof clockTolerance
|
|
38040
|
+
if (typeof clockTolerance == "string")
|
|
38739
38041
|
tolerance = secs(clockTolerance);
|
|
38740
|
-
|
|
38741
|
-
if (typeof clockTolerance
|
|
38042
|
+
else if (clockTolerance !== void 0) {
|
|
38043
|
+
if (typeof clockTolerance != "number")
|
|
38742
38044
|
throw new TypeError("Invalid clockTolerance option type");
|
|
38743
|
-
}
|
|
38744
38045
|
tolerance = clockTolerance;
|
|
38745
38046
|
}
|
|
38746
38047
|
validateInput("clockTolerance option", tolerance);
|
|
38747
|
-
const { currentDate } = options;
|
|
38748
|
-
|
|
38749
|
-
|
|
38750
|
-
const nbf = validateNumericDate(payload, "nbf");
|
|
38751
|
-
if (nbf !== void 0) {
|
|
38752
|
-
if (nbf > now + tolerance) {
|
|
38753
|
-
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", checkFailed);
|
|
38754
|
-
}
|
|
38755
|
-
}
|
|
38048
|
+
const { currentDate } = options, now = validateInput("currentDate option", epoch(currentDate === void 0 ? /* @__PURE__ */ new Date() : currentDate)), iat = validateNumericDate(payload, "iat", maxTokenAge !== void 0), nbf = validateNumericDate(payload, "nbf");
|
|
38049
|
+
if (nbf !== void 0 && nbf > now + tolerance)
|
|
38050
|
+
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", checkFailed);
|
|
38756
38051
|
const exp = validateNumericDate(payload, "exp");
|
|
38757
|
-
if (exp !== void 0)
|
|
38758
|
-
|
|
38759
|
-
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", checkFailed);
|
|
38760
|
-
}
|
|
38761
|
-
}
|
|
38052
|
+
if (exp !== void 0 && exp <= now - tolerance)
|
|
38053
|
+
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", checkFailed);
|
|
38762
38054
|
if (maxTokenAge !== void 0) {
|
|
38763
|
-
const age = now - iat;
|
|
38764
|
-
|
|
38765
|
-
if (age - tolerance > max) {
|
|
38055
|
+
const age = now - iat, max = validateInput("maxTokenAge option", typeof maxTokenAge == "number" ? maxTokenAge : secs(maxTokenAge));
|
|
38056
|
+
if (age - tolerance > max)
|
|
38766
38057
|
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", checkFailed);
|
|
38767
|
-
|
|
38768
|
-
if (age < -tolerance) {
|
|
38058
|
+
if (age < -tolerance)
|
|
38769
38059
|
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", checkFailed);
|
|
38770
|
-
}
|
|
38771
38060
|
}
|
|
38772
38061
|
return payload;
|
|
38773
38062
|
}
|
|
@@ -38778,9 +38067,8 @@ return true;`);
|
|
|
38778
38067
|
const payload = producerPayload(producer);
|
|
38779
38068
|
for (const claim of ["iat", "nbf", "exp"]) {
|
|
38780
38069
|
const value = payload[claim];
|
|
38781
|
-
if (typeof value
|
|
38070
|
+
if (typeof value == "number" && !Number.isFinite(value))
|
|
38782
38071
|
throw new TypeError(`"${claim}" claim must be a finite number`);
|
|
38783
|
-
}
|
|
38784
38072
|
}
|
|
38785
38073
|
return encoder.encode(JSON.stringify(payload));
|
|
38786
38074
|
}
|
|
@@ -38792,7 +38080,7 @@ return true;`);
|
|
|
38792
38080
|
"../node_modules/jose/dist/webapi/lib/jwt_claims_set.js"() {
|
|
38793
38081
|
init_errors();
|
|
38794
38082
|
init_buffer_utils();
|
|
38795
|
-
|
|
38083
|
+
init_validate2();
|
|
38796
38084
|
epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
38797
38085
|
multipliers = {
|
|
38798
38086
|
s: 1,
|
|
@@ -38808,61 +38096,34 @@ return true;`);
|
|
|
38808
38096
|
const normalized = value.toLowerCase();
|
|
38809
38097
|
return value.includes("/") ? normalized : `application/${normalized}`;
|
|
38810
38098
|
};
|
|
38811
|
-
checkAudiencePresence = (audPayload, audOption) =>
|
|
38812
|
-
if (typeof audPayload === "string") {
|
|
38813
|
-
return audOption.includes(audPayload);
|
|
38814
|
-
}
|
|
38815
|
-
if (Array.isArray(audPayload)) {
|
|
38816
|
-
return audOption.some((aud) => audPayload.includes(aud));
|
|
38817
|
-
}
|
|
38818
|
-
return false;
|
|
38819
|
-
};
|
|
38099
|
+
checkAudiencePresence = (audPayload, audOption) => typeof audPayload == "string" ? audOption.includes(audPayload) : Array.isArray(audPayload) ? audOption.some((aud) => audPayload.includes(aud)) : false;
|
|
38820
38100
|
JWTClaimsBuilder = class {
|
|
38821
38101
|
constructor(payload = {}) {
|
|
38822
|
-
if (!isObject(payload))
|
|
38102
|
+
if (!isObject(payload))
|
|
38823
38103
|
throw new TypeError("JWT Claims Set MUST be an object");
|
|
38824
|
-
}
|
|
38825
|
-
;
|
|
38826
38104
|
(producerPayloads || (producerPayloads = /* @__PURE__ */ new WeakMap())).set(this, structuredClone(payload));
|
|
38827
38105
|
}
|
|
38828
38106
|
setIssuer(value) {
|
|
38829
|
-
validateStringClaim("iss", value);
|
|
38830
|
-
producerPayload(this).iss = value;
|
|
38831
|
-
return this;
|
|
38107
|
+
return validateStringClaim("iss", value), producerPayload(this).iss = value, this;
|
|
38832
38108
|
}
|
|
38833
38109
|
setSubject(value) {
|
|
38834
|
-
validateStringClaim("sub", value);
|
|
38835
|
-
producerPayload(this).sub = value;
|
|
38836
|
-
return this;
|
|
38110
|
+
return validateStringClaim("sub", value), producerPayload(this).sub = value, this;
|
|
38837
38111
|
}
|
|
38838
38112
|
setAudience(value) {
|
|
38839
|
-
validateAudienceClaim(value);
|
|
38840
|
-
producerPayload(this).aud = value;
|
|
38841
|
-
return this;
|
|
38113
|
+
return validateAudienceClaim(value), producerPayload(this).aud = value, this;
|
|
38842
38114
|
}
|
|
38843
38115
|
setJti(value) {
|
|
38844
|
-
validateStringClaim("jti", value);
|
|
38845
|
-
producerPayload(this).jti = value;
|
|
38846
|
-
return this;
|
|
38116
|
+
return validateStringClaim("jti", value), producerPayload(this).jti = value, this;
|
|
38847
38117
|
}
|
|
38848
38118
|
setNotBefore(value) {
|
|
38849
|
-
producerPayload(this).nbf = numericDate(value, "setNotBefore");
|
|
38850
|
-
return this;
|
|
38119
|
+
return producerPayload(this).nbf = numericDate(value, "setNotBefore"), this;
|
|
38851
38120
|
}
|
|
38852
38121
|
setExpirationTime(value) {
|
|
38853
|
-
producerPayload(this).exp = numericDate(value, "setExpirationTime");
|
|
38854
|
-
return this;
|
|
38122
|
+
return producerPayload(this).exp = numericDate(value, "setExpirationTime"), this;
|
|
38855
38123
|
}
|
|
38856
38124
|
setIssuedAt(value) {
|
|
38857
38125
|
const payload = producerPayload(this);
|
|
38858
|
-
|
|
38859
|
-
payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
38860
|
-
} else if (typeof value === "string") {
|
|
38861
|
-
payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
38862
|
-
} else {
|
|
38863
|
-
payload.iat = numericDate(value, "setIssuedAt");
|
|
38864
|
-
}
|
|
38865
|
-
return this;
|
|
38126
|
+
return value === void 0 ? payload.iat = epoch(/* @__PURE__ */ new Date()) : typeof value == "string" ? payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value)) : payload.iat = numericDate(value, "setIssuedAt"), this;
|
|
38866
38127
|
}
|
|
38867
38128
|
};
|
|
38868
38129
|
}
|
|
@@ -38870,16 +38131,11 @@ return true;`);
|
|
|
38870
38131
|
|
|
38871
38132
|
// ../node_modules/jose/dist/webapi/jwt/verify.js
|
|
38872
38133
|
async function jwtVerify(jwt, key, options) {
|
|
38873
|
-
const verified = await verifyCompact(jwt, prepareVerify(options), key);
|
|
38874
|
-
if (!
|
|
38134
|
+
const [verified, b64] = await verifyCompact(jwt, prepareVerify(options), key);
|
|
38135
|
+
if (!b64)
|
|
38875
38136
|
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
38876
|
-
|
|
38877
|
-
|
|
38878
|
-
const result = { payload, protectedHeader: verified[1] };
|
|
38879
|
-
if (typeof key === "function") {
|
|
38880
|
-
return { ...result, key: verified[3] };
|
|
38881
|
-
}
|
|
38882
|
-
return result;
|
|
38137
|
+
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
|
38138
|
+
return { ...verified, payload };
|
|
38883
38139
|
}
|
|
38884
38140
|
var init_verify4 = __esm({
|
|
38885
38141
|
"../node_modules/jose/dist/webapi/jwt/verify.js"() {
|
|
@@ -38891,19 +38147,11 @@ return true;`);
|
|
|
38891
38147
|
|
|
38892
38148
|
// ../node_modules/jose/dist/webapi/jwt/decrypt.js
|
|
38893
38149
|
async function jwtDecrypt(jwt, key, options) {
|
|
38894
|
-
const
|
|
38895
|
-
const
|
|
38896
|
-
|
|
38897
|
-
for (const claim of ["iss", "sub", "aud"]) {
|
|
38898
|
-
if (protectedHeader[claim] !== void 0 && (claim === "aud" ? JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud) : protectedHeader[claim] !== payload[claim])) {
|
|
38150
|
+
const { plaintext, ...result } = await decryptCompact(jwt, prepareDecrypt(options), key), { protectedHeader } = result, payload = validateClaimsSet(protectedHeader, plaintext, options);
|
|
38151
|
+
for (const claim of ["iss", "sub", "aud"])
|
|
38152
|
+
if (protectedHeader[claim] !== void 0 && (claim === "aud" ? JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud) : protectedHeader[claim] !== payload[claim]))
|
|
38899
38153
|
throw new JWTClaimValidationFailed(`replicated "${claim}" claim header parameter mismatch`, payload, claim, "mismatch");
|
|
38900
|
-
|
|
38901
|
-
}
|
|
38902
|
-
const result = { payload, protectedHeader };
|
|
38903
|
-
if (typeof key === "function") {
|
|
38904
|
-
return { ...result, key: decrypted[2] };
|
|
38905
|
-
}
|
|
38906
|
-
return result;
|
|
38154
|
+
return { payload, ...result };
|
|
38907
38155
|
}
|
|
38908
38156
|
var init_decrypt4 = __esm({
|
|
38909
38157
|
"../node_modules/jose/dist/webapi/jwt/decrypt.js"() {
|
|
@@ -38914,332 +38162,196 @@ return true;`);
|
|
|
38914
38162
|
});
|
|
38915
38163
|
|
|
38916
38164
|
// ../node_modules/jose/dist/webapi/jwe/compact/encrypt.js
|
|
38917
|
-
var
|
|
38165
|
+
var _input, CompactEncrypt;
|
|
38918
38166
|
var init_encrypt2 = __esm({
|
|
38919
38167
|
"../node_modules/jose/dist/webapi/jwe/compact/encrypt.js"() {
|
|
38920
|
-
|
|
38921
|
-
init_type_checks();
|
|
38168
|
+
init_validate2();
|
|
38922
38169
|
init_jwe_encrypt();
|
|
38923
38170
|
CompactEncrypt = class {
|
|
38924
38171
|
constructor(plaintext) {
|
|
38925
|
-
__privateAdd(this,
|
|
38926
|
-
|
|
38927
|
-
__privateAdd(this, _cek);
|
|
38928
|
-
__privateAdd(this, _iv);
|
|
38929
|
-
__privateAdd(this, _keyManagementParameters);
|
|
38930
|
-
assertUint8Array(plaintext, "plaintext");
|
|
38931
|
-
__privateSet(this, _plaintext2, plaintext);
|
|
38172
|
+
__privateAdd(this, _input);
|
|
38173
|
+
assertUint8Array(plaintext, "plaintext"), __privateSet(this, _input, [plaintext]);
|
|
38932
38174
|
}
|
|
38933
38175
|
setContentEncryptionKey(cek) {
|
|
38934
|
-
assertNotSet(__privateGet(this,
|
|
38935
|
-
__privateSet(this, _cek, cek);
|
|
38936
|
-
return this;
|
|
38176
|
+
return assertNotSet(__privateGet(this, _input)[5], "setContentEncryptionKey"), __privateGet(this, _input)[5] = cek, this;
|
|
38937
38177
|
}
|
|
38938
38178
|
setInitializationVector(iv) {
|
|
38939
|
-
assertNotSet(__privateGet(this,
|
|
38940
|
-
__privateSet(this, _iv, iv);
|
|
38941
|
-
return this;
|
|
38179
|
+
return assertNotSet(__privateGet(this, _input)[6], "setInitializationVector"), __privateGet(this, _input)[6] = iv, this;
|
|
38942
38180
|
}
|
|
38943
38181
|
setProtectedHeader(protectedHeader) {
|
|
38944
|
-
assertNotSet(__privateGet(this,
|
|
38945
|
-
__privateSet(this, _protectedHeader2, protectedHeader);
|
|
38946
|
-
return this;
|
|
38182
|
+
return assertNotSet(__privateGet(this, _input)[1], "setProtectedHeader"), __privateGet(this, _input)[1] = protectedHeader, this;
|
|
38947
38183
|
}
|
|
38948
38184
|
setKeyManagementParameters(parameters) {
|
|
38949
|
-
assertNotSet(__privateGet(this,
|
|
38950
|
-
__privateSet(this, _keyManagementParameters, parameters);
|
|
38951
|
-
return this;
|
|
38185
|
+
return assertNotSet(__privateGet(this, _input)[7], "setKeyManagementParameters"), __privateGet(this, _input)[7] = parameters, this;
|
|
38952
38186
|
}
|
|
38953
38187
|
async encrypt(key, options) {
|
|
38954
|
-
|
|
38955
|
-
|
|
38956
|
-
|
|
38957
|
-
|
|
38958
|
-
void 0,
|
|
38959
|
-
void 0,
|
|
38960
|
-
__privateGet(this, _cek),
|
|
38961
|
-
__privateGet(this, _iv),
|
|
38962
|
-
__privateGet(this, _keyManagementParameters),
|
|
38963
|
-
void 0,
|
|
38964
|
-
false
|
|
38965
|
-
], key, options);
|
|
38966
|
-
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
38967
|
-
}
|
|
38968
|
-
};
|
|
38969
|
-
_plaintext2 = new WeakMap();
|
|
38970
|
-
_protectedHeader2 = new WeakMap();
|
|
38971
|
-
_cek = new WeakMap();
|
|
38972
|
-
_iv = new WeakMap();
|
|
38973
|
-
_keyManagementParameters = new WeakMap();
|
|
38188
|
+
return compactJWE(await createJWE([...__privateGet(this, _input)], key, options));
|
|
38189
|
+
}
|
|
38190
|
+
};
|
|
38191
|
+
_input = new WeakMap();
|
|
38974
38192
|
}
|
|
38975
38193
|
});
|
|
38976
38194
|
|
|
38977
38195
|
// ../node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
38978
|
-
var
|
|
38196
|
+
var _input2, FlattenedEncrypt;
|
|
38979
38197
|
var init_encrypt3 = __esm({
|
|
38980
38198
|
"../node_modules/jose/dist/webapi/jwe/flattened/encrypt.js"() {
|
|
38981
|
-
|
|
38199
|
+
init_validate2();
|
|
38982
38200
|
init_jwe_encrypt();
|
|
38983
|
-
init_type_checks();
|
|
38984
38201
|
FlattenedEncrypt = class {
|
|
38985
38202
|
constructor(plaintext) {
|
|
38986
|
-
__privateAdd(this,
|
|
38987
|
-
|
|
38988
|
-
__privateAdd(this, _sharedUnprotectedHeader);
|
|
38989
|
-
__privateAdd(this, _unprotectedHeader2);
|
|
38990
|
-
__privateAdd(this, _aad2);
|
|
38991
|
-
__privateAdd(this, _cek2);
|
|
38992
|
-
__privateAdd(this, _iv2);
|
|
38993
|
-
__privateAdd(this, _keyManagementParameters2);
|
|
38994
|
-
assertUint8Array(plaintext, "plaintext");
|
|
38995
|
-
__privateSet(this, _plaintext3, plaintext);
|
|
38203
|
+
__privateAdd(this, _input2);
|
|
38204
|
+
assertUint8Array(plaintext, "plaintext"), __privateSet(this, _input2, [plaintext]);
|
|
38996
38205
|
}
|
|
38997
38206
|
setKeyManagementParameters(parameters) {
|
|
38998
|
-
assertNotSet(__privateGet(this,
|
|
38999
|
-
__privateSet(this, _keyManagementParameters2, parameters);
|
|
39000
|
-
return this;
|
|
38207
|
+
return assertNotSet(__privateGet(this, _input2)[7], "setKeyManagementParameters"), __privateGet(this, _input2)[7] = parameters, this;
|
|
39001
38208
|
}
|
|
39002
38209
|
setProtectedHeader(protectedHeader) {
|
|
39003
|
-
assertNotSet(__privateGet(this,
|
|
39004
|
-
__privateSet(this, _protectedHeader3, protectedHeader);
|
|
39005
|
-
return this;
|
|
38210
|
+
return assertNotSet(__privateGet(this, _input2)[1], "setProtectedHeader"), __privateGet(this, _input2)[1] = protectedHeader, this;
|
|
39006
38211
|
}
|
|
39007
38212
|
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
39008
|
-
assertNotSet(__privateGet(this,
|
|
39009
|
-
__privateSet(this, _sharedUnprotectedHeader, sharedUnprotectedHeader);
|
|
39010
|
-
return this;
|
|
38213
|
+
return assertNotSet(__privateGet(this, _input2)[3], "setSharedUnprotectedHeader"), __privateGet(this, _input2)[3] = sharedUnprotectedHeader, this;
|
|
39011
38214
|
}
|
|
39012
38215
|
setUnprotectedHeader(unprotectedHeader) {
|
|
39013
|
-
assertNotSet(__privateGet(this,
|
|
39014
|
-
__privateSet(this, _unprotectedHeader2, unprotectedHeader);
|
|
39015
|
-
return this;
|
|
38216
|
+
return assertNotSet(__privateGet(this, _input2)[2], "setUnprotectedHeader"), __privateGet(this, _input2)[2] = unprotectedHeader, this;
|
|
39016
38217
|
}
|
|
39017
38218
|
setAdditionalAuthenticatedData(aad) {
|
|
39018
|
-
|
|
39019
|
-
return this;
|
|
38219
|
+
return __privateGet(this, _input2)[4] = aad, this;
|
|
39020
38220
|
}
|
|
39021
38221
|
setContentEncryptionKey(cek) {
|
|
39022
|
-
assertNotSet(__privateGet(this,
|
|
39023
|
-
__privateSet(this, _cek2, cek);
|
|
39024
|
-
return this;
|
|
38222
|
+
return assertNotSet(__privateGet(this, _input2)[5], "setContentEncryptionKey"), __privateGet(this, _input2)[5] = cek, this;
|
|
39025
38223
|
}
|
|
39026
38224
|
setInitializationVector(iv) {
|
|
39027
|
-
assertNotSet(__privateGet(this,
|
|
39028
|
-
__privateSet(this, _iv2, iv);
|
|
39029
|
-
return this;
|
|
38225
|
+
return assertNotSet(__privateGet(this, _input2)[6], "setInitializationVector"), __privateGet(this, _input2)[6] = iv, this;
|
|
39030
38226
|
}
|
|
39031
38227
|
async encrypt(key, options) {
|
|
39032
|
-
return createJWE([
|
|
39033
|
-
|
|
39034
|
-
|
|
39035
|
-
|
|
39036
|
-
__privateGet(this, _sharedUnprotectedHeader),
|
|
39037
|
-
__privateGet(this, _aad2),
|
|
39038
|
-
__privateGet(this, _cek2),
|
|
39039
|
-
__privateGet(this, _iv2),
|
|
39040
|
-
__privateGet(this, _keyManagementParameters2),
|
|
39041
|
-
void 0,
|
|
39042
|
-
false
|
|
39043
|
-
], key, options);
|
|
39044
|
-
}
|
|
39045
|
-
};
|
|
39046
|
-
_plaintext3 = new WeakMap();
|
|
39047
|
-
_protectedHeader3 = new WeakMap();
|
|
39048
|
-
_sharedUnprotectedHeader = new WeakMap();
|
|
39049
|
-
_unprotectedHeader2 = new WeakMap();
|
|
39050
|
-
_aad2 = new WeakMap();
|
|
39051
|
-
_cek2 = new WeakMap();
|
|
39052
|
-
_iv2 = new WeakMap();
|
|
39053
|
-
_keyManagementParameters2 = new WeakMap();
|
|
38228
|
+
return createJWE([...__privateGet(this, _input2)], key, options);
|
|
38229
|
+
}
|
|
38230
|
+
};
|
|
38231
|
+
_input2 = new WeakMap();
|
|
39054
38232
|
}
|
|
39055
38233
|
});
|
|
39056
38234
|
|
|
39057
38235
|
// ../node_modules/jose/dist/webapi/lib/jws_sign.js
|
|
39058
|
-
function
|
|
39059
|
-
|
|
39060
|
-
|
|
39061
|
-
|
|
39062
|
-
|
|
39063
|
-
}
|
|
39064
|
-
function validateSignatureHeader(protectedHeader, joseHeader, crit) {
|
|
39065
|
-
validateCritDuplicates(JWSInvalid, protectedHeader);
|
|
39066
|
-
return validateB64(protectedHeader, validateCrit(JWSInvalid, JWS_RECOGNIZED, crit, protectedHeader, joseHeader));
|
|
39067
|
-
}
|
|
39068
|
-
function signatureAlgorithm(joseHeader) {
|
|
39069
|
-
const alg = joseHeader.alg;
|
|
39070
|
-
if (typeof alg !== "string" || !alg) {
|
|
39071
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
38236
|
+
async function createSignature(input, key, rejectUnencoded) {
|
|
38237
|
+
let [payload, protectedHeader, unprotectedHeader, crit] = input, protectedHeaderString = "";
|
|
38238
|
+
if (protectedHeader !== void 0) {
|
|
38239
|
+
const normalized = serializeJoseHeader(JWSInvalid, protectedHeader);
|
|
38240
|
+
protectedHeader = normalized[0], protectedHeaderString = encode2(normalized[1]);
|
|
39072
38241
|
}
|
|
39073
|
-
|
|
39074
|
-
}
|
|
39075
|
-
async function signSignature(protectedHeader, payload, entry, key) {
|
|
39076
|
-
const data = concat(encode(protectedHeader), encode("."), payload);
|
|
39077
|
-
const k = await prepareKey(entry, key, "sign");
|
|
39078
|
-
return encode2(await sign(entry, k, data));
|
|
39079
|
-
}
|
|
39080
|
-
async function createSignature(input, key, assertB64) {
|
|
39081
|
-
let { protectedHeader, unprotectedHeader } = input;
|
|
39082
|
-
let protectedHeaderString;
|
|
39083
|
-
[protectedHeader, protectedHeaderString] = serializeProtectedHeader(protectedHeader);
|
|
39084
|
-
if (unprotectedHeader !== void 0) {
|
|
39085
|
-
unprotectedHeader = serializeJoseHeader(JWSInvalid, unprotectedHeader)[0];
|
|
39086
|
-
}
|
|
39087
|
-
if (!protectedHeader && !unprotectedHeader) {
|
|
38242
|
+
if (unprotectedHeader !== void 0 && (unprotectedHeader = serializeJoseHeader(JWSInvalid, unprotectedHeader)[0]), !protectedHeader && !unprotectedHeader)
|
|
39088
38243
|
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
39089
|
-
|
|
39090
|
-
if (!isDisjoint(protectedHeader, unprotectedHeader)) {
|
|
38244
|
+
if (!isDisjoint(protectedHeader, unprotectedHeader))
|
|
39091
38245
|
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
39092
|
-
}
|
|
39093
38246
|
const joseHeader = { ...protectedHeader, ...unprotectedHeader };
|
|
39094
|
-
|
|
39095
|
-
|
|
39096
|
-
|
|
39097
|
-
|
|
39098
|
-
|
|
38247
|
+
validateCritDuplicates(JWSInvalid, protectedHeader);
|
|
38248
|
+
const b64 = validateB64(protectedHeader, validateCrit(JWSInvalid, JWS_RECOGNIZED, crit, protectedHeader, joseHeader));
|
|
38249
|
+
b64 || rejectUnencoded?.();
|
|
38250
|
+
const { alg } = joseHeader;
|
|
38251
|
+
if (typeof alg != "string" || !alg)
|
|
38252
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
38253
|
+
const entry = jwsAlgorithm(alg);
|
|
38254
|
+
let payloadS = "", payloadB = payload, data;
|
|
39099
38255
|
if (b64) {
|
|
39100
|
-
const encoded = input
|
|
39101
|
-
encoded[0] ?? (encoded[0] = encode2(
|
|
39102
|
-
encoded[1] ?? (encoded[1] = encode(encoded[0]));
|
|
39103
|
-
payloadS = encoded[0];
|
|
39104
|
-
payloadB = encoded[1];
|
|
39105
|
-
} else {
|
|
39106
|
-
payloadB = input.payload;
|
|
39107
|
-
payloadS = "";
|
|
38256
|
+
const encoded = input[4];
|
|
38257
|
+
encoded ? (payloadS = encoded[0] ?? (encoded[0] = encode2(payload)), payloadB = encoded[1] ?? (encoded[1] = encode(payloadS))) : (payloadS = encode2(payload), data = encoder.encode(`${protectedHeaderString}.${payloadS}`));
|
|
39108
38258
|
}
|
|
38259
|
+
data ?? (data = concat(encode(protectedHeaderString), encode("."), payloadB));
|
|
38260
|
+
const k = await rawKey(await prepareKey(entry, key, "sign"), entry.subtle, "sign");
|
|
38261
|
+
entry.minRsaBits && checkModulusLength(entry.alg, k);
|
|
39109
38262
|
const jws = {
|
|
39110
|
-
signature: await
|
|
38263
|
+
signature: encode2(new Uint8Array(await crypto.subtle.sign(entry.signing, k, data))),
|
|
39111
38264
|
payload: payloadS
|
|
39112
38265
|
};
|
|
39113
|
-
|
|
39114
|
-
jws.protected = protectedHeaderString;
|
|
39115
|
-
}
|
|
39116
|
-
if (unprotectedHeader) {
|
|
39117
|
-
jws.header = unprotectedHeader;
|
|
39118
|
-
}
|
|
39119
|
-
return [jws, b64];
|
|
38266
|
+
return protectedHeader && (jws.protected = protectedHeaderString), unprotectedHeader && (jws.header = unprotectedHeader), [jws, b64];
|
|
39120
38267
|
}
|
|
39121
|
-
async function createCompactSignature(payload,
|
|
39122
|
-
const [protectedHeader,
|
|
39123
|
-
|
|
39124
|
-
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
39125
|
-
}
|
|
39126
|
-
const b64 = validateSignatureHeader(protectedHeader, protectedHeader, inputCrit);
|
|
39127
|
-
if (!b64)
|
|
39128
|
-
rejectUnencoded();
|
|
39129
|
-
const entry = signatureAlgorithm(protectedHeader);
|
|
39130
|
-
const encodedPayload = encode2(payload);
|
|
39131
|
-
const signature = await signSignature(protectedHeaderString, encode(encodedPayload), entry, key);
|
|
39132
|
-
return `${protectedHeaderString}.${encodedPayload}.${signature}`;
|
|
38268
|
+
async function createCompactSignature(payload, protectedHeader, crit, key, rejectUnencoded) {
|
|
38269
|
+
const [jws] = await createSignature([payload, protectedHeader, void 0, crit], key, rejectUnencoded);
|
|
38270
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
39133
38271
|
}
|
|
39134
38272
|
var init_jws_sign = __esm({
|
|
39135
38273
|
"../node_modules/jose/dist/webapi/lib/jws_sign.js"() {
|
|
39136
38274
|
init_base64url();
|
|
39137
|
-
init_signing();
|
|
39138
38275
|
init_jws_algorithms();
|
|
39139
|
-
|
|
38276
|
+
init_validate2();
|
|
39140
38277
|
init_errors();
|
|
39141
38278
|
init_buffer_utils();
|
|
39142
|
-
init_options();
|
|
39143
38279
|
init_key();
|
|
39144
38280
|
}
|
|
39145
38281
|
});
|
|
39146
38282
|
|
|
39147
38283
|
// ../node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
39148
|
-
var _payload,
|
|
38284
|
+
var _payload, _protectedHeader2, CompactSign;
|
|
39149
38285
|
var init_sign = __esm({
|
|
39150
38286
|
"../node_modules/jose/dist/webapi/jws/compact/sign.js"() {
|
|
39151
38287
|
init_jws_sign();
|
|
39152
|
-
|
|
38288
|
+
init_validate2();
|
|
39153
38289
|
CompactSign = class {
|
|
39154
38290
|
constructor(payload) {
|
|
39155
38291
|
__privateAdd(this, _payload);
|
|
39156
|
-
__privateAdd(this,
|
|
39157
|
-
|
|
39158
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
39159
|
-
}
|
|
39160
|
-
__privateSet(this, _payload, payload);
|
|
38292
|
+
__privateAdd(this, _protectedHeader2);
|
|
38293
|
+
assertUint8Array(payload, "payload"), __privateSet(this, _payload, payload);
|
|
39161
38294
|
}
|
|
39162
38295
|
setProtectedHeader(protectedHeader) {
|
|
39163
|
-
assertNotSet(__privateGet(this,
|
|
39164
|
-
__privateSet(this, _protectedHeader4, protectedHeader);
|
|
39165
|
-
return this;
|
|
38296
|
+
return assertNotSet(__privateGet(this, _protectedHeader2), "setProtectedHeader"), __privateSet(this, _protectedHeader2, protectedHeader), this;
|
|
39166
38297
|
}
|
|
39167
38298
|
async sign(key, options) {
|
|
39168
|
-
return createCompactSignature(__privateGet(this, _payload), __privateGet(this,
|
|
38299
|
+
return createCompactSignature(__privateGet(this, _payload), __privateGet(this, _protectedHeader2), options?.crit, key, () => {
|
|
39169
38300
|
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
39170
38301
|
});
|
|
39171
38302
|
}
|
|
39172
38303
|
};
|
|
39173
38304
|
_payload = new WeakMap();
|
|
39174
|
-
|
|
38305
|
+
_protectedHeader2 = new WeakMap();
|
|
39175
38306
|
}
|
|
39176
38307
|
});
|
|
39177
38308
|
|
|
39178
38309
|
// ../node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
39179
|
-
var
|
|
38310
|
+
var _input3, FlattenedSign;
|
|
39180
38311
|
var init_sign2 = __esm({
|
|
39181
38312
|
"../node_modules/jose/dist/webapi/jws/flattened/sign.js"() {
|
|
39182
38313
|
init_jws_sign();
|
|
39183
|
-
|
|
38314
|
+
init_validate2();
|
|
39184
38315
|
FlattenedSign = class {
|
|
39185
38316
|
constructor(payload) {
|
|
39186
|
-
__privateAdd(this,
|
|
39187
|
-
|
|
39188
|
-
__privateAdd(this, _unprotectedHeader3);
|
|
39189
|
-
if (!(payload instanceof Uint8Array)) {
|
|
39190
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
39191
|
-
}
|
|
39192
|
-
__privateSet(this, _payload2, payload);
|
|
38317
|
+
__privateAdd(this, _input3);
|
|
38318
|
+
assertUint8Array(payload, "payload"), __privateSet(this, _input3, [payload]);
|
|
39193
38319
|
}
|
|
39194
38320
|
setProtectedHeader(protectedHeader) {
|
|
39195
|
-
assertNotSet(__privateGet(this,
|
|
39196
|
-
__privateSet(this, _protectedHeader5, protectedHeader);
|
|
39197
|
-
return this;
|
|
38321
|
+
return assertNotSet(__privateGet(this, _input3)[1], "setProtectedHeader"), __privateGet(this, _input3)[1] = protectedHeader, this;
|
|
39198
38322
|
}
|
|
39199
38323
|
setUnprotectedHeader(unprotectedHeader) {
|
|
39200
|
-
assertNotSet(__privateGet(this,
|
|
39201
|
-
__privateSet(this, _unprotectedHeader3, unprotectedHeader);
|
|
39202
|
-
return this;
|
|
38324
|
+
return assertNotSet(__privateGet(this, _input3)[2], "setUnprotectedHeader"), __privateGet(this, _input3)[2] = unprotectedHeader, this;
|
|
39203
38325
|
}
|
|
39204
38326
|
async sign(key, options) {
|
|
39205
|
-
const
|
|
39206
|
-
|
|
39207
|
-
|
|
39208
|
-
unprotectedHeader: __privateGet(this, _unprotectedHeader3),
|
|
39209
|
-
crit: options?.crit
|
|
39210
|
-
}, key);
|
|
38327
|
+
const input = [...__privateGet(this, _input3)];
|
|
38328
|
+
input[3] = options?.crit;
|
|
38329
|
+
const [jws] = await createSignature(input, key);
|
|
39211
38330
|
return jws;
|
|
39212
38331
|
}
|
|
39213
38332
|
};
|
|
39214
|
-
|
|
39215
|
-
_protectedHeader5 = new WeakMap();
|
|
39216
|
-
_unprotectedHeader3 = new WeakMap();
|
|
38333
|
+
_input3 = new WeakMap();
|
|
39217
38334
|
}
|
|
39218
38335
|
});
|
|
39219
38336
|
|
|
39220
38337
|
// ../node_modules/jose/dist/webapi/jws/general/sign.js
|
|
39221
|
-
var _parent2, IndividualSignature,
|
|
38338
|
+
var _parent2, IndividualSignature, _payload2, _signatures, GeneralSign;
|
|
39222
38339
|
var init_sign3 = __esm({
|
|
39223
38340
|
"../node_modules/jose/dist/webapi/jws/general/sign.js"() {
|
|
39224
38341
|
init_jws_sign();
|
|
39225
38342
|
init_errors();
|
|
39226
|
-
|
|
38343
|
+
init_validate2();
|
|
39227
38344
|
IndividualSignature = class {
|
|
39228
38345
|
constructor(sig2, key, options) {
|
|
39229
38346
|
__privateAdd(this, _parent2);
|
|
39230
38347
|
__publicField(this, "state");
|
|
39231
|
-
__privateSet(this, _parent2, sig2);
|
|
39232
|
-
this.state = [void 0, void 0, key, options?.crit];
|
|
38348
|
+
__privateSet(this, _parent2, sig2), this.state = [void 0, void 0, key, options?.crit];
|
|
39233
38349
|
}
|
|
39234
38350
|
setProtectedHeader(protectedHeader) {
|
|
39235
|
-
assertNotSet(this.state[0], "setProtectedHeader");
|
|
39236
|
-
this.state[0] = protectedHeader;
|
|
39237
|
-
return this;
|
|
38351
|
+
return assertNotSet(this.state[0], "setProtectedHeader"), this.state[0] = protectedHeader, this;
|
|
39238
38352
|
}
|
|
39239
38353
|
setUnprotectedHeader(unprotectedHeader) {
|
|
39240
|
-
assertNotSet(this.state[1], "setUnprotectedHeader");
|
|
39241
|
-
this.state[1] = unprotectedHeader;
|
|
39242
|
-
return this;
|
|
38354
|
+
return assertNotSet(this.state[1], "setUnprotectedHeader"), this.state[1] = unprotectedHeader, this;
|
|
39243
38355
|
}
|
|
39244
38356
|
addSignature(...args) {
|
|
39245
38357
|
return __privateGet(this, _parent2).addSignature(...args);
|
|
@@ -39254,163 +38366,116 @@ return true;`);
|
|
|
39254
38366
|
_parent2 = new WeakMap();
|
|
39255
38367
|
GeneralSign = class {
|
|
39256
38368
|
constructor(payload) {
|
|
39257
|
-
__privateAdd(this,
|
|
38369
|
+
__privateAdd(this, _payload2);
|
|
39258
38370
|
__privateAdd(this, _signatures, []);
|
|
39259
|
-
__privateSet(this,
|
|
38371
|
+
__privateSet(this, _payload2, payload);
|
|
39260
38372
|
}
|
|
39261
38373
|
addSignature(key, options) {
|
|
39262
38374
|
const signature = new IndividualSignature(this, key, options);
|
|
39263
|
-
__privateGet(this, _signatures).push(signature);
|
|
39264
|
-
return signature;
|
|
38375
|
+
return __privateGet(this, _signatures).push(signature), signature;
|
|
39265
38376
|
}
|
|
39266
38377
|
async sign() {
|
|
39267
|
-
if (!__privateGet(this, _signatures).length)
|
|
38378
|
+
if (!__privateGet(this, _signatures).length)
|
|
39268
38379
|
throw new JWSInvalid("at least one signature must be added");
|
|
39269
|
-
|
|
39270
|
-
if (!(__privateGet(this, _payload3) instanceof Uint8Array)) {
|
|
39271
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
39272
|
-
}
|
|
38380
|
+
assertUint8Array(__privateGet(this, _payload2), "payload");
|
|
39273
38381
|
const jws = {
|
|
39274
38382
|
signatures: [],
|
|
39275
38383
|
payload: ""
|
|
39276
|
-
};
|
|
39277
|
-
const encoded = [];
|
|
38384
|
+
}, encoded = [];
|
|
39278
38385
|
let b64;
|
|
39279
|
-
for (
|
|
39280
|
-
const signature = __privateGet(this,
|
|
39281
|
-
|
|
39282
|
-
|
|
39283
|
-
|
|
39284
|
-
protectedHeader,
|
|
39285
|
-
unprotectedHeader,
|
|
39286
|
-
crit,
|
|
39287
|
-
encoded
|
|
39288
|
-
}, key);
|
|
39289
|
-
if (b64 === void 0) {
|
|
39290
|
-
b64 = signatureB64;
|
|
39291
|
-
jws.payload = payload;
|
|
39292
|
-
} else if (b64 !== signatureB64) {
|
|
38386
|
+
for (const signature of __privateGet(this, _signatures)) {
|
|
38387
|
+
const [protectedHeader, unprotectedHeader, key, crit] = signature.state, [{ payload, ...rest }, signatureB64] = await createSignature([__privateGet(this, _payload2), protectedHeader, unprotectedHeader, crit, encoded], key);
|
|
38388
|
+
if (b64 === void 0)
|
|
38389
|
+
b64 = signatureB64, jws.payload = payload;
|
|
38390
|
+
else if (b64 !== signatureB64)
|
|
39293
38391
|
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
39294
|
-
}
|
|
39295
38392
|
jws.signatures.push(rest);
|
|
39296
38393
|
}
|
|
39297
38394
|
return jws;
|
|
39298
38395
|
}
|
|
39299
38396
|
};
|
|
39300
|
-
|
|
38397
|
+
_payload2 = new WeakMap();
|
|
39301
38398
|
_signatures = new WeakMap();
|
|
39302
38399
|
}
|
|
39303
38400
|
});
|
|
39304
38401
|
|
|
39305
38402
|
// ../node_modules/jose/dist/webapi/jwt/sign.js
|
|
39306
|
-
var SignJWT_base,
|
|
38403
|
+
var SignJWT_base, _protectedHeader3, SignJWT;
|
|
39307
38404
|
var init_sign4 = __esm({
|
|
39308
38405
|
"../node_modules/jose/dist/webapi/jwt/sign.js"() {
|
|
39309
38406
|
init_jws_sign();
|
|
39310
38407
|
init_errors();
|
|
39311
38408
|
init_jwt_claims_set();
|
|
39312
|
-
|
|
38409
|
+
init_validate2();
|
|
39313
38410
|
SignJWT_base = JWTClaimsBuilder;
|
|
39314
38411
|
SignJWT = class extends SignJWT_base {
|
|
39315
38412
|
constructor() {
|
|
39316
38413
|
super(...arguments);
|
|
39317
|
-
__privateAdd(this,
|
|
38414
|
+
__privateAdd(this, _protectedHeader3);
|
|
39318
38415
|
}
|
|
39319
38416
|
setProtectedHeader(protectedHeader) {
|
|
39320
|
-
assertNotSet(__privateGet(this,
|
|
39321
|
-
__privateSet(this, _protectedHeader6, protectedHeader);
|
|
39322
|
-
return this;
|
|
38417
|
+
return assertNotSet(__privateGet(this, _protectedHeader3), "setProtectedHeader"), __privateSet(this, _protectedHeader3, protectedHeader), this;
|
|
39323
38418
|
}
|
|
39324
38419
|
async sign(key, options) {
|
|
39325
|
-
return createCompactSignature(jwtData(this), __privateGet(this,
|
|
38420
|
+
return createCompactSignature(jwtData(this), __privateGet(this, _protectedHeader3), options?.crit, key, () => {
|
|
39326
38421
|
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
39327
38422
|
});
|
|
39328
38423
|
}
|
|
39329
38424
|
};
|
|
39330
|
-
|
|
38425
|
+
_protectedHeader3 = new WeakMap();
|
|
39331
38426
|
}
|
|
39332
38427
|
});
|
|
39333
38428
|
|
|
39334
38429
|
// ../node_modules/jose/dist/webapi/jwt/encrypt.js
|
|
39335
|
-
var EncryptJWT_base,
|
|
38430
|
+
var EncryptJWT_base, _input4, _replicateIssuerAsHeader, _replicateSubjectAsHeader, _replicateAudienceAsHeader, EncryptJWT;
|
|
39336
38431
|
var init_encrypt4 = __esm({
|
|
39337
38432
|
"../node_modules/jose/dist/webapi/jwt/encrypt.js"() {
|
|
39338
38433
|
init_jwe_encrypt();
|
|
39339
38434
|
init_jwt_claims_set();
|
|
39340
|
-
|
|
38435
|
+
init_validate2();
|
|
39341
38436
|
EncryptJWT_base = JWTClaimsBuilder;
|
|
39342
38437
|
EncryptJWT = class extends EncryptJWT_base {
|
|
39343
38438
|
constructor() {
|
|
39344
38439
|
super(...arguments);
|
|
39345
|
-
__privateAdd(this,
|
|
39346
|
-
__privateAdd(this, _iv3);
|
|
39347
|
-
__privateAdd(this, _keyManagementParameters3);
|
|
39348
|
-
__privateAdd(this, _protectedHeader7);
|
|
38440
|
+
__privateAdd(this, _input4, [void 0]);
|
|
39349
38441
|
__privateAdd(this, _replicateIssuerAsHeader);
|
|
39350
38442
|
__privateAdd(this, _replicateSubjectAsHeader);
|
|
39351
38443
|
__privateAdd(this, _replicateAudienceAsHeader);
|
|
39352
38444
|
}
|
|
39353
38445
|
setProtectedHeader(protectedHeader) {
|
|
39354
|
-
assertNotSet(__privateGet(this,
|
|
39355
|
-
__privateSet(this, _protectedHeader7, protectedHeader);
|
|
39356
|
-
return this;
|
|
38446
|
+
return assertNotSet(__privateGet(this, _input4)[1], "setProtectedHeader"), __privateGet(this, _input4)[1] = protectedHeader, this;
|
|
39357
38447
|
}
|
|
39358
38448
|
setKeyManagementParameters(parameters) {
|
|
39359
|
-
assertNotSet(__privateGet(this,
|
|
39360
|
-
__privateSet(this, _keyManagementParameters3, parameters);
|
|
39361
|
-
return this;
|
|
38449
|
+
return assertNotSet(__privateGet(this, _input4)[7], "setKeyManagementParameters"), __privateGet(this, _input4)[7] = parameters, this;
|
|
39362
38450
|
}
|
|
39363
38451
|
setContentEncryptionKey(cek) {
|
|
39364
|
-
assertNotSet(__privateGet(this,
|
|
39365
|
-
__privateSet(this, _cek3, cek);
|
|
39366
|
-
return this;
|
|
38452
|
+
return assertNotSet(__privateGet(this, _input4)[5], "setContentEncryptionKey"), __privateGet(this, _input4)[5] = cek, this;
|
|
39367
38453
|
}
|
|
39368
38454
|
setInitializationVector(iv) {
|
|
39369
|
-
assertNotSet(__privateGet(this,
|
|
39370
|
-
__privateSet(this, _iv3, iv);
|
|
39371
|
-
return this;
|
|
38455
|
+
return assertNotSet(__privateGet(this, _input4)[6], "setInitializationVector"), __privateGet(this, _input4)[6] = iv, this;
|
|
39372
38456
|
}
|
|
39373
38457
|
replicateIssuerAsHeader() {
|
|
39374
|
-
__privateSet(this, _replicateIssuerAsHeader, true);
|
|
39375
|
-
return this;
|
|
38458
|
+
return __privateSet(this, _replicateIssuerAsHeader, true), this;
|
|
39376
38459
|
}
|
|
39377
38460
|
replicateSubjectAsHeader() {
|
|
39378
|
-
__privateSet(this, _replicateSubjectAsHeader, true);
|
|
39379
|
-
return this;
|
|
38461
|
+
return __privateSet(this, _replicateSubjectAsHeader, true), this;
|
|
39380
38462
|
}
|
|
39381
38463
|
replicateAudienceAsHeader() {
|
|
39382
|
-
__privateSet(this, _replicateAudienceAsHeader, true);
|
|
39383
|
-
return this;
|
|
38464
|
+
return __privateSet(this, _replicateAudienceAsHeader, true), this;
|
|
39384
38465
|
}
|
|
39385
38466
|
async encrypt(key, options) {
|
|
39386
38467
|
const plaintext = jwtData(this);
|
|
39387
|
-
|
|
39388
|
-
|
|
39389
|
-
|
|
39390
|
-
|
|
39391
|
-
|
|
39392
|
-
|
|
39393
|
-
|
|
39394
|
-
|
|
39395
|
-
|
|
39396
|
-
|
|
39397
|
-
|
|
39398
|
-
void 0,
|
|
39399
|
-
void 0,
|
|
39400
|
-
void 0,
|
|
39401
|
-
__privateGet(this, _cek3),
|
|
39402
|
-
__privateGet(this, _iv3),
|
|
39403
|
-
__privateGet(this, _keyManagementParameters3),
|
|
39404
|
-
void 0,
|
|
39405
|
-
false
|
|
39406
|
-
], key, options);
|
|
39407
|
-
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
39408
|
-
}
|
|
39409
|
-
};
|
|
39410
|
-
_cek3 = new WeakMap();
|
|
39411
|
-
_iv3 = new WeakMap();
|
|
39412
|
-
_keyManagementParameters3 = new WeakMap();
|
|
39413
|
-
_protectedHeader7 = new WeakMap();
|
|
38468
|
+
__privateGet(this, _input4)[1] && (__privateGet(this, _replicateIssuerAsHeader) || __privateGet(this, _replicateSubjectAsHeader) || __privateGet(this, _replicateAudienceAsHeader)) && (__privateGet(this, _input4)[1] = {
|
|
38469
|
+
...__privateGet(this, _input4)[1],
|
|
38470
|
+
iss: __privateGet(this, _replicateIssuerAsHeader) ? jwtClaim(this, "iss") : void 0,
|
|
38471
|
+
sub: __privateGet(this, _replicateSubjectAsHeader) ? jwtClaim(this, "sub") : void 0,
|
|
38472
|
+
aud: __privateGet(this, _replicateAudienceAsHeader) ? jwtClaim(this, "aud") : void 0
|
|
38473
|
+
});
|
|
38474
|
+
const input = [...__privateGet(this, _input4)];
|
|
38475
|
+
return input[0] = plaintext, compactJWE(await createJWE(input, key, options));
|
|
38476
|
+
}
|
|
38477
|
+
};
|
|
38478
|
+
_input4 = new WeakMap();
|
|
39414
38479
|
_replicateIssuerAsHeader = new WeakMap();
|
|
39415
38480
|
_replicateSubjectAsHeader = new WeakMap();
|
|
39416
38481
|
_replicateAudienceAsHeader = new WeakMap();
|
|
@@ -39422,7 +38487,7 @@ return true;`);
|
|
|
39422
38487
|
throw new JOSENotSupported(`Invalid or unsupported ${source} value`);
|
|
39423
38488
|
}
|
|
39424
38489
|
function keyAlgorithm(alg, source) {
|
|
39425
|
-
return (typeof alg
|
|
38490
|
+
return (typeof alg == "string" ? JWS[alg] ?? JWE[alg] : void 0) ?? unsupportedAlg(source);
|
|
39426
38491
|
}
|
|
39427
38492
|
var algArgument;
|
|
39428
38493
|
var init_key_algorithm = __esm({
|
|
@@ -39434,44 +38499,22 @@ return true;`);
|
|
|
39434
38499
|
}
|
|
39435
38500
|
});
|
|
39436
38501
|
|
|
39437
|
-
// ../node_modules/jose/dist/webapi/lib/key_options.js
|
|
39438
|
-
function validateExtractableOption(extractable) {
|
|
39439
|
-
if (extractable !== void 0 && typeof extractable !== "boolean") {
|
|
39440
|
-
throw new TypeError('"extractable" option must be a boolean');
|
|
39441
|
-
}
|
|
39442
|
-
return extractable;
|
|
39443
|
-
}
|
|
39444
|
-
var init_key_options = __esm({
|
|
39445
|
-
"../node_modules/jose/dist/webapi/lib/key_options.js"() {
|
|
39446
|
-
}
|
|
39447
|
-
});
|
|
39448
|
-
|
|
39449
38502
|
// ../node_modules/jose/dist/webapi/lib/asn1.js
|
|
39450
38503
|
function parseKeyHeader(state, keyFormat) {
|
|
39451
|
-
expectTag(state, 48, `Invalid ${keyFormat === "spki" ? "SPKI" : "PKCS#8"} structure`)
|
|
39452
|
-
parseLength(state);
|
|
39453
|
-
if (keyFormat === "pkcs8") {
|
|
38504
|
+
if (expectTag(state, 48, `Invalid ${keyFormat === "spki" ? "SPKI" : "PKCS#8"} structure`), parseLength(state), keyFormat === "pkcs8") {
|
|
39454
38505
|
expectTag(state, 2, "Expected version field");
|
|
39455
38506
|
const length = parseLength(state);
|
|
39456
38507
|
state.pos += length;
|
|
39457
38508
|
}
|
|
39458
|
-
expectTag(state, 48, "Expected algorithm identifier");
|
|
39459
|
-
parseLength(state);
|
|
38509
|
+
expectTag(state, 48, "Expected algorithm identifier"), parseLength(state);
|
|
39460
38510
|
}
|
|
39461
38511
|
function spkiFromX509(buf) {
|
|
39462
38512
|
const state = createASN1State(buf);
|
|
39463
38513
|
expectTag(state, 48, "Invalid certificate structure");
|
|
39464
38514
|
const certificateLength = parseLength(state);
|
|
39465
|
-
if (certificateLength < 0 || state.pos + certificateLength > state.data.length)
|
|
38515
|
+
if (certificateLength < 0 || state.pos + certificateLength > state.data.length)
|
|
39466
38516
|
throw new Error("Unexpected end of ASN.1 input");
|
|
39467
|
-
|
|
39468
|
-
expectTag(state, 48, "Invalid tbsCertificate structure");
|
|
39469
|
-
parseLength(state);
|
|
39470
|
-
if (buf[state.pos] === 160) {
|
|
39471
|
-
skipElement(state, 6);
|
|
39472
|
-
} else {
|
|
39473
|
-
skipElement(state, 5);
|
|
39474
|
-
}
|
|
38517
|
+
expectTag(state, 48, "Invalid tbsCertificate structure"), parseLength(state), buf[state.pos] === 160 ? skipElement(state, 6) : skipElement(state, 5);
|
|
39475
38518
|
const spkiStart = state.pos;
|
|
39476
38519
|
expectTag(state, 48, "Invalid SPKI structure");
|
|
39477
38520
|
const spkiContentLen = parseLength(state);
|
|
@@ -39480,34 +38523,29 @@ return true;`);
|
|
|
39480
38523
|
var formatPEM, genericExport, toSPKI, toPKCS8, bytesEqual, createASN1State, readByte, parseLength, skipElement, expectTag, getSubarray, parseAlgorithmOID, parseECAlgorithmIdentifier, genericImport, processPEMData, fromPKCS8, fromSPKI, fromX509;
|
|
39481
38524
|
var init_asn1 = __esm({
|
|
39482
38525
|
"../node_modules/jose/dist/webapi/lib/asn1.js"() {
|
|
39483
|
-
|
|
39484
|
-
|
|
38526
|
+
init_key();
|
|
38527
|
+
init_buffer_utils();
|
|
39485
38528
|
init_errors();
|
|
39486
38529
|
init_key_algorithm();
|
|
39487
|
-
init_is_key_like();
|
|
39488
|
-
init_key_options();
|
|
39489
38530
|
formatPEM = (b64, descriptor) => {
|
|
39490
|
-
const newlined = (b64.match(/.{1,64}/g) || []).join(
|
|
38531
|
+
const newlined = (b64.match(/.{1,64}/g) || []).join(`
|
|
38532
|
+
`);
|
|
39491
38533
|
return `-----BEGIN ${descriptor}-----
|
|
39492
38534
|
${newlined}
|
|
39493
38535
|
-----END ${descriptor}-----`;
|
|
39494
38536
|
};
|
|
39495
38537
|
genericExport = async (keyType, keyFormat, key) => {
|
|
39496
38538
|
if (isKeyObject(key)) {
|
|
39497
|
-
if (key.type !== keyType)
|
|
38539
|
+
if (key.type !== keyType)
|
|
39498
38540
|
throw new TypeError(`key is not a ${keyType} key`);
|
|
39499
|
-
}
|
|
39500
38541
|
return key.export({ format: "pem", type: keyFormat });
|
|
39501
38542
|
}
|
|
39502
|
-
if (!isCryptoKey(key))
|
|
38543
|
+
if (!isCryptoKey(key))
|
|
39503
38544
|
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject"));
|
|
39504
|
-
|
|
39505
|
-
if (!key.extractable) {
|
|
38545
|
+
if (!key.extractable)
|
|
39506
38546
|
throw new TypeError("CryptoKey is not extractable");
|
|
39507
|
-
|
|
39508
|
-
if (key.type !== keyType) {
|
|
38547
|
+
if (key.type !== keyType)
|
|
39509
38548
|
throw new TypeError(`key is not a ${keyType} key`);
|
|
39510
|
-
}
|
|
39511
38549
|
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
39512
38550
|
};
|
|
39513
38551
|
toSPKI = (key) => genericExport("public", "spki", key);
|
|
@@ -39515,18 +38553,16 @@ ${newlined}
|
|
|
39515
38553
|
bytesEqual = (a, b) => {
|
|
39516
38554
|
if (a.byteLength !== b.length)
|
|
39517
38555
|
return false;
|
|
39518
|
-
for (let i = 0; i < a.byteLength; i++)
|
|
38556
|
+
for (let i = 0; i < a.byteLength; i++)
|
|
39519
38557
|
if (a[i] !== b[i])
|
|
39520
38558
|
return false;
|
|
39521
|
-
}
|
|
39522
38559
|
return true;
|
|
39523
38560
|
};
|
|
39524
38561
|
createASN1State = (data) => ({ data, pos: 0 });
|
|
39525
38562
|
readByte = (state) => {
|
|
39526
38563
|
const byte = state.data[state.pos++];
|
|
39527
|
-
if (byte === void 0)
|
|
38564
|
+
if (byte === void 0)
|
|
39528
38565
|
throw new Error("Unexpected end of ASN.1 input");
|
|
39529
|
-
}
|
|
39530
38566
|
return byte;
|
|
39531
38567
|
};
|
|
39532
38568
|
parseLength = (state) => {
|
|
@@ -39534,32 +38570,28 @@ ${newlined}
|
|
|
39534
38570
|
if (first & 128) {
|
|
39535
38571
|
const lengthOfLen = first & 127;
|
|
39536
38572
|
let length = 0;
|
|
39537
|
-
for (let i = 0; i < lengthOfLen; i++)
|
|
38573
|
+
for (let i = 0; i < lengthOfLen; i++)
|
|
39538
38574
|
length = length << 8 | readByte(state);
|
|
39539
|
-
}
|
|
39540
38575
|
return length;
|
|
39541
38576
|
}
|
|
39542
38577
|
return first;
|
|
39543
38578
|
};
|
|
39544
38579
|
skipElement = (state, count = 1) => {
|
|
39545
|
-
|
|
38580
|
+
for (; count-- > 0; ) {
|
|
39546
38581
|
state.pos++;
|
|
39547
38582
|
const length = parseLength(state);
|
|
39548
38583
|
state.pos += length;
|
|
39549
38584
|
}
|
|
39550
38585
|
};
|
|
39551
38586
|
expectTag = (state, expectedTag, errorMessage) => {
|
|
39552
|
-
if (readByte(state) !== expectedTag)
|
|
38587
|
+
if (readByte(state) !== expectedTag)
|
|
39553
38588
|
throw new Error(errorMessage);
|
|
39554
|
-
}
|
|
39555
38589
|
};
|
|
39556
38590
|
getSubarray = (state, length) => {
|
|
39557
|
-
if (length < 0 || state.pos + length > state.data.length)
|
|
38591
|
+
if (length < 0 || state.pos + length > state.data.length)
|
|
39558
38592
|
throw new Error("Unexpected end of ASN.1 input");
|
|
39559
|
-
}
|
|
39560
38593
|
const result = state.data.subarray(state.pos, state.pos + length);
|
|
39561
|
-
state.pos += length;
|
|
39562
|
-
return result;
|
|
38594
|
+
return state.pos += length, result;
|
|
39563
38595
|
};
|
|
39564
38596
|
parseAlgorithmOID = (state) => {
|
|
39565
38597
|
expectTag(state, 6, "Expected algorithm OID");
|
|
@@ -39568,15 +38600,12 @@ ${newlined}
|
|
|
39568
38600
|
};
|
|
39569
38601
|
parseECAlgorithmIdentifier = (state) => {
|
|
39570
38602
|
const algOid = parseAlgorithmOID(state);
|
|
39571
|
-
if (bytesEqual(algOid, [43, 101, 110]))
|
|
38603
|
+
if (bytesEqual(algOid, [43, 101, 110]))
|
|
39572
38604
|
return "X25519";
|
|
39573
|
-
|
|
39574
|
-
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
|
|
38605
|
+
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1]))
|
|
39575
38606
|
throw new Error("Unsupported key algorithm");
|
|
39576
|
-
}
|
|
39577
38607
|
expectTag(state, 6, "Expected curve OID");
|
|
39578
|
-
const curveOidLen = parseLength(state);
|
|
39579
|
-
const curveOid = getSubarray(state, curveOidLen);
|
|
38608
|
+
const curveOidLen = parseLength(state), curveOid = getSubarray(state, curveOidLen);
|
|
39580
38609
|
if (bytesEqual(curveOid, [42, 134, 72, 206, 61, 3, 1, 7]))
|
|
39581
38610
|
return "P-256";
|
|
39582
38611
|
if (bytesEqual(curveOid, [43, 129, 4, 0, 34]))
|
|
@@ -39586,29 +38615,22 @@ ${newlined}
|
|
|
39586
38615
|
throw new Error("Unsupported named curve");
|
|
39587
38616
|
};
|
|
39588
38617
|
genericImport = async (keyFormat, keyData, alg, options) => {
|
|
39589
|
-
const extractable = validateExtractableOption(options?.extractable);
|
|
39590
|
-
|
|
39591
|
-
if (entry.secret) {
|
|
39592
|
-
unsupportedAlg(algArgument);
|
|
39593
|
-
}
|
|
38618
|
+
const extractable = validateExtractableOption(options?.extractable), entry = keyAlgorithm(alg, algArgument);
|
|
38619
|
+
entry.secret && unsupportedAlg(algArgument);
|
|
39594
38620
|
const isPublic = keyFormat === "spki";
|
|
39595
38621
|
let algorithm;
|
|
39596
|
-
if (entry.resolve)
|
|
38622
|
+
if (entry.resolve)
|
|
39597
38623
|
try {
|
|
39598
38624
|
const state = createASN1State(keyData);
|
|
39599
|
-
parseKeyHeader(state, keyFormat);
|
|
39600
|
-
algorithm = entry.resolve({ crv: parseECAlgorithmIdentifier(state) });
|
|
38625
|
+
parseKeyHeader(state, keyFormat), algorithm = entry.resolve({ crv: parseECAlgorithmIdentifier(state) });
|
|
39601
38626
|
} catch {
|
|
39602
38627
|
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
39603
38628
|
}
|
|
39604
|
-
|
|
38629
|
+
else
|
|
39605
38630
|
algorithm = entry.subtle;
|
|
39606
|
-
}
|
|
39607
38631
|
return crypto.subtle.importKey(keyFormat, keyData, algorithm, extractable ?? isPublic, entry.usages[isPublic ? 0 : 1]);
|
|
39608
38632
|
};
|
|
39609
|
-
processPEMData = (pem, pattern) =>
|
|
39610
|
-
return decodeBase64(pem.replace(pattern, ""));
|
|
39611
|
-
};
|
|
38633
|
+
processPEMData = (pem, pattern) => decodeBase64(pem.replace(pattern, ""));
|
|
39612
38634
|
fromPKCS8 = (pem, alg, options) => {
|
|
39613
38635
|
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
39614
38636
|
return genericImport("pkcs8", keyData, alg, options);
|
|
@@ -39631,51 +38653,38 @@ ${newlined}
|
|
|
39631
38653
|
});
|
|
39632
38654
|
|
|
39633
38655
|
// ../node_modules/jose/dist/webapi/key/export.js
|
|
39634
|
-
function
|
|
39635
|
-
return
|
|
38656
|
+
function exportSPKI(key) {
|
|
38657
|
+
return toSPKI(key);
|
|
38658
|
+
}
|
|
38659
|
+
function exportPKCS8(key) {
|
|
38660
|
+
return toPKCS8(key);
|
|
39636
38661
|
}
|
|
39637
|
-
async function
|
|
39638
|
-
if (isKeyObject(key))
|
|
39639
|
-
if (key.type === "secret")
|
|
38662
|
+
async function exportJWK(key) {
|
|
38663
|
+
if (isKeyObject(key))
|
|
38664
|
+
if (key.type === "secret")
|
|
39640
38665
|
key = key.export();
|
|
39641
|
-
|
|
38666
|
+
else
|
|
39642
38667
|
return key.export({ format: "jwk" });
|
|
39643
|
-
|
|
39644
|
-
}
|
|
39645
|
-
if (key instanceof Uint8Array) {
|
|
38668
|
+
if (key instanceof Uint8Array)
|
|
39646
38669
|
return {
|
|
39647
38670
|
kty: "oct",
|
|
39648
38671
|
k: encode2(key)
|
|
39649
38672
|
};
|
|
39650
|
-
|
|
39651
|
-
if (!isCryptoKey(key)) {
|
|
38673
|
+
if (!isCryptoKey(key))
|
|
39652
38674
|
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
39653
|
-
|
|
39654
|
-
if (!key.extractable) {
|
|
38675
|
+
if (!key.extractable)
|
|
39655
38676
|
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
39656
|
-
|
|
39657
|
-
|
|
39658
|
-
|
|
39659
|
-
;
|
|
39660
|
-
jwk.alg = alg;
|
|
39661
|
-
}
|
|
38677
|
+
const jwk = await crypto.subtle.exportKey("jwk", key);
|
|
38678
|
+
delete jwk.ext, delete jwk.key_ops, delete jwk.use, jwk.kty !== "AKP" && delete jwk.alg;
|
|
38679
|
+
for (const parameter of Object.keys(jwk))
|
|
38680
|
+
jwk[parameter] === void 0 && delete jwk[parameter];
|
|
39662
38681
|
return jwk;
|
|
39663
38682
|
}
|
|
39664
|
-
function exportSPKI(key) {
|
|
39665
|
-
return toSPKI(key);
|
|
39666
|
-
}
|
|
39667
|
-
function exportPKCS8(key) {
|
|
39668
|
-
return toPKCS8(key);
|
|
39669
|
-
}
|
|
39670
|
-
function exportJWK(key) {
|
|
39671
|
-
return keyToJWK(key);
|
|
39672
|
-
}
|
|
39673
38683
|
var init_export = __esm({
|
|
39674
38684
|
"../node_modules/jose/dist/webapi/key/export.js"() {
|
|
39675
38685
|
init_asn1();
|
|
39676
|
-
|
|
38686
|
+
init_key();
|
|
39677
38687
|
init_base64url();
|
|
39678
|
-
init_is_key_like();
|
|
39679
38688
|
}
|
|
39680
38689
|
});
|
|
39681
38690
|
|
|
@@ -39683,46 +38692,31 @@ ${newlined}
|
|
|
39683
38692
|
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
39684
38693
|
let jwk;
|
|
39685
38694
|
if (isObject(key)) {
|
|
39686
|
-
jwk = snapshotJwk(key)
|
|
39687
|
-
if (typeof jwk.kty !== "string") {
|
|
38695
|
+
if (jwk = snapshotJwk(key), typeof jwk.kty != "string")
|
|
39688
38696
|
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
39689
|
-
|
|
39690
|
-
} else if (isKeyLike(key)) {
|
|
38697
|
+
} else if (isKeyLike(key))
|
|
39691
38698
|
jwk = snapshotJwk(await exportJWK(key));
|
|
39692
|
-
|
|
38699
|
+
else
|
|
39693
38700
|
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
39694
|
-
|
|
39695
|
-
digestAlgorithm ?? (digestAlgorithm = "sha256");
|
|
39696
|
-
if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") {
|
|
38701
|
+
if (digestAlgorithm ?? (digestAlgorithm = "sha256"), digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512")
|
|
39697
38702
|
throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
|
|
39698
|
-
}
|
|
39699
38703
|
let components;
|
|
39700
38704
|
switch (jwk.kty) {
|
|
39701
38705
|
case "AKP":
|
|
39702
|
-
check(jwk.alg, '"alg" (Algorithm) Parameter');
|
|
39703
|
-
check(jwk.pub, '"pub" (Public key) Parameter');
|
|
39704
|
-
components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
|
|
38706
|
+
check(jwk.alg, '"alg" (Algorithm) Parameter'), check(jwk.pub, '"pub" (Public key) Parameter'), components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
|
|
39705
38707
|
break;
|
|
39706
38708
|
case "EC":
|
|
39707
|
-
check(jwk.crv, '"crv" (Curve) Parameter');
|
|
39708
|
-
check(jwk.x, '"x" (X Coordinate) Parameter');
|
|
39709
|
-
check(jwk.y, '"y" (Y Coordinate) Parameter');
|
|
39710
|
-
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
38709
|
+
check(jwk.crv, '"crv" (Curve) Parameter'), check(jwk.x, '"x" (X Coordinate) Parameter'), check(jwk.y, '"y" (Y Coordinate) Parameter'), components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
39711
38710
|
break;
|
|
39712
38711
|
case "OKP":
|
|
39713
|
-
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
|
|
39714
|
-
check(jwk.x, '"x" (Public Key) Parameter');
|
|
39715
|
-
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
38712
|
+
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter'), check(jwk.x, '"x" (Public Key) Parameter'), components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
39716
38713
|
break;
|
|
39717
38714
|
case "RSA":
|
|
39718
|
-
check(jwk.e, '"e" (Exponent) Parameter');
|
|
39719
|
-
check(jwk.n, '"n" (Modulus) Parameter');
|
|
39720
|
-
components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
38715
|
+
check(jwk.e, '"e" (Exponent) Parameter'), check(jwk.n, '"n" (Modulus) Parameter'), components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
39721
38716
|
break;
|
|
39722
38717
|
case "oct":
|
|
39723
|
-
if (typeof jwk.k
|
|
38718
|
+
if (typeof jwk.k != "string")
|
|
39724
38719
|
throw new JWKInvalid('"k" (Key Value) Parameter missing or invalid');
|
|
39725
|
-
}
|
|
39726
38720
|
components = { k: jwk.k, kty: jwk.kty };
|
|
39727
38721
|
break;
|
|
39728
38722
|
default:
|
|
@@ -39739,19 +38733,15 @@ ${newlined}
|
|
|
39739
38733
|
var check;
|
|
39740
38734
|
var init_thumbprint = __esm({
|
|
39741
38735
|
"../node_modules/jose/dist/webapi/jwk/thumbprint.js"() {
|
|
39742
|
-
|
|
38736
|
+
init_buffer_utils();
|
|
39743
38737
|
init_base64url();
|
|
39744
38738
|
init_errors();
|
|
39745
|
-
|
|
39746
|
-
|
|
39747
|
-
init_type_checks();
|
|
38739
|
+
init_key();
|
|
38740
|
+
init_validate2();
|
|
39748
38741
|
init_export();
|
|
39749
|
-
init_invalid_key_input();
|
|
39750
|
-
init_jwk_metadata();
|
|
39751
38742
|
check = (value, description) => {
|
|
39752
|
-
if (typeof value
|
|
38743
|
+
if (typeof value != "string" || !value)
|
|
39753
38744
|
throw new JWKInvalid(`${description} missing or invalid`);
|
|
39754
|
-
}
|
|
39755
38745
|
};
|
|
39756
38746
|
}
|
|
39757
38747
|
});
|
|
@@ -39762,9 +38752,8 @@ ${newlined}
|
|
|
39762
38752
|
...protectedHeader,
|
|
39763
38753
|
...token?.header
|
|
39764
38754
|
};
|
|
39765
|
-
if (!isObject(joseHeader.jwk))
|
|
38755
|
+
if (!isObject(joseHeader.jwk))
|
|
39766
38756
|
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
|
|
39767
|
-
}
|
|
39768
38757
|
let jwk;
|
|
39769
38758
|
try {
|
|
39770
38759
|
jwk = normalizeJwk(joseHeader.jwk);
|
|
@@ -39772,45 +38761,42 @@ ${newlined}
|
|
|
39772
38761
|
throw new JWSInvalid("Invalid Embedded JWK", { cause });
|
|
39773
38762
|
}
|
|
39774
38763
|
const entry = jwsAlgorithm(joseHeader.alg);
|
|
39775
|
-
if (jwk.use !== void 0 && jwk.use !== "sig")
|
|
38764
|
+
if (jwk.use !== void 0 && jwk.use !== "sig")
|
|
39776
38765
|
throw new JWSInvalid('Invalid Embedded JWK, its "use" must be "sig" when present');
|
|
39777
|
-
|
|
39778
|
-
if (jwk.alg !== void 0 && jwk.alg !== entry.alg) {
|
|
38766
|
+
if (jwk.alg !== void 0 && jwk.alg !== entry.alg)
|
|
39779
38767
|
throw new JWSInvalid(`Invalid Embedded JWK, its "alg" must be "${entry.alg}" when present`);
|
|
39780
|
-
|
|
39781
|
-
|
|
39782
|
-
if (key.type !== "public") {
|
|
38768
|
+
const key = await jwkToKey(entry, jwk, true);
|
|
38769
|
+
if (key.type !== "public")
|
|
39783
38770
|
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
|
|
39784
|
-
}
|
|
39785
38771
|
return key;
|
|
39786
38772
|
}
|
|
39787
38773
|
var init_embedded = __esm({
|
|
39788
38774
|
"../node_modules/jose/dist/webapi/jwk/embedded.js"() {
|
|
39789
|
-
|
|
38775
|
+
init_key();
|
|
39790
38776
|
init_jws_algorithms();
|
|
39791
|
-
|
|
38777
|
+
init_validate2();
|
|
39792
38778
|
init_errors();
|
|
39793
|
-
init_jwk_metadata();
|
|
39794
38779
|
}
|
|
39795
38780
|
});
|
|
39796
38781
|
|
|
39797
38782
|
// ../node_modules/jose/dist/webapi/jwks/local.js
|
|
39798
38783
|
function isUsableJWK(jwk, entry, alg, kid) {
|
|
39799
|
-
const { kty, key_ops, ext, kid: jwkKid, alg: jwkAlg, use, crv } =
|
|
39800
|
-
|
|
39801
|
-
return (ext === void 0 || typeof ext === "boolean") && (keyOps === void 0 || Array.isArray(keyOps) && keyOps.every((operation, index) => typeof operation === "string" && keyOps.indexOf(operation) === index) && keyOps.includes("verify")) && entry.kty.includes(kty) && (kid === void 0 || typeof kid === "string" && kid === jwkKid) && (jwkAlg === void 0 ? kty !== "AKP" : alg === jwkAlg) && (use === void 0 || use === "sig") && (!entry.crv || crv === entry.crv);
|
|
38784
|
+
const { kty, key_ops: keyOps, ext, kid: jwkKid, alg: jwkAlg, use, crv } = jwk;
|
|
38785
|
+
return (ext === void 0 || typeof ext == "boolean") && (keyOps === void 0 || Array.isArray(keyOps) && keyOps.every((operation, index) => typeof operation == "string" && keyOps.indexOf(operation) === index) && keyOps.includes("verify")) && entry.kty.includes(kty) && (kid === void 0 || typeof kid == "string" && kid === jwkKid) && (jwkAlg === void 0 ? kty !== "AKP" : alg === jwkAlg) && (use === void 0 || use === "sig") && (!entry.crv || crv === entry.crv);
|
|
39802
38786
|
}
|
|
39803
38787
|
async function importWithAlgCache(cache2, jwk, entry) {
|
|
39804
|
-
const
|
|
39805
|
-
|
|
39806
|
-
|
|
39807
|
-
|
|
39808
|
-
|
|
39809
|
-
|
|
39810
|
-
}
|
|
39811
|
-
|
|
38788
|
+
const cached = cache2.get(jwk) || cache2.set(jwk, {}).get(jwk), { alg } = entry;
|
|
38789
|
+
if (cached[alg] === void 0) {
|
|
38790
|
+
const pending = jwkToKey(entry, jwk, true).then((key) => {
|
|
38791
|
+
if (key.type !== "public")
|
|
38792
|
+
throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
38793
|
+
return cached[alg] = key, key;
|
|
38794
|
+
}).catch((error) => {
|
|
38795
|
+
throw cached[alg] === pending && delete cached[alg], error;
|
|
38796
|
+
});
|
|
38797
|
+
cached[alg] = pending;
|
|
39812
38798
|
}
|
|
39813
|
-
return
|
|
38799
|
+
return cached[alg];
|
|
39814
38800
|
}
|
|
39815
38801
|
function createLocalJWKSet(jwks) {
|
|
39816
38802
|
let snapshot;
|
|
@@ -39818,52 +38804,46 @@ ${newlined}
|
|
|
39818
38804
|
snapshot = structuredClone(jwks);
|
|
39819
38805
|
} catch {
|
|
39820
38806
|
}
|
|
39821
|
-
if (!isJwkSet(snapshot))
|
|
38807
|
+
if (!isJwkSet(snapshot))
|
|
39822
38808
|
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
39823
|
-
|
|
39824
|
-
|
|
39825
|
-
|
|
39826
|
-
|
|
39827
|
-
|
|
39828
|
-
|
|
38809
|
+
const metadata = snapshot.keys.map((jwk) => {
|
|
38810
|
+
const normalized = snapshotJwk(jwk);
|
|
38811
|
+
return Array.isArray(normalized.key_ops) && (normalized.key_ops = [...normalized.key_ops]), normalized;
|
|
38812
|
+
}), cached = /* @__PURE__ */ new WeakMap();
|
|
38813
|
+
return Object.defineProperty(async (protectedHeader, token) => {
|
|
38814
|
+
const { alg, kid } = { ...protectedHeader, ...token?.header }, entry = typeof alg == "string" ? JWS[alg] : void 0;
|
|
38815
|
+
if (!entry || entry.secret)
|
|
39829
38816
|
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
39830
|
-
}
|
|
39831
|
-
|
|
39832
|
-
const { 0: jwk, length } = candidates;
|
|
39833
|
-
if (!length) {
|
|
38817
|
+
const candidates = snapshot.keys.filter((_, index) => isUsableJWK(metadata[index], entry, alg, kid)), { 0: jwk, length } = candidates;
|
|
38818
|
+
if (!length)
|
|
39834
38819
|
throw new JWKSNoMatchingKey();
|
|
39835
|
-
}
|
|
39836
38820
|
if (length !== 1) {
|
|
39837
38821
|
const error = new JWKSMultipleMatchingKeys();
|
|
39838
|
-
error[Symbol.asyncIterator] = async function* () {
|
|
39839
|
-
for (const jwk2 of candidates)
|
|
38822
|
+
throw error[Symbol.asyncIterator] = async function* () {
|
|
38823
|
+
for (const jwk2 of candidates)
|
|
39840
38824
|
try {
|
|
39841
|
-
yield await importWithAlgCache(
|
|
38825
|
+
yield await importWithAlgCache(cached, jwk2, entry);
|
|
39842
38826
|
} catch {
|
|
39843
38827
|
}
|
|
39844
|
-
|
|
39845
|
-
};
|
|
39846
|
-
throw error;
|
|
38828
|
+
}, error;
|
|
39847
38829
|
}
|
|
39848
|
-
return importWithAlgCache(
|
|
39849
|
-
}
|
|
39850
|
-
return Object.defineProperty(localJWKSet, "jwks", {
|
|
38830
|
+
return importWithAlgCache(cached, jwk, entry);
|
|
38831
|
+
}, "jwks", {
|
|
39851
38832
|
value: () => structuredClone(snapshot)
|
|
39852
38833
|
});
|
|
39853
38834
|
}
|
|
39854
38835
|
var init_local = __esm({
|
|
39855
38836
|
"../node_modules/jose/dist/webapi/jwks/local.js"() {
|
|
39856
|
-
|
|
38837
|
+
init_key();
|
|
39857
38838
|
init_jws_algorithms();
|
|
39858
38839
|
init_errors();
|
|
39859
|
-
|
|
39860
|
-
init_jwk_metadata();
|
|
38840
|
+
init_validate2();
|
|
39861
38841
|
}
|
|
39862
38842
|
});
|
|
39863
38843
|
|
|
39864
38844
|
// ../node_modules/jose/dist/webapi/jwks/remote.js
|
|
39865
38845
|
function isCloudflareWorkers() {
|
|
39866
|
-
return typeof WebSocketPair
|
|
38846
|
+
return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
|
|
39867
38847
|
}
|
|
39868
38848
|
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
39869
38849
|
const response = await fetchImpl(url, {
|
|
@@ -39872,14 +38852,10 @@ ${newlined}
|
|
|
39872
38852
|
redirect: "manual",
|
|
39873
38853
|
headers
|
|
39874
38854
|
}).catch((err) => {
|
|
39875
|
-
|
|
39876
|
-
throw new JWKSTimeout();
|
|
39877
|
-
}
|
|
39878
|
-
throw err;
|
|
38855
|
+
throw err.name === "TimeoutError" ? new JWKSTimeout() : err;
|
|
39879
38856
|
});
|
|
39880
|
-
if (response.status !== 200)
|
|
38857
|
+
if (response.status !== 200)
|
|
39881
38858
|
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
39882
|
-
}
|
|
39883
38859
|
try {
|
|
39884
38860
|
return await response.json();
|
|
39885
38861
|
} catch {
|
|
@@ -39890,87 +38866,49 @@ ${newlined}
|
|
|
39890
38866
|
return Number.isFinite(timestamp) && Date.now() < timestamp + duration;
|
|
39891
38867
|
}
|
|
39892
38868
|
function validateDuration(value, fallback, option) {
|
|
39893
|
-
if (Number.isNaN(value))
|
|
38869
|
+
if (Number.isNaN(value))
|
|
39894
38870
|
throw new TypeError(`"${option}" option must not be NaN`);
|
|
39895
|
-
|
|
39896
|
-
return typeof value === "number" ? value : fallback;
|
|
38871
|
+
return typeof value == "number" ? value : fallback;
|
|
39897
38872
|
}
|
|
39898
38873
|
function createRemoteJWKSet(url, options) {
|
|
39899
|
-
if (!(url instanceof URL))
|
|
38874
|
+
if (!(url instanceof URL))
|
|
39900
38875
|
throw new TypeError("url must be an instance of URL");
|
|
39901
|
-
}
|
|
39902
|
-
|
|
39903
|
-
const opts = options ?? {};
|
|
39904
|
-
const timeoutOption = opts.timeoutDuration;
|
|
39905
|
-
if (typeof timeoutOption === "number" && (!Number.isInteger(timeoutOption) || timeoutOption < 0)) {
|
|
38876
|
+
const href = new URL(url.href).href, opts = options ?? {}, timeoutOption = opts.timeoutDuration;
|
|
38877
|
+
if (typeof timeoutOption == "number" && (!Number.isInteger(timeoutOption) || timeoutOption < 0))
|
|
39906
38878
|
throw new TypeError('"timeoutDuration" option must be a non-negative integer');
|
|
39907
|
-
|
|
39908
|
-
|
|
39909
|
-
const
|
|
39910
|
-
|
|
39911
|
-
|
|
39912
|
-
if (USER_AGENT && !headers.has("User-Agent")) {
|
|
39913
|
-
headers.set("User-Agent", USER_AGENT);
|
|
39914
|
-
}
|
|
39915
|
-
if (!headers.has("accept")) {
|
|
39916
|
-
headers.set("accept", "application/json, application/jwk-set+json");
|
|
39917
|
-
}
|
|
39918
|
-
const fetchImpl = opts[customFetch];
|
|
39919
|
-
const cache2 = opts[jwksCache];
|
|
39920
|
-
let jwksTimestamp;
|
|
39921
|
-
let pendingFetch;
|
|
39922
|
-
let reloadSequence = 0;
|
|
39923
|
-
let appliedSequence = 0;
|
|
39924
|
-
let local;
|
|
39925
|
-
if (cache2 && typeof cache2 === "object") {
|
|
38879
|
+
const timeoutDuration = typeof timeoutOption == "number" ? timeoutOption : 5e3, cooldownDuration = validateDuration(opts.cooldownDuration, 3e4, "cooldownDuration"), cacheMaxAge = validateDuration(opts.cacheMaxAge, 6e5, "cacheMaxAge"), headers = new Headers(opts.headers);
|
|
38880
|
+
USER_AGENT && !headers.has("User-Agent") && headers.set("User-Agent", USER_AGENT), headers.has("accept") || headers.set("accept", "application/json, application/jwk-set+json");
|
|
38881
|
+
const fetchImpl = opts[customFetch], cache2 = opts[jwksCache];
|
|
38882
|
+
let jwksTimestamp, pendingFetch, reloadSequence = 0, appliedSequence = 0, local;
|
|
38883
|
+
if (cache2 && typeof cache2 == "object") {
|
|
39926
38884
|
const { uat, jwks } = cache2;
|
|
39927
|
-
|
|
39928
|
-
jwksTimestamp = uat;
|
|
39929
|
-
local = createLocalJWKSet(jwks);
|
|
39930
|
-
}
|
|
38885
|
+
isFreshFor(uat, cacheMaxAge) && isJwkSet(jwks) && (jwksTimestamp = uat, local = createLocalJWKSet(jwks));
|
|
39931
38886
|
}
|
|
39932
38887
|
const reload = async () => {
|
|
39933
|
-
if (pendingFetch && isCloudflareWorkers()) {
|
|
39934
|
-
pendingFetch =
|
|
39935
|
-
}
|
|
39936
|
-
if (!pendingFetch) {
|
|
39937
|
-
const sequence = ++reloadSequence;
|
|
39938
|
-
const current = pendingFetch = fetchJwks(href, headers, AbortSignal.timeout(timeoutDuration), fetchImpl).then((json) => {
|
|
38888
|
+
if (pendingFetch && isCloudflareWorkers() && (pendingFetch = void 0), !pendingFetch) {
|
|
38889
|
+
const sequence = ++reloadSequence, current = pendingFetch = fetchJwks(href, headers, AbortSignal.timeout(timeoutDuration), fetchImpl).then((json) => {
|
|
39939
38890
|
const next = createLocalJWKSet(json);
|
|
39940
|
-
if (sequence <= appliedSequence)
|
|
38891
|
+
if (sequence <= appliedSequence)
|
|
39941
38892
|
return;
|
|
39942
|
-
}
|
|
39943
38893
|
local = next;
|
|
39944
38894
|
const updatedAt = Date.now();
|
|
39945
|
-
|
|
39946
|
-
cache2.uat = updatedAt;
|
|
39947
|
-
cache2.jwks = json;
|
|
39948
|
-
}
|
|
39949
|
-
jwksTimestamp = updatedAt;
|
|
39950
|
-
appliedSequence = sequence;
|
|
38895
|
+
cache2 && (cache2.uat = updatedAt, cache2.jwks = json), jwksTimestamp = updatedAt, appliedSequence = sequence;
|
|
39951
38896
|
}).finally(() => {
|
|
39952
|
-
|
|
39953
|
-
pendingFetch = void 0;
|
|
39954
|
-
}
|
|
38897
|
+
pendingFetch === current && (pendingFetch = void 0);
|
|
39955
38898
|
});
|
|
39956
38899
|
}
|
|
39957
38900
|
await pendingFetch;
|
|
39958
38901
|
};
|
|
39959
|
-
|
|
39960
|
-
|
|
39961
|
-
await reload();
|
|
39962
|
-
}
|
|
38902
|
+
return Object.defineProperties(async (protectedHeader, token) => {
|
|
38903
|
+
(!local || !isFreshFor(jwksTimestamp, cacheMaxAge)) && await reload();
|
|
39963
38904
|
try {
|
|
39964
38905
|
return await local(protectedHeader, token);
|
|
39965
38906
|
} catch (err) {
|
|
39966
|
-
if (err instanceof JWKSNoMatchingKey && !isFreshFor(jwksTimestamp, cooldownDuration))
|
|
39967
|
-
await reload();
|
|
39968
|
-
return local(protectedHeader, token);
|
|
39969
|
-
}
|
|
38907
|
+
if (err instanceof JWKSNoMatchingKey && !isFreshFor(jwksTimestamp, cooldownDuration))
|
|
38908
|
+
return await reload(), local(protectedHeader, token);
|
|
39970
38909
|
throw err;
|
|
39971
38910
|
}
|
|
39972
|
-
}
|
|
39973
|
-
return Object.defineProperties(remoteJWKSet, {
|
|
38911
|
+
}, {
|
|
39974
38912
|
coolingDown: {
|
|
39975
38913
|
get: () => isFreshFor(jwksTimestamp, cooldownDuration),
|
|
39976
38914
|
enumerable: true
|
|
@@ -39998,12 +38936,8 @@ ${newlined}
|
|
|
39998
38936
|
"../node_modules/jose/dist/webapi/jwks/remote.js"() {
|
|
39999
38937
|
init_errors();
|
|
40000
38938
|
init_local();
|
|
40001
|
-
|
|
40002
|
-
|
|
40003
|
-
const NAME = "jose";
|
|
40004
|
-
const VERSION = "v6.2.10";
|
|
40005
|
-
USER_AGENT = `${NAME}/${VERSION}`;
|
|
40006
|
-
}
|
|
38939
|
+
init_validate2();
|
|
38940
|
+
(typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.12");
|
|
40007
38941
|
customFetch = /* @__PURE__ */ Symbol();
|
|
40008
38942
|
jwksCache = /* @__PURE__ */ Symbol();
|
|
40009
38943
|
}
|
|
@@ -40014,45 +38948,34 @@ ${newlined}
|
|
|
40014
38948
|
var init_unsecured = __esm({
|
|
40015
38949
|
"../node_modules/jose/dist/webapi/jwt/unsecured.js"() {
|
|
40016
38950
|
init_base64url();
|
|
40017
|
-
|
|
38951
|
+
init_validate2();
|
|
40018
38952
|
init_errors();
|
|
40019
38953
|
init_jwt_claims_set();
|
|
40020
|
-
init_options();
|
|
40021
38954
|
UnsecuredJWT_base = JWTClaimsBuilder;
|
|
40022
38955
|
UnsecuredJWT = class extends UnsecuredJWT_base {
|
|
40023
38956
|
encode() {
|
|
40024
|
-
const header = encode2(JSON.stringify({ alg: "none" }));
|
|
40025
|
-
const payload = encode2(jwtData(this));
|
|
38957
|
+
const header = encode2(JSON.stringify({ alg: "none" })), payload = encode2(jwtData(this));
|
|
40026
38958
|
return `${header}.${payload}.`;
|
|
40027
38959
|
}
|
|
40028
38960
|
static decode(jwt, options) {
|
|
40029
|
-
if (typeof jwt
|
|
38961
|
+
if (typeof jwt != "string")
|
|
40030
38962
|
throw new JWTInvalid("Unsecured JWT must be a string");
|
|
40031
|
-
}
|
|
40032
38963
|
const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
|
|
40033
|
-
if (length !== 3 || signature !== "")
|
|
38964
|
+
if (length !== 3 || signature !== "")
|
|
40034
38965
|
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
40035
|
-
|
|
40036
|
-
let header;
|
|
40037
|
-
let b64;
|
|
38966
|
+
let header, b64;
|
|
40038
38967
|
try {
|
|
40039
38968
|
header = parseJoseHeader(encodedHeader, JWSInvalid, "JWS Protected Header is invalid");
|
|
40040
38969
|
const extensions = validateCrit(JWSInvalid, JWS_RECOGNIZED, void 0, header, header);
|
|
40041
38970
|
b64 = validateB64(header, extensions);
|
|
40042
38971
|
} catch (cause) {
|
|
40043
|
-
|
|
40044
|
-
throw cause;
|
|
40045
|
-
}
|
|
40046
|
-
throw new JWTInvalid("Invalid Unsecured JWT", { cause });
|
|
38972
|
+
throw cause instanceof JWSInvalid ? new JWTInvalid("Invalid Unsecured JWT", { cause }) : cause;
|
|
40047
38973
|
}
|
|
40048
|
-
if (header.alg !== "none")
|
|
38974
|
+
if (header.alg !== "none")
|
|
40049
38975
|
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
40050
|
-
|
|
40051
|
-
if (!b64) {
|
|
38976
|
+
if (!b64)
|
|
40052
38977
|
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
40053
|
-
}
|
|
40054
|
-
const payload = validateClaimsSet(header, decodeBase64url(encodedPayload, "payload", JWTInvalid), options);
|
|
40055
|
-
return { payload, header };
|
|
38978
|
+
return { payload: validateClaimsSet(header, decodeBase64url(encodedPayload, "payload", JWTInvalid), options), header };
|
|
40056
38979
|
}
|
|
40057
38980
|
};
|
|
40058
38981
|
}
|
|
@@ -40060,54 +38983,42 @@ ${newlined}
|
|
|
40060
38983
|
|
|
40061
38984
|
// ../node_modules/jose/dist/webapi/key/import.js
|
|
40062
38985
|
async function importSPKI(spki, alg, options) {
|
|
40063
|
-
if (typeof spki
|
|
38986
|
+
if (typeof spki != "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
|
|
40064
38987
|
throw new TypeError('"spki" must be SPKI formatted string');
|
|
40065
|
-
}
|
|
40066
38988
|
return fromSPKI(spki, alg, options);
|
|
40067
38989
|
}
|
|
40068
38990
|
async function importX509(x509, alg, options) {
|
|
40069
|
-
if (typeof x509
|
|
38991
|
+
if (typeof x509 != "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0)
|
|
40070
38992
|
throw new TypeError('"x509" must be X.509 formatted string');
|
|
40071
|
-
}
|
|
40072
38993
|
return fromX509(x509, alg, options);
|
|
40073
38994
|
}
|
|
40074
38995
|
async function importPKCS8(pkcs8, alg, options) {
|
|
40075
|
-
if (typeof pkcs8
|
|
38996
|
+
if (typeof pkcs8 != "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0)
|
|
40076
38997
|
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
40077
|
-
}
|
|
40078
38998
|
return fromPKCS8(pkcs8, alg, options);
|
|
40079
38999
|
}
|
|
40080
39000
|
async function importJWK(jwk, alg, options) {
|
|
40081
|
-
if (!isObject(jwk))
|
|
39001
|
+
if (!isObject(jwk))
|
|
40082
39002
|
throw new TypeError("JWK must be an object");
|
|
40083
|
-
}
|
|
40084
|
-
|
|
40085
|
-
const extractable = validateExtractableOption(options?.extractable);
|
|
40086
|
-
const { alg: jwkAlg } = normalized;
|
|
40087
|
-
alg ?? (alg = jwkAlg);
|
|
40088
|
-
const ext = extractable ?? normalized.ext;
|
|
40089
|
-
if (normalized.kty !== "oct" && !alg) {
|
|
39003
|
+
const normalized = normalizeJwk(jwk), extractable = validateExtractableOption(options?.extractable), { alg: jwkAlg } = normalized;
|
|
39004
|
+
if (alg ?? (alg = jwkAlg), normalized.kty !== "oct" && !alg)
|
|
40090
39005
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
40091
|
-
}
|
|
40092
39006
|
switch (normalized.kty) {
|
|
40093
39007
|
case "oct":
|
|
40094
|
-
if (typeof normalized.k
|
|
39008
|
+
if (typeof normalized.k != "string")
|
|
40095
39009
|
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
40096
|
-
}
|
|
40097
39010
|
return decode(normalized.k);
|
|
40098
39011
|
case "AKP": {
|
|
40099
|
-
if (typeof jwkAlg
|
|
39012
|
+
if (typeof jwkAlg != "string" || !jwkAlg)
|
|
40100
39013
|
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
40101
|
-
|
|
40102
|
-
if (alg !== jwkAlg) {
|
|
39014
|
+
if (alg !== jwkAlg)
|
|
40103
39015
|
throw new TypeError("JWK alg and alg option value mismatch");
|
|
40104
|
-
|
|
40105
|
-
return jwkToKey(keyAlgorithm(alg), { ...normalized, ext });
|
|
39016
|
+
return jwkToKey(keyAlgorithm(alg), normalized, extractable);
|
|
40106
39017
|
}
|
|
40107
39018
|
case "RSA":
|
|
40108
39019
|
case "EC":
|
|
40109
39020
|
case "OKP":
|
|
40110
|
-
return jwkToKey(keyAlgorithm(alg),
|
|
39021
|
+
return jwkToKey(keyAlgorithm(alg), normalized, extractable);
|
|
40111
39022
|
default:
|
|
40112
39023
|
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
40113
39024
|
}
|
|
@@ -40116,46 +39027,38 @@ ${newlined}
|
|
|
40116
39027
|
"../node_modules/jose/dist/webapi/key/import.js"() {
|
|
40117
39028
|
init_base64url();
|
|
40118
39029
|
init_asn1();
|
|
40119
|
-
|
|
39030
|
+
init_key();
|
|
40120
39031
|
init_key_algorithm();
|
|
40121
39032
|
init_errors();
|
|
40122
|
-
|
|
40123
|
-
init_key_options();
|
|
40124
|
-
init_jwk_metadata();
|
|
39033
|
+
init_validate2();
|
|
40125
39034
|
}
|
|
40126
39035
|
});
|
|
40127
39036
|
|
|
40128
39037
|
// ../node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
40129
39038
|
function decodeProtectedHeader(token) {
|
|
40130
39039
|
let protectedB64u;
|
|
40131
|
-
if (typeof token
|
|
39040
|
+
if (typeof token == "string") {
|
|
40132
39041
|
const parts = token.split(".");
|
|
40133
|
-
|
|
40134
|
-
|
|
40135
|
-
|
|
40136
|
-
}
|
|
40137
|
-
} else if (typeof token === "object" && token) {
|
|
40138
|
-
if ("protected" in token) {
|
|
39042
|
+
(parts.length === 3 || parts.length === 5) && ([protectedB64u] = parts);
|
|
39043
|
+
} else if (typeof token == "object" && token)
|
|
39044
|
+
if ("protected" in token)
|
|
40139
39045
|
protectedB64u = token.protected;
|
|
40140
|
-
|
|
39046
|
+
else
|
|
40141
39047
|
throw new TypeError("Token does not contain a Protected Header");
|
|
40142
|
-
}
|
|
40143
|
-
}
|
|
40144
39048
|
const invalid2 = "Invalid Token or Protected Header formatting";
|
|
40145
|
-
if (typeof protectedB64u
|
|
39049
|
+
if (typeof protectedB64u != "string" || !protectedB64u)
|
|
40146
39050
|
throw new TypeError(invalid2);
|
|
40147
|
-
}
|
|
40148
39051
|
return parseJoseHeader(protectedB64u, TypeError, invalid2);
|
|
40149
39052
|
}
|
|
40150
39053
|
var init_decode_protected_header = __esm({
|
|
40151
39054
|
"../node_modules/jose/dist/webapi/util/decode_protected_header.js"() {
|
|
40152
|
-
|
|
39055
|
+
init_validate2();
|
|
40153
39056
|
}
|
|
40154
39057
|
});
|
|
40155
39058
|
|
|
40156
39059
|
// ../node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
40157
39060
|
function decodeJwt(jwt) {
|
|
40158
|
-
if (typeof jwt
|
|
39061
|
+
if (typeof jwt != "string")
|
|
40159
39062
|
throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
40160
39063
|
const { 1: payload, length } = jwt.split(".");
|
|
40161
39064
|
if (length === 5)
|
|
@@ -40184,7 +39087,7 @@ ${newlined}
|
|
|
40184
39087
|
"../node_modules/jose/dist/webapi/util/decode_jwt.js"() {
|
|
40185
39088
|
init_base64url();
|
|
40186
39089
|
init_buffer_utils();
|
|
40187
|
-
|
|
39090
|
+
init_validate2();
|
|
40188
39091
|
init_errors();
|
|
40189
39092
|
}
|
|
40190
39093
|
});
|
|
@@ -40192,36 +39095,22 @@ ${newlined}
|
|
|
40192
39095
|
// ../node_modules/jose/dist/webapi/key/generate_key_pair.js
|
|
40193
39096
|
function getModulusLengthOption(options) {
|
|
40194
39097
|
const modulusLength = options?.modulusLength ?? 2048;
|
|
40195
|
-
if (typeof modulusLength
|
|
39098
|
+
if (typeof modulusLength != "number" || !Number.isInteger(modulusLength) || modulusLength < 2048)
|
|
40196
39099
|
throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
|
|
40197
|
-
}
|
|
40198
39100
|
return modulusLength;
|
|
40199
39101
|
}
|
|
40200
39102
|
async function generateKeyPair(alg, options) {
|
|
40201
|
-
const extractable = validateExtractableOption(options?.extractable);
|
|
40202
|
-
|
|
40203
|
-
if (entry.secret) {
|
|
40204
|
-
unsupportedAlg(algArgument);
|
|
40205
|
-
}
|
|
39103
|
+
const extractable = validateExtractableOption(options?.extractable), entry = keyAlgorithm(alg, algArgument);
|
|
39104
|
+
entry.secret && unsupportedAlg(algArgument);
|
|
40206
39105
|
let algorithm;
|
|
40207
39106
|
if (entry.resolve) {
|
|
40208
39107
|
const crv = options?.crv ?? "P-256";
|
|
40209
|
-
|
|
40210
|
-
|
|
40211
|
-
|
|
40212
|
-
case "P-521":
|
|
40213
|
-
algorithm = { name: "ECDH", namedCurve: crv };
|
|
40214
|
-
break;
|
|
40215
|
-
case "X25519":
|
|
40216
|
-
algorithm = { name: "X25519" };
|
|
40217
|
-
break;
|
|
40218
|
-
default:
|
|
40219
|
-
throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
|
|
40220
|
-
}
|
|
39108
|
+
if (!["P-256", "P-384", "P-521", "X25519"].includes(crv))
|
|
39109
|
+
throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
|
|
39110
|
+
algorithm = entry.resolve({ crv });
|
|
40221
39111
|
} else {
|
|
40222
|
-
if (entry.crv !== void 0 && options?.crv !== void 0 && options.crv !== entry.crv)
|
|
39112
|
+
if (entry.crv !== void 0 && options?.crv !== void 0 && options.crv !== entry.crv)
|
|
40223
39113
|
throw new JOSENotSupported(`Invalid or unsupported crv option provided, the only supported value for ${alg} is ${entry.crv}`);
|
|
40224
|
-
}
|
|
40225
39114
|
algorithm = entry.kty[0] === "RSA" ? {
|
|
40226
39115
|
...entry.subtle,
|
|
40227
39116
|
publicExponent: Uint8Array.of(1, 0, 1),
|
|
@@ -40236,7 +39125,7 @@ ${newlined}
|
|
|
40236
39125
|
var init_generate_key_pair = __esm({
|
|
40237
39126
|
"../node_modules/jose/dist/webapi/key/generate_key_pair.js"() {
|
|
40238
39127
|
init_errors();
|
|
40239
|
-
|
|
39128
|
+
init_key();
|
|
40240
39129
|
init_key_algorithm();
|
|
40241
39130
|
}
|
|
40242
39131
|
});
|
|
@@ -40244,16 +39133,12 @@ ${newlined}
|
|
|
40244
39133
|
// ../node_modules/jose/dist/webapi/key/generate_secret.js
|
|
40245
39134
|
async function generateSecret(alg, options) {
|
|
40246
39135
|
const extractable = validateExtractableOption(options?.extractable);
|
|
40247
|
-
let length;
|
|
40248
|
-
let algorithm;
|
|
40249
|
-
let keyUsages;
|
|
39136
|
+
let length, algorithm, keyUsages;
|
|
40250
39137
|
switch (alg) {
|
|
40251
39138
|
case "HS256":
|
|
40252
39139
|
case "HS384":
|
|
40253
39140
|
case "HS512":
|
|
40254
|
-
length = +alg.slice(-3);
|
|
40255
|
-
algorithm = { name: "HMAC", hash: `SHA-${length}`, length };
|
|
40256
|
-
keyUsages = ["sign", "verify"];
|
|
39141
|
+
length = +alg.slice(-3), algorithm = { name: "HMAC", hash: `SHA-${length}`, length }, keyUsages = ["sign", "verify"];
|
|
40257
39142
|
break;
|
|
40258
39143
|
case "A128CBC-HS256":
|
|
40259
39144
|
case "A192CBC-HS384":
|
|
@@ -40262,9 +39147,7 @@ ${newlined}
|
|
|
40262
39147
|
case "A128KW":
|
|
40263
39148
|
case "A192KW":
|
|
40264
39149
|
case "A256KW":
|
|
40265
|
-
length = +alg.slice(1, 4);
|
|
40266
|
-
algorithm = { name: "AES-KW", length };
|
|
40267
|
-
keyUsages = ["wrapKey", "unwrapKey"];
|
|
39150
|
+
length = +alg.slice(1, 4), algorithm = { name: "AES-KW", length }, keyUsages = ["wrapKey", "unwrapKey"];
|
|
40268
39151
|
break;
|
|
40269
39152
|
case "A128GCMKW":
|
|
40270
39153
|
case "A192GCMKW":
|
|
@@ -40272,9 +39155,7 @@ ${newlined}
|
|
|
40272
39155
|
case "A128GCM":
|
|
40273
39156
|
case "A192GCM":
|
|
40274
39157
|
case "A256GCM":
|
|
40275
|
-
length = +alg.slice(1, 4);
|
|
40276
|
-
algorithm = { name: "AES-GCM", length };
|
|
40277
|
-
keyUsages = ["encrypt", "decrypt"];
|
|
39158
|
+
length = +alg.slice(1, 4), algorithm = { name: "AES-GCM", length }, keyUsages = ["encrypt", "decrypt"];
|
|
40278
39159
|
break;
|
|
40279
39160
|
default:
|
|
40280
39161
|
unsupportedAlg(algArgument);
|
|
@@ -40284,7 +39165,7 @@ ${newlined}
|
|
|
40284
39165
|
var init_generate_secret = __esm({
|
|
40285
39166
|
"../node_modules/jose/dist/webapi/key/generate_secret.js"() {
|
|
40286
39167
|
init_key_algorithm();
|
|
40287
|
-
|
|
39168
|
+
init_key();
|
|
40288
39169
|
}
|
|
40289
39170
|
});
|
|
40290
39171
|
|
|
@@ -42054,8 +40935,8 @@ ${newlined}
|
|
|
42054
40935
|
});
|
|
42055
40936
|
}
|
|
42056
40937
|
static async fromJwt(jwtStr, options = {}) {
|
|
42057
|
-
const { token, verify
|
|
42058
|
-
if (
|
|
40938
|
+
const { token, verify = true } = options;
|
|
40939
|
+
if (verify) {
|
|
42059
40940
|
const verificationToken = token ?? getEnvValue("MESHAGENT_SECRET");
|
|
42060
40941
|
if (verificationToken === void 0) {
|
|
42061
40942
|
throw new Error("Failed to verify JWT: no token provided");
|