@enbox/dwn-sdk-js 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (527) hide show
  1. package/dist/browser.mjs +8 -8
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/generated/precompiled-validators.js +762 -911
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/core/abstract-message.js +4 -0
  6. package/dist/esm/src/core/abstract-message.js.map +1 -1
  7. package/dist/esm/src/core/auth.js +22 -33
  8. package/dist/esm/src/core/auth.js.map +1 -1
  9. package/dist/esm/src/core/constants.js +11 -0
  10. package/dist/esm/src/core/constants.js.map +1 -0
  11. package/dist/esm/src/core/core-protocol.js +44 -0
  12. package/dist/esm/src/core/core-protocol.js.map +1 -0
  13. package/dist/esm/src/core/dwn-constant.js +7 -7
  14. package/dist/esm/src/core/dwn-constant.js.map +1 -1
  15. package/dist/esm/src/core/dwn-error.js +10 -12
  16. package/dist/esm/src/core/dwn-error.js.map +1 -1
  17. package/dist/esm/src/core/grant-authorization.js +50 -52
  18. package/dist/esm/src/core/grant-authorization.js.map +1 -1
  19. package/dist/esm/src/core/message.js +85 -116
  20. package/dist/esm/src/core/message.js.map +1 -1
  21. package/dist/esm/src/core/messages-grant-authorization.js +63 -78
  22. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
  23. package/dist/esm/src/core/protocol-authorization-action.js +266 -0
  24. package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
  25. package/dist/esm/src/core/protocol-authorization-validation.js +321 -0
  26. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
  27. package/dist/esm/src/core/protocol-authorization.js +144 -741
  28. package/dist/esm/src/core/protocol-authorization.js.map +1 -1
  29. package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
  30. package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
  31. package/dist/esm/src/core/record-chain.js +64 -0
  32. package/dist/esm/src/core/record-chain.js.map +1 -0
  33. package/dist/esm/src/core/records-grant-authorization.js +53 -72
  34. package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
  35. package/dist/esm/src/core/resumable-task-manager.js +50 -65
  36. package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
  37. package/dist/esm/src/core/tenant-gate.js +2 -13
  38. package/dist/esm/src/core/tenant-gate.js.map +1 -1
  39. package/dist/esm/src/dwn.js +108 -101
  40. package/dist/esm/src/dwn.js.map +1 -1
  41. package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
  42. package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
  43. package/dist/esm/src/handlers/messages-read.js +67 -81
  44. package/dist/esm/src/handlers/messages-read.js.map +1 -1
  45. package/dist/esm/src/handlers/messages-subscribe.js +51 -63
  46. package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
  47. package/dist/esm/src/handlers/messages-sync.js +75 -89
  48. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  49. package/dist/esm/src/handlers/protocols-configure.js +153 -163
  50. package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
  51. package/dist/esm/src/handlers/protocols-query.js +52 -55
  52. package/dist/esm/src/handlers/protocols-query.js.map +1 -1
  53. package/dist/esm/src/handlers/records-count.js +97 -85
  54. package/dist/esm/src/handlers/records-count.js.map +1 -1
  55. package/dist/esm/src/handlers/records-delete.js +75 -93
  56. package/dist/esm/src/handlers/records-delete.js.map +1 -1
  57. package/dist/esm/src/handlers/records-query.js +116 -105
  58. package/dist/esm/src/handlers/records-query.js.map +1 -1
  59. package/dist/esm/src/handlers/records-read.js +130 -132
  60. package/dist/esm/src/handlers/records-read.js.map +1 -1
  61. package/dist/esm/src/handlers/records-subscribe.js +164 -104
  62. package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
  63. package/dist/esm/src/handlers/records-write.js +213 -280
  64. package/dist/esm/src/handlers/records-write.js.map +1 -1
  65. package/dist/esm/src/index.js +5 -2
  66. package/dist/esm/src/index.js.map +1 -1
  67. package/dist/esm/src/interfaces/messages-read.js +24 -32
  68. package/dist/esm/src/interfaces/messages-read.js.map +1 -1
  69. package/dist/esm/src/interfaces/messages-subscribe.js +28 -41
  70. package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
  71. package/dist/esm/src/interfaces/messages-sync.js +26 -40
  72. package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
  73. package/dist/esm/src/interfaces/protocols-configure.js +87 -65
  74. package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
  75. package/dist/esm/src/interfaces/protocols-query.js +55 -68
  76. package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
  77. package/dist/esm/src/interfaces/records-count.js +50 -66
  78. package/dist/esm/src/interfaces/records-count.js.map +1 -1
  79. package/dist/esm/src/interfaces/records-delete.js +45 -55
  80. package/dist/esm/src/interfaces/records-delete.js.map +1 -1
  81. package/dist/esm/src/interfaces/records-query.js +60 -76
  82. package/dist/esm/src/interfaces/records-query.js.map +1 -1
  83. package/dist/esm/src/interfaces/records-read.js +51 -67
  84. package/dist/esm/src/interfaces/records-read.js.map +1 -1
  85. package/dist/esm/src/interfaces/records-subscribe.js +53 -68
  86. package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
  87. package/dist/esm/src/interfaces/records-write-query.js +102 -0
  88. package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
  89. package/dist/esm/src/interfaces/records-write-signing.js +81 -0
  90. package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
  91. package/dist/esm/src/interfaces/records-write.js +396 -610
  92. package/dist/esm/src/interfaces/records-write.js.map +1 -1
  93. package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
  94. package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
  95. package/dist/esm/src/jose/jws/general/builder.js +23 -35
  96. package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
  97. package/dist/esm/src/jose/jws/general/verifier.js +56 -69
  98. package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
  99. package/dist/esm/src/protocols/permission-grant.js +43 -14
  100. package/dist/esm/src/protocols/permission-grant.js.map +1 -1
  101. package/dist/esm/src/protocols/permission-request.js +28 -14
  102. package/dist/esm/src/protocols/permission-request.js.map +1 -1
  103. package/dist/esm/src/protocols/permissions.js +325 -227
  104. package/dist/esm/src/protocols/permissions.js.map +1 -1
  105. package/dist/esm/src/smt/smt-store-level.js +42 -64
  106. package/dist/esm/src/smt/smt-store-level.js.map +1 -1
  107. package/dist/esm/src/smt/smt-store-memory.js +19 -45
  108. package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
  109. package/dist/esm/src/smt/smt-utils.js +28 -45
  110. package/dist/esm/src/smt/smt-utils.js.map +1 -1
  111. package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
  112. package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
  113. package/dist/esm/src/state-index/state-index-level.js +113 -150
  114. package/dist/esm/src/state-index/state-index-level.js.map +1 -1
  115. package/dist/esm/src/store/blockstore-level.js +54 -156
  116. package/dist/esm/src/store/blockstore-level.js.map +1 -1
  117. package/dist/esm/src/store/blockstore-mock.js +48 -153
  118. package/dist/esm/src/store/blockstore-mock.js.map +1 -1
  119. package/dist/esm/src/store/data-store-level.js +137 -100
  120. package/dist/esm/src/store/data-store-level.js.map +1 -1
  121. package/dist/esm/src/store/index-level-compound.js +246 -0
  122. package/dist/esm/src/store/index-level-compound.js.map +1 -0
  123. package/dist/esm/src/store/index-level.js +307 -715
  124. package/dist/esm/src/store/index-level.js.map +1 -1
  125. package/dist/esm/src/store/level-wrapper.js +143 -244
  126. package/dist/esm/src/store/level-wrapper.js.map +1 -1
  127. package/dist/esm/src/store/message-store-level.js +71 -94
  128. package/dist/esm/src/store/message-store-level.js.map +1 -1
  129. package/dist/esm/src/store/resumable-task-store-level.js +62 -101
  130. package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
  131. package/dist/esm/src/store/storage-controller.js +131 -146
  132. package/dist/esm/src/store/storage-controller.js.map +1 -1
  133. package/dist/esm/src/types/permission-types.js.map +1 -1
  134. package/dist/esm/src/types/protocols-types.js +10 -0
  135. package/dist/esm/src/types/protocols-types.js.map +1 -1
  136. package/dist/esm/src/types/records-types.js.map +1 -1
  137. package/dist/esm/src/utils/abort.js +8 -19
  138. package/dist/esm/src/utils/abort.js.map +1 -1
  139. package/dist/esm/src/utils/array.js +15 -49
  140. package/dist/esm/src/utils/array.js.map +1 -1
  141. package/dist/esm/src/utils/cid.js +29 -77
  142. package/dist/esm/src/utils/cid.js.map +1 -1
  143. package/dist/esm/src/utils/data-stream.js +37 -65
  144. package/dist/esm/src/utils/data-stream.js.map +1 -1
  145. package/dist/esm/src/utils/encryption.js +136 -162
  146. package/dist/esm/src/utils/encryption.js.map +1 -1
  147. package/dist/esm/src/utils/filter.js +1 -12
  148. package/dist/esm/src/utils/filter.js.map +1 -1
  149. package/dist/esm/src/utils/hd-key.js +45 -71
  150. package/dist/esm/src/utils/hd-key.js.map +1 -1
  151. package/dist/esm/src/utils/jws.js +9 -20
  152. package/dist/esm/src/utils/jws.js.map +1 -1
  153. package/dist/esm/src/utils/memory-cache.js +12 -23
  154. package/dist/esm/src/utils/memory-cache.js.map +1 -1
  155. package/dist/esm/src/utils/messages.js +21 -33
  156. package/dist/esm/src/utils/messages.js.map +1 -1
  157. package/dist/esm/src/utils/private-key-signer.js +9 -17
  158. package/dist/esm/src/utils/private-key-signer.js.map +1 -1
  159. package/dist/esm/src/utils/protocols.js +62 -70
  160. package/dist/esm/src/utils/protocols.js.map +1 -1
  161. package/dist/esm/src/utils/records.js +103 -166
  162. package/dist/esm/src/utils/records.js.map +1 -1
  163. package/dist/esm/src/utils/secp256k1.js +60 -96
  164. package/dist/esm/src/utils/secp256k1.js.map +1 -1
  165. package/dist/esm/src/utils/secp256r1.js +54 -71
  166. package/dist/esm/src/utils/secp256r1.js.map +1 -1
  167. package/dist/esm/src/utils/time.js +5 -18
  168. package/dist/esm/src/utils/time.js.map +1 -1
  169. package/dist/esm/src/utils/url.js +3 -3
  170. package/dist/esm/src/utils/url.js.map +1 -1
  171. package/dist/esm/tests/core/auth.spec.js +3 -12
  172. package/dist/esm/tests/core/auth.spec.js.map +1 -1
  173. package/dist/esm/tests/core/message.spec.js +50 -59
  174. package/dist/esm/tests/core/message.spec.js.map +1 -1
  175. package/dist/esm/tests/core/protocol-authorization.spec.js +10 -18
  176. package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
  177. package/dist/esm/tests/dwn.spec.js +65 -89
  178. package/dist/esm/tests/dwn.spec.js.map +1 -1
  179. package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
  180. package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
  181. package/dist/esm/tests/features/author-delegated-grant.spec.js +337 -347
  182. package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
  183. package/dist/esm/tests/features/owner-delegated-grant.spec.js +160 -172
  184. package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
  185. package/dist/esm/tests/features/owner-signature.spec.js +78 -82
  186. package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
  187. package/dist/esm/tests/features/permissions.spec.js +449 -184
  188. package/dist/esm/tests/features/permissions.spec.js.map +1 -1
  189. package/dist/esm/tests/features/protocol-composition.spec.js +981 -360
  190. package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
  191. package/dist/esm/tests/features/protocol-create-action.spec.js +45 -54
  192. package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
  193. package/dist/esm/tests/features/protocol-delete-action.spec.js +99 -108
  194. package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
  195. package/dist/esm/tests/features/protocol-update-action.spec.js +108 -117
  196. package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
  197. package/dist/esm/tests/features/records-immutable.spec.js +315 -0
  198. package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
  199. package/dist/esm/tests/features/records-prune.spec.js +178 -194
  200. package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
  201. package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
  202. package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
  203. package/dist/esm/tests/features/records-tags.spec.js +456 -463
  204. package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
  205. package/dist/esm/tests/features/resumable-tasks.spec.js +88 -98
  206. package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
  207. package/dist/esm/tests/handlers/messages-read.spec.js +215 -210
  208. package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
  209. package/dist/esm/tests/handlers/messages-subscribe.spec.js +309 -171
  210. package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
  211. package/dist/esm/tests/handlers/messages-sync.spec.js +272 -199
  212. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  213. package/dist/esm/tests/handlers/protocols-configure.spec.js +247 -241
  214. package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
  215. package/dist/esm/tests/handlers/protocols-query.spec.js +159 -172
  216. package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
  217. package/dist/esm/tests/handlers/records-count.spec.js +101 -105
  218. package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
  219. package/dist/esm/tests/handlers/records-delete.spec.js +266 -279
  220. package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
  221. package/dist/esm/tests/handlers/records-query.spec.js +984 -996
  222. package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
  223. package/dist/esm/tests/handlers/records-read.spec.js +542 -671
  224. package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
  225. package/dist/esm/tests/handlers/records-subscribe.spec.js +433 -302
  226. package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
  227. package/dist/esm/tests/handlers/records-write.spec.js +1216 -1140
  228. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  229. package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
  230. package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
  231. package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
  232. package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
  233. package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
  234. package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
  235. package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
  236. package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
  237. package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
  238. package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
  239. package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
  240. package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
  241. package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
  242. package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
  243. package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
  244. package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
  245. package/dist/esm/tests/interfaces/records-write.spec.js +190 -219
  246. package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
  247. package/dist/esm/tests/jose/jws/general.spec.js +36 -45
  248. package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
  249. package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
  250. package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
  251. package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
  252. package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
  253. package/dist/esm/tests/protocols/permissions.spec.js +49 -55
  254. package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
  255. package/dist/esm/tests/scenarios/aggregator.spec.js +127 -138
  256. package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
  257. package/dist/esm/tests/scenarios/deleted-record.spec.js +372 -36
  258. package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
  259. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +55 -64
  260. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
  261. package/dist/esm/tests/scenarios/nested-roles.spec.js +66 -76
  262. package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
  263. package/dist/esm/tests/scenarios/subscriptions.spec.js +451 -354
  264. package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
  265. package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
  266. package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
  267. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
  268. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
  269. package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
  270. package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
  271. package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
  272. package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
  273. package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
  274. package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
  275. package/dist/esm/tests/store/data-store-level.spec.js +160 -108
  276. package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
  277. package/dist/esm/tests/store/index-level.spec.js +404 -414
  278. package/dist/esm/tests/store/index-level.spec.js.map +1 -1
  279. package/dist/esm/tests/store/message-store-level.spec.js +13 -22
  280. package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
  281. package/dist/esm/tests/store/message-store.spec.js +229 -238
  282. package/dist/esm/tests/store/message-store.spec.js.map +1 -1
  283. package/dist/esm/tests/test-event-stream.js +12 -13
  284. package/dist/esm/tests/test-event-stream.js.map +1 -1
  285. package/dist/esm/tests/test-stores.js +16 -13
  286. package/dist/esm/tests/test-stores.js.map +1 -1
  287. package/dist/esm/tests/test-suite.js +8 -15
  288. package/dist/esm/tests/test-suite.js.map +1 -1
  289. package/dist/esm/tests/utils/cid.spec.js +24 -33
  290. package/dist/esm/tests/utils/cid.spec.js.map +1 -1
  291. package/dist/esm/tests/utils/data-stream.spec.js +48 -57
  292. package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
  293. package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
  294. package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
  295. package/dist/esm/tests/utils/encryption.spec.js +229 -82
  296. package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
  297. package/dist/esm/tests/utils/filters.spec.js +46 -55
  298. package/dist/esm/tests/utils/filters.spec.js.map +1 -1
  299. package/dist/esm/tests/utils/hd-key.spec.js +10 -19
  300. package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
  301. package/dist/esm/tests/utils/jws.spec.js +3 -12
  302. package/dist/esm/tests/utils/jws.spec.js.map +1 -1
  303. package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
  304. package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
  305. package/dist/esm/tests/utils/messages.spec.js +18 -20
  306. package/dist/esm/tests/utils/messages.spec.js.map +1 -1
  307. package/dist/esm/tests/utils/poller.js +22 -33
  308. package/dist/esm/tests/utils/poller.js.map +1 -1
  309. package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
  310. package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
  311. package/dist/esm/tests/utils/records.spec.js +14 -27
  312. package/dist/esm/tests/utils/records.spec.js.map +1 -1
  313. package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
  314. package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
  315. package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
  316. package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
  317. package/dist/esm/tests/utils/test-data-generator.js +446 -467
  318. package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
  319. package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
  320. package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
  321. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
  322. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
  323. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
  324. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
  325. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
  326. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
  327. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
  328. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
  329. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
  330. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
  331. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
  332. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
  333. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +44 -24
  334. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
  335. package/dist/types/generated/precompiled-validators.d.ts +49 -40
  336. package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
  337. package/dist/types/src/core/constants.d.ts +11 -0
  338. package/dist/types/src/core/constants.d.ts.map +1 -0
  339. package/dist/types/src/core/core-protocol.d.ts +89 -0
  340. package/dist/types/src/core/core-protocol.d.ts.map +1 -0
  341. package/dist/types/src/core/dwn-error.d.ts +9 -12
  342. package/dist/types/src/core/dwn-error.d.ts.map +1 -1
  343. package/dist/types/src/core/grant-authorization.d.ts +6 -2
  344. package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
  345. package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
  346. package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
  347. package/dist/types/src/core/protocol-authorization-validation.d.ts +81 -0
  348. package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
  349. package/dist/types/src/core/protocol-authorization.d.ts +24 -106
  350. package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
  351. package/dist/types/src/core/record-chain.d.ts +24 -0
  352. package/dist/types/src/core/record-chain.d.ts.map +1 -0
  353. package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
  354. package/dist/types/src/dwn.d.ts +19 -7
  355. package/dist/types/src/dwn.d.ts.map +1 -1
  356. package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
  357. package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
  358. package/dist/types/src/handlers/messages-read.d.ts +3 -8
  359. package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
  360. package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
  361. package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
  362. package/dist/types/src/handlers/messages-sync.d.ts +3 -8
  363. package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
  364. package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
  365. package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
  366. package/dist/types/src/handlers/protocols-query.d.ts +3 -8
  367. package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
  368. package/dist/types/src/handlers/records-count.d.ts +3 -6
  369. package/dist/types/src/handlers/records-count.d.ts.map +1 -1
  370. package/dist/types/src/handlers/records-delete.d.ts +3 -8
  371. package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
  372. package/dist/types/src/handlers/records-query.d.ts +3 -8
  373. package/dist/types/src/handlers/records-query.d.ts.map +1 -1
  374. package/dist/types/src/handlers/records-read.d.ts +3 -8
  375. package/dist/types/src/handlers/records-read.d.ts.map +1 -1
  376. package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
  377. package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
  378. package/dist/types/src/handlers/records-write.d.ts +4 -24
  379. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  380. package/dist/types/src/index.d.ts +8 -4
  381. package/dist/types/src/index.d.ts.map +1 -1
  382. package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
  383. package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
  384. package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
  385. package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
  386. package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
  387. package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
  388. package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
  389. package/dist/types/src/interfaces/records-write-signing.d.ts +34 -0
  390. package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
  391. package/dist/types/src/interfaces/records-write.d.ts +13 -53
  392. package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
  393. package/dist/types/src/protocols/permission-grant.d.ts +1 -1
  394. package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
  395. package/dist/types/src/protocols/permission-request.d.ts +1 -1
  396. package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
  397. package/dist/types/src/protocols/permissions.d.ts +40 -3
  398. package/dist/types/src/protocols/permissions.d.ts.map +1 -1
  399. package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
  400. package/dist/types/src/store/data-store-level.d.ts +20 -4
  401. package/dist/types/src/store/data-store-level.d.ts.map +1 -1
  402. package/dist/types/src/store/index-level-compound.d.ts +70 -0
  403. package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
  404. package/dist/types/src/store/index-level.d.ts +4 -58
  405. package/dist/types/src/store/index-level.d.ts.map +1 -1
  406. package/dist/types/src/store/storage-controller.d.ts +4 -4
  407. package/dist/types/src/store/storage-controller.d.ts.map +1 -1
  408. package/dist/types/src/types/message-types.d.ts +3 -3
  409. package/dist/types/src/types/message-types.d.ts.map +1 -1
  410. package/dist/types/src/types/messages-types.d.ts +12 -3
  411. package/dist/types/src/types/messages-types.d.ts.map +1 -1
  412. package/dist/types/src/types/method-handler.d.ts +24 -3
  413. package/dist/types/src/types/method-handler.d.ts.map +1 -1
  414. package/dist/types/src/types/permission-types.d.ts +7 -0
  415. package/dist/types/src/types/permission-types.d.ts.map +1 -1
  416. package/dist/types/src/types/protocols-types.d.ts +41 -1
  417. package/dist/types/src/types/protocols-types.d.ts.map +1 -1
  418. package/dist/types/src/types/records-types.d.ts +16 -6
  419. package/dist/types/src/types/records-types.d.ts.map +1 -1
  420. package/dist/types/src/types/subscriptions.d.ts +151 -13
  421. package/dist/types/src/types/subscriptions.d.ts.map +1 -1
  422. package/dist/types/src/utils/hd-key.d.ts +1 -9
  423. package/dist/types/src/utils/hd-key.d.ts.map +1 -1
  424. package/dist/types/src/utils/messages.d.ts +7 -5
  425. package/dist/types/src/utils/messages.d.ts.map +1 -1
  426. package/dist/types/src/utils/protocols.d.ts +5 -0
  427. package/dist/types/src/utils/protocols.d.ts.map +1 -1
  428. package/dist/types/src/utils/records.d.ts +1 -11
  429. package/dist/types/src/utils/records.d.ts.map +1 -1
  430. package/dist/types/tests/dwn.spec.d.ts.map +1 -1
  431. package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
  432. package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
  433. package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
  434. package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
  435. package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
  436. package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
  437. package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
  438. package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
  439. package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
  440. package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
  441. package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
  442. package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
  443. package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
  444. package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
  445. package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
  446. package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
  447. package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
  448. package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
  449. package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
  450. package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
  451. package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
  452. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
  453. package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
  454. package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
  455. package/dist/types/tests/test-event-stream.d.ts +11 -12
  456. package/dist/types/tests/test-event-stream.d.ts.map +1 -1
  457. package/dist/types/tests/test-suite.d.ts +2 -2
  458. package/dist/types/tests/test-suite.d.ts.map +1 -1
  459. package/dist/types/tests/utils/test-data-generator.d.ts +18 -0
  460. package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
  461. package/package.json +5 -4
  462. package/src/core/constants.ts +11 -0
  463. package/src/core/core-protocol.ts +129 -0
  464. package/src/core/dwn-error.ts +15 -12
  465. package/src/core/grant-authorization.ts +20 -3
  466. package/src/core/protocol-authorization-action.ts +377 -0
  467. package/src/core/protocol-authorization-validation.ts +487 -0
  468. package/src/core/protocol-authorization.ts +111 -856
  469. package/src/core/record-chain.ts +99 -0
  470. package/src/core/records-grant-authorization.ts +6 -8
  471. package/src/dwn.ts +58 -73
  472. package/src/event-stream/event-emitter-event-log.ts +283 -0
  473. package/src/handlers/messages-read.ts +8 -9
  474. package/src/handlers/messages-subscribe.ts +24 -28
  475. package/src/handlers/messages-sync.ts +10 -16
  476. package/src/handlers/protocols-configure.ts +47 -32
  477. package/src/handlers/protocols-query.ts +6 -9
  478. package/src/handlers/records-count.ts +11 -10
  479. package/src/handlers/records-delete.ts +12 -21
  480. package/src/handlers/records-query.ts +12 -12
  481. package/src/handlers/records-read.ts +34 -22
  482. package/src/handlers/records-subscribe.ts +47 -26
  483. package/src/handlers/records-write.ts +47 -104
  484. package/src/index.ts +9 -5
  485. package/src/interfaces/messages-subscribe.ts +7 -1
  486. package/src/interfaces/protocols-configure.ts +73 -8
  487. package/src/interfaces/records-count.ts +1 -1
  488. package/src/interfaces/records-delete.ts +1 -1
  489. package/src/interfaces/records-query.ts +1 -1
  490. package/src/interfaces/records-read.ts +1 -1
  491. package/src/interfaces/records-subscribe.ts +8 -1
  492. package/src/interfaces/records-write-query.ts +139 -0
  493. package/src/interfaces/records-write-signing.ts +123 -0
  494. package/src/interfaces/records-write.ts +66 -261
  495. package/src/protocols/permission-grant.ts +1 -1
  496. package/src/protocols/permission-request.ts +1 -1
  497. package/src/protocols/permissions.ts +148 -6
  498. package/src/state-index/state-index-level.ts +5 -7
  499. package/src/store/data-store-level.ts +124 -34
  500. package/src/store/index-level-compound.ts +324 -0
  501. package/src/store/index-level.ts +68 -341
  502. package/src/store/storage-controller.ts +11 -11
  503. package/src/types/message-types.ts +3 -3
  504. package/src/types/messages-types.ts +12 -3
  505. package/src/types/method-handler.ts +26 -4
  506. package/src/types/mitt.d.ts +28 -0
  507. package/src/types/permission-types.ts +7 -0
  508. package/src/types/protocols-types.ts +46 -0
  509. package/src/types/records-types.ts +16 -6
  510. package/src/types/subscriptions.ts +178 -14
  511. package/src/utils/hd-key.ts +0 -9
  512. package/src/utils/messages.ts +17 -37
  513. package/src/utils/protocols.ts +8 -0
  514. package/src/utils/records.ts +8 -59
  515. package/dist/esm/src/event-stream/event-emitter-stream.js +0 -60
  516. package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
  517. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -77
  518. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
  519. package/dist/esm/tests/event-stream/event-stream.spec.js +0 -123
  520. package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
  521. package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
  522. package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
  523. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
  524. package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
  525. package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
  526. package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
  527. package/src/event-stream/event-emitter-stream.ts +0 -69
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import 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,91 @@ 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(),
22
+ protocol: 'http://test-protocol.xyz',
23
+ protocolPath: 'testRecord',
31
24
  signer: Jws.createSigner(alice)
