@serfab/cadre-core 1.21.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +294 -294
  2. package/dist/cadre-node.d.ts +334 -53
  3. package/dist/cadre-node.js +794 -85
  4. package/dist/cadre-node.js.map +1 -1
  5. package/dist/control-authorization.d.ts +32 -2
  6. package/dist/control-authorization.js +19 -0
  7. package/dist/control-authorization.js.map +1 -1
  8. package/dist/control-database.d.ts +236 -23
  9. package/dist/control-database.js +587 -173
  10. package/dist/control-database.js.map +1 -1
  11. package/dist/control-schema.d.ts +3 -3
  12. package/dist/control-schema.js +71 -7
  13. package/dist/control-schema.js.map +1 -1
  14. package/dist/ed25519-key.d.ts +8 -0
  15. package/dist/ed25519-key.js +11 -1
  16. package/dist/ed25519-key.js.map +1 -1
  17. package/dist/index.d.ts +5 -1
  18. package/dist/index.js +13 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/machine-removal.d.ts +51 -1
  21. package/dist/machine-removal.js +42 -1
  22. package/dist/machine-removal.js.map +1 -1
  23. package/dist/membership-connection-gater.d.ts +8 -0
  24. package/dist/membership-connection-gater.js +13 -1
  25. package/dist/membership-connection-gater.js.map +1 -1
  26. package/dist/membership-view.js +4 -1
  27. package/dist/membership-view.js.map +1 -1
  28. package/dist/owner-keys.js +2 -1
  29. package/dist/owner-keys.js.map +1 -1
  30. package/dist/owner-signer.js +3 -4
  31. package/dist/owner-signer.js.map +1 -1
  32. package/dist/peer-authorization.d.ts +14 -2
  33. package/dist/peer-authorization.js +24 -1
  34. package/dist/peer-authorization.js.map +1 -1
  35. package/dist/sealed-party-key.d.ts +32 -0
  36. package/dist/sealed-party-key.js +162 -0
  37. package/dist/sealed-party-key.js.map +1 -0
  38. package/dist/seed-bootstrap.d.ts +10 -3
  39. package/dist/seed-bootstrap.js +12 -0
  40. package/dist/seed-bootstrap.js.map +1 -1
  41. package/dist/strand-addr-protocol.d.ts +56 -6
  42. package/dist/strand-addr-protocol.js +57 -5
  43. package/dist/strand-addr-protocol.js.map +1 -1
  44. package/dist/strand-commit-durability.d.ts +33 -2
  45. package/dist/strand-commit-durability.js +44 -4
  46. package/dist/strand-commit-durability.js.map +1 -1
  47. package/dist/strand-database.d.ts +35 -5
  48. package/dist/strand-database.js +34 -10
  49. package/dist/strand-database.js.map +1 -1
  50. package/dist/strand-instance-manager.d.ts +200 -18
  51. package/dist/strand-instance-manager.js +434 -64
  52. package/dist/strand-instance-manager.js.map +1 -1
  53. package/dist/strand-membership-reconciler.d.ts +250 -51
  54. package/dist/strand-membership-reconciler.js +410 -66
  55. package/dist/strand-membership-reconciler.js.map +1 -1
  56. package/dist/strand-membership-writer.d.ts +7 -0
  57. package/dist/strand-membership-writer.js +9 -0
  58. package/dist/strand-membership-writer.js.map +1 -1
  59. package/dist/strand-party-key-rotation.d.ts +177 -0
  60. package/dist/strand-party-key-rotation.js +340 -0
  61. package/dist/strand-party-key-rotation.js.map +1 -0
  62. package/dist/strand-party-machines.d.ts +111 -0
  63. package/dist/strand-party-machines.js +258 -0
  64. package/dist/strand-party-machines.js.map +1 -0
  65. package/dist/strand-party-peers.d.ts +101 -0
  66. package/dist/strand-party-peers.js +49 -0
  67. package/dist/strand-party-peers.js.map +1 -0
  68. package/dist/strand-peer-redial.d.ts +34 -7
  69. package/dist/strand-peer-redial.js +46 -13
  70. package/dist/strand-peer-redial.js.map +1 -1
  71. package/dist/strand-revocation-enforcer.d.ts +15 -1
  72. package/dist/strand-revocation-enforcer.js +16 -9
  73. package/dist/strand-revocation-enforcer.js.map +1 -1
  74. package/dist/strand-transport-key.js +3 -0
  75. package/dist/strand-transport-key.js.map +1 -1
  76. package/dist/strand-watcher.d.ts +7 -4
  77. package/dist/strand-watcher.js +12 -7
  78. package/dist/strand-watcher.js.map +1 -1
  79. package/dist/types.d.ts +169 -13
  80. package/dist/types.js.map +1 -1
  81. package/package.json +9 -8
  82. package/src/cadre-node.ts +12280 -11528
  83. package/src/control-authorization.ts +41 -1
  84. package/src/control-database.ts +6123 -5603
  85. package/src/control-schema.ts +71 -7
  86. package/src/ed25519-key.ts +12 -1
  87. package/src/index.ts +957 -924
  88. package/src/machine-removal.ts +80 -1
  89. package/src/membership-connection-gater.ts +13 -1
  90. package/src/membership-view.ts +4 -1
  91. package/src/owner-keys.ts +2 -1
  92. package/src/owner-signer.ts +92 -94
  93. package/src/peer-authorization.ts +27 -3
  94. package/src/sealed-party-key.ts +190 -0
  95. package/src/seed-bootstrap.ts +17 -3
  96. package/src/strand-addr-protocol.ts +67 -6
  97. package/src/strand-commit-durability.ts +54 -5
  98. package/src/strand-database.ts +47 -11
  99. package/src/strand-instance-manager.ts +524 -65
  100. package/src/strand-membership-reconciler.ts +1310 -942
  101. package/src/strand-membership-writer.ts +10 -0
  102. package/src/strand-party-key-rotation.ts +436 -0
  103. package/src/strand-party-machines.ts +293 -0
  104. package/src/strand-party-peers.ts +129 -0
  105. package/src/strand-peer-redial.ts +61 -14
  106. package/src/strand-revocation-enforcer.ts +27 -9
  107. package/src/strand-transport-key.ts +3 -0
  108. package/src/strand-watcher.ts +12 -7
  109. package/src/types.ts +3121 -2963
