@serfab/cadre-core 1.19.0 → 1.20.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 (131) hide show
  1. package/dist/cadre-node.d.ts +118 -16
  2. package/dist/cadre-node.js +210 -31
  3. package/dist/cadre-node.js.map +1 -1
  4. package/dist/control-database.d.ts +2 -1
  5. package/dist/control-database.js +128 -126
  6. package/dist/control-database.js.map +1 -1
  7. package/dist/control-protocol-guard.js +3 -2
  8. package/dist/control-protocol-guard.js.map +1 -1
  9. package/dist/control-read-retry.d.ts +19 -16
  10. package/dist/control-read-retry.js +22 -54
  11. package/dist/control-read-retry.js.map +1 -1
  12. package/dist/control-retry.d.ts +50 -6
  13. package/dist/control-retry.js +53 -6
  14. package/dist/control-retry.js.map +1 -1
  15. package/dist/control-stream.js +2 -1
  16. package/dist/control-stream.js.map +1 -1
  17. package/dist/control-write-retry.d.ts +24 -16
  18. package/dist/control-write-retry.js +58 -30
  19. package/dist/control-write-retry.js.map +1 -1
  20. package/dist/describe-thrown.d.ts +12 -0
  21. package/dist/describe-thrown.js +59 -0
  22. package/dist/describe-thrown.js.map +1 -0
  23. package/dist/edge-node/config.d.ts +8 -2
  24. package/dist/edge-node/config.js +5 -1
  25. package/dist/edge-node/config.js.map +1 -1
  26. package/dist/edge-node/dissolve.d.ts +1 -1
  27. package/dist/edge-node/dissolve.js +1 -1
  28. package/dist/edge-node/dissolve.js.map +1 -1
  29. package/dist/edge-node/edge-join.js +4 -1
  30. package/dist/edge-node/edge-join.js.map +1 -1
  31. package/dist/edge-node/edge-node.d.ts +10 -0
  32. package/dist/edge-node/edge-node.js +54 -9
  33. package/dist/edge-node/edge-node.js.map +1 -1
  34. package/dist/edge-node/options.d.ts +11 -2
  35. package/dist/edge-node/options.js +11 -4
  36. package/dist/edge-node/options.js.map +1 -1
  37. package/dist/edge-node/platform.d.ts +15 -3
  38. package/dist/edge-node/strand-move.d.ts +0 -2
  39. package/dist/edge-node/strand-move.js +1 -4
  40. package/dist/edge-node/strand-move.js.map +1 -1
  41. package/dist/edge-node/strands.js +5 -3
  42. package/dist/edge-node/strands.js.map +1 -1
  43. package/dist/enrollment.js +2 -1
  44. package/dist/enrollment.js.map +1 -1
  45. package/dist/index.d.ts +6 -2
  46. package/dist/index.js +9 -1
  47. package/dist/index.js.map +1 -1
  48. package/dist/member-redemption.js +3 -9
  49. package/dist/member-redemption.js.map +1 -1
  50. package/dist/node-local-snapshot.js +2 -1
  51. package/dist/node-local-snapshot.js.map +1 -1
  52. package/dist/peer-dial.js +3 -2
  53. package/dist/peer-dial.js.map +1 -1
  54. package/dist/pending-join-runner.d.ts +29 -2
  55. package/dist/pending-join-runner.js +60 -20
  56. package/dist/pending-join-runner.js.map +1 -1
  57. package/dist/push-notifier-apns.js +8 -7
  58. package/dist/push-notifier-apns.js.map +1 -1
  59. package/dist/push-notifier-fcm.js +6 -5
  60. package/dist/push-notifier-fcm.js.map +1 -1
  61. package/dist/push-notifier-shared.d.ts +0 -2
  62. package/dist/push-notifier-shared.js +4 -4
  63. package/dist/push-notifier-shared.js.map +1 -1
  64. package/dist/relay-reservation.js +4 -3
  65. package/dist/relay-reservation.js.map +1 -1
  66. package/dist/strand-addr-protocol.js +2 -1
  67. package/dist/strand-addr-protocol.js.map +1 -1
  68. package/dist/strand-app-schema-report.d.ts +53 -0
  69. package/dist/strand-app-schema-report.js +77 -0
  70. package/dist/strand-app-schema-report.js.map +1 -0
  71. package/dist/strand-database.d.ts +60 -0
  72. package/dist/strand-database.js +93 -0
  73. package/dist/strand-database.js.map +1 -1
  74. package/dist/strand-first-sync-gate.js +4 -3
  75. package/dist/strand-first-sync-gate.js.map +1 -1
  76. package/dist/strand-formation-protocol.js +4 -3
  77. package/dist/strand-formation-protocol.js.map +1 -1
  78. package/dist/strand-instance-manager.d.ts +73 -2
  79. package/dist/strand-instance-manager.js +112 -9
  80. package/dist/strand-instance-manager.js.map +1 -1
  81. package/dist/strand-membership-reconciler.d.ts +13 -1
  82. package/dist/strand-membership-reconciler.js +25 -16
  83. package/dist/strand-membership-reconciler.js.map +1 -1
  84. package/dist/strand-membership-writer.d.ts +16 -2
  85. package/dist/strand-membership-writer.js +54 -8
  86. package/dist/strand-membership-writer.js.map +1 -1
  87. package/dist/strand-move.js +4 -6
  88. package/dist/strand-move.js.map +1 -1
  89. package/dist/strand-offline.d.ts +102 -0
  90. package/dist/strand-offline.js +97 -0
  91. package/dist/strand-offline.js.map +1 -0
  92. package/dist/types.d.ts +37 -0
  93. package/dist/types.js.map +1 -1
  94. package/package.json +8 -8
  95. package/src/cadre-node.ts +230 -31
  96. package/src/control-database.ts +5594 -5592
  97. package/src/control-protocol-guard.ts +3 -2
  98. package/src/control-read-retry.ts +22 -58
  99. package/src/control-retry.ts +54 -6
  100. package/src/control-stream.ts +2 -1
  101. package/src/control-write-retry.ts +58 -30
  102. package/src/describe-thrown.ts +60 -0
  103. package/src/edge-node/config.ts +11 -2
  104. package/src/edge-node/dissolve.ts +2 -1
  105. package/src/edge-node/edge-join.ts +2 -1
  106. package/src/edge-node/edge-node.ts +57 -7
  107. package/src/edge-node/options.ts +20 -4
  108. package/src/edge-node/platform.ts +15 -3
  109. package/src/edge-node/strand-move.ts +1 -5
  110. package/src/edge-node/strands.ts +74 -72
  111. package/src/enrollment.ts +2 -1
  112. package/src/index.ts +27 -1
  113. package/src/member-redemption.ts +3 -9
  114. package/src/node-local-snapshot.ts +2 -1
  115. package/src/peer-dial.ts +605 -604
  116. package/src/pending-join-runner.ts +68 -22
  117. package/src/push-notifier-apns.ts +8 -7
  118. package/src/push-notifier-fcm.ts +6 -5
  119. package/src/push-notifier-shared.ts +5 -5
  120. package/src/relay-reservation.ts +1212 -1211
  121. package/src/strand-addr-protocol.ts +2 -1
  122. package/src/strand-app-schema-report.ts +115 -0
  123. package/src/strand-database.ts +123 -1
  124. package/src/strand-first-sync-gate.ts +600 -599
  125. package/src/strand-formation-protocol.ts +4 -3
  126. package/src/strand-instance-manager.ts +137 -10
  127. package/src/strand-membership-reconciler.ts +942 -928
  128. package/src/strand-membership-writer.ts +61 -14
  129. package/src/strand-move.ts +594 -597
  130. package/src/strand-offline.ts +178 -0
  131. package/src/types.ts +36 -0
