@swal/edge-mesh 0.0.0-stage → 0.1.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 (464) hide show
  1. package/LICENSE +128 -0
  2. package/NOTICE +37 -0
  3. package/README.md +470 -2
  4. package/dist/adapters/gpu-agent/index.d.ts +61 -0
  5. package/dist/adapters/gpu-agent/index.d.ts.map +1 -0
  6. package/dist/adapters/gpu-agent/index.js +364 -0
  7. package/dist/adapters/gpu-agent/index.js.map +1 -0
  8. package/dist/adapters/maloca-salud/citas-distribuidas.d.ts +19 -0
  9. package/dist/adapters/maloca-salud/citas-distribuidas.d.ts.map +1 -0
  10. package/dist/adapters/maloca-salud/citas-distribuidas.js +51 -0
  11. package/dist/adapters/maloca-salud/citas-distribuidas.js.map +1 -0
  12. package/dist/adapters/maloca-salud/eps-bridge.d.ts +15 -0
  13. package/dist/adapters/maloca-salud/eps-bridge.d.ts.map +1 -0
  14. package/dist/adapters/maloca-salud/eps-bridge.js +27 -0
  15. package/dist/adapters/maloca-salud/eps-bridge.js.map +1 -0
  16. package/dist/adapters/maloca-salud/patient-profile.d.ts +20 -0
  17. package/dist/adapters/maloca-salud/patient-profile.d.ts.map +1 -0
  18. package/dist/adapters/maloca-salud/patient-profile.js +36 -0
  19. package/dist/adapters/maloca-salud/patient-profile.js.map +1 -0
  20. package/dist/adapters/maloca-salud/types.d.ts +40 -0
  21. package/dist/adapters/maloca-salud/types.d.ts.map +1 -0
  22. package/dist/adapters/maloca-salud/types.js +2 -0
  23. package/dist/adapters/maloca-salud/types.js.map +1 -0
  24. package/dist/adapters/maloca-veeduria/contract-bridge.d.ts +31 -0
  25. package/dist/adapters/maloca-veeduria/contract-bridge.d.ts.map +1 -0
  26. package/dist/adapters/maloca-veeduria/contract-bridge.js +103 -0
  27. package/dist/adapters/maloca-veeduria/contract-bridge.js.map +1 -0
  28. package/dist/adapters/maloca-veeduria/evidentia-veeduria.d.ts +14 -0
  29. package/dist/adapters/maloca-veeduria/evidentia-veeduria.d.ts.map +1 -0
  30. package/dist/adapters/maloca-veeduria/evidentia-veeduria.js +40 -0
  31. package/dist/adapters/maloca-veeduria/evidentia-veeduria.js.map +1 -0
  32. package/dist/adapters/maloca-veeduria/licitante-profile.d.ts +21 -0
  33. package/dist/adapters/maloca-veeduria/licitante-profile.d.ts.map +1 -0
  34. package/dist/adapters/maloca-veeduria/licitante-profile.js +58 -0
  35. package/dist/adapters/maloca-veeduria/licitante-profile.js.map +1 -0
  36. package/dist/adapters/maloca-veeduria/types.d.ts +30 -0
  37. package/dist/adapters/maloca-veeduria/types.d.ts.map +1 -0
  38. package/dist/adapters/maloca-veeduria/types.js +2 -0
  39. package/dist/adapters/maloca-veeduria/types.js.map +1 -0
  40. package/dist/adapters/maloca-xavier/agent-profile.d.ts +32 -0
  41. package/dist/adapters/maloca-xavier/agent-profile.d.ts.map +1 -0
  42. package/dist/adapters/maloca-xavier/agent-profile.js +56 -0
  43. package/dist/adapters/maloca-xavier/agent-profile.js.map +1 -0
  44. package/dist/adapters/maloca-xavier/codegraph-bridge.d.ts +27 -0
  45. package/dist/adapters/maloca-xavier/codegraph-bridge.d.ts.map +1 -0
  46. package/dist/adapters/maloca-xavier/codegraph-bridge.js +58 -0
  47. package/dist/adapters/maloca-xavier/codegraph-bridge.js.map +1 -0
  48. package/dist/adapters/maloca-xavier/llm-router.d.ts +25 -0
  49. package/dist/adapters/maloca-xavier/llm-router.d.ts.map +1 -0
  50. package/dist/adapters/maloca-xavier/llm-router.js +58 -0
  51. package/dist/adapters/maloca-xavier/llm-router.js.map +1 -0
  52. package/dist/authz/index.d.ts +81 -0
  53. package/dist/authz/index.d.ts.map +1 -0
  54. package/dist/authz/index.js +271 -0
  55. package/dist/authz/index.js.map +1 -0
  56. package/dist/chat/index.d.ts +138 -0
  57. package/dist/chat/index.d.ts.map +1 -0
  58. package/dist/chat/index.js +394 -0
  59. package/dist/chat/index.js.map +1 -0
  60. package/dist/chat/offline-queue.d.ts +32 -0
  61. package/dist/chat/offline-queue.d.ts.map +1 -0
  62. package/dist/chat/offline-queue.js +93 -0
  63. package/dist/chat/offline-queue.js.map +1 -0
  64. package/dist/core/DefaultEdgeMeshNode.d.ts +17 -0
  65. package/dist/core/DefaultEdgeMeshNode.d.ts.map +1 -0
  66. package/dist/core/DefaultEdgeMeshNode.js +57 -0
  67. package/dist/core/DefaultEdgeMeshNode.js.map +1 -0
  68. package/dist/core/node.d.ts +26 -0
  69. package/dist/core/node.d.ts.map +1 -0
  70. package/dist/core/node.js +16 -0
  71. package/dist/core/node.js.map +1 -0
  72. package/dist/edge-mesh.d.ts +139 -0
  73. package/dist/edge-mesh.d.ts.map +1 -0
  74. package/dist/edge-mesh.js +1146 -0
  75. package/dist/edge-mesh.js.map +1 -0
  76. package/dist/gos/GosBridge.d.ts +49 -0
  77. package/dist/gos/GosBridge.d.ts.map +1 -0
  78. package/dist/gos/GosBridge.js +133 -0
  79. package/dist/gos/GosBridge.js.map +1 -0
  80. package/dist/governance/authority.d.ts +44 -0
  81. package/dist/governance/authority.d.ts.map +1 -0
  82. package/dist/governance/authority.js +123 -0
  83. package/dist/governance/authority.js.map +1 -0
  84. package/dist/governance/index.d.ts +66 -0
  85. package/dist/governance/index.d.ts.map +1 -0
  86. package/dist/governance/index.js +210 -0
  87. package/dist/governance/index.js.map +1 -0
  88. package/dist/governance/merge.d.ts +31 -0
  89. package/dist/governance/merge.d.ts.map +1 -0
  90. package/dist/governance/merge.js +167 -0
  91. package/dist/governance/merge.js.map +1 -0
  92. package/dist/identity/index.d.ts +199 -0
  93. package/dist/identity/index.d.ts.map +1 -0
  94. package/dist/identity/index.js +415 -0
  95. package/dist/identity/index.js.map +1 -0
  96. package/dist/index.d.ts +71 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +56 -0
  99. package/dist/index.js.map +1 -0
  100. package/dist/maloca/backoffice.d.ts +31 -0
  101. package/dist/maloca/backoffice.d.ts.map +1 -0
  102. package/dist/maloca/backoffice.js +40 -0
  103. package/dist/maloca/backoffice.js.map +1 -0
  104. package/dist/maloca/event-bus.d.ts +60 -0
  105. package/dist/maloca/event-bus.d.ts.map +1 -0
  106. package/dist/maloca/event-bus.js +175 -0
  107. package/dist/maloca/event-bus.js.map +1 -0
  108. package/dist/maloca/evidentia.d.ts +136 -0
  109. package/dist/maloca/evidentia.d.ts.map +1 -0
  110. package/dist/maloca/evidentia.js +447 -0
  111. package/dist/maloca/evidentia.js.map +1 -0
  112. package/dist/maloca/gateway/api.d.ts +146 -0
  113. package/dist/maloca/gateway/api.d.ts.map +1 -0
  114. package/dist/maloca/gateway/api.js +228 -0
  115. package/dist/maloca/gateway/api.js.map +1 -0
  116. package/dist/maloca/gateway/auth.d.ts +20 -0
  117. package/dist/maloca/gateway/auth.d.ts.map +1 -0
  118. package/dist/maloca/gateway/auth.js +115 -0
  119. package/dist/maloca/gateway/auth.js.map +1 -0
  120. package/dist/maloca/gateway/dashboard.d.ts +42 -0
  121. package/dist/maloca/gateway/dashboard.d.ts.map +1 -0
  122. package/dist/maloca/gateway/dashboard.js +67 -0
  123. package/dist/maloca/gateway/dashboard.js.map +1 -0
  124. package/dist/maloca/gateway/websocket.d.ts +34 -0
  125. package/dist/maloca/gateway/websocket.d.ts.map +1 -0
  126. package/dist/maloca/gateway/websocket.js +71 -0
  127. package/dist/maloca/gateway/websocket.js.map +1 -0
  128. package/dist/maloca/karma.d.ts +165 -0
  129. package/dist/maloca/karma.d.ts.map +1 -0
  130. package/dist/maloca/karma.js +307 -0
  131. package/dist/maloca/karma.js.map +1 -0
  132. package/dist/maloca/kernel.d.ts +20 -0
  133. package/dist/maloca/kernel.d.ts.map +1 -0
  134. package/dist/maloca/kernel.js +76 -0
  135. package/dist/maloca/kernel.js.map +1 -0
  136. package/dist/maloca/metadata.d.ts +30 -0
  137. package/dist/maloca/metadata.d.ts.map +1 -0
  138. package/dist/maloca/metadata.js +80 -0
  139. package/dist/maloca/metadata.js.map +1 -0
  140. package/dist/maloca/perfil.d.ts +57 -0
  141. package/dist/maloca/perfil.d.ts.map +1 -0
  142. package/dist/maloca/perfil.js +113 -0
  143. package/dist/maloca/perfil.js.map +1 -0
  144. package/dist/maloca/plugin-registry.d.ts +27 -0
  145. package/dist/maloca/plugin-registry.d.ts.map +1 -0
  146. package/dist/maloca/plugin-registry.js +76 -0
  147. package/dist/maloca/plugin-registry.js.map +1 -0
  148. package/dist/maloca/polygon-bridge.d.ts +63 -0
  149. package/dist/maloca/polygon-bridge.d.ts.map +1 -0
  150. package/dist/maloca/polygon-bridge.js +198 -0
  151. package/dist/maloca/polygon-bridge.js.map +1 -0
  152. package/dist/maloca/types.d.ts +44 -0
  153. package/dist/maloca/types.d.ts.map +1 -0
  154. package/dist/maloca/types.js +2 -0
  155. package/dist/maloca/types.js.map +1 -0
  156. package/dist/medico/aval.d.ts +149 -0
  157. package/dist/medico/aval.d.ts.map +1 -0
  158. package/dist/medico/aval.js +281 -0
  159. package/dist/medico/aval.js.map +1 -0
  160. package/dist/medico/canonica.d.ts +96 -0
  161. package/dist/medico/canonica.d.ts.map +1 -0
  162. package/dist/medico/canonica.js +148 -0
  163. package/dist/medico/canonica.js.map +1 -0
  164. package/dist/medico/credencial.d.ts +160 -0
  165. package/dist/medico/credencial.d.ts.map +1 -0
  166. package/dist/medico/credencial.js +240 -0
  167. package/dist/medico/credencial.js.map +1 -0
  168. package/dist/medico/index.d.ts +36 -0
  169. package/dist/medico/index.d.ts.map +1 -0
  170. package/dist/medico/index.js +39 -0
  171. package/dist/medico/index.js.map +1 -0
  172. package/dist/medico/malla.d.ts +218 -0
  173. package/dist/medico/malla.d.ts.map +1 -0
  174. package/dist/medico/malla.js +347 -0
  175. package/dist/medico/malla.js.map +1 -0
  176. package/dist/medico/registro-profesional.d.ts +84 -0
  177. package/dist/medico/registro-profesional.d.ts.map +1 -0
  178. package/dist/medico/registro-profesional.js +135 -0
  179. package/dist/medico/registro-profesional.js.map +1 -0
  180. package/dist/medico/registro.d.ts +149 -0
  181. package/dist/medico/registro.d.ts.map +1 -0
  182. package/dist/medico/registro.js +173 -0
  183. package/dist/medico/registro.js.map +1 -0
  184. package/dist/medico/types.d.ts +287 -0
  185. package/dist/medico/types.d.ts.map +1 -0
  186. package/dist/medico/types.js +135 -0
  187. package/dist/medico/types.js.map +1 -0
  188. package/dist/medico/verificacion-registro.d.ts +300 -0
  189. package/dist/medico/verificacion-registro.d.ts.map +1 -0
  190. package/dist/medico/verificacion-registro.js +319 -0
  191. package/dist/medico/verificacion-registro.js.map +1 -0
  192. package/dist/mesh/index.d.ts +457 -0
  193. package/dist/mesh/index.d.ts.map +1 -0
  194. package/dist/mesh/index.js +929 -0
  195. package/dist/mesh/index.js.map +1 -0
  196. package/dist/namespaces/encrypted-plugin.d.ts +56 -0
  197. package/dist/namespaces/encrypted-plugin.d.ts.map +1 -0
  198. package/dist/namespaces/encrypted-plugin.js +173 -0
  199. package/dist/namespaces/encrypted-plugin.js.map +1 -0
  200. package/dist/namespaces/index.d.ts +52 -0
  201. package/dist/namespaces/index.d.ts.map +1 -0
  202. package/dist/namespaces/index.js +134 -0
  203. package/dist/namespaces/index.js.map +1 -0
  204. package/dist/namespaces/ivn-proofs.d.ts +54 -0
  205. package/dist/namespaces/ivn-proofs.d.ts.map +1 -0
  206. package/dist/namespaces/ivn-proofs.js +162 -0
  207. package/dist/namespaces/ivn-proofs.js.map +1 -0
  208. package/dist/namespaces/offers-gossip.d.ts +95 -0
  209. package/dist/namespaces/offers-gossip.d.ts.map +1 -0
  210. package/dist/namespaces/offers-gossip.js +213 -0
  211. package/dist/namespaces/offers-gossip.js.map +1 -0
  212. package/dist/node-memory/idb-store.d.ts +22 -0
  213. package/dist/node-memory/idb-store.d.ts.map +1 -0
  214. package/dist/node-memory/idb-store.js +154 -0
  215. package/dist/node-memory/idb-store.js.map +1 -0
  216. package/dist/node-memory/index.d.ts +14 -0
  217. package/dist/node-memory/index.d.ts.map +1 -0
  218. package/dist/node-memory/index.js +159 -0
  219. package/dist/node-memory/index.js.map +1 -0
  220. package/dist/node-memory/sync-flush.d.ts +11 -0
  221. package/dist/node-memory/sync-flush.d.ts.map +1 -0
  222. package/dist/node-memory/sync-flush.js +37 -0
  223. package/dist/node-memory/sync-flush.js.map +1 -0
  224. package/dist/node-memory/types.d.ts +34 -0
  225. package/dist/node-memory/types.d.ts.map +1 -0
  226. package/dist/node-memory/types.js +2 -0
  227. package/dist/node-memory/types.js.map +1 -0
  228. package/dist/node-memory/xavier-store.d.ts +12 -0
  229. package/dist/node-memory/xavier-store.d.ts.map +1 -0
  230. package/dist/node-memory/xavier-store.js +75 -0
  231. package/dist/node-memory/xavier-store.js.map +1 -0
  232. package/dist/op-log/index.d.ts +49 -0
  233. package/dist/op-log/index.d.ts.map +1 -0
  234. package/dist/op-log/index.js +190 -0
  235. package/dist/op-log/index.js.map +1 -0
  236. package/dist/presence/health.d.ts +54 -0
  237. package/dist/presence/health.d.ts.map +1 -0
  238. package/dist/presence/health.js +139 -0
  239. package/dist/presence/health.js.map +1 -0
  240. package/dist/presence/index.d.ts +85 -0
  241. package/dist/presence/index.d.ts.map +1 -0
  242. package/dist/presence/index.js +255 -0
  243. package/dist/presence/index.js.map +1 -0
  244. package/dist/presence/peer-health.d.ts +40 -0
  245. package/dist/presence/peer-health.d.ts.map +1 -0
  246. package/dist/presence/peer-health.js +118 -0
  247. package/dist/presence/peer-health.js.map +1 -0
  248. package/dist/protocol/canonical.d.ts +10 -0
  249. package/dist/protocol/canonical.d.ts.map +1 -0
  250. package/dist/protocol/canonical.js +32 -0
  251. package/dist/protocol/canonical.js.map +1 -0
  252. package/dist/protocol/crypto.d.ts +299 -0
  253. package/dist/protocol/crypto.d.ts.map +1 -0
  254. package/dist/protocol/crypto.js +739 -0
  255. package/dist/protocol/crypto.js.map +1 -0
  256. package/dist/protocol/index.d.ts +30 -0
  257. package/dist/protocol/index.d.ts.map +1 -0
  258. package/dist/protocol/index.js +116 -0
  259. package/dist/protocol/index.js.map +1 -0
  260. package/dist/protocol/utils.d.ts +5 -0
  261. package/dist/protocol/utils.d.ts.map +1 -0
  262. package/dist/protocol/utils.js +27 -0
  263. package/dist/protocol/utils.js.map +1 -0
  264. package/dist/salones/manager.d.ts +100 -0
  265. package/dist/salones/manager.d.ts.map +1 -0
  266. package/dist/salones/manager.js +240 -0
  267. package/dist/salones/manager.js.map +1 -0
  268. package/dist/security/rate-limiter.d.ts +13 -0
  269. package/dist/security/rate-limiter.d.ts.map +1 -0
  270. package/dist/security/rate-limiter.js +32 -0
  271. package/dist/security/rate-limiter.js.map +1 -0
  272. package/dist/snapshot/index.d.ts +90 -0
  273. package/dist/snapshot/index.d.ts.map +1 -0
  274. package/dist/snapshot/index.js +189 -0
  275. package/dist/snapshot/index.js.map +1 -0
  276. package/dist/storage/index.d.ts +49 -0
  277. package/dist/storage/index.d.ts.map +1 -0
  278. package/dist/storage/index.js +176 -0
  279. package/dist/storage/index.js.map +1 -0
  280. package/dist/storage/optimizer.d.ts +28 -0
  281. package/dist/storage/optimizer.d.ts.map +1 -0
  282. package/dist/storage/optimizer.js +50 -0
  283. package/dist/storage/optimizer.js.map +1 -0
  284. package/dist/storage/ydoc-persistence.d.ts +27 -0
  285. package/dist/storage/ydoc-persistence.d.ts.map +1 -0
  286. package/dist/storage/ydoc-persistence.js +128 -0
  287. package/dist/storage/ydoc-persistence.js.map +1 -0
  288. package/dist/sync/ChunkSyncManager.d.ts +41 -0
  289. package/dist/sync/ChunkSyncManager.d.ts.map +1 -0
  290. package/dist/sync/ChunkSyncManager.js +115 -0
  291. package/dist/sync/ChunkSyncManager.js.map +1 -0
  292. package/dist/sync/conflict-resolver.d.ts +33 -0
  293. package/dist/sync/conflict-resolver.d.ts.map +1 -0
  294. package/dist/sync/conflict-resolver.js +54 -0
  295. package/dist/sync/conflict-resolver.js.map +1 -0
  296. package/dist/sync/engine.d.ts +168 -0
  297. package/dist/sync/engine.d.ts.map +1 -0
  298. package/dist/sync/engine.js +315 -0
  299. package/dist/sync/engine.js.map +1 -0
  300. package/dist/sync/index.d.ts +3 -0
  301. package/dist/sync/index.d.ts.map +1 -0
  302. package/dist/sync/index.js +3 -0
  303. package/dist/sync/index.js.map +1 -0
  304. package/dist/transport/TorTransportAdapter.d.ts +70 -0
  305. package/dist/transport/TorTransportAdapter.d.ts.map +1 -0
  306. package/dist/transport/TorTransportAdapter.js +192 -0
  307. package/dist/transport/TorTransportAdapter.js.map +1 -0
  308. package/dist/transport/memory.d.ts +31 -0
  309. package/dist/transport/memory.d.ts.map +1 -0
  310. package/dist/transport/memory.js +114 -0
  311. package/dist/transport/memory.js.map +1 -0
  312. package/dist/transport/peerjs.d.ts +45 -0
  313. package/dist/transport/peerjs.d.ts.map +1 -0
  314. package/dist/transport/peerjs.js +301 -0
  315. package/dist/transport/peerjs.js.map +1 -0
  316. package/dist/transport/pqc-handshake.d.ts +72 -0
  317. package/dist/transport/pqc-handshake.d.ts.map +1 -0
  318. package/dist/transport/pqc-handshake.js +129 -0
  319. package/dist/transport/pqc-handshake.js.map +1 -0
  320. package/dist/transport/relay-config.d.ts +11 -0
  321. package/dist/transport/relay-config.d.ts.map +1 -0
  322. package/dist/transport/relay-config.js +48 -0
  323. package/dist/transport/relay-config.js.map +1 -0
  324. package/dist/transport/relay-server.d.ts +37 -0
  325. package/dist/transport/relay-server.d.ts.map +1 -0
  326. package/dist/transport/relay-server.js +230 -0
  327. package/dist/transport/relay-server.js.map +1 -0
  328. package/dist/transport/tor.d.ts +47 -0
  329. package/dist/transport/tor.d.ts.map +1 -0
  330. package/dist/transport/tor.js +158 -0
  331. package/dist/transport/tor.js.map +1 -0
  332. package/dist/transport/types.d.ts +34 -0
  333. package/dist/transport/types.d.ts.map +1 -0
  334. package/dist/transport/types.js +2 -0
  335. package/dist/transport/types.js.map +1 -0
  336. package/dist/types/index.d.ts +293 -0
  337. package/dist/types/index.d.ts.map +1 -0
  338. package/dist/types/index.js +73 -0
  339. package/dist/types/index.js.map +1 -0
  340. package/dist/web/admission.d.ts +24 -0
  341. package/dist/web/admission.d.ts.map +1 -0
  342. package/dist/web/admission.js +41 -0
  343. package/dist/web/admission.js.map +1 -0
  344. package/dist/web/crypto.d.ts +18 -0
  345. package/dist/web/crypto.d.ts.map +1 -0
  346. package/dist/web/crypto.js +78 -0
  347. package/dist/web/crypto.js.map +1 -0
  348. package/dist/web/exchange.d.ts +23 -0
  349. package/dist/web/exchange.d.ts.map +1 -0
  350. package/dist/web/exchange.js +54 -0
  351. package/dist/web/exchange.js.map +1 -0
  352. package/dist/web/fragment.d.ts +58 -0
  353. package/dist/web/fragment.d.ts.map +1 -0
  354. package/dist/web/fragment.js +198 -0
  355. package/dist/web/fragment.js.map +1 -0
  356. package/dist/web/index.d.ts +25 -0
  357. package/dist/web/index.d.ts.map +1 -0
  358. package/dist/web/index.js +14 -0
  359. package/dist/web/index.js.map +1 -0
  360. package/dist/web/merge/index.d.ts +104 -0
  361. package/dist/web/merge/index.d.ts.map +1 -0
  362. package/dist/web/merge/index.js +236 -0
  363. package/dist/web/merge/index.js.map +1 -0
  364. package/dist/web/oplog/hlc.d.ts +19 -0
  365. package/dist/web/oplog/hlc.d.ts.map +1 -0
  366. package/dist/web/oplog/hlc.js +39 -0
  367. package/dist/web/oplog/hlc.js.map +1 -0
  368. package/dist/web/oplog/index.d.ts +10 -0
  369. package/dist/web/oplog/index.d.ts.map +1 -0
  370. package/dist/web/oplog/index.js +6 -0
  371. package/dist/web/oplog/index.js.map +1 -0
  372. package/dist/web/oplog/log.d.ts +182 -0
  373. package/dist/web/oplog/log.d.ts.map +1 -0
  374. package/dist/web/oplog/log.js +693 -0
  375. package/dist/web/oplog/log.js.map +1 -0
  376. package/dist/web/oplog/store.d.ts +40 -0
  377. package/dist/web/oplog/store.d.ts.map +1 -0
  378. package/dist/web/oplog/store.js +85 -0
  379. package/dist/web/oplog/store.js.map +1 -0
  380. package/dist/web/oplog/sync.d.ts +54 -0
  381. package/dist/web/oplog/sync.d.ts.map +1 -0
  382. package/dist/web/oplog/sync.js +162 -0
  383. package/dist/web/oplog/sync.js.map +1 -0
  384. package/dist/web/oplog/types.d.ts +119 -0
  385. package/dist/web/oplog/types.d.ts.map +1 -0
  386. package/dist/web/oplog/types.js +2 -0
  387. package/dist/web/oplog/types.js.map +1 -0
  388. package/dist/web/pairing.d.ts +186 -0
  389. package/dist/web/pairing.d.ts.map +1 -0
  390. package/dist/web/pairing.js +395 -0
  391. package/dist/web/pairing.js.map +1 -0
  392. package/dist/web/pq.d.ts +36 -0
  393. package/dist/web/pq.d.ts.map +1 -0
  394. package/dist/web/pq.js +59 -0
  395. package/dist/web/pq.js.map +1 -0
  396. package/dist/web/provider.d.ts +188 -0
  397. package/dist/web/provider.d.ts.map +1 -0
  398. package/dist/web/provider.js +2042 -0
  399. package/dist/web/provider.js.map +1 -0
  400. package/dist/web/rooms.d.ts +20 -0
  401. package/dist/web/rooms.d.ts.map +1 -0
  402. package/dist/web/rooms.js +51 -0
  403. package/dist/web/rooms.js.map +1 -0
  404. package/dist/web/rotation.d.ts +73 -0
  405. package/dist/web/rotation.d.ts.map +1 -0
  406. package/dist/web/rotation.js +130 -0
  407. package/dist/web/rotation.js.map +1 -0
  408. package/dist/web/secstate.d.ts +213 -0
  409. package/dist/web/secstate.d.ts.map +1 -0
  410. package/dist/web/secstate.js +789 -0
  411. package/dist/web/secstate.js.map +1 -0
  412. package/dist/web/store.d.ts +9 -0
  413. package/dist/web/store.d.ts.map +1 -0
  414. package/dist/web/store.js +32 -0
  415. package/dist/web/store.js.map +1 -0
  416. package/dist/web/transports/loopback.d.ts +11 -0
  417. package/dist/web/transports/loopback.d.ts.map +1 -0
  418. package/dist/web/transports/loopback.js +97 -0
  419. package/dist/web/transports/loopback.js.map +1 -0
  420. package/dist/web/transports/qr-sdp.d.ts +27 -0
  421. package/dist/web/transports/qr-sdp.d.ts.map +1 -0
  422. package/dist/web/transports/qr-sdp.js +131 -0
  423. package/dist/web/transports/qr-sdp.js.map +1 -0
  424. package/dist/web/transports/ws.d.ts +12 -0
  425. package/dist/web/transports/ws.d.ts.map +1 -0
  426. package/dist/web/transports/ws.js +139 -0
  427. package/dist/web/transports/ws.js.map +1 -0
  428. package/dist/web/trust/canonical.d.ts +8 -0
  429. package/dist/web/trust/canonical.d.ts.map +1 -0
  430. package/dist/web/trust/canonical.js +27 -0
  431. package/dist/web/trust/canonical.js.map +1 -0
  432. package/dist/web/trust/docs.d.ts +51 -0
  433. package/dist/web/trust/docs.d.ts.map +1 -0
  434. package/dist/web/trust/docs.js +170 -0
  435. package/dist/web/trust/docs.js.map +1 -0
  436. package/dist/web/trust/index.d.ts +10 -0
  437. package/dist/web/trust/index.d.ts.map +1 -0
  438. package/dist/web/trust/index.js +7 -0
  439. package/dist/web/trust/index.js.map +1 -0
  440. package/dist/web/trust/keys.d.ts +37 -0
  441. package/dist/web/trust/keys.d.ts.map +1 -0
  442. package/dist/web/trust/keys.js +75 -0
  443. package/dist/web/trust/keys.js.map +1 -0
  444. package/dist/web/trust/store.d.ts +150 -0
  445. package/dist/web/trust/store.d.ts.map +1 -0
  446. package/dist/web/trust/store.js +587 -0
  447. package/dist/web/trust/store.js.map +1 -0
  448. package/dist/web/trust/types.d.ts +134 -0
  449. package/dist/web/trust/types.d.ts.map +1 -0
  450. package/dist/web/trust/types.js +4 -0
  451. package/dist/web/trust/types.js.map +1 -0
  452. package/dist/web/types.d.ts +115 -0
  453. package/dist/web/types.d.ts.map +1 -0
  454. package/dist/web/types.js +2 -0
  455. package/dist/web/types.js.map +1 -0
  456. package/dist/web/util.d.ts +12 -0
  457. package/dist/web/util.d.ts.map +1 -0
  458. package/dist/web/util.js +54 -0
  459. package/dist/web/util.js.map +1 -0
  460. package/dist/web/webrtc.d.ts +35 -0
  461. package/dist/web/webrtc.d.ts.map +1 -0
  462. package/dist/web/webrtc.js +304 -0
  463. package/dist/web/webrtc.js.map +1 -0
  464. package/package.json +138 -4