@@ -43,7 +43,7 @@
43
43
  * CHECK the `'reissue'`-tagged digest `ControlDatabase.reissueRevocations`
44
44
  * signs — and `countRows` counts it.
45
45
  */
46
- export declare const CONTROL_TABLES: readonly ["OwnerKey", "ValidationKey", "Strand", "StrandPartyKey", "JoinedStrand", "JoinRequest", "JoinSuccess", "JoinFailure", "CadrePeer", "DeviceToken", "FormationInvite", "FormationUsage", "CadreInvite", "CadreInviteUsage", "OwnerGrant", "OwnerGrantUsage", "Revocation"];
46
+ export declare const CONTROL_TABLES: readonly ["OwnerKey", "ValidationKey", "Strand", "StrandPartyKey", "PendingStrandPartyKey", "JoinedStrand", "JoinRequest", "JoinSuccess", "JoinFailure", "CadrePeer", "DeviceToken", "StrandPeer", "FormationInvite", "FormationUsage", "CadreInvite", "CadreInviteUsage", "OwnerGrant", "OwnerGrantUsage", "Revocation"];
47
47
  /**
48
48
  * Name of a CadreControl table. Doubles as the table half of a
49
49
  * {@link ControlDomain} tag.
@@ -67,7 +67,7 @@ export type ControlTable = typeof CONTROL_TABLES[number];
67
67
  * (`control-database.ts`) so the lightweight signers — `peer-authorization.ts`'s
68
68
  * `revocationDigest` — can type against it without pulling in the runtime.
69
69
  */
70
- export type RevocableTable = Extract<ControlTable, 'OwnerKey' | 'CadrePeer' | 'ValidationKey' | 'Strand' | 'StrandPartyKey' | 'JoinedStrand' | 'JoinRequest' | 'DeviceToken' | 'CadreInvite' | 'OwnerGrant'>;
70
+ export type RevocableTable = Extract<ControlTable, 'OwnerKey' | 'CadrePeer' | 'ValidationKey' | 'Strand' | 'StrandPartyKey' | 'PendingStrandPartyKey' | 'JoinedStrand' | 'JoinRequest' | 'DeviceToken' | 'CadreInvite' | 'OwnerGrant'>;
71
71
  /**
72
72
  * What a signature authorizes, scoped to one table rule — or, for
73
73
  * `'Cadre.Enrollment'`, the offline peer vouch that `cadre enroll register`
@@ -157,6 +157,36 @@ export interface OwnerGrantSignedFields {
157
157
  * coalesce(cast(new.ExpiresAt as text), ''), coalesce(cast(new.TotalUses as text), ''), new.StampId`.
158
158
  */
159
159
  export declare function ownerGrantRowFields(row: OwnerGrantSignedFields): string[];
