@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
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import dexProtocolDefinition from '../vectors/protocol-definitions/dex.json' with { type: 'json' };
11
2
  import minimalProtocolDefinition from '../vectors/protocol-definitions/minimal.json' with { type: 'json' };
12
3
  import sinon from 'sinon';
@@ -15,7 +6,7 @@ import { lexicographicalCompare } from '../../src/utils/string.js';
15
6
  import { Message } from '../../src/core/message.js';
16
7
  import { ProtocolAction } from '../../src/types/protocols-types.js';
17
8
  import { TestDataGenerator } from '../utils/test-data-generator.js';
18
- import { TestEventStream } from '../test-event-stream.js';
9
+ import { TestEventLog } from '../test-event-stream.js';
19
10
  import { TestStores } from '../test-stores.js';
20
11
  import { TestStubGenerator } from '../utils/test-stub-generator.js';
21
12
  import { Time } from '../../src/utils/time.js';
@@ -29,202 +20,209 @@ export function testProtocolsConfigureHandler() {
29
20
  let dataStore;
30
21
  let resumableTaskStore;
31
22
  let stateIndex;
32
- let eventStream;
23
+ let eventLog;
33
24
  let dwn;
34
25
  describe('functional tests', () => {
35
26
  // important to follow the `before` and `after` pattern to initialize and clean the stores in tests
36
27
  // so that different test suites can reuse the same backend store for testing
37
- beforeAll(() => __awaiter(this, void 0, void 0, function* () {
28
+ beforeAll(async () => {
38
29
  didResolver = new UniversalResolver({ didResolvers: [DidKey] });
39
30
  const stores = TestStores.get();
40
31
  messageStore = stores.messageStore;
41
32
  dataStore = stores.dataStore;
42
33
  resumableTaskStore = stores.resumableTaskStore;
43
34
  stateIndex = stores.stateIndex;
44
- eventStream = TestEventStream.get();
45
- dwn = yield Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
46
- }));
47
- beforeEach(() => __awaiter(this, void 0, void 0, function* () {
35
+ eventLog = TestEventLog.get();
36
+ dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventLog, resumableTaskStore });
37
+ });
38
+ beforeEach(async () => {
48
39
  sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
49
40
  // clean up before each test rather than after so that a test does not depend on other tests to do the clean up
50
- yield messageStore.clear();
51
- yield dataStore.clear();
52
- yield resumableTaskStore.clear();
53
- yield stateIndex.clear();
54
- }));
55
- afterAll(() => __awaiter(this, void 0, void 0, function* () {
56
- yield dwn.close();
57
- }));
58
- it('should allow a protocol definition with schema or dataFormat omitted', () => __awaiter(this, void 0, void 0, function* () {
59
- const alice = yield TestDataGenerator.generateDidKeyPersona();
41
+ await messageStore.clear();
42
+ await dataStore.clear();
43
+ await resumableTaskStore.clear();
44
+ await stateIndex.clear();
45
+ });
46
+ afterAll(async () => {
47
+ await dwn.close();
48
+ });
49
+ it('should allow a protocol definition with schema or dataFormat omitted', async () => {
50
+ const alice = await TestDataGenerator.generateDidKeyPersona();
60
51
  const protocolDefinition = minimalProtocolDefinition;
61
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
52
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
62
53
  author: alice,
63
54
  protocolDefinition,
64
55
  });
65
- const reply = yield dwn.processMessage(alice.did, protocolsConfig.message);
56
+ const reply = await dwn.processMessage(alice.did, protocolsConfig.message);
66
57
  expect(reply.status.code).toBe(202);
67
- }));
68
- it('should return 400 if more than 1 signature is provided in `authorization`', () => __awaiter(this, void 0, void 0, function* () {
69
- const { author, message, protocolsConfigure } = yield TestDataGenerator.generateProtocolsConfigure();
58
+ });
59
+ it('should return 400 if more than 1 signature is provided in `authorization`', async () => {
60
+ const { author, message, protocolsConfigure } = await TestDataGenerator.generateProtocolsConfigure();
70
61
  const tenant = author.did;
71
62
  // intentionally create more than one signature, which is not allowed
72
- const extraRandomPersona = yield TestDataGenerator.generatePersona();
63
+ const extraRandomPersona = await TestDataGenerator.generatePersona();
73
64
  const signer1 = Jws.createSigner(author);
74
65
  const signer2 = Jws.createSigner(extraRandomPersona);
75
66
  const signaturePayloadBytes = Encoder.objectToBytes(protocolsConfigure.signaturePayload);
76
- const jwsBuilder = yield GeneralJwsBuilder.create(signaturePayloadBytes, [signer1, signer2]);
67
+ const jwsBuilder = await GeneralJwsBuilder.create(signaturePayloadBytes, [signer1, signer2]);
77
68
  message.authorization = { signature: jwsBuilder.getJws() };
78
69
  TestStubGenerator.stubDidResolver(didResolver, [author]);
79
- const reply = yield dwn.processMessage(tenant, message);
70
+ const reply = await dwn.processMessage(tenant, message);
80
71
  expect(reply.status.code).toBe(400);
81
72
  expect(reply.status.detail).toContain('expected no more than 1 signature');
82
- }));
83
- it('should return 401 if auth fails', () => __awaiter(this, void 0, void 0, function* () {
84
- const alice = yield TestDataGenerator.generateDidKeyPersona();
85
- const { message } = yield TestDataGenerator.generateProtocolsConfigure({ author: alice });
73
+ });
74
+ it('should return 401 if auth fails', async () => {
75
+ const alice = await TestDataGenerator.generateDidKeyPersona();
76
+ const { message } = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
86
77
  // use a bad signature to fail authentication
87
- const badSignature = yield TestDataGenerator.randomSignatureString();
78
+ const badSignature = await TestDataGenerator.randomSignatureString();
88
79
  message.authorization.signature.signatures[0].signature = badSignature;
89
- const reply = yield dwn.processMessage(alice.did, message);
80
+ const reply = await dwn.processMessage(alice.did, message);
90
81
  expect(reply.status.code).toBe(401);
91
82
  expect(reply.status.detail).toContain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
92
- }));
93
- it('should store all protocol versions and query should only return the latest', () => __awaiter(this, void 0, void 0, function* () {
94
- var _a;
95
- const alice = yield TestDataGenerator.generateDidKeyPersona();
83
+ });
84
+ it('should store all protocol versions and query should only return the latest', async () => {
85
+ const alice = await TestDataGenerator.generateDidKeyPersona();
96
86
  const protocolDefinition = minimalProtocolDefinition;
97
- const oldProtocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
87
+ const oldProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
98
88
  author: alice,
99
89
  protocolDefinition,
100
90
  });
101
- yield Time.minimalSleep();
102
- const middleProtocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
91
+ await Time.minimalSleep();
92
+ const middleProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
103
93
  author: alice,
104
94
  protocolDefinition,
105
95
  });
106
96
  // first ProtocolsConfigure
107
- const reply1 = yield dwn.processMessage(alice.did, middleProtocolsConfigure.message);
97
+ const reply1 = await dwn.processMessage(alice.did, middleProtocolsConfigure.message);
108
98
  expect(reply1.status.code).toBe(202);
