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