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