@enbox/dwn-sdk-js 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/dist/browser.mjs +8 -8
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/generated/precompiled-validators.js +1 -2
  4. package/dist/esm/generated/precompiled-validators.js.map +1 -1
  5. package/dist/esm/src/core/abstract-message.js +4 -0
  6. package/dist/esm/src/core/abstract-message.js.map +1 -1
  7. package/dist/esm/src/core/auth.js +22 -33
  8. package/dist/esm/src/core/auth.js.map +1 -1
  9. package/dist/esm/src/core/dwn-constant.js +7 -7
  10. package/dist/esm/src/core/dwn-constant.js.map +1 -1
  11. package/dist/esm/src/core/dwn-error.js +1 -0
  12. package/dist/esm/src/core/dwn-error.js.map +1 -1
  13. package/dist/esm/src/core/grant-authorization.js +37 -52
  14. package/dist/esm/src/core/grant-authorization.js.map +1 -1
  15. package/dist/esm/src/core/message.js +85 -116
  16. package/dist/esm/src/core/message.js.map +1 -1
  17. package/dist/esm/src/core/messages-grant-authorization.js +63 -78
  18. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
  19. package/dist/esm/src/core/protocol-authorization-action.js +266 -0
  20. package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
  21. package/dist/esm/src/core/protocol-authorization-validation.js +254 -0
  22. package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
  23. package/dist/esm/src/core/protocol-authorization.js +122 -740
  24. package/dist/esm/src/core/protocol-authorization.js.map +1 -1
  25. package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
  26. package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
  27. package/dist/esm/src/core/record-chain.js +64 -0
  28. package/dist/esm/src/core/record-chain.js.map +1 -0
  29. package/dist/esm/src/core/records-grant-authorization.js +55 -72
  30. package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
  31. package/dist/esm/src/core/resumable-task-manager.js +50 -65
  32. package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
  33. package/dist/esm/src/core/tenant-gate.js +2 -13
  34. package/dist/esm/src/core/tenant-gate.js.map +1 -1
  35. package/dist/esm/src/dwn.js +69 -86
  36. package/dist/esm/src/dwn.js.map +1 -1
  37. package/dist/esm/src/event-stream/event-emitter-stream.js +17 -31
  38. package/dist/esm/src/event-stream/event-emitter-stream.js.map +1 -1
  39. package/dist/esm/src/handlers/messages-read.js +67 -77
  40. package/dist/esm/src/handlers/messages-read.js.map +1 -1
  41. package/dist/esm/src/handlers/messages-subscribe.js +51 -61
  42. package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
  43. package/dist/esm/src/handlers/messages-sync.js +75 -85
  44. package/dist/esm/src/handlers/messages-sync.js.map +1 -1
  45. package/dist/esm/src/handlers/protocols-configure.js +135 -155
  46. package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
  47. package/dist/esm/src/handlers/protocols-query.js +52 -51
  48. package/dist/esm/src/handlers/protocols-query.js.map +1 -1
  49. package/dist/esm/src/handlers/records-count.js +96 -82
  50. package/dist/esm/src/handlers/records-count.js.map +1 -1
  51. package/dist/esm/src/handlers/records-delete.js +78 -88
  52. package/dist/esm/src/handlers/records-delete.js.map +1 -1
  53. package/dist/esm/src/handlers/records-query.js +116 -101
  54. package/dist/esm/src/handlers/records-query.js.map +1 -1
  55. package/dist/esm/src/handlers/records-read.js +124 -131
  56. package/dist/esm/src/handlers/records-read.js.map +1 -1
  57. package/dist/esm/src/handlers/records-subscribe.js +150 -103
  58. package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
  59. package/dist/esm/src/handlers/records-write.js +250 -259
  60. package/dist/esm/src/handlers/records-write.js.map +1 -1
  61. package/dist/esm/src/interfaces/messages-read.js +24 -32
  62. package/dist/esm/src/interfaces/messages-read.js.map +1 -1
  63. package/dist/esm/src/interfaces/messages-subscribe.js +27 -41
  64. package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
  65. package/dist/esm/src/interfaces/messages-sync.js +26 -40
  66. package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
  67. package/dist/esm/src/interfaces/protocols-configure.js +63 -63
  68. package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
  69. package/dist/esm/src/interfaces/protocols-query.js +55 -68
  70. package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
  71. package/dist/esm/src/interfaces/records-count.js +50 -66
  72. package/dist/esm/src/interfaces/records-count.js.map +1 -1
  73. package/dist/esm/src/interfaces/records-delete.js +45 -55
  74. package/dist/esm/src/interfaces/records-delete.js.map +1 -1
  75. package/dist/esm/src/interfaces/records-query.js +60 -76
  76. package/dist/esm/src/interfaces/records-query.js.map +1 -1
  77. package/dist/esm/src/interfaces/records-read.js +51 -67
  78. package/dist/esm/src/interfaces/records-read.js.map +1 -1
  79. package/dist/esm/src/interfaces/records-subscribe.js +52 -68
  80. package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
  81. package/dist/esm/src/interfaces/records-write-query.js +102 -0
  82. package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
  83. package/dist/esm/src/interfaces/records-write-signing.js +92 -0
  84. package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
  85. package/dist/esm/src/interfaces/records-write.js +407 -602
  86. package/dist/esm/src/interfaces/records-write.js.map +1 -1
  87. package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
  88. package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
  89. package/dist/esm/src/jose/jws/general/builder.js +23 -35
  90. package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
  91. package/dist/esm/src/jose/jws/general/verifier.js +56 -69
  92. package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
  93. package/dist/esm/src/protocols/permission-grant.js +44 -15
  94. package/dist/esm/src/protocols/permission-grant.js.map +1 -1
  95. package/dist/esm/src/protocols/permission-request.js +29 -15
  96. package/dist/esm/src/protocols/permission-request.js.map +1 -1
  97. package/dist/esm/src/protocols/permissions.js +216 -226
  98. package/dist/esm/src/protocols/permissions.js.map +1 -1
  99. package/dist/esm/src/smt/smt-store-level.js +42 -64
  100. package/dist/esm/src/smt/smt-store-level.js.map +1 -1
  101. package/dist/esm/src/smt/smt-store-memory.js +19 -45
  102. package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
  103. package/dist/esm/src/smt/smt-utils.js +28 -45
  104. package/dist/esm/src/smt/smt-utils.js.map +1 -1
  105. package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
  106. package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
  107. package/dist/esm/src/state-index/state-index-level.js +115 -150
  108. package/dist/esm/src/state-index/state-index-level.js.map +1 -1
  109. package/dist/esm/src/store/blockstore-level.js +54 -156
  110. package/dist/esm/src/store/blockstore-level.js.map +1 -1
  111. package/dist/esm/src/store/blockstore-mock.js +48 -153
  112. package/dist/esm/src/store/blockstore-mock.js.map +1 -1
  113. package/dist/esm/src/store/data-store-level.js +59 -99
  114. package/dist/esm/src/store/data-store-level.js.map +1 -1
  115. package/dist/esm/src/store/index-level-compound.js +246 -0
  116. package/dist/esm/src/store/index-level-compound.js.map +1 -0
  117. package/dist/esm/src/store/index-level.js +295 -713
  118. package/dist/esm/src/store/index-level.js.map +1 -1
  119. package/dist/esm/src/store/level-wrapper.js +143 -244
  120. package/dist/esm/src/store/level-wrapper.js.map +1 -1
  121. package/dist/esm/src/store/message-store-level.js +71 -94
  122. package/dist/esm/src/store/message-store-level.js.map +1 -1
  123. package/dist/esm/src/store/resumable-task-store-level.js +62 -101
  124. package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
  125. package/dist/esm/src/store/storage-controller.js +129 -144
  126. package/dist/esm/src/store/storage-controller.js.map +1 -1
  127. package/dist/esm/src/utils/abort.js +8 -19
  128. package/dist/esm/src/utils/abort.js.map +1 -1
  129. package/dist/esm/src/utils/array.js +15 -49
  130. package/dist/esm/src/utils/array.js.map +1 -1
  131. package/dist/esm/src/utils/cid.js +29 -77
  132. package/dist/esm/src/utils/cid.js.map +1 -1
  133. package/dist/esm/src/utils/data-stream.js +37 -65
  134. package/dist/esm/src/utils/data-stream.js.map +1 -1
  135. package/dist/esm/src/utils/encryption.js +136 -162
  136. package/dist/esm/src/utils/encryption.js.map +1 -1
  137. package/dist/esm/src/utils/filter.js +1 -12
  138. package/dist/esm/src/utils/filter.js.map +1 -1
  139. package/dist/esm/src/utils/hd-key.js +45 -63
  140. package/dist/esm/src/utils/hd-key.js.map +1 -1
  141. package/dist/esm/src/utils/jws.js +9 -20
  142. package/dist/esm/src/utils/jws.js.map +1 -1
  143. package/dist/esm/src/utils/memory-cache.js +12 -23
  144. package/dist/esm/src/utils/memory-cache.js.map +1 -1
  145. package/dist/esm/src/utils/messages.js +9 -3
  146. package/dist/esm/src/utils/messages.js.map +1 -1
  147. package/dist/esm/src/utils/private-key-signer.js +9 -17
  148. package/dist/esm/src/utils/private-key-signer.js.map +1 -1
  149. package/dist/esm/src/utils/protocols.js +62 -70
  150. package/dist/esm/src/utils/protocols.js.map +1 -1
  151. package/dist/esm/src/utils/records.js +100 -125
  152. package/dist/esm/src/utils/records.js.map +1 -1
  153. package/dist/esm/src/utils/secp256k1.js +60 -96
  154. package/dist/esm/src/utils/secp256k1.js.map +1 -1
  155. package/dist/esm/src/utils/secp256r1.js +54 -71
  156. package/dist/esm/src/utils/secp256r1.js.map +1 -1
  157. package/dist/esm/src/utils/time.js +5 -18
  158. package/dist/esm/src/utils/time.js.map +1 -1
  159. package/dist/esm/src/utils/url.js +3 -3
  160. package/dist/esm/src/utils/url.js.map +1 -1
  161. package/dist/esm/tests/core/auth.spec.js +3 -12
  162. package/dist/esm/tests/core/auth.spec.js.map +1 -1
  163. package/dist/esm/tests/core/message.spec.js +50 -59
  164. package/dist/esm/tests/core/message.spec.js.map +1 -1
  165. package/dist/esm/tests/core/protocol-authorization.spec.js +9 -18
  166. package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
  167. package/dist/esm/tests/dwn.spec.js +45 -58
  168. package/dist/esm/tests/dwn.spec.js.map +1 -1
  169. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +24 -33
  170. package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +1 -1
  171. package/dist/esm/tests/event-stream/event-stream.spec.js +46 -55
  172. package/dist/esm/tests/event-stream/event-stream.spec.js.map +1 -1
  173. package/dist/esm/tests/features/author-delegated-grant.spec.js +326 -343
  174. package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
  175. package/dist/esm/tests/features/owner-delegated-grant.spec.js +153 -169
  176. package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
  177. package/dist/esm/tests/features/owner-signature.spec.js +67 -78
  178. package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
  179. package/dist/esm/tests/features/permissions.spec.js +446 -181
  180. package/dist/esm/tests/features/permissions.spec.js.map +1 -1
  181. package/dist/esm/tests/features/protocol-composition.spec.js +346 -356
  182. package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
  183. package/dist/esm/tests/features/protocol-create-action.spec.js +42 -51
  184. package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
  185. package/dist/esm/tests/features/protocol-delete-action.spec.js +94 -103
  186. package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
  187. package/dist/esm/tests/features/protocol-update-action.spec.js +105 -114
  188. package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
  189. package/dist/esm/tests/features/records-prune.spec.js +175 -191
  190. package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
  191. package/dist/esm/tests/features/records-tags.spec.js +441 -460
  192. package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
  193. package/dist/esm/tests/features/resumable-tasks.spec.js +82 -91
  194. package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
  195. package/dist/esm/tests/handlers/messages-read.spec.js +206 -207
  196. package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
  197. package/dist/esm/tests/handlers/messages-subscribe.spec.js +145 -154
  198. package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
  199. package/dist/esm/tests/handlers/messages-sync.spec.js +174 -183
  200. package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
  201. package/dist/esm/tests/handlers/protocols-configure.spec.js +244 -238
  202. package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
  203. package/dist/esm/tests/handlers/protocols-query.spec.js +156 -169
  204. package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
  205. package/dist/esm/tests/handlers/records-count.spec.js +93 -102
  206. package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
  207. package/dist/esm/tests/handlers/records-delete.spec.js +252 -264
  208. package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
  209. package/dist/esm/tests/handlers/records-query.spec.js +917 -988
  210. package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
  211. package/dist/esm/tests/handlers/records-read.spec.js +549 -564
  212. package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
  213. package/dist/esm/tests/handlers/records-subscribe.spec.js +269 -278
  214. package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
  215. package/dist/esm/tests/handlers/records-write.spec.js +1057 -1082
  216. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
  217. package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
  218. package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
  219. package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
  220. package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
  221. package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
  222. package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
  223. package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
  224. package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
  225. package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
  226. package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
  227. package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
  228. package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
  229. package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
  230. package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
  231. package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
  232. package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
  233. package/dist/esm/tests/interfaces/records-write.spec.js +152 -165
  234. package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
  235. package/dist/esm/tests/jose/jws/general.spec.js +36 -45
  236. package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
  237. package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
  238. package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
  239. package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
  240. package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
  241. package/dist/esm/tests/protocols/permissions.spec.js +49 -55
  242. package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
  243. package/dist/esm/tests/scenarios/aggregator.spec.js +124 -135
  244. package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
  245. package/dist/esm/tests/scenarios/deleted-record.spec.js +23 -32
  246. package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
  247. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +52 -61
  248. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
  249. package/dist/esm/tests/scenarios/nested-roles.spec.js +63 -73
  250. package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
  251. package/dist/esm/tests/scenarios/subscriptions.spec.js +377 -333
  252. package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
  253. package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
  254. package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
  255. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
  256. package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
  257. package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
  258. package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
  259. package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
  260. package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
  261. package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
  262. package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
  263. package/dist/esm/tests/store/data-store-level.spec.js +86 -95
  264. package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
  265. package/dist/esm/tests/store/index-level.spec.js +404 -414
  266. package/dist/esm/tests/store/index-level.spec.js.map +1 -1
  267. package/dist/esm/tests/store/message-store-level.spec.js +13 -22
  268. package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
  269. package/dist/esm/tests/store/message-store.spec.js +229 -238
  270. package/dist/esm/tests/store/message-store.spec.js.map +1 -1
  271. package/dist/esm/tests/test-event-stream.js +3 -3
  272. package/dist/esm/tests/test-event-stream.js.map +1 -1
  273. package/dist/esm/tests/test-stores.js +16 -13
  274. package/dist/esm/tests/test-stores.js.map +1 -1
  275. package/dist/esm/tests/test-suite.js +2 -11
  276. package/dist/esm/tests/test-suite.js.map +1 -1
  277. package/dist/esm/tests/utils/cid.spec.js +24 -33
  278. package/dist/esm/tests/utils/cid.spec.js.map +1 -1
  279. package/dist/esm/tests/utils/data-stream.spec.js +48 -57
  280. package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
  281. package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
  282. package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
  283. package/dist/esm/tests/utils/encryption.spec.js +229 -82
  284. package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
  285. package/dist/esm/tests/utils/filters.spec.js +46 -55
  286. package/dist/esm/tests/utils/filters.spec.js.map +1 -1
  287. package/dist/esm/tests/utils/hd-key.spec.js +10 -19
  288. package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
  289. package/dist/esm/tests/utils/jws.spec.js +3 -12
  290. package/dist/esm/tests/utils/jws.spec.js.map +1 -1
  291. package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
  292. package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
  293. package/dist/esm/tests/utils/messages.spec.js +6 -15
  294. package/dist/esm/tests/utils/messages.spec.js.map +1 -1
  295. package/dist/esm/tests/utils/poller.js +22 -33
  296. package/dist/esm/tests/utils/poller.js.map +1 -1
  297. package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
  298. package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
  299. package/dist/esm/tests/utils/records.spec.js +10 -19
  300. package/dist/esm/tests/utils/records.spec.js.map +1 -1
  301. package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
  302. package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
  303. package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
  304. package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
  305. package/dist/esm/tests/utils/test-data-generator.js +414 -468
  306. package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
  307. package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
  308. package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
  309. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
  310. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
  311. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
  312. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
  313. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
  314. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
  315. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
  316. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
  317. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
  318. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
  319. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
  320. package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
  321. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +7 -16
  322. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
  323. package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
  324. package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
  325. package/dist/types/src/core/protocol-authorization-validation.d.ts +60 -0
  326. package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
  327. package/dist/types/src/core/protocol-authorization.d.ts +10 -100
  328. package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
  329. package/dist/types/src/core/record-chain.d.ts +24 -0
  330. package/dist/types/src/core/record-chain.d.ts.map +1 -0
  331. package/dist/types/src/handlers/records-write.d.ts +2 -1
  332. package/dist/types/src/handlers/records-write.d.ts.map +1 -1
  333. package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
  334. package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
  335. package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
  336. package/dist/types/src/interfaces/records-write-signing.d.ts +35 -0
  337. package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
  338. package/dist/types/src/interfaces/records-write.d.ts +10 -44
  339. package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
  340. package/dist/types/src/store/index-level-compound.d.ts +70 -0
  341. package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
  342. package/dist/types/src/store/index-level.d.ts +0 -58
  343. package/dist/types/src/store/index-level.d.ts.map +1 -1
  344. package/dist/types/src/utils/protocols.d.ts +5 -0
  345. package/dist/types/src/utils/protocols.d.ts.map +1 -1
  346. package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
  347. package/package.json +2 -2
  348. package/src/core/protocol-authorization-action.ts +377 -0
  349. package/src/core/protocol-authorization-validation.ts +391 -0
  350. package/src/core/protocol-authorization.ts +60 -849
  351. package/src/core/record-chain.ts +99 -0
  352. package/src/handlers/records-read.ts +1 -1
  353. package/src/handlers/records-write.ts +37 -21
  354. package/src/interfaces/protocols-configure.ts +33 -5
  355. package/src/interfaces/records-write-query.ts +139 -0
  356. package/src/interfaces/records-write-signing.ts +143 -0
  357. package/src/interfaces/records-write.ts +49 -221
  358. package/src/store/index-level-compound.ts +324 -0
  359. package/src/store/index-level.ts +24 -306
  360. package/src/utils/protocols.ts +8 -0
  361. package/src/utils/records.ts +1 -1
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import * as cbor from '@ipld/dag-cbor';
11
2
  import { CID } from 'multiformats/cid';
