@camstack/system 1.2.444 → 1.2.445

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.
Files changed (142) hide show
  1. package/dist/addon-runner.js +40 -31
  2. package/dist/addon-runner.mjs +41 -32
  3. package/dist/{agent-https-DlpTMDqA.js → agent-https-CiOW0-sj.js} +810 -12
  4. package/dist/{agent-https-U0d4uvn2.mjs → agent-https-D4Q8iFNd.mjs} +697 -13
  5. package/dist/auth/admin-token-manager.d.ts +9 -3
  6. package/dist/auth/api-key-manager.d.ts +9 -3
  7. package/dist/auth/auth-audit-log.d.ts +9 -3
  8. package/dist/auth/device-credential-manager.d.ts +5 -1
  9. package/dist/auth/external-identity-manager.d.ts +8 -21
  10. package/dist/auth/login-session-manager.d.ts +11 -3
  11. package/dist/auth/scoped-token-manager.d.ts +8 -52
  12. package/dist/auth/totp-manager.d.ts +11 -3
  13. package/dist/auth/user-manager.d.ts +10 -17
  14. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  15. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  16. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  17. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  18. package/dist/builtins/alerts/alert-store.d.ts +32 -0
  19. package/dist/builtins/alerts/alerts.addon.d.ts +9 -2
  20. package/dist/builtins/alerts/alerts.addon.js +289 -150
  21. package/dist/builtins/alerts/alerts.addon.mjs +288 -150
  22. package/dist/builtins/alerts/record-kinds.d.ts +15 -0
  23. package/dist/builtins/autotrack/index.js +1 -1
  24. package/dist/builtins/autotrack/index.mjs +1 -1
  25. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.d.ts +1 -0
  26. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +134 -193
  27. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +134 -193
  28. package/dist/builtins/backup-orchestrator/destination-policy.d.ts +4 -2
  29. package/dist/builtins/backup-orchestrator/encryption-key-store.d.ts +4 -2
  30. package/dist/builtins/backup-orchestrator/record-kinds.d.ts +58 -0
  31. package/dist/builtins/backup-orchestrator/schedule-store.d.ts +4 -2
  32. package/dist/builtins/backup-orchestrator/seed-marker-store.d.ts +4 -2
  33. package/dist/builtins/calendars/calendar-prefs-store.d.ts +13 -5
  34. package/dist/builtins/calendars/calendars.addon.d.ts +2 -2
  35. package/dist/builtins/calendars/calendars.addon.js +67 -64
  36. package/dist/builtins/calendars/calendars.addon.mjs +59 -64
  37. package/dist/builtins/calendars/record-kinds.d.ts +18 -0
  38. package/dist/builtins/camera-grid/index.js +1 -1
  39. package/dist/builtins/camera-grid/index.mjs +1 -1
  40. package/dist/builtins/cluster-agent/record-kinds.d.ts +36 -0
  41. package/dist/builtins/composer/composer.addon.js +2 -2
  42. package/dist/builtins/composer/composer.addon.mjs +2 -2
  43. package/dist/builtins/console-logging/index.js +1 -1
  44. package/dist/builtins/console-logging/index.mjs +1 -1
  45. package/dist/builtins/core-blocks/block-settings-store.d.ts +8 -4
  46. package/dist/builtins/core-blocks/core-block-store.d.ts +8 -16
  47. package/dist/builtins/core-blocks/core-blocks.addon.js +85 -112
  48. package/dist/builtins/core-blocks/core-blocks.addon.mjs +86 -113
  49. package/dist/builtins/core-blocks/index.mjs +1 -1
  50. package/dist/builtins/core-blocks/record-kinds.d.ts +26 -0
  51. package/dist/builtins/device-manager/device-manager.addon.js +111 -187
  52. package/dist/builtins/device-manager/device-manager.addon.mjs +110 -187
  53. package/dist/builtins/device-manager/device-tombstone-store.d.ts +9 -48
  54. package/dist/builtins/device-manager/record-kinds.d.ts +14 -0
  55. package/dist/builtins/hub-forwarder/index.js +1 -1
  56. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  57. package/dist/builtins/keychain/index.js +152 -22
  58. package/dist/builtins/keychain/index.mjs +152 -22
  59. package/dist/builtins/keychain/keychain-service.d.ts +3 -2
  60. package/dist/builtins/keychain/keychain-store.d.ts +13 -2
  61. package/dist/builtins/keychain/record-kinds.d.ts +16 -0
  62. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  63. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  64. package/dist/builtins/local-auth/auth-schema.d.ts +3 -1
  65. package/dist/builtins/local-auth/local-auth.addon.js +2903 -2123
  66. package/dist/builtins/local-auth/local-auth.addon.mjs +2904 -2124
  67. package/dist/builtins/local-auth/oauth-session-manager.d.ts +8 -48
  68. package/dist/builtins/local-auth/record-kinds.d.ts +141 -0
  69. package/dist/builtins/local-network/local-network.addon.js +2 -2
  70. package/dist/builtins/local-network/local-network.addon.mjs +2 -2
  71. package/dist/builtins/loki-logging/index.js +1 -1
  72. package/dist/builtins/loki-logging/index.mjs +1 -1
  73. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  74. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  75. package/dist/builtins/platform-probe/index.js +1 -1
  76. package/dist/builtins/platform-probe/index.mjs +1 -1
  77. package/dist/builtins/record-entries/index.js +1 -1
  78. package/dist/builtins/record-entries/index.mjs +1 -1
  79. package/dist/builtins/records/legacy-table-row-count.d.ts +5 -0
  80. package/dist/builtins/records/phase6-declare-gate.d.ts +28 -0
  81. package/dist/builtins/records-isolated.d.ts +10 -0
  82. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  83. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  84. package/dist/builtins/snapshot/index.js +1 -1
  85. package/dist/builtins/snapshot/index.mjs +1 -1
  86. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  87. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  88. package/dist/builtins/sqlite-storage/index.js +1 -1
  89. package/dist/builtins/sqlite-storage/index.mjs +1 -1
  90. package/dist/builtins/sqlite-storage/integration-record-kinds.d.ts +30 -0
  91. package/dist/builtins/sqlite-storage/integration-registry.d.ts +10 -16
  92. package/dist/builtins/sqlite-storage/records/count-settings-array-legacy.d.ts +5 -0
  93. package/dist/builtins/sqlite-storage/records/count-settings-brokers-legacy.d.ts +6 -0
  94. package/dist/builtins/sqlite-storage/records/records-engine-types.d.ts +5 -0
  95. package/dist/builtins/sqlite-storage/records/records-engine.d.ts +4 -0
  96. package/dist/builtins/sqlite-storage/records/records-provider.d.ts +5 -1
  97. package/dist/builtins/sqlite-storage/sqlite-settings-backend.d.ts +17 -0
  98. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +111 -3
  99. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +111 -3
  100. package/dist/builtins/sqlite-storage/storage-admin-provider.d.ts +9 -1
  101. package/dist/builtins/storage-orchestrator/drain-state-store.d.ts +5 -2
  102. package/dist/builtins/storage-orchestrator/location-store.d.ts +7 -2
  103. package/dist/builtins/storage-orchestrator/record-kinds.d.ts +38 -0
  104. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +2 -0
  105. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +196 -5
  106. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +195 -6
  107. package/dist/builtins/system-config/record-kinds.d.ts +32 -0
  108. package/dist/builtins/system-config/system-config.addon.js +53 -618
  109. package/dist/builtins/system-config/system-config.addon.mjs +29 -577
  110. package/dist/builtins/winston-logging/index.js +1 -1
  111. package/dist/builtins/winston-logging/index.mjs +1 -1
  112. package/dist/{composition-sources-C3rKncIF.mjs → composition-sources-BMt5cFYb.mjs} +1 -1
  113. package/dist/{composition-sources-NAPZddic.js → composition-sources-D3fi9Xns.js} +1 -1
  114. package/dist/{constants-BKX2QnIg.mjs → constants-BMHCxRzb.mjs} +1 -1
  115. package/dist/{constants-BXiNEIeV.js → constants-Br879Axi.js} +1 -1
  116. package/dist/{device-ca-DT9X2S6d.js → device-ca-CnJ_va7i.js} +1 -1
  117. package/dist/{device-ca-jxjSL8Ov.mjs → device-ca-T8osSMos.mjs} +1 -1
  118. package/dist/{dist-DERK-gP5.mjs → dist-BNunRyXT.mjs} +174 -58
  119. package/dist/{dist-D1vECb_6.js → dist-DgOG8flk.js} +233 -57
  120. package/dist/file-host-worker.js +1 -1
  121. package/dist/file-host-worker.mjs +1 -1
  122. package/dist/{hub-mdns-ciao-Cah9GCIg.js → hub-mdns-ciao-BIkTHq-n.js} +2 -2
  123. package/dist/{hub-mdns-ciao-CRaC97V0.mjs → hub-mdns-ciao-D16oRQ9K.mjs} +2 -2
  124. package/dist/index.d.ts +7 -0
  125. package/dist/index.js +3093 -2820
  126. package/dist/index.mjs +3065 -2809
  127. package/dist/kernel/index.d.ts +2 -0
  128. package/dist/kernel/moleculer/event-bus.d.ts +3 -1
  129. package/dist/kernel/moleculer/mesh-mtls/mesh-certificate-registry.d.ts +5 -1
  130. package/dist/kernel/moleculer/remote-logger.d.ts +2 -2
  131. package/dist/kernel/transport/cap-route-resolver.d.ts +9 -38
  132. package/dist/phase6-declare-gate-Ci1-8uUn.js +98 -0
  133. package/dist/phase6-declare-gate-tkKOEitw.mjs +93 -0
  134. package/dist/read-all-rows-CVoO1ONM.js +29 -0
  135. package/dist/read-all-rows-TaPqdWNF.mjs +25 -0
  136. package/dist/records/read-all-rows.d.ts +6 -0
  137. package/dist/{restore-archive-daKyE24F.mjs → restore-archive-DR9MtO7J.mjs} +339 -9
  138. package/dist/{restore-archive-Dy-qKTdF.js → restore-archive-DjJnCgap.js} +353 -5
  139. package/dist/tls/agent-https-names.d.ts +9 -13
  140. package/dist/{wal-maintenance-dAv4IdzC.js → wal-maintenance-CODGqhKY.js} +0 -0
  141. package/dist/{wal-maintenance-zRc24mOC.mjs → wal-maintenance-CfvgtQ7C.mjs} +0 -0
  142. package/package.json +1 -1
