@enbox/dwn-sdk-js 0.4.0 → 0.4.2

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 (522) hide show
  1. package/README.md +4 -4
  2. package/dist/browser.mjs +3 -10
  3. package/dist/browser.mjs.map +4 -4
  4. package/dist/esm/generated/precompiled-validators.js +799 -885
  5. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  6. package/dist/esm/src/core/dwn-constant.js +5 -0
  7. package/dist/esm/src/core/dwn-constant.js.map +1 -1
  8. package/dist/esm/src/core/dwn-error.js +12 -4
  9. package/dist/esm/src/core/dwn-error.js.map +1 -1
  10. package/dist/esm/src/core/grant-authorization.js +9 -18
  11. package/dist/esm/src/core/grant-authorization.js.map +1 -1
  12. package/dist/esm/src/core/message-reply.js.map +1 -1
  13. package/dist/esm/src/core/messages-grant-authorization.js +28 -45
  14. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
  15. package/dist/esm/src/core/protocol-authorization-action.js +25 -27
  16. package/dist/esm/src/core/protocol-authorization-action.js.map +1 -1
  17. package/dist/esm/src/core/protocol-authorization-validation.js +34 -89
  18. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -1
  19. package/dist/esm/src/core/protocol-authorization.js +44 -118
  20. package/dist/esm/src/core/protocol-authorization.js.map +1 -1
  21. package/dist/esm/src/core/protocols-grant-authorization.js +5 -5
  22. package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
  23. package/dist/esm/src/core/recording-validation-state-reader.js +84 -0
  24. package/dist/esm/src/core/recording-validation-state-reader.js.map +1 -0
  25. package/dist/esm/src/core/records-grant-authorization.js +11 -11
  26. package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
  27. package/dist/esm/src/core/replication-apply.js +123 -28
  28. package/dist/esm/src/core/replication-apply.js.map +1 -1
  29. package/dist/esm/src/core/resumable-task-manager.js +5 -4
  30. package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
  31. package/dist/esm/src/core/validation-state-reader.js +237 -0
  32. package/dist/esm/src/core/validation-state-reader.js.map +1 -0
  33. package/dist/esm/src/dwn.js +165 -132
  34. package/dist/esm/src/dwn.js.map +1 -1
  35. package/dist/esm/src/enums/dwn-interface-method.js +0 -1
  36. package/dist/esm/src/enums/dwn-interface-method.js.map +1 -1
  37. package/dist/esm/src/event-stream/durable-event-log.js +365 -0
  38. package/dist/esm/src/event-stream/durable-event-log.js.map +1 -0
  39. package/dist/esm/src/event-stream/event-emitter-wake-publisher.js +25 -0
  40. package/dist/esm/src/event-stream/event-emitter-wake-publisher.js.map +1 -0
  41. package/dist/esm/src/handlers/messages-query.js +159 -0
  42. package/dist/esm/src/handlers/messages-query.js.map +1 -0
  43. package/dist/esm/src/handlers/messages-read.js +5 -5
  44. package/dist/esm/src/handlers/messages-read.js.map +1 -1
  45. package/dist/esm/src/handlers/messages-subscribe.js +8 -8
  46. package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
  47. package/dist/esm/src/handlers/protocols-configure.js +30 -49
  48. package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
  49. package/dist/esm/src/handlers/protocols-query.js +1 -1
  50. package/dist/esm/src/handlers/protocols-query.js.map +1 -1
  51. package/dist/esm/src/handlers/records-count.js +20 -11
  52. package/dist/esm/src/handlers/records-count.js.map +1 -1
  53. package/dist/esm/src/handlers/records-delete.js +20 -16
  54. package/dist/esm/src/handlers/records-delete.js.map +1 -1
  55. package/dist/esm/src/handlers/records-query.js +35 -11
  56. package/dist/esm/src/handlers/records-query.js.map +1 -1
  57. package/dist/esm/src/handlers/records-read.js +52 -42
  58. package/dist/esm/src/handlers/records-read.js.map +1 -1
  59. package/dist/esm/src/handlers/records-subscribe.js +107 -11
  60. package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
  61. package/dist/esm/src/handlers/records-write.js +62 -116
  62. package/dist/esm/src/handlers/records-write.js.map +1 -1
  63. package/dist/esm/src/index.js +6 -7
  64. package/dist/esm/src/index.js.map +1 -1
  65. package/dist/esm/src/interfaces/{messages-sync.js → messages-query.js} +21 -15
  66. package/dist/esm/src/interfaces/messages-query.js.map +1 -0
  67. package/dist/esm/src/interfaces/protocols-configure.js +12 -9
  68. package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
  69. package/dist/esm/src/interfaces/protocols-query.js +3 -4
  70. package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
  71. package/dist/esm/src/interfaces/records-count.js +4 -3
  72. package/dist/esm/src/interfaces/records-count.js.map +1 -1
  73. package/dist/esm/src/interfaces/records-delete.js +21 -4
  74. package/dist/esm/src/interfaces/records-delete.js.map +1 -1
  75. package/dist/esm/src/interfaces/records-query.js +4 -3
  76. package/dist/esm/src/interfaces/records-query.js.map +1 -1
  77. package/dist/esm/src/interfaces/records-read.js +3 -3
  78. package/dist/esm/src/interfaces/records-read.js.map +1 -1
  79. package/dist/esm/src/interfaces/records-subscribe.js +4 -3
  80. package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
  81. package/dist/esm/src/interfaces/records-write.js +27 -13
  82. package/dist/esm/src/interfaces/records-write.js.map +1 -1
  83. package/dist/esm/src/protocols/permissions.js +27 -34
  84. package/dist/esm/src/protocols/permissions.js.map +1 -1
  85. package/dist/esm/src/store/index-level.js +24 -9
  86. package/dist/esm/src/store/index-level.js.map +1 -1
  87. package/dist/esm/src/store/level-wrapper.js +7 -0
  88. package/dist/esm/src/store/level-wrapper.js.map +1 -1
  89. package/dist/esm/src/store/message-store-level.js +536 -42
  90. package/dist/esm/src/store/message-store-level.js.map +1 -1
  91. package/dist/esm/src/store/storage-controller.js +58 -49
  92. package/dist/esm/src/store/storage-controller.js.map +1 -1
  93. package/dist/esm/src/types/message-types.js.map +1 -1
  94. package/dist/esm/src/types/validation-state-reader.js +2 -0
  95. package/dist/esm/src/types/validation-state-reader.js.map +1 -0
  96. package/dist/esm/src/utils/messages.js +17 -0
  97. package/dist/esm/src/utils/messages.js.map +1 -1
  98. package/dist/esm/src/utils/protocol-tags.js +262 -0
  99. package/dist/esm/src/utils/protocol-tags.js.map +1 -0
  100. package/dist/esm/src/utils/record-limit-occupancy.js +244 -0
  101. package/dist/esm/src/utils/record-limit-occupancy.js.map +1 -0
  102. package/dist/esm/src/utils/records.js +50 -14
  103. package/dist/esm/src/utils/records.js.map +1 -1
  104. package/dist/esm/src/utils/replication.js +85 -0
  105. package/dist/esm/src/utils/replication.js.map +1 -0
  106. package/dist/esm/tests/core/grant-authorization.spec.js +4 -4
  107. package/dist/esm/tests/core/grant-authorization.spec.js.map +1 -1
  108. package/dist/esm/tests/core/process-message-parity.spec.js +222 -0
  109. package/dist/esm/tests/core/process-message-parity.spec.js.map +1 -0
  110. package/dist/esm/tests/core/protocol-authorization.spec.js +5 -2
  111. package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
  112. package/dist/esm/tests/core/records-grant-authorization.spec.js +5 -5
  113. package/dist/esm/tests/core/records-grant-authorization.spec.js.map +1 -1
  114. package/dist/esm/tests/core/replication-apply.spec.js +55 -1
  115. package/dist/esm/tests/core/replication-apply.spec.js.map +1 -1
  116. package/dist/esm/tests/core/replication-replay-property.spec.js +350 -0
  117. package/dist/esm/tests/core/replication-replay-property.spec.js.map +1 -0
  118. package/dist/esm/tests/core/validation-read-closure.spec.js +469 -0
  119. package/dist/esm/tests/core/validation-read-closure.spec.js.map +1 -0
  120. package/dist/esm/tests/core/validation-state-reader.spec.js +716 -0
  121. package/dist/esm/tests/core/validation-state-reader.spec.js.map +1 -0
  122. package/dist/esm/tests/durable-event-log.spec.js +373 -0
  123. package/dist/esm/tests/durable-event-log.spec.js.map +1 -0
  124. package/dist/esm/tests/dwn.spec.js +504 -35
  125. package/dist/esm/tests/dwn.spec.js.map +1 -1
  126. package/dist/esm/tests/features/author-delegated-grant.spec.js +9 -6
  127. package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
  128. package/dist/esm/tests/features/owner-delegated-grant.spec.js +1 -4
  129. package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
  130. package/dist/esm/tests/features/owner-signature.spec.js +1 -4
  131. package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
  132. package/dist/esm/tests/features/permissions.spec.js +165 -4
  133. package/dist/esm/tests/features/permissions.spec.js.map +1 -1
  134. package/dist/esm/tests/features/protocol-composition.spec.js +8 -11
  135. package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
  136. package/dist/esm/tests/features/protocol-create-action.spec.js +1 -4
  137. package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
  138. package/dist/esm/tests/features/protocol-delete-action.spec.js +3 -5
  139. package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
  140. package/dist/esm/tests/features/protocol-update-action.spec.js +3 -6
  141. package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
  142. package/dist/esm/tests/features/records-delivery.spec.js +1 -4
  143. package/dist/esm/tests/features/records-delivery.spec.js.map +1 -1
  144. package/dist/esm/tests/features/records-immutable.spec.js +1 -4
  145. package/dist/esm/tests/features/records-immutable.spec.js.map +1 -1
  146. package/dist/esm/tests/features/records-nested-query-scope.spec.js +281 -0
  147. package/dist/esm/tests/features/records-nested-query-scope.spec.js.map +1 -0
  148. package/dist/esm/tests/features/records-prune-cross-protocol.spec.js +3 -7
  149. package/dist/esm/tests/features/records-prune-cross-protocol.spec.js.map +1 -1
  150. package/dist/esm/tests/features/records-prune.spec.js +11 -22
  151. package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
  152. package/dist/esm/tests/features/records-record-limit.spec.js +441 -231
  153. package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -1
  154. package/dist/esm/tests/features/records-squash.spec.js +6 -4
  155. package/dist/esm/tests/features/records-squash.spec.js.map +1 -1
  156. package/dist/esm/tests/features/records-tags.spec.js +1 -4
  157. package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
  158. package/dist/esm/tests/features/resumable-tasks.spec.js +3 -5
  159. package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
  160. package/dist/esm/tests/fuzz/message-store.fuzz.spec.js +1 -2
  161. package/dist/esm/tests/fuzz/message-store.fuzz.spec.js.map +1 -1
  162. package/dist/esm/tests/fuzz/process-message.fuzz.spec.js +2 -4
  163. package/dist/esm/tests/fuzz/process-message.fuzz.spec.js.map +1 -1
  164. package/dist/esm/tests/fuzz/schema-validation.fuzz.spec.js +1 -1
  165. package/dist/esm/tests/fuzz/schema-validation.fuzz.spec.js.map +1 -1
  166. package/dist/esm/tests/handlers/messages-query.spec.js +246 -0
  167. package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -0
  168. package/dist/esm/tests/handlers/messages-read.spec.js +2 -5
  169. package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
  170. package/dist/esm/tests/handlers/messages-subscribe.spec.js +3 -14
  171. package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
  172. package/dist/esm/tests/handlers/protocols-configure.spec.js +27 -26
  173. package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
  174. package/dist/esm/tests/handlers/protocols-query.spec.js +1 -4
  175. package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
  176. package/dist/esm/tests/handlers/records-count.spec.js +1 -4
  177. package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
  178. package/dist/esm/tests/handlers/records-delete.spec.js +312 -30
  179. package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
  180. package/dist/esm/tests/handlers/records-query.spec.js +32 -9
  181. package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
  182. package/dist/esm/tests/handlers/records-read.spec.js +4 -4
  183. package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
  184. package/dist/esm/tests/handlers/records-subscribe.spec.js +33 -14
  185. package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
  186. package/dist/esm/tests/handlers/records-write.spec.js +82 -36
  187. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  188. package/dist/esm/tests/interfaces/records-delete.spec.js +69 -2
  189. package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
  190. package/dist/esm/tests/interfaces/records-write.spec.js +4 -3
  191. package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
  192. package/dist/esm/tests/protocols/permissions.spec.js +55 -6
  193. package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
  194. package/dist/esm/tests/scenarios/aggregator.spec.js +1 -4
  195. package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
  196. package/dist/esm/tests/scenarios/deleted-record.spec.js +1 -4
  197. package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
  198. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +1 -4
  199. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
  200. package/dist/esm/tests/scenarios/nested-roles.spec.js +1 -4
  201. package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
  202. package/dist/esm/tests/scenarios/subscriptions.spec.js +1 -4
  203. package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
  204. package/dist/esm/tests/store/message-store-level.spec.js +361 -5
  205. package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
  206. package/dist/esm/tests/store/message-store.spec.js +60 -0
  207. package/dist/esm/tests/store/message-store.spec.js.map +1 -1
  208. package/dist/esm/tests/test-event-stream.js +7 -3
  209. package/dist/esm/tests/test-event-stream.js.map +1 -1
  210. package/dist/esm/tests/test-stores.js +19 -9
  211. package/dist/esm/tests/test-stores.js.map +1 -1
  212. package/dist/esm/tests/test-suite.js +4 -2
  213. package/dist/esm/tests/test-suite.js.map +1 -1
  214. package/dist/esm/tests/utils/protocol-tags.spec.js +96 -0
  215. package/dist/esm/tests/utils/protocol-tags.spec.js.map +1 -0
  216. package/dist/esm/tests/utils/test-data-generator.js +25 -0
  217. package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
  218. package/dist/esm/tests/utils/test-stub-generator.js.map +1 -1
  219. package/dist/esm/tests/utils/test-validation-state-reader.js +16 -0
  220. package/dist/esm/tests/utils/test-validation-state-reader.js.map +1 -0
  221. package/dist/types/generated/precompiled-validators.d.ts +6 -6
  222. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  223. package/dist/types/src/core/core-protocol.d.ts +3 -3
  224. package/dist/types/src/core/core-protocol.d.ts.map +1 -1
  225. package/dist/types/src/core/dwn-constant.d.ts +5 -0
  226. package/dist/types/src/core/dwn-constant.d.ts.map +1 -1
  227. package/dist/types/src/core/dwn-error.d.ts +12 -4
  228. package/dist/types/src/core/dwn-error.d.ts.map +1 -1
  229. package/dist/types/src/core/grant-authorization.d.ts +5 -5
  230. package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
  231. package/dist/types/src/core/message-reply.d.ts +5 -4
  232. package/dist/types/src/core/message-reply.d.ts.map +1 -1
  233. package/dist/types/src/core/messages-grant-authorization.d.ts +12 -14
  234. package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -1
  235. package/dist/types/src/core/protocol-authorization-action.d.ts +4 -5
  236. package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -1
  237. package/dist/types/src/core/protocol-authorization-validation.d.ts +14 -17
  238. package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -1
  239. package/dist/types/src/core/protocol-authorization.d.ts +8 -33
  240. package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
  241. package/dist/types/src/core/protocols-grant-authorization.d.ts +4 -4
  242. package/dist/types/src/core/protocols-grant-authorization.d.ts.map +1 -1
  243. package/dist/types/src/core/recording-validation-state-reader.d.ts +75 -0
  244. package/dist/types/src/core/recording-validation-state-reader.d.ts.map +1 -0
  245. package/dist/types/src/core/records-grant-authorization.d.ts +8 -8
  246. package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
  247. package/dist/types/src/core/replication-apply.d.ts +36 -0
  248. package/dist/types/src/core/replication-apply.d.ts.map +1 -1
  249. package/dist/types/src/core/resumable-task-manager.d.ts +1 -1
  250. package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -1
  251. package/dist/types/src/core/validation-state-reader.d.ts +79 -0
  252. package/dist/types/src/core/validation-state-reader.d.ts.map +1 -0
  253. package/dist/types/src/dwn.d.ts +33 -20
  254. package/dist/types/src/dwn.d.ts.map +1 -1
  255. package/dist/types/src/enums/dwn-interface-method.d.ts +0 -1
  256. package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -1
  257. package/dist/types/src/event-stream/durable-event-log.d.ts +69 -0
  258. package/dist/types/src/event-stream/durable-event-log.d.ts.map +1 -0
  259. package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts +13 -0
  260. package/dist/types/src/event-stream/event-emitter-wake-publisher.d.ts.map +1 -0
  261. package/dist/types/src/handlers/messages-query.d.ts +20 -0
  262. package/dist/types/src/handlers/messages-query.d.ts.map +1 -0
  263. package/dist/types/src/handlers/messages-read.d.ts +1 -1
  264. package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
  265. package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
  266. package/dist/types/src/handlers/protocols-configure.d.ts +0 -5
  267. package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
  268. package/dist/types/src/handlers/records-count.d.ts +2 -1
  269. package/dist/types/src/handlers/records-count.d.ts.map +1 -1
  270. package/dist/types/src/handlers/records-delete.d.ts +2 -2
  271. package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
  272. package/dist/types/src/handlers/records-query.d.ts +1 -1
  273. package/dist/types/src/handlers/records-query.d.ts.map +1 -1
  274. package/dist/types/src/handlers/records-read.d.ts +2 -1
  275. package/dist/types/src/handlers/records-read.d.ts.map +1 -1
  276. package/dist/types/src/handlers/records-subscribe.d.ts +4 -5
  277. package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
  278. package/dist/types/src/handlers/records-write.d.ts +3 -11
  279. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  280. package/dist/types/src/index.d.ts +14 -16
  281. package/dist/types/src/index.d.ts.map +1 -1
  282. package/dist/types/src/interfaces/messages-query.d.ts +23 -0
  283. package/dist/types/src/interfaces/messages-query.d.ts.map +1 -0
  284. package/dist/types/src/interfaces/protocols-configure.d.ts +3 -3
  285. package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
  286. package/dist/types/src/interfaces/protocols-query.d.ts +2 -2
  287. package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -1
  288. package/dist/types/src/interfaces/records-count.d.ts +3 -3
  289. package/dist/types/src/interfaces/records-count.d.ts.map +1 -1
  290. package/dist/types/src/interfaces/records-delete.d.ts +11 -3
  291. package/dist/types/src/interfaces/records-delete.d.ts.map +1 -1
  292. package/dist/types/src/interfaces/records-query.d.ts +3 -3
  293. package/dist/types/src/interfaces/records-query.d.ts.map +1 -1
  294. package/dist/types/src/interfaces/records-read.d.ts +3 -3
  295. package/dist/types/src/interfaces/records-read.d.ts.map +1 -1
  296. package/dist/types/src/interfaces/records-subscribe.d.ts +3 -3
  297. package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
  298. package/dist/types/src/interfaces/records-write.d.ts +15 -7
  299. package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
  300. package/dist/types/src/protocols/permissions.d.ts +9 -12
  301. package/dist/types/src/protocols/permissions.d.ts.map +1 -1
  302. package/dist/types/src/store/index-level.d.ts +10 -1
  303. package/dist/types/src/store/index-level.d.ts.map +1 -1
  304. package/dist/types/src/store/level-wrapper.d.ts +5 -0
  305. package/dist/types/src/store/level-wrapper.d.ts.map +1 -1
  306. package/dist/types/src/store/message-store-level.d.ts +94 -14
  307. package/dist/types/src/store/message-store-level.d.ts.map +1 -1
  308. package/dist/types/src/store/storage-controller.d.ts +17 -14
  309. package/dist/types/src/store/storage-controller.d.ts.map +1 -1
  310. package/dist/types/src/types/message-store.d.ts +29 -1
  311. package/dist/types/src/types/message-store.d.ts.map +1 -1
  312. package/dist/types/src/types/message-types.d.ts +2 -0
  313. package/dist/types/src/types/message-types.d.ts.map +1 -1
  314. package/dist/types/src/types/messages-types.d.ts +21 -37
  315. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  316. package/dist/types/src/types/method-handler.d.ts +2 -2
  317. package/dist/types/src/types/method-handler.d.ts.map +1 -1
  318. package/dist/types/src/types/permission-types.d.ts +1 -1
  319. package/dist/types/src/types/subscriptions.d.ts +50 -39
  320. package/dist/types/src/types/subscriptions.d.ts.map +1 -1
  321. package/dist/types/src/types/validation-state-reader.d.ts +116 -0
  322. package/dist/types/src/types/validation-state-reader.d.ts.map +1 -0
  323. package/dist/types/src/utils/messages.d.ts +10 -0
  324. package/dist/types/src/utils/messages.d.ts.map +1 -1
  325. package/dist/types/src/utils/protocol-tags.d.ts +15 -0
  326. package/dist/types/src/utils/protocol-tags.d.ts.map +1 -0
  327. package/dist/types/src/utils/record-limit-occupancy.d.ts +40 -0
  328. package/dist/types/src/utils/record-limit-occupancy.d.ts.map +1 -0
  329. package/dist/types/src/utils/records.d.ts +25 -3
  330. package/dist/types/src/utils/records.d.ts.map +1 -1
  331. package/dist/types/src/utils/replication.d.ts +22 -0
  332. package/dist/types/src/utils/replication.d.ts.map +1 -0
  333. package/dist/types/tests/core/process-message-parity.spec.d.ts +2 -0
  334. package/dist/types/tests/core/process-message-parity.spec.d.ts.map +1 -0
  335. package/dist/types/tests/core/replication-replay-property.spec.d.ts +2 -0
  336. package/dist/types/tests/core/replication-replay-property.spec.d.ts.map +1 -0
  337. package/dist/types/tests/core/validation-read-closure.spec.d.ts +2 -0
  338. package/dist/types/tests/core/validation-read-closure.spec.d.ts.map +1 -0
  339. package/dist/types/tests/core/validation-state-reader.spec.d.ts +2 -0
  340. package/dist/types/tests/core/validation-state-reader.spec.d.ts.map +1 -0
  341. package/dist/types/tests/durable-event-log.spec.d.ts +2 -0
  342. package/dist/types/tests/durable-event-log.spec.d.ts.map +1 -0
  343. package/dist/types/tests/dwn.spec.d.ts.map +1 -1
  344. package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
  345. package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
  346. package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
  347. package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
  348. package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
  349. package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -1
  350. package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -1
  351. package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -1
  352. package/dist/types/tests/features/records-delivery.spec.d.ts.map +1 -1
  353. package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -1
  354. package/dist/types/tests/features/records-nested-query-scope.spec.d.ts +2 -0
  355. package/dist/types/tests/features/records-nested-query-scope.spec.d.ts.map +1 -0
  356. package/dist/types/tests/features/records-prune-cross-protocol.spec.d.ts.map +1 -1
  357. package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -1
  358. package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -1
  359. package/dist/types/tests/features/records-squash.spec.d.ts.map +1 -1
  360. package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
  361. package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
  362. package/dist/types/tests/handlers/messages-query.spec.d.ts +2 -0
  363. package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -0
  364. package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
  365. package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
  366. package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -1
  367. package/dist/types/tests/handlers/protocols-query.spec.d.ts.map +1 -1
  368. package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
  369. package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
  370. package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
  371. package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
  372. package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
  373. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
  374. package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
  375. package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -1
  376. package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -1
  377. package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
  378. package/dist/types/tests/store/message-store.spec.d.ts.map +1 -1
  379. package/dist/types/tests/test-event-stream.d.ts +1 -1
  380. package/dist/types/tests/test-event-stream.d.ts.map +1 -1
  381. package/dist/types/tests/test-stores.d.ts +5 -4
  382. package/dist/types/tests/test-stores.d.ts.map +1 -1
  383. package/dist/types/tests/test-suite.d.ts +1 -2
  384. package/dist/types/tests/test-suite.d.ts.map +1 -1
  385. package/dist/types/tests/utils/protocol-tags.spec.d.ts +2 -0
  386. package/dist/types/tests/utils/protocol-tags.spec.d.ts.map +1 -0
  387. package/dist/types/tests/utils/test-data-generator.d.ts +20 -1
  388. package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
  389. package/dist/types/tests/utils/test-validation-state-reader.d.ts +15 -0
  390. package/dist/types/tests/utils/test-validation-state-reader.d.ts.map +1 -0
  391. package/package.json +2 -2
  392. package/src/core/core-protocol.ts +3 -3
  393. package/src/core/dwn-constant.ts +7 -1
  394. package/src/core/dwn-error.ts +12 -4
  395. package/src/core/grant-authorization.ts +11 -20
  396. package/src/core/message-reply.ts +6 -5
  397. package/src/core/messages-grant-authorization.ts +37 -70
  398. package/src/core/protocol-authorization-action.ts +29 -38
  399. package/src/core/protocol-authorization-validation.ts +47 -121
  400. package/src/core/protocol-authorization.ts +56 -202
  401. package/src/core/protocols-grant-authorization.ts +9 -9
  402. package/src/core/recording-validation-state-reader.ts +130 -0
  403. package/src/core/records-grant-authorization.ts +16 -16
  404. package/src/core/replication-apply.ts +172 -32
  405. package/src/core/resumable-task-manager.ts +10 -8
  406. package/src/core/validation-state-reader.ts +350 -0
  407. package/src/dwn.ts +285 -192
  408. package/src/enums/dwn-interface-method.ts +0 -1
  409. package/src/event-stream/durable-event-log.ts +509 -0
  410. package/src/event-stream/event-emitter-wake-publisher.ts +34 -0
  411. package/src/handlers/messages-query.ts +203 -0
  412. package/src/handlers/messages-read.ts +9 -10
  413. package/src/handlers/messages-subscribe.ts +12 -13
  414. package/src/handlers/protocols-configure.ts +37 -58
  415. package/src/handlers/protocols-query.ts +1 -1
  416. package/src/handlers/records-count.ts +24 -17
  417. package/src/handlers/records-delete.ts +29 -27
  418. package/src/handlers/records-query.ts +38 -17
  419. package/src/handlers/records-read.ts +63 -50
  420. package/src/handlers/records-subscribe.ts +132 -19
  421. package/src/handlers/records-write.ts +77 -168
  422. package/src/index.ts +14 -17
  423. package/src/interfaces/messages-query.ts +70 -0
  424. package/src/interfaces/protocols-configure.ts +20 -10
  425. package/src/interfaces/protocols-query.ts +4 -5
  426. package/src/interfaces/records-count.ts +9 -4
  427. package/src/interfaces/records-delete.ts +25 -5
  428. package/src/interfaces/records-query.ts +9 -4
  429. package/src/interfaces/records-read.ts +4 -4
  430. package/src/interfaces/records-subscribe.ts +9 -4
  431. package/src/interfaces/records-write.ts +41 -13
  432. package/src/protocols/permissions.ts +32 -52
  433. package/src/store/index-level.ts +30 -9
  434. package/src/store/level-wrapper.ts +9 -1
  435. package/src/store/message-store-level.ts +757 -47
  436. package/src/store/storage-controller.ts +74 -63
  437. package/src/types/message-store.ts +45 -2
  438. package/src/types/message-types.ts +3 -1
  439. package/src/types/messages-types.ts +26 -45
  440. package/src/types/method-handler.ts +3 -3
  441. package/src/types/permission-types.ts +1 -1
  442. package/src/types/subscriptions.ts +53 -42
  443. package/src/types/validation-state-reader.ts +127 -0
  444. package/src/utils/messages.ts +25 -1
  445. package/src/utils/protocol-tags.ts +366 -0
  446. package/src/utils/record-limit-occupancy.ts +377 -0
  447. package/src/utils/records.ts +69 -13
  448. package/src/utils/replication.ts +122 -0
  449. package/dist/esm/src/core/record-chain.js +0 -64
  450. package/dist/esm/src/core/record-chain.js.map +0 -1
  451. package/dist/esm/src/event-stream/event-emitter-event-log.js +0 -334
  452. package/dist/esm/src/event-stream/event-emitter-event-log.js.map +0 -1
  453. package/dist/esm/src/handlers/messages-sync.js +0 -278
  454. package/dist/esm/src/handlers/messages-sync.js.map +0 -1
  455. package/dist/esm/src/interfaces/messages-sync.js.map +0 -1
  456. package/dist/esm/src/smt/smt-store-level.js +0 -103
  457. package/dist/esm/src/smt/smt-store-level.js.map +0 -1
  458. package/dist/esm/src/smt/smt-store-memory.js +0 -41
  459. package/dist/esm/src/smt/smt-store-memory.js.map +0 -1
  460. package/dist/esm/src/smt/smt-utils.js +0 -129
  461. package/dist/esm/src/smt/smt-utils.js.map +0 -1
  462. package/dist/esm/src/smt/sparse-merkle-tree.js +0 -577
  463. package/dist/esm/src/smt/sparse-merkle-tree.js.map +0 -1
  464. package/dist/esm/src/state-index/state-index-level.js +0 -191
  465. package/dist/esm/src/state-index/state-index-level.js.map +0 -1
  466. package/dist/esm/src/types/smt-types.js +0 -5
  467. package/dist/esm/src/types/smt-types.js.map +0 -1
  468. package/dist/esm/src/types/state-index.js +0 -2
  469. package/dist/esm/src/types/state-index.js.map +0 -1
  470. package/dist/esm/tests/event-emitter-event-log.spec.js +0 -499
  471. package/dist/esm/tests/event-emitter-event-log.spec.js.map +0 -1
  472. package/dist/esm/tests/handlers/messages-sync.spec.js +0 -1088
  473. package/dist/esm/tests/handlers/messages-sync.spec.js.map +0 -1
  474. package/dist/esm/tests/smt/smt-store-level.spec.js +0 -132
  475. package/dist/esm/tests/smt/smt-store-level.spec.js.map +0 -1
  476. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +0 -732
  477. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +0 -1
  478. package/dist/esm/tests/state-index/state-index-level.spec.js +0 -245
  479. package/dist/esm/tests/state-index/state-index-level.spec.js.map +0 -1
  480. package/dist/types/src/core/record-chain.d.ts +0 -24
  481. package/dist/types/src/core/record-chain.d.ts.map +0 -1
  482. package/dist/types/src/event-stream/event-emitter-event-log.d.ts +0 -80
  483. package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +0 -1
  484. package/dist/types/src/handlers/messages-sync.d.ts +0 -39
  485. package/dist/types/src/handlers/messages-sync.d.ts.map +0 -1
  486. package/dist/types/src/interfaces/messages-sync.d.ts +0 -20
  487. package/dist/types/src/interfaces/messages-sync.d.ts.map +0 -1
  488. package/dist/types/src/smt/smt-store-level.d.ts +0 -32
  489. package/dist/types/src/smt/smt-store-level.d.ts.map +0 -1
  490. package/dist/types/src/smt/smt-store-memory.d.ts +0 -22
  491. package/dist/types/src/smt/smt-store-memory.d.ts.map +0 -1
  492. package/dist/types/src/smt/smt-utils.d.ts +0 -58
  493. package/dist/types/src/smt/smt-utils.d.ts.map +0 -1
  494. package/dist/types/src/smt/sparse-merkle-tree.d.ts +0 -124
  495. package/dist/types/src/smt/sparse-merkle-tree.d.ts.map +0 -1
  496. package/dist/types/src/state-index/state-index-level.d.ts +0 -83
  497. package/dist/types/src/state-index/state-index-level.d.ts.map +0 -1
  498. package/dist/types/src/types/smt-types.d.ts +0 -81
  499. package/dist/types/src/types/smt-types.d.ts.map +0 -1
  500. package/dist/types/src/types/state-index.d.ts +0 -90
  501. package/dist/types/src/types/state-index.d.ts.map +0 -1
  502. package/dist/types/tests/event-emitter-event-log.spec.d.ts +0 -2
  503. package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +0 -1
  504. package/dist/types/tests/handlers/messages-sync.spec.d.ts +0 -2
  505. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +0 -1
  506. package/dist/types/tests/smt/smt-store-level.spec.d.ts +0 -2
  507. package/dist/types/tests/smt/smt-store-level.spec.d.ts.map +0 -1
  508. package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts +0 -2
  509. package/dist/types/tests/smt/sparse-merkle-tree.spec.d.ts.map +0 -1
  510. package/dist/types/tests/state-index/state-index-level.spec.d.ts +0 -2
  511. package/dist/types/tests/state-index/state-index-level.spec.d.ts.map +0 -1
  512. package/src/core/record-chain.ts +0 -99
  513. package/src/event-stream/event-emitter-event-log.ts +0 -430
  514. package/src/handlers/messages-sync.ts +0 -403
  515. package/src/interfaces/messages-sync.ts +0 -69
  516. package/src/smt/smt-store-level.ts +0 -143
  517. package/src/smt/smt-store-memory.ts +0 -53
  518. package/src/smt/smt-utils.ts +0 -149
  519. package/src/smt/sparse-merkle-tree.ts +0 -698
  520. package/src/state-index/state-index-level.ts +0 -239
  521. package/src/types/smt-types.ts +0 -95
  522. package/src/types/state-index.ts +0 -100