160
+ /**
161
+ * The `StrandPeer` columns its `'add'` signature binds, in the schema's order. Structurally
162
+ * satisfied by a `StrandPeerRow` (`types.ts`), which adds the signature itself.
163
+ */
164
+ export interface StrandPeerSignedFields {
165
+ strandId: string;
166
+ peerId: string;
167
+ strandPeerId: string;
168
+ }
169
+ /**
170
+ * The row-field half of a `StrandPeer` `'add'` digest, shared by the signer
171
+ * (`ControlDatabase.insertStrandPeer`) and the verifier (`peer-authorization.ts`'s
172
+ * `strandPeerAddDigest`). SQL mirror, in `StrandPeer.Authorized`:
173
+ * `new.StrandId, new.PeerId, new.StrandPeerId`.
174
+ */
175
+ export declare function strandPeerRowFields(row: StrandPeerSignedFields): string[];
176
+ /** The `PendingStrandPartyKey` columns its `'add'` signature binds, in the schema's order and with the row's stored forms. */
177
+ export interface PendingStrandPartyKeySignedFields {
178
+ strandId: string;
179
+ publicKey: string;
180
+ sealedKey: string;
181
+ superseded: string | null;
182
+ stampId: string;
183
+ }
184
+ /**
185
+ * The row-field half of a `PendingStrandPartyKey` `'add'` digest. SQL mirror, in
186
+ * `PendingStrandPartyKey.AuthorizedInsert`:
187
+ * `new.Id, new.PublicKey, new.SealedKey, coalesce(new.Superseded, ''), new.StampId`.
188
+ */
189
+ export declare function pendingStrandPartyKeyRowFields(row: PendingStrandPartyKeySignedFields): string[];
160
190
  /**
161
191
  * The full ordered field vector a party-bound control-plane signature covers. Digest
162
192
  * this with the crypto plugin's injective multi-field encoding (every field TEXT);
@@ -48,12 +48,14 @@ export const CONTROL_TABLES = [
48
48
  'ValidationKey',
49
49
  'Strand',
50
50
  'StrandPartyKey',
51
+ 'PendingStrandPartyKey',
51
52
  'JoinedStrand',
52
53
  'JoinRequest',
53
54
  'JoinSuccess',
54
55
  'JoinFailure',
55
56
  'CadrePeer',
56
57
  'DeviceToken',
58
+ 'StrandPeer',
57
59
  'FormationInvite',
58
60
  'FormationUsage',
59
61
  'CadreInvite',
@@ -95,6 +97,23 @@ export function ownerGrantRowFields(row) {
95
97
  row.stampId,
96
98
  ];
97
99
  }
100
+ /**
101
+ * The row-field half of a `StrandPeer` `'add'` digest, shared by the signer
102
+ * (`ControlDatabase.insertStrandPeer`) and the verifier (`peer-authorization.ts`'s
103
+ * `strandPeerAddDigest`). SQL mirror, in `StrandPeer.Authorized`:
104
+ * `new.StrandId, new.PeerId, new.StrandPeerId`.
105
+ */
106
+ export function strandPeerRowFields(row) {
107
+ return [row.strandId, row.peerId, row.strandPeerId];
108
+ }
109
+ /**
110
+ * The row-field half of a `PendingStrandPartyKey` `'add'` digest. SQL mirror, in
111
+ * `PendingStrandPartyKey.AuthorizedInsert`:
112
+ * `new.Id, new.PublicKey, new.SealedKey, coalesce(new.Superseded, ''), new.StampId`.
113
+ */
114
+ export function pendingStrandPartyKeyRowFields(row) {
115
+ return [row.strandId, row.publicKey, row.sealedKey, row.superseded ?? '', row.stampId];
116
+ }
98
117
  /**
99
118
  * The full ordered field vector a party-bound control-plane signature covers. Digest
100
119
  * this with the crypto plugin's injective multi-field encoding (every field TEXT);
@@ -1 +1 @@
1
- {"version":3,"file":"control-authorization.js","sourceRoot":"","sources":["../src/control-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,eAAe;IACf,QAAQ;IACR,gBAAgB;IAChB,cAAc;IACd,aAAa;IACb,aAAa;IACb,aAAa;IACb,WAAW;IACX,aAAa;IACb,iBAAiB;IACjB,gBAAgB;IAChB,aAAa;IACb,kBAAkB;IAClB,YAAY;IACZ,iBAAiB;IACjB,YAAY;CACJ,CAAC;AA2FX;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAA4B;IAC/D,OAAO;QACL,GAAG,CAAC,GAAG;QACP,GAAG,CAAC,MAAM,IAAI,EAAE;QAChB,GAAG,CAAC,SAAS,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACnD,GAAG,CAAC,OAAO;KACZ,CAAC;AACJ,CAAC;AAiBD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAA2B;IAC7D,OAAO;QACL,GAAG,CAAC,GAAG;QACP,GAAG,CAAC,KAAK,IAAI,EAAE;QACf,GAAG,CAAC,SAAS,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACnD,GAAG,CAAC,OAAO;KACZ,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAA0B,EAC1B,MAAqB,EACrB,OAAe,EACf,SAAmB;IAEnB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAA4B,EAC5B,MAAqB,EACrB,SAAmB;IAEnB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;AACxC,CAAC"}
1
+ {"version":3,"file":"control-authorization.js","sourceRoot":"","sources":["../src/control-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,eAAe;IACf,QAAQ;IACR,gBAAgB;IAChB,uBAAuB;IACvB,cAAc;IACd,aAAa;IACb,aAAa;IACb,aAAa;IACb,WAAW;IACX,aAAa;IACb,YAAY;IACZ,iBAAiB;IACjB,gBAAgB;IAChB,aAAa;IACb,kBAAkB;IAClB,YAAY;IACZ,iBAAiB;IACjB,YAAY;CACJ,CAAC;AA2FX;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAA4B;IAC/D,OAAO;QACL,GAAG,CAAC,GAAG;QACP,GAAG,CAAC,MAAM,IAAI,EAAE;QAChB,GAAG,CAAC,SAAS,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACnD,GAAG,CAAC,OAAO;KACZ,CAAC;AACJ,CAAC;AAiBD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAA2B;IAC7D,OAAO;QACL,GAAG,CAAC,GAAG;QACP,GAAG,CAAC,KAAK,IAAI,EAAE;QACf,GAAG,CAAC,SAAS,IAAI,EAAE;QACnB,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QACnD,GAAG,CAAC,OAAO;KACZ,CAAC;AACJ,CAAC;AAYD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAA2B;IAC7D,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC;AACtD,CAAC;AAWD;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAAC,GAAsC;IACnF,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AACzF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAA0B,EAC1B,MAAqB,EACrB,OAAe,EACf,SAAmB;IAEnB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,MAA4B,EAC5B,MAAqB,EACrB,SAAmB;IAEnB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;AACxC,CAAC"}
@@ -2,7 +2,7 @@ import { Database } from '@quereus/quereus';
2
2
  import type { SqlParameters } from '@quereus/quereus';
3
3
  import type { Libp2p } from '@libp2p/interface';
4
4
  import type { IRepo } from '@optimystic/db-core';
5
- import type { StrandRow, JoinRequestRow, JoinOutcome, PendingJoin, NodeProfile, PeerAddressRecord, CadrePeerRow, OwnerKeyRow, RevocationRow, DeviceTokenRecord, DeviceTokenRow, CadreInviteRow, CadreInviteUsageRow, CadreInviteRedemptionResult, CadreInviteStatus, OwnerGrantRow, OwnerGrantUsageRow, OwnerGrantRedemptionResult, OwnerGrantStatus, SeedPeer, MachineRemovalResult } from './types.js';
5
+ import type { StrandRow, StrandPeerRow, PendingStrandPartyKeyRow, SealedPendingPartyKey, JoinRequestRow, JoinOutcome, PendingJoin, NodeProfile, PeerAddressRecord, CadrePeerRow, OwnerKeyRow, RevocationRow, DeviceTokenRecord, DeviceTokenRow, CadreInviteRow, CadreInviteUsageRow, CadreInviteRedemptionResult, CadreInviteStatus, OwnerGrantRow, OwnerGrantUsageRow, OwnerGrantRedemptionResult, OwnerGrantStatus, SeedPeer, MachineRemovalWrites } from './types.js';
6
6
  import type { ControlTable, RevocableTable, BoundControlDomain, ControlAction, CadreInviteSignedFields, OwnerGrantSignedFields } from './control-authorization.js';
7
7
  import type { ControlWriteRetryOptions } from './control-write-retry.js';
8
8
  import type { ControlRetryAbandonment } from './control-retry.js';
@@ -309,6 +309,22 @@ export declare function ownerGrantConsentMessage(partyId: string, fields: OwnerG
309
309
  * ({@link ControlDatabase.withdrawCadreInvite}, {@link ControlDatabase.withdrawOwnerGrant}).
310
310
  */