12
3
  import { DataStream } from '../../src/utils/data-stream.js';
@@ -41,143 +32,131 @@ export class TestDataGenerator {
41
32
  /**
42
33
  * Generates a persona.
43
34
  */
44
- static generatePersona(input) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- var _a, _b;
47
- // generate DID if not given
48
- let did = input === null || input === void 0 ? void 0 : input.did;
49
- if (!did) {
50
- const didSuffix = TestDataGenerator.randomString(32);
51
- did = `did:example:${didSuffix}`;
52
- }
53
- // generate persona key ID if not given
54
- const keyIdSuffix = TestDataGenerator.randomString(10);
55
- const keyId = (_a = input === null || input === void 0 ? void 0 : input.keyId) !== null && _a !== void 0 ? _a : `${did}#${keyIdSuffix}`;
56
- // generate persona signing key pair if not given (secp256k1 for ES256K signatures)
57
- const keyPair = (_b = input === null || input === void 0 ? void 0 : input.keyPair) !== null && _b !== void 0 ? _b : yield Secp256k1.generateKeyPair();
58
- // generate persona encryption key pair if not given (X25519 for ECDH-ES key agreement)
59
- let encryptionKeyPair = input === null || input === void 0 ? void 0 : input.encryptionKeyPair;
60
- if (!encryptionKeyPair) {
61
- const encPrivateKey = yield X25519.generateKey();
62
- const encPublicKey = yield X25519.getPublicKey({ key: encPrivateKey });
63
- encryptionKeyPair = {
64
- publicJwk: encPublicKey,
65
- privateJwk: encPrivateKey,
66
- };
67
- }
68
- const persona = {
69
- did,
70
- keyId,
71
- keyPair,
72
- encryptionKeyPair,
73
- signer: new PrivateKeySigner({
74
- privateJwk: keyPair.privateJwk,
75
- algorithm: keyPair.privateJwk.alg,
76
- keyId: `${did}#${keyId}`,
77
- })
35
+ static async generatePersona(input) {
36
+ // generate DID if not given
37
+ let did = input?.did;
38
+ if (!did) {
39
+ const didSuffix = TestDataGenerator.randomString(32);
40
+ did = `did:example:${didSuffix}`;
41
+ }
42
+ // generate persona key ID if not given
43
+ const keyIdSuffix = TestDataGenerator.randomString(10);
44
+ const keyId = input?.keyId ?? `${did}#${keyIdSuffix}`;
45
+ // generate persona signing key pair if not given (secp256k1 for ES256K signatures)
46
+ const keyPair = input?.keyPair ?? await Secp256k1.generateKeyPair();
47
+ // generate persona encryption key pair if not given (X25519 for ECDH-ES key agreement)
48
+ let encryptionKeyPair = input?.encryptionKeyPair;
49
+ if (!encryptionKeyPair) {
50
+ const encPrivateKey = await X25519.generateKey();
51
+ const encPublicKey = await X25519.getPublicKey({ key: encPrivateKey });
52
+ encryptionKeyPair = {
53
+ publicJwk: encPublicKey,
54
+ privateJwk: encPrivateKey,
78
55
  };
79
- return persona;
80
- });
56
+ }
57
+ const persona = {
58
+ did,
59
+ keyId,
60
+ keyPair,
61
+ encryptionKeyPair,
62
+ signer: new PrivateKeySigner({
63
+ privateJwk: keyPair.privateJwk,
64
+ algorithm: keyPair.privateJwk.alg,
65
+ keyId: `${did}#${keyId}`,
66
+ })
67
+ };
68
+ return persona;
81
69
  }
