toiljs 0.0.120 → 0.0.122

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.
@@ -663,11 +663,11 @@ var require_clean = __commonJS({
663
663
  "node_modules/semver/functions/clean.js"(exports, module) {
664
664
  "use strict";
665
665
  var parse = require_parse();
666
- var clean = (version2, options) => {
666
+ var clean2 = (version2, options) => {
667
667
  const s = parse(version2.trim().replace(/^[=v]+/, ""), options);
668
668
  return s ? s.version : null;
669
669
  };
670
- module.exports = clean;
670
+ module.exports = clean2;
671
671
  }
672
672
  });
673
673
 
@@ -2064,7 +2064,7 @@ var require_semver2 = __commonJS({
2064
2064
  var identifiers = require_identifiers();
2065
2065
  var parse = require_parse();
2066
2066
  var valid = require_valid();
2067
- var clean = require_clean();
2067
+ var clean2 = require_clean();
2068
2068
  var inc = require_inc();
2069
2069
  var diff = require_diff();
2070
2070
  var major = require_major();
@@ -2103,7 +2103,7 @@ var require_semver2 = __commonJS({
2103
2103
  module.exports = {
2104
2104
  parse,
2105
2105
  valid,
2106
- clean,
2106
+ clean: clean2,
2107
2107
  inc,
2108
2108
  diff,
2109
2109
  major,
@@ -3256,8 +3256,8 @@ var C = (o, e, s) => {
3256
3256
  var note = (o = "", e = "", s) => {
3257
3257
  const a2 = s?.output ?? process$1.stdout, i2 = s?.withGuide ?? settings.withGuide, c2 = s?.format ?? W$1, g = ["", ...C(o, getColumns(a2) - 6, c2).split(`
3258
3258
  `).map(c2), ""], n3 = dist_default2(e), t2 = Math.max(
3259
- g.reduce((m2, F) => {
3260
- const O = dist_default2(F);
3259
+ g.reduce((m2, F2) => {
3260
+ const O = dist_default2(F2);
3261
3261
  return O > m2 ? O : m2;
3262
3262
  }, 0),
3263
3263
  n3
@@ -3284,7 +3284,7 @@ var spinner = ({
3284
3284
  cancelMessage: G,
3285
3285
  errorMessage: O,
3286
3286
  frames: E = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"],
3287
- delay: F = unicode ? 80 : 120,
3287
+ delay: F2 = unicode ? 80 : 120,
3288
3288
  signal: m2,
3289
3289
  ...I2
3290
3290
  } = {}) => {
@@ -3310,8 +3310,8 @@ var spinner = ({
3310
3310
  }, C2 = (e) => e.replace(/\.+$/, ""), _ = (e) => {
3311
3311
  const r2 = (performance.now() - e) / 1e3, t2 = Math.floor(r2 / 60), o = Math.floor(r2 % 60);
3312
3312
  return t2 > 0 ? `[${t2}m ${o}s]` : `[${o}s]`;
3313
- }, N = I2.withGuide ?? settings.withGuide, P = (e = "") => {
3314
- d = true, M = block({ output: n3 }), s = C2(e), w = performance.now(), N && n3.write(`${styleText2("gray", S_BAR)}
3313
+ }, N2 = I2.withGuide ?? settings.withGuide, P = (e = "") => {
3314
+ d = true, M = block({ output: n3 }), s = C2(e), w = performance.now(), N2 && n3.write(`${styleText2("gray", S_BAR)}
3315
3315
  `);
3316
3316
  let r2 = 0, t2 = 0;
3317
3317
  A(), T = setInterval(() => {
@@ -3333,7 +3333,7 @@ var spinner = ({
3333
3333
  trim: false
3334
3334
  });
3335
3335
  n3.write(j), r2 = r2 + 1 < E.length ? r2 + 1 : 0, t2 = t2 < 4 ? t2 + 0.125 : 0;
3336
- }, F);
3336
+ }, F2);
3337
3337
  }, a2 = (e = "", r2 = 0, t2 = false) => {
3338
3338
  if (!d) return;
3339
3339
  d = false, clearInterval(T), y2();
@@ -3611,10 +3611,10 @@ function detectTailwind(deps) {
3611
3611
 
3612
3612
  // src/cli/proc.ts
3613
3613
  import { spawn } from "node:child_process";
3614
- function run(cmd, args, cwd, opts = {}) {
3614
+ function run(cmd, args, cwd, opts2 = {}) {
3615
3615
  return new Promise((resolve, reject) => {
3616
3616
  const onWindows = process.platform === "win32";
3617
- const stdio = opts.stdio ?? "ignore";
3617
+ const stdio = opts2.stdio ?? "ignore";
3618
3618
  const child = onWindows ? spawn([cmd, ...args].join(" "), { cwd, stdio, shell: true }) : spawn(cmd, args, { cwd, stdio });
3619
3619
  child.on("error", reject);
3620
3620
  child.on(
@@ -3923,9 +3923,9 @@ function describe(from, to) {
3923
3923
  if (remove.length) lines.push(`- ${remove.join(", ")}`);
3924
3924
  return lines.map((l2) => dim(" ") + l2).join("\n");
3925
3925
  }
3926
- async function runConfigure(opts) {
3926
+ async function runConfigure(opts2) {
3927
3927
  intro(accent(" toiljs configure "));
3928
- const root = path2.resolve(opts.root ?? opts.cwd);
3928
+ const root = path2.resolve(opts2.root ?? opts2.cwd);
3929
3929
  const pkgPath = path2.join(root, "package.json");
3930
3930
  let pkg;
3931
3931
  try {
@@ -3941,15 +3941,15 @@ async function runConfigure(opts) {
3941
3941
  tailwind: detectTailwind(deps)
3942
3942
  };
3943
3943
  const currentImages = await resolveImages(root);
3944
- const nonInteractive = opts.preprocessor !== void 0 || opts.tailwind !== void 0 || opts.images !== void 0;
3944
+ const nonInteractive = opts2.preprocessor !== void 0 || opts2.tailwind !== void 0 || opts2.images !== void 0;
3945
3945
  let target;
3946
3946
  let targetImages;
3947
3947
  if (nonInteractive) {
3948
3948
  target = {
3949
- preprocessor: opts.preprocessor ?? current.preprocessor,
3950
- tailwind: opts.tailwind ?? current.tailwind
3949
+ preprocessor: opts2.preprocessor ?? current.preprocessor,
3950
+ tailwind: opts2.tailwind ?? current.tailwind
3951
3951
  };
3952
- targetImages = opts.images ?? currentImages;
3952
+ targetImages = opts2.images ?? currentImages;
3953
3953
  } else {
3954
3954
  const ppChoice = await select({
3955
3955
  message: "CSS preprocessor",
@@ -3988,7 +3988,7 @@ async function runConfigure(opts) {
3988
3988
  s.stop("Updated project files");
3989
3989
  if (styleChanged) {
3990
3990
  const pm = await detectPackageManager(root);
3991
- if (opts.install === false) {
3991
+ if (opts2.install === false) {
3992
3992
  note(`${import_picocolors2.default.cyan(`${pm} install`)} to sync the dependency changes.`, "Next step");
3993
3993
  } else {
3994
3994
  const i2 = spinner();
@@ -4066,7 +4066,7 @@ function scaffold(name, template, features, aiTools, images) {
4066
4066
  oxlint: "^1.83.0",
4067
4067
  "oxlint-tsgolint": "^7.0.2001",
4068
4068
  prettier: "^3.9.6",
4069
- toilscript: "^0.1.60",
4069
+ toilscript: "^0.1.63",
4070
4070
  typescript: "^7.0.2"
4071
4071
  };
4072
4072
  for (const dep of requiredPackages(features).sort()) {
@@ -4094,10 +4094,8 @@ function scaffold(name, template, features, aiTools, images) {
4094
4094
  };
4095
4095
  const files = {
4096
4096
  "package.json": JSON.stringify(pkg, null, 4) + "\n",
4097
- "toil.config.ts": `import { defineConfig } from 'toiljs/compiler';
4098
-
4099
- export default defineConfig({
4100
- client: {
4097
+ "toil.config.ts": "import { defineConfig } from 'toiljs/compiler';\n\nexport default defineConfig({\n" + // The app starter's session routes use the identity fields injected by built-in auth.
4098
+ (template === "app" ? " server: { auth: true },\n" : "") + ` client: {
4101
4099
  // Optimize images at build time (resize/compress imported images).
4102
4100
  images: ${String(images)},
4103
4101
  },
@@ -4407,11 +4405,11 @@ async function writeFiles(dir, files) {
4407
4405
  await fs3.writeFile(full, contents, "utf8");
4408
4406
  }
4409
4407
  }
4410
- async function runCreate(opts) {
4408
+ async function runCreate(opts2) {
4411
4409
  intro(accent(" toiljs create "));
4412
- let name = opts.name;
4410
+ let name = opts2.name;
4413
4411
  if (!name) {
4414
- if (opts.yes) {
4412
+ if (opts2.yes) {
4415
4413
  name = "my-toil-app";
4416
4414
  } else {
4417
4415
  const answer = await text({
@@ -4432,14 +4430,14 @@ async function runCreate(opts) {
4432
4430
  cancel(valid);
4433
4431
  process.exit(1);
4434
4432
  }
4435
- const targetDir = resolveProjectDir(opts.cwd, name);
4433
+ const targetDir = resolveProjectDir(opts2.cwd, name);
4436
4434
  if (targetDir === null) {
4437
4435
  cancel('Project name must stay inside the current directory (no "..", no absolute paths).');
4438
4436
  process.exit(1);
4439
4437
  }
4440
- const rel = path4.relative(opts.cwd, targetDir) || ".";
4438
+ const rel = path4.relative(opts2.cwd, targetDir) || ".";
4441
4439
  if (!await isEmptyDir(targetDir)) {
4442
- if (opts.yes) {
4440
+ if (opts2.yes) {
4443
4441
  cancel(`Directory ${import_picocolors3.default.cyan(rel)} is not empty.`);
4444
4442
  process.exit(1);
4445
4443
  }
@@ -4453,8 +4451,8 @@ async function runCreate(opts) {
4453
4451
  process.exit(0);
4454
4452
  }
4455
4453
  }
4456
- let template = opts.template ?? "app";
4457
- if (!opts.template && !opts.yes) {
4454
+ let template = opts2.template ?? "app";
4455
+ if (!opts2.template && !opts2.yes) {
4458
4456
  const templateOptions = [
4459
4457
  {
4460
4458
  value: "app",
@@ -4476,10 +4474,10 @@ async function runCreate(opts) {
4476
4474
  bail2(choice);
4477
4475
  template = choice === "minimal" || choice === "agent" ? choice : "app";
4478
4476
  }
4479
- let preprocessor = opts.preprocessor ?? "css";
4480
- let tailwind = opts.tailwind ?? false;
4481
- if (!opts.yes) {
4482
- if (opts.preprocessor === void 0) {
4477
+ let preprocessor = opts2.preprocessor ?? "css";
4478
+ let tailwind = opts2.tailwind ?? false;
4479
+ if (!opts2.yes) {
4480
+ if (opts2.preprocessor === void 0) {
4483
4481
  const choice = await select({
4484
4482
  message: "Styling",
4485
4483
  options: PREPROCESSORS.map((value) => ({
@@ -4491,15 +4489,15 @@ async function runCreate(opts) {
4491
4489
  bail2(choice);
4492
4490
  preprocessor = choice;
4493
4491
  }
4494
- if (opts.tailwind === void 0) {
4492
+ if (opts2.tailwind === void 0) {
4495
4493
  const tw = await confirm({ message: "Add Tailwind CSS?", initialValue: false });
4496
4494
  bail2(tw);
4497
4495
  tailwind = tw;
4498
4496
  }
4499
4497
  }
4500
4498
  const features = { preprocessor, tailwind };
4501
- let aiTools = opts.ai === false ? [] : [...AI_HELPER_IDS];
4502
- if (opts.ai === void 0 && !opts.yes) {
4499
+ let aiTools = opts2.ai === false ? [] : [...AI_HELPER_IDS];
4500
+ if (opts2.ai === void 0 && !opts2.yes) {
4503
4501
  const picked = await multiselect({
4504
4502
  message: "AI assistant files (read by Claude, Cursor, Codex, Copilot)",
4505
4503
  options: [
@@ -4512,21 +4510,21 @@ async function runCreate(opts) {
4512
4510
  bail2(picked);
4513
4511
  aiTools = picked.includes("none") ? [] : picked;
4514
4512
  }
4515
- let images = opts.images ?? true;
4516
- if (opts.images === void 0 && !opts.yes) {
4513
+ let images = opts2.images ?? true;
4514
+ if (opts2.images === void 0 && !opts2.yes) {
4517
4515
  const im = await confirm({ message: "Optimize images at build time?", initialValue: true });
4518
4516
  bail2(im);
4519
4517
  images = im;
4520
4518
  }
4521
- let initGit = opts.git ?? false;
4522
- let install = opts.install ?? true;
4523
- const pm = opts.pm ?? "npm";
4519
+ let initGit = opts2.git ?? false;
4520
+ let install = opts2.install ?? true;
4521
+ const pm = opts2.pm ?? "npm";
4524
4522
  if (!isPackageManager(pm)) {
4525
4523
  cancel(`Unsupported package manager: ${pm} (use npm, pnpm, yarn, or bun).`);
4526
4524
  process.exit(1);
4527
4525
  }
4528
- if (!opts.yes) {
4529
- if (opts.git === void 0) {
4526
+ if (!opts2.yes) {
4527
+ if (opts2.git === void 0) {
4530
4528
  const g = await confirm({
4531
4529
  message: "Initialize a git repository?",
4532
4530
  initialValue: true
@@ -4534,7 +4532,7 @@ async function runCreate(opts) {
4534
4532
  bail2(g);
4535
4533
  initGit = g;
4536
4534
  }
4537
- if (opts.install === void 0) {
4535
+ if (opts2.install === void 0) {
4538
4536
  const i2 = await confirm({ message: "Install dependencies now?", initialValue: true });
4539
4537
  bail2(i2);
4540
4538
  install = i2;
@@ -4547,6 +4545,8 @@ async function runCreate(opts) {
4547
4545
  await fs3.cp(appClientDir(), path4.join(targetDir, "client"), { recursive: true });
4548
4546
  const serverAllow = /* @__PURE__ */ new Set([
4549
4547
  "main.ts",
4548
+ "main.stream.ts",
4549
+ "SsrHelloRender.ts",
4550
4550
  "README.md",
4551
4551
  "tsconfig.json",
4552
4552
  "toil-server-env.d.ts",
@@ -4554,6 +4554,7 @@ async function runCreate(opts) {
4554
4554
  "models",
4555
4555
  "routes",
4556
4556
  "services",
4557
+ "streams",
4557
4558
  "scheduled"
4558
4559
  ]);
4559
4560
  const serverSrc = appServerDir();
@@ -4611,8 +4612,8 @@ async function runCreate(opts) {
4611
4612
  import fs4 from "node:fs";
4612
4613
  import path5 from "node:path";
4613
4614
  var FAMILIES = ["store", "views", "members", "counters", "events", "eventDedup", "capacity"];
4614
- function devdataPath(opts) {
4615
- return path5.join(path5.resolve(opts.root ?? process.cwd()), ".toil", "devdata.json");
4615
+ function devdataPath(opts2) {
4616
+ return path5.join(path5.resolve(opts2.root ?? process.cwd()), ".toil", "devdata.json");
4616
4617
  }
4617
4618
  function out(line) {
4618
4619
  process.stdout.write(line + "\n");
@@ -4634,8 +4635,8 @@ function familyCounts(file) {
4634
4635
  function isSnapshot(v) {
4635
4636
  return typeof v === "object" && v !== null && FAMILIES.every((f) => f in v);
4636
4637
  }
4637
- function runDb(action, fileArg, opts) {
4638
- const file = devdataPath(opts);
4638
+ function runDb(action, fileArg, opts2) {
4639
+ const file = devdataPath(opts2);
4639
4640
  const rel = path5.relative(process.cwd(), file) || file;
4640
4641
  switch (action) {
4641
4642
  case "reset":
@@ -5061,7 +5062,7 @@ function checkWasmBuilt(exists) {
5061
5062
  fix: "Run your server build (toilscript) before toiljs start."
5062
5063
  };
5063
5064
  }
5064
- var RPC_TOILSCRIPT_MIN = "0.1.27";
5065
+ var RPC_TOILSCRIPT_MIN = "0.1.63";
5065
5066
  function checkRpcWiring(f) {
5066
5067
  const missing = [];
5067
5068
  if (!f.toilscriptOk) missing.push(`toilscript >=${RPC_TOILSCRIPT_MIN}`);
@@ -5722,8 +5723,8 @@ function renderHuman(groups) {
5722
5723
  out2.push("");
5723
5724
  process.stdout.write(out2.join("\n") + "\n");
5724
5725
  }
5725
- async function runDoctor(opts) {
5726
- const root = path6.resolve(opts.root ?? opts.cwd);
5726
+ async function runDoctor(opts2) {
5727
+ const root = path6.resolve(opts2.root ?? opts2.cwd);
5727
5728
  const meta = frameworkMeta();
5728
5729
  const projectPkg = readJsonObject(path6.join(root, "package.json"));
5729
5730
  const deps = {
@@ -5782,7 +5783,7 @@ async function runDoctor(opts) {
5782
5783
  }
5783
5784
  const peerName = (n3) => checkPeer(n3, deps[n3] ?? null, meta.peers[n3] ?? "*");
5784
5785
  const peerChecks = Object.keys(meta.peers).filter((n3) => n3 !== "typescript").map(peerName);
5785
- const typeScriptFix = opts.fix ? applyTypeScriptFix(root) : null;
5786
+ const typeScriptFix = opts2.fix ? applyTypeScriptFix(root) : null;
5786
5787
  const declaredTypeScript = (() => {
5787
5788
  const pkg = readJsonObject(path6.join(root, "package.json"));
5788
5789
  if (pkg === null) return deps.typescript ?? null;
@@ -5798,9 +5799,9 @@ async function runDoctor(opts) {
5798
5799
  installedVersion(root, "typescript"),
5799
5800
  declaredTypeScript
5800
5801
  );
5801
- const rpcFix = serverPresent && opts.fix ? applyRpcFix(root) : null;
5802
- const prettierFix = serverPresent && opts.fix ? applyPrettierFix(root, projectPkg) : null;
5803
- const editorFix = opts.fix ? applyServerEditorFix(root, toilconfig) : null;
5802
+ const rpcFix = serverPresent && opts2.fix ? applyRpcFix(root) : null;
5803
+ const prettierFix = serverPresent && opts2.fix ? applyPrettierFix(root, projectPkg) : null;
5804
+ const editorFix = opts2.fix ? applyServerEditorFix(root, toilconfig) : null;
5804
5805
  const rpcFacts = gatherRpcFacts(root);
5805
5806
  const restFacts = gatherRestFacts(root, toilconfig);
5806
5807
  const authFacts = gatherAuthFacts(root, toilconfig);
@@ -5887,7 +5888,7 @@ async function runDoctor(opts) {
5887
5888
  groups.push({ title: "Security", checks: [checkAuthSecrets(authFacts)] });
5888
5889
  }
5889
5890
  const summary = summarize(groups);
5890
- if (opts.json) {
5891
+ if (opts2.json) {
5891
5892
  process.stdout.write(JSON.stringify({ groups, summary, fixed: serverFix }, null, 2) + "\n");
5892
5893
  } else {
5893
5894
  process.stdout.write("\n" + accent(" Doctor") + dim(` ${root}`) + "\n\n");
@@ -5912,15 +5913,1019 @@ function renderFix(result) {
5912
5913
  process.stdout.write(out2.join("\n") + "\n\n");
5913
5914
  }
5914
5915
 
5916
+ // src/cli/generate.ts
5917
+ import { randomBytes as randomBytes3, timingSafeEqual } from "node:crypto";
5918
+ import fs6 from "node:fs";
5919
+ import path7 from "node:path";
5920
+ import { parseEnv } from "node:util";
5921
+
5922
+ // node_modules/@noble/hashes/_u64.js
5923
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
5924
+ var _32n = /* @__PURE__ */ BigInt(32);
5925
+ function fromBig(n3, le = false) {
5926
+ if (le)
5927
+ return { h: Number(n3 & U32_MASK64), l: Number(n3 >> _32n & U32_MASK64) };
5928
+ return { h: Number(n3 >> _32n & U32_MASK64) | 0, l: Number(n3 & U32_MASK64) | 0 };
5929
+ }
5930
+ function split(lst, le = false) {
5931
+ const len = lst.length;
5932
+ let Ah = new Uint32Array(len);
5933
+ let Al = new Uint32Array(len);
5934
+ for (let i2 = 0; i2 < len; i2++) {
5935
+ const { h: h2, l: l2 } = fromBig(lst[i2], le);
5936
+ [Ah[i2], Al[i2]] = [h2, l2];
5937
+ }
5938
+ return [Ah, Al];
5939
+ }
5940
+ var rotlSH = (h2, l2, s) => h2 << s | l2 >>> 32 - s;
5941
+ var rotlSL = (h2, l2, s) => l2 << s | h2 >>> 32 - s;
5942
+ var rotlBH = (h2, l2, s) => l2 << s - 32 | h2 >>> 64 - s;
5943
+ var rotlBL = (h2, l2, s) => h2 << s - 32 | l2 >>> 64 - s;
5944
+
5945
+ // node_modules/@noble/hashes/utils.js
5946
+ function isBytes(a2) {
5947
+ return a2 instanceof Uint8Array || ArrayBuffer.isView(a2) && a2.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a2 && a2.BYTES_PER_ELEMENT === 1;
5948
+ }
5949
+ function anumber(n3, title = "") {
5950
+ if (typeof n3 !== "number") {
5951
+ const prefix = title && `"${title}" `;
5952
+ throw new TypeError(`${prefix}expected number, got ${typeof n3}`);
5953
+ }
5954
+ if (!Number.isSafeInteger(n3) || n3 < 0) {
5955
+ const prefix = title && `"${title}" `;
5956
+ throw new RangeError(`${prefix}expected integer >= 0, got ${n3}`);
5957
+ }
5958
+ }
5959
+ function abytes(value, length, title = "") {
5960
+ const bytes = isBytes(value);
5961
+ const len = value?.length;
5962
+ const needsLen = length !== void 0;
5963
+ if (!bytes || needsLen && len !== length) {
5964
+ const prefix = title && `"${title}" `;
5965
+ const ofLen = needsLen ? ` of length ${length}` : "";
5966
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
5967
+ const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
5968
+ if (!bytes)
5969
+ throw new TypeError(message);
5970
+ throw new RangeError(message);
5971
+ }
5972
+ return value;
5973
+ }
5974
+ function aexists(instance, checkFinished = true) {
5975
+ if (instance.destroyed)
5976
+ throw new Error("Hash instance has been destroyed");
5977
+ if (checkFinished && instance.finished)
5978
+ throw new Error("Hash#digest() has already been called");
5979
+ }
5980
+ function aoutput(out2, instance) {
5981
+ abytes(out2, void 0, "digestInto() output");
5982
+ const min = instance.outputLen;
5983
+ if (out2.length < min) {
5984
+ throw new RangeError('"digestInto() output" expected to be of length >=' + min);
5985
+ }
5986
+ }
5987
+ function u32(arr) {
5988
+ return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
5989
+ }
5990
+ function clean(...arrays) {
5991
+ for (let i2 = 0; i2 < arrays.length; i2++) {
5992
+ arrays[i2].fill(0);
5993
+ }
5994
+ }
5995
+ var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
5996
+ function byteSwap(word) {
5997
+ return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
5998
+ }
5999
+ function byteSwap32(arr) {
6000
+ for (let i2 = 0; i2 < arr.length; i2++) {
6001
+ arr[i2] = byteSwap(arr[i2]);
6002
+ }
6003
+ return arr;
6004
+ }
6005
+ var swap32IfBE = isLE ? (u3) => u3 : byteSwap32;
6006
+ function createHasher(hashCons, info = {}) {
6007
+ const hashC = (msg, opts2) => hashCons(opts2).update(msg).digest();
6008
+ const tmp = hashCons(void 0);
6009
+ hashC.outputLen = tmp.outputLen;
6010
+ hashC.blockLen = tmp.blockLen;
6011
+ hashC.canXOF = tmp.canXOF;
6012
+ hashC.create = (opts2) => hashCons(opts2);
6013
+ Object.assign(hashC, info);
6014
+ return Object.freeze(hashC);
6015
+ }
6016
+ function randomBytes(bytesLength = 32) {
6017
+ anumber(bytesLength, "bytesLength");
6018
+ const cr = typeof globalThis === "object" ? globalThis.crypto : null;
6019
+ if (typeof cr?.getRandomValues !== "function")
6020
+ throw new Error("crypto.getRandomValues must be defined");
6021
+ if (bytesLength > 65536)
6022
+ throw new RangeError(`"bytesLength" expected <= 65536, got ${bytesLength}`);
6023
+ return cr.getRandomValues(new Uint8Array(bytesLength));
6024
+ }
6025
+ var oidNist = (suffix) => ({
6026
+ // Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
6027
+ // Larger suffix values would need base-128 OID encoding and a different length byte.
6028
+ oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
6029
+ });
6030
+
6031
+ // node_modules/@noble/hashes/sha3.js
6032
+ var _0n = BigInt(0);
6033
+ var _1n = BigInt(1);
6034
+ var _2n = BigInt(2);
6035
+ var _7n = BigInt(7);
6036
+ var _256n = BigInt(256);
6037
+ var _0x71n = BigInt(113);
6038
+ var SHA3_PI = [];
6039
+ var SHA3_ROTL = [];
6040
+ var _SHA3_IOTA = [];
6041
+ for (let round = 0, R2 = _1n, x = 1, y2 = 0; round < 24; round++) {
6042
+ [x, y2] = [y2, (2 * x + 3 * y2) % 5];
6043
+ SHA3_PI.push(2 * (5 * y2 + x));
6044
+ SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
6045
+ let t2 = _0n;
6046
+ for (let j = 0; j < 7; j++) {
6047
+ R2 = (R2 << _1n ^ (R2 >> _7n) * _0x71n) % _256n;
6048
+ if (R2 & _2n)
6049
+ t2 ^= _1n << (_1n << BigInt(j)) - _1n;
6050
+ }
6051
+ _SHA3_IOTA.push(t2);
6052
+ }
6053
+ var IOTAS = split(_SHA3_IOTA, true);
6054
+ var SHA3_IOTA_H = IOTAS[0];
6055
+ var SHA3_IOTA_L = IOTAS[1];
6056
+ var rotlH = (h2, l2, s) => s > 32 ? rotlBH(h2, l2, s) : rotlSH(h2, l2, s);
6057
+ var rotlL = (h2, l2, s) => s > 32 ? rotlBL(h2, l2, s) : rotlSL(h2, l2, s);
6058
+ function keccakP(s, rounds = 24) {
6059
+ anumber(rounds, "rounds");
6060
+ if (rounds < 1 || rounds > 24)
6061
+ throw new Error('"rounds" expected integer 1..24');
6062
+ const B = new Uint32Array(5 * 2);
6063
+ for (let round = 24 - rounds; round < 24; round++) {
6064
+ for (let x = 0; x < 10; x++)
6065
+ B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
6066
+ for (let x = 0; x < 10; x += 2) {
6067
+ const idx1 = (x + 8) % 10;
6068
+ const idx0 = (x + 2) % 10;
6069
+ const B0 = B[idx0];
6070
+ const B1 = B[idx0 + 1];
6071
+ const Th = rotlH(B0, B1, 1) ^ B[idx1];
6072
+ const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
6073
+ for (let y2 = 0; y2 < 50; y2 += 10) {
6074
+ s[x + y2] ^= Th;
6075
+ s[x + y2 + 1] ^= Tl;
6076
+ }
6077
+ }
6078
+ let curH = s[2];
6079
+ let curL = s[3];
6080
+ for (let t2 = 0; t2 < 24; t2++) {
6081
+ const shift = SHA3_ROTL[t2];
6082
+ const Th = rotlH(curH, curL, shift);
6083
+ const Tl = rotlL(curH, curL, shift);
6084
+ const PI = SHA3_PI[t2];
6085
+ curH = s[PI];
6086
+ curL = s[PI + 1];
6087
+ s[PI] = Th;
6088
+ s[PI + 1] = Tl;
6089
+ }
6090
+ for (let y2 = 0; y2 < 50; y2 += 10) {
6091
+ const b0 = s[y2], b1 = s[y2 + 1], b2 = s[y2 + 2], b3 = s[y2 + 3];
6092
+ s[y2] ^= ~s[y2 + 2] & s[y2 + 4];
6093
+ s[y2 + 1] ^= ~s[y2 + 3] & s[y2 + 5];
6094
+ s[y2 + 2] ^= ~s[y2 + 4] & s[y2 + 6];
6095
+ s[y2 + 3] ^= ~s[y2 + 5] & s[y2 + 7];
6096
+ s[y2 + 4] ^= ~s[y2 + 6] & s[y2 + 8];
6097
+ s[y2 + 5] ^= ~s[y2 + 7] & s[y2 + 9];
6098
+ s[y2 + 6] ^= ~s[y2 + 8] & b0;
6099
+ s[y2 + 7] ^= ~s[y2 + 9] & b1;
6100
+ s[y2 + 8] ^= ~b0 & b2;
6101
+ s[y2 + 9] ^= ~b1 & b3;
6102
+ }
6103
+ s[0] ^= SHA3_IOTA_H[round];
6104
+ s[1] ^= SHA3_IOTA_L[round];
6105
+ }
6106
+ clean(B);
6107
+ }
6108
+ var Keccak = class _Keccak {
6109
+ state;
6110
+ pos = 0;
6111
+ posOut = 0;
6112
+ finished = false;
6113
+ state32;
6114
+ destroyed = false;
6115
+ blockLen;
6116
+ suffix;
6117
+ outputLen;
6118
+ canXOF;
6119
+ enableXOF = false;
6120
+ rounds;
6121
+ // NOTE: we accept arguments in bytes instead of bits here.
6122
+ constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
6123
+ this.blockLen = blockLen;
6124
+ this.suffix = suffix;
6125
+ this.outputLen = outputLen;
6126
+ this.enableXOF = enableXOF;
6127
+ this.canXOF = enableXOF;
6128
+ this.rounds = rounds;
6129
+ anumber(outputLen, "outputLen");
6130
+ if (!(0 < blockLen && blockLen < 200))
6131
+ throw new Error("only keccak-f1600 function is supported");
6132
+ this.state = new Uint8Array(200);
6133
+ this.state32 = u32(this.state);
6134
+ }
6135
+ clone() {
6136
+ return this._cloneInto();
6137
+ }
6138
+ keccak() {
6139
+ swap32IfBE(this.state32);
6140
+ keccakP(this.state32, this.rounds);
6141
+ swap32IfBE(this.state32);
6142
+ this.posOut = 0;
6143
+ this.pos = 0;
6144
+ }
6145
+ update(data) {
6146
+ aexists(this);
6147
+ abytes(data);
6148
+ const { blockLen, state } = this;
6149
+ const len = data.length;
6150
+ for (let pos = 0; pos < len; ) {
6151
+ const take = Math.min(blockLen - this.pos, len - pos);
6152
+ for (let i2 = 0; i2 < take; i2++)
6153
+ state[this.pos++] ^= data[pos++];
6154
+ if (this.pos === blockLen)
6155
+ this.keccak();
6156
+ }
6157
+ return this;
6158
+ }
6159
+ finish() {
6160
+ if (this.finished)
6161
+ return;
6162
+ this.finished = true;
6163
+ const { state, suffix, pos, blockLen } = this;
6164
+ state[pos] ^= suffix;
6165
+ if ((suffix & 128) !== 0 && pos === blockLen - 1)
6166
+ this.keccak();
6167
+ state[blockLen - 1] ^= 128;
6168
+ this.keccak();
6169
+ }
6170
+ writeInto(out2) {
6171
+ aexists(this, false);
6172
+ abytes(out2);
6173
+ this.finish();
6174
+ const bufferOut = this.state;
6175
+ const { blockLen } = this;
6176
+ for (let pos = 0, len = out2.length; pos < len; ) {
6177
+ if (this.posOut >= blockLen)
6178
+ this.keccak();
6179
+ const take = Math.min(blockLen - this.posOut, len - pos);
6180
+ out2.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
6181
+ this.posOut += take;
6182
+ pos += take;
6183
+ }
6184
+ return out2;
6185
+ }
6186
+ xofInto(out2) {
6187
+ if (!this.enableXOF)
6188
+ throw new Error("XOF is not possible for this instance");
6189
+ return this.writeInto(out2);
6190
+ }
6191
+ xof(bytes) {
6192
+ anumber(bytes);
6193
+ return this.xofInto(new Uint8Array(bytes));
6194
+ }
6195
+ digestInto(out2) {
6196
+ aoutput(out2, this);
6197
+ if (this.finished)
6198
+ throw new Error("digest() was already called");
6199
+ this.writeInto(out2.subarray(0, this.outputLen));
6200
+ this.destroy();
6201
+ }
6202
+ digest() {
6203
+ const out2 = new Uint8Array(this.outputLen);
6204
+ this.digestInto(out2);
6205
+ return out2;
6206
+ }
6207
+ destroy() {
6208
+ this.destroyed = true;
6209
+ clean(this.state);
6210
+ }
6211
+ _cloneInto(to) {
6212
+ const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
6213
+ to ||= new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
6214
+ to.blockLen = blockLen;
6215
+ to.state32.set(this.state32);
6216
+ to.pos = this.pos;
6217
+ to.posOut = this.posOut;
6218
+ to.finished = this.finished;
6219
+ to.rounds = rounds;
6220
+ to.suffix = suffix;
6221
+ to.outputLen = outputLen;
6222
+ to.enableXOF = enableXOF;
6223
+ to.canXOF = this.canXOF;
6224
+ to.destroyed = this.destroyed;
6225
+ return to;
6226
+ }
6227
+ };
6228
+ var genKeccak = (suffix, blockLen, outputLen, info = {}) => createHasher(() => new Keccak(blockLen, suffix, outputLen), info);
6229
+ var sha3_256 = /* @__PURE__ */ genKeccak(
6230
+ 6,
6231
+ 136,
6232
+ 32,
6233
+ /* @__PURE__ */ oidNist(8)
6234
+ );
6235
+ var sha3_512 = /* @__PURE__ */ genKeccak(
6236
+ 6,
6237
+ 72,
6238
+ 64,
6239
+ /* @__PURE__ */ oidNist(10)
6240
+ );
6241
+ var genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts2 = {}) => new Keccak(blockLen, suffix, opts2.dkLen === void 0 ? outputLen : opts2.dkLen, true), info);
6242
+ var shake128 = /* @__PURE__ */ genShake(31, 168, 16, /* @__PURE__ */ oidNist(11));
6243
+ var shake256 = /* @__PURE__ */ genShake(31, 136, 32, /* @__PURE__ */ oidNist(12));
6244
+
6245
+ // node_modules/@dacely/noble-post-quantum/node_modules/@noble/curves/abstract/fft.js
6246
+ function checkU32(n3) {
6247
+ if (!Number.isSafeInteger(n3) || n3 < 0 || n3 > 4294967295)
6248
+ throw new Error("wrong u32 integer:" + n3);
6249
+ return n3;
6250
+ }
6251
+ function isPowerOfTwo(x) {
6252
+ checkU32(x);
6253
+ return (x & x - 1) === 0 && x !== 0;
6254
+ }
6255
+ function reverseBits(n3, bits) {
6256
+ checkU32(n3);
6257
+ if (!Number.isSafeInteger(bits) || bits < 0 || bits > 32)
6258
+ throw new Error(`expected integer 0 <= bits <= 32, got ${bits}`);
6259
+ let reversed = 0;
6260
+ for (let i2 = 0; i2 < bits; i2++, n3 >>>= 1)
6261
+ reversed = reversed << 1 | n3 & 1;
6262
+ return reversed >>> 0;
6263
+ }
6264
+ function log2(n3) {
6265
+ checkU32(n3);
6266
+ return 31 - Math.clz32(n3);
6267
+ }
6268
+ function bitReversalInplace(values) {
6269
+ const n3 = values.length;
6270
+ if (!isPowerOfTwo(n3))
6271
+ throw new Error("expected positive power-of-two length, got " + n3);
6272
+ const bits = log2(n3);
6273
+ for (let i2 = 0; i2 < n3; i2++) {
6274
+ const j = reverseBits(i2, bits);
6275
+ if (i2 < j) {
6276
+ const tmp = values[i2];
6277
+ values[i2] = values[j];
6278
+ values[j] = tmp;
6279
+ }
6280
+ }
6281
+ return values;
6282
+ }
6283
+ var FFTCore = (F2, coreOpts) => {
6284
+ const { N: N2, roots, dit, invertButterflies = false, skipStages = 0, brp = true } = coreOpts;
6285
+ const bits = log2(N2);
6286
+ if (!isPowerOfTwo(N2))
6287
+ throw new Error("FFT: Polynomial size should be power of two");
6288
+ if (roots.length !== N2)
6289
+ throw new Error(`FFT: wrong roots length: expected ${N2}, got ${roots.length}`);
6290
+ const isDit = dit !== invertButterflies;
6291
+ isDit;
6292
+ return (values) => {
6293
+ if (values.length !== N2)
6294
+ throw new Error("FFT: wrong Polynomial length");
6295
+ if (dit && brp)
6296
+ bitReversalInplace(values);
6297
+ for (let i2 = 0, g = 1; i2 < bits - skipStages; i2++) {
6298
+ const s = dit ? i2 + 1 + skipStages : bits - i2;
6299
+ const m2 = 1 << s;
6300
+ const m22 = m2 >> 1;
6301
+ const stride = N2 >> s;
6302
+ for (let k = 0; k < N2; k += m2) {
6303
+ for (let j = 0, grp = g++; j < m22; j++) {
6304
+ const rootPos = invertButterflies ? dit ? N2 - grp : grp : j * stride;
6305
+ const i0 = k + j;
6306
+ const i1 = k + j + m22;
6307
+ const omega = roots[rootPos];
6308
+ const b = values[i1];
6309
+ const a2 = values[i0];
6310
+ if (isDit) {
6311
+ const t2 = F2.mul(b, omega);
6312
+ values[i0] = F2.add(a2, t2);
6313
+ values[i1] = F2.sub(a2, t2);
6314
+ } else if (invertButterflies) {
6315
+ values[i0] = F2.add(b, a2);
6316
+ values[i1] = F2.mul(F2.sub(b, a2), omega);
6317
+ } else {
6318
+ values[i0] = F2.add(a2, b);
6319
+ values[i1] = F2.mul(F2.sub(a2, b), omega);
6320
+ }
6321
+ }
6322
+ }
6323
+ }
6324
+ if (!dit && brp)
6325
+ bitReversalInplace(values);
6326
+ return values;
6327
+ };
6328
+ };
6329
+
6330
+ // node_modules/@dacely/noble-post-quantum/utils.js
6331
+ var abytesDoc = abytes;
6332
+ var randomBytes2 = randomBytes;
6333
+ function aarray(item, title, inner = () => {
6334
+ }) {
6335
+ if (!Array.isArray(item))
6336
+ throw new TypeError(`"${title}" expected array, got type=${typeof item}`);
6337
+ for (let i2 = 0; i2 < item.length; i2++)
6338
+ inner(item[i2], `${title}[${i2}]`);
6339
+ return item;
6340
+ }
6341
+ function equalBytes(a2, b) {
6342
+ if (a2.length !== b.length)
6343
+ return false;
6344
+ let diff = 0;
6345
+ for (let i2 = 0; i2 < a2.length; i2++)
6346
+ diff |= a2[i2] ^ b[i2];
6347
+ return diff === 0;
6348
+ }
6349
+ function copyBytes(bytes) {
6350
+ return Uint8Array.from(abytes(bytes));
6351
+ }
6352
+ function splitCoder(label, ...lengths) {
6353
+ const getLength = (c2) => typeof c2 === "number" ? c2 : c2.bytesLen;
6354
+ const bytesLen = lengths.reduce((sum, a2) => sum + getLength(a2), 0);
6355
+ return {
6356
+ bytesLen,
6357
+ encode: (bufs) => {
6358
+ const res = new Uint8Array(bytesLen);
6359
+ for (let i2 = 0, pos = 0; i2 < lengths.length; i2++) {
6360
+ const c2 = lengths[i2];
6361
+ const l2 = getLength(c2);
6362
+ const b = typeof c2 === "number" ? bufs[i2] : c2.encode(bufs[i2]);
6363
+ abytes(b, l2, label);
6364
+ res.set(b, pos);
6365
+ if (typeof c2 !== "number")
6366
+ b.fill(0);
6367
+ pos += l2;
6368
+ }
6369
+ return res;
6370
+ },
6371
+ decode: (buf) => {
6372
+ abytes(buf, bytesLen, label);
6373
+ const res = [];
6374
+ for (const c2 of lengths) {
6375
+ const l2 = getLength(c2);
6376
+ const b = buf.subarray(0, l2);
6377
+ res.push(typeof c2 === "number" ? b : c2.decode(b));
6378
+ buf = buf.subarray(l2);
6379
+ }
6380
+ return res;
6381
+ }
6382
+ };
6383
+ }
6384
+ function vecCoder(c2, vecLen) {
6385
+ const coder = c2;
6386
+ const bytesLen = vecLen * coder.bytesLen;
6387
+ return {
6388
+ bytesLen,
6389
+ encode: (u3) => {
6390
+ const uArr = aarray(u3, "u");
6391
+ if (uArr.length !== vecLen)
6392
+ throw new RangeError(`vecCoder.encode: wrong length=${uArr.length}. Expected: ${vecLen}`);
6393
+ const res = new Uint8Array(bytesLen);
6394
+ for (let i2 = 0, pos = 0; i2 < uArr.length; i2++) {
6395
+ const b = coder.encode(uArr[i2]);
6396
+ res.set(b, pos);
6397
+ b.fill(0);
6398
+ pos += b.length;
6399
+ }
6400
+ return res;
6401
+ },
6402
+ decode: (a2) => {
6403
+ abytes(a2, bytesLen);
6404
+ const r2 = [];
6405
+ for (let i2 = 0; i2 < a2.length; i2 += coder.bytesLen)
6406
+ r2.push(coder.decode(a2.subarray(i2, i2 + coder.bytesLen)));
6407
+ return r2;
6408
+ }
6409
+ };
6410
+ }
6411
+ function cleanBytes(...list) {
6412
+ for (const t2 of list) {
6413
+ if (Array.isArray(t2))
6414
+ for (const b of t2)
6415
+ b.fill(0);
6416
+ else
6417
+ t2.fill(0);
6418
+ }
6419
+ }
6420
+ function getMask(bits) {
6421
+ anumber(bits, "bits");
6422
+ if (bits > 32)
6423
+ throw new RangeError('"bits" expected <= 32, got ' + bits);
6424
+ return bits === 32 ? 4294967295 : ~(-1 << bits) >>> 0;
6425
+ }
6426
+
6427
+ // node_modules/@dacely/noble-post-quantum/_crystals.js
6428
+ var genCrystals = (opts2) => {
6429
+ const { newPoly, N: N2, Q: Q2, F: F2, ROOT_OF_UNITY: ROOT_OF_UNITY2, brvBits, isKyber } = opts2;
6430
+ const mod = (a2, modulo = Q2) => {
6431
+ const result = a2 % modulo | 0;
6432
+ return (result >= 0 ? result | 0 : modulo + result | 0) | 0;
6433
+ };
6434
+ const smod = (a2, modulo = Q2) => {
6435
+ const r2 = mod(a2, modulo) | 0;
6436
+ return (r2 > modulo >> 1 ? r2 - modulo | 0 : r2) | 0;
6437
+ };
6438
+ function getZettas() {
6439
+ const out2 = newPoly(N2);
6440
+ for (let i2 = 0; i2 < N2; i2++) {
6441
+ const b = reverseBits(i2, brvBits);
6442
+ const p = BigInt(ROOT_OF_UNITY2) ** BigInt(b) % BigInt(Q2);
6443
+ out2[i2] = Number(p) | 0;
6444
+ }
6445
+ return out2;
6446
+ }
6447
+ const nttZetas = getZettas();
6448
+ const field = {
6449
+ add: (a2, b) => mod((a2 | 0) + (b | 0)) | 0,
6450
+ sub: (a2, b) => mod((a2 | 0) - (b | 0)) | 0,
6451
+ mul: (a2, b) => mod((a2 | 0) * (b | 0)) | 0,
6452
+ inv: (_a) => {
6453
+ throw new Error("not implemented");
6454
+ }
6455
+ };
6456
+ const nttOpts = {
6457
+ N: N2,
6458
+ roots: nttZetas,
6459
+ invertButterflies: true,
6460
+ skipStages: isKyber ? 1 : 0,
6461
+ brp: false
6462
+ };
6463
+ const dif = FFTCore(field, { dit: false, ...nttOpts });
6464
+ const dit = FFTCore(field, { dit: true, ...nttOpts });
6465
+ const NTT = {
6466
+ encode: (r2) => {
6467
+ return dif(r2);
6468
+ },
6469
+ decode: (r2) => {
6470
+ dit(r2);
6471
+ for (let i2 = 0; i2 < r2.length; i2++)
6472
+ r2[i2] = mod(F2 * r2[i2]);
6473
+ return r2;
6474
+ }
6475
+ };
6476
+ const bitsCoder = (d, c2) => {
6477
+ const mask = getMask(d);
6478
+ const bytesLen = d * (N2 / 8);
6479
+ return {
6480
+ bytesLen,
6481
+ encode: (poly_) => {
6482
+ const poly = poly_;
6483
+ const r2 = new Uint8Array(bytesLen);
6484
+ for (let i2 = 0, buf = 0, bufLen = 0, pos = 0; i2 < poly.length; i2++) {
6485
+ buf |= (c2.encode(poly[i2]) & mask) << bufLen;
6486
+ bufLen += d;
6487
+ for (; bufLen >= 8; bufLen -= 8, buf >>= 8)
6488
+ r2[pos++] = buf & getMask(bufLen);
6489
+ }
6490
+ return r2;
6491
+ },
6492
+ decode: (bytes) => {
6493
+ const r2 = newPoly(N2);
6494
+ for (let i2 = 0, buf = 0, bufLen = 0, pos = 0; i2 < bytes.length; i2++) {
6495
+ buf |= bytes[i2] << bufLen;
6496
+ bufLen += 8;
6497
+ for (; bufLen >= d; bufLen -= d, buf >>= d)
6498
+ r2[pos++] = c2.decode(buf & mask);
6499
+ }
6500
+ return r2;
6501
+ }
6502
+ };
6503
+ };
6504
+ return {
6505
+ mod,
6506
+ smod,
6507
+ nttZetas,
6508
+ NTT: {
6509
+ encode: (r2) => NTT.encode(r2),
6510
+ decode: (r2) => NTT.decode(r2)
6511
+ },
6512
+ bitsCoder
6513
+ };
6514
+ };
6515
+ var createXofShake = (shake) => (seed, blockLen) => {
6516
+ if (!blockLen)
6517
+ blockLen = shake.blockLen;
6518
+ const _seed = new Uint8Array(seed.length + 2);
6519
+ _seed.set(seed);
6520
+ const seedLen = seed.length;
6521
+ const buf = new Uint8Array(blockLen);
6522
+ let h2 = shake.create({});
6523
+ let calls = 0;
6524
+ let xofs = 0;
6525
+ return {
6526
+ stats: () => ({ calls, xofs }),
6527
+ get: (x, y2) => {
6528
+ _seed[seedLen + 0] = x;
6529
+ _seed[seedLen + 1] = y2;
6530
+ h2.destroy();
6531
+ h2 = shake.create({}).update(_seed);
6532
+ calls++;
6533
+ return () => {
6534
+ xofs++;
6535
+ return h2.xofInto(buf);
6536
+ };
6537
+ },
6538
+ clean: () => {
6539
+ h2.destroy();
6540
+ cleanBytes(buf, _seed);
6541
+ }
6542
+ };
6543
+ };
6544
+ var XOF128 = /* @__PURE__ */ createXofShake(shake128);
6545
+
6546
+ // node_modules/@dacely/noble-post-quantum/ml-kem.js
6547
+ var N = 256;
6548
+ var Q = 3329;
6549
+ var F = 3303;
6550
+ var ROOT_OF_UNITY = 17;
6551
+ var crystals = /* @__PURE__ */ genCrystals({
6552
+ N,
6553
+ Q,
6554
+ F,
6555
+ ROOT_OF_UNITY,
6556
+ newPoly: (n3) => new Uint16Array(n3),
6557
+ brvBits: 7,
6558
+ isKyber: true
6559
+ });
6560
+ var PARAMS = /* @__PURE__ */ (() => Object.freeze({
6561
+ 512: Object.freeze({ N, Q, K: 2, ETA1: 3, ETA2: 2, du: 10, dv: 4, RBGstrength: 128 }),
6562
+ 768: Object.freeze({ N, Q, K: 3, ETA1: 2, ETA2: 2, du: 10, dv: 4, RBGstrength: 192 }),
6563
+ 1024: Object.freeze({ N, Q, K: 4, ETA1: 2, ETA2: 2, du: 11, dv: 5, RBGstrength: 256 })
6564
+ }))();
6565
+ var compress = (d) => {
6566
+ if (d >= 12)
6567
+ return { encode: (i2) => i2, decode: (i2) => i2 >= Q ? i2 - Q : i2 };
6568
+ const a2 = 2 ** (d - 1);
6569
+ return {
6570
+ // This only matches standalone Compress_d after bitsCoder masks the result into Z_(2^d).
6571
+ encode: (i2) => ((i2 << d) + Q / 2) / Q,
6572
+ // const decompress = (i: number) => round((Q / 2 ** d) * i);
6573
+ decode: (i2) => i2 * Q + a2 >>> d
6574
+ };
6575
+ };
6576
+ var byteCoder = (d) => crystals.bitsCoder(d, d === 12 ? { encode: (i2) => i2, decode: (i2) => i2 >= Q ? i2 - Q : i2 } : { encode: (i2) => i2, decode: (i2) => i2 });
6577
+ var polyCoder = (d) => d === 12 ? byteCoder(12) : crystals.bitsCoder(d, compress(d));
6578
+ function polyAdd(a_, b_) {
6579
+ const a2 = a_;
6580
+ const b = b_;
6581
+ for (let i2 = 0; i2 < N; i2++)
6582
+ a2[i2] = crystals.mod(a2[i2] + b[i2]);
6583
+ }
6584
+ function polySub(a_, b_) {
6585
+ const a2 = a_;
6586
+ const b = b_;
6587
+ for (let i2 = 0; i2 < N; i2++)
6588
+ a2[i2] = crystals.mod(a2[i2] - b[i2]);
6589
+ }
6590
+ function BaseCaseMultiply(a0, a1, b0, b1, zeta) {
6591
+ const c0 = crystals.mod(a1 * b1 * zeta + a0 * b0);
6592
+ const c1 = crystals.mod(a0 * b1 + a1 * b0);
6593
+ return { c0, c1 };
6594
+ }
6595
+ function MultiplyNTTs(f_, g_) {
6596
+ const f = f_;
6597
+ const g = g_;
6598
+ for (let i2 = 0; i2 < N / 2; i2++) {
6599
+ let z = crystals.nttZetas[64 + (i2 >> 1)];
6600
+ if (i2 & 1)
6601
+ z = -z;
6602
+ const { c0, c1 } = BaseCaseMultiply(f[2 * i2 + 0], f[2 * i2 + 1], g[2 * i2 + 0], g[2 * i2 + 1], z);
6603
+ f[2 * i2 + 0] = c0;
6604
+ f[2 * i2 + 1] = c1;
6605
+ }
6606
+ return f;
6607
+ }
6608
+ function SampleNTT(xof_) {
6609
+ const xof = xof_;
6610
+ const r2 = new Uint16Array(N);
6611
+ for (let j = 0; j < N; ) {
6612
+ const b = xof();
6613
+ if (b.length % 3)
6614
+ throw new Error("SampleNTT: unaligned block");
6615
+ for (let i2 = 0; j < N && i2 + 3 <= b.length; i2 += 3) {
6616
+ const d1 = (b[i2 + 0] >> 0 | b[i2 + 1] << 8) & 4095;
6617
+ const d2 = (b[i2 + 1] >> 4 | b[i2 + 2] << 4) & 4095;
6618
+ if (d1 < Q)
6619
+ r2[j++] = d1;
6620
+ if (j < N && d2 < Q)
6621
+ r2[j++] = d2;
6622
+ }
6623
+ }
6624
+ return r2;
6625
+ }
6626
+ var sampleCBDBytes = (buf, eta) => {
6627
+ const r2 = new Uint16Array(N);
6628
+ const b32 = u32(buf);
6629
+ swap32IfBE(b32);
6630
+ let len = 0;
6631
+ for (let i2 = 0, p = 0, bb = 0, t0 = 0; i2 < b32.length; i2++) {
6632
+ let b = b32[i2];
6633
+ for (let j = 0; j < 32; j++) {
6634
+ bb += b & 1;
6635
+ b >>= 1;
6636
+ len += 1;
6637
+ if (len === eta) {
6638
+ t0 = bb;
6639
+ bb = 0;
6640
+ } else if (len === 2 * eta) {
6641
+ r2[p++] = crystals.mod(t0 - bb);
6642
+ bb = 0;
6643
+ len = 0;
6644
+ }
6645
+ }
6646
+ }
6647
+ swap32IfBE(b32);
6648
+ if (len)
6649
+ throw new Error(`sampleCBD: leftover bits: ${len}`);
6650
+ return r2;
6651
+ };
6652
+ function sampleCBD(PRF_, seed, nonce, eta) {
6653
+ const PRF = PRF_;
6654
+ return sampleCBDBytes(PRF(eta * N / 4, seed, nonce), eta);
6655
+ }
6656
+ var genKPKE = (opts_) => {
6657
+ const opts2 = opts_;
6658
+ const { K, PRF, XOF, HASH512, ETA1, ETA2, du, dv } = opts2;
6659
+ const poly1 = polyCoder(1);
6660
+ const polyV = polyCoder(dv);
6661
+ const polyU = polyCoder(du);
6662
+ const publicCoder = splitCoder("publicKey", vecCoder(polyCoder(12), K), 32);
6663
+ const secretCoder = vecCoder(polyCoder(12), K);
6664
+ const cipherCoder = splitCoder("ciphertext", vecCoder(polyU, K), polyV);
6665
+ const seedCoder = splitCoder("seed", 32, 32);
6666
+ return {
6667
+ secretCoder,
6668
+ lengths: {
6669
+ secretKey: secretCoder.bytesLen,
6670
+ publicKey: publicCoder.bytesLen,
6671
+ cipherText: cipherCoder.bytesLen
6672
+ },
6673
+ keygen: (seed) => {
6674
+ abytesDoc(seed, 32, "seed");
6675
+ const seedDst = new Uint8Array(33);
6676
+ seedDst.set(seed);
6677
+ seedDst[32] = K;
6678
+ const seedHash = HASH512(seedDst);
6679
+ const [rho, sigma] = seedCoder.decode(seedHash);
6680
+ const sHat = [];
6681
+ const tHat = [];
6682
+ for (let i2 = 0; i2 < K; i2++)
6683
+ sHat.push(crystals.NTT.encode(sampleCBD(PRF, sigma, i2, ETA1)));
6684
+ const x = XOF(rho);
6685
+ for (let i2 = 0; i2 < K; i2++) {
6686
+ const e = crystals.NTT.encode(sampleCBD(PRF, sigma, K + i2, ETA1));
6687
+ for (let j = 0; j < K; j++) {
6688
+ const aji = SampleNTT(x.get(j, i2));
6689
+ polyAdd(e, MultiplyNTTs(aji, sHat[j]));
6690
+ }
6691
+ tHat.push(e);
6692
+ }
6693
+ x.clean();
6694
+ const res = {
6695
+ publicKey: publicCoder.encode([tHat, rho]),
6696
+ secretKey: secretCoder.encode(sHat)
6697
+ };
6698
+ cleanBytes(rho, sigma, sHat, tHat, seedDst, seedHash);
6699
+ return res;
6700
+ },
6701
+ encrypt: (publicKey, msg, seed) => {
6702
+ const [tHat, rho] = publicCoder.decode(publicKey);
6703
+ const rHat = [];
6704
+ for (let i2 = 0; i2 < K; i2++)
6705
+ rHat.push(crystals.NTT.encode(sampleCBD(PRF, seed, i2, ETA1)));
6706
+ const x = XOF(rho);
6707
+ const tmp2 = new Uint16Array(N);
6708
+ const u3 = [];
6709
+ for (let i2 = 0; i2 < K; i2++) {
6710
+ const e1 = sampleCBD(PRF, seed, K + i2, ETA2);
6711
+ const tmp = new Uint16Array(N);
6712
+ for (let j = 0; j < K; j++) {
6713
+ const aij = SampleNTT(x.get(i2, j));
6714
+ polyAdd(tmp, MultiplyNTTs(aij, rHat[j]));
6715
+ }
6716
+ polyAdd(e1, crystals.NTT.decode(tmp));
6717
+ u3.push(e1);
6718
+ polyAdd(tmp2, MultiplyNTTs(tHat[i2], rHat[i2]));
6719
+ cleanBytes(tmp);
6720
+ }
6721
+ x.clean();
6722
+ const e2 = sampleCBD(PRF, seed, 2 * K, ETA2);
6723
+ polyAdd(e2, crystals.NTT.decode(tmp2));
6724
+ const v = poly1.decode(msg);
6725
+ polyAdd(v, e2);
6726
+ cleanBytes(tHat, rHat, tmp2, e2);
6727
+ return cipherCoder.encode([u3, v]);
6728
+ },
6729
+ decrypt: (cipherText, privateKey) => {
6730
+ const [u3, v] = cipherCoder.decode(cipherText);
6731
+ const sk = secretCoder.decode(privateKey);
6732
+ const tmp = new Uint16Array(N);
6733
+ for (let i2 = 0; i2 < K; i2++)
6734
+ polyAdd(tmp, MultiplyNTTs(sk[i2], crystals.NTT.encode(u3[i2])));
6735
+ polySub(v, crystals.NTT.decode(tmp));
6736
+ cleanBytes(tmp, sk, u3);
6737
+ return poly1.encode(v);
6738
+ }
6739
+ };
6740
+ };
6741
+ function createKyber(opts2) {
6742
+ const rawOpts = opts2;
6743
+ const KPKE = genKPKE(rawOpts);
6744
+ const { HASH256, HASH512, KDF } = rawOpts;
6745
+ const { secretCoder: KPKESecretCoder, lengths } = KPKE;
6746
+ const secretCoder = splitCoder("secretKey", lengths.secretKey, lengths.publicKey, 32, 32);
6747
+ const msgLen = 32;
6748
+ const seedLen = 64;
6749
+ const kemLengths = Object.freeze({
6750
+ ...lengths,
6751
+ seed: 64,
6752
+ msg: msgLen,
6753
+ msgRand: msgLen,
6754
+ secretKey: secretCoder.bytesLen
6755
+ });
6756
+ return Object.freeze({
6757
+ info: Object.freeze({ type: "ml-kem" }),
6758
+ lengths: kemLengths,
6759
+ keygen: (seed = randomBytes2(seedLen)) => {
6760
+ abytesDoc(seed, seedLen, "seed");
6761
+ const { publicKey, secretKey: sk } = KPKE.keygen(seed.subarray(0, 32));
6762
+ const publicKeyHash = HASH256(publicKey);
6763
+ const secretKey = secretCoder.encode([sk, publicKey, publicKeyHash, seed.subarray(32)]);
6764
+ cleanBytes(sk, publicKeyHash);
6765
+ return {
6766
+ publicKey,
6767
+ secretKey
6768
+ };
6769
+ },
6770
+ getPublicKey: (secretKey) => {
6771
+ const [_sk, publicKey, _publicKeyHash, _z] = secretCoder.decode(secretKey);
6772
+ return Uint8Array.from(publicKey);
6773
+ },
6774
+ encapsulate: (publicKey, msg = randomBytes2(msgLen)) => {
6775
+ abytesDoc(publicKey, lengths.publicKey, "publicKey");
6776
+ abytesDoc(msg, msgLen, "message");
6777
+ const eke = publicKey.subarray(0, 384 * opts2.K);
6778
+ const ek = KPKESecretCoder.encode(KPKESecretCoder.decode(copyBytes(eke)));
6779
+ if (!equalBytes(ek, eke)) {
6780
+ cleanBytes(ek);
6781
+ throw new Error("ML-KEM.encapsulate: wrong publicKey modulus");
6782
+ }
6783
+ cleanBytes(ek);
6784
+ const kr = HASH512.create().update(msg).update(HASH256(publicKey)).digest();
6785
+ const cipherText = KPKE.encrypt(publicKey, msg, kr.subarray(32, 64));
6786
+ cleanBytes(kr.subarray(32));
6787
+ return {
6788
+ cipherText,
6789
+ sharedSecret: kr.subarray(0, 32)
6790
+ };
6791
+ },
6792
+ decapsulate: (cipherText, secretKey) => {
6793
+ abytesDoc(secretKey, secretCoder.bytesLen, "secretKey");
6794
+ abytesDoc(cipherText, lengths.cipherText, "cipherText");
6795
+ const k768 = secretCoder.bytesLen - 96;
6796
+ const start2 = k768 + 32;
6797
+ const test = HASH256(secretKey.subarray(k768 / 2, start2));
6798
+ if (!equalBytes(test, secretKey.subarray(start2, start2 + 32)))
6799
+ throw new Error("invalid secretKey: hash check failed");
6800
+ const [sk, publicKey, publicKeyHash, z] = secretCoder.decode(secretKey);
6801
+ const msg = KPKE.decrypt(cipherText, sk);
6802
+ const kr = HASH512.create().update(msg).update(publicKeyHash).digest();
6803
+ const Khat = kr.subarray(0, 32);
6804
+ const cipherText2 = KPKE.encrypt(publicKey, msg, kr.subarray(32, 64));
6805
+ const isValid = equalBytes(cipherText, cipherText2);
6806
+ const Kbar = KDF.create({ dkLen: 32 }).update(z).update(cipherText).digest();
6807
+ cleanBytes(msg, cipherText2, !isValid ? Khat : Kbar);
6808
+ return isValid ? Khat : Kbar;
6809
+ }
6810
+ });
6811
+ }
6812
+ function shakePRF(dkLen, key, nonce) {
6813
+ return shake256.create({ dkLen }).update(key).update(new Uint8Array([nonce])).digest();
6814
+ }
6815
+ var opts = /* @__PURE__ */ (() => ({
6816
+ HASH256: sha3_256,
6817
+ HASH512: sha3_512,
6818
+ KDF: shake256,
6819
+ XOF: XOF128,
6820
+ PRF: shakePRF
6821
+ }))();
6822
+ var mk = (params) => createKyber({
6823
+ ...opts,
6824
+ ...params
6825
+ });
6826
+ var ml_kem768 = /* @__PURE__ */ (() => mk(PARAMS[768]))();
6827
+
6828
+ // src/cli/generate.ts
6829
+ var PRIVATE_KEYS = ["AUTH_SESSION_SECRET", "AUTH_OPRF_SEED", "AUTH_KEM_SK"];
6830
+ var PUBLIC_KEY = "VITE_AUTH_KEM_PUBLIC_KEY";
6831
+ function read(file) {
6832
+ const stat = fs6.lstatSync(file, { throwIfNoEntry: false });
6833
+ if (!stat) return "";
6834
+ if (!stat.isFile()) throw new Error(`Expected a regular file: ${file}`);
6835
+ return fs6.readFileSync(file, "utf8");
6836
+ }
6837
+ function append(text2, lines) {
6838
+ if (!lines.length) return text2;
6839
+ return text2 + (text2 && !text2.endsWith("\n") ? "\n" : "") + lines.join("\n") + "\n";
6840
+ }
6841
+ function publicKeyFor(secret) {
6842
+ try {
6843
+ if (!/^[0-9a-fA-F]{4800}$/.test(secret)) throw new Error();
6844
+ const sk = Buffer.from(secret, "hex");
6845
+ const pk = ml_kem768.getPublicKey(sk);
6846
+ const { cipherText, sharedSecret } = ml_kem768.encapsulate(pk);
6847
+ if (!timingSafeEqual(sharedSecret, ml_kem768.decapsulate(cipherText, sk)))
6848
+ throw new Error();
6849
+ return Buffer.from(pk).toString("hex");
6850
+ } catch {
6851
+ throw new Error(
6852
+ "AUTH_KEM_SK is not a valid ML-KEM-768 secret key. Existing files were not changed."
6853
+ );
6854
+ }
6855
+ }
6856
+ function runGenerate(target, opts2 = {}) {
6857
+ if (target !== "auth") throw new Error("Usage: toiljs generate auth [--root <dir>]");
6858
+ const root = path7.resolve(opts2.root ?? process.cwd());
6859
+ const envFile = path7.join(root, ".env");
6860
+ const secretsFile = path7.join(root, ".env.secrets");
6861
+ const ignoreFile = path7.join(root, ".gitignore");
6862
+ const envText = read(envFile);
6863
+ const secretsText = read(secretsFile);
6864
+ const ignoreText = read(ignoreFile);
6865
+ const env = parseEnv(envText);
6866
+ const secrets = parseEnv(secretsText);
6867
+ for (const key of PRIVATE_KEYS) {
6868
+ if (Object.hasOwn(env, key))
6869
+ throw new Error(`Move ${key} from .env to .env.secrets before generating auth keys.`);
6870
+ if (Object.hasOwn(secrets, key) && !secrets[key]?.trim())
6871
+ throw new Error(
6872
+ `${key} is empty in .env.secrets. Remove the empty assignment to generate it.`
6873
+ );
6874
+ }
6875
+ if (Object.hasOwn(env, PUBLIC_KEY) && !secrets.AUTH_KEM_SK)
6876
+ throw new Error(
6877
+ "A public key already exists. Restore its matching AUTH_KEM_SK in .env.secrets; no keys were changed."
6878
+ );
6879
+ const additions = [];
6880
+ let publicKey;
6881
+ if (secrets.AUTH_KEM_SK) {
6882
+ publicKey = publicKeyFor(secrets.AUTH_KEM_SK);
6883
+ } else {
6884
+ const pair = ml_kem768.keygen();
6885
+ publicKey = Buffer.from(pair.publicKey).toString("hex");
6886
+ additions.push(`AUTH_KEM_SK=${Buffer.from(pair.secretKey).toString("hex")}`);
6887
+ }
6888
+ if (Object.hasOwn(env, PUBLIC_KEY) && env[PUBLIC_KEY] !== publicKey)
6889
+ throw new Error(
6890
+ "VITE_AUTH_KEM_PUBLIC_KEY does not match AUTH_KEM_SK. Existing files were not changed. Restore the matching pair before continuing."
6891
+ );
6892
+ for (const key of ["AUTH_SESSION_SECRET", "AUTH_OPRF_SEED"]) {
6893
+ if (!Object.hasOwn(secrets, key))
6894
+ additions.push(`${key}=${randomBytes3(32).toString("hex")}`);
6895
+ }
6896
+ const publicAdditions = Object.hasOwn(env, PUBLIC_KEY) ? [] : [`${PUBLIC_KEY}=${publicKey}`];
6897
+ const ignoreLines = new Set(ignoreText.split(/\r?\n/));
6898
+ const ignoreAdditions = ["/.env", "/.env.secrets"].filter((line) => !ignoreLines.has(line));
6899
+ if (ignoreAdditions.length) fs6.writeFileSync(ignoreFile, append(ignoreText, ignoreAdditions));
6900
+ if (fs6.existsSync(secretsFile)) fs6.chmodSync(secretsFile, 384);
6901
+ if (additions.length)
6902
+ fs6.writeFileSync(secretsFile, append(secretsText, additions), { mode: 384 });
6903
+ if (publicAdditions.length)
6904
+ fs6.writeFileSync(envFile, append(envText, publicAdditions), { mode: 384 });
6905
+ process.stdout.write(
6906
+ [
6907
+ `Authentication keys ready in ${root}. Existing credentials were preserved.`,
6908
+ " .env.secrets: AUTH_SESSION_SECRET, AUTH_OPRF_SEED, AUTH_KEM_SK (private; mode 0600)",
6909
+ " .env: VITE_AUTH_KEM_PUBLIC_KEY (public; pin it with Auth login/register options)",
6910
+ "Back up .env.secrets securely. This command does not rotate existing keys.",
6911
+ "For toil-backend, merge private settings into /run/toil/env/<host>.env.secrets",
6912
+ "(or TOIL_ENV_DIR); use toil env sync <host> if the env store is database-backed.",
6913
+ "Keep VITE_AUTH_KEM_PUBLIC_KEY in the project .env on the build machine, then rebuild",
6914
+ "and deploy the client. Backend runtime env changes cannot update the browser bundle.",
6915
+ ""
6916
+ ].join("\n")
6917
+ );
6918
+ }
6919
+
5915
6920
  // src/cli/notify.ts
5916
- import fs7 from "node:fs";
6921
+ import fs8 from "node:fs";
5917
6922
  import os from "node:os";
5918
- import path8 from "node:path";
6923
+ import path9 from "node:path";
5919
6924
  import { fileURLToPath as fileURLToPath4 } from "node:url";
5920
6925
 
5921
6926
  // src/cli/update.ts
5922
- import fs6 from "node:fs";
5923
- import path7 from "node:path";
6927
+ import fs7 from "node:fs";
6928
+ import path8 from "node:path";
5924
6929
 
5925
6930
  // src/cli/updates.ts
5926
6931
  function parseVersion2(v) {
@@ -5963,13 +6968,13 @@ function buildRows(upgraded, currentDeps) {
5963
6968
 
5964
6969
  // src/cli/update.ts
5965
6970
  function detectPackageManager2(root) {
5966
- if (fs6.existsSync(path7.join(root, "pnpm-lock.yaml"))) return { name: "pnpm", ncuName: "pnpm" };
5967
- if (fs6.existsSync(path7.join(root, "yarn.lock"))) return { name: "yarn", ncuName: "yarn" };
5968
- if (fs6.existsSync(path7.join(root, "bun.lockb"))) return { name: "bun", ncuName: "bun" };
6971
+ if (fs7.existsSync(path8.join(root, "pnpm-lock.yaml"))) return { name: "pnpm", ncuName: "pnpm" };
6972
+ if (fs7.existsSync(path8.join(root, "yarn.lock"))) return { name: "yarn", ncuName: "yarn" };
6973
+ if (fs7.existsSync(path8.join(root, "bun.lockb"))) return { name: "bun", ncuName: "bun" };
5969
6974
  return { name: "npm", ncuName: "npm" };
5970
6975
  }
5971
6976
  function readDependencies(pkgPath) {
5972
- const parsed = JSON.parse(fs6.readFileSync(pkgPath, "utf8"));
6977
+ const parsed = JSON.parse(fs7.readFileSync(pkgPath, "utf8"));
5973
6978
  if (typeof parsed !== "object" || parsed === null) return {};
5974
6979
  const pkg = parsed;
5975
6980
  const merge = (v) => {
@@ -5997,26 +7002,26 @@ function serverDirs(root) {
5997
7002
  const dirs = /* @__PURE__ */ new Set();
5998
7003
  try {
5999
7004
  const parsed = JSON.parse(
6000
- fs6.readFileSync(path7.join(root, "toilconfig.json"), "utf8")
7005
+ fs7.readFileSync(path8.join(root, "toilconfig.json"), "utf8")
6001
7006
  );
6002
7007
  const entries = typeof parsed === "object" && parsed !== null && Array.isArray(parsed.entries) ? parsed.entries.filter(
6003
7008
  (e) => typeof e === "string"
6004
7009
  ) : [];
6005
- for (const e of entries) dirs.add(path7.dirname(path7.resolve(root, e)));
7010
+ for (const e of entries) dirs.add(path8.dirname(path8.resolve(root, e)));
6006
7011
  } catch {
6007
7012
  }
6008
- if (dirs.size === 0) dirs.add(path7.join(root, "server"));
7013
+ if (dirs.size === 0) dirs.add(path8.join(root, "server"));
6009
7014
  return [...dirs];
6010
7015
  }
6011
7016
  function ensureMigrationsDirs(root) {
6012
7017
  const created = [];
6013
7018
  for (const dir of serverDirs(root)) {
6014
- if (!fs6.existsSync(dir)) continue;
6015
- const migrations = path7.join(dir, "migrations");
6016
- if (fs6.existsSync(migrations)) continue;
6017
- fs6.mkdirSync(migrations, { recursive: true });
6018
- fs6.writeFileSync(path7.join(migrations, "README.md"), MIGRATIONS_README);
6019
- created.push(path7.relative(root, migrations) || "migrations");
7019
+ if (!fs7.existsSync(dir)) continue;
7020
+ const migrations = path8.join(dir, "migrations");
7021
+ if (fs7.existsSync(migrations)) continue;
7022
+ fs7.mkdirSync(migrations, { recursive: true });
7023
+ fs7.writeFileSync(path8.join(migrations, "README.md"), MIGRATIONS_README);
7024
+ created.push(path8.relative(root, migrations) || "migrations");
6020
7025
  }
6021
7026
  return created;
6022
7027
  }
@@ -6038,15 +7043,15 @@ function noteWithheld(names) {
6038
7043
  );
6039
7044
  }
6040
7045
  var TARGETS = /* @__PURE__ */ new Set(["latest", "minor", "patch", "newest", "greatest"]);
6041
- async function runUpdate(opts) {
6042
- const root = path7.resolve(opts.root ?? opts.cwd);
6043
- const pkgPath = path7.join(root, "package.json");
6044
- if (!fs6.existsSync(pkgPath)) {
7046
+ async function runUpdate(opts2) {
7047
+ const root = path8.resolve(opts2.root ?? opts2.cwd);
7048
+ const pkgPath = path8.join(root, "package.json");
7049
+ if (!fs7.existsSync(pkgPath)) {
6045
7050
  throw new Error("No package.json here. Run from your project root or pass --root <dir>.");
6046
7051
  }
6047
7052
  const currentDeps = readDependencies(pkgPath);
6048
7053
  const pm = detectPackageManager2(root);
6049
- const target = opts.target && TARGETS.has(opts.target) ? opts.target : "latest";
7054
+ const target = opts2.target && TARGETS.has(opts2.target) ? opts2.target : "latest";
6050
7055
  const ncuArgs = (extra) => [
6051
7056
  "--yes",
6052
7057
  "npm-check-updates",
@@ -6103,7 +7108,7 @@ async function runUpdate(opts) {
6103
7108
  `${danger(`${String(counts.major)} major`)} ${warn(`${String(counts.minor)} minor`)} ${success(`${String(counts.patch)} patch`)}`
6104
7109
  );
6105
7110
  let selected;
6106
- if (opts.yes) {
7111
+ if (opts2.yes) {
6107
7112
  selected = rows.map((r2) => r2.name);
6108
7113
  } else {
6109
7114
  const answer = await multiselect({
@@ -6126,7 +7131,7 @@ async function runUpdate(opts) {
6126
7131
  outro(dim("No packages selected."));
6127
7132
  return;
6128
7133
  }
6129
- const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf8"));
7134
+ const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf8"));
6130
7135
  const targetTypeScript = selected.includes("typescript") ? upgraded.typescript : currentDeps.typescript;
6131
7136
  if (!targetTypeScript || !isSupportedTypeScriptRange(targetTypeScript)) {
6132
7137
  throw new Error("Select the TypeScript 7 migration before installing updates.");
@@ -6152,7 +7157,7 @@ async function runUpdate(opts) {
6152
7157
  pkg.devDependencies = deps;
6153
7158
  }
6154
7159
  }
6155
- fs6.writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + "\n");
7160
+ fs7.writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + "\n");
6156
7161
  s.stop("package.json updated");
6157
7162
  note(dim(`Running ${pm.name} install\u2026`), "Install");
6158
7163
  try {
@@ -6243,8 +7248,8 @@ function findOutdated(latest, projectVersion, cliVersion, cliIsLocal, pm) {
6243
7248
  var REGISTRY_URL = "https://registry.npmjs.org/toiljs/latest";
6244
7249
  var FETCH_TIMEOUT_MS = 2e3;
6245
7250
  function cacheFile() {
6246
- const base = process.env.XDG_CACHE_HOME ?? path8.join(os.homedir(), ".cache");
6247
- return path8.join(base, "toiljs", "update-check.json");
7251
+ const base = process.env.XDG_CACHE_HOME ?? path9.join(os.homedir(), ".cache");
7252
+ return path9.join(base, "toiljs", "update-check.json");
6248
7253
  }
6249
7254
  async function fetchLatest() {
6250
7255
  const ctrl = new AbortController();
@@ -6270,22 +7275,22 @@ async function fetchLatest() {
6270
7275
  async function resolveLatest() {
6271
7276
  const file = cacheFile();
6272
7277
  try {
6273
- const cached = parseCheckCache(fs7.readFileSync(file, "utf8"));
7278
+ const cached = parseCheckCache(fs8.readFileSync(file, "utf8"));
6274
7279
  if (cached && isCacheFresh(cached, Date.now())) return cached.latest;
6275
7280
  } catch {
6276
7281
  }
6277
7282
  const latest = await fetchLatest();
6278
7283
  try {
6279
- fs7.mkdirSync(path8.dirname(file), { recursive: true });
6280
- fs7.writeFileSync(file, JSON.stringify({ latest, checkedAt: Date.now() }));
7284
+ fs8.mkdirSync(path9.dirname(file), { recursive: true });
7285
+ fs8.writeFileSync(file, JSON.stringify({ latest, checkedAt: Date.now() }));
6281
7286
  } catch {
6282
7287
  }
6283
7288
  return latest;
6284
7289
  }
6285
7290
  function projectToiljsVersion(root) {
6286
7291
  try {
6287
- const raw = fs7.readFileSync(
6288
- path8.join(root, "node_modules", "toiljs", "package.json"),
7292
+ const raw = fs8.readFileSync(
7293
+ path9.join(root, "node_modules", "toiljs", "package.json"),
6289
7294
  "utf8"
6290
7295
  );
6291
7296
  const parsed = JSON.parse(raw);
@@ -6310,9 +7315,9 @@ async function notifyIfOutdated(rootArg) {
6310
7315
  if (env.TOILJS_NO_UPDATE_CHECK || env.NO_UPDATE_NOTIFIER || env.CI) return;
6311
7316
  const latest = await resolveLatest();
6312
7317
  if (!latest) return;
6313
- const root = path8.resolve(rootArg ?? process.cwd());
6314
- const cliDir = path8.dirname(fileURLToPath4(import.meta.url));
6315
- const cliIsLocal = cliDir.startsWith(path8.join(root, "node_modules") + path8.sep);
7318
+ const root = path9.resolve(rootArg ?? process.cwd());
7319
+ const cliDir = path9.dirname(fileURLToPath4(import.meta.url));
7320
+ const cliIsLocal = cliDir.startsWith(path9.join(root, "node_modules") + path9.sep);
6316
7321
  const rows = findOutdated(
6317
7322
  latest,
6318
7323
  projectToiljsVersion(root),
@@ -6431,6 +7436,7 @@ function printHelp() {
6431
7436
  bold("Commands"),
6432
7437
  cmd("create [name]", "scaffold a new toiljs app"),
6433
7438
  cmd("configure", "toggle styling features (Sass/Less/Stylus, Tailwind)"),
7439
+ cmd("generate auth", "generate private auth keys and the matching client public key"),
6434
7440
  cmd("dev", "start the dev server with HMR"),
6435
7441
  cmd("build", "build the optimized production bundle"),
6436
7442
  cmd("start", "self-host the built app (hyper-express / uWS)"),
@@ -6497,6 +7503,9 @@ async function main() {
6497
7503
  cwd: process.cwd()
6498
7504
  });
6499
7505
  break;
7506
+ case "generate":
7507
+ runGenerate(flags.name, { root: flags.root });
7508
+ break;
6500
7509
  case "dev":
6501
7510
  banner();
6502
7511
  process.stdout.write(dim(" starting dev server\u2026") + "\n\n");
@@ -6522,7 +7531,7 @@ async function main() {
6522
7531
  threads: flags.threads
6523
7532
  });
6524
7533
  const wildcard = server.host === "0.0.0.0" || server.host === "::" || server.host === "";
6525
- const shownHost = wildcard ? "localhost" : server.host;
7534
+ const shownHost = wildcard || server.host === "127.0.0.1" ? "localhost" : server.host;
6526
7535
  const exposed = server.host !== "127.0.0.1" && server.host !== "localhost" && server.host !== "::1";
6527
7536
  process.stdout.write(
6528
7537
  accent(" \u279C ") + bold(`http://${shownHost}:${String(server.port)}`) + dim(` ws channel: ${server.wsPath}`) + (exposed ? "\n" + dim(` bound to ${server.host}:${String(server.port)} (exposed beyond loopback)`) : "") + "\n\n"
@@ -6572,3 +7581,10 @@ main().catch((err) => {
6572
7581
  process.stderr.write("\n" + danger(" \u2717 ") + message + "\n");
6573
7582
  process.exitCode = 1;
6574
7583
  });
7584
+ /*! Bundled license information:
7585
+
7586
+ @dacely/noble-post-quantum/utils.js:
7587
+ @dacely/noble-post-quantum/_crystals.js:
7588
+ @dacely/noble-post-quantum/ml-kem.js:
7589
+ (*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)
7590
+ */