@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 emailProtocolDefinition from '../vectors/protocol-definitions/email.json' with { type: 'json' };
11
2
  import messageProtocolDefinition from '../vectors/protocol-definitions/message.json' with { type: 'json' };
12
3
  import sinon from 'sinon';
@@ -20,7 +11,7 @@ import { PermissionGrant } from '../../src/protocols/permission-grant.js';
20
11
  import { Poller } from '../utils/poller.js';
21
12
  import { RecordsWrite } from '../../src/interfaces/records-write.js';
22
13
  import { TestDataGenerator } from '../utils/test-data-generator.js';
23
- import { TestEventStream } from '../test-event-stream.js';
14
+ import { TestEventLog } from '../test-event-stream.js';
24
15
  import { TestStores } from '../test-stores.js';
25
16
  import { Time } from '../../src/utils/time.js';
26
17
  import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
@@ -33,41 +24,41 @@ export function testAuthorDelegatedGrant() {
33
24
  let dataStore;
34
25
  let resumableTaskStore;
35
26
  let stateIndex;
36
- let eventStream;
27
+ let eventLog;
37
28
  let dwn;
38
29
  // important to follow the `before` and `after` pattern to initialize and clean the stores in tests
39
30
  // so that different test suites can reuse the same backend store for testing
40
- beforeAll(() => __awaiter(this, void 0, void 0, function* () {
31
+ beforeAll(async () => {
41
32
  didResolver = new UniversalResolver({ didResolvers: [DidKey] });
42
33
  const stores = TestStores.get();
43
34
  messageStore = stores.messageStore;
44
35
  dataStore = stores.dataStore;
45
36
  resumableTaskStore = stores.resumableTaskStore;
46
37
  stateIndex = stores.stateIndex;
47
- eventStream = TestEventStream.get();
48
- dwn = yield Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
49
- }));
50
- beforeEach(() => __awaiter(this, void 0, void 0, function* () {
38
+ eventLog = TestEventLog.get();
39
+ dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventLog, resumableTaskStore });
40
+ });
41
+ beforeEach(async () => {
51
42
  sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
52
43
  // clean up before each test rather than after so that a test does not depend on other tests to do the clean up
53
- yield messageStore.clear();
54
- yield dataStore.clear();
55
- yield resumableTaskStore.clear();
56
- yield stateIndex.clear();
57
- }));
58
- afterAll(() => __awaiter(this, void 0, void 0, function* () {
59
- yield dwn.close();
60
- }));
44
+ await messageStore.clear();
45
+ await dataStore.clear();
46
+ await resumableTaskStore.clear();
47
+ await stateIndex.clear();
48
+ });
49
+ afterAll(async () => {
50
+ await dwn.close();
51
+ });
61
52
  describe('ProtocolsConfigure', () => {
62
- it('should allow author-delegated grant to configure protocols', () => __awaiter(this, void 0, void 0, function* () {
63
- const alice = yield TestDataGenerator.generateDidKeyPersona();
64
- const bob = yield TestDataGenerator.generateDidKeyPersona();
53
+ it('should allow author-delegated grant to configure protocols', async () => {
54
+ const alice = await TestDataGenerator.generateDidKeyPersona();
55
+ const bob = await TestDataGenerator.generateDidKeyPersona();
65
56
  // Alice grants Bob ability to configure any protocol, bob will use it to configure the email protocol
66
57
  const scope = {
67
58
  interface: DwnInterfaceName.Protocols,
68
59
  method: DwnMethodName.Configure,
69
60
  };
70
- const grantToBob = yield PermissionsProtocol.createGrant({
61
+ const grantToBob = await PermissionsProtocol.createGrant({
71
62
  delegated: true, // this is a delegated grant
72
63
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
73
64
  description: 'Allow Bob to configure the email protocol',
@@ -76,22 +67,22 @@ export function testAuthorDelegatedGrant() {
76
67
  signer: Jws.createSigner(alice)
77
68
  });
78
69
  // Bob attempts to configure a protocol
79
- const protocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
70
+ const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
80
71
  delegatedGrant: grantToBob.dataEncodedMessage,
81
72
  author: bob,
82
73
  protocolDefinition: emailProtocolDefinition,
83
74
  });
84
75
  // Bob should be able to configure a protocol on behalf of alice
85
- const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfigure.message);
76
+ const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
86
77
  expect(protocolConfigureReply.status.code).toBe(202);
87
78
  // verify the protocol configure message was processed
88
- const protocolsQuery = yield TestDataGenerator.generateProtocolsQuery({
79
+ const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
89
80
  author: alice,
90
81
  filter: { protocol: emailProtocolDefinition.protocol }
91
82
  });
92
- const { status, entries } = yield dwn.processMessage(alice.did, protocolsQuery.message);
83
+ const { status, entries } = await dwn.processMessage(alice.did, protocolsQuery.message);
93
84
  expect(status.code).toBe(200);
94
- expect(entries === null || entries === void 0 ? void 0 : entries.length).toBe(1);
85
+ expect(entries?.length).toBe(1);
95
86
  const fetchedProtocolConfigure = entries[0];
96
87
  expect(fetchedProtocolConfigure.descriptor.definition).toEqual(emailProtocolDefinition);
97
88
  // author should be alice
@@ -99,17 +90,17 @@ export function testAuthorDelegatedGrant() {
99
90
  expect(author).toBe(alice.did);
100
91
  const signer = Message.getSigner(fetchedProtocolConfigure);
101
92
  expect(signer).toBe(bob.did);
102
- }));
103
- it('should allow author-delegated grant to configure a specific protocol', () => __awaiter(this, void 0, void 0, function* () {
104
- const alice = yield TestDataGenerator.generateDidKeyPersona();
105
- const bob = yield TestDataGenerator.generateDidKeyPersona();
93
+ });
94
+ it('should allow author-delegated grant to configure a specific protocol', async () => {
95
+ const alice = await TestDataGenerator.generateDidKeyPersona();
96
+ const bob = await TestDataGenerator.generateDidKeyPersona();
106
97
  // Alice grants Bob to configure the email protocol
107
98
  const scope = {
108
99
  interface: DwnInterfaceName.Protocols,
109
100
  method: DwnMethodName.Configure,
110
101
  protocol: emailProtocolDefinition.protocol,
111
102
  };
112
- const grantToBob = yield PermissionsProtocol.createGrant({
103
+ const grantToBob = await PermissionsProtocol.createGrant({
113
104
  delegated: true, // this is a delegated grant
114
105
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
115
106
  description: 'Allow Bob to configure the email protocol',
@@ -118,22 +109,22 @@ export function testAuthorDelegatedGrant() {
118
109
  signer: Jws.createSigner(alice)
119
110
  });
120
111
  // Bob attempts to configure a protocol
121
- const protocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
112
+ const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
122
113
  delegatedGrant: grantToBob.dataEncodedMessage,
123
114
  author: bob,
124
115
  protocolDefinition: emailProtocolDefinition,
125
116
  });
126
117
  // Bob should be able to configure a protocol on behalf of alice
127
- const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfigure.message);
118
+ const protocolConfigureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
128
119
  expect(protocolConfigureReply.status.code).toBe(202);
129
120
  // verify the protocol configure message was processed
130
- const protocolsQuery = yield TestDataGenerator.generateProtocolsQuery({
121
+ const protocolsQuery = await TestDataGenerator.generateProtocolsQuery({
131
122
  author: alice,
132
123
  filter: { protocol: emailProtocolDefinition.protocol }
133
124
  });
134
- const { status, entries } = yield dwn.processMessage(alice.did, protocolsQuery.message);
125
+ const { status, entries } = await dwn.processMessage(alice.did, protocolsQuery.message);
135
126
  expect(status.code).toBe(200);
136
- expect(entries === null || entries === void 0 ? void 0 : entries.length).toBe(1);
127
+ expect(entries?.length).toBe(1);
137
128
  const fetchedProtocolConfigure = entries[0];
138
129
  expect(fetchedProtocolConfigure.descriptor.definition).toEqual(emailProtocolDefinition);
139
130
  // author should be alice
@@ -142,28 +133,31 @@ export function testAuthorDelegatedGrant() {
142
133
  const signer = Message.getSigner(fetchedProtocolConfigure);
143
134
  expect(signer).toBe(bob.did);
144
135
  // verify that bob cannot configure a different protocol
145
- const otherProtocolDefinition = Object.assign(Object.assign({}, emailProtocolDefinition), { protocol: 'https://example.com/protocol/otherProtocol' });
146
- const otherProtocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
136
+ const otherProtocolDefinition = {
137
+ ...emailProtocolDefinition,
138
+ protocol: 'https://example.com/protocol/otherProtocol'
139
+ };
140
+ const otherProtocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
147
141
  delegatedGrant: grantToBob.dataEncodedMessage,
148
142
  author: bob,
149
143
  protocolDefinition: otherProtocolDefinition,
150
144
  });
151
- const otherProtocolConfigureReply = yield dwn.processMessage(alice.did, otherProtocolConfigure.message);
145
+ const otherProtocolConfigureReply = await dwn.processMessage(alice.did, otherProtocolConfigure.message);
152
146
  expect(otherProtocolConfigureReply.status.code).toBe(401);
153
147
  expect(otherProtocolConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsGrantAuthorizationScopeProtocolMismatch);
154
- }));
148
+ });
155
149
  });
156
150
  describe('RecordsWrite.parse()', () => {
157
- it('should throw if a message invokes a author-delegated grant (ID) but the author-delegated grant is not given', () => __awaiter(this, void 0, void 0, function* () {
158
- const alice = yield TestDataGenerator.generatePersona();
159
- const bob = yield TestDataGenerator.generatePersona();
151
+ it('should throw if a message invokes a author-delegated grant (ID) but the author-delegated grant is not given', async () => {
152
+ const alice = await TestDataGenerator.generatePersona();
153
+ const bob = await TestDataGenerator.generatePersona();
160
154
  // Alice grants Bob to write as her for the chat protocol
161
155
  const scope = {
162
156
  interface: DwnInterfaceName.Records,
163
157
  method: DwnMethodName.Write,
164
158
  protocol: 'chat'
165
159
  };
166
- const grantToBob = yield PermissionsProtocol.createGrant({
160
+ const grantToBob = await PermissionsProtocol.createGrant({
167
161
  delegated: true, // this is a delegated grant
168
162
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
169
163
  description: 'Allow Bob to write as me in chat protocol',
@@ -172,26 +166,28 @@ export function testAuthorDelegatedGrant() {
172
166
  signer: Jws.createSigner(alice)
173
167
  });
174
168
  // Bob creates a chat message invoking the delegated grant (ID) but does not include the author-delegated grant (we remove it below)
175
- const recordsWrite = yield RecordsWrite.create({
169
+ const recordsWrite = await RecordsWrite.create({
176
170
  signer: Jws.createSigner(bob),
177
171
  delegatedGrant: grantToBob.dataEncodedMessage,
172
+ protocol: 'http://test-protocol.xyz',
173
+ protocolPath: 'testRecord',
178
174
  dataFormat: 'application/octet-stream',
179
175
  data: TestDataGenerator.randomBytes(10),
180
176
  });
181
177
  delete recordsWrite.message.authorization.authorDelegatedGrant; // intentionally remove `authorDelegatedGrant`
182
178
  const parsePromise = RecordsWrite.parse(recordsWrite.message);
183
- yield expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
184
- }));
185
- it('should throw if a message includes an author-delegated grant but does not reference it in author signature', () => __awaiter(this, void 0, void 0, function* () {
186
- const alice = yield TestDataGenerator.generatePersona();
187
- const bob = yield TestDataGenerator.generatePersona();
179
+ await expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
180
+ });
181
+ it('should throw if a message includes an author-delegated grant but does not reference it in author signature', async () => {
182
+ const alice = await TestDataGenerator.generatePersona();
183
+ const bob = await TestDataGenerator.generatePersona();
188
184
  // Alice grants Bob to write as her for the chat protocol
189
185
  const scope = {
190
186
  interface: DwnInterfaceName.Records,
191
187
  method: DwnMethodName.Write,
192
188
  protocol: 'chat'
193
189
  };
194
- const grantToBob = yield PermissionsProtocol.createGrant({
190
+ const grantToBob = await PermissionsProtocol.createGrant({
195
191
  delegated: true, // this is a delegated grant
196
192
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
197
193
  description: 'Allow Bob to write as me in chat protocol',
@@ -201,39 +197,40 @@ export function testAuthorDelegatedGrant() {
201
197
  });
202
198
  // Bob attempts to sign as Alice by including an author-delegated grant
203
199
  // but does not reference the grant ID in author signature (we remove it below)
204
- const recordsWrite = yield RecordsWrite.create({
200
+ const recordsWrite = await RecordsWrite.create({
205
201
  signer: Jws.createSigner(bob),
206
202
  delegatedGrant: grantToBob.dataEncodedMessage,
203
+ protocol: 'http://test-protocol.xyz',
204
+ protocolPath: 'testRecord',
207
205
  dataFormat: 'application/octet-stream',
208
206
  data: TestDataGenerator.randomBytes(10),
209
207
  });
210
- const authorSignaturePayloadCopy = Object.assign({}, recordsWrite.signaturePayload);
208
+ const authorSignaturePayloadCopy = { ...recordsWrite.signaturePayload };
211
209
  delete authorSignaturePayloadCopy.delegatedGrantId; // intentionally remove `delegatedGrantId` in author signature
212
210
  recordsWrite.message.authorization.signature.payload = Encoder.stringToBase64Url(JSON.stringify(authorSignaturePayloadCopy));
213
211
  const parsePromise = RecordsWrite.parse(recordsWrite.message);
214
- yield expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
215
- }));
212
+ await expect(parsePromise).rejects.toThrow(DwnErrorCode.RecordsAuthorDelegatedGrantAndIdExistenceMismatch);
213
+ });
216
214
  });
217
- it('should only allow correct entity invoking an author-delegated grant to write', () => __awaiter(this, void 0, void 0, function* () {
218
- var _a, _b;
215
+ it('should only allow correct entity invoking an author-delegated grant to write', async () => {
219
216
  // scenario:
220
217
  // 1. Alice creates a delegated grant for Device X and Device Y,
221
218
  // 2. Device X and Y can both use their grants to write a message to Bob's DWN as Alice
222
219
  // 3. Messages written by device X and Y should be considered to have been authored by Alice
223
220
  // 4. Carol should not be able to write a message as Alice using Device X's delegated grant
224
- const alice = yield TestDataGenerator.generateDidKeyPersona();
225
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
226
- const deviceY = yield TestDataGenerator.generateDidKeyPersona();
227
- const bob = yield TestDataGenerator.generateDidKeyPersona();
228
- const carol = yield TestDataGenerator.generateDidKeyPersona();
221
+ const alice = await TestDataGenerator.generateDidKeyPersona();
222
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
223
+ const deviceY = await TestDataGenerator.generateDidKeyPersona();
224
+ const bob = await TestDataGenerator.generateDidKeyPersona();
225
+ const carol = await TestDataGenerator.generateDidKeyPersona();
229
226
  // Bob has the message protocol installed
230
227
  const protocolDefinition = messageProtocolDefinition;
231
228
  const protocol = protocolDefinition.protocol;
232
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
229
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
233
230
  author: bob,
234
231
  protocolDefinition
235
232
  });
236
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
233
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
237
234
  expect(protocolConfigureReply.status.code).toBe(202);
238
235
  // Alice creates a delegated grant for device X and device Y
239
236
  const scope = {
@@ -241,14 +238,14 @@ export function testAuthorDelegatedGrant() {
241
238
  method: DwnMethodName.Write,
242
239
  protocol
243
240
  };
244
- const deviceXGrant = yield PermissionsProtocol.createGrant({
241
+ const deviceXGrant = await PermissionsProtocol.createGrant({
245
242
  delegated: true, // this is a delegated grant
246
243
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
247
244
  grantedTo: deviceX.did,
248
245
  scope: scope,
249
246
  signer: Jws.createSigner(alice)
250
247
  });
251
- const deviceYGrant = yield PermissionsProtocol.createGrant({
248
+ const deviceYGrant = await PermissionsProtocol.createGrant({
252
249
  delegated: true, // this is a delegated grant
253
250
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
254
251
  grantedTo: deviceY.did,
@@ -258,7 +255,7 @@ export function testAuthorDelegatedGrant() {
258
255
  // generate a `RecordsWrite` message from device X and write to Bob's DWN
259
256
  const deviceXData = new TextEncoder().encode('message from device X');
260
257
  const deviceXDataStream = DataStream.fromBytes(deviceXData);
261
- const messageByDeviceX = yield RecordsWrite.create({
258
+ const messageByDeviceX = await RecordsWrite.create({
262
259
  signer: Jws.createSigner(deviceX),
263
260
  delegatedGrant: deviceXGrant.dataEncodedMessage,
264
261
  protocol,
@@ -267,42 +264,42 @@ export function testAuthorDelegatedGrant() {
267
264
  dataFormat: protocolDefinition.types.message.dataFormats[0],
268
265
  data: deviceXData
269
266
  });
270
- const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
267
+ const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
271
268
  expect(deviceXWriteReply.status.code).toBe(202);
272
269
  // verify the message by device X got written to Bob's DWN, AND Alice is the logical author
273
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
270
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
274
271
  author: bob,
275
272
  filter: { protocol }
276
273
  });
277
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
274
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
278
275
  expect(bobRecordsQueryReply.status.code).toBe(200);
279
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
276
+ expect(bobRecordsQueryReply.entries?.length).toBe(1);
280
277
  const fetchedDeviceXWriteEntry = bobRecordsQueryReply.entries[0];
281
278
  expect(fetchedDeviceXWriteEntry.encodedData).toBe(base64url.baseEncode(deviceXData));
282
- const fetchedDeviceXWrite = yield RecordsWrite.parse(fetchedDeviceXWriteEntry);
279
+ const fetchedDeviceXWrite = await RecordsWrite.parse(fetchedDeviceXWriteEntry);
283
280
  expect(fetchedDeviceXWrite.author).toBe(alice.did);
284
281
  // generate a new message by device Y updating the existing record device X created, and write to Bob's DWN
285
282
  const deviceYData = new TextEncoder().encode('message from device Y');
286
283
  const deviceYDataStream = DataStream.fromBytes(deviceYData);
287
- const messageByDeviceY = yield RecordsWrite.createFrom({
284
+ const messageByDeviceY = await RecordsWrite.createFrom({
288
285
  recordsWriteMessage: fetchedDeviceXWrite.message,
289
286
  data: deviceYData,
290
287
  signer: Jws.createSigner(deviceY),
291
288
  delegatedGrant: deviceYGrant.dataEncodedMessage,
292
289
  });
293
- const deviceYWriteReply = yield dwn.processMessage(bob.did, messageByDeviceY.message, { dataStream: deviceYDataStream });
290
+ const deviceYWriteReply = await dwn.processMessage(bob.did, messageByDeviceY.message, { dataStream: deviceYDataStream });
294
291
  expect(deviceYWriteReply.status.code).toBe(202);
295
292
  // verify the message by device Y got written to Bob's DWN, AND Alice is the logical author
296
- const bobRecordsQueryReply2 = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
293
+ const bobRecordsQueryReply2 = await dwn.processMessage(bob.did, recordsQueryByBob.message);
297
294
  expect(bobRecordsQueryReply2.status.code).toBe(200);
298
- expect((_b = bobRecordsQueryReply2.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
295
+ expect(bobRecordsQueryReply2.entries?.length).toBe(1);
299
296
  const fetchedDeviceYWriteEntry = bobRecordsQueryReply2.entries[0];
300
297
  expect(fetchedDeviceYWriteEntry.encodedData).toBe(base64url.baseEncode(deviceYData));
301
- const fetchedDeviceYWrite = yield RecordsWrite.parse(fetchedDeviceYWriteEntry);
298
+ const fetchedDeviceYWrite = await RecordsWrite.parse(fetchedDeviceYWriteEntry);
302
299
  expect(fetchedDeviceYWrite.author).toBe(alice.did);
303
300
  // Verify that Carol cannot write a chat message as Alice by invoking the Device X's grant
304
301
  const messageByCarolAsAlice = new TextEncoder().encode('Message from Carol pretending to be Alice');
305
- const writeByCarolAsAlice = yield RecordsWrite.create({
302
+ const writeByCarolAsAlice = await RecordsWrite.create({
306
303
  signer: Jws.createSigner(carol),
307
304
  delegatedGrant: deviceXGrant.dataEncodedMessage,
308
305
  protocol,
@@ -311,40 +308,39 @@ export function testAuthorDelegatedGrant() {
311
308
  dataFormat: protocolDefinition.types.message.dataFormats[0],
312
309
  data: messageByCarolAsAlice
313
310
  });
314
- const carolWriteReply = yield dwn.processMessage(carol.did, writeByCarolAsAlice.message, { dataStream: DataStream.fromBytes(messageByCarolAsAlice) });
311
+ const carolWriteReply = await dwn.processMessage(carol.did, writeByCarolAsAlice.message, { dataStream: DataStream.fromBytes(messageByCarolAsAlice) });
315
312
  expect(carolWriteReply.status.code).toBe(400);
316
313
  expect(carolWriteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
317
- }));
318
- it('should only allow correct entity invoking an author-delegated grant to read and query ', () => __awaiter(this, void 0, void 0, function* () {
319
- var _a, _b, _c, _d;
314
+ });
315
+ it('should only allow correct entity invoking an author-delegated grant to read and query ', async () => {
320
316
  // scenario:
321
317
  // 1. Alice creates read and query delegated grants for device X,
322
318
  // 2. Bob starts a chat thread with Alice on his DWN
323
319
  // 3. device X should be able to read the chat thread
324
320
  // 4. Carol should not be able to read the chat thread using device X's delegated grant
325
- const alice = yield TestDataGenerator.generateDidKeyPersona();
326
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
327
- const bob = yield TestDataGenerator.generateDidKeyPersona();
328
- const carol = yield TestDataGenerator.generateDidKeyPersona();
321
+ const alice = await TestDataGenerator.generateDidKeyPersona();
322
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
323
+ const bob = await TestDataGenerator.generateDidKeyPersona();
324
+ const carol = await TestDataGenerator.generateDidKeyPersona();
329
325
  // Bob has the chat protocol installed
330
326
  const protocolDefinition = threadRoleProtocolDefinition;
331
327
  const protocol = threadRoleProtocolDefinition.protocol;
332
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
328
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
333
329
  author: bob,
334
330
  protocolDefinition
335
331
  });
336
- const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
332
+ const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
337
333
  expect(protocolsConfigureReply.status.code).toBe(202);
338
334
  // Bob starts a chat thread
339
- const threadRecord = yield TestDataGenerator.generateRecordsWrite({
335
+ const threadRecord = await TestDataGenerator.generateRecordsWrite({
340
336
  author: bob,
341
337
  protocol: protocolDefinition.protocol,
342
338
  protocolPath: 'thread',
343
339
  });
344
- const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
340
+ const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
345
341
  expect(threadRoleReply.status.code).toBe(202);
346
342
  // Bob adds Alice as a participant in the thread
347
- const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
343
+ const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
348
344
  author: bob,
349
345
  recipient: alice.did,
350
346
  protocol: protocolDefinition.protocol,
@@ -352,19 +348,19 @@ export function testAuthorDelegatedGrant() {
352
348
  parentContextId: threadRecord.message.contextId,
353
349
  data: new TextEncoder().encode('Alice is my friend'),
354
350
  });
355
- const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
351
+ const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
356
352
  expect(participantRoleReply.status.code).toBe(202);
357
353
  // Bob writes a chat message in the thread
358
- const chatRecord = yield TestDataGenerator.generateRecordsWrite({
354
+ const chatRecord = await TestDataGenerator.generateRecordsWrite({
359
355
  author: bob,
360
356
  protocol: protocolDefinition.protocol,
361
357
  protocolPath: 'thread/chat',
362
358
  parentContextId: threadRecord.message.contextId,
363
359
  });
364
- const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
360
+ const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
365
361
  expect(chatRecordReply.status.code).toBe(202);
366
362
  // Alice creates a delegated query grant for device X to act as Alice.
367
- const queryGrantForDeviceX = yield PermissionsProtocol.createGrant({
363
+ const queryGrantForDeviceX = await PermissionsProtocol.createGrant({
368
364
  delegated: true, // this is a delegated grant
369
365
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
370
366
  grantedTo: deviceX.did,
@@ -376,7 +372,7 @@ export function testAuthorDelegatedGrant() {
376
372
  signer: Jws.createSigner(alice)
377
373
  });
378
374
  // Alice creates a delegated read grant for device X to act as Alice.
379
- const readGrantForDeviceX = yield PermissionsProtocol.createGrant({
375
+ const readGrantForDeviceX = await PermissionsProtocol.createGrant({
380
376
  delegated: true, // this is a delegated grant
381
377
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
382
378
  grantedTo: deviceX.did,
@@ -388,15 +384,15 @@ export function testAuthorDelegatedGrant() {
388
384
  signer: Jws.createSigner(alice)
389
385
  });
390
386
  // sanity verify Bob himself is able to query for the chat thread from Bob's DWN
391
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
387
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
392
388
  author: bob,
393
389
  filter: { protocol }
394
390
  });
395
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
391
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
396
392
  expect(bobRecordsQueryReply.status.code).toBe(200);
397
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(3);
393
+ expect(bobRecordsQueryReply.entries?.length).toBe(3);
398
394
  // sanity verify Alice herself is able to query for the chat message from Bob's DWN
399
- const recordsQueryByAlice = yield RecordsQuery.create({
395
+ const recordsQueryByAlice = await RecordsQuery.create({
400
396
  signer: Jws.createSigner(alice),
401
397
  protocolRole: 'thread/participant',
402
398
  filter: {
@@ -405,11 +401,11 @@ export function testAuthorDelegatedGrant() {
405
401
  protocolPath: 'thread/chat'
406
402
  }
407
403
  });
408
- const aliceRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByAlice.message);
404
+ const aliceRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByAlice.message);
409
405
  expect(aliceRecordsQueryReply.status.code).toBe(200);
410
- expect((_b = aliceRecordsQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(1);
406
+ expect(aliceRecordsQueryReply.entries?.length).toBe(1);
411
407
  // verify device X is able to query for the chat message from Bob's DWN
412
- const recordsQueryByDeviceX = yield RecordsQuery.create({
408
+ const recordsQueryByDeviceX = await RecordsQuery.create({
413
409
  signer: Jws.createSigner(deviceX),
414
410
  delegatedGrant: queryGrantForDeviceX.dataEncodedMessage,
415
411
  protocolRole: 'thread/participant',
@@ -419,11 +415,11 @@ export function testAuthorDelegatedGrant() {
419
415
  protocolPath: 'thread/chat'
420
416
  }
421
417
  });
422
- const deviceXRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
418
+ const deviceXRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
423
419
  expect(deviceXRecordsQueryReply.status.code).toBe(200);
424
- expect((_c = deviceXRecordsQueryReply.entries) === null || _c === void 0 ? void 0 : _c.length).toBe(1);
420
+ expect(deviceXRecordsQueryReply.entries?.length).toBe(1);
425
421
  // verify device X is able to read the chat message from Bob's DWN
426
- const recordsReadByDeviceX = yield RecordsRead.create({
422
+ const recordsReadByDeviceX = await RecordsRead.create({
427
423
  signer: Jws.createSigner(deviceX),
428
424
  delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
429
425
  protocolRole: 'thread/participant',
@@ -431,11 +427,11 @@ export function testAuthorDelegatedGrant() {
431
427
  recordId: chatRecord.message.recordId
432
428
  }
433
429
  });
434
- const deviceXRecordsReadReply = yield dwn.processMessage(bob.did, recordsReadByDeviceX.message);
430
+ const deviceXRecordsReadReply = await dwn.processMessage(bob.did, recordsReadByDeviceX.message);
435
431
  expect(deviceXRecordsReadReply.status.code).toBe(200);
436
- expect((_d = deviceXRecordsReadReply.entry.recordsWrite) === null || _d === void 0 ? void 0 : _d.recordId).toBe(chatRecord.message.recordId);
432
+ expect(deviceXRecordsReadReply.entry.recordsWrite?.recordId).toBe(chatRecord.message.recordId);
437
433
  // Verify that Carol cannot query as Alice by invoking the delegated grant granted to Device X
438
- const recordsQueryByCarol = yield RecordsQuery.create({
434
+ const recordsQueryByCarol = await RecordsQuery.create({
439
435
  signer: Jws.createSigner(carol),
440
436
  delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
441
437
  protocolRole: 'thread/participant',
@@ -445,11 +441,11 @@ export function testAuthorDelegatedGrant() {
445
441
  protocolPath: 'thread/chat'
446
442
  }
447
443
  });
448
- const recordsQueryByCarolReply = yield dwn.processMessage(bob.did, recordsQueryByCarol.message);
444
+ const recordsQueryByCarolReply = await dwn.processMessage(bob.did, recordsQueryByCarol.message);
449
445
  expect(recordsQueryByCarolReply.status.code).toBe(400);
450
446
  expect(recordsQueryByCarolReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
451
447
  // Verify that Carol cannot read as Alice by invoking the delegated grant granted to Device X
452
- const recordsReadByCarol = yield RecordsRead.create({
448
+ const recordsReadByCarol = await RecordsRead.create({
453
449
  signer: Jws.createSigner(carol),
454
450
  delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
455
451
  protocolRole: 'thread/participant',
@@ -457,11 +453,11 @@ export function testAuthorDelegatedGrant() {
457
453
  recordId: chatRecord.message.recordId
458
454
  }
459
455
  });
460
- const recordsReadByCarolReply = yield dwn.processMessage(bob.did, recordsReadByCarol.message);
456
+ const recordsReadByCarolReply = await dwn.processMessage(bob.did, recordsReadByCarol.message);
461
457
  expect(recordsReadByCarolReply.status.code).toBe(400);
462
458
  expect(recordsQueryByCarolReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
463
- }));
464
- it('should only allow correct entity invoking an author-delegated grant to subscribe', () => __awaiter(this, void 0, void 0, function* () {
459
+ });
460
+ it('should only allow correct entity invoking an author-delegated grant to subscribe', async () => {
465
461
  // scenario:
466
462
  // 1. Bob installs a chat protocol and creates a thread, adding Alice as a participant.
467
463
  // 2. Alice a creates subscribe delegated grant for device X,
@@ -471,30 +467,29 @@ export function testAuthorDelegatedGrant() {
471
467
  // 6. The subscription should have received the chat messages.
472
468
  // 7. Bob deletes one of the chat messages.
473
469
  // 8. The subscription should have received the delete event.
474
- var _a;
475
- const alice = yield TestDataGenerator.generateDidKeyPersona();
476
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
477
- const bob = yield TestDataGenerator.generateDidKeyPersona();
478
- const carol = yield TestDataGenerator.generateDidKeyPersona();
470
+ const alice = await TestDataGenerator.generateDidKeyPersona();
471
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
472
+ const bob = await TestDataGenerator.generateDidKeyPersona();
473
+ const carol = await TestDataGenerator.generateDidKeyPersona();
479
474
  // Bob has the chat protocol installed
480
475
  const protocolDefinition = threadRoleProtocolDefinition;
481
476
  const protocol = threadRoleProtocolDefinition.protocol;
482
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
477
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
483
478
  author: bob,
484
479
  protocolDefinition
485
480
  });
486
- const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
481
+ const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
487
482
  expect(protocolsConfigureReply.status.code).toBe(202);
488
483
  // Bob starts a chat thread
489
- const threadRecord = yield TestDataGenerator.generateRecordsWrite({
484
+ const threadRecord = await TestDataGenerator.generateRecordsWrite({
490
485
  author: bob,
491
486
  protocol: protocolDefinition.protocol,
492
487
  protocolPath: 'thread',
493
488
  });
494
- const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
489
+ const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
495
490
  expect(threadRoleReply.status.code).toBe(202);
496
491
  // Bob adds Alice as a participant in the thread
497
- const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
492
+ const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
498
493
  author: bob,
499
494
  recipient: alice.did,
500
495
  protocol: protocolDefinition.protocol,
@@ -502,10 +497,10 @@ export function testAuthorDelegatedGrant() {
502
497
  parentContextId: threadRecord.message.contextId,
503
498
  data: new TextEncoder().encode('Alice is my friend'),
504
499
  });
505
- const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
500
+ const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
506
501
  expect(participantRoleReply.status.code).toBe(202);
507
502
  // Alice creates a delegated subscribe grant for device X to act as Alice.
508
- const subscribeGrantForDeviceX = yield PermissionsProtocol.createGrant({
503
+ const subscribeGrantForDeviceX = await PermissionsProtocol.createGrant({
509
504
  delegated: true, // this is a delegated grant
510
505
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
511
506
  grantedTo: deviceX.did,
@@ -518,8 +513,11 @@ export function testAuthorDelegatedGrant() {
518
513
  });
519
514
  // Create a handler to set or delete the chat record ID in the subscription set depending on the interface method
520
515
  const subscriptionChatRecords = new Set();
521
- const captureChatRecords = (event) => __awaiter(this, void 0, void 0, function* () {
522
- const { message } = event;
516
+ const captureChatRecords = async (msg) => {
517
+ if (msg.type !== 'event') {
518
+ return;
519
+ }
520
+ const { message } = msg.event;
523
521
  if (message.descriptor.method === DwnMethodName.Delete) {
524
522
  const recordId = message.descriptor.recordId;
525
523
  subscriptionChatRecords.delete(recordId);
@@ -528,9 +526,9 @@ export function testAuthorDelegatedGrant() {
528
526
  const recordId = message.recordId;
529
527
  subscriptionChatRecords.add(recordId);
530
528
  }
531
- });
529
+ };
532
530
  // control: verify that device X cannot subscribe to the chat thread without the delegated grant
533
- const recordsSubscribeByDeviceXWithoutGrant = yield RecordsSubscribe.create({
531
+ const recordsSubscribeByDeviceXWithoutGrant = await RecordsSubscribe.create({
534
532
  signer: Jws.createSigner(deviceX),
535
533
  protocolRole: 'thread/participant',
536
534
  filter: {
@@ -539,10 +537,10 @@ export function testAuthorDelegatedGrant() {
539
537
  protocolPath: 'thread/chat'
540
538
  }
541
539
  });
542
- const recordsSubscribeByDeviceXWithoutGrantReply = yield dwn.processMessage(bob.did, recordsSubscribeByDeviceXWithoutGrant.message);
540
+ const recordsSubscribeByDeviceXWithoutGrantReply = await dwn.processMessage(bob.did, recordsSubscribeByDeviceXWithoutGrant.message);
543
541
  expect(recordsSubscribeByDeviceXWithoutGrantReply.status.code).toBe(401, 'device X without grant subscribe');
544
542
  // control: verify that Carol cannot subscribe as Alice by invoking the delegated grant granted to Device X
545
- const recordsSubscribeByCarol = yield RecordsSubscribe.create({
543
+ const recordsSubscribeByCarol = await RecordsSubscribe.create({
546
544
  signer: Jws.createSigner(carol),
547
545
  delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
548
546
  protocolRole: 'thread/participant',
@@ -552,11 +550,11 @@ export function testAuthorDelegatedGrant() {
552
550
  protocolPath: 'thread/chat'
553
551
  }
554
552
  });
555
- const recordsSubscribeByCarolReply = yield dwn.processMessage(bob.did, recordsSubscribeByCarol.message);
553
+ const recordsSubscribeByCarolReply = await dwn.processMessage(bob.did, recordsSubscribeByCarol.message);
556
554
  expect(recordsSubscribeByCarolReply.status.code).toBe(400, 'carol subscribe');
557
555
  expect(recordsSubscribeByCarolReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantGrantedToAndOwnerSignatureMismatch);
558
556
  // verify device X is able to subscribe the chat message from Bob's DWN using the delegated grant
559
- const recordsSubscribeByDeviceX = yield RecordsSubscribe.create({
557
+ const recordsSubscribeByDeviceX = await RecordsSubscribe.create({
560
558
  signer: Jws.createSigner(deviceX),
561
559
  delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
562
560
  protocolRole: 'thread/participant',
@@ -566,84 +564,83 @@ export function testAuthorDelegatedGrant() {
566
564
  protocolPath: 'thread/chat'
567
565
  }
568
566
  });
569
- const recordsSubscribeByDeviceXReply = yield dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message, {
567
+ const recordsSubscribeByDeviceXReply = await dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message, {
570
568
  subscriptionHandler: captureChatRecords
571
569
  });
572
570
  expect(recordsSubscribeByDeviceXReply.status.code).toBe(200, 'subscribe');
573
571
  // Bob writes chat messages in the thread
574
- const chatRecord1 = yield TestDataGenerator.generateRecordsWrite({
572
+ const chatRecord1 = await TestDataGenerator.generateRecordsWrite({
575
573
  author: bob,
576
574
  protocol: protocolDefinition.protocol,
577
575
  protocolPath: 'thread/chat',
578
576
  parentContextId: threadRecord.message.contextId,
579
577
  });
580
- const chatRecord1Reply = yield dwn.processMessage(bob.did, chatRecord1.message, { dataStream: chatRecord1.dataStream });
578
+ const chatRecord1Reply = await dwn.processMessage(bob.did, chatRecord1.message, { dataStream: chatRecord1.dataStream });
581
579
  expect(chatRecord1Reply.status.code).toBe(202);
582
- const chatRecord2 = yield TestDataGenerator.generateRecordsWrite({
580
+ const chatRecord2 = await TestDataGenerator.generateRecordsWrite({
583
581
  author: bob,
584
582
  protocol: protocolDefinition.protocol,
585
583
  protocolPath: 'thread/chat',
586
584
  parentContextId: threadRecord.message.contextId,
587
585
  });
588
- const chatRecord2Reply = yield dwn.processMessage(bob.did, chatRecord2.message, { dataStream: chatRecord2.dataStream });
586
+ const chatRecord2Reply = await dwn.processMessage(bob.did, chatRecord2.message, { dataStream: chatRecord2.dataStream });
589
587
  expect(chatRecord2Reply.status.code).toBe(202);
590
- yield Poller.pollUntilSuccessOrTimeout(() => __awaiter(this, void 0, void 0, function* () {
588
+ await Poller.pollUntilSuccessOrTimeout(async () => {
591
589
  expect(subscriptionChatRecords.size).toBe(2);
592
590
  expect([...subscriptionChatRecords]).toEqual(expect.arrayContaining([chatRecord1.message.recordId, chatRecord2.message.recordId]));
593
- }));
594
- yield ((_a = recordsSubscribeByDeviceXReply.subscription) === null || _a === void 0 ? void 0 : _a.close());
595
- }));
596
- it('should only allow correct entity invoking an author-delegated grant to delete', () => __awaiter(this, void 0, void 0, function* () {
597
- var _a, _b;
591
+ });
592
+ await recordsSubscribeByDeviceXReply.subscription?.close();
593
+ });
594
+ it('should only allow correct entity invoking an author-delegated grant to delete', async () => {
598
595
  // scenario:
599
596
  // 1. Bob installs the chat protocol on his DWN and makes Alice an admin
600
597
  // 2. Bob starts a chat thread with Carol on his DWN
601
598
  // 3. Alice creates a delegated grant for Device X to act as her
602
599
  // 4. Carol should not be able to delete a chat message as Alice using Device X's delegated grant
603
600
  // 5. Device X should be able to delete a chat message as Alice
604
- const alice = yield TestDataGenerator.generateDidKeyPersona();
605
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
606
- const bob = yield TestDataGenerator.generateDidKeyPersona();
607
- const carol = yield TestDataGenerator.generateDidKeyPersona();
601
+ const alice = await TestDataGenerator.generateDidKeyPersona();
602
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
603
+ const bob = await TestDataGenerator.generateDidKeyPersona();
604
+ const carol = await TestDataGenerator.generateDidKeyPersona();
608
605
  // Bob has the chat protocol installed
609
606
  const protocolDefinition = threadRoleProtocolDefinition;
610
607
  const protocol = threadRoleProtocolDefinition.protocol;
611
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
608
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
612
609
  author: bob,
613
610
  protocolDefinition
614
611
  });
615
- const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
612
+ const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
616
613
  expect(protocolsConfigureReply.status.code).toBe(202);
617
614
  // Bob adds Alice as an admin
618
- const globalAdminRecord = yield TestDataGenerator.generateRecordsWrite({
615
+ const globalAdminRecord = await TestDataGenerator.generateRecordsWrite({
619
616
  author: bob,
620
617
  recipient: alice.did,
621
618
  protocol: protocolDefinition.protocol,
622
619
  protocolPath: 'globalAdmin',
623
620
  data: new TextEncoder().encode('I trust Alice to manage my chat thread'),
624
621
  });
625
- const globalAdminRecordReply = yield dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
622
+ const globalAdminRecordReply = await dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
626
623
  expect(globalAdminRecordReply.status.code).toBe(202);
627
624
  // Bob starts a chat thread
628
- const threadRecord = yield TestDataGenerator.generateRecordsWrite({
625
+ const threadRecord = await TestDataGenerator.generateRecordsWrite({
629
626
  author: bob,
630
627
  protocol: protocolDefinition.protocol,
631
628
  protocolPath: 'thread',
632
629
  });
633
- const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
630
+ const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
634
631
  expect(threadRoleReply.status.code).toBe(202);
635
632
  // Bob adds Carol as a participant in the thread
636
- const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
633
+ const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
637
634
  author: bob,
638
635
  recipient: carol.did,
639
636
  protocol: protocolDefinition.protocol,
640
637
  protocolPath: 'thread/participant',
641
638
  parentContextId: threadRecord.message.contextId
642
639
  });
643
- const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
640
+ const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
644
641
  expect(participantRoleReply.status.code).toBe(202);
645
642
  // Carol writes a chat message in the thread
646
- const chatRecord = yield TestDataGenerator.generateRecordsWrite({
643
+ const chatRecord = await TestDataGenerator.generateRecordsWrite({
647
644
  author: carol,
648
645
  protocolRole: 'thread/participant',
649
646
  protocol: protocolDefinition.protocol,
@@ -651,10 +648,10 @@ export function testAuthorDelegatedGrant() {
651
648
  parentContextId: threadRecord.message.contextId,
652
649
  data: new TextEncoder().encode('A rude message'),
653
650
  });
654
- const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
651
+ const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
655
652
  expect(chatRecordReply.status.code).toBe(202);
656
653
  // Alice creates a delegated delete grant for device X to act as Alice.
657
- const deleteGrantForDeviceX = yield PermissionsProtocol.createGrant({
654
+ const deleteGrantForDeviceX = await PermissionsProtocol.createGrant({
658
655
  delegated: true, // this is a delegated grant
659
656
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
660
657
  grantedTo: deviceX.did,
@@ -666,54 +663,53 @@ export function testAuthorDelegatedGrant() {
666
663
  signer: Jws.createSigner(alice)
667
664
  });
668
665
  // verify Carol is not able to delete Carol's chat message from Bob's DWN
669
- const recordsDeleteByCarol = yield RecordsDelete.create({
666
+ const recordsDeleteByCarol = await RecordsDelete.create({
670
667
  signer: Jws.createSigner(carol),
671
668
  delegatedGrant: deleteGrantForDeviceX.dataEncodedMessage,
672
669
  protocolRole: 'thread/participant',
673
670
  recordId: chatRecord.message.recordId
674
671
  });
675
- const carolRecordsDeleteReply = yield dwn.processMessage(bob.did, recordsDeleteByCarol.message);
672
+ const carolRecordsDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByCarol.message);
676
673
  expect(carolRecordsDeleteReply.status.code).toBe(400);
677
674
  // sanity verify the chat message is still in Bob's DWN
678
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
675
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
679
676
  author: bob,
680
677
  filter: { protocolPath: 'thread/chat' }
681
678
  });
682
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
679
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
683
680
  expect(bobRecordsQueryReply.status.code).toBe(200);
684
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
681
+ expect(bobRecordsQueryReply.entries?.length).toBe(1);
685
682
  // verify device X is able to delete Carol's chat message from Bob's DWN
686
- const recordsDeleteByDeviceX = yield RecordsDelete.create({
683
+ const recordsDeleteByDeviceX = await RecordsDelete.create({
687
684
  signer: Jws.createSigner(deviceX),
688
685
  delegatedGrant: deleteGrantForDeviceX.dataEncodedMessage,
689
686
  protocolRole: 'globalAdmin',
690
687
  recordId: chatRecord.message.recordId
691
688
  });
692
- const deviceXRecordsDeleteReply = yield dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
689
+ const deviceXRecordsDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
693
690
  expect(deviceXRecordsDeleteReply.status.code).toBe(202);
694
691
  // sanity verify the chat message is no longer queryable from Bob's DWN
695
- const bobRecordsQueryReply2 = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
692
+ const bobRecordsQueryReply2 = await dwn.processMessage(bob.did, recordsQueryByBob.message);
696
693
  expect(bobRecordsQueryReply2.status.code).toBe(200);
697
- expect((_b = bobRecordsQueryReply2.entries) === null || _b === void 0 ? void 0 : _b.length).toBe(0);
698
- }));
699
- it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke write', () => __awaiter(this, void 0, void 0, function* () {
700
- var _a;
694
+ expect(bobRecordsQueryReply2.entries?.length).toBe(0);
695
+ });
696
+ it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke write', async () => {
701
697
  // scenario:
702
698
  // 1. Bob has the message protocol installed
703
699
  // 2. Alice creates a non-delegated grant for device X
704
700
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the non-delegated grant
705
701
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
706
- const alice = yield TestDataGenerator.generateDidKeyPersona();
707
- const bob = yield TestDataGenerator.generateDidKeyPersona();
708
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
702
+ const alice = await TestDataGenerator.generateDidKeyPersona();
703
+ const bob = await TestDataGenerator.generateDidKeyPersona();
704
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
709
705
  // 1. Bob has the message protocol installed
710
706
  const protocolDefinition = messageProtocolDefinition;
711
707
  const protocol = protocolDefinition.protocol;
712
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
708
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
713
709
  author: bob,
714
710
  protocolDefinition
715
711
  });
716
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
712
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
717
713
  expect(protocolConfigureReply.status.code).toBe(202);
718
714
  // 2. Alice creates a non-delegated grant for device X
719
715
  const scope = {
@@ -721,7 +717,7 @@ export function testAuthorDelegatedGrant() {
721
717
  method: DwnMethodName.Write,
722
718
  protocol
723
719
  };
724
- const deviceXGrant = yield PermissionsProtocol.createGrant({
720
+ const deviceXGrant = await PermissionsProtocol.createGrant({
725
721
  // delegated : true, // intentionally commented out to show that this is not a delegated grant
726
722
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
727
723
  grantedTo: deviceX.did,
@@ -731,7 +727,7 @@ export function testAuthorDelegatedGrant() {
731
727
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the non-delegated grant
732
728
  const deviceXData = new TextEncoder().encode('message from device X');
733
729
  const deviceXDataStream = DataStream.fromBytes(deviceXData);
734
- const messageByDeviceX = yield RecordsWrite.create({
730
+ const messageByDeviceX = await RecordsWrite.create({
735
731
  signer: Jws.createSigner(deviceX),
736
732
  delegatedGrant: deviceXGrant.dataEncodedMessage,
737
733
  protocol,
@@ -740,48 +736,48 @@ export function testAuthorDelegatedGrant() {
740
736
  dataFormat: protocolDefinition.types.message.dataFormats[0],
741
737
  data: deviceXData
742
738
  });
743
- const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
739
+ const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
744
740
  expect(deviceXWriteReply.status.code).toBe(400);
745
741
  expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
746
742
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
747
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
743
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
748
744
  author: bob,
749
745
  filter: { protocol }
750
746
  });
751
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
747
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
752
748
  expect(bobRecordsQueryReply.status.code).toBe(200);
753
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
754
- }));
755
- it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke read', () => __awaiter(this, void 0, void 0, function* () {
749
+ expect(bobRecordsQueryReply.entries?.length).toBe(0);
750
+ });
751
+ it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke read', async () => {
756
752
  // scenario:
757
753
  // 1. Bob has the message protocol installed
758
754
  // 2. Alice writes a message to Bob's DWN
759
755
  // 3. Alice creates a non-delegated read grant for device X
760
756
  // 4. Verify that device X cannot read the message from Bob's DWN as Alice using the non-delegated grant
761
- const alice = yield TestDataGenerator.generateDidKeyPersona();
762
- const bob = yield TestDataGenerator.generateDidKeyPersona();
763
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
757
+ const alice = await TestDataGenerator.generateDidKeyPersona();
758
+ const bob = await TestDataGenerator.generateDidKeyPersona();
759
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
764
760
  // 1. Bob has the message protocol installed
765
761
  const protocolDefinition = messageProtocolDefinition;
766
762
  const protocol = protocolDefinition.protocol;
767
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
763
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
768
764
  author: bob,
769
765
  protocolDefinition
770
766
  });
771
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
767
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
772
768
  expect(protocolConfigureReply.status.code).toBe(202);
773
769
  // 2. Alice writes a message to Bob's DWN
774
- const messageByAlice = yield TestDataGenerator.generateRecordsWrite({
770
+ const messageByAlice = await TestDataGenerator.generateRecordsWrite({
775
771
  author: alice,
776
772
  protocol,
777
773
  protocolPath: 'message',
778
774
  schema: protocolDefinition.types.message.schema,
779
775
  dataFormat: protocolDefinition.types.message.dataFormats[0],
780
776
  });
781
- const aliceWriteReply = yield dwn.processMessage(bob.did, messageByAlice.message, { dataStream: messageByAlice.dataStream });
777
+ const aliceWriteReply = await dwn.processMessage(bob.did, messageByAlice.message, { dataStream: messageByAlice.dataStream });
782
778
  expect(aliceWriteReply.status.code).toBe(202);
783
779
  // 3. Alice creates a non-delegated read grant for device X
784
- const deviceXGrant = yield PermissionsProtocol.createGrant({
780
+ const deviceXGrant = await PermissionsProtocol.createGrant({
785
781
  // delegated : true, // intentionally commented out to show that this is not a delegated grant
786
782
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
787
783
  grantedTo: deviceX.did,
@@ -793,36 +789,36 @@ export function testAuthorDelegatedGrant() {
793
789
  signer: Jws.createSigner(alice)
794
790
  });
795
791
  // 4. Verify that device X cannot read the message from Bob's DWN as Alice using the non-delegated grant
796
- const recordsReadByDeviceX = yield RecordsRead.create({
792
+ const recordsReadByDeviceX = await RecordsRead.create({
797
793
  signer: Jws.createSigner(deviceX),
798
794
  delegatedGrant: deviceXGrant.dataEncodedMessage,
799
795
  filter: {
800
796
  recordId: messageByAlice.message.recordId
801
797
  }
802
798
  });
803
- const deviceXReadReply = yield dwn.processMessage(bob.did, recordsReadByDeviceX.message);
799
+ const deviceXReadReply = await dwn.processMessage(bob.did, recordsReadByDeviceX.message);
804
800
  expect(deviceXReadReply.status.code).toBe(400);
805
801
  expect(deviceXReadReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
806
- }));
807
- it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke query', () => __awaiter(this, void 0, void 0, function* () {
802
+ });
803
+ it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke query', async () => {
808
804
  // scenario:
809
805
  // 1. Bob has the message protocol installed
810
806
  // 2. Alice creates a non-delegated query grant for device X
811
807
  // 3. Verify that device X cannot query Bob's DWN as Alice using the non-delegated grant
812
- const alice = yield TestDataGenerator.generateDidKeyPersona();
813
- const bob = yield TestDataGenerator.generateDidKeyPersona();
814
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
808
+ const alice = await TestDataGenerator.generateDidKeyPersona();
809
+ const bob = await TestDataGenerator.generateDidKeyPersona();
810
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
815
811
  // 1. Bob has the message protocol installed
816
812
  const protocolDefinition = messageProtocolDefinition;
817
813
  const protocol = protocolDefinition.protocol;
818
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
814
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
819
815
  author: bob,
820
816
  protocolDefinition
821
817
  });
822
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
818
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
823
819
  expect(protocolConfigureReply.status.code).toBe(202);
824
820
  // 2. Alice creates a non-delegated query grant for device X
825
- const deviceXGrant = yield PermissionsProtocol.createGrant({
821
+ const deviceXGrant = await PermissionsProtocol.createGrant({
826
822
  // delegated : true, // intentionally commented out to show that this is not a delegated grant
827
823
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
828
824
  grantedTo: deviceX.did,
@@ -834,7 +830,7 @@ export function testAuthorDelegatedGrant() {
834
830
  signer: Jws.createSigner(alice)
835
831
  });
836
832
  // 3. Verify that device X cannot query Bob's DWN as Alice using the non-delegated grant
837
- const recordsQueryByDeviceX = yield RecordsQuery.create({
833
+ const recordsQueryByDeviceX = await RecordsQuery.create({
838
834
  signer: Jws.createSigner(deviceX),
839
835
  delegatedGrant: deviceXGrant.dataEncodedMessage,
840
836
  filter: {
@@ -842,42 +838,41 @@ export function testAuthorDelegatedGrant() {
842
838
  protocolPath: 'message'
843
839
  }
844
840
  });
845
- const deviceXQueryReply = yield dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
841
+ const deviceXQueryReply = await dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
846
842
  expect(deviceXQueryReply.status.code).toBe(400);
847
843
  expect(deviceXQueryReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
848
- }));
849
- it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke delete', () => __awaiter(this, void 0, void 0, function* () {
850
- var _a;
844
+ });
845
+ it('should not allow entity using a non-delegated grant as an author-delegated grant to invoke delete', async () => {
851
846
  // scenario:
852
847
  // 1. Bob has the message protocol installed
853
848
  // 2. Alice writes a message to Bob's DWN
854
849
  // 3. Alice creates a non-delegated delete grant for device X
855
850
  // 4. Verify that device X cannot delete the message from Bob's DWN as Alice using the non-delegated grant
856
851
  // 5. Sanity verify the message still exists in Bob's DWN
857
- const alice = yield TestDataGenerator.generateDidKeyPersona();
858
- const bob = yield TestDataGenerator.generateDidKeyPersona();
859
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
852
+ const alice = await TestDataGenerator.generateDidKeyPersona();
853
+ const bob = await TestDataGenerator.generateDidKeyPersona();
854
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
860
855
  // 1. Bob has the message protocol installed
861
856
  const protocolDefinition = messageProtocolDefinition;
862
857
  const protocol = protocolDefinition.protocol;
863
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
858
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
864
859
  author: bob,
865
860
  protocolDefinition
866
861
  });
867
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
862
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
868
863
  expect(protocolConfigureReply.status.code).toBe(202);
869
864
  // 2. Alice writes a message to Bob's DWN
870
- const messageByAlice = yield TestDataGenerator.generateRecordsWrite({
865
+ const messageByAlice = await TestDataGenerator.generateRecordsWrite({
871
866
  author: alice,
872
867
  protocol,
873
868
  protocolPath: 'message',
874
869
  schema: protocolDefinition.types.message.schema,
875
870
  dataFormat: protocolDefinition.types.message.dataFormats[0],
876
871
  });
877
- const aliceWriteReply = yield dwn.processMessage(bob.did, messageByAlice.message, { dataStream: messageByAlice.dataStream });
872
+ const aliceWriteReply = await dwn.processMessage(bob.did, messageByAlice.message, { dataStream: messageByAlice.dataStream });
878
873
  expect(aliceWriteReply.status.code).toBe(202);
879
874
  // 3. Alice creates a non-delegated delete grant for device X
880
- const deviceXGrant = yield PermissionsProtocol.createGrant({
875
+ const deviceXGrant = await PermissionsProtocol.createGrant({
881
876
  // delegated : true, // intentionally commented out to show that this is not a delegated grant
882
877
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
883
878
  grantedTo: deviceX.did,
@@ -889,39 +884,39 @@ export function testAuthorDelegatedGrant() {
889
884
  signer: Jws.createSigner(alice)
890
885
  });
891
886
  // 4. Verify that device X cannot delete the message from Bob's DWN as Alice using the non-delegated grant
892
- const recordsDeleteByDeviceX = yield RecordsDelete.create({
887
+ const recordsDeleteByDeviceX = await RecordsDelete.create({
893
888
  signer: Jws.createSigner(deviceX),
894
889
  delegatedGrant: deviceXGrant.dataEncodedMessage,
895
890
  recordId: messageByAlice.message.recordId
896
891
  });
897
- const deviceXDeleteReply = yield dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
892
+ const deviceXDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
898
893
  expect(deviceXDeleteReply.status.code).toBe(400);
899
894
  expect(deviceXDeleteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantNotADelegatedGrant);
900
895
  // 5. Sanity verify the message still exists in Bob's DWN
901
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
896
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
902
897
  author: bob,
903
898
  filter: { protocol }
904
899
  });
905
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
900
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
906
901
  expect(bobRecordsQueryReply.status.code).toBe(200);
907
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
908
- }));
909
- it('should fail if author-delegated grant has a mismatching protocol scope - write', () => __awaiter(this, void 0, void 0, function* () {
902
+ expect(bobRecordsQueryReply.entries?.length).toBe(1);
903
+ });
904
+ it('should fail if author-delegated grant has a mismatching protocol scope - write', async () => {
910
905
  // scenario:
911
906
  // 1. Alice creates a delegated grant for device X to act as her for a protocol that is NOT email protocol
912
907
  // 2. Bob has email protocol configured for his DWN that allows anyone to write an email to him
913
908
  // 3. Device X attempts to use the delegated grant to write an email to Bob as Alice
914
909
  // 4. Bob's DWN should reject Device X's message
915
- const alice = yield TestDataGenerator.generateDidKeyPersona();
916
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
917
- const bob = yield TestDataGenerator.generateDidKeyPersona();
910
+ const alice = await TestDataGenerator.generateDidKeyPersona();
911
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
912
+ const bob = await TestDataGenerator.generateDidKeyPersona();
918
913
  // 1. Alice creates a delegated grant for device X to act as her for a protocol that is NOT email protocol
919
914
  const scope = {
920
915
  interface: DwnInterfaceName.Records,
921
916
  method: DwnMethodName.Write,
922
917
  protocol: 'random-protocol'
923
918
  };
924
- const deviceXGrant = yield PermissionsProtocol.createGrant({
919
+ const deviceXGrant = await PermissionsProtocol.createGrant({
925
920
  delegated: true, // this is a delegated grant
926
921
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
927
922
  grantedTo: deviceX.did,
@@ -931,16 +926,16 @@ export function testAuthorDelegatedGrant() {
931
926
  // 2. Bob has email protocol configured for his DWN that allows anyone to write an email to him
932
927
  const protocolDefinition = emailProtocolDefinition;
933
928
  const protocol = protocolDefinition.protocol;
934
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
929
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
935
930
  author: bob,
936
931
  protocolDefinition
937
932
  });
938
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
933
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
939
934
  expect(protocolConfigureReply.status.code).toBe(202);
940
935
  // 3. Device X attempts to use the delegated grant to write an email to Bob as Alice
941
936
  const deviceXData = new TextEncoder().encode('message from device X');
942
937
  const deviceXDataStream = DataStream.fromBytes(deviceXData);
943
- const messageByDeviceX = yield RecordsWrite.create({
938
+ const messageByDeviceX = await RecordsWrite.create({
944
939
  signer: Jws.createSigner(deviceX),
945
940
  delegatedGrant: deviceXGrant.dataEncodedMessage,
946
941
  protocol,
@@ -949,38 +944,38 @@ export function testAuthorDelegatedGrant() {
949
944
  dataFormat: protocolDefinition.types.email.dataFormats[0],
950
945
  data: deviceXData
951
946
  });
952
- const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
947
+ const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
953
948
  expect(deviceXWriteReply.status.code).toBe(401);
954
949
  expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
955
- }));
956
- it('should fail if author-delegated grant has a mismatching protocol scope - query, subscribe & read', () => __awaiter(this, void 0, void 0, function* () {
950
+ });
951
+ it('should fail if author-delegated grant has a mismatching protocol scope - query, subscribe & read', async () => {
957
952
  // scenario:
958
953
  // 1. Bob starts a chat thread with Alice on his DWN
959
954
  // 2. Alice creates a delegated grant for device X to act as her for a protocol that is NOT chat protocol
960
955
  // 3. Device X attempts to use the delegated grant to read, query and subscribe to the chat thread and gets rejected by Bob's DWN
961
- const alice = yield TestDataGenerator.generateDidKeyPersona();
962
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
963
- const bob = yield TestDataGenerator.generateDidKeyPersona();
956
+ const alice = await TestDataGenerator.generateDidKeyPersona();
957
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
958
+ const bob = await TestDataGenerator.generateDidKeyPersona();
964
959
  // 1. Bob starts a chat thread with Alice on his DWN
965
960
  // Bob has the chat protocol installed
966
961
  const protocolDefinition = threadRoleProtocolDefinition;
967
962
  const protocol = threadRoleProtocolDefinition.protocol;
968
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
963
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
969
964
  author: bob,
970
965
  protocolDefinition
971
966
  });
972
- const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
967
+ const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
973
968
  expect(protocolsConfigureReply.status.code).toBe(202);
974
969
  // Bob starts a chat thread
975
- const threadRecord = yield TestDataGenerator.generateRecordsWrite({
970
+ const threadRecord = await TestDataGenerator.generateRecordsWrite({
976
971
  author: bob,
977
972
  protocol: protocolDefinition.protocol,
978
973
  protocolPath: 'thread',
979
974
  });
980
- const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
975
+ const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
981
976
  expect(threadRoleReply.status.code).toBe(202);
982
977
  // Bob adds Alice as a participant in the thread
983
- const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
978
+ const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
984
979
  author: bob,
985
980
  recipient: alice.did,
986
981
  protocol: protocolDefinition.protocol,
@@ -988,20 +983,20 @@ export function testAuthorDelegatedGrant() {
988
983
  parentContextId: threadRecord.message.contextId,
989
984
  data: new TextEncoder().encode('Alice is my friend'),
990
985
  });
991
- const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
986
+ const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
992
987
  expect(participantRoleReply.status.code).toBe(202);
993
988
  // Bob writes a chat message in the thread
994
- const chatRecord = yield TestDataGenerator.generateRecordsWrite({
989
+ const chatRecord = await TestDataGenerator.generateRecordsWrite({
995
990
  author: bob,
996
991
  protocol: protocolDefinition.protocol,
997
992
  protocolPath: 'thread/chat',
998
993
  parentContextId: threadRecord.message.contextId,
999
994
  });
1000
- const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
995
+ const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
1001
996
  expect(chatRecordReply.status.code).toBe(202);
1002
997
  // 2. Alice creates a delegated grant for device X to act as her for a protocol that is NOT chat protocol
1003
998
  // Alice creates a delegated query grant for device X to act as Alice but not for chat protocol
1004
- const queryGrantForDeviceX = yield PermissionsProtocol.createGrant({
999
+ const queryGrantForDeviceX = await PermissionsProtocol.createGrant({
1005
1000
  delegated: true, // this is a delegated grant
1006
1001
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1007
1002
  grantedTo: deviceX.did,
@@ -1013,7 +1008,7 @@ export function testAuthorDelegatedGrant() {
1013
1008
  signer: Jws.createSigner(alice)
1014
1009
  });
1015
1010
  // Alice creates a delegated read grant for device X to act as Alice but not for chat protocol
1016
- const readGrantForDeviceX = yield PermissionsProtocol.createGrant({
1011
+ const readGrantForDeviceX = await PermissionsProtocol.createGrant({
1017
1012
  delegated: true, // this is a delegated grant
1018
1013
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1019
1014
  grantedTo: deviceX.did,
@@ -1025,7 +1020,7 @@ export function testAuthorDelegatedGrant() {
1025
1020
  signer: Jws.createSigner(alice)
1026
1021
  });
1027
1022
  // Alice creates a delegated subscribe grant for device X to act as Alice but not for chat protocol
1028
- const subscribeGrantForDeviceX = yield PermissionsProtocol.createGrant({
1023
+ const subscribeGrantForDeviceX = await PermissionsProtocol.createGrant({
1029
1024
  delegated: true, // this is a delegated grant
1030
1025
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1031
1026
  grantedTo: deviceX.did,
@@ -1038,7 +1033,7 @@ export function testAuthorDelegatedGrant() {
1038
1033
  });
1039
1034
  // 3. Device X attempts to use the delegated grant to read, query and subscribe to the chat thread and gets rejected by Bob's DWN
1040
1035
  // verify device X querying for the chat message from Bob's DWN fails
1041
- const recordsQueryByDeviceX = yield RecordsQuery.create({
1036
+ const recordsQueryByDeviceX = await RecordsQuery.create({
1042
1037
  signer: Jws.createSigner(deviceX),
1043
1038
  delegatedGrant: queryGrantForDeviceX.dataEncodedMessage,
1044
1039
  protocolRole: 'thread/participant',
@@ -1048,11 +1043,11 @@ export function testAuthorDelegatedGrant() {
1048
1043
  protocolPath: 'thread/chat'
1049
1044
  }
1050
1045
  });
1051
- const deviceXRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
1046
+ const deviceXRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByDeviceX.message);
1052
1047
  expect(deviceXRecordsQueryReply.status.code).toBe(401);
1053
1048
  expect(deviceXRecordsQueryReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch);
1054
1049
  // verify device X reading for the chat message from Bob's DWN fails
1055
- const recordsReadByDeviceX = yield RecordsRead.create({
1050
+ const recordsReadByDeviceX = await RecordsRead.create({
1056
1051
  signer: Jws.createSigner(deviceX),
1057
1052
  delegatedGrant: readGrantForDeviceX.dataEncodedMessage,
1058
1053
  protocolRole: 'thread/participant',
@@ -1060,11 +1055,11 @@ export function testAuthorDelegatedGrant() {
1060
1055
  recordId: chatRecord.message.recordId
1061
1056
  }
1062
1057
  });
1063
- const deviceXReadReply = yield dwn.processMessage(bob.did, recordsReadByDeviceX.message);
1058
+ const deviceXReadReply = await dwn.processMessage(bob.did, recordsReadByDeviceX.message);
1064
1059
  expect(deviceXReadReply.status.code).toBe(401);
1065
1060
  expect(deviceXReadReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationScopeProtocolMismatch);
1066
1061
  // verify device X subscribing to the chat message from Bob's DWN fails
1067
- const recordsSubscribeByDeviceX = yield RecordsSubscribe.create({
1062
+ const recordsSubscribeByDeviceX = await RecordsSubscribe.create({
1068
1063
  signer: Jws.createSigner(deviceX),
1069
1064
  delegatedGrant: subscribeGrantForDeviceX.dataEncodedMessage,
1070
1065
  protocolRole: 'thread/participant',
@@ -1074,59 +1069,58 @@ export function testAuthorDelegatedGrant() {
1074
1069
  protocolPath: 'thread/chat'
1075
1070
  }
1076
1071
  });
1077
- const deviceXRecordsSubscribeReply = yield dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message);
1072
+ const deviceXRecordsSubscribeReply = await dwn.processMessage(bob.did, recordsSubscribeByDeviceX.message);
1078
1073
  expect(deviceXRecordsSubscribeReply.status.code).toBe(401);
1079
1074
  expect(deviceXRecordsSubscribeReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationQueryOrSubscribeProtocolScopeMismatch);
1080
- }));
1081
- it('should fail if author-delegated grant has a mismatching protocol scope - delete', () => __awaiter(this, void 0, void 0, function* () {
1082
- var _a;
1075
+ });
1076
+ it('should fail if author-delegated grant has a mismatching protocol scope - delete', async () => {
1083
1077
  // scenario:
1084
1078
  // 1. Bob installs the chat protocol on his DWN and makes Alice an admin
1085
1079
  // 2. Bob starts a chat thread with Carol on his DWN
1086
1080
  // 3. Alice creates a delegated delete grant for Device X to act as her for a protocol that is NOT chat protocol
1087
1081
  // 4. Device X should NOT be able to delete a chat message as Alice
1088
- const alice = yield TestDataGenerator.generateDidKeyPersona();
1089
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
1090
- const bob = yield TestDataGenerator.generateDidKeyPersona();
1091
- const carol = yield TestDataGenerator.generateDidKeyPersona();
1082
+ const alice = await TestDataGenerator.generateDidKeyPersona();
1083
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
1084
+ const bob = await TestDataGenerator.generateDidKeyPersona();
1085
+ const carol = await TestDataGenerator.generateDidKeyPersona();
1092
1086
  // Bob has the chat protocol installed
1093
1087
  const protocolDefinition = threadRoleProtocolDefinition;
1094
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
1088
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
1095
1089
  author: bob,
1096
1090
  protocolDefinition
1097
1091
  });
1098
- const protocolsConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
1092
+ const protocolsConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
1099
1093
  expect(protocolsConfigureReply.status.code).toBe(202);
1100
1094
  // Bob adds Alice as an admin
1101
- const globalAdminRecord = yield TestDataGenerator.generateRecordsWrite({
1095
+ const globalAdminRecord = await TestDataGenerator.generateRecordsWrite({
1102
1096
  author: bob,
1103
1097
  recipient: alice.did,
1104
1098
  protocol: protocolDefinition.protocol,
1105
1099
  protocolPath: 'globalAdmin',
1106
1100
  data: new TextEncoder().encode('I trust Alice to manage my chat thread'),
1107
1101
  });
1108
- const globalAdminRecordReply = yield dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
1102
+ const globalAdminRecordReply = await dwn.processMessage(bob.did, globalAdminRecord.message, { dataStream: globalAdminRecord.dataStream });
1109
1103
  expect(globalAdminRecordReply.status.code).toBe(202);
1110
1104
  // Bob starts a chat thread
1111
- const threadRecord = yield TestDataGenerator.generateRecordsWrite({
1105
+ const threadRecord = await TestDataGenerator.generateRecordsWrite({
1112
1106
  author: bob,
1113
1107
  protocol: protocolDefinition.protocol,
1114
1108
  protocolPath: 'thread',
1115
1109
  });
1116
- const threadRoleReply = yield dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
1110
+ const threadRoleReply = await dwn.processMessage(bob.did, threadRecord.message, { dataStream: threadRecord.dataStream });
1117
1111
  expect(threadRoleReply.status.code).toBe(202);
1118
1112
  // Bob adds Carol as a participant in the thread
1119
- const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
1113
+ const participantRoleRecord = await TestDataGenerator.generateRecordsWrite({
1120
1114
  author: bob,
1121
1115
  recipient: carol.did,
1122
1116
  protocol: protocolDefinition.protocol,
1123
1117
  protocolPath: 'thread/participant',
1124
1118
  parentContextId: threadRecord.message.contextId
1125
1119
  });
1126
- const participantRoleReply = yield dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
1120
+ const participantRoleReply = await dwn.processMessage(bob.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
1127
1121
  expect(participantRoleReply.status.code).toBe(202);
1128
1122
  // Carol writes a chat message in the thread
1129
- const chatRecord = yield TestDataGenerator.generateRecordsWrite({
1123
+ const chatRecord = await TestDataGenerator.generateRecordsWrite({
1130
1124
  author: carol,
1131
1125
  protocolRole: 'thread/participant',
1132
1126
  protocol: protocolDefinition.protocol,
@@ -1134,10 +1128,10 @@ export function testAuthorDelegatedGrant() {
1134
1128
  parentContextId: threadRecord.message.contextId,
1135
1129
  data: new TextEncoder().encode('A rude message'),
1136
1130
  });
1137
- const chatRecordReply = yield dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
1131
+ const chatRecordReply = await dwn.processMessage(bob.did, chatRecord.message, { dataStream: chatRecord.dataStream });
1138
1132
  expect(chatRecordReply.status.code).toBe(202);
1139
1133
  // Alice creates a delegated delete grant for Device X to act as her for a protocol that is NOT chat protocol
1140
- const delegatedGrantForDeviceX = yield PermissionsProtocol.createGrant({
1134
+ const delegatedGrantForDeviceX = await PermissionsProtocol.createGrant({
1141
1135
  delegated: true, // this is a delegated grant
1142
1136
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1143
1137
  grantedTo: deviceX.did,
@@ -1149,42 +1143,41 @@ export function testAuthorDelegatedGrant() {
1149
1143
  signer: Jws.createSigner(alice)
1150
1144
  });
1151
1145
  // verify device X is NOT able to delete Carol's chat message from Bob's DWN
1152
- const recordsDeleteByDeviceX = yield RecordsDelete.create({
1146
+ const recordsDeleteByDeviceX = await RecordsDelete.create({
1153
1147
  signer: Jws.createSigner(deviceX),
1154
1148
  delegatedGrant: delegatedGrantForDeviceX.dataEncodedMessage,
1155
1149
  protocolRole: 'globalAdmin',
1156
1150
  recordId: chatRecord.message.recordId
1157
1151
  });
1158
- const deviceXRecordsDeleteReply = yield dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
1152
+ const deviceXRecordsDeleteReply = await dwn.processMessage(bob.did, recordsDeleteByDeviceX.message);
1159
1153
  expect(deviceXRecordsDeleteReply.status.code).toBe(401);
1160
1154
  expect(deviceXRecordsDeleteReply.status.detail).toContain(DwnErrorCode.RecordsGrantAuthorizationDeleteProtocolScopeMismatch);
1161
1155
  // sanity verify the chat message is still in Bob's DWN
1162
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
1156
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
1163
1157
  author: bob,
1164
1158
  filter: { protocolPath: 'thread/chat' }
1165
1159
  });
1166
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
1160
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
1167
1161
  expect(bobRecordsQueryReply.status.code).toBe(200);
1168
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(1);
1169
- }));
1170
- it('should fail if presented with an author-delegated grant with invalid grantor signature - write', () => __awaiter(this, void 0, void 0, function* () {
1171
- var _a;
1162
+ expect(bobRecordsQueryReply.entries?.length).toBe(1);
1163
+ });
1164
+ it('should fail if presented with an author-delegated grant with invalid grantor signature - write', async () => {
1172
1165
  // scenario:
1173
1166
  // 1. Bob has the message protocol installed
1174
1167
  // 2. Alice creates a delegated grant for device X to write as Alice, but with invalid signature
1175
1168
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the delegated grant with invalid grantor signature
1176
1169
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
1177
- const alice = yield TestDataGenerator.generateDidKeyPersona();
1178
- const bob = yield TestDataGenerator.generateDidKeyPersona();
1179
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
1170
+ const alice = await TestDataGenerator.generateDidKeyPersona();
1171
+ const bob = await TestDataGenerator.generateDidKeyPersona();
1172
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
1180
1173
  // 1. Bob has the message protocol installed
1181
1174
  const protocolDefinition = messageProtocolDefinition;
1182
1175
  const protocol = protocolDefinition.protocol;
1183
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
1176
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
1184
1177
  author: bob,
1185
1178
  protocolDefinition
1186
1179
  });
1187
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
1180
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
1188
1181
  expect(protocolConfigureReply.status.code).toBe(202);
1189
1182
  // 2. Alice creates a delegated grant for device X to write as Alice, but with invalid signature
1190
1183
  const scope = {
@@ -1192,7 +1185,7 @@ export function testAuthorDelegatedGrant() {
1192
1185
  method: DwnMethodName.Write,
1193
1186
  protocol
1194
1187
  };
1195
- const deviceXGrant = yield PermissionsProtocol.createGrant({
1188
+ const deviceXGrant = await PermissionsProtocol.createGrant({
1196
1189
  delegated: true,
1197
1190
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1198
1191
  grantedTo: deviceX.did,
@@ -1200,11 +1193,11 @@ export function testAuthorDelegatedGrant() {
1200
1193
  signer: Jws.createSigner(alice)
1201
1194
  });
1202
1195
  const deviceXGrantMessage = deviceXGrant.dataEncodedMessage;
1203
- deviceXGrantMessage.authorization.signature.signatures[0].signature = yield TestDataGenerator.randomSignatureString();
1196
+ deviceXGrantMessage.authorization.signature.signatures[0].signature = await TestDataGenerator.randomSignatureString();
1204
1197
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using the delegated grant with invalid grantor signature
1205
1198
  const deviceXData = new TextEncoder().encode('message from device X');
1206
1199
  const deviceXDataStream = DataStream.fromBytes(deviceXData);
1207
- const messageByDeviceX = yield RecordsWrite.create({
1200
+ const messageByDeviceX = await RecordsWrite.create({
1208
1201
  signer: Jws.createSigner(deviceX),
1209
1202
  delegatedGrant: deviceXGrantMessage,
1210
1203
  protocol,
@@ -1213,36 +1206,35 @@ export function testAuthorDelegatedGrant() {
1213
1206
  dataFormat: protocolDefinition.types.message.dataFormats[0],
1214
1207
  data: deviceXData
1215
1208
  });
1216
- const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1209
+ const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1217
1210
  expect(deviceXWriteReply.status.code).toBe(401);
1218
1211
  expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.GeneralJwsVerifierInvalidSignature);
1219
1212
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
1220
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
1213
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
1221
1214
  author: bob,
1222
1215
  filter: { protocol }
1223
1216
  });
1224
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
1217
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
1225
1218
  expect(bobRecordsQueryReply.status.code).toBe(200);
1226
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
1227
- }));
1228
- it('should fail if the CID of the author-delegated grant and the grant ID in the payload of the message signature is mismatching - write', () => __awaiter(this, void 0, void 0, function* () {
1229
- var _a;
1219
+ expect(bobRecordsQueryReply.entries?.length).toBe(0);
1220
+ });
1221
+ it('should fail if the CID of the author-delegated grant and the grant ID in the payload of the message signature is mismatching - write', async () => {
1230
1222
  // scenario:
1231
1223
  // 1. Bob has the message protocol installed
1232
1224
  // 2. Alice creates two delegated grants for device X to write as Alice
1233
1225
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
1234
1226
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
1235
- const alice = yield TestDataGenerator.generateDidKeyPersona();
1236
- const bob = yield TestDataGenerator.generateDidKeyPersona();
1237
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
1227
+ const alice = await TestDataGenerator.generateDidKeyPersona();
1228
+ const bob = await TestDataGenerator.generateDidKeyPersona();
1229
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
1238
1230
  // 1. Bob has the message protocol installed
1239
1231
  const protocolDefinition = messageProtocolDefinition;
1240
1232
  const protocol = protocolDefinition.protocol;
1241
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
1233
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
1242
1234
  author: bob,
1243
1235
  protocolDefinition
1244
1236
  });
1245
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
1237
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
1246
1238
  expect(protocolConfigureReply.status.code).toBe(202);
1247
1239
  // 2. Alice creates two delegated grants for device X to write as Alice
1248
1240
  const scope = {
@@ -1250,15 +1242,15 @@ export function testAuthorDelegatedGrant() {
1250
1242
  method: DwnMethodName.Write,
1251
1243
  protocol
1252
1244
  };
1253
- const deviceXGrant = yield PermissionsProtocol.createGrant({
1245
+ const deviceXGrant = await PermissionsProtocol.createGrant({
1254
1246
  delegated: true,
1255
1247
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1256
1248
  grantedTo: deviceX.did,
1257
1249
  scope: scope,
1258
1250
  signer: Jws.createSigner(alice)
1259
1251
  });
1260
- yield Time.minimalSleep();
1261
- const deviceXGrant2 = yield PermissionsProtocol.createGrant({
1252
+ await Time.minimalSleep();
1253
+ const deviceXGrant2 = await PermissionsProtocol.createGrant({
1262
1254
  delegated: true,
1263
1255
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1264
1256
  grantedTo: deviceX.did,
@@ -1268,7 +1260,7 @@ export function testAuthorDelegatedGrant() {
1268
1260
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
1269
1261
  const deviceXData = new TextEncoder().encode('message from device X');
1270
1262
  const deviceXDataStream = DataStream.fromBytes(deviceXData);
1271
- const messageByDeviceX = yield RecordsWrite.create({
1263
+ const messageByDeviceX = await RecordsWrite.create({
1272
1264
  signer: Jws.createSigner(deviceX),
1273
1265
  delegatedGrant: deviceXGrant.dataEncodedMessage,
1274
1266
  protocol,
@@ -1278,37 +1270,36 @@ export function testAuthorDelegatedGrant() {
1278
1270
  data: deviceXData
1279
1271
  });
1280
1272
  messageByDeviceX.message.authorization.authorDelegatedGrant = deviceXGrant2.dataEncodedMessage; // intentionally have a mismatching grant
1281
- const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1273
+ const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1282
1274
  expect(deviceXWriteReply.status.code).toBe(400);
1283
1275
  expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.RecordsAuthorDelegatedGrantCidMismatch);
1284
1276
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
1285
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
1277
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
1286
1278
  author: bob,
1287
1279
  filter: { protocol }
1288
1280
  });
1289
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
1281
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
1290
1282
  expect(bobRecordsQueryReply.status.code).toBe(200);
1291
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
1292
- }));
1293
- it('should fail if author-delegated grant is revoked - write', () => __awaiter(this, void 0, void 0, function* () {
1294
- var _a;
1283
+ expect(bobRecordsQueryReply.entries?.length).toBe(0);
1284
+ });
1285
+ it('should fail if author-delegated grant is revoked - write', async () => {
1295
1286
  // scenario:
1296
1287
  // 1. Bob has the message protocol installed
1297
1288
  // 2. Alice creates a delegated grant for device X to write as Alice
1298
1289
  // 3. Alice revokes the grant
1299
1290
  // 4. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a revoked delegated grant
1300
1291
  // 5. Sanity verify the message by device X did not get written to Bob's DWN
1301
- const alice = yield TestDataGenerator.generateDidKeyPersona();
1302
- const bob = yield TestDataGenerator.generateDidKeyPersona();
1303
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
1292
+ const alice = await TestDataGenerator.generateDidKeyPersona();
1293
+ const bob = await TestDataGenerator.generateDidKeyPersona();
1294
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
1304
1295
  // 1. Bob has the message protocol installed
1305
1296
  const protocolDefinition = messageProtocolDefinition;
1306
1297
  const protocol = protocolDefinition.protocol;
1307
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
1298
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
1308
1299
  author: bob,
1309
1300
  protocolDefinition
1310
1301
  });
1311
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
1302
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
1312
1303
  expect(protocolConfigureReply.status.code).toBe(202);
1313
1304
  // 2. Alice creates a delegated grant for device X to write as Alice
1314
1305
  const scope = {
@@ -1316,7 +1307,7 @@ export function testAuthorDelegatedGrant() {
1316
1307
  method: DwnMethodName.Write,
1317
1308
  protocol
1318
1309
  };
1319
- const deviceXGrant = yield PermissionsProtocol.createGrant({
1310
+ const deviceXGrant = await PermissionsProtocol.createGrant({
1320
1311
  delegated: true,
1321
1312
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
1322
1313
  grantedTo: deviceX.did,
@@ -1324,20 +1315,20 @@ export function testAuthorDelegatedGrant() {
1324
1315
  signer: Jws.createSigner(alice)
1325
1316
  });
1326
1317
  const deviceXGrantDataStream = DataStream.fromBytes(deviceXGrant.permissionGrantBytes);
1327
- const permissionGrantWriteReply = yield dwn.processMessage(alice.did, deviceXGrant.recordsWrite.message, { dataStream: deviceXGrantDataStream });
1318
+ const permissionGrantWriteReply = await dwn.processMessage(alice.did, deviceXGrant.recordsWrite.message, { dataStream: deviceXGrantDataStream });
1328
1319
  expect(permissionGrantWriteReply.status.code).toBe(202);
1329
1320
  // 3. Alice revokes the grant
1330
- const permissionRevoke = yield PermissionsProtocol.createRevocation({
1321
+ const permissionRevoke = await PermissionsProtocol.createRevocation({
1331
1322
  signer: Jws.createSigner(alice),
1332
- grant: yield PermissionGrant.parse(deviceXGrant.dataEncodedMessage),
1323
+ grant: PermissionGrant.parse(deviceXGrant.dataEncodedMessage),
1333
1324
  });
1334
1325
  const revocationDataStream = DataStream.fromBytes(permissionRevoke.permissionRevocationBytes);
1335
- const permissionRevokeReply = yield dwn.processMessage(alice.did, permissionRevoke.recordsWrite.message, { dataStream: revocationDataStream });
1326
+ const permissionRevokeReply = await dwn.processMessage(alice.did, permissionRevoke.recordsWrite.message, { dataStream: revocationDataStream });
1336
1327
  expect(permissionRevokeReply.status.code).toBe(202);
1337
1328
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using a mismatching delegated grant ID
1338
1329
  const deviceXData = new TextEncoder().encode('message from device X');
1339
1330
  const deviceXDataStream = DataStream.fromBytes(deviceXData);
1340
- const messageByDeviceX = yield RecordsWrite.create({
1331
+ const messageByDeviceX = await RecordsWrite.create({
1341
1332
  signer: Jws.createSigner(deviceX),
1342
1333
  delegatedGrant: deviceXGrant.dataEncodedMessage,
1343
1334
  protocol,
@@ -1346,36 +1337,35 @@ export function testAuthorDelegatedGrant() {
1346
1337
  dataFormat: protocolDefinition.types.message.dataFormats[0],
1347
1338
  data: deviceXData
1348
1339
  });
1349
- const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1340
+ const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1350
1341
  expect(deviceXWriteReply.status.code).toBe(401);
1351
1342
  expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantRevoked);
1352
1343
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
1353
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
1344
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
1354
1345
  author: bob,
1355
1346
  filter: { protocol }
1356
1347
  });
1357
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
1348
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
1358
1349
  expect(bobRecordsQueryReply.status.code).toBe(200);
1359
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
1360
- }));
1361
- it('should fail if author-delegated grant is expired - write', () => __awaiter(this, void 0, void 0, function* () {
1362
- var _a;
1350
+ expect(bobRecordsQueryReply.entries?.length).toBe(0);
1351
+ });
1352
+ it('should fail if author-delegated grant is expired - write', async () => {
1363
1353
  // scenario:
1364
1354
  // 1. Bob has the message protocol installed
1365
1355
  // 2. Alice creates a delegated grant for device X to write as Alice, but make it expired
1366
1356
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using an expired delegated grant
1367
1357
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
1368
- const alice = yield TestDataGenerator.generateDidKeyPersona();
1369
- const bob = yield TestDataGenerator.generateDidKeyPersona();
1370
- const deviceX = yield TestDataGenerator.generateDidKeyPersona();
1358
+ const alice = await TestDataGenerator.generateDidKeyPersona();
1359
+ const bob = await TestDataGenerator.generateDidKeyPersona();
1360
+ const deviceX = await TestDataGenerator.generateDidKeyPersona();
1371
1361
  // 1. Bob has the message protocol installed
1372
1362
  const protocolDefinition = messageProtocolDefinition;
1373
1363
  const protocol = protocolDefinition.protocol;
1374
- const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
1364
+ const protocolsConfig = await TestDataGenerator.generateProtocolsConfigure({
1375
1365
  author: bob,
1376
1366
  protocolDefinition
1377
1367
  });
1378
- const protocolConfigureReply = yield dwn.processMessage(bob.did, protocolsConfig.message);
1368
+ const protocolConfigureReply = await dwn.processMessage(bob.did, protocolsConfig.message);
1379
1369
  expect(protocolConfigureReply.status.code).toBe(202);
1380
1370
  // 2. Alice creates a delegated grant for device X to write as Alice, but make it expired
1381
1371
  const scope = {
@@ -1383,7 +1373,7 @@ export function testAuthorDelegatedGrant() {
1383
1373
  method: DwnMethodName.Write,
1384
1374
  protocol
1385
1375
  };
1386
- const deviceXGrant = yield PermissionsProtocol.createGrant({
1376
+ const deviceXGrant = await PermissionsProtocol.createGrant({
1387
1377
  delegated: true,
1388
1378
  dateExpires: Time.getCurrentTimestamp(), // intentionally set to current time to make it expired immediately
1389
1379
  grantedTo: deviceX.did,
@@ -1393,7 +1383,7 @@ export function testAuthorDelegatedGrant() {
1393
1383
  // 3. Verify that device X cannot write a `RecordsWrite` message to Bob's DWN as Alice using an expired delegated grant
1394
1384
  const deviceXData = new TextEncoder().encode('message from device X');
1395
1385
  const deviceXDataStream = DataStream.fromBytes(deviceXData);
1396
- const messageByDeviceX = yield RecordsWrite.create({
1386
+ const messageByDeviceX = await RecordsWrite.create({
1397
1387
  signer: Jws.createSigner(deviceX),
1398
1388
  delegatedGrant: deviceXGrant.dataEncodedMessage,
1399
1389
  protocol,
@@ -1402,18 +1392,18 @@ export function testAuthorDelegatedGrant() {
1402
1392
  dataFormat: protocolDefinition.types.message.dataFormats[0],
1403
1393
  data: deviceXData
1404
1394
  });
1405
- const deviceXWriteReply = yield dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1395
+ const deviceXWriteReply = await dwn.processMessage(bob.did, messageByDeviceX.message, { dataStream: deviceXDataStream });
1406
1396
  expect(deviceXWriteReply.status.code).toBe(401);
1407
1397
  expect(deviceXWriteReply.status.detail).toContain(DwnErrorCode.GrantAuthorizationGrantExpired);
1408
1398
  // 4. Sanity verify the message by device X did not get written to Bob's DWN
1409
- const recordsQueryByBob = yield TestDataGenerator.generateRecordsQuery({
1399
+ const recordsQueryByBob = await TestDataGenerator.generateRecordsQuery({
1410
1400
  author: bob,
1411
1401
  filter: { protocol }
1412
1402
  });
1413
- const bobRecordsQueryReply = yield dwn.processMessage(bob.did, recordsQueryByBob.message);
1403
+ const bobRecordsQueryReply = await dwn.processMessage(bob.did, recordsQueryByBob.message);
1414
1404
  expect(bobRecordsQueryReply.status.code).toBe(200);
1415
- expect((_a = bobRecordsQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).toBe(0);
1416
- }));
1405
+ expect(bobRecordsQueryReply.entries?.length).toBe(0);
1406
+ });
1417
1407
  });
1418
1408
  }
1419
1409
  //# sourceMappingURL=author-delegated-grant.spec.js.map