@serfab/cadre-core 0.9.0 → 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 (162) hide show
  1. package/README.md +4 -2
  2. package/dist/bootstrap-peer-store-file.d.ts +13 -0
  3. package/dist/bootstrap-peer-store-file.js +42 -0
  4. package/dist/bootstrap-peer-store-file.js.map +1 -0
  5. package/dist/bootstrap-peer-store.d.ts +73 -0
  6. package/dist/bootstrap-peer-store.js +128 -0
  7. package/dist/bootstrap-peer-store.js.map +1 -0
  8. package/dist/cadre-node.d.ts +918 -53
  9. package/dist/cadre-node.js +1843 -190
  10. package/dist/cadre-node.js.map +1 -1
  11. package/dist/control-authorization.d.ts +93 -0
  12. package/dist/control-authorization.js +57 -0
  13. package/dist/control-authorization.js.map +1 -0
  14. package/dist/control-database.d.ts +990 -50
  15. package/dist/control-database.js +1459 -108
  16. package/dist/control-database.js.map +1 -1
  17. package/dist/control-formation-recorder.d.ts +89 -10
  18. package/dist/control-formation-recorder.js +129 -14
  19. package/dist/control-formation-recorder.js.map +1 -1
  20. package/dist/control-schema.d.ts +1 -1
  21. package/dist/control-schema.js +774 -210
  22. package/dist/control-schema.js.map +1 -1
  23. package/dist/control-stream.d.ts +38 -4
  24. package/dist/control-stream.js +70 -4
  25. package/dist/control-stream.js.map +1 -1
  26. package/dist/control-write-retry.d.ts +151 -0
  27. package/dist/control-write-retry.js +411 -0
  28. package/dist/control-write-retry.js.map +1 -0
  29. package/dist/delegate-admission.d.ts +134 -0
  30. package/dist/delegate-admission.js +244 -0
  31. package/dist/delegate-admission.js.map +1 -0
  32. package/dist/device-token.d.ts +11 -11
  33. package/dist/device-token.js +14 -13
  34. package/dist/device-token.js.map +1 -1
  35. package/dist/ed25519-key.d.ts +26 -0
  36. package/dist/ed25519-key.js +56 -1
  37. package/dist/ed25519-key.js.map +1 -1
  38. package/dist/file-durable-slot.d.ts +20 -0
  39. package/dist/file-durable-slot.js +53 -0
  40. package/dist/file-durable-slot.js.map +1 -0
  41. package/dist/formation-approval.d.ts +157 -0
  42. package/dist/formation-approval.js +375 -0
  43. package/dist/formation-approval.js.map +1 -0
  44. package/dist/fs-atomic.d.ts +38 -0
  45. package/dist/fs-atomic.js +97 -0
  46. package/dist/fs-atomic.js.map +1 -0
  47. package/dist/identity-key.d.ts +49 -0
  48. package/dist/identity-key.js +81 -0
  49. package/dist/identity-key.js.map +1 -0
  50. package/dist/index.d.ts +16 -6
  51. package/dist/index.js +39 -5
  52. package/dist/index.js.map +1 -1
  53. package/dist/key-store-file.d.ts +2 -24
  54. package/dist/key-store-file.js +10 -77
  55. package/dist/key-store-file.js.map +1 -1
  56. package/dist/membership-connection-gater.d.ts +146 -0
  57. package/dist/membership-connection-gater.js +180 -0
  58. package/dist/membership-connection-gater.js.map +1 -0
  59. package/dist/node-local-snapshot.d.ts +109 -0
  60. package/dist/node-local-snapshot.js +182 -0
  61. package/dist/node-local-snapshot.js.map +1 -0
  62. package/dist/peer-authorization.d.ts +135 -18
  63. package/dist/peer-authorization.js +152 -21
  64. package/dist/peer-authorization.js.map +1 -1
  65. package/dist/peer-record.d.ts +21 -8
  66. package/dist/peer-record.js +26 -10
  67. package/dist/peer-record.js.map +1 -1
  68. package/dist/relay-addrs.d.ts +45 -0
  69. package/dist/relay-addrs.js +103 -0
  70. package/dist/relay-addrs.js.map +1 -0
  71. package/dist/relay-reservation.d.ts +266 -0
  72. package/dist/relay-reservation.js +613 -0
  73. package/dist/relay-reservation.js.map +1 -0
  74. package/dist/seed-bootstrap.d.ts +221 -56
  75. package/dist/seed-bootstrap.js +328 -188
  76. package/dist/seed-bootstrap.js.map +1 -1
  77. package/dist/seed-trust-policy.d.ts +47 -21
  78. package/dist/seed-trust-policy.js +24 -15
  79. package/dist/seed-trust-policy.js.map +1 -1
  80. package/dist/strand-addr-protocol.d.ts +42 -13
  81. package/dist/strand-addr-protocol.js +58 -52
  82. package/dist/strand-addr-protocol.js.map +1 -1
  83. package/dist/strand-backfill.d.ts +109 -0
  84. package/dist/strand-backfill.js +279 -0
  85. package/dist/strand-backfill.js.map +1 -0
  86. package/dist/strand-formation-manager.d.ts +38 -9
  87. package/dist/strand-formation-manager.js +120 -17
  88. package/dist/strand-formation-manager.js.map +1 -1
  89. package/dist/strand-formation-protocol.d.ts +103 -4
  90. package/dist/strand-formation-protocol.js +232 -4
  91. package/dist/strand-formation-protocol.js.map +1 -1
  92. package/dist/strand-instance-manager.d.ts +39 -1
  93. package/dist/strand-instance-manager.js +92 -14
  94. package/dist/strand-instance-manager.js.map +1 -1
  95. package/dist/strand-member-registry.d.ts +5 -5
  96. package/dist/strand-member-registry.js +18 -10
  97. package/dist/strand-member-registry.js.map +1 -1
  98. package/dist/strand-membership-writer.d.ts +482 -88
  99. package/dist/strand-membership-writer.js +757 -136
  100. package/dist/strand-membership-writer.js.map +1 -1
  101. package/dist/strand-solicitation.d.ts +99 -33
  102. package/dist/strand-solicitation.js +100 -52
  103. package/dist/strand-solicitation.js.map +1 -1
  104. package/dist/strand-transport-key.d.ts +40 -0
  105. package/dist/strand-transport-key.js +56 -0
  106. package/dist/strand-transport-key.js.map +1 -0
  107. package/dist/strand-wake-protocol.d.ts +9 -7
  108. package/dist/strand-wake-protocol.js +22 -46
  109. package/dist/strand-wake-protocol.js.map +1 -1
  110. package/dist/strand-watcher.d.ts +17 -2
  111. package/dist/strand-watcher.js +47 -3
  112. package/dist/strand-watcher.js.map +1 -1
  113. package/dist/trusted-owner-store-file.d.ts +12 -0
  114. package/dist/trusted-owner-store-file.js +39 -0
  115. package/dist/trusted-owner-store-file.js.map +1 -0
  116. package/dist/trusted-owner-store.d.ts +64 -0
  117. package/dist/trusted-owner-store.js +126 -0
  118. package/dist/trusted-owner-store.js.map +1 -0
  119. package/dist/types.d.ts +275 -20
  120. package/dist/types.js +13 -0
  121. package/dist/types.js.map +1 -1
  122. package/package.json +19 -8
  123. package/src/bootstrap-peer-store-file.ts +44 -0
  124. package/src/bootstrap-peer-store.ts +172 -0
  125. package/src/cadre-node.ts +1992 -202
  126. package/src/control-authorization.ts +114 -0
  127. package/src/control-database.ts +1704 -146
  128. package/src/control-formation-recorder.ts +172 -19
  129. package/src/control-schema.ts +786 -222
  130. package/src/control-stream.ts +81 -4
  131. package/src/control-write-retry.ts +473 -0
  132. package/src/delegate-admission.ts +302 -0
  133. package/src/device-token.ts +18 -13
  134. package/src/ed25519-key.ts +134 -69
  135. package/src/file-durable-slot.ts +61 -0
  136. package/src/formation-approval.ts +604 -0
  137. package/src/fs-atomic.ts +107 -0
  138. package/src/identity-key.ts +109 -0
  139. package/src/index.ts +136 -5
  140. package/src/key-store-file.ts +10 -81
  141. package/src/membership-connection-gater.ts +204 -0
  142. package/src/node-local-snapshot.ts +260 -0
  143. package/src/peer-authorization.ts +199 -21
  144. package/src/peer-record.ts +28 -10
  145. package/src/relay-addrs.ts +111 -0
  146. package/src/relay-reservation.ts +823 -0
  147. package/src/seed-bootstrap.ts +397 -197
  148. package/src/seed-trust-policy.ts +58 -25
  149. package/src/strand-addr-protocol.ts +84 -53
  150. package/src/strand-backfill.ts +366 -0
  151. package/src/strand-formation-manager.ts +145 -19
  152. package/src/strand-formation-protocol.ts +309 -8
  153. package/src/strand-instance-manager.ts +111 -14
  154. package/src/strand-member-registry.ts +18 -13
  155. package/src/strand-membership-writer.ts +1430 -640
  156. package/src/strand-solicitation.ts +155 -90
  157. package/src/strand-transport-key.ts +58 -0
  158. package/src/strand-wake-protocol.ts +29 -46
  159. package/src/strand-watcher.ts +66 -3
  160. package/src/trusted-owner-store-file.ts +41 -0
  161. package/src/trusted-owner-store.ts +171 -0
  162. package/src/types.ts +292 -21