82
70
  /**
83
71
  * Generates a ProtocolsConfigure message for testing.
84
72
  * Optional parameters are generated if not given.
85
73
  * Implementation currently uses `ProtocolsConfigure.create()`.
86
74
  */
87
- static generateProtocolsConfigure(input) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- var _a, _b;
90
- const author = (_a = input === null || input === void 0 ? void 0 : input.author) !== null && _a !== void 0 ? _a : yield TestDataGenerator.generatePersona();
91
- // generate protocol types and definition if not given
92
- let definition = input === null || input === void 0 ? void 0 : input.protocolDefinition;
93
- if (!definition) {
94
- const generatedLabel = 'record' + TestDataGenerator.randomString(10);
95
- definition = {
96
- protocol: TestDataGenerator.randomString(20),
97
- published: (_b = input === null || input === void 0 ? void 0 : input.published) !== null && _b !== void 0 ? _b : false,
98
- types: {},
99
- structure: {}
100
- };
101
- definition.types[generatedLabel] = {
102
- schema: `test-object`,
103
- dataFormats: ['text/plain']
104
- };
105
- definition.structure[generatedLabel] = {};
106
- }
107
- const signer = Jws.createSigner(author);
108
- const options = {
109
- messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
110
- definition,
111
- signer,
112
- permissionGrantId: input === null || input === void 0 ? void 0 : input.permissionGrantId,
113
- delegatedGrant: input === null || input === void 0 ? void 0 : input.delegatedGrant
75
+ static async generateProtocolsConfigure(input) {
76
+ const author = input?.author ?? await TestDataGenerator.generatePersona();
77
+ // generate protocol types and definition if not given
78
+ let definition = input?.protocolDefinition;
79
+ if (!definition) {
80
+ const generatedLabel = 'record' + TestDataGenerator.randomString(10);
81
+ definition = {
82
+ protocol: TestDataGenerator.randomString(20),
83
+ published: input?.published ?? false,
84
+ types: {},
85
+ structure: {}
114
86
  };
115
- const protocolsConfigure = yield ProtocolsConfigure.create(options);
116
- return {
117
- author,
118
- message: protocolsConfigure.message,
119
- protocolsConfigure
87
+ definition.types[generatedLabel] = {
88
+ schema: `test-object`,
89
+ dataFormats: ['text/plain']
120
90
  };
121
- });
91
+ definition.structure[generatedLabel] = {};
92
+ }
93
+ const signer = Jws.createSigner(author);
94
+ const options = {
95
+ messageTimestamp: input?.messageTimestamp,
96
+ definition,
97
+ signer,
98
+ permissionGrantId: input?.permissionGrantId,
99
+ delegatedGrant: input?.delegatedGrant
100
+ };
101
+ const protocolsConfigure = await ProtocolsConfigure.create(options);
102
+ return {
103
+ author,
104
+ message: protocolsConfigure.message,
105
+ protocolsConfigure
106
+ };
122
107
  }
