@serfab/cadre-host 0.8.1 → 0.10.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 (198) hide show
  1. package/dist/auth/index.d.ts +2 -0
  2. package/dist/auth/index.js +1 -0
  3. package/dist/auth/index.js.map +1 -1
  4. package/dist/auth/self-label.d.ts +36 -0
  5. package/dist/auth/self-label.js +57 -0
  6. package/dist/auth/self-label.js.map +1 -0
  7. package/dist/auth/trust-circle.d.ts +36 -9
  8. package/dist/auth/trust-circle.js +40 -20
  9. package/dist/auth/trust-circle.js.map +1 -1
  10. package/dist/auth/types.d.ts +2 -2
  11. package/dist/bin/host.js +291 -54
  12. package/dist/bin/host.js.map +1 -1
  13. package/dist/donation/__tests__/fake-orchestrator.d.ts +103 -0
  14. package/dist/donation/__tests__/fake-orchestrator.js +180 -0
  15. package/dist/donation/__tests__/fake-orchestrator.js.map +1 -0
  16. package/dist/donation/donation-service.d.ts +361 -0
  17. package/dist/donation/donation-service.js +763 -0
  18. package/dist/donation/donation-service.js.map +1 -0
  19. package/dist/donation/donation-store.d.ts +49 -0
  20. package/dist/donation/donation-store.js +148 -0
  21. package/dist/donation/donation-store.js.map +1 -0
  22. package/dist/donation/donation-supervisor.d.ts +167 -0
  23. package/dist/donation/donation-supervisor.js +341 -0
  24. package/dist/donation/donation-supervisor.js.map +1 -0
  25. package/dist/donation/grant-service.d.ts +71 -0
  26. package/dist/donation/grant-service.js +163 -0
  27. package/dist/donation/grant-service.js.map +1 -0
  28. package/dist/donation/grant-store.d.ts +38 -0
  29. package/dist/donation/grant-store.js +135 -0
  30. package/dist/donation/grant-store.js.map +1 -0
  31. package/dist/donation/index.d.ts +20 -0
  32. package/dist/donation/index.js +17 -0
  33. package/dist/donation/index.js.map +1 -0
  34. package/dist/donation/types.d.ts +201 -0
  35. package/dist/donation/types.js +40 -0
  36. package/dist/donation/types.js.map +1 -0
  37. package/dist/index.d.ts +9 -5
  38. package/dist/index.js +7 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/installer/config.d.ts +26 -0
  41. package/dist/installer/config.js +13 -0
  42. package/dist/installer/config.js.map +1 -1
  43. package/dist/installer/index.d.ts +2 -0
  44. package/dist/installer/index.js +3 -0
  45. package/dist/installer/index.js.map +1 -1
  46. package/dist/installer/wizard.d.ts +4 -0
  47. package/dist/installer/wizard.js +5 -1
  48. package/dist/installer/wizard.js.map +1 -1
  49. package/dist/nat/nat-service.d.ts +5 -5
  50. package/dist/nat/nat-service.js +9 -9
  51. package/dist/nat/nat-service.js.map +1 -1
  52. package/dist/nat/types.d.ts +1 -1
  53. package/dist/orchestrator/host-process-orchestrator.d.ts +144 -32
  54. package/dist/orchestrator/host-process-orchestrator.js +397 -128
  55. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  56. package/dist/orchestrator/index.d.ts +3 -3
  57. package/dist/orchestrator/index.js +1 -1
  58. package/dist/orchestrator/index.js.map +1 -1
  59. package/dist/orchestrator/node-identity.d.ts +26 -0
  60. package/dist/orchestrator/node-identity.js +36 -0
  61. package/dist/orchestrator/node-identity.js.map +1 -0
  62. package/dist/orchestrator/port-allocator.d.ts +14 -0
  63. package/dist/orchestrator/port-allocator.js +45 -0
  64. package/dist/orchestrator/port-allocator.js.map +1 -1
  65. package/dist/orchestrator/state-store.d.ts +5 -5
  66. package/dist/orchestrator/state-store.js +2 -2
  67. package/dist/orchestrator/state-store.js.map +1 -1
  68. package/dist/orchestrator/types.d.ts +8 -8
  69. package/dist/owner/index.d.ts +11 -0
  70. package/dist/owner/index.js +11 -0
  71. package/dist/owner/index.js.map +1 -0
  72. package/dist/owner/owner-node-client.d.ts +110 -0
  73. package/dist/{authority/authority-node-client.js → owner/owner-node-client.js} +58 -17
  74. package/dist/owner/owner-node-client.js.map +1 -0
  75. package/dist/server/error-handler.d.ts +22 -1
  76. package/dist/server/error-handler.js +64 -1
  77. package/dist/server/error-handler.js.map +1 -1
  78. package/dist/server/events/types.d.ts +3 -0
  79. package/dist/server/index.d.ts +33 -2
  80. package/dist/server/index.js +43 -16
  81. package/dist/server/index.js.map +1 -1
  82. package/dist/server/routes/grants-admin.d.ts +17 -0
  83. package/dist/server/routes/grants-admin.js +32 -0
  84. package/dist/server/routes/grants-admin.js.map +1 -0
  85. package/dist/server/routes/grants.d.ts +28 -0
  86. package/dist/server/routes/grants.js +182 -0
  87. package/dist/server/routes/grants.js.map +1 -0
  88. package/dist/server/routes/nodes.d.ts +5 -4
  89. package/dist/server/routes/nodes.js +19 -18
  90. package/dist/server/routes/nodes.js.map +1 -1
  91. package/dist/server/routes/settings.d.ts +6 -1
  92. package/dist/server/routes/settings.js +5 -2
  93. package/dist/server/routes/settings.js.map +1 -1
  94. package/dist/server/routes/status.d.ts +8 -4
  95. package/dist/server/routes/status.js +9 -4
  96. package/dist/server/routes/status.js.map +1 -1
  97. package/dist/server/routes/strands.d.ts +20 -0
  98. package/dist/server/routes/strands.js +38 -0
  99. package/dist/server/routes/strands.js.map +1 -0
  100. package/dist/strands/index.d.ts +7 -0
  101. package/dist/strands/index.js +6 -0
  102. package/dist/strands/index.js.map +1 -0
  103. package/dist/strands/strand-service.d.ts +50 -0
  104. package/dist/strands/strand-service.js +103 -0
  105. package/dist/strands/strand-service.js.map +1 -0
  106. package/dist/strands/types.d.ts +93 -0
  107. package/dist/strands/types.js +23 -0
  108. package/dist/strands/types.js.map +1 -0
  109. package/dist/ui/assets/index-BVoqLjyX.css +1 -0
  110. package/dist/ui/assets/index-C-iks41M.js +17 -0
  111. package/dist/ui/assets/index-C-iks41M.js.map +1 -0
  112. package/dist/ui/index.html +2 -2
  113. package/dist/update/release-key.d.ts +1 -1
  114. package/dist/update/release-key.js +8 -6
  115. package/dist/update/release-key.js.map +1 -1
  116. package/package.json +5 -5
  117. package/src/__tests__/build-targets.test.ts +26 -0
  118. package/src/__tests__/global-setup.ts +51 -0
  119. package/src/__tests__/{host-authority.smoke.test.ts → host-owner.smoke.test.ts} +7 -7
  120. package/src/__tests__/orchestrator-env-scrub.test.ts +140 -0
  121. package/src/__tests__/orchestrator-node-identity.test.ts +204 -0
  122. package/src/__tests__/{orchestrator-authority.test.ts → orchestrator-owner.test.ts} +33 -33
  123. package/src/__tests__/orchestrator-pin-keys.test.ts +153 -0
  124. package/src/__tests__/orchestrator-push.test.ts +10 -10
  125. package/src/__tests__/orchestrator.test.ts +387 -6
  126. package/src/auth/__tests__/self-label.test.ts +85 -0
  127. package/src/auth/__tests__/trust-circle-integration.test.ts +152 -147
  128. package/src/auth/__tests__/trust-circle.test.ts +55 -11
  129. package/src/auth/index.ts +2 -0
  130. package/src/auth/self-label.ts +74 -0
  131. package/src/auth/trust-circle.ts +54 -22
  132. package/src/auth/types.ts +2 -2
  133. package/src/bin/host.ts +1299 -1038
  134. package/src/donation/__tests__/donation-service.test.ts +1068 -0
  135. package/src/donation/__tests__/donation-supervisor.test.ts +510 -0
  136. package/src/donation/__tests__/fake-orchestrator.test.ts +168 -0
  137. package/src/donation/__tests__/fake-orchestrator.ts +225 -0
  138. package/src/donation/__tests__/grant-service.test.ts +213 -0
  139. package/src/donation/__tests__/grant-store.test.ts +113 -0
  140. package/src/donation/donation-service.ts +962 -0
  141. package/src/donation/donation-store.ts +171 -0
  142. package/src/donation/donation-supervisor.ts +388 -0
  143. package/src/donation/grant-service.ts +200 -0
  144. package/src/donation/grant-store.ts +152 -0
  145. package/src/donation/index.ts +64 -0
  146. package/src/donation/types.ts +243 -0
  147. package/src/index.ts +51 -5
  148. package/src/installer/__tests__/config.test.ts +27 -1
  149. package/src/installer/__tests__/installer.smoke.test.ts +31 -1
  150. package/src/installer/__tests__/wizard.test.ts +5 -1
  151. package/src/installer/config.ts +34 -0
  152. package/src/installer/index.ts +5 -0
  153. package/src/installer/wizard.ts +12 -1
  154. package/src/nat/__tests__/nat-service.test.ts +5 -5
  155. package/src/nat/nat-service.ts +10 -10
  156. package/src/nat/types.ts +1 -1
  157. package/src/orchestrator/__tests__/node-identity.test.ts +62 -0
  158. package/src/orchestrator/host-process-orchestrator.ts +401 -134
  159. package/src/orchestrator/index.ts +3 -3
  160. package/src/orchestrator/node-identity.ts +40 -0
  161. package/src/orchestrator/port-allocator.ts +48 -0
  162. package/src/orchestrator/state-store.ts +7 -7
  163. package/src/orchestrator/types.ts +8 -8
  164. package/src/{authority/__tests__/authority-node-client.test.ts → owner/__tests__/owner-node-client.test.ts} +45 -17
  165. package/src/owner/index.ts +12 -0
  166. package/src/{authority/authority-node-client.ts → owner/owner-node-client.ts} +83 -23
  167. package/src/server/__tests__/error-handler.test.ts +22 -0
  168. package/src/server/__tests__/grants-admin-route.test.ts +73 -0
  169. package/src/server/__tests__/grants-route.test.ts +263 -0
  170. package/src/server/__tests__/nodes-route.test.ts +25 -25
  171. package/src/server/__tests__/server.smoke.test.ts +75 -0
  172. package/src/server/__tests__/settings-route.test.ts +17 -0
  173. package/src/server/__tests__/status-route.test.ts +21 -0
  174. package/src/server/__tests__/strands-route.test.ts +233 -0
  175. package/src/server/error-handler.ts +67 -1
  176. package/src/server/events/types.ts +1 -0
  177. package/src/server/index.ts +75 -17
  178. package/src/server/routes/grants-admin.ts +41 -0
  179. package/src/server/routes/grants.ts +210 -0
  180. package/src/server/routes/nodes.ts +19 -18
  181. package/src/server/routes/settings.ts +11 -3
  182. package/src/server/routes/status.ts +18 -8
  183. package/src/server/routes/strands.ts +54 -0
  184. package/src/strands/__tests__/strand-service.test.ts +165 -0
  185. package/src/strands/index.ts +14 -0
  186. package/src/strands/strand-service.ts +135 -0
  187. package/src/strands/types.ts +102 -0
  188. package/src/update/__tests__/release-key.test.ts +16 -3
  189. package/src/update/release-key.ts +8 -6
  190. package/dist/authority/authority-node-client.d.ts +0 -77
  191. package/dist/authority/authority-node-client.js.map +0 -1
  192. package/dist/authority/index.d.ts +0 -11
  193. package/dist/authority/index.js +0 -11
  194. package/dist/authority/index.js.map +0 -1
  195. package/dist/ui/assets/index-BlMXQPSw.js +0 -14
  196. package/dist/ui/assets/index-BlMXQPSw.js.map +0 -1
  197. package/dist/ui/assets/index-BwU5mJGF.css +0 -1
  198. package/src/authority/index.ts +0 -12
