@serfab/cadre-core 1.22.0 → 1.24.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 +216 -294
- package/dist/arachnode-stub.d.ts +12 -4
- package/dist/arachnode-stub.js +15 -8
- package/dist/arachnode-stub.js.map +1 -1
- package/dist/cadre-invite-protocol.js +5 -4
- package/dist/cadre-invite-protocol.js.map +1 -1
- package/dist/cadre-node.d.ts +159 -53
- package/dist/cadre-node.js +276 -89
- package/dist/cadre-node.js.map +1 -1
- package/dist/control-authorization.d.ts +14 -2
- package/dist/control-authorization.js +8 -3
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-cohort.d.ts +27 -13
- package/dist/control-cohort.js +21 -14
- package/dist/control-cohort.js.map +1 -1
- package/dist/control-database.d.ts +18 -16
- package/dist/control-database.js +57 -22
- package/dist/control-database.js.map +1 -1
- package/dist/control-protocol-guard.d.ts +1 -1
- package/dist/control-protocol-guard.js +7 -3
- package/dist/control-protocol-guard.js.map +1 -1
- package/dist/control-read-retry.d.ts +49 -11
- package/dist/control-read-retry.js +56 -15
- package/dist/control-read-retry.js.map +1 -1
- package/dist/control-retry.d.ts +32 -3
- package/dist/control-retry.js +35 -4
- package/dist/control-retry.js.map +1 -1
- package/dist/control-schema-version.d.ts +5 -5
- package/dist/control-schema-version.js +5 -5
- package/dist/control-schema-version.js.map +1 -1
- package/dist/control-schema.d.ts +5 -5
- package/dist/control-schema.js +1032 -1011
- package/dist/control-schema.js.map +1 -1
- package/dist/control-write-retry.d.ts +54 -65
- package/dist/control-write-retry.js +134 -158
- package/dist/control-write-retry.js.map +1 -1
- package/dist/delegate-admission.d.ts +1 -1
- package/dist/delegate-admission.js +1 -1
- package/dist/edge-node/config.d.ts +4 -3
- package/dist/edge-node/config.js +11 -9
- package/dist/edge-node/config.js.map +1 -1
- package/dist/edge-node/dissolve.d.ts +4 -4
- package/dist/edge-node/dissolve.js +4 -4
- package/dist/edge-node/edge-join.d.ts +1 -1
- package/dist/edge-node/edge-join.js +1 -1
- package/dist/edge-node/edge-node.js +2 -2
- package/dist/edge-node/edge-node.js.map +1 -1
- package/dist/edge-node/index.d.ts +1 -0
- package/dist/edge-node/index.js +1 -0
- package/dist/edge-node/index.js.map +1 -1
- package/dist/edge-node/join-credential.d.ts +1 -1
- package/dist/edge-node/join-credential.js +1 -1
- package/dist/edge-node/lazy-raw-storage.js +12 -0
- package/dist/edge-node/lazy-raw-storage.js.map +1 -1
- package/dist/edge-node/listen-addrs.d.ts +21 -0
- package/dist/edge-node/listen-addrs.js +25 -0
- package/dist/edge-node/listen-addrs.js.map +1 -0
- package/dist/edge-node/owner-grant.d.ts +1 -1
- package/dist/edge-node/owner-grant.js +1 -1
- package/dist/edge-node/platform.d.ts +5 -4
- package/dist/edge-node/platform.js.map +1 -1
- package/dist/edge-node/strand-move.d.ts +1 -1
- package/dist/edge-node/strand-move.js +1 -1
- package/dist/edge-node/strands.js +27 -11
- package/dist/edge-node/strands.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/invitation-bootstrap.d.ts +28 -5
- package/dist/invitation-bootstrap.js +41 -8
- package/dist/invitation-bootstrap.js.map +1 -1
- package/dist/link-budget.d.ts +53 -4
- package/dist/link-budget.js +58 -5
- package/dist/link-budget.js.map +1 -1
- package/dist/machine-removal.d.ts +2 -2
- package/dist/machine-removal.js +4 -3
- package/dist/machine-removal.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +2 -2
- package/dist/membership-connection-gater.js +2 -2
- package/dist/membership-view.d.ts +2 -2
- package/dist/membership-view.js +6 -3
- package/dist/membership-view.js.map +1 -1
- package/dist/node-claim-payload.d.ts +15 -7
- package/dist/node-claim-payload.js +25 -9
- package/dist/node-claim-payload.js.map +1 -1
- package/dist/node-class.d.ts +36 -0
- package/dist/node-class.js +26 -0
- package/dist/node-class.js.map +1 -0
- package/dist/node-default-transports.d.ts +50 -3
- package/dist/node-default-transports.js +48 -3
- package/dist/node-default-transports.js.map +1 -1
- package/dist/node-roles.d.ts +118 -0
- package/dist/node-roles.js +142 -0
- package/dist/node-roles.js.map +1 -0
- package/dist/node-transports.d.ts +6 -2
- package/dist/node-transports.js +39 -7
- package/dist/node-transports.js.map +1 -1
- package/dist/owner-anchor-sync.js +1 -1
- package/dist/owner-key-export.js +1 -1
- package/dist/owner-key-flows.d.ts +1 -1
- package/dist/owner-key-store.js +1 -1
- package/dist/owner-signer.js +1 -1
- package/dist/peer-authorization.d.ts +3 -1
- package/dist/peer-authorization.js +3 -1
- package/dist/peer-authorization.js.map +1 -1
- package/dist/peer-dial.d.ts +74 -10
- package/dist/peer-dial.js +89 -17
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.js +4 -4
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/peer-record.d.ts +34 -9
- package/dist/peer-record.js +66 -13
- package/dist/peer-record.js.map +1 -1
- package/dist/pending-join-runner.d.ts +1 -1
- package/dist/pending-join-runner.js +1 -1
- package/dist/provider/client.d.ts +6 -5
- package/dist/provider/client.js +3 -3
- package/dist/provider/client.js.map +1 -1
- package/dist/provider/descriptor.d.ts +1 -1
- package/dist/provider/descriptor.js +1 -1
- package/dist/provider/oauth.d.ts +1 -1
- package/dist/provider/oauth.js +1 -1
- package/dist/provider/rent-node.d.ts +4 -3
- package/dist/provider/rent-node.js +3 -3
- package/dist/provider/rent-node.js.map +1 -1
- package/dist/relay-addrs.d.ts +62 -7
- package/dist/relay-addrs.js +74 -11
- package/dist/relay-addrs.js.map +1 -1
- package/dist/relay-reservation.d.ts +1 -1
- package/dist/relay-reservation.js +1 -1
- package/dist/relay-server.d.ts +6 -5
- package/dist/relay-server.js +5 -5
- package/dist/relay-server.js.map +1 -1
- package/dist/schema-verification.d.ts +13 -10
- package/dist/schema-verification.js +32 -24
- package/dist/schema-verification.js.map +1 -1
- package/dist/sealed-party-key.js +1 -1
- package/dist/seed-bootstrap.d.ts +4 -3
- package/dist/seed-bootstrap.js +6 -7
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +8 -6
- package/dist/strand-addr-protocol.js +12 -10
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-app-schema-report.d.ts +16 -2
- package/dist/strand-app-schema-report.js +15 -0
- package/dist/strand-app-schema-report.js.map +1 -1
- package/dist/strand-cohort.d.ts +1 -4
- package/dist/strand-cohort.js.map +1 -1
- package/dist/strand-commit-durability.d.ts +1 -1
- package/dist/strand-database.d.ts +13 -6
- package/dist/strand-database.js +17 -9
- package/dist/strand-database.js.map +1 -1
- package/dist/strand-first-sync-gate.d.ts +3 -2
- package/dist/strand-first-sync-gate.js +3 -2
- package/dist/strand-first-sync-gate.js.map +1 -1
- package/dist/strand-formation-deadlines.d.ts +2 -2
- package/dist/strand-formation-deadlines.js +2 -2
- package/dist/strand-formation-protocol.d.ts +1 -1
- package/dist/strand-formation-protocol.js +51 -16
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-instance-manager.d.ts +134 -42
- package/dist/strand-instance-manager.js +331 -76
- package/dist/strand-instance-manager.js.map +1 -1
- package/dist/strand-membership-reconciler.d.ts +8 -3
- package/dist/strand-membership-reconciler.js +8 -3
- package/dist/strand-membership-reconciler.js.map +1 -1
- package/dist/strand-membership-writer.d.ts +2 -2
- package/dist/strand-membership-writer.js +41 -39
- package/dist/strand-membership-writer.js.map +1 -1
- package/dist/strand-move.js +1 -1
- package/dist/strand-network-config.d.ts +15 -5
- package/dist/strand-network-config.js +7 -6
- package/dist/strand-network-config.js.map +1 -1
- package/dist/strand-party-key-rotation.d.ts +7 -3
- package/dist/strand-party-key-rotation.js +7 -3
- package/dist/strand-party-key-rotation.js.map +1 -1
- package/dist/strand-party-machines.d.ts +19 -8
- package/dist/strand-party-machines.js +26 -11
- package/dist/strand-party-machines.js.map +1 -1
- package/dist/strand-party-peers.d.ts +36 -14
- package/dist/strand-party-peers.js +24 -15
- package/dist/strand-party-peers.js.map +1 -1
- package/dist/strand-peer-redial.d.ts +1 -1
- package/dist/strand-peer-redial.js +1 -1
- package/dist/strand-reactivity.d.ts +20 -17
- package/dist/strand-reactivity.js +31 -18
- package/dist/strand-reactivity.js.map +1 -1
- package/dist/strand-revocation-enforcer.d.ts +3 -3
- package/dist/strand-revocation-enforcer.js +3 -3
- package/dist/strand-wake-protocol.d.ts +19 -7
- package/dist/strand-wake-protocol.js +22 -10
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/strand-watcher.d.ts +1 -1
- package/dist/strand-watcher.js +1 -1
- package/dist/table-change-watch.js +1 -1
- package/dist/types.d.ts +127 -57
- package/dist/types.js.map +1 -1
- package/dist/webrtc-upgrade.d.ts +254 -0
- package/dist/webrtc-upgrade.js +355 -0
- package/dist/webrtc-upgrade.js.map +1 -0
- package/package.json +9 -9
- package/src/announce-addrs.ts +93 -93
- package/src/arachnode-stub.ts +18 -10
- package/src/bootstrap-peer-store-file.ts +44 -44
- package/src/bootstrap-peer-store.ts +214 -214
- package/src/cadre-invite-protocol.ts +741 -740
- package/src/cadre-node.ts +12462 -12252
- package/src/claim-proof.ts +147 -147
- package/src/control-authorization.ts +290 -276
- package/src/control-cohort.ts +223 -204
- package/src/control-database.ts +72 -28
- package/src/control-formation-recorder.ts +359 -359
- package/src/control-protocol-guard.ts +370 -366
- package/src/control-read-retry.ts +222 -180
- package/src/control-retry.ts +36 -4
- package/src/control-schema-version.ts +301 -301
- package/src/control-schema.ts +1108 -1087
- package/src/control-write-retry.ts +639 -669
- package/src/delegate-admission.ts +351 -351
- package/src/describe-thrown.ts +60 -60
- package/src/ed25519-key.ts +185 -185
- package/src/edge-node/config.ts +13 -10
- package/src/edge-node/dissolve.ts +252 -252
- package/src/edge-node/edge-join.ts +320 -320
- package/src/edge-node/edge-node.ts +1095 -1095
- package/src/edge-node/index.ts +60 -59
- package/src/edge-node/join-credential.ts +16 -16
- package/src/edge-node/lazy-raw-storage.ts +194 -178
- package/src/edge-node/listen-addrs.ts +26 -0
- package/src/edge-node/node-local.ts +84 -84
- package/src/edge-node/options.ts +195 -195
- package/src/edge-node/owner-grant.ts +63 -63
- package/src/edge-node/platform.ts +5 -4
- package/src/edge-node/strand-move.ts +266 -266
- package/src/edge-node/strands.ts +27 -12
- package/src/enrolled-machine-store-file.ts +43 -43
- package/src/enrolled-machine-store.ts +280 -280
- package/src/fetch-impl.ts +23 -23
- package/src/file-durable-slot.ts +64 -64
- package/src/file-safe-name.ts +32 -32
- package/src/formation-approval.ts +604 -604
- package/src/formation-token.ts +63 -63
- package/src/fs-atomic.ts +92 -92
- package/src/index.ts +987 -957
- package/src/invitation-bootstrap.ts +152 -118
- package/src/joined-strand-store.ts +553 -553
- package/src/key-store-file.ts +142 -142
- package/src/link-budget.ts +61 -5
- package/src/machine-removal.ts +211 -210
- package/src/member-redemption.ts +643 -643
- package/src/membership-connection-gater.ts +650 -650
- package/src/membership-view.ts +147 -144
- package/src/node-claim-payload.ts +34 -12
- package/src/node-class.ts +47 -0
- package/src/node-default-transports.ts +65 -3
- package/src/node-roles.ts +220 -0
- package/src/node-transports.ts +86 -49
- package/src/owner-anchor-sync.ts +172 -172
- package/src/owner-grant-protocol.ts +547 -547
- package/src/owner-key-export.ts +348 -348
- package/src/owner-key-flows.ts +109 -109
- package/src/owner-key-store.ts +1 -1
- package/src/owner-keys.ts +179 -179
- package/src/owner-signer.ts +92 -92
- package/src/peer-addr-book.ts +252 -252
- package/src/peer-authorization.ts +584 -582
- package/src/peer-dial.ts +698 -605
- package/src/peer-join-backfill.ts +961 -961
- package/src/peer-record.ts +71 -16
- package/src/pending-join-runner.ts +798 -798
- package/src/primary-lan-address.ts +47 -47
- package/src/provider/client.ts +327 -326
- package/src/provider/descriptor.ts +129 -129
- package/src/provider/index.ts +59 -59
- package/src/provider/oauth.ts +285 -285
- package/src/provider/rent-node.ts +276 -275
- package/src/relay-addrs.ts +90 -12
- package/src/relay-reservation.ts +1 -1
- package/src/relay-server.ts +99 -98
- package/src/schema-verification.ts +38 -23
- package/src/sealed-party-key.ts +190 -190
- package/src/seed-bootstrap.ts +8 -11
- package/src/seed-trust-policy.ts +353 -353
- package/src/self-address-update.ts +19 -19
- package/src/strand-addr-protocol.ts +17 -14
- package/src/strand-app-schema-report.ts +147 -122
- package/src/strand-cohort.ts +1 -5
- package/src/strand-commit-durability.ts +165 -165
- package/src/strand-database.ts +522 -510
- package/src/strand-first-sync-gate.ts +3 -2
- package/src/strand-formation-deadlines.ts +227 -227
- package/src/strand-formation-manager.ts +731 -731
- package/src/strand-formation-protocol.ts +1174 -1138
- package/src/strand-fret-addrs.ts +179 -179
- package/src/strand-instance-manager.ts +381 -85
- package/src/strand-membership-reconciler.ts +1315 -1310
- package/src/strand-membership-writer.ts +2152 -2150
- package/src/strand-move.ts +1 -1
- package/src/strand-network-config.ts +16 -6
- package/src/strand-offline.ts +178 -178
- package/src/strand-party-key-rotation.ts +440 -436
- package/src/strand-party-machines.ts +308 -293
- package/src/strand-party-peers.ts +151 -129
- package/src/strand-peer-redial.ts +1 -1
- package/src/strand-reactivity.ts +36 -19
- package/src/strand-revocation-enforcer.ts +758 -758
- package/src/strand-wake-protocol.ts +406 -394
- package/src/strand-watcher.ts +1 -1
- package/src/table-change-watch.ts +285 -285
- package/src/timed-step.ts +28 -28
- package/src/timeout-scheduler.ts +29 -29
- package/src/trusted-owner-store.ts +242 -242
- package/src/types.ts +3182 -3112
- package/src/webrtc-upgrade.ts +439 -0
package/README.md
CHANGED
|
@@ -1,294 +1,216 @@
|
|
|
1
|
-
# @serfab/cadre-core
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
The
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
|
96
|
-
|
|
97
|
-
|
|
|
98
|
-
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
|
187
|
-
|
|
188
|
-
|
|
|
189
|
-
| `
|
|
190
|
-
| `
|
|
191
|
-
|
|
|
192
|
-
|
|
|
193
|
-
|
|
|
194
|
-
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
|
199
|
-
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
- **[Schema Guide](../../docs/schema-guide.md)** - Optimystic schema definitions
|
|
218
|
-
|
|
219
|
-
## React Native Support
|
|
220
|
-
|
|
221
|
-
This package is compatible with React Native. For mobile apps, use the RN-specific storage provider:
|
|
222
|
-
|
|
223
|
-
```typescript
|
|
224
|
-
import { CadreNode } from '@serfab/cadre-core';
|
|
225
|
-
import { RNRawStorage } from '@optimystic/db-p2p-storage-rn';
|
|
226
|
-
import { webSockets } from '@libp2p/websockets';
|
|
227
|
-
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
228
|
-
|
|
229
|
-
const node = new CadreNode({
|
|
230
|
-
controlNetwork: {
|
|
231
|
-
partyId: 'your-unique-party-id',
|
|
232
|
-
bootstrapNodes: ['/dns4/relay.example.com/tcp/443/wss/p2p/12D3KooW...']
|
|
233
|
-
},
|
|
234
|
-
profile: 'transaction', // Mobile devices typically use transaction profile
|
|
235
|
-
strandFilter: { mode: 'sAppId', sAppId: 'com.example.myapp' },
|
|
236
|
-
storage: {
|
|
237
|
-
// RN storage provider creates per-scope AsyncStorage
|
|
238
|
-
provider: (scope) => new RNRawStorage(scope)
|
|
239
|
-
},
|
|
240
|
-
network: {
|
|
241
|
-
// TCP doesn't work in React Native — use WebSocket transport instead
|
|
242
|
-
transports: [webSockets(), circuitRelayTransport()],
|
|
243
|
-
listenAddrs: [] // RN nodes typically cannot listen
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### Storage Provider Pattern
|
|
249
|
-
|
|
250
|
-
The `storage.provider` option accepts either:
|
|
251
|
-
- **An `IRawStorage` instance** - One store shared by every scope, so it can serve only a single party
|
|
252
|
-
- **A factory function** `(scope: string) => IRawStorage` - Creates isolated storage per scope (recommended)
|
|
253
|
-
|
|
254
|
-
A **scope key** is what the factory receives. It is the strand id for each strand, and
|
|
255
|
-
`controlStorageScope(partyId)` — `control-<lowercase hex of the party id>` — for the control
|
|
256
|
-
database, which holds one party's own records and must not be shared between parties. Every
|
|
257
|
-
key is opaque and already safe as a file, directory or database name (always within
|
|
258
|
-
`[a-z0-9._-]`), and two different keys are two different names even on a filesystem that
|
|
259
|
-
ignores case (Windows, macOS): use it verbatim, do not parse it. `isControlStorageScope(scope)`
|
|
260
|
-
tells the two kinds apart. The control key holds the charset by lowercase hex encoding; a strand
|
|
261
|
-
id holds it by check — `assertStrandScopeKey` runs on every strand launch, so a strand
|
|
262
|
-
whose row replicated in from another node with an unusable id (including one with an
|
|
263
|
-
uppercase letter) is refused rather than
|
|
264
|
-
handed to the factory, and on `publishStrand`, so this node never writes such an id into
|
|
265
|
-
the party's control database to begin with.
|
|
266
|
-
|
|
267
|
-
Available storage implementations:
|
|
268
|
-
| Package | Environment | Description |
|
|
269
|
-
|---------|-------------|-------------|
|
|
270
|
-
| `@optimystic/db-p2p` | All | `MemoryRawStorage` - In-memory (testing only) |
|
|
271
|
-
| `@optimystic/db-p2p-storage-fs` | Node.js | `FileRawStorage` - File system storage |
|
|
272
|
-
| `@optimystic/db-p2p-storage-rn` | React Native | `RNRawStorage` - AsyncStorage-based |
|
|
273
|
-
|
|
274
|
-
### React Native Considerations
|
|
275
|
-
|
|
276
|
-
1. **Network Transport**: libp2p's TCP transport doesn't work in RN. Pass `transports: [webSockets(), circuitRelayTransport()]` in the `network` config (see example above).
|
|
277
|
-
|
|
278
|
-
2. **Schema Loading**: The control schema is embedded in the package. Do not set `schemaPath` in React Native.
|
|
279
|
-
|
|
280
|
-
3. **Profile**: Mobile devices should use `profile: 'transaction'` for battery/bandwidth efficiency.
|
|
281
|
-
|
|
282
|
-
4. **Strand Filtering**: Always filter strands on mobile to avoid participating in unnecessary networks.
|
|
283
|
-
|
|
284
|
-
## Related Packages
|
|
285
|
-
|
|
286
|
-
- **[@optimystic/db-core](https://github.com/gotchoices/optimystic)** - Distributed database core
|
|
287
|
-
- **[@optimystic/db-p2p](https://github.com/gotchoices/optimystic)** - libp2p integration for Optimystic
|
|
288
|
-
- **[@optimystic/db-p2p-storage-fs](https://github.com/gotchoices/optimystic)** - File system storage (Node.js)
|
|
289
|
-
- **[@optimystic/db-p2p-storage-rn](https://github.com/gotchoices/optimystic)** - AsyncStorage (React Native)
|
|
290
|
-
|
|
291
|
-
## License
|
|
292
|
-
|
|
293
|
-
MIT
|
|
294
|
-
|
|
1
|
+
# @serfab/cadre-core
|
|
2
|
+
|
|
3
|
+
The library that runs a Sereus cadre node. A node connects one machine to its party's private control network, starts the strands the party takes part in, and gives the app each strand as a SQL database.
|
|
4
|
+
|
|
5
|
+
In Sereus a **party** is a person or organisation, its **cadre** is the set of machines it runs, and a **strand** is an invitation-only SQL database shared among parties. [Concepts](https://github.com/gotchoices/sereus/blob/master/docs/concepts.md) defines the terms used here, and [Getting started](https://github.com/gotchoices/sereus/blob/master/docs/getting-started.md) walks through a first app with two parties.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- **An ES module project.** The package ships ES modules only. It runs on Node.js 20.19 or later, in browsers, and in React Native and NativeScript apps.
|
|
10
|
+
- **A block store for the platform.** cadre-core stores data through Optimystic's `IRawStorage` interface and does not bundle a durable implementation; see [Storage provider](#storage-provider).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @serfab/cadre-core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The [quick start](#quick-start) also imports two packages directly:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @optimystic/db-p2p @optimystic/quereus-plugin-crypto
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
This script starts one node for a new party on Node.js, makes it the owner of its cadre, founds a strand, and reads back a row it wrote. It keeps everything in memory, so each run starts a new party.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { CadreNode, InMemoryKeyStore, createOwnerKey, signSchema } from '@serfab/cadre-core';
|
|
30
|
+
import { MemoryRawStorage } from '@optimystic/db-p2p';
|
|
31
|
+
import { generatePrivateKey, getPublicKey } from '@optimystic/quereus-plugin-crypto';
|
|
32
|
+
|
|
33
|
+
// The sApp: an app schema signed by its author. The author's public key is the sApp id.
|
|
34
|
+
const authorKey = generatePrivateKey('ed25519', 'base64url') as string;
|
|
35
|
+
const sApp = {
|
|
36
|
+
version: '1.0.0',
|
|
37
|
+
schemaVersion: 1,
|
|
38
|
+
schema: 'table Note (Id text primary key, Body text not null);',
|
|
39
|
+
};
|
|
40
|
+
const sAppConfig = {
|
|
41
|
+
id: getPublicKey(authorKey, 'ed25519', 'base64url', 'base64url') as string,
|
|
42
|
+
...sApp,
|
|
43
|
+
signature: signSchema(sApp, authorKey),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// One store per scope: one for the control database, one for each strand.
|
|
47
|
+
const stores = new Map<string, MemoryRawStorage>();
|
|
48
|
+
const storeFor = (scope: string): MemoryRawStorage => {
|
|
49
|
+
let store = stores.get(scope);
|
|
50
|
+
if (!store) {
|
|
51
|
+
store = new MemoryRawStorage();
|
|
52
|
+
stores.set(scope, store);
|
|
53
|
+
}
|
|
54
|
+
return store;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const keyStore = new InMemoryKeyStore();
|
|
58
|
+
const node = new CadreNode({
|
|
59
|
+
keyStore,
|
|
60
|
+
controlNetwork: { partyId: crypto.randomUUID(), bootstrapNodes: [] },
|
|
61
|
+
nodeClass: 'device',
|
|
62
|
+
storage: { provider: storeFor },
|
|
63
|
+
});
|
|
64
|
+
await node.start();
|
|
65
|
+
|
|
66
|
+
// A new cadre has no owner. Create an owner key, seat it as the first owner, and sign with it.
|
|
67
|
+
const owner = await createOwnerKey(keyStore);
|
|
68
|
+
await node.getControlDatabase()!.ensureOwnerKey(owner.publicKey);
|
|
69
|
+
await node.useOwnerSigner(owner);
|
|
70
|
+
|
|
71
|
+
// Publish the strand to the party and start it here.
|
|
72
|
+
const { instance } = await node.foundStrand({ strandId: 'notes', sAppConfig });
|
|
73
|
+
|
|
74
|
+
// The strand is a Quereus database. App tables are in the App schema.
|
|
75
|
+
const db = instance.database!.getDatabase();
|
|
76
|
+
await db.exec("insert into App.Note (Id, Body) values ('1', 'hello')");
|
|
77
|
+
for await (const row of db.eval('select Body from App.Note')) {
|
|
78
|
+
console.log(row.Body); // hello
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
await node.stop();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Expected output is the line `hello`. Set `DEBUG=sereus:*` to see what the node does on the way.
|
|
85
|
+
|
|
86
|
+
An app on a phone or in a browser does not construct `CadreNode` itself. It calls `createEdgeNode` from `@serfab/cadre-core/edge-node`, which builds the node over the app's key store and storage, creates the owner key on first run, and remembers how to start again. See [The edge node](https://github.com/gotchoices/sereus/blob/master/docs/cadre/node.md#the-edge-node).
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
`new CadreNode(config)` takes a `CadreNodeConfig`, declared in [`src/types.ts`](src/types.ts). [Configuration](https://github.com/gotchoices/sereus/blob/master/docs/cadre/node.md#configuration) describes every option group. The options most embedders set:
|
|
91
|
+
|
|
92
|
+
| Option | Meaning |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `controlNetwork.partyId` | The party this node serves. The app mints it once, for example as a UUID, and reuses it on every start. |
|
|
95
|
+
| `controlNetwork.bootstrapNodes` | Multiaddrs of the party's other machines to dial at start. Empty for the first machine. |
|
|
96
|
+
| `nodeClass` | `'device'` or `'server'`; see [Node class and roles](#node-class-and-roles). |
|
|
97
|
+
| `roles` | Per-role overrides of what the class means; see [Node class and roles](#node-class-and-roles). |
|
|
98
|
+
| `strandFilter` | Which of the party's strands this node runs; see [Strand filter](#strand-filter). |
|
|
99
|
+
| `storage.provider` | Where blocks are kept; see [Storage provider](#storage-provider). |
|
|
100
|
+
| `keyStore` | Where the node's identity key and other secrets are kept. With neither this nor `privateKey`, the node gets a new peer id on every start. `InMemoryKeyStore` is for tests; `FileKeyStore` from `@serfab/cadre-core/key-store-file` is the Node.js backend. |
|
|
101
|
+
| `network` | Listen addresses, transports and relays. On Node.js the default listens on TCP. A browser or phone passes WebSocket and circuit-relay transports with `listenAddrs: []`. |
|
|
102
|
+
| `requireSignedSchemas` | Default `true`: an sApp config without a valid author signature is refused. Set `false` only for development. |
|
|
103
|
+
|
|
104
|
+
### Node class and roles
|
|
105
|
+
|
|
106
|
+
`nodeClass` says what kind of machine this node runs on. `'device'` is a phone, a laptop or a browser tab running an app, connected some of the time. `'server'` is an always-on machine: it also runs a relay server by default and keeps a copy of every strand its `strandFilter` admits, including strands no app on that machine uses. Under either preset a node stores the data of the strands it runs; the `strandCohortMember` role below is what changes that.
|
|
107
|
+
|
|
108
|
+
The class is only the preset for four decisions, the node's **roles**, which `roles` sets one at a time:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
roles: {
|
|
112
|
+
alwaysOn: true, // declare that this machine stays running and reachable
|
|
113
|
+
overlayTier: 'core', // FRET resource tier: 'edge' or 'core'
|
|
114
|
+
reactivity: 'subscriber', // 'forwarder' may carry other subscribers' change notifications
|
|
115
|
+
strandCohortMember: true, // hold and sign the blocks of the strands this node runs
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
A role left out takes its preset's value (`device`: `false`, `'edge'`, `'forwarder'`, `true`; `server`: `true`, `'core'`, `'forwarder'`, `true`). A misspelled role name, or a value outside a role's own set, throws. `NODE_ROLE_PRESETS` and `resolveNodeRoles` are exported for a program that wants to show an operator what a config resolves to. See [Node classes](https://github.com/gotchoices/sereus/blob/master/docs/cadre/node.md#node-classes).
|
|
120
|
+
|
|
121
|
+
`strandCohortMember: false` makes the node a **client** of every strand it runs: it reads and writes the strand through the machines that store it, asks `storage.provider` for no per-strand store, and is left out of every cluster, so it is never on the path of another machine's save. It cannot host storage replicas, so `hostUnclaimedStrands` defaults to `false` on it and an explicit `true` throws naming both settings. A client needs a serving machine reachable to open or found a strand. See [A node that holds no strand blocks](https://github.com/gotchoices/sereus/blob/master/docs/cadre/node.md#a-node-that-holds-no-strand-blocks).
|
|
122
|
+
|
|
123
|
+
### Strand filter
|
|
124
|
+
|
|
125
|
+
`strandFilter` limits which of the party's strands the node runs. An app that should run only its own strands filters by its sApp id.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
strandFilter: { mode: 'all' } // every strand of the party (the default)
|
|
129
|
+
strandFilter: { mode: 'sAppId', sAppId } // strands of one sApp
|
|
130
|
+
strandFilter: { mode: 'strandId', strandId: 'notes' } // one strand
|
|
131
|
+
strandFilter: { mode: 'none' } // the control network only
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`sAppId` is the sApp author's public key in base64url, the same value as `SAppConfig.id`. It is not a reverse-DNS application name. See [Strand filtering](https://github.com/gotchoices/sereus/blob/master/docs/cadre/node.md#strand-filtering).
|
|
135
|
+
|
|
136
|
+
### Storage provider
|
|
137
|
+
|
|
138
|
+
`storage.provider` is a function from a scope key to an `IRawStorage`. cadre-core calls it once for the control database and once for each strand the node starts.
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import { FileRawStorage } from '@optimystic/db-p2p-storage-fs';
|
|
142
|
+
import { FileKeyStore } from '@serfab/cadre-core/key-store-file';
|
|
143
|
+
|
|
144
|
+
const node = new CadreNode({
|
|
145
|
+
keyStore: new FileKeyStore('/var/lib/my-app/keys'),
|
|
146
|
+
controlNetwork: { partyId, bootstrapNodes: [] },
|
|
147
|
+
nodeClass: 'server',
|
|
148
|
+
storage: { provider: (scope) => new FileRawStorage(`/var/lib/my-app/data/${scope}`) },
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- **The scope key is safe to use as a name.** It is a strand id, or `control-` followed by a hex encoding of the party id. Every key stays within `[a-z0-9._-]`, so it can go straight into a path or a database name. Do not parse it.
|
|
153
|
+
- **Return the same data for the same key.** The provider is called again for a scope after its strand stops or the node restarts, and must return a store over the same durable data.
|
|
154
|
+
- **Keep the control scope per party.** Two parties on one device must get two control stores, which the function form gives them. A single `IRawStorage` instance is also accepted, but it shares one store across every scope and can serve only one party.
|
|
155
|
+
- **Close the stores yourself.** cadre-core never closes what the provider returned.
|
|
156
|
+
|
|
157
|
+
| Package | Class | Platform |
|
|
158
|
+
| --- | --- | --- |
|
|
159
|
+
| `@optimystic/db-p2p` | `MemoryRawStorage` | Any; nothing persists |
|
|
160
|
+
| `@optimystic/db-p2p-storage-fs` | `FileRawStorage` | Node.js |
|
|
161
|
+
| `@optimystic/db-p2p-storage-rn` | `LevelDBRawStorage` | React Native |
|
|
162
|
+
| `@optimystic/db-p2p-storage-ns` | `SqliteRawStorage` | NativeScript |
|
|
163
|
+
| `@optimystic/db-p2p-storage-web` | `IndexedDBRawStorage` | Browsers |
|
|
164
|
+
|
|
165
|
+
See [Storage](https://github.com/gotchoices/sereus/blob/master/docs/cadre/node.md#storage) for the cache cadre-core puts in front of a store and the rules that follow from it.
|
|
166
|
+
|
|
167
|
+
## What the node keeps, and where
|
|
168
|
+
|
|
169
|
+
cadre-core writes no files of its own. Everything durable goes through an object the embedder supplies:
|
|
170
|
+
|
|
171
|
+
- **Blocks** of the control database and of each strand go to `storage.provider`.
|
|
172
|
+
- **Secrets** go to `keyStore`: the node's identity key, the owner key, and the record of strands joined from other parties.
|
|
173
|
+
- **Node-local state** goes to the stores named in the config (`trustedOwners`, `bootstrapPeers`, `enrolledMachines`, `strandNetworkState`). Each defaults to memory. The file-backed versions are Node.js subpath imports such as `@serfab/cadre-core/trusted-owner-store-file`.
|
|
174
|
+
|
|
175
|
+
A node that keeps these in memory forgets which owner keys it trusts and which machines to dial when the process exits. See [Node-local state](https://github.com/gotchoices/sereus/blob/master/docs/cadre/node.md#node-local-state).
|
|
176
|
+
|
|
177
|
+
## API map
|
|
178
|
+
|
|
179
|
+
The [cadre-core API guide](https://github.com/gotchoices/sereus/blob/master/docs/api.md) lists every call an app makes, what each one promises and where its mechanism is explained.
|
|
180
|
+
|
|
181
|
+
| Task | Calls | Guide section |
|
|
182
|
+
| --- | --- | --- |
|
|
183
|
+
| Create and run a node | `new CadreNode`, `start`, `stop`, `createEdgeNode` | [Creating a node](https://github.com/gotchoices/sereus/blob/master/docs/api.md#creating-a-node) |
|
|
184
|
+
| Hold and manage owner keys | `createOwnerKey`, `useOwnerSigner`, `isOwner`, `addOwner`, `createOwnerGrant` | [Owner keys](https://github.com/gotchoices/sereus/blob/master/docs/api.md#owner-keys) |
|
|
185
|
+
| Add a machine to the cadre | `createCadreInvitation`, `redeemCadreInvitation`, `claimNode`, `addDrone`, `rentNode` | [Adding a machine](https://github.com/gotchoices/sereus/blob/master/docs/api.md#adding-a-machine) |
|
|
186
|
+
| List and remove machines | `listMachines`, `planMachineRemoval`, `removeMachine` | [Listing and removing machines](https://github.com/gotchoices/sereus/blob/master/docs/api.md#listing-and-removing-machines) |
|
|
187
|
+
| Found a strand | `foundStrand`, `signSchema` | [Founding](https://github.com/gotchoices/sereus/blob/master/docs/api.md#founding) |
|
|
188
|
+
| Invite another party | `createOpenInvitation`, `publishFormationInvite`, `encodeInvitation` | [Inviting another party](https://github.com/gotchoices/sereus/blob/master/docs/api.md#inviting-another-party) |
|
|
189
|
+
| Join a strand | `formStrand`, `requestJoin`, `addStrand`, the `strand:discovered` event | [Joining](https://github.com/gotchoices/sereus/blob/master/docs/api.md#joining) |
|
|
190
|
+
| Read and write | `getStrand`, `instance.database.getDatabase()`, `setStrandOfflineMode` | [The strand's database](https://github.com/gotchoices/sereus/blob/master/docs/api.md#the-strands-database) |
|
|
191
|
+
| Stop or leave a strand | `stopStrand`, `unpublishStrand`, `forgetJoinedStrand` | [Stopping and leaving](https://github.com/gotchoices/sereus/blob/master/docs/api.md#stopping-and-leaving) |
|
|
192
|
+
| Administer a closed strand | `revokeMember`, `addMemberByManager`, `leaveStrand` | [Membership of closed strands](https://github.com/gotchoices/sereus/blob/master/docs/api.md#membership-of-closed-strands) |
|
|
193
|
+
| Approve joins from outside the party | `enrollValidationKey`, `signFormationApproval` | [Formation approval hook](https://github.com/gotchoices/sereus/blob/master/docs/formation-approval-hook.md) |
|
|
194
|
+
| React to changes and failures | `node.on(...)`, the error classes | [Events](https://github.com/gotchoices/sereus/blob/master/docs/api.md#events), [Errors](https://github.com/gotchoices/sereus/blob/master/docs/api.md#errors) |
|
|
195
|
+
|
|
196
|
+
## Entry points
|
|
197
|
+
|
|
198
|
+
| Import | Use |
|
|
199
|
+
| --- | --- |
|
|
200
|
+
| `@serfab/cadre-core` | Everything that runs on every platform |
|
|
201
|
+
| `@serfab/cadre-core/edge-node` | `createEdgeNode`, for phones and browsers |
|
|
202
|
+
| `@serfab/cadre-core/key-store-file`, `/trusted-owner-store-file`, `/bootstrap-peer-store-file`, `/enrolled-machine-store-file`, `/strand-network-state-file` | File-backed stores, Node.js only |
|
|
203
|
+
| `@serfab/cadre-core/push-node` | FCM and APNs senders, Node.js only |
|
|
204
|
+
| `@serfab/cadre-core/node-default-transports`, `/primary-lan-address` | Node.js transport list and LAN address probe |
|
|
205
|
+
|
|
206
|
+
## Related documentation
|
|
207
|
+
|
|
208
|
+
- [Architecture](https://github.com/gotchoices/sereus/blob/master/docs/architecture.md): how the control network, strands and nodes fit together.
|
|
209
|
+
- [Writing an app schema](https://github.com/gotchoices/sereus/blob/master/docs/schema-guide.md): how to write the Quereus schema an sApp runs.
|
|
210
|
+
- [Writing to a strand](https://github.com/gotchoices/sereus/blob/master/docs/strands/writes.md): commit durability and offline mode.
|
|
211
|
+
- [Running a node in a React Native app](https://github.com/gotchoices/sereus/blob/master/docs/platforms/react-native.md), [in a NativeScript app](https://github.com/gotchoices/sereus/blob/master/docs/platforms/nativescript.md) and [in a browser](https://github.com/gotchoices/sereus/blob/master/docs/platforms/browser.md).
|
|
212
|
+
- [`@serfab/cadre-cli`](https://github.com/gotchoices/sereus/blob/master/packages/cadre-cli/README.md) runs a node from the command line without writing code.
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
MIT
|
package/dist/arachnode-stub.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ArachnodeConfig } from './types.js';
|
|
2
|
+
import type { NodeClass } from './node-class.js';
|
|
2
3
|
/**
|
|
3
4
|
* Ring configuration for a storage node
|
|
4
5
|
*/
|
|
@@ -26,11 +27,11 @@ export interface RingConfig {
|
|
|
26
27
|
* This is a stub that will be replaced when arachnode is fully implemented.
|
|
27
28
|
*/
|
|
28
29
|
export declare class ArachnodeStub {
|
|
29
|
-
private readonly
|
|
30
|
+
private readonly nodeClass;
|
|
30
31
|
private readonly config;
|
|
31
32
|
private ringConfig?;
|
|
32
33
|
private running;
|
|
33
|
-
constructor(
|
|
34
|
+
constructor(nodeClass: NodeClass, config: ArachnodeConfig);
|
|
34
35
|
/**
|
|
35
36
|
* Start participating in rings
|
|
36
37
|
*/
|
|
@@ -56,5 +57,12 @@ export declare class ArachnodeStub {
|
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* Create an arachnode instance for a strand
|
|
60
|
+
*
|
|
61
|
+
* NOTE: the node class, not the `alwaysOn` node role every other behaviour now follows
|
|
62
|
+
* (`node-roles.ts`). Nothing in this repo calls this, and the storage rings it hands out are
|
|
63
|
+
* unimplemented (`backlog/later/5-ring-zulu-storage-rings`), so the divergence reaches nobody —
|
|
64
|
+
* but it means a `device` told `roles: { alwaysOn: true }` joins the real Ring Zulu and would
|
|
65
|
+
* still be given no storage ring here. Take `NodeRoles` instead of a class when the rings are
|
|
66
|
+
* built; the signature is exported, so that is a breaking change rather than a rename.
|
|
59
67
|
*/
|
|
60
|
-
export declare function createArachnodeStub(
|
|
68
|
+
export declare function createArachnodeStub(nodeClass: NodeClass, config?: Partial<ArachnodeConfig>): ArachnodeStub;
|