311
311
  type IssuedTable = Extract<RevocableTable, 'CadreInvite' | 'OwnerGrant'>;
312
+ /**
313
+ * The key the party moves to in one strand, for {@link ControlDatabase.removeMachine}: its public
314
+ * half in the clear, its private half sealed to the machines that remain (`sealed-party-key.ts`).
315
+ */
316
+ export interface PendingPartyKeyEntry extends SealedPendingPartyKey {
317
+ readonly strandId: string;
318
+ }
319
+ /**
320
+ * One strand's control-row swap for {@link ControlDatabase.swapStrandPartyKeys}: the
321
+ * `StrandPartyKey` row moves from `oldKey` to `newKey`, both encoded as its `PrivateKey`.
322
+ */
323
+ export interface StrandPartyKeySwap {
324
+ readonly strandId: string;
325
+ readonly oldKey: string;
326
+ readonly newKey: string;
327
+ }
312
328
  /**
313
329
  * An owner key's label as its row stores it: trimmed, a blank one left out, and refused past
314
330
  * {@link OWNER_KEY_MAX_LABEL} by name rather than by the schema's `LabelLength` check.
@@ -459,10 +475,10 @@ export declare function projectSeedPeers(rows: readonly CadrePeerRow[], minterPe
459
475
  /**
460
476
  * Guarded tables a node may reap locally once their tombstone has committed — the
461
477
  * tables whose `AuthorizedDelete` carries the REAP branch (see the constraint comment on
462
- * `CadrePeer.AuthorizedDelete` in the schema). `Strand` and `StrandPartyKey` are
463
- * deliberately absent: their rows carry `MemberPrivateKey` / `PrivateKey` — party
464
- * secrets stored nowhere else (tickets/backlog/debt-strand-tombstone-reap.md owns any
465
- * future change). `JoinedStrand` also carries a `MemberPrivateKey` but IS reapable: that
478
+ * `CadrePeer.AuthorizedDelete` in the schema). `Strand`, `StrandPartyKey` and
479
+ * `PendingStrandPartyKey` are deliberately absent: their rows carry `MemberPrivateKey` /
480
+ * `PrivateKey` / `SealedKey` — party secrets stored nowhere else (tickets/backlog/debt-strand-tombstone-reap.md
481
+ * owns any future change). `JoinedStrand` also carries a `MemberPrivateKey` but IS reapable: that
466
482
  * secret is the joined strand's shared read key, which its founding party and every member
467
483
  * hold, so a reaped row is recoverable by re-forming. `JoinRequest` is reapable for the same
468
484
  * reason: the inviting party and the user also hold its invitation. `OwnerKey` has no
@@ -528,11 +544,12 @@ export interface ControlDatabaseConfig {
528
544
  */
529
545
  partyId: string;
530
546
  /**
531
- * Optional path to the control schema file.
547
+ * Optional path to the control schema file, for tests that vary the schema.
532
548
  * If not provided, uses the embedded schema for cross-platform compatibility.
533
- * Only use this if you need to override the default schema (e.g., for testing).
534
549
  * The file has the shape of `schemas/control.qsql`: one `declare schema CadreControl`
535
550
  * followed by one plain `apply schema CadreControl` ({@link controlSchemaFileDeclaration}).
551
+ * Under a `CadreNode` it must declare every table of this build's control schema, because the
552
+ * node watches and writes them.
536
553
  */
537
554
  schemaPath?: string;
538
555
  /** Libp2p node for the control network (injected) */