123
108
  ;
124
109
  /**
125
110
  * Generates a ProtocolsQuery message for testing.
126
111
  */
127
- static generateProtocolsQuery(input) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- var _a;
130
- // generate author persona if not given
131
- const author = (_a = input === null || input === void 0 ? void 0 : input.author) !== null && _a !== void 0 ? _a : yield TestDataGenerator.generatePersona();
132
- const signer = Jws.createSigner(author);
133
- const options = {
134
- messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
135
- filter: input === null || input === void 0 ? void 0 : input.filter,
136
- signer,
137
- permissionGrantId: input === null || input === void 0 ? void 0 : input.permissionGrantId,
138
- };
139
- removeUndefinedProperties(options);
140
- const protocolsQuery = yield ProtocolsQuery.create(options);
141
- return {
142
- author,
143
- message: protocolsQuery.message,
144
- protocolsQuery
145
- };
146
- });
112
+ static async generateProtocolsQuery(input) {
113
+ // generate author persona if not given
114
+ const author = input?.author ?? await TestDataGenerator.generatePersona();
115
+ const signer = Jws.createSigner(author);
116
+ const options = {
117
+ messageTimestamp: input?.messageTimestamp,
118
+ filter: input?.filter,
119
+ signer,
120
+ permissionGrantId: input?.permissionGrantId,
121
+ };
122
+ removeUndefinedProperties(options);
123
+ const protocolsQuery = await ProtocolsQuery.create(options);
124
+ return {
125
+ author,
126
+ message: protocolsQuery.message,
127
+ protocolsQuery
128
+ };
147
129
  }
148
130
  ;
149
- static generateGrantCreate(input) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- var _a, _b, _c, _d, _e, _f;
152
- const author = (_a = input === null || input === void 0 ? void 0 : input.author) !== null && _a !== void 0 ? _a : yield TestDataGenerator.generatePersona();
153
- const grantedToPersona = (_b = input === null || input === void 0 ? void 0 : input.grantedTo) !== null && _b !== void 0 ? _b : yield TestDataGenerator.generatePersona();
154
- const dateExpires = (_c = input === null || input === void 0 ? void 0 : input.dateExpires) !== null && _c !== void 0 ? _c : Time.createOffsetTimestamp({ seconds: 10 });
155
- const scope = (_d = input === null || input === void 0 ? void 0 : input.scope) !== null && _d !== void 0 ? _d : {
156
- interface: DwnInterfaceName.Messages,
157
- method: DwnMethodName.Read
158
- };
159
- const signer = Jws.createSigner(author);
160
- const grantedTo = grantedToPersona.did;
161
- const options = {
162
- signer,
163
- grantedTo,
164
- dateExpires,
165
- scope,
166
- description: (_e = input === null || input === void 0 ? void 0 : input.description) !== null && _e !== void 0 ? _e : TestDataGenerator.randomString(10),
167
- delegated: (_f = input === null || input === void 0 ? void 0 : input.delegated) !== null && _f !== void 0 ? _f : false,
168
- requestId: input === null || input === void 0 ? void 0 : input.requestId,
169
- conditions: input === null || input === void 0 ? void 0 : input.conditions,
170
- };
171
- const grant = yield PermissionsProtocol.createGrant(options);
172
- const dataStream = DataStream.fromBytes(grant.permissionGrantBytes);
173
- return {
174
- dataStream,
175
- recordsWrite: grant.recordsWrite,
176
- dataBytes: grant.permissionGrantBytes,
177
- message: grant.recordsWrite.message,
178
- dataEncodedMessage: grant.dataEncodedMessage
179
- };
180
- });
131
+ static async generateGrantCreate(input) {
132
+ const author = input?.author ?? await TestDataGenerator.generatePersona();
133
+ const grantedToPersona = input?.grantedTo ?? await TestDataGenerator.generatePersona();
134
+ const dateExpires = input?.dateExpires ?? Time.createOffsetTimestamp({ seconds: 10 });
135
+ const scope = input?.scope ?? {
136
+ interface: DwnInterfaceName.Messages,
137
+ method: DwnMethodName.Read
138
+ };
139
+ const signer = Jws.createSigner(author);
140
+ const grantedTo = grantedToPersona.did;
141
+ const options = {
142
+ signer,
143
+ grantedTo,
144
+ dateExpires,
145
+ scope,
146
+ description: input?.description ?? TestDataGenerator.randomString(10),
147
+ delegated: input?.delegated ?? false,
148
+ requestId: input?.requestId,
149
+ conditions: input?.conditions,
150
+ };
151
+ const grant = await PermissionsProtocol.createGrant(options);
152
+ const dataStream = DataStream.fromBytes(grant.permissionGrantBytes);
153
+ return {
154
+ dataStream,
155
+ recordsWrite: grant.recordsWrite,
156
+ dataBytes: grant.permissionGrantBytes,
157
+ message: grant.recordsWrite.message,
158
+ dataEncodedMessage: grant.dataEncodedMessage
159
+ };
181
160
  }
182
161
  ;
183
162
  /**
@@ -190,54 +169,51 @@ export class TestDataGenerator {
190
169
  * @param input.signer MessageSigner of the message. Generated if not given.
191
170
  * @param input.schema Schema of the message. Randomly generated if not given.
192
171
  */