package/dist/types.d.ts CHANGED
@@ -1,16 +1,28 @@
1
1
  import type { ConnectionGater, Libp2p, PeerId, PrivateKey } from '@libp2p/interface';
2
2
  import type { IRawStorage, Libp2pTransports } from '@optimystic/db-p2p';
3
- import type { IRepo } from '@optimystic/db-core';
3
+ import type { IPeerNetwork, IRepo } from '@optimystic/db-core';
4
+ import type { StrandBackfillConfig } from './strand-backfill.js';
4
5
  import type { StrandDatabase } from './strand-database.js';
5
6
  import type { SeedTrustPolicy } from './seed-trust-policy.js';
6
7
  import type { KeyStore, KeyId } from './key-store.js';
8
+ import type { TrustedOwnerStore, TrustSource } from './trusted-owner-store.js';
9
+ import type { BootstrapPeerStore } from './bootstrap-peer-store.js';
7
10
  import type { PushNotifier } from './push-notifier.js';
11
+ import type { RevocableTable } from './control-authorization.js';
8
12
  /**
9
13
  * Extended Libp2p node with the coordinatedRepo attached by db-p2p's
10
14
  * createLibp2pNode after node creation (not surfaced on the base Libp2p type).
11
15
  */
12
16
  export interface Libp2pNodeWithRepo extends Libp2p {
13
17
  coordinatedRepo: IRepo;
18
+ /**
19
+ * The node's key-addressed peer network, attached by db-p2p's factory alongside
20
+ * `coordinatedRepo` (`libp2p-node-base.ts`). Optional deliberately: the base
21
+ * factory always assigns it, but it is not part of the upstream node type, so
22
+ * declaring it required would be a claim this repo cannot enforce. The strand
23
+ * backfill (`strand-backfill.ts`) logs once and stays inert when it is absent.
24
+ */
25
+ keyNetwork?: IPeerNetwork;
14
26
  }