@@ -3,11 +3,11 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D1vECb_6.js");
6
+ const require_dist = require("../../dist-DgOG8flk.js");
7
7
  const require_safe_buffer$1 = require("../../safe-buffer-D3aoa-7X.js");
8
8
  const require_x509_es = require("../../x509.es-C4cOo48M.js");
9
- const require_agent_https = require("../../agent-https-DlpTMDqA.js");
10
- const require_constants$8 = require("../../constants-BXiNEIeV.js");
9
+ const require_constants$8 = require("../../constants-Br879Axi.js");
10
+ const require_agent_https = require("../../agent-https-CiOW0-sj.js");
11
11
  const require_src$1 = require("../../src-CnAqG6EF.js");
12
12
  let zod = require("zod");
13
13
  let node_crypto = require("node:crypto");
@@ -298,161 +298,8 @@ function parsePayload(value) {
298
298
  };
299
299
  }
300
300
  //#endregion
301
- //#region src/kernel/moleculer/mesh-mtls/mesh-ca.ts
302
- /**
303
- * Hub mesh CA — EC P-256, key in the keychain, cert in `cluster.meshCa`.
304
- *
305
- * Distinct from the HTTPS local CA (`tls/cert-issue.ts`, RSA): the mesh CA
306
- * signs node leaves (CN = nodeID) and unlock-ticket JWS (ES256). Issuance uses
307
- * `@peculiar/x509` over WebCrypto — same library the HTTPS path already uses
308
- * (installed `1.14.3`; registry latest at adoption time was `2.1.0` — stay on
309
- * the pinned range already shipping).
310
- */
311
- require_x509_es.cryptoProvider.set(node_crypto.webcrypto);
312
- var MS_PER_DAY = 864e5;
313
- /** Key generation — EC P-256 (plan). WebCrypto DOM names are not in @types/node. */
314
- var MESH_KEY_ALGORITHM = {
315
- name: "ECDSA",
316
- namedCurve: "P-256"
317
- };
318
- /** Signing — ECDSA with SHA-256. */
319
- var MESH_SIGNING_ALGORITHM = {
320
- name: "ECDSA",
321
- hash: "SHA-256"
322
- };
323
- /** A node id: letters, digits, `.`, `_`, `-`; at most 63 characters; starts with a letter or digit. */
324
- var NODE_ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,62}$/i;
325
- /** Ids no agent may take: the hub's own, whatever the case (D857). */
326
- var RESERVED_NODE_IDS = new Set(["hub"]);
327
- /** True for an id an agent may carry: the pattern, and not a reserved name. */
328
- function isValidAgentNodeId(nodeId) {
329
- return NODE_ID_PATTERN.test(nodeId) && !RESERVED_NODE_IDS.has(nodeId.toLowerCase());
330
- }
331
- function freshSerial() {
332
- return `00${(0, node_crypto.randomBytes)(16).toString("hex")}`;
333
- }
334
- function toPkcs8Pem(pkcs8) {
335
- return `${require_x509_es.PemConverter.encode(pkcs8, "PRIVATE KEY")}\n`;
336
- }
337
- function toCertPem(cert) {
338
- return `${cert.toString("pem")}\n`;
339
- }
340
- async function exportKeyPem(key) {
341
- return toPkcs8Pem(await node_crypto.webcrypto.subtle.exportKey("pkcs8", key));
342
- }
343
- /** SHA-256 fingerprint of the DER cert, colon-hex uppercase (Node style). */
344
- function caFingerprint(certPem) {
345
- return new node_crypto.X509Certificate(certPem).fingerprint256;
346
- }
347
- /** Compact fingerprint (lowercase hex, no colons). */
348
- function caFingerprintCompact(certPem) {
349
- return (0, node_crypto.createHash)("sha256").update(new node_crypto.X509Certificate(certPem).raw).digest("hex");
350
- }
351
- async function generateMeshCa(now = /* @__PURE__ */ new Date()) {
352
- const keys = await node_crypto.webcrypto.subtle.generateKey(MESH_KEY_ALGORITHM, true, ["sign", "verify"]);
353
- const extensions = [
354
- new require_x509_es.BasicConstraintsExtension(true, 0, true),
355
- new require_x509_es.KeyUsagesExtension(require_x509_es.KeyUsageFlags.keyCertSign | require_x509_es.KeyUsageFlags.cRLSign, true),
356
- await require_x509_es.SubjectKeyIdentifierExtension.create(keys.publicKey)
357
- ];
358
- const cert = await require_x509_es.X509CertificateGenerator.createSelfSigned({
359
- serialNumber: freshSerial(),
360
- name: `CN=${require_constants$8.MESH_CA_COMMON_NAME}`,
361
- notBefore: require_x509_es.backdatedNotBefore(now),
362
- notAfter: new Date(now.getTime() + require_constants$8.MESH_CA_VALIDITY_DAYS * MS_PER_DAY),
363
- keys,
364
- signingAlgorithm: MESH_SIGNING_ALGORITHM,
365
- extensions
366
- });
367
- return {
368
- certPem: toCertPem(cert),
369
- keyPem: await exportKeyPem(keys.privateKey),
370
- cert,
371
- privateKey: keys.privateKey,
372
- publicKey: keys.publicKey
373
- };
374
- }
375
- async function loadMeshCa(certPem, keyPem) {
376
- const cert = new require_x509_es.X509Certificate(certPem);
377
- return {
378
- certPem,
379
- keyPem,
380
- cert,
381
- privateKey: await node_crypto.webcrypto.subtle.importKey("pkcs8", require_x509_es.PemConverter.decodeFirst(keyPem), MESH_KEY_ALGORITHM, true, ["sign"]),
382
- publicKey: await cert.publicKey.export(node_crypto.webcrypto)
383
- };
384
- }
385
- /**
386
- * Issue a leaf from a CSR. CN must be present; when `expectedNodeId` is set
387
- * it must match. Validity: 30 days.
388
- */
389
- async function issueMeshLeafFromCsr(ca, csrPem, opts = {}) {
390
- const csr = new require_x509_es.Pkcs10CertificateRequest(csrPem);
391
- if (!await csr.verify(node_crypto.webcrypto)) throw new Error("CSR signature is invalid");
392
- const cn = subjectCn(csr.subject);
393
- if (cn === null || cn.length === 0) throw new Error("CSR subject has no CN");
394
- if (opts.allowReserved !== true && !isValidAgentNodeId(cn)) throw new Error(`CSR CN '${cn}' is not an id an agent may carry`);
395
- if (opts.expectedNodeId !== void 0 && opts.expectedNodeId !== cn) throw new Error(`CSR CN '${cn}' does not match the token nodeId '${opts.expectedNodeId}'`);
396
- const now = opts.now ?? /* @__PURE__ */ new Date();
397
- const validDays = opts.validDays ?? 30;
398
- const serialNumber = freshSerial();
399
- const notAfter = new Date(now.getTime() + validDays * MS_PER_DAY);
400
- const extensions = [
401
- new require_x509_es.BasicConstraintsExtension(false, void 0, true),
402
- new require_x509_es.KeyUsagesExtension(require_x509_es.KeyUsageFlags.digitalSignature, true),
403
- new require_x509_es.ExtendedKeyUsageExtension([require_constants$8.SERVER_AUTH_OID, require_constants$8.CLIENT_AUTH_OID]),
404
- await require_x509_es.SubjectKeyIdentifierExtension.create(csr.publicKey),
405
- await require_x509_es.AuthorityKeyIdentifierExtension.create(ca.cert)
406
- ];
407
- return {
408
- certPem: toCertPem(await require_x509_es.X509CertificateGenerator.create({
409
- serialNumber,
410
- subject: `CN=${cn}`,
411
- issuer: ca.cert.subject,
412
- notBefore: require_x509_es.backdatedNotBefore(now),
413
- notAfter,
414
- publicKey: csr.publicKey,
415
- signingKey: ca.privateKey,
416
- signingAlgorithm: MESH_SIGNING_ALGORITHM,
417
- extensions
418
- })),
419
- serialNumber,
420
- notAfter,
421
- commonName: cn
422
- };
423
- }
424
- /** Issue a leaf for a known nodeID with a freshly generated key pair (tests / hub self). */
425
- async function issueMeshLeafForNode(ca, nodeId, opts = {}) {
426
- const keys = await node_crypto.webcrypto.subtle.generateKey(MESH_KEY_ALGORITHM, true, ["sign", "verify"]);
427
- return {
428
- ...await issueMeshLeafFromCsr(ca, await createMeshCsrPem(keys, nodeId), {
429
- expectedNodeId: nodeId,
430
- now: opts.now,
431
- validDays: opts.validDays,
432
- allowReserved: true
433
- }),
434
- keyPem: await exportKeyPem(keys.privateKey)
435
- };
436
- }
437
- function subjectCn(subject) {
438
- return /(?:^|,)\s*CN\s*=\s*([^,]+)/i.exec(subject)?.[1]?.trim() ?? null;
439
- }
440
- async function createMeshCsrPem(keys, commonName) {
441
- return `${(await require_x509_es.Pkcs10CertificateRequestGenerator.create({
442
- name: `CN=${commonName}`,
443
- keys,
444
- signingAlgorithm: MESH_SIGNING_ALGORITHM
445
- })).toString("pem")}\n`;
446
- }
447
- async function generateMeshKeyPair() {
448
- return node_crypto.webcrypto.subtle.generateKey(MESH_KEY_ALGORITHM, true, ["sign", "verify"]);
449
- }
450
- async function exportMeshPrivateKeyPem(key) {
451
- return exportKeyPem(key);
452
- }
453
- //#endregion
454
301
  //#region src/kernel/moleculer/mesh-mtls/mesh-ca-keeper.ts