193
- static generateRecordsWrite(input) {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- var _a, _b, _c, _d, _e;
196
- const author = (_a = input === null || input === void 0 ? void 0 : input.author) !== null && _a !== void 0 ? _a : yield TestDataGenerator.generatePersona();
197
- const signer = Jws.createSigner(author);
198
- const attestationSigners = Jws.createSigners((_b = input === null || input === void 0 ? void 0 : input.attesters) !== null && _b !== void 0 ? _b : []);
199
- const dataCid = input === null || input === void 0 ? void 0 : input.dataCid;
200
- const dataSize = input === null || input === void 0 ? void 0 : input.dataSize;
201
- let dataBytes;
202
- let dataStream;
203
- if (dataCid === undefined && dataSize === undefined) {
204
- dataBytes = (_c = input === null || input === void 0 ? void 0 : input.data) !== null && _c !== void 0 ? _c : TestDataGenerator.randomBytes(32);
205
- dataStream = DataStream.fromBytes(dataBytes);
206
- }
207
- const options = {
208
- recipient: input === null || input === void 0 ? void 0 : input.recipient,
209
- protocol: input === null || input === void 0 ? void 0 : input.protocol,
210
- protocolPath: input === null || input === void 0 ? void 0 : input.protocolPath,
211
- protocolRole: input === null || input === void 0 ? void 0 : input.protocolRole,
212
- schema: (_d = input === null || input === void 0 ? void 0 : input.schema) !== null && _d !== void 0 ? _d : `http://${TestDataGenerator.randomString(20)}`,
213
- tags: input === null || input === void 0 ? void 0 : input.tags,
214
- recordId: input === null || input === void 0 ? void 0 : input.recordId,
215
- parentContextId: input === null || input === void 0 ? void 0 : input.parentContextId,
216
- published: input === null || input === void 0 ? void 0 : input.published,
217
- dataFormat: (_e = input === null || input === void 0 ? void 0 : input.dataFormat) !== null && _e !== void 0 ? _e : 'application/json',
218
- dateCreated: input === null || input === void 0 ? void 0 : input.dateCreated,
219
- messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
220
- datePublished: input === null || input === void 0 ? void 0 : input.datePublished,
221
- data: dataBytes,
222
- dataCid,
223
- dataSize,
224
- signer,
225
- attestationSigners,
226
- encryptionInput: input === null || input === void 0 ? void 0 : input.encryptionInput,
227
- permissionGrantId: input === null || input === void 0 ? void 0 : input.permissionGrantId,
228
- };
229
- const recordsWrite = yield RecordsWrite.create(options);
230
- const message = recordsWrite.message;
231
- return {
232
- author,
233
- message,
234
- dataCid,
235
- dataSize,
236
- dataBytes,
237
- dataStream,
238
- recordsWrite
239
- };
240
- });
172
+ static async generateRecordsWrite(input) {
173
+ const author = input?.author ?? await TestDataGenerator.generatePersona();
174
+ const signer = Jws.createSigner(author);
175
+ const attestationSigners = Jws.createSigners(input?.attesters ?? []);
176
+ const dataCid = input?.dataCid;
177
+ const dataSize = input?.dataSize;
178
+ let dataBytes;
179
+ let dataStream;
180
+ if (dataCid === undefined && dataSize === undefined) {
181
+ dataBytes = input?.data ?? TestDataGenerator.randomBytes(32);
182
+ dataStream = DataStream.fromBytes(dataBytes);
183
+ }
184
+ const options = {
185
+ recipient: input?.recipient,
186
+ protocol: input?.protocol,
187
+ protocolPath: input?.protocolPath,
188
+ protocolRole: input?.protocolRole,
189
+ schema: input?.schema ?? `http://${TestDataGenerator.randomString(20)}`,
190
+ tags: input?.tags,
191
+ recordId: input?.recordId,
192
+ parentContextId: input?.parentContextId,
193
+ published: input?.published,
194
+ dataFormat: input?.dataFormat ?? 'application/json',
195
+ dateCreated: input?.dateCreated,
196
+ messageTimestamp: input?.messageTimestamp,
197
+ datePublished: input?.datePublished,
198
+ data: dataBytes,
199
+ dataCid,
200
+ dataSize,
201
+ signer,
202
+ attestationSigners,
203
+ encryptionInput: input?.encryptionInput,
204
+ permissionGrantId: input?.permissionGrantId,
205
+ };
206
+ const recordsWrite = await RecordsWrite.create(options);
207
+ const message = recordsWrite.message;
208
+ return {
209
+ author,
210
+ message,
211
+ dataCid,
212
+ dataSize,
213
+ dataBytes,
214
+ dataStream,
215
+ recordsWrite
216
+ };
241
217
  }
242
218
  ;
243
219
  /**
@@ -253,286 +229,262 @@ export class TestDataGenerator {
253
229
  * @param input.encryptSymmetricKeyWithProtocolContextDerivedKey
254
230
  * Set to `true` to attach the symmetric key encrypted by the protocol context derived public key
255
231
  */