15
27
  /**
16
28
  * Node profile determines storage participation
@@ -89,8 +101,9 @@ export interface StorageConfig {
89
101
  *
90
102
  * For React Native, use the appropriate storage from @optimystic/db-p2p-storage-rn:
91
103
  * ```typescript
92
- * import { RNRawStorage } from '@optimystic/db-p2p-storage-rn';
93
- * storage: { provider: (strandId) => new RNRawStorage(strandId) }
104
+ * import { LevelDBRawStorage } from '@optimystic/db-p2p-storage-rn';
105
+ * // `db` is an open LevelDB handle (see `openOptimysticRNDb` over `rn-leveldb`)
106
+ * storage: { provider: (strandId) => new LevelDBRawStorage(openDb(`sereus-${strandId}`)) }
94
107
  * ```
95
108
  *
96
109
  * For in-memory storage (testing):
@@ -107,7 +120,47 @@ export interface StorageConfig {
107
120
  */
108
121
  export interface NetworkConfig {
109
122
  listenAddrs?: string[];
123
+ /**
124
+ * Addresses to advertise to peers instead of `listenAddrs` — for a node behind
125
+ * NAT or a reverse proxy that is reachable at a different address than it binds
126
+ * (e.g. `mynode.example.com:4001` in front of a `0.0.0.0:4001` listener).
127
+ *
128
+ * Accepted (settable in `cadre.yaml`, via `CADRE_ANNOUNCE_ADDRS`, and through the
129
+ * Docker entrypoint) but **not yet applied**: libp2p only takes announce addresses
130
+ * at construction (`addresses.announce` / `addresses.appendAnnounce`), and
131
+ * `@optimystic/db-p2p`'s `NodeOptions` has no field for either — there is nothing
132
+ * in this repo to wire this into. `CadreNode.start()` warns when this is set,
133
+ * rather than pretending it works. Unblocked by the `announce-addrs-option`
134
+ * request filed against `@optimystic/db-p2p`; wiring lands here once this repo's
135
+ * dependency range moves to a version carrying it.
136
+ *
137
+ * Use {@link relayAddrs} for reachability behind NAT today (a reserved relay slot
138
+ * gives the node a real dialable circuit address), or `inviteAddressResolver` to
139
+ * substitute a reachable address into invite payloads specifically — neither
140
+ * changes what this node advertises on the wire, but both cover the operator need
141
+ * this field cannot yet.
142
+ */
110
143
  announceAddrs?: string[];
144
+ /**
145
+ * Circuit-relay servers this node reserves a slot on, so peers can reach it
146
+ * from behind NAT. Each entry is the relay's DIRECT dial multiaddr ending in
147
+ * its peerId — `/dns4/relay.example.com/tcp/4001/p2p/12D3KooW…` — with no
148
+ * `/p2p-circuit` suffix (one is appended for you; an entry that already has
149
+ * one is passed through unchanged).
150
+ *
151
+ * This is sugar for a circuit entry in {@link listenAddrs}: `relay-addrs.ts`
152
+ * resolves the two into one listen list, and listening on a relay's circuit
153
+ * addr is what makes libp2p dial it and hold the reservation. A relay named
154
+ * here therefore also becomes a delegate-announce target, so this node's
155
+ * strand nodes may reserve on it too (see `delegate-admission.ts`).
156
+ *
157
+ * Setting this gives the node a listener even when `listenAddrs` is `[]` —
158
+ * that is the point of naming a relay, but note that React Native hosts
159
+ * (`reference-app-rn`'s `cadre-phone.ts`) deliberately do NOT listen, and
160
+ * must not acquire a listener by accident.
161
+ *
162
+ * A malformed entry throws at node start rather than being silently dropped.
163
+ */
111
164
  relayAddrs?: string[];
112
165
  /**
113
166
  * Enable circuit relay server - allows this node to relay connections for other peers.
@@ -147,6 +200,12 @@ export interface NetworkConfig {
147
200
  * Playwright e2e, RN simulators) supply a permissive gater here — e.g.
148
201
  * `{ denyDialMultiaddr: () => false }`. See `@optimystic/db-p2p`'s
149
202
  * `libp2p-node-base` for the underlying option.
203
+ *
204
+ * On the CONTROL node this gater is composed with the built-in membership
205
+ * admission gate (`membership-connection-gater.ts`): every hook supplied here
206
+ * is honored unchanged, and on inbound encrypted connections a deny from
207
+ * either this gater or the membership policy denies. Strand cohort nodes
208
+ * receive this gater as-is (their peers are legitimately cross-party).
150
209
  */
151
210
  connectionGater?: ConnectionGater;
152
211
  /**
@@ -201,6 +260,19 @@ export interface ControlNetworkConfig {
201
260
  /** Optional path to the control schema file (defaults to bundled schema) */
202
261
  schemaPath?: string;
203
262
  }
