@serfab/cadre-core 1.3.0 → 1.5.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 (90) hide show
  1. package/README.md +5 -3
  2. package/dist/cadre-node.d.ts +70 -34
  3. package/dist/cadre-node.js +197 -60
  4. package/dist/cadre-node.js.map +1 -1
  5. package/dist/control-database.d.ts +24 -10
  6. package/dist/control-database.js +48 -16
  7. package/dist/control-database.js.map +1 -1
  8. package/dist/control-formation-recorder.d.ts +4 -4
  9. package/dist/control-formation-recorder.js +6 -6
  10. package/dist/control-formation-recorder.js.map +1 -1
  11. package/dist/control-read-retry.d.ts +12 -0
  12. package/dist/control-read-retry.js +12 -0
  13. package/dist/control-read-retry.js.map +1 -1
  14. package/dist/control-write-retry.d.ts +5 -4
  15. package/dist/control-write-retry.js +24 -7
  16. package/dist/control-write-retry.js.map +1 -1
  17. package/dist/index.d.ts +5 -4
  18. package/dist/index.js +10 -5
  19. package/dist/index.js.map +1 -1
  20. package/dist/link-budget.d.ts +182 -0
  21. package/dist/link-budget.js +195 -0
  22. package/dist/link-budget.js.map +1 -0
  23. package/dist/membership-connection-gater.d.ts +18 -5
  24. package/dist/membership-connection-gater.js +50 -10
  25. package/dist/membership-connection-gater.js.map +1 -1
  26. package/dist/peer-dial.d.ts +36 -17
  27. package/dist/peer-dial.js +37 -17
  28. package/dist/peer-dial.js.map +1 -1
  29. package/dist/peer-join-backfill.d.ts +58 -4
  30. package/dist/peer-join-backfill.js +165 -20
  31. package/dist/peer-join-backfill.js.map +1 -1
  32. package/dist/relay-reservation.d.ts +59 -11
  33. package/dist/relay-reservation.js +169 -43
  34. package/dist/relay-reservation.js.map +1 -1
  35. package/dist/seed-bootstrap.js +2 -1
  36. package/dist/seed-bootstrap.js.map +1 -1
  37. package/dist/storage-scope.d.ts +50 -12
  38. package/dist/storage-scope.js +85 -12
  39. package/dist/storage-scope.js.map +1 -1
  40. package/dist/strand-first-sync-gate.d.ts +43 -5
  41. package/dist/strand-first-sync-gate.js +55 -7
  42. package/dist/strand-first-sync-gate.js.map +1 -1
  43. package/dist/strand-formation-manager.js +2 -1
  44. package/dist/strand-formation-manager.js.map +1 -1
  45. package/dist/strand-id.d.ts +35 -0
  46. package/dist/strand-id.js +46 -0
  47. package/dist/strand-id.js.map +1 -0
  48. package/dist/strand-instance-manager.d.ts +27 -2
  49. package/dist/strand-instance-manager.js +75 -15
  50. package/dist/strand-instance-manager.js.map +1 -1
  51. package/dist/strand-membership-reconciler.d.ts +200 -45
  52. package/dist/strand-membership-reconciler.js +302 -86
  53. package/dist/strand-membership-reconciler.js.map +1 -1
  54. package/dist/strand-membership-writer.d.ts +3 -2
  55. package/dist/strand-membership-writer.js +67 -90
  56. package/dist/strand-membership-writer.js.map +1 -1
  57. package/dist/strand-network-config.d.ts +3 -3
  58. package/dist/strand-network-config.js +3 -3
  59. package/dist/strand-solicitation.js +2 -1
  60. package/dist/strand-solicitation.js.map +1 -1
  61. package/dist/strand-watcher.d.ts +45 -0
  62. package/dist/strand-watcher.js +74 -13
  63. package/dist/strand-watcher.js.map +1 -1
  64. package/dist/types.d.ts +190 -24
  65. package/dist/types.js +73 -4
  66. package/dist/types.js.map +1 -1
  67. package/package.json +8 -8
  68. package/src/cadre-node.ts +7445 -7302
  69. package/src/control-database.ts +48 -16
  70. package/src/control-formation-recorder.ts +6 -6
  71. package/src/control-read-retry.ts +214 -202
  72. package/src/control-write-retry.ts +24 -7
  73. package/src/index.ts +29 -2
  74. package/src/link-budget.ts +217 -0
  75. package/src/membership-connection-gater.ts +56 -11
  76. package/src/peer-dial.ts +39 -17
  77. package/src/peer-join-backfill.ts +192 -23
  78. package/src/relay-reservation.ts +1119 -951
  79. package/src/seed-bootstrap.ts +2 -1
  80. package/src/storage-scope.ts +163 -78
  81. package/src/strand-first-sync-gate.ts +55 -7
  82. package/src/strand-formation-manager.ts +647 -646
  83. package/src/strand-id.ts +48 -0
  84. package/src/strand-instance-manager.ts +1516 -1440
  85. package/src/strand-membership-reconciler.ts +334 -92
  86. package/src/strand-membership-writer.ts +1962 -1987
  87. package/src/strand-network-config.ts +250 -250
  88. package/src/strand-solicitation.ts +500 -499
  89. package/src/strand-watcher.ts +388 -325
  90. package/src/types.ts +192 -23