256
- static generateProtocolEncryptedRecordsWrite(input) {
257
- return __awaiter(this, void 0, void 0, function* () {
258
- var _a, _b, _c;
259
- const { plaintextBytes, author, recipient, protocolDefinition, protocolPath, protocolParentContextId, protocolContextDerivingRootKeyId, protocolContextDerivedPublicKeyJwk, } = input;
260
- // encrypt the plaintext data for the target with a randomly generated symmetric key
261
- const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12); // 12 bytes for AES-GCM
262
- const dataEncryptionKey = TestDataGenerator.randomBytes(32);
263
- const { ciphertext: encryptedDataBytes, tag: authenticationTag } = yield Encryption.aeadEncrypt(ContentEncryptionAlgorithm.A256GCM, dataEncryptionKey, dataEncryptionInitializationVector, plaintextBytes);
264
- // author generates a RecordsWrite using the encrypted data
265
- const protocolPathSegments = protocolPath.split('/');
266
- const recordType = protocolPathSegments[protocolPathSegments.length - 1];
267
- const { message, dataStream, recordsWrite } = yield TestDataGenerator.generateRecordsWrite({
268
- author,
269
- recipient,
270
- protocol: protocolDefinition.protocol,
271
- protocolPath,
272
- parentContextId: protocolParentContextId,
273
- schema: protocolDefinition.types[recordType].schema,
274
- dataFormat: (_a = protocolDefinition.types[recordType].dataFormats) === null || _a === void 0 ? void 0 : _a[0],
275
- data: encryptedDataBytes
276
- });
277
- // final encryption input (`keyEncryptionInputs` to be populated below)
278
- const encryptionInput = {
279
- initializationVector: dataEncryptionInitializationVector,
280
- key: dataEncryptionKey,
281
- authenticationTag,
282
- keyEncryptionInputs: []
232
+ static async generateProtocolEncryptedRecordsWrite(input) {
233
+ const { plaintextBytes, author, recipient, protocolDefinition, protocolPath, protocolParentContextId, protocolContextDerivingRootKeyId, protocolContextDerivedPublicKeyJwk, } = input;
234
+ // encrypt the plaintext data for the target with a randomly generated symmetric key
235
+ const dataEncryptionInitializationVector = TestDataGenerator.randomBytes(12); // 12 bytes for AES-GCM
236
+ const dataEncryptionKey = TestDataGenerator.randomBytes(32);
237
+ const { ciphertext: encryptedDataBytes, tag: authenticationTag } = await Encryption.aeadEncrypt(ContentEncryptionAlgorithm.A256GCM, dataEncryptionKey, dataEncryptionInitializationVector, plaintextBytes);
238
+ // author generates a RecordsWrite using the encrypted data
239
+ const protocolPathSegments = protocolPath.split('/');
240
+ const recordType = protocolPathSegments[protocolPathSegments.length - 1];
241
+ const { message, dataStream, recordsWrite } = await TestDataGenerator.generateRecordsWrite({
242
+ author,
243
+ recipient,
244
+ protocol: protocolDefinition.protocol,
245
+ protocolPath,
246
+ parentContextId: protocolParentContextId,
247
+ schema: protocolDefinition.types[recordType].schema,
248
+ dataFormat: protocolDefinition.types[recordType].dataFormats?.[0],
249
+ data: encryptedDataBytes
250
+ });
251
+ // final encryption input (`keyEncryptionInputs` to be populated below)
252
+ const encryptionInput = {
253
+ initializationVector: dataEncryptionInitializationVector,
254
+ key: dataEncryptionKey,
255
+ authenticationTag,
256
+ keyEncryptionInputs: []
257
+ };
258
+ if (input.encryptSymmetricKeyWithProtocolPathDerivedKey) {
259
+ // locate the rule set corresponding the protocol path of the message
260
+ let protocolRuleSetSegment = protocolDefinition.structure;
261
+ for (const pathSegment of protocolPathSegments) {
262
+ protocolRuleSetSegment = protocolRuleSetSegment[pathSegment];
263
+ }
264
+ const protocolPathDerivedPublicKeyJwk = protocolRuleSetSegment.$encryption?.publicKeyJwk;
265
+ const protocolPathDerivationRootKeyId = protocolRuleSetSegment.$encryption?.rootKeyId;
266
+ const protocolPathDerivedKeyEncryptionInput = {
267
+ publicKeyId: protocolPathDerivationRootKeyId,
268
+ publicKey: protocolPathDerivedPublicKeyJwk,
269
+ derivationScheme: KeyDerivationScheme.ProtocolPath
283
270
  };
284
- if (input.encryptSymmetricKeyWithProtocolPathDerivedKey) {
285
- // locate the rule set corresponding the protocol path of the message
286
- let protocolRuleSetSegment = protocolDefinition.structure;
287
- for (const pathSegment of protocolPathSegments) {
288
- protocolRuleSetSegment = protocolRuleSetSegment[pathSegment];
289
- }
290
- const protocolPathDerivedPublicKeyJwk = (_b = protocolRuleSetSegment.$encryption) === null || _b === void 0 ? void 0 : _b.publicKeyJwk;
291
- const protocolPathDerivationRootKeyId = (_c = protocolRuleSetSegment.$encryption) === null || _c === void 0 ? void 0 : _c.rootKeyId;
292
- const protocolPathDerivedKeyEncryptionInput = {
293
- publicKeyId: protocolPathDerivationRootKeyId,
294
- publicKey: protocolPathDerivedPublicKeyJwk,
295
- derivationScheme: KeyDerivationScheme.ProtocolPath
271
+ encryptionInput.keyEncryptionInputs.push(protocolPathDerivedKeyEncryptionInput);
272
+ }
273
+ if (input.encryptSymmetricKeyWithProtocolContextDerivedKey) {
274
+ // generate key encryption input that will encrypt the symmetric encryption key using protocol-context derived public key
275
+ let protocolContextDerivedKeyEncryptionInput;
276
+ if (protocolParentContextId === undefined) {
277
+ // author generates protocol-context derived public key for encrypting symmetric key
278
+ const authorRootPrivateKey = {
279
+ rootKeyId: author.keyId,
280
+ derivationScheme: KeyDerivationScheme.ProtocolContext,
281
+ derivedPrivateKey: author.encryptionKeyPair.privateJwk
282
+ };
283
+ const contextId = await RecordsWrite.getEntryId(author.did, message.descriptor);
284
+ const contextDerivationPath = Records.constructKeyDerivationPathUsingProtocolContextScheme(contextId);
285
+ const authorGeneratedProtocolContextDerivedPublicKeyJwk = await HdKey.derivePublicKey(authorRootPrivateKey, contextDerivationPath);
286
+ protocolContextDerivedKeyEncryptionInput = {
287
+ publicKeyId: author.keyId,
288
+ publicKey: authorGeneratedProtocolContextDerivedPublicKeyJwk,
289
+ derivationScheme: KeyDerivationScheme.ProtocolContext
296
290
  };
297
- encryptionInput.keyEncryptionInputs.push(protocolPathDerivedKeyEncryptionInput);
298
291
  }
299
- if (input.encryptSymmetricKeyWithProtocolContextDerivedKey) {
300
- // generate key encryption input that will encrypt the symmetric encryption key using protocol-context derived public key
301
- let protocolContextDerivedKeyEncryptionInput;
302
- if (protocolParentContextId === undefined) {
303
- // author generates protocol-context derived public key for encrypting symmetric key
304
- const authorRootPrivateKey = {
305
- rootKeyId: author.keyId,
306
- derivationScheme: KeyDerivationScheme.ProtocolContext,
307
- derivedPrivateKey: author.encryptionKeyPair.privateJwk
308
- };
309
- const contextId = yield RecordsWrite.getEntryId(author.did, message.descriptor);
310
- const contextDerivationPath = Records.constructKeyDerivationPathUsingProtocolContextScheme(contextId);
311
- const authorGeneratedProtocolContextDerivedPublicKeyJwk = yield HdKey.derivePublicKey(authorRootPrivateKey, contextDerivationPath);
312
- protocolContextDerivedKeyEncryptionInput = {
313
- publicKeyId: author.keyId,
314
- publicKey: authorGeneratedProtocolContextDerivedPublicKeyJwk,
315
- derivationScheme: KeyDerivationScheme.ProtocolContext
316
- };
292
+ else {
293
+ if (protocolContextDerivingRootKeyId === undefined ||
294
+ protocolContextDerivedPublicKeyJwk === undefined) {
295
+ throw new Error('`protocolContextDerivingRootKeyId` and `protocolContextDerivedPublicKeyJwk` must both be defined if `protocolContextId` is given');
317
296
  }
318
- else {
319
- if (protocolContextDerivingRootKeyId === undefined ||
320
- protocolContextDerivedPublicKeyJwk === undefined) {
321
- throw new Error('`protocolContextDerivingRootKeyId` and `protocolContextDerivedPublicKeyJwk` must both be defined if `protocolContextId` is given');
322
- }
323
- protocolContextDerivedKeyEncryptionInput = {
324
- publicKeyId: protocolContextDerivingRootKeyId,
325
- publicKey: protocolContextDerivedPublicKeyJwk,
326
- derivationScheme: KeyDerivationScheme.ProtocolContext
327
- };
328
- }
329
- encryptionInput.keyEncryptionInputs.push(protocolContextDerivedKeyEncryptionInput);
297
+ protocolContextDerivedKeyEncryptionInput = {
298
+ publicKeyId: protocolContextDerivingRootKeyId,
299
+ publicKey: protocolContextDerivedPublicKeyJwk,
300
+ derivationScheme: KeyDerivationScheme.ProtocolContext
301
+ };
330
302
  }
331
- yield recordsWrite.encryptSymmetricEncryptionKey(encryptionInput);
332
- yield recordsWrite.sign({ signer: Jws.createSigner(author) });
333
- return { message, dataStream: dataStream, recordsWrite, encryptedDataBytes, encryptionInput };
334
- });
303
+ encryptionInput.keyEncryptionInputs.push(protocolContextDerivedKeyEncryptionInput);
304
+ }
305
+ await recordsWrite.encryptSymmetricEncryptionKey(encryptionInput);
306
+ await recordsWrite.sign({ signer: Jws.createSigner(author) });
307
+ return { message, dataStream: dataStream, recordsWrite, encryptedDataBytes, encryptionInput };
335
308
  }
336
309
  /**
337
310
  * Generates a valid RecordsWrite that modifies the given an existing write.
338
311
  * Any mutable property is not specified will be automatically mutated.
339
312
  * e.g. if `published` is not specified, it will be toggled from the state of the given existing write.
340
313
  */
341
- static generateFromRecordsWrite(input) {
342
- return __awaiter(this, void 0, void 0, function* () {
343
- var _a, _b, _c;
344
- const existingMessage = input.existingWrite.message;
345
- const currentTime = Time.getCurrentTimestamp();
346
- const published = ((_a = input.published) !== null && _a !== void 0 ? _a : existingMessage.descriptor.published) ? false : true; // toggle from the parent value if not given explicitly
347
- const datePublished = (_b = input.datePublished) !== null && _b !== void 0 ? _b : (published ? currentTime : undefined);
348
- const dataBytes = (_c = input.data) !== null && _c !== void 0 ? _c : TestDataGenerator.randomBytes(32);
349
- const dataStream = DataStream.fromBytes(dataBytes);
350
- const options = {
351
- recordsWriteMessage: input.existingWrite.message,
352
- data: dataBytes,
353
- published,
354
- datePublished,
355
- messageTimestamp: input.messageTimestamp,
356
- protocolRole: input.protocolRole,
357
- tags: input.tags,
358
- signer: Jws.createSigner(input.author)
359
- };
360
- const recordsWrite = yield RecordsWrite.createFrom(options);
361
- return {
362
- message: recordsWrite.message,
363
- recordsWrite,
364
- dataBytes,
365
- dataStream
366
- };
367
- });
314
+ static async generateFromRecordsWrite(input) {
315
+ const existingMessage = input.existingWrite.message;
316
+ const currentTime = Time.getCurrentTimestamp();
317
+ const published = input.published ?? existingMessage.descriptor.published ? false : true; // toggle from the parent value if not given explicitly
318
+ const datePublished = input.datePublished ?? (published ? currentTime : undefined);
319
+ const dataBytes = input.data ?? TestDataGenerator.randomBytes(32);
320
+ const dataStream = DataStream.fromBytes(dataBytes);
321
+ const options = {
322
+ recordsWriteMessage: input.existingWrite.message,
323
+ data: dataBytes,
324
+ published,
325
+ datePublished,
326
+ messageTimestamp: input.messageTimestamp,
327
+ protocolRole: input.protocolRole,
328
+ tags: input.tags,
329
+ signer: Jws.createSigner(input.author)
330
+ };
331
+ const recordsWrite = await RecordsWrite.createFrom(options);
332
+ return {
333
+ message: recordsWrite.message,
334
+ recordsWrite,
335
+ dataBytes,
336
+ dataStream
337
+ };
368
338
  }
369
339
  /**
370
340
  * Generates a RecordsQuery message for testing.
371
341
  */
372
- static generateRecordsQuery(input) {
373
- return __awaiter(this, void 0, void 0, function* () {
374
- var _a, _b;
375
- let author = input === null || input === void 0 ? void 0 : input.author;
376
- const anonymous = (_a = input === null || input === void 0 ? void 0 : input.anonymous) !== null && _a !== void 0 ? _a : false;
377
- if (anonymous && author) {
378
- throw new Error('Cannot have `author` and be anonymous at the same time.');
379
- }
380
- // generate author if needed
381
- if (author === undefined && !anonymous) {
382
- author = yield TestDataGenerator.generatePersona();
383
- }
384
- let signer = undefined;
385
- if (author !== undefined) {
386
- signer = Jws.createSigner(author);
387
- }
388
- const options = {
389
- messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
390
- signer,
391
- filter: (_b = input === null || input === void 0 ? void 0 : input.filter) !== null && _b !== void 0 ? _b : { schema: TestDataGenerator.randomString(10) }, // must have one filter property if no filter is given
392
- dateSort: input === null || input === void 0 ? void 0 : input.dateSort,
393
- pagination: input === null || input === void 0 ? void 0 : input.pagination,
394
- protocolRole: input === null || input === void 0 ? void 0 : input.protocolRole,
395
- };
396
- removeUndefinedProperties(options);
397
- const recordsQuery = yield RecordsQuery.create(options);
398
- const message = recordsQuery.message;
399
- return {
400
- author,
401
- message
402
- };
403
- });
342
+ static async generateRecordsQuery(input) {
343
+ let author = input?.author;
344
+ const anonymous = input?.anonymous ?? false;
345
+ if (anonymous && author) {
346
+ throw new Error('Cannot have `author` and be anonymous at the same time.');
347
+ }
348
+ // generate author if needed
349
+ if (author === undefined && !anonymous) {
350
+ author = await TestDataGenerator.generatePersona();
351
+ }
352
+ let signer = undefined;
353
+ if (author !== undefined) {
354
+ signer = Jws.createSigner(author);
355
+ }
356
+ const options = {
357
+ messageTimestamp: input?.messageTimestamp,
358
+ signer,
359
+ filter: input?.filter ?? { schema: TestDataGenerator.randomString(10) }, // must have one filter property if no filter is given
360
+ dateSort: input?.dateSort,
361
+ pagination: input?.pagination,
362
+ protocolRole: input?.protocolRole,
363
+ };
364
+ removeUndefinedProperties(options);
365
+ const recordsQuery = await RecordsQuery.create(options);
366
+ const message = recordsQuery.message;
367
+ return {
368
+ author,
369
+ message
370
+ };
404
371
  }
405
372
  ;
406
373
  /**
407
374
  * Generates a RecordsSubscribe message for testing.
408
375
  */
409
- static generateRecordsSubscribe(input) {
410
- return __awaiter(this, void 0, void 0, function* () {
411
- var _a, _b;
412
- let author = input === null || input === void 0 ? void 0 : input.author;
413
- const anonymous = (_a = input === null || input === void 0 ? void 0 : input.anonymous) !== null && _a !== void 0 ? _a : false;
414
- if (anonymous && author) {
415
- throw new Error('Cannot have `author` and be anonymous at the same time.');
416
- }
417
- // generate author if needed
418
- if (author === undefined && !anonymous) {
419
- author = yield TestDataGenerator.generatePersona();
420
- }
421
- let signer = undefined;
422
- if (author !== undefined) {
423
- signer = Jws.createSigner(author);
424
- }
425
- const options = {
426
- messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
427
- signer,
428
- filter: (_b = input === null || input === void 0 ? void 0 : input.filter) !== null && _b !== void 0 ? _b : { schema: TestDataGenerator.randomString(10) }, // must have one filter property if no filter is given
429
- dateSort: input === null || input === void 0 ? void 0 : input.dateSort,
430
- pagination: input === null || input === void 0 ? void 0 : input.pagination,
431
- protocolRole: input === null || input === void 0 ? void 0 : input.protocolRole,
432
- };
433
- removeUndefinedProperties(options);
434
- const recordsSubscribe = yield RecordsSubscribe.create(options);
435
- const message = recordsSubscribe.message;
436
- return {
437
- author,
438
- message
439
- };
440
- });
376
+ static async generateRecordsSubscribe(input) {
377
+ let author = input?.author;
378
+ const anonymous = input?.anonymous ?? false;
379
+ if (anonymous && author) {
380
+ throw new Error('Cannot have `author` and be anonymous at the same time.');
381
+ }
382
+ // generate author if needed
383
+ if (author === undefined && !anonymous) {
384
+ author = await TestDataGenerator.generatePersona();
385
+ }
386
+ let signer = undefined;
387
+ if (author !== undefined) {
388
+ signer = Jws.createSigner(author);
389
+ }
390
+ const options = {
391
+ messageTimestamp: input?.messageTimestamp,
392
+ signer,
393
+ filter: input?.filter ?? { schema: TestDataGenerator.randomString(10) }, // must have one filter property if no filter is given
394
+ dateSort: input?.dateSort,
395
+ pagination: input?.pagination,
396
+ protocolRole: input?.protocolRole,
397
+ };
398
+ removeUndefinedProperties(options);
399
+ const recordsSubscribe = await RecordsSubscribe.create(options);
400
+ const message = recordsSubscribe.message;
401
+ return {
402
+ author,
403
+ message
404
+ };
441
405
  }
442
406
  /**
443
407
  * Generates a RecordsCount message for testing.
444
408
  */
445
- static generateRecordsCount(input) {
446
- return __awaiter(this, void 0, void 0, function* () {
447
- var _a, _b;
448
- let author = input === null || input === void 0 ? void 0 : input.author;
449
- const anonymous = (_a = input === null || input === void 0 ? void 0 : input.anonymous) !== null && _a !== void 0 ? _a : false;
450
- if (anonymous && author) {
451
- throw new Error('Cannot have `author` and be anonymous at the same time.');
452
- }
453
- // generate author if needed
454
- if (author === undefined && !anonymous) {
455
- author = yield TestDataGenerator.generatePersona();
456
- }
457
- let signer = undefined;
458
- if (author !== undefined) {
459
- signer = Jws.createSigner(author);
460
- }
461
- const options = {
462
- messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
463
- signer,
464
- filter: (_b = input === null || input === void 0 ? void 0 : input.filter) !== null && _b !== void 0 ? _b : { schema: TestDataGenerator.randomString(10) },
465
- protocolRole: input === null || input === void 0 ? void 0 : input.protocolRole,
466
- };
467
- removeUndefinedProperties(options);
468
- const recordsCount = yield RecordsCount.create(options);
469
- const message = recordsCount.message;
470
- return {
471
- author,
472
- message
473
- };
474
- });
409
+ static async generateRecordsCount(input) {
410
+ let author = input?.author;
411
+ const anonymous = input?.anonymous ?? false;
412
+ if (anonymous && author) {
413
+ throw new Error('Cannot have `author` and be anonymous at the same time.');
414
+ }
415
+ // generate author if needed
416
+ if (author === undefined && !anonymous) {
417
+ author = await TestDataGenerator.generatePersona();
418
+ }
419
+ let signer = undefined;
420
+ if (author !== undefined) {
421
+ signer = Jws.createSigner(author);
422
+ }
423
+ const options = {
424
+ messageTimestamp: input?.messageTimestamp,
425
+ signer,
426
+ filter: input?.filter ?? { schema: TestDataGenerator.randomString(10) },
427
+ protocolRole: input?.protocolRole,
428
+ };
429
+ removeUndefinedProperties(options);
430
+ const recordsCount = await RecordsCount.create(options);
431
+ const message = recordsCount.message;
432
+ return {
433
+ author,
434
+ message
435
+ };
475
436
  }
476
437
  /**
477
438
  * Generates a RecordsDelete for testing.
478
439
  */
479
- static generateRecordsDelete(input) {
480
- return __awaiter(this, void 0, void 0, function* () {
481
- var _a, _b;
482
- const author = (_a = input === null || input === void 0 ? void 0 : input.author) !== null && _a !== void 0 ? _a : yield TestDataGenerator.generateDidKeyPersona();
483
- const recordsDelete = yield RecordsDelete.create({
484
- recordId: (_b = input === null || input === void 0 ? void 0 : input.recordId) !== null && _b !== void 0 ? _b : yield TestDataGenerator.randomCborSha256Cid(),
485
- protocolRole: input === null || input === void 0 ? void 0 : input.protocolRole,
486
- signer: Jws.createSigner(author)
487
- });
488
- return {
489
- author,
490
- recordsDelete,
491
- message: recordsDelete.message
492
- };
440
+ static async generateRecordsDelete(input) {
441
+ const author = input?.author ?? await TestDataGenerator.generateDidKeyPersona();
442
+ const recordsDelete = await RecordsDelete.create({
443
+ recordId: input?.recordId ?? await TestDataGenerator.randomCborSha256Cid(),
444
+ protocolRole: input?.protocolRole,
445
+ signer: Jws.createSigner(author)
493
446
  });
447
+ return {
448
+ author,
449
+ recordsDelete,
450
+ message: recordsDelete.message
451
+ };
494
452
  }
495
453
  /**
496
454
  * Generates a MessagesSubscribe message for testing.
497
455
  */
498
- static generateMessagesSubscribe(input) {
499
- return __awaiter(this, void 0, void 0, function* () {
500
- var _a;
501
- const author = (_a = input === null || input === void 0 ? void 0 : input.author) !== null && _a !== void 0 ? _a : yield TestDataGenerator.generatePersona();
502
- const signer = Jws.createSigner(author);
503
- const options = {
504
- filters: input === null || input === void 0 ? void 0 : input.filters,
505
- messageTimestamp: input === null || input === void 0 ? void 0 : input.messageTimestamp,
506
- permissionGrantId: input === null || input === void 0 ? void 0 : input.permissionGrantId,
507
- signer,
508
- };
509
- removeUndefinedProperties(options);
510
- const messagesSubscribe = yield MessagesSubscribe.create(options);
511
- const message = messagesSubscribe.message;
512
- return {
513
- author,
514
- messagesSubscribe,
515
- message
516
- };
517
- });
456
+ static async generateMessagesSubscribe(input) {
457
+ const author = input?.author ?? await TestDataGenerator.generatePersona();
458
+ const signer = Jws.createSigner(author);
459
+ const options = {
460
+ filters: input?.filters,
461
+ messageTimestamp: input?.messageTimestamp,
462
+ permissionGrantId: input?.permissionGrantId,
463
+ signer,
464
+ };
465
+ removeUndefinedProperties(options);
466
+ const messagesSubscribe = await MessagesSubscribe.create(options);
467
+ const message = messagesSubscribe.message;
468
+ return {
469
+ author,
470
+ messagesSubscribe,
471
+ message
472
+ };
518
473
  }
519
- static generateMessagesRead(input) {
520
- return __awaiter(this, void 0, void 0, function* () {
521
- var _a;
522
- const author = (_a = input === null || input === void 0 ? void 0 : input.author) !== null && _a !== void 0 ? _a : yield TestDataGenerator.generatePersona();
523
- const signer = Jws.createSigner(author);
524
- const options = {
525
- signer,
526
- messageCid: input.messageCid,
527
- permissionGrantId: input.permissionGrantId
528
- };
529
- const messagesRead = yield MessagesRead.create(options);
530
- return {
531
- author,
532
- messagesRead,
533
- message: messagesRead.message,
534
- };
535
- });
474
+ static async generateMessagesRead(input) {
475
+ const author = input?.author ?? await TestDataGenerator.generatePersona();
476
+ const signer = Jws.createSigner(author);
477
+ const options = {
478
+ signer,
479
+ messageCid: input.messageCid,
480
+ permissionGrantId: input.permissionGrantId
481
+ };
482
+ const messagesRead = await MessagesRead.create(options);
483
+ return {
484
+ author,
485
+ messagesRead,
486
+ message: messagesRead.message,
487
+ };
536
488
  }
537
489
  /**
538
490
  * Generates a dummy `authorization` property for a DWN message that only conforms to schema validation.
@@ -557,13 +509,11 @@ export class TestDataGenerator {
557
509
  /**
558
510
  * Generates a random but well-formed signature string in Base64Url format.
559
511
  */
560
- static randomSignatureString() {
561
- return __awaiter(this, void 0, void 0, function* () {
562
- const keyPair = yield ed25519.generateKeyPair();
563
- const signatureBytes = yield ed25519.sign(TestDataGenerator.randomBytes(32), keyPair.privateJwk);
564
- const signatureString = Encoder.bytesToBase64Url(signatureBytes);
565
- return signatureString;
566
- });
512
+ static async randomSignatureString() {
513
+ const keyPair = await ed25519.generateKeyPair();
514
+ const signatureBytes = await ed25519.sign(TestDataGenerator.randomBytes(32), keyPair.privateJwk);
515
+ const signatureString = Encoder.bytesToBase64Url(signatureBytes);
516
+ return signatureString;
567
517
  }
568
518
  /**
569
519
  * Generates a random alpha-numeric string.
@@ -592,13 +542,11 @@ export class TestDataGenerator {
592
542
  /**
593
543
  * Generates a random CBOR SHA256 CID.
594
544
  */
595
- static randomCborSha256Cid() {
596
- return __awaiter(this, void 0, void 0, function* () {
597
- const randomBytes = TestDataGenerator.randomBytes(32);
598
- const randomMultihash = yield sha256.digest(randomBytes);
599
- const cid = yield CID.createV1(cbor.code, randomMultihash);
600
- return cid.toString();
601
- });
545
+ static async randomCborSha256Cid() {
546
+ const randomBytes = TestDataGenerator.randomBytes(32);
547
+ const randomMultihash = await sha256.digest(randomBytes);
548
+ const cid = await CID.createV1(cbor.code, randomMultihash);
549
+ return cid.toString();
602
550
  }
603
551
  /**
604
552
  * Generates a random within a range (inclusive).
@@ -648,36 +596,34 @@ export class TestDataGenerator {
648
596
  /**
649
597
  * Generates a did:key persona.
650
598
  */
651
- static generateDidKeyPersona() {
652
- return __awaiter(this, void 0, void 0, function* () {
653
- const did = yield DidKey.create();
654
- const signingMethod = yield DidKey.getSigningMethod({ didDocument: did.document });
655
- const keyId = signingMethod.id;
656
- const portableDid = yield did.export();
657
- const keyPair = {
658
- // TODO: #672 - port and use type from @enbox/crypto - https://github.com/enboxorg/enbox/issues/672
659
- publicJwk: signingMethod.publicKeyJwk,
660
- privateJwk: portableDid.privateKeys[0],
661
- };
662
- // Generate X25519 encryption key pair for did:key personas
663
- const encPrivateKey = yield X25519.generateKey();
664
- const encPublicKey = yield X25519.getPublicKey({ key: encPrivateKey });
665
- const encryptionKeyPair = {
666
- publicJwk: encPublicKey,
667
- privateJwk: encPrivateKey,
668
- };
669
- return {
670
- did: did.uri,
671
- keyId,
672
- keyPair,
673
- encryptionKeyPair,
674
- signer: new PrivateKeySigner({
675
- privateJwk: keyPair.privateJwk,
676
- algorithm: keyPair.privateJwk.alg,
677
- keyId
678
- })
679
- };
680
- });
599
+ static async generateDidKeyPersona() {
600
+ const did = await DidKey.create();
601
+ const signingMethod = await DidKey.getSigningMethod({ didDocument: did.document });
602
+ const keyId = signingMethod.id;
603
+ const portableDid = await did.export();
604
+ const keyPair = {
605
+ // TODO: #672 - port and use type from @enbox/crypto - https://github.com/enboxorg/enbox/issues/672
606
+ publicJwk: signingMethod.publicKeyJwk,
607
+ privateJwk: portableDid.privateKeys[0],
608
+ };
609
+ // Generate X25519 encryption key pair for did:key personas
610
+ const encPrivateKey = await X25519.generateKey();
611
+ const encPublicKey = await X25519.getPublicKey({ key: encPrivateKey });
612
+ const encryptionKeyPair = {
613
+ publicJwk: encPublicKey,
614
+ privateJwk: encPrivateKey,
615
+ };
616
+ return {
617
+ did: did.uri,
618
+ keyId,
619
+ keyPair,
620
+ encryptionKeyPair,
621
+ signer: new PrivateKeySigner({
622
+ privateJwk: keyPair.privateJwk,
623
+ algorithm: keyPair.privateJwk.alg,
624
+ keyId
625
+ })
626
+ };
681
627
  }
682
628
  }
683
629
  //# sourceMappingURL=test-data-generator.js.map