@enbox/dwn-sdk-js 0.0.6 → 0.0.8

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 (527) hide show
  1. package/dist/browser.mjs +8 -8
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/generated/precompiled-validators.js +762 -911
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/core/abstract-message.js +4 -0
  6. package/dist/esm/src/core/abstract-message.js.map +1 -1
  7. package/dist/esm/src/core/auth.js +22 -33
  8. package/dist/esm/src/core/auth.js.map +1 -1
  9. package/dist/esm/src/core/constants.js +11 -0
  10. package/dist/esm/src/core/constants.js.map +1 -0
  11. package/dist/esm/src/core/core-protocol.js +44 -0
  12. package/dist/esm/src/core/core-protocol.js.map +1 -0
  13. package/dist/esm/src/core/dwn-constant.js +7 -7
  14. package/dist/esm/src/core/dwn-constant.js.map +1 -1
  15. package/dist/esm/src/core/dwn-error.js +10 -12
  16. package/dist/esm/src/core/dwn-error.js.map +1 -1
  17. package/dist/esm/src/core/grant-authorization.js +50 -52
  18. package/dist/esm/src/core/grant-authorization.js.map +1 -1
  19. package/dist/esm/src/core/message.js +85 -116
  20. package/dist/esm/src/core/message.js.map +1 -1
  21. package/dist/esm/src/core/messages-grant-authorization.js +63 -78
  22. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
  23. package/dist/esm/src/core/protocol-authorization-action.js +266 -0
  24. package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
  25. package/dist/esm/src/core/protocol-authorization-validation.js +321 -0
  26. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
  27. package/dist/esm/src/core/protocol-authorization.js +144 -741
  28. package/dist/esm/src/core/protocol-authorization.js.map +1 -1
  29. package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
  30. package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
  31. package/dist/esm/src/core/record-chain.js +64 -0
  32. package/dist/esm/src/core/record-chain.js.map +1 -0
  33. package/dist/esm/src/core/records-grant-authorization.js +53 -72
  34. package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
  35. package/dist/esm/src/core/resumable-task-manager.js +50 -65
  36. package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
  37. package/dist/esm/src/core/tenant-gate.js +2 -13
  38. package/dist/esm/src/core/tenant-gate.js.map +1 -1
  39. package/dist/esm/src/dwn.js +108 -101
  40. package/dist/esm/src/dwn.js.map +1 -1
  41. package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
  42. package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
  43. package/dist/esm/src/handlers/messages-read.js +67 -81
  44. package/dist/esm/src/handlers/messages-read.js.map +1 -1
  45. package/dist/esm/src/handlers/messages-subscribe.js +51 -63
  46. package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
  47. package/dist/esm/src/handlers/messages-sync.js +75 -89
  48. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  49. package/dist/esm/src/handlers/protocols-configure.js +153 -163
  50. package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
  51. package/dist/esm/src/handlers/protocols-query.js +52 -55
  52. package/dist/esm/src/handlers/protocols-query.js.map +1 -1
  53. package/dist/esm/src/handlers/records-count.js +97 -85
  54. package/dist/esm/src/handlers/records-count.js.map +1 -1
  55. package/dist/esm/src/handlers/records-delete.js +75 -93
  56. package/dist/esm/src/handlers/records-delete.js.map +1 -1
  57. package/dist/esm/src/handlers/records-query.js +116 -105
  58. package/dist/esm/src/handlers/records-query.js.map +1 -1
  59. package/dist/esm/src/handlers/records-read.js +130 -132
  60. package/dist/esm/src/handlers/records-read.js.map +1 -1
  61. package/dist/esm/src/handlers/records-subscribe.js +164 -104
  62. package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
  63. package/dist/esm/src/handlers/records-write.js +213 -280
  64. package/dist/esm/src/handlers/records-write.js.map +1 -1
  65. package/dist/esm/src/index.js +5 -2
  66. package/dist/esm/src/index.js.map +1 -1
  67. package/dist/esm/src/interfaces/messages-read.js +24 -32
  68. package/dist/esm/src/interfaces/messages-read.js.map +1 -1
  69. package/dist/esm/src/interfaces/messages-subscribe.js +28 -41
  70. package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
  71. package/dist/esm/src/interfaces/messages-sync.js +26 -40
  72. package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
  73. package/dist/esm/src/interfaces/protocols-configure.js +87 -65
  74. package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
  75. package/dist/esm/src/interfaces/protocols-query.js +55 -68
  76. package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
  77. package/dist/esm/src/interfaces/records-count.js +50 -66
  78. package/dist/esm/src/interfaces/records-count.js.map +1 -1
  79. package/dist/esm/src/interfaces/records-delete.js +45 -55
  80. package/dist/esm/src/interfaces/records-delete.js.map +1 -1
  81. package/dist/esm/src/interfaces/records-query.js +60 -76
  82. package/dist/esm/src/interfaces/records-query.js.map +1 -1
  83. package/dist/esm/src/interfaces/records-read.js +51 -67
  84. package/dist/esm/src/interfaces/records-read.js.map +1 -1
  85. package/dist/esm/src/interfaces/records-subscribe.js +53 -68
  86. package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
  87. package/dist/esm/src/interfaces/records-write-query.js +102 -0
  88. package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
  89. package/dist/esm/src/interfaces/records-write-signing.js +81 -0
  90. package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
  91. package/dist/esm/src/interfaces/records-write.js +396 -610
  92. package/dist/esm/src/interfaces/records-write.js.map +1 -1
  93. package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
  94. package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
  95. package/dist/esm/src/jose/jws/general/builder.js +23 -35
  96. package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
  97. package/dist/esm/src/jose/jws/general/verifier.js +56 -69
  98. package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
  99. package/dist/esm/src/protocols/permission-grant.js +43 -14
  100. package/dist/esm/src/protocols/permission-grant.js.map +1 -1
  101. package/dist/esm/src/protocols/permission-request.js +28 -14
  102. package/dist/esm/src/protocols/permission-request.js.map +1 -1
  103. package/dist/esm/src/protocols/permissions.js +325 -227
  104. package/dist/esm/src/protocols/permissions.js.map +1 -1
  105. package/dist/esm/src/smt/smt-store-level.js +42 -64
  106. package/dist/esm/src/smt/smt-store-level.js.map +1 -1
  107. package/dist/esm/src/smt/smt-store-memory.js +19 -45
  108. package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
  109. package/dist/esm/src/smt/smt-utils.js +28 -45
  110. package/dist/esm/src/smt/smt-utils.js.map +1 -1
  111. package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
  112. package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
  113. package/dist/esm/src/state-index/state-index-level.js +113 -150
  114. package/dist/esm/src/state-index/state-index-level.js.map +1 -1
  115. package/dist/esm/src/store/blockstore-level.js +54 -156
  116. package/dist/esm/src/store/blockstore-level.js.map +1 -1
  117. package/dist/esm/src/store/blockstore-mock.js +48 -153
  118. package/dist/esm/src/store/blockstore-mock.js.map +1 -1
  119. package/dist/esm/src/store/data-store-level.js +137 -100
  120. package/dist/esm/src/store/data-store-level.js.map +1 -1
  121. package/dist/esm/src/store/index-level-compound.js +246 -0
  122. package/dist/esm/src/store/index-level-compound.js.map +1 -0
  123. package/dist/esm/src/store/index-level.js +307 -715
  124. package/dist/esm/src/store/index-level.js.map +1 -1
  125. package/dist/esm/src/store/level-wrapper.js +143 -244
  126. package/dist/esm/src/store/level-wrapper.js.map +1 -1
  127. package/dist/esm/src/store/message-store-level.js +71 -94
  128. package/dist/esm/src/store/message-store-level.js.map +1 -1
  129. package/dist/esm/src/store/resumable-task-store-level.js +62 -101
  130. package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
  131. package/dist/esm/src/store/storage-controller.js +131 -146
  132. package/dist/esm/src/store/storage-controller.js.map +1 -1
  133. package/dist/esm/src/types/permission-types.js.map +1 -1
  134. package/dist/esm/src/types/protocols-types.js +10 -0
  135. package/dist/esm/src/types/protocols-types.js.map +1 -1
  136. package/dist/esm/src/types/records-types.js.map +1 -1
  137. package/dist/esm/src/utils/abort.js +8 -19
  138. package/dist/esm/src/utils/abort.js.map +1 -1
  139. package/dist/esm/src/utils/array.js +15 -49
  140. package/dist/esm/src/utils/array.js.map +1 -1
  141. package/dist/esm/src/utils/cid.js +29 -77
  142. package/dist/esm/src/utils/cid.js.map +1 -1
  143. package/dist/esm/src/utils/data-stream.js +37 -65
  144. package/dist/esm/src/utils/data-stream.js.map +1 -1
  145. package/dist/esm/src/utils/encryption.js +136 -162
  146. package/dist/esm/src/utils/encryption.js.map +1 -1
  147. package/dist/esm/src/utils/filter.js +1 -12
  148. package/dist/esm/src/utils/filter.js.map +1 -1
  149. package/dist/esm/src/utils/hd-key.js +45 -71
  150. package/dist/esm/src/utils/hd-key.js.map +1 -1
  151. package/dist/esm/src/utils/jws.js +9 -20
  152. package/dist/esm/src/utils/jws.js.map +1 -1
  153. package/dist/esm/src/utils/memory-cache.js +12 -23
  154. package/dist/esm/src/utils/memory-cache.js.map +1 -1
  155. package/dist/esm/src/utils/messages.js +21 -33
  156. package/dist/esm/src/utils/messages.js.map +1 -1
  157. package/dist/esm/src/utils/private-key-signer.js +9 -17
  158. package/dist/esm/src/utils/private-key-signer.js.map +1 -1
  159. package/dist/esm/src/utils/protocols.js +62 -70
  160. package/dist/esm/src/utils/protocols.js.map +1 -1
  161. package/dist/esm/src/utils/records.js +103 -166
  162. package/dist/esm/src/utils/records.js.map +1 -1
  163. package/dist/esm/src/utils/secp256k1.js +60 -96
  164. package/dist/esm/src/utils/secp256k1.js.map +1 -1
  165. package/dist/esm/src/utils/secp256r1.js +54 -71
  166. package/dist/esm/src/utils/secp256r1.js.map +1 -1
  167. package/dist/esm/src/utils/time.js +5 -18
  168. package/dist/esm/src/utils/time.js.map +1 -1
  169. package/dist/esm/src/utils/url.js +3 -3
  170. package/dist/esm/src/utils/url.js.map +1 -1
  171. package/dist/esm/tests/core/auth.spec.js +3 -12
  172. package/dist/esm/tests/core/auth.spec.js.map +1 -1
  173. package/dist/esm/tests/core/message.spec.js +50 -59
  174. package/dist/esm/tests/core/message.spec.js.map +1 -1
  175. package/dist/esm/tests/core/protocol-authorization.spec.js +10 -18
  176. package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
  177. package/dist/esm/tests/dwn.spec.js +65 -89
  178. package/dist/esm/tests/dwn.spec.js.map +1 -1
  179. package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
  180. package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
  181. package/dist/esm/tests/features/author-delegated-grant.spec.js +337 -347
  182. package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
  183. package/dist/esm/tests/features/owner-delegated-grant.spec.js +160 -172
  184. package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
  185. package/dist/esm/tests/features/owner-signature.spec.js +78 -82
  186. package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
  187. package/dist/esm/tests/features/permissions.spec.js +449 -184
  188. package/dist/esm/tests/features/permissions.spec.js.map +1 -1
  189. package/dist/esm/tests/features/protocol-composition.spec.js +981 -360
  190. package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
  191. package/dist/esm/tests/features/protocol-create-action.spec.js +45 -54
  192. package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
  193. package/dist/esm/tests/features/protocol-delete-action.spec.js +99 -108
  194. package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
  195. package/dist/esm/tests/features/protocol-update-action.spec.js +108 -117
  196. package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
  197. package/dist/esm/tests/features/records-immutable.spec.js +315 -0
  198. package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
  199. package/dist/esm/tests/features/records-prune.spec.js +178 -194
  200. package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
  201. package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
  202. package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
  203. package/dist/esm/tests/features/records-tags.spec.js +456 -463
  204. package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
  205. package/dist/esm/tests/features/resumable-tasks.spec.js +88 -98
  206. package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
  207. package/dist/esm/tests/handlers/messages-read.spec.js +215 -210
  208. package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
  209. package/dist/esm/tests/handlers/messages-subscribe.spec.js +309 -171
  210. package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
  211. package/dist/esm/tests/handlers/messages-sync.spec.js +272 -199
  212. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  213. package/dist/esm/tests/handlers/protocols-configure.spec.js +247 -241
  214. package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
  215. package/dist/esm/tests/handlers/protocols-query.spec.js +159 -172
  216. package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
  217. package/dist/esm/tests/handlers/records-count.spec.js +101 -105
  218. package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
  219. package/dist/esm/tests/handlers/records-delete.spec.js +266 -279
  220. package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
  221. package/dist/esm/tests/handlers/records-query.spec.js +984 -996
  222. package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
  223. package/dist/esm/tests/handlers/records-read.spec.js +542 -671
  224. package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
  225. package/dist/esm/tests/handlers/records-subscribe.spec.js +433 -302
  226. package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
  227. package/dist/esm/tests/handlers/records-write.spec.js +1216 -1140
  228. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  229. package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
  230. package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
  231. package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
  232. package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
  233. package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
  234. package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
  235. package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
  236. package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
  237. package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
  238. package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
  239. package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
  240. package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
  241. package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
  242. package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
  243. package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
  244. package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
  245. package/dist/esm/tests/interfaces/records-write.spec.js +190 -219
  246. package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
  247. package/dist/esm/tests/jose/jws/general.spec.js +36 -45
  248. package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
  249. package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
  250. package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
  251. package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
  252. package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
  253. package/dist/esm/tests/protocols/permissions.spec.js +49 -55
  254. package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
  255. package/dist/esm/tests/scenarios/aggregator.spec.js +127 -138
  256. package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
  257. package/dist/esm/tests/scenarios/deleted-record.spec.js +372 -36
  258. package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
  259. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +55 -64
  260. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
  261. package/dist/esm/tests/scenarios/nested-roles.spec.js +66 -76
  262. package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
  263. package/dist/esm/tests/scenarios/subscriptions.spec.js +451 -354
  264. package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
  265. package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
  266. package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
  267. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
  268. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
  269. package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
  270. package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
  271. package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
  272. package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
  273. package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
  274. package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
  275. package/dist/esm/tests/store/data-store-level.spec.js +160 -108
  276. package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
  277. package/dist/esm/tests/store/index-level.spec.js +404 -414
  278. package/dist/esm/tests/store/index-level.spec.js.map +1 -1
  279. package/dist/esm/tests/store/message-store-level.spec.js +13 -22
  280. package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
  281. package/dist/esm/tests/store/message-store.spec.js +229 -238
  282. package/dist/esm/tests/store/message-store.spec.js.map +1 -1
  283. package/dist/esm/tests/test-event-stream.js +12 -13
  284. package/dist/esm/tests/test-event-stream.js.map +1 -1
  285. package/dist/esm/tests/test-stores.js +16 -13
  286. package/dist/esm/tests/test-stores.js.map +1 -1
  287. package/dist/esm/tests/test-suite.js +8 -15
  288. package/dist/esm/tests/test-suite.js.map +1 -1
  289. package/dist/esm/tests/utils/cid.spec.js +24 -33
  290. package/dist/esm/tests/utils/cid.spec.js.map +1 -1
  291. package/dist/esm/tests/utils/data-stream.spec.js +48 -57
  292. package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
  293. package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
  294. package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
  295. package/dist/esm/tests/utils/encryption.spec.js +229 -82
  296. package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
  297. package/dist/esm/tests/utils/filters.spec.js +46 -55
  298. package/dist/esm/tests/utils/filters.spec.js.map +1 -1
  299. package/dist/esm/tests/utils/hd-key.spec.js +10 -19
  300. package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
  301. package/dist/esm/tests/utils/jws.spec.js +3 -12
  302. package/dist/esm/tests/utils/jws.spec.js.map +1 -1
  303. package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
  304. package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
  305. package/dist/esm/tests/utils/messages.spec.js +18 -20
  306. package/dist/esm/tests/utils/messages.spec.js.map +1 -1
  307. package/dist/esm/tests/utils/poller.js +22 -33
  308. package/dist/esm/tests/utils/poller.js.map +1 -1
  309. package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
  310. package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
  311. package/dist/esm/tests/utils/records.spec.js +14 -27
  312. package/dist/esm/tests/utils/records.spec.js.map +1 -1
  313. package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
  314. package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
  315. package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
  316. package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
  317. package/dist/esm/tests/utils/test-data-generator.js +446 -467
  318. package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
  319. package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
  320. package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
  321. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
  322. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
  323. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
  324. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
  325. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
  326. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
  327. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
  328. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
  329. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
  330. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
  331. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
  332. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
  333. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +44 -24
  334. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
  335. package/dist/types/generated/precompiled-validators.d.ts +49 -40
  336. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  337. package/dist/types/src/core/constants.d.ts +11 -0
  338. package/dist/types/src/core/constants.d.ts.map +1 -0
  339. package/dist/types/src/core/core-protocol.d.ts +89 -0
  340. package/dist/types/src/core/core-protocol.d.ts.map +1 -0
  341. package/dist/types/src/core/dwn-error.d.ts +9 -12
  342. package/dist/types/src/core/dwn-error.d.ts.map +1 -1
  343. package/dist/types/src/core/grant-authorization.d.ts +6 -2
  344. package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
  345. package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
  346. package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
  347. package/dist/types/src/core/protocol-authorization-validation.d.ts +81 -0
  348. package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
  349. package/dist/types/src/core/protocol-authorization.d.ts +24 -106
  350. package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
  351. package/dist/types/src/core/record-chain.d.ts +24 -0
  352. package/dist/types/src/core/record-chain.d.ts.map +1 -0
  353. package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
  354. package/dist/types/src/dwn.d.ts +19 -7
  355. package/dist/types/src/dwn.d.ts.map +1 -1
  356. package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
  357. package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
  358. package/dist/types/src/handlers/messages-read.d.ts +3 -8
  359. package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
  360. package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
  361. package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
  362. package/dist/types/src/handlers/messages-sync.d.ts +3 -8
  363. package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
  364. package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
  365. package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
  366. package/dist/types/src/handlers/protocols-query.d.ts +3 -8
  367. package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
  368. package/dist/types/src/handlers/records-count.d.ts +3 -6
  369. package/dist/types/src/handlers/records-count.d.ts.map +1 -1
  370. package/dist/types/src/handlers/records-delete.d.ts +3 -8
  371. package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
  372. package/dist/types/src/handlers/records-query.d.ts +3 -8
  373. package/dist/types/src/handlers/records-query.d.ts.map +1 -1
  374. package/dist/types/src/handlers/records-read.d.ts +3 -8
  375. package/dist/types/src/handlers/records-read.d.ts.map +1 -1
  376. package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
  377. package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
  378. package/dist/types/src/handlers/records-write.d.ts +4 -24
  379. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  380. package/dist/types/src/index.d.ts +8 -4
  381. package/dist/types/src/index.d.ts.map +1 -1
  382. package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
  383. package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
  384. package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
  385. package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
  386. package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
  387. package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
  388. package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
  389. package/dist/types/src/interfaces/records-write-signing.d.ts +34 -0
  390. package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
  391. package/dist/types/src/interfaces/records-write.d.ts +13 -53
  392. package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
  393. package/dist/types/src/protocols/permission-grant.d.ts +1 -1
  394. package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
  395. package/dist/types/src/protocols/permission-request.d.ts +1 -1
  396. package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
  397. package/dist/types/src/protocols/permissions.d.ts +40 -3
  398. package/dist/types/src/protocols/permissions.d.ts.map +1 -1
  399. package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
  400. package/dist/types/src/store/data-store-level.d.ts +20 -4
  401. package/dist/types/src/store/data-store-level.d.ts.map +1 -1
  402. package/dist/types/src/store/index-level-compound.d.ts +70 -0
  403. package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
  404. package/dist/types/src/store/index-level.d.ts +4 -58
  405. package/dist/types/src/store/index-level.d.ts.map +1 -1
  406. package/dist/types/src/store/storage-controller.d.ts +4 -4
  407. package/dist/types/src/store/storage-controller.d.ts.map +1 -1
  408. package/dist/types/src/types/message-types.d.ts +3 -3
  409. package/dist/types/src/types/message-types.d.ts.map +1 -1
  410. package/dist/types/src/types/messages-types.d.ts +12 -3
  411. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  412. package/dist/types/src/types/method-handler.d.ts +24 -3
  413. package/dist/types/src/types/method-handler.d.ts.map +1 -1
  414. package/dist/types/src/types/permission-types.d.ts +7 -0
  415. package/dist/types/src/types/permission-types.d.ts.map +1 -1
  416. package/dist/types/src/types/protocols-types.d.ts +41 -1
  417. package/dist/types/src/types/protocols-types.d.ts.map +1 -1
  418. package/dist/types/src/types/records-types.d.ts +16 -6
  419. package/dist/types/src/types/records-types.d.ts.map +1 -1
  420. package/dist/types/src/types/subscriptions.d.ts +151 -13
  421. package/dist/types/src/types/subscriptions.d.ts.map +1 -1
  422. package/dist/types/src/utils/hd-key.d.ts +1 -9
  423. package/dist/types/src/utils/hd-key.d.ts.map +1 -1
  424. package/dist/types/src/utils/messages.d.ts +7 -5
  425. package/dist/types/src/utils/messages.d.ts.map +1 -1
  426. package/dist/types/src/utils/protocols.d.ts +5 -0
  427. package/dist/types/src/utils/protocols.d.ts.map +1 -1
  428. package/dist/types/src/utils/records.d.ts +1 -11
  429. package/dist/types/src/utils/records.d.ts.map +1 -1
  430. package/dist/types/tests/dwn.spec.d.ts.map +1 -1
  431. package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
  432. package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
  433. package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
  434. package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
  435. package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
  436. package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
  437. package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
  438. package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
  439. package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
  440. package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
  441. package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
  442. package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
  443. package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
  444. package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
  445. package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
  446. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
  447. package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
  448. package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
  449. package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
  450. package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
  451. package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
  452. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
  453. package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
  454. package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
  455. package/dist/types/tests/test-event-stream.d.ts +11 -12
  456. package/dist/types/tests/test-event-stream.d.ts.map +1 -1
  457. package/dist/types/tests/test-suite.d.ts +2 -2
  458. package/dist/types/tests/test-suite.d.ts.map +1 -1
  459. package/dist/types/tests/utils/test-data-generator.d.ts +18 -0
  460. package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
  461. package/package.json +5 -4
  462. package/src/core/constants.ts +11 -0
  463. package/src/core/core-protocol.ts +129 -0
  464. package/src/core/dwn-error.ts +15 -12
  465. package/src/core/grant-authorization.ts +20 -3
  466. package/src/core/protocol-authorization-action.ts +377 -0
  467. package/src/core/protocol-authorization-validation.ts +487 -0
  468. package/src/core/protocol-authorization.ts +111 -856
  469. package/src/core/record-chain.ts +99 -0
  470. package/src/core/records-grant-authorization.ts +6 -8
  471. package/src/dwn.ts +58 -73
  472. package/src/event-stream/event-emitter-event-log.ts +283 -0
  473. package/src/handlers/messages-read.ts +8 -9
  474. package/src/handlers/messages-subscribe.ts +24 -28
  475. package/src/handlers/messages-sync.ts +10 -16
  476. package/src/handlers/protocols-configure.ts +47 -32
  477. package/src/handlers/protocols-query.ts +6 -9
  478. package/src/handlers/records-count.ts +11 -10
  479. package/src/handlers/records-delete.ts +12 -21
  480. package/src/handlers/records-query.ts +12 -12
  481. package/src/handlers/records-read.ts +34 -22
  482. package/src/handlers/records-subscribe.ts +47 -26
  483. package/src/handlers/records-write.ts +47 -104
  484. package/src/index.ts +9 -5
  485. package/src/interfaces/messages-subscribe.ts +7 -1
  486. package/src/interfaces/protocols-configure.ts +73 -8
  487. package/src/interfaces/records-count.ts +1 -1
  488. package/src/interfaces/records-delete.ts +1 -1
  489. package/src/interfaces/records-query.ts +1 -1
  490. package/src/interfaces/records-read.ts +1 -1
  491. package/src/interfaces/records-subscribe.ts +8 -1
  492. package/src/interfaces/records-write-query.ts +139 -0
  493. package/src/interfaces/records-write-signing.ts +123 -0
  494. package/src/interfaces/records-write.ts +66 -261
  495. package/src/protocols/permission-grant.ts +1 -1
  496. package/src/protocols/permission-request.ts +1 -1
  497. package/src/protocols/permissions.ts +148 -6
  498. package/src/state-index/state-index-level.ts +5 -7
  499. package/src/store/data-store-level.ts +124 -34
  500. package/src/store/index-level-compound.ts +324 -0
  501. package/src/store/index-level.ts +68 -341
  502. package/src/store/storage-controller.ts +11 -11
  503. package/src/types/message-types.ts +3 -3
  504. package/src/types/messages-types.ts +12 -3
  505. package/src/types/method-handler.ts +26 -4
  506. package/src/types/mitt.d.ts +28 -0
  507. package/src/types/permission-types.ts +7 -0
  508. package/src/types/protocols-types.ts +46 -0
  509. package/src/types/records-types.ts +16 -6
  510. package/src/types/subscriptions.ts +178 -14
  511. package/src/utils/hd-key.ts +0 -9
  512. package/src/utils/messages.ts +17 -37
  513. package/src/utils/protocols.ts +8 -0
  514. package/src/utils/records.ts +8 -59
  515. package/dist/esm/src/event-stream/event-emitter-stream.js +0 -60
  516. package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
  517. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -77
  518. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
  519. package/dist/esm/tests/event-stream/event-stream.spec.js +0 -123
  520. package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
  521. package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
  522. package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
  523. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
  524. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
  525. package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
  526. package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
  527. package/src/event-stream/event-emitter-stream.ts +0 -69