263
+ /**
264
+ * Replication-breadth constants, both networks' cluster policies, and the strand
265
+ * resolver, re-exported so cadre embedders, the SQL plugin and the integration
266
+ * harness share one definition. Defined in `@serfab/quereus-plugin-sereus`
267
+ * because that package also creates libp2p nodes and cannot depend on this one.
268
+ * The control network's breadth is fixed ({@link CONTROL_REPLICATION_BREADTH},
269
+ * not configurable) and so is its consensus policy ({@link CONTROL_CLUSTER_POLICY}
270
+ * — notably the super-majority threshold, which it leaves at Optimystic's default
271
+ * by omission); the strand breadth defaults to
272
+ * {@link CadreNodeConfig.strandClusterSize} while its policy is the fixed
273
+ * {@link STRAND_CLUSTER_POLICY}.
274
+ */
275
+ export { MIN_CLUSTER_SIZE, CONTROL_REPLICATION_BREADTH, CONTROL_CLUSTER_POLICY, DEFAULT_STRAND_CLUSTER_SIZE, STRAND_CLUSTER_POLICY, resolveStrandClusterSize } from '@serfab/quereus-plugin-sereus';
204
276
  /**
205
277
  * Main configuration for a CadreNode
206
278
  */
@@ -237,6 +309,41 @@ export interface CadreNodeConfig {
237
309
  storage?: StorageConfig;
238
310
  /** Network configuration */
239
311
  network?: NetworkConfig;
312
+ /**
313
+ * Number of nodes Optimystic is told a **strand** network's replication cluster
314
+ * should have, for every strand this node starts. The control network is not
315
+ * configurable — it always replicates to {@link CONTROL_REPLICATION_BREADTH}
316
+ * nodes, which is above any party's node count, because every member reads the
317
+ * whole control database and a member that misses a write may never learn the
318
+ * fact (see that constant for the full reasoning).
319
+ *
320
+ * Every node on the same strand should use the same value: the number bounds the
321
+ * cohort a member independently derives, and Optimystic's cluster-membership gate
322
+ * can reject a coordinator's smaller declared set as a downsize against a larger
323
+ * derived view.
324
+ *
325
+ * Frozen when the strand's libp2p node is created; a change takes effect on
326
+ * restart, not when cadre membership grows. Defaults to
327
+ * {@link DEFAULT_STRAND_CLUSTER_SIZE} (4 — the smallest breadth whose 0.75
328
+ * super-majority still commits with one holder offline); anything below
329
+ * {@link MIN_CLUSTER_SIZE} is rejected before a node is created. The cost of a
330
+ * small value is replication breadth and reliance on read repair, not commit
331
+ * correctness — but at 2 that read repair cannot converge, because a lone
332
+ * corroborator's stale answer is accepted as the cluster's truth.
333
+ */
334
+ strandClusterSize?: number;
335
+ /**
336
+ * Tuning for the strand peer-join block catch-up (see `strand-backfill.ts`):
337
+ * when a strand's libp2p node connects to a peer this runtime has not yet
338
+ * caught up, every block in the strand's own raw store is pushed to that peer,
339
+ * so a machine that joined the strand after blocks were committed still ends
340
+ * up physically holding them. Applies to every strand this node starts;
341
+ * strand-only — the control network has its own row-level re-issue queue
342
+ * (`drainPendingControlReplication`). Omit for the defaults
343
+ * (`DEFAULT_STRAND_BACKFILL`); `{ enabled: false }` restores the
344
+ * no-backfill behaviour.
345
+ */
346
+ strandBackfill?: StrandBackfillConfig;
240
347
  /** Hibernation configuration */
241
348
  hibernation?: HibernationConfig;
242
349
  /** Polling interval for strand watcher in ms (default: 5000) */
@@ -253,13 +360,73 @@ export interface CadreNodeConfig {
253
360
  * into every SeedBootstrapService this node constructs (owner, receive-only
254
361
  * listener, and the temp service used by applySeed when no service exists), and
255
362
  * used as the service-level default the libp2p seed-protocol handler relies on
256
- * (that path has no per-call override seam). Defaults to dbAnchoredTrustPolicy()
257
- * inside SeedBootstrapService when unset — a cold-start node then rejects every
258
- * seed. A per-call `applySeed(seed, { trustPolicy })` override still wins over
259
- * this default for callers that hold out-of-band material (e.g. a pinned key
260
- * from a CadreInvite).
363
+ * (that path has no per-call override seam). Defaults to anchoredTrustPolicy()
364
+ * inside SeedBootstrapService when unset — a node whose node-local trusted-owner
365
+ * anchor was never seeded then rejects every seed. A per-call
366
+ * `applySeed(seed, { trustPolicy })` override still wins over this default for
367
+ * callers that hold out-of-band material (e.g. a pinned key from a CadreInvite).
261
368
  */
262
369
  seedTrustPolicy?: SeedTrustPolicy;
370
+ /**
371
+ * Node-local trusted-owner anchor (see `trusted-owner-store.ts`): the
372
+ * NON-replicated, per-party record of owner keys established out of band —
373
+ * the anchor membership/seed trust can rest on, since the replicated
374
+ * `OwnerKey` table can be polluted by a stranger's self-genesis. Absent ⇒ an
375
+ * in-memory store is created at start() (ephemeral: anchored trust does not
376
+ * survive the process).
377
+ */
378
+ trustedOwners?: {
379
+ /**
380
+ * Injected store instance — e.g. a `FileTrustedOwnerStore` from the
381
+ * Node-only subpath `@serfab/cadre-core/trusted-owner-store-file`,
382
+ * persisted in the node's state directory (same injection/isolation pattern
383
+ * as {@link keyStore}). Its `partyId` must match `controlNetwork.partyId`;
384
+ * start() fails closed on a mismatch.
385
+ */
386
+ store?: TrustedOwnerStore;
387
+ /**
388
+ * Owner keys (base64url ed25519) established out of band and seeded into
389
+ * the store during start(): operator pins (e.g. cadre-cli
390
+ * `--pin-owner-key` / `CADRE_OWNER_KEYS`) or a `CadreInvite.ownerKeys`
391
+ * already known at config time. Seeding is idempotent across restarts.
392
+ */
393
+ pinnedKeys?: string[];
394
+ /**
395
+ * Provenance recorded for {@link pinnedKeys}. Default: 'operator'.
396
+ * ('genesis' is reserved for the node's own founding key, seeded
397
+ * internally by `initializeSeedBootstrap`.)
398
+ */
399
+ pinnedSource?: Exclude<TrustSource, 'genesis'>;
400
+ };
401
+ /**
402
+ * Node-local cold-start bootstrap-peer store (see `bootstrap-peer-store.ts`):
403
+ * the owner addresses an applied seed nominated, kept so
404
+ * `reconcileControlCohort`'s cold-start branch can keep retrying a node that
405
+ * was seeded but never managed to connect. Sibling of {@link trustedOwners} —
406
+ * same NON-replicated, per-party, injected-backend shape — but nothing here is
407
+ * trust-bearing: these are dial hints only, and every address is re-bound to
408
+ * its peer id before the dial. Absent ⇒ an in-memory store is created at
409
+ * start() (ephemeral: the retry set does not survive the process, and such a
410
+ * node is stranded permanently if it restarts before connecting).
411
+ *
412
+ * The Node CLI, the browser, and React Native all inject a durable backend
413
+ * today; only NativeScript stays ephemeral, tracked by the
414
+ * `ns-durable-node-local-stores` ticket (which covers the same gap for
415
+ * {@link trustedOwners}). A new platform needs no new store class: supply a
416
+ * `DurableSlot` for the platform's storage and inject
417
+ * `PersistentBootstrapPeerStore.open(slot, partyId)` /
418
+ * `PersistentTrustedOwnerStore.open(slot, partyId)`.
419
+ */
420
+ bootstrapPeers?: {
421
+ /**
422
+ * Injected store instance — e.g. a `FileBootstrapPeerStore` from the
423
+ * Node-only subpath `@serfab/cadre-core/bootstrap-peer-store-file`, persisted
424
+ * in the node's state directory (same injection/isolation pattern as
425
+ * {@link keyStore} / {@link trustedOwners}). Its `partyId` must match
426
+ * `controlNetwork.partyId`; start() fails closed on a mismatch.
427
+ */
428
+ store?: BootstrapPeerStore;
429
+ };
263
430
  /**
264
431
  * Platform push-delivery for suspended mobile peers. When present, the node's
265
432
  * server fan-out can deliver strand-wake data messages over the platform push
@@ -308,6 +475,13 @@ export interface StrandInstance {
308
475
  strandId: string;
309
476
  status: StrandStatus;
310
477
  sAppInfo?: SAppInfo;
478
+ /**
479
+ * The lifecycle mode this instance's runtime was built with — `bootstrap`
480
+ * (purely local transactor) or `networked` (cluster transactor). Refreshed on
481
+ * every runtime (re)build, so a resume that shifts `bootstrap → networked`
482
+ * updates it. Read-only reporting; drives no behavior.
483
+ */
484
+ mode: StrandMode;
311
485
  /** The libp2p node for this strand (only when active/idle) */
312
486
  libp2pNode?: Libp2p;
313
487
  /** The Quereus database for this strand (only when active/idle) */
@@ -473,15 +647,6 @@ export interface FormStrandResult {
473
647
  */
474
648
  memberPrivateKey?: string;
475
649
  }
476
- /**
477
- * Result of validating a strand formation request
478
- */
479
- export interface ValidateFormationResult {
480
- /** Public key for validating this formation */
481
- validationKey: string;
482
- /** Signature over the formation approval */
483
- validationSignature: string;
484
- }
485
650
  /**
486
651
  * Disclosure object provided during strand formation.
487
652
  * Contains identity and context information from the initiator.
@@ -589,13 +754,57 @@ export interface PeerAddressRecord {
589
754
  /** ed25519 self-signature over the signed payload, base64url. */
590
755
  sig: string;
591
756
  }
757
+ /**
758
+ * One `CadreControl.CadrePeer` row as read by `ControlDatabase.queryCadrePeers`:
759
+ * the addressing columns plus the persisted membership voucher.
760
+ *
761
+ * The voucher triple (`stampId`, `vouchOwner`, `vouchSig`) is what
762
+ * {@link CadreNode.listAuthorizedMembers} re-checks against the node-local
763
+ * trusted-owner anchor — it is null on a row written before the voucher columns
764
+ * existed, and all three must be present for the row to be authorizable. Named
765
+ * (rather than restated inline at each read site) so a future column addition
766
+ * cannot reach the query without the predicate seeing it.
767
+ */
768
+ export interface CadrePeerRow {
769
+ /** libp2p peer ID (base58btc) — the row key. */
770
+ peerId: string;
771
+ /** Comma-joined dialable multiaddrs as stored, or null when unpublished. */
772
+ multiaddr: string | null;
773
+ /** Single-use anti-replay nonce the voucher signature is bound to. */
774
+ stampId: string | null;
775
+ /** ed25519 public key (base64url) of the owner that vouched this row. */
776
+ vouchOwner: string | null;
777
+ /** That owner's signature over `digest('CadreControl.CadrePeer', 'vouch', peerId, stampId)`, base64url. */
778
+ vouchSig: string | null;
779
+ }
780
+ /** The voucher-bearing subset of a {@link CadrePeerRow} — what the authorized-membership predicate reads. */
781
+ export type CadrePeerVoucherFields = Pick<CadrePeerRow, 'peerId' | 'stampId' | 'vouchOwner' | 'vouchSig'>;
782
+ /**
783
+ * One `CadreControl.Revocation` tombstone as read by
784
+ * `ControlDatabase.queryRevocations`: the identity triple plus the `ReissuedAt`
785
+ * counter an owner bumps (`ControlDatabase.reissueRevocations`) to re-write — and
786
+ * therefore re-broadcast — a tombstone that committed while the node was alone.
787
+ */
788
+ export interface RevocationRow {
789
+ /** Which guarded table's stamp was retired. */
790
+ tableName: RevocableTable;
791
+ /** Primary key of the removed row (peer id / key / strand id). */
792
+ rowKey: string;
793
+ /** The retired single-use nonce — the tombstone's identity. */
794
+ stampId: string;
795
+ /** Monotonic re-issue counter; carries no semantics (see the schema comment). */
796
+ reissuedAt: number;
797
+ }
592
798
  /**
593
799
  * Outcome of {@link CadreNode.registerSelf}, surfaced so callers (e.g. the CLI
594
800
  * `--owner` branch) can log what happened:
595
801
  * - `inserted` — the first owner-signed INSERT of this node's `CadrePeer` row.
596
802
  * - `refreshed` — a self-signed UPDATE of an existing row (heartbeat / addr change).
597
- * - `skipped` — nothing written (no self-signing key, or not yet a member with no
598
- * owner service to self-insert).
803
+ * Also reported when a first publish found its row seated by a concurrent
804
+ * `authorizePeer` of this node's own id and fell through to the UPDATE — the write
805
+ * really was an UPDATE, even though the caller's intent was a first publish.
806
+ * - `skipped` — nothing written (no self-signing key, not yet a member with no
807
+ * owner service to self-insert, or the row was removed mid-publish).
599
808
  */
600
809
  export type SelfRegistrationOutcome = 'inserted' | 'refreshed' | 'skipped';
601
810
  /**
@@ -668,6 +877,20 @@ export interface DeviceTokenRecord {
668
877
  /** ed25519 self-signature over the signed payload, base64url. */
669
878
  sig: string;
670
879
  }
