@optimystic/db-core 0.13.5 → 0.14.1

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 (447) hide show
  1. package/dist/src/cluster/structs.d.ts +13 -0
  2. package/dist/src/cluster/structs.d.ts.map +1 -1
  3. package/dist/src/cohort-topic/addressing.d.ts +53 -0
  4. package/dist/src/cohort-topic/addressing.d.ts.map +1 -0
  5. package/dist/src/cohort-topic/addressing.js +95 -0
  6. package/dist/src/cohort-topic/addressing.js.map +1 -0
  7. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.d.ts +105 -0
  8. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.d.ts.map +1 -0
  9. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.js +197 -0
  10. package/dist/src/cohort-topic/antidos/bootstrap-evidence-envelope.js.map +1 -0
  11. package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts +50 -0
  12. package/dist/src/cohort-topic/antidos/bootstrap-evidence.d.ts.map +1 -0
  13. package/dist/src/cohort-topic/antidos/bootstrap-evidence.js +62 -0
  14. package/dist/src/cohort-topic/antidos/bootstrap-evidence.js.map +1 -0
  15. package/dist/src/cohort-topic/antidos/index.d.ts +6 -0
  16. package/dist/src/cohort-topic/antidos/index.d.ts.map +1 -0
  17. package/dist/src/cohort-topic/antidos/index.js +6 -0
  18. package/dist/src/cohort-topic/antidos/index.js.map +1 -0
  19. package/dist/src/cohort-topic/antidos/rate-limiter.d.ts +95 -0
  20. package/dist/src/cohort-topic/antidos/rate-limiter.d.ts.map +1 -0
  21. package/dist/src/cohort-topic/antidos/rate-limiter.js +146 -0
  22. package/dist/src/cohort-topic/antidos/rate-limiter.js.map +1 -0
  23. package/dist/src/cohort-topic/antidos/replay-guard.d.ts +37 -0
  24. package/dist/src/cohort-topic/antidos/replay-guard.d.ts.map +1 -0
  25. package/dist/src/cohort-topic/antidos/replay-guard.js +78 -0
  26. package/dist/src/cohort-topic/antidos/replay-guard.js.map +1 -0
  27. package/dist/src/cohort-topic/antidos/topic-budget.d.ts +50 -0
  28. package/dist/src/cohort-topic/antidos/topic-budget.d.ts.map +1 -0
  29. package/dist/src/cohort-topic/antidos/topic-budget.js +95 -0
  30. package/dist/src/cohort-topic/antidos/topic-budget.js.map +1 -0
  31. package/dist/src/cohort-topic/antiflood/index.d.ts +3 -0
  32. package/dist/src/cohort-topic/antiflood/index.d.ts.map +1 -0
  33. package/dist/src/cohort-topic/antiflood/index.js +3 -0
  34. package/dist/src/cohort-topic/antiflood/index.js.map +1 -0
  35. package/dist/src/cohort-topic/antiflood/invariants.d.ts +70 -0
  36. package/dist/src/cohort-topic/antiflood/invariants.d.ts.map +1 -0
  37. package/dist/src/cohort-topic/antiflood/invariants.js +86 -0
  38. package/dist/src/cohort-topic/antiflood/invariants.js.map +1 -0
  39. package/dist/src/cohort-topic/antiflood/jitter.d.ts +65 -0
  40. package/dist/src/cohort-topic/antiflood/jitter.d.ts.map +1 -0
  41. package/dist/src/cohort-topic/antiflood/jitter.js +75 -0
  42. package/dist/src/cohort-topic/antiflood/jitter.js.map +1 -0
  43. package/dist/src/cohort-topic/coldstart.d.ts +117 -0
  44. package/dist/src/cohort-topic/coldstart.d.ts.map +1 -0
  45. package/dist/src/cohort-topic/coldstart.js +127 -0
  46. package/dist/src/cohort-topic/coldstart.js.map +1 -0
  47. package/dist/src/cohort-topic/dmax.d.ts +44 -0
  48. package/dist/src/cohort-topic/dmax.d.ts.map +1 -0
  49. package/dist/src/cohort-topic/dmax.js +70 -0
  50. package/dist/src/cohort-topic/dmax.js.map +1 -0
  51. package/dist/src/cohort-topic/gossip/bus.d.ts +85 -0
  52. package/dist/src/cohort-topic/gossip/bus.d.ts.map +1 -0
  53. package/dist/src/cohort-topic/gossip/bus.js +146 -0
  54. package/dist/src/cohort-topic/gossip/bus.js.map +1 -0
  55. package/dist/src/cohort-topic/gossip/index.d.ts +4 -0
  56. package/dist/src/cohort-topic/gossip/index.d.ts.map +1 -0
  57. package/dist/src/cohort-topic/gossip/index.js +4 -0
  58. package/dist/src/cohort-topic/gossip/index.js.map +1 -0
  59. package/dist/src/cohort-topic/gossip/records.d.ts +12 -0
  60. package/dist/src/cohort-topic/gossip/records.d.ts.map +1 -0
  61. package/dist/src/cohort-topic/gossip/records.js +41 -0
  62. package/dist/src/cohort-topic/gossip/records.js.map +1 -0
  63. package/dist/src/cohort-topic/gossip/view.d.ts +39 -0
  64. package/dist/src/cohort-topic/gossip/view.d.ts.map +1 -0
  65. package/dist/src/cohort-topic/gossip/view.js +30 -0
  66. package/dist/src/cohort-topic/gossip/view.js.map +1 -0
  67. package/dist/src/cohort-topic/index.d.ts +21 -0
  68. package/dist/src/cohort-topic/index.d.ts.map +1 -0
  69. package/dist/src/cohort-topic/index.js +21 -0
  70. package/dist/src/cohort-topic/index.js.map +1 -0
  71. package/dist/src/cohort-topic/load/barometer.d.ts +78 -0
  72. package/dist/src/cohort-topic/load/barometer.d.ts.map +1 -0
  73. package/dist/src/cohort-topic/load/barometer.js +93 -0
  74. package/dist/src/cohort-topic/load/barometer.js.map +1 -0
  75. package/dist/src/cohort-topic/load/index.d.ts +2 -0
  76. package/dist/src/cohort-topic/load/index.d.ts.map +1 -0
  77. package/dist/src/cohort-topic/load/index.js +2 -0
  78. package/dist/src/cohort-topic/load/index.js.map +1 -0
  79. package/dist/src/cohort-topic/member-engine.d.ts +134 -0
  80. package/dist/src/cohort-topic/member-engine.d.ts.map +1 -0
  81. package/dist/src/cohort-topic/member-engine.js +264 -0
  82. package/dist/src/cohort-topic/member-engine.js.map +1 -0
  83. package/dist/src/cohort-topic/membership/index.d.ts +4 -0
  84. package/dist/src/cohort-topic/membership/index.d.ts.map +1 -0
  85. package/dist/src/cohort-topic/membership/index.js +4 -0
  86. package/dist/src/cohort-topic/membership/index.js.map +1 -0
  87. package/dist/src/cohort-topic/membership/publisher.d.ts +82 -0
  88. package/dist/src/cohort-topic/membership/publisher.d.ts.map +1 -0
  89. package/dist/src/cohort-topic/membership/publisher.js +107 -0
  90. package/dist/src/cohort-topic/membership/publisher.js.map +1 -0
  91. package/dist/src/cohort-topic/membership/source.d.ts +31 -0
  92. package/dist/src/cohort-topic/membership/source.d.ts.map +1 -0
  93. package/dist/src/cohort-topic/membership/source.js +32 -0
  94. package/dist/src/cohort-topic/membership/source.js.map +1 -0
  95. package/dist/src/cohort-topic/membership/verifier.d.ts +96 -0
  96. package/dist/src/cohort-topic/membership/verifier.d.ts.map +1 -0
  97. package/dist/src/cohort-topic/membership/verifier.js +250 -0
  98. package/dist/src/cohort-topic/membership/verifier.js.map +1 -0
  99. package/dist/src/cohort-topic/ports.d.ts +149 -0
  100. package/dist/src/cohort-topic/ports.d.ts.map +1 -0
  101. package/dist/src/cohort-topic/ports.js +25 -0
  102. package/dist/src/cohort-topic/ports.js.map +1 -0
  103. package/dist/src/cohort-topic/promotion.d.ts +135 -0
  104. package/dist/src/cohort-topic/promotion.d.ts.map +1 -0
  105. package/dist/src/cohort-topic/promotion.js +269 -0
  106. package/dist/src/cohort-topic/promotion.js.map +1 -0
  107. package/dist/src/cohort-topic/registration/bytes.d.ts +16 -0
  108. package/dist/src/cohort-topic/registration/bytes.d.ts.map +1 -0
  109. package/dist/src/cohort-topic/registration/bytes.js +32 -0
  110. package/dist/src/cohort-topic/registration/bytes.js.map +1 -0
  111. package/dist/src/cohort-topic/registration/handoff.d.ts +69 -0
  112. package/dist/src/cohort-topic/registration/handoff.d.ts.map +1 -0
  113. package/dist/src/cohort-topic/registration/handoff.js +98 -0
  114. package/dist/src/cohort-topic/registration/handoff.js.map +1 -0
  115. package/dist/src/cohort-topic/registration/index.d.ts +7 -0
  116. package/dist/src/cohort-topic/registration/index.d.ts.map +1 -0
  117. package/dist/src/cohort-topic/registration/index.js +7 -0
  118. package/dist/src/cohort-topic/registration/index.js.map +1 -0
  119. package/dist/src/cohort-topic/registration/renewal.d.ts +115 -0
  120. package/dist/src/cohort-topic/registration/renewal.d.ts.map +1 -0
  121. package/dist/src/cohort-topic/registration/renewal.js +306 -0
  122. package/dist/src/cohort-topic/registration/renewal.js.map +1 -0
  123. package/dist/src/cohort-topic/registration/sharding.d.ts +31 -0
  124. package/dist/src/cohort-topic/registration/sharding.d.ts.map +1 -0
  125. package/dist/src/cohort-topic/registration/sharding.js +48 -0
  126. package/dist/src/cohort-topic/registration/sharding.js.map +1 -0
  127. package/dist/src/cohort-topic/registration/store.d.ts +13 -0
  128. package/dist/src/cohort-topic/registration/store.d.ts.map +1 -0
  129. package/dist/src/cohort-topic/registration/store.js +72 -0
  130. package/dist/src/cohort-topic/registration/store.js.map +1 -0
  131. package/dist/src/cohort-topic/registration/types.d.ts +71 -0
  132. package/dist/src/cohort-topic/registration/types.d.ts.map +1 -0
  133. package/dist/src/cohort-topic/registration/types.js +27 -0
  134. package/dist/src/cohort-topic/registration/types.js.map +1 -0
  135. package/dist/src/cohort-topic/ring-hash.d.ts +27 -0
  136. package/dist/src/cohort-topic/ring-hash.d.ts.map +1 -0
  137. package/dist/src/cohort-topic/ring-hash.js +45 -0
  138. package/dist/src/cohort-topic/ring-hash.js.map +1 -0
  139. package/dist/src/cohort-topic/service.d.ts +157 -0
  140. package/dist/src/cohort-topic/service.d.ts.map +1 -0
  141. package/dist/src/cohort-topic/service.js +237 -0
  142. package/dist/src/cohort-topic/service.js.map +1 -0
  143. package/dist/src/cohort-topic/sig/index.d.ts +3 -0
  144. package/dist/src/cohort-topic/sig/index.d.ts.map +1 -0
  145. package/dist/src/cohort-topic/sig/index.js +3 -0
  146. package/dist/src/cohort-topic/sig/index.js.map +1 -0
  147. package/dist/src/cohort-topic/sig/payloads.d.ts +25 -0
  148. package/dist/src/cohort-topic/sig/payloads.d.ts.map +1 -0
  149. package/dist/src/cohort-topic/sig/payloads.js +25 -0
  150. package/dist/src/cohort-topic/sig/payloads.js.map +1 -0
  151. package/dist/src/cohort-topic/sig/threshold.d.ts +33 -0
  152. package/dist/src/cohort-topic/sig/threshold.d.ts.map +1 -0
  153. package/dist/src/cohort-topic/sig/threshold.js +51 -0
  154. package/dist/src/cohort-topic/sig/threshold.js.map +1 -0
  155. package/dist/src/cohort-topic/tiers.d.ts +58 -0
  156. package/dist/src/cohort-topic/tiers.d.ts.map +1 -0
  157. package/dist/src/cohort-topic/tiers.js +49 -0
  158. package/dist/src/cohort-topic/tiers.js.map +1 -0
  159. package/dist/src/cohort-topic/traffic.d.ts +90 -0
  160. package/dist/src/cohort-topic/traffic.d.ts.map +1 -0
  161. package/dist/src/cohort-topic/traffic.js +146 -0
  162. package/dist/src/cohort-topic/traffic.js.map +1 -0
  163. package/dist/src/cohort-topic/walk.d.ts +123 -0
  164. package/dist/src/cohort-topic/walk.d.ts.map +1 -0
  165. package/dist/src/cohort-topic/walk.js +150 -0
  166. package/dist/src/cohort-topic/walk.js.map +1 -0
  167. package/dist/src/cohort-topic/willingness.d.ts +123 -0
  168. package/dist/src/cohort-topic/willingness.d.ts.map +1 -0
  169. package/dist/src/cohort-topic/willingness.js +143 -0
  170. package/dist/src/cohort-topic/willingness.js.map +1 -0
  171. package/dist/src/cohort-topic/wire/codec.d.ts +42 -0
  172. package/dist/src/cohort-topic/wire/codec.d.ts.map +1 -0
  173. package/dist/src/cohort-topic/wire/codec.js +163 -0
  174. package/dist/src/cohort-topic/wire/codec.js.map +1 -0
  175. package/dist/src/cohort-topic/wire/index.d.ts +6 -0
  176. package/dist/src/cohort-topic/wire/index.d.ts.map +1 -0
  177. package/dist/src/cohort-topic/wire/index.js +6 -0
  178. package/dist/src/cohort-topic/wire/index.js.map +1 -0
  179. package/dist/src/cohort-topic/wire/payloads.d.ts +38 -0
  180. package/dist/src/cohort-topic/wire/payloads.d.ts.map +1 -0
  181. package/dist/src/cohort-topic/wire/payloads.js +102 -0
  182. package/dist/src/cohort-topic/wire/payloads.js.map +1 -0
  183. package/dist/src/cohort-topic/wire/types.d.ts +304 -0
  184. package/dist/src/cohort-topic/wire/types.d.ts.map +1 -0
  185. package/dist/src/cohort-topic/wire/types.js +16 -0
  186. package/dist/src/cohort-topic/wire/types.js.map +1 -0
  187. package/dist/src/cohort-topic/wire/validate.d.ts +25 -0
  188. package/dist/src/cohort-topic/wire/validate.d.ts.map +1 -0
  189. package/dist/src/cohort-topic/wire/validate.js +427 -0
  190. package/dist/src/cohort-topic/wire/validate.js.map +1 -0
  191. package/dist/src/collection/collection.d.ts +58 -1
  192. package/dist/src/collection/collection.d.ts.map +1 -1
  193. package/dist/src/collection/collection.js +76 -0
  194. package/dist/src/collection/collection.js.map +1 -1
  195. package/dist/src/collections/tree/tree.d.ts +58 -2
  196. package/dist/src/collections/tree/tree.d.ts.map +1 -1
  197. package/dist/src/collections/tree/tree.js +59 -2
  198. package/dist/src/collections/tree/tree.js.map +1 -1
  199. package/dist/src/index.d.ts +3 -0
  200. package/dist/src/index.d.ts.map +1 -1
  201. package/dist/src/index.js +3 -0
  202. package/dist/src/index.js.map +1 -1
  203. package/dist/src/log/log.d.ts +42 -4
  204. package/dist/src/log/log.d.ts.map +1 -1
  205. package/dist/src/log/log.js +71 -3
  206. package/dist/src/log/log.js.map +1 -1
  207. package/dist/src/log/struct.d.ts +122 -2
  208. package/dist/src/log/struct.d.ts.map +1 -1
  209. package/dist/src/log/struct.js.map +1 -1
  210. package/dist/src/matchmaking/capability-filter.d.ts +24 -0
  211. package/dist/src/matchmaking/capability-filter.d.ts.map +1 -0
  212. package/dist/src/matchmaking/capability-filter.js +37 -0
  213. package/dist/src/matchmaking/capability-filter.js.map +1 -0
  214. package/dist/src/matchmaking/config.d.ts +77 -0
  215. package/dist/src/matchmaking/config.d.ts.map +1 -0
  216. package/dist/src/matchmaking/config.js +69 -0
  217. package/dist/src/matchmaking/config.js.map +1 -0
  218. package/dist/src/matchmaking/index.d.ts +21 -0
  219. package/dist/src/matchmaking/index.d.ts.map +1 -0
  220. package/dist/src/matchmaking/index.js +21 -0
  221. package/dist/src/matchmaking/index.js.map +1 -0
  222. package/dist/src/matchmaking/multi-cohort-seeker.d.ts +133 -0
  223. package/dist/src/matchmaking/multi-cohort-seeker.d.ts.map +1 -0
  224. package/dist/src/matchmaking/multi-cohort-seeker.js +142 -0
  225. package/dist/src/matchmaking/multi-cohort-seeker.js.map +1 -0
  226. package/dist/src/matchmaking/provider.d.ts +70 -0
  227. package/dist/src/matchmaking/provider.d.ts.map +1 -0
  228. package/dist/src/matchmaking/provider.js +93 -0
  229. package/dist/src/matchmaking/provider.js.map +1 -0
  230. package/dist/src/matchmaking/query-eval.d.ts +53 -0
  231. package/dist/src/matchmaking/query-eval.d.ts.map +1 -0
  232. package/dist/src/matchmaking/query-eval.js +69 -0
  233. package/dist/src/matchmaking/query-eval.js.map +1 -0
  234. package/dist/src/matchmaking/seeker-walk.d.ts +95 -0
  235. package/dist/src/matchmaking/seeker-walk.d.ts.map +1 -0
  236. package/dist/src/matchmaking/seeker-walk.js +75 -0
  237. package/dist/src/matchmaking/seeker-walk.js.map +1 -0
  238. package/dist/src/matchmaking/seeker.d.ts +51 -0
  239. package/dist/src/matchmaking/seeker.d.ts.map +1 -0
  240. package/dist/src/matchmaking/seeker.js +62 -0
  241. package/dist/src/matchmaking/seeker.js.map +1 -0
  242. package/dist/src/matchmaking/topic-anchor.d.ts +54 -0
  243. package/dist/src/matchmaking/topic-anchor.d.ts.map +1 -0
  244. package/dist/src/matchmaking/topic-anchor.js +67 -0
  245. package/dist/src/matchmaking/topic-anchor.js.map +1 -0
  246. package/dist/src/matchmaking/voting-quorum.d.ts +233 -0
  247. package/dist/src/matchmaking/voting-quorum.d.ts.map +1 -0
  248. package/dist/src/matchmaking/voting-quorum.js +238 -0
  249. package/dist/src/matchmaking/voting-quorum.js.map +1 -0
  250. package/dist/src/matchmaking/wire.d.ts +259 -0
  251. package/dist/src/matchmaking/wire.d.ts.map +1 -0
  252. package/dist/src/matchmaking/wire.js +484 -0
  253. package/dist/src/matchmaking/wire.js.map +1 -0
  254. package/dist/src/network/i-repo.d.ts +9 -0
  255. package/dist/src/network/i-repo.d.ts.map +1 -1
  256. package/dist/src/network/repo-protocol.d.ts +3 -1
  257. package/dist/src/network/repo-protocol.d.ts.map +1 -1
  258. package/dist/src/network/struct.d.ts +23 -1
  259. package/dist/src/network/struct.d.ts.map +1 -1
  260. package/dist/src/reactivity/backfill.d.ts +118 -0
  261. package/dist/src/reactivity/backfill.d.ts.map +1 -0
  262. package/dist/src/reactivity/backfill.js +137 -0
  263. package/dist/src/reactivity/backfill.js.map +1 -0
  264. package/dist/src/reactivity/backpressure.d.ts +99 -0
  265. package/dist/src/reactivity/backpressure.d.ts.map +1 -0
  266. package/dist/src/reactivity/backpressure.js +153 -0
  267. package/dist/src/reactivity/backpressure.js.map +1 -0
  268. package/dist/src/reactivity/checkpoint.d.ts +165 -0
  269. package/dist/src/reactivity/checkpoint.d.ts.map +1 -0
  270. package/dist/src/reactivity/checkpoint.js +232 -0
  271. package/dist/src/reactivity/checkpoint.js.map +1 -0
  272. package/dist/src/reactivity/config.d.ts +131 -0
  273. package/dist/src/reactivity/config.d.ts.map +1 -0
  274. package/dist/src/reactivity/config.js +135 -0
  275. package/dist/src/reactivity/config.js.map +1 -0
  276. package/dist/src/reactivity/dedupe.d.ts +51 -0
  277. package/dist/src/reactivity/dedupe.d.ts.map +1 -0
  278. package/dist/src/reactivity/dedupe.js +90 -0
  279. package/dist/src/reactivity/dedupe.js.map +1 -0
  280. package/dist/src/reactivity/forwarder.d.ts +50 -0
  281. package/dist/src/reactivity/forwarder.d.ts.map +1 -0
  282. package/dist/src/reactivity/forwarder.js +52 -0
  283. package/dist/src/reactivity/forwarder.js.map +1 -0
  284. package/dist/src/reactivity/index.d.ts +34 -0
  285. package/dist/src/reactivity/index.d.ts.map +1 -0
  286. package/dist/src/reactivity/index.js +34 -0
  287. package/dist/src/reactivity/index.js.map +1 -0
  288. package/dist/src/reactivity/notification.d.ts +72 -0
  289. package/dist/src/reactivity/notification.d.ts.map +1 -0
  290. package/dist/src/reactivity/notification.js +92 -0
  291. package/dist/src/reactivity/notification.js.map +1 -0
  292. package/dist/src/reactivity/policy.d.ts +59 -0
  293. package/dist/src/reactivity/policy.d.ts.map +1 -0
  294. package/dist/src/reactivity/policy.js +64 -0
  295. package/dist/src/reactivity/policy.js.map +1 -0
  296. package/dist/src/reactivity/push-state.d.ts +140 -0
  297. package/dist/src/reactivity/push-state.d.ts.map +1 -0
  298. package/dist/src/reactivity/push-state.js +270 -0
  299. package/dist/src/reactivity/push-state.js.map +1 -0
  300. package/dist/src/reactivity/recover.d.ts +75 -0
  301. package/dist/src/reactivity/recover.d.ts.map +1 -0
  302. package/dist/src/reactivity/recover.js +105 -0
  303. package/dist/src/reactivity/recover.js.map +1 -0
  304. package/dist/src/reactivity/replay-buffer.d.ts +57 -0
  305. package/dist/src/reactivity/replay-buffer.d.ts.map +1 -0
  306. package/dist/src/reactivity/replay-buffer.js +88 -0
  307. package/dist/src/reactivity/replay-buffer.js.map +1 -0
  308. package/dist/src/reactivity/resume.d.ts +214 -0
  309. package/dist/src/reactivity/resume.d.ts.map +1 -0
  310. package/dist/src/reactivity/resume.js +358 -0
  311. package/dist/src/reactivity/resume.js.map +1 -0
  312. package/dist/src/reactivity/rotation.d.ts +283 -0
  313. package/dist/src/reactivity/rotation.d.ts.map +1 -0
  314. package/dist/src/reactivity/rotation.js +265 -0
  315. package/dist/src/reactivity/rotation.js.map +1 -0
  316. package/dist/src/reactivity/subscriber.d.ts +66 -0
  317. package/dist/src/reactivity/subscriber.d.ts.map +1 -0
  318. package/dist/src/reactivity/subscriber.js +75 -0
  319. package/dist/src/reactivity/subscriber.js.map +1 -0
  320. package/dist/src/reactivity/subscription.d.ts +52 -0
  321. package/dist/src/reactivity/subscription.d.ts.map +1 -0
  322. package/dist/src/reactivity/subscription.js +28 -0
  323. package/dist/src/reactivity/subscription.js.map +1 -0
  324. package/dist/src/reactivity/topic-anchor.d.ts +46 -0
  325. package/dist/src/reactivity/topic-anchor.d.ts.map +1 -0
  326. package/dist/src/reactivity/topic-anchor.js +61 -0
  327. package/dist/src/reactivity/topic-anchor.js.map +1 -0
  328. package/dist/src/reactivity/verify.d.ts +41 -0
  329. package/dist/src/reactivity/verify.d.ts.map +1 -0
  330. package/dist/src/reactivity/verify.js +48 -0
  331. package/dist/src/reactivity/verify.js.map +1 -0
  332. package/dist/src/reactivity/wire-validate.d.ts +28 -0
  333. package/dist/src/reactivity/wire-validate.d.ts.map +1 -0
  334. package/dist/src/reactivity/wire-validate.js +79 -0
  335. package/dist/src/reactivity/wire-validate.js.map +1 -0
  336. package/dist/src/reactivity/wire.d.ts +102 -0
  337. package/dist/src/reactivity/wire.d.ts.map +1 -0
  338. package/dist/src/reactivity/wire.js +129 -0
  339. package/dist/src/reactivity/wire.js.map +1 -0
  340. package/dist/src/transaction/coordinator.d.ts +9 -5
  341. package/dist/src/transaction/coordinator.d.ts.map +1 -1
  342. package/dist/src/transaction/coordinator.js +48 -25
  343. package/dist/src/transaction/coordinator.js.map +1 -1
  344. package/dist/src/transactor/change-notifier.d.ts +74 -0
  345. package/dist/src/transactor/change-notifier.d.ts.map +1 -0
  346. package/dist/src/transactor/change-notifier.js +4 -0
  347. package/dist/src/transactor/change-notifier.js.map +1 -0
  348. package/dist/src/transactor/index.d.ts +1 -0
  349. package/dist/src/transactor/index.d.ts.map +1 -1
  350. package/dist/src/transactor/index.js +1 -0
  351. package/dist/src/transactor/index.js.map +1 -1
  352. package/dist/src/transactor/network-transactor.d.ts +34 -2
  353. package/dist/src/transactor/network-transactor.d.ts.map +1 -1
  354. package/dist/src/transactor/network-transactor.js +113 -13
  355. package/dist/src/transactor/network-transactor.js.map +1 -1
  356. package/package.json +2 -2
  357. package/src/cluster/structs.ts +13 -0
  358. package/src/cohort-topic/addressing.ts +112 -0
  359. package/src/cohort-topic/antidos/bootstrap-evidence-envelope.ts +253 -0
  360. package/src/cohort-topic/antidos/bootstrap-evidence.ts +94 -0
  361. package/src/cohort-topic/antidos/index.ts +5 -0
  362. package/src/cohort-topic/antidos/rate-limiter.ts +210 -0
  363. package/src/cohort-topic/antidos/replay-guard.ts +109 -0
  364. package/src/cohort-topic/antidos/topic-budget.ts +145 -0
  365. package/src/cohort-topic/antiflood/index.ts +2 -0
  366. package/src/cohort-topic/antiflood/invariants.ts +108 -0
  367. package/src/cohort-topic/antiflood/jitter.ts +117 -0
  368. package/src/cohort-topic/coldstart.ts +204 -0
  369. package/src/cohort-topic/dmax.ts +88 -0
  370. package/src/cohort-topic/gossip/bus.ts +217 -0
  371. package/src/cohort-topic/gossip/index.ts +3 -0
  372. package/src/cohort-topic/gossip/records.ts +45 -0
  373. package/src/cohort-topic/gossip/view.ts +66 -0
  374. package/src/cohort-topic/index.ts +20 -0
  375. package/src/cohort-topic/load/barometer.ts +134 -0
  376. package/src/cohort-topic/load/index.ts +1 -0
  377. package/src/cohort-topic/member-engine.ts +409 -0
  378. package/src/cohort-topic/membership/index.ts +3 -0
  379. package/src/cohort-topic/membership/publisher.ts +171 -0
  380. package/src/cohort-topic/membership/source.ts +41 -0
  381. package/src/cohort-topic/membership/verifier.ts +345 -0
  382. package/src/cohort-topic/ports.ts +157 -0
  383. package/src/cohort-topic/promotion.ts +384 -0
  384. package/src/cohort-topic/registration/bytes.ts +37 -0
  385. package/src/cohort-topic/registration/handoff.ts +154 -0
  386. package/src/cohort-topic/registration/index.ts +6 -0
  387. package/src/cohort-topic/registration/renewal.ts +423 -0
  388. package/src/cohort-topic/registration/sharding.ts +61 -0
  389. package/src/cohort-topic/registration/store.ts +81 -0
  390. package/src/cohort-topic/registration/types.ts +76 -0
  391. package/src/cohort-topic/ring-hash.ts +50 -0
  392. package/src/cohort-topic/service.ts +390 -0
  393. package/src/cohort-topic/sig/index.ts +2 -0
  394. package/src/cohort-topic/sig/payloads.ts +39 -0
  395. package/src/cohort-topic/sig/threshold.ts +64 -0
  396. package/src/cohort-topic/tiers.ts +74 -0
  397. package/src/cohort-topic/traffic.ts +211 -0
  398. package/src/cohort-topic/walk.ts +255 -0
  399. package/src/cohort-topic/willingness.ts +237 -0
  400. package/src/cohort-topic/wire/codec.ts +204 -0
  401. package/src/cohort-topic/wire/index.ts +16 -0
  402. package/src/cohort-topic/wire/payloads.ts +117 -0
  403. package/src/cohort-topic/wire/types.ts +343 -0
  404. package/src/cohort-topic/wire/validate.ts +478 -0
  405. package/src/collection/collection.ts +93 -1
  406. package/src/collections/tree/tree.ts +84 -3
  407. package/src/index.ts +3 -0
  408. package/src/log/log.ts +86 -7
  409. package/src/log/struct.ts +126 -2
  410. package/src/matchmaking/capability-filter.ts +45 -0
  411. package/src/matchmaking/config.ts +98 -0
  412. package/src/matchmaking/index.ts +21 -0
  413. package/src/matchmaking/multi-cohort-seeker.ts +234 -0
  414. package/src/matchmaking/provider.ts +123 -0
  415. package/src/matchmaking/query-eval.ts +105 -0
  416. package/src/matchmaking/seeker-walk.ts +127 -0
  417. package/src/matchmaking/seeker.ts +86 -0
  418. package/src/matchmaking/topic-anchor.ts +90 -0
  419. package/src/matchmaking/voting-quorum.ts +394 -0
  420. package/src/matchmaking/wire.ts +680 -0
  421. package/src/network/i-repo.ts +9 -0
  422. package/src/network/repo-protocol.ts +3 -2
  423. package/src/network/struct.ts +24 -1
  424. package/src/reactivity/backfill.ts +220 -0
  425. package/src/reactivity/backpressure.ts +191 -0
  426. package/src/reactivity/checkpoint.ts +308 -0
  427. package/src/reactivity/config.ts +172 -0
  428. package/src/reactivity/dedupe.ts +132 -0
  429. package/src/reactivity/forwarder.ts +87 -0
  430. package/src/reactivity/index.ts +34 -0
  431. package/src/reactivity/notification.ts +123 -0
  432. package/src/reactivity/policy.ts +79 -0
  433. package/src/reactivity/push-state.ts +343 -0
  434. package/src/reactivity/recover.ts +153 -0
  435. package/src/reactivity/replay-buffer.ts +141 -0
  436. package/src/reactivity/resume.ts +549 -0
  437. package/src/reactivity/rotation.ts +415 -0
  438. package/src/reactivity/subscriber.ts +132 -0
  439. package/src/reactivity/subscription.ts +66 -0
  440. package/src/reactivity/topic-anchor.ts +71 -0
  441. package/src/reactivity/verify.ts +73 -0
  442. package/src/reactivity/wire-validate.ts +87 -0
  443. package/src/reactivity/wire.ts +224 -0
  444. package/src/transaction/coordinator.ts +53 -27
  445. package/src/transactor/change-notifier.ts +80 -0
  446. package/src/transactor/index.ts +1 -0
  447. package/src/transactor/network-transactor.ts +133 -15
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Cohort-topic substrate — TTL renewal and failover.
3
+ *
4
+ * Per `docs/cohort-topic.md` §TTL and renewal and §Failure modes:
5
+ *
6
+ * - Participant pings `primary` every `ttl/3`. Success → primary touches `lastPing` and gossips it.
7
+ * - Three consecutive ping failures → participant promotes `backups[0]` via a re-attach RPC: a renew
8
+ * carrying a **signed `reattach` flag** (no full re-registration). The backup accepts when it holds
9
+ * the record locally *and* is a computed backup under the current epoch — re-stamping `primary` to
10
+ * itself and serving subsequent plain pings via an epoch-scoped failover override (the unchanged
11
+ * `cohortEpoch` still names the dead node as the computed primary). A re-attach answered
12
+ * `primary_moved` means a real rotation moved primary to a live member: the participant adopts that
13
+ * payload instead of promoting the contacted backup (ignoring a reply that points back at the dead
14
+ * primary). **Resolved (GROUNDING):** the participant's `cohortEpoch` hint refreshes lazily — on the
15
+ * *next* ping/renewal after failover, not eagerly at failover time.
16
+ * - All of primary + backups fail → participant re-runs lookup from `d_max` (walk ticket, injected).
17
+ * - Cohort-side: evict where `now − lastPing > ttl`; eviction is gossiped so members converge.
18
+ *
19
+ * Both sides take their transport/gossip by injection so storage + sharding + TTL stay unit-testable
20
+ * in isolation; db-core never imports FRET or libp2p here.
21
+ */
22
+ import { b64urlToBytes } from "../wire/codec.js";
23
+ import { bytesEqual, bytesKey, recordKey } from "./bytes.js";
24
+ import { MAX_PING_FAILURES, pingIntervalMs } from "./types.js";
25
+ class TtlRenewalParticipant {
26
+ deps;
27
+ consecutiveFailures = 0;
28
+ current;
29
+ epochHint;
30
+ constructor(initial, deps) {
31
+ this.deps = deps;
32
+ this.current = initial;
33
+ this.epochHint = deps.initialCohortEpoch;
34
+ }
35
+ get record() {
36
+ return this.current;
37
+ }
38
+ get cohortEpochHint() {
39
+ return this.epochHint;
40
+ }
41
+ get pingIntervalMs() {
42
+ return pingIntervalMs(this.current.ttl);
43
+ }
44
+ async pingLoop() {
45
+ const reply = await this.trySend(this.current.primary);
46
+ if (reply !== undefined) {
47
+ this.onPingSuccess(reply);
48
+ return;
49
+ }
50
+ this.consecutiveFailures++;
51
+ if (this.consecutiveFailures < MAX_PING_FAILURES) {
52
+ return;
53
+ }
54
+ await this.failover();
55
+ }
56
+ async reattach(target) {
57
+ return this.deps.transport.send(target, await this.buildRenew({ reattach: true }));
58
+ }
59
+ async withdraw() {
60
+ // Fire-and-forget signed tombstone to the current primary. A send failure is swallowed — the
61
+ // record TTL-expires as it does today (the local-half fallback) — and crucially we never bump
62
+ // `consecutiveFailures` or fail over: the participant is leaving, not recovering.
63
+ try {
64
+ await this.deps.transport.send(this.current.primary, await this.buildRenew({ withdraw: true }));
65
+ }
66
+ catch {
67
+ /* best-effort; the cohort TTL bounds the leak */
68
+ }
69
+ }
70
+ /** Send a renew, mapping an RPC rejection to `undefined` (a counted failure). */
71
+ async trySend(target) {
72
+ try {
73
+ return await this.deps.transport.send(target, await this.buildRenew({}));
74
+ }
75
+ catch {
76
+ return undefined;
77
+ }
78
+ }
79
+ onPingSuccess(reply) {
80
+ this.consecutiveFailures = 0;
81
+ if (reply.result === "primary_moved") {
82
+ // Lazy cohortEpoch refresh lands here: a move discovered on a normal ping updates the hint.
83
+ this.applyPrimaryMoved(reply);
84
+ }
85
+ }
86
+ /**
87
+ * 3-fail path: re-attach to each backup in turn (a signed `reattach=true` renew). An `ok` means the
88
+ * backup accepted the crash-failover promotion → promote it locally. A `primary_moved` means a real
89
+ * rotation moved primary to a different live member → adopt that payload (not the contacted backup),
90
+ * **unless** it points back at the just-failed primary (the bounce guard) — then keep trying. All
91
+ * backups exhausted → re-run lookup from `d_max`.
92
+ */
93
+ async failover() {
94
+ const failedPrimary = this.current.primary;
95
+ for (const backup of this.current.backups) {
96
+ const reply = await this.tryReattach(backup);
97
+ if (reply === undefined) {
98
+ continue;
99
+ }
100
+ if (reply.result === "ok") {
101
+ this.promote(backup);
102
+ return;
103
+ }
104
+ if (reply.result === "primary_moved") {
105
+ // A genuine rotation: adopt the rotated assignment — but never re-adopt the dead primary
106
+ // (the defensive guard against the exact bounce crash-failover is meant to fix).
107
+ if (reply.newPrimary !== undefined && bytesEqual(b64(reply.newPrimary), failedPrimary)) {
108
+ continue;
109
+ }
110
+ this.applyPrimaryMoved(reply);
111
+ // We now have a fresh, live primary to ping — clear the strike count so the next single
112
+ // transient failure doesn't immediately re-failover (matching `promote` and the
113
+ // normal-ping `primary_moved` path, which both reset here).
114
+ this.consecutiveFailures = 0;
115
+ return;
116
+ }
117
+ // unknown_registration (replication lag) or anything else: try the next backup.
118
+ }
119
+ await this.deps.transport.relookup();
120
+ // relookup is a terminal recovery action (it owns re-establishing the registration out of
121
+ // band); reset the counter so a still-dead primary backs off to one relookup per
122
+ // MAX_PING_FAILURES cycles rather than re-running the d_max walk on every subsequent ping.
123
+ this.consecutiveFailures = 0;
124
+ }
125
+ async tryReattach(target) {
126
+ try {
127
+ return await this.reattach(target);
128
+ }
129
+ catch {
130
+ return undefined;
131
+ }
132
+ }
133
+ /**
134
+ * Promote `target` (a backup) to primary. The `cohortEpoch` hint is deliberately *not* refreshed
135
+ * here — per the resolved open question it refreshes lazily on the next ping/renewal.
136
+ */
137
+ promote(target) {
138
+ const backups = this.current.backups.filter((b) => !bytesEqual(b, target));
139
+ this.current = { ...this.current, primary: target, backups, lastPing: this.deps.clock() };
140
+ this.consecutiveFailures = 0;
141
+ }
142
+ applyPrimaryMoved(reply) {
143
+ const patch = { lastPing: this.deps.clock() };
144
+ if (reply.newPrimary !== undefined) {
145
+ patch.primary = b64(reply.newPrimary);
146
+ }
147
+ if (reply.newBackups !== undefined) {
148
+ patch.backups = reply.newBackups.map(b64);
149
+ }
150
+ if (reply.cohortEpoch !== undefined) {
151
+ // Lazy refresh: the epoch hint catches up here, on the ping that discovers the move.
152
+ this.epochHint = b64(reply.cohortEpoch);
153
+ }
154
+ this.current = { ...this.current, ...patch };
155
+ }
156
+ /**
157
+ * Build a signed renew. The `reattach=true` (crash-failover) / `withdraw=true` (leave tombstone)
158
+ * flags are carried inside the signed body so the accepting member can trust the attestation; a plain
159
+ * ping omits both fields entirely (a stray renew can never silently usurp a live primary or evict a
160
+ * registration). Each flag is set only when true, matching the current plain-ping wire shape.
161
+ */
162
+ async buildRenew(opts) {
163
+ const body = {
164
+ v: 1,
165
+ topicId: bytesKey(this.current.topicId),
166
+ participantId: bytesKey(this.current.participantId),
167
+ correlationId: this.deps.correlationId,
168
+ timestamp: this.deps.clock(),
169
+ };
170
+ if (opts.reattach === true) {
171
+ body.reattach = true;
172
+ }
173
+ if (opts.withdraw === true) {
174
+ body.withdraw = true;
175
+ }
176
+ return { ...body, signature: await this.deps.sign(body) };
177
+ }
178
+ }
179
+ /** Build a {@link RenewalParticipant} around an initial record. */
180
+ export function createRenewalParticipant(initial, deps) {
181
+ return new TtlRenewalParticipant(initial, deps);
182
+ }
183
+ class StoreRenewalCohortSide {
184
+ deps;
185
+ /**
186
+ * Epoch-scoped crash-failover overrides: `recordKey → cohortEpoch under which this member accepted a
187
+ * promotion`. A matching entry makes a *subsequent plain ping* serve here even though the computed
188
+ * primary is still the dead node, so the migrated participant stops bouncing. Cleared on epoch change
189
+ * (the next rotation handoff reasserts the deterministic assignment). Sibling to the rotation
190
+ * `isServing` dual-serve exception — distinct state, OR-ed into the serve decision.
191
+ */
192
+ failoverServing = new Map();
193
+ constructor(deps) {
194
+ this.deps = deps;
195
+ }
196
+ onRenew(msg, now) {
197
+ const topicId = b64(msg.topicId);
198
+ const participantId = b64(msg.participantId);
199
+ const rec = this.deps.store.getByParticipant(topicId, participantId);
200
+ if (rec === undefined) {
201
+ return { v: 1, result: "unknown_registration" };
202
+ }
203
+ const key = recordKey(topicId, participantId);
204
+ if (msg.withdraw === true) {
205
+ // Signed leave attestation. A forged/missing signature must never evict someone else's
206
+ // registration → ignore, revealing nothing (`unknown_registration`, the same opaque answer a
207
+ // non-existent record gets). The gate is absent in key-less unit mode, matching reattach.
208
+ // `withdraw` is checked before the slot/primary computation: a withdraw needs no slot or
209
+ // primary check (any holder evicts its replica), and it takes precedence over a (malformed)
210
+ // co-set `reattach` — a record being withdrawn is gone regardless of a promotion request.
211
+ if (this.deps.verifyParticipantSig?.(msg) === false) {
212
+ return { v: 1, result: "unknown_registration" };
213
+ }
214
+ this.deps.store.delete(topicId, participantId);
215
+ this.failoverServing.delete(key); // mirror sweepStale: drop any crash-failover override
216
+ this.deps.gossip.evicted(rec);
217
+ return { v: 1, result: "withdrawn" };
218
+ }
219
+ const { members, cohortEpoch } = this.deps.cohort();
220
+ const { primary, backups } = this.deps.slots.assignSlots(participantId, cohortEpoch, members);
221
+ const self = this.deps.self;
222
+ if (msg.reattach === true) {
223
+ // Crash-failover promotion request (participant attests primary unreachable). The signed
224
+ // `reattach` flag is what a backup trusts to promote itself, so a missing/forged signature
225
+ // must never escalate: fall through to a plain redirect (never promote).
226
+ if (this.deps.verifyParticipantSig?.(msg) === false) {
227
+ return this.primaryMoved(primary, backups, cohortEpoch);
228
+ }
229
+ if (bytesEqual(primary, self)) {
230
+ // A rotation already made this member the computed primary; serve, no override needed.
231
+ return this.touchAndServe(rec, now);
232
+ }
233
+ if (backups.some((b) => bytesEqual(b, self))) {
234
+ // Legitimate backup takeover: re-stamp primary, gossip the new assignment, and record an
235
+ // epoch-scoped override so subsequent plain pings keep being served here.
236
+ const restamped = {
237
+ ...rec,
238
+ primary: self,
239
+ backups: rec.backups.filter((b) => !bytesEqual(b, self)),
240
+ lastPing: now,
241
+ };
242
+ this.deps.store.put(restamped);
243
+ this.failoverServing.set(key, cohortEpoch);
244
+ this.deps.gossip.touch(restamped);
245
+ return { v: 1, result: "ok" };
246
+ }
247
+ if (this.deps.isServing?.(topicId, participantId) === true) {
248
+ // Rotation dual-serve already covers this record here.
249
+ return this.touchAndServe(rec, now);
250
+ }
251
+ // Not a valid takeover target (stale participant view): redirect, do not promote.
252
+ return this.primaryMoved(primary, backups, cohortEpoch);
253
+ }
254
+ // Plain ping.
255
+ const isComputedPrimary = bytesEqual(primary, self);
256
+ const override = this.failoverServing.get(key);
257
+ const overrideMatches = override !== undefined && bytesEqual(override, cohortEpoch);
258
+ // Housekeeping: drop a now-redundant override (this member is the computed primary again) or a
259
+ // stale one tagged under a prior epoch (the rotation handoff governs across the epoch change).
260
+ if (override !== undefined && (isComputedPrimary || !overrideMatches)) {
261
+ this.failoverServing.delete(key);
262
+ }
263
+ const serving = isComputedPrimary || this.deps.isServing?.(topicId, participantId) === true || overrideMatches;
264
+ if (serving) {
265
+ return this.touchAndServe(rec, now);
266
+ }
267
+ return this.primaryMoved(primary, backups, cohortEpoch);
268
+ }
269
+ /** Existing touch path: stamp `lastPing`, gossip the touch, reply `ok`. */
270
+ touchAndServe(rec, now) {
271
+ const touched = { ...rec, lastPing: now };
272
+ this.deps.store.put(touched);
273
+ this.deps.gossip.touch(touched);
274
+ return { v: 1, result: "ok" };
275
+ }
276
+ primaryMoved(primary, backups, cohortEpoch) {
277
+ return {
278
+ v: 1,
279
+ result: "primary_moved",
280
+ newPrimary: bytesKey(primary),
281
+ newBackups: backups.map(bytesKey),
282
+ cohortEpoch: bytesKey(cohortEpoch),
283
+ };
284
+ }
285
+ sweepStale(now) {
286
+ const evicted = this.deps.store.evictStale(now);
287
+ for (const rec of evicted) {
288
+ // Drop any crash-failover override for an evicted record. Otherwise it leaks (the record gets
289
+ // no more pings, so the plain-ping housekeeping that would clear it never runs) and — if the
290
+ // same `(topic, participant)` re-registers under the unchanged epoch — could wrongly make a
291
+ // non-primary member keep serving via the stale override.
292
+ this.failoverServing.delete(recordKey(rec.topicId, rec.participantId));
293
+ this.deps.gossip.evicted(rec);
294
+ }
295
+ return evicted;
296
+ }
297
+ }
298
+ /** Build a {@link RenewalCohortSide}. */
299
+ export function createRenewalCohortSide(deps) {
300
+ return new StoreRenewalCohortSide(deps);
301
+ }
302
+ /** Decode a base64url wire field to bytes (the canonical byte form on the wire). */
303
+ function b64(s) {
304
+ return b64urlToBytes(s);
305
+ }
306
+ //# sourceMappingURL=renewal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renewal.js","sourceRoot":"","sources":["../../../../src/cohort-topic/registration/renewal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAoD/D,MAAM,qBAAqB;IAKgC;IAJlD,mBAAmB,GAAG,CAAC,CAAC;IACxB,OAAO,CAAqB;IAC5B,SAAS,CAAyB;IAE1C,YAAY,OAA2B,EAAmB,IAA4B;QAA5B,SAAI,GAAJ,IAAI,CAAwB;QACrF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,kBAAkB,CAAC;IAC1C,CAAC;IAED,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED,IAAI,eAAe;QAClB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,IAAI,cAAc;QACjB,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,QAAQ;QACb,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,IAAI,CAAC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,CAAC,OAAO,CAAC;YAC7B,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;YACjC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC;SAClC,CAAC;IACH,CAAC;IAED,UAAU,CAAC,GAAW;QACrB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAChD,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC3B,8FAA8F;YAC9F,6FAA6F;YAC7F,4FAA4F;YAC5F,0DAA0D;YAC1D,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;YACvE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;CACD;AAED,yCAAyC;AACzC,MAAM,UAAU,uBAAuB,CAAC,IAA2B;IAClE,OAAO,IAAI,sBAAsB,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,oFAAoF;AACpF,SAAS,GAAG,CAAC,CAAS;IACrB,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Cohort-topic substrate — deterministic primary/backup sharding.
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Primary and backup sharding:
5
+ *
6
+ * ```
7
+ * order(cohortMembers) = sort(cohortMembers, by PeerId ascending)
8
+ * slot(participantId, cohortEpoch) = H(participantId ‖ cohortEpoch) mod k
9
+ * primary = order[slot]
10
+ * backups = order[slot+1 .. slot+2 (mod k)]
11
+ * ```
12
+ *
13
+ * Deterministic given `(participantId, cohortEpoch, members)`; shards delivery load roughly evenly
14
+ * across the `~k` members. `H` is the injected {@link IRingHash} (db-core's own SHA-256 — **not** a
15
+ * FRET import), reused so coords stay byte-compatible with the rest of the substrate.
16
+ */
17
+ import type { IRingHash } from "../ports.js";
18
+ /** Deterministic slot assignment over a fixed cohort snapshot. */
19
+ export interface SlotAssigner {
20
+ /**
21
+ * `(primary, backups)` for `participantId` under `cohortEpoch` and `cohortMembers`.
22
+ * Backups are the 1..2 members following the primary in ascending order, wrapping mod `k`.
23
+ */
24
+ assignSlots(participantId: Uint8Array, cohortEpoch: Uint8Array, cohortMembers: readonly Uint8Array[]): {
25
+ primary: Uint8Array;
26
+ backups: Uint8Array[];
27
+ };
28
+ }
29
+ /** Build a {@link SlotAssigner} bound to a hash. */
30
+ export declare function createSlotAssigner(hash: IRingHash): SlotAssigner;
31
+ //# sourceMappingURL=sharding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharding.d.ts","sourceRoot":"","sources":["../../../../src/cohort-topic/registration/sharding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC5B;;;OAGG;IACH,WAAW,CAAC,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,UAAU,EAAE,GAAG;QAAE,OAAO,EAAE,UAAU,CAAC;QAAC,OAAO,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;CACtJ;AAcD,oDAAoD;AACpD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAkBhE"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Cohort-topic substrate — deterministic primary/backup sharding.
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Primary and backup sharding:
5
+ *
6
+ * ```
7
+ * order(cohortMembers) = sort(cohortMembers, by PeerId ascending)
8
+ * slot(participantId, cohortEpoch) = H(participantId ‖ cohortEpoch) mod k
9
+ * primary = order[slot]
10
+ * backups = order[slot+1 .. slot+2 (mod k)]
11
+ * ```
12
+ *
13
+ * Deterministic given `(participantId, cohortEpoch, members)`; shards delivery load roughly evenly
14
+ * across the `~k` members. `H` is the injected {@link IRingHash} (db-core's own SHA-256 — **not** a
15
+ * FRET import), reused so coords stay byte-compatible with the rest of the substrate.
16
+ */
17
+ import { compareBytes, concatBytes } from "./bytes.js";
18
+ /** Number of warm-failover backups (capped by available members). */
19
+ const MAX_BACKUPS = 2;
20
+ /** `coord mod k` over the full digest, MSB-first, without bigint allocation. */
21
+ function modK(coord, k) {
22
+ let acc = 0;
23
+ for (let i = 0; i < coord.length; i++) {
24
+ acc = (acc * 256 + coord[i]) % k;
25
+ }
26
+ return acc;
27
+ }
28
+ /** Build a {@link SlotAssigner} bound to a hash. */
29
+ export function createSlotAssigner(hash) {
30
+ return {
31
+ assignSlots(participantId, cohortEpoch, cohortMembers) {
32
+ const k = cohortMembers.length;
33
+ if (k === 0) {
34
+ throw new RangeError("assignSlots requires a non-empty cohort");
35
+ }
36
+ const order = [...cohortMembers].sort(compareBytes);
37
+ const slot = modK(hash.H(concatBytes(participantId, cohortEpoch)), k);
38
+ const primary = order[slot];
39
+ const backups = [];
40
+ const nBackups = Math.min(MAX_BACKUPS, k - 1);
41
+ for (let i = 1; i <= nBackups; i++) {
42
+ backups.push(order[(slot + i) % k]);
43
+ }
44
+ return { primary, backups };
45
+ },
46
+ };
47
+ }
48
+ //# sourceMappingURL=sharding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharding.js","sourceRoot":"","sources":["../../../../src/cohort-topic/registration/sharding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAWvD,qEAAqE;AACrE,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,gFAAgF;AAChF,SAAS,IAAI,CAAC,KAAiB,EAAE,CAAS;IACzC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,K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topic substrate — in-memory registration store.
3
+ *
4
+ * Per `docs/cohort-topic.md` §Registration mechanics. Records are doubly indexed: an outer map
5
+ * keyed by topic, each holding an inner map keyed by participant. This gives O(1)
6
+ * {@link RegistrationStore.getByParticipant} / {@link RegistrationStore.delete} and O(participants)
7
+ * {@link RegistrationStore.listByTopic} without a secondary index to keep in sync. The store is
8
+ * local soft state; cross-member replication runs over cohort gossip in a later ticket.
9
+ */
10
+ import type { RegistrationStore } from "./types.js";
11
+ /** Construct an empty {@link RegistrationStore}. */
12
+ export declare function createRegistrationStore(): RegistrationStore;
13
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../../src/cohort-topic/registration/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAkExE,oDAAoD;AACpD,wBAAgB,uBAAuB,IAAI,iBAAiB,CAE3D"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Cohort-topic substrate — in-memory registration store.
3
+ *
4
+ * Per `docs/cohort-topic.md` §Registration mechanics. Records are doubly indexed: an outer map
5
+ * keyed by topic, each holding an inner map keyed by participant. This gives O(1)
6
+ * {@link RegistrationStore.getByParticipant} / {@link RegistrationStore.delete} and O(participants)
7
+ * {@link RegistrationStore.listByTopic} without a secondary index to keep in sync. The store is
8
+ * local soft state; cross-member replication runs over cohort gossip in a later ticket.
9
+ */
10
+ import { bytesKey } from "./bytes.js";
11
+ class InMemoryRegistrationStore {
12
+ /** topicKey → (participantKey → record). Inner maps are pruned when they empty. */
13
+ byTopic = new Map();
14
+ put(rec) {
15
+ const tk = bytesKey(rec.topicId);
16
+ let inner = this.byTopic.get(tk);
17
+ if (inner === undefined) {
18
+ inner = new Map();
19
+ this.byTopic.set(tk, inner);
20
+ }
21
+ inner.set(bytesKey(rec.participantId), rec);
22
+ }
23
+ getByParticipant(topicId, participantId) {
24
+ return this.byTopic.get(bytesKey(topicId))?.get(bytesKey(participantId));
25
+ }
26
+ listByTopic(topicId) {
27
+ const inner = this.byTopic.get(bytesKey(topicId));
28
+ return inner === undefined ? [] : [...inner.values()];
29
+ }
30
+ listAll() {
31
+ const out = [];
32
+ for (const inner of this.byTopic.values()) {
33
+ for (const rec of inner.values()) {
34
+ out.push(rec);
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ delete(topicId, participantId) {
40
+ const tk = bytesKey(topicId);
41
+ const inner = this.byTopic.get(tk);
42
+ if (inner === undefined)
43
+ return;
44
+ inner.delete(bytesKey(participantId));
45
+ if (inner.size === 0) {
46
+ this.byTopic.delete(tk);
47
+ }
48
+ }
49
+ directParticipants(topicId) {
50
+ return this.byTopic.get(bytesKey(topicId))?.size ?? 0;
51
+ }
52
+ evictStale(now) {
53
+ const evicted = [];
54
+ for (const [tk, inner] of this.byTopic) {
55
+ for (const [pk, rec] of inner) {
56
+ if (now - rec.lastPing > rec.ttl) {
57
+ evicted.push(rec);
58
+ inner.delete(pk);
59
+ }
60
+ }
61
+ if (inner.size === 0) {
62
+ this.byTopic.delete(tk);
63
+ }
64
+ }
65
+ return evicted;
66
+ }
67
+ }
68
+ /** Construct an empty {@link RegistrationStore}. */
69
+ export function createRegistrationStore() {
70
+ return new InMemoryRegistrationStore();
71
+ }
72
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/cohort-topic/registration/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,yBAAyB;IAC9B,mFAAmF;IAClE,OAAO,GAAG,IAAI,GAAG,EAA2C,CAAC;IAE9E,GAAG,CAAC,GAAuB;QAC1B,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,KAAK,GAAG,IAAI,CAAC,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QACnC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO;QAChC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;QACtC,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;IAED,kBAAkB,CAAC,OAAmB;QACrC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,UAAU,CAAC,GAAW;QACrB,MAAM,OAAO,GAAyB,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACxC,KAAK,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC;gBAC/B,IAAI,GAAG,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;oBAClC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBAClB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAClB,CAAC;YACF,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;gBACtB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACzB,CAAC;QACF,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;CACD;AAED,oDAAoD;AACpD,MAAM,UAAU,uBAAuB;IACtC,OAAO,IAAI,yBAAyB,EAAE,CAAC;AACxC,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Cohort-topic substrate — registration record store, types and constants.
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Registration mechanics and §Primary and backup
5
+ * sharding. This module owns the **local**, transport-agnostic shapes: the soft-state record a
6
+ * cohort member holds per participant, the in-memory store interface over those records, and the
7
+ * TTL constants. Cross-member replication (cohort gossip) is layered on top by db-p2p and the
8
+ * bridge ticket; db-core never imports FRET or libp2p here.
9
+ *
10
+ * Peer ids are the opaque byte-array references the cohort-topic substrate uses throughout — the
11
+ * same representation as {@link import("../ports.js").PeerRef}`.id` and
12
+ * {@link import("../ports.js").RingCoord} (raw `Uint8Array`, not the structural
13
+ * {@link import("../../network/types.js").PeerId}). The wire layer carries them as base64url
14
+ * strings; this store works in raw bytes and the renewal/handoff bridges translate at the wire
15
+ * boundary.
16
+ */
17
+ /**
18
+ * Soft-state registration a cohort member holds per participant. Replicated across the `~k`
19
+ * members by cohort gossip; only {@link RegistrationRecord.primary} serves, with
20
+ * {@link RegistrationRecord.backups} watching for warm failover.
21
+ */
22
+ export interface RegistrationRecord {
23
+ /** Topic id, 32 bytes. */
24
+ topicId: Uint8Array;
25
+ /** Registering participant. */
26
+ participantId: Uint8Array;
27
+ /** Tier this registration sits at (0..3). */
28
+ tier: number;
29
+ /** Cohort member assigned to serve this participant. */
30
+ primary: Uint8Array;
31
+ /** 1..2 warm-failover cohort members. */
32
+ backups: Uint8Array[];
33
+ /** Unix ms the registration first attached. */
34
+ attachedAt: number;
35
+ /** Unix ms of the most recent successful ping/touch. */
36
+ lastPing: number;
37
+ /** Lifetime in ms; record is stale once `now − lastPing > ttl`. */
38
+ ttl: number;
39
+ /** Opaque application-defined per-registration state; the layer never interprets it. */
40
+ appState?: Uint8Array;
41
+ }
42
+ /**
43
+ * In-memory registration store, indexed for both per-participant lookup and per-topic listing.
44
+ * This ticket owns the **local** store and its indexes; the gossip layer and TTL loop call the
45
+ * deterministic functions over it.
46
+ */
47
+ export interface RegistrationStore {
48
+ /** Insert or replace the record for `(topicId, participantId)`. */
49
+ put(rec: RegistrationRecord): void;
50
+ /** Record for `(topicId, participantId)`, or `undefined`. */
51
+ getByParticipant(topicId: Uint8Array, participantId: Uint8Array): RegistrationRecord | undefined;
52
+ /** All records held for `topicId` (empty if none). */
53
+ listByTopic(topicId: Uint8Array): readonly RegistrationRecord[];
54
+ /** Every record across all topics — used by the rotation handoff inventory pass. */
55
+ listAll(): readonly RegistrationRecord[];
56
+ /** Remove the record for `(topicId, participantId)`. */
57
+ delete(topicId: Uint8Array, participantId: Uint8Array): void;
58
+ /** Stock count of direct participants for `topicId` (drives promotion). */
59
+ directParticipants(topicId: Uint8Array): number;
60
+ /** Remove and return every record where `now − lastPing > ttl`. */
61
+ evictStale(now: number): readonly RegistrationRecord[];
62
+ }
63
+ /** Core-tier default registration TTL (ms). */
64
+ export declare const DEFAULT_TTL_MS = 90000;
65
+ /** Edge-tier default registration TTL (ms). */
66
+ export declare const EDGE_TTL_MS = 60000;
67
+ /** Consecutive ping failures before a participant promotes `backups[0]`. */
68
+ export declare const MAX_PING_FAILURES = 3;
69
+ /** `ping_interval = ttl / 3` (default 30s Core, 20s Edge), floored to whole ms. */
70
+ export declare function pingIntervalMs(ttl: number): number;
71
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/cohort-topic/registration/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC,0BAA0B;IAC1B,OAAO,EAAE,UAAU,CAAC;IACpB,+BAA+B;IAC/B,aAAa,EAAE,UAAU,CAAC;IAC1B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,OAAO,EAAE,UAAU,CAAC;IACpB,yCAAyC;IACzC,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAC;IACZ,wFAAwF;IACxF,QAAQ,CAAC,EAAE,UAAU,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IACjC,mEAAmE;IACnE,GAAG,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACnC,6DAA6D;IAC7D,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,GAAG,kBAAkB,GAAG,SAAS,CAAC;IACjG,sDAAsD;IACtD,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,kBAAkB,EAAE,CAAC;IAChE,oFAAoF;IACpF,OAAO,IAAI,SAAS,kBAAkB,EAAE,CAAC;IACzC,wDAAwD;IACxD,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,GAAG,IAAI,CAAC;IAC7D,2EAA2E;IAC3E,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC;IAChD,mEAAmE;IACnE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,kBAAkB,EAAE,CAAC;CACvD;AAED,+CAA+C;AAC/C,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,+CAA+C;AAC/C,eAAO,MAAM,WAAW,QAAS,CAAC;AAClC,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAElD"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Cohort-topic substrate — registration record store, types and constants.
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Registration mechanics and §Primary and backup
5
+ * sharding. This module owns the **local**, transport-agnostic shapes: the soft-state record a
6
+ * cohort member holds per participant, the in-memory store interface over those records, and the
7
+ * TTL constants. Cross-member replication (cohort gossip) is layered on top by db-p2p and the
8
+ * bridge ticket; db-core never imports FRET or libp2p here.
9
+ *
10
+ * Peer ids are the opaque byte-array references the cohort-topic substrate uses throughout — the
11
+ * same representation as {@link import("../ports.js").PeerRef}`.id` and
12
+ * {@link import("../ports.js").RingCoord} (raw `Uint8Array`, not the structural
13
+ * {@link import("../../network/types.js").PeerId}). The wire layer carries them as base64url
14
+ * strings; this store works in raw bytes and the renewal/handoff bridges translate at the wire
15
+ * boundary.
16
+ */
17
+ /** Core-tier default registration TTL (ms). */
18
+ export const DEFAULT_TTL_MS = 90_000;
19
+ /** Edge-tier default registration TTL (ms). */
20
+ export const EDGE_TTL_MS = 60_000;
21
+ /** Consecutive ping failures before a participant promotes `backups[0]`. */
22
+ export const MAX_PING_FAILURES = 3;
23
+ /** `ping_interval = ttl / 3` (default 30s Core, 20s Edge), floored to whole ms. */
24
+ export function pingIntervalMs(ttl) {
25
+ return Math.floor(ttl / 3);
26
+ }
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/cohort-topic/registration/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAkDH,+CAA+C;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AACrC,+CAA+C;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC;AAClC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAEnC,mFAAmF;AACnF,MAAM,UAAU,cAAc,CAAC,GAAW;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { IRingHash, RingCoord } from './ports.js';
2
+ /**
3
+ * Default ring width in bits. 256 = the full SHA-256 digest, which lines up byte-for-byte with
4
+ * FRET's coordinate type (FRET hashes ring keys with SHA-256). Override only when targeting a
5
+ * DHT with a narrower ring.
6
+ */
7
+ export declare const RING_BITS = 256;
8
+ /**
9
+ * db-core's {@link IRingHash}, backed by its own SHA-256 (the same digest db-core already uses
10
+ * for logs and block ids) — **not** an import of any FRET hash module. This keeps db-core
11
+ * FRET-free while guaranteeing on-the-wire coord compatibility: at the default `ringBits = 256`,
12
+ * `H(bytes)` is the full SHA-256 digest, identical to what FRET produces for the same input.
13
+ *
14
+ * For ring widths that are not a whole number of bytes, the digest is truncated to
15
+ * `ceil(ringBits / 8)` bytes and the trailing partial byte's unused low bits are zeroed, so two
16
+ * inputs whose digests share the first `ringBits` bits yield byte-identical coords.
17
+ */
18
+ export declare class RingHash implements IRingHash {
19
+ readonly ringBits: number;
20
+ private readonly nBytes;
21
+ private readonly tailMask;
22
+ constructor(ringBits?: number);
23
+ H(bytes: Uint8Array): RingCoord;
24
+ }
25
+ /** Convenience factory mirroring the db-p2p adapter construction style. */
26
+ export declare function createRingHash(ringBits?: number): IRingHash;
27
+ //# sourceMappingURL=ring-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ring-hash.d.ts","sourceRoot":"","sources":["../../../src/cohort-topic/ring-hash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,SAAS,MAAM,CAAC;AAE7B;;;;;;;;;GASG;AACH,qBAAa,QAAS,YAAW,SAAS;IACzC,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,QAAQ,GAAE,MAAkB;IAUxC,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS;CAS/B;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,QAAQ,GAAE,MAAkB,GAAG,SAAS,CAEtE"}