109
99
  // older messages are also accepted (stored as historical versions)
110
- const reply2 = yield dwn.processMessage(alice.did, oldProtocolsConfigure.message);
100
+ const reply2 = await dwn.processMessage(alice.did, oldProtocolsConfigure.message);
111
101
  expect(reply2.status.code).toBe(202);
112
102
  // newer message is also accepted and becomes the latest
113
- const newProtocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
103
+ const newProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
114
104
  author: alice,
115
105
  protocolDefinition,
116
106
  });
117
- const reply3 = yield dwn.processMessage(alice.did, newProtocolsConfigure.message);
107
+ const reply3 = await dwn.processMessage(alice.did, newProtocolsConfigure.message);
118
108
  expect(reply3.status.code).toBe(202);
119
109
  // only the newest protocol should be returned by query (ProtocolsQuery returns only latest)
120
- const queryMessageData = yield TestDataGenerator.generateProtocolsQuery({
110
+ const queryMessageData = await TestDataGenerator.generateProtocolsQuery({
121
111
  author: alice,
122
112
  filter: { protocol: protocolDefinition.protocol }
123
113
  });
124
- const queryReply = yield dwn.processMessage(alice.did, queryMessageData.message);
114
+ const queryReply = await dwn.processMessage(alice.did, queryMessageData.message);
125
115
  expect(queryReply.status.code).toBe(200);
126
- expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
127
- }));
128
- it('should store all protocol versions with identical timestamps and query should only return the newest (by CID tiebreak)', () => __awaiter(this, void 0, void 0, function* () {
129
- var _a;
130
- const alice = yield TestDataGenerator.generateDidKeyPersona();
116
+ expect(queryReply.entries?.length).toBe(1);
117
+ });
118
+ it('should store all protocol versions with identical timestamps and query should only return the newest (by CID tiebreak)', async () => {
119
+ const alice = await TestDataGenerator.generateDidKeyPersona();
131
120
  // Alter each protocol slightly to create lexicographic difference between them
132
- const protocolDefinition1 = Object.assign(Object.assign({}, minimalProtocolDefinition), { types: Object.assign(Object.assign({}, minimalProtocolDefinition.types), { foo1: { dataFormats: ['bar1'] } }) });
133
- const protocolDefinition2 = Object.assign(Object.assign({}, minimalProtocolDefinition), { types: Object.assign(Object.assign({}, minimalProtocolDefinition.types), { foo2: { dataFormats: ['bar2'] } }) });
134
- const protocolDefinition3 = Object.assign(Object.assign({}, minimalProtocolDefinition), { types: Object.assign(Object.assign({}, minimalProtocolDefinition.types), { foo3: { dataFormats: ['bar3'] } }) });
121
+ const protocolDefinition1 = {
122
+ ...minimalProtocolDefinition,
123
+ types: { ...minimalProtocolDefinition.types, foo1: { dataFormats: ['bar1'] } }
124
+ };
125
+ const protocolDefinition2 = {
126
+ ...minimalProtocolDefinition,
127
+ types: { ...minimalProtocolDefinition.types, foo2: { dataFormats: ['bar2'] } }
128
+ };
129
+ const protocolDefinition3 = {
130
+ ...minimalProtocolDefinition,
131
+ types: { ...minimalProtocolDefinition.types, foo3: { dataFormats: ['bar3'] } }
132
+ };
135
133
  // Create three `ProtocolsConfigure` with identical timestamp
136
- const messageData1 = yield TestDataGenerator.generateProtocolsConfigure({
134
+ const messageData1 = await TestDataGenerator.generateProtocolsConfigure({
137
135
  author: alice,
138
136
  protocolDefinition: protocolDefinition1
139
137
  });
140
- const messageData2 = yield TestDataGenerator.generateProtocolsConfigure({
138
+ const messageData2 = await TestDataGenerator.generateProtocolsConfigure({
141
139
  author: alice,
142
140
  protocolDefinition: protocolDefinition2,
143
141
  messageTimestamp: messageData1.message.descriptor.messageTimestamp
144
142
  });
145
- const messageData3 = yield TestDataGenerator.generateProtocolsConfigure({
143
+ const messageData3 = await TestDataGenerator.generateProtocolsConfigure({
146
144
  author: alice,
147
145
  protocolDefinition: protocolDefinition3,
148
146
  messageTimestamp: messageData1.message.descriptor.messageTimestamp
149
147
  });
150
148
  const messageDataWithCid = [];
151
149
  for (const messageData of [messageData1, messageData2, messageData3]) {
152
- const cid = yield Message.getCid(messageData.message);
153
- messageDataWithCid.push(Object.assign({ cid }, messageData));
150
+ const cid = await Message.getCid(messageData.message);
151
+ messageDataWithCid.push({ cid, ...messageData });
154
152
  }
155
153
  // sort the message in lexicographic order
156
154
  const [lowestProtocolsConfigure, middleProtocolsConfigure, highestProtocolsConfigure] = messageDataWithCid.sort((messageDataA, messageDataB) => { return lexicographicalCompare(messageDataA.cid, messageDataB.cid); });
157
155
  // write the protocol with the middle lexicographic value
158
- const reply1 = yield dwn.processMessage(alice.did, middleProtocolsConfigure.message);
156
+ const reply1 = await dwn.processMessage(alice.did, middleProtocolsConfigure.message);
159
157
  expect(reply1.status.code).toBe(202);
160
158
  // all versions are accepted (stored as historical versions)
161
- const reply2 = yield dwn.processMessage(alice.did, lowestProtocolsConfigure.message);
159
+ const reply2 = await dwn.processMessage(alice.did, lowestProtocolsConfigure.message);
162
160
  expect(reply2.status.code).toBe(202);
163
161
  // highest lexicographic value is also accepted and becomes the latest
164
- const reply3 = yield dwn.processMessage(alice.did, highestProtocolsConfigure.message);
162
+ const reply3 = await dwn.processMessage(alice.did, highestProtocolsConfigure.message);
165
163
  expect(reply3.status.code).toBe(202);
166
164
  // query should only return the latest protocol definition (highest by CID tiebreak)
167
- const queryMessageData = yield TestDataGenerator.generateProtocolsQuery({
165
+ const queryMessageData = await TestDataGenerator.generateProtocolsQuery({
168
166
  author: alice,
169
167
  filter: { protocol: protocolDefinition1.protocol }
170
168
  });
171
- const queryReply = yield dwn.processMessage(alice.did, queryMessageData.message);
169
+ const queryReply = await dwn.processMessage(alice.did, queryMessageData.message);
172
170
  expect(queryReply.status.code).toBe(200);
173
- expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
174
- }));
175
- it('should return 400 if protocol is not normalized', () => __awaiter(this, void 0, void 0, function* () {
176
- const alice = yield TestDataGenerator.generateDidKeyPersona();
171
+ expect(queryReply.entries?.length).toBe(1);
172
+ });
173
+ it('should return 400 if protocol is not normalized', async () => {
174
+ const alice = await TestDataGenerator.generateDidKeyPersona();
177
175
  // query for non-normalized protocol
178
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
176
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
179
177
  author: alice,
180
178
  protocolDefinition: minimalProtocolDefinition
181
179
  });
182
180
  // overwrite protocol because #create auto-normalizes protocol
183
181
  protocolsConfig.message.descriptor.definition.protocol = 'example.com/';
184
182
  // Re-create auth because we altered the descriptor after signing
185
- protocolsConfig.message.authorization = yield Message.createAuthorization({
183
+ protocolsConfig.message.authorization = await Message.createAuthorization({
186
184
  descriptor: protocolsConfig.message.descriptor,
187
185
  signer: Jws.createSigner(alice)
188
186
  });
189
187
  // Send records write message
190
- const reply = yield dwn.processMessage(alice.did, protocolsConfig.message);
188
+ const reply = await dwn.processMessage(alice.did, protocolsConfig.message);
191
189
  expect(reply.status.code).toBe(400);
192
190
  expect(reply.status.detail).toContain(DwnErrorCode.UrlProtocolNotNormalized);
193
- }));
194
- it('should return 400 if schema is not normalized', () => __awaiter(this, void 0, void 0, function* () {
195
- const alice = yield TestDataGenerator.generateDidKeyPersona();
191
+ });
192
+ it('should return 400 if schema is not normalized', async () => {
193
+ const alice = await TestDataGenerator.generateDidKeyPersona();
196
194
  const protocolDefinition = dexProtocolDefinition;
197
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
195
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
198
196
  author: alice,
199
197
  protocolDefinition,
200
198
  });
201
199
  // overwrite schema because #create auto-normalizes schema
202
200
  protocolsConfig.message.descriptor.definition.types.ask.schema = 'ask';
203
201
  // Re-create auth because we altered the descriptor after signing
204
- protocolsConfig.message.authorization = yield Message.createAuthorization({
202
+ protocolsConfig.message.authorization = await Message.createAuthorization({
205
203
  descriptor: protocolsConfig.message.descriptor,
206
204
  signer: Jws.createSigner(alice)
207
205
  });
208
206
  // Send records write message
209
- const reply = yield dwn.processMessage(alice.did, protocolsConfig.message);
207
+ const reply = await dwn.processMessage(alice.did, protocolsConfig.message);
210
208
  expect(reply.status.code).toBe(400);
211
209
  expect(reply.status.detail).toContain(DwnErrorCode.UrlSchemaNotNormalized);
212
- }));
213
- it('rejects non-tenant non-granted ProtocolsConfigures with 401', () => __awaiter(this, void 0, void 0, function* () {
210
+ });
211
+ it('rejects non-tenant non-granted ProtocolsConfigures with 401', async () => {
214
212
  // Bob tries to ProtocolsConfigure to Alice's DWN without a permission grant
215
- const alice = yield TestDataGenerator.generateDidKeyPersona();
216
- const bob = yield TestDataGenerator.generateDidKeyPersona();
213
+ const alice = await TestDataGenerator.generateDidKeyPersona();
214
+ const bob = await TestDataGenerator.generateDidKeyPersona();
217
215
  const protocolDefinition = dexProtocolDefinition;
218
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
216
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
219
217
  author: bob,
220
218
  protocolDefinition,
221
219
  });
222
- const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
220
+ const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfig.message);
223
221
  expect(protocolsConfigureReply.status.code).toBe(401);
224
222
  expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureAuthorizationFailed);
225
- }));
226
- it('should reject ProtocolsConfigure with action rule containing duplicated actor (`who` or `who` + `of` combination) within a rule set', () => __awaiter(this, void 0, void 0, function* () {
227
- const alice = yield TestDataGenerator.generateDidKeyPersona();
223
+ });
224
+ it('should reject ProtocolsConfigure with action rule containing duplicated actor (`who` or `who` + `of` combination) within a rule set', async () => {
225
+ const alice = await TestDataGenerator.generateDidKeyPersona();
228
226
  const protocolDefinition = {
229
227
  protocol: 'http://foo-bar',
230
228
  published: true,
@@ -254,12 +252,12 @@ export function testProtocolsConfigureHandler() {
254
252
  messageTimestamp: Time.getCurrentTimestamp(),
255
253
  definition: protocolDefinition
256
254
  };
257
- const authorization = yield Message.createAuthorization({
255
+ const authorization = await Message.createAuthorization({
258
256
  descriptor,
259
257
  signer: Jws.createSigner(alice)
260
258
  });
261
259
  const protocolsConfigureMessage = { descriptor, authorization };
262
- const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
260
+ const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
263
261
  expect(protocolsConfigureReply.status.code).toBe(400);
264
262
  expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateActorInRuleSet);
265
263
  // similar test as above but with `of` property
@@ -296,17 +294,17 @@ export function testProtocolsConfigureHandler() {
296
294
  messageTimestamp: Time.getCurrentTimestamp(),
297
295
  definition: protocolDefinition2
298
296
  };
299
- const authorization2 = yield Message.createAuthorization({
297
+ const authorization2 = await Message.createAuthorization({
300
298
  descriptor: descriptor2,
301
299
  signer: Jws.createSigner(alice)
302
300
  });
303
301
  const protocolsConfigureMessage2 = { descriptor: descriptor2, authorization: authorization2 };
304
- const protocolsConfigure2Reply = yield dwn.processMessage(alice.did, protocolsConfigureMessage2);
302
+ const protocolsConfigure2Reply = await dwn.processMessage(alice.did, protocolsConfigureMessage2);
305
303
  expect(protocolsConfigure2Reply.status.code).toBe(400);
306
304
  expect(protocolsConfigure2Reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateActorInRuleSet);
307
- }));
308
- it('should reject ProtocolsConfigure with action rule containing duplicated role within a rule set', () => __awaiter(this, void 0, void 0, function* () {
309
- const alice = yield TestDataGenerator.generateDidKeyPersona();
305
+ });
306
+ it('should reject ProtocolsConfigure with action rule containing duplicated role within a rule set', async () => {
307
+ const alice = await TestDataGenerator.generateDidKeyPersona();
310
308
  const protocolDefinition = {
311
309
  protocol: 'http://foo',
312
310
  published: true,
@@ -340,17 +338,17 @@ export function testProtocolsConfigureHandler() {
340
338
  messageTimestamp: Time.getCurrentTimestamp(),
341
339
  definition: protocolDefinition
342
340
  };
343
- const authorization = yield Message.createAuthorization({
341
+ const authorization = await Message.createAuthorization({
344
342
  descriptor,
345
343
  signer: Jws.createSigner(alice)
346
344
  });
347
345
  const protocolsConfigureMessage = { descriptor, authorization };
348
- const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
346
+ const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
349
347
  expect(protocolsConfigureReply.status.code).toBe(400);
350
348
  expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureDuplicateRoleInRuleSet);
351
- }));
352
- it('should reject ProtocolsConfigure with action rule `of` pointing to a sibling type (not an ancestor)', () => __awaiter(this, void 0, void 0, function* () {
353
- const alice = yield TestDataGenerator.generateDidKeyPersona();
349
+ });
350
+ it('should reject ProtocolsConfigure with action rule `of` pointing to a sibling type (not an ancestor)', async () => {
351
+ const alice = await TestDataGenerator.generateDidKeyPersona();
354
352
  // `bar` and `baz` are siblings under `foo`, so `baz` action rule cannot reference `of: 'foo/bar'`
355
353
  const protocolDefinition = {
356
354
  protocol: 'http://example.com/sibling-of-test',
@@ -382,17 +380,17 @@ export function testProtocolsConfigureHandler() {
382
380
  messageTimestamp: Time.getCurrentTimestamp(),
383
381
  definition: protocolDefinition
384
382
  };
385
- const authorization = yield Message.createAuthorization({
383
+ const authorization = await Message.createAuthorization({
386
384
  descriptor,
387
385
  signer: Jws.createSigner(alice)
388
386
  });
389
387
  const protocolsConfigureMessage = { descriptor, authorization };
390
- const reply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
388
+ const reply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
391
389
  expect(reply.status.code).toBe(400);
392
390
  expect(reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureInvalidActionOfNotAnAncestor);
393
- }));
394
- it('should reject ProtocolsConfigure with action rule `of` pointing to an unrelated type', () => __awaiter(this, void 0, void 0, function* () {
395
- const alice = yield TestDataGenerator.generateDidKeyPersona();
391
+ });
392
+ it('should reject ProtocolsConfigure with action rule `of` pointing to an unrelated type', async () => {
393
+ const alice = await TestDataGenerator.generateDidKeyPersona();
396
394
  // `comment` is a top-level type unrelated to the nested `thread/reply` path
397
395
  const protocolDefinition = {
398
396
  protocol: 'http://example.com/unrelated-of-test',
@@ -423,17 +421,17 @@ export function testProtocolsConfigureHandler() {
423
421
  messageTimestamp: Time.getCurrentTimestamp(),
424
422
  definition: protocolDefinition
425
423
  };
426
- const authorization = yield Message.createAuthorization({
424
+ const authorization = await Message.createAuthorization({
427
425
  descriptor,
428
426
  signer: Jws.createSigner(alice)
429
427
  });
430
428
  const protocolsConfigureMessage = { descriptor, authorization };
431
- const reply = yield dwn.processMessage(alice.did, protocolsConfigureMessage);
429
+ const reply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
432
430
  expect(reply.status.code).toBe(400);
433
431
  expect(reply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureInvalidActionOfNotAnAncestor);
434
- }));
435
- it('should accept ProtocolsConfigure with action rule `of` pointing to itself (same protocol path)', () => __awaiter(this, void 0, void 0, function* () {
436
- const alice = yield TestDataGenerator.generateDidKeyPersona();
432
+ });
433
+ it('should accept ProtocolsConfigure with action rule `of` pointing to itself (same protocol path)', async () => {
434
+ const alice = await TestDataGenerator.generateDidKeyPersona();
437
435
  // `of` pointing to the same protocol path is valid: "the author of this record can update it"
438
436
  const protocolDefinition = {
439
437
  protocol: 'http://example.com/self-of-test',
@@ -456,15 +454,15 @@ export function testProtocolsConfigureHandler() {
456
454
  }
457
455
  }
458
456
  };
459
- const protocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
457
+ const protocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
460
458
  author: alice,
461
459
  protocolDefinition,
462
460
  });
463
- const reply = yield dwn.processMessage(alice.did, protocolsConfigure.message);
461
+ const reply = await dwn.processMessage(alice.did, protocolsConfigure.message);
464
462
  expect(reply.status.code).toBe(202);
465
- }));
466
- it('should accept ProtocolsConfigure with action rule `of` pointing to a valid ancestor', () => __awaiter(this, void 0, void 0, function* () {
467
- const alice = yield TestDataGenerator.generateDidKeyPersona();
463
+ });
464
+ it('should accept ProtocolsConfigure with action rule `of` pointing to a valid ancestor', async () => {
465
+ const alice = await TestDataGenerator.generateDidKeyPersona();
468
466
  // `of: 'thread'` is a valid ancestor of `thread/reply/reaction`
469
467
  const protocolDefinition = {
470
468
  protocol: 'http://example.com/valid-ancestor-of-test',
@@ -497,138 +495,147 @@ export function testProtocolsConfigureHandler() {
497
495
  }
498
496
  }
499
497
  };
500
- const protocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
498
+ const protocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
501
499
  author: alice,
502
500
  protocolDefinition,
503
501
  });
504
- const reply = yield dwn.processMessage(alice.did, protocolsConfigure.message);
502
+ const reply = await dwn.processMessage(alice.did, protocolsConfigure.message);
505
503
  expect(reply.status.code).toBe(202);
506
- }));
504
+ });
507
505
  describe('Grant authorization', () => {
508
- it('allows an external party to ProtocolsConfigure only if they have a valid grant', () => __awaiter(this, void 0, void 0, function* () {
506
+ it('allows an external party to ProtocolsConfigure only if they have a valid grant', async () => {
509
507
  // scenario:
510
508
  // 1. Alice grants Bob the access to ProtocolsConfigure on her DWN
511
509
  // 2. Verify Bob can perform a ProtocolsConfigure
512
510
  // 3. Verify that Mallory cannot to use Bob's permission grant to gain access to Alice's DWN
513
511
  // 4. Alice revokes Bob's grant
514
512
  // 5. Verify Bob cannot perform ProtocolsConfigure with the revoked grant
515
- const alice = yield TestDataGenerator.generateDidKeyPersona();
516
- const bob = yield TestDataGenerator.generateDidKeyPersona();
517
- const mallory = yield TestDataGenerator.generateDidKeyPersona();
513
+ const alice = await TestDataGenerator.generateDidKeyPersona();
514
+ const bob = await TestDataGenerator.generateDidKeyPersona();
515
+ const mallory = await TestDataGenerator.generateDidKeyPersona();
518
516
  // 1. Alice grants Bob the access to ProtocolsConfigure on her DWN
519
- const permissionGrant = yield PermissionsProtocol.createGrant({
517
+ const permissionGrant = await PermissionsProtocol.createGrant({
520
518
  signer: Jws.createSigner(alice),
521
519
  grantedTo: bob.did,
522
520
  dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
523
521
  scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Configure }
524
522
  });
525
523
  const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
526
- const grantRecordsWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
524
+ const grantRecordsWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
527
525
  expect(grantRecordsWriteReply.status.code).toBe(202);
528
526
  // 2. Verify Bob can perform a ProtocolsConfigure
529
527
  const permissionGrantId = permissionGrant.recordsWrite.message.recordId;
530
- const protocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
528
+ const protocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
531
529
  permissionGrantId,
532
530
  author: bob,
533
531
  protocolDefinition: minimalProtocolDefinition
534
532
  });
535
- const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfigure.message);
533
+ const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfigure.message);
536
534
  expect(protocolsConfigureReply.status.code).toBe(202);
537
535
  // 3. Verify that Mallory cannot to use Bob's permission grant to gain access to Alice's DWN
538
- const malloryProtocolsQuery = yield TestDataGenerator.generateProtocolsConfigure({
536
+ const malloryProtocolsQuery = await TestDataGenerator.generateProtocolsConfigure({
539
537
  permissionGrantId,
540
538
  author: mallory,
541
539
  protocolDefinition: minimalProtocolDefinition
542
540
  });
543
- const malloryProtocolsQueryReply = yield dwn.processMessage(alice.did, malloryProtocolsQuery.message);
541
+ const malloryProtocolsQueryReply = await dwn.processMessage(alice.did, malloryProtocolsQuery.message);
544
542
  expect(malloryProtocolsQueryReply.status.code).toBe(401);
545
543
  expect(malloryProtocolsQueryReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationNotGrantedToAuthor);
546
544
  // 4. Alice revokes Bob's grant
547
- const revokeWrite = yield PermissionsProtocol.createRevocation({
545
+ const revokeWrite = await PermissionsProtocol.createRevocation({
548
546
  signer: Jws.createSigner(alice),
549
- grant: yield PermissionGrant.parse(permissionGrant.dataEncodedMessage),
547
+ grant: PermissionGrant.parse(permissionGrant.dataEncodedMessage),
550
548
  dateRevoked: Time.getCurrentTimestamp()
551
549
  });
552
- const revokeWriteReply = yield dwn.processMessage(alice.did, revokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeWrite.permissionRevocationBytes) });
550
+ const revokeWriteReply = await dwn.processMessage(alice.did, revokeWrite.recordsWrite.message, { dataStream: DataStream.fromBytes(revokeWrite.permissionRevocationBytes) });
553
551
  expect(revokeWriteReply.status.code).toBe(202);
554
552
  // 5. Verify Bob cannot perform ProtocolsQuery with the revoked grant
555
- const unauthorizedProtocolsConfigure = yield TestDataGenerator.generateProtocolsConfigure({
553
+ const unauthorizedProtocolsConfigure = await TestDataGenerator.generateProtocolsConfigure({
556
554
  permissionGrantId,
557
555
  author: bob,
558
- protocolDefinition: Object.assign(Object.assign({}, minimalProtocolDefinition), { protocol: 'https://example.com/protocol/another-protocol' })
556
+ protocolDefinition: {
557
+ ...minimalProtocolDefinition,
558
+ protocol: 'https://example.com/protocol/another-protocol'
559
+ }
559
560
  });
560
- const unauthorizedProtocolsConfigureReply = yield dwn.processMessage(alice.did, unauthorizedProtocolsConfigure.message);
561
+ const unauthorizedProtocolsConfigureReply = await dwn.processMessage(alice.did, unauthorizedProtocolsConfigure.message);
561
562
  expect(unauthorizedProtocolsConfigureReply.status.code).toBe(401);
562
563
  expect(unauthorizedProtocolsConfigureReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantRevoked);
563
- }));
564
- it('should allow to scope a ProtocolsConfigure to a specific protocol', () => __awaiter(this, void 0, void 0, function* () {
565
- const alice = yield TestDataGenerator.generateDidKeyPersona();
566
- const bob = yield TestDataGenerator.generateDidKeyPersona();
564
+ });
565
+ it('should allow to scope a ProtocolsConfigure to a specific protocol', async () => {
566
+ const alice = await TestDataGenerator.generateDidKeyPersona();
567
+ const bob = await TestDataGenerator.generateDidKeyPersona();
567
568
  // Alice grants Bob the access to ProtocolsConfigure on her DWN for a specific protocol
568
- const permissionGrant = yield PermissionsProtocol.createGrant({
569
+ const permissionGrant = await PermissionsProtocol.createGrant({
569
570
  signer: Jws.createSigner(alice),
570
571
  grantedTo: bob.did,
571
572
  dateExpires: Time.createOffsetTimestamp({ seconds: 60 * 60 * 24 }),
572
573
  scope: { interface: DwnInterfaceName.Protocols, method: DwnMethodName.Configure, protocol: 'https://example.com/protocol/allowed' }
573
574
  });
574
575
  const dataStream = DataStream.fromBytes(permissionGrant.permissionGrantBytes);
575
- const grantRecordsWriteReply = yield dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
576
+ const grantRecordsWriteReply = await dwn.processMessage(alice.did, permissionGrant.recordsWrite.message, { dataStream });
576
577
  expect(grantRecordsWriteReply.status.code).toBe(202);
577
578
  // Bob tries to ProtocolsConfigure to Alice's DWN for the allowed protocol
578
- const protocolConfigureAllowed = yield TestDataGenerator.generateProtocolsConfigure({
579
+ const protocolConfigureAllowed = await TestDataGenerator.generateProtocolsConfigure({
579
580
  author: bob,
580
- protocolDefinition: Object.assign(Object.assign({}, minimalProtocolDefinition), { protocol: 'https://example.com/protocol/allowed' }),
581
+ protocolDefinition: {
582
+ ...minimalProtocolDefinition,
583
+ protocol: 'https://example.com/protocol/allowed'
584
+ },
581
585
  permissionGrantId: permissionGrant.recordsWrite.message.recordId
582
586
  });
583
- const protocolConfigureAllowedReply = yield dwn.processMessage(alice.did, protocolConfigureAllowed.message);
587
+ const protocolConfigureAllowedReply = await dwn.processMessage(alice.did, protocolConfigureAllowed.message);
584
588
  expect(protocolConfigureAllowedReply.status.code).toBe(202);
585
589
  // Bob tries to ProtocolsConfigure to Alice's DWN for a different protocol
586
- const protocolConfigureNotAllowed = yield TestDataGenerator.generateProtocolsConfigure({
590
+ const protocolConfigureNotAllowed = await TestDataGenerator.generateProtocolsConfigure({
587
591
  author: bob,
588
- protocolDefinition: Object.assign(Object.assign({}, minimalProtocolDefinition), { protocol: 'https://example.com/protocol/not-allowed' }),
592
+ protocolDefinition: {
593
+ ...minimalProtocolDefinition,
594
+ protocol: 'https://example.com/protocol/not-allowed'
595
+ },
589
596
  permissionGrantId: permissionGrant.recordsWrite.message.recordId
590
597
  });
591
- const protocolConfigureNotAllowedReply = yield dwn.processMessage(alice.did, protocolConfigureNotAllowed.message);
598
+ const protocolConfigureNotAllowedReply = await dwn.processMessage(alice.did, protocolConfigureNotAllowed.message);
592
599
  expect(protocolConfigureNotAllowedReply.status.code).toBe(401);
593
- }));
600
+ });
594
601
  });
595
602
  describe('state index', () => {
596
- it('should add event for ProtocolsConfigure', () => __awaiter(this, void 0, void 0, function* () {
597
- const alice = yield TestDataGenerator.generateDidKeyPersona();
598
- const { message } = yield TestDataGenerator.generateProtocolsConfigure({ author: alice });
599
- const reply = yield dwn.processMessage(alice.did, message);
603
+ it('should add event for ProtocolsConfigure', async () => {
604
+ const alice = await TestDataGenerator.generateDidKeyPersona();
605
+ const { message } = await TestDataGenerator.generateProtocolsConfigure({ author: alice });
606
+ const reply = await dwn.processMessage(alice.did, message);
600
607
  expect(reply.status.code).toBe(202);
601
- const events = yield stateIndex.getLeaves(alice.did, []);
608
+ const events = await stateIndex.getLeaves(alice.did, []);
602
609
  expect(events.length).toBe(1);
603
- const messageCid = yield Message.getCid(message);
610
+ const messageCid = await Message.getCid(message);
604
611
  expect(events[0]).toBe(messageCid);
605
- }));
606
- it('should retain all ProtocolsConfigure events for protocol versioning', () => __awaiter(this, void 0, void 0, function* () {
607
- const alice = yield TestDataGenerator.generateDidKeyPersona();
608
- const oldestWrite = yield TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
609
- yield Time.minimalSleep();
610
- const newestWrite = yield TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
611
- let reply = yield dwn.processMessage(alice.did, oldestWrite.message);
612
+ });
613
+ it('should retain all ProtocolsConfigure events for protocol versioning', async () => {
614
+ const alice = await TestDataGenerator.generateDidKeyPersona();
615
+ const oldestWrite = await TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
616
+ await Time.minimalSleep();
617
+ const newestWrite = await TestDataGenerator.generateProtocolsConfigure({ author: alice, protocolDefinition: minimalProtocolDefinition });
618
+ let reply = await dwn.processMessage(alice.did, oldestWrite.message);
612
619
  expect(reply.status.code).toBe(202);
613
- reply = yield dwn.processMessage(alice.did, newestWrite.message);
620
+ reply = await dwn.processMessage(alice.did, newestWrite.message);
614
621
  expect(reply.status.code).toBe(202);
615
- const events = yield stateIndex.getLeaves(alice.did, []);
622
+ const events = await stateIndex.getLeaves(alice.did, []);
616
623
  expect(events.length).toBe(2);
617
- const oldestMessageCid = yield Message.getCid(oldestWrite.message);
618
- const newestMessageCid = yield Message.getCid(newestWrite.message);
624
+ const oldestMessageCid = await Message.getCid(oldestWrite.message);
625
+ const newestMessageCid = await Message.getCid(newestWrite.message);
619
626
  expect(events).toContain(oldestMessageCid);
620
627
  expect(events).toContain(newestMessageCid);
621
- }));
628
+ });
622
629
  });
623
630
  describe('temporal protocol versioning', () => {
624
- it('should authorize records created under v1 even after re-configuring to v2 that removes the type', () => __awaiter(this, void 0, void 0, function* () {
631
+ it('should authorize records created under v1 even after re-configuring to v2 that removes the type', async () => {
625
632
  // scenario:
626
633
  // 1. Alice installs protocol v1 with types `post` and `comment`
627
634
  // 2. Alice writes a `post` record under v1
628
635
  // 3. Alice re-configures the protocol to v2 which removes the `comment` type
629
636
  // 4. Alice should still be able to read the v1 `post` record
630
637
  // 5. Alice should still be able to update the v1 `post` record (governed by v1 definition)
631
- const alice = yield TestDataGenerator.generateDidKeyPersona();
638
+ const alice = await TestDataGenerator.generateDidKeyPersona();
632
639
  // v1: has `post` and `comment` types
633
640
  const protocolUri = 'https://example.com/versioned-protocol';
634
641
  const protocolDefinitionV1 = {
@@ -647,24 +654,24 @@ export function testProtocolsConfigureHandler() {
647
654
  }
648
655
  }
649
656
  };
650
- const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
657
+ const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
651
658
  author: alice,
652
659
  protocolDefinition: protocolDefinitionV1,
653
660
  });
654
- const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
661
+ const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
655
662
  expect(configureV1Reply.status.code).toBe(202);
656
663
  // write a `post` record under v1
657
- const postRecord = yield TestDataGenerator.generateRecordsWrite({
664
+ const postRecord = await TestDataGenerator.generateRecordsWrite({
658
665
  author: alice,
659
666
  protocol: protocolUri,
660
667
  protocolPath: 'post',
661
668
  schema: 'https://example.com/post',
662
669
  dataFormat: 'application/json',
663
670
  });
664
- const postReply = yield dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
671
+ const postReply = await dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
665
672
  expect(postReply.status.code).toBe(202);
666
673
  // write a `comment` record under v1
667
- const commentRecord = yield TestDataGenerator.generateRecordsWrite({
674
+ const commentRecord = await TestDataGenerator.generateRecordsWrite({
668
675
  author: alice,
669
676
  protocol: protocolUri,
670
677
  protocolPath: 'post/comment',
@@ -672,9 +679,9 @@ export function testProtocolsConfigureHandler() {
672
679
  dataFormat: 'application/json',
673
680
  parentContextId: postRecord.message.contextId,
674
681
  });
675
- const commentReply = yield dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
682
+ const commentReply = await dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
676
683
  expect(commentReply.status.code).toBe(202);
677
- yield Time.minimalSleep();
684
+ await Time.minimalSleep();
678
685
  // v2: removes the `comment` type entirely, changes `post` schema
679
686
  const protocolDefinitionV2 = {
680
687
  protocol: protocolUri,
@@ -688,43 +695,43 @@ export function testProtocolsConfigureHandler() {
688
695
  }
689
696
  }
690
697
  };
691
- const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
698
+ const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
692
699
  author: alice,
693
700
  protocolDefinition: protocolDefinitionV2,
694
701
  });
695
- const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
702
+ const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
696
703
  expect(configureV2Reply.status.code).toBe(202);
697
704
  // read the v1 `post` record — should succeed because read authorization uses v1 definition
698
- const readPost = yield RecordsRead.create({
705
+ const readPost = await RecordsRead.create({
699
706
  filter: { recordId: postRecord.message.recordId },
700
707
  signer: Jws.createSigner(alice),
701
708
  });
702
- const readPostReply = yield dwn.processMessage(alice.did, readPost.message);
709
+ const readPostReply = await dwn.processMessage(alice.did, readPost.message);
703
710
  expect(readPostReply.status.code).toBe(200);
704
711
  // read the v1 `comment` record — should succeed (governed by v1 definition where `comment` exists)
705
- const readComment = yield RecordsRead.create({
712
+ const readComment = await RecordsRead.create({
706
713
  filter: { recordId: commentRecord.message.recordId },
707
714
  signer: Jws.createSigner(alice),
708
715
  });
709
- const readCommentReply = yield dwn.processMessage(alice.did, readComment.message);
716
+ const readCommentReply = await dwn.processMessage(alice.did, readComment.message);
710
717
  expect(readCommentReply.status.code).toBe(200);
711
718
  // update the v1 `post` record — should succeed (governed by v1 definition)
712
719
  const updatedData = new TextEncoder().encode('{"title":"updated post"}');
713
- const updatePost = yield RecordsWrite.createFrom({
720
+ const updatePost = await RecordsWrite.createFrom({
714
721
  recordsWriteMessage: postRecord.message,
715
722
  data: updatedData,
716
723
  signer: Jws.createSigner(alice),
717
724
  });
718
- const updatePostReply = yield dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
725
+ const updatePostReply = await dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
719
726
  expect(updatePostReply.status.code).toBe(202);
720
- }));
721
- it('should authorize new records against the latest protocol definition, not an older one', () => __awaiter(this, void 0, void 0, function* () {
727
+ });
728
+ it('should authorize new records against the latest protocol definition, not an older one', async () => {
722
729
  // scenario:
723
730
  // 1. Alice installs protocol v1 with type `post`
724
731
  // 2. Alice re-configures to v2 that changes `post` schema to 'https://example.com/post-v2'
725
732
  // 3. A new record with v1 schema should be rejected (not matching the latest definition)
726
733
  // 4. A new record with v2 schema should be accepted
727
- const alice = yield TestDataGenerator.generateDidKeyPersona();
734
+ const alice = await TestDataGenerator.generateDidKeyPersona();
728
735
  const protocolUri = 'https://example.com/versioned-protocol-2';
729
736
  const protocolDefinitionV1 = {
730
737
  protocol: protocolUri,
@@ -738,13 +745,13 @@ export function testProtocolsConfigureHandler() {
738
745
  }
739
746
  }
740
747
  };
741
- const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
748
+ const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
742
749
  author: alice,
743
750
  protocolDefinition: protocolDefinitionV1,
744
751
  });
745
- const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
752
+ const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
746
753
  expect(configureV1Reply.status.code).toBe(202);
747
- yield Time.minimalSleep();
754
+ await Time.minimalSleep();
748
755
  // v2: changes `post` schema
749
756
  const protocolDefinitionV2 = {
750
757
  protocol: protocolUri,
@@ -758,41 +765,41 @@ export function testProtocolsConfigureHandler() {
758
765
  }
759
766
  }
760
767
  };
761
- const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
768
+ const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
762
769
  author: alice,
763
770
  protocolDefinition: protocolDefinitionV2,
764
771
  });
765
- const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
772
+ const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
766
773
  expect(configureV2Reply.status.code).toBe(202);
767
774
  // write a new record with v1 schema — should fail (latest definition requires v2 schema)
768
- const postV1 = yield TestDataGenerator.generateRecordsWrite({
775
+ const postV1 = await TestDataGenerator.generateRecordsWrite({
769
776
  author: alice,
770
777
  protocol: protocolUri,
771
778
  protocolPath: 'post',
772
779
  schema: 'https://example.com/post-v1',
773
780
  dataFormat: 'application/json',
774
781
  });
775
- const postV1Reply = yield dwn.processMessage(alice.did, postV1.message, { dataStream: postV1.dataStream });
782
+ const postV1Reply = await dwn.processMessage(alice.did, postV1.message, { dataStream: postV1.dataStream });
776
783
  expect(postV1Reply.status.code).toBe(400);
777
784
  expect(postV1Reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationInvalidSchema);
778
785
  // write a new record with v2 schema — should succeed
779
- const postV2 = yield TestDataGenerator.generateRecordsWrite({
786
+ const postV2 = await TestDataGenerator.generateRecordsWrite({
780
787
  author: alice,
781
788
  protocol: protocolUri,
782
789
  protocolPath: 'post',
783
790
  schema: 'https://example.com/post-v2',
784
791
  dataFormat: 'application/json',
785
792
  });
786
- const postV2Reply = yield dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
793
+ const postV2Reply = await dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
787
794
  expect(postV2Reply.status.code).toBe(202);
788
- }));
789
- it('should authorize deletes of v1 records after re-configuring to v2 that removes the type', () => __awaiter(this, void 0, void 0, function* () {
795
+ });
796
+ it('should authorize deletes of v1 records after re-configuring to v2 that removes the type', async () => {
790
797
  // scenario:
791
798
  // 1. Alice installs protocol v1 with types `post` (with delete action) and `comment`
792
799
  // 2. Alice writes a `post/comment` record
793
800
  // 3. Alice re-configures to v2 which removes the `comment` type
794
801
  // 4. Alice should still be able to delete the v1 `comment` record (governed by v1 definition)
795
- const alice = yield TestDataGenerator.generateDidKeyPersona();
802
+ const alice = await TestDataGenerator.generateDidKeyPersona();
796
803
  const protocolUri = 'https://example.com/versioned-protocol-3';
797
804
  const protocolDefinitionV1 = {
798
805
  protocol: protocolUri,
@@ -810,30 +817,30 @@ export function testProtocolsConfigureHandler() {
810
817
  }
811
818
  }
812
819
  };
813
- const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
820
+ const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
814
821
  author: alice,
815
822
  protocolDefinition: protocolDefinitionV1,
816
823
  });
817
- const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
824
+ const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
818
825
  expect(configureV1Reply.status.code).toBe(202);
819
826
  // write a `post` record
820
- const postRecord = yield TestDataGenerator.generateRecordsWrite({
827
+ const postRecord = await TestDataGenerator.generateRecordsWrite({
821
828
  author: alice,
822
829
  protocol: protocolUri,
823
830
  protocolPath: 'post',
824
831
  });
825
- const postReply = yield dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
832
+ const postReply = await dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
826
833
  expect(postReply.status.code).toBe(202);
827
834
  // write a `comment` record under the post
828
- const commentRecord = yield TestDataGenerator.generateRecordsWrite({
835
+ const commentRecord = await TestDataGenerator.generateRecordsWrite({
829
836
  author: alice,
830
837
  protocol: protocolUri,
831
838
  protocolPath: 'post/comment',
832
839
  parentContextId: postRecord.message.contextId,
833
840
  });
834
- const commentReply = yield dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
841
+ const commentReply = await dwn.processMessage(alice.did, commentRecord.message, { dataStream: commentRecord.dataStream });
835
842
  expect(commentReply.status.code).toBe(202);
836
- yield Time.minimalSleep();
843
+ await Time.minimalSleep();
837
844
  // v2: removes the `comment` type
838
845
  const protocolDefinitionV2 = {
839
846
  protocol: protocolUri,
@@ -847,28 +854,28 @@ export function testProtocolsConfigureHandler() {
847
854
  }
848
855
  }
849
856
  };
850
- const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
857
+ const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
851
858
  author: alice,
852
859
  protocolDefinition: protocolDefinitionV2,
853
860
  });
854
- const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
861
+ const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
855
862
  expect(configureV2Reply.status.code).toBe(202);
856
863
  // delete the v1 `comment` record — should succeed (governed by v1 definition)
857
- const deleteComment = yield RecordsDelete.create({
864
+ const deleteComment = await RecordsDelete.create({
858
865
  signer: Jws.createSigner(alice),
859
866
  recordId: commentRecord.message.recordId,
860
867
  });
861
- const deleteReply = yield dwn.processMessage(alice.did, deleteComment.message);
868
+ const deleteReply = await dwn.processMessage(alice.did, deleteComment.message);
862
869
  expect(deleteReply.status.code).toBe(202);
863
- }));
864
- it('should not retroactively apply v2 action rules to records created under v1', () => __awaiter(this, void 0, void 0, function* () {
870
+ });
871
+ it('should not retroactively apply v2 action rules to records created under v1', async () => {
865
872
  // scenario:
866
873
  // 1. Alice installs protocol v1 where anyone can create and update `post` records
867
874
  // 2. Bob writes a `post` to Alice's DWN
868
875
  // 3. Alice re-configures to v2 that restricts `post` updates to author-only (removes co-update)
869
876
  // 4. Bob should still be able to update his own record (governed by v1 definition which had update)
870
- const alice = yield TestDataGenerator.generateDidKeyPersona();
871
- const bob = yield TestDataGenerator.generateDidKeyPersona();
877
+ const alice = await TestDataGenerator.generateDidKeyPersona();
878
+ const bob = await TestDataGenerator.generateDidKeyPersona();
872
879
  const protocolUri = 'https://example.com/versioned-protocol-4';
873
880
  const protocolDefinitionV1 = {
874
881
  protocol: protocolUri,
@@ -882,21 +889,21 @@ export function testProtocolsConfigureHandler() {
882
889
  }
883
890
  }
884
891
  };
885
- const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
892
+ const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
886
893
  author: alice,
887
894
  protocolDefinition: protocolDefinitionV1,
888
895
  });
889
- const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
896
+ const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
890
897
  expect(configureV1Reply.status.code).toBe(202);
891
898
  // Bob writes a `post` record to Alice's DWN under v1
892
- const postRecord = yield TestDataGenerator.generateRecordsWrite({
899
+ const postRecord = await TestDataGenerator.generateRecordsWrite({
893
900
  author: bob,
894
901
  protocol: protocolUri,
895
902
  protocolPath: 'post',
896
903
  });
897
- const postReply = yield dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
904
+ const postReply = await dwn.processMessage(alice.did, postRecord.message, { dataStream: postRecord.dataStream });
898
905
  expect(postReply.status.code).toBe(202);
899
- yield Time.minimalSleep();
906
+ await Time.minimalSleep();
900
907
  // v2: restricts actions (only create, no update for anyone)
901
908
  const protocolDefinitionV2 = {
902
909
  protocol: protocolUri,
@@ -910,30 +917,29 @@ export function testProtocolsConfigureHandler() {
910
917
  }
911
918
  }
912
919
  };
913
- const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
920
+ const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
914
921
  author: alice,
915
922
  protocolDefinition: protocolDefinitionV2,
916
923
  });
917
- const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
924
+ const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
918
925
  expect(configureV2Reply.status.code).toBe(202);
919
926
  // Bob updates his v1 record — should succeed because v1 definition (which governs this record) allowed update
920
927
  const updatedData = new TextEncoder().encode('updated-post-data');
921
- const updatePost = yield RecordsWrite.createFrom({
928
+ const updatePost = await RecordsWrite.createFrom({
922
929
  recordsWriteMessage: postRecord.message,
923
930
  data: updatedData,
924
931
  signer: Jws.createSigner(bob),
925
932
  });
926
- const updateReply = yield dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
933
+ const updateReply = await dwn.processMessage(alice.did, updatePost.message, { dataStream: DataStream.fromBytes(updatedData) });
927
934
  expect(updateReply.status.code).toBe(202);
928
- }));
929
- it('should handle out-of-order protocol configure processing correctly', () => __awaiter(this, void 0, void 0, function* () {
930
- var _a;
935
+ });
936
+ it('should handle out-of-order protocol configure processing correctly', async () => {
931
937
  // scenario:
932
938
  // 1. Create v1 and v2 ProtocolsConfigure messages (v2 has a newer timestamp)
933
939
  // 2. Process v2 first, then v1
934
940
  // 3. Both should be stored; query should return only v2 (the latest)
935
941
  // 4. A record written under v2 schema should succeed
936
- const alice = yield TestDataGenerator.generateDidKeyPersona();
942
+ const alice = await TestDataGenerator.generateDidKeyPersona();
937
943
  const protocolUri = 'https://example.com/versioned-protocol-5';
938
944
  const protocolDefinitionV1 = {
939
945
  protocol: protocolUri,
@@ -947,11 +953,11 @@ export function testProtocolsConfigureHandler() {
947
953
  }
948
954
  }
949
955
  };
950
- const configureV1 = yield TestDataGenerator.generateProtocolsConfigure({
956
+ const configureV1 = await TestDataGenerator.generateProtocolsConfigure({
951
957
  author: alice,
952
958
  protocolDefinition: protocolDefinitionV1,
953
959
  });
954
- yield Time.minimalSleep();
960
+ await Time.minimalSleep();
955
961
  const protocolDefinitionV2 = {
956
962
  protocol: protocolUri,
957
963
  published: true,
@@ -964,36 +970,36 @@ export function testProtocolsConfigureHandler() {
964
970
  }
965
971
  }
966
972
  };
967
- const configureV2 = yield TestDataGenerator.generateProtocolsConfigure({
973
+ const configureV2 = await TestDataGenerator.generateProtocolsConfigure({
968
974
  author: alice,
969
975
  protocolDefinition: protocolDefinitionV2,
970
976
  });
971
977
  // process v2 first (out of order)
972
- const configureV2Reply = yield dwn.processMessage(alice.did, configureV2.message);
978
+ const configureV2Reply = await dwn.processMessage(alice.did, configureV2.message);
973
979
  expect(configureV2Reply.status.code).toBe(202);
974
980
  // process v1 second (older, arrives later)
975
- const configureV1Reply = yield dwn.processMessage(alice.did, configureV1.message);
981
+ const configureV1Reply = await dwn.processMessage(alice.did, configureV1.message);
976
982
  expect(configureV1Reply.status.code).toBe(202);
977
983
  // query should return only v2 (the latest)
978
- const queryMessageData = yield TestDataGenerator.generateProtocolsQuery({
984
+ const queryMessageData = await TestDataGenerator.generateProtocolsQuery({
979
985
  author: alice,
980
986
  filter: { protocol: protocolUri }
981
987
  });
982
- const queryReply = yield dwn.processMessage(alice.did, queryMessageData.message);
988
+ const queryReply = await dwn.processMessage(alice.did, queryMessageData.message);
983
989
  expect(queryReply.status.code).toBe(200);
984
- expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
990
+ expect(queryReply.entries?.length).toBe(1);
985
991
  expect(queryReply.entries[0].descriptor.definition.types.post.schema).toBe('https://example.com/post-v2');
986
992
  // writing a new record with v2 schema should succeed (latest definition)
987
- const postV2 = yield TestDataGenerator.generateRecordsWrite({
993
+ const postV2 = await TestDataGenerator.generateRecordsWrite({
988
994
  author: alice,
989
995
  protocol: protocolUri,
990
996
  protocolPath: 'post',
991
997
  schema: 'https://example.com/post-v2',
992
998
  dataFormat: 'application/json',
993
999
  });
994
- const postV2Reply = yield dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
1000
+ const postV2Reply = await dwn.processMessage(alice.did, postV2.message, { dataStream: postV2.dataStream });
995
1001
  expect(postV2Reply.status.code).toBe(202);
996
- }));
1002
+ });
997
1003
  });
998
1004
  });
999
1005
  });