@@ -884,8 +901,8 @@ export declare class ControlDatabase {
884
901
  * such collections, and nothing creates them later: the start-time schema apply runs on every
885
902
  * machine, possibly alone, where committing one would be exactly the fork genesis avoids.
886
903
  *
887
- * NOTE: one `sync()` per collection, in sequence: 32 collections for today's schema (17 tables,
888
- * 3 indexes, 12 `unique` columns). Measured 2026-10-20 on a lone `CadreNode` over the network
904
+ * NOTE: one `sync()` per collection, in sequence: 35 collections for today's schema (19 tables,
905
+ * 3 indexes, 13 `unique` columns), 32 when this was measured. Measured 2026-10-20 on a lone `CadreNode` over the network
889
906
  * transactor (started, then `ensureOwnerKey` alone, 3 runs each): 64–105 ms in memory and
890
907
  * 750–820 ms on `FileRawStorage`, about 25 ms per collection on disk, roughly 1/75 of the edge
891
908
  * node's 60 s `DEFAULT_OWNER_GENESIS_TIMEOUT_MS`. Under the whole cadre-core suite's load (151
@@ -970,6 +987,20 @@ export declare class ControlDatabase {
970
987
  * lock is the same defect.
971
988
  */
972
989
  queryCadrePeers(retry?: boolean): Promise<CadrePeerRow[]>;
990
+ /**
991
+ * The live `CadrePeer` rows as {@link queryCadrePeers} judges them, and every `Revocation`
992
+ * tombstone, both read through storage now rather than served from the membership views.
993
+ * For the one reader that races the views' lag: the membership reconciler's sibling binding
994
+ * (`strand-party-peers.ts`), which must not bind a machine under a key because the removal
995
+ * that tombstoned it reached storage with no change event, which the view would serve for
996
+ * up to `MEMBERSHIP_VIEW_MAX_AGE_MS`. The chain tables stay on the views: a chain row missing
997
+ * makes a machine untrusted, which that reader ignores rather than acts on. One read of each
998
+ * table; the tombstones filter the rows and are returned, so the caller joins them once.
999
+ */
1000
+ queryMachineRowsFresh(): Promise<{
1001
+ peers: CadrePeerRow[];
1002
+ tombstones: RevocationRow[];
1003
+ }>;
973
1004
  /**
974
1005
  * The cadre's peers as a seed or a redemption reply carries them: every live `CadrePeer`
975
1006
  * row with its addresses, the minter and every always-on machine marked preferred
@@ -1035,6 +1066,8 @@ export declare class ControlDatabase {
1035
1066
  queryStrandStampId(strandId: string): Promise<string | null>;
1036
1067
  /** `StrandPartyKey` stamp nonce — bound into {@link deleteStrandPartyKey}'s remove digest. */
1037
1068
  queryStrandPartyKeyStampId(strandId: string): Promise<string | null>;
1069
+ /** `PendingStrandPartyKey` stamp nonce, retired or not — bound into {@link deletePendingStrandPartyKey}'s remove digest. */
1070
+ queryPendingStrandPartyKeyStampId(strandId: string): Promise<string | null>;
1038
1071
  /** `JoinedStrand` stamp nonce — bound into {@link deleteJoinedStrand}'s remove digest. */
1039
1072
  queryJoinedStrandStampId(strandId: string): Promise<string | null>;
1040
1073
  /**
@@ -1045,6 +1078,45 @@ export declare class ControlDatabase {
1045
1078
  * strand-wide read secret every joining party receives.
1046
1079
  */
1047
1080
  queryStrandPartyKey(strandId: string): Promise<string | null>;
1081
+ /**
1082
+ * The key this party is moving to in one strand, or null when no rotation is pending there. The
1083
+ * key itself rides sealed (`sealedKey`); `CadreNode` opens it under this machine's identity key
1084
+ * before driving the rotation, and a reader that only asks whether a rotation is pending never
1085
+ * needs to.
1086
+ *
1087
+ * A row whose stamp is retired reads as absent, as {@link queryPendingJoin} treats one: the
1088
+ * table has no reap branch, so a node that received the tombstone without the delete keeps the
1089
+ * physical row, and a replayed approval can re-seat a removed row on a node that has not seen
1090
+ * its tombstone. Either way a key that was replaced, perhaps because a removed machine had it,
1091
+ * must not read as the key to move to.
1092
+ */
1093
+ queryPendingStrandPartyKey(strandId: string): Promise<PendingStrandPartyKeyRow | null>;
1094
+ /** Every {@link queryPendingStrandPartyKey} row at once, by strand id, a retired stamp hidden the same way. */
1095
+ queryPendingStrandPartyKeys(): Promise<Map<string, PendingStrandPartyKeyRow>>;
1096
+ /**
1097
+ * Every machine's signed statement of its peer id in one strand. A row whose signature does
1098
+ * not verify against the key its `PeerId` derives from is dropped ({@link verifyStrandPeerRow}).
1099
+ * Which rows are live machines and which removed ones is the caller's question.
1100
+ *
1101
+ * NOTE: on a party whose store migrated to this table, nothing holds its collection until a
1102
+ * machine writes it, so a read asks the cohort to prove it empty and can fail while the other
1103
+ * machines are offline (`backlog/feat-strand-tables-added-by-a-later-schema-get-their-collection`).
1104
+ * A failure propagates rather than reading as "no rows": decide that with the caller that would
1105
+ * act on an empty list.
1106
+ */
1107
+ queryStrandPeers(strandId: string): Promise<StrandPeerRow[]>;
1108
+ /**
1109
+ * The raw `StrandPeer` rows of one strand. Filters on the leading primary-key column only and
1110
+ * compares again here: the optimystic module serves an equality on the whole composite key
1111
+ * with a single point lookup that can miss a row on a networked table, and declines a partial
1112
+ * match, which then scans (`scanMemberPeers` in `strand-membership-writer.ts`).
1113
+ * `retry: false` inside a locked write body.
1114
+ *
1115
+ * NOTE: because the predicate is not pushed down, this walks every strand's rows per call. Fine
1116
+ * at party scale; if a party ever runs many strands on many machines, this wants a reliable
1117
+ * composite-key seek rather than a secondary index, which would restore the seek dependency.
1118
+ */
1119
+ private readStrandPeerRows;
1048
1120
  /** `ValidationKey` stamp nonce — bound into {@link deleteValidationKey}'s remove digest. */
1049
1121
  queryValidationKeyStampId(key: string): Promise<string | null>;
1050
1122
  /**
@@ -1315,14 +1387,28 @@ export declare class ControlDatabase {
1315
1387
  * `DeviceToken` row when it has one, each with the `Revocation` tombstone retiring its stamp
1316
1388
  * ({@link deleteGuardedRow}'s statement pair, composed bare as {@link deleteStrandAndPartyKey}
1317
1389
  * composes it), plus a withdrawal tombstone for every `CadreInvite` in `target.inviteKeys`
1318
- * that is still live here ({@link withdrawCadreInvite}'s body). One transaction so no reader
1319
- * sees the machine half removed: a row gone but its push token resolvable, or an invitation
1320
- * it could redeem again still open. Owner keys are never touched: they are the person's, and
1321
- * removing one is {@link deleteOwnerKey}.
1390
+ * that is still live here ({@link withdrawCadreInvite}'s body), plus, for every strand in
1391
+ * `target.pendingPartyKeys`, a `PendingStrandPartyKey` row holding the key the party moves
1392
+ * to there (`strand-party-key-rotation.ts` moves it). One transaction so no reader sees the
1393
+ * machine half removed: a row gone but its push token resolvable, an invitation it could
1394
+ * redeem again still open, or its tombstone without the intent to rotate, which the strand
1395
+ * membership reconciler reads as "no rotation" and would then clear the binding the rotation
1396
+ * means to orphan (`strand-membership-reconciler.ts` → "Binding the party's other machines").
1397
+ * Owner keys are never touched: they are the person's, and removing one is
1398
+ * {@link deleteOwnerKey}.
1399
+ *
1400
+ * A strand that already holds a pending row gets it replaced: the stored row is retired
1401
+ * ({@link signPendingKeyRetirement}) and the fresh row's `Superseded` carries the replaced
1402
+ * key's public half after the stored row's own list, because the replaced key may already
1403
+ * have reached the machine being removed, and a seat it holds must be revoked. A stored row
1404
+ * whose stamp is already retired (held without its delete) is replaced the same way, with
1405
+ * no second tombstone. The caller seals each fresh key to the machines that remain
1406
+ * ({@link PendingPartyKeyEntry}); this writer never sees a pending key in the clear.
1322
1407
  *
1323
1408
  * Through {@link mutateCadrePeer}, the membership hub. Every stamp is read inside the locked
1324
1409
  * body, and a row whose stamp is already retired (held without its delete) is skipped rather
1325
- * than tombstoned twice. Nothing to remove writes nothing and returns all false.
1410
+ * than tombstoned twice. Nothing to remove writes nothing, pending rows included, and returns
1411
+ * all false: the machine was removed elsewhere, and that removal wrote the rotation rows.
1326
1412
  *
1327
1413
  * Opted into {@link LOST_UPDATE_RETRY_POLICY} for the reason on {@link deleteCadrePeer}: every
1328
1414
  * stamp and signature is minted inside the body, and the invitation keys come from the
@@ -1331,20 +1417,59 @@ export declare class ControlDatabase {
1331
1417
  * before). A lost update after a sibling tree of the transaction already synced arrives as a
1332
1418
  * partial commit and stays declined.
1333
1419
  *
1334
- * The caller decides which invitations the machine could use, from its plan
1335
- * (`CadreNode.planMachineRemoval`).
1420
+ * The caller decides which invitations the machine could use and which strands to rotate,
1421
+ * from its plan (`CadreNode.planMachineRemoval`).
1336
1422
  */
1337
1423
  removeMachine(target: {
1338
1424
  peerId: string;
1339
1425
  inviteKeys: readonly string[];
1340
- }, ownerKey: string, signMessage: ControlSign): Promise<MachineRemovalResult>;
1426
+ pendingPartyKeys?: readonly PendingPartyKeyEntry[];
1427
+ }, ownerKey: string, signMessage: ControlSign): Promise<MachineRemovalWrites>;
1428
+ /**
1429
+ * Every retired stamp held here, by table, from ONE `Revocation` scan inside a locked body
1430
+ * (`retry: false`), for a writer that checks several rows' stamps before one transaction.
1431
+ */
1432
+ private retiredStampsByTable;
1341
1433
  /**
1342
1434
  * The guarded removals {@link removeMachine} runs, signed over each row's current stamp:
1343
1435
  * the `CadrePeer` row and the `DeviceToken` row, each when present. Inside the locked body
1344
- * (every read `retry: false`); one `Revocation` scan serves the retired-stamp check for both
1345
- * tables.
1436
+ * (every read `retry: false`); `retired` is the body's one `Revocation` scan.
1346
1437
  */