880
+ /**
881
+ * A stored `CadreControl.DeviceToken` row: the self-signed
882
+ * {@link DeviceTokenRecord} plus the row's single-use `StampId` nonce.
883
+ *
884
+ * The stamp is deliberately OUTSIDE `DeviceTokenRecord`: the peer's own `Sig`
885
+ * covers only (peerId, platform, token, updatedAt), while the stamp is bound by
886
+ * the OWNER's insert/delete approvals. Readers need it to drop a row whose stamp
887
+ * has been retired into `CadreControl.Revocation` (a token resurrected by an
888
+ * approval replay on a node that had not yet converged on the tombstone).
889
+ */
890
+ export interface DeviceTokenRow extends DeviceTokenRecord {
891
+ /** Single-use authorization nonce; rotates on every (re)insert. */
892
+ stampId: string;
893
+ }
671
894
  /**
672
895
  * Options for {@link CadreNode.resolveDeviceToken}.
673
896
  */
@@ -815,6 +1038,14 @@ export interface WakeAck {
815
1038
  export interface StrandAddrRequest {
816
1039
  /** The strand whose strand-network address the requester wants to seed from. */
817
1040
  strandId: string;
1041
+ /**
1042
+ * The derived transport peerId the requester's own strand-`strandId` node
1043
+ * runs as (see `strand-transport-key.ts`). Present → the responder records a
1044
+ * delegate admission grant for it, so its own connection gate (and thus its
1045
+ * circuit-relay server, when it runs one) admits that peerId; absent →
1046
+ * today's behavior exactly. See `delegate-admission.ts` for the trust model.
1047
+ */
1048
+ delegatePeerId?: string;
818
1049
  }
819
1050
  /**
820
1051
  * Response to a {@link StrandAddrRequest}, carrying the responder's strand-node
@@ -849,6 +1080,27 @@ export interface ApplySeedResult {
849
1080
  peersAdded: number;
850
1081
  /** Error message if not successful */
851
1082
  error?: string;
1083
+ /**
1084
+ * Owner-flagged seed peers this apply attempted to dial. Zero when the seed
1085
+ * carried no owner peer with an address, or when the seed was rejected before
1086
+ * the dial loop ran.
1087
+ */
1088
+ ownerDialsAttempted: number;
1089
+ /**
1090
+ * How many of those dials threw. `ownerDialsAttempted > 0 && ownerDialsFailed
1091
+ * === ownerDialsAttempted` means "seeded but stranded": the seed itself was
1092
+ * accepted (`success: true`) but no owner could be reached, so this node has
1093
+ * no connection to bootstrap its control database from. The node retries those
1094
+ * addresses on every control-cohort reconcile pass (see
1095
+ * `CadreNode.dialColdStartBootstrap`), so this is a signal, not a fatal error.
1096
+ *
1097
+ * Zero failures is NOT proof of a live connection: the receiving node's
1098
+ * membership gate denies AFTER the dialer's upgrade completes (see
1099
+ * `createMembershipConnectionGater`), so a dial can resolve and then be torn
1100
+ * down. Treat a non-zero value as certain failure and zero as "no failure
1101
+ * observed".
1102
+ */
1103
+ ownerDialsFailed: number;
852
1104
  }