@@ -0,0 +1,48 @@
1
+ /**
2
+ * strand-id.ts — the only places cadre-core mints a strand id.
3
+ *
4
+ * A strand id is not just a key in the control database: it is the strand's storage
5
+ * scope key (a directory, a LevelDB filename, an IndexedDB database name — whatever
6
+ * the embedder's provider makes of it) and the strand node's libp2p network name,
7
+ * `strand-<id>`, which becomes the protocol prefix `/optimystic/strand-<id>`. It also
8
+ * replicates to every other node in the party, which will turn it into those same
9
+ * names on their own disks.
10
+ *
11
+ * So a generator that emits a shape `isValidStrandScopeKey` rejects does not fail
12
+ * here — it fails later, on a peer, at launch. Minting in one module and asserting the
13
+ * predicate on the way out is what keeps that impossible: a future edit to either shape
14
+ * fails at its own call site rather than on someone else's machine.
15
+ */
16
+
17
+ import { randomBytes } from '@optimystic/quereus-plugin-crypto';
18
+ import { assertStrandScopeKey } from './storage-scope.js';
19
+
20
+ /**
21
+ * Mint a fresh, unguessable strand id: `strand-` plus 32 hex characters (128 bits).
22
+ *
23
+ * Uses {@link randomBytes} — the same cross-platform CSPRNG `control-database`'s
24
+ * `generateStampId` uses — NOT `crypto.randomUUID` / `Date.now` / `Math.random`, none
25
+ * of which are uniformly available across node/browser/React Native. Unguessability is
26
+ * the point for a responder-provisioned strand: the id is what an invite redemption
27
+ * hands back, so a predictable one would let a third party name a strand before its
28
+ * founder published it.
29
+ */
30
+ export function mintStrandId(): string {
31
+ const strandId = `strand-${randomBytes(128, 'hex') as string}`;
32
+ assertStrandScopeKey(strandId);
33
+ return strandId;
34
+ }
35
+
36
+ /**
37
+ * Mint a structural placeholder strand id: `strand-<ms since epoch>-<6 base36 chars>`.
38
+ *
39
+ * For the no-node / no-recorder fallbacks, where the caller needs a well-shaped id an
40
+ * initiator can validate but no strand is actually provisioned. NOT unguessable —
41
+ * `Math.random` is not a CSPRNG — so never use it where {@link mintStrandId}'s
42
+ * unpredictability is load-bearing.
43
+ */
44
+ export function mintPlaceholderStrandId(): string {
45
+ const strandId = `strand-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
46
+ assertStrandScopeKey(strandId);
47
+ return strandId;
48
+ }