32
25
  };
33
- const recordsWrite = yield RecordsWrite.create(options);
26
+ const recordsWrite = await RecordsWrite.create(options);
34
27
  const message = recordsWrite.message;
35
28
  expect(message.authorization).toBeDefined();
36
29
  expect(message.descriptor.dataFormat).toBe(options.dataFormat);
37
30
  expect(message.descriptor.dateCreated).toBe(options.dateCreated);
38
31
  expect(message.recordId).toBe(options.recordId);
39
32
  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({
33
+ // authorizeRecordsWrite is a private instance method; invoke via bracket notation on an instance
34
+ const handler = new RecordsWriteHandler({
35
+ didResolver: {},
36
+ messageStore: messageStoreStub,
37
+ dataStore: {},
38
+ stateIndex: {},
39
+ });
40
+ await handler.authorizeRecordsWrite(alice.did, recordsWrite, messageStoreStub);
41
+ });
42
+ it('should include permissionGrantId in the descriptor when provided', async () => {
43
+ const alice = await TestDataGenerator.generatePersona();
44
+ const grantId = await TestDataGenerator.randomCborSha256Cid();
45
+ const recordsWrite = await RecordsWrite.create({
46
46
  data: TestDataGenerator.randomBytes(10),
47
47
  dataFormat: 'application/json',
48
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
48
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
49
+ protocol: 'http://test-protocol.xyz',
50
+ protocolPath: 'testRecord',
49
51
  signer: Jws.createSigner(alice),
50
52
  permissionGrantId: grantId,
51
53
  });
52
54
  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({
55
+ });
56
+ it('should not include permissionGrantId in the descriptor when not provided', async () => {
57
+ const alice = await TestDataGenerator.generatePersona();
58
+ const recordsWrite = await RecordsWrite.create({
57
59
  data: TestDataGenerator.randomBytes(10),
58
60
  dataFormat: 'application/json',
59
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
61
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
62
+ protocol: 'http://test-protocol.xyz',
63
+ protocolPath: 'testRecord',
60
64
  signer: Jws.createSigner(alice),
61
65
  });
62
66
  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();
67
+ });
68
+ it('should be able to auto-fill `datePublished` when `published` set to `true` but `datePublished` not given', async () => {
69
+ const alice = await TestDataGenerator.generatePersona();
66
70
  const options = {
67
71
  data: TestDataGenerator.randomBytes(10),
68
72
  dataFormat: 'application/json',
69
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
73
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
74
+ protocol: 'http://test-protocol.xyz',
75
+ protocolPath: 'testRecord',
70
76
  published: true,
71
77
  signer: Jws.createSigner(alice)
72
78
  };
73
- const recordsWrite = yield RecordsWrite.create(options);
79
+ const recordsWrite = await RecordsWrite.create(options);
74
80
  const message = recordsWrite.message;
75
81
  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();
82
+ });
83
+ it('should not allow `data` and `dataCid` to be both defined or undefined', async () => {
84
+ const alice = await TestDataGenerator.generatePersona();
79
85
  // testing `data` and `dataCid` both defined
80
86
  const options1 = {
81
87
  recipient: alice.did,
82
88
  data: TestDataGenerator.randomBytes(10),
83
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
89
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
84
90
  dataFormat: 'application/json',
85
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
91
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
92
+ protocol: 'http://test-protocol.xyz',
93
+ protocolPath: 'testRecord',
86
94
  published: true,
87
95
  signer: Jws.createSigner(alice)
88
96
  };
89
97
  const createPromise1 = RecordsWrite.create(options1);
90
- yield expect(createPromise1).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
98
+ await expect(createPromise1).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
91
99
  // testing `data` and `dataCid` both undefined
92
100
  const options2 = {
93
101
  recipient: alice.did,
@@ -95,41 +103,47 @@ describe('RecordsWrite', () => {
95
103
  // data : TestDataGenerator.randomBytes(10),
96
104
  // dataCid : await TestDataGenerator.randomCborSha256Cid(),
97
105
  dataFormat: 'application/json',
98
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
106
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
107
+ protocol: 'http://test-protocol.xyz',
108
+ protocolPath: 'testRecord',
99
109
  published: true,
100
110
  signer: Jws.createSigner(alice)
101
111
  };
102
112
  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();
113
+ await expect(createPromise2).rejects.toThrow(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive);
114
+ });
115
+ it('should required `dataCid` and `dataSize` to be both defined or undefined at the same time', async () => {
116
+ const alice = await TestDataGenerator.generatePersona();
107
117
  const options1 = {
108
118
  recipient: alice.did,
109
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
119
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
110
120
  // dataSize : 123, // intentionally missing
111
121
  dataFormat: 'application/json',
112
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
122
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
123
+ protocol: 'http://test-protocol.xyz',
124
+ protocolPath: 'testRecord',
113
125
  published: true,
114
126
  signer: Jws.createSigner(alice)
115
127
  };
116
128
  const createPromise1 = RecordsWrite.create(options1);
117
- yield expect(createPromise1).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
129
+ await expect(createPromise1).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
118
130
  const options2 = {
119
131
  recipient: alice.did,
120
132
  data: TestDataGenerator.randomBytes(10),
121
133
  // dataCid : await TestDataGenerator.randomCborSha256Cid(), // intentionally missing
122
134
  dataSize: 123,
123
135
  dataFormat: 'application/json',
124
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
136
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
137
+ protocol: 'http://test-protocol.xyz',
138
+ protocolPath: 'testRecord',
125
139
  published: true,
126
140
  signer: Jws.createSigner(alice)
127
141
  };
128
142
  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();
143
+ await expect(createPromise2).rejects.toThrow('`dataCid` and `dataSize` must both be defined or undefined at the same time');
144
+ });
145
+ it('should auto-normalize protocol URL', async () => {
146
+ const alice = await TestDataGenerator.generatePersona();
133
147
  const options = {
134
148
  recipient: alice.did,
135
149
  data: TestDataGenerator.randomBytes(10),
@@ -139,50 +153,41 @@ describe('RecordsWrite', () => {
139
153
  protocolPath: 'example',
140
154
  schema: 'http://foo.bar/schema'
141
155
  };
142
- const recordsWrite = yield RecordsWrite.create(options);
156
+ const recordsWrite = await RecordsWrite.create(options);
143
157
  const message = recordsWrite.message;
144
158
  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();
148
- const options1 = {
159
+ });
160
+ it('should require `protocol` and `protocolPath`', async () => {
161
+ const alice = await TestDataGenerator.generatePersona();
162
+ const baseOptions = {
149
163
  recipient: alice.did,
150
- protocol: 'http://example.com',
151
- // protocolPath : 'foo/bar', // intentionally missing
152
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
164
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
153
165
  dataSize: 123,
154
166
  dataFormat: 'application/json',
155
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
167
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
156
168
  signer: Jws.createSigner(alice)
157
169
  };
158
- const createPromise1 = RecordsWrite.create(options1);
159
- yield expect(createPromise1).rejects.toThrow('`protocol` and `protocolPath` must both be defined or undefined at the same time');
160
- const options2 = {
161
- recipient: alice.did,
162
- // protocol : 'http://example.com', // intentionally missing
170
+ // missing protocol
171
+ const missingProtocol = RecordsWrite.create({
172
+ ...baseOptions,
163
173
  protocolPath: 'foo/bar',
164
- data: TestDataGenerator.randomBytes(10),
165
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
166
- dataSize: 123,
167
- dataFormat: 'application/json',
168
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
169
- signer: Jws.createSigner(alice)
170
- };
171
- 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* () {
174
+ });
175
+ await expect(missingProtocol).rejects.toThrow('`protocol` and `protocolPath` are required');
176
+ // missing protocolPath
177
+ const missingProtocolPath = RecordsWrite.create({
178
+ ...baseOptions,
179
+ protocol: 'http://example.com',
180
+ });
181
+ await expect(missingProtocolPath).rejects.toThrow('`protocol` and `protocolPath` are required');
182
+ });
183
+ it('should be able to create a RecordsWrite successfully using a custom signer', async () => {
175
184
  // create a custom signer
176
185
  const hardCodedSignature = Encoder.stringToBytes('some_hard_coded_signature');
177
186
  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
- });
187
+ keyId = 'did:example:alice#key1';
188
+ algorithm = 'unused';
189
+ async sign(_content) {
190
+ return hardCodedSignature;
186
191
  }
187
192
  }
188
193
  const signer = new CustomSigner();
@@ -190,70 +195,24 @@ describe('RecordsWrite', () => {
190
195
  schema: 'http://any-schema.com',
191
196
  protocol: 'http://example.com',
192
197
  protocolPath: 'foo/bar',
193
- dataCid: yield TestDataGenerator.randomCborSha256Cid(),
198
+ dataCid: await TestDataGenerator.randomCborSha256Cid(),
194
199
  dataSize: 123,
195
200
  dataFormat: 'application/json',
196
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
201
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
197
202
  signer
198
203
  };
199
- const recordsWrite = yield RecordsWrite.create(options);
204
+ const recordsWrite = await RecordsWrite.create(options);
200
205
  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();
204
- const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12);
205
- const dataEncryptionKey = TestDataGenerator.randomBytes(32);
206
- const encryptionInput = {
207
- initializationVector: dataEncryptionInitializationVector,
208
- key: dataEncryptionKey,
209
- authenticationTag: TestDataGenerator.randomBytes(16),
210
- keyEncryptionInputs: [{
211
- publicKeyId: alice.keyId, // reusing signing key for encryption purely as a convenience
212
- publicKey: alice.encryptionKeyPair.publicJwk,
213
- derivationScheme: KeyDerivationScheme.ProtocolPath
214
- }]
215
- };
216
- // intentionally generating a record that is not protocol-based
217
- const createPromise = RecordsWrite.create({
218
- signer: Jws.createSigner(alice),
219
- dataFormat: 'application/json',
220
- data: TestDataGenerator.randomBytes(10),
221
- encryptionInput
222
- });
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();
227
- const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12);
228
- const dataEncryptionKey = TestDataGenerator.randomBytes(32);
229
- const encryptionInput = {
230
- initializationVector: dataEncryptionInitializationVector,
231
- key: dataEncryptionKey,
232
- authenticationTag: TestDataGenerator.randomBytes(16),
233
- keyEncryptionInputs: [{
234
- publicKeyId: alice.keyId, // reusing signing key for encryption purely as a convenience
235
- publicKey: alice.encryptionKeyPair.publicJwk,
236
- derivationScheme: KeyDerivationScheme.Schemas
237
- }]
238
- };
239
- // intentionally generating a record that is without `schema`
240
- const createPromise = RecordsWrite.create({
241
- signer: Jws.createSigner(alice),
242
- dataFormat: 'application/octet-stream',
243
- data: TestDataGenerator.randomBytes(10),
244
- encryptionInput
245
- });
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();
206
+ });
207
+ it('should throw if delegated grant is given but signer is not given', async () => {
208
+ const alice = await TestDataGenerator.generatePersona();
209
+ const bob = await TestDataGenerator.generatePersona();
251
210
  const scope = {
252
211
  interface: DwnInterfaceName.Records,
253
212
  method: DwnMethodName.Write,
254
213
  protocol: 'chat'
255
214
  };
256
- const grantToBob = yield PermissionsProtocol.createGrant({
215
+ const grantToBob = await PermissionsProtocol.createGrant({
257
216
  signer: Jws.createSigner(alice),
258
217
  delegated: true, // this is a delegated grant
259
218
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
@@ -263,27 +222,29 @@ describe('RecordsWrite', () => {
263
222
  });
264
223
  const createPromise = RecordsWrite.create({
265
224
  delegatedGrant: grantToBob.dataEncodedMessage,
225
+ protocol: 'http://test-protocol.xyz',
226
+ protocolPath: 'testRecord',
266
227
  dataFormat: 'application/octet-stream',
267
228
  data: TestDataGenerator.randomBytes(10),
268
229
  });
269
- yield expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteCreateMissingSigner);
270
- }));
230
+ await expect(createPromise).rejects.toThrow(DwnErrorCode.RecordsWriteCreateMissingSigner);
231
+ });
271
232
  });
272
233
  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({
234
+ it('should create a RecordsWrite with `published` set to `true` with just `publishedDate` given', async () => {
235
+ const { author, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
275
236
  published: false
276
237
  });
277
- const write = yield RecordsWrite.createFrom({
238
+ const write = await RecordsWrite.createFrom({
278
239
  recordsWriteMessage: recordsWrite.message,
279
240
  datePublished: Time.getCurrentTimestamp(),
280
241
  signer: Jws.createSigner(author)
281
242
  });
282
243
  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* () {
244
+ });
245
+ it('replace tags with updated tags, if tags do not exist in createFrom remove them', async () => {
285
246
  // create a record with tags
286
- const { author, message, recordsWrite } = yield TestDataGenerator.generateRecordsWrite({
247
+ const { author, message, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
287
248
  tags: {
288
249
  tag1: ['value1', 'value2']
289
250
  }
@@ -292,7 +253,7 @@ describe('RecordsWrite', () => {
292
253
  expect(message.descriptor.tags.tag1).toBeDefined();
293
254
  expect(message.descriptor.tags.tag1).toEqual(expect.arrayContaining(['value1', 'value2']));
294
255
  // update the record's tags
295
- const write = yield RecordsWrite.createFrom({
256
+ const write = await RecordsWrite.createFrom({
296
257
  recordsWriteMessage: recordsWrite.message,
297
258
  signer: Jws.createSigner(author),
298
259
  tags: {
@@ -304,30 +265,32 @@ describe('RecordsWrite', () => {
304
265
  expect(write.message.descriptor.tags.tag2).toBeDefined();
305
266
  expect(write.message.descriptor.tags.tag2).toEqual(expect.arrayContaining(['value1', 'value2', 'value3']));
306
267
  // update without tags
307
- const write2 = yield RecordsWrite.createFrom({
268
+ const write2 = await RecordsWrite.createFrom({
308
269
  recordsWriteMessage: write.message,
309
270
  signer: Jws.createSigner(author),
310
271
  });
311
272
  expect(write2.message.descriptor.tags).toBeUndefined();
312
- }));
273
+ });
313
274
  });
314
275
  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({
276
+ it('should invoke JSON schema validation when parsing a RecordsWrite', async () => {
277
+ const alice = await TestDataGenerator.generatePersona();
278
+ const recordsWrite = await RecordsWrite.create({
318
279
  signer: Jws.createSigner(alice),
280
+ protocol: 'http://test-protocol.xyz',
281
+ protocolPath: 'testRecord',
319
282
  dataFormat: 'application/octet-stream',
320
283
  data: TestDataGenerator.randomBytes(10),
321
284
  });
322
285
  const validateJsonSchemaSpy = sinon.spy(Message, 'validateJsonSchema');
323
- yield RecordsWrite.parse(recordsWrite.message);
286
+ await RecordsWrite.parse(recordsWrite.message);
324
287
  expect(validateJsonSchemaSpy.called).toBe(true);
325
- }));
288
+ });
326
289
  });
327
290
  describe('isSignedByAuthorDelegate()', () => {
328
- it('should return false if the given RecordsWrite is not signed at all', () => __awaiter(void 0, void 0, void 0, function* () {
291
+ it('should return false if the given RecordsWrite is not signed at all', async () => {
329
292
  const data = new TextEncoder().encode('any data');
330
- const recordsWrite = yield RecordsWrite.create({
293
+ const recordsWrite = await RecordsWrite.create({
331
294
  protocol: 'unused',
332
295
  protocolPath: 'unused',
333
296
  schema: 'unused',
@@ -336,12 +299,12 @@ describe('RecordsWrite', () => {
336
299
  });
337
300
  const isSignedByAuthorDelegate = recordsWrite.isSignedByAuthorDelegate;
338
301
  expect(isSignedByAuthorDelegate).toBe(false);
339
- }));
302
+ });
340
303
  });
341
304
  describe('isSignedByOwnerDelegate()', () => {
342
- it('should return false if the given RecordsWrite is not signed at all', () => __awaiter(void 0, void 0, void 0, function* () {
305
+ it('should return false if the given RecordsWrite is not signed at all', async () => {
343
306
  const data = new TextEncoder().encode('any data');
344
- const recordsWrite = yield RecordsWrite.create({
307
+ const recordsWrite = await RecordsWrite.create({
345
308
  protocol: 'unused',
346
309
  protocolPath: 'unused',
347
310
  schema: 'unused',
@@ -350,103 +313,111 @@ describe('RecordsWrite', () => {
350
313
  });
351
314
  const isSignedByOwnerDelegate = recordsWrite.isSignedByOwnerDelegate;
352
315
  expect(isSignedByOwnerDelegate).toBe(false);
353
- }));
316
+ });
354
317
  });
355
318
  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);
319
+ it('should return false if given message is not a RecordsWrite', async () => {
320
+ const { message } = await TestDataGenerator.generateRecordsQuery();
321
+ const isInitialWrite = await RecordsWrite.isInitialWrite(message);
359
322
  expect(isInitialWrite).toBe(false);
360
- }));
323
+ });
361
324
  });
362
325
  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();
326
+ it('should throw if the given author is undefined', async () => {
327
+ const { message } = await TestDataGenerator.generateRecordsWrite();
365
328
  const author = undefined;
366
- yield expect(RecordsWrite.getEntryId(author, message.descriptor)).rejects.toThrow(DwnErrorCode.RecordsWriteGetEntryIdUndefinedAuthor);
367
- }));
329
+ await expect(RecordsWrite.getEntryId(author, message.descriptor)).rejects.toThrow(DwnErrorCode.RecordsWriteGetEntryIdUndefinedAuthor);
330
+ });
368
331
  });
369
332
  describe('signAsOwner()', () => {
370
- it('should throw if the RecordsWrite is not signed by an author yet', () => __awaiter(void 0, void 0, void 0, function* () {
333
+ it('should throw if the RecordsWrite is not signed by an author yet', async () => {
371
334
  const options = {
372
335
  data: TestDataGenerator.randomBytes(10),
373
336
  dataFormat: 'application/json',
374
337
  dateCreated: '2023-07-27T10:20:30.405060Z',
375
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
338
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
339
+ protocol: 'http://test-protocol.xyz',
340
+ protocolPath: 'testRecord',
376
341
  };
377
- const recordsWrite = yield RecordsWrite.create(options);
342
+ const recordsWrite = await RecordsWrite.create(options);
378
343
  expect(recordsWrite.author).toBeUndefined();
379
344
  expect(recordsWrite.signaturePayload).toBeUndefined();
380
- const alice = yield TestDataGenerator.generateDidKeyPersona();
381
- yield expect(recordsWrite.signAsOwner(Jws.createSigner(alice))).rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerUnknownAuthor);
345
+ const alice = await TestDataGenerator.generateDidKeyPersona();
346
+ await expect(recordsWrite.signAsOwner(Jws.createSigner(alice))).rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerUnknownAuthor);
382
347
  expect(recordsWrite.owner).toBeUndefined();
383
348
  expect(recordsWrite.ownerSignaturePayload).toBeUndefined();
384
- }));
349
+ });
385
350
  });
386
351
  describe('signAsOwnerDelegate()', () => {
387
- it('should throw if the RecordsWrite is not signed by an author yet', () => __awaiter(void 0, void 0, void 0, function* () {
352
+ it('should throw if the RecordsWrite is not signed by an author yet', async () => {
388
353
  const options = {
389
354
  data: TestDataGenerator.randomBytes(10),
390
355
  dataFormat: 'application/json',
391
356
  dateCreated: '2023-07-27T10:20:30.405060Z',
392
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
357
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
358
+ protocol: 'http://test-protocol.xyz',
359
+ protocolPath: 'testRecord',
393
360
  };
394
- const recordsWrite = yield RecordsWrite.create(options);
361
+ const recordsWrite = await RecordsWrite.create(options);
395
362
  expect(recordsWrite.author).toBeUndefined();
396
363
  expect(recordsWrite.signaturePayload).toBeUndefined();
397
364
  // create a delegated grant
398
- const alice = yield TestDataGenerator.generateDidKeyPersona();
399
- const bob = yield TestDataGenerator.generateDidKeyPersona();
365
+ const alice = await TestDataGenerator.generateDidKeyPersona();
366
+ const bob = await TestDataGenerator.generateDidKeyPersona();
400
367
  const scope = {
401
368
  interface: DwnInterfaceName.Records,
402
369
  method: DwnMethodName.Write,
403
370
  protocol: 'chat'
404
371
  };
405
- const ownerDelegatedGrant = yield PermissionsProtocol.createGrant({
372
+ const ownerDelegatedGrant = await PermissionsProtocol.createGrant({
406
373
  signer: Jws.createSigner(alice),
407
374
  delegated: true, // this is a delegated grant
408
375
  dateExpires: Time.createOffsetTimestamp({ seconds: 100 }),
409
376
  grantedTo: bob.did,
410
377
  scope
411
378
  });
412
- yield expect(recordsWrite.signAsOwnerDelegate(Jws.createSigner(bob), ownerDelegatedGrant.dataEncodedMessage))
379
+ await expect(recordsWrite.signAsOwnerDelegate(Jws.createSigner(bob), ownerDelegatedGrant.dataEncodedMessage))
413
380
  .rejects.toThrow(DwnErrorCode.RecordsWriteSignAsOwnerDelegateUnknownAuthor);
414
381
  expect(recordsWrite.owner).toBeUndefined();
415
382
  expect(recordsWrite.ownerSignaturePayload).toBeUndefined();
416
- }));
383
+ });
417
384
  });
418
385
  describe('ownerSignatureSigner()', () => {
419
- it('should return `undefined` if owner signature is not present in the message', () => __awaiter(void 0, void 0, void 0, function* () {
386
+ it('should return `undefined` if owner signature is not present in the message', async () => {
420
387
  const options = {
421
388
  data: TestDataGenerator.randomBytes(10),
422
389
  dataFormat: 'application/json',
423
390
  dateCreated: '2023-07-27T10:20:30.405060Z',
424
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
391
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
392
+ protocol: 'http://test-protocol.xyz',
393
+ protocolPath: 'testRecord',
425
394
  };
426
- const recordsWrite = yield RecordsWrite.create(options);
395
+ const recordsWrite = await RecordsWrite.create(options);
427
396
  expect(recordsWrite.ownerSignatureSigner).toBeUndefined();
428
- }));
397
+ });
429
398
  });
430
399
  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* () {
400
+ it('should throw if attempting to access the message of a RecordsWrite that is not given authorization signature input', async () => {
432
401
  const options = {
433
402
  data: TestDataGenerator.randomBytes(10),
434
403
  dataFormat: 'application/json',
435
404
  dateCreated: '2023-07-27T10:20:30.405060Z',
436
- recordId: yield TestDataGenerator.randomCborSha256Cid(),
405
+ recordId: await TestDataGenerator.randomCborSha256Cid(),
406
+ protocol: 'http://test-protocol.xyz',
407
+ protocolPath: 'testRecord',
437
408
  };
438
- const recordsWrite = yield RecordsWrite.create(options);
409
+ const recordsWrite = await RecordsWrite.create(options);
439
410
  expect(recordsWrite.author).toBeUndefined();
440
411
  expect(recordsWrite.signaturePayload).toBeUndefined();
441
412
  expect(() => recordsWrite.message).toThrow(DwnErrorCode.RecordsWriteMissingSigner);
442
- }));
413
+ });
443
414
  });
444
415
  describe('encryptSymmetricEncryptionKey()', () => {
445
- it('should replace encryption property by default', () => __awaiter(void 0, void 0, void 0, function* () {
446
- const alice = yield TestDataGenerator.generatePersona();
416
+ it('should replace encryption property by default', async () => {
417
+ const alice = await TestDataGenerator.generatePersona();
447
418
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
448
419
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
449
- const recordsWrite = yield RecordsWrite.create({
420
+ const recordsWrite = await RecordsWrite.create({
450
421
  signer: Jws.createSigner(alice),
451
422
  protocol: 'https://example.com/protocol',
452
423
  protocolPath: 'test',
@@ -465,7 +436,7 @@ describe('RecordsWrite', () => {
465
436
  derivationScheme: KeyDerivationScheme.ProtocolPath,
466
437
  }],
467
438
  };
468
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
439
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
469
440
  expect(recordsWrite['_message'].encryption).toBeDefined();
470
441
  expect(recordsWrite['_message'].encryption.recipients).toHaveLength(1);
471
442
  expect(recordsWrite['_message'].encryption.recipients[0].header.derivationScheme).toBe('protocolPath');
@@ -477,19 +448,19 @@ describe('RecordsWrite', () => {
477
448
  keyEncryptionInputs: [{
478
449
  publicKeyId: alice.keyId,
479
450
  publicKey: alice.encryptionKeyPair.publicJwk,
480
- derivationScheme: KeyDerivationScheme.Schemas,
451
+ derivationScheme: KeyDerivationScheme.ProtocolContext,
481
452
  }],
482
453
  };
483
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2);
484
- // Should have replaced — only 1 entry with Schemas scheme
454
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2);
455
+ // Should have replaced — only 1 entry with ProtocolContext scheme
485
456
  expect(recordsWrite['_message'].encryption.recipients).toHaveLength(1);
486
- 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();
457
+ expect(recordsWrite['_message'].encryption.recipients[0].header.derivationScheme).toBe('protocolContext');
458
+ });
459
+ it('should append recipients when append option is true', async () => {
460
+ const alice = await TestDataGenerator.generatePersona();
490
461
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
491
462
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
492
- const recordsWrite = yield RecordsWrite.create({
463
+ const recordsWrite = await RecordsWrite.create({
493
464
  signer: Jws.createSigner(alice),
494
465
  protocol: 'https://example.com/protocol',
495
466
  protocolPath: 'test',
@@ -508,7 +479,7 @@ describe('RecordsWrite', () => {
508
479
  derivationScheme: KeyDerivationScheme.ProtocolPath,
509
480
  }],
510
481
  };
511
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
482
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
512
483
  const originalIV = recordsWrite['_message'].encryption.iv;
513
484
  const originalProtected = recordsWrite['_message'].encryption.protected;
514
485
  // Second encryption with append — ProtocolContext
@@ -522,7 +493,7 @@ describe('RecordsWrite', () => {
522
493
  derivationScheme: KeyDerivationScheme.ProtocolContext,
523
494
  }],
524
495
  };
525
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
496
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
526
497
  // Should have both entries
527
498
  const encryption = recordsWrite['_message'].encryption;
528
499
  expect(encryption.recipients).toHaveLength(2);
@@ -538,16 +509,16 @@ describe('RecordsWrite', () => {
538
509
  // When starting from a parsed/signed message (the signAsOwner test
539
510
  // below), authorization IS preserved by append mode.
540
511
  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* () {
512
+ });
513
+ it('should allow signAsOwner after append (reactive root-record upgrade)', async () => {
543
514
  // Simulates the cross-DWN scenario: Bob authors a record, Alice (owner)
544
515
  // appends a ProtocolContext recipient entry, then signs as owner.
545
- const alice = yield TestDataGenerator.generatePersona();
546
- const bob = yield TestDataGenerator.generatePersona();
516
+ const alice = await TestDataGenerator.generatePersona();
517
+ const bob = await TestDataGenerator.generatePersona();
547
518
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
548
519
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
549
520
  // Bob creates and signs the record
550
- const recordsWrite = yield RecordsWrite.create({
521
+ const recordsWrite = await RecordsWrite.create({
551
522
  signer: Jws.createSigner(bob),
552
523
  protocol: 'https://example.com/protocol',
553
524
  protocolPath: 'thread',
@@ -566,12 +537,12 @@ describe('RecordsWrite', () => {
566
537
  derivationScheme: KeyDerivationScheme.ProtocolPath,
567
538
  }],
568
539
  };
569
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
570
- yield recordsWrite.sign({ signer: Jws.createSigner(bob) });
540
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput1);
541
+ await recordsWrite.sign({ signer: Jws.createSigner(bob) });
571
542
  expect(recordsWrite.author).toBe(bob.did);
572
543
  expect(recordsWrite['_message'].authorization).toBeDefined();
573
544
  // Simulate: Alice parses Bob's message and appends ProtocolContext
574
- const parsed = yield RecordsWrite.parse(recordsWrite.message);
545
+ const parsed = await RecordsWrite.parse(recordsWrite.message);
575
546
  expect(parsed.author).toBe(bob.did);
576
547
  const encryptionInput2 = {
577
548
  initializationVector: dataEncryptionIV,
@@ -583,12 +554,12 @@ describe('RecordsWrite', () => {
583
554
  derivationScheme: KeyDerivationScheme.ProtocolContext,
584
555
  }],
585
556
  };
586
- yield parsed.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
557
+ await parsed.encryptSymmetricEncryptionKey(encryptionInput2, { append: true });
587
558
  // Author and authorization should be preserved after append
588
559
  expect(parsed.author).toBe(bob.did);
589
560
  expect(parsed['_message'].authorization).toBeDefined();
590
561
  // Alice signs as owner — should NOT throw
591
- yield parsed.signAsOwner(Jws.createSigner(alice));
562
+ await parsed.signAsOwner(Jws.createSigner(alice));
592
563
  expect(parsed.owner).toBe(alice.did);
593
564
  expect(parsed['_message'].authorization.ownerSignature).toBeDefined();
594
565
  // Both recipient entries should be present
@@ -598,13 +569,13 @@ describe('RecordsWrite', () => {
598
569
  expect(encryption.recipients[1].header.derivationScheme).toBe('protocolContext');
599
570
  // validateIntegrity should pass — the stale encryptionCid in the
600
571
  // 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();
572
+ await parsed['validateIntegrity']();
573
+ });
574
+ it('should throw when append is true but encryption does not exist', async () => {
575
+ const alice = await TestDataGenerator.generatePersona();
605
576
  const dataEncryptionKey = TestDataGenerator.randomBytes(32);
606
577
  const dataEncryptionIV = TestDataGenerator.randomBytes(12);
607
- const recordsWrite = yield RecordsWrite.create({
578
+ const recordsWrite = await RecordsWrite.create({
608
579
  signer: Jws.createSigner(alice),
609
580
  protocol: 'https://example.com/protocol',
610
581
  protocolPath: 'test',
@@ -621,8 +592,8 @@ describe('RecordsWrite', () => {
621
592
  derivationScheme: KeyDerivationScheme.ProtocolPath,
622
593
  }],
623
594
  };
624
- yield expect(recordsWrite.encryptSymmetricEncryptionKey(encryptionInput, { append: true })).rejects.toThrow(DwnErrorCode.RecordsWriteMissingEncryption);
625
- }));
595
+ await expect(recordsWrite.encryptSymmetricEncryptionKey(encryptionInput, { append: true })).rejects.toThrow(DwnErrorCode.RecordsWriteMissingEncryption);
596
+ });
626
597
  });
627
598
  });
628
599
  //# sourceMappingURL=records-write.spec.js.map