1347
1438
  private signMachineRemovals;
1439
+ /**
1440
+ * The `PendingStrandPartyKey` writes {@link removeMachine} runs for `entries`: per strand, the
1441
+ * retirement of the row it already holds, if any, and the insert of the fresh key, whose
1442
+ * `Superseded` extends the stored row's list with the stored key's public half, read from the
1443
+ * row in the clear, so a remover that cannot open the stored row still replaces it. Signed
1444
+ * inside the locked body, before the transaction.
1445
+ *
1446
+ * NOTE: two owners removing different machines while partitioned each seal their fresh key to
1447
+ * the machine the other removed, and the row that survives the merge names it as a recipient;
1448
+ * the removed machine is then cut by the strand's rows alone, as before sealing. Revisit if a
1449
+ * partitioned double removal is seen to hand a removed machine a key it uses.
1450
+ */
1451
+ private signPendingPartyKeyReplacements;
1452
+ /**
1453
+ * The `PendingStrandPartyKey` row physically stored for `strandId`, retired or not, or null.
1454
+ * For a locked write body (`retry: false`): the public reader
1455
+ * ({@link queryPendingStrandPartyKey}) hides a retired row, and a writer replacing the row has
1456
+ * to remove the physical one either way.
1457
+ */
1458
+ private readStoredPendingPartyKey;
1459
+ /**
1460
+ * The owner-signed removal of a stored `PendingStrandPartyKey` row ({@link RowRetirement}): with
1461
+ * its tombstone when the row is live, as every guarded removal; without one when its stamp is
1462
+ * already retired (the tombstone reached this node without the delete; the table has no reap
1463
+ * branch, so a second tombstone would collide on `Revocation`'s key and leave the row).
1464
+ */
1465
+ private signPendingKeyRetirement;
1466
+ /**
1467
+ * Run one {@link RowRetirement} inside the caller's transaction: the guarded statement pair,
1468
+ * or the signed delete alone when the tombstone already exists.
1469
+ */
1470
+ private execRowRetirement;
1471
+ /** Fire the guarded-delete listener for a {@link RowRetirement} that filed a tombstone; a null or tombstone-less one fires nothing. */
1472
+ private notifyRowRetirement;
1348
1473
  /**
1349
1474
  * Insert a strand into the control database using an owner signature.
1350
1475
  *
@@ -1460,6 +1585,77 @@ export declare class ControlDatabase {
1460
1585
  * when the row does not exist — `false` then, `true` when a row was actually removed.
1461
1586
  */
