@enbox/dwn-sdk-js 0.0.6 → 0.0.7

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