@enbox/dwn-sdk-js 0.0.5 → 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 (363) 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 +108 -140
  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 +553 -568
  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 +291 -44
  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/src/utils/records.d.ts +3 -1
  347. package/dist/types/src/utils/records.d.ts.map +1 -1
  348. package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
  349. package/package.json +3 -3
  350. package/src/core/protocol-authorization-action.ts +377 -0
  351. package/src/core/protocol-authorization-validation.ts +391 -0
  352. package/src/core/protocol-authorization.ts +60 -849
  353. package/src/core/record-chain.ts +99 -0
  354. package/src/handlers/records-read.ts +1 -1
  355. package/src/handlers/records-write.ts +37 -21
  356. package/src/interfaces/protocols-configure.ts +33 -5
  357. package/src/interfaces/records-write-query.ts +139 -0
  358. package/src/interfaces/records-write-signing.ts +143 -0
  359. package/src/interfaces/records-write.ts +49 -221
  360. package/src/store/index-level-compound.ts +324 -0
  361. package/src/store/index-level.ts +24 -306
  362. package/src/utils/protocols.ts +8 -0
  363. package/src/utils/records.ts +9 -15
@@ -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 sinon from 'sinon';
11
2
  import { beforeEach, describe, expect, it } from 'bun:test';
12
3
  import { DwnErrorCode } from '../../src/core/dwn-error.js';
@@ -20,74 +11,74 @@ describe('RecordsWrite', () => {
20
11
  sinon.restore();
21
12
  });