@@ -0,0 +1,135 @@
1
+ import debug from 'debug';
2
+
3
+ import { OwnerNodeUnavailableError } from '../owner/owner-node-client.js';
4
+
5
+ import type {
6
+ StrandHandlers,
7
+ StrandListSnapshot,
8
+ StrandRemovalResult,
9
+ } from './types.js';
10
+ import { StrandError } from './types.js';
11
+
12
+ const log = debug('cadre:host:strands');
13
+
14
+ /**
15
+ * Minimal slice of the owner node that StrandService uses. Declared here (rather
16
+ * than reaching into `OwnerNodeClient`) so unit tests can inject a fake without
17
+ * standing up an admin channel — the third such trimmed interface the client
18
+ * satisfies, alongside the trust-circle and NAT ones.
19
+ */
20
+ export interface CadreNodeLike {
21
+ listStrands(): Promise<StrandListSnapshot>;
22
+ removeStrand(strandId: string, opts: { confirm: boolean }): Promise<StrandRemovalResult>;
23
+ }
24
+
25
+ /** Constructor options. */
26
+ export interface StrandServiceOptions {
27
+ /** The owner node — provides listStrands / removeStrand over the admin channel. */
28
+ cadreNode: CadreNodeLike;
29
+ }
30
+
31
+ /**
32
+ * StrandService — validation and error translation over the owner node's strand
33
+ * admin routes.
34
+ *
35
+ * It owns no state and makes no policy. In particular it does NOT decide whether a
36
+ * closed strand needs confirmation: it never reads the row, so it could only guess.
37
+ * The node enforces that rule and answers `confirmation_required`; this layer
38
+ * forwards the caller's flag verbatim and surfaces the refusal as a distinct code
39
+ * so the UI can raise the right dialog.
40
+ */
41
+ export class StrandService {
42
+ private readonly cadreNode: CadreNodeLike;
43
+
44
+ constructor(opts: StrandServiceOptions) {
45
+ this.cadreNode = opts.cadreNode;
46
+ }
47
+
48
+ /** This party's strands, plus the node's current control-connection count. */
49
+ async list(): Promise<StrandListSnapshot> {
50
+ return await this.cadreNode.listStrands().catch((err: unknown) => toDomainError(err));
51
+ }
52
+
53
+ /**
54
+ * Remove this party's participation in one strand.
55
+ *
56
+ * `confirm` is forwarded exactly as given — never defaulted to true, never
57
+ * re-sent as true after a refusal. A closed strand's row carries this party's
58
+ * membership key for that network and is stored nowhere else, so an automatic
59
+ * retry would destroy it on the caller's behalf.
60
+ */
61
+ async remove(rawId: string, opts: { confirm: boolean }): Promise<StrandRemovalResult> {
62
+ const strandId = validateStrandId(rawId);
63
+ log('remove %s (confirm=%s)', strandId, opts.confirm);
64
+ return await this.cadreNode
65
+ .removeStrand(strandId, { confirm: opts.confirm })
66
+ .catch((err: unknown) => toDomainError(err));
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Trim and reject an id this surface cannot act on. Blank is the only such id.
72
+ *
73
+ * A `/` is deliberately NOT refused. `/api/strands/:id` is one path segment, but a
74
+ * caller that percent-encodes the id reaches this layer with the `/` restored
75
+ * (Fastify decodes `params`), `OwnerNodeClient` re-encodes it, and the admin channel
76
+ * splits on the still-encoded `%2F` and decodes it back — so the whole chain carries
77
+ * it. Refusing here would break the only form that works, while doing nothing about
78
+ * an UNencoded `/`, which never reaches this handler at all (the router 404s it).
79
+ */
80
+ function validateStrandId(rawId: string): string {
81
+ const strandId = typeof rawId === 'string' ? rawId.trim() : '';
82
+ if (!strandId) {
83
+ throw new StrandError('invalid_id', 'A strand id is required');
84
+ }
85
+ return strandId;
86
+ }
87
+
88
+ /**
89
+ * Translate an owner-node failure into the strand error vocabulary.
90
+ *
91
+ * `OwnerNodeUnavailableError` is thrown for *every* non-ok admin response, not only
92
+ * for a node that is down — so read `nodeCode` first and fall back to
93
+ * `node_unavailable` only when nothing better fits. Reporting a 428 as "your node is
94
+ * down" would be actively misleading.
95
+ *
96
+ * Declared to return `never` so callers can `.catch((err) => toDomainError(err))`.
97
+ *
98
+ * NOTE: the trust-circle and NAT services translate the SAME error blanket-style —
99
+ * every `OwnerNodeUnavailableError` becomes `node_unavailable` — because neither has
100
+ * a code worth distinguishing yet. If a second surface ever needs a code-aware
101
+ * mapping, hoist this switch into a shared owner-error translator instead of growing
102
+ * a third copy.
103
+ */
104
+ function toDomainError(err: unknown): never {
105
+ if (!(err instanceof OwnerNodeUnavailableError)) {
106
+ throw err instanceof Error ? err : new Error(String(err));
107
+ }
108
+ switch (err.nodeCode) {
109
+ case 'confirmation_required':
110
+ throw new StrandError('confirmation_required', err.message);
111
+ case 'bad_request':
112
+ throw new StrandError('invalid_id', err.message);
113
+ case undefined:
114
+ case 'not_ready':
115
+ case 'not_authorized':
116
+ throw new StrandError('node_unavailable', `Owner node unavailable: ${err.message}`);
117
+ default:
118
+ throw new StrandError('internal', err.message);
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Wrap a StrandService into the typed handler shape the local UI server mounts.
124
+ * Errors propagate as StrandError; `server/error-handler.ts` maps `.code` → status.
125
+ */
126
+ export function createStrandHandlers(service: StrandService): StrandHandlers {
127
+ return {
128
+ async listStrands() {
129
+ return await service.list();
130
+ },
131
+ async removeStrand(strandId, opts) {
132
+ return await service.remove(strandId, { confirm: opts.confirm === true });
133
+ },
134
+ };
135
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Strand-management types for cadre-host.
3
+ *
4
+ * A *strand* is a shared data network this party participates in. Membership is
5
+ * canonical in the cadre control network's `Strand` table, reached over the owner
6
+ * node's loopback admin channel (`GET /admin/strands`,
7
+ * `DELETE /admin/strands/:id?confirm=1`).
8
+ *
9
+ * Unlike the trust circle — which layers host-local labels and pending invites on
10
+ * top of the node's state — this layer holds **no host-local state at all**. There
11
+ * is no `strands.json`. It exists for id validation, for translating the admin
12
+ * channel's error codes into a stable vocabulary the management API can map to HTTP
13
+ * statuses, and for nothing else. Keep it small.
14
+ */
15
+
16
+ /** One strand this party belongs to, as projected by the admin channel. */
17
+ export interface StrandSummary {
18
+ /** The `Strand` row id — what a removal takes. */
19
+ id: string;
20
+ /** `'o'` = open, `'c'` = closed (the row carries this party's membership key). */
21
+ type: 'o' | 'c';
22
+ /** Whether the owner node currently has a running instance for the id. */
23
+ running: boolean;
24
+ /**
25
+ * The instance's status when running, else `null`. Deliberately `string` rather
26
+ * than cadre-core's `StrandStatus`: this is a wire projection the manager only
27
+ * forwards, and widening it keeps cadre-host from tracking a cadre-core union it
28
+ * never inspects.
29
+ */
30
+ status: string | null;
31
+ }
32
+
33
+ /** The result of listing this party's strands. */
34
+ export interface StrandListSnapshot {
35
+ strands: StrandSummary[];
36
+ /**
37
+ * Open control-network connections on the owner node; 0 ⇒ writes commit
38
+ * local-only. A snapshot at read time, not a subscription — treat it as advisory.
39
+ */
40
+ controlConnections: number;
41
+ }
42
+
43
+ /** The result of removing this party's participation in one strand. */
44
+ export interface StrandRemovalResult {
45
+ /** The trimmed id the call was about. */
46
+ strandId: string;
47
+ /** Whether a row existed before the write. */
48
+ published: boolean;
49
+ /** The found row's type; `null` when no row was found. */
50
+ type: 'o' | 'c' | null;
51
+ /**
52
+ * Whether THIS call issued the delete — not that the row was observed to vanish.
53
+ * The node's read and write are not atomic, so a concurrent removal landing in
54
+ * between makes this a no-op that still reports `true`.
55
+ */
56
+ removed: boolean;
57
+ /**
58
+ * The node saw 0 control connections at the end of the call. Sampled on EVERY
59
+ * call, including one that found no row and wrote nothing — read it as "this
60
+ * machine currently sees no siblings", and only as "your delete may not have
61
+ * travelled" when `removed` is also true.
62
+ */
63
+ alone: boolean;
64
+ }
65
+
66
+ /** Error codes thrown by StrandService. */
67
+ export type StrandErrorCode =
68
+ /** The id was blank or whitespace-only, here or at the node. */
69
+ | 'invalid_id'
70
+ /** The node refused a closed-strand removal that carried no confirmation. */
71
+ | 'confirmation_required'
72
+ /** The owner node's admin channel is unreachable / not ready. */
73
+ | 'node_unavailable'
74
+ /** The node answered with a code this layer has no better word for. */
75
+ | 'internal';
76
+
77
+ /** Typed error carrying a stable `code` for HTTP mapping. */
78
+ export class StrandError extends Error {
79
+ readonly code: StrandErrorCode;
80
+
81
+ constructor(code: StrandErrorCode, message: string) {
82
+ super(message);
83
+ this.name = 'StrandError';
84
+ this.code = code;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Typed handlers exposed to the local UI server for Fastify wiring.
90
+ *
91
+ * Handlers either return typed results or throw a `StrandError` whose `.code`
92
+ * `server/error-handler.ts` maps to an HTTP status:
93
+ *
94
+ * - `invalid_id` → 400
95
+ * - `confirmation_required` → 428
96
+ * - `node_unavailable` → 503
97
+ * - `internal` → 500
98
+ */
99
+ export interface StrandHandlers {
100
+ listStrands(): Promise<StrandListSnapshot>;
101
+ removeStrand(strandId: string, opts: { confirm: boolean }): Promise<StrandRemovalResult>;
102
+ }
@@ -12,9 +12,14 @@ function freshPublicRawB64(): string {
12
12
  describe('isPlaceholderReleaseKey', () => {
13
13
  afterEach(() => { delete process.env.CADRE_HOST_UPDATE_DEV_KEY; });
14
14
 
15
- it('is true for the default all-zeros placeholder (no override)', () => {
15
+ it('is true for an explicit all-zeros placeholder key', () => {
16
+ const allZeros = Buffer.alloc(32).toString('base64');
17
+ expect(isPlaceholderReleaseKey({ CADRE_HOST_UPDATE_DEV_KEY: allZeros })).toBe(true);
18
+ });
19
+
20
+ it('is false for the shipped embedded default (real key, no override)', () => {
16
21
  delete process.env.CADRE_HOST_UPDATE_DEV_KEY;
17
- expect(isPlaceholderReleaseKey()).toBe(true);
22
+ expect(isPlaceholderReleaseKey()).toBe(false);
18
23
  });
19
24
 
20
25
  it('is false when a real key overrides via CADRE_HOST_UPDATE_DEV_KEY', () => {
@@ -24,6 +29,14 @@ describe('isPlaceholderReleaseKey', () => {
24
29
 
25
30
  it('honors an explicit env argument over process.env', () => {
26
31
  expect(isPlaceholderReleaseKey({ CADRE_HOST_UPDATE_DEV_KEY: freshPublicRawB64() })).toBe(false);
27
- expect(isPlaceholderReleaseKey({})).toBe(true);
32
+ // no override in the explicit arg -> falls through to the real embedded default
33
+ expect(isPlaceholderReleaseKey({})).toBe(false);
34
+ });
35
+
36
+ it('is false for a key that does not decode to 32 bytes', () => {
37
+ // Not the all-zeros placeholder even though it is a degenerate key: the
38
+ // 32-byte length gate short-circuits before the all-zeros check.
39
+ const shortZeros = Buffer.alloc(16).toString('base64');
40
+ expect(isPlaceholderReleaseKey({ CADRE_HOST_UPDATE_DEV_KEY: shortZeros })).toBe(false);
28
41
  });
29
42
  });
@@ -12,11 +12,13 @@ import type { KeyObject } from 'node:crypto';
12
12
  import { createPublicKey } from 'node:crypto';
13
13
 
14
14
  /**
15
- * Raw 32-byte Ed25519 public key, base64-encoded. The all-zeros value below is
16
- * the placeholder that ships in source until the release operator embeds a real
17
- * key (`isPlaceholderReleaseKey` reports it; the publish guard refuses to ship
18
- * it). Mismatch with the real signer surfaces as `signature_invalid`, which the
19
- * UI treats as "update available but unverifiable" rather than auto-applying.
15
+ * Raw 32-byte Ed25519 public key, base64-encoded. This is the real production
16
+ * public key embedded by the release operator (see the "Release signing"
17
+ * runbook in `docs/cadre-host.md`). Before a real key was embedded the source
18
+ * shipped an all-zeros placeholder; `isPlaceholderReleaseKey` still detects that
19
+ * state and the publish guard refuses to ship it. Mismatch with the real signer
20
+ * surfaces as `signature_invalid`, which the UI treats as "update available but
21
+ * unverifiable" rather than auto-applying.
20
22
  */
21
23
  const PROD_KEY_BASE64 = 'XyRVnOY9DVgU6xdMgJIguOsc9B2L1o2KoU9626Nk+OE=';
22
24
 
@@ -41,7 +43,7 @@ export function getReleasePublicKey(env: NodeJS.ProcessEnv = process.env): KeyOb
41
43
  * ships in source until the release operator embeds a real public key.
42
44
  *
43
45
  * Consumers:
44
- * - the publish guard (`scripts/publish-package.js`) refuses to ship a build
46
+ * - the publish guard (`scripts/publish-package.mjs`) refuses to ship a build
45
47
  * whose embedded key is still the placeholder, so a real release can never
46
48
  * silently ship the dead key;
47
49
  * - `UpdateService.check()` logs a diagnostic breadcrumb so a misbuilt binary
@@ -1,77 +0,0 @@
1
- /**
2
- * HTTP client for the authority node's loopback admin channel (the 6.6
3
- * `cadre-node-admin-channel` contract).
4
- *
5
- * cadre-host's manager process holds no in-process `CadreNode`; it spawns the
6
- * admin's authority node as a managed child (see `HostProcessOrchestrator`)
7
- * and delegates all authority/membership/identity operations to it over this
8
- * client. The client implements **both** trimmed `CadreNodeLike` interfaces —
9
- * the trust-circle one (`auth/trust-circle.ts`) and the NAT one
10
- * (`nat/nat-service.ts`) — plus `pushInviteAddresses`.
11
- *
12
- * Transport: `Authorization: Bearer <token>` against
13
- * `http://127.0.0.1:<adminPort>`. Every response uses the cadre-provider
14
- * envelope `{ ok: true, data }` / `{ ok: false, error: { code, message } }`.
15
- * A refused connection, a transport error, or any non-2xx response surfaces
16
- * as {@link AuthorityNodeUnavailableError}; the trust-circle / NAT services
17
- * translate that into a `node_unavailable` domain error so the management API
18
- * returns a clear 503 rather than a raw 500.
19
- */
20
- import type { CadreInvite } from '@serfab/cadre-core';
21
- import type { AuthorityAdminEndpoint } from '../orchestrator/index.js';
22
- import type { CadreNodeLike as TrustCircleCadreNodeLike } from '../auth/trust-circle.js';
23
- import type { CadreNodeLike as NatCadreNodeLike } from '../nat/nat-service.js';
24
- /**
25
- * Raised when the authority node's admin channel can't be reached or returns
26
- * a non-success response. Carries the node's stable error `code` when one was
27
- * present in the envelope (e.g. `not_ready`, `not_authorized`).
28
- */
29
- export declare class AuthorityNodeUnavailableError extends Error {
30
- /** The admin-channel error code, when the node answered with an envelope. */
31
- readonly nodeCode?: string;
32
- constructor(message: string, nodeCode?: string);
33
- }
34
- /** Endpoint provided directly or via a getter (so it tracks re-spawns). */
35
- type EndpointSource = AuthorityAdminEndpoint | (() => AuthorityAdminEndpoint | undefined) | undefined;
36
- export interface AuthorityNodeClientOptions {
37
- /** Fetch override for tests. Defaults to the global `fetch`. */
38
- fetch?: typeof fetch;
39
- }
40
- export declare class AuthorityNodeClient implements TrustCircleCadreNodeLike, NatCadreNodeLike {
41
- private readonly endpointSource;
42
- private readonly fetchImpl;
43
- /**
44
- * @param endpoint Either a fixed `{ baseUrl, token }` or a getter returning
45
- * the current endpoint (pass `orchestrator.getAuthorityAdminEndpoint`
46
- * bound, so a restart's new bearer token is picked up automatically).
47
- */
48
- constructor(endpoint: EndpointSource, opts?: AuthorityNodeClientOptions);
49
- createInvite(token?: string, expiresInMs?: number): Promise<{
50
- invite: CadreInvite;
51
- encodedInvite: string;
52
- }>;
53
- acceptPhone(options: {
54
- phonePeerId: string;
55
- token?: string;
56
- }, issuedInvite?: CadreInvite): Promise<void>;
57
- removePeer(peerId: string): Promise<void>;
58
- /**
59
- * Encode an invite for out-of-band delivery. The admin contract has no
60
- * encode route (the mint route already returns `encodedInvite`), so this
61
- * mirrors cadre-core's encoding (`base64url(JSON.stringify(invite))`).
62
- */
63
- encodeInvite(invite: CadreInvite): string;
64
- listMembers(): Promise<Array<{
65
- peerId: string;
66
- multiaddr: string | null;
67
- }>>;
68
- isMember(peerId: string): Promise<boolean>;
69
- getPeerId(): Promise<string>;
70
- getMultiaddrs(): Promise<string[]>;
71
- /** Push the NAT-resolved addresses the node should embed in future invites. */
72
- pushInviteAddresses(addresses: string[]): Promise<void>;
73
- private resolveEndpoint;
74
- private request;
75
- private parseEnvelope;
76
- }
77
- export {};
@@ -1 +0,0 @@
1
- {"version":3,"file":"authority-node-client.js","sourceRoot":"","sources":["../../src/authority/authority-node-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,MAAM,GAAG,GAAG,KAAK,CAAC,6BAA6B,CAAC,CAAC;AAEjD;;;;GAIG;AACH,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAItD,YAAY,OAAe,EAAE,QAAiB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;QAC5C,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACvD,CAAC;CACF;AAaD,MAAM,OAAO,mBAAmB;IAI9B;;;;OAIG;IACH,YAAY,QAAwB,EAAE,OAAmC,EAAE;QACzE,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAA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I,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,QAAQ,CAAC,IAAS,CAAC;IAC5B,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,GAAa;QAKvC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACzC,OAAO,MAAuF,CAAC;YACjG,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,uEAAuE;YACvE,oCAAoC;QACtC,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Authority-node delegation surface for cadre-host.
3
- *
4
- * The manager process spawns the admin's authority cadre node (via
5
- * `HostProcessOrchestrator`) and delegates authority/membership/identity
6
- * operations to it over the loopback admin channel using
7
- * {@link AuthorityNodeClient}. See `docs/cadre-host.md` § Control-plane
8
- * separation.
9
- */
10
- export { AuthorityNodeClient, AuthorityNodeUnavailableError } from './authority-node-client.js';
11
- export type { AuthorityNodeClientOptions } from './authority-node-client.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Authority-node delegation surface for cadre-host.
3
- *
4
- * The manager process spawns the admin's authority cadre node (via
5
- * `HostProcessOrchestrator`) and delegates authority/membership/identity
6
- * operations to it over the loopback admin channel using
7
- * {@link AuthorityNodeClient}. See `docs/cadre-host.md` § Control-plane
8
- * separation.
9
- */
10
- export { AuthorityNodeClient, AuthorityNodeUnavailableError } from './authority-node-client.js';
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authority/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC"}