@serfab/cadre-core 1.13.0 → 1.14.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/dist/cadre-invite-protocol.d.ts +348 -0
- package/dist/cadre-invite-protocol.js +605 -0
- package/dist/cadre-invite-protocol.js.map +1 -0
- package/dist/cadre-node.d.ts +523 -180
- package/dist/cadre-node.js +921 -293
- package/dist/cadre-node.js.map +1 -1
- package/dist/claim-proof.d.ts +45 -0
- package/dist/claim-proof.js +132 -0
- package/dist/claim-proof.js.map +1 -0
- package/dist/control-authorization.d.ts +80 -19
- package/dist/control-authorization.js +55 -13
- package/dist/control-authorization.js.map +1 -1
- package/dist/control-cohort.js +1 -1
- package/dist/control-cohort.js.map +1 -1
- package/dist/control-database.d.ts +514 -97
- package/dist/control-database.js +1033 -195
- package/dist/control-database.js.map +1 -1
- package/dist/control-protocol-guard.d.ts +142 -0
- package/dist/control-protocol-guard.js +293 -0
- package/dist/control-protocol-guard.js.map +1 -0
- package/dist/control-schema.d.ts +1 -1
- package/dist/control-schema.js +801 -1067
- package/dist/control-schema.js.map +1 -1
- package/dist/control-stream.d.ts +4 -0
- package/dist/control-stream.js +22 -7
- package/dist/control-stream.js.map +1 -1
- package/dist/delegate-admission.d.ts +1 -1
- package/dist/delegate-admission.js +1 -1
- package/dist/device-token.d.ts +11 -9
- package/dist/device-token.js +14 -12
- package/dist/device-token.js.map +1 -1
- package/dist/ed25519-key.d.ts +15 -0
- package/dist/ed25519-key.js +28 -1
- package/dist/ed25519-key.js.map +1 -1
- package/dist/index.d.ts +14 -9
- package/dist/index.js +27 -9
- package/dist/index.js.map +1 -1
- package/dist/link-budget.d.ts +16 -29
- package/dist/link-budget.js +16 -31
- package/dist/link-budget.js.map +1 -1
- package/dist/membership-connection-gater.d.ts +190 -151
- package/dist/membership-connection-gater.js +235 -173
- package/dist/membership-connection-gater.js.map +1 -1
- package/dist/node-claim-payload.d.ts +19 -0
- package/dist/node-claim-payload.js +120 -0
- package/dist/node-claim-payload.js.map +1 -0
- package/dist/owner-anchor-sync.d.ts +22 -0
- package/dist/owner-anchor-sync.js +143 -0
- package/dist/owner-anchor-sync.js.map +1 -0
- package/dist/peer-authorization.d.ts +113 -18
- package/dist/peer-authorization.js +225 -29
- package/dist/peer-authorization.js.map +1 -1
- package/dist/peer-dial.d.ts +19 -0
- package/dist/peer-dial.js +22 -1
- package/dist/peer-dial.js.map +1 -1
- package/dist/peer-join-backfill.d.ts +26 -2
- package/dist/peer-join-backfill.js +54 -12
- package/dist/peer-join-backfill.js.map +1 -1
- package/dist/peer-record.d.ts +13 -9
- package/dist/peer-record.js +16 -12
- package/dist/peer-record.js.map +1 -1
- package/dist/pending-join-runner.d.ts +66 -58
- package/dist/pending-join-runner.js +136 -145
- package/dist/pending-join-runner.js.map +1 -1
- package/dist/push-fanout.d.ts +8 -2
- package/dist/push-fanout.js +8 -2
- package/dist/push-fanout.js.map +1 -1
- package/dist/seed-bootstrap.d.ts +147 -122
- package/dist/seed-bootstrap.js +284 -269
- package/dist/seed-bootstrap.js.map +1 -1
- package/dist/seed-trust-policy.d.ts +98 -37
- package/dist/seed-trust-policy.js +188 -2
- package/dist/seed-trust-policy.js.map +1 -1
- package/dist/strand-addr-protocol.d.ts +24 -26
- package/dist/strand-addr-protocol.js +19 -26
- package/dist/strand-addr-protocol.js.map +1 -1
- package/dist/strand-formation-protocol.js +1 -1
- package/dist/strand-formation-protocol.js.map +1 -1
- package/dist/strand-revocation-enforcer.d.ts +11 -11
- package/dist/strand-revocation-enforcer.js +11 -11
- package/dist/strand-wake-protocol.d.ts +13 -16
- package/dist/strand-wake-protocol.js +13 -20
- package/dist/strand-wake-protocol.js.map +1 -1
- package/dist/trusted-owner-store.d.ts +35 -5
- package/dist/trusted-owner-store.js +50 -8
- package/dist/trusted-owner-store.js.map +1 -1
- package/dist/types.d.ts +302 -87
- package/dist/types.js.map +1 -1
- package/package.json +8 -7
- package/src/cadre-invite-protocol.ts +864 -0
- package/src/cadre-node.ts +9381 -8686
- package/src/claim-proof.ts +147 -0
- package/src/control-authorization.ts +203 -117
- package/src/control-cohort.ts +1 -1
- package/src/control-database.ts +1216 -218
- package/src/control-protocol-guard.ts +348 -0
- package/src/control-schema.ts +812 -1078
- package/src/control-stream.ts +26 -7
- package/src/delegate-admission.ts +1 -1
- package/src/device-token.ts +14 -10
- package/src/ed25519-key.ts +28 -1
- package/src/index.ts +84 -10
- package/src/link-budget.ts +16 -32
- package/src/membership-connection-gater.ts +637 -570
- package/src/node-claim-payload.ts +125 -0
- package/src/owner-anchor-sync.ts +171 -0
- package/src/peer-authorization.ts +258 -29
- package/src/peer-dial.ts +22 -1
- package/src/peer-join-backfill.ts +56 -11
- package/src/peer-record.ts +16 -11
- package/src/pending-join-runner.ts +729 -735
- package/src/push-fanout.ts +8 -2
- package/src/seed-bootstrap.ts +344 -321
- package/src/seed-trust-policy.ts +353 -140
- package/src/strand-addr-protocol.ts +26 -35
- package/src/strand-formation-protocol.ts +1 -1
- package/src/strand-revocation-enforcer.ts +11 -11
- package/src/strand-wake-protocol.ts +13 -23
- package/src/trusted-owner-store.ts +242 -171
- package/src/types.ts +2471 -2242
package/src/control-schema.ts
CHANGED
|
@@ -1,1078 +1,812 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Embedded control schema for cross-platform compatibility.
|
|
3
|
-
*
|
|
4
|
-
* This is the authoritative runtime copy of the CadreControl authorization
|
|
5
|
-
* schema. It is duplicated from `schemas/control.qsql` so that React Native and
|
|
6
|
-
* other filesystem-less environments get the schema without a runtime file read.
|
|
7
|
-
*
|
|
8
|
-
* The two copies MUST stay identical — `control-schema-drift.spec.ts` fails the
|
|
9
|
-
* build if they drift. Any edit here must be mirrored in `schemas/control.qsql`
|
|
10
|
-
* and vice versa.
|
|
11
|
-
*/
|
|
12
|
-
export const CONTROL_SCHEMA = `--
|
|
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
|
-
|
|
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
|
-
constraint
|
|
167
|
-
not exists (select 1 from Revocation R where R.TableName = '
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
),
|
|
287
|
-
constraint
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
--
|
|
346
|
-
--
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
--
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
--
|
|
389
|
-
--
|
|
390
|
-
constraint
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
--
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
--
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
),
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
--
|
|
622
|
-
--
|
|
623
|
-
--
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
--
|
|
641
|
-
--
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
),
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
),
|
|
758
|
-
--
|
|
759
|
-
|
|
760
|
-
--
|
|
761
|
-
--
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
where FI.Token = new.Token
|
|
814
|
-
-- The use cap is COUNTED against the pre-transaction snapshot, never
|
|
815
|
-
-- sequenced. This CHECK auto-defers to commit (it has a subquery), by
|
|
816
|
-
-- which point the in-flight row is live; committed.* is what excludes
|
|
817
|
-
-- it, so a sequentially exhausted invite — every seat already committed
|
|
818
|
-
-- on this node — is still refused here. What is deliberately NOT
|
|
819
|
-
-- refused: concurrent redeemers on separate nodes (or nodes that have
|
|
820
|
-
-- not yet converged) each count the same committed snapshot and both
|
|
821
|
-
-- land, over-admitting by at most the number of concurrent redeemers.
|
|
822
|
-
-- Both rows survive in this append-only record, so the overage is
|
|
823
|
-
-- auditable, and removal is owner-gated (member removal + Revocation).
|
|
824
|
-
-- Same class as the convergence note on UsageStampId above.
|
|
825
|
-
-- One rule for FUTURE writers: two FormationUsage rows for one token
|
|
826
|
-
-- inserted in ONE transaction each read the same committed count, so
|
|
827
|
-
-- they can jointly exceed the cap. No writer in this repo does that; it
|
|
828
|
-
-- is a constraint on new writers, not a case to engineer for.
|
|
829
|
-
-- Do not "fix" this into a per-token sequence number to restore a
|
|
830
|
-
-- strict cap — that trade was weighed and rejected (2026-08-04): a
|
|
831
|
-
-- fought-over sequence key turns a concurrent redemption into a silent,
|
|
832
|
-
-- unrecoverable loss of a consented join, which is strictly worse than
|
|
833
|
-
-- a visible, reversible over-admission.
|
|
834
|
-
and (FI.TotalUses is null or FI.TotalUses > (select count(1) from committed.FormationUsage U where U.Token = new.Token))
|
|
835
|
-
and (FI.ExpiresAt is null or FI.ExpiresAt > context.Now)
|
|
836
|
-
-- An invite carrying a ValidationUrl demands a sign-off from a key the party
|
|
837
|
-
-- ENROLLED in ValidationKey. The signature is verified against the STORED VK.Key,
|
|
838
|
-
-- NOT against context.ValidationKey — that distinction is the whole point:
|
|
839
|
-
-- context.ValidationKey is a plain insert parameter, so verifying against it asked
|
|
840
|
-
-- only "did the redeemer sign its own disclosure with SOME key it holds?", which any
|
|
841
|
-
-- redeemer answers by minting a throwaway keypair. context.ValidationKey survives
|
|
842
|
-
-- purely to SELECT which enrolled row is being claimed; naming an enrolled key while
|
|
843
|
-
-- signing with a different one fails the verify against VK.Key.
|
|
844
|
-
--
|
|
845
|
-
-- Deliberate: CHECKs run on write only, so removing a validation key later does NOT
|
|
846
|
-
-- re-examine the FormationUsage rows it already approved. The sign-off was valid when
|
|
847
|
-
-- given and the strand it authorized stays formed; removal narrows who may approve
|
|
848
|
-
-- FUTURE redemptions, it is not a retroactive revocation of past ones.
|
|
849
|
-
--
|
|
850
|
-
-- What ONE sign-off buys: exactly ONE row. The digest covers
|
|
851
|
-
-- (Token, UsageStampId, StrandId, PeerKey, Disclosure), so an approval is NOT
|
|
852
|
-
-- transferable across invitations, redemptions, networks, joiners, or disclosure
|
|
853
|
-
-- text. Replay is closed twice over, by two independent mechanisms: presenting an
|
|
854
|
-
-- approval VERBATIM repeats its UsageStampId and is refused by this table's
|
|
855
|
-
-- primary key; presenting it under any OTHER redemption changes a signed field
|
|
856
|
-
-- and fails this verify.
|
|
857
|
-
-- Every signed field is supplied by the redeeming side — nothing derived from
|
|
858
|
-
-- the table's current state is bound — so no concurrent write can invalidate an
|
|
859
|
-
-- approval between the sign-off and the row landing.
|
|
860
|
-
-- Why StrandStampId is deliberately NOT bound: it names the strand ROW
|
|
861
|
-
-- incarnation, which the unbound path (redeemInvitation) mints inside its own
|
|
862
|
-
-- transaction, and it adds nothing on top of a strictly single-use approval —
|
|
863
|
-
-- StrandId already pins WHICH network the approver approved joining.
|
|
864
|
-
and (FI.ValidationUrl is null or exists (
|
|
865
|
-
select 1 from ValidationKey VK
|
|
866
|
-
where VK.Key = context.ValidationKey
|
|
867
|
-
and verify(digest('CadreControl.FormationUsage', 'vouch', new.Token, new.UsageStampId, new.StrandId, new.PeerKey, new.Disclosure), context.ValidationSignature, VK.Key, 'ed25519')))
|
|
868
|
-
-- A bound invite (non-null StrandId) may only ever name its own host strand:
|
|
869
|
-
-- without this, any holder of a bound token could record consent against an
|
|
870
|
-
-- arbitrary strand id — annotating an unrelated strand, or (before
|
|
871
|
-
-- Strand.AuthorizedInsert's consent branch was narrowed to unbound invites)
|
|
872
|
-
-- consent-seating that id outright.
|
|
873
|
-
-- NOTE: an UNBOUND invite is deliberately left free to name any strand, so a
|
|
874
|
-
-- holder can spend a use appending a consent row to an unrelated existing
|
|
875
|
-
-- strand. Harmless today (the row grants nothing, it only burns a use and
|
|
876
|
-
-- forecloses that id's consent-seating, which is the safe direction); if
|
|
877
|
-
-- unlimited-TotalUses invites ever become common, this is an append-only
|
|
878
|
-
-- growth surface worth bounding.
|
|
879
|
-
and (FI.StrandId is null or FI.StrandId = new.StrandId)
|
|
880
|
-
)
|
|
881
|
-
),
|
|
882
|
-
-- Matched on the (id, stamp) PAIR, the same key Strand.AuthorizedInsert's consent branch
|
|
883
|
-
-- reads back: a usage row may only ever name a strand ROW that exists, so a consent record
|
|
884
|
-
-- can never be filed against a stamp of the writer's choosing and held in reserve to
|
|
885
|
-
-- re-seat the id after a removal.
|
|
886
|
-
constraint StrandExists check (exists (select 1 from Strand S where S.Id = new.StrandId and S.StampId = new.StrandStampId)),
|
|
887
|
-
-- The JOINING peer proves it consented to this redemption: PeerKey is its own ed25519
|
|
888
|
-
-- public key and PeerSig is its signature over the 'consent'-tagged digest below.
|
|
889
|
-
-- Unlike the approver's sign-off (context.ValidationSignature, checked against a STORED
|
|
890
|
-
-- ValidationKey row), the identity here IS the key, so there is no enrolled row to look
|
|
891
|
-
-- up and nothing for a writer to substitute: a forged joiner would need that joiner's
|
|
892
|
-
-- private key. Stored rather than passed in context so any later reader can re-check it
|
|
893
|
-
-- (verifyFormationConsent); the 'consent' action tag keeps this replicated signature
|
|
894
|
-
-- useless against every other rule in this schema (notably the approver's 'vouch'
|
|
895
|
-
-- digest over the same table).
|
|
896
|
-
-- NOTE: StrandId is deliberately NOT in this digest — the joiner cannot know it when it
|
|
897
|
-
-- signs (a bound invite's host strand arrives only in the result frame; an unbound
|
|
898
|
-
-- strand is responder-minted). The responder cannot substitute a strand anyway: bound
|
|
899
|
-
-- invites are pinned by Authorized's FI.StrandId check, unbound invites mint fresh.
|
|
900
|
-
constraint PeerConsented check on insert (
|
|
901
|
-
verify(digest('CadreControl.FormationUsage', 'consent',
|
|
902
|
-
new.Token, new.UsageStampId, new.PeerKey, new.Disclosure),
|
|
903
|
-
new.PeerSig, new.PeerKey, 'ed25519')
|
|
904
|
-
),
|
|
905
|
-
-- Context here is only what the approver-side rules read: Now for expiry, and the
|
|
906
|
-
-- ValidationKey/ValidationSignature pair for the 'vouch' check in Authorized. The joiner's
|
|
907
|
-
-- signature is NOT context — it lives on the row (PeerSig, verified by PeerConsented above).
|
|
908
|
-
) with context (Now datetime, ValidationKey text null, ValidationSignature text null);
|
|
909
|
-
|
|
910
|
-
-- Token is no longer a primary-key prefix (the key is the redemption nonce), so the
|
|
911
|
-
-- per-token filters — the cap count in Authorized above, and cadre-core's
|
|
912
|
-
-- countFormationUsage / isTokenUsed / hasOutstandingFormationInvite — are served by this
|
|
913
|
-
-- index rather than by a full scan of a table that is append-only and grows for the life
|
|
914
|
-
-- of the party.
|
|
915
|
-
--
|
|
916
|
-
-- The cap count is only ever as correct as this index's convergence across machines. That
|
|
917
|
-
-- convergence failed once: from 2026-08-04 to 2026-08-25 a descent on a second machine
|
|
918
|
-
-- returned only the rows THAT machine wrote, so the index was removed and the reads went
|
|
919
|
-
-- back to the scan. The engine defect was fixed upstream and re-measured here on
|
|
920
|
-
-- 2026-09-17, so the index is declared again. Its guard is the integration-tests scenario
|
|
921
|
-
-- \`strand-formation-concurrent-redemption\`, which asserts BOTH machines' views of a raced
|
|
922
|
-
-- redemption and therefore goes red if that convergence regresses.
|
|
923
|
-
--
|
|
924
|
-
-- NOTE: the write side has its own exposure. Every FormationUsage insert now maintains this
|
|
925
|
-
-- sub-collection as well as the table, and an intermittent engine failure once hit exactly that
|
|
926
|
-
-- step on other tables (a table's rows committed while its index did not; closed 2026-09-17 with
|
|
927
|
-
-- the upstream sync fixes, \`tickets/complete/strand-unique-index-sync-stale-revision\`). Nothing
|
|
928
|
-
-- has been observed here, and redemptions are rare writes; but if joins start failing
|
|
929
|
-
-- intermittently with an index-sync error naming FormationUsage, this declaration is the first
|
|
930
|
-
-- thing to suspect.
|
|
931
|
-
index FormationUsageByToken on FormationUsage (Token);
|
|
932
|
-
|
|
933
|
-
-- Append-only retirement record for the one-off StampId nonces of removed rows of every
|
|
934
|
-
-- guarded table (listed on TableName below). Without it a removal was undoable: the add
|
|
935
|
-
-- approval is a signature over
|
|
936
|
-
-- (row key, stamp) that never expires, and deleting the row freed the stamp, so anyone who
|
|
937
|
-
-- kept a copy of the approval could resurrect the row.
|
|
938
|
-
-- Each tombstone also records WHICH row was retired (RowKey below): the consent branch of
|
|
939
|
-
-- Strand.AuthorizedInsert reads it to refuse consent-seating any strand id that has ever
|
|
940
|
-
-- been removed, whichever way it was seated.
|
|
941
|
-
-- NOTE: the guarded tables' NotRevoked CHECK runs against locally visible rows, so a node
|
|
942
|
-
-- that has not yet converged on a Revocation row can still accept the replayed add, and the
|
|
943
|
-
-- resurrected row coexists with the tombstone after merge — same class as the MinOneOwner
|
|
944
|
-
-- note on OwnerKey. The read-side mitigation is ControlDatabase.queryCadrePeers, which
|
|
945
|
-
-- drops any CadrePeer row whose StampId appears here; every membership reader inherits it.
|
|
946
|
-
-- NOTE: append-only, so this table only ever grows. Every append is owner-signed
|
|
947
|
-
-- (Authorized below), so the growth surface is the owner keys, not every writer that can
|
|
948
|
-
-- reach the control database. Cadres are a handful of peers and owner rotation is rare, so
|
|
949
|
-
-- unbounded growth is fine today; revisit if either changes.
|
|
950
|
-
-- A tombstone committed while the node was alone is local-only (never broadcast); the
|
|
951
|
-
-- ReissuedAt counter below exists so an owner can re-write — and therefore re-broadcast —
|
|
952
|
-
-- such a tombstone once peers are reachable, without changing what it means.
|
|
953
|
-
-- One row retires nothing: the singleton ledger marker ('Revocation', 'ledger', 'opened'),
|
|
954
|
-
-- filed once by an owner's connected reconcile pass (ControlDatabase.openRevocationLedger).
|
|
955
|
-
-- It exists only so this table is never a never-written block. The storage layer consults
|
|
956
|
-
-- a block's cohort on EVERY read of a block it does not hold, and every membership lookup
|
|
957
|
-
-- and every guarded insert (NotRevoked) reads this table; once any row exists the block is
|
|
958
|
-
-- held and re-checked on the storage layer's normal read-repair schedule, like every other
|
|
959
|
-
-- populated table. It cannot read as a retirement: every reader of this table filters on
|
|
960
|
-
-- its own guarded TableName, 'Revocation' is not one, and ControlDatabase.queryRevocations
|
|
961
|
-
-- skips the marker, so nothing reaps or re-issues it.
|
|
962
|
-
table Revocation (
|
|
963
|
-
TableName text, -- 'OwnerKey' | 'CadrePeer' | 'ValidationKey' | 'Strand' | 'StrandPartyKey' |
|
|
964
|
-
-- 'JoinedStrand' | 'PendingJoin' | 'DeviceToken', or 'Revocation' for the
|
|
965
|
-
-- ledger marker only (all confined by RowIsGone below)
|
|
966
|
-
RowKey text not null, -- primary key of the removed row: OwnerKey.Key / ValidationKey.Key /
|
|
967
|
-
-- CadrePeer.PeerId / DeviceToken.PeerId / Strand.Id / StrandPartyKey.Id /
|
|
968
|
-
-- JoinedStrand.Id / PendingJoin.Id
|
|
969
|
-
-- Every guarded table's RevocationRecorded CHECK requires the
|
|
970
|
-
-- accompanying tombstone to carry the removed row's key here, so
|
|
971
|
-
-- a REMOVAL cannot file a misnamed tombstone. A tombstone with no
|
|
972
|
-
-- accompanying delete is not covered by that (see Authorized).
|
|
973
|
-
StampId text, -- the retired nonce
|
|
974
|
-
-- Bumped by an owner-signed re-issue so a tombstone written while the node was alone
|
|
975
|
-
-- (committed local-only, never broadcast) can be re-written and therefore re-broadcast
|
|
976
|
-
-- on cohort growth. Carries NO semantics: nothing reads it, and retirement is decided
|
|
977
|
-
-- by the row's existence, not by this value.
|
|
978
|
-
ReissuedAt integer not null default 0,
|
|
979
|
-
-- Keyed on the stamp, not the RowKey: stamps are unique per row incarnation, and one
|
|
980
|
-
-- name may legitimately carry several tombstones over its life (seat -> delete ->
|
|
981
|
-
-- owner re-seat -> delete).
|
|
982
|
-
primary key (TableName, StampId),
|
|
983
|
-
-- Retirement is permanent: a tombstone may never be withdrawn.
|
|
984
|
-
constraint NoDelete check on delete (false),
|
|
985
|
-
-- Pinned at 0 on insert so an owner cannot seat a tombstone at a saturated counter and
|
|
986
|
-
-- thereby freeze its own later re-issues (ReissueOnly below). Deliberately NOT folded
|
|
987
|
-
-- into the Authorized digest: the value is fixed by this rule, so signing over it would
|
|
988
|
-
-- only widen the signed surface for no gain, and would invalidate every existing
|
|
989
|
-
-- insert-side digest.
|
|
990
|
-
constraint FreshTombstone check on insert (new.ReissuedAt = 0),
|
|
991
|
-
-- A re-issue may move NOTHING but the counter, and only upward. Without the identity
|
|
992
|
-
-- clause an "update" would be a way to re-point a tombstone at a different row,
|
|
993
|
-
-- restoring exactly the replay this table exists to stop.
|
|
994
|
-
constraint ReissueOnly check on update (
|
|
995
|
-
new.TableName = old.TableName and new.RowKey = old.RowKey
|
|
996
|
-
and new.StampId = old.StampId and new.ReissuedAt > old.ReissuedAt
|
|
997
|
-
),
|
|
998
|
-
-- A stamp may only be retired once its row is actually gone. Deferred (subquery), so a
|
|
999
|
-
-- delete in the same transaction has already landed. Retiring a stamp that never
|
|
1000
|
-
-- existed is permitted and harmless: a stamp carries 128 bits of CSPRNG output
|
|
1001
|
-
-- (control-database.ts:generateStampId — 16 bytes of sha256(PeerId) followed by 16
|
|
1002
|
-
-- random bytes), so a future legitimate one cannot be guessed and pre-planted.
|
|
1003
|
-
-- Deliberately keyed on the STAMP only, not RowKey: checking "no live row named
|
|
1004
|
-
-- new.RowKey" breaks under out-of-order convergence — a peer removed (tombstone names
|
|
1005
|
-
-- it, stamp1) then re-admitted (stamp2) would leave a node that converges on the
|
|
1006
|
-
-- re-add FIRST rejecting the stamp1 tombstone forever, never learning that stamp is
|
|
1007
|
-
-- retired. The stamp-only form passes there (stamp1 is not live).
|
|
1008
|
-
-- The last branch admits the ledger marker (see the table comment) and nothing else under
|
|
1009
|
-
-- TableName 'Revocation': the whole triple is pinned, so with the primary key
|
|
1010
|
-
-- (TableName, StampId) it is a singleton and the append-only growth surface is unchanged.
|
|
1011
|
-
-- 'opened' cannot collide with a real stamp (43 base64url characters, generateStampId),
|
|
1012
|
-
-- and the primary key includes TableName anyway.
|
|
1013
|
-
constraint RowIsGone check on insert (
|
|
1014
|
-
(new.TableName = 'OwnerKey' and not exists (select 1 from OwnerKey K where K.StampId = new.StampId))
|
|
1015
|
-
or (new.TableName = 'CadrePeer' and not exists (select 1 from CadrePeer P where P.StampId = new.StampId))
|
|
1016
|
-
or (new.TableName = 'ValidationKey' and not exists (select 1 from ValidationKey V where V.StampId = new.StampId))
|
|
1017
|
-
or (new.TableName = 'Strand' and not exists (select 1 from Strand S where S.StampId = new.StampId))
|
|
1018
|
-
or (new.TableName = 'StrandPartyKey' and not exists (select 1 from StrandPartyKey K where K.StampId = new.StampId))
|
|
1019
|
-
or (new.TableName = 'JoinedStrand' and not exists (select 1 from JoinedStrand J where J.StampId = new.StampId))
|
|
1020
|
-
or (new.TableName = 'PendingJoin' and not exists (select 1 from PendingJoin P where P.StampId = new.StampId))
|
|
1021
|
-
or (new.TableName = 'DeviceToken' and not exists (select 1 from DeviceToken D where D.StampId = new.StampId))
|
|
1022
|
-
or (new.TableName = 'Revocation' and new.RowKey = 'ledger' and new.StampId = 'opened')
|
|
1023
|
-
),
|
|
1024
|
-
-- Appending a tombstone is an OWNER action, like every other write in this schema.
|
|
1025
|
-
-- Ungated, any writer that could reach the control database could retire a stamp:
|
|
1026
|
-
-- filing one against a CadrePeer row not visible locally (RowIsGone reads LOCALLY
|
|
1027
|
-
-- VISIBLE rows — see the convergence note above) evicted that peer party-wide AND
|
|
1028
|
-
-- permanently blocked the owner's own later re-admission of it (NotRevoked), and
|
|
1029
|
-
-- filing arbitrary stamps flooded a table whose rows never go away.
|
|
1030
|
-
-- The digest binds the WHOLE row (TableName, RowKey, StampId); the 'CadreControl.Revocation'
|
|
1031
|
-
-- domain tag keeps it disjoint from every other rule — including the
|
|
1032
|
-
-- 'CadreControl.CadrePeer' 'remove' digest the same owner signs in the SAME
|
|
1033
|
-
-- transaction for the delete this tombstone accompanies.
|
|
1034
|
-
-- RowKey is not cross-checked HERE against the retired row: positively binding it (e.g.
|
|
1035
|
-
-- requiring a committed.Strand row carrying the pair) would reject a tombstone re-issued
|
|
1036
|
-
-- in a LATER transaction — which the delete-while-alone durability path
|
|
1037
|
-
-- (docs/architecture.md) plans to do — and reject it outright on a node that never
|
|
1038
|
-
-- converged on the removed row. The binding lives on the other side instead: each
|
|
1039
|
-
-- guarded table's RevocationRecorded requires the tombstone accompanying a DELETE to
|
|
1040
|
-
-- name that row's key, which the re-issue path never trips (it files no delete).
|
|
1041
|
-
-- Residual: a STANDALONE tombstone — owner-signed, naming a stamp no live row holds —
|
|
1042
|
-
-- is still accepted, so an owner can name an id that never existed and thereby
|
|
1043
|
-
-- permanently foreclose CONSENT-seating of that id (Strand.AuthorizedInsert).
|
|
1044
|
-
-- Owner-only, the owner already controls invite issuance, and unbound ids are 128
|
|
1045
|
-
-- random bytes minted at redemption — no escalation (same reasoning as the pre-plant
|
|
1046
|
-
-- note on RowIsGone).
|
|
1047
|
-
-- Reads LIVE OwnerKey (like ValidationKey / Strand / CadrePeer / DeviceToken), not
|
|
1048
|
-
-- committed.OwnerKey. The one difference that makes: a founding transaction on an
|
|
1049
|
-
-- owner-less database could seat an owner key and file a tombstone in one go. An
|
|
1050
|
-
-- owner-less control database is already a total loss, and a second transaction
|
|
1051
|
-
-- achieves the same thing under committed.*, so consistency with the siblings is
|
|
1052
|
-
-- worth more than the distinction — do not "tighten" this without a reason other
|
|
1053
|
-
-- than that one.
|
|
1054
|
-
-- RowIsGone and NoDelete are unchanged: they guard an owner retiring a stamp early
|
|
1055
|
-
-- or withdrawing one later, which authorization does not cover.
|
|
1056
|
-
-- The ledger marker is signed under this same rule, over
|
|
1057
|
-
-- digest('CadreControl.Revocation', 'remove', 'Revocation', 'ledger', 'opened'). The
|
|
1058
|
-
-- 'remove' tag on a row that retires nothing is deliberate: reusing the one append rule
|
|
1059
|
-
-- keeps every append owner-signed without adding an unsigned or differently tagged
|
|
1060
|
-
-- branch, and a captured marker signature can only re-file the identical row, whose
|
|
1061
|
-
-- primary key is already taken.
|
|
1062
|
-
constraint Authorized check on insert (
|
|
1063
|
-
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and verify(digest('CadreControl.Revocation', 'remove', new.TableName, new.RowKey, new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
1064
|
-
),
|
|
1065
|
-
-- A re-issue is an OWNER action, like the original append. Distinct 'reissue' action
|
|
1066
|
-
-- tag, so an append approval can never be replayed as a re-issue and vice versa. The
|
|
1067
|
-
-- digest adds ReissuedAt so a captured re-issue signature cannot bump the counter to
|
|
1068
|
-
-- any other value. Reads LIVE OwnerKey, matching Authorized above.
|
|
1069
|
-
constraint AuthorizedReissue check on update (
|
|
1070
|
-
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey
|
|
1071
|
-
and verify(digest('CadreControl.Revocation', 'reissue',
|
|
1072
|
-
new.TableName, new.RowKey, new.StampId, cast(new.ReissuedAt as text)),
|
|
1073
|
-
context.Signature, A.Key, 'ed25519'))
|
|
1074
|
-
)
|
|
1075
|
-
) with context (OwnerKey text, Signature text);
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
apply schema CadreControl;`;
|
|
1
|
+
/**
|
|
2
|
+
* Embedded control schema for cross-platform compatibility.
|
|
3
|
+
*
|
|
4
|
+
* This is the authoritative runtime copy of the CadreControl authorization
|
|
5
|
+
* schema. It is duplicated from `schemas/control.qsql` so that React Native and
|
|
6
|
+
* other filesystem-less environments get the schema without a runtime file read.
|
|
7
|
+
*
|
|
8
|
+
* The two copies MUST stay identical — `control-schema-drift.spec.ts` fails the
|
|
9
|
+
* build if they drift. Any edit here must be mirrored in `schemas/control.qsql`
|
|
10
|
+
* and vice versa.
|
|
11
|
+
*/
|
|
12
|
+
export const CONTROL_SCHEMA = `-- A Sereus party's cadre (its nodes) and their participation in strands (networks).
|
|
13
|
+
--
|
|
14
|
+
-- Every write is authorized by a check: an owner signs an action-tagged digest of the row
|
|
15
|
+
-- (cadre-core control-authorization.ts), or a peer signs its own record. Each digest leads
|
|
16
|
+
-- with a 'CadreControl.<Table>' domain tag, an action tag and party_id(), the party this
|
|
17
|
+
-- machine is configured for (a zero-argument function ControlDatabase registers on its own
|
|
18
|
+
-- engine, never read from a context value or a replicated table), so an approval verifies
|
|
19
|
+
-- only against the one rule, in the one party, it was minted for: two parties that share
|
|
20
|
+
-- an owner key never accept each other's approvals. FormationUsage is the exception, its
|
|
21
|
+
-- two digests scoped by the invitation token instead (FormationUsage.Authorized).
|
|
22
|
+
--
|
|
23
|
+
-- Rows of the guarded tables (OwnerKey, ValidationKey, Strand, StrandPartyKey, JoinedStrand,
|
|
24
|
+
-- JoinRequest, CadrePeer, DeviceToken, CadreInvite) carry a one-off StampId bound into their
|
|
25
|
+
-- add and remove digests. \`unique\` holds over live rows only, so a delete retires the stamp
|
|
26
|
+
-- into Revocation in the same transaction (RevocationRecorded) and an insert refuses a retired
|
|
27
|
+
-- stamp (NotRevoked): the never-expiring add approval cannot re-seat a removed row. A
|
|
28
|
+
-- legitimate re-add mints a fresh stamp and a fresh signature. CadreInvite is the one guarded
|
|
29
|
+
-- table that is never deleted: its tombstone withdraws the invitation while the row stays,
|
|
30
|
+
-- because the rows it admitted prove their membership through it.
|
|
31
|
+
--
|
|
32
|
+
-- A check whose expression evaluates to null passes (SQL three-valued logic), so every
|
|
33
|
+
-- comparison over a nullable column that is meant to pin a value is written null-safe
|
|
34
|
+
-- (\`coalesce(col, '')\` or an explicit \`is null\`); a bare \`new.Col = context.X\` over a null
|
|
35
|
+
-- column would pass with nothing pinned.
|
|
36
|
+
--
|
|
37
|
+
-- A check with a subquery defers to commit, so a sibling row written in the same transaction
|
|
38
|
+
-- is visible to it; \`committed.<Table>\` reads the pre-transaction snapshot instead. Every
|
|
39
|
+
-- check reads the rows this node holds: a node that has not converged on a Revocation row
|
|
40
|
+
-- still accepts the replayed add, and the resurrected row then coexists with its tombstone.
|
|
41
|
+
-- ControlDatabase drops retired stamps on the reads that matter (queryCadrePeers,
|
|
42
|
+
-- queryPendingJoins, getOwnerKeys), and every owner lookup in the checks below drops them
|
|
43
|
+
-- too (the \`not exists ... Revocation\` conjunct beside each OwnerKey read, reading live
|
|
44
|
+
-- Revocation so a tombstone filed in the same transaction counts), so a removal is
|
|
45
|
+
-- effective at the writer as soon as its tombstone arrives, whether or not the row's delete
|
|
46
|
+
-- has. Only the founding count in OwnerKey.Authorized stays raw.
|
|
47
|
+
declare schema CadreControl {
|
|
48
|
+
-- A key that can authorize control changes. A row is seated one of three ways, told apart
|
|
49
|
+
-- by the vouch columns: the founding row (all three null), an owner-signed add (VouchOwner
|
|
50
|
+
-- and VouchSig pinned to the insert context, VouchUsage null), or an owner-granting
|
|
51
|
+
-- invitation redeemed by consent (VouchOwner = the invitation's IssuerKey, VouchSig null,
|
|
52
|
+
-- VouchUsage = the CadreInviteUsage row that admitted it). A reader judges the stored proof
|
|
53
|
+
-- against its node-local anchor, never against this replicated table.
|
|
54
|
+
table OwnerKey (
|
|
55
|
+
Key text primary key,
|
|
56
|
+
StampId text unique,
|
|
57
|
+
VouchOwner text null,
|
|
58
|
+
VouchSig text null,
|
|
59
|
+
VouchUsage text null,
|
|
60
|
+
constraint NotRevoked check on insert (
|
|
61
|
+
not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = new.StampId)
|
|
62
|
+
),
|
|
63
|
+
-- The tombstone must name the removed row, not just its stamp (Revocation.RowKey).
|
|
64
|
+
constraint RevocationRecorded check on delete (
|
|
65
|
+
exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = old.StampId and R.RowKey = old.Key)
|
|
66
|
+
),
|
|
67
|
+
-- Every other table's checks require an owner, so an empty table is a permanent denial of
|
|
68
|
+
-- the party's control plane. Counted post-delete, on this node's rows only: two partitioned
|
|
69
|
+
-- nodes removing different owners can still converge to zero.
|
|
70
|
+
constraint MinOneOwner check on delete (
|
|
71
|
+
(select count(1) from OwnerKey) >= 1
|
|
72
|
+
),
|
|
73
|
+
-- Rotation is add-then-remove. An update branch would let the sole owner be re-pointed at
|
|
74
|
+
-- another key under a post-image count of one.
|
|
75
|
+
constraint NoUpdate check on update (false),
|
|
76
|
+
-- The authorizer is read from the pre-transaction snapshot: the check defers to commit, by
|
|
77
|
+
-- which point the inserted row (and any sibling) is live, so a plain OwnerKey read would let
|
|
78
|
+
-- a row authorize itself or two strangers seat each other. The founding transaction, whose
|
|
79
|
+
-- pre-transaction owner set is empty, needs no authorization; gating on the pre-transaction
|
|
80
|
+
-- count keeps a same-transaction swap of the sole owner off that branch. That count is
|
|
81
|
+
-- deliberately raw, the one owner read here that ignores Revocation: a machine holding only
|
|
82
|
+
-- a retired owner row must still be refused a second genesis, or a removed device could
|
|
83
|
+
-- re-found the party on its own copy. An owner cannot sign its own removal.
|
|
84
|
+
-- The consent branch seats an owner with no signature at all: a CadreInviteUsage row
|
|
85
|
+
-- written in the same transaction names this exact row (Key and stamp), and the
|
|
86
|
+
-- invitation it redeemed grants ownership and was issued by the stored VouchOwner. The
|
|
87
|
+
-- invitation is read from committed.CadreInvite, so an invitation cannot be seated and
|
|
88
|
+
-- redeemed in one transaction; the usage row carries the liveness conditions.
|
|
89
|
+
constraint Authorized check on insert, delete (
|
|
90
|
+
(old.Key is null and (select count(1) from committed.OwnerKey) = 0
|
|
91
|
+
and new.VouchOwner is null and new.VouchSig is null and new.VouchUsage is null)
|
|
92
|
+
or (old.Key is null and exists (select 1 from committed.OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.OwnerKey', 'add', party_id(), new.Key, new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
93
|
+
and coalesce(new.VouchOwner, '') = context.OwnerKey
|
|
94
|
+
and coalesce(new.VouchSig, '') = context.Signature
|
|
95
|
+
and new.VouchUsage is null)
|
|
96
|
+
or (old.Key is null and new.VouchSig is null and new.VouchUsage is not null
|
|
97
|
+
and exists (
|
|
98
|
+
select 1 from CadreInviteUsage U
|
|
99
|
+
where U.UsageStampId = new.VouchUsage
|
|
100
|
+
and U.PeerKey = new.Key
|
|
101
|
+
and U.OwnerStampId = new.StampId
|
|
102
|
+
and exists (select 1 from committed.CadreInvite I where I.Key = U.InviteKey and I.GrantsOwner = 1 and I.IssuerKey = new.VouchOwner)
|
|
103
|
+
))
|
|
104
|
+
or (new.Key is null and exists (select 1 from committed.OwnerKey A where A.Key = context.OwnerKey and A.Key <> old.Key and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.OwnerKey', 'remove', party_id(), old.Key, old.StampId), context.Signature, A.Key, 'ed25519')))
|
|
105
|
+
)
|
|
106
|
+
) with context (OwnerKey text null, Signature text null);
|
|
107
|
+
|
|
108
|
+
-- A key that can validate a strand formation disclosure (FormationUsage.Authorized).
|
|
109
|
+
table ValidationKey (
|
|
110
|
+
Key text primary key,
|
|
111
|
+
StampId text unique,
|
|
112
|
+
constraint NotRevoked check on insert (
|
|
113
|
+
not exists (select 1 from Revocation R where R.TableName = 'ValidationKey' and R.StampId = new.StampId)
|
|
114
|
+
),
|
|
115
|
+
constraint RevocationRecorded check on delete (
|
|
116
|
+
exists (select 1 from Revocation R where R.TableName = 'ValidationKey' and R.StampId = old.StampId and R.RowKey = old.Key)
|
|
117
|
+
),
|
|
118
|
+
constraint NoUpdate check on update (false),
|
|
119
|
+
constraint AuthorizedInsert check on insert (
|
|
120
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.ValidationKey', 'add', party_id(), new.Key, new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
121
|
+
),
|
|
122
|
+
-- Owner-signed over the stored row, or a reap: a committed tombstone naming this exact row
|
|
123
|
+
-- incarnation lets a node that was offline at removal time delete the stale row unsigned
|
|
124
|
+
-- (ControlDatabase.reapRevokedRow). committed.*, so a tombstone filed in this transaction
|
|
125
|
+
-- cannot stand in for the signature; the stamp clause, so a tombstone of an earlier
|
|
126
|
+
-- incarnation cannot remove the current one.
|
|
127
|
+
constraint AuthorizedDelete check on delete (
|
|
128
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.ValidationKey', 'remove', party_id(), old.Key, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
129
|
+
or exists (select 1 from committed.Revocation R where R.TableName = 'ValidationKey' and R.RowKey = old.Key and R.StampId = old.StampId)
|
|
130
|
+
)
|
|
131
|
+
) with context (OwnerKey text, Signature text);
|
|
132
|
+
|
|
133
|
+
-- A network of members sharing an sApp database, each contributing its cadre's peers. This
|
|
134
|
+
-- party's own strands; a strand joined from another party is a JoinedStrand row.
|
|
135
|
+
table Strand (
|
|
136
|
+
Id text primary key, -- UUID
|
|
137
|
+
MemberPrivateKey text null unique, -- the strand's shared read secret; closed strands only
|
|
138
|
+
Type text, -- 'o' open | 'c' closed: open gates writes in the sApp, only closed gates reads
|
|
139
|
+
FounderOwnerKey text null, -- owner key of the machine that published the row, the founding machine
|
|
140
|
+
-- (cadre-node.ts launchStrand); null on a consent-seated strand, whose
|
|
141
|
+
-- insert carries no signature. Provenance, not content (strandRowMismatches).
|
|
142
|
+
StampId text unique,
|
|
143
|
+
constraint NotRevoked check on insert (
|
|
144
|
+
not exists (select 1 from Revocation R where R.TableName = 'Strand' and R.StampId = new.StampId)
|
|
145
|
+
),
|
|
146
|
+
constraint RevocationRecorded check on delete (
|
|
147
|
+
exists (select 1 from Revocation R where R.TableName = 'Strand' and R.StampId = old.StampId and R.RowKey = old.Id)
|
|
148
|
+
),
|
|
149
|
+
-- The consent branch below carries no signature, so an update rule would let anyone rewrite
|
|
150
|
+
-- a consent-seated strand.
|
|
151
|
+
constraint NoUpdate check on update (false),
|
|
152
|
+
-- Owner-signed, with FounderOwnerKey pinned to the verified signer; or consent-seated by a
|
|
153
|
+
-- FormationUsage row naming this exact row (id and stamp), written in the same transaction
|
|
154
|
+
-- (ControlDatabase.redeemInvitation). Binding the stamp is what makes a removal stick:
|
|
155
|
+
-- the usage row outlives the strand, and keyed on the id alone it would re-authorize an
|
|
156
|
+
-- unsigned re-seat under a fresh stamp. The consent branch is narrow, each clause closing
|
|
157
|
+
-- one door:
|
|
158
|
+
-- * open and keyless: a closed strand with a caller-chosen read secret has no legitimate
|
|
159
|
+
-- producer;
|
|
160
|
+
-- * through an unbound invite only: a bound invite's host strand is owner-provisioned,
|
|
161
|
+
-- and consent-seating its id would downgrade the real row on a node it has not reached;
|
|
162
|
+
-- * no usage row under another stamp, and no tombstone for the id: an id is consent-seated
|
|
163
|
+
-- once, ever, and never after any removal. Re-joining a removed id is owner-signed.
|
|
164
|
+
-- A standalone tombstone (no accompanying delete, Revocation.Authorized) lets an owner
|
|
165
|
+
-- foreclose consent-seating of an id that never existed: owner-only, and ids are random.
|
|
166
|
+
constraint AuthorizedInsert check on insert (
|
|
167
|
+
(exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.Strand', 'add', party_id(), new.Id, new.Type, coalesce(new.MemberPrivateKey, ''), new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
168
|
+
and new.FounderOwnerKey = context.OwnerKey)
|
|
169
|
+
or (
|
|
170
|
+
new.Type = 'o'
|
|
171
|
+
and new.MemberPrivateKey is null
|
|
172
|
+
and new.FounderOwnerKey is null
|
|
173
|
+
and exists (
|
|
174
|
+
select 1 from FormationUsage FU
|
|
175
|
+
where FU.StrandId = new.Id
|
|
176
|
+
and FU.StrandStampId = new.StampId
|
|
177
|
+
and exists (select 1 from FormationInvite FI where FI.Token = FU.Token and FI.StrandId is null)
|
|
178
|
+
)
|
|
179
|
+
and not exists (
|
|
180
|
+
select 1 from FormationUsage FU2
|
|
181
|
+
where FU2.StrandId = new.Id and FU2.StrandStampId <> new.StampId
|
|
182
|
+
)
|
|
183
|
+
and not exists (
|
|
184
|
+
select 1 from Revocation R
|
|
185
|
+
where R.TableName = 'Strand' and R.RowKey = new.Id
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
),
|
|
189
|
+
-- No consent branch (an invitation forms a strand, never destroys one) and no reap branch:
|
|
190
|
+
-- MemberPrivateKey is stored nowhere else, so this delete is unrecoverable
|
|
191
|
+
-- (tickets/backlog/debt-strand-tombstone-reap.md owns any change).
|
|
192
|
+
constraint AuthorizedDelete check on delete (
|
|
193
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.Strand', 'remove', party_id(), old.Id, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
194
|
+
),
|
|
195
|
+
-- An open strand has no membership gate, so no member key.
|
|
196
|
+
constraint MemberKeyClosedOnly check (
|
|
197
|
+
new.MemberPrivateKey is null or new.Type = 'c'
|
|
198
|
+
)
|
|
199
|
+
) with context (OwnerKey text, Signature text);
|
|
200
|
+
|
|
201
|
+
-- This party's own membership identity for one strand: the private key whose public half
|
|
202
|
+
-- seats its Strand.Member / Strand.Manager rows. Separate from Strand.MemberPrivateKey, which
|
|
203
|
+
-- every joining party receives and so could forge (gotchoices/sereus#4). A side table because
|
|
204
|
+
-- a joiner holds no Strand row. Replicated in plaintext to every machine the party owns
|
|
205
|
+
-- (docs/strands.md → "Closed-Strand Member Key Handling") but never put on the formation wire.
|
|
206
|
+
table StrandPartyKey (
|
|
207
|
+
Id text primary key, -- the strand id
|
|
208
|
+
PrivateKey text, -- ed25519, base64 protobuf, as Strand.MemberPrivateKey (cadre-core strandMemberKeyPair)
|
|
209
|
+
StampId text unique,
|
|
210
|
+
constraint NotRevoked check on insert (
|
|
211
|
+
not exists (select 1 from Revocation R where R.TableName = 'StrandPartyKey' and R.StampId = new.StampId)
|
|
212
|
+
),
|
|
213
|
+
constraint RevocationRecorded check on delete (
|
|
214
|
+
exists (select 1 from Revocation R where R.TableName = 'StrandPartyKey' and R.StampId = old.StampId and R.RowKey = old.Id)
|
|
215
|
+
),
|
|
216
|
+
constraint NoUpdate check on update (false),
|
|
217
|
+
-- Binding PrivateKey means a captured approval can only reproduce the key it approved.
|
|
218
|
+
constraint AuthorizedInsert check on insert (
|
|
219
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.StrandPartyKey', 'add', party_id(), new.Id, new.PrivateKey, new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
220
|
+
),
|
|
221
|
+
-- No reap branch: the key is stored nowhere else (as Strand.AuthorizedDelete).
|
|
222
|
+
constraint AuthorizedDelete check on delete (
|
|
223
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.StrandPartyKey', 'remove', party_id(), old.Id, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
224
|
+
)
|
|
225
|
+
) with context (OwnerKey text, Signature text);
|
|
226
|
+
|
|
227
|
+
-- A strand this party joined from another party, whose control database holds the Strand
|
|
228
|
+
-- row. Every machine of the party reads it, so a replica host keeps a copy and the party's
|
|
229
|
+
-- other machines can attach. A separate table because every reader of Strand takes it to
|
|
230
|
+
-- mean this party's own strand. MemberPrivateKey is held by the founding party and every
|
|
231
|
+
-- member, so a removed row is recoverable by re-forming, which is why this table has a reap
|
|
232
|
+
-- branch (unlike Strand and StrandPartyKey).
|
|
233
|
+
table JoinedStrand (
|
|
234
|
+
Id text primary key, -- the founder's Strand.Id
|
|
235
|
+
Type text, -- 'o' | 'c', as Strand.Type
|
|
236
|
+
MemberPrivateKey text null, -- the closed strand's shared read secret
|
|
237
|
+
StampId text unique,
|
|
238
|
+
constraint NotRevoked check on insert (
|
|
239
|
+
not exists (select 1 from Revocation R where R.TableName = 'JoinedStrand' and R.StampId = new.StampId)
|
|
240
|
+
),
|
|
241
|
+
constraint RevocationRecorded check on delete (
|
|
242
|
+
exists (select 1 from Revocation R where R.TableName = 'JoinedStrand' and R.StampId = old.StampId and R.RowKey = old.Id)
|
|
243
|
+
),
|
|
244
|
+
constraint NoUpdate check on update (false),
|
|
245
|
+
-- Readers cast Type (ControlDatabase.queryJoinedStrands).
|
|
246
|
+
constraint KnownType check (new.Type = 'o' or new.Type = 'c'),
|
|
247
|
+
constraint MemberKeyClosedOnly check (new.MemberPrivateKey is null or new.Type = 'c'),
|
|
248
|
+
-- Owner-signed only: every always-on machine of the party downloads the strands named
|
|
249
|
+
-- here, so a machine that is not an owner keeps its joins machine-local.
|
|
250
|
+
constraint AuthorizedInsert check on insert (
|
|
251
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.JoinedStrand', 'add', party_id(), new.Id, new.Type, coalesce(new.MemberPrivateKey, ''), new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
252
|
+
),
|
|
253
|
+
constraint AuthorizedDelete check on delete (
|
|
254
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.JoinedStrand', 'remove', party_id(), old.Id, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
255
|
+
or exists (select 1 from committed.Revocation R where R.TableName = 'JoinedStrand' and R.RowKey = old.Id and R.StampId = old.StampId)
|
|
256
|
+
)
|
|
257
|
+
) with context (OwnerKey text, Signature text);
|
|
258
|
+
|
|
259
|
+
-- A join this party asked for by redeeming another party's invitation, kept party-wide so
|
|
260
|
+
-- the request outlives the device that asked and any owner machine can carry it on
|
|
261
|
+
-- (docs/strands.md → "Joining while the inviter is offline"). The row is the request alone
|
|
262
|
+
-- and never changes; its outcome is a JoinSuccess or JoinFailure row keyed by this row's
|
|
263
|
+
-- stamp, so asking again (a fresh stamp) starts clean and a dismissal's tombstone retires
|
|
264
|
+
-- the outcome with the request. Invitation is a bearer credential, replicated in plaintext
|
|
265
|
+
-- to every machine the party owns, under the same accepted risk as JoinedStrand.
|
|
266
|
+
-- Owner-signed only; whether a machine that is not an owner may write here is
|
|
267
|
+
-- tickets/blocked/decide-non-owner-machine-completes-a-pending-join.md.
|
|
268
|
+
-- The three tables reference only tables declared before them, so an apply that fails
|
|
269
|
+
-- midway can drop them in reverse order. The two rules that would close a cycle are the
|
|
270
|
+
-- writer's (ControlDatabase): a request's delete takes its outcome row with it, and a join
|
|
271
|
+
-- recorded over a failure deletes the failure. An outcome row left behind is unreadable,
|
|
272
|
+
-- since readers start from the request.
|
|
273
|
+
table JoinRequest (
|
|
274
|
+
Id text primary key, -- base64url sha256 of the invitation token (cadre-core pendingJoinId),
|
|
275
|
+
-- so the token never reaches Revocation
|
|
276
|
+
Invitation text, -- CadreNode.encodeInvitation
|
|
277
|
+
Disclosure text, -- canonicalJson of the disclosure the requester gave
|
|
278
|
+
RequestedAt integer, -- epoch ms
|
|
279
|
+
ExpiresAt integer, -- epoch ms; no attempt starts at or after it
|
|
280
|
+
StampId text unique,
|
|
281
|
+
constraint NotRevoked check on insert (
|
|
282
|
+
not exists (select 1 from Revocation R where R.TableName = 'JoinRequest' and R.StampId = new.StampId)
|
|
283
|
+
),
|
|
284
|
+
constraint RevocationRecorded check on delete (
|
|
285
|
+
exists (select 1 from Revocation R where R.TableName = 'JoinRequest' and R.StampId = old.StampId and R.RowKey = old.Id)
|
|
286
|
+
),
|
|
287
|
+
constraint NoUpdate check on update (false),
|
|
288
|
+
constraint AuthorizedInsert check on insert (
|
|
289
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(
|
|
290
|
+
digest('CadreControl.JoinRequest', 'add', party_id(), new.Id, new.Invitation, new.Disclosure, cast(new.RequestedAt as text), cast(new.ExpiresAt as text), new.StampId),
|
|
291
|
+
context.Signature, A.Key, 'ed25519'))
|
|
292
|
+
),
|
|
293
|
+
-- Reapable: the inviting party and the user hold the invitation too.
|
|
294
|
+
constraint AuthorizedDelete check on delete (
|
|
295
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.JoinRequest', 'remove', party_id(), old.Id, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
296
|
+
or exists (select 1 from committed.Revocation R where R.TableName = 'JoinRequest' and R.RowKey = old.Id and R.StampId = old.StampId)
|
|
297
|
+
)
|
|
298
|
+
) with context (OwnerKey text null, Signature text null);
|
|
299
|
+
|
|
300
|
+
-- The outcome of a JoinRequest that joined: the strand the formation returned and, for a
|
|
301
|
+
-- closed strand, the single-use membership invitation it delivered. Keyed by the request's
|
|
302
|
+
-- stamp, so it names one request incarnation and a replayed approval can only re-seat the
|
|
303
|
+
-- row it approved, against the request it approved. A join is final: it may be recorded
|
|
304
|
+
-- over a failure (whose row the writer deletes with it), and nothing is recorded over it.
|
|
305
|
+
table JoinSuccess (
|
|
306
|
+
RequestStampId text primary key,
|
|
307
|
+
RecordedAt integer, -- epoch ms
|
|
308
|
+
StrandId text,
|
|
309
|
+
MembershipInvite text null, -- JSON {inviteKey, invitePrivateKey}, the StrandMembershipInvite; closed strands only
|
|
310
|
+
constraint RequestExists check on insert (
|
|
311
|
+
exists (select 1 from JoinRequest R where R.StampId = new.RequestStampId)
|
|
312
|
+
),
|
|
313
|
+
constraint NoUpdate check on update (false),
|
|
314
|
+
constraint AuthorizedInsert check on insert (
|
|
315
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(
|
|
316
|
+
digest('CadreControl.JoinSuccess', 'add', party_id(), new.RequestStampId, cast(new.RecordedAt as text), new.StrandId, coalesce(new.MembershipInvite, '')),
|
|
317
|
+
context.Signature, A.Key, 'ed25519'))
|
|
318
|
+
),
|
|
319
|
+
-- Removed only with its request: the tombstone retiring the request's stamp (owner-signed,
|
|
320
|
+
-- or already committed for a reap) authorizes this delete.
|
|
321
|
+
constraint AuthorizedDelete check on delete (
|
|
322
|
+
exists (select 1 from Revocation R where R.TableName = 'JoinRequest' and R.StampId = old.RequestStampId)
|
|
323
|
+
)
|
|
324
|
+
) with context (OwnerKey text null, Signature text null);
|
|
325
|
+
|
|
326
|
+
-- The outcome of a JoinRequest that failed for good. Keyed as JoinSuccess is.
|
|
327
|
+
table JoinFailure (
|
|
328
|
+
RequestStampId text primary key,
|
|
329
|
+
RecordedAt integer, -- epoch ms
|
|
330
|
+
Code text, -- a FormationRejectionCode, 'expired' or 'local'
|
|
331
|
+
Reason text, -- human-readable
|
|
332
|
+
constraint RequestExists check on insert (
|
|
333
|
+
exists (select 1 from JoinRequest R where R.StampId = new.RequestStampId)
|
|
334
|
+
),
|
|
335
|
+
-- A join is final: nothing records a failure over it.
|
|
336
|
+
constraint NotJoined check on insert (
|
|
337
|
+
not exists (select 1 from JoinSuccess S where S.RequestStampId = new.RequestStampId)
|
|
338
|
+
),
|
|
339
|
+
constraint NoUpdate check on update (false),
|
|
340
|
+
constraint AuthorizedInsert check on insert (
|
|
341
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(
|
|
342
|
+
digest('CadreControl.JoinFailure', 'add', party_id(), new.RequestStampId, cast(new.RecordedAt as text), new.Code, new.Reason),
|
|
343
|
+
context.Signature, A.Key, 'ed25519'))
|
|
344
|
+
),
|
|
345
|
+
-- Removed with its request (JoinSuccess.AuthorizedDelete), or superseded by a join
|
|
346
|
+
-- recorded in the same transaction.
|
|
347
|
+
constraint AuthorizedDelete check on delete (
|
|
348
|
+
exists (select 1 from Revocation R where R.TableName = 'JoinRequest' and R.StampId = old.RequestStampId)
|
|
349
|
+
or exists (select 1 from JoinSuccess S where S.RequestStampId = old.RequestStampId)
|
|
350
|
+
)
|
|
351
|
+
) with context (OwnerKey text null, Signature text null);
|
|
352
|
+
|
|
353
|
+
-- A node of the cadre, carrying its self-published, freshness-stamped, self-signed address
|
|
354
|
+
-- record (cadre-core PeerAddressRecord): a resolver re-verifies Sig against PublicKey,
|
|
355
|
+
-- checks UpdatedAt and trust, then dials Multiaddr.
|
|
356
|
+
table CadrePeer (
|
|
357
|
+
PeerId text primary key,
|
|
358
|
+
PublicKey text null, -- ed25519 (base64url) behind PeerId; null if not ed25519
|
|
359
|
+
Multiaddr text, -- comma-joined current addrs (signaling / p2p-circuit first)
|
|
360
|
+
UpdatedAt int null, -- epoch ms; strictly increases per self-update
|
|
361
|
+
Sig text null, -- self-signature over the 'publish' digest; null until self-published
|
|
362
|
+
StampId text unique,
|
|
363
|
+
VouchOwner text null, -- the owner key that vouched this membership (== insert context.OwnerKey), or
|
|
364
|
+
-- the issuer of the invitation that admitted it (CadreInvite.IssuerKey)
|
|
365
|
+
VouchSig text null, -- that owner's 'vouch' signature (== insert context.Signature); null on an
|
|
366
|
+
-- invitation-admitted row. A reader checks VouchOwner against its node-local
|
|
367
|
+
-- trusted-owner anchor, not against this replicated table, which a self-owner
|
|
368
|
+
-- can pollute.
|
|
369
|
+
VouchUsage text null, -- the CadreInviteUsage.UsageStampId that admitted this row; null on an
|
|
370
|
+
-- owner-vouched row. A row carries exactly one proof: a signature or a usage.
|
|
371
|
+
constraint NotRevoked check on insert (
|
|
372
|
+
not exists (select 1 from Revocation R where R.TableName = 'CadrePeer' and R.StampId = new.StampId)
|
|
373
|
+
),
|
|
374
|
+
constraint RevocationRecorded check on delete (
|
|
375
|
+
exists (select 1 from Revocation R where R.TableName = 'CadrePeer' and R.StampId = old.StampId and R.RowKey = old.PeerId)
|
|
376
|
+
),
|
|
377
|
+
-- The owner vouches membership and the PublicKey<->PeerId binding (cadre-core derives
|
|
378
|
+
-- PublicKey from PeerId) over (PeerId, StampId); the stored voucher must be the pair
|
|
379
|
+
-- verified here. The same 'vouch' digest serves the owner branch of AuthorizedUpdate:
|
|
380
|
+
-- both mean "this owner vouches this membership row".
|
|
381
|
+
-- Or admitted by consent: a CadreInviteUsage row written in the same transaction names
|
|
382
|
+
-- this exact row incarnation (PeerId, StampId and PublicKey), and the invitation it
|
|
383
|
+
-- redeemed, read from committed.CadreInvite, was issued by the stored VouchOwner. The
|
|
384
|
+
-- usage row carries the liveness conditions (unexpired, not withdrawn, uses left,
|
|
385
|
+
-- issuer still an owner); this branch only requires that it exists. A reader verifies
|
|
386
|
+
-- the chain row -> usage -> invitation against its anchor (cadre-core
|
|
387
|
+
-- verifyInvitationAdmission), so the invitation row must outlive the rows it admitted.
|
|
388
|
+
-- A removed device may redeem a still-live invitation again and come back: keeping a
|
|
389
|
+
-- device out is removing its row AND withdrawing the invitation.
|
|
390
|
+
constraint AuthorizedInsert check on insert (
|
|
391
|
+
(
|
|
392
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.CadrePeer', 'vouch', party_id(), new.PeerId, new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
393
|
+
and coalesce(new.VouchOwner, '') = context.OwnerKey
|
|
394
|
+
and coalesce(new.VouchSig, '') = context.Signature
|
|
395
|
+
and new.VouchUsage is null
|
|
396
|
+
)
|
|
397
|
+
or (
|
|
398
|
+
new.VouchSig is null
|
|
399
|
+
and new.VouchOwner is not null
|
|
400
|
+
and new.VouchUsage is not null
|
|
401
|
+
and exists (
|
|
402
|
+
select 1 from CadreInviteUsage U
|
|
403
|
+
where U.UsageStampId = new.VouchUsage
|
|
404
|
+
and U.PeerId = new.PeerId
|
|
405
|
+
and U.PeerStampId = new.StampId
|
|
406
|
+
and U.PeerKey = new.PublicKey
|
|
407
|
+
and exists (select 1 from committed.CadreInvite I where I.Key = U.InviteKey and I.IssuerKey = new.VouchOwner)
|
|
408
|
+
)
|
|
409
|
+
)
|
|
410
|
+
),
|
|
411
|
+
-- The stored 'vouch' voucher never authorizes a delete; the 'remove' signature rides in
|
|
412
|
+
-- context and is never stored. Or a reap (ValidationKey.AuthorizedDelete).
|
|
413
|
+
constraint AuthorizedDelete check on delete (
|
|
414
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.CadrePeer', 'remove', party_id(), old.PeerId, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
415
|
+
or exists (select 1 from committed.Revocation R where R.TableName = 'CadrePeer' and R.RowKey = old.PeerId and R.StampId = old.StampId)
|
|
416
|
+
),
|
|
417
|
+
-- A peer re-publishes its own addrs and freshness under its own key (cadre-core
|
|
418
|
+
-- peer-record.ts); everything else is immutable and UpdatedAt must increase. Or an owner
|
|
419
|
+
-- re-vouches the row over its current stamp, which also clears VouchUsage: the row then
|
|
420
|
+
-- stands on the signature and its invitation is no longer consulted for it. StampId never
|
|
421
|
+
-- changes on update: an update that rotated it would leave the old stamp free and
|
|
422
|
+
-- untombstoned, so retiring a stamp is delete plus tombstone. The proof columns are
|
|
423
|
+
-- compared null-safe: VouchSig and VouchUsage are null on one of the two row kinds, and a
|
|
424
|
+
-- bare \`new.X = old.X\` over a null would let a self-publish fill the column in.
|
|
425
|
+
constraint AuthorizedUpdate check on update (
|
|
426
|
+
(
|
|
427
|
+
new.PeerId = old.PeerId
|
|
428
|
+
and new.PublicKey = old.PublicKey
|
|
429
|
+
and new.StampId = old.StampId
|
|
430
|
+
and new.VouchOwner = old.VouchOwner
|
|
431
|
+
and coalesce(new.VouchSig, '') = coalesce(old.VouchSig, '')
|
|
432
|
+
and coalesce(new.VouchUsage, '') = coalesce(old.VouchUsage, '')
|
|
433
|
+
and new.UpdatedAt > coalesce(old.UpdatedAt, 0)
|
|
434
|
+
and verify(
|
|
435
|
+
digest('CadreControl.CadrePeer', 'publish', party_id(), new.PeerId, new.Multiaddr, cast(new.UpdatedAt as text)),
|
|
436
|
+
new.Sig, new.PublicKey, 'ed25519')
|
|
437
|
+
)
|
|
438
|
+
or (
|
|
439
|
+
new.StampId = old.StampId
|
|
440
|
+
and exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.CadrePeer', 'vouch', party_id(), new.PeerId, new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
441
|
+
and coalesce(new.VouchOwner, '') = context.OwnerKey
|
|
442
|
+
and coalesce(new.VouchSig, '') = context.Signature
|
|
443
|
+
and new.VouchUsage is null
|
|
444
|
+
)
|
|
445
|
+
)
|
|
446
|
+
) with context (OwnerKey text null, Signature text);
|
|
447
|
+
|
|
448
|
+
-- A mobile peer's platform push token, self-published so a server peer can push-wake a
|
|
449
|
+
-- suspended app. A resolver re-verifies Sig against the CadrePeer.PublicKey for PeerId
|
|
450
|
+
-- (cadre-core device-token.ts), checks freshness, then hands the token to the push sender.
|
|
451
|
+
table DeviceToken (
|
|
452
|
+
PeerId text primary key,
|
|
453
|
+
Platform text, -- 'fcm' | 'apns'
|
|
454
|
+
Token text, -- opaque platform device/registration token
|
|
455
|
+
UpdatedAt int null, -- epoch ms; strictly increases per self-update
|
|
456
|
+
Sig text null, -- self-signature over the 'publish' digest
|
|
457
|
+
StampId text unique,
|
|
458
|
+
-- A resurrected token has no freshness ceiling to retire it (resolveDeviceToken defaults
|
|
459
|
+
-- maxAgeMs to infinity), so stamp retirement is what makes a clear stick.
|
|
460
|
+
constraint NotRevoked check on insert (
|
|
461
|
+
not exists (select 1 from Revocation R where R.TableName = 'DeviceToken' and R.StampId = new.StampId)
|
|
462
|
+
),
|
|
463
|
+
constraint RevocationRecorded check on delete (
|
|
464
|
+
exists (select 1 from Revocation R where R.TableName = 'DeviceToken' and R.StampId = old.StampId and R.RowKey = old.PeerId)
|
|
465
|
+
),
|
|
466
|
+
-- The owner signs the whole row, nullable columns as '', so a replayed approval can only
|
|
467
|
+
-- reproduce the row it approved (cadre-core peer-authorization.ts deviceTokenAddDigest).
|
|
468
|
+
constraint AuthorizedInsert check on insert (
|
|
469
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(
|
|
470
|
+
digest(
|
|
471
|
+
'CadreControl.DeviceToken', 'add', party_id(),
|
|
472
|
+
new.PeerId,
|
|
473
|
+
new.Platform,
|
|
474
|
+
new.Token,
|
|
475
|
+
coalesce(cast(new.UpdatedAt as text), ''),
|
|
476
|
+
coalesce(new.Sig, ''),
|
|
477
|
+
new.StampId
|
|
478
|
+
),
|
|
479
|
+
context.Signature, A.Key, 'ed25519'))
|
|
480
|
+
),
|
|
481
|
+
constraint AuthorizedDelete check on delete (
|
|
482
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.DeviceToken', 'remove', party_id(), old.PeerId, old.StampId), context.Signature, A.Key, 'ed25519'))
|
|
483
|
+
or exists (select 1 from committed.Revocation R where R.TableName = 'DeviceToken' and R.RowKey = old.PeerId and R.StampId = old.StampId)
|
|
484
|
+
),
|
|
485
|
+
-- Self-update only: Platform and Token may change, PeerId and StampId may not, UpdatedAt
|
|
486
|
+
-- must increase. No owner re-touch branch: one outside the monotonicity rule would let a
|
|
487
|
+
-- captured approval roll UpdatedAt back; an owner correcting a row deletes and re-inserts.
|
|
488
|
+
constraint AuthorizedUpdate check on update (
|
|
489
|
+
new.PeerId = old.PeerId
|
|
490
|
+
and new.StampId = old.StampId
|
|
491
|
+
and new.UpdatedAt > coalesce(old.UpdatedAt, 0)
|
|
492
|
+
and exists (select 1 from CadrePeer P where P.PeerId = new.PeerId and verify(
|
|
493
|
+
digest('CadreControl.DeviceToken', 'publish', party_id(), new.PeerId, new.Platform, new.Token, cast(new.UpdatedAt as text)),
|
|
494
|
+
new.Sig, P.PublicKey, 'ed25519'))
|
|
495
|
+
)
|
|
496
|
+
) with context (OwnerKey text null, Signature text);
|
|
497
|
+
|
|
498
|
+
-- An open invitation to form a strand with this party.
|
|
499
|
+
table FormationInvite (
|
|
500
|
+
Token text primary key, -- a random string
|
|
501
|
+
sAppId text, -- the app of the strand to be formed
|
|
502
|
+
ExpiresAt datetime null,
|
|
503
|
+
TotalUses int null check (TotalUses >= 0),
|
|
504
|
+
ValidationUrl text null, -- web hook sent the disclosure; a ValidationKey then signs off each redemption
|
|
505
|
+
StrandId text null, -- bound invite: the host strand consent is recorded against;
|
|
506
|
+
-- null: the responder provisions a fresh open strand per redemption
|
|
507
|
+
StampId text unique,
|
|
508
|
+
-- The owner signs the whole row, nullable columns as ''.
|
|
509
|
+
constraint AuthorizedInsert check on insert (
|
|
510
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(
|
|
511
|
+
digest(
|
|
512
|
+
'CadreControl.FormationInvite', 'add', party_id(),
|
|
513
|
+
new.Token,
|
|
514
|
+
new.sAppId,
|
|
515
|
+
coalesce(cast(new.ExpiresAt as text), ''),
|
|
516
|
+
coalesce(cast(new.TotalUses as text), ''),
|
|
517
|
+
coalesce(new.ValidationUrl, ''),
|
|
518
|
+
coalesce(new.StrandId, ''),
|
|
519
|
+
new.StampId
|
|
520
|
+
),
|
|
521
|
+
context.Signature, A.Key, 'ed25519'))
|
|
522
|
+
),
|
|
523
|
+
constraint AuthorizedDelete check on delete (
|
|
524
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(
|
|
525
|
+
digest(
|
|
526
|
+
'CadreControl.FormationInvite', 'remove', party_id(),
|
|
527
|
+
old.Token,
|
|
528
|
+
old.sAppId,
|
|
529
|
+
coalesce(cast(old.ExpiresAt as text), ''),
|
|
530
|
+
coalesce(cast(old.TotalUses as text), ''),
|
|
531
|
+
coalesce(old.ValidationUrl, ''),
|
|
532
|
+
coalesce(old.StrandId, ''),
|
|
533
|
+
old.StampId
|
|
534
|
+
),
|
|
535
|
+
context.Signature, A.Key, 'ed25519'))
|
|
536
|
+
),
|
|
537
|
+
-- Insert and delete only, so the consent parameters cannot change under a signature.
|
|
538
|
+
constraint Immutable check on update (false)
|
|
539
|
+
) with context (OwnerKey text, Signature text);
|
|
540
|
+
|
|
541
|
+
-- Append-only record of formation invite redemptions, one row per redemption.
|
|
542
|
+
table FormationUsage (
|
|
543
|
+
Token text, -- the FormationInvite redeemed
|
|
544
|
+
UsageStampId text, -- single-use nonce minted by the joining peer, signed into its 'consent' digest
|
|
545
|
+
-- and the approver's 'vouch' digest. The primary key: this table never
|
|
546
|
+
-- deletes, so the key alone makes a nonce permanent and there is no
|
|
547
|
+
-- NotRevoked pair here. Two nodes that have not converged can each admit
|
|
548
|
+
-- the same nonce: a duplicated audit row, never a join nobody approved.
|
|
549
|
+
PeerKey text, -- the joining peer's ed25519 public key (base64url); its peer id derives from it
|
|
550
|
+
PeerSig text, -- the joiner's signature over the 'consent' digest (PeerConsented)
|
|
551
|
+
Disclosure text,
|
|
552
|
+
StrandId text,
|
|
553
|
+
StrandStampId text, -- the Strand.StampId this consent names: one strand row, not an id forever
|
|
554
|
+
-- (Strand.AuthorizedInsert). Not unique: a bound invite's redeemers share
|
|
555
|
+
-- a host strand.
|
|
556
|
+
primary key (UsageStampId),
|
|
557
|
+
constraint InsertOnly check on update, delete (false),
|
|
558
|
+
-- The use cap counts the pre-transaction snapshot, so concurrent redeemers on separate
|
|
559
|
+
-- nodes can over-admit by their number; both rows survive and removal is owner-gated. A
|
|
560
|
+
-- strict per-token sequence was rejected: a lost race would silently drop a consented
|
|
561
|
+
-- join. Two usage rows for one token in one transaction read the same count; no writer
|
|
562
|
+
-- does that.
|
|
563
|
+
-- A ValidationUrl invite needs a sign-off verified against a STORED ValidationKey row;
|
|
564
|
+
-- context.ValidationKey only selects which row, so a redeemer cannot approve itself with
|
|
565
|
+
-- a throwaway key. The sign-off covers (Token, UsageStampId, StrandId, PeerKey,
|
|
566
|
+
-- Disclosure), so it buys exactly one row; StrandStampId is not bound because the
|
|
567
|
+
-- unbound path mints it inside the redeeming transaction. Removing the key later does
|
|
568
|
+
-- not revisit rows it approved.
|
|
569
|
+
-- A bound invite may only name its own host strand. An unbound invite may name any
|
|
570
|
+
-- existing strand, which burns a use and forecloses that id's consent-seating: harmless.
|
|
571
|
+
-- Neither digest of this table binds party_id(), alone in this schema: the joiner signs
|
|
572
|
+
-- its consent before the responder's party id reaches it (it arrives in the result
|
|
573
|
+
-- frame) and with a key made fresh for this one formation, and the outside approver
|
|
574
|
+
-- behind ValidationUrl is sent only the five fields below. Both digests bind the
|
|
575
|
+
-- invitation Token, a random secret seated in one party's FormationInvite table, so
|
|
576
|
+
-- replaying either in another party needs that party's owner to seat the same token in
|
|
577
|
+
-- its own database, and the only database harmed would be its own.
|
|
578
|
+
constraint Authorized check on insert (
|
|
579
|
+
exists (
|
|
580
|
+
select 1 from FormationInvite FI
|
|
581
|
+
where FI.Token = new.Token
|
|
582
|
+
and (FI.TotalUses is null or FI.TotalUses > (select count(1) from committed.FormationUsage U where U.Token = new.Token))
|
|
583
|
+
and (FI.ExpiresAt is null or FI.ExpiresAt > context.Now)
|
|
584
|
+
and (FI.ValidationUrl is null or exists (
|
|
585
|
+
select 1 from ValidationKey VK
|
|
586
|
+
where VK.Key = context.ValidationKey
|
|
587
|
+
and verify(digest('CadreControl.FormationUsage', 'vouch', new.Token, new.UsageStampId, new.StrandId, new.PeerKey, new.Disclosure), context.ValidationSignature, VK.Key, 'ed25519')))
|
|
588
|
+
and (FI.StrandId is null or FI.StrandId = new.StrandId)
|
|
589
|
+
)
|
|
590
|
+
),
|
|
591
|
+
-- A usage row may only name a strand row that exists, so a consent record cannot be held
|
|
592
|
+
-- in reserve to re-seat an id after its removal.
|
|
593
|
+
constraint StrandExists check (exists (select 1 from Strand S where S.Id = new.StrandId and S.StampId = new.StrandStampId)),
|
|
594
|
+
-- The joiner proves it agreed. PeerKey is its own key, so there is nothing for a writer to
|
|
595
|
+
-- substitute; stored on the row so any reader can re-check it (verifyFormationConsent).
|
|
596
|
+
-- StrandId and the party id are not signed: the joiner cannot know them when it signs
|
|
597
|
+
-- (Authorized, above).
|
|
598
|
+
constraint PeerConsented check on insert (
|
|
599
|
+
verify(digest('CadreControl.FormationUsage', 'consent',
|
|
600
|
+
new.Token, new.UsageStampId, new.PeerKey, new.Disclosure),
|
|
601
|
+
new.PeerSig, new.PeerKey, 'ed25519')
|
|
602
|
+
)
|
|
603
|
+
) with context (Now datetime, ValidationKey text null, ValidationSignature text null);
|
|
604
|
+
|
|
605
|
+
-- Serves the per-token reads (the cap count above; cadre-core's countFormationUsage,
|
|
606
|
+
-- isTokenUsed and hasOutstandingFormationInvite) on an append-only table. Its cross-machine
|
|
607
|
+
-- convergence is guarded by the integration scenario strand-formation-concurrent-redemption.
|
|
608
|
+
index FormationUsageByToken on FormationUsage (Token);
|
|
609
|
+
|
|
610
|
+
-- An owner-signed invitation to join this cadre, redeemable on the owner's behalf by any
|
|
611
|
+
-- member machine (ControlDatabase.redeemCadreInvite). The invitation is a keypair, not a
|
|
612
|
+
-- bearer token: the row holds the public half and the holder proves possession by signing
|
|
613
|
+
-- with the private half (CadreInviteUsage.InvitePossessed), so the member that redeems it
|
|
614
|
+
-- can verify but never redeem it for itself. Rows are never deleted: a device admitted
|
|
615
|
+
-- through one carries no owner signature of its own, and its membership is the chain
|
|
616
|
+
-- invitation -> usage -> peer row, verified at read time, so the row must outlive every
|
|
617
|
+
-- device it admitted. Withdrawing an invitation is an owner-signed Revocation tombstone
|
|
618
|
+
-- over the row's stamp with the row kept (Revocation.RowIsGone); liveness is read as no
|
|
619
|
+
-- tombstone, unexpired, uses left, issuer still an owner (CadreInviteUsage.Authorized).
|
|
620
|
+
-- NOTE: expired and withdrawn rows accumulate for the life of the party; the same tripwire
|
|
621
|
+
-- as hasOutstandingFormationInvite applies (ControlDatabase.hasLiveCadreInvite). An owner
|
|
622
|
+
-- retires a device's dependency on its invitation by re-vouching the row (the owner branch
|
|
623
|
+
-- of CadrePeer.AuthorizedUpdate).
|
|
624
|
+
table CadreInvite (
|
|
625
|
+
Key text primary key, -- the invitation's ed25519 public key (base64url)
|
|
626
|
+
PeerId text null, -- the device this invitation is for; null: whoever redeems first designates it
|
|
627
|
+
GrantsOwner integer check (GrantsOwner = 0 or GrantsOwner = 1), -- 1: redemption also seats an OwnerKey row
|
|
628
|
+
ExpiresAt datetime null,
|
|
629
|
+
TotalUses int null check (TotalUses >= 0),
|
|
630
|
+
IssuerKey text, -- the owner that signed the row (== insert context.OwnerKey). A reader checks it
|
|
631
|
+
-- against its node-local anchor, never against the replicated OwnerKey table.
|
|
632
|
+
IssuerSig text, -- that owner's 'add' signature (== insert context.Signature), stored so any reader
|
|
633
|
+
-- can re-verify the row from the holder's copy or the replicated one
|
|
634
|
+
StampId text unique,
|
|
635
|
+
-- A withdrawn invitation cannot be re-seated from the signed copy its holder keeps, on
|
|
636
|
+
-- any node that holds the tombstone (schema header for the node that does not).
|
|
637
|
+
constraint NotRevoked check on insert (
|
|
638
|
+
not exists (select 1 from Revocation R where R.TableName = 'CadreInvite' and R.StampId = new.StampId)
|
|
639
|
+
),
|
|
640
|
+
-- The owner signs the whole row, nullable columns as '' (cadre-core cadreInviteRowFields),
|
|
641
|
+
-- and the stored issuer pair must be the pair verified here, as CadrePeer pins its voucher.
|
|
642
|
+
constraint AuthorizedInsert check on insert (
|
|
643
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(
|
|
644
|
+
digest(
|
|
645
|
+
'CadreControl.CadreInvite', 'add', party_id(),
|
|
646
|
+
new.Key,
|
|
647
|
+
coalesce(new.PeerId, ''),
|
|
648
|
+
cast(new.GrantsOwner as text),
|
|
649
|
+
coalesce(cast(new.ExpiresAt as text), ''),
|
|
650
|
+
coalesce(cast(new.TotalUses as text), ''),
|
|
651
|
+
new.StampId
|
|
652
|
+
),
|
|
653
|
+
context.Signature, A.Key, 'ed25519'))
|
|
654
|
+
and coalesce(new.IssuerKey, '') = context.OwnerKey
|
|
655
|
+
and coalesce(new.IssuerSig, '') = context.Signature
|
|
656
|
+
),
|
|
657
|
+
constraint NoUpdate check on update (false),
|
|
658
|
+
-- Never deleted (table comment). Withdrawal is the tombstone alone.
|
|
659
|
+
constraint NoDelete check on delete (false)
|
|
660
|
+
) with context (OwnerKey text, Signature text);
|
|
661
|
+
|
|
662
|
+
-- Append-only record of cadre invitation redemptions, one row per redemption: the proof a
|
|
663
|
+
-- CadrePeer row (and, for an owner-granting invitation, an OwnerKey row) was admitted by
|
|
664
|
+
-- consent rather than by an owner signature.
|
|
665
|
+
table CadreInviteUsage (
|
|
666
|
+
UsageStampId text primary key, -- nonce minted by the redeeming device and signed into both signatures
|
|
667
|
+
-- below. The primary key: this table never deletes, so the key alone
|
|
668
|
+
-- makes a nonce permanent and there is no NotRevoked pair here. Two nodes
|
|
669
|
+
-- that have not converged can each admit the same nonce (FormationUsage).
|
|
670
|
+
InviteKey text, -- the CadreInvite redeemed
|
|
671
|
+
PeerId text, -- the redeeming device: the identity multihash of PeerKey. The writer
|
|
672
|
+
-- asserts the pair and a reader re-derives it (verifyInvitationAdmission);
|
|
673
|
+
-- the schema cannot unwrap a multihash.
|
|
674
|
+
PeerKey text, -- the redeeming device's ed25519 public key (base64url)
|
|
675
|
+
PeerStampId text, -- the CadrePeer.StampId this usage seats: one row incarnation, not a peer id
|
|
676
|
+
-- forever. Minted by the writer inside the redeeming transaction and not
|
|
677
|
+
-- signed (FormationUsage.StrandStampId).
|
|
678
|
+
OwnerStampId text null, -- the OwnerKey.StampId this usage seats when the invitation grants ownership
|
|
679
|
+
InviteSig text, -- by the invitation's private key over the 'redeem' digest: proof of possession
|
|
680
|
+
PeerSig text, -- by PeerKey over the 'consent' digest: the device agreed to join
|
|
681
|
+
constraint InsertOnly check on update, delete (false),
|
|
682
|
+
-- The invitation is read from the pre-transaction snapshot, so an invitation cannot be
|
|
683
|
+
-- seated and redeemed in one transaction (the OwnerKey consent branch rests on that).
|
|
684
|
+
-- NOTE: accepted tradeoff — the use cap counts committed usage, so two redeemers racing
|
|
685
|
+
-- for a single-use invitation on different machines may both be admitted until merge,
|
|
686
|
+
-- and after merge both rows stand (FormationUsage.Authorized), for owner grants too.
|
|
687
|
+
-- Serializing would need cross-machine coordination the control plane does not have;
|
|
688
|
+
-- the mitigations are the defaults the redemption protocol sets (untargeted owner
|
|
689
|
+
-- invitations single-use with a short expiry), the targeted form for owner grants, and
|
|
690
|
+
-- the owner seeing the extra owner and removing it. Revisit if the control plane gains
|
|
691
|
+
-- a cross-machine sequencer. An issuer removed since issuing takes its outstanding
|
|
692
|
+
-- invitations with it (the committed.OwnerKey clause, which a tombstone alone
|
|
693
|
+
-- satisfies); devices it already admitted stay members.
|
|
694
|
+
constraint Authorized check on insert (
|
|
695
|
+
exists (
|
|
696
|
+
select 1 from committed.CadreInvite I
|
|
697
|
+
where I.Key = new.InviteKey
|
|
698
|
+
and not exists (select 1 from Revocation R where R.TableName = 'CadreInvite' and R.StampId = I.StampId)
|
|
699
|
+
and (I.ExpiresAt is null or I.ExpiresAt > context.Now)
|
|
700
|
+
and (I.TotalUses is null or I.TotalUses > (select count(1) from committed.CadreInviteUsage U where U.InviteKey = new.InviteKey))
|
|
701
|
+
and (I.PeerId is null or I.PeerId = new.PeerId)
|
|
702
|
+
and exists (select 1 from committed.OwnerKey K where K.Key = I.IssuerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = K.StampId))
|
|
703
|
+
)
|
|
704
|
+
),
|
|
705
|
+
-- Verified against the invitation key itself: the member writing the row can check this
|
|
706
|
+
-- signature but, holding only the public half, cannot produce it.
|
|
707
|
+
constraint InvitePossessed check on insert (
|
|
708
|
+
verify(digest('CadreControl.CadreInviteUsage', 'redeem', party_id(), new.InviteKey, new.UsageStampId, new.PeerKey),
|
|
709
|
+
new.InviteSig, new.InviteKey, 'ed25519')
|
|
710
|
+
),
|
|
711
|
+
-- The device proves it agreed (FormationUsage.PeerConsented).
|
|
712
|
+
constraint PeerConsented check on insert (
|
|
713
|
+
verify(digest('CadreControl.CadreInviteUsage', 'consent', party_id(), new.InviteKey, new.UsageStampId, new.PeerKey),
|
|
714
|
+
new.PeerSig, new.PeerKey, 'ed25519')
|
|
715
|
+
),
|
|
716
|
+
-- Deferred, so the same-transaction peer insert counts: a usage row can never be held in
|
|
717
|
+
-- reserve to seat a row later (FormationUsage.StrandExists). PeerKey must be the key the
|
|
718
|
+
-- peer row stores: a redemption that only completes an already-admitted device with its
|
|
719
|
+
-- OwnerKey row (no peer insert to pin it) cannot name a key other than that device's.
|
|
720
|
+
constraint PeerExists check (exists (
|
|
721
|
+
select 1 from CadrePeer P where P.PeerId = new.PeerId and P.StampId = new.PeerStampId and P.PublicKey = new.PeerKey
|
|
722
|
+
)),
|
|
723
|
+
constraint OwnerExists check (
|
|
724
|
+
new.OwnerStampId is null
|
|
725
|
+
or exists (select 1 from OwnerKey K where K.Key = new.PeerKey and K.StampId = new.OwnerStampId)
|
|
726
|
+
)
|
|
727
|
+
) with context (Now datetime);
|
|
728
|
+
|
|
729
|
+
-- Serves the cap count above and the liveness reads (cadre-core countCadreInviteUsage,
|
|
730
|
+
-- hasLiveCadreInvite) on an append-only table, as FormationUsageByToken does.
|
|
731
|
+
index CadreInviteUsageByInvite on CadreInviteUsage (InviteKey);
|
|
732
|
+
|
|
733
|
+
-- Append-only retirement record for the stamps of removed rows of every guarded table, with
|
|
734
|
+
-- the removed row's key. Every append is owner-signed, so the growth surface is the owner
|
|
735
|
+
-- keys. One singleton marker row, ('Revocation', 'ledger', 'opened'), retires nothing: an
|
|
736
|
+
-- owner's connected reconcile pass files it (ControlDatabase.openRevocationLedger) so this
|
|
737
|
+
-- table is never a never-written block, which the storage layer would consult the cohort
|
|
738
|
+
-- for on every guarded insert and membership lookup. Readers filter on their own guarded
|
|
739
|
+
-- TableName, and queryRevocations skips it. A 'CadreInvite' row withdraws an invitation
|
|
740
|
+
-- whose row stays (CadreInvite table comment).
|
|
741
|
+
table Revocation (
|
|
742
|
+
TableName text, -- 'OwnerKey' | 'ValidationKey' | 'Strand' | 'StrandPartyKey' | 'JoinedStrand' |
|
|
743
|
+
-- 'JoinRequest' | 'CadrePeer' | 'DeviceToken' | 'CadreInvite', or 'Revocation'
|
|
744
|
+
-- for the marker
|
|
745
|
+
RowKey text, -- primary key of the removed row
|
|
746
|
+
StampId text, -- the retired stamp
|
|
747
|
+
ReissuedAt integer default 0, -- bumped by an owner-signed re-issue so a tombstone committed while the
|
|
748
|
+
-- node was alone can be re-written and so re-broadcast; nothing reads it
|
|
749
|
+
SignerKey text null, -- the owner that filed the tombstone (== insert context.OwnerKey)
|
|
750
|
+
SignerSig text null, -- that owner's 'remove' signature (== insert context.Signature). A node that
|
|
751
|
+
-- received the row by replication re-verifies the pair and judges SignerKey
|
|
752
|
+
-- against its node-local trusted-owner anchor (cadre-core
|
|
753
|
+
-- verifyRevocationSigner), not against this replicated table.
|
|
754
|
+
-- Keyed on the stamp: one row key may carry several tombstones over its life.
|
|
755
|
+
primary key (TableName, StampId),
|
|
756
|
+
-- Retirement is permanent.
|
|
757
|
+
constraint NoDelete check on delete (false),
|
|
758
|
+
-- Pinned at 0 so an owner cannot seat a tombstone at a counter its own re-issues cannot pass.
|
|
759
|
+
constraint FreshTombstone check on insert (new.ReissuedAt = 0),
|
|
760
|
+
-- A re-issue moves nothing but the counter, and only upward. The signer pair stays the
|
|
761
|
+
-- filing owner's; the re-issuing owner's signature rides in context only.
|
|
762
|
+
constraint ReissueOnly check on update (
|
|
763
|
+
new.TableName = old.TableName and new.RowKey = old.RowKey
|
|
764
|
+
and new.StampId = old.StampId and new.ReissuedAt > old.ReissuedAt
|
|
765
|
+
and coalesce(new.SignerKey, '') = coalesce(old.SignerKey, '')
|
|
766
|
+
and coalesce(new.SignerSig, '') = coalesce(old.SignerSig, '')
|
|
767
|
+
),
|
|
768
|
+
-- A stamp is retired only once its row is gone (deferred, so the same-transaction delete
|
|
769
|
+
-- counts). Keyed on the stamp, not RowKey: a node that converges on a re-admission before
|
|
770
|
+
-- the earlier removal's tombstone must still accept that tombstone. Retiring a stamp that
|
|
771
|
+
-- never existed is harmless: stamps carry 128 random bits (generateStampId). For
|
|
772
|
+
-- 'CadreInvite' there is no row-gone test: a tombstone there is a withdrawal, and the
|
|
773
|
+
-- row stays (CadreInvite table comment). The last branch admits the marker row and
|
|
774
|
+
-- nothing else under 'Revocation'.
|
|
775
|
+
constraint RowIsGone check on insert (
|
|
776
|
+
(new.TableName = 'OwnerKey' and not exists (select 1 from OwnerKey K where K.StampId = new.StampId))
|
|
777
|
+
or (new.TableName = 'CadrePeer' and not exists (select 1 from CadrePeer P where P.StampId = new.StampId))
|
|
778
|
+
or (new.TableName = 'ValidationKey' and not exists (select 1 from ValidationKey V where V.StampId = new.StampId))
|
|
779
|
+
or (new.TableName = 'Strand' and not exists (select 1 from Strand S where S.StampId = new.StampId))
|
|
780
|
+
or (new.TableName = 'StrandPartyKey' and not exists (select 1 from StrandPartyKey K where K.StampId = new.StampId))
|
|
781
|
+
or (new.TableName = 'JoinedStrand' and not exists (select 1 from JoinedStrand J where J.StampId = new.StampId))
|
|
782
|
+
or (new.TableName = 'JoinRequest' and not exists (select 1 from JoinRequest J where J.StampId = new.StampId))
|
|
783
|
+
or (new.TableName = 'DeviceToken' and not exists (select 1 from DeviceToken D where D.StampId = new.StampId))
|
|
784
|
+
or (new.TableName = 'CadreInvite')
|
|
785
|
+
or (new.TableName = 'Revocation' and new.RowKey = 'ledger' and new.StampId = 'opened')
|
|
786
|
+
),
|
|
787
|
+
-- Owner-signed over the whole row under its own domain tag, so the delete's 'remove'
|
|
788
|
+
-- signature filed in the same transaction never doubles as the tombstone's. Ungated, any
|
|
789
|
+
-- writer could evict a peer party-wide and block its re-admission. RowKey is not checked
|
|
790
|
+
-- against the retired row here (that would reject a tombstone re-issued later, or filed on
|
|
791
|
+
-- a node that never held the row); each guarded table's RevocationRecorded binds it
|
|
792
|
+
-- instead. Reads live OwnerKey like the sibling tables. The marker is signed under this
|
|
793
|
+
-- rule too, over ('Revocation', 'ledger', 'opened'). The stored signer pair must be the
|
|
794
|
+
-- pair verified here.
|
|
795
|
+
constraint Authorized check on insert (
|
|
796
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId) and verify(digest('CadreControl.Revocation', 'remove', party_id(), new.TableName, new.RowKey, new.StampId), context.Signature, A.Key, 'ed25519'))
|
|
797
|
+
and coalesce(new.SignerKey, '') = context.OwnerKey
|
|
798
|
+
and coalesce(new.SignerSig, '') = context.Signature
|
|
799
|
+
),
|
|
800
|
+
-- Distinct 'reissue' tag, binding ReissuedAt, so neither approval replays as the other.
|
|
801
|
+
constraint AuthorizedReissue check on update (
|
|
802
|
+
exists (select 1 from OwnerKey A where A.Key = context.OwnerKey
|
|
803
|
+
and not exists (select 1 from Revocation R where R.TableName = 'OwnerKey' and R.StampId = A.StampId)
|
|
804
|
+
and verify(digest('CadreControl.Revocation', 'reissue', party_id(),
|
|
805
|
+
new.TableName, new.RowKey, new.StampId, cast(new.ReissuedAt as text)),
|
|
806
|
+
context.Signature, A.Key, 'ed25519'))
|
|
807
|
+
)
|
|
808
|
+
) with context (OwnerKey text, Signature text);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
apply schema CadreControl;
|
|
812
|
+
`;
|