@@ -1702,7 +1702,8 @@ export declare class ControlDatabase {
1702
1702
  * when a row was actually removed.
1703
1703
  *
1704
1704
  * Opted into {@link LOST_UPDATE_RETRY_POLICY}: the row's machine may publish its own record
1705
- * at the moment of the removal (its first publish lands about a second after it starts), and
1705
+ * at the moment of the removal (its first publish lands about a second after it starts, or once
1706
+ * it reaches a sibling), and
1706
1707
  * the removal that loses is refused as a lost update. {@link deleteGuardedRow} reads the stamp
1707
1708
  * and signs inside the body, and a self-publish never changes the stamp the `'remove'` digest
1708
1709
  * binds, so the re-run reads the published row and removes it.
@@ -17,6 +17,7 @@ import { isCohortUnreachableRead, retryControlRead } from './control-read-retry.
17
17
  import { chainMessages } from './control-retry.js';
18
18
  import { TableWatchRegistry } from './table-change-watch.js';
19
19
  import { MembershipView } from './membership-view.js';
20
+ import { describeThrown } from './describe-thrown.js';
20
21
  const log = debug('sereus:cadre:control-db');
21
22
  const timing = debug('sereus:cadre:timing');
22
23
  /**
@@ -728,32 +729,32 @@ function formationInviteRowOf(row) {
728
729
  strandId: row.StrandId ?? null,
729
730
  };
730
731
  }
731
- const JOIN_REQUEST_INSERT_SQL = `
732
- insert into CadreControl.JoinRequest (Id, Invitation, Disclosure, RequestedAt, ExpiresAt, StampId)
733
- with context OwnerKey = ?, Signature = ?
734
- values (?, ?, ?, ?, ?, ?)
732
+ const JOIN_REQUEST_INSERT_SQL = `
733
+ insert into CadreControl.JoinRequest (Id, Invitation, Disclosure, RequestedAt, ExpiresAt, StampId)
734
+ with context OwnerKey = ?, Signature = ?
735
+ values (?, ?, ?, ?, ?, ?)
735
736
  `;
736
- const JOIN_SUCCESS_INSERT_SQL = `
737
- insert into CadreControl.JoinSuccess (RequestStampId, RecordedAt, StrandId, MembershipInvite)
738
- with context OwnerKey = ?, Signature = ?
739
- values (?, ?, ?, ?)
737
+ const JOIN_SUCCESS_INSERT_SQL = `
738
+ insert into CadreControl.JoinSuccess (RequestStampId, RecordedAt, StrandId, MembershipInvite)
739
+ with context OwnerKey = ?, Signature = ?
740
+ values (?, ?, ?, ?)
740
741
  `;
741
- const JOIN_FAILURE_INSERT_SQL = `
742
- insert into CadreControl.JoinFailure (RequestStampId, RecordedAt, Code, Reason)
743
- with context OwnerKey = ?, Signature = ?
744
- values (?, ?, ?, ?)
742
+ const JOIN_FAILURE_INSERT_SQL = `
743
+ insert into CadreControl.JoinFailure (RequestStampId, RecordedAt, Code, Reason)
744
+ with context OwnerKey = ?, Signature = ?
745
+ values (?, ?, ?, ?)
745
746
  `;
746
747
  /**
747
748
  * A request with its outcome in one statement: the outcome tables are keyed by the request's
748
749
  * stamp, so the join finds exactly this incarnation's outcome.
749
750
  */
750
- const PENDING_JOIN_SELECT_SQL = `
751
- select R.Id, R.Invitation, R.Disclosure, R.RequestedAt, R.ExpiresAt, R.StampId,
752
- S.RecordedAt as JoinedAt, S.StrandId, S.MembershipInvite,
753
- F.RecordedAt as FailedAt, F.Code, F.Reason
754
- from CadreControl.JoinRequest R
755
- left join CadreControl.JoinSuccess S on S.RequestStampId = R.StampId
756
- left join CadreControl.JoinFailure F on F.RequestStampId = R.StampId
751
+ const PENDING_JOIN_SELECT_SQL = `
752
+ select R.Id, R.Invitation, R.Disclosure, R.RequestedAt, R.ExpiresAt, R.StampId,
753
+ S.RecordedAt as JoinedAt, S.StrandId, S.MembershipInvite,
754
+ F.RecordedAt as FailedAt, F.Code, F.Reason
755
+ from CadreControl.JoinRequest R
756
+ left join CadreControl.JoinSuccess S on S.RequestStampId = R.StampId
757
+ left join CadreControl.JoinFailure F on F.RequestStampId = R.StampId
757
758
  `;
758
759
  /** A {@link PENDING_JOIN_SELECT_SQL} row as read. */
759
760
  function pendingJoinOf(row) {
@@ -818,7 +819,7 @@ async function readSchemaFile(schemaPath) {
818
819
  return await fs.readFile(schemaPath, 'utf-8');
819
820
  }
820
821
  catch (error) {
821
- throw new Error(`Failed to load schema from ${schemaPath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
822
+ throw new Error(`Failed to load schema from ${schemaPath}: ${describeThrown(error)}`, { cause: error });
822
823
  }
823
824
  }