22
13
  describe('create()', () => {
23
- it('should be able to create and authorize a valid RecordsWrite message', () => __awaiter(void 0, void 0, void 0, function* () {
14
+ it('should be able to create and authorize a valid RecordsWrite message', async () => {
24
15
  // testing `create()` first
25
- const alice = yield TestDataGenerator.generatePersona();
16
+ const alice = await TestDataGenerator.generatePersona();
26
17
  const options = {
27
18
  data: TestDataGenerator.randomBytes(10),
28
19
  dataFormat: 'application/json',
29
20
  dateCreated: '2022-10-14T10:20:30.405060Z',
30
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
21
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
31
22
  signer: Jws.createSigner(alice)
32
23
  };
33
- const recordsWrite = yield RecordsWrite.create(options);
24
+ const recordsWrite = await RecordsWrite.create(options);
34
25
  const message = recordsWrite.message;
35
26
  expect(message.authorization).toBeDefined();
36
27
  expect(message.descriptor.dataFormat).toBe(options.dataFormat);
37
28
  expect(message.descriptor.dateCreated).toBe(options.dateCreated);
38
29
  expect(message.recordId).toBe(options.recordId);
39
30
  const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
40
- yield RecordsWriteHandler['authorizeRecordsWrite'](alice.did, recordsWrite, messageStoreStub);
41
- }));
42
- it('should include permissionGrantId in the descriptor when provided', () => __awaiter(void 0, void 0, void 0, function* () {
43
- const alice = yield TestDataGenerator.generatePersona();
44
- const grantId = yield TestDataGenerator.randomCborSha256Cid();
45
- const recordsWrite = yield RecordsWrite.create({
31
+ await RecordsWriteHandler['authorizeRecordsWrite'](alice.did, recordsWrite, messageStoreStub);
32
+ });
33
+ it('should include permissionGrantId in the descriptor when provided', async () => {
34
+ const alice = await TestDataGenerator.generatePersona();
35
+ const grantId = await TestDataGenerator.randomCborSha256Cid();
36
+ const recordsWrite = await RecordsWrite.create({
46
37
  data: TestDataGenerator.randomBytes(10),
47
38
  dataFormat: 'application/json',
48
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
39
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
49
40
  signer: Jws.createSigner(alice),
50
41
  permissionGrantId: grantId,
51
42
  });
52
43
  expect(recordsWrite.message.descriptor.permissionGrantId).toBe(grantId);
53
- }));
54
- it('should not include permissionGrantId in the descriptor when not provided', () => __awaiter(void 0, void 0, void 0, function* () {
55
- const alice = yield TestDataGenerator.generatePersona();
56
- const recordsWrite = yield RecordsWrite.create({
44
+ });
45
+ it('should not include permissionGrantId in the descriptor when not provided', async () => {
46
+ const alice = await TestDataGenerator.generatePersona();
47
+ const recordsWrite = await RecordsWrite.create({
57
48
  data: TestDataGenerator.randomBytes(10),
58
49
  dataFormat: 'application/json',
59
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
50
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
60
51
  signer: Jws.createSigner(alice),
61
52
  });
62
53
  expect(recordsWrite.message.descriptor.permissionGrantId).toBeUndefined();
63
- }));
64
- it('should be able to auto-fill `datePublished` when `published` set to `true` but `datePublished` not given', () => __awaiter(void 0, void 0, void 0, function* () {
65
- const alice = yield TestDataGenerator.generatePersona();
54
+ });
55
+ it('should be able to auto-fill `datePublished` when `published` set to `true` but `datePublished` not given', async () => {
56
+ const alice = await TestDataGenerator.generatePersona();
66
57
  const options = {
67
58
  data: TestDataGenerator.randomBytes(10),
68
59
  dataFormat: 'application/json',
69
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
60
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
70
61
  published: true,
71
62
  signer: Jws.createSigner(alice)
72
63
  };
73
- const recordsWrite = yield RecordsWrite.create(options);
64
+ const recordsWrite = await RecordsWrite.create(options);
74
65
  const message = recordsWrite.message;
75
66
  expect(message.descriptor.datePublished).toBeDefined();
76
- }));
77
- it('should not allow `data` and `dataCid` to be both defined or undefined', () => __awaiter(void 0, void 0, void 0, function* () {
78
- const alice = yield TestDataGenerator.generatePersona();
67
+ });
68
+ it('should not allow `data` and `dataCid` to be both defined or undefined', async () => {
69
+ const alice = await TestDataGenerator.generatePersona();
79
70
  // testing `data` and `dataCid` both defined
80
71
  const options1 = {
81
72
  recipient: alice.did,
82
73
  data: TestDataGenerator.randomBytes(10),
83
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
74
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
84
75
  dataFormat: 'application/json',
85
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
76
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
86
77
  published: true,
87
78
  signer: Jws.createSigner(alice)
88
79
  };
89
80
  const createPromise1 = RecordsWrite.create(options1);
90
- yield expect(createPromise1).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
81
+ await expect(createPromise1).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
91
82
  // testing `data` and `dataCid` both undefined
92
83
  const options2 = {
93
84
  recipient: alice.did,
@@ -95,41 +86,41 @@ describe('RecordsWrite', () => {
95
86
  // data : TestDataGenerator.randomBytes(10),
96
87
  // dataCid : await TestDataGenerator.randomCborSha256Cid(),
97
88
  dataFormat: 'application/json',
98
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
89
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
99
90
  published: true,
100
91
  signer: Jws.createSigner(alice)
101
92
  };
102
93
  const createPromise2 = RecordsWrite.create(options2);
103
- yield expect(createPromise2).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
104
- }));
105
- it('should required `dataCid` and `dataSize` to be both defined or undefined at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
106
- const alice = yield TestDataGenerator.generatePersona();
94
+ await expect(createPromise2).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
95
+ });
96
+ it('should required `dataCid` and `dataSize` to be both defined or undefined at the same time', async () => {
97
+ const alice = await TestDataGenerator.generatePersona();
107
98
  const options1 = {
108
99
  recipient: alice.did,
109
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
100
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
110
101
  // dataSize : 123, // intentionally missing
111
102
  dataFormat: 'application/json',
112
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
103
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
113
104
  published: true,
114
105
  signer: Jws.createSigner(alice)
115
106
  };
116
107
  const createPromise1 = RecordsWrite.create(options1);
117
- yield expect(createPromise1).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
108
+ await expect(createPromise1).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
118
109
  const options2 = {
119
110
  recipient: alice.did,
120
111
  data: TestDataGenerator.randomBytes(10),
121
112
  // dataCid : await TestDataGenerator.randomCborSha256Cid(), // intentionally missing
122
113
  dataSize: 123,
123
114
  dataFormat: 'application/json',
124
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
115
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
125
116
  published: true,
126
117
  signer: Jws.createSigner(alice)
127
118
  };
128
119
  const createPromise2 = RecordsWrite.create(options2);
129
- yield expect(createPromise2).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
130
- }));
131
- it('should auto-normalize protocol URL', () => __awaiter(void 0, void 0, void 0, function* () {
132
- const alice = yield TestDataGenerator.generatePersona();
120
+ await expect(createPromise2).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
121
+ });
122
+ it('should auto-normalize protocol URL', async () => {
123
+ const alice = await TestDataGenerator.generatePersona();
133
124
  const options = {
134
125
  recipient: alice.did,
135
126
  data: TestDataGenerator.randomBytes(10),
@@ -139,50 +130,46 @@ describe('RecordsWrite', () => {
139
130
  protocolPath: 'example',
140
131
  schema: 'http://foo.bar/schema'
141
132
  };
142
- const recordsWrite = yield RecordsWrite.create(options);
133
+ const recordsWrite = await RecordsWrite.create(options);
143
134
  const message = recordsWrite.message;
144
135
  expect(message.descriptor.protocol).toBe('http://example.com');
145
- }));
146
- it('should required `protocol` and `protocolPath` to be both defined or undefined at the same time', () => __awaiter(void 0, void 0, void 0, function* () {
147
- const alice = yield TestDataGenerator.generatePersona();
136
+ });
137
+ it('should required `protocol` and `protocolPath` to be both defined or undefined at the same time', async () => {
138
+ const alice = await TestDataGenerator.generatePersona();
148
139
  const options1 = {
149
140
  recipient: alice.did,
150
141
  protocol: 'http://example.com',
151
142
  // protocolPath : 'foo/bar', // intentionally missing
152
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
143
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
153
144
  dataSize: 123,
154
145
  dataFormat: 'application/json',
155
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
146
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
156
147
  signer: Jws.createSigner(alice)
157
148
  };
158
149
  const createPromise1 = RecordsWrite.create(options1);
159
- yield expect(createPromise1).rejects.toThrow('`protocol` and `protocolPath` must both be defined or undefined at the same time');
150
+ await expect(createPromise1).rejects.toThrow('`protocol` and `protocolPath` must both be defined or undefined at the same time');
160
151
  const options2 = {
161
152
  recipient: alice.did,
162
153
  // protocol : 'http://example.com', // intentionally missing
163
154
  protocolPath: 'foo/bar',
164
155
  data: TestDataGenerator.randomBytes(10),
165
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
156
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
166
157
  dataSize: 123,
167
158
  dataFormat: 'application/json',
168
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
159
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
169
160
  signer: Jws.createSigner(alice)
170
161
  };
171
162
  const createPromise2 = RecordsWrite.create(options2);
172
- yield expect(createPromise2).rejects.toThrow('`protocol` and `protocolPath` must both be defined or undefined at the same time');
173
- }));
174
- it('should be able to create a RecordsWrite successfully using a custom signer', () => __awaiter(void 0, void 0, void 0, function* () {
163
+ await expect(createPromise2).rejects.toThrow('`protocol` and `protocolPath` must both be defined or undefined at the same time');
164
+ });
165
+ it('should be able to create a RecordsWrite successfully using a custom signer', async () => {
175
166
  // create a custom signer
176
167
  const hardCodedSignature = Encoder.stringToBytes('some_hard_coded_signature');
177
168
  class CustomSigner {
178
- constructor() {
179
- this.keyId = 'did:example:alice#key1';
180
- this.algorithm = 'unused';
181
- }
182
- sign(_content) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- return hardCodedSignature;
185
- });
169
+ keyId = 'did:example:alice#key1';
170
+ algorithm = 'unused';
171
+ async sign(_content) {
172
+ return hardCodedSignature;
186
173
  }
187
174
  }
188
175
  const signer = new CustomSigner();
@@ -190,17 +177,17 @@ describe('RecordsWrite', () => {
190
177
  schema: 'http://any-schema.com',
191
178
  protocol: 'http://example.com',
192
179
  protocolPath: 'foo/bar',
193
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
180
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
194
181
  dataSize: 123,
195
182
  dataFormat: 'application/json',
196
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
183
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
197
184
  signer
198
185
  };
199
- const recordsWrite = yield RecordsWrite.create(options);
186
+ const recordsWrite = await RecordsWrite.create(options);
200
187
  expect(recordsWrite.message.authorization.signature.signatures[0].signature).toBe(Encoder.bytesToBase64Url(hardCodedSignature));
201
- }));
202
- it('should throw if attempting to use `protocols` key derivation encryption scheme on non-protocol-based record', () => __awaiter(void 0, void 0, void 0, function* () {
203
- const alice = yield TestDataGenerator.generatePersona();
188
+ });
189
+ it('should throw if attempting to use `protocols` key derivation encryption scheme on non-protocol-based record', async () => {
190
+ const alice = await TestDataGenerator.generatePersona();
204
191
  const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12);
205
192
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
206
193
  const encryptionInput = {
@@ -220,10 +207,10 @@ describe('RecordsWrite', () => {
220
207
  data: TestDataGenerator.randomBytes(10),
221
208
  encryptionInput
222
209
  });
223
- yield expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteMissingProtocol);
224
- }));
225
- it('should throw if attempting to use `schemas` key derivation encryption scheme on a record without `schema`', () => __awaiter(void 0, void 0, void 0, function* () {
226
- const alice = yield TestDataGenerator.generatePersona();
210
+ await expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteMissingProtocol);
211
+ });
212
+ it('should throw if attempting to use `schemas` key derivation encryption scheme on a record without `schema`', async () => {
213
+ const alice = await TestDataGenerator.generatePersona();
227
214
  const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12);
228
215
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
229
216
  const encryptionInput = {
@@ -243,17 +230,17 @@ describe('RecordsWrite', () => {
243
230
  data: TestDataGenerator.randomBytes(10),
244
231
  encryptionInput
245
232
  });
246
- yield expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteMissingSchema);
247
- }));
248
- it('should throw if delegated grant is given but signer is not given', () => __awaiter(void 0, void 0, void 0, function* () {
249
- const alice = yield TestDataGenerator.generatePersona();
250
- const bob = yield TestDataGenerator.generatePersona();
233
+ await expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteMissingSchema);
234
+ });
235
+ it('should throw if delegated grant is given but signer is not given', async () => {
236
+ const alice = await TestDataGenerator.generatePersona();
237
+ const bob = await TestDataGenerator.generatePersona();
251
238
  const scope = {
252
239
  interface: DwnInterfaceName.Records,
253
240
  method: DwnMethodName.Write,
254
241
  protocol: 'chat'
255
242
  };
256
- const grantToBob = yield PermissionsProtocol.createGrant({
243
+ const grantToBob = await PermissionsProtocol.createGrant({
257
244
  signer: Jws.createSigner(alice),
258
245
  delegated: true, // this is a delegated grant
259
246
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
@@ -266,24 +253,24 @@ describe('RecordsWrite', () => {
266
253
  dataFormat: 'application/octet-stream',
267
254
  data: TestDataGenerator.randomBytes(10),
268
255
  });
269
- yield expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteCreateMissingSigner);
270
- }));
256
+ await expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteCreateMissingSigner);
257
+ });
271
258
  });
272
259
  describe('createFrom()', () => {
273
- it('should create a RecordsWrite with `published` set to `true` with just `publishedDate` given', () => __awaiter(void 0, void 0, void 0, function* () {
274
- const { author, recordsWrite } = yield TestDataGenerator.generateRecordsWrite({
260
+ it('should create a RecordsWrite with `published` set to `true` with just `publishedDate` given', async () => {
261
+ const { author, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
275
262
  published: false
276
263
  });
277
- const write = yield RecordsWrite.createFrom({
264
+ const write = await RecordsWrite.createFrom({
278
265
  recordsWriteMessage: recordsWrite.message,
279
266
  datePublished: Time.getCurrentTimestamp(),
280
267
  signer: Jws.createSigner(author)
281
268
  });
282
269
  expect(write.message.descriptor.published).toBe(true);
283
- }));
284
- it('replace tags with updated tags, if tags do not exist in createFrom remove them', () => __awaiter(void 0, void 0, void 0, function* () {
270
+ });
271
+ it('replace tags with updated tags, if tags do not exist in createFrom remove them', async () => {
285
272
  // create a record with tags
286
- const { author, message, recordsWrite } = yield TestDataGenerator.generateRecordsWrite({
273
+ const { author, message, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
287
274
  tags: {
288
275
  tag1: ['value1', 'value2']
289
276
  }
@@ -292,7 +279,7 @@ describe('RecordsWrite', () => {
292
279
  expect(message.descriptor.tags.tag1).toBeDefined();
293
280
  expect(message.descriptor.tags.tag1).toEqual(expect.arrayContaining(['value1', 'value2']));
294
281
  // update the record's tags
295
- const write = yield RecordsWrite.createFrom({
282
+ const write = await RecordsWrite.createFrom({
296
283
  recordsWriteMessage: recordsWrite.message,
297
284
  signer: Jws.createSigner(author),
298
285
  tags: {
@@ -304,30 +291,30 @@ describe('RecordsWrite', () => {
304
291
  expect(write.message.descriptor.tags.tag2).toBeDefined();
305
292
  expect(write.message.descriptor.tags.tag2).toEqual(expect.arrayContaining(['value1', 'value2', 'value3']));
306
293
  // update without tags
307
- const write2 = yield RecordsWrite.createFrom({
294
+ const write2 = await RecordsWrite.createFrom({
308
295
  recordsWriteMessage: write.message,
309
296
  signer: Jws.createSigner(author),
310
297
  });
311
298
  expect(write2.message.descriptor.tags).toBeUndefined();
312
- }));
299
+ });
313
300
  });
314
301
  describe('parse()', () => {
315
- it('should invoke JSON schema validation when parsing a RecordsWrite', () => __awaiter(void 0, void 0, void 0, function* () {
316
- const alice = yield TestDataGenerator.generatePersona();
317
- const recordsWrite = yield RecordsWrite.create({
302
+ it('should invoke JSON schema validation when parsing a RecordsWrite', async () => {
303
+ const alice = await TestDataGenerator.generatePersona();
304
+ const recordsWrite = await RecordsWrite.create({
318
305
  signer: Jws.createSigner(alice),
319
306
  dataFormat: 'application/octet-stream',
320
307
  data: TestDataGenerator.randomBytes(10),
321
308
  });
322
309
  const validateJsonSchemaSpy = sinon.spy(Message, 'validateJsonSchema');
323
- yield RecordsWrite.parse(recordsWrite.message);
310
+ await RecordsWrite.parse(recordsWrite.message);
324
311
  expect(validateJsonSchemaSpy.called).toBe(true);
325
- }));
312
+ });
326
313
  });
327
314
  describe('isSignedByAuthorDelegate()', () => {
328
- it('should return false if the given RecordsWrite is not signed at all', () => __awaiter(void 0, void 0, void 0, function* () {
315
+ it('should return false if the given RecordsWrite is not signed at all', async () => {
329
316
  const data = new TextEncoder().encode('any data');
330
- const recordsWrite = yield RecordsWrite.create({
317
+ const recordsWrite = await RecordsWrite.create({
331
318
  protocol: 'unused',
332
319
  protocolPath: 'unused',
333
320
  schema: 'unused',
@@ -336,12 +323,12 @@ describe('RecordsWrite', () => {
336
323
  });
337
324
  const isSignedByAuthorDelegate = recordsWrite.isSignedByAuthorDelegate;
338
325
  expect(isSignedByAuthorDelegate).toBe(false);
339
- }));
326
+ });
340
327
  });
341
328
  describe('isSignedByOwnerDelegate()', () => {
342
- it('should return false if the given RecordsWrite is not signed at all', () => __awaiter(void 0, void 0, void 0, function* () {
329
+ it('should return false if the given RecordsWrite is not signed at all', async () => {
343
330
  const data = new TextEncoder().encode('any data');
344
- const recordsWrite = yield RecordsWrite.create({
331
+ const recordsWrite = await RecordsWrite.create({
345
332
  protocol: 'unused',
346
333
  protocolPath: 'unused',
347
334
  schema: 'unused',
@@ -350,103 +337,103 @@ describe('RecordsWrite', () => {
350
337
  });
351
338
  const isSignedByOwnerDelegate = recordsWrite.isSignedByOwnerDelegate;
352
339
  expect(isSignedByOwnerDelegate).toBe(false);
353
- }));
340
+ });
354
341
  });
355
342
  describe('isInitialWrite()', () => {
356
- it('should return false if given message is not a RecordsWrite', () => __awaiter(void 0, void 0, void 0, function* () {
357
- const { message } = yield TestDataGenerator.generateRecordsQuery();
358
- const isInitialWrite = yield RecordsWrite.isInitialWrite(message);
343
+ it('should return false if given message is not a RecordsWrite', async () => {
344
+ const { message } = await TestDataGenerator.generateRecordsQuery();
345
+ const isInitialWrite = await RecordsWrite.isInitialWrite(message);
359
346
  expect(isInitialWrite).toBe(false);
360
- }));
347
+ });
361
348
  });
362
349
  describe('getEntryId()', () => {
363
- it('should throw if the given author is undefined', () => __awaiter(void 0, void 0, void 0, function* () {
364
- const { message } = yield TestDataGenerator.generateRecordsWrite();
350
+ it('should throw if the given author is undefined', async () => {
351
+ const { message } = await TestDataGenerator.generateRecordsWrite();
365
352
  const author = undefined;
366
- yield expect(RecordsWrite.getEntryId(author, message.descriptor)).rejects.toThrow(DwnErrorCode.RecordsWriteGetEntryIdUndefinedAuthor);
367
- }));
353
+ await expect(RecordsWrite.getEntryId(author, message.descriptor)).rejects.toThrow(DwnErrorCode.RecordsWriteGetEntryIdUndefinedAuthor);
354
+ });
368
355
  });
369
356
  describe('signAsOwner()', () => {
370
- it('should throw if the RecordsWrite is not signed by an author yet', () => __awaiter(void 0, void 0, void 0, function* () {
357
+ it('should throw if the RecordsWrite is not signed by an author yet', async () => {
371
358
  const options = {
372
359
  data: TestDataGenerator.randomBytes(10),
373
360
  dataFormat: 'application/json',
374
361
  dateCreated: '2023-07-27T10:20:30.405060Z',
375
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
362
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
376
363
  };
377
- const recordsWrite = yield RecordsWrite.create(options);
364
+ const recordsWrite = await RecordsWrite.create(options);
378
365
  expect(recordsWrite.author).toBeUndefined();
379
366
  expect(recordsWrite.signaturePayload).toBeUndefined();
380
- const alice = yield TestDataGenerator.generateDidKeyPersona();
381
- yield expect(recordsWrite.signAsOwner(Jws.createSigner(alice))).rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerUnknownAuthor);
367
+ const alice = await TestDataGenerator.generateDidKeyPersona();
368
+ await expect(recordsWrite.signAsOwner(Jws.createSigner(alice))).rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerUnknownAuthor);
382
369
  expect(recordsWrite.owner).toBeUndefined();
383
370
  expect(recordsWrite.ownerSignaturePayload).toBeUndefined();
384
- }));
371
+ });
385
372
  });
386
373
  describe('signAsOwnerDelegate()', () => {
387
- it('should throw if the RecordsWrite is not signed by an author yet', () => __awaiter(void 0, void 0, void 0, function* () {
374
+ it('should throw if the RecordsWrite is not signed by an author yet', async () => {
388
375
  const options = {
389
376
  data: TestDataGenerator.randomBytes(10),
390
377
  dataFormat: 'application/json',
391
378
  dateCreated: '2023-07-27T10:20:30.405060Z',
392
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
379
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
393
380
  };
394
- const recordsWrite = yield RecordsWrite.create(options);
381
+ const recordsWrite = await RecordsWrite.create(options);
395
382
  expect(recordsWrite.author).toBeUndefined();
396
383
  expect(recordsWrite.signaturePayload).toBeUndefined();
397
384
  // create a delegated grant
398
- const alice = yield TestDataGenerator.generateDidKeyPersona();
399
- const bob = yield TestDataGenerator.generateDidKeyPersona();
385
+ const alice = await TestDataGenerator.generateDidKeyPersona();
386
+ const bob = await TestDataGenerator.generateDidKeyPersona();
400
387
  const scope = {
401
388
  interface: DwnInterfaceName.Records,
402
389
  method: DwnMethodName.Write,
403
390
  protocol: 'chat'
404
391
  };
405
- const ownerDelegatedGrant = yield PermissionsProtocol.createGrant({
392
+ const ownerDelegatedGrant = await PermissionsProtocol.createGrant({
406
393
  signer: Jws.createSigner(alice),
407
394
  delegated: true, // this is a delegated grant
408
395
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
409
396
  grantedTo: bob.did,
410
397
  scope
411
398
  });
412
- yield expect(recordsWrite.signAsOwnerDelegate(Jws.createSigner(bob), ownerDelegatedGrant.dataEncodedMessage))
399
+ await expect(recordsWrite.signAsOwnerDelegate(Jws.createSigner(bob), ownerDelegatedGrant.dataEncodedMessage))
413
400
  .rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerDelegateUnknownAuthor);
414
401
  expect(recordsWrite.owner).toBeUndefined();
415
402
  expect(recordsWrite.ownerSignaturePayload).toBeUndefined();
416
- }));
403
+ });
417
404
  });
418
405
  describe('ownerSignatureSigner()', () => {
419
- it('should return `undefined` if owner signature is not present in the message', () => __awaiter(void 0, void 0, void 0, function* () {
406
+ it('should return `undefined` if owner signature is not present in the message', async () => {
420
407
  const options = {
421
408
  data: TestDataGenerator.randomBytes(10),
422
409
  dataFormat: 'application/json',
423
410
  dateCreated: '2023-07-27T10:20:30.405060Z',
424
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
411
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
425
412
  };
426
- const recordsWrite = yield RecordsWrite.create(options);
413
+ const recordsWrite = await RecordsWrite.create(options);
427
414
  expect(recordsWrite.ownerSignatureSigner).toBeUndefined();
428
- }));
415
+ });
429
416
  });
430
417
  describe('message', () => {
431
- it('should throw if attempting to access the message of a RecordsWrite that is not given authorization signature input', () => __awaiter(void 0, void 0, void 0, function* () {
418
+ it('should throw if attempting to access the message of a RecordsWrite that is not given authorization signature input', async () => {
432
419
  const options = {
433
420
  data: TestDataGenerator.randomBytes(10),
434
421
  dataFormat: 'application/json',
435
422
  dateCreated: '2023-07-27T10:20:30.405060Z',
436
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
423
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
437
424
  };
438
- const recordsWrite = yield RecordsWrite.create(options);
425
+ const recordsWrite = await RecordsWrite.create(options);
439
426
  expect(recordsWrite.author).toBeUndefined();
440
427
  expect(recordsWrite.signaturePayload).toBeUndefined();
441
428
  expect(() => recordsWrite.message).toThrow(DwnErrorCode.RecordsWriteMissingSigner);
442
- }));
429
+ });
443
430
  });
444
431
  describe('encryptSymmetricEncryptionKey()', () => {
445
- it('should replace encryption property by default', () => __awaiter(void 0, void 0, void 0, function* () {
446
- const alice = yield TestDataGenerator.generatePersona();
432
+ it('should replace encryption property by default', async () => {
433
+ const alice = await TestDataGenerator.generatePersona();
447
434
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
448
435
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
449
- const recordsWrite = yield RecordsWrite.create({
436
+ const recordsWrite = await RecordsWrite.create({
450
437
  signer: Jws.createSigner(alice),
451
438
  protocol: 'https://example.com/protocol',
452
439
  protocolPath: 'test',
@@ -465,7 +452,7 @@ describe('RecordsWrite', () => {
465
452
  derivationScheme: KeyDerivationScheme.ProtocolPath,
466
453
  }],
467
454
  };
468
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
455
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
469
456
  expect(recordsWrite['_message'].encryption).toBeDefined();
470
457
  expect(recordsWrite['_message'].encryption.recipients).toHaveLength(1);
471
458
  expect(recordsWrite['_message'].encryption.recipients[0].header.derivationScheme).toBe('protocolPath');
@@ -480,16 +467,16 @@ describe('RecordsWrite', () => {
480
467
  derivationScheme: KeyDerivationScheme.Schemas,
481
468
  }],
482
469
  };
483
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2);
470
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2);
484
471
  // Should have replaced — only 1 entry with Schemas scheme
485
472
  expect(recordsWrite['_message'].encryption.recipients).toHaveLength(1);
486
473
  expect(recordsWrite['_message'].encryption.recipients[0].header.derivationScheme).toBe('schemas');
487
- }));
488
- it('should append recipients when append option is true', () => __awaiter(void 0, void 0, void 0, function* () {
489
- const alice = yield TestDataGenerator.generatePersona();
474
+ });
475
+ it('should append recipients when append option is true', async () => {
476
+ const alice = await TestDataGenerator.generatePersona();
490
477
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
491
478
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
492
- const recordsWrite = yield RecordsWrite.create({
479
+ const recordsWrite = await RecordsWrite.create({
493
480
  signer: Jws.createSigner(alice),
494
481
  protocol: 'https://example.com/protocol',
495
482
  protocolPath: 'test',
@@ -508,7 +495,7 @@ describe('RecordsWrite', () => {
508
495
  derivationScheme: KeyDerivationScheme.ProtocolPath,
509
496
  }],
510
497
  };
511
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
498
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
512
499
  const originalIV = recordsWrite['_message'].encryption.iv;
513
500
  const originalProtected = recordsWrite['_message'].encryption.protected;
514
501
  // Second encryption with append — ProtocolContext
@@ -522,7 +509,7 @@ describe('RecordsWrite', () => {
522
509
  derivationScheme: KeyDerivationScheme.ProtocolContext,
523
510
  }],
524
511
  };
525
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
512
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
526
513
  // Should have both entries
527
514
  const encryption = recordsWrite['_message'].encryption;
528
515
  expect(encryption.recipients).toHaveLength(2);
@@ -538,16 +525,16 @@ describe('RecordsWrite', () => {
538
525
  // When starting from a parsed/signed message (the signAsOwner test
539
526
  // below), authorization IS preserved by append mode.
540
527
  expect(recordsWrite['_message'].authorization).toBeUndefined();
541
- }));
542
- it('should allow signAsOwner after append (reactive root-record upgrade)', () => __awaiter(void 0, void 0, void 0, function* () {
528
+ });
529
+ it('should allow signAsOwner after append (reactive root-record upgrade)', async () => {
543
530
  // Simulates the cross-DWN scenario: Bob authors a record, Alice (owner)
544
531
  // appends a ProtocolContext recipient entry, then signs as owner.
545
- const alice = yield TestDataGenerator.generatePersona();
546
- const bob = yield TestDataGenerator.generatePersona();
532
+ const alice = await TestDataGenerator.generatePersona();
533
+ const bob = await TestDataGenerator.generatePersona();
547
534
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
548
535
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
549
536
  // Bob creates and signs the record
550
- const recordsWrite = yield RecordsWrite.create({
537
+ const recordsWrite = await RecordsWrite.create({
551
538
  signer: Jws.createSigner(bob),
552
539
  protocol: 'https://example.com/protocol',
553
540
  protocolPath: 'thread',
@@ -566,12 +553,12 @@ describe('RecordsWrite', () => {
566
553
  derivationScheme: KeyDerivationScheme.ProtocolPath,
567
554
  }],
568
555
  };
569
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
570
- yield recordsWrite.sign({ signer: Jws.createSigner(bob) });
556
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
557
+ await recordsWrite.sign({ signer: Jws.createSigner(bob) });
571
558
  expect(recordsWrite.author).toBe(bob.did);
572
559
  expect(recordsWrite['_message'].authorization).toBeDefined();
573
560
  // Simulate: Alice parses Bob's message and appends ProtocolContext
574
- const parsed = yield RecordsWrite.parse(recordsWrite.message);
561
+ const parsed = await RecordsWrite.parse(recordsWrite.message);
575
562
  expect(parsed.author).toBe(bob.did);
576
563
  const encryptionInput2 = {
577
564
  initializationVector: dataEncryptionIV,
@@ -583,12 +570,12 @@ describe('RecordsWrite', () => {
583
570
  derivationScheme: KeyDerivationScheme.ProtocolContext,
584
571
  }],
585
572
  };
586
- yield parsed.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
573
+ await parsed.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
587
574
  // Author and authorization should be preserved after append
588
575
  expect(parsed.author).toBe(bob.did);
589
576
  expect(parsed['_message'].authorization).toBeDefined();
590
577
  // Alice signs as owner — should NOT throw
591
- yield parsed.signAsOwner(Jws.createSigner(alice));
578
+ await parsed.signAsOwner(Jws.createSigner(alice));
592
579
  expect(parsed.owner).toBe(alice.did);
593
580
  expect(parsed['_message'].authorization.ownerSignature).toBeDefined();
594
581
  // Both recipient entries should be present
@@ -598,13 +585,13 @@ describe('RecordsWrite', () => {
598
585
  expect(encryption.recipients[1].header.derivationScheme).toBe('protocolContext');
599
586
  // validateIntegrity should pass — the stale encryptionCid in the
600
587
  // author's signature is allowed when ownerSignature is present
601
- yield parsed['validateIntegrity']();
602
- }));
603
- it('should throw when append is true but encryption does not exist', () => __awaiter(void 0, void 0, void 0, function* () {
604
- const alice = yield TestDataGenerator.generatePersona();
588
+ await parsed['validateIntegrity']();
589
+ });
590
+ it('should throw when append is true but encryption does not exist', async () => {
591
+ const alice = await TestDataGenerator.generatePersona();
605
592
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
606
593
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
607
- const recordsWrite = yield RecordsWrite.create({
594
+ const recordsWrite = await RecordsWrite.create({
608
595
  signer: Jws.createSigner(alice),
609
596
  protocol: 'https://example.com/protocol',
610
597
  protocolPath: 'test',
@@ -621,8 +608,8 @@ describe('RecordsWrite', () => {
621
608
  derivationScheme: KeyDerivationScheme.ProtocolPath,
622
609
  }],
623
610
  };
624
- yield expect(recordsWrite.encryptSymmetricEncryptionKey(encryptionInput, { append: true })).rejects.toThrow(DwnErrorCode.RecordsWriteMissingEncryption);
625
- }));
611
+ await expect(recordsWrite.encryptSymmetricEncryptionKey(encryptionInput, { append: true })).rejects.toThrow(DwnErrorCode.RecordsWriteMissingEncryption);
612
+ });
626
613
  });
627
614
  });
628
615
  //# sourceMappingURL=records-write.spec.js.map