@frontmcp/plugin-cache 1.9.2 → 1.9.3
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/esm/index.mjs +180 -294
- package/esm/package.json +3 -3
- package/index.js +180 -294
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -105,22 +105,22 @@ var require_node = __commonJS({
|
|
|
105
105
|
mod
|
|
106
106
|
));
|
|
107
107
|
var __toCommonJS2 = (mod) => __copyProps2(__defProp3({}, "__esModule", { value: true }), mod);
|
|
108
|
-
var
|
|
109
|
-
__export3(
|
|
110
|
-
createSignedJwt: () =>
|
|
111
|
-
cryptoProvider: () =>
|
|
112
|
-
generateRsaKeyPair: () =>
|
|
108
|
+
var node_exports = {};
|
|
109
|
+
__export3(node_exports, {
|
|
110
|
+
createSignedJwt: () => createSignedJwt,
|
|
111
|
+
cryptoProvider: () => nodeCrypto,
|
|
112
|
+
generateRsaKeyPair: () => generateRsaKeyPair3,
|
|
113
113
|
isRsaPssAlg: () => isRsaPssAlg2,
|
|
114
|
-
jwtAlgToNodeAlg: () =>
|
|
115
|
-
nodeCrypto: () =>
|
|
116
|
-
pemToPublicJwk: () =>
|
|
117
|
-
rsaSign: () =>
|
|
118
|
-
rsaSignBase64Url: () =>
|
|
119
|
-
rsaVerify: () =>
|
|
120
|
-
rsaVerifySync: () =>
|
|
114
|
+
jwtAlgToNodeAlg: () => jwtAlgToNodeAlg,
|
|
115
|
+
nodeCrypto: () => nodeCrypto,
|
|
116
|
+
pemToPublicJwk: () => pemToPublicJwk3,
|
|
117
|
+
rsaSign: () => rsaSign,
|
|
118
|
+
rsaSignBase64Url: () => rsaSignBase64Url3,
|
|
119
|
+
rsaVerify: () => rsaVerify3,
|
|
120
|
+
rsaVerifySync: () => rsaVerifySync3
|
|
121
121
|
});
|
|
122
|
-
module2.exports = __toCommonJS2(
|
|
123
|
-
var
|
|
122
|
+
module2.exports = __toCommonJS2(node_exports);
|
|
123
|
+
var import_node_crypto = __toESM2(require("node:crypto"));
|
|
124
124
|
var JWT_ALG_TO_NODE_DIGEST2 = {
|
|
125
125
|
RS256: "RSA-SHA256",
|
|
126
126
|
RS384: "RSA-SHA384",
|
|
@@ -130,7 +130,7 @@ var require_node = __commonJS({
|
|
|
130
130
|
PS384: "RSA-SHA384",
|
|
131
131
|
PS512: "RSA-SHA512"
|
|
132
132
|
};
|
|
133
|
-
function
|
|
133
|
+
function jwtAlgToNodeAlg(jwtAlg) {
|
|
134
134
|
const nodeAlg = JWT_ALG_TO_NODE_DIGEST2[jwtAlg];
|
|
135
135
|
if (!nodeAlg) {
|
|
136
136
|
throw new Error(`Unsupported JWT algorithm: ${jwtAlg}`);
|
|
@@ -140,70 +140,70 @@ var require_node = __commonJS({
|
|
|
140
140
|
function isRsaPssAlg2(jwtAlg) {
|
|
141
141
|
return jwtAlg.startsWith("PS");
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function toUint8Array(buf) {
|
|
144
144
|
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function toBuffer(data) {
|
|
147
147
|
if (typeof data === "string") {
|
|
148
148
|
return Buffer.from(data, "utf8");
|
|
149
149
|
}
|
|
150
150
|
return Buffer.from(data);
|
|
151
151
|
}
|
|
152
|
-
var
|
|
152
|
+
var nodeCrypto = {
|
|
153
153
|
randomUUID() {
|
|
154
|
-
return
|
|
154
|
+
return import_node_crypto.default.randomUUID();
|
|
155
155
|
},
|
|
156
156
|
randomBytes(length) {
|
|
157
|
-
return
|
|
157
|
+
return toUint8Array(import_node_crypto.default.randomBytes(length));
|
|
158
158
|
},
|
|
159
159
|
sha256(data) {
|
|
160
|
-
const hash =
|
|
161
|
-
return
|
|
160
|
+
const hash = import_node_crypto.default.createHash("sha256").update(toBuffer(data)).digest();
|
|
161
|
+
return toUint8Array(hash);
|
|
162
162
|
},
|
|
163
163
|
sha256Hex(data) {
|
|
164
|
-
return
|
|
164
|
+
return import_node_crypto.default.createHash("sha256").update(toBuffer(data)).digest("hex");
|
|
165
165
|
},
|
|
166
166
|
hmacSha256(key, data) {
|
|
167
|
-
const hmac2 =
|
|
168
|
-
return
|
|
167
|
+
const hmac2 = import_node_crypto.default.createHmac("sha256", Buffer.from(key)).update(Buffer.from(data)).digest();
|
|
168
|
+
return toUint8Array(hmac2);
|
|
169
169
|
},
|
|
170
170
|
hkdfSha256(ikm, salt, info, length) {
|
|
171
171
|
const ikmBuf = Buffer.from(ikm);
|
|
172
172
|
const saltBuf = salt.length > 0 ? Buffer.from(salt) : Buffer.alloc(32);
|
|
173
|
-
const prk =
|
|
173
|
+
const prk = import_node_crypto.default.createHmac("sha256", saltBuf).update(ikmBuf).digest();
|
|
174
174
|
const hashLen = 32;
|
|
175
175
|
const n = Math.ceil(length / hashLen);
|
|
176
176
|
const chunks = [];
|
|
177
177
|
let prev = Buffer.alloc(0);
|
|
178
178
|
for (let i = 1; i <= n; i++) {
|
|
179
|
-
prev =
|
|
179
|
+
prev = import_node_crypto.default.createHmac("sha256", prk).update(Buffer.concat([prev, Buffer.from(info), Buffer.from([i])])).digest();
|
|
180
180
|
chunks.push(prev);
|
|
181
181
|
}
|
|
182
|
-
return
|
|
182
|
+
return toUint8Array(Buffer.concat(chunks).subarray(0, length));
|
|
183
183
|
},
|
|
184
184
|
encryptAesGcm(key, plaintext, iv) {
|
|
185
|
-
const cipher =
|
|
185
|
+
const cipher = import_node_crypto.default.createCipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
186
186
|
const encrypted = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]);
|
|
187
187
|
const tag = cipher.getAuthTag();
|
|
188
188
|
return {
|
|
189
|
-
ciphertext:
|
|
190
|
-
tag:
|
|
189
|
+
ciphertext: toUint8Array(encrypted),
|
|
190
|
+
tag: toUint8Array(tag)
|
|
191
191
|
};
|
|
192
192
|
},
|
|
193
193
|
decryptAesGcm(key, ciphertext, iv, tag) {
|
|
194
|
-
const decipher =
|
|
194
|
+
const decipher = import_node_crypto.default.createDecipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
195
195
|
decipher.setAuthTag(Buffer.from(tag));
|
|
196
196
|
const decrypted = Buffer.concat([decipher.update(Buffer.from(ciphertext)), decipher.final()]);
|
|
197
|
-
return
|
|
197
|
+
return toUint8Array(decrypted);
|
|
198
198
|
},
|
|
199
199
|
timingSafeEqual(a, b) {
|
|
200
200
|
if (a.length !== b.length) return false;
|
|
201
|
-
return
|
|
201
|
+
return import_node_crypto.default.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
|
-
function
|
|
205
|
-
const kid = `rsa-key-${Date.now()}-${
|
|
206
|
-
const { privateKey, publicKey } =
|
|
204
|
+
function generateRsaKeyPair3(modulusLength = 2048, alg = "RS256") {
|
|
205
|
+
const kid = `rsa-key-${Date.now()}-${import_node_crypto.default.randomBytes(8).toString("hex")}`;
|
|
206
|
+
const { privateKey, publicKey } = import_node_crypto.default.generateKeyPairSync("rsa", {
|
|
207
207
|
modulusLength
|
|
208
208
|
});
|
|
209
209
|
const exported = publicKey.export({ format: "jwk" });
|
|
@@ -216,66 +216,66 @@ var require_node = __commonJS({
|
|
|
216
216
|
};
|
|
217
217
|
return { privateKey, publicKey, publicJwk };
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function rsaSign(algorithm, data, privateKey, options) {
|
|
220
220
|
const signingKey = options ? { key: privateKey, ...options } : privateKey;
|
|
221
|
-
return
|
|
221
|
+
return import_node_crypto.default.sign(algorithm, data, signingKey);
|
|
222
222
|
}
|
|
223
|
-
function
|
|
224
|
-
const publicKey =
|
|
225
|
-
const nodeAlgorithm =
|
|
223
|
+
function rsaVerify3(jwtAlg, data, publicJwk, signature) {
|
|
224
|
+
const publicKey = import_node_crypto.default.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
225
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
226
226
|
const verifyKey = isRsaPssAlg2(jwtAlg) ? {
|
|
227
227
|
key: publicKey,
|
|
228
|
-
padding:
|
|
229
|
-
saltLength:
|
|
228
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
229
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
230
230
|
} : publicKey;
|
|
231
|
-
return
|
|
231
|
+
return import_node_crypto.default.verify(nodeAlgorithm, data, verifyKey, signature);
|
|
232
232
|
}
|
|
233
|
-
function
|
|
234
|
-
const privateKey =
|
|
235
|
-
const nodeAlgorithm =
|
|
233
|
+
function rsaSignBase64Url3(jwtAlg, data, privateJwk) {
|
|
234
|
+
const privateKey = import_node_crypto.default.createPrivateKey({ key: privateJwk, format: "jwk" });
|
|
235
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
236
236
|
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
237
|
-
const sig = isRsaPssAlg2(jwtAlg) ?
|
|
238
|
-
padding:
|
|
239
|
-
saltLength:
|
|
240
|
-
}) :
|
|
237
|
+
const sig = isRsaPssAlg2(jwtAlg) ? rsaSign(nodeAlgorithm, buf, privateKey, {
|
|
238
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
239
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
240
|
+
}) : rsaSign(nodeAlgorithm, buf, privateKey);
|
|
241
241
|
return sig.toString("base64url");
|
|
242
242
|
}
|
|
243
|
-
function
|
|
243
|
+
function rsaVerifySync3(jwtAlg, data, publicJwk, signature) {
|
|
244
244
|
try {
|
|
245
|
-
const publicKey =
|
|
245
|
+
const publicKey = import_node_crypto.default.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
246
246
|
const dataBuf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
247
247
|
const sigBuf = Buffer.isBuffer(signature) ? signature : Buffer.from(signature);
|
|
248
248
|
if (jwtAlg === "EdDSA") {
|
|
249
|
-
return
|
|
249
|
+
return import_node_crypto.default.verify(null, dataBuf, publicKey, sigBuf);
|
|
250
250
|
}
|
|
251
|
-
const nodeAlgorithm =
|
|
251
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
252
252
|
const verifyKey = isRsaPssAlg2(jwtAlg) ? {
|
|
253
253
|
key: publicKey,
|
|
254
|
-
padding:
|
|
255
|
-
saltLength:
|
|
254
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
255
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
256
256
|
} : publicKey;
|
|
257
|
-
return
|
|
257
|
+
return import_node_crypto.default.verify(nodeAlgorithm, dataBuf, verifyKey, sigBuf);
|
|
258
258
|
} catch {
|
|
259
259
|
return false;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
function
|
|
263
|
-
const key =
|
|
262
|
+
function pemToPublicJwk3(pem) {
|
|
263
|
+
const key = import_node_crypto.default.createPublicKey({ key: pem, format: "pem" });
|
|
264
264
|
return key.export({ format: "jwk" });
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function createSignedJwt(payload, privateKey, kid, alg = "RS256") {
|
|
267
267
|
const header = { alg, typ: "JWT", kid };
|
|
268
268
|
const headerB64 = Buffer.from(JSON.stringify(header)).toString("base64url");
|
|
269
269
|
const payloadB64 = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
270
270
|
const signatureInput = `${headerB64}.${payloadB64}`;
|
|
271
|
-
const nodeAlgorithm =
|
|
272
|
-
const signature =
|
|
271
|
+
const nodeAlgorithm = jwtAlgToNodeAlg(alg);
|
|
272
|
+
const signature = rsaSign(
|
|
273
273
|
nodeAlgorithm,
|
|
274
274
|
Buffer.from(signatureInput),
|
|
275
275
|
privateKey,
|
|
276
276
|
isRsaPssAlg2(alg) ? {
|
|
277
|
-
padding:
|
|
278
|
-
saltLength:
|
|
277
|
+
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
278
|
+
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
279
279
|
} : void 0
|
|
280
280
|
);
|
|
281
281
|
const signatureB64 = signature.toString("base64url");
|
|
@@ -300,13 +300,12 @@ var import_sdk4 = require("@frontmcp/sdk");
|
|
|
300
300
|
var import_lazy_zod = require("@frontmcp/lazy-zod");
|
|
301
301
|
var import_lazy_zod2 = require("@frontmcp/lazy-zod");
|
|
302
302
|
var import_event_emitter = __toESM(require_node_event_emitter(), 1);
|
|
303
|
-
var
|
|
304
|
-
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
305
|
-
var import_hmac = require("@noble/hashes/hmac.js");
|
|
303
|
+
var import_aes = require("@noble/ciphers/aes.js");
|
|
306
304
|
var import_hkdf = require("@noble/hashes/hkdf.js");
|
|
305
|
+
var import_hmac = require("@noble/hashes/hmac.js");
|
|
306
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
307
307
|
var import_utils = require("@noble/hashes/utils.js");
|
|
308
|
-
var
|
|
309
|
-
var import_crypto_provider = __toESM(require_node(), 1);
|
|
308
|
+
var platformCrypto = __toESM(require_node(), 1);
|
|
310
309
|
var import_ast = require("@enclave-vm/ast");
|
|
311
310
|
var import_meta = {};
|
|
312
311
|
var __frontmcpModule = typeof process !== "undefined" && typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : void 0;
|
|
@@ -413,13 +412,6 @@ var init_fs2 = __esm({
|
|
|
413
412
|
init_fs();
|
|
414
413
|
}
|
|
415
414
|
});
|
|
416
|
-
function jwtAlgToNodeAlg(jwtAlg) {
|
|
417
|
-
const nodeAlg = JWT_ALG_TO_NODE_DIGEST[jwtAlg];
|
|
418
|
-
if (!nodeAlg) {
|
|
419
|
-
throw new Error(`Unsupported JWT algorithm: ${jwtAlg}`);
|
|
420
|
-
}
|
|
421
|
-
return nodeAlg;
|
|
422
|
-
}
|
|
423
415
|
function isRsaPssAlg(jwtAlg) {
|
|
424
416
|
return jwtAlg.startsWith("PS");
|
|
425
417
|
}
|
|
@@ -2206,176 +2198,18 @@ var init_key_persistence2 = __esm({
|
|
|
2206
2198
|
init_factory();
|
|
2207
2199
|
}
|
|
2208
2200
|
});
|
|
2209
|
-
var node_exports = {};
|
|
2210
|
-
__export2(node_exports, {
|
|
2211
|
-
createSignedJwt: () => createSignedJwt,
|
|
2212
|
-
cryptoProvider: () => nodeCrypto,
|
|
2213
|
-
generateRsaKeyPair: () => generateRsaKeyPair,
|
|
2214
|
-
isRsaPssAlg: () => isRsaPssAlg,
|
|
2215
|
-
jwtAlgToNodeAlg: () => jwtAlgToNodeAlg,
|
|
2216
|
-
nodeCrypto: () => nodeCrypto,
|
|
2217
|
-
pemToPublicJwk: () => pemToPublicJwk,
|
|
2218
|
-
rsaSign: () => rsaSign,
|
|
2219
|
-
rsaSignBase64Url: () => rsaSignBase64Url,
|
|
2220
|
-
rsaVerify: () => rsaVerify,
|
|
2221
|
-
rsaVerifySync: () => rsaVerifySync
|
|
2222
|
-
});
|
|
2223
|
-
function toUint8Array(buf) {
|
|
2224
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
2225
|
-
}
|
|
2226
|
-
function toBuffer(data) {
|
|
2227
|
-
if (typeof data === "string") {
|
|
2228
|
-
return Buffer.from(data, "utf8");
|
|
2229
|
-
}
|
|
2230
|
-
return Buffer.from(data);
|
|
2231
|
-
}
|
|
2232
|
-
function generateRsaKeyPair(modulusLength = 2048, alg = "RS256") {
|
|
2233
|
-
const kid = `rsa-key-${Date.now()}-${import_node_crypto.default.randomBytes(8).toString("hex")}`;
|
|
2234
|
-
const { privateKey, publicKey } = import_node_crypto.default.generateKeyPairSync("rsa", {
|
|
2235
|
-
modulusLength
|
|
2236
|
-
});
|
|
2237
|
-
const exported = publicKey.export({ format: "jwk" });
|
|
2238
|
-
const publicJwk = {
|
|
2239
|
-
...exported,
|
|
2240
|
-
kid,
|
|
2241
|
-
alg,
|
|
2242
|
-
use: "sig",
|
|
2243
|
-
kty: "RSA"
|
|
2244
|
-
};
|
|
2245
|
-
return { privateKey, publicKey, publicJwk };
|
|
2246
|
-
}
|
|
2247
|
-
function rsaSign(algorithm, data, privateKey, options) {
|
|
2248
|
-
const signingKey = options ? { key: privateKey, ...options } : privateKey;
|
|
2249
|
-
return import_node_crypto.default.sign(algorithm, data, signingKey);
|
|
2250
|
-
}
|
|
2251
|
-
function rsaVerify(jwtAlg, data, publicJwk, signature) {
|
|
2252
|
-
const publicKey = import_node_crypto.default.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
2253
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
2254
|
-
const verifyKey = isRsaPssAlg(jwtAlg) ? {
|
|
2255
|
-
key: publicKey,
|
|
2256
|
-
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
2257
|
-
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2258
|
-
} : publicKey;
|
|
2259
|
-
return import_node_crypto.default.verify(nodeAlgorithm, data, verifyKey, signature);
|
|
2260
|
-
}
|
|
2261
|
-
function rsaSignBase64Url(jwtAlg, data, privateJwk) {
|
|
2262
|
-
const privateKey = import_node_crypto.default.createPrivateKey({ key: privateJwk, format: "jwk" });
|
|
2263
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
2264
|
-
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
2265
|
-
const sig = isRsaPssAlg(jwtAlg) ? rsaSign(nodeAlgorithm, buf, privateKey, {
|
|
2266
|
-
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
2267
|
-
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2268
|
-
}) : rsaSign(nodeAlgorithm, buf, privateKey);
|
|
2269
|
-
return sig.toString("base64url");
|
|
2270
|
-
}
|
|
2271
|
-
function rsaVerifySync(jwtAlg, data, publicJwk, signature) {
|
|
2272
|
-
try {
|
|
2273
|
-
const publicKey = import_node_crypto.default.createPublicKey({ key: publicJwk, format: "jwk" });
|
|
2274
|
-
const dataBuf = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
2275
|
-
const sigBuf = Buffer.isBuffer(signature) ? signature : Buffer.from(signature);
|
|
2276
|
-
if (jwtAlg === "EdDSA") {
|
|
2277
|
-
return import_node_crypto.default.verify(null, dataBuf, publicKey, sigBuf);
|
|
2278
|
-
}
|
|
2279
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(jwtAlg);
|
|
2280
|
-
const verifyKey = isRsaPssAlg(jwtAlg) ? {
|
|
2281
|
-
key: publicKey,
|
|
2282
|
-
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
2283
|
-
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2284
|
-
} : publicKey;
|
|
2285
|
-
return import_node_crypto.default.verify(nodeAlgorithm, dataBuf, verifyKey, sigBuf);
|
|
2286
|
-
} catch {
|
|
2287
|
-
return false;
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
function pemToPublicJwk(pem) {
|
|
2291
|
-
const key = import_node_crypto.default.createPublicKey({ key: pem, format: "pem" });
|
|
2292
|
-
return key.export({ format: "jwk" });
|
|
2293
|
-
}
|
|
2294
|
-
function createSignedJwt(payload, privateKey, kid, alg = "RS256") {
|
|
2295
|
-
const header = { alg, typ: "JWT", kid };
|
|
2296
|
-
const headerB64 = Buffer.from(JSON.stringify(header)).toString("base64url");
|
|
2297
|
-
const payloadB64 = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
2298
|
-
const signatureInput = `${headerB64}.${payloadB64}`;
|
|
2299
|
-
const nodeAlgorithm = jwtAlgToNodeAlg(alg);
|
|
2300
|
-
const signature = rsaSign(
|
|
2301
|
-
nodeAlgorithm,
|
|
2302
|
-
Buffer.from(signatureInput),
|
|
2303
|
-
privateKey,
|
|
2304
|
-
isRsaPssAlg(alg) ? {
|
|
2305
|
-
padding: import_node_crypto.default.constants.RSA_PKCS1_PSS_PADDING,
|
|
2306
|
-
saltLength: import_node_crypto.default.constants.RSA_PSS_SALTLEN_DIGEST
|
|
2307
|
-
} : void 0
|
|
2308
|
-
);
|
|
2309
|
-
const signatureB64 = signature.toString("base64url");
|
|
2310
|
-
return `${headerB64}.${payloadB64}.${signatureB64}`;
|
|
2311
|
-
}
|
|
2312
|
-
var nodeCrypto;
|
|
2313
|
-
var init_node = __esm({
|
|
2314
|
-
"libs/utils/src/crypto/node.ts"() {
|
|
2315
|
-
"use strict";
|
|
2316
|
-
init_jwt_alg();
|
|
2317
|
-
init_jwt_alg();
|
|
2318
|
-
nodeCrypto = {
|
|
2319
|
-
randomUUID() {
|
|
2320
|
-
return import_node_crypto.default.randomUUID();
|
|
2321
|
-
},
|
|
2322
|
-
randomBytes(length) {
|
|
2323
|
-
return toUint8Array(import_node_crypto.default.randomBytes(length));
|
|
2324
|
-
},
|
|
2325
|
-
sha256(data) {
|
|
2326
|
-
const hash = import_node_crypto.default.createHash("sha256").update(toBuffer(data)).digest();
|
|
2327
|
-
return toUint8Array(hash);
|
|
2328
|
-
},
|
|
2329
|
-
sha256Hex(data) {
|
|
2330
|
-
return import_node_crypto.default.createHash("sha256").update(toBuffer(data)).digest("hex");
|
|
2331
|
-
},
|
|
2332
|
-
hmacSha256(key, data) {
|
|
2333
|
-
const hmac2 = import_node_crypto.default.createHmac("sha256", Buffer.from(key)).update(Buffer.from(data)).digest();
|
|
2334
|
-
return toUint8Array(hmac2);
|
|
2335
|
-
},
|
|
2336
|
-
hkdfSha256(ikm, salt, info, length) {
|
|
2337
|
-
const ikmBuf = Buffer.from(ikm);
|
|
2338
|
-
const saltBuf = salt.length > 0 ? Buffer.from(salt) : Buffer.alloc(32);
|
|
2339
|
-
const prk = import_node_crypto.default.createHmac("sha256", saltBuf).update(ikmBuf).digest();
|
|
2340
|
-
const hashLen = 32;
|
|
2341
|
-
const n = Math.ceil(length / hashLen);
|
|
2342
|
-
const chunks = [];
|
|
2343
|
-
let prev = Buffer.alloc(0);
|
|
2344
|
-
for (let i = 1; i <= n; i++) {
|
|
2345
|
-
prev = import_node_crypto.default.createHmac("sha256", prk).update(Buffer.concat([prev, Buffer.from(info), Buffer.from([i])])).digest();
|
|
2346
|
-
chunks.push(prev);
|
|
2347
|
-
}
|
|
2348
|
-
return toUint8Array(Buffer.concat(chunks).subarray(0, length));
|
|
2349
|
-
},
|
|
2350
|
-
encryptAesGcm(key, plaintext, iv) {
|
|
2351
|
-
const cipher = import_node_crypto.default.createCipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
2352
|
-
const encrypted = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]);
|
|
2353
|
-
const tag = cipher.getAuthTag();
|
|
2354
|
-
return {
|
|
2355
|
-
ciphertext: toUint8Array(encrypted),
|
|
2356
|
-
tag: toUint8Array(tag)
|
|
2357
|
-
};
|
|
2358
|
-
},
|
|
2359
|
-
decryptAesGcm(key, ciphertext, iv, tag) {
|
|
2360
|
-
const decipher = import_node_crypto.default.createDecipheriv("aes-256-gcm", Buffer.from(key), Buffer.from(iv));
|
|
2361
|
-
decipher.setAuthTag(Buffer.from(tag));
|
|
2362
|
-
const decrypted = Buffer.concat([decipher.update(Buffer.from(ciphertext)), decipher.final()]);
|
|
2363
|
-
return toUint8Array(decrypted);
|
|
2364
|
-
},
|
|
2365
|
-
timingSafeEqual(a, b) {
|
|
2366
|
-
if (a.length !== b.length) return false;
|
|
2367
|
-
return import_node_crypto.default.timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
2368
|
-
}
|
|
2369
|
-
};
|
|
2370
|
-
}
|
|
2371
|
-
});
|
|
2372
2201
|
var browser_exports = {};
|
|
2373
2202
|
__export2(browser_exports, {
|
|
2374
2203
|
browserCrypto: () => browserCrypto,
|
|
2375
2204
|
cryptoProvider: () => browserCrypto,
|
|
2205
|
+
generateRsaKeyPair: () => generateRsaKeyPair2,
|
|
2376
2206
|
isRsaPssAlg: () => isRsaPssAlg,
|
|
2377
2207
|
jwtAlgToWebCryptoAlg: () => jwtAlgToWebCryptoAlg,
|
|
2378
|
-
|
|
2208
|
+
pemToPublicJwk: () => pemToPublicJwk2,
|
|
2209
|
+
rsaSignBase64Url: () => rsaSignBase64Url2,
|
|
2210
|
+
rsaVerify: () => rsaVerify2,
|
|
2211
|
+
rsaVerifyBrowser: () => rsaVerifyBrowser,
|
|
2212
|
+
rsaVerifySync: () => rsaVerifySync2
|
|
2379
2213
|
});
|
|
2380
2214
|
function toBytes(data) {
|
|
2381
2215
|
if (typeof data === "string") {
|
|
@@ -2404,6 +2238,24 @@ function constantTimeEqual(a, b) {
|
|
|
2404
2238
|
}
|
|
2405
2239
|
return result === 0;
|
|
2406
2240
|
}
|
|
2241
|
+
function nodeOnly(name) {
|
|
2242
|
+
throw new Error(`${name} is only available in Node.js runtimes`);
|
|
2243
|
+
}
|
|
2244
|
+
function rsaVerify2() {
|
|
2245
|
+
return nodeOnly("rsaVerify");
|
|
2246
|
+
}
|
|
2247
|
+
function rsaSignBase64Url2() {
|
|
2248
|
+
return nodeOnly("rsaSignBase64Url");
|
|
2249
|
+
}
|
|
2250
|
+
function rsaVerifySync2() {
|
|
2251
|
+
return nodeOnly("rsaVerifySync");
|
|
2252
|
+
}
|
|
2253
|
+
function pemToPublicJwk2() {
|
|
2254
|
+
return nodeOnly("pemToPublicJwk");
|
|
2255
|
+
}
|
|
2256
|
+
function generateRsaKeyPair2() {
|
|
2257
|
+
return nodeOnly("generateRsaKeyPair");
|
|
2258
|
+
}
|
|
2407
2259
|
async function rsaVerifyBrowser(jwtAlg, data, publicJwk, signature) {
|
|
2408
2260
|
if (typeof globalThis.crypto?.subtle === "undefined") {
|
|
2409
2261
|
throw new Error("WebCrypto API (crypto.subtle) is not available in this environment");
|
|
@@ -2482,7 +2334,7 @@ var init_browser = __esm({
|
|
|
2482
2334
|
}
|
|
2483
2335
|
});
|
|
2484
2336
|
function getCrypto() {
|
|
2485
|
-
return
|
|
2337
|
+
return platformCrypto.cryptoProvider;
|
|
2486
2338
|
}
|
|
2487
2339
|
function randomUUID() {
|
|
2488
2340
|
return getCrypto().randomUUID();
|
|
@@ -2603,37 +2455,55 @@ function decodeOrRaw(encoded) {
|
|
|
2603
2455
|
return encoded;
|
|
2604
2456
|
}
|
|
2605
2457
|
}
|
|
2606
|
-
function
|
|
2458
|
+
function integerOrUndefined(text) {
|
|
2459
|
+
const value = Number.parseInt(text ?? "", 10);
|
|
2460
|
+
return Number.isNaN(value) ? void 0 : value;
|
|
2461
|
+
}
|
|
2462
|
+
function readRedisUrl(rawUrl) {
|
|
2607
2463
|
let url;
|
|
2608
2464
|
try {
|
|
2609
2465
|
url = new URL(rawUrl);
|
|
2610
2466
|
} catch {
|
|
2611
2467
|
return void 0;
|
|
2612
2468
|
}
|
|
2613
|
-
|
|
2614
|
-
const
|
|
2615
|
-
const
|
|
2616
|
-
const
|
|
2617
|
-
const
|
|
2618
|
-
|
|
2469
|
+
if (url.protocol !== "redis:" && url.protocol !== "rediss:") return void 0;
|
|
2470
|
+
const query = Object.fromEntries(url.searchParams);
|
|
2471
|
+
const { host, port, username, password, db, ...otherOptions } = query;
|
|
2472
|
+
const queryOptions = {};
|
|
2473
|
+
for (const [name, value = ""] of Object.entries(otherOptions)) {
|
|
2474
|
+
queryOptions[name] = name === "family" ? integerOrUndefined(value) ?? value : value;
|
|
2475
|
+
}
|
|
2476
|
+
return {
|
|
2477
|
+
host: url.hostname.replace(/^\[(.*)\]$/, "$1") || host,
|
|
2478
|
+
port: integerOrUndefined(url.port || port),
|
|
2479
|
+
username: decodeOrRaw(url.username) || username || void 0,
|
|
2480
|
+
password: decodeOrRaw(url.password) || password || void 0,
|
|
2481
|
+
db: integerOrUndefined(url.pathname.replace(/^\/+/, "") || db),
|
|
2482
|
+
tls: url.protocol === "rediss:",
|
|
2483
|
+
queryOptions
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
function mergeRedisUrlFields(rawUrl, fields) {
|
|
2487
|
+
const connection = readRedisUrl(rawUrl);
|
|
2488
|
+
if (!connection) return void 0;
|
|
2619
2489
|
const fillIns = {};
|
|
2620
2490
|
const conflicts = [];
|
|
2621
|
-
if (fields.host !== void 0 && fields.host !==
|
|
2491
|
+
if (fields.host !== void 0 && fields.host !== connection.host) conflicts.push("host");
|
|
2622
2492
|
if (fields.port !== void 0) {
|
|
2623
|
-
if (
|
|
2624
|
-
else if (fields.port !==
|
|
2493
|
+
if (connection.port === void 0) fillIns.port = fields.port;
|
|
2494
|
+
else if (fields.port !== connection.port) conflicts.push("port");
|
|
2625
2495
|
}
|
|
2626
2496
|
if (fields.password !== void 0) {
|
|
2627
|
-
if (
|
|
2628
|
-
else if (fields.password !==
|
|
2497
|
+
if (connection.password === void 0) fillIns.password = fields.password;
|
|
2498
|
+
else if (fields.password !== connection.password) conflicts.push("password");
|
|
2629
2499
|
}
|
|
2630
2500
|
if (fields.db !== void 0) {
|
|
2631
|
-
if (
|
|
2632
|
-
else if (fields.db !==
|
|
2501
|
+
if (connection.db === void 0) fillIns.db = fields.db;
|
|
2502
|
+
else if (fields.db !== connection.db) conflicts.push("db");
|
|
2633
2503
|
}
|
|
2634
|
-
if (fields.tls === true && !
|
|
2635
|
-
if (fields.tls === false &&
|
|
2636
|
-
return { fillIns, conflicts };
|
|
2504
|
+
if (fields.tls === true && !connection.tls) fillIns.tls = true;
|
|
2505
|
+
if (fields.tls === false && connection.tls) conflicts.push("tls");
|
|
2506
|
+
return { connection, fillIns, conflicts };
|
|
2637
2507
|
}
|
|
2638
2508
|
function describeRedisUrlConflicts(conflicts) {
|
|
2639
2509
|
return `redis ${conflicts.join(", ")} contradict${conflicts.length === 1 ? "s" : ""} redis.url. Fields beside a url only fill in what the URL leaves out (port, password, db, tls); put the value in the URL or drop the field.`;
|
|
@@ -2677,28 +2547,49 @@ function getRedisClass() {
|
|
|
2677
2547
|
});
|
|
2678
2548
|
}
|
|
2679
2549
|
}
|
|
2680
|
-
function
|
|
2550
|
+
function resolveUrlOptions(connectionUrl, options) {
|
|
2681
2551
|
const { url: configUrl, ...siblingFields } = { url: void 0, ...options.config };
|
|
2682
2552
|
if (options.url && configUrl && configUrl !== options.url) {
|
|
2683
2553
|
throw new StorageConfigError("redis", "redis.url and redis.config.url name different servers; set one of them.");
|
|
2684
2554
|
}
|
|
2685
|
-
|
|
2686
|
-
|
|
2555
|
+
return urlConnectionOptions(connectionUrl, siblingFields);
|
|
2556
|
+
}
|
|
2557
|
+
function urlConnectionOptions(url, fields) {
|
|
2558
|
+
const merge = mergeRedisUrlFields(url, fields);
|
|
2559
|
+
if (!merge) return void 0;
|
|
2560
|
+
if (merge.conflicts.length > 0) {
|
|
2687
2561
|
throw new StorageConfigError("redis", describeRedisUrlConflicts(merge.conflicts));
|
|
2688
2562
|
}
|
|
2689
|
-
|
|
2563
|
+
const { queryOptions, tls, ...stated } = merge.connection;
|
|
2564
|
+
return { ...queryOptions, ...stated, ...toFillInOptions(merge.fillIns), ...tls ? { tls: {} } : {} };
|
|
2565
|
+
}
|
|
2566
|
+
function toFillInOptions({ port, password, db, tls }) {
|
|
2567
|
+
return {
|
|
2568
|
+
...port !== void 0 ? { port } : {},
|
|
2569
|
+
...password !== void 0 ? { password } : {},
|
|
2570
|
+
...db !== void 0 ? { db } : {},
|
|
2571
|
+
...tls ? { tls: {} } : {}
|
|
2572
|
+
};
|
|
2690
2573
|
}
|
|
2691
2574
|
function createRedisClient(options) {
|
|
2575
|
+
const urlOptions = options.url ? urlConnectionOptions(options.url, options) : void 0;
|
|
2692
2576
|
const RedisClass = getRedisClass();
|
|
2693
2577
|
const baseOptions = { lazyConnect: false, maxRetriesPerRequest: 3 };
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2578
|
+
let client;
|
|
2579
|
+
if (urlOptions) {
|
|
2580
|
+
client = new RedisClass({ ...baseOptions, ...urlOptions });
|
|
2581
|
+
} else if (options.url) {
|
|
2582
|
+
client = new RedisClass(options.url, baseOptions);
|
|
2583
|
+
} else {
|
|
2584
|
+
client = new RedisClass({
|
|
2585
|
+
...baseOptions,
|
|
2586
|
+
host: options.host ?? "localhost",
|
|
2587
|
+
port: options.port ?? 6379,
|
|
2588
|
+
password: options.password,
|
|
2589
|
+
db: options.db ?? 0,
|
|
2590
|
+
tls: options.tls ? {} : void 0
|
|
2591
|
+
});
|
|
2592
|
+
}
|
|
2702
2593
|
attachRedisErrorListener(client, { label: options.label ?? "redis", logger: options.logger });
|
|
2703
2594
|
return client;
|
|
2704
2595
|
}
|
|
@@ -2723,7 +2614,8 @@ var init_redis = __esm({
|
|
|
2723
2614
|
keyPrefix;
|
|
2724
2615
|
subscriptionHandlers = /* @__PURE__ */ new Map();
|
|
2725
2616
|
connectionUrl;
|
|
2726
|
-
|
|
2617
|
+
/** The connection options of a URL this adapter reads itself; undefined for one only ioredis reads. */
|
|
2618
|
+
urlOptions;
|
|
2727
2619
|
constructor(options = {}) {
|
|
2728
2620
|
super();
|
|
2729
2621
|
const hasClient = options.client !== void 0;
|
|
@@ -2747,7 +2639,7 @@ var init_redis = __esm({
|
|
|
2747
2639
|
this.keyPrefix = options.keyPrefix ?? "";
|
|
2748
2640
|
const configUrl = options.config?.url;
|
|
2749
2641
|
this.connectionUrl = options.url ?? (typeof configUrl === "string" ? configUrl : void 0);
|
|
2750
|
-
this.
|
|
2642
|
+
this.urlOptions = this.connectionUrl ? resolveUrlOptions(this.connectionUrl, options) : void 0;
|
|
2751
2643
|
}
|
|
2752
2644
|
// ============================================
|
|
2753
2645
|
// Connection Lifecycle
|
|
@@ -2769,12 +2661,7 @@ var init_redis = __esm({
|
|
|
2769
2661
|
if (this.options.client) {
|
|
2770
2662
|
client = this.options.client;
|
|
2771
2663
|
} else {
|
|
2772
|
-
|
|
2773
|
-
if (this.connectionUrl) {
|
|
2774
|
-
client = new RedisClass(this.connectionUrl, this.buildRedisOptions());
|
|
2775
|
-
} else {
|
|
2776
|
-
client = new RedisClass(this.buildRedisOptions());
|
|
2777
|
-
}
|
|
2664
|
+
client = this.newClient();
|
|
2778
2665
|
client.on("error", recordSocketError);
|
|
2779
2666
|
}
|
|
2780
2667
|
await client.ping();
|
|
@@ -3008,15 +2895,7 @@ var init_redis = __esm({
|
|
|
3008
2895
|
*/
|
|
3009
2896
|
buildRedisOptions() {
|
|
3010
2897
|
if (this.connectionUrl) {
|
|
3011
|
-
|
|
3012
|
-
return {
|
|
3013
|
-
...port !== void 0 ? { port } : {},
|
|
3014
|
-
...password !== void 0 ? { password } : {},
|
|
3015
|
-
...db !== void 0 ? { db } : {},
|
|
3016
|
-
...tls ? { tls: {} } : {},
|
|
3017
|
-
lazyConnect: false,
|
|
3018
|
-
maxRetriesPerRequest: 3
|
|
3019
|
-
};
|
|
2898
|
+
return { lazyConnect: false, maxRetriesPerRequest: 3, ...this.urlOptions };
|
|
3020
2899
|
}
|
|
3021
2900
|
const config = this.options.config;
|
|
3022
2901
|
if (!config || typeof config.url === "string" || config.host === void 0) {
|
|
@@ -3032,16 +2911,23 @@ var init_redis = __esm({
|
|
|
3032
2911
|
maxRetriesPerRequest: 3
|
|
3033
2912
|
};
|
|
3034
2913
|
}
|
|
2914
|
+
/**
|
|
2915
|
+
* Create a client this adapter owns. A URL only ioredis reads goes to it as is.
|
|
2916
|
+
*/
|
|
2917
|
+
newClient() {
|
|
2918
|
+
const RedisClass = getRedisClass();
|
|
2919
|
+
if (this.connectionUrl && !this.urlOptions) {
|
|
2920
|
+
return new RedisClass(this.connectionUrl, this.buildRedisOptions());
|
|
2921
|
+
}
|
|
2922
|
+
return new RedisClass(this.buildRedisOptions());
|
|
2923
|
+
}
|
|
3035
2924
|
/**
|
|
3036
2925
|
* Create subscriber connection.
|
|
3037
2926
|
*/
|
|
3038
2927
|
async createSubscriber() {
|
|
3039
|
-
const RedisClass = getRedisClass();
|
|
3040
2928
|
let subscriber;
|
|
3041
|
-
if (this.connectionUrl) {
|
|
3042
|
-
subscriber =
|
|
3043
|
-
} else if (this.options.config) {
|
|
3044
|
-
subscriber = new RedisClass(this.buildRedisOptions());
|
|
2929
|
+
if (this.connectionUrl || this.options.config) {
|
|
2930
|
+
subscriber = this.newClient();
|
|
3045
2931
|
} else if (this.options.client) {
|
|
3046
2932
|
subscriber = this.options.client.duplicate();
|
|
3047
2933
|
} else {
|