1462
1587
  deleteStrandPartyKey(strandId: string, ownerKey: string, signMessage: ControlSign): Promise<boolean>;
1588
+ /**
1589
+ * Insert the key this party is moving to in one strand (`PendingStrandPartyKey` row), under an
1590
+ * owner signature, before the strand is touched.
1591
+ *
1592
+ * @param strandId - The strand whose party key is being replaced.
1593
+ * @param key - The new key: its public half (base64url) and its private half sealed to the
1594
+ * machines that may drive the move (`sealPartyKey` in `sealed-party-key.ts`).
1595
+ * @param superseded - Public keys (base64url) of earlier pending keys this row replaces.
1596
+ * @param ownerKey - Public key of the authorizing owner.
1597
+ * @param signMessage - Signs the raw message bytes with that owner's private key.
1598
+ */
1599
+ insertPendingStrandPartyKey(strandId: string, key: SealedPendingPartyKey, superseded: readonly string[], ownerKey: string, signMessage: ControlSign): Promise<void>;
1600
+ /**
1601
+ * The stamped, owner-signed `PendingStrandPartyKey` insert. Apart from
1602
+ * {@link insertPendingStrandPartyKey} so a writer can run it inside a larger transaction, as
1603
+ * {@link signStrandPartyKeyInsert} is. The public half and each superseded key must be a
1604
+ * well-formed public key: `Superseded` is comma-joined, base64url is what keeps the join
1605
+ * reversible, and the public half is what a later removal copies into it.
1606
+ */
1607
+ private signPendingStrandPartyKeyInsert;
1608
+ /**
1609
+ * Owner-signed removal of one `PendingStrandPartyKey` row with its tombstone, as
1610
+ * {@link deleteStrandPartyKey}. A no-op when the row does not exist — `false` then, `true`
1611
+ * when a row was actually removed.
1612
+ */
1613
+ deletePendingStrandPartyKey(strandId: string, ownerKey: string, signMessage: ControlSign): Promise<boolean>;
1614
+ /**
1615
+ * Move this party's membership key in each of `entries`' strands from `oldKey` to `newKey` in
1616
+ * the control record, in ONE transaction: per strand, the `StrandPartyKey` row's guarded
1617
+ * removal and a fresh insert naming `newKey` ({@link revouchOwnerKey}'s delete-and-re-add
1618
+ * idiom, under the same owner approval), and the retirement of the strand's
1619
+ * `PendingStrandPartyKey` row when its public half is `newKey`'s. The last step of a party key
1620
+ * rotation (`strand-party-key-rotation.ts`): the strand's rows already name `newKey` as the
1621
+ * party's member, so a reader that sees the new control row sees a key that counts.
1622
+ *
1623
+ * NOTE: the swapped `StrandPartyKey` row holds `newKey` in the clear and replicates to every
1624
+ * party machine, as it always has, since a machine admitted later has to read it; the pending
1625
+ * row is sealed, this one is not. The removed machine could receive it only from a sibling that
1626
+ * holds the swap but not yet the tombstone, and the swap runs strictly after the removal
1627
+ * committed; the `machine-removal-rotates-party-key` scenario asserts the removed machine stays
1628
+ * on the old key. Sealing this row too would mean re-sealing it at every admission. Revisit if
1629
+ * that assertion fails or such a sibling is observed.
1630
+ *
1631
+ * Decided inside the locked body, per strand, over the rows as stored (every read
1632
+ * `retry: false`): a row already naming `newKey` was swapped by another machine's driver and
1633
+ * is skipped; a row naming neither key, or no row at all (the strand left the party), is left
1634
+ * alone with a log, since the driver re-plans from the rows it finds; a pending row naming
1635
+ * another key (a later removal replaced it) stays, because that key is the next rotation's,
1636
+ * which the driver runs from `newKey`. A stale `StrandPartyKey` or pending row (stamp already
1637
+ * retired) is removed without a second tombstone ({@link RowRetirement}).
1638
+ *
1639
+ * @returns The strand ids whose control row was swapped here.
1640
+ */
1641
+ swapStrandPartyKeys(entries: readonly StrandPartyKeySwap[], ownerKey: string, signMessage: ControlSign): Promise<string[]>;
1642
+ /** The `StrandPartyKey` row stored for `strandId` with its stamp, for a locked write body (`retry: false`), or null. */
1643
+ private readStoredPartyKey;
1644
+ /**
1645
+ * Publish this machine's peer id in one strand (`StrandPeer` row), signed by this machine's
1646
+ * own identity key. Insert-if-absent: `true` when a row was written, `false` when this machine
1647
+ * already has one for the strand. The schema refuses the insert while this node does not hold
1648
+ * the machine's `CadrePeer` row, and that rejection propagates.
1649
+ *
1650
+ * @param row - The strand, and this machine's peer id in it (`strandTransportKey`).
1651
+ * @param sign - Signs the raw message bytes with the identity key behind this machine's
1652
+ * control peer id. A callback for the reason {@link updateSelfPeerRecord} takes one: this
1653
+ * class holds no private key.
1654
+ */
1655
+ insertStrandPeer(row: {
1656
+ strandId: string;
1657
+ strandPeerId: string;
1658
+ }, sign: ControlSign): Promise<boolean>;
1463
1659
  /**
1464
1660
  * Record, party-wide, a strand this party joined from another party (`JoinedStrand` row),
1465
1661
  * using an owner signature.
@@ -1765,6 +1961,13 @@ export declare class ControlDatabase {
1765
1961
  * come from closed literal unions — no caller-supplied string reaches the statement.
1766
1962
  */
