@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.
- package/README.md +5 -3
- package/dist/cadre-node.d.ts +70 -34
- package/dist/cadre-node.js +197 -60
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-database.d.ts +24 -10
- package/dist/control-database.js +48 -16
- package/dist/control-database.js.map +1 -1
- package/dist/control-formation-recorder.d.ts +4 -4
- package/dist/control-formation-recorder.js +6 -6
- package/dist/control-formation-recorder.js.map +1 -1
- package/dist/control-read-retry.d.ts +12 -0
- package/dist/control-read-retry.js +12 -0
- package/dist/control-read-retry.js.map +1 -1
- package/dist/control-write-retry.d.ts +5 -4
- package/dist/control-write-retry.js +24 -7
- package/dist/control-write-retry.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/link-budget.d.ts +182 -0
- package/dist/link-budget.js +195 -0
- package/dist/link-budget.js.map +1 -0
- package/dist/membership-connection-gater.d.ts +18 -5
- package/dist/membership-connection-gater.js +50 -10
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/peer-dial.d.ts +36 -17
- package/dist/peer-dial.js +37 -17
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.d.ts +58 -4
- package/dist/peer-join-backfill.js +165 -20
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/relay-reservation.d.ts +59 -11
- package/dist/relay-reservation.js +169 -43
- package/dist/relay-reservation.js.map +1 -1
- package/dist/seed-bootstrap.js +2 -1
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/storage-scope.d.ts +50 -12
- package/dist/storage-scope.js +85 -12
- package/dist/storage-scope.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +43 -5
- package/dist/strand-first-sync-gate.js +55 -7
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-manager.js +2 -1
- package/dist/strand-formation-manager.js.map +1 -1
- package/dist/strand-id.d.ts +35 -0
- package/dist/strand-id.js +46 -0
- package/dist/strand-id.js.map +1 -0
- package/dist/strand-instance-manager.d.ts +27 -2
- package/dist/strand-instance-manager.js +75 -15
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +200 -45
- package/dist/strand-membership-reconciler.js +302 -86
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +3 -2
- package/dist/strand-membership-writer.js +67 -90
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-network-config.d.ts +3 -3
- package/dist/strand-network-config.js +3 -3
- package/dist/strand-solicitation.js +2 -1
- package/dist/strand-solicitation.js.map +1 -1
- package/dist/strand-watcher.d.ts +45 -0
- package/dist/strand-watcher.js +74 -13
- package/dist/strand-watcher.js.map +1 -1
- package/dist/types.d.ts +190 -24
- package/dist/types.js +73 -4
- package/dist/types.js.map +1 -1
- package/package.json +8 -8
- package/src/cadre-node.ts +7445 -7302
- package/src/control-database.ts +48 -16
- package/src/control-formation-recorder.ts +6 -6
- package/src/control-read-retry.ts +214 -202
- package/src/control-write-retry.ts +24 -7
- package/src/index.ts +29 -2
- package/src/link-budget.ts +217 -0
- package/src/membership-connection-gater.ts +56 -11
- package/src/peer-dial.ts +39 -17
- package/src/peer-join-backfill.ts +192 -23
- package/src/relay-reservation.ts +1119 -951
- package/src/seed-bootstrap.ts +2 -1
- package/src/storage-scope.ts +163 -78
- package/src/strand-first-sync-gate.ts +55 -7
- package/src/strand-formation-manager.ts +647 -646
- package/src/strand-id.ts +48 -0
- package/src/strand-instance-manager.ts +1516 -1440
- package/src/strand-membership-reconciler.ts +334 -92
- package/src/strand-membership-writer.ts +1962 -1987
- package/src/strand-network-config.ts +250 -250
- package/src/strand-solicitation.ts +500 -499
- package/src/strand-watcher.ts +388 -325
- package/src/types.ts +192 -23
package/src/strand-id.ts
ADDED
|
@@ -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
|
+
}
|