toiljs 0.0.119 → 0.0.121

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