@serfab/cadre-host 0.11.0 → 0.13.0

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 (46) hide show
  1. package/README.md +406 -296
  2. package/dist/bin/host.d.ts +11 -7
  3. package/dist/bin/host.js +40 -12
  4. package/dist/bin/host.js.map +1 -1
  5. package/dist/installer/config.d.ts +4 -4
  6. package/dist/installer/config.js +5 -39
  7. package/dist/installer/config.js.map +1 -1
  8. package/dist/installer/identity.d.ts +8 -1
  9. package/dist/installer/identity.js +8 -1
  10. package/dist/installer/identity.js.map +1 -1
  11. package/dist/orchestrator/host-process-orchestrator.d.ts +2 -2
  12. package/dist/orchestrator/host-process-orchestrator.js +14 -4
  13. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  14. package/dist/server/routes/bootstrap-node-validation.d.ts +96 -0
  15. package/dist/server/routes/bootstrap-node-validation.js +178 -0
  16. package/dist/server/routes/bootstrap-node-validation.js.map +1 -0
  17. package/dist/server/routes/grants.js +8 -25
  18. package/dist/server/routes/grants.js.map +1 -1
  19. package/dist/server/routes/provision-request-validation.d.ts +45 -0
  20. package/dist/server/routes/provision-request-validation.js +97 -0
  21. package/dist/server/routes/provision-request-validation.js.map +1 -0
  22. package/dist/server/settings-store.d.ts +1 -1
  23. package/dist/server/settings-store.js +5 -1
  24. package/dist/server/settings-store.js.map +1 -1
  25. package/package.json +5 -4
  26. package/src/__tests__/cli.smoke.test.ts +8 -3
  27. package/src/__tests__/global-setup.ts +9 -4
  28. package/src/__tests__/orchestrator-node-identity.test.ts +204 -204
  29. package/src/__tests__/orchestrator.test.ts +951 -951
  30. package/src/bin/__tests__/cli-reference.test.ts +167 -0
  31. package/src/bin/host.ts +1326 -1299
  32. package/src/donation/__tests__/donation-service.test.ts +1068 -1068
  33. package/src/donation/__tests__/donation-supervisor.test.ts +510 -510
  34. package/src/donation/__tests__/fake-orchestrator.test.ts +168 -168
  35. package/src/installer/__tests__/config.test.ts +134 -112
  36. package/src/installer/config.ts +5 -43
  37. package/src/installer/identity.ts +8 -1
  38. package/src/nat/__tests__/nat-service.test.ts +515 -497
  39. package/src/orchestrator/host-process-orchestrator.ts +1143 -1133
  40. package/src/server/__tests__/bootstrap-node-validation.test.ts +134 -0
  41. package/src/server/__tests__/grants-route.test.ts +326 -263
  42. package/src/server/__tests__/settings-route.test.ts +8 -7
  43. package/src/server/routes/bootstrap-node-validation.ts +187 -0
  44. package/src/server/routes/grants.ts +9 -26
  45. package/src/server/routes/provision-request-validation.ts +105 -0
  46. package/src/server/settings-store.ts +41 -37
@@ -5,10 +5,10 @@
5
5
  * orchestrator) each own their own files under `<dataDir>/`; this is NOT
6
6
  * an umbrella config.
7
7
  *
8
- * Schema versions:
9
- * v1 — initial layout from 6.4.1.
10
- * v2 — adds `updates: { autoApply, manifestUrl? }` for the update-flow
11
- * (6.4.2). v1 files are silently upgraded on read with autoApply=false.
8
+ * Schema version: 2. `version` is a forward guard — a file whose version
9
+ * does not match `CURRENT_VERSION` is rejected on read rather than
10
+ * reinterpreted, so a future incompatible layout fails loudly instead of
11
+ * being silently misread.
12
12
  */
13
13
 
14
14
  import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
@@ -119,7 +119,7 @@ export function updateHostConfig(
119
119
  ...current,
120
120
  ...patch,
121
121
  updates: { ...current.updates, ...(patch.updates ?? {}) },
122
- version: 2,
122
+ version: CURRENT_VERSION,
123
123
  };
124
124
  writeHostConfig(filePath, next);
125
125
  return next;
@@ -137,12 +137,6 @@ export function readHostConfig(filePath: string): HostConfigFile {
137
137
  throw new Error(`host.config.json at ${filePath} is not a JSON object`);
138
138
  }
139
139
  const obj = parsed as Record<string, unknown>;
140
- if (obj.version === 1) {
141
- // Silent in-place upgrade. v1 lacks `updates`; default to notify-only.
142
- const upgraded = upgradeV1(obj, filePath);
143
- writeHostConfig(filePath, upgraded);
144
- return upgraded;
145
- }
146
140
  if (obj.version !== CURRENT_VERSION) {
147
141
  throw new Error(
148
142
  `host.config.json at ${filePath} has unsupported version=${obj.version} (this build expects ${CURRENT_VERSION})`,
@@ -154,38 +148,6 @@ export function readHostConfig(filePath: string): HostConfigFile {
154
148
  return obj;
155
149
  }
156
150
 
157
- /** v1 → v2 migration: stamp `updates: { autoApply: false }` and bump version. */
158
- function upgradeV1(obj: Record<string, unknown>, filePath: string): HostConfigFile {
159
- if (!isV1Shape(obj)) {
160
- throw new Error(`host.config.json at ${filePath} is missing required v1 fields`);
161
- }
162
- return {
163
- version: 2,
164
- installId: obj.installId as string,
165
- uiPort: obj.uiPort as number,
166
- libp2pPort: obj.libp2pPort as number,
167
- dataDir: obj.dataDir as string,
168
- identityPath: obj.identityPath as string,
169
- upnpEnabled: obj.upnpEnabled as boolean,
170
- installedAt: obj.installedAt as string,
171
- installerVersion: obj.installerVersion as string,
172
- updates: { autoApply: false },
173
- };
174
- }
175
-
176
- function isV1Shape(v: Record<string, unknown>): boolean {
177
- return (
178
- typeof v.installId === 'string' &&
179
- typeof v.uiPort === 'number' &&
180
- typeof v.libp2pPort === 'number' &&
181
- typeof v.dataDir === 'string' &&
182
- typeof v.identityPath === 'string' &&
183
- typeof v.upnpEnabled === 'boolean' &&
184
- typeof v.installedAt === 'string' &&
185
- typeof v.installerVersion === 'string'
186
- );
187
- }
188
-
189
151
  function isHostConfigShape(v: unknown): v is HostConfigFile {
190
152
  if (!v || typeof v !== 'object') return false;
191
153
  const o = v as Record<string, unknown>;
@@ -9,7 +9,14 @@
9
9
  * We persist the protobuf form (not raw bytes) because that's the format
10
10
  * libp2p's `privateKeyFromProtobuf` consumes directly and it preserves the
11
11
  * key type tag — future migrations to a different key algorithm don't
12
- * require a schema change here.
12
+ * require a schema change here. Raw bytes carry no type tag AND no way to tell
13
+ * a damaged file from a valid one: `privateKeyFromRaw` accepts any 64 bytes as
14
+ * an Ed25519 key without checking that the public half matches the private, so
15
+ * a truncated file would load as a *different* working identity.
16
+ *
17
+ * This is the repo-wide identity file format, not a cadre-host-local choice:
18
+ * `cadre enroll create` writes exactly these bytes, and `cadre-cli`'s
19
+ * `identity.keyFile` accepts nothing else (`config/loader.ts` → `loadIdentityKey`).
13
20
  */
14
21
 
15
22
  import { chmodSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';