824
825
  /**
@@ -1911,11 +1912,11 @@ export class ControlDatabase {
1911
1912
  }
1912
1913
  const record = sign(current);
1913
1914
  // Bare `exec` — inside the non-re-entrant write lock (see insertCadrePeer).
1914
- await this.db.exec(`
1915
- update CadreControl.CadrePeer
1916
- with context OwnerKey = null, Signature = ?
1917
- set Multiaddr = ?, UpdatedAt = ?, Profile = ?, Sig = ?
1918
- where PeerId = ?
1915
+ await this.db.exec(`
1916
+ update CadreControl.CadrePeer
1917
+ with context OwnerKey = null, Signature = ?
1918
+ set Multiaddr = ?, UpdatedAt = ?, Profile = ?, Sig = ?
1919
+ where PeerId = ?
1919
1920
  `, [record.sig, record.addrs.join(','), record.updatedAt, record.profile, record.sig, peerId]);
1920
1921
  return record;
1921
1922
  }, LOST_UPDATE_RETRY_POLICY, 'self-record-update');
@@ -1967,11 +1968,11 @@ export class ControlDatabase {
1967
1968
  */
1968
1969
  async updateSelfDeviceToken(record) {
1969
1970
  this.ensureInitialized();
1970
- await this.execWrite(`
1971
- update CadreControl.DeviceToken
1972
- with context OwnerKey = null, Signature = ?
1973
- set Platform = ?, Token = ?, UpdatedAt = ?, Sig = ?
1974
- where PeerId = ?
1971
+ await this.execWrite(`
1972
+ update CadreControl.DeviceToken
1973
+ with context OwnerKey = null, Signature = ?
1974
+ set Platform = ?, Token = ?, UpdatedAt = ?, Sig = ?
1975
+ where PeerId = ?
1975
1976
  `, [record.sig, record.platform, record.token, record.updatedAt, record.sig, record.peerId], 'device-token-update');
1976
1977
  log('Self device token updated: %s (platform=%s, updatedAt=%d)', record.peerId, record.platform, record.updatedAt);
1977
1978
  }
@@ -1994,10 +1995,10 @@ export class ControlDatabase {
1994
1995
  // not-null/unique anti-replay constraint — the StampId is a real column value, not the
1995
1996
  // optimystic `StampId()` SQL function.
1996
1997
  const stampId = generateStampId(this.config.libp2pNode.peerId.toString());
1997
- await this.execWrite(`
1998
- insert into CadreControl.OwnerKey (Key, Label, StampId)
1999
- with context OwnerKey = null, Signature = null
2000
- values (?, ?, ?)
1998
+ await this.execWrite(`
1999
+ insert into CadreControl.OwnerKey (Key, Label, StampId)
2000
+ with context OwnerKey = null, Signature = null
2001
+ values (?, ?, ?)
2001
2002
  `, [key, storedLabel, stampId], 'owner-key-insert');
2002
2003
  log('Owner key inserted');
2003
2004
  }
@@ -2064,10 +2065,10 @@ export class ControlDatabase {
2064
2065
  * NOT re-entrant.
2065
2066
  */
2066
2067
  async execOwnerKeyVouchedInsert(row, ownerKey, signature) {
2067
- await this.db.exec(`
2068
- insert into CadreControl.OwnerKey (Key, Label, StampId, VouchOwner, VouchSig)
2069
- with context OwnerKey = ?, Signature = ?
2070
- values (?, ?, ?, ?, ?)
2068
+ await this.db.exec(`
2069
+ insert into CadreControl.OwnerKey (Key, Label, StampId, VouchOwner, VouchSig)
2070
+ with context OwnerKey = ?, Signature = ?
2071
+ values (?, ?, ?, ?, ?)
2071
2072
  `, [ownerKey, signature, row.key, row.label, row.stampId, ownerKey, signature]);
2072
2073
  }
2073
2074
  /**
@@ -2266,10 +2267,10 @@ export class ControlDatabase {
2266
2267
  // StampId is a real, unique column (single-use anti-replay), no longer a context value.
2267
2268
  // FounderOwnerKey must equal the signing owner or the constraint rejects the row.
2268
2269
  return {
2269
- sql: `
2270
- insert into CadreControl.Strand (Id, Type, MemberPrivateKey, StampId, FounderOwnerKey, FounderPeerId)
2271
- with context OwnerKey = ?, Signature = ?
2272
- values (?, ?, ?, ?, ?, ?)
2270
+ sql: `
2271
+ insert into CadreControl.Strand (Id, Type, MemberPrivateKey, StampId, FounderOwnerKey, FounderPeerId)
2272
+ with context OwnerKey = ?, Signature = ?
2273
+ values (?, ?, ?, ?, ?, ?)
2273
2274
  `,
2274
2275
  params: [ownerKey, signature, strandId, type, memberPrivateKey ?? null, stampId, ownerKey, peerId],
2275
2276
  };
@@ -2412,10 +2413,10 @@ export class ControlDatabase {
2412
2413
  const message = buildAuthorizationMessage('CadreControl.StrandPartyKey', 'add', this.config.partyId, [strandId, privateKey, stampId]);
2413
2414
  const signature = await signMessage(message);
2414
2415
  return {
2415
- sql: `
2416
- insert into CadreControl.StrandPartyKey (Id, PrivateKey, StampId)
2417
- with context OwnerKey = ?, Signature = ?
2418
- values (?, ?, ?)
2416
+ sql: `
2417
+ insert into CadreControl.StrandPartyKey (Id, PrivateKey, StampId)
2418
+ with context OwnerKey = ?, Signature = ?
2419
+ values (?, ?, ?)
2419
2420
  `,
2420
2421
  params: [ownerKey, signature, strandId, privateKey, stampId],
2421
2422
  };
@@ -2455,10 +2456,10 @@ export class ControlDatabase {
2455
2456
  // Id, Type, MemberPrivateKey ('' when null), StampId.
2456
2457
  const message = buildAuthorizationMessage('CadreControl.JoinedStrand', 'add', this.config.partyId, [row.Id, row.Type, row.MemberPrivateKey ?? '', stampId]);
2457
2458
  const signature = await signMessage(message);
2458
- await this.execWrite(`
2459
- insert into CadreControl.JoinedStrand (Id, Type, MemberPrivateKey, StampId)
2460
- with context OwnerKey = ?, Signature = ?
2461
- values (?, ?, ?, ?)
2459
+ await this.execWrite(`
2460
+ insert into CadreControl.JoinedStrand (Id, Type, MemberPrivateKey, StampId)
2461
+ with context OwnerKey = ?, Signature = ?
2462
+ values (?, ?, ?, ?)
2462
2463
  `, [ownerKey, signature, row.Id, row.Type, row.MemberPrivateKey, stampId], 'joined-strand-insert');
2463
2464
  log('Joined strand inserted: %s', row.Id);
2464
2465
  }
@@ -2585,10 +2586,10 @@ export class ControlDatabase {
2585
2586
  }
2586
2587
  /** One unsigned outcome delete (see {@link deleteJoinOutcomes}; a failure's is also authorized by the join superseding it). */
2587
2588
  async deleteJoinOutcome(table, requestStampId) {
2588
- await this.db.exec(`
2589
- delete from CadreControl.${table}
2590
- with context OwnerKey = null, Signature = null
2591
- where RequestStampId = ?
2589
+ await this.db.exec(`
2590
+ delete from CadreControl.${table}
2591
+ with context OwnerKey = null, Signature = null
2592
+ where RequestStampId = ?
2592
2593
  `, [requestStampId]);
2593
2594
  }
2594
2595
  /**
@@ -2612,10 +2613,10 @@ export class ControlDatabase {
2612
2613
  // Field order MUST match the schema's ValidationKey `AuthorizedInsert` verify: Key, StampId.
2613
2614
  const message = buildAuthorizationMessage('CadreControl.ValidationKey', 'add', this.config.partyId, [key, stampId]);
2614
2615
  const signature = await signMessage(message);
2615
- await this.execWrite(`
2616
- insert into CadreControl.ValidationKey (Key, StampId)
2617
- with context OwnerKey = ?, Signature = ?
2618
- values (?, ?)
2616
+ await this.execWrite(`
2617
+ insert into CadreControl.ValidationKey (Key, StampId)
2618
+ with context OwnerKey = ?, Signature = ?
2619
+ values (?, ?)
2619
2620
  `, [ownerKey, signature, key, stampId], 'validation-key-insert');
2620
2621
  log('Validation key inserted: %s', key);
2621
2622
  }
@@ -2693,10 +2694,10 @@ export class ControlDatabase {
2693
2694
  // Persist the vouching (owner, signature) onto the row (VouchOwner/VouchSig) —
2694
2695
  // identical to the context pair, which the AuthorizedInsert constraint binds — so a
2695
2696
  // reader can later re-check the voucher against its node-local trusted-owner anchor.
2696
- await this.db.exec(`
2697
- insert into CadreControl.CadrePeer (PeerId, PublicKey, Multiaddr, UpdatedAt, Sig, Profile, StampId, VouchOwner, VouchSig)
2698
- with context OwnerKey = ?, Signature = ?
2699
- values (?, ?, ?, ?, ?, ?, ?, ?, ?)
2697
+ await this.db.exec(`
2698
+ insert into CadreControl.CadrePeer (PeerId, PublicKey, Multiaddr, UpdatedAt, Sig, Profile, StampId, VouchOwner, VouchSig)
2699
+ with context OwnerKey = ?, Signature = ?
2700
+ values (?, ?, ?, ?, ?, ?, ?, ?, ?)
2700
2701
  `, [ownerKey, signature, row.peerId, row.publicKey, row.multiaddr, row.updatedAt, row.sig, row.profile, stampId, ownerKey, signature]);
2701
2702
  return true;
2702
2703
  });
@@ -2785,19 +2786,19 @@ export class ControlDatabase {
2785
2786
  const signature = await signMessage(buildAuthorizationMessage('CadreControl.CadrePeer', 'vouch', this.config.partyId, [peerId, target.stampId]));
2786
2787
  // Bare `exec` — inside the non-re-entrant write lock (see insertCadrePeer).
2787
2788
  if (mode === 'rebroadcast') {
2788
- await this.db.exec(`
2789
- update CadreControl.CadrePeer
2790
- with context OwnerKey = ?, Signature = ?
2791
- set UpdatedAt = ?, VouchOwner = ?, VouchSig = ?, VouchUsage = null
2792
- where PeerId = ?
2789
+ await this.db.exec(`
2790
+ update CadreControl.CadrePeer
2791
+ with context OwnerKey = ?, Signature = ?
2792
+ set UpdatedAt = ?, VouchOwner = ?, VouchSig = ?, VouchUsage = null
2793
+ where PeerId = ?
2793
2794
  `, [ownerKey, signature, Math.max(Date.now(), target.updatedAt + 1), ownerKey, signature, peerId]);
2794
2795
  }
2795
2796
  else {
2796
- await this.db.exec(`
2797
- update CadreControl.CadrePeer
2798
- with context OwnerKey = ?, Signature = ?
2799
- set VouchOwner = ?, VouchSig = ?, VouchUsage = null
2800
- where PeerId = ?
2797
+ await this.db.exec(`
2798
+ update CadreControl.CadrePeer
2799
+ with context OwnerKey = ?, Signature = ?
2800
+ set VouchOwner = ?, VouchSig = ?, VouchUsage = null
2801
+ where PeerId = ?
2801
2802
  `, [ownerKey, signature, ownerKey, signature, peerId]);
2802
2803
  }
2803
2804
  return 'retouched';
@@ -2824,7 +2825,8 @@ export class ControlDatabase {
2824
2825
  * when a row was actually removed.
2825
2826
  *
2826
2827
  * Opted into {@link LOST_UPDATE_RETRY_POLICY}: the row's machine may publish its own record
2827
- * at the moment of the removal (its first publish lands about a second after it starts), and
2828
+ * at the moment of the removal (its first publish lands about a second after it starts, or once
2829
+ * it reaches a sibling), and
2828
2830
  * the removal that loses is refused as a lost update. {@link deleteGuardedRow} reads the stamp
2829
2831
  * and signs inside the body, and a self-publish never changes the stamp the `'remove'` digest
2830
2832
  * binds, so the re-run reads the published row and removes it.
@@ -2907,10 +2909,10 @@ export class ControlDatabase {
2907
2909
  */
2908
2910
  async execGuardedRemoval(removal, ownerKey) {
2909
2911
  const { tableName, rowKey, stampId } = removal.ref;
2910
- await this.db.exec(`
2911
- delete from CadreControl.${tableName}
2912
- with context OwnerKey = ?, Signature = ?
2913
- where ${GUARDED_KEY_COLUMN[tableName]} = ? and StampId = ?
2912
+ await this.db.exec(`
2913
+ delete from CadreControl.${tableName}
2914
+ with context OwnerKey = ?, Signature = ?
2915
+ where ${GUARDED_KEY_COLUMN[tableName]} = ? and StampId = ?
2914
2916
  `, [ownerKey, removal.signature, rowKey, stampId]);
2915
2917
  await this.execTombstone(removal.ref, removal.revocationSignature, ownerKey);
2916
2918
  }
@@ -2928,10 +2930,10 @@ export class ControlDatabase {
2928
2930
  * equal), so a node that receives the row by replication can tell which owner filed it.
2929
2931
  */
2930
2932
  async execTombstone(ref, revocationSignature, ownerKey) {
2931
- await this.db.exec(`
2932
- insert into CadreControl.Revocation (TableName, RowKey, StampId, ReissuedAt, SignerKey, SignerSig)
2933
- with context OwnerKey = ?, Signature = ?
2934
- values (?, ?, ?, 0, ?, ?)
2933
+ await this.db.exec(`
2934
+ insert into CadreControl.Revocation (TableName, RowKey, StampId, ReissuedAt, SignerKey, SignerSig)
2935
+ with context OwnerKey = ?, Signature = ?
2936
+ values (?, ?, ?, 0, ?, ?)
2935
2937
  `, [ownerKey, revocationSignature, ref.tableName, ref.rowKey, ref.stampId, ownerKey, revocationSignature]);
2936
2938
  }
2937
2939
  /**
@@ -3015,10 +3017,10 @@ export class ControlDatabase {
3015
3017
  log('reap %s: %s holds a fresh incarnation (live stamp differs from the tombstoned one); leaving it', table, rowKey);
3016
3018
  return false;
3017
3019
  }
3018
- const sql = `
3019
- delete from CadreControl.${table}
3020
- with context OwnerKey = null, Signature = null
3021
- where ${GUARDED_KEY_COLUMN[table]} = ? and StampId = ?
3020
+ const sql = `
3021
+ delete from CadreControl.${table}
3022
+ with context OwnerKey = null, Signature = null
3023
+ where ${GUARDED_KEY_COLUMN[table]} = ? and StampId = ?
3022
3024
  `;
3023
3025
  if (table === 'CadrePeer') {
3024
3026
  // Through mutateCadrePeer so the "EVERY CadrePeer writer goes through here"
@@ -3193,11 +3195,11 @@ export class ControlDatabase {
3193
3195
  // output minted per row incarnation (generateStampId), so it identifies one
3194
3196
  // row across all TableName values. Do NOT "fix" this by adding TableName to
3195
3197
  // the where clause.
3196
- await this.db.exec(`
3197
- update CadreControl.Revocation
3198
- with context OwnerKey = ?, Signature = ?
3199
- set ReissuedAt = ?
3200
- where StampId = ?
3198
+ await this.db.exec(`
3199
+ update CadreControl.Revocation
3200
+ with context OwnerKey = ?, Signature = ?
3201
+ set ReissuedAt = ?
3202
+ where StampId = ?
3201
3203
  `, [ownerKey, signature, reissuedAt, row.stampId]);
3202
3204
  executed++;
3203
3205
  }
@@ -3598,10 +3600,10 @@ export class ControlDatabase {
3598
3600
  // signed source-of-truth and the stored value are produced once. StampId is a real,
3599
3601
  // unique column (single-use anti-replay), no longer a context value.
3600
3602
  return {
3601
- sql: `
3602
- insert into CadreControl.FormationInvite (Token, sAppId, ExpiresAt, TotalUses, ValidationUrl, StrandId, StampId)
3603
- with context OwnerKey = ?, Signature = ?
3604
- values (?, ?, ?, ?, ?, ?, ?)
3603
+ sql: `
3604
+ insert into CadreControl.FormationInvite (Token, sAppId, ExpiresAt, TotalUses, ValidationUrl, StrandId, StampId)
3605
+ with context OwnerKey = ?, Signature = ?
3606
+ values (?, ?, ?, ?, ?, ?, ?)
3605
3607
  `,
3606
3608
  params: [
3607
3609
  ownerKey, signature,
@@ -3671,10 +3673,10 @@ export class ControlDatabase {
3671
3673
  // Hard-coded open + keyless + explicit null founder columns: the
3672
3674
  // consent branch admits no other shape (no signature means no
3673
3675
  // trustworthy founder machine to record — see the schema's comment).
3674
- await this.db.exec(`
3675
- insert into CadreControl.Strand (Id, Type, MemberPrivateKey, StampId, FounderOwnerKey, FounderPeerId)
3676
- with context OwnerKey = null, Signature = null
3677
- values (?, 'o', null, ?, null, null)
3676
+ await this.db.exec(`
3677
+ insert into CadreControl.Strand (Id, Type, MemberPrivateKey, StampId, FounderOwnerKey, FounderPeerId)
3678
+ with context OwnerKey = null, Signature = null
3679
+ values (?, 'o', null, ?, null, null)
3678
3680
  `, [strandId, strandStampId]);
3679
3681
  // 2. FormationUsage row — authorised by the matching FormationInvite, and
3680
3682
  // carrying the strand's stamp so it authorizes THIS row and no other.
@@ -3793,10 +3795,10 @@ export class ControlDatabase {
3793
3795
  // robustness/consistency change, matching the strand layer's `consumeInvite`,
3794
3796
  // not a fix for an observable mis-ordering.
3795
3797
  const nowCanonical = await canonicalDatetime(this.db, opts.nowMs);
3796
- await this.db.exec(`
3797
- insert into CadreControl.FormationUsage (Token, UsageStampId, PeerKey, PeerSig, Disclosure, StrandId, StrandStampId)
3798
- with context Now = ?, ValidationKey = ?, ValidationSignature = ?
3799
- values (?, ?, ?, ?, ?, ?, ?)
3798
+ await this.db.exec(`
3799
+ insert into CadreControl.FormationUsage (Token, UsageStampId, PeerKey, PeerSig, Disclosure, StrandId, StrandStampId)
3800
+ with context Now = ?, ValidationKey = ?, ValidationSignature = ?
3801
+ values (?, ?, ?, ?, ?, ?, ?)
3800
3802
  `, [
3801
3803
  nowCanonical, opts.validationKey, opts.validationSignature,
3802
3804
  opts.token, opts.usageStampId, opts.peerKey,
@@ -4045,10 +4047,10 @@ export class ControlDatabase {
4045
4047
  }
4046
4048
  /** Bare `CadreInvite` insert shared by {@link insertCadreInvite} and {@link seatCadreInvite}; the caller holds the lock. */
4047
4049
  async execCadreInviteInsert(row) {
4048
- await this.db.exec(`
4049
- insert into CadreControl.CadreInvite (Key, PeerId, ExpiresAt, TotalUses, IssuerKey, IssuerSig, StampId)
4050
- with context OwnerKey = ?, Signature = ?
4051
- values (?, ?, ?, ?, ?, ?, ?)
4050
+ await this.db.exec(`
4051
+ insert into CadreControl.CadreInvite (Key, PeerId, ExpiresAt, TotalUses, IssuerKey, IssuerSig, StampId)
4052
+ with context OwnerKey = ?, Signature = ?
4053
+ values (?, ?, ?, ?, ?, ?, ?)
4052
4054
  `, [
4053
4055
  row.issuerKey, row.issuerSig,
4054
4056
  row.key, row.peerId, row.expiresAt, row.totalUses,
@@ -4349,16 +4351,16 @@ export class ControlDatabase {
4349
4351
  const peerStampId = generateStampId(peerId);
4350
4352
  const nowCanonical = await canonicalDatetime(this.db, nowMs);
4351
4353
  await this.inTransaction('cadre-invite-redeem', async () => {
4352
- await this.db.exec(`
4353
- insert into CadreControl.CadrePeer (PeerId, PublicKey, Multiaddr, UpdatedAt, Sig, Profile, StampId, VouchOwner, VouchSig, VouchUsage)
4354
- with context OwnerKey = null, Signature = null
4355
- values (?, ?, ?, ?, ?, ?, ?, ?, null, ?)
4354
+ await this.db.exec(`
4355
+ insert into CadreControl.CadrePeer (PeerId, PublicKey, Multiaddr, UpdatedAt, Sig, Profile, StampId, VouchOwner, VouchSig, VouchUsage)
4356
+ with context OwnerKey = null, Signature = null
4357
+ values (?, ?, ?, ?, ?, ?, ?, ?, null, ?)
4356
4358
  `, [peerId, peerKey, multiaddr, record?.updatedAt ?? nowMs, record?.sig ?? null, record?.profile ?? null,
4357
4359
  peerStampId, invite.issuerKey, usageStampId]);
4358
- await this.db.exec(`
4359
- insert into CadreControl.CadreInviteUsage (UsageStampId, InviteKey, PeerId, PeerKey, PeerStampId, InviteSig, PeerSig)
4360
- with context Now = ?
4361
- values (?, ?, ?, ?, ?, ?, ?)
4360
+ await this.db.exec(`
4361
+ insert into CadreControl.CadreInviteUsage (UsageStampId, InviteKey, PeerId, PeerKey, PeerStampId, InviteSig, PeerSig)
4362
+ with context Now = ?
4363
+ values (?, ?, ?, ?, ?, ?, ?)
4362
4364
  `, [nowCanonical, usageStampId, inviteKey, peerId, peerKey, peerStampId, inviteSig, peerSig]);
4363
4365
  });
4364
4366
  log('Redeemed cadre invitation %s: %s admitted (usage %s)', inviteKey, peerId, usageStampId);
@@ -4439,10 +4441,10 @@ export class ControlDatabase {
4439
4441
  }
4440
4442
  /** Bare `OwnerGrant` insert shared by {@link insertOwnerGrant} and {@link seatOwnerGrant}; the caller holds the lock. */
4441
4443
  async execOwnerGrantInsert(row) {
4442
- await this.db.exec(`
4443
- insert into CadreControl.OwnerGrant (Key, Label, ExpiresAt, TotalUses, IssuerKey, IssuerSig, StampId)
4444
- with context OwnerKey = ?, Signature = ?
4445
- values (?, ?, ?, ?, ?, ?, ?)
4444
+ await this.db.exec(`
4445
+ insert into CadreControl.OwnerGrant (Key, Label, ExpiresAt, TotalUses, IssuerKey, IssuerSig, StampId)
4446
+ with context OwnerKey = ?, Signature = ?
4447
+ values (?, ?, ?, ?, ?, ?, ?)
4446
4448
  `, [
4447
4449
  row.issuerKey, row.issuerSig,
4448
4450
  row.key, row.label, row.expiresAt, row.totalUses,
@@ -4572,15 +4574,15 @@ export class ControlDatabase {
4572
4574
  const seatedStampId = generateStampId(this.config.libp2pNode.peerId.toString());
4573
4575
  const nowCanonical = await canonicalDatetime(this.db, nowMs);
4574
4576
  await this.inTransaction('owner-grant-redeem', async () => {
4575
- await this.db.exec(`
4576
- insert into CadreControl.OwnerKey (Key, Label, StampId, VouchOwner, VouchSig, VouchUsage)
4577
- with context OwnerKey = null, Signature = null
4578
- values (?, ?, ?, ?, null, ?)
4577
+ await this.db.exec(`
4578
+ insert into CadreControl.OwnerKey (Key, Label, StampId, VouchOwner, VouchSig, VouchUsage)
4579
+ with context OwnerKey = null, Signature = null
4580
+ values (?, ?, ?, ?, null, ?)
4579
4581
  `, [seatedKey, grant.label, seatedStampId, grant.issuerKey, usageStampId]);
4580
- await this.db.exec(`
4581
- insert into CadreControl.OwnerGrantUsage (UsageStampId, GrantKey, SeatedKey, SeatedStampId, GrantSig, OwnerSig)
4582
- with context Now = ?
4583
- values (?, ?, ?, ?, ?, ?)
4582
+ await this.db.exec(`
4583
+ insert into CadreControl.OwnerGrantUsage (UsageStampId, GrantKey, SeatedKey, SeatedStampId, GrantSig, OwnerSig)
4584
+ with context Now = ?
4585
+ values (?, ?, ?, ?, ?, ?)
4584
4586
  `, [nowCanonical, usageStampId, grantKey, seatedKey, seatedStampId, grantSig, ownerSig]);
4585
4587
  });
4586
4588
  log('Redeemed owner grant %s: %s seated as an owner (usage %s)', grantKey, seatedKey, usageStampId);