853
1105
  /**
854
1106
  * Node network topology type for seed helper scenarios.
@@ -867,7 +1119,10 @@ export interface CadreInvite {
867
1119
  * Owner ed25519 public keys (base64url) of the cadre, carried out-of-band
868
1120
  * so a cold-start invitee can pin the trusted owner set before applying
869
1121
  * any seed (the seed itself cannot vouch for its own signer). Populated by
870
- * `createInvite` from the issuer's `OwnerKey` table.
1122
+ * `createInvite` from the issuer's OWN node-local trusted-owner anchor —
1123
+ * not its replicated `OwnerKey` table, because the invitee anchors whatever
1124
+ * arrives here and a stranger's genesis-inserted key must not ride an
1125
+ * otherwise-legitimate invite into a fresh node's anchor.
871
1126
  */
872
1127
  ownerKeys?: string[];
873
1128
  /** Optional invite token for validation */
package/dist/types.js CHANGED
@@ -40,4 +40,17 @@ export const HIBERNATION_TIMEOUTS = {
40
40
  * See {@link HibernationConfig.checkInWindowMs}.
41
41
  */
42
42
  export const DEFAULT_CHECKIN_WINDOW_MS = 15 * 1000;
43
+ /**
44
+ * Replication-breadth constants, both networks' cluster policies, and the strand
45
+ * resolver, re-exported so cadre embedders, the SQL plugin and the integration
46
+ * harness share one definition. Defined in `@serfab/quereus-plugin-sereus`
47
+ * because that package also creates libp2p nodes and cannot depend on this one.
48
+ * The control network's breadth is fixed ({@link CONTROL_REPLICATION_BREADTH},
49
+ * not configurable) and so is its consensus policy ({@link CONTROL_CLUSTER_POLICY}
50
+ * — notably the super-majority threshold, which it leaves at Optimystic's default
51
+ * by omission); the strand breadth defaults to
52
+ * {@link CadreNodeConfig.strandClusterSize} while its policy is the fixed
53
+ * {@link STRAND_CLUSTER_POLICY}.
54
+ */
55
+ export { MIN_CLUSTER_SIZE, CONTROL_REPLICATION_BREADTH, CONTROL_CLUSTER_POLICY, DEFAULT_STRAND_CLUSTER_SIZE, STRAND_CLUSTER_POLICY, resolveStrandClusterSize } from '@serfab/quereus-plugin-sereus';
43
56
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA+DA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA6C;IAC5E,QAAQ,EAAE;QACR,WAAW,EAAE,QAAQ,EAAS,aAAa;QAC3C,gBAAgB,EAAE,QAAQ,EAAI,kBAAkB;QAChD,eAAe,EAAE,QAAQ,EAAK,MAAM;QACpC,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,QAAQ,CAAE,MAAM;KACrC;IACD,WAAW,EAAE;QACX,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAI,YAAY;QAC1C,gBAAgB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,wBAAwB;QAC1D,eAAe,EAAE,EAAE,GAAG,IAAI,EAAI,mBAAmB;QACjD,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,eAAe;KACnD;IACD,UAAU,EAAE;QACV,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAI,WAAW;QACzC,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAG,uBAAuB;QACzD,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAI,kBAAkB;QACpD,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,gBAAgB;KACxD;IACD,OAAO,EAAE;QACP,WAAW,EAAE,EAAE,GAAG,IAAI,EAAQ,aAAa;QAC3C,gBAAgB,EAAE,EAAE,GAAG,IAAI,EAAG,wBAAwB;QACtD,eAAe,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAG,eAAe;QACjD,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,eAAe;KAC5D;CACF,CAAC;AA4HF;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,IAAI,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2EA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAA6C;IAC5E,QAAQ,EAAE;QACR,WAAW,EAAE,QAAQ,EAAS,aAAa;QAC3C,gBAAgB,EAAE,QAAQ,EAAI,kBAAkB;QAChD,eAAe,EAAE,QAAQ,EAAK,MAAM;QACpC,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,QAAQ,CAAE,MAAM;KACrC;IACD,WAAW,EAAE;QACX,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAI,YAAY;QAC1C,gBAAgB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,wBAAwB;QAC1D,eAAe,EAAE,EAAE,GAAG,IAAI,EAAI,mBAAmB;QACjD,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,eAAe;KACnD;IACD,UAAU,EAAE;QACV,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAI,WAAW;QACzC,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAG,uBAAuB;QACzD,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAI,kBAAkB;QACpD,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,gBAAgB;KACxD;IACD,OAAO,EAAE;QACP,WAAW,EAAE,EAAE,GAAG,IAAI,EAAQ,aAAa;QAC3C,gBAAgB,EAAE,EAAE,GAAG,IAAI,EAAG,wBAAwB;QACtD,eAAe,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAG,eAAe;QACjD,oBAAoB,EAAE,CAAC;QACvB,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,eAAe;KAC5D;CACF,CAAC;AA2KF;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,GAAG,IAAI,CAAC;AAYnD;;;;;;;;;;;GAWG;AACH,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,+BAA+B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serfab/cadre-core",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "description": "Core library for Sereus cadre nodes - manages control networks and strand participation",
6
6
  "main": "dist/index.js",
@@ -24,6 +24,14 @@
24
24
  "types": "./dist/key-store-file.d.ts",
25
25
  "import": "./dist/key-store-file.js"
26
26
  },