1767
1963
  private execGuardedRemoval;
1964
+ /**
1965
+ * The delete half of {@link execGuardedRemoval}, alone: for a row whose stamp a committed
1966
+ * tombstone already retires ({@link RowRetirement} with no tombstone to file). The table's
1967
+ * `RevocationRecorded` check is met by that tombstone, and `AuthorizedDelete` by the owner
1968
+ * signature here, which the reap branch other tables carry does not exist for the key tables.
1969
+ */
1970
+ private execSignedDelete;
1768
1971
  /**
1769
1972
  * File the owner-signed `Revocation` tombstone retiring one row incarnation — the second
1770
1973
  * statement of every guarded removal ({@link execGuardedRemoval}) and the whole of an
@@ -1858,7 +2061,7 @@ export declare class ControlDatabase {
1858
2061
  *
1859
2062
  * Two rows are deliberately left alone:
1860
2063
  *
1861
- * - **Tables outside {@link REAPABLE_TABLES}** (`Strand`, `StrandPartyKey`, `OwnerKey`)
2064
+ * - **Tables outside {@link REAPABLE_TABLES}** (`Strand`, `StrandPartyKey`, `PendingStrandPartyKey`, `OwnerKey`)
1862
2065
  * — no reap branch exists on their `AuthorizedDelete`, so the delete would throw
1863
2066
  * rather than no-op.
1864
2067
  * - **This node's OWN `CadrePeer` / `DeviceToken` row** (`selfPeerId`). Reaping it would
@@ -2814,9 +3017,19 @@ export declare class ControlDatabase {
2814
3017
  * null handle instead of committing. The tail never rejects (it swallows both
2815
3018
  * outcomes), so the bare await is safe.
2816
3019
  *
2817
- * NOTE: this makes `close()` wait on a stuck write. Acceptable today — every locked
2818
- * body is a bounded local `exec` — but revisit (bounded drain, or abandon after a
2819
- * deadline) if a write can ever hang.
3020
+ * Then closes the Quereus `Database` and waits for it, and only then shuts the collection
3021
+ * factory down (which stops the control node): Quereus's close stops every running
3022
+ * statement and open iterator and resolves once nothing reads or writes, so no statement
3023
+ * reaches stopped storage. The handle stays set across the awaits, so a second, concurrent
3024
+ * close awaits the same teardown (Quereus returns the first call's promise) rather than
3025
+ * skipping ahead to the storage shutdown. A rejected Quereus close is logged and the
3026
+ * teardown goes on, because callers stop storage once this resolves.
3027
+ *
3028
+ * NOTE: this makes `close()` wait on a stuck write, and on a statement in a network wait
3029
+ * (a control read the local replica could not answer), the latter bounded by Optimystic's
3030
+ * RPC deadlines. Acceptable today — every locked body is a bounded local `exec`, and control
3031
+ * reads answer from the local replica — but revisit (bounded drain, or abort in-flight
3032
+ * collection work before closing Quereus) if a write can ever hang or node stops show up slow.
2820
3033
  */
2821
3034
  close(): Promise<void>;
2822
3035
  private ensureInitialized;