@@ -0,0 +1,693 @@
1
+ // OpLog: per-device append-only, signed, hash-chained operation logs with capability-gated application.
2
+ //
3
+ // Ingest pipeline (serialized):
4
+ // shape/size/instance -> duplicate? -> author key known? (else pending) -> signature -> fork check (same seq,
5
+ // different id = equivocation) -> chain (gap = pending, prev mismatch = equivocation, HLC must increase) ->
6
+ // future HLC? (pending) -> append to the author's chain -> verdict.
7
+ // Verdict (pure, recomputed whenever trust changes): equivocation cut -> app `validate` -> TrustStore.can(author,
8
+ // module, level(action), { seq, time: hlc wall }). Ops in the chain with a negative verdict are "held" in
9
+ // quarantine and re-evaluated; the accepted set (and so every projection) is a function of (ops, trust docs).
10
+ import { canonicalBytes, contentId } from "../trust/canonical.js";
11
+ import { SIG_ALG, signCanonical, verifyCanonical, } from "../trust/keys.js";
12
+ import { compareHlc, createHlc, hlcWall, isHlc } from "./hlc.js";
13
+ import { MemoryOpStore, MemoryQuarantineStore, } from "./store.js";
14
+ export class OpLogError extends Error {
15
+ code;
16
+ constructor(code, message) {
17
+ super(message);
18
+ this.code = code;
19
+ }
20
+ }
21
+ const isObj = (x) => !!x && typeof x === "object" && !Array.isArray(x);
22
+ const isStr = (x, max = 256) => typeof x === "string" && x.length > 0 && x.length <= max;
23
+ const isOptStr = (x, max = 256) => x === undefined || isStr(x, max);
24
+ const vkey = (author, seq) => `${author}:${seq}`;
25
+ function opShape(x) {
26
+ if (!isObj(x) || x.t !== "op")
27
+ return "not an op";
28
+ if (x.v !== 1 || x.alg !== SIG_ALG)
29
+ return "unsupported version/alg";
30
+ if (!isStr(x.inst) || !isStr(x.author) || !isStr(x.sig, 4500))
31
+ return "missing fields";
32
+ if (typeof x.seq !== "number" || !Number.isSafeInteger(x.seq) || x.seq < 1)
33
+ return "bad seq";
34
+ if (x.seq === 1 ? x.prev !== null : !isStr(x.prev))
35
+ return "bad prev";
36
+ if (!isHlc(x.hlc))
37
+ return "bad hlc";
38
+ if (!isStr(x.module, 64) ||
39
+ !isStr(x.action, 128) ||
40
+ !isStr(x.entity, 128) ||
41
+ !isStr(x.entityId, 256)) {
42
+ return "bad module/action/entity";
43
+ }
44
+ if (!isOptStr(x.base) || !isOptStr(x.actor))
45
+ return "bad base/actor";
46
+ return null;
47
+ }
48
+ const bodyOfOp = (op) => {
49
+ const { sig: _sig, ...body } = op;
50
+ return body;
51
+ };
52
+ /** Total order used by projections: (hlc, author, seq). */
53
+ export const compareOps = (a, b) => compareHlc(a.hlc, b.hlc) ||
54
+ (a.author < b.author ? -1 : a.author > b.author ? 1 : 0) ||
55
+ a.seq - b.seq;
56
+ export async function openOpLog(opts) {
57
+ const log = new OpLog(opts);
58
+ await log.load();
59
+ return log;
60
+ }
61
+ export class OpLog {
62
+ trust;
63
+ inst;
64
+ store;
65
+ quarantine;
66
+ signer;
67
+ validateFn;
68
+ now;
69
+ maxSkewMs;
70
+ maxPending;
71
+ maxPendingBytes;
72
+ maxPendingPerAuthor;
73
+ maxPendingUnknown;
74
+ maxPendingUnknownBytes;
75
+ pendingBytes = 0;
76
+ unknownCount = 0;
77
+ unknownBytes = 0;
78
+ pendingPerAuthor = new Map();
79
+ /** BL2: op id -> pending key of ops parked for an anchor (backward resolution walks `prev` ids) */
80
+ anchorIds = new Map();
81
+ /** finding 6: pending keys of ops parked for an anchor, per `author:seq` (at most 2 per seq) */
82
+ anchorBySeq = new Map();
83
+ maxOpBytes;
84
+ clock;
85
+ verdicts = new Map();
86
+ modulesOf = new Map();
87
+ equiv = new Map();
88
+ pendingOps = new Map(); // key author:seq:sig
89
+ /** S3: author -> highest anchored seq whose STORED op is not the anchored one (its history <= that seq is void) */
90
+ offAnchor = new Map();
91
+ listeners = new Map();
92
+ queue = Promise.resolve();
93
+ changed = new Set();
94
+ unsubscribeTrust;
95
+ constructor(opts) {
96
+ this.trust = opts.trust;
97
+ this.inst = opts.trust.inst;
98
+ this.store = opts.store ?? new MemoryOpStore();
99
+ this.quarantine = opts.quarantine ?? new MemoryQuarantineStore();
100
+ this.signer = opts.signer;
101
+ this.validateFn = opts.validate;
102
+ this.now = opts.now ?? Date.now;
103
+ this.maxSkewMs = opts.maxSkewMs ?? 10 * 60_000;
104
+ this.maxPending = opts.maxPending ?? 10_000;
105
+ this.maxPendingBytes = opts.maxPendingBytes ?? 16 * 1024 * 1024;
106
+ this.maxPendingPerAuthor = opts.maxPendingPerAuthor ?? 1024;
107
+ this.maxPendingUnknown =
108
+ opts.maxPendingUnknown ?? Math.max(1, Math.floor(this.maxPending / 10));
109
+ this.maxPendingUnknownBytes = opts.maxPendingUnknownBytes ?? 1024 * 1024;
110
+ this.maxOpBytes = opts.maxOpBytes ?? 32 * 1024;
111
+ this.clock = createHlc(this.now);
112
+ this.unsubscribeTrust = this.trust.onChange(() => void this.reevaluate());
113
+ }
114
+ /** Rebuild in-memory indexes from the stores (no events). */
115
+ async load() {
116
+ await this.serial(async () => {
117
+ await this.refreshAnchors();
118
+ for (const q of await this.quarantine.list()) {
119
+ if (q.kind === "evidence" && q.author && q.forkSeq !== undefined) {
120
+ const cur = this.equiv.get(q.author);
121
+ if (!cur || q.forkSeq < cur.forkSeq)
122
+ this.equiv.set(q.author, { forkSeq: q.forkSeq });
123
+ }
124
+ }
125
+ for (const s of await this.store.all()) {
126
+ this.modulesOf.set(vkey(s.op.author, s.op.seq), s.op.module);
127
+ this.verdicts.set(vkey(s.op.author, s.op.seq), this.verdict(s));
128
+ this.clock.observe(s.op.hlc);
129
+ }
130
+ });
131
+ }
132
+ close() {
133
+ this.unsubscribeTrust();
134
+ this.listeners.clear();
135
+ }
136
+ on(event, cb) {
137
+ let s = this.listeners.get(event);
138
+ if (!s) {
139
+ s = new Set();
140
+ this.listeners.set(event, s);
141
+ }
142
+ s.add(cb);
143
+ return () => s?.delete(cb);
144
+ }
145
+ emit(event, e) {
146
+ for (const cb of [...(this.listeners.get(event) ?? [])]) {
147
+ try {
148
+ cb(e);
149
+ }
150
+ catch {
151
+ // listener errors never break the log
152
+ }
153
+ }
154
+ }
155
+ serial(fn) {
156
+ const run = this.queue.then(fn);
157
+ this.queue = run.catch(() => undefined);
158
+ return run;
159
+ }
160
+ flushChange() {
161
+ if (!this.changed.size)
162
+ return;
163
+ const modules = [...this.changed].sort();
164
+ this.changed = new Set();
165
+ this.emit("change", { modules });
166
+ }
167
+ // ─── verdict ─────────────────────────────────────────────────────────────
168
+ levelFor(module, action) {
169
+ return this.trust.schema.actionLevel?.(module, action) ?? "editar";
170
+ }
171
+ /** Pure function of (op, trust docs, equivocation evidence, validate). */
172
+ verdict(s) {
173
+ const { op } = s;
174
+ const eq = this.equiv.get(op.author);
175
+ if (eq && op.seq >= eq.forkSeq)
176
+ return {
177
+ ok: false,
178
+ reason: "equivocation",
179
+ detail: `fork at seq ${eq.forkSeq}`,
180
+ };
181
+ const off = this.offAnchor.get(op.author);
182
+ if (off !== undefined && op.seq <= off)
183
+ return {
184
+ ok: false,
185
+ reason: "unauthorized",
186
+ detail: "not on the revocation anchor chain",
187
+ };
188
+ const v = this.validateFn?.(op) ?? true;
189
+ if (v !== true)
190
+ return { ok: false, reason: "invalid", detail: v };
191
+ const d = this.trust.explain(op.author, op.module, this.levelFor(op.module, op.action), {
192
+ seq: op.seq,
193
+ time: hlcWall(op.hlc),
194
+ });
195
+ return d.ok
196
+ ? { ok: true }
197
+ : { ok: false, reason: "unauthorized", detail: d.reason };
198
+ }
199
+ async setVerdict(s, v, fresh) {
200
+ const k = vkey(s.op.author, s.op.seq);
201
+ const prev = this.verdicts.get(k);
202
+ this.verdicts.set(k, v);
203
+ this.modulesOf.set(k, s.op.module);
204
+ const qkey = `held:${k}`;
205
+ if (v.ok) {
206
+ if (prev && !prev.ok)
207
+ await this.quarantine.delete(qkey);
208
+ if (fresh || !prev?.ok) {
209
+ this.changed.add(s.op.module);
210
+ this.clock.observe(s.op.hlc);
211
+ this.emit("applied", s);
212
+ }
213
+ return;
214
+ }
215
+ if (prev?.ok) {
216
+ this.changed.add(s.op.module);
217
+ this.emit("retracted", { entry: s, reason: v.reason, detail: v.detail });
218
+ }
219
+ if (fresh ||
220
+ prev?.ok ||
221
+ (prev &&
222
+ !prev.ok &&
223
+ (prev.reason !== v.reason || prev.detail !== v.detail))) {
224
+ const entry = {
225
+ key: qkey,
226
+ kind: "held",
227
+ reason: v.reason,
228
+ detail: v.detail,
229
+ author: s.op.author,
230
+ seq: s.op.seq,
231
+ id: s.id,
232
+ op: s.op,
233
+ at: this.now(),
234
+ };
235
+ await this.quarantine.put(entry);
236
+ this.emit("quarantined", entry);
237
+ }
238
+ }
239
+ async rejectOp(reason, op, detail, id) {
240
+ const o = isObj(op) ? op : {};
241
+ const author = typeof o.author === "string" ? o.author.slice(0, 64) : undefined;
242
+ const seq = typeof o.seq === "number" ? o.seq : undefined;
243
+ const entry = {
244
+ key: `rej:${author ?? "?"}:${seq ?? "?"}:${id ?? (typeof o.sig === "string" ? o.sig.slice(0, 16) : "?")}`,
245
+ kind: "rejected",
246
+ reason,
247
+ detail,
248
+ author,
249
+ seq,
250
+ id,
251
+ // keep the evidence only for well-formed, size-checked ops
252
+ op: reason === "too-large" || reason === "malformed" ? undefined : op,
253
+ at: this.now(),
254
+ };
255
+ await this.quarantine.put(entry);
256
+ this.emit("quarantined", entry);
257
+ return { status: "quarantined", reason, detail, id };
258
+ }
259
+ // ─── append (local) ──────────────────────────────────────────────────────
260
+ /** Sign and append a local op. Throws OpLogError if the local device is not allowed (nothing is signed). */
261
+ append(input) {
262
+ return this.serial(async () => {
263
+ const signer = this.signer;
264
+ if (!signer)
265
+ throw new OpLogError("no-signer", "append needs a signer");
266
+ const head = await this.store.head(signer.fp);
267
+ const seq = (head?.op.seq ?? 0) + 1;
268
+ if (head)
269
+ this.clock.observe(head.op.hlc);
270
+ const hlc = this.clock.now();
271
+ const body = JSON.parse(JSON.stringify({
272
+ ...input,
273
+ t: "op",
274
+ v: 1,
275
+ alg: SIG_ALG,
276
+ inst: this.inst,
277
+ author: signer.fp,
278
+ seq,
279
+ prev: head?.id ?? null,
280
+ hlc,
281
+ }));
282
+ const shape = opShape({ ...body, sig: "x" });
283
+ if (shape)
284
+ throw new OpLogError("invalid", shape);
285
+ if (canonicalBytes(body).length > this.maxOpBytes)
286
+ throw new OpLogError("too-large", "op too large");
287
+ const pre = this.verdict({ id: "", op: { ...body, sig: "" } });
288
+ if (!pre.ok) {
289
+ throw new OpLogError(pre.reason === "invalid" ? "invalid" : "unauthorized", `${pre.reason}: ${pre.detail}`);
290
+ }
291
+ const op = { ...body, sig: await signCanonical(signer, body) };
292
+ const entry = { id: await contentId(body), op };
293
+ await this.store.append(entry);
294
+ this.emit("appended", entry);
295
+ await this.setVerdict(entry, this.verdict(entry), true);
296
+ this.flushChange();
297
+ return entry;
298
+ });
299
+ }
300
+ // ─── ingest (remote) ─────────────────────────────────────────────────────
301
+ ingest(op) {
302
+ return this.ingestMany([op]).then((r) => r[0]);
303
+ }
304
+ ingestMany(ops) {
305
+ return this.serial(async () => {
306
+ const out = [];
307
+ for (const op of ops)
308
+ out.push(await this.ingestOne(op));
309
+ this.flushChange();
310
+ return out;
311
+ });
312
+ }
313
+ takePending(k) {
314
+ const p = this.pendingOps.get(k);
315
+ if (!p)
316
+ return undefined;
317
+ this.pendingOps.delete(k);
318
+ this.pendingBytes -= p.size;
319
+ const n = (this.pendingPerAuthor.get(p.op.author) ?? 1) - 1;
320
+ if (n > 0)
321
+ this.pendingPerAuthor.set(p.op.author, n);
322
+ else
323
+ this.pendingPerAuthor.delete(p.op.author);
324
+ if (p.reason === "unknown-author") {
325
+ this.unknownCount--;
326
+ this.unknownBytes -= p.size;
327
+ }
328
+ if (p.reason === "anchor" && p.id && this.anchorIds.get(p.id) === k)
329
+ this.anchorIds.delete(p.id);
330
+ if (p.reason === "anchor") {
331
+ const sk = `${p.op.author}:${p.op.seq}`;
332
+ const set = this.anchorBySeq.get(sk);
333
+ set?.delete(k);
334
+ if (set && set.size === 0)
335
+ this.anchorBySeq.delete(sk);
336
+ }
337
+ return p;
338
+ }
339
+ /** Drop the oldest unknown-author pending op (insertion order). False if there is none. */
340
+ evictUnknown() {
341
+ for (const [k, p] of this.pendingOps) {
342
+ if (p.reason !== "unknown-author")
343
+ continue;
344
+ this.takePending(k);
345
+ return true;
346
+ }
347
+ return false;
348
+ }
349
+ /**
350
+ * S4: bounded pending set. Known authors (gap/future/anchor) only take free room (or room held by unknown authors);
351
+ * unknown authors live in a small FIFO budget of their own and never displace a known author's op.
352
+ */
353
+ park(op, reason, size, id, authorCap = this.maxPendingPerAuthor) {
354
+ const k = `${op.author}:${op.seq}:${op.sig}`;
355
+ if (this.pendingOps.has(k))
356
+ return { status: "pending", reason };
357
+ const overflow = {
358
+ status: "quarantined",
359
+ reason: "pending-overflow",
360
+ };
361
+ if ((this.pendingPerAuthor.get(op.author) ?? 0) >= authorCap)
362
+ return overflow;
363
+ const unknown = reason === "unknown-author";
364
+ if (unknown && size > this.maxPendingUnknownBytes)
365
+ return overflow;
366
+ while (this.pendingOps.size >= this.maxPending ||
367
+ this.pendingBytes + size > this.maxPendingBytes ||
368
+ (unknown &&
369
+ (this.unknownCount >= this.maxPendingUnknown ||
370
+ this.unknownBytes + size > this.maxPendingUnknownBytes))) {
371
+ if (!this.evictUnknown())
372
+ return overflow;
373
+ }
374
+ this.pendingOps.set(k, { op, reason, id, size });
375
+ if (reason === "anchor" && id)
376
+ this.anchorIds.set(id, k);
377
+ if (reason === "anchor") {
378
+ const sk = `${op.author}:${op.seq}`;
379
+ const set = this.anchorBySeq.get(sk) ?? new Set();
380
+ set.add(k);
381
+ this.anchorBySeq.set(sk, set);
382
+ }
383
+ this.pendingBytes += size;
384
+ this.pendingPerAuthor.set(op.author, (this.pendingPerAuthor.get(op.author) ?? 0) + 1);
385
+ if (unknown) {
386
+ this.unknownCount++;
387
+ this.unknownBytes += size;
388
+ }
389
+ this.emit("pending", { op, reason });
390
+ return { status: "pending", reason };
391
+ }
392
+ /** Highest anchor of `author` covering `seq` (S3), if any. */
393
+ anchorFor(author, seq) {
394
+ return this.trust.anchorsOf(author).find((a) => a.seq >= seq);
395
+ }
396
+ /**
397
+ * S3: ops of a revoked author at or below an anchor wait as pending until a chain from our stored head up to the
398
+ * anchored op is complete (walked backwards from the anchor id through `prev`); then exactly that chain is
399
+ * ingested and every other pending op of the author at or below the anchor is rejected as a forgery.
400
+ */
401
+ async resolveAnchor(author, anchor) {
402
+ const head = await this.store.head(author);
403
+ const headSeq = head?.op.seq ?? 0;
404
+ if (headSeq >= anchor.seq)
405
+ return;
406
+ // BL2: walk backwards from the anchor through `prev` ids (index lookups, no scan per step)
407
+ const chain = [];
408
+ let want = anchor.id;
409
+ for (let s = anchor.seq; s > headSeq; s--) {
410
+ const k = want === null ? undefined : this.anchorIds.get(want);
411
+ const p = k ? this.pendingOps.get(k) : undefined;
412
+ if (!k || !p || p.op.author !== author || p.op.seq !== s)
413
+ return; // incomplete: keep waiting
414
+ chain.push([k, p.op]);
415
+ want = p.op.prev;
416
+ }
417
+ if ((head?.id ?? null) !== want)
418
+ return; // does not continue what we store
419
+ chain.reverse();
420
+ for (const [k, o] of chain) {
421
+ this.takePending(k);
422
+ await this.ingestOne(o, false, true);
423
+ }
424
+ const mine = [...this.pendingOps.entries()].filter(([, p]) => p.op.author === author && p.op.seq <= anchor.seq);
425
+ for (const [k, p] of mine) {
426
+ if (!this.pendingOps.has(k))
427
+ continue;
428
+ this.takePending(k);
429
+ await this.rejectOp("broken-chain", p.op, "not on the revocation anchor chain", p.id);
430
+ }
431
+ }
432
+ /** finding 6: pending keys on the (partial) chain walked back from the anchor id through `prev`. */
433
+ anchoredChainKeys(author, anchor) {
434
+ const out = new Set();
435
+ let want = anchor.id;
436
+ while (want !== null) {
437
+ const k = this.anchorIds.get(want);
438
+ const p = k ? this.pendingOps.get(k) : undefined;
439
+ if (!k || !p || p.op.author !== author)
440
+ break;
441
+ out.add(k);
442
+ want = p.op.prev;
443
+ }
444
+ return out;
445
+ }
446
+ /** Is our stored op of `author` at `seq` on an anchored chain (an anchor >= seq whose op we store)? */
447
+ async storedAnchored(author, seq) {
448
+ for (const a of this.trust.anchorsOf(author))
449
+ if (a.seq >= seq && (await this.store.get(author, a.seq))?.id === a.id)
450
+ return true;
451
+ return false;
452
+ }
453
+ /** Recompute which authors' STORED history contradicts an anchor (sync verdicts read the result). */
454
+ async refreshAnchors() {
455
+ const next = new Map();
456
+ for (const author of Object.keys(await this.store.heads())) {
457
+ for (const a of this.trust.anchorsOf(author)) {
458
+ const stored = await this.store.get(author, a.seq);
459
+ if (stored && stored.id !== a.id)
460
+ next.set(author, Math.max(next.get(author) ?? 0, a.seq));
461
+ }
462
+ }
463
+ this.offAnchor = next;
464
+ }
465
+ async ingestOne(x, drain = true, anchored = false) {
466
+ const bad = opShape(x);
467
+ if (bad)
468
+ return this.rejectOp("malformed", x, bad);
469
+ const op = x;
470
+ const body = bodyOfOp(op);
471
+ const size = canonicalBytes(body).length;
472
+ if (size > this.maxOpBytes)
473
+ return this.rejectOp("too-large", op);
474
+ if (op.inst !== this.inst)
475
+ return this.rejectOp("wrong-instance", op);
476
+ const id = await contentId(body);
477
+ const existing = await this.store.get(op.author, op.seq);
478
+ if (existing && existing.id === id)
479
+ return { status: "duplicate", id };
480
+ const pub = this.trust.keyOf(op.author);
481
+ if (!pub)
482
+ return this.park(op, "unknown-author", size);
483
+ if (!(await verifyCanonical(pub, body, op.sig)))
484
+ return this.rejectOp("bad-signature", op, undefined, id);
485
+ const anchor = anchored ? undefined : this.anchorFor(op.author, op.seq);
486
+ if (existing) {
487
+ // S3: our stored chain IS the anchored one: a different op at that seq is a forgery by the revoked key, not
488
+ // evidence against the legit history (no equivocation cut)
489
+ if (await this.storedAnchored(op.author, op.seq))
490
+ return this.rejectOp("broken-chain", op, "not on the revocation anchor chain", id);
491
+ return this.equivocate(op.author, op.seq, existing.op, op);
492
+ }
493
+ const head = await this.store.head(op.author);
494
+ const headSeq = head?.op.seq ?? 0;
495
+ if (op.seq <= headSeq)
496
+ return { status: "stale", id }; // below a pruned base
497
+ if (anchor) {
498
+ if (op.seq === anchor.seq && id !== anchor.id)
499
+ return this.rejectOp("broken-chain", op, "not the op the revocation anchored", id);
500
+ // finding 6: at most 2 waiting ops per (author, seq); when full, the ones not on the chain walked back from
501
+ // the anchor so far are evicted (a fork sent first must not keep the real history out)
502
+ const sk = `${op.author}:${op.seq}`;
503
+ if ((this.anchorBySeq.get(sk)?.size ?? 0) >= 2) {
504
+ const onChain = this.anchoredChainKeys(op.author, anchor);
505
+ for (const k of [...(this.anchorBySeq.get(sk) ?? [])])
506
+ if (!onChain.has(k))
507
+ this.takePending(k);
508
+ if ((this.anchorBySeq.get(sk)?.size ?? 0) >= 2)
509
+ return { status: "quarantined", reason: "pending-overflow" };
510
+ }
511
+ // BL2: the whole anchored span may wait (bounded by the global pending caps, not the per-author one), twice
512
+ // over (a fork and the real history), finding 6
513
+ const r = this.park(op, "anchor", size, id, Math.max(this.maxPendingPerAuthor, 2 * (anchor.seq - headSeq)));
514
+ if (r.status !== "pending")
515
+ return r; // overflow is reported as such, never as a broken chain
516
+ await this.resolveAnchor(op.author, anchor);
517
+ if ((await this.store.get(op.author, op.seq))?.id === id) {
518
+ if (drain)
519
+ await this.drain(op.author);
520
+ const v = this.verdictOf(op.author, op.seq);
521
+ return !v || v.ok
522
+ ? { status: "applied", id, stored: true }
523
+ : {
524
+ status: "quarantined",
525
+ id,
526
+ stored: true,
527
+ reason: v.reason,
528
+ detail: v.detail,
529
+ };
530
+ }
531
+ return this.pendingOps.has(`${op.author}:${op.seq}:${op.sig}`)
532
+ ? r
533
+ : {
534
+ status: "quarantined",
535
+ id,
536
+ reason: "broken-chain",
537
+ detail: "not on the revocation anchor chain",
538
+ };
539
+ }
540
+ if (op.seq > headSeq + 1)
541
+ return this.park(op, "gap", size);
542
+ if (head && op.prev !== head.id) {
543
+ if (await this.storedAnchored(op.author, headSeq))
544
+ return this.rejectOp("broken-chain", op, "not on the revocation anchor chain", id);
545
+ return this.equivocate(op.author, headSeq, head.op, op);
546
+ }
547
+ if (head && compareHlc(op.hlc, head.op.hlc) <= 0)
548
+ return this.rejectOp("hlc-regression", op, undefined, id);
549
+ if (hlcWall(op.hlc) > this.now() + this.maxSkewMs)
550
+ return this.park(op, "future", size);
551
+ const entry = { id, op };
552
+ await this.store.append(entry);
553
+ this.emit("stored", entry);
554
+ const v = this.verdict(entry);
555
+ await this.setVerdict(entry, v, true);
556
+ if (drain)
557
+ await this.drain(op.author);
558
+ return v.ok
559
+ ? { status: "applied", id, stored: true }
560
+ : {
561
+ status: "quarantined",
562
+ id,
563
+ reason: v.reason,
564
+ detail: v.detail,
565
+ stored: true,
566
+ };
567
+ }
568
+ /** Retry pending ops (of one author, or all) in seq order. */
569
+ async drain(author) {
570
+ for (;;) {
571
+ const batch = [...this.pendingOps.entries()]
572
+ .filter(([, p]) => author === undefined || p.op.author === author)
573
+ .sort(([, a], [, b]) => a.op.author < b.op.author
574
+ ? -1
575
+ : a.op.author > b.op.author
576
+ ? 1
577
+ : a.op.seq - b.op.seq);
578
+ let progressed = false;
579
+ for (const [k, p] of batch) {
580
+ this.takePending(k);
581
+ const r = await this.ingestOne(p.op, false);
582
+ if (r.status !== "pending")
583
+ progressed = true;
584
+ else if (r.reason !== p.reason)
585
+ progressed = true;
586
+ }
587
+ if (!progressed)
588
+ return;
589
+ }
590
+ }
591
+ async equivocate(author, forkSeq, a, b) {
592
+ const cur = this.equiv.get(author);
593
+ if (!cur || forkSeq < cur.forkSeq) {
594
+ this.equiv.set(author, { forkSeq });
595
+ const entry = {
596
+ key: `eq:${author}`,
597
+ kind: "evidence",
598
+ reason: "equivocation",
599
+ detail: `two signed ops for ${author} at/after seq ${forkSeq}`,
600
+ author,
601
+ seq: forkSeq,
602
+ forkSeq,
603
+ evidence: [a, b],
604
+ at: this.now(),
605
+ };
606
+ await this.quarantine.put(entry);
607
+ this.emit("quarantined", entry);
608
+ this.emit("equivocation", { author, forkSeq });
609
+ await this.reevaluateAuthor(author);
610
+ }
611
+ return {
612
+ status: "equivocation",
613
+ reason: "equivocation",
614
+ detail: `fork at seq ${forkSeq}`,
615
+ };
616
+ }
617
+ async reevaluateAuthor(author) {
618
+ const head = await this.store.head(author);
619
+ if (!head)
620
+ return;
621
+ for (const s of await this.store.range(author, 1, head.op.seq))
622
+ await this.setVerdict(s, this.verdict(s), false);
623
+ }
624
+ /** Recompute every verdict (trust changed) and retry pending ops. Called automatically on trust changes. */
625
+ reevaluate() {
626
+ return this.serial(async () => {
627
+ await this.refreshAnchors();
628
+ for (const s of await this.store.all())
629
+ await this.setVerdict(s, this.verdict(s), false);
630
+ await this.drain();
631
+ this.flushChange();
632
+ });
633
+ }
634
+ /** Retry pending ops (e.g. on a timer so future-dated ops are picked up once the clock reaches them). */
635
+ retryPending() {
636
+ return this.serial(async () => {
637
+ await this.drain();
638
+ this.flushChange();
639
+ });
640
+ }
641
+ // ─── queries ─────────────────────────────────────────────────────────────
642
+ isAccepted(author, seq) {
643
+ return this.verdicts.get(vkey(author, seq))?.ok === true;
644
+ }
645
+ verdictOf(author, seq) {
646
+ return this.verdicts.get(vkey(author, seq));
647
+ }
648
+ /** Accepted ops (optionally of one module), in projection order (hlc, author, seq). */
649
+ async accepted(module) {
650
+ const all = await this.store.all();
651
+ return all
652
+ .filter((s) => (module === undefined || s.op.module === module) &&
653
+ this.isAccepted(s.op.author, s.op.seq))
654
+ .sort((a, b) => compareOps(a.op, b.op));
655
+ }
656
+ heads() {
657
+ return this.store.heads();
658
+ }
659
+ /** Head seq AND op id per author: pass it to `TrustStore.prepareRevocation` to anchor a revocation (S3). */
660
+ async headIds() {
661
+ const out = {};
662
+ for (const author of Object.keys(await this.store.heads())) {
663
+ const h = await this.store.head(author);
664
+ if (h)
665
+ out[author] = { seq: h.op.seq, id: h.id };
666
+ }
667
+ return out;
668
+ }
669
+ pending() {
670
+ return [...this.pendingOps.values()].map((p) => ({
671
+ author: p.op.author,
672
+ seq: p.op.seq,
673
+ reason: p.reason,
674
+ }));
675
+ }
676
+ equivocations() {
677
+ return [...this.equiv.entries()].map(([author, e]) => ({
678
+ author,
679
+ forkSeq: e.forkSeq,
680
+ }));
681
+ }
682
+ quarantined() {
683
+ return this.quarantine.list();
684
+ }
685
+ /** Local clock helper (e.g. to stamp UI checks). */
686
+ hlcNow() {
687
+ return this.clock.last();
688
+ }
689
+ get deviceFp() {
690
+ return this.signer?.fp;
691
+ }
692
+ }
693
+ //# sourceMappingURL=log.js.map