27
+ "./trusted-owner-store-file": {
28
+ "types": "./dist/trusted-owner-store-file.d.ts",
29
+ "import": "./dist/trusted-owner-store-file.js"
30
+ },
31
+ "./bootstrap-peer-store-file": {
32
+ "types": "./dist/bootstrap-peer-store-file.d.ts",
33
+ "import": "./dist/bootstrap-peer-store-file.js"
34
+ },
27
35
  "./push-node": {
28
36
  "types": "./dist/push-node.d.ts",
29
37
  "import": "./dist/push-node.js"
@@ -54,8 +62,11 @@
54
62
  "devDependencies": {
55
63
  "@chainsafe/libp2p-noise": "^17.0.0",
56
64
  "@chainsafe/libp2p-yamux": "^8.0.1",
57
- "@libp2p/peer-id-factory": "^4.2.4",
65
+ "@libp2p/circuit-relay-v2": "^4.1.3",
66
+ "@libp2p/identify": "4.0.10",
58
67
  "@libp2p/tcp": "^11.0.10",
68
+ "@libp2p/webrtc": "6.0.14",
69
+ "@libp2p/websockets": "^10.1.3",
59
70
  "@types/debug": "^4.1.12",
60
71
  "@types/node": "^25.0.10",
61
72
  "@vitest/coverage-v8": "^4.0.17",
@@ -68,12 +79,12 @@
68
79
  "@libp2p/interface": "^3.1.0",
69
80
  "@libp2p/peer-id": "^6.0.4",
70
81
  "@multiformats/multiaddr": "^12.5.1",
71
- "@optimystic/db-core": "^0.14.1",
72
- "@optimystic/db-p2p": "^0.14.1",
73
- "@optimystic/quereus-plugin-crypto": "^0.14.1",
74
- "@optimystic/quereus-plugin-optimystic": "^0.14.1",
75
- "@quereus/quereus": "^4.4.0",
76
- "@serfab/quereus-plugin-sereus": "^0.9.0",
82
+ "@optimystic/db-core": "^0.22.0",
83
+ "@optimystic/db-p2p": "^0.22.0",
84
+ "@optimystic/quereus-plugin-crypto": "^0.22.0",
85
+ "@optimystic/quereus-plugin-optimystic": "^0.22.0",
86
+ "@quereus/quereus": "^4.10.0",
87
+ "@serfab/quereus-plugin-sereus": "^0.10.0",
77
88
  "debug": "^4.4.3",
78
89
  "libp2p": "^3.1.3",
79
90
  "uint8arrays": "^5.1.0"
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Node-only file-backed {@link BootstrapPeerStore}: one JSON file per party under
3
+ * a configured directory (the node's state directory — `cadre-cli` passes
4
+ * `ResolvedConfig.nodeStateDir`), holding the node-local, non-replicated
5
+ * cold-start dial targets a seed nominated.
6
+ *
7
+ * Nothing but the file itself lives here: the envelope, load policy, per-entry
8
+ * validation (shape only — never signatures; see the `bootstrap-peer-store.ts`
9
+ * module comment for why nothing persisted here is trust-bearing) and the
10
+ * serialised snapshot writes are cross-platform in
11
+ * `PersistentBootstrapPeerStore` / `node-local-snapshot.ts`, and the file is a
12
+ * `FileDurableSlot`. This module exists only so the `node:fs` edge stays out of
13
+ * the package's cross-platform default entry (`./index.js`) — import it from the
14
+ * dedicated subpath instead:
15
+ *
16
+ * ```ts
17
+ * import { FileBootstrapPeerStore } from '@serfab/cadre-core/bootstrap-peer-store-file';
18
+ * ```
19
+ *
20
+ * A React Native / browser entry graph never resolves this path, so the
21
+ * `node:fs` edge never reaches a bundler that cannot satisfy it (same isolation
22
+ * pattern as `trusted-owner-store-file.ts` / `key-store-file.ts`).
23
+ */
24
+ import { FileDurableSlot } from './file-durable-slot.js';
25
+ import { PersistentBootstrapPeerStore } from './bootstrap-peer-store.js';
26
+ import type { BootstrapPeerStore } from './bootstrap-peer-store.js';
27
+
28
+ /** Base name of the store file: `<dir>/bootstrap-peers.<encoded partyId>.json`. */
29
+ const SLOT_NAME = 'bootstrap-peers';
30
+
31
+ /**
32
+ * File-backed {@link BootstrapPeerStore}. Open via {@link open}, which loads the
33
+ * existing file and returns the cross-platform store over it; an absent, corrupt, or wrong-party file is a cold
34
+ * start (empty store) and structurally junk entries are dropped, while a
35
+ * present-but-unreadable file throws. Those rules and their reasoning live on
36
+ * `NodeLocalSnapshot.open` — including the in-process-only write serialisation,
37
+ * which two nodes sharing one directory for one party would defeat.
38
+ */
39
+ export const FileBootstrapPeerStore = {
40
+ /** Load (or cold-start) the party's retained dial targets from a file in `dir`. */
41
+ async open(dir: string, partyId: string): Promise<BootstrapPeerStore> {
42
+ return PersistentBootstrapPeerStore.open(new FileDurableSlot(dir, SLOT_NAME, partyId), partyId);
43
+ }
44
+ };