455
- var SLOT$3 = Symbol.for("camstack.mesh.ca");
302
+ var SLOT$2 = Symbol.for("camstack.mesh.ca");
456
303
  var NOT_LOADED = {
457
304
  state: "unavailable",
458
305
  reason: "not-loaded"
@@ -464,10 +311,10 @@ function isState(value) {
464
311
  return state === "unavailable" && typeof Reflect.get(value, "reason") === "string";
465
312
  }
466
313
  function setProcessMeshCa(state) {
467
- Reflect.set(globalThis, SLOT$3, state);
314
+ Reflect.set(globalThis, SLOT$2, state);
468
315
  }
469
316
  function getProcessMeshCaState() {
470
- const value = Reflect.get(globalThis, SLOT$3);
317
+ const value = Reflect.get(globalThis, SLOT$2);
471
318
  return isState(value) ? value : NOT_LOADED;
472
319
  }
473
320
  function requireProcessMeshCa() {
@@ -573,7 +420,7 @@ async function loadOrGenerateMeshCa(deps) {
573
420
  try {
574
421
  return {
575
422
  state: "ready",
576
- ca: await loadMeshCa(certPem, entry.value)
423
+ ca: await require_agent_https.loadMeshCa(certPem, entry.value)
577
424
  };
578
425
  } catch (err) {
579
426
  return {
@@ -583,12 +430,12 @@ async function loadOrGenerateMeshCa(deps) {
583
430
  }
584
431
  }
585
432
  case "missing": try {
586
- const generated = await generateMeshCa();
433
+ const generated = await require_agent_https.generateMeshCa();
587
434
  await deps.secrets.put(require_constants$8.MESH_CA_KEY_REF, generated.keyPem);
588
435
  await deps.writeMeshCaCert(generated.certPem);
589
436
  return {
590
437
  state: "ready",
591
- ca: await loadMeshCa(generated.certPem, generated.keyPem)
438
+ ca: await require_agent_https.loadMeshCa(generated.certPem, generated.keyPem)
592
439
  };
593
440
  } catch (err) {
594
441
  return {
@@ -609,10 +456,10 @@ async function loadOrGenerateMeshCa(deps) {
609
456
  var MeshCrl = class {
610
457
  serials = /* @__PURE__ */ new Set();
611
458
  revoke(serialNumber) {
612
- this.serials.add(normalizeSerial$1(serialNumber));
459
+ this.serials.add(normalizeSerial(serialNumber));
613
460
  }
614
461
  isRevoked(serialNumber) {
615
- return this.serials.has(normalizeSerial$1(serialNumber));
462
+ return this.serials.has(normalizeSerial(serialNumber));
616
463
  }
617
464
  list() {
618
465
  return [...this.serials];
@@ -620,424 +467,21 @@ var MeshCrl = class {
620
467
  /** Restore from persisted serials (system-settings). */
621
468
  replaceAll(serials) {
622
469
  this.serials.clear();
623
- for (const s of serials) this.serials.add(normalizeSerial$1(s));
470
+ for (const s of serials) this.serials.add(normalizeSerial(s));
624
471
  }
625
472
  };
626
- function normalizeSerial$1(serial) {
473
+ function normalizeSerial(serial) {
627
474
  return serial.replace(/^0x/i, "").replace(/:/g, "").toLowerCase();
628
475
  }
629
- var SLOT$2 = Symbol.for("camstack.mesh.crl");
476
+ var SLOT$1 = Symbol.for("camstack.mesh.crl");
630
477
  function processMeshCrl() {
631
- const existing = Reflect.get(globalThis, SLOT$2);
478
+ const existing = Reflect.get(globalThis, SLOT$1);
632
479
  if (existing instanceof MeshCrl) return existing;
633
480
  const crl = new MeshCrl();
634
- Reflect.set(globalThis, SLOT$2, crl);
481
+ Reflect.set(globalThis, SLOT$1, crl);
635
482
  return crl;
636
483
  }
637
484
  //#endregion
638
- //#region src/kernel/moleculer/mesh-mtls/mesh-certificate-registry.ts
639
- /**
640
- * The hub's record of every mesh leaf (D856): which certificate each node holds,
641
- * when it expires, and which serials are revoked.
642
- *
643
- * Three ways a row appears:
644
- * - `enroll` / `renewal` / `boot` - the hub issued it and wrote it down at the
645
- * moment of issuing (the authoritative record);
646
- * - `observed` - a node enrolled before this record existed (or by a path that
647
- * did not write it) presented this leaf on its LIVE mutual-TLS connection.
648
- *
649
- * Revoked serials are persisted here and replayed into the in-memory CRL at boot,
650
- * so a revocation survives a hub restart. Hub only: agents persist none of it.
651
- */
652
- /**
653
- * @durable class=config owner=system-config
654
- * write="the hub records every mesh leaf it issues (enroll, renewal, boot) and every
655
- * leaf a connected node is observed presenting; a revocation stamps revokedAt"
656
- * retention="a revoked or expired row is kept 90 days past its end, then reaped; a
657
- * live row is never deleted. Forgetting a node does not delete its rows."
658
- */
659
- var MESH_NODE_CERTIFICATES_COLLECTION = "mesh_node_certificates";
660
- var MESH_NODE_CERTIFICATES_COLUMNS = [
661
- {
662
- name: "id",
663
- type: "TEXT",
664
- primaryKey: true,
665
- notNull: true
666
- },
667
- {
668
- name: "nodeId",
669
- type: "TEXT",
670
- notNull: true
671
- },
672
- {
673
- name: "serial",
674
- type: "TEXT",
675
- notNull: true
676
- },
677
- {
678
- name: "fingerprint",
679
- type: "TEXT",
680
- notNull: true
681
- },
682
- {
683
- name: "notBefore",
684
- type: "INTEGER",
685
- notNull: true
686
- },
687
- {
688
- name: "notAfter",
689
- type: "INTEGER",
690
- notNull: true
691
- },
692
- {
693
- name: "issuedAt",
694
- type: "INTEGER",
695
- notNull: true
696
- },
697
- {
698
- name: "issuedVia",
699
- type: "TEXT",
700
- notNull: true
701
- },
702
- {
703
- name: "revokedAt",
704
- type: "INTEGER"
705
- },
706
- {
707
- name: "revokedReason",
708
- type: "TEXT"
709
- }
710
- ];
711
- var RETENTION_MS = 90 * 864e5;
712
- /**
713
- * A leaf the hub signed for a renewal that did not complete. It must not be the node's
714
- * `current` leaf, but it is NOT on the CRL: the node may still hold it (the swap
715
- * could have landed without the hub seeing it), and cutting it off would be the
716
- * outage the hand-over exists to prevent. If the node is later seen presenting it, it
717
- * is reinstated.
718
- */
719
- var RENEWAL_ABANDONED = "renewal-abandoned";
720
- var VIAS = [
721
- "enroll",
722
- "pairing",
723
- "renewal",
724
- "boot",
725
- "observed"
726
- ];
727
- /** CN, serial, fingerprint and validity of a leaf PEM (or DER). */
728
- function describeMeshLeaf(cert) {
729
- const x509 = new node_crypto.X509Certificate(cert);
730
- return {
731
- cn: subjectCn(x509.subject) ?? "",
732
- serial: x509.serialNumber,
733
- fingerprint: x509.fingerprint256,
734
- notBefore: Date.parse(x509.validFrom),
735
- notAfter: Date.parse(x509.validTo)
736
- };
737
- }
738
- function normalizeSerial(serial) {
739
- return serial.replace(/^0x/i, "").replace(/:/g, "").toLowerCase();
740
- }
741
- function parse$1(data) {
742
- const str = (k) => {
743
- const v = data[k];
744
- return typeof v === "string" && v.length > 0 ? v : null;
745
- };
746
- const num = (k) => {
747
- const v = data[k];
748
- return typeof v === "number" && Number.isFinite(v) ? v : null;
749
- };
750
- const nodeId = str("nodeId");
751
- const serial = str("serial");
752
- const fingerprint = str("fingerprint");
753
- const notBefore = num("notBefore");
754
- const notAfter = num("notAfter");
755
- const issuedAt = num("issuedAt");
756
- if (nodeId === null || serial === null || fingerprint === null || notBefore === null || notAfter === null || issuedAt === null) return null;
757
- return {
758
- nodeId,
759
- serial,
760
- fingerprint,
761
- notBefore,
762
- notAfter,
763
- issuedAt,
764
- issuedVia: VIAS.find((v) => v === data["issuedVia"]) ?? "observed",
765
- revokedAt: num("revokedAt"),
766
- revokedReason: str("revokedReason")
767
- };
768
- }
769
- var MeshCertificateRegistry = class {
770
- store;
771
- deps;
772
- rows = /* @__PURE__ */ new Map();
773
- constructor(store, deps = {}) {
774
- this.store = store;
775
- this.deps = deps;
776
- }
777
- now() {
778
- return (this.deps.now ?? Date.now)();
779
- }
780
- async load() {
781
- const rows = await this.store.query.query({ collection: MESH_NODE_CERTIFICATES_COLLECTION });
782
- for (const row of rows) {
783
- const record = parse$1(row.data);
784
- if (record !== null) this.rows.set(record.fingerprint, record);
785
- }
786
- }
787
- /** Write down a leaf the hub just issued. Idempotent per fingerprint. */
788
- async recordIssued(nodeId, certPem, via) {
789
- const leaf = describeMeshLeaf(certPem);
790
- const existing = this.rows.get(leaf.fingerprint);
791
- if (existing !== void 0) return existing;
792
- const record = {
793
- nodeId,
794
- serial: leaf.serial,
795
- fingerprint: leaf.fingerprint,
796
- notBefore: leaf.notBefore,
797
- notAfter: leaf.notAfter,
798
- issuedAt: this.now(),
799
- issuedVia: via,
800
- revokedAt: null,
801
- revokedReason: null
802
- };
803
- await this.insert(record);
804
- this.deps.logger?.info("Mesh certificate recorded", {
805
- tags: { nodeId },
806
- meta: {
807
- via,
808
- serial: leaf.serial,
809
- notAfter: new Date(leaf.notAfter).toISOString()
810
- }
811
- });
812
- return record;
813
- }
814
- /**
815
- * A node was seen presenting `leaf` on its live connection. A leaf the hub already
816
- * knows is left alone; an unknown one is recorded `observed` (a node enrolled
817
- * before this record existed).
818
- */
819
- async recordObserved(nodeId, leaf) {
820
- const known = this.rows.get(leaf.fingerprint);
821
- if (known !== void 0) {
822
- if (known.revokedReason !== "renewal-abandoned") return known.revokedAt === null ? this.abandonRenewalsNewerThan(known) : false;
823
- const reinstated = {
824
- ...known,
825
- revokedAt: null,
826
- revokedReason: null
827
- };
828
- this.rows.set(known.fingerprint, reinstated);
829
- await this.persist(reinstated);
830
- this.deps.logger?.warn("An abandoned renewal leaf is in use - reinstated", {
831
- tags: { nodeId },
832
- meta: { serial: known.serial }
833
- });
834
- return true;
835
- }
836
- const record = {
837
- nodeId,
838
- serial: leaf.serial,
839
- fingerprint: leaf.fingerprint,
840
- notBefore: leaf.notBefore,
841
- notAfter: leaf.notAfter,
842
- issuedAt: this.now(),
843
- issuedVia: "observed",
844
- revokedAt: null,
845
- revokedReason: null
846
- };
847
- await this.insert(record);
848
- this.deps.logger?.info("Mesh certificate observed on a live connection and recorded", {
849
- tags: { nodeId },
850
- meta: {
851
- serial: leaf.serial,
852
- fingerprint: leaf.fingerprint
853
- }
854
- });
855
- return true;
856
- }
857
- list(nodeId) {
858
- return [...this.rows.values()].filter((r) => nodeId === void 0 || r.nodeId === nodeId).toSorted((a, b) => b.issuedAt - a.issuedAt);
859
- }
860
- /** The newest non-revoked leaf of a node, or `undefined`. */
861
- currentFor(nodeId) {
862
- return this.list(nodeId).find((r) => r.revokedAt === null);
863
- }
864
- /** Every non-revoked leaf of a node (a renewal in flight has two). */
865
- liveFor(nodeId) {
866
- return this.list(nodeId).filter((r) => r.revokedAt === null);
867
- }
868
- /** Stamp a leaf revoked (and mirror it into `crl`). `false` when unknown or already revoked. */
869
- async revoke(fingerprint, reason, crl) {
870
- const record = this.rows.get(fingerprint);
871
- if (record === void 0 || record.revokedAt !== null) return false;
872
- const revoked = {
873
- ...record,
874
- revokedAt: this.now(),
875
- revokedReason: reason
876
- };
877
- this.rows.set(fingerprint, revoked);
878
- crl?.revoke(record.serial);
879
- await this.persist(revoked);
880
- this.deps.logger?.warn("Mesh certificate revoked", {
881
- tags: { nodeId: record.nodeId },
882
- meta: {
883
- serial: record.serial,
884
- reason
885
- }
886
- });
887
- return true;
888
- }
889
- /**
890
- * Operator revocation of a whole node: EVERY leaf of the node that is not already on the
891
- * CRL goes on it - the current one, an observed one, a renewal one, and a leaf that was set
892
- * aside (`renewal-abandoned`: a copy of it may sit on a stolen box, and it must not stay
893
- * valid just because the hub once set it aside). Returns the serials put on the CRL.
894
- * A leaf revoked this way is never reinstated by `recordObserved`.
895
- */
896
- async revokeAllForNode(nodeId, reason, crl, keepFingerprint) {
897
- const serials = [];
898
- for (const record of this.list(nodeId)) {
899
- if (keepFingerprint !== void 0 && record.fingerprint === keepFingerprint) continue;
900
- if (record.revokedAt !== null && record.revokedReason !== "renewal-abandoned") continue;
901
- const revoked = {
902
- ...record,
903
- revokedAt: record.revokedAt ?? this.now(),
904
- revokedReason: reason
905
- };
906
- this.rows.set(record.fingerprint, revoked);
907
- crl.revoke(record.serial);
908
- await this.persist(revoked);
909
- serials.push(record.serial);
910
- }
911
- if (serials.length > 0) this.deps.logger?.warn("Every mesh certificate of the node revoked", {
912
- tags: { nodeId },
913
- meta: {
914
- serials,
915
- reason
916
- }
917
- });
918
- return serials;
919
- }
920
- /**
921
- * At boot: a node with TWO live leaves had a renewal in flight when the hub stopped. The
922
- * newer (renewal) one is set aside - it is not the node's current leaf until the node is
923
- * seen presenting it, which reinstates it. It is NOT put on the CRL.
924
- */
925
- async settleInterruptedRenewals() {
926
- let settled = 0;
927
- const byNode = /* @__PURE__ */ new Map();
928
- for (const record of this.rows.values()) {
929
- if (record.revokedAt !== null) continue;
930
- byNode.set(record.nodeId, [...byNode.get(record.nodeId) ?? [], record]);
931
- }
932
- for (const records of byNode.values()) {
933
- if (records.length < 2) continue;
934
- for (const record of records) if (record.issuedVia === "renewal" && await this.abandon(record.fingerprint)) settled += 1;
935
- }
936
- return settled;
937
- }
938
- /** Set a never-completed renewal leaf aside (not current, NOT on the CRL). */
939
- /** Fingerprints of renewal leaves whose handover is running right now (this process only). */
940
- renewalsInFlight = /* @__PURE__ */ new Set();
941
- /**
942
- * A renewal's leaf is "in flight" from signing until the handover ends. While it is, a node seen
943
- * presenting its OLD leaf is simply not swapped yet: the new leaf is not set aside (that would
944
- * flap set-aside / reinstate on the node's first connection with it).
945
- */
946
- beginRenewal(fingerprint) {
947
- this.renewalsInFlight.add(fingerprint);
948
- }
949
- endRenewal(fingerprint) {
950
- this.renewalsInFlight.delete(fingerprint);
951
- }
952
- async abandonRenewalsNewerThan(presented) {
953
- let changed = false;
954
- for (const record of this.liveFor(presented.nodeId)) {
955
- if (record.fingerprint === presented.fingerprint) continue;
956
- if (record.issuedVia !== "renewal" || record.issuedAt <= presented.issuedAt) continue;
957
- if (this.renewalsInFlight.has(record.fingerprint)) continue;
958
- if (await this.abandon(record.fingerprint)) changed = true;
959
- }
960
- return changed;
961
- }
962
- async abandon(fingerprint) {
963
- const record = this.rows.get(fingerprint);
964
- if (record === void 0 || record.revokedAt !== null) return false;
965
- const abandoned = {
966
- ...record,
967
- revokedAt: this.now(),
968
- revokedReason: RENEWAL_ABANDONED
969
- };
970
- this.rows.set(fingerprint, abandoned);
971
- await this.persist(abandoned);
972
- this.deps.logger?.warn("Renewal leaf set aside (not current, not on the CRL)", {
973
- tags: { nodeId: record.nodeId },
974
- meta: { serial: record.serial }
975
- });
976
- return true;
977
- }
978
- /** Replay every persisted revocation into `crl` (hub boot). Set-aside leaves are not revocations. */
979
- restoreCrl(crl) {
980
- let restored = 0;
981
- for (const record of this.rows.values()) {
982
- if (record.revokedAt === null || record.revokedReason === "renewal-abandoned") continue;
983
- crl.revoke(record.serial);
984
- restored += 1;
985
- }
986
- return restored;
987
- }
988
- /** Is `serial` listed as revoked here? */
989
- isRevoked(serial) {
990
- const wanted = normalizeSerial(serial);
991
- for (const record of this.rows.values()) if (record.revokedAt !== null && record.revokedReason !== "renewal-abandoned" && normalizeSerial(record.serial) === wanted) return true;
992
- return false;
993
- }
994
- async reap() {
995
- const cutoff = this.now() - RETENTION_MS;
996
- const dead = [...this.rows.values()].filter((r) => (r.revokedAt ?? r.notAfter) < cutoff);
997
- for (const r of dead) {
998
- this.rows.delete(r.fingerprint);
999
- await this.store.delete.mutate({
1000
- collection: MESH_NODE_CERTIFICATES_COLLECTION,
1001
- key: r.fingerprint
1002
- });
1003
- }
1004
- return dead.length;
1005
- }
1006
- async insert(record) {
1007
- this.rows.set(record.fingerprint, record);
1008
- await this.store.insert.mutate({
1009
- collection: MESH_NODE_CERTIFICATES_COLLECTION,
1010
- record: {
1011
- id: record.fingerprint,
1012
- data: { ...record }
1013
- }
1014
- });
1015
- }
1016
- async persist(record) {
1017
- try {
1018
- await this.store.update.mutate({
1019
- collection: MESH_NODE_CERTIFICATES_COLLECTION,
1020
- id: record.fingerprint,
1021
- data: { ...record }
1022
- });
1023
- } catch (error) {
1024
- this.deps.logger?.error("Mesh certificate write failed - the change holds until restart", {
1025
- tags: { nodeId: record.nodeId },
1026
- meta: { error: error instanceof Error ? error.message : String(error) }
1027
- });
1028
- }
1029
- }
1030
- };
1031
- var SLOT$1 = Symbol.for("camstack.mesh.certificate-registry");
1032
- function setProcessMeshCertificateRegistry(registry) {
1033
- if (registry === null) Reflect.deleteProperty(globalThis, SLOT$1);
1034
- else Reflect.set(globalThis, SLOT$1, registry);
1035
- }
1036
- function getProcessMeshCertificateRegistry() {
1037
- const value = Reflect.get(globalThis, SLOT$1);
1038
- return value !== null && typeof value === "object" && typeof Reflect.get(value, "recordIssued") === "function" ? value : null;
1039
- }
1040
- //#endregion
1041
485
  //#region src/kernel/moleculer/mesh-mtls/mesh-tls-gate.ts
1042
486
  var STATE_SLOT = Symbol.for("camstack.mesh.tls-listener-state");
1043
487
  function setProcessMeshTlsListenerState(state) {
@@ -1180,7 +624,7 @@ async function runRenewal(deps, inFlight) {
1180
624
  }
1181
625
  let issued;
1182
626
  try {
1183
- issued = await issueMeshLeafFromCsr(deps.ca, csrPem, { expectedNodeId: nodeId });
627
+ issued = await require_agent_https.issueMeshLeafFromCsr(deps.ca, csrPem, { expectedNodeId: nodeId });
1184
628
  await deps.registry.recordIssued(nodeId, issued.certPem, "renewal");
1185
629
  log.info("Mesh renewal: new leaf signed and recorded", {
1186
630
  tags,
@@ -1192,7 +636,7 @@ async function runRenewal(deps, inFlight) {
1192
636
  } catch (error) {
1193
637
  return fail("issue", message(error), true);
1194
638
  }
1195
- const newLeaf = describeMeshLeaf(issued.certPem);
639
+ const newLeaf = require_agent_https.describeMeshLeaf(issued.certPem);
1196
640
  deps.registry.beginRenewal(newLeaf.fingerprint);
1197
641
  inFlight.fingerprint = newLeaf.fingerprint;
1198
642
  let resolveRegistered = () => void 0;
@@ -86710,7 +86154,7 @@ function peerIdentity(socket) {
86710
86154
  if (cert == null || typeof cert !== "object" || !("raw" in cert) || !cert.raw) return null;
86711
86155
  try {
86712
86156
  const x509 = new node_crypto.X509Certificate(cert.raw);
86713
- const cn = subjectCn(x509.subject) ?? subjectCn(`CN=${cert.subject?.CN ?? ""}`);
86157
+ const cn = require_agent_https.subjectCn(x509.subject) ?? require_agent_https.subjectCn(`CN=${cert.subject?.CN ?? ""}`);
86714
86158
  if (cn === null || cn.length === 0) return null;
86715
86159
  return {
86716
86160
  cn,
@@ -87238,7 +86682,7 @@ function newPairingId() {
87238
86682
  }
87239
86683
  /** The hub's commitment to its nonce, bound to the CA certificate it offers. */
87240
86684
  function computePairingCommitment(caCertPem, hubNonce) {
87241
- return (0, node_crypto.createHash)("sha256").update(`${PAIRING_DOMAIN}|commit|${caFingerprintCompact(caCertPem)}|${hubNonce}`, "utf8").digest("hex");
86685
+ return (0, node_crypto.createHash)("sha256").update(`${PAIRING_DOMAIN}|commit|${require_agent_https.caFingerprintCompact(caCertPem)}|${hubNonce}`, "utf8").digest("hex");
87242
86686
  }
87243
86687
  function commitmentsEqual(expected, presented) {
87244
86688
  return constantTimeEqual(expected, presented);
@@ -87248,7 +86692,7 @@ function computePairingSas(input) {
87248
86692
  const value = (0, node_crypto.createHash)("sha256").update([
87249
86693
  PAIRING_DOMAIN,
87250
86694
  "sas",
87251
- caFingerprintCompact(input.caCertPem),
86695
+ require_agent_https.caFingerprintCompact(input.caCertPem),
87252
86696
  input.agentPublicKeySpki,
87253
86697
  input.hubNonce,
87254
86698
  input.agentNonce
@@ -87264,7 +86708,7 @@ function constantTimeEqual(expected, presented) {
87264
86708
  async function describeCsr(csrPem) {
87265
86709
  const csr = new require_x509_es.Pkcs10CertificateRequest(csrPem);
87266
86710
  if (!await csr.verify(node_crypto.webcrypto)) throw new Error("the agent CSR signature is invalid");
87267
- const cn = subjectCn(csr.subject);
86711
+ const cn = require_agent_https.subjectCn(csr.subject);
87268
86712
  if (cn === null || cn.length === 0) throw new Error("the agent CSR has no CN");
87269
86713
  return {
87270
86714
  commonName: cn,
@@ -87575,23 +87019,23 @@ var AgentPairing = class {
87575
87019
  async offer(body) {
87576
87020
  this.expireIfDue();
87577
87021
  if (this.deps.isPaired()) return fail(409, "already-paired", "this agent is paired — unpair it first (from the hub or here)");
87578
- if (!isValidAgentNodeId(this.deps.nodeId)) return fail(409, "invalid-node-id", `this agent's node id "${this.deps.nodeId}" cannot be paired - rename the agent`);
87022
+ if (!require_agent_https.isValidAgentNodeId(this.deps.nodeId)) return fail(409, "invalid-node-id", `this agent's node id "${this.deps.nodeId}" cannot be paired - rename the agent`);
87579
87023
  const request = parseOffer(body);
87580
87024
  if (request === null) return fail(400, "bad-offer", "the offer is malformed");
87581
87025
  if (request.protocol !== 1) return fail(400, "unsupported-protocol", `pairing protocol ${String(request.protocol)} is not supported`);
87582
87026
  if (readCaCertificate(request.hubCaCertPem, this.now()) === null) return fail(400, "bad-ca", "the offered CA is not a valid self-signed CA certificate");
87583
87027
  if (!/^[0-9a-f]{64}$/.test(request.commitment)) return fail(400, "bad-offer", "the commitment is malformed");
87584
87028
  if (!isHttpUrl(request.hubUrl)) return fail(400, "bad-offer", "hubUrl is not an http(s) URL");
87585
- const caFingerprint = caFingerprintCompact(request.hubCaCertPem);
87029
+ const caFingerprint = require_agent_https.caFingerprintCompact(request.hubCaCertPem);
87586
87030
  const refused = this.checkOfferSignature(request, caFingerprint);
87587
87031
  if (refused !== null) return refused;
87588
87032
  const rationed = this.rationOffer(caFingerprint);
87589
87033
  if (rationed !== null) return rationed;
87590
87034
  for (const existing of [...this.sessions.values()]) if (existing.hub.caFingerprint === caFingerprint) this.end(existing, "failed");
87591
87035
  if (this.sessions.size >= 4 && !this.makeRoom()) return fail(409, "too-many-pending", "too many pairings are pending on this agent");
87592
- const keys = await generateMeshKeyPair();
87593
- const csrPem = await createMeshCsrPem(keys, this.deps.nodeId);
87594
- const keyPem = await exportMeshPrivateKeyPem(keys.privateKey);
87036
+ const keys = await require_agent_https.generateMeshKeyPair();
87037
+ const csrPem = await require_agent_https.createMeshCsrPem(keys, this.deps.nodeId);
87038
+ const keyPem = await require_agent_https.exportMeshPrivateKeyPem(keys.privateKey);
87595
87039
  const publicKeySpki = Buffer.from(await node_crypto.webcrypto.subtle.exportKey("spki", keys.publicKey)).toString("base64");
87596
87040
  if (this.sessions.size >= 4 && !this.makeRoom()) return fail(409, "too-many-pending", "too many pairings are pending on this agent");
87597
87041
  const session = {
@@ -87931,7 +87375,7 @@ var AgentPairing = class {
87931
87375
  const leaf = new node_crypto.X509Certificate(leafPem);
87932
87376
  const ca = new node_crypto.X509Certificate(session.hub.caCertPem);
87933
87377
  if (!leaf.verify(ca.publicKey)) return fail(400, "bad-leaf", "the certificate is not signed by the offered CA");
87934
- if (subjectCn(leaf.subject.replaceAll("\n", ",")) !== this.deps.nodeId) return fail(400, "bad-leaf", `the certificate is not issued for "${this.deps.nodeId}"`);
87378
+ if (require_agent_https.subjectCn(leaf.subject.replaceAll("\n", ",")) !== this.deps.nodeId) return fail(400, "bad-leaf", `the certificate is not issued for "${this.deps.nodeId}"`);
87935
87379
  if (!leaf.checkPrivateKey((0, node_crypto.createPrivateKey)(session.keyPem))) return fail(400, "bad-leaf", "the certificate does not match this agent's private key");
87936
87380
  if (Date.parse(leaf.validTo) <= this.now()) return fail(400, "bad-leaf", "the certificate is already expired");
87937
87381
  } catch {
@@ -87989,7 +87433,7 @@ function field(body, key) {
87989
87433
  }
87990
87434
  function caFingerprintOf(pem) {
87991
87435
  try {
87992
- return caFingerprintCompact(pem);
87436
+ return require_agent_https.caFingerprintCompact(pem);
87993
87437
  } catch {
87994
87438
  return null;
87995
87439
  }
@@ -88084,7 +87528,7 @@ var HubPairing = class {
88084
87528
  use: PAIRING_OFFER_USE,
88085
87529
  agentNodeId: hello.nodeId,
88086
87530
  hubNodeId: this.deps.hubNodeId,
88087
- caFingerprint: caFingerprintCompact(ca.certPem),
87531
+ caFingerprint: require_agent_https.caFingerprintCompact(ca.certPem),
88088
87532
  commitment,
88089
87533
  hubUrl,
88090
87534
  hubMeshAddress,
@@ -88201,14 +87645,14 @@ var HubPairing = class {
88201
87645
  }
88202
87646
  async complete(session) {
88203
87647
  const ca = this.deps.ca();
88204
- if (ca === null || caFingerprintCompact(ca.certPem) !== caFingerprintCompact(session.caCertPem)) {
87648
+ if (ca === null || require_agent_https.caFingerprintCompact(ca.certPem) !== require_agent_https.caFingerprintCompact(session.caCertPem)) {
88205
87649
  await this.cancel(session, "failed", "the mesh CA changed during the pairing");
88206
87650
  return;
88207
87651
  }
88208
87652
  session.state = "completing";
88209
87653
  let issuedPem = null;
88210
87654
  try {
88211
- const leaf = await issueMeshLeafFromCsr(ca, session.csrPem, { expectedNodeId: session.nodeId });
87655
+ const leaf = await require_agent_https.issueMeshLeafFromCsr(ca, session.csrPem, { expectedNodeId: session.nodeId });
88212
87656
  issuedPem = leaf.certPem;
88213
87657
  await this.deps.recordIssued(session.nodeId, leaf.certPem);
88214
87658
  session.issued = true;
@@ -88220,7 +87664,7 @@ var HubPairing = class {
88220
87664
  hubNonce: session.hubNonce,
88221
87665
  agentNonce: session.agentNonce,
88222
87666
  leafFingerprint: leafFingerprintCompact(leaf.certPem),
88223
- caFingerprint: caFingerprintCompact(ca.certPem),
87667
+ caFingerprint: require_agent_https.caFingerprintCompact(ca.certPem),
88224
87668
  hubMeshAddress: session.hubMeshAddress,
88225
87669
  hubUrl: session.hubUrl,
88226
87670
  iat: this.now(),
@@ -88274,7 +87718,7 @@ var HubPairing = class {
88274
87718
  }
88275
87719
  }
88276
87720
  assertNodeIdUsable(nodeId) {
88277
- if (!isValidAgentNodeId(nodeId)) throw new Error(`"${nodeId}" cannot be an agent node id (letters, digits, . _ - ; not "hub"; at most 63 characters)`);
87721
+ if (!require_agent_https.isValidAgentNodeId(nodeId)) throw new Error(`"${nodeId}" cannot be an agent node id (letters, digits, . _ - ; not "hub"; at most 63 characters)`);
88278
87722
  if (this.deps.isNodeConnected(nodeId)) throw new Error(`a node called "${nodeId}" is already connected to this hub — unpair it first`);
88279
87723
  const lower = nodeId.toLowerCase();
88280
87724
  const clash = (this.deps.knownNodeIds?.() ?? []).find((known) => known !== nodeId && known.toLowerCase() === lower);
@@ -88459,7 +87903,7 @@ var SystemConfigAddon = class extends require_dist.BaseAddon {
88459
87903
  };
88460
87904
  }
88461
87905
  async onShutdown() {
88462
- setProcessMeshCertificateRegistry(null);
87906
+ require_agent_https.setProcessMeshCertificateRegistry(null);
88463
87907
  setProcessMeshTlsListenerState(null);
88464
87908
  require_agent_https.setProcessAgentHttpsNames(null);
88465
87909
  this.stoppedMesh = true;
@@ -88485,22 +87929,27 @@ var SystemConfigAddon = class extends require_dist.BaseAddon {
88485
87929
  }
88486
87930
  return null;
88487
87931
  }
88488
- this.loadAgentHttpsNames(store);
87932
+ const records = this.ctx.records;
87933
+ const meshKind = records === void 0 ? null : (await records.declare(require_agent_https.systemConfigRecordKinds), records.kind(require_agent_https.systemConfigRecordKinds["mesh-node-certificates"]));
87934
+ this.loadAgentHttpsNames(store, records);
88489
87935
  try {
88490
- await store.declareCollection.mutate({
88491
- collection: MESH_NODE_CERTIFICATES_COLLECTION,
88492
- columns: MESH_NODE_CERTIFICATES_COLUMNS,
87936
+ if (records === void 0) await store.declareCollection.mutate({
87937
+ collection: require_agent_https.MESH_NODE_CERTIFICATES_COLLECTION,
87938
+ columns: require_agent_https.MESH_NODE_CERTIFICATES_COLUMNS,
88493
87939
  indexes: [{
88494
87940
  name: "idx_mesh_node_certificates_node",
88495
87941
  columns: ["nodeId"]
88496
87942
  }]
88497
87943
  });
88498
- const registry = new MeshCertificateRegistry(store, { logger: this.ctx.logger });
87944
+ const registry = new require_agent_https.MeshCertificateRegistry(store, {
87945
+ logger: this.ctx.logger,
87946
+ meshKind
87947
+ });
88499
87948
  await registry.load();
88500
87949
  const restored = registry.restoreCrl(processMeshCrl());
88501
87950
  const settled = await registry.settleInterruptedRenewals();
88502
87951
  if (settled > 0) this.ctx.logger.warn("A mesh renewal was interrupted by a hub restart - its new leaf was set aside", { meta: { settled } });
88503
- setProcessMeshCertificateRegistry(registry);
87952
+ require_agent_https.setProcessMeshCertificateRegistry(registry);
88504
87953
  if (restored > 0) this.ctx.logger.info("Mesh revocations restored into the CRL", { meta: { restored } });
88505
87954
  return registry;
88506
87955
  } catch (err) {
@@ -88509,13 +87958,16 @@ var SystemConfigAddon = class extends require_dist.BaseAddon {
88509
87958
  }
88510
87959
  }
88511
87960
  /** Which names the hub certified to which agent. Best effort; nothing waits on it. */
88512
- async loadAgentHttpsNames(store) {
87961
+ async loadAgentHttpsNames(store, records) {
88513
87962
  try {
88514
- await store.declareCollection.mutate({
87963
+ if (records === void 0) await store.declareCollection.mutate({
88515
87964
  collection: require_agent_https.AGENT_HTTPS_NAMES_COLLECTION,
88516
87965
  columns: require_agent_https.AGENT_HTTPS_NAMES_COLUMNS
88517
87966
  });
88518
- const names = new require_agent_https.AgentHttpsNames(store);
87967
+ const names = records === void 0 ? new require_agent_https.AgentHttpsNames(store) : new require_agent_https.AgentHttpsNames({
87968
+ agentHttpsNamesKind: records.kind(require_agent_https.systemConfigRecordKinds["agent-https-names"]),
87969
+ legacyStore: store
87970
+ });
88519
87971
  await names.load();
88520
87972
  require_agent_https.setProcessAgentHttpsNames(names);
88521
87973
  } catch (err) {
@@ -88531,7 +87983,7 @@ var SystemConfigAddon = class extends require_dist.BaseAddon {
88531
87983
  await openMeshTlsWhenRevocationsLoaded({
88532
87984
  loadRegistry: () => this.initMeshCertificateRegistry(),
88533
87985
  open: async (registry) => {
88534
- const hubLeaf = await issueMeshLeafForNode(ca, "hub");
87986
+ const hubLeaf = await require_agent_https.issueMeshLeafForNode(ca, "hub");
88535
87987
  await registry.recordIssued("hub", hubLeaf.certPem, "boot").catch((err) => {
88536
87988
  this.ctx.logger.warn("Hub mesh leaf could not be recorded", { meta: { error: err instanceof Error ? err.message : String(err) } });
88537
87989
  });
@@ -88838,11 +88290,8 @@ exports.AGENT_UI_UNLOCK_VERSION = AGENT_UI_UNLOCK_VERSION;
88838
88290
  exports.AgentPairing = AgentPairing;
88839
88291
  exports.Errors = Errors;
88840
88292
  exports.HubPairing = HubPairing;
88841
- exports.MESH_NODE_CERTIFICATES_COLLECTION = MESH_NODE_CERTIFICATES_COLLECTION;
88842
- exports.MESH_NODE_CERTIFICATES_COLUMNS = MESH_NODE_CERTIFICATES_COLUMNS;
88843
88293
  exports.MESH_TLS_PORT_HELLO_FIELD = MESH_TLS_PORT_HELLO_FIELD;
88844
88294
  exports.MeshCaKeeper = MeshCaKeeper;
88845
- exports.MeshCertificateRegistry = MeshCertificateRegistry;
88846
88295
  exports.MeshCrl = MeshCrl;
88847
88296
  exports.PAIRING_CODE_DIGITS = PAIRING_CODE_DIGITS;
88848
88297
  exports.PAIRING_MAX_CODE_ATTEMPTS = PAIRING_MAX_CODE_ATTEMPTS;
@@ -88852,39 +88301,26 @@ exports.PAIRING_PIN_DIGITS = PAIRING_PIN_DIGITS;
88852
88301
  exports.PAIRING_PROTOCOL = PAIRING_PROTOCOL;
88853
88302
  exports.PAIRING_TTL_MS = PAIRING_TTL_MS;
88854
88303
  exports.PairingHttpError = PairingHttpError;
88855
- exports.RENEWAL_ABANDONED = RENEWAL_ABANDONED;
88856
88304
  exports.SYSTEM_CONFIG_CLUSTER_SECTION_ID = SYSTEM_CONFIG_CLUSTER_SECTION_ID;
88857
88305
  exports.ServiceBroker = ServiceBroker;
88858
88306
  exports.SystemConfigAddon = SystemConfigAddon;
88859
88307
  exports.default = SystemConfigAddon;
88860
88308
  exports.TlsTcpTransporter = TlsTcpTransporter;
88861
88309
  exports.UnlockTicketJtiStore = UnlockTicketJtiStore;
88862
- exports.caFingerprint = caFingerprint;
88863
- exports.caFingerprintCompact = caFingerprintCompact;
88864
88310
  exports.computePairingCommitment = computePairingCommitment;
88865
88311
  exports.computePairingSas = computePairingSas;
88866
88312
  exports.createCidrMatcher = createCidrMatcher;
88867
- exports.createMeshCsrPem = createMeshCsrPem;
88868
88313
  exports.describeCsr = describeCsr;
88869
- exports.describeMeshLeaf = describeMeshLeaf;
88870
88314
  exports.dropProcessPeer = dropProcessPeer;
88871
88315
  exports.emitProcessNodeRegistered = emitProcessNodeRegistered;
88872
- exports.exportMeshPrivateKeyPem = exportMeshPrivateKeyPem;
88873
- exports.generateMeshCa = generateMeshCa;
88874
- exports.generateMeshKeyPair = generateMeshKeyPair;
88875
88316
  exports.getProcessMeshCaState = getProcessMeshCaState;
88876
- exports.getProcessMeshCertificateRegistry = getProcessMeshCertificateRegistry;
88877
88317
  exports.getProcessMeshTlsListenerState = getProcessMeshTlsListenerState;
88878
88318
  exports.getProcessNodeMeshTransport = getProcessNodeMeshTransport;
88879
88319
  exports.getProcessPeerLeaf = getProcessPeerLeaf;
88880
88320
  exports.hubHostFromMeshAddress = hubHostFromMeshAddress;
88881
88321
  exports.isAllowedAgentDashboardReturnTo = isAllowedAgentDashboardReturnTo;
88882
88322
  exports.isProcessVerifiedMeshPeer = isProcessVerifiedMeshPeer;
88883
- exports.isValidAgentNodeId = isValidAgentNodeId;
88884
- exports.issueMeshLeafForNode = issueMeshLeafForNode;
88885
- exports.issueMeshLeafFromCsr = issueMeshLeafFromCsr;
88886
88323
  exports.keyFingerprintShort = keyFingerprintShort;
88887
- exports.loadMeshCa = loadMeshCa;
88888
88324
  exports.mintAgentUiUnlockTicket = mintAgentUiUnlockTicket;
88889
88325
  exports.normalizeIp = normalizeIp;
88890
88326
  exports.onProcessNodeRegistered = onProcessNodeRegistered;
@@ -88896,7 +88332,6 @@ exports.readCidrSetting = readCidrSetting;
88896
88332
  exports.renewMeshCertificate = renewMeshCertificate;
88897
88333
  exports.requireProcessMeshCa = requireProcessMeshCa;
88898
88334
  exports.revokeMeshCertificate = revokeMeshCertificate;
88899
- exports.setProcessMeshCertificateRegistry = setProcessMeshCertificateRegistry;
88900
88335
  exports.setProcessMeshPeerTransportLookup = setProcessMeshPeerTransportLookup;
88901
88336
  exports.setProcessMeshTlsEnabler = setProcessMeshTlsEnabler;
88902
88337
  exports.setProcessMeshTlsListenerState = setProcessMeshTlsListenerState;