@optimystic/db-core 0.13.5 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -56,6 +56,19 @@ export interface ClusterConsensusConfig {
56
56
  disputeEnabled?: boolean;
57
57
  /** Timeout for dispute arbitration in milliseconds (default 60000) */
58
58
  disputeArbitrationTimeoutMs?: number;
59
+ /**
60
+ * Hard horizon on an invalidation cascade: maximum number of recursive re-evaluation rounds
61
+ * (dependency-graph depth) before the cascade stops and escalates the affected collection(s)
62
+ * for operator full re-sync (default 32). Bounds unbounded automatic reversal.
63
+ */
64
+ maxCascadeDepth?: number;
65
+ /**
66
+ * Hard horizon on an invalidation cascade: maximum number of transactions (including the root)
67
+ * the cascade may invalidate before it stops and escalates for operator full re-sync
68
+ * (default 1000). On overflow the already-applied invalidations stand; the remainder is flagged,
69
+ * never silently dropped.
70
+ */
71
+ maxCascadeTransactions?: number;
59
72
  /** Initial scheduled-retry interval for failed commit broadcasts, ms (default 250) */
60
73
  commitBroadcastRetryInitialMs?: number;
61
74
  /** Backoff factor for commit-broadcast scheduled retries (default 2) */
@@ -1 +1 @@
1
- {"version":3,"file":"structs.d.ts","sourceRoot":"","sources":["../../../src/cluster/structs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,MAAM,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAC1B,CAAC,EAAE,EAAE,MAAM,GAAG;QACb,UAAU,EAAE,MAAM,EAAE,CAAC;QACrB,wDAAwD;QACxD,SAAS,EAAE,MAAM,CAAC;KAClB,CAAC;CACF,CAAC;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AC;IAC7C,4GAA4G;IAC5G,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gIAAgI;IAChI,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Cohort-topic substrate — tier addressing (`coord_d`).
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Tier addressing:
5
+ *
6
+ * ```
7
+ * coord_0(_, topicId) = H(0x00 ‖ topicId)
8
+ * coord_d(P, topicId) = H(d ‖ prefix(P, d·log₂F) ‖ topicId) for d ≥ 1
9
+ * ```
10
+ *
11
+ * `H` is the injected {@link IRingHash} (db-core's own SHA-256 truncated to the ring width — **not**
12
+ * a FRET import). `prefix(P, n)` is the `n` most-significant bits of peer id `P`, left-padded if
13
+ * shorter. `F` is the fan-out (default 16, `log₂F = 4`); tier `d` has exactly `F^d` coordinates.
14
+ *
15
+ * The db-p2p binding is responsible for ensuring the coord byte layout (ring width) matches FRET's
16
+ * `RING_BITS` so the routing keys produced here line up with FRET's ring on the wire.
17
+ */
18
+ import type { IRingHash, RingCoord } from "./ports.js";
19
+ /** Tier-addressing surface — derives the ring coordinate for tier `d` of a topic. */
20
+ export interface TierAddressing {
21
+ /** Fan-out per tier (default 16). */
22
+ readonly F: number;
23
+ /** Tier-0 root coordinate: `H(0x00 ‖ topicId)`. Peer-independent. */
24
+ coord0(topicId: Uint8Array): RingCoord;
25
+ /** Tier-`d` coordinate for `d ≥ 1`: `H(d ‖ prefix(peerId, d·log₂F) ‖ topicId)`. */
26
+ coordD(d: number, peerId: Uint8Array, topicId: Uint8Array): RingCoord;
27
+ /** Dispatches `d === 0` to {@link coord0}, otherwise to {@link coordD}. */
28
+ coord(d: number, peerId: Uint8Array, topicId: Uint8Array): RingCoord;
29
+ }
30
+ /** Default fan-out per tier (`log₂16 = 4`). */
31
+ export declare const DEFAULT_FANOUT = 16;
32
+ /**
33
+ * `prefix(P, n)` — the `n` most-significant bits of `P`, packed MSB-first into `⌈n/8⌉` bytes with
34
+ * the trailing partial byte's unused low bits zeroed. If `P` carries fewer than `n` bits it is
35
+ * **left-padded**: the high `(n − bits(P))` positions are zero and `P`'s bits occupy the low end, so
36
+ * the result is always exactly `n` bits wide. `n === 0` yields an empty array (the tier-0 case).
37
+ *
38
+ * Exported for tests; not part of the public substrate surface.
39
+ */
40
+ export declare function prefixBits(peerId: Uint8Array, n: number): Uint8Array;
41
+ /** Implements {@link TierAddressing} over an injected {@link IRingHash}. */
42
+ export declare class HashTierAddressing implements TierAddressing {
43
+ private readonly hash;
44
+ readonly F: number;
45
+ private readonly log2F;
46
+ constructor(hash: IRingHash, F?: number);
47
+ coord0(topicId: Uint8Array): RingCoord;
48
+ coordD(d: number, peerId: Uint8Array, topicId: Uint8Array): RingCoord;
49
+ coord(d: number, peerId: Uint8Array, topicId: Uint8Array): RingCoord;
50
+ }
51
+ /** Convenience factory mirroring the db-p2p adapter construction style. */
52
+ export declare function createTierAddressing(hash: IRingHash, F?: number): TierAddressing;
53
+ //# sourceMappingURL=addressing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressing.d.ts","sourceRoot":"","sources":["../../../src/cohort-topic/addressing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvD,qFAAqF;AACrF,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;IACvC,mFAAmF;IACnF,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;IACtE,2EAA2E;IAC3E,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;CACrE;AAED,+CAA+C;AAC/C,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAiBpE;AAED,4EAA4E;AAC5E,qBAAa,kBAAmB,YAAW,cAAc;IAI5C,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,SAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;gBAEF,IAAI,EAAE,SAAS,EAAE,CAAC,GAAE,MAAuB;IAYxE,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS;IAQtC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS;IAgBrE,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS;CAGpE;AAED,2EAA2E;AAC3E,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,GAAE,MAAuB,GAAG,cAAc,CAEhG"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Cohort-topic substrate — tier addressing (`coord_d`).
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Tier addressing:
5
+ *
6
+ * ```
7
+ * coord_0(_, topicId) = H(0x00 ‖ topicId)
8
+ * coord_d(P, topicId) = H(d ‖ prefix(P, d·log₂F) ‖ topicId) for d ≥ 1
9
+ * ```
10
+ *
11
+ * `H` is the injected {@link IRingHash} (db-core's own SHA-256 truncated to the ring width — **not**
12
+ * a FRET import). `prefix(P, n)` is the `n` most-significant bits of peer id `P`, left-padded if
13
+ * shorter. `F` is the fan-out (default 16, `log₂F = 4`); tier `d` has exactly `F^d` coordinates.
14
+ *
15
+ * The db-p2p binding is responsible for ensuring the coord byte layout (ring width) matches FRET's
16
+ * `RING_BITS` so the routing keys produced here line up with FRET's ring on the wire.
17
+ */
18
+ /** Default fan-out per tier (`log₂16 = 4`). */
19
+ export const DEFAULT_FANOUT = 16;
20
+ /**
21
+ * `prefix(P, n)` — the `n` most-significant bits of `P`, packed MSB-first into `⌈n/8⌉` bytes with
22
+ * the trailing partial byte's unused low bits zeroed. If `P` carries fewer than `n` bits it is
23
+ * **left-padded**: the high `(n − bits(P))` positions are zero and `P`'s bits occupy the low end, so
24
+ * the result is always exactly `n` bits wide. `n === 0` yields an empty array (the tier-0 case).
25
+ *
26
+ * Exported for tests; not part of the public substrate surface.
27
+ */
28
+ export function prefixBits(peerId, n) {
29
+ if (!Number.isInteger(n) || n < 0) {
30
+ throw new RangeError(`prefix bit count must be a non-negative integer, got ${n}`);
31
+ }
32
+ const outBytes = Math.ceil(n / 8);
33
+ const out = new Uint8Array(outBytes);
34
+ const available = peerId.length * 8;
35
+ const pad = Math.max(0, n - available);
36
+ for (let j = 0; j < n; j++) {
37
+ // Result bit j (MSB-first). High `pad` positions are zero (left-pad); the rest map to P.
38
+ if (j < pad)
39
+ continue;
40
+ const srcBit = j - pad;
41
+ const srcByte = peerId[srcBit >>> 3];
42
+ const bit = (srcByte >>> (7 - (srcBit & 7))) & 1;
43
+ if (bit)
44
+ out[j >>> 3] |= 1 << (7 - (j & 7));
45
+ }
46
+ return out;
47
+ }
48
+ /** Implements {@link TierAddressing} over an injected {@link IRingHash}. */
49
+ export class HashTierAddressing {
50
+ hash;
51
+ F;
52
+ log2F;
53
+ constructor(hash, F = DEFAULT_FANOUT) {
54
+ this.hash = hash;
55
+ if (!Number.isInteger(F) || F < 2) {
56
+ throw new RangeError(`fan-out F must be an integer ≥ 2, got ${F}`);
57
+ }
58
+ const log2F = Math.log2(F);
59
+ if (!Number.isInteger(log2F)) {
60
+ throw new RangeError(`fan-out F must be a power of two, got ${F}`);
61
+ }
62
+ this.F = F;
63
+ this.log2F = log2F;
64
+ }
65
+ coord0(topicId) {
66
+ // H(0x00 ‖ topicId)
67
+ const input = new Uint8Array(1 + topicId.length);
68
+ input[0] = 0x00;
69
+ input.set(topicId, 1);
70
+ return this.hash.H(input);
71
+ }
72
+ coordD(d, peerId, topicId) {
73
+ if (!Number.isInteger(d) || d < 1) {
74
+ throw new RangeError(`coordD requires an integer tier d ≥ 1, got ${d}`);
75
+ }
76
+ if (d > 255) {
77
+ throw new RangeError(`tier d must fit in one byte (≤ 255), got ${d}`);
78
+ }
79
+ // H(d ‖ prefix(peerId, d·log₂F) ‖ topicId)
80
+ const prefix = prefixBits(peerId, d * this.log2F);
81
+ const input = new Uint8Array(1 + prefix.length + topicId.length);
82
+ input[0] = d;
83
+ input.set(prefix, 1);
84
+ input.set(topicId, 1 + prefix.length);
85
+ return this.hash.H(input);
86
+ }
87
+ coord(d, peerId, topicId) {
88
+ return d === 0 ? this.coord0(topicId) : this.coordD(d, peerId, topicId);
89
+ }
90
+ }
91
+ /** Convenience factory mirroring the db-p2p adapter construction style. */
92
+ export function createTierAddressing(hash, F = DEFAULT_FANOUT) {
93
+ return new HashTierAddressing(hash, F);
94
+ }
95
+ //# sourceMappingURL=addressing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressing.js","sourceRoot":"","sources":["../../../src/cohort-topic/addressing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAgBH,+CAA+C;AAC/C,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,MAAkB,EAAE,CAAS;IACvD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,UAAU,CAAC,wDAAwD,CAAC,EAAE,CAAC,CAAC;IACnF,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,M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I,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,CAAS,EAAE,MAAkB,EAAE,OAAmB;QACvD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;CACD;AAED,2EAA2E;AAC3E,MAAM,UAAU,oBAAoB,CAAC,IAAe,EAAE,IAAY,cAAc;IAC/E,OAAO,IAAI,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Cohort-topic substrate — bootstrap-evidence envelope (anti-DoS, crypto-free).
3
+ *
4
+ * The on-the-wire structure a participant attaches to a cold-start `bootstrap: true` register, and the
5
+ * byte-level canonicalization both sides agree on. This module owns only the **format** — the versioned
6
+ * envelope, the canonical anti-replay bound image, and the proof-of-work puzzle's preimage/difficulty.
7
+ * It embeds **no cryptography**: the actual PoW hashing, reputation-signature checks, and parent-topic
8
+ * verification live in db-p2p (which binds the node's `RingHash` and peer-key crypto). The sibling
9
+ * discipline of `wire/payloads.ts` / `sig/payloads.ts` — explicitly-ordered arrays, deterministic UTF-8
10
+ * JSON, base64url without padding — so a participant who *mints* evidence and a cohort that *verifies*
11
+ * it never re-canonicalize bytes independently.
12
+ *
13
+ * The envelope rides in the dedicated, signature-covered {@link RegisterV1.bootstrapEvidence} field
14
+ * (not `appPayload`). A verifier reads only the kind its tier accepts; an absent kind, a malformed
15
+ * envelope, or a wrong/future version all surface as "this kind not offered" (the parse is **total** —
16
+ * like `verifyPeerSig`, any decode error yields `undefined`, never a throw), so a verifier fails its
17
+ * check (→ `unwilling_cohort`) rather than crashing on attacker-supplied input.
18
+ */
19
+ import type { RegisterV1 } from "../wire/types.js";
20
+ /** Proof-of-work evidence (T2/T3 path). `nonce` is base64url, bound via {@link powPreimage}. */
21
+ export interface PowEvidenceV1 {
22
+ /** Base64url nonce; `hash(powPreimage(reg, nonce))` must satisfy {@link meetsDifficulty}. */
23
+ nonce: string;
24
+ }
25
+ /** Signed parent-topic reference (all tiers). Both base64url; `sig` is over {@link parentRefSigningImage}. */
26
+ export interface ParentRefEvidenceV1 {
27
+ /** The committed parent topic id, base64url. */
28
+ parentTopicId: string;
29
+ /** Participant peer-key signature over {@link parentRefSigningImage} (the bound tuple extended with `parentTopicId`), base64url. */
30
+ sig: string;
31
+ }
32
+ /**
33
+ * Reputation endorsement (T2/T3 path). `referee` is the endorsing peer-id-string bytes (base64url) and
34
+ * `sig` is that referee's peer-key signature over the bound image. The referee MAY equal the
35
+ * participant (a reputable participant self-vouches).
36
+ */
37
+ export interface ReputationEvidenceV1 {
38
+ /** Endorsing peer-id-string bytes, base64url. */
39
+ referee: string;
40
+ /** Referee's peer-key signature over the bound image, base64url. */
41
+ sig: string;
42
+ }
43
+ /** V1 bootstrap-evidence envelope, base64url-encoded into {@link RegisterV1.bootstrapEvidence}. */
44
+ export interface BootstrapEvidenceEnvelopeV1 {
45
+ v: 1;
46
+ /** Proof-of-work (T2/T3 path). Absent → no PoW offered. */
47
+ pow?: PowEvidenceV1;
48
+ /** Signed parent-topic reference (all tiers). Absent → none offered. */
49
+ parentRef?: ParentRefEvidenceV1;
50
+ /** Reputation endorsement (T2/T3 path). Absent → none offered. */
51
+ reputation?: ReputationEvidenceV1;
52
+ }
53
+ /**
54
+ * The four register fields every bootstrap-evidence kind is bound to (the anti-replay tuple). The full
55
+ * {@link RegisterV1} satisfies this, so a verifier passes its decoded register directly; the
56
+ * participant-side builder passes just these fields (it has no full register yet).
57
+ */
58
+ export type BootstrapBoundFields = Pick<RegisterV1, "topicId" | "tier" | "participantCoord" | "timestamp">;
59
+ /** Default PoW difficulty: leading zero bits required. ~2^bits hashes to mint, one hash to verify. */
60
+ export declare const DEFAULT_POW_DIFFICULTY_BITS = 20;
61
+ /**
62
+ * The canonical bytes every bootstrap-evidence kind is bound to: `(topicId, tier, participantCoord,
63
+ * timestamp)`. `topicId`/`participantCoord` are bound as their base64url wire strings verbatim (matching
64
+ * `sig/payloads.ts`) so signer and verifier never re-canonicalize bytes independently. Binding all four
65
+ * means evidence minted for one (topic, tier, peer, time) cannot be replayed for another; binding
66
+ * `timestamp` additionally bounds a captured proof's reuse window, since the register replay guard drops
67
+ * a `timestamp` older than its acceptance window.
68
+ */
69
+ export declare function bootstrapBoundImage(reg: BootstrapBoundFields): Uint8Array;
70
+ /**
71
+ * The canonical bytes a **signed parent-topic reference** binds: the {@link bootstrapBoundImage} tuple
72
+ * `(topicId, tier, participantCoord, timestamp)` **extended with the referenced `parentTopicId`**, under a
73
+ * distinct discriminator tag (`"BootstrapParentRefV1"`). Extending the image with `parentTopicId` means a
74
+ * reference minted for one `(topic, tier, peer, time, parent)` cannot be lifted onto another register —
75
+ * including onto a register naming a *different* parent; the distinct tag keeps it from colliding with a
76
+ * {@link bootstrapBoundImage} reputation/PoW signature (domain separation). `topicId`/`participantCoord`/
77
+ * `parentTopicId` are bound as their base64url wire strings verbatim, like {@link bootstrapBoundImage}, so
78
+ * the participant who *signs* the reference and the cohort that *verifies* it never re-canonicalize bytes.
79
+ */
80
+ export declare function parentRefSigningImage(reg: BootstrapBoundFields, parentTopicId: string): Uint8Array;
81
+ /**
82
+ * The proof-of-work hash preimage: {@link bootstrapBoundImage} concatenated with `nonce`. db-p2p hashes
83
+ * this (via the node's `RingHash`) and checks the digest against {@link meetsDifficulty}. Bound to the
84
+ * register tuple ⇒ no cross-topic / cross-peer replay; cheap to verify (one hash + bit check), tunably
85
+ * costly to produce.
86
+ */
87
+ export declare function powPreimage(reg: BootstrapBoundFields, nonce: Uint8Array): Uint8Array;
88
+ /**
89
+ * True iff the first `bits` most-significant bits of `hash` are zero (the PoW difficulty target). Bits
90
+ * are read MSB-first per byte (mirroring `addressing.ts`'s `prefixBits`). `bits = 0` is trivially met
91
+ * (lets a config disable PoW cost for tests); a non-finite `bits` is a guard-failure (never met); a
92
+ * negative `bits` clamps to 0; `bits` larger than `hash.length * 8` requires every bit of `hash` to be
93
+ * zero and so is effectively unsatisfiable for a random hash.
94
+ */
95
+ export declare function meetsDifficulty(hash: Uint8Array, bits: number): boolean;
96
+ /** Serialize an envelope to the base64url JSON string carried in {@link RegisterV1.bootstrapEvidence}. */
97
+ export declare function serializeBootstrapEvidenceEnvelope(env: BootstrapEvidenceEnvelopeV1): string;
98
+ /**
99
+ * Decode {@link RegisterV1.bootstrapEvidence} (base64url → JSON), structurally validate it, and return
100
+ * the {@link BootstrapEvidenceEnvelopeV1}. **Total**: returns `undefined` on an absent/empty field, a
101
+ * non-base64url or non-JSON body, a wrong/future `v`, or a structurally-invalid kind — never throws. A
102
+ * verifier treats `undefined` as "this kind not offered" and fails its check (fails closed).
103
+ */
104
+ export declare function parseBootstrapEvidenceEnvelope(reg: Pick<RegisterV1, "bootstrapEvidence">): BootstrapEvidenceEnvelopeV1 | undefined;
105
+ //# sourceMappingURL=bootstrap-evidence-envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-evidence-envelope.d.ts","sourceRoot":"","sources":["../../../../src/cohort-topic/antidos/bootstrap-evidence-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAKnD,gGAAgG;AAChG,MAAM,WAAW,aAAa;IAC7B,6FAA6F;IAC7F,KAAK,EAAE,MAAM,CAAC;CACd;AAED,8GAA8G;AAC9G,MAAM,WAAW,mBAAmB;IACnC,gDAAgD;IAChD,aAAa,EAAE,MAAM,CAAC;IACtB,oIAAoI;IACpI,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,mGAAmG;AACnG,MAAM,WAAW,2BAA2B;IAC3C,CAAC,EAAE,CAAC,CAAC;IACL,2DAA2D;IAC3D,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,wEAAwE;IACxE,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,kEAAkE;IAClE,UAAU,CAAC,EAAE,oBAAoB,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,GAAG,kBAAkB,GAAG,WAAW,CAAC,CAAC;AAE3G,sGAAsG;AACtG,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,oBAAoB,GAAG,UAAU,CAQzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,GAAG,UAAU,CASlG;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,oBAAoB,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAMpF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CA0BvE;AAED,0GAA0G;AAC1G,wBAAgB,kCAAkC,CAAC,GAAG,EAAE,2BAA2B,GAAG,MAAM,CAc3F;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE,mBAAmB,CAAC,GAAG,2BAA2B,GAAG,SAAS,CAYlI"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Cohort-topic substrate — bootstrap-evidence envelope (anti-DoS, crypto-free).
3
+ *
4
+ * The on-the-wire structure a participant attaches to a cold-start `bootstrap: true` register, and the
5
+ * byte-level canonicalization both sides agree on. This module owns only the **format** — the versioned
6
+ * envelope, the canonical anti-replay bound image, and the proof-of-work puzzle's preimage/difficulty.
7
+ * It embeds **no cryptography**: the actual PoW hashing, reputation-signature checks, and parent-topic
8
+ * verification live in db-p2p (which binds the node's `RingHash` and peer-key crypto). The sibling
9
+ * discipline of `wire/payloads.ts` / `sig/payloads.ts` — explicitly-ordered arrays, deterministic UTF-8
10
+ * JSON, base64url without padding — so a participant who *mints* evidence and a cohort that *verifies*
11
+ * it never re-canonicalize bytes independently.
12
+ *
13
+ * The envelope rides in the dedicated, signature-covered {@link RegisterV1.bootstrapEvidence} field
14
+ * (not `appPayload`). A verifier reads only the kind its tier accepts; an absent kind, a malformed
15
+ * envelope, or a wrong/future version all surface as "this kind not offered" (the parse is **total** —
16
+ * like `verifyPeerSig`, any decode error yields `undefined`, never a throw), so a verifier fails its
17
+ * check (→ `unwilling_cohort`) rather than crashing on attacker-supplied input.
18
+ */
19
+ import { b64urlToBytes, bytesToB64url } from "../wire/codec.js";
20
+ const utf8 = new TextEncoder();
21
+ const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
22
+ /** Default PoW difficulty: leading zero bits required. ~2^bits hashes to mint, one hash to verify. */
23
+ export const DEFAULT_POW_DIFFICULTY_BITS = 20;
24
+ /**
25
+ * The canonical bytes every bootstrap-evidence kind is bound to: `(topicId, tier, participantCoord,
26
+ * timestamp)`. `topicId`/`participantCoord` are bound as their base64url wire strings verbatim (matching
27
+ * `sig/payloads.ts`) so signer and verifier never re-canonicalize bytes independently. Binding all four
28
+ * means evidence minted for one (topic, tier, peer, time) cannot be replayed for another; binding
29
+ * `timestamp` additionally bounds a captured proof's reuse window, since the register replay guard drops
30
+ * a `timestamp` older than its acceptance window.
31
+ */
32
+ export function bootstrapBoundImage(reg) {
33
+ return utf8.encode(JSON.stringify([
34
+ "BootstrapEvidenceV1",
35
+ reg.topicId,
36
+ reg.tier,
37
+ reg.participantCoord,
38
+ reg.timestamp,
39
+ ]));
40
+ }
41
+ /**
42
+ * The canonical bytes a **signed parent-topic reference** binds: the {@link bootstrapBoundImage} tuple
43
+ * `(topicId, tier, participantCoord, timestamp)` **extended with the referenced `parentTopicId`**, under a
44
+ * distinct discriminator tag (`"BootstrapParentRefV1"`). Extending the image with `parentTopicId` means a
45
+ * reference minted for one `(topic, tier, peer, time, parent)` cannot be lifted onto another register —
46
+ * including onto a register naming a *different* parent; the distinct tag keeps it from colliding with a
47
+ * {@link bootstrapBoundImage} reputation/PoW signature (domain separation). `topicId`/`participantCoord`/
48
+ * `parentTopicId` are bound as their base64url wire strings verbatim, like {@link bootstrapBoundImage}, so
49
+ * the participant who *signs* the reference and the cohort that *verifies* it never re-canonicalize bytes.
50
+ */
51
+ export function parentRefSigningImage(reg, parentTopicId) {
52
+ return utf8.encode(JSON.stringify([
53
+ "BootstrapParentRefV1",
54
+ reg.topicId,
55
+ reg.tier,
56
+ reg.participantCoord,
57
+ reg.timestamp,
58
+ parentTopicId,
59
+ ]));
60
+ }
61
+ /**
62
+ * The proof-of-work hash preimage: {@link bootstrapBoundImage} concatenated with `nonce`. db-p2p hashes
63
+ * this (via the node's `RingHash`) and checks the digest against {@link meetsDifficulty}. Bound to the
64
+ * register tuple ⇒ no cross-topic / cross-peer replay; cheap to verify (one hash + bit check), tunably
65
+ * costly to produce.
66
+ */
67
+ export function powPreimage(reg, nonce) {
68
+ const image = bootstrapBoundImage(reg);
69
+ const out = new Uint8Array(image.length + nonce.length);
70
+ out.set(image, 0);
71
+ out.set(nonce, image.length);
72
+ return out;
73
+ }
74
+ /**
75
+ * True iff the first `bits` most-significant bits of `hash` are zero (the PoW difficulty target). Bits
76
+ * are read MSB-first per byte (mirroring `addressing.ts`'s `prefixBits`). `bits = 0` is trivially met
77
+ * (lets a config disable PoW cost for tests); a non-finite `bits` is a guard-failure (never met); a
78
+ * negative `bits` clamps to 0; `bits` larger than `hash.length * 8` requires every bit of `hash` to be
79
+ * zero and so is effectively unsatisfiable for a random hash.
80
+ */
81
+ export function meetsDifficulty(hash, bits) {
82
+ if (!Number.isFinite(bits)) {
83
+ return false; // NaN / ±Infinity → defensive guard, never satisfiable
84
+ }
85
+ let remaining = Math.floor(bits);
86
+ if (remaining <= 0) {
87
+ return true; // 0 (or clamped-negative) leading zero bits is trivially met
88
+ }
89
+ for (let i = 0; i < hash.length && remaining > 0; i++) {
90
+ const byte = hash[i];
91
+ if (remaining >= 8) {
92
+ if (byte !== 0) {
93
+ return false;
94
+ }
95
+ remaining -= 8;
96
+ }
97
+ else {
98
+ // Check only the top `remaining` MSBs of this partial final byte (MSB-first).
99
+ const mask = (0xff << (8 - remaining)) & 0xff;
100
+ if ((byte & mask) !== 0) {
101
+ return false;
102
+ }
103
+ remaining = 0;
104
+ }
105
+ }
106
+ // Exhausted the hash before satisfying `bits` (oversize target) → unsatisfiable.
107
+ return remaining === 0;
108
+ }
109
+ /** Serialize an envelope to the base64url JSON string carried in {@link RegisterV1.bootstrapEvidence}. */
110
+ export function serializeBootstrapEvidenceEnvelope(env) {
111
+ // Rebuild in a fixed field order so serialization is a pure function of the logical content
112
+ // (serialize∘parse is stable regardless of how a caller ordered the source object's keys).
113
+ const out = { v: 1 };
114
+ if (env.pow !== undefined) {
115
+ out.pow = { nonce: env.pow.nonce };
116
+ }
117
+ if (env.parentRef !== undefined) {
118
+ out.parentRef = { parentTopicId: env.parentRef.parentTopicId, sig: env.parentRef.sig };
119
+ }
120
+ if (env.reputation !== undefined) {
121
+ out.reputation = { referee: env.reputation.referee, sig: env.reputation.sig };
122
+ }
123
+ return bytesToB64url(utf8.encode(JSON.stringify(out)));
124
+ }
125
+ /**
126
+ * Decode {@link RegisterV1.bootstrapEvidence} (base64url → JSON), structurally validate it, and return
127
+ * the {@link BootstrapEvidenceEnvelopeV1}. **Total**: returns `undefined` on an absent/empty field, a
128
+ * non-base64url or non-JSON body, a wrong/future `v`, or a structurally-invalid kind — never throws. A
129
+ * verifier treats `undefined` as "this kind not offered" and fails its check (fails closed).
130
+ */
131
+ export function parseBootstrapEvidenceEnvelope(reg) {
132
+ const raw = reg.bootstrapEvidence;
133
+ if (raw === undefined || raw === "") {
134
+ return undefined; // not offered
135
+ }
136
+ let parsed;
137
+ try {
138
+ parsed = JSON.parse(utf8Decoder.decode(b64urlToBytes(raw)));
139
+ }
140
+ catch {
141
+ return undefined; // not base64url / not UTF-8 / not JSON → fail closed
142
+ }
143
+ return narrowEnvelope(parsed);
144
+ }
145
+ /** Structurally narrow an already-parsed value to a v1 envelope, or `undefined`. */
146
+ function narrowEnvelope(value) {
147
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
148
+ return undefined;
149
+ }
150
+ const obj = value;
151
+ if (obj["v"] !== 1) {
152
+ return undefined; // wrong / future version → fail closed under the v1 reader
153
+ }
154
+ const out = { v: 1 };
155
+ if (obj["pow"] !== undefined) {
156
+ const nonce = b64urlSubfield(obj["pow"], "nonce");
157
+ if (nonce === undefined) {
158
+ return undefined;
159
+ }
160
+ out.pow = { nonce };
161
+ }
162
+ if (obj["parentRef"] !== undefined) {
163
+ const parentTopicId = b64urlSubfield(obj["parentRef"], "parentTopicId");
164
+ const sig = b64urlSubfield(obj["parentRef"], "sig");
165
+ if (parentTopicId === undefined || sig === undefined) {
166
+ return undefined;
167
+ }
168
+ out.parentRef = { parentTopicId, sig };
169
+ }
170
+ if (obj["reputation"] !== undefined) {
171
+ const referee = b64urlSubfield(obj["reputation"], "referee");
172
+ const sig = b64urlSubfield(obj["reputation"], "sig");
173
+ if (referee === undefined || sig === undefined) {
174
+ return undefined;
175
+ }
176
+ out.reputation = { referee, sig };
177
+ }
178
+ return out;
179
+ }
180
+ /** A required base64url sub-field: a non-empty string that decodes cleanly, else `undefined`. */
181
+ function b64urlSubfield(container, key) {
182
+ if (typeof container !== "object" || container === null || Array.isArray(container)) {
183
+ return undefined;
184
+ }
185
+ const value = container[key];
186
+ if (typeof value !== "string" || value === "") {
187
+ return undefined; // missing, non-string, or empty → treat as absent
188
+ }
189
+ try {
190
+ b64urlToBytes(value); // structural: must decode as base64url
191
+ }
192
+ catch {
193
+ return undefined;
194
+ }
195
+ return value;
196
+ }
197
+ //# sourceMappingURL=bootstrap-evidence-envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-evidence-envelope.js","sourceRoot":"","sources":["../../../../src/cohort-topic/antidos/bootstrap-evidence-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGhE,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAC/B,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AA8C9D,sGAAsG;AACtG,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAyB;IAC5D,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;QACjC,qBAAqB;QACrB,GAAG,CAAC,OAAO;QACX,GAAG,CAAC,IAAI;QACR,GAAG,CAAC,gBAAgB;QACpB,GAAG,CAAC,SAAS;KACb,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAyB,EAAE,aAAqB;IACrF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;QACjC,sBAAsB;QACtB,GAAG,CAAC,OAAO;QACX,GAAG,CAAC,IAAI;QACR,GAAG,CAAC,gBAAgB;QACpB,GAAG,CAAC,SAAS;QACb,aAAa;KACb,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,GAAyB,EAAE,KAAiB;IACvE,MAAM,KAAK,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,UAAU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G,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC;QAC7D,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YAChD,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,GAAG,CAAC,UAAU,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;IACnC,CAAC;IAED,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,iGAAiG;AACjG,SAAS,cAAc,CAAC,SAAkB,EAAE,GAAW;IACtD,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACrF,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,KAAK,GAAI,SAAqC,CAAC,GAAG,CAAC,CAAC;IAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QAC/C,OAAO,SAAS,CAAC,CAAC,kDAAkD;IACrE,CAAC;IACD,IAAI,CAAC;QACJ,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,uCAAuC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Cohort-topic substrate — bootstrap evidence policy (anti-DoS).
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Anti-DoS bullet 4. A cold root that accepts a
5
+ * `bootstrap: true` registration must demand evidence, so a cold topic cannot be instantiated for
6
+ * free by an attacker. The accepted evidence is **tier-dependent**:
7
+ *
8
+ * - **T0 / T1** — generally no proof-of-work, because these tiers correspond to committed work; a
9
+ * *signed reference to a committed parent topic that does exist* is sufficient.
10
+ * - **T2 / T3** — a **proof-of-work** OR a **reputation-score signature** (a signature from a peer
11
+ * with sufficient reputation, see `architecture.md` §Reputation) OR a **signed parent-topic
12
+ * reference**.
13
+ *
14
+ * This module is the *policy* — which evidence kinds satisfy which tier. The cryptographic checks
15
+ * themselves (verifying a PoW, a reputation signature, a parent-topic reference) are injected, keeping
16
+ * db-core free of any specific PoW/reputation scheme (the same injection discipline as the threshold
17
+ * crypto port). The evidence travels in the registration's dedicated, signature-covered
18
+ * `bootstrapEvidence` field — a versioned `BootstrapEvidenceEnvelopeV1`
19
+ * (`./bootstrap-evidence-envelope.js`), parsed crypto-free here and checked by the injected verifiers;
20
+ * NOT the opaque `appPayload` slot (which the cohort copies verbatim into the registration's appState).
21
+ * A registration that is not a bootstrap needs no evidence and is admitted.
22
+ */
23
+ import type { RegisterV1 } from "../wire/types.js";
24
+ /** Tiers at/below this need no proof-of-work — a signed parent reference suffices (T0/T1). */
25
+ export declare const DEFAULT_MAX_NO_POW_TIER = 1;
26
+ export interface BootstrapEvidenceDeps {
27
+ /** Verify a proof-of-work attached to `reg` (T2/T3 path). Absent → PoW is never satisfiable. */
28
+ verifyPoW?: (reg: RegisterV1) => boolean;
29
+ /** Verify a sufficient-reputation signature on `reg` (T2/T3 path). Absent → never satisfiable. */
30
+ verifyReputation?: (reg: RegisterV1) => boolean;
31
+ /** Verify a signed reference to an existing committed parent topic (all tiers). Absent → never satisfiable. */
32
+ verifyParentReference?: (reg: RegisterV1) => boolean;
33
+ config?: BootstrapEvidenceConfig;
34
+ }
35
+ export interface BootstrapEvidenceConfig {
36
+ /** Highest tier exempt from proof-of-work (T0/T1 → 1). Default {@link DEFAULT_MAX_NO_POW_TIER}. */
37
+ maxNoPowTier?: number;
38
+ }
39
+ /** Tier-dependent bootstrap-evidence gate for cold-root registrations. */
40
+ export interface BootstrapEvidence {
41
+ /**
42
+ * Whether `reg` carries acceptable bootstrap evidence for `tier`. A non-bootstrap registration is
43
+ * always acceptable (nothing to prove). For a bootstrap: T0/T1 require a signed parent reference;
44
+ * T2/T3 accept proof-of-work OR a reputation signature OR a signed parent reference.
45
+ */
46
+ verify(reg: RegisterV1, tier: number): boolean;
47
+ }
48
+ /** Build a {@link BootstrapEvidence} policy over the injected (db-p2p-supplied) evidence verifiers. */
49
+ export declare function createBootstrapEvidence(deps?: BootstrapEvidenceDeps): BootstrapEvidence;
50
+ //# sourceMappingURL=bootstrap-evidence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-evidence.d.ts","sourceRoot":"","sources":["../../../../src/cohort-topic/antidos/bootstrap-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAKnD,8FAA8F;AAC9F,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,WAAW,qBAAqB;IACrC,gGAAgG;IAChG,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC,kGAAkG;IAClG,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC;IAChD,+GAA+G;IAC/G,qBAAqB,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,CAAC;IACrD,MAAM,CAAC,EAAE,uBAAuB,CAAC;CACjC;AAED,MAAM,WAAW,uBAAuB;IACvC,mGAAmG;IACnG,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IACjC;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/C;AAoCD,uGAAuG;AACvG,wBAAgB,uBAAuB,CAAC,IAAI,GAAE,qBAA0B,GAAG,iBAAiB,CAE3F"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Cohort-topic substrate — bootstrap evidence policy (anti-DoS).
3
+ *
4
+ * Transcribed from `docs/cohort-topic.md` §Anti-DoS bullet 4. A cold root that accepts a
5
+ * `bootstrap: true` registration must demand evidence, so a cold topic cannot be instantiated for
6
+ * free by an attacker. The accepted evidence is **tier-dependent**:
7
+ *
8
+ * - **T0 / T1** — generally no proof-of-work, because these tiers correspond to committed work; a
9
+ * *signed reference to a committed parent topic that does exist* is sufficient.
10
+ * - **T2 / T3** — a **proof-of-work** OR a **reputation-score signature** (a signature from a peer
11
+ * with sufficient reputation, see `architecture.md` §Reputation) OR a **signed parent-topic
12
+ * reference**.
13
+ *
14
+ * This module is the *policy* — which evidence kinds satisfy which tier. The cryptographic checks
15
+ * themselves (verifying a PoW, a reputation signature, a parent-topic reference) are injected, keeping
16
+ * db-core free of any specific PoW/reputation scheme (the same injection discipline as the threshold
17
+ * crypto port). The evidence travels in the registration's dedicated, signature-covered
18
+ * `bootstrapEvidence` field — a versioned `BootstrapEvidenceEnvelopeV1`
19
+ * (`./bootstrap-evidence-envelope.js`), parsed crypto-free here and checked by the injected verifiers;
20
+ * NOT the opaque `appPayload` slot (which the cohort copies verbatim into the registration's appState).
21
+ * A registration that is not a bootstrap needs no evidence and is admitted.
22
+ */
23
+ import { createLogger } from "../../logger.js";
24
+ const log = createLogger("cohort-topic:antidos");
25
+ /** Tiers at/below this need no proof-of-work — a signed parent reference suffices (T0/T1). */
26
+ export const DEFAULT_MAX_NO_POW_TIER = 1;
27
+ class TieredBootstrapEvidence {
28
+ maxNoPowTier;
29
+ verifyPoW;
30
+ verifyReputation;
31
+ verifyParentReference;
32
+ constructor(deps = {}) {
33
+ this.maxNoPowTier = deps.config?.maxNoPowTier ?? DEFAULT_MAX_NO_POW_TIER;
34
+ this.verifyPoW = deps.verifyPoW ?? (() => false);
35
+ this.verifyReputation = deps.verifyReputation ?? (() => false);
36
+ this.verifyParentReference = deps.verifyParentReference ?? (() => false);
37
+ }
38
+ verify(reg, tier) {
39
+ if (reg.bootstrap !== true) {
40
+ return true; // only a cold-root bootstrap must carry evidence
41
+ }
42
+ if (tier <= this.maxNoPowTier) {
43
+ // T0/T1: a signed reference to a committed parent topic is sufficient (no PoW expected).
44
+ const ok = this.verifyParentReference(reg);
45
+ if (!ok) {
46
+ log("bootstrap-evidence reject: tier=%d needs a signed parent reference", tier);
47
+ }
48
+ return ok;
49
+ }
50
+ // T2/T3: any one of PoW, a reputation signature, or a signed parent reference.
51
+ const ok = this.verifyPoW(reg) || this.verifyReputation(reg) || this.verifyParentReference(reg);
52
+ if (!ok) {
53
+ log("bootstrap-evidence reject: tier=%d needs PoW / reputation / parent reference", tier);
54
+ }
55
+ return ok;
56
+ }
57
+ }
58
+ /** Build a {@link BootstrapEvidence} policy over the injected (db-p2p-supplied) evidence verifiers. */
59
+ export function createBootstrapEvidence(deps = {}) {
60
+ return new TieredBootstrapEvidence(deps);
61
+ }
62
+ //# sourceMappingURL=bootstrap-evidence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-evidence.js","sourceRoot":"","sources":["../../../../src/cohort-topic/antidos/bootstrap-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,GAAG,GAAG,YAAY,CAAC,sBAAsB,CAAC,CAAC;AAEjD,8FAA8F;AAC9F,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AA2BzC,MAAM,uBAAuB;IACX,YAAY,CAAS;IACrB,SAAS,CAA+B;IACxC,gBAAgB,CAA+B;IAC/C,qBAAqB,CAA+B;IAErE,YAAY,OAA8B,EAAE;QAC3C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,YAAY,IAAI,uBAAuB,CAAC;QACzE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,CAAC,GAAY,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,CAAC,GAAY,EAAE,CAAC,KAAK,CAAC,CAAC;QACxE,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,IAAI,CAAC,GAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IACnF,CAAC;IAED,MAAM,CAAC,GAAe,EAAE,IAAY;QACnC,IAAI,GAAG,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,CAAC,iDAAiD;QAC/D,CAAC;QACD,IAAI,IAAI,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC/B,yFAAyF;YACzF,MAAM,EAAE,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;YAC3C,IAAI,CAAC,EAAE,EAAE,CAAC;gBACT,GAAG,CAAC,oEAAoE,EAAE,IAAI,CAAC,CAAC;YACjF,CAAC;YACD,OAAO,EAAE,CAAC;QACX,CAAC;QACD,+EAA+E;QAC/E,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAChG,IAAI,CAAC,EAAE,EAAE,CAAC;YACT,GAAG,CAAC,8EAA8E,EAAE,IAAI,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,EAAE,CAAC;IACX,CAAC;CACD;AAED,uGAAuG;AACvG,MAAM,UAAU,uBAAuB,CAAC,OAA8B,EAAE;IACvE,OAAO,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./rate-limiter.js";
2
+ export * from "./topic-budget.js";
3
+ export * from "./replay-guard.js";
4
+ export * from "./bootstrap-evidence.js";
5
+ export * from "./bootstrap-evidence-envelope.js";
6
+ //# sourceMappingURL=index.d.ts.map