@@ -0,0 +1,266 @@
1
+ import { FilterUtility } from '../utils/filter.js';
2
+ import { RecordsWrite } from '../interfaces/records-write.js';
3
+ import { DwnError, DwnErrorCode } from './dwn-error.js';
4
+ import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
5
+ import { getRuleSetAtPath, isCrossProtocolRef, parseCrossProtocolRef } from '../utils/protocols.js';
6
+ import { ProtocolAction, ProtocolActor } from '../types/protocols-types.js';
7
+ /**
8
+ * Check if the incoming message is invoking a role. If so, validate the invoked role.
9
+ * For cross-protocol role invocation, the role record may live in a different protocol
10
+ * (resolved via the composing protocol's `uses` map).
11
+ */
12
+ export async function verifyInvokedRole(tenant, incomingMessage, protocolUri, contextId, protocolDefinition, messageStore, fetchProtocolDefinition, governingTimestamp) {
13
+ const protocolRole = incomingMessage.signaturePayload?.protocolRole;
14
+ // Only verify role if there is a role being invoked
15
+ if (protocolRole === undefined) {
16
+ return;
17
+ }
18
+ // Determine the protocol URI and protocol path for the role record.
19
+ // For cross-protocol roles (e.g., "threads:thread/participant"), resolve the alias.
20
+ let roleProtocolUri = protocolUri;
21
+ let roleProtocolPath = protocolRole;
22
+ if (isCrossProtocolRef(protocolRole)) {
23
+ const parsed = parseCrossProtocolRef(protocolRole);
24
+ if (parsed === undefined) {
25
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationNotARole, `Cross-protocol role '${protocolRole}' could not be parsed as a valid 'alias:path' format.`);
26
+ }
27
+ if (protocolDefinition.uses === undefined || protocolDefinition.uses[parsed.alias] === undefined) {
28
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationNotARole, `Cross-protocol role alias '${parsed.alias}' in '${protocolRole}' does not exist in the protocol's 'uses' map.`);
29
+ }
30
+ roleProtocolUri = protocolDefinition.uses[parsed.alias];
31
+ roleProtocolPath = parsed.protocolPath;
32
+ // Fetch the referenced protocol's definition to validate the role exists
33
+ const refDefinition = await fetchProtocolDefinition(tenant, roleProtocolUri, messageStore, governingTimestamp);
34
+ const roleRuleSet = getRuleSetAtPath(roleProtocolPath, refDefinition.structure);
35
+ if (roleRuleSet === undefined || !roleRuleSet.$role) {
36
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationNotARole, `Cross-protocol role path ${protocolRole} does not match role record type.`);
37
+ }
38
+ }
39
+ else {
40
+ // Local role: validate in the composing protocol's definition
41
+ const roleRuleSet = getRuleSetAtPath(protocolRole, protocolDefinition.structure);
42
+ if (roleRuleSet === undefined || !roleRuleSet.$role) {
43
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationNotARole, `Protocol path ${protocolRole} does not match role record type.`);
44
+ }
45
+ }
46
+ // Construct a filter to fetch the invoked role record
47
+ const roleRecordFilter = {
48
+ interface: DwnInterfaceName.Records,
49
+ method: DwnMethodName.Write,
50
+ protocol: roleProtocolUri,
51
+ protocolPath: roleProtocolPath,
52
+ recipient: incomingMessage.author,
53
+ isLatestBaseState: true,
54
+ };
55
+ const ancestorSegmentCountOfRolePath = roleProtocolPath.split('/').length - 1;
56
+ if (contextId === undefined && ancestorSegmentCountOfRolePath > 0) {
57
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationMissingContextId, 'Could not verify role because contextId is missing.');
58
+ }
59
+ // Compute `contextId` prefix filter for fetching the invoked role record if the role path is not at the root level.
60
+ // e.g. if invoked role path is `Thread/Participant`, and the `contextId` of the message is `threadX/messageY/attachmentZ`,
61
+ // then we need to add a prefix filter as `threadX` for the `contextId`
62
+ // because the `contextId` of the Participant record would be in the form of be `threadX/participantA`
63
+ if (ancestorSegmentCountOfRolePath > 0) {
64
+ const contextIdSegments = contextId.split('/'); // NOTE: currently contextId segment count is never shorter than the role path count.
65
+ const contextIdPrefix = contextIdSegments.slice(0, ancestorSegmentCountOfRolePath).join('/');
66
+ const contextIdPrefixFilter = FilterUtility.constructPrefixFilterAsRangeFilter(contextIdPrefix);
67
+ roleRecordFilter.contextId = contextIdPrefixFilter;
68
+ }
69
+ const { messages: matchingMessages } = await messageStore.query(tenant, [roleRecordFilter]);
70
+ if (matchingMessages.length === 0) {
71
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound, `No matching role record found for protocol path ${roleProtocolPath}`);
72
+ }
73
+ }
74
+ /**
75
+ * Returns all the ProtocolActions that would authorized the incoming message
76
+ * (but we still need to later verify if there is a rule defined that matches one of the actions).
77
+ * NOTE: the reason why there could be multiple actions is because:
78
+ * - In case of an initial RecordsWrite, the RecordsWrite can be authorized by an allow `create` or `write` rule.
79
+ * - In case of a non-initial RecordsWrite by the original record author, the RecordsWrite can be authorized by a `write` or `co-update` rule.
80
+ *
81
+ * It is important to recognize that the `write` access that allowed the original record author to create the record maybe revoked
82
+ * (e.g. by role revocation) by the time a "non-initial" write by the same author is attempted.
83
+ */
84
+ export async function getActionsSeekingARuleMatch(tenant, incomingMessage, messageStore) {
85
+ switch (incomingMessage.message.descriptor.method) {
86
+ case DwnMethodName.Delete:
87
+ const recordsDelete = incomingMessage;
88
+ const recordId = recordsDelete.message.descriptor.recordId;
89
+ const initialWrite = await RecordsWrite.fetchInitialRecordsWrite(messageStore, tenant, recordId);
90
+ // if there is no initial write, then no action rule can authorize the incoming message, because we won't know who the original author is
91
+ // NOTE: purely defensive programming: currently not reachable
92
+ // because RecordsDelete handler already have an existence check prior to this method being called.
93
+ if (initialWrite === undefined) {
94
+ return [];
95
+ }
96
+ const actionsThatWouldAuthorizeDelete = [];
97
+ const prune = recordsDelete.message.descriptor.prune;
98
+ if (prune) {
99
+ actionsThatWouldAuthorizeDelete.push(ProtocolAction.CoPrune);
100
+ // A prune by the original record author can also be authorized by a 'prune' rule.
101
+ if (incomingMessage.author === initialWrite.author) {
102
+ actionsThatWouldAuthorizeDelete.push(ProtocolAction.Prune);
103
+ }
104
+ }
105
+ else {
106
+ actionsThatWouldAuthorizeDelete.push(ProtocolAction.CoDelete);
107
+ // A delete by the original record author can also be authorized by a 'delete' rule.
108
+ if (incomingMessage.author === initialWrite.author) {
109
+ actionsThatWouldAuthorizeDelete.push(ProtocolAction.Delete);
110
+ }
111
+ }
112
+ return actionsThatWouldAuthorizeDelete;
113
+ case DwnMethodName.Count:
114
+ return [ProtocolAction.Read];
115
+ case DwnMethodName.Query:
116
+ return [ProtocolAction.Read];
117
+ case DwnMethodName.Read:
118
+ return [ProtocolAction.Read];
119
+ case DwnMethodName.Subscribe:
120
+ return [ProtocolAction.Read];
121
+ case DwnMethodName.Write:
122
+ const incomingRecordsWrite = incomingMessage;
123
+ if (await incomingRecordsWrite.isInitialWrite()) {
124
+ return [ProtocolAction.Create];
125
+ }
126
+ else {
127
+ // else incoming RecordsWrite not an initial write
128
+ const recordId = incomingMessage.message.recordId;
129
+ const initialWrite = await RecordsWrite.fetchInitialRecordsWrite(messageStore, tenant, recordId);
130
+ // if there is no initial write to update from, then no action rule can authorize the incoming message
131
+ if (initialWrite === undefined) {
132
+ return [];
133
+ }
134
+ if (incomingMessage.author === initialWrite.author) {
135
+ // 'update' or 'co-update' action authorizes the incoming message
136
+ return [ProtocolAction.CoUpdate, ProtocolAction.Update];
137
+ }
138
+ else {
139
+ // An update by someone who is not the record author can only be authorized by a 'co-update' rule.
140
+ return [ProtocolAction.CoUpdate];
141
+ }
142
+ }
143
+ }
144
+ // purely defensive programming: should not be reachable
145
+ // setting to empty array will prevent any message from being authorized
146
+ return [];
147
+ }
148
+ /**
149
+ * Verifies the given message is authorized by one of the action rules in the given protocol rule set.
150
+ * @param protocolDefinition Optional protocol definition for resolving cross-protocol `of` and `role` references.
151
+ * @throws {Error} if action not allowed.
152
+ */
153
+ export async function authorizeAgainstAllowedActions(tenant, incomingMessage, ruleSet, recordChain, messageStore, protocolDefinition) {
154
+ const incomingMessageMethod = incomingMessage.message.descriptor.method;
155
+ const actionsSeekingARuleMatch = await getActionsSeekingARuleMatch(tenant, incomingMessage, messageStore);
156
+ const author = incomingMessage.author;
157
+ const actionRules = ruleSet.$actions;
158
+ // NOTE: We have already checked that the message is not from tenant, owner, or permission grant authorized prior to this method being called.
159
+ if (actionRules === undefined) {
160
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationActionRulesNotFound, `no action rule defined for Records${incomingMessageMethod}, ${author} is unauthorized`);
161
+ }
162
+ const invokedRole = incomingMessage.signaturePayload?.protocolRole;
163
+ // Iterate through the action rules to find a rule that authorizes the incoming message.
164
+ for (const actionRule of actionRules) {
165
+ // If the action rule does not have an allowed action that matches an action that can authorize the message, skip to evaluate next action rule.
166
+ const ruleHasAMatchingAllowedAction = actionRule.can.some((allowedAction) => actionsSeekingARuleMatch.includes(allowedAction));
167
+ if (!ruleHasAMatchingAllowedAction) {
168
+ continue;
169
+ }
170
+ // Code reaches here means this action rule has an allowed action that matches the action of the message.
171
+ // The remaining code checks the actor/author of the incoming message.
172
+ // If the action rule allows `anyone`, then no further checks are needed.
173
+ if (actionRule.who === ProtocolActor.Anyone) {
174
+ return;
175
+ }
176
+ // Since not `anyone` is allowed in this action rule, we will need to check the author of the incoming message,
177
+ // if the author of incoming message is not defined, this action rule cannot authorize the incoming message.
178
+ if (author === undefined) {
179
+ continue;
180
+ }
181
+ // go through role validation path if a role is invoked by the incoming message
182
+ if (invokedRole !== undefined) {
183
+ // When a protocol role is being invoked, we require that there is a matching `role` rule.
184
+ if (actionRule.role === invokedRole) {
185
+ // role is successfully invoked
186
+ return;
187
+ }
188
+ else {
189
+ continue;
190
+ }
191
+ }
192
+ // else we go through the actor (`who`) validation
193
+ // If `of` is not set, handle it as a special case
194
+ // NOTE: `of` is always set if `who` is set to `author` (we do this check in `validateRuleSetRecursively()`)
195
+ if (actionRule.who === ProtocolActor.Recipient && actionRule.of === undefined) {
196
+ // If the action rule specifies a recipient without `of` and the incoming message is authenticated:
197
+ // Author must be recipient of the record being accessed
198
+ let recordsWriteMessage;
199
+ if (incomingMessage.message.descriptor.method === DwnMethodName.Write) {
200
+ recordsWriteMessage = incomingMessage.message;
201
+ }
202
+ else {
203
+ // else the incoming message must be a `RecordsDelete` because only `co-update`, `co-delete`, `co-prune` are allowed recipient actions,
204
+ // (we do this check in `validateRuleSetRecursively()`)
205
+ // and we have already checked that the incoming message is not a `RecordsWrite` above which covers `co-update` path.
206
+ recordsWriteMessage = recordChain[recordChain.length - 1];
207
+ }
208
+ if (recordsWriteMessage.descriptor.recipient === author) {
209
+ return;
210
+ }
211
+ else {
212
+ continue;
213
+ }
214
+ }
215
+ // validate the actor is allowed by the current action rule
216
+ const ancestorRuleSuccess = await checkActor(author, actionRule, recordChain, protocolDefinition);
217
+ if (ancestorRuleSuccess) {
218
+ return;
219
+ }
220
+ }
221
+ // No action rules were satisfied, message is not authorized
222
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationActionNotAllowed, `Inbound message action Records${incomingMessageMethod} by author ${incomingMessage.author} not allowed.`);
223
+ }
224
+ /**
225
+ * Checks if the `who: 'author' | 'recipient'` action rule has a matching record in the record chain.
226
+ * For cross-protocol `of` references (e.g., `"threads:thread"`), matches against both the protocol URI
227
+ * and the protocol path of the ancestor record.
228
+ * @returns `true` if the action rule is satisfied; `false` otherwise.
229
+ */
230
+ export async function checkActor(author, actionRule, recordChain, composingDefinition) {
231
+ const ofValue = actionRule.of;
232
+ // `of` should always be defined when `checkActor` is called, but guard defensively
233
+ if (ofValue === undefined) {
234
+ return false;
235
+ }
236
+ let ancestorRecordsWrite;
237
+ if (isCrossProtocolRef(ofValue) && composingDefinition?.uses !== undefined) {
238
+ // Cross-protocol `of`: resolve alias to protocol URI and match by both protocol + protocolPath
239
+ const parsed = parseCrossProtocolRef(ofValue);
240
+ if (parsed !== undefined) {
241
+ const refProtocolUri = composingDefinition.uses[parsed.alias];
242
+ if (refProtocolUri !== undefined) {
243
+ ancestorRecordsWrite = recordChain.find((msg) => msg.descriptor.protocol === refProtocolUri && msg.descriptor.protocolPath === parsed.protocolPath);
244
+ }
245
+ }
246
+ }
247
+ else {
248
+ // Local `of`: match by protocolPath only (same protocol assumed)
249
+ ancestorRecordsWrite = recordChain.find((msg) => msg.descriptor.protocolPath === ofValue);
250
+ }
251
+ if (ancestorRecordsWrite === undefined) {
252
+ // No matching ancestor found in the record chain. Return false to allow the caller
253
+ // to continue evaluating other action rules that might authorize the request.
254
+ return false;
255
+ }
256
+ if (actionRule.who === ProtocolActor.Recipient) {
257
+ // author of the incoming message must be the recipient of the ancestor message
258
+ return author === ancestorRecordsWrite.descriptor.recipient;
259
+ }
260
+ else { // actionRule.who === ProtocolActor.Author
261
+ // author of the incoming message must be the author of the ancestor message
262
+ const ancestorAuthor = (await RecordsWrite.parse(ancestorRecordsWrite)).author;
263
+ return author === ancestorAuthor;
264
+ }
265
+ }
266
+ //# sourceMappingURL=protocol-authorization-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-authorization-action.js","sourceRoot":"","sources":["../../../../src/core/protocol-authorization-action.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,E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C,UAAU,CAAC,YAAY,KAAK,OAAO,CACxC,CAAC;IACJ,CAAC;IAED,IAAI,oBAAoB,KAAK,SAAS,EAAE,CAAC;QACvC,mFAAmF;QACnF,8EAA8E;QAC9E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,UAAU,CAAC,GAAG,KAAK,aAAa,CAAC,SAAS,EAAE,CAAC;QAC/C,+EAA+E;QAC/E,OAAO,MAAM,KAAK,oBAAoB,CAAC,UAAU,CAAC,SAAS,CAAC;IAC9D,CAAC;SAAM,CAAC,CAAC,0CAA0C;QACjD,4EAA4E;QAC5E,MAAM,cAAc,GAAG,CAAC,MAAM,YAAY,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC;QAC/E,OAAO,MAAM,KAAK,cAAc,CAAC;IACnC,CAAC;AACH,CAAC"}
@@ -0,0 +1,321 @@
1
+ import { ProtocolRecordLimitStrategy } from '../types/protocols-types.js';
2
+ import Ajv from 'ajv/dist/2020.js';
3
+ import { FilterUtility } from '../utils/filter.js';
4
+ import { Records } from '../utils/records.js';
5
+ import { DwnError, DwnErrorCode } from './dwn-error.js';
6
+ import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
7
+ import { getTypeName, parseCrossProtocolRef } from '../utils/protocols.js';
8
+ /**
9
+ * Verifies the `protocolPath` declared in the given message matches the path of actual record chain.
10
+ * For cross-protocol composition, the parent record may belong to a different protocol (resolved via `$ref` in the composing protocol).
11
+ * @throws {DwnError} if fails verification.
12
+ */
13
+ export async function verifyProtocolPathAndContextId(tenant, inboundMessage, messageStore, fetchProtocolDefinition, governingTimestamp) {
14
+ const declaredProtocolPath = inboundMessage.message.descriptor.protocolPath;
15
+ const declaredTypeName = getTypeName(declaredProtocolPath);
16
+ const parentId = inboundMessage.message.descriptor.parentId;
17
+ if (parentId === undefined) {
18
+ if (declaredProtocolPath !== declaredTypeName) {
19
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationParentlessIncorrectProtocolPath, `Declared protocol path '${declaredProtocolPath}' is not valid for records with no parent'.`);
20
+ }
21
+ return;
22
+ }
23
+ // Else `parentId` is defined, so we need to verify both protocolPath and contextId
24
+ // Determine the protocol URI for the parent query.
25
+ // If the parent path segment has a `$ref` in the composing protocol, the parent lives in a different protocol.
26
+ const childProtocol = inboundMessage.message.descriptor.protocol;
27
+ const parentProtocolUri = await resolveParentProtocolUri(tenant, childProtocol, declaredProtocolPath, messageStore, fetchProtocolDefinition, governingTimestamp);
28
+ // fetch the parent message
29
+ const query = {
30
+ isLatestBaseState: true, // NOTE: this filter is critical, to ensure are are not returning a deleted parent
31
+ interface: DwnInterfaceName.Records,
32
+ method: DwnMethodName.Write,
33
+ protocol: parentProtocolUri,
34
+ recordId: parentId
35
+ };
36
+ const { messages: parentMessages } = await messageStore.query(tenant, [query]);
37
+ const parentMessage = parentMessages[0];
38
+ if (parentMessage === undefined) {
39
+ // if this is a cross-protocol composition lookup, use a more descriptive error
40
+ if (parentProtocolUri !== childProtocol) {
41
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationCrossProtocolParentNotFound, `Could not find parent record '${parentId}' in protocol '${parentProtocolUri}' ` +
42
+ `for cross-protocol child at path '${declaredProtocolPath}'.`);
43
+ }
44
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationIncorrectProtocolPath, `Could not find matching parent record to verify declared protocol path '${declaredProtocolPath}'.`);
45
+ }
46
+ // verifying protocolPath of incoming message is a child of the parent message's protocolPath
47
+ const parentProtocolPath = parentMessage.descriptor.protocolPath;
48
+ const expectedProtocolPath = `${parentProtocolPath}/${declaredTypeName}`;
49
+ if (expectedProtocolPath !== declaredProtocolPath) {
50
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationIncorrectProtocolPath, `Could not find matching parent record to verify declared protocol path '${declaredProtocolPath}'.`);
51
+ }
52
+ // verifying contextId of incoming message is a child of the parent message's contextId
53
+ const expectedContextId = `${parentMessage.contextId}/${inboundMessage.message.recordId}`;
54
+ const actualContextId = inboundMessage.message.contextId;
55
+ if (actualContextId !== expectedContextId) {
56
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationIncorrectContextId, `Declared contextId '${actualContextId}' is not the same as expected: '${expectedContextId}'.`);
57
+ }
58
+ }
59
+ /**
60
+ * Resolves the protocol URI that should be used when querying for the parent record.
61
+ * For standard (non-composed) records, this is the same as the child's protocol.
62
+ * For cross-protocol composition, the parent may live in a different protocol
63
+ * (resolved via `$ref` in the composing protocol's definition).
64
+ *
65
+ * Logic: Given a child at protocolPath `a/b/c`, the parent is at `a/b`.
66
+ * Walk up the composing protocol's structure from root to `a/b`.
67
+ * If any segment along the way has a `$ref`, the parent (and its ancestors up to the `$ref` boundary)
68
+ * live in the referenced protocol. Specifically, the `$ref` at the topmost ancestor tells us
69
+ * the parent's protocol URI.
70
+ */
71
+ export async function resolveParentProtocolUri(tenant, childProtocolUri, childProtocolPath, messageStore, fetchProtocolDefinition, governingTimestamp) {
72
+ const segments = childProtocolPath.split('/');
73
+ // A root-level record (no `/` in path) has no parent or uses the same protocol
74
+ if (segments.length <= 1) {
75
+ return childProtocolUri;
76
+ }
77
+ // Fetch the composing protocol's definition at the governing timestamp
78
+ const composingDefinition = await fetchProtocolDefinition(tenant, childProtocolUri, messageStore, governingTimestamp);
79
+ // Walk the structure to find the parent's path segment
80
+ // The parent's position in the structure is at segments[0..n-2]
81
+ // We check if the first segment has a `$ref`, which means the parent is in a different protocol
82
+ const firstSegmentRuleSet = composingDefinition.structure[segments[0]];
83
+ if (firstSegmentRuleSet?.$ref !== undefined) {
84
+ const parsed = parseCrossProtocolRef(firstSegmentRuleSet.$ref);
85
+ if (parsed !== undefined && composingDefinition.uses !== undefined) {
86
+ const resolvedUri = composingDefinition.uses[parsed.alias];
87
+ if (resolvedUri !== undefined) {
88
+ // The parent path is within the `$ref` boundary — check if the parent IS the `$ref` node
89
+ // or is a descendant of it (which would still be in the composing protocol).
90
+ // If segments.length === 2, parent is at segments[0] which IS the $ref node → parent's protocol is the referenced one.
91
+ // If segments.length > 2, parent is at segments[0..n-2]. If segments[0] is $ref, the parent could be:
92
+ // - Still the $ref node itself (segments.length === 2) → referenced protocol
93
+ // - A child of the $ref node defined in the composing protocol (segments.length > 2) → composing protocol
94
+ if (segments.length === 2) {
95
+ // Parent is the $ref node itself (e.g., child is "thread/comment", parent is "thread")
96
+ return resolvedUri;
97
+ }
98
+ // else: parent is a deeper child defined in the composing protocol
99
+ return childProtocolUri;
100
+ }
101
+ }
102
+ }
103
+ return childProtocolUri;
104
+ }
105
+ /**
106
+ * Verifies the `dataFormat` and `schema` declared in the given message matches the type in the protocol.
107
+ * For cross-protocol composition, if the type is at a `$ref` position in the structure,
108
+ * the type definition is looked up in the referenced protocol's `types` map instead.
109
+ */
110
+ export async function verifyTypeWithComposition(tenant, inboundMessage, protocolDefinition, messageStore, fetchProtocolDefinition, governingTimestamp) {
111
+ const declaredProtocolPath = inboundMessage.descriptor.protocolPath;
112
+ const declaredTypeName = getTypeName(declaredProtocolPath);
113
+ // Resolve which protocol types map to use.
114
+ // If the first path segment has `$ref`, this record's type might be defined in a referenced protocol.
115
+ const protocolTypes = await resolveProtocolTypesForPath(tenant, declaredProtocolPath, protocolDefinition, messageStore, fetchProtocolDefinition, governingTimestamp);
116
+ verifyType(inboundMessage, protocolTypes, declaredTypeName);
117
+ }
118
+ /**
119
+ * Resolves the `ProtocolTypes` map that contains the type definition for the given protocol path.
120
+ * For non-composed records, this is the protocol definition's own `types` map.
121
+ * For records at a `$ref` position, this is the referenced protocol's `types` map.
122
+ */
123
+ export async function resolveProtocolTypesForPath(tenant, protocolPath, protocolDefinition, messageStore, fetchProtocolDefinition, governingTimestamp) {
124
+ const segments = protocolPath.split('/');
125
+ // Check if the first segment has a `$ref`
126
+ const firstSegmentRuleSet = protocolDefinition.structure[segments[0]];
127
+ if (firstSegmentRuleSet?.$ref !== undefined && segments.length === 1) {
128
+ // This record IS the $ref node itself — its type is defined in the referenced protocol
129
+ const parsed = parseCrossProtocolRef(firstSegmentRuleSet.$ref);
130
+ if (parsed !== undefined && protocolDefinition.uses !== undefined) {
131
+ const refProtocolUri = protocolDefinition.uses[parsed.alias];
132
+ if (refProtocolUri !== undefined) {
133
+ const refDefinition = await fetchProtocolDefinition(tenant, refProtocolUri, messageStore, governingTimestamp);
134
+ return refDefinition.types;
135
+ }
136
+ }
137
+ }
138
+ // Default: use the composing protocol's own types
139
+ return protocolDefinition.types;
140
+ }
141
+ /**
142
+ * Verifies the `dataFormat` and `schema` declared in the given message (if it is a RecordsWrite) matches dataFormat
143
+ * and schema of the type in the given protocol.
144
+ * @throws {DwnError} if fails verification.
145
+ */
146
+ export function verifyType(inboundMessage, protocolTypes, typeName) {
147
+ const declaredTypeName = typeName ?? getTypeName(inboundMessage.descriptor.protocolPath);
148
+ const typeNames = Object.keys(protocolTypes);
149
+ if (!typeNames.includes(declaredTypeName)) {
150
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationInvalidType, `record with type ${declaredTypeName} not allowed in protocol`);
151
+ }
152
+ const protocolType = protocolTypes[declaredTypeName];
153
+ // no `schema` specified in protocol definition means that any schema is allowed
154
+ const { schema } = inboundMessage.descriptor;
155
+ if (protocolType.schema !== undefined && protocolType.schema !== schema) {
156
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationInvalidSchema, `type '${declaredTypeName}' must have schema '${protocolType.schema}', \
157
+ instead has '${schema}'`);
158
+ }
159
+ // no `dataFormats` specified in protocol definition means that all dataFormats are allowed
160
+ const { dataFormat } = inboundMessage.descriptor;
161
+ if (protocolType.dataFormats !== undefined && !protocolType.dataFormats.includes(dataFormat)) {
162
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationIncorrectDataFormat, `type '${declaredTypeName}' must have data format in (${protocolType.dataFormats}), \
163
+ instead has '${dataFormat}'`);
164
+ }
165
+ // enforce encryption when the protocol type requires it
166
+ if (protocolType.encryptionRequired === true && inboundMessage.encryption === undefined) {
167
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationEncryptionRequired, `type '${declaredTypeName}' requires encryption but message has no encryption metadata`);
168
+ }
169
+ }
170
+ /**
171
+ * Verifies that writes adhere to the $size constraints if provided
172
+ * @throws {Error} if size is exceeded.
173
+ */
174
+ export function verifySizeLimit(incomingMessage, ruleSet) {
175
+ const { min = 0, max } = ruleSet.$size || {};
176
+ const dataSize = incomingMessage.message.descriptor.dataSize;
177
+ if (dataSize < min) {
178
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationMinSizeInvalid, `data size ${dataSize} is less than allowed ${min}`);
179
+ }
180
+ if (max === undefined) {
181
+ return;
182
+ }
183
+ if (dataSize > max) {
184
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationMaxSizeInvalid, `data size ${dataSize} is more than allowed ${max}`);
185
+ }
186
+ }
187
+ /**
188
+ * Verifies record tags against the `$tags` schema in the rule set using JSON Schema (Ajv).
189
+ * Checks required tags, additional properties, and schema conformance.
190
+ */
191
+ export function verifyTagsIfNeeded(incomingMessage, ruleSet) {
192
+ if (ruleSet.$tags !== undefined) {
193
+ const { tags = {}, protocol, protocolPath } = incomingMessage.message.descriptor;
194
+ const { $allowUndefinedTags, $requiredTags, ...properties } = ruleSet.$tags;
195
+ // if $allowUndefinedTags is set to false and there are properties not defined in the schema, an error is thrown
196
+ const additionalProperties = $allowUndefinedTags || false;
197
+ // if $requiredTags is set, all required tags must be present
198
+ const required = $requiredTags || [];
199
+ const ajv = new Ajv.default();
200
+ const compiledTags = ajv.compile({
201
+ type: 'object',
202
+ properties,
203
+ required,
204
+ additionalProperties,
205
+ });
206
+ const validSchema = compiledTags(tags);
207
+ if (!validSchema) {
208
+ // the `dataVar` is used to add a qualifier to the error message.
209
+ // For example. If the error is related to a tag `status` in a protocol `https://example.protocol` with the protocolPath `example/path`
210
+ // the error would be described as `https://example.protocol/example/path/$tags/status'
211
+ // without this decorator it would show up as `data/status` which may be confusing.
212
+ const schemaError = ajv.errorsText(compiledTags.errors, { dataVar: `${protocol}/${protocolPath}/$tags` });
213
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema, `tags schema validation error: ${schemaError}`);
214
+ }
215
+ }
216
+ }
217
+ /**
218
+ * If the given RecordsWrite is not a role record, this method does nothing and succeeds immediately.
219
+ *
220
+ * Else it verifies the validity of the given `RecordsWrite` as a role record, including:
221
+ * 1. The same role has not been assigned to the same entity/recipient.
222
+ */
223
+ export async function verifyAsRoleRecordIfNeeded(tenant, incomingMessage, ruleSet, messageStore) {
224
+ if (!ruleSet.$role) {
225
+ return;
226
+ }
227
+ // else this is a role record
228
+ const incomingRecordsWrite = incomingMessage;
229
+ const recipient = incomingRecordsWrite.message.descriptor.recipient;
230
+ if (recipient === undefined) {
231
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationRoleMissingRecipient, 'Role records must have a recipient');
232
+ }
233
+ const protocolPath = incomingRecordsWrite.message.descriptor.protocolPath;
234
+ const filter = {
235
+ interface: DwnInterfaceName.Records,
236
+ method: DwnMethodName.Write,
237
+ isLatestBaseState: true,
238
+ protocol: incomingRecordsWrite.message.descriptor.protocol,
239
+ protocolPath,
240
+ recipient,
241
+ };
242
+ const parentContextId = Records.getParentContextFromOfContextId(incomingRecordsWrite.message.contextId);
243
+ // if this is not the root record, add a prefix filter to the query
244
+ if (parentContextId !== '') {
245
+ const prefixFilter = FilterUtility.constructPrefixFilterAsRangeFilter(parentContextId);
246
+ filter.contextId = prefixFilter;
247
+ }
248
+ const { messages: matchingMessages } = await messageStore.query(tenant, [filter]);
249
+ const matchingRecords = matchingMessages;
250
+ const matchingRecordsExceptIncomingRecordId = matchingRecords.filter((recordsWriteMessage) => recordsWriteMessage.recordId !== incomingRecordsWrite.message.recordId);
251
+ if (matchingRecordsExceptIncomingRecordId.length > 0) {
252
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationDuplicateRoleRecipient, `DID '${recipient}' is already recipient of a role record at protocol path '${protocolPath} under the parent context ${parentContextId}.`);
253
+ }
254
+ }
255
+ /**
256
+ * Verifies that a new record creation does not exceed the `$recordLimit` defined in the rule set.
257
+ *
258
+ * This check only applies to initial writes (new records). Updates to existing records are not counted.
259
+ * The count is scoped to the same `protocol + protocolPath` within the parent context:
260
+ * - For root-level records: counted across the entire protocol for the tenant.
261
+ * - For nested records: counted within the parent record's context.
262
+ *
263
+ * @throws {DwnError} with `ProtocolAuthorizationRecordLimitExceeded` if the limit is reached and strategy is `reject`.
264
+ * @throws {DwnError} with `ProtocolAuthorizationRecordLimitStrategyNotImplemented` if strategy is not yet implemented.
265
+ */
266
+ export async function verifyRecordLimit(tenant, incomingMessage, ruleSet, messageStore) {
267
+ if (ruleSet.$recordLimit === undefined) {
268
+ return;
269
+ }
270
+ // Only enforce on initial writes — updates to existing records do not count as new records.
271
+ const isInitialWrite = await incomingMessage.isInitialWrite();
272
+ if (!isInitialWrite) {
273
+ return;
274
+ }
275
+ const { max, strategy } = ruleSet.$recordLimit;
276
+ // Build a filter to count existing records at the same protocol path and parent context.
277
+ const protocolPath = incomingMessage.message.descriptor.protocolPath;
278
+ const filter = {
279
+ interface: DwnInterfaceName.Records,
280
+ method: DwnMethodName.Write,
281
+ isLatestBaseState: true,
282
+ protocol: incomingMessage.message.descriptor.protocol,
283
+ protocolPath,
284
+ };
285
+ // Scope by parent context for nested records.
286
+ const parentContextId = Records.getParentContextFromOfContextId(incomingMessage.message.contextId);
287
+ if (parentContextId !== '') {
288
+ const prefixFilter = FilterUtility.constructPrefixFilterAsRangeFilter(parentContextId);
289
+ filter.contextId = prefixFilter;
290
+ }
291
+ const existingCount = await messageStore.count(tenant, [filter]);
292
+ if (existingCount >= max) {
293
+ if (strategy === ProtocolRecordLimitStrategy.Reject) {
294
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationRecordLimitExceeded, `record limit of ${max} reached at protocol path '${protocolPath}'` +
295
+ `${parentContextId !== '' ? ` under parent context '${parentContextId}'` : ''}` +
296
+ `: new records are rejected until existing records are deleted.`);
297
+ }
298
+ // Future strategies (e.g. purgeOldest) will be implemented here.
299
+ // For now, any non-reject strategy that somehow passes schema validation is rejected.
300
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationRecordLimitStrategyNotImplemented, `record limit strategy '${strategy}' is not yet implemented.`);
301
+ }
302
+ }
303
+ /**
304
+ * Verifies that an update is not attempted on a record whose protocol path has `$immutable: true`.
305
+ *
306
+ * Only non-initial writes (updates) are rejected — initial writes are always allowed.
307
+ * `RecordsDelete` is not affected by this check; immutability prevents data mutation, not removal.
308
+ *
309
+ * @throws {DwnError} with `ProtocolAuthorizationImmutableRecord` if an update is attempted on an immutable record.
310
+ */
311
+ export async function verifyImmutability(incomingMessage, ruleSet) {
312
+ if (ruleSet.$immutable !== true) {
313
+ return;
314
+ }
315
+ const isInitialWrite = await incomingMessage.isInitialWrite();
316
+ if (isInitialWrite) {
317
+ return;
318
+ }
319
+ throw new DwnError(DwnErrorCode.ProtocolAuthorizationImmutableRecord, `record at protocol path '${incomingMessage.message.descriptor.protocolPath}' is immutable: updates are not allowed.`);
320
+ }
321
+ //# sourceMappingURL=protocol-authorization-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-authorization-validation.js","sourceRoot":"","sources":["../../../../src/core/protocol-authorization-validation.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAI1E,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAI3E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAClD,M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