@@ -1,58 +0,0 @@
1
- /**
2
- * Utility functions for the Sparse Merkle Tree.
3
- * Uses SHA-256 from multiformats (already a dependency of dwn-sdk-js).
4
- */
5
- import type { Hash } from '../types/smt-types.js';
6
- /** The tree depth — one level per bit of a SHA-256 hash. */
7
- export declare const SMT_DEPTH = 256;
8
- /** A constant zero hash (32 bytes of 0x00). */
9
- export declare const ZERO_HASH: Hash;
10
- export declare function getDefaultHashes(): Hash[];
11
- /**
12
- * Reset the cached default hashes. Only used by tests to verify the
13
- * uninitialized code path in `getDefaultHashes()`.
14
- * @internal
15
- */
16
- export declare function resetDefaultHashesForTesting(): void;
17
- /**
18
- * Initialize the default hashes array. Must be called once before using the SMT.
19
- * This is async because sha256.digest is async.
20
- */
21
- export declare function initDefaultHashes(): Promise<Hash[]>;
22
- /**
23
- * Hash two child hashes together: H(left || right).
24
- * Uses SHA-256 via multiformats.
25
- */
26
- export declare function hashChildren(left: Hash, right: Hash): Promise<Hash>;
27
- /**
28
- * Hash a leaf node: H(0x00 || keyHash || valueCid_bytes).
29
- * The 0x00 prefix distinguishes leaf hashes from internal node hashes,
30
- * preventing second-preimage attacks.
31
- */
32
- export declare function hashLeaf(keyHash: Hash, valueCid: string): Promise<Hash>;
33
- /**
34
- * Compute SHA-256 of a string (used to hash messageCid into the 256-bit key space).
35
- */
36
- export declare function hashKey(key: string): Promise<Hash>;
37
- /**
38
- * Extract the bit at a given depth from a 256-bit hash.
39
- * Depth 0 is the most significant bit of the first byte.
40
- *
41
- * @param hash - The 32-byte hash.
42
- * @param depth - The bit position (0 = MSB of byte 0, 255 = LSB of byte 31).
43
- * @returns `true` for 1 (right), `false` for 0 (left).
44
- */
45
- export declare function getBit(hash: Hash, depth: number): boolean;
46
- /**
47
- * Compare two hashes for equality.
48
- */
49
- export declare function hashEquals(a: Hash, b: Hash): boolean;
50
- /**
51
- * Convert a hash to a hex string for use as a store key.
52
- */
53
- export declare function hashToHex(hash: Hash): string;
54
- /**
55
- * Convert a hex string back to a Hash.
56
- */
57
- export declare function hexToHash(hex: string): Hash;
58
- //# sourceMappingURL=smt-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"smt-utils.d.ts","sourceRoot":"","sources":["../../../../src/smt/smt-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAIlD,4DAA4D;AAC5D,eAAO,MAAM,SAAS,MAAM,CAAC;AAE7B,+CAA+C;AAC/C,eAAO,MAAM,SAAS,EAAE,IAAyB,CAAC;AAalD,wBAAgB,gBAAgB,IAAI,IAAI,EAAE,CAQzC;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAczD;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAOzE;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7E;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIxD;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CAUpD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM3C"}
@@ -1,124 +0,0 @@
1
- /**
2
- * Sparse Merkle Tree (SMT) implementation.
3
- *
4
- * A 256-level binary trie where:
5
- * - Keys are SHA-256 hashes of messageCids (uniformly distributed across 2^256 key space)
6
- * - Leaves store the messageCid value
7
- * - Internal nodes store H(leftChild || rightChild)
8
- * - Empty subtrees are represented implicitly via precomputed default hashes
9
- *
10
- * Key properties:
11
- * - Deterministic: the same set of key-value pairs always produces the same root hash
12
- * - O(log n) insert, delete, and proof operations (practically O(256) worst case)
13
- * - Supports inclusion and non-inclusion proofs
14
- * - Root hash provides a fingerprint of the entire set for O(1) comparison
15
- */
16
- import type { Hash, SMTDiffResult, SMTNodeStore, SMTProof } from '../types/smt-types.js';
17
- export declare class SparseMerkleTree {
18
- private readonly store;
19
- private defaultHashes;
20
- constructor(store: SMTNodeStore);
21
- /**
22
- * Initialize the SMT. Must be called before any operations.
23
- * Opens the store and precomputes default hashes.
24
- */
25
- initialize(): Promise<void>;
26
- /**
27
- * Close the underlying store.
28
- */
29
- close(): Promise<void>;
30
- /**
31
- * Clear all data from the tree.
32
- */
33
- clear(): Promise<void>;
34
- /**
35
- * Get the current root hash. Returns the default empty root if no root is set.
36
- */
37
- getRoot(): Promise<Hash>;
38
- /**
39
- * Insert a messageCid into the tree.
40
- * The key is SHA-256(messageCid), the value is the messageCid string.
41
- *
42
- * @returns the new root hash after insertion
43
- */
44
- insert(messageCid: string): Promise<Hash>;
45
- /**
46
- * Delete a messageCid from the tree.
47
- *
48
- * @returns the new root hash after deletion
49
- */
50
- delete(messageCid: string): Promise<Hash>;
51
- /**
52
- * Check if a messageCid exists in the tree.
53
- */
54
- has(messageCid: string): Promise<boolean>;
55
- /**
56
- * Generate a membership proof (inclusion or non-inclusion) for a messageCid.
57
- */
58
- getProof(messageCid: string): Promise<SMTProof>;
59
- /**
60
- * Get the hash of a subtree at a given bit prefix.
61
- * Used by the sync protocol for tree walking.
62
- *
63
- * @param prefix - array of booleans representing the path (false=left, true=right)
64
- * @returns the hash of the subtree at that prefix
65
- */
66
- getSubtreeHash(prefix: boolean[]): Promise<Hash>;
67
- /**
68
- * Get all leaf messageCids under a given prefix.
69
- * Used by the sync protocol for tree walking.
70
- */
71
- getLeaves(prefix: boolean[]): Promise<string[]>;
72
- /**
73
- * Compute a local diff between this tree and another tree's state,
74
- * given access to the other tree instance.
75
- *
76
- * This is used for same-process diffing (e.g., in tests or local operations).
77
- * For remote diffing, the sync protocol exchanges subtree hashes via messages.
78
- */
79
- diff(other: SparseMerkleTree): Promise<SMTDiffResult>;
80
- /**
81
- * Recursively insert a leaf into the tree, returning the new hash for the subtree at `depth`.
82
- */
83
- private insertAtNode;
84
- /**
85
- * When two leaves collide at the same position in the tree, push them down
86
- * until their key paths diverge, creating internal nodes along the way.
87
- *
88
- * For example, if two leaves share the first 3 bits but diverge at bit 3,
89
- * and we're currently at depth 0, we need to create internal nodes at depths
90
- * 0, 1, and 2 (where one child is the chain and the other is a default hash),
91
- * plus the divergence node at depth 3 where the two leaves split.
92
- */
93
- private splitLeaves;
94
- /**
95
- * Recursively delete a key from the tree, returning the new hash for the subtree at `depth`.
96
- */
97
- private deleteAtNode;
98
- /**
99
- * Check if a key exists at the given node.
100
- */
101
- private existsAtNode;
102
- /**
103
- * Generate a proof for the given key at the given node.
104
- */
105
- private generateProof;
106
- /**
107
- * Compute the subtree hash for a leaf that exists above the target prefix depth.
108
- * The leaf's effective position is determined by its keyHash bits.
109
- */
110
- private computeSubtreeHashForLeaf;
111
- /**
112
- * Check if a leaf's keyHash matches a given prefix.
113
- */
114
- private leafMatchesPrefix;
115
- /**
116
- * Collect all leaf messageCids in the subtree rooted at the given hash.
117
- */
118
- private collectLeaves;
119
- /**
120
- * Recursively diff two subtrees, collecting leaves that exist only in one or the other.
121
- */
122
- private diffAtNode;
123
- }
124
- //# sourceMappingURL=sparse-merkle-tree.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sparse-merkle-tree.d.ts","sourceRoot":"","sources":["../../../../src/smt/sparse-merkle-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAgC,YAAY,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAIvH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,aAAa,CAAU;gBAEnB,KAAK,EAAE,YAAY;IAI/B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B;;;;;OAKG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB/C;;;;OAIG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU/C;;OAEG;IACG,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM/C;;OAEG;IACG,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMrD;;;;;;OAMG;IACG,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCtD;;;OAGG;IACG,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAmCrD;;;;;;OAMG;IACG,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAkB3D;;OAEG;YACW,YAAY;IAyE1B;;;;;;;;OAQG;YACW,WAAW;IAoEzB;;OAEG;YACW,YAAY;IA6E1B;;OAEG;YACW,YAAY;IA4B1B;;OAEG;YACW,aAAa;IAsC3B;;;OAGG;YACW,yBAAyB;IAiBvC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IASzB;;OAEG;YACW,aAAa;IAqB3B;;OAEG;YACW,UAAU;CA2GzB"}
@@ -1,83 +0,0 @@
1
- /**
2
- * LevelDB-backed implementation of the StateIndex interface.
3
- *
4
- * Manages per-tenant Sparse Merkle Trees (global + per-protocol sub-trees).
5
- *
6
- * All data lives within a single LevelDB instance, partitioned by sublevels:
7
- * {tenant}/global/ -> SMT nodes + root for the tenant's global tree
8
- * {tenant}/proto/{proto}/ -> SMT nodes + root for a protocol-scoped tree
9
- * {tenant}/meta/{cid} -> JSON(indexes) for reverse lookup during deletion
10
- */
11
- import type { Hash } from '../types/smt-types.js';
12
- import type { KeyValues } from '../types/query-types.js';
13
- import type { StateIndex } from '../types/state-index.js';
14
- import { createLevelDatabase } from '../store/level-wrapper.js';
15
- export type StateIndexLevelConfig = {
16
- /**
17
- * Must be a directory path (relative or absolute) where LevelDB will store its files,
18
- * or in browsers, the name of the IDBDatabase to be opened.
19
- */
20
- location?: string;
21
- createLevelDatabase?: typeof createLevelDatabase;
22
- };
23
- export declare class StateIndexLevel implements StateIndex {
24
- private readonly config;
25
- private db;
26
- /**
27
- * Cache of per-tenant global SMTs. Lazily populated on first access.
28
- * Stores promises to avoid race conditions when multiple concurrent operations
29
- * trigger lazy initialization of the same tenant's SMT.
30
- */
31
- private readonly globalTrees;
32
- /**
33
- * Cache of per-tenant, per-protocol SMTs. Key format: `{tenant}\x00{protocol}`
34
- * Stores promises to avoid race conditions (same reason as globalTrees).
35
- */
36
- private readonly protocolTrees;
37
- constructor(config?: StateIndexLevelConfig);
38
- open(): Promise<void>;
39
- close(): Promise<void>;
40
- clear(): Promise<void>;
41
- insert(tenant: string, messageCid: string, indexes: KeyValues): Promise<void>;
42
- delete(tenant: string, messageCids: string[]): Promise<void>;
43
- getRoot(tenant: string): Promise<Hash>;
44
- getProtocolRoot(tenant: string, protocol: string): Promise<Hash>;
45
- getSubtreeHash(tenant: string, prefix: boolean[]): Promise<Hash>;
46
- getProtocolSubtreeHash(tenant: string, protocol: string, prefix: boolean[]): Promise<Hash>;
47
- getLeaves(tenant: string, prefix: boolean[]): Promise<string[]>;
48
- getProtocolLeaves(tenant: string, protocol: string, prefix: boolean[]): Promise<string[]>;
49
- /**
50
- * Get or create the global SMT for a tenant.
51
- * Uses a promise-based cache to prevent concurrent callers from racing to
52
- * initialize the same tenant's SMT twice.
53
- */
54
- private getGlobalTree;
55
- /**
56
- * Get or create a protocol-scoped SMT for a tenant.
57
- * Uses a promise-based cache to prevent concurrent callers from racing to
58
- * initialize the same tenant's SMT twice.
59
- */
60
- private getProtocolTree;
61
- /**
62
- * Create and initialize a new SparseMerkleTree backed by a sublevel chain
63
- * within the single LevelDB instance.
64
- */
65
- private createTree;
66
- /**
67
- * Store the indexes for a messageCid so we can look up the protocol during deletion.
68
- */
69
- private storeIndexes;
70
- /**
71
- * Get the stored indexes for a messageCid.
72
- */
73
- private getStoredIndexes;
74
- /**
75
- * Delete the stored indexes for a messageCid.
76
- */
77
- private deleteStoredIndexes;
78
- /**
79
- * Get the metadata partition for a tenant.
80
- */
81
- private getMetaPartition;
82
- }
83
- //# sourceMappingURL=state-index-level.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state-index-level.d.ts","sourceRoot":"","sources":["../../../../src/state-index/state-index-level.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAK1D,OAAO,EAAE,mBAAmB,EAAgB,MAAM,2BAA2B,CAAC;AAE9E,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,QAAQ,CAAC,EAAG,MAAM,CAAC;IACnB,mBAAmB,CAAC,EAAG,OAAO,mBAAmB,CAAC;CACnD,CAAC;AAEF,qBAAa,eAAgB,YAAW,UAAU;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAC/C,OAAO,CAAC,EAAE,CAAwB;IAElC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqD;IAEjF;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqD;gBAEvE,MAAM,CAAC,EAAE,qBAAqB;IAQpC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAYrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB7E,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB5D,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhE,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhE,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1F,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAK/D,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAO/F;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAWrB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAYvB;;;OAGG;YACW,UAAU;IAYxB;;OAEG;YACW,YAAY;IAO1B;;OAEG;YACW,gBAAgB;IAS9B;;OAEG;YACW,mBAAmB;IAKjC;;OAEG;YACW,gBAAgB;CAG/B"}
@@ -1,81 +0,0 @@
1
- /**
2
- * Types for the Sparse Merkle Tree implementation.
3
- */
4
- /**
5
- * A 32-byte hash (SHA-256 output).
6
- */
7
- export type Hash = Uint8Array;
8
- /**
9
- * Represents the path through the tree as a sequence of bits derived from the key hash.
10
- * Each bit determines whether to go left (0) or right (1) at each depth level.
11
- */
12
- export type BitPath = boolean[];
13
- /**
14
- * A node in the Sparse Merkle Tree.
15
- *
16
- * - `internal`: has left and right child hashes but no leaf data
17
- * - `leaf`: has a key hash and value (the messageCid) but no children
18
- * - empty subtrees are represented implicitly via precomputed default hashes
19
- */
20
- export type SMTNode = SMTInternalNode | SMTLeafNode;
21
- export type SMTInternalNode = {
22
- type: 'internal';
23
- leftHash: Hash;
24
- rightHash: Hash;
25
- };
26
- export type SMTLeafNode = {
27
- type: 'leaf';
28
- keyHash: Hash;
29
- valueCid: string;
30
- };
31
- /**
32
- * An inclusion or non-inclusion proof for a key in the SMT.
33
- *
34
- * - `siblings`: the sibling hashes along the path from leaf to root
35
- * - `leafNode`: the leaf node at the path (undefined if non-inclusion proof for an empty slot)
36
- * - `depth`: the depth at which the proof terminates
37
- */
38
- export type SMTProof = {
39
- siblings: Hash[];
40
- leafNode: SMTLeafNode | undefined;
41
- depth: number;
42
- };
43
- /**
44
- * Result of diffing two SMT roots.
45
- */
46
- export type SMTDiffResult = {
47
- /** messageCids present in the local tree but not the remote tree */
48
- onlyLocal: string[];
49
- /** messageCids present in the remote tree but not the local tree */
50
- onlyRemote: string[];
51
- };
52
- /**
53
- * Interface for persisting SMT nodes. Implementations can use LevelDB, SQL, or in-memory maps.
54
- * Nodes are keyed by their hash. The root hash is stored separately.
55
- */
56
- export interface SMTNodeStore {
57
- open(): Promise<void>;
58
- close(): Promise<void>;
59
- clear(): Promise<void>;
60
- /**
61
- * Get a node by its hash. Returns undefined if not found.
62
- */
63
- getNode(hash: Hash): Promise<SMTNode | undefined>;
64
- /**
65
- * Store a node, keyed by its hash.
66
- */
67
- putNode(hash: Hash, node: SMTNode): Promise<void>;
68
- /**
69
- * Delete a node by its hash.
70
- */
71
- deleteNode(hash: Hash): Promise<void>;
72
- /**
73
- * Get the current root hash. Returns undefined if no root has been set.
74
- */
75
- getRoot(): Promise<Hash | undefined>;
76
- /**
77
- * Set the root hash.
78
- */
79
- setRoot(hash: Hash): Promise<void>;
80
- }
81
- //# sourceMappingURL=smt-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"smt-types.d.ts","sourceRoot":"","sources":["../../../../src/types/smt-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC;AAE9B;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,MAAM,OAAO,GACf,eAAe,GACf,WAAW,CAAC;AAEhB,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAG,UAAU,CAAC;IAClB,QAAQ,EAAG,IAAI,CAAC;IAChB,SAAS,EAAG,IAAI,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAG,MAAM,CAAC;IACd,OAAO,EAAG,IAAI,CAAC;IACf,QAAQ,EAAG,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAG,IAAI,EAAE,CAAC;IAClB,QAAQ,EAAG,WAAW,GAAG,SAAS,CAAC;IACnC,KAAK,EAAG,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,oEAAoE;IACpE,SAAS,EAAG,MAAM,EAAE,CAAC;IACrB,oEAAoE;IACpE,UAAU,EAAG,MAAM,EAAE,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IAElD;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElD;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IAErC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC"}
@@ -1,90 +0,0 @@
1
- import type { Hash } from './smt-types.js';
2
- import type { KeyValues } from './query-types.js';
3
- /**
4
- * A Sparse Merkle Tree-backed state index that tracks the set of messageCids
5
- * for each tenant. Replaces the EventLog as the mechanism for sync state tracking.
6
- *
7
- * Key differences from EventLog:
8
- * - No watermark ordering — the SMT is a set, not a log
9
- * - Root hash provides O(1) "are we in sync?" comparison
10
- * - Supports subtree hashing for O(log n) set reconciliation
11
- * - Per-protocol sub-trees for scoped sync
12
- */
13
- export interface StateIndex {
14
- /**
15
- * Opens a connection to the underlying store.
16
- */
17
- open(): Promise<void>;
18
- /**
19
- * Closes the connection to the underlying store.
20
- */
21
- close(): Promise<void>;
22
- /**
23
- * Clears all data. Mainly used for cleaning up in test environments.
24
- */
25
- clear(): Promise<void>;
26
- /**
27
- * Insert a message into the state index.
28
- *
29
- * @param tenant - the tenant's DID
30
- * @param messageCid - the CID of the message
31
- * @param indexes - key-value pairs from the message (used to extract `protocol` for
32
- * per-protocol sub-tree maintenance, and stored for reverse lookup during deletion)
33
- */
34
- insert(tenant: string, messageCid: string, indexes: KeyValues): Promise<void>;
35
- /**
36
- * Delete messages from the state index.
37
- *
38
- * @param tenant - the tenant's DID
39
- * @param messageCids - the CIDs of the messages to remove
40
- */
41
- delete(tenant: string, messageCids: string[]): Promise<void>;
42
- /**
43
- * Get the SMT root hash for a tenant's global state (all protocols).
44
- *
45
- * @param tenant - the tenant's DID
46
- * @returns the root hash. Returns the default empty root if no messages exist.
47
- */
48
- getRoot(tenant: string): Promise<Hash>;
49
- /**
50
- * Get the SMT root hash for a specific protocol's state within a tenant.
51
- *
52
- * @param tenant - the tenant's DID
53
- * @param protocol - the protocol URI
54
- * @returns the root hash. Returns the default empty root if no messages exist for this protocol.
55
- */
56
- getProtocolRoot(tenant: string, protocol: string): Promise<Hash>;
57
- /**
58
- * Get the hash of a subtree at a given bit prefix within a tenant's global tree.
59
- * Used by the sync protocol for tree walking during set reconciliation.
60
- *
61
- * @param tenant - the tenant's DID
62
- * @param prefix - array of booleans representing the path (false=left, true=right)
63
- */
64
- getSubtreeHash(tenant: string, prefix: boolean[]): Promise<Hash>;
65
- /**
66
- * Get the hash of a subtree at a given bit prefix within a protocol-scoped tree.
67
- *
68
- * @param tenant - the tenant's DID
69
- * @param protocol - the protocol URI
70
- * @param prefix - array of booleans representing the path (false=left, true=right)
71
- */
72
- getProtocolSubtreeHash(tenant: string, protocol: string, prefix: boolean[]): Promise<Hash>;
73
- /**
74
- * Get all leaf messageCids under a given prefix in the tenant's global tree.
75
- * Used by the sync protocol to enumerate leaves in a divergent subtree.
76
- *
77
- * @param tenant - the tenant's DID
78
- * @param prefix - array of booleans representing the path
79
- */
80
- getLeaves(tenant: string, prefix: boolean[]): Promise<string[]>;
81
- /**
82
- * Get all leaf messageCids under a given prefix in a protocol-scoped tree.
83
- *
84
- * @param tenant - the tenant's DID
85
- * @param protocol - the protocol URI
86
- * @param prefix - array of booleans representing the path
87
- */
88
- getProtocolLeaves(tenant: string, protocol: string, prefix: boolean[]): Promise<string[]>;
89
- }
90
- //# sourceMappingURL=state-index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state-index.d.ts","sourceRoot":"","sources":["../../../../src/types/state-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9E;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;;;;;OAMG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;;;OAMG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjE;;;;;;OAMG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3F;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEhE;;;;;;OAMG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC3F"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=event-emitter-event-log.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-emitter-event-log.spec.d.ts","sourceRoot":"","sources":["../../../tests/event-emitter-event-log.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare function testMessagesSyncHandler(): void;
2
- //# sourceMappingURL=messages-sync.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"messages-sync.spec.d.ts","sourceRoot":"","sources":["../../../../tests/handlers/messages-sync.spec.ts"],"names":[],"mappings":"AAoCA,wBAAgB,uBAAuB,IAAI,IAAI,CAwuC9C"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=smt-store-level.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"smt-store-level.spec.d.ts","sourceRoot":"","sources":["../../../../tests/smt/smt-store-level.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=sparse-merkle-tree.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sparse-merkle-tree.spec.d.ts","sourceRoot":"","sources":["../../../../tests/smt/sparse-merkle-tree.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=state-index-level.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state-index-level.spec.d.ts","sourceRoot":"","sources":["../../../../tests/state-index/state-index-level.spec.ts"],"names":[],"mappings":""}
@@ -1,99 +0,0 @@
1
- import type { Filter } from '../types/query-types.js';
2
- import type { MessageStore } from '../types/message-store.js';
3
- import type { RecordsWriteMessage } from '../types/records-types.js';
4
-
5
- import { RecordsWrite } from '../interfaces/records-write.js';
6
- import { DwnError, DwnErrorCode } from './dwn-error.js';
7
- import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
8
-
9
- /**
10
- * Fetches the initial RecordsWrite message associated with the given (tenant + recordId).
11
- */
12
- export async function fetchInitialWrite(
13
- tenant: string,
14
- recordId: string,
15
- messageStore: MessageStore
16
- ): Promise<RecordsWriteMessage | undefined> {
17
-
18
- const query: Filter = {
19
- interface : DwnInterfaceName.Records,
20
- method : DwnMethodName.Write,
21
- recordId : recordId
22
- };
23
- const { messages } = await messageStore.query(tenant, [query]);
24
-
25
- if (messages.length === 0) {
26
- return undefined;
27
- }
28
-
29
- const initialWrite = await RecordsWrite.getInitialWrite(messages);
30
- return initialWrite;
31
- }
32
-
33
- /**
34
- * Constructs the chain of EXISTING records in the datastore where the first record is the root initial `RecordsWrite` of the record chain
35
- * and last record is the initial `RecordsWrite` of the descendant record specified.
36
- * @param descendantRecordId The ID of the descendent record to start constructing the record chain from by repeatedly looking up the parent.
37
- * @returns the record chain where each record is represented by its initial `RecordsWrite`;
38
- * returns empty array if `descendantRecordId` is `undefined`.
39
- * @throws {DwnError} if `descendantRecordId` is defined but any initial `RecordsWrite` is not found in the chain of records.
40
- */
41
- export async function constructRecordChain(
42
- tenant: string,
43
- descendantRecordId: string | undefined,
44
- messageStore: MessageStore
45
- ): Promise<RecordsWriteMessage[]> {
46
-
47
- if (descendantRecordId === undefined) {
48
- return [];
49
- }
50
-
51
- const recordChain: RecordsWriteMessage[] = [];
52
-
53
- // keep walking up the chain from the inbound message's parent, until there is no more parent
54
- let currentRecordId: string | undefined = descendantRecordId;
55
- while (currentRecordId !== undefined) {
56
-
57
- const initialWrite = await fetchInitialWrite(tenant, currentRecordId, messageStore);
58
-
59
- // RecordsWrite needed should be available since we perform necessary checks at the time of writes,
60
- // eg. check the immediate parent in `verifyProtocolPathAndContextId` at the time of writing,
61
- // so if this condition is triggered, it means there is an unexpected bug that caused an incomplete chain.
62
- // We add additional defensive check here because returning an unexpected/incorrect record chain could lead to security vulnerabilities.
63
- if (initialWrite === undefined) {
64
- throw new DwnError(
65
- DwnErrorCode.ProtocolAuthorizationParentNotFoundConstructingRecordChain,
66
- `Unexpected error that should never trigger: no parent found with ID ${currentRecordId} when constructing record chain.`
67
- );
68
- }
69
-
70
- recordChain.push(initialWrite);
71
- currentRecordId = initialWrite.descriptor.parentId;
72
- }
73
-
74
- return recordChain.reverse(); // root record first
75
- }
76
-
77
- /**
78
- * Determines the timestamp that governs which protocol definition version applies to the given RecordsWrite.
79
- * For an update, this is the initial write's `messageTimestamp` (the protocol version is locked at creation time).
80
- * For a new initial write, returns `undefined` — the latest protocol definition should be used because the
81
- * record is being created now and must conform to the current protocol rules.
82
- */
83
- export async function getGoverningTimestamp(
84
- tenant: string,
85
- incomingMessage: RecordsWrite,
86
- messageStore: MessageStore,
87
- ): Promise<string | undefined> {
88
- const existingInitialWrite = await fetchInitialWrite(
89
- tenant, incomingMessage.message.recordId, messageStore
90
- );
91
-
92
- if (existingInitialWrite !== undefined) {
93
- // update case: use the initial write's timestamp
94
- return existingInitialWrite.descriptor.messageTimestamp;
95
- }
96
-
97
- // initial write case: validate against the latest protocol definition
98
- return undefined;
99
- }