@enbox/dwn-sdk-js 0.0.1

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 (810) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +352 -0
  3. package/dist/bundles/dwn.js +153 -0
  4. package/dist/cjs/index.js +36749 -0
  5. package/dist/cjs/package.json +1 -0
  6. package/dist/esm/generated/precompiled-validators.js +11973 -0
  7. package/dist/esm/generated/precompiled-validators.js.map +1 -0
  8. package/dist/esm/json-schemas/definitions.json +23 -0
  9. package/dist/esm/src/core/abstract-message.js +47 -0
  10. package/dist/esm/src/core/abstract-message.js.map +1 -0
  11. package/dist/esm/src/core/auth.js +39 -0
  12. package/dist/esm/src/core/auth.js.map +1 -0
  13. package/dist/esm/src/core/dwn-constant.js +10 -0
  14. package/dist/esm/src/core/dwn-constant.js.map +1 -0
  15. package/dist/esm/src/core/dwn-error.js +169 -0
  16. package/dist/esm/src/core/dwn-error.js.map +1 -0
  17. package/dist/esm/src/core/grant-authorization.js +97 -0
  18. package/dist/esm/src/core/grant-authorization.js.map +1 -0
  19. package/dist/esm/src/core/message-reply.js +5 -0
  20. package/dist/esm/src/core/message-reply.js.map +1 -0
  21. package/dist/esm/src/core/message.js +233 -0
  22. package/dist/esm/src/core/message.js.map +1 -0
  23. package/dist/esm/src/core/messages-grant-authorization.js +101 -0
  24. package/dist/esm/src/core/messages-grant-authorization.js.map +1 -0
  25. package/dist/esm/src/core/protocol-authorization.js +608 -0
  26. package/dist/esm/src/core/protocol-authorization.js.map +1 -0
  27. package/dist/esm/src/core/protocols-grant-authorization.js +66 -0
  28. package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -0
  29. package/dist/esm/src/core/records-grant-authorization.js +132 -0
  30. package/dist/esm/src/core/records-grant-authorization.js.map +1 -0
  31. package/dist/esm/src/core/resumable-task-manager.js +109 -0
  32. package/dist/esm/src/core/resumable-task-manager.js.map +1 -0
  33. package/dist/esm/src/core/tenant-gate.js +20 -0
  34. package/dist/esm/src/core/tenant-gate.js.map +1 -0
  35. package/dist/esm/src/dwn.js +164 -0
  36. package/dist/esm/src/dwn.js.map +1 -0
  37. package/dist/esm/src/enums/dwn-interface-method.js +16 -0
  38. package/dist/esm/src/enums/dwn-interface-method.js.map +1 -0
  39. package/dist/esm/src/event-log/event-emitter-stream.js +60 -0
  40. package/dist/esm/src/event-log/event-emitter-stream.js.map +1 -0
  41. package/dist/esm/src/event-log/event-log-level.js +63 -0
  42. package/dist/esm/src/event-log/event-log-level.js.map +1 -0
  43. package/dist/esm/src/handlers/messages-query.js +71 -0
  44. package/dist/esm/src/handlers/messages-query.js.map +1 -0
  45. package/dist/esm/src/handlers/messages-read.js +102 -0
  46. package/dist/esm/src/handlers/messages-read.js.map +1 -0
  47. package/dist/esm/src/handlers/messages-subscribe.js +81 -0
  48. package/dist/esm/src/handlers/messages-subscribe.js.map +1 -0
  49. package/dist/esm/src/handlers/protocols-configure.js +133 -0
  50. package/dist/esm/src/handlers/protocols-configure.js.map +1 -0
  51. package/dist/esm/src/handlers/protocols-query.js +73 -0
  52. package/dist/esm/src/handlers/protocols-query.js.map +1 -0
  53. package/dist/esm/src/handlers/records-delete.js +107 -0
  54. package/dist/esm/src/handlers/records-delete.js.map +1 -0
  55. package/dist/esm/src/handlers/records-query.js +210 -0
  56. package/dist/esm/src/handlers/records-query.js.map +1 -0
  57. package/dist/esm/src/handlers/records-read.js +169 -0
  58. package/dist/esm/src/handlers/records-read.js.map +1 -0
  59. package/dist/esm/src/handlers/records-subscribe.js +172 -0
  60. package/dist/esm/src/handlers/records-subscribe.js.map +1 -0
  61. package/dist/esm/src/handlers/records-write.js +344 -0
  62. package/dist/esm/src/handlers/records-write.js.map +1 -0
  63. package/dist/esm/src/index.js +49 -0
  64. package/dist/esm/src/index.js.map +1 -0
  65. package/dist/esm/src/interfaces/messages-query.js +53 -0
  66. package/dist/esm/src/interfaces/messages-query.js.map +1 -0
  67. package/dist/esm/src/interfaces/messages-read.js +61 -0
  68. package/dist/esm/src/interfaces/messages-read.js.map +1 -0
  69. package/dist/esm/src/interfaces/messages-subscribe.js +58 -0
  70. package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -0
  71. package/dist/esm/src/interfaces/protocols-configure.js +271 -0
  72. package/dist/esm/src/interfaces/protocols-configure.js.map +1 -0
  73. package/dist/esm/src/interfaces/protocols-query.js +84 -0
  74. package/dist/esm/src/interfaces/protocols-query.js.map +1 -0
  75. package/dist/esm/src/interfaces/records-delete.js +89 -0
  76. package/dist/esm/src/interfaces/records-delete.js.map +1 -0
  77. package/dist/esm/src/interfaces/records-query.js +104 -0
  78. package/dist/esm/src/interfaces/records-query.js.map +1 -0
  79. package/dist/esm/src/interfaces/records-read.js +84 -0
  80. package/dist/esm/src/interfaces/records-read.js.map +1 -0
  81. package/dist/esm/src/interfaces/records-subscribe.js +91 -0
  82. package/dist/esm/src/interfaces/records-subscribe.js.map +1 -0
  83. package/dist/esm/src/interfaces/records-write.js +795 -0
  84. package/dist/esm/src/interfaces/records-write.js.map +1 -0
  85. package/dist/esm/src/jose/algorithms/signing/ed25519.js +51 -0
  86. package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -0
  87. package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js +20 -0
  88. package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js.map +1 -0
  89. package/dist/esm/src/jose/jws/general/builder.js +47 -0
  90. package/dist/esm/src/jose/jws/general/builder.js.map +1 -0
  91. package/dist/esm/src/jose/jws/general/verifier.js +97 -0
  92. package/dist/esm/src/jose/jws/general/verifier.js.map +1 -0
  93. package/dist/esm/src/protocols/permission-grant.js +39 -0
  94. package/dist/esm/src/protocols/permission-grant.js.map +1 -0
  95. package/dist/esm/src/protocols/permission-request.js +35 -0
  96. package/dist/esm/src/protocols/permission-request.js.map +1 -0
  97. package/dist/esm/src/protocols/permissions.js +357 -0
  98. package/dist/esm/src/protocols/permissions.js.map +1 -0
  99. package/dist/esm/src/schema-validator.js +37 -0
  100. package/dist/esm/src/schema-validator.js.map +1 -0
  101. package/dist/esm/src/store/blockstore-level.js +187 -0
  102. package/dist/esm/src/store/blockstore-level.js.map +1 -0
  103. package/dist/esm/src/store/blockstore-mock.js +168 -0
  104. package/dist/esm/src/store/blockstore-mock.js.map +1 -0
  105. package/dist/esm/src/store/data-store-level.js +136 -0
  106. package/dist/esm/src/store/data-store-level.js.map +1 -0
  107. package/dist/esm/src/store/index-level.js +660 -0
  108. package/dist/esm/src/store/index-level.js.map +1 -0
  109. package/dist/esm/src/store/level-wrapper.js +305 -0
  110. package/dist/esm/src/store/level-wrapper.js.map +1 -0
  111. package/dist/esm/src/store/message-store-level.js +159 -0
  112. package/dist/esm/src/store/message-store-level.js.map +1 -0
  113. package/dist/esm/src/store/resumable-task-store-level.js +131 -0
  114. package/dist/esm/src/store/resumable-task-store-level.js.map +1 -0
  115. package/dist/esm/src/store/storage-controller.js +184 -0
  116. package/dist/esm/src/store/storage-controller.js.map +1 -0
  117. package/dist/esm/src/types/cache.js +2 -0
  118. package/dist/esm/src/types/cache.js.map +1 -0
  119. package/dist/esm/src/types/data-store.js +2 -0
  120. package/dist/esm/src/types/data-store.js.map +1 -0
  121. package/dist/esm/src/types/event-log.js +2 -0
  122. package/dist/esm/src/types/event-log.js.map +1 -0
  123. package/dist/esm/src/types/jose-types.js +2 -0
  124. package/dist/esm/src/types/jose-types.js.map +1 -0
  125. package/dist/esm/src/types/jws-types.js +2 -0
  126. package/dist/esm/src/types/jws-types.js.map +1 -0
  127. package/dist/esm/src/types/message-interface.js +2 -0
  128. package/dist/esm/src/types/message-interface.js.map +1 -0
  129. package/dist/esm/src/types/message-store.js +2 -0
  130. package/dist/esm/src/types/message-store.js.map +1 -0
  131. package/dist/esm/src/types/message-types.js +3 -0
  132. package/dist/esm/src/types/message-types.js.map +1 -0
  133. package/dist/esm/src/types/messages-types.js +2 -0
  134. package/dist/esm/src/types/messages-types.js.map +1 -0
  135. package/dist/esm/src/types/method-handler.js +2 -0
  136. package/dist/esm/src/types/method-handler.js.map +1 -0
  137. package/dist/esm/src/types/permission-types.js +6 -0
  138. package/dist/esm/src/types/permission-types.js.map +1 -0
  139. package/dist/esm/src/types/protocols-types.js +20 -0
  140. package/dist/esm/src/types/protocols-types.js.map +1 -0
  141. package/dist/esm/src/types/query-types.js +6 -0
  142. package/dist/esm/src/types/query-types.js.map +1 -0
  143. package/dist/esm/src/types/records-types.js +8 -0
  144. package/dist/esm/src/types/records-types.js.map +1 -0
  145. package/dist/esm/src/types/resumable-task-store.js +2 -0
  146. package/dist/esm/src/types/resumable-task-store.js.map +1 -0
  147. package/dist/esm/src/types/signer.js +2 -0
  148. package/dist/esm/src/types/signer.js.map +1 -0
  149. package/dist/esm/src/types/subscriptions.js +2 -0
  150. package/dist/esm/src/types/subscriptions.js.map +1 -0
  151. package/dist/esm/src/utils/abort.js +40 -0
  152. package/dist/esm/src/utils/abort.js.map +1 -0
  153. package/dist/esm/src/utils/array.js +72 -0
  154. package/dist/esm/src/utils/array.js.map +1 -0
  155. package/dist/esm/src/utils/cid.js +130 -0
  156. package/dist/esm/src/utils/cid.js.map +1 -0
  157. package/dist/esm/src/utils/data-stream.js +100 -0
  158. package/dist/esm/src/utils/data-stream.js.map +1 -0
  159. package/dist/esm/src/utils/encoder.js +45 -0
  160. package/dist/esm/src/utils/encoder.js.map +1 -0
  161. package/dist/esm/src/utils/encryption.js +128 -0
  162. package/dist/esm/src/utils/encryption.js.map +1 -0
  163. package/dist/esm/src/utils/filter.js +229 -0
  164. package/dist/esm/src/utils/filter.js.map +1 -0
  165. package/dist/esm/src/utils/hd-key.js +114 -0
  166. package/dist/esm/src/utils/hd-key.js.map +1 -0
  167. package/dist/esm/src/utils/jws.js +89 -0
  168. package/dist/esm/src/utils/jws.js.map +1 -0
  169. package/dist/esm/src/utils/memory-cache.js +41 -0
  170. package/dist/esm/src/utils/memory-cache.js.map +1 -0
  171. package/dist/esm/src/utils/messages.js +84 -0
  172. package/dist/esm/src/utils/messages.js.map +1 -0
  173. package/dist/esm/src/utils/object.js +40 -0
  174. package/dist/esm/src/utils/object.js.map +1 -0
  175. package/dist/esm/src/utils/private-key-signer.js +43 -0
  176. package/dist/esm/src/utils/private-key-signer.js.map +1 -0
  177. package/dist/esm/src/utils/protocols.js +51 -0
  178. package/dist/esm/src/utils/protocols.js.map +1 -0
  179. package/dist/esm/src/utils/records.js +454 -0
  180. package/dist/esm/src/utils/records.js.map +1 -0
  181. package/dist/esm/src/utils/secp256k1.js +166 -0
  182. package/dist/esm/src/utils/secp256k1.js.map +1 -0
  183. package/dist/esm/src/utils/secp256r1.js +120 -0
  184. package/dist/esm/src/utils/secp256r1.js.map +1 -0
  185. package/dist/esm/src/utils/string.js +16 -0
  186. package/dist/esm/src/utils/string.js.map +1 -0
  187. package/dist/esm/src/utils/time.js +85 -0
  188. package/dist/esm/src/utils/time.js.map +1 -0
  189. package/dist/esm/src/utils/url.js +62 -0
  190. package/dist/esm/src/utils/url.js.map +1 -0
  191. package/dist/esm/tests/core/auth.spec.js +22 -0
  192. package/dist/esm/tests/core/auth.spec.js.map +1 -0
  193. package/dist/esm/tests/core/message-reply.spec.js +16 -0
  194. package/dist/esm/tests/core/message-reply.spec.js.map +1 -0
  195. package/dist/esm/tests/core/message.spec.js +146 -0
  196. package/dist/esm/tests/core/message.spec.js.map +1 -0
  197. package/dist/esm/tests/core/protocol-authorization.spec.js +48 -0
  198. package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -0
  199. package/dist/esm/tests/dwn.spec.js +166 -0
  200. package/dist/esm/tests/dwn.spec.js.map +1 -0
  201. package/dist/esm/tests/event-log/event-emitter-stream.spec.js +78 -0
  202. package/dist/esm/tests/event-log/event-emitter-stream.spec.js.map +1 -0
  203. package/dist/esm/tests/event-log/event-log-level.spec.js +44 -0
  204. package/dist/esm/tests/event-log/event-log-level.spec.js.map +1 -0
  205. package/dist/esm/tests/event-log/event-log.spec.js +236 -0
  206. package/dist/esm/tests/event-log/event-log.spec.js.map +1 -0
  207. package/dist/esm/tests/event-log/event-stream.spec.js +125 -0
  208. package/dist/esm/tests/event-log/event-stream.spec.js.map +1 -0
  209. package/dist/esm/tests/features/author-delegated-grant.spec.js +1273 -0
  210. package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -0
  211. package/dist/esm/tests/features/owner-delegated-grant.spec.js +584 -0
  212. package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -0
  213. package/dist/esm/tests/features/owner-signature.spec.js +192 -0
  214. package/dist/esm/tests/features/owner-signature.spec.js.map +1 -0
  215. package/dist/esm/tests/features/permissions.spec.js +815 -0
  216. package/dist/esm/tests/features/permissions.spec.js.map +1 -0
  217. package/dist/esm/tests/features/protocol-create-action.spec.js +248 -0
  218. package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -0
  219. package/dist/esm/tests/features/protocol-delete-action.spec.js +492 -0
  220. package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -0
  221. package/dist/esm/tests/features/protocol-update-action.spec.js +572 -0
  222. package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -0
  223. package/dist/esm/tests/features/records-prune.spec.js +812 -0
  224. package/dist/esm/tests/features/records-prune.spec.js.map +1 -0
  225. package/dist/esm/tests/features/records-tags.spec.js +2516 -0
  226. package/dist/esm/tests/features/records-tags.spec.js.map +1 -0
  227. package/dist/esm/tests/features/resumable-tasks.spec.js +349 -0
  228. package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -0
  229. package/dist/esm/tests/handlers/messages-query.spec.js +349 -0
  230. package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -0
  231. package/dist/esm/tests/handlers/messages-read.spec.js +647 -0
  232. package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -0
  233. package/dist/esm/tests/handlers/messages-subscribe.spec.js +432 -0
  234. package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -0
  235. package/dist/esm/tests/handlers/protocols-configure.spec.js +608 -0
  236. package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -0
  237. package/dist/esm/tests/handlers/protocols-query.spec.js +454 -0
  238. package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -0
  239. package/dist/esm/tests/handlers/records-delete.spec.js +662 -0
  240. package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -0
  241. package/dist/esm/tests/handlers/records-query.spec.js +2695 -0
  242. package/dist/esm/tests/handlers/records-query.spec.js.map +1 -0
  243. package/dist/esm/tests/handlers/records-read.spec.js +1724 -0
  244. package/dist/esm/tests/handlers/records-read.spec.js.map +1 -0
  245. package/dist/esm/tests/handlers/records-subscribe.spec.js +684 -0
  246. package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -0
  247. package/dist/esm/tests/handlers/records-write.spec.js +3637 -0
  248. package/dist/esm/tests/handlers/records-write.spec.js.map +1 -0
  249. package/dist/esm/tests/interfaces/messages-get.spec.js +78 -0
  250. package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -0
  251. package/dist/esm/tests/interfaces/messages-subscribe.spec.js +30 -0
  252. package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -0
  253. package/dist/esm/tests/interfaces/messagess-query.spec.js +127 -0
  254. package/dist/esm/tests/interfaces/messagess-query.spec.js.map +1 -0
  255. package/dist/esm/tests/interfaces/protocols-configure.spec.js +489 -0
  256. package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -0
  257. package/dist/esm/tests/interfaces/protocols-query.spec.js +46 -0
  258. package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -0
  259. package/dist/esm/tests/interfaces/records-delete.spec.js +39 -0
  260. package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -0
  261. package/dist/esm/tests/interfaces/records-query.spec.js +85 -0
  262. package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -0
  263. package/dist/esm/tests/interfaces/records-read.spec.js +62 -0
  264. package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -0
  265. package/dist/esm/tests/interfaces/records-subscribe.spec.js +72 -0
  266. package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -0
  267. package/dist/esm/tests/interfaces/records-write.spec.js +423 -0
  268. package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -0
  269. package/dist/esm/tests/jose/jws/general.spec.js +243 -0
  270. package/dist/esm/tests/jose/jws/general.spec.js.map +1 -0
  271. package/dist/esm/tests/protocols/permission-request.spec.js +40 -0
  272. package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -0
  273. package/dist/esm/tests/protocols/permissions.spec.js +123 -0
  274. package/dist/esm/tests/protocols/permissions.spec.js.map +1 -0
  275. package/dist/esm/tests/scenarios/aggregator.spec.js +670 -0
  276. package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -0
  277. package/dist/esm/tests/scenarios/deleted-record.spec.js +102 -0
  278. package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -0
  279. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +220 -0
  280. package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -0
  281. package/dist/esm/tests/scenarios/messages-query.spec.js +395 -0
  282. package/dist/esm/tests/scenarios/messages-query.spec.js.map +1 -0
  283. package/dist/esm/tests/scenarios/nested-roles.spec.js +300 -0
  284. package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -0
  285. package/dist/esm/tests/scenarios/subscriptions.spec.js +886 -0
  286. package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -0
  287. package/dist/esm/tests/store/blockstore-mock.spec.js +192 -0
  288. package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -0
  289. package/dist/esm/tests/store/data-store-level.spec.js +146 -0
  290. package/dist/esm/tests/store/data-store-level.spec.js.map +1 -0
  291. package/dist/esm/tests/store/index-level.spec.js +1208 -0
  292. package/dist/esm/tests/store/index-level.spec.js.map +1 -0
  293. package/dist/esm/tests/store/message-store-level.spec.js +48 -0
  294. package/dist/esm/tests/store/message-store-level.spec.js.map +1 -0
  295. package/dist/esm/tests/store/message-store.spec.js +404 -0
  296. package/dist/esm/tests/store/message-store.spec.js.map +1 -0
  297. package/dist/esm/tests/store-dependent-tests.spec.js +5 -0
  298. package/dist/esm/tests/store-dependent-tests.spec.js.map +1 -0
  299. package/dist/esm/tests/test-event-stream.js +25 -0
  300. package/dist/esm/tests/test-event-stream.js.map +1 -0
  301. package/dist/esm/tests/test-stores.js +45 -0
  302. package/dist/esm/tests/test-stores.js.map +1 -0
  303. package/dist/esm/tests/test-suite.js +88 -0
  304. package/dist/esm/tests/test-suite.js.map +1 -0
  305. package/dist/esm/tests/utils/cid.spec.js +80 -0
  306. package/dist/esm/tests/utils/cid.spec.js.map +1 -0
  307. package/dist/esm/tests/utils/data-stream.spec.js +27 -0
  308. package/dist/esm/tests/utils/data-stream.spec.js.map +1 -0
  309. package/dist/esm/tests/utils/encryption.spec.js +148 -0
  310. package/dist/esm/tests/utils/encryption.spec.js.map +1 -0
  311. package/dist/esm/tests/utils/filters.spec.js +295 -0
  312. package/dist/esm/tests/utils/filters.spec.js.map +1 -0
  313. package/dist/esm/tests/utils/hd-key.spec.js +35 -0
  314. package/dist/esm/tests/utils/hd-key.spec.js.map +1 -0
  315. package/dist/esm/tests/utils/jws.spec.js +8 -0
  316. package/dist/esm/tests/utils/jws.spec.js.map +1 -0
  317. package/dist/esm/tests/utils/memory-cache.spec.js +35 -0
  318. package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -0
  319. package/dist/esm/tests/utils/messages.spec.js +101 -0
  320. package/dist/esm/tests/utils/messages.spec.js.map +1 -0
  321. package/dist/esm/tests/utils/object.spec.js +36 -0
  322. package/dist/esm/tests/utils/object.spec.js.map +1 -0
  323. package/dist/esm/tests/utils/poller.js +49 -0
  324. package/dist/esm/tests/utils/poller.js.map +1 -0
  325. package/dist/esm/tests/utils/private-key-signer.spec.js +44 -0
  326. package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -0
  327. package/dist/esm/tests/utils/records.spec.js +53 -0
  328. package/dist/esm/tests/utils/records.spec.js.map +1 -0
  329. package/dist/esm/tests/utils/secp256k1.spec.js +50 -0
  330. package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -0
  331. package/dist/esm/tests/utils/secp256r1.spec.js +56 -0
  332. package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -0
  333. package/dist/esm/tests/utils/test-data-generator.js +643 -0
  334. package/dist/esm/tests/utils/test-data-generator.js.map +1 -0
  335. package/dist/esm/tests/utils/test-stub-generator.js +39 -0
  336. package/dist/esm/tests/utils/test-stub-generator.js.map +1 -0
  337. package/dist/esm/tests/utils/time.spec.js +64 -0
  338. package/dist/esm/tests/utils/time.spec.js.map +1 -0
  339. package/dist/esm/tests/utils/url.spec.js +43 -0
  340. package/dist/esm/tests/utils/url.spec.js.map +1 -0
  341. package/dist/esm/tests/validation/json-schemas/definitions.spec.js +33 -0
  342. package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -0
  343. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +50 -0
  344. package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -0
  345. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +36 -0
  346. package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -0
  347. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +82 -0
  348. package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -0
  349. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +75 -0
  350. package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -0
  351. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +148 -0
  352. package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -0
  353. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +421 -0
  354. package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -0
  355. package/dist/esm/tests/vectors/protocol-definitions/anyone-collaborate.json +21 -0
  356. package/dist/esm/tests/vectors/protocol-definitions/author-can.json +33 -0
  357. package/dist/esm/tests/vectors/protocol-definitions/chat.json +70 -0
  358. package/dist/esm/tests/vectors/protocol-definitions/credential-issuance.json +41 -0
  359. package/dist/esm/tests/vectors/protocol-definitions/dex.json +58 -0
  360. package/dist/esm/tests/vectors/protocol-definitions/email.json +62 -0
  361. package/dist/esm/tests/vectors/protocol-definitions/free-for-all.json +45 -0
  362. package/dist/esm/tests/vectors/protocol-definitions/friend-role.json +48 -0
  363. package/dist/esm/tests/vectors/protocol-definitions/message.json +37 -0
  364. package/dist/esm/tests/vectors/protocol-definitions/minimal.json +10 -0
  365. package/dist/esm/tests/vectors/protocol-definitions/nested.json +31 -0
  366. package/dist/esm/tests/vectors/protocol-definitions/private-protocol.json +15 -0
  367. package/dist/esm/tests/vectors/protocol-definitions/recipient-can.json +33 -0
  368. package/dist/esm/tests/vectors/protocol-definitions/slack.json +242 -0
  369. package/dist/esm/tests/vectors/protocol-definitions/social-media.json +106 -0
  370. package/dist/esm/tests/vectors/protocol-definitions/thread-role.json +70 -0
  371. package/dist/types/generated/precompiled-validators.d.ts +597 -0
  372. package/dist/types/generated/precompiled-validators.d.ts.map +1 -0
  373. package/dist/types/src/core/abstract-message.d.ts +25 -0
  374. package/dist/types/src/core/abstract-message.d.ts.map +1 -0
  375. package/dist/types/src/core/auth.d.ts +9 -0
  376. package/dist/types/src/core/auth.d.ts.map +1 -0
  377. package/dist/types/src/core/dwn-constant.d.ts +10 -0
  378. package/dist/types/src/core/dwn-constant.d.ts.map +1 -0
  379. package/dist/types/src/core/dwn-error.d.ts +164 -0
  380. package/dist/types/src/core/dwn-error.d.ts.map +1 -0
  381. package/dist/types/src/core/grant-authorization.d.ts +43 -0
  382. package/dist/types/src/core/grant-authorization.d.ts.map +1 -0
  383. package/dist/types/src/core/message-reply.d.ts +32 -0
  384. package/dist/types/src/core/message-reply.d.ts.map +1 -0
  385. package/dist/types/src/core/message.d.ts +94 -0
  386. package/dist/types/src/core/message.d.ts.map +1 -0
  387. package/dist/types/src/core/messages-grant-authorization.d.ts +34 -0
  388. package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -0
  389. package/dist/types/src/core/protocol-authorization.d.ts +103 -0
  390. package/dist/types/src/core/protocol-authorization.d.ts.map +1 -0
  391. package/dist/types/src/core/protocols-grant-authorization.d.ts +31 -0
  392. package/dist/types/src/core/protocols-grant-authorization.d.ts.map +1 -0
  393. package/dist/types/src/core/records-grant-authorization.d.ts +60 -0
  394. package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -0
  395. package/dist/types/src/core/resumable-task-manager.d.ts +43 -0
  396. package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -0
  397. package/dist/types/src/core/tenant-gate.d.ts +29 -0
  398. package/dist/types/src/core/tenant-gate.d.ts.map +1 -0
  399. package/dist/types/src/dwn.d.ts +85 -0
  400. package/dist/types/src/dwn.d.ts.map +1 -0
  401. package/dist/types/src/enums/dwn-interface-method.d.ts +14 -0
  402. package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -0
  403. package/dist/types/src/event-log/event-emitter-stream.d.ts +23 -0
  404. package/dist/types/src/event-log/event-emitter-stream.d.ts.map +1 -0
  405. package/dist/types/src/event-log/event-log-level.d.ts +35 -0
  406. package/dist/types/src/event-log/event-log-level.d.ts.map +1 -0
  407. package/dist/types/src/handlers/messages-query.d.ts +17 -0
  408. package/dist/types/src/handlers/messages-query.d.ts.map +1 -0
  409. package/dist/types/src/handlers/messages-read.d.ts +22 -0
  410. package/dist/types/src/handlers/messages-read.d.ts.map +1 -0
  411. package/dist/types/src/handlers/messages-subscribe.d.ts +18 -0
  412. package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -0
  413. package/dist/types/src/handlers/protocols-configure.d.ts +24 -0
  414. package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -0
  415. package/dist/types/src/handlers/protocols-query.d.ts +20 -0
  416. package/dist/types/src/handlers/protocols-query.d.ts.map +1 -0
  417. package/dist/types/src/handlers/records-delete.d.ts +23 -0
  418. package/dist/types/src/handlers/records-delete.d.ts.map +1 -0
  419. package/dist/types/src/handlers/records-query.d.ts +70 -0
  420. package/dist/types/src/handlers/records-query.d.ts.map +1 -0
  421. package/dist/types/src/handlers/records-read.d.ts +20 -0
  422. package/dist/types/src/handlers/records-read.d.ts.map +1 -0
  423. package/dist/types/src/handlers/records-subscribe.d.ts +62 -0
  424. package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -0
  425. package/dist/types/src/handlers/records-write.d.ts +51 -0
  426. package/dist/types/src/handlers/records-write.d.ts.map +1 -0
  427. package/dist/types/src/index.d.ts +63 -0
  428. package/dist/types/src/index.d.ts.map +1 -0
  429. package/dist/types/src/interfaces/messages-query.d.ts +16 -0
  430. package/dist/types/src/interfaces/messages-query.d.ts.map +1 -0
  431. package/dist/types/src/interfaces/messages-read.d.ts +20 -0
  432. package/dist/types/src/interfaces/messages-read.d.ts.map +1 -0
  433. package/dist/types/src/interfaces/messages-subscribe.d.ts +20 -0
  434. package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -0
  435. package/dist/types/src/interfaces/protocols-configure.d.ts +40 -0
  436. package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -0
  437. package/dist/types/src/interfaces/protocols-query.d.ts +17 -0
  438. package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -0
  439. package/dist/types/src/interfaces/records-delete.d.ts +34 -0
  440. package/dist/types/src/interfaces/records-delete.d.ts.map +1 -0
  441. package/dist/types/src/interfaces/records-query.d.ts +31 -0
  442. package/dist/types/src/interfaces/records-query.d.ts.map +1 -0
  443. package/dist/types/src/interfaces/records-read.d.ts +36 -0
  444. package/dist/types/src/interfaces/records-read.d.ts.map +1 -0
  445. package/dist/types/src/interfaces/records-subscribe.d.ts +27 -0
  446. package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -0
  447. package/dist/types/src/interfaces/records-write.d.ts +309 -0
  448. package/dist/types/src/interfaces/records-write.d.ts.map +1 -0
  449. package/dist/types/src/jose/algorithms/signing/ed25519.d.ts +3 -0
  450. package/dist/types/src/jose/algorithms/signing/ed25519.d.ts.map +1 -0
  451. package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts +3 -0
  452. package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts.map +1 -0
  453. package/dist/types/src/jose/jws/general/builder.d.ts +10 -0
  454. package/dist/types/src/jose/jws/general/builder.d.ts.map +1 -0
  455. package/dist/types/src/jose/jws/general/verifier.d.ts +32 -0
  456. package/dist/types/src/jose/jws/general/verifier.d.ts.map +1 -0
  457. package/dist/types/src/protocols/permission-grant.d.ts +50 -0
  458. package/dist/types/src/protocols/permission-grant.d.ts.map +1 -0
  459. package/dist/types/src/protocols/permission-request.d.ts +35 -0
  460. package/dist/types/src/protocols/permission-request.d.ts.map +1 -0
  461. package/dist/types/src/protocols/permissions.d.ts +150 -0
  462. package/dist/types/src/protocols/permissions.d.ts.map +1 -0
  463. package/dist/types/src/schema-validator.d.ts +8 -0
  464. package/dist/types/src/schema-validator.d.ts.map +1 -0
  465. package/dist/types/src/store/blockstore-level.d.ts +34 -0
  466. package/dist/types/src/store/blockstore-level.d.ts.map +1 -0
  467. package/dist/types/src/store/blockstore-mock.d.ts +27 -0
  468. package/dist/types/src/store/blockstore-mock.d.ts.map +1 -0
  469. package/dist/types/src/store/data-store-level.d.ts +34 -0
  470. package/dist/types/src/store/data-store-level.d.ts.map +1 -0
  471. package/dist/types/src/store/index-level.d.ts +171 -0
  472. package/dist/types/src/store/index-level.d.ts.map +1 -0
  473. package/dist/types/src/store/level-wrapper.d.ts +48 -0
  474. package/dist/types/src/store/level-wrapper.d.ts.map +1 -0
  475. package/dist/types/src/store/message-store-level.d.ts +46 -0
  476. package/dist/types/src/store/message-store-level.d.ts.map +1 -0
  477. package/dist/types/src/store/resumable-task-store-level.d.ts +28 -0
  478. package/dist/types/src/store/resumable-task-store-level.d.ts.map +1 -0
  479. package/dist/types/src/store/storage-controller.d.ts +46 -0
  480. package/dist/types/src/store/storage-controller.d.ts.map +1 -0
  481. package/dist/types/src/types/cache.d.ts +16 -0
  482. package/dist/types/src/types/cache.d.ts.map +1 -0
  483. package/dist/types/src/types/data-store.d.ts +57 -0
  484. package/dist/types/src/types/data-store.d.ts.map +1 -0
  485. package/dist/types/src/types/event-log.d.ts +52 -0
  486. package/dist/types/src/types/event-log.d.ts.map +1 -0
  487. package/dist/types/src/types/jose-types.d.ts +75 -0
  488. package/dist/types/src/types/jose-types.d.ts.map +1 -0
  489. package/dist/types/src/types/jws-types.d.ts +27 -0
  490. package/dist/types/src/types/jws-types.d.ts.map +1 -0
  491. package/dist/types/src/types/message-interface.d.ts +27 -0
  492. package/dist/types/src/types/message-interface.d.ts.map +1 -0
  493. package/dist/types/src/types/message-store.d.ts +42 -0
  494. package/dist/types/src/types/message-store.d.ts.map +1 -0
  495. package/dist/types/src/types/message-types.d.ts +116 -0
  496. package/dist/types/src/types/message-types.d.ts.map +1 -0
  497. package/dist/types/src/types/messages-types.d.ts +65 -0
  498. package/dist/types/src/types/messages-types.d.ts.map +1 -0
  499. package/dist/types/src/types/method-handler.d.ts +19 -0
  500. package/dist/types/src/types/method-handler.d.ts.map +1 -0
  501. package/dist/types/src/types/permission-types.d.ts +93 -0
  502. package/dist/types/src/types/permission-types.d.ts.map +1 -0
  503. package/dist/types/src/types/protocols-types.d.ts +154 -0
  504. package/dist/types/src/types/protocols-types.d.ts.map +1 -0
  505. package/dist/types/src/types/query-types.d.ts +66 -0
  506. package/dist/types/src/types/query-types.d.ts.map +1 -0
  507. package/dist/types/src/types/records-types.d.ts +230 -0
  508. package/dist/types/src/types/records-types.d.ts.map +1 -0
  509. package/dist/types/src/types/resumable-task-store.d.ts +89 -0
  510. package/dist/types/src/types/resumable-task-store.d.ts.map +1 -0
  511. package/dist/types/src/types/signer.d.ts +26 -0
  512. package/dist/types/src/types/signer.d.ts.map +1 -0
  513. package/dist/types/src/types/subscriptions.d.ts +30 -0
  514. package/dist/types/src/types/subscriptions.d.ts.map +1 -0
  515. package/dist/types/src/utils/abort.d.ts +5 -0
  516. package/dist/types/src/utils/abort.d.ts.map +1 -0
  517. package/dist/types/src/utils/array.d.ts +18 -0
  518. package/dist/types/src/utils/array.d.ts.map +1 -0
  519. package/dist/types/src/utils/cid.d.ts +30 -0
  520. package/dist/types/src/utils/cid.d.ts.map +1 -0
  521. package/dist/types/src/utils/data-stream.d.ts +31 -0
  522. package/dist/types/src/utils/data-stream.d.ts.map +1 -0
  523. package/dist/types/src/utils/encoder.d.ts +14 -0
  524. package/dist/types/src/utils/encoder.d.ts.map +1 -0
  525. package/dist/types/src/utils/encryption.d.ts +44 -0
  526. package/dist/types/src/utils/encryption.d.ts.map +1 -0
  527. package/dist/types/src/utils/filter.d.ts +60 -0
  528. package/dist/types/src/utils/filter.d.ts.map +1 -0
  529. package/dist/types/src/utils/hd-key.d.ts +54 -0
  530. package/dist/types/src/utils/hd-key.d.ts.map +1 -0
  531. package/dist/types/src/utils/jws.d.ts +39 -0
  532. package/dist/types/src/utils/jws.d.ts.map +1 -0
  533. package/dist/types/src/utils/memory-cache.d.ts +15 -0
  534. package/dist/types/src/utils/memory-cache.d.ts.map +1 -0
  535. package/dist/types/src/utils/messages.d.ts +27 -0
  536. package/dist/types/src/utils/messages.d.ts.map +1 -0
  537. package/dist/types/src/utils/object.d.ts +13 -0
  538. package/dist/types/src/utils/object.d.ts.map +1 -0
  539. package/dist/types/src/utils/private-key-signer.d.ts +34 -0
  540. package/dist/types/src/utils/private-key-signer.d.ts.map +1 -0
  541. package/dist/types/src/utils/protocols.d.ts +14 -0
  542. package/dist/types/src/utils/protocols.d.ts.map +1 -0
  543. package/dist/types/src/utils/records.d.ts +122 -0
  544. package/dist/types/src/utils/records.d.ts.map +1 -0
  545. package/dist/types/src/utils/secp256k1.d.ts +59 -0
  546. package/dist/types/src/utils/secp256k1.d.ts.map +1 -0
  547. package/dist/types/src/utils/secp256r1.d.ts +39 -0
  548. package/dist/types/src/utils/secp256r1.d.ts.map +1 -0
  549. package/dist/types/src/utils/string.d.ts +6 -0
  550. package/dist/types/src/utils/string.d.ts.map +1 -0
  551. package/dist/types/src/utils/time.d.ts +50 -0
  552. package/dist/types/src/utils/time.d.ts.map +1 -0
  553. package/dist/types/src/utils/url.d.ts +5 -0
  554. package/dist/types/src/utils/url.d.ts.map +1 -0
  555. package/dist/types/tests/core/auth.spec.d.ts +2 -0
  556. package/dist/types/tests/core/auth.spec.d.ts.map +1 -0
  557. package/dist/types/tests/core/message-reply.spec.d.ts +2 -0
  558. package/dist/types/tests/core/message-reply.spec.d.ts.map +1 -0
  559. package/dist/types/tests/core/message.spec.d.ts +2 -0
  560. package/dist/types/tests/core/message.spec.d.ts.map +1 -0
  561. package/dist/types/tests/core/protocol-authorization.spec.d.ts +2 -0
  562. package/dist/types/tests/core/protocol-authorization.spec.d.ts.map +1 -0
  563. package/dist/types/tests/dwn.spec.d.ts +2 -0
  564. package/dist/types/tests/dwn.spec.d.ts.map +1 -0
  565. package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts +2 -0
  566. package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts.map +1 -0
  567. package/dist/types/tests/event-log/event-log-level.spec.d.ts +2 -0
  568. package/dist/types/tests/event-log/event-log-level.spec.d.ts.map +1 -0
  569. package/dist/types/tests/event-log/event-log.spec.d.ts +2 -0
  570. package/dist/types/tests/event-log/event-log.spec.d.ts.map +1 -0
  571. package/dist/types/tests/event-log/event-stream.spec.d.ts +2 -0
  572. package/dist/types/tests/event-log/event-stream.spec.d.ts.map +1 -0
  573. package/dist/types/tests/features/author-delegated-grant.spec.d.ts +2 -0
  574. package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -0
  575. package/dist/types/tests/features/owner-delegated-grant.spec.d.ts +2 -0
  576. package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -0
  577. package/dist/types/tests/features/owner-signature.spec.d.ts +2 -0
  578. package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -0
  579. package/dist/types/tests/features/permissions.spec.d.ts +2 -0
  580. package/dist/types/tests/features/permissions.spec.d.ts.map +1 -0
  581. package/dist/types/tests/features/protocol-create-action.spec.d.ts +2 -0
  582. package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -0
  583. package/dist/types/tests/features/protocol-delete-action.spec.d.ts +2 -0
  584. package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -0
  585. package/dist/types/tests/features/protocol-update-action.spec.d.ts +2 -0
  586. package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -0
  587. package/dist/types/tests/features/records-prune.spec.d.ts +2 -0
  588. package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -0
  589. package/dist/types/tests/features/records-tags.spec.d.ts +2 -0
  590. package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -0
  591. package/dist/types/tests/features/resumable-tasks.spec.d.ts +2 -0
  592. package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -0
  593. package/dist/types/tests/handlers/messages-query.spec.d.ts +2 -0
  594. package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -0
  595. package/dist/types/tests/handlers/messages-read.spec.d.ts +2 -0
  596. package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -0
  597. package/dist/types/tests/handlers/messages-subscribe.spec.d.ts +2 -0
  598. package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -0
  599. package/dist/types/tests/handlers/protocols-configure.spec.d.ts +2 -0
  600. package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -0
  601. package/dist/types/tests/handlers/protocols-query.spec.d.ts +2 -0
  602. package/dist/types/tests/handlers/protocols-query.spec.d.ts.map +1 -0
  603. package/dist/types/tests/handlers/records-delete.spec.d.ts +2 -0
  604. package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -0
  605. package/dist/types/tests/handlers/records-query.spec.d.ts +2 -0
  606. package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -0
  607. package/dist/types/tests/handlers/records-read.spec.d.ts +2 -0
  608. package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -0
  609. package/dist/types/tests/handlers/records-subscribe.spec.d.ts +2 -0
  610. package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -0
  611. package/dist/types/tests/handlers/records-write.spec.d.ts +2 -0
  612. package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -0
  613. package/dist/types/tests/interfaces/messages-get.spec.d.ts +2 -0
  614. package/dist/types/tests/interfaces/messages-get.spec.d.ts.map +1 -0
  615. package/dist/types/tests/interfaces/messages-subscribe.spec.d.ts +2 -0
  616. package/dist/types/tests/interfaces/messages-subscribe.spec.d.ts.map +1 -0
  617. package/dist/types/tests/interfaces/messagess-query.spec.d.ts +2 -0
  618. package/dist/types/tests/interfaces/messagess-query.spec.d.ts.map +1 -0
  619. package/dist/types/tests/interfaces/protocols-configure.spec.d.ts +2 -0
  620. package/dist/types/tests/interfaces/protocols-configure.spec.d.ts.map +1 -0
  621. package/dist/types/tests/interfaces/protocols-query.spec.d.ts +2 -0
  622. package/dist/types/tests/interfaces/protocols-query.spec.d.ts.map +1 -0
  623. package/dist/types/tests/interfaces/records-delete.spec.d.ts +2 -0
  624. package/dist/types/tests/interfaces/records-delete.spec.d.ts.map +1 -0
  625. package/dist/types/tests/interfaces/records-query.spec.d.ts +2 -0
  626. package/dist/types/tests/interfaces/records-query.spec.d.ts.map +1 -0
  627. package/dist/types/tests/interfaces/records-read.spec.d.ts +2 -0
  628. package/dist/types/tests/interfaces/records-read.spec.d.ts.map +1 -0
  629. package/dist/types/tests/interfaces/records-subscribe.spec.d.ts +2 -0
  630. package/dist/types/tests/interfaces/records-subscribe.spec.d.ts.map +1 -0
  631. package/dist/types/tests/interfaces/records-write.spec.d.ts +2 -0
  632. package/dist/types/tests/interfaces/records-write.spec.d.ts.map +1 -0
  633. package/dist/types/tests/jose/jws/general.spec.d.ts +2 -0
  634. package/dist/types/tests/jose/jws/general.spec.d.ts.map +1 -0
  635. package/dist/types/tests/protocols/permission-request.spec.d.ts +2 -0
  636. package/dist/types/tests/protocols/permission-request.spec.d.ts.map +1 -0
  637. package/dist/types/tests/protocols/permissions.spec.d.ts +2 -0
  638. package/dist/types/tests/protocols/permissions.spec.d.ts.map +1 -0
  639. package/dist/types/tests/scenarios/aggregator.spec.d.ts +2 -0
  640. package/dist/types/tests/scenarios/aggregator.spec.d.ts.map +1 -0
  641. package/dist/types/tests/scenarios/deleted-record.spec.d.ts +2 -0
  642. package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -0
  643. package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts +2 -0
  644. package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -0
  645. package/dist/types/tests/scenarios/messages-query.spec.d.ts +2 -0
  646. package/dist/types/tests/scenarios/messages-query.spec.d.ts.map +1 -0
  647. package/dist/types/tests/scenarios/nested-roles.spec.d.ts +2 -0
  648. package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -0
  649. package/dist/types/tests/scenarios/subscriptions.spec.d.ts +2 -0
  650. package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -0
  651. package/dist/types/tests/store/blockstore-mock.spec.d.ts +2 -0
  652. package/dist/types/tests/store/blockstore-mock.spec.d.ts.map +1 -0
  653. package/dist/types/tests/store/data-store-level.spec.d.ts +2 -0
  654. package/dist/types/tests/store/data-store-level.spec.d.ts.map +1 -0
  655. package/dist/types/tests/store/index-level.spec.d.ts +2 -0
  656. package/dist/types/tests/store/index-level.spec.d.ts.map +1 -0
  657. package/dist/types/tests/store/message-store-level.spec.d.ts +2 -0
  658. package/dist/types/tests/store/message-store-level.spec.d.ts.map +1 -0
  659. package/dist/types/tests/store/message-store.spec.d.ts +2 -0
  660. package/dist/types/tests/store/message-store.spec.d.ts.map +1 -0
  661. package/dist/types/tests/store-dependent-tests.spec.d.ts +2 -0
  662. package/dist/types/tests/store-dependent-tests.spec.d.ts.map +1 -0
  663. package/dist/types/tests/test-event-stream.d.ts +22 -0
  664. package/dist/types/tests/test-event-stream.d.ts.map +1 -0
  665. package/dist/types/tests/test-stores.d.ts +33 -0
  666. package/dist/types/tests/test-stores.d.ts.map +1 -0
  667. package/dist/types/tests/test-suite.d.ts +18 -0
  668. package/dist/types/tests/test-suite.d.ts.map +1 -0
  669. package/dist/types/tests/utils/cid.spec.d.ts +2 -0
  670. package/dist/types/tests/utils/cid.spec.d.ts.map +1 -0
  671. package/dist/types/tests/utils/data-stream.spec.d.ts +2 -0
  672. package/dist/types/tests/utils/data-stream.spec.d.ts.map +1 -0
  673. package/dist/types/tests/utils/encryption.spec.d.ts +2 -0
  674. package/dist/types/tests/utils/encryption.spec.d.ts.map +1 -0
  675. package/dist/types/tests/utils/filters.spec.d.ts +2 -0
  676. package/dist/types/tests/utils/filters.spec.d.ts.map +1 -0
  677. package/dist/types/tests/utils/hd-key.spec.d.ts +2 -0
  678. package/dist/types/tests/utils/hd-key.spec.d.ts.map +1 -0
  679. package/dist/types/tests/utils/jws.spec.d.ts +2 -0
  680. package/dist/types/tests/utils/jws.spec.d.ts.map +1 -0
  681. package/dist/types/tests/utils/memory-cache.spec.d.ts +2 -0
  682. package/dist/types/tests/utils/memory-cache.spec.d.ts.map +1 -0
  683. package/dist/types/tests/utils/messages.spec.d.ts +2 -0
  684. package/dist/types/tests/utils/messages.spec.d.ts.map +1 -0
  685. package/dist/types/tests/utils/object.spec.d.ts +2 -0
  686. package/dist/types/tests/utils/object.spec.d.ts.map +1 -0
  687. package/dist/types/tests/utils/poller.d.ts +21 -0
  688. package/dist/types/tests/utils/poller.d.ts.map +1 -0
  689. package/dist/types/tests/utils/private-key-signer.spec.d.ts +2 -0
  690. package/dist/types/tests/utils/private-key-signer.spec.d.ts.map +1 -0
  691. package/dist/types/tests/utils/records.spec.d.ts +2 -0
  692. package/dist/types/tests/utils/records.spec.d.ts.map +1 -0
  693. package/dist/types/tests/utils/secp256k1.spec.d.ts +2 -0
  694. package/dist/types/tests/utils/secp256k1.spec.d.ts.map +1 -0
  695. package/dist/types/tests/utils/secp256r1.spec.d.ts +2 -0
  696. package/dist/types/tests/utils/secp256r1.spec.d.ts.map +1 -0
  697. package/dist/types/tests/utils/test-data-generator.d.ts +342 -0
  698. package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -0
  699. package/dist/types/tests/utils/test-stub-generator.d.ts +16 -0
  700. package/dist/types/tests/utils/test-stub-generator.d.ts.map +1 -0
  701. package/dist/types/tests/utils/time.spec.d.ts +2 -0
  702. package/dist/types/tests/utils/time.spec.d.ts.map +1 -0
  703. package/dist/types/tests/utils/url.spec.d.ts +2 -0
  704. package/dist/types/tests/utils/url.spec.d.ts.map +1 -0
  705. package/dist/types/tests/validation/json-schemas/definitions.spec.d.ts +2 -0
  706. package/dist/types/tests/validation/json-schemas/definitions.spec.d.ts.map +1 -0
  707. package/dist/types/tests/validation/json-schemas/jwk/general-jwk.spec.d.ts +2 -0
  708. package/dist/types/tests/validation/json-schemas/jwk/general-jwk.spec.d.ts.map +1 -0
  709. package/dist/types/tests/validation/json-schemas/jwk/public-jwk.spec.d.ts +2 -0
  710. package/dist/types/tests/validation/json-schemas/jwk/public-jwk.spec.d.ts.map +1 -0
  711. package/dist/types/tests/validation/json-schemas/jwk-verification-method.spec.d.ts +2 -0
  712. package/dist/types/tests/validation/json-schemas/jwk-verification-method.spec.d.ts.map +1 -0
  713. package/dist/types/tests/validation/json-schemas/protocols/protocols-configure.spec.d.ts +2 -0
  714. package/dist/types/tests/validation/json-schemas/protocols/protocols-configure.spec.d.ts.map +1 -0
  715. package/dist/types/tests/validation/json-schemas/records/records-query.spec.d.ts +2 -0
  716. package/dist/types/tests/validation/json-schemas/records/records-query.spec.d.ts.map +1 -0
  717. package/dist/types/tests/validation/json-schemas/records/records-write.spec.d.ts +2 -0
  718. package/dist/types/tests/validation/json-schemas/records/records-write.spec.d.ts.map +1 -0
  719. package/package.json +167 -0
  720. package/src/core/abstract-message.ts +62 -0
  721. package/src/core/auth.ts +36 -0
  722. package/src/core/dwn-constant.ts +9 -0
  723. package/src/core/dwn-error.ts +167 -0
  724. package/src/core/grant-authorization.ts +148 -0
  725. package/src/core/message-reply.ts +41 -0
  726. package/src/core/message.ts +259 -0
  727. package/src/core/messages-grant-authorization.ts +134 -0
  728. package/src/core/protocol-authorization.ts +903 -0
  729. package/src/core/protocols-grant-authorization.ts +88 -0
  730. package/src/core/records-grant-authorization.ts +197 -0
  731. package/src/core/resumable-task-manager.ts +114 -0
  732. package/src/core/tenant-gate.ts +33 -0
  733. package/src/dwn.ts +264 -0
  734. package/src/enums/dwn-interface-method.ts +14 -0
  735. package/src/event-log/event-emitter-stream.ts +69 -0
  736. package/src/event-log/event-log-level.ts +72 -0
  737. package/src/handlers/messages-query.ts +67 -0
  738. package/src/handlers/messages-read.ts +103 -0
  739. package/src/handlers/messages-subscribe.ts +89 -0
  740. package/src/handlers/protocols-configure.ts +137 -0
  741. package/src/handlers/protocols-query.ts +82 -0
  742. package/src/handlers/records-delete.ts +124 -0
  743. package/src/handlers/records-query.ts +262 -0
  744. package/src/handlers/records-read.ts +187 -0
  745. package/src/handlers/records-subscribe.ts +218 -0
  746. package/src/handlers/records-write.ts +404 -0
  747. package/src/index.ts +67 -0
  748. package/src/interfaces/messages-query.ts +60 -0
  749. package/src/interfaces/messages-read.ts +63 -0
  750. package/src/interfaces/messages-subscribe.ts +64 -0
  751. package/src/interfaces/protocols-configure.ts +340 -0
  752. package/src/interfaces/protocols-query.ts +96 -0
  753. package/src/interfaces/records-delete.ts +117 -0
  754. package/src/interfaces/records-query.ts +131 -0
  755. package/src/interfaces/records-read.ts +100 -0
  756. package/src/interfaces/records-subscribe.ts +104 -0
  757. package/src/interfaces/records-write.ts +1072 -0
  758. package/src/jose/algorithms/signing/ed25519.ts +58 -0
  759. package/src/jose/algorithms/signing/signature-algorithms.ts +22 -0
  760. package/src/jose/jws/general/builder.ts +48 -0
  761. package/src/jose/jws/general/verifier.ts +112 -0
  762. package/src/protocols/permission-grant.ts +86 -0
  763. package/src/protocols/permission-request.ts +63 -0
  764. package/src/protocols/permissions.ts +508 -0
  765. package/src/schema-validator.ts +46 -0
  766. package/src/store/blockstore-level.ts +113 -0
  767. package/src/store/blockstore-mock.ts +80 -0
  768. package/src/store/data-store-level.ts +120 -0
  769. package/src/store/index-level.ts +691 -0
  770. package/src/store/level-wrapper.ts +272 -0
  771. package/src/store/message-store-level.ts +195 -0
  772. package/src/store/resumable-task-store-level.ts +120 -0
  773. package/src/store/storage-controller.ts +240 -0
  774. package/src/types/cache.ts +16 -0
  775. package/src/types/data-store.ts +64 -0
  776. package/src/types/event-log.ts +52 -0
  777. package/src/types/jose-types.ts +76 -0
  778. package/src/types/jws-types.ts +28 -0
  779. package/src/types/message-interface.ts +30 -0
  780. package/src/types/message-store.ts +57 -0
  781. package/src/types/message-types.ts +132 -0
  782. package/src/types/messages-types.ts +77 -0
  783. package/src/types/method-handler.ts +19 -0
  784. package/src/types/permission-types.ts +110 -0
  785. package/src/types/protocols-types.ts +177 -0
  786. package/src/types/query-types.ts +61 -0
  787. package/src/types/records-types.ts +263 -0
  788. package/src/types/resumable-task-store.ts +96 -0
  789. package/src/types/signer.ts +27 -0
  790. package/src/types/subscriptions.ts +34 -0
  791. package/src/utils/abort.ts +31 -0
  792. package/src/utils/array.ts +39 -0
  793. package/src/utils/cid.ts +101 -0
  794. package/src/utils/data-stream.ts +99 -0
  795. package/src/utils/encoder.ts +54 -0
  796. package/src/utils/encryption.ts +145 -0
  797. package/src/utils/filter.ts +245 -0
  798. package/src/utils/hd-key.ts +126 -0
  799. package/src/utils/jws.ts +95 -0
  800. package/src/utils/memory-cache.ts +31 -0
  801. package/src/utils/messages.ts +109 -0
  802. package/src/utils/object.ts +43 -0
  803. package/src/utils/private-key-signer.ts +72 -0
  804. package/src/utils/protocols.ts +50 -0
  805. package/src/utils/records.ts +559 -0
  806. package/src/utils/secp256k1.ts +157 -0
  807. package/src/utils/secp256r1.ts +142 -0
  808. package/src/utils/string.ts +13 -0
  809. package/src/utils/time.ts +78 -0
  810. package/src/utils/url.ts +65 -0
@@ -0,0 +1,795 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { Cid } from '../utils/cid.js';
22
+ import { Encoder } from '../utils/encoder.js';
23
+ import { Encryption } from '../utils/encryption.js';
24
+ import { EncryptionAlgorithm } from '../utils/encryption.js';
25
+ import { GeneralJwsBuilder } from '../jose/jws/general/builder.js';
26
+ import { Jws } from '../utils/jws.js';
27
+ import { KeyDerivationScheme } from '../utils/hd-key.js';
28
+ import { Message } from '../core/message.js';
29
+ import { PermissionGrant } from '../protocols/permission-grant.js';
30
+ import { Records } from '../utils/records.js';
31
+ import { RecordsGrantAuthorization } from '../core/records-grant-authorization.js';
32
+ import { removeUndefinedProperties } from '../utils/object.js';
33
+ import { Secp256k1 } from '../utils/secp256k1.js';
34
+ import { Time } from '../utils/time.js';
35
+ import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
36
+ import { DwnInterfaceName, DwnMethodName } from '../enums/dwn-interface-method.js';
37
+ import { normalizeProtocolUrl, normalizeSchemaUrl, validateProtocolUrlNormalized, validateSchemaUrlNormalized } from '../utils/url.js';
38
+ /**
39
+ * A class representing a RecordsWrite DWN message.
40
+ * NOTE: Unable to extend `AbstractMessage` directly because the incompatible `_message` type, which is not just a generic `<M>` type.
41
+ */
42
+ export class RecordsWrite {
43
+ /**
44
+ * Valid JSON message representing this RecordsWrite.
45
+ * @throws `DwnErrorCode.RecordsWriteMissingSigner` if the message is not signed yet.
46
+ */
47
+ get message() {
48
+ if (this._message.authorization === undefined) {
49
+ throw new DwnError(DwnErrorCode.RecordsWriteMissingSigner, 'This RecordsWrite is not yet signed, JSON message cannot be generated from an incomplete state.');
50
+ }
51
+ return this._message;
52
+ }
53
+ get author() {
54
+ return this._author;
55
+ }
56
+ get signaturePayload() {
57
+ return this._signaturePayload;
58
+ }
59
+ /**
60
+ * The owner DID of the message if owner signature is present in the message; `undefined` otherwise.
61
+ * This is the logical owner of the message, not to be confused with the actual signer of the owner signature,
62
+ * this is because the signer of the owner signature may not be the actual DWN owner, but a delegate authorized by the owner.
63
+ */
64
+ get owner() {
65
+ return this._owner;
66
+ }
67
+ /**
68
+ * Decoded owner signature payload.
69
+ */
70
+ get ownerSignaturePayload() {
71
+ return this._ownerSignaturePayload;
72
+ }
73
+ /**
74
+ * If this message is signed by an author-delegate.
75
+ */
76
+ get isSignedByAuthorDelegate() {
77
+ return Message.isSignedByAuthorDelegate(this._message);
78
+ }
79
+ /**
80
+ * If this message is signed by an owner-delegate.
81
+ */
82
+ get isSignedByOwnerDelegate() {
83
+ return Message.isSignedByOwnerDelegate(this._message);
84
+ }
85
+ /**
86
+ * Gets the signer of this message.
87
+ * This is not to be confused with the logical author of the message.
88
+ */
89
+ get signer() {
90
+ return Message.getSigner(this._message);
91
+ }
92
+ /**
93
+ * Gets the signer of owner signature; `undefined` if owner signature is not present in the message.
94
+ * This is not to be confused with the logical owner {@link #owner} of the message,
95
+ * this is because the signer of the owner signature may not be the actual DWN owner, but a delegate authorized by the owner.
96
+ * In the case that the owner signature is signed by the actual DWN owner, this value will be the same as {@link #owner}.
97
+ */
98
+ get ownerSignatureSigner() {
99
+ var _a;
100
+ if (((_a = this._message.authorization) === null || _a === void 0 ? void 0 : _a.ownerSignature) === undefined) {
101
+ return undefined;
102
+ }
103
+ const signer = Jws.getSignerDid(this._message.authorization.ownerSignature.signatures[0]);
104
+ return signer;
105
+ }
106
+ constructor(message, parentContextId) {
107
+ this.parentContextId = parentContextId;
108
+ this._message = message;
109
+ if (message.authorization !== undefined) {
110
+ this._author = Message.getAuthor(message);
111
+ this._signaturePayload = Jws.decodePlainObjectPayload(message.authorization.signature);
112
+ if (message.authorization.ownerSignature !== undefined) {
113
+ // if the message authorization contains owner delegated grant, the owner would be the grantor of the grant
114
+ // else the owner would be the signer of the owner signature
115
+ if (message.authorization.ownerDelegatedGrant !== undefined) {
116
+ this._owner = Message.getSigner(message.authorization.ownerDelegatedGrant);
117
+ }
118
+ else {
119
+ this._owner = Jws.getSignerDid(message.authorization.ownerSignature.signatures[0]);
120
+ }
121
+ this._ownerSignaturePayload = Jws.decodePlainObjectPayload(message.authorization.ownerSignature);
122
+ }
123
+ }
124
+ this.attesters = RecordsWrite.getAttesters(message);
125
+ // consider converting isInitialWrite() & getEntryId() into properties for performance and convenience
126
+ }
127
+ /**
128
+ * Parses a RecordsWrite message and returns a {RecordsWrite} instance.
129
+ */
130
+ static parse(recordsWriteMessage) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ // Make a copy so that the stored copy is not subject to external, unexpected modification.
133
+ const message = JSON.parse(JSON.stringify(recordsWriteMessage));
134
+ // asynchronous checks that are required by the constructor to initialize members properly
135
+ yield Message.validateSignatureStructure(message.authorization.signature, message.descriptor, 'RecordsWriteSignaturePayload');
136
+ if (message.authorization.ownerSignature !== undefined) {
137
+ yield Message.validateSignatureStructure(message.authorization.ownerSignature, message.descriptor);
138
+ }
139
+ yield RecordsWrite.validateAttestationIntegrity(message);
140
+ const recordsWrite = new RecordsWrite(message);
141
+ yield recordsWrite.validateIntegrity(); // RecordsWrite specific data integrity check
142
+ return recordsWrite;
143
+ });
144
+ }
145
+ /**
146
+ * Creates a RecordsWrite message.
147
+ * @param options.recordId If `undefined`, will be auto-filled as the initial message as convenience for developer.
148
+ * @param options.data Data used to compute the `dataCid`, must be the encrypted data bytes if `options.encryptionInput` is given.
149
+ * Must specify `options.dataCid` if `undefined`.
150
+ * @param options.dataCid CID of the data that is already stored in the DWN. Must specify `options.data` if `undefined`.
151
+ * @param options.dataSize Size of data in number of bytes. Must be defined if `options.dataCid` is defined; must be `undefined` otherwise.
152
+ * @param options.dateCreated If `undefined`, it will be auto-filled with current time.
153
+ * @param options.messageTimestamp If `undefined`, it will be auto-filled with current time.
154
+ * @param options.parentContextId Must be given if this message is for a non-root protocol record.
155
+ * If not given, it either means this write is for a root protocol record or a flat-space record.
156
+ */
157
+ static create(options) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ var _a, _b, _c, _d;
160
+ if ((options.protocol === undefined && options.protocolPath !== undefined) ||
161
+ (options.protocol !== undefined && options.protocolPath === undefined)) {
162
+ throw new DwnError(DwnErrorCode.RecordsWriteCreateProtocolAndProtocolPathMutuallyInclusive, '`protocol` and `protocolPath` must both be defined or undefined at the same time');
163
+ }
164
+ if ((options.data === undefined && options.dataCid === undefined) ||
165
+ (options.data !== undefined && options.dataCid !== undefined)) {
166
+ throw new DwnError(DwnErrorCode.RecordsWriteCreateDataAndDataCidMutuallyExclusive, 'one and only one parameter between `data` and `dataCid` is required');
167
+ }
168
+ if ((options.dataCid === undefined && options.dataSize !== undefined) ||
169
+ (options.dataCid !== undefined && options.dataSize === undefined)) {
170
+ throw new DwnError(DwnErrorCode.RecordsWriteCreateDataCidAndDataSizeMutuallyInclusive, '`dataCid` and `dataSize` must both be defined or undefined at the same time');
171
+ }
172
+ if (options.signer === undefined && options.delegatedGrant !== undefined) {
173
+ throw new DwnError(DwnErrorCode.RecordsWriteCreateMissingSigner, '`signer` must be given when `delegatedGrant` is given');
174
+ }
175
+ const dataCid = (_a = options.dataCid) !== null && _a !== void 0 ? _a : yield Cid.computeDagPbCidFromBytes(options.data);
176
+ const dataSize = (_b = options.dataSize) !== null && _b !== void 0 ? _b : options.data.length;
177
+ const currentTime = Time.getCurrentTimestamp();
178
+ const descriptor = {
179
+ interface: DwnInterfaceName.Records,
180
+ method: DwnMethodName.Write,
181
+ protocol: options.protocol !== undefined ? normalizeProtocolUrl(options.protocol) : undefined,
182
+ protocolPath: options.protocolPath,
183
+ recipient: options.recipient,
184
+ schema: options.schema !== undefined ? normalizeSchemaUrl(options.schema) : undefined,
185
+ tags: options.tags,
186
+ parentId: RecordsWrite.getRecordIdFromContextId(options.parentContextId),
187
+ dataCid,
188
+ dataSize,
189
+ dateCreated: (_c = options.dateCreated) !== null && _c !== void 0 ? _c : currentTime,
190
+ messageTimestamp: (_d = options.messageTimestamp) !== null && _d !== void 0 ? _d : currentTime,
191
+ published: options.published,
192
+ datePublished: options.datePublished,
193
+ dataFormat: options.dataFormat
194
+ };
195
+ // generate `datePublished` if the message is to be published but `datePublished` is not given
196
+ if (options.published === true &&
197
+ options.datePublished === undefined) {
198
+ descriptor.datePublished = currentTime;
199
+ }
200
+ // delete all descriptor properties that are `undefined` else the code will encounter the following IPLD issue when attempting to generate CID:
201
+ // Error: `undefined` is not supported by the IPLD Data Model and cannot be encoded
202
+ removeUndefinedProperties(descriptor);
203
+ // `recordId` computation
204
+ const recordId = options.recordId;
205
+ // `attestation` generation
206
+ const descriptorCid = yield Cid.computeCid(descriptor);
207
+ const attestation = yield RecordsWrite.createAttestation(descriptorCid, options.attestationSigners);
208
+ // `encryption` generation
209
+ const encryption = yield RecordsWrite.createEncryptionProperty(descriptor, options.encryptionInput);
210
+ const message = {
211
+ recordId,
212
+ descriptor
213
+ };
214
+ // assign optional properties only if they exist
215
+ if (attestation !== undefined) {
216
+ message.attestation = attestation;
217
+ }
218
+ if (encryption !== undefined) {
219
+ message.encryption = encryption;
220
+ }
221
+ const recordsWrite = new RecordsWrite(message, options.parentContextId);
222
+ if (options.signer !== undefined) {
223
+ yield recordsWrite.sign({
224
+ signer: options.signer,
225
+ delegatedGrant: options.delegatedGrant,
226
+ permissionGrantId: options.permissionGrantId,
227
+ protocolRole: options.protocolRole
228
+ });
229
+ }
230
+ return recordsWrite;
231
+ });
232
+ }
233
+ static getRecordIdFromContextId(contextId) {
234
+ return contextId === null || contextId === void 0 ? void 0 : contextId.split('/').filter(segment => segment !== '').pop();
235
+ }
236
+ /**
237
+ * Convenience method that creates a message by:
238
+ * 1. Copying over immutable properties from the given source message
239
+ * 2. Copying over mutable properties that are not overwritten from the given source message
240
+ * 3. Replace the mutable properties that are given new value
241
+ * @param options.recordsWriteMessage Message that the new RecordsWrite will be based from.
242
+ * @param options.messageTimestamp The new date the record is modified. If not given, current time will be used .
243
+ * @param options.data The new data or the record. If not given, data from given message will be used.
244
+ * @param options.published The new published state. If not given, then will be set to `true` if {options.messageTimestamp} is given;
245
+ * else the state from given message will be used.
246
+ * @param options.publishedDate The new date the record is modified. If not given, then:
247
+ * - will not be set if the record will be unpublished as the result of this RecordsWrite; else
248
+ * - will be set to the same published date as the given message if it wss already published; else
249
+ * - will be set to current time (because this is a toggle from unpublished to published)
250
+ */
251
+ static createFrom(options) {
252
+ return __awaiter(this, void 0, void 0, function* () {
253
+ var _a, _b, _c, _d;
254
+ const sourceMessage = options.recordsWriteMessage;
255
+ const sourceRecordsWrite = yield RecordsWrite.parse(sourceMessage);
256
+ const currentTime = Time.getCurrentTimestamp();
257
+ // inherit published value from parent if neither published nor datePublished is specified
258
+ const published = (_a = options.published) !== null && _a !== void 0 ? _a : (options.datePublished ? true : sourceMessage.descriptor.published);
259
+ // use current time if published but no explicit time given
260
+ let datePublished = undefined;
261
+ // if given explicitly published dated
262
+ if (options.datePublished) {
263
+ datePublished = options.datePublished;
264
+ }
265
+ else {
266
+ // if this RecordsWrite will publish the record
267
+ if (published) {
268
+ // the parent was already published, inherit the same published date
269
+ if (sourceMessage.descriptor.published) {
270
+ datePublished = sourceMessage.descriptor.datePublished;
271
+ }
272
+ else {
273
+ // this is a toggle from unpublished to published, use current time
274
+ datePublished = currentTime;
275
+ }
276
+ }
277
+ }
278
+ const createOptions = {
279
+ // immutable properties below, just copy from the source message
280
+ recipient: sourceMessage.descriptor.recipient,
281
+ recordId: sourceMessage.recordId,
282
+ dateCreated: sourceMessage.descriptor.dateCreated,
283
+ protocol: sourceMessage.descriptor.protocol,
284
+ protocolPath: sourceMessage.descriptor.protocolPath,
285
+ schema: sourceMessage.descriptor.schema,
286
+ parentContextId: Records.getParentContextFromOfContextId(sourceMessage.contextId),
287
+ // mutable properties below
288
+ messageTimestamp: (_b = options.messageTimestamp) !== null && _b !== void 0 ? _b : currentTime,
289
+ published,
290
+ datePublished,
291
+ tags: options.tags,
292
+ data: options.data,
293
+ dataCid: options.data ? undefined : sourceMessage.descriptor.dataCid, // if new `data` not given, use value from source message
294
+ dataSize: options.data ? undefined : sourceMessage.descriptor.dataSize, // if new `data` not given, use value from source message
295
+ dataFormat: (_c = options.dataFormat) !== null && _c !== void 0 ? _c : sourceMessage.descriptor.dataFormat,
296
+ protocolRole: (_d = options.protocolRole) !== null && _d !== void 0 ? _d : sourceRecordsWrite.signaturePayload.protocolRole, // if not given, use value from source message
297
+ delegatedGrant: options.delegatedGrant,
298
+ // finally still need signers
299
+ signer: options.signer,
300
+ attestationSigners: options.attestationSigners
301
+ };
302
+ const recordsWrite = yield RecordsWrite.create(createOptions);
303
+ return recordsWrite;
304
+ });
305
+ }
306
+ /**
307
+ * Called by `JSON.stringify(...)` automatically.
308
+ */
309
+ toJSON() {
310
+ return this.message;
311
+ }
312
+ /**
313
+ * Encrypts the symmetric encryption key using the public keys given and attach the resulting `encryption` property to the RecordsWrite.
314
+ */
315
+ encryptSymmetricEncryptionKey(encryptionInput) {
316
+ return __awaiter(this, void 0, void 0, function* () {
317
+ this._message.encryption = yield RecordsWrite.createEncryptionProperty(this._message.descriptor, encryptionInput);
318
+ // opportunity here to re-sign instead of remove
319
+ delete this._message.authorization;
320
+ this._signaturePayload = undefined;
321
+ this._author = undefined;
322
+ });
323
+ }
324
+ /**
325
+ * Signs the RecordsWrite, the signer is commonly the author, but can also be a delegate.
326
+ */
327
+ sign(options) {
328
+ return __awaiter(this, void 0, void 0, function* () {
329
+ var _a;
330
+ const { signer, delegatedGrant, permissionGrantId, protocolRole } = options;
331
+ // compute delegated grant ID and author if delegated grant is given
332
+ let delegatedGrantId;
333
+ let authorDid;
334
+ if (delegatedGrant !== undefined) {
335
+ delegatedGrantId = yield Message.getCid(delegatedGrant);
336
+ authorDid = Jws.getSignerDid(delegatedGrant.authorization.signature.signatures[0]);
337
+ }
338
+ else {
339
+ authorDid = Jws.extractDid(signer.keyId);
340
+ }
341
+ const descriptor = this._message.descriptor;
342
+ const descriptorCid = yield Cid.computeCid(descriptor);
343
+ // compute `recordId` if not given at construction time
344
+ this._message.recordId = (_a = this._message.recordId) !== null && _a !== void 0 ? _a : yield RecordsWrite.getEntryId(authorDid, descriptor);
345
+ // compute `contextId` if this is a protocol-space record
346
+ if (this._message.descriptor.protocol !== undefined) {
347
+ // if `parentContextId` is not given, this is a root protocol record
348
+ if (this.parentContextId === undefined || this.parentContextId === '') {
349
+ this._message.contextId = this._message.recordId;
350
+ }
351
+ else {
352
+ // else this is a non-root protocol record
353
+ this._message.contextId = this.parentContextId + '/' + this._message.recordId;
354
+ }
355
+ }
356
+ // `signature` generation
357
+ const signature = yield RecordsWrite.createSignerSignature({
358
+ recordId: this._message.recordId,
359
+ contextId: this._message.contextId,
360
+ descriptorCid,
361
+ attestation: this._message.attestation,
362
+ encryption: this._message.encryption,
363
+ signer,
364
+ delegatedGrantId,
365
+ permissionGrantId,
366
+ protocolRole
367
+ });
368
+ this._message.authorization = { signature };
369
+ if (delegatedGrant !== undefined) {
370
+ this._message.authorization.authorDelegatedGrant = delegatedGrant;
371
+ }
372
+ // there is opportunity to optimize here as the payload is constructed within `createAuthorization(...)`
373
+ this._signaturePayload = Jws.decodePlainObjectPayload(signature);
374
+ this._author = authorDid;
375
+ });
376
+ }
377
+ /**
378
+ * Signs the `RecordsWrite` as the DWN owner.
379
+ * This is used when the DWN owner wants to retain a copy of a message that the owner did not author.
380
+ * NOTE: requires the `RecordsWrite` to already have the author's signature.
381
+ */
382
+ signAsOwner(signer) {
383
+ return __awaiter(this, void 0, void 0, function* () {
384
+ if (this._author === undefined) {
385
+ throw new DwnError(DwnErrorCode.RecordsWriteSignAsOwnerUnknownAuthor, 'Unable to sign as owner without message signature because owner needs to sign over `recordId` which depends on author DID.');
386
+ }
387
+ const descriptor = this._message.descriptor;
388
+ const ownerSignature = yield Message.createSignature(descriptor, signer);
389
+ this._message.authorization.ownerSignature = ownerSignature;
390
+ this._ownerSignaturePayload = Jws.decodePlainObjectPayload(ownerSignature);
391
+ this._owner = Jws.extractDid(signer.keyId);
392
+ ;
393
+ });
394
+ }
395
+ /**
396
+ * Signs the `RecordsWrite` as the DWN owner-delegate.
397
+ * This is used when a DWN owner-delegate wants to retain a copy of a message that the owner did not author.
398
+ * NOTE: requires the `RecordsWrite` to already have the author's signature.
399
+ */
400
+ signAsOwnerDelegate(signer, delegatedGrant) {
401
+ return __awaiter(this, void 0, void 0, function* () {
402
+ if (this._author === undefined) {
403
+ throw new DwnError(DwnErrorCode.RecordsWriteSignAsOwnerDelegateUnknownAuthor, 'Unable to sign as owner delegate without message signature because owner delegate needs to sign over `recordId` which depends on author DID.');
404
+ }
405
+ const delegatedGrantId = yield Message.getCid(delegatedGrant);
406
+ const descriptor = this._message.descriptor;
407
+ const ownerSignature = yield Message.createSignature(descriptor, signer, { delegatedGrantId });
408
+ this._message.authorization.ownerSignature = ownerSignature;
409
+ this._message.authorization.ownerDelegatedGrant = delegatedGrant;
410
+ this._ownerSignaturePayload = Jws.decodePlainObjectPayload(ownerSignature);
411
+ this._owner = Jws.getSignerDid(delegatedGrant.authorization.signature.signatures[0]);
412
+ });
413
+ }
414
+ /**
415
+ * Validates the integrity of the RecordsWrite message assuming the message passed basic schema validation.
416
+ * There is opportunity to integrate better with `validateSchema(...)`
417
+ */
418
+ validateIntegrity() {
419
+ return __awaiter(this, void 0, void 0, function* () {
420
+ // if the new message is the initial write
421
+ const isInitialWrite = yield this.isInitialWrite();
422
+ if (isInitialWrite) {
423
+ // `messageTimestamp` and `dateCreated` equality check
424
+ const dateRecordCreated = this.message.descriptor.dateCreated;
425
+ const messageTimestamp = this.message.descriptor.messageTimestamp;
426
+ if (messageTimestamp !== dateRecordCreated) {
427
+ throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityDateCreatedMismatch, `messageTimestamp ${messageTimestamp} must match dateCreated ${dateRecordCreated} for the initial write`);
428
+ }
429
+ // if the message is also a protocol context root, the `contextId` must match the expected deterministic value
430
+ if (this.message.descriptor.protocol !== undefined &&
431
+ this.message.descriptor.parentId === undefined) {
432
+ const expectedContextId = yield this.getEntryId();
433
+ if (this.message.contextId !== expectedContextId) {
434
+ throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityContextIdMismatch, `contextId in message: ${this.message.contextId} does not match deterministic contextId: ${expectedContextId}`);
435
+ }
436
+ }
437
+ }
438
+ // NOTE: validateSignatureStructure() call earlier enforces the presence of `authorization` and thus `signature` in RecordsWrite
439
+ const signaturePayload = this.signaturePayload;
440
+ // make sure the `recordId` in message is the same as the `recordId` in the payload of the message signature
441
+ if (this.message.recordId !== signaturePayload.recordId) {
442
+ throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityRecordIdUnauthorized, `recordId in message ${this.message.recordId} does not match recordId in authorization: ${signaturePayload.recordId}`);
443
+ }
444
+ // if `contextId` is given in message, make sure the same `contextId` is in the payload of the message signature
445
+ if (this.message.contextId !== signaturePayload.contextId) {
446
+ throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityContextIdNotInSignerSignaturePayload, `contextId in message ${this.message.contextId} does not match contextId in authorization: ${signaturePayload.contextId}`);
447
+ }
448
+ yield Records.validateDelegatedGrantReferentialIntegrity(this.message, signaturePayload, this.ownerSignaturePayload);
449
+ // if `attestation` is given in message, make sure the correct `attestationCid` is in the payload of the message signature
450
+ if (signaturePayload.attestationCid !== undefined) {
451
+ const expectedAttestationCid = yield Cid.computeCid(this.message.attestation);
452
+ const actualAttestationCid = signaturePayload.attestationCid;
453
+ if (actualAttestationCid !== expectedAttestationCid) {
454
+ throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityAttestationMismatch, `CID ${expectedAttestationCid} of attestation property in message does not match attestationCid in authorization: ${actualAttestationCid}`);
455
+ }
456
+ }
457
+ // if `encryption` is given in message, make sure the correct `encryptionCid` is in the payload of the message signature
458
+ if (signaturePayload.encryptionCid !== undefined) {
459
+ const expectedEncryptionCid = yield Cid.computeCid(this.message.encryption);
460
+ const actualEncryptionCid = signaturePayload.encryptionCid;
461
+ if (actualEncryptionCid !== expectedEncryptionCid) {
462
+ throw new DwnError(DwnErrorCode.RecordsWriteValidateIntegrityEncryptionCidMismatch, `CID ${expectedEncryptionCid} of encryption property in message does not match encryptionCid in authorization: ${actualEncryptionCid}`);
463
+ }
464
+ }
465
+ if (this.message.descriptor.protocol !== undefined) {
466
+ validateProtocolUrlNormalized(this.message.descriptor.protocol);
467
+ }
468
+ if (this.message.descriptor.schema !== undefined) {
469
+ validateSchemaUrlNormalized(this.message.descriptor.schema);
470
+ }
471
+ Time.validateTimestamp(this.message.descriptor.messageTimestamp);
472
+ Time.validateTimestamp(this.message.descriptor.dateCreated);
473
+ if (this.message.descriptor.datePublished) {
474
+ Time.validateTimestamp(this.message.descriptor.datePublished);
475
+ }
476
+ });
477
+ }
478
+ /**
479
+ * Validates the structural integrity of the `attestation` property.
480
+ * NOTE: signature is not verified.
481
+ */
482
+ static validateAttestationIntegrity(message) {
483
+ return __awaiter(this, void 0, void 0, function* () {
484
+ if (message.attestation === undefined) {
485
+ return;
486
+ }
487
+ // TODO: multi-attesters to be unblocked by #205 - Revisit database interfaces (https://github.com/TBD54566975/dwn-sdk-js/issues/205)
488
+ if (message.attestation.signatures.length !== 1) {
489
+ throw new DwnError(DwnErrorCode.RecordsWriteAttestationIntegrityMoreThanOneSignature, `Currently implementation only supports 1 attester, but got ${message.attestation.signatures.length}`);
490
+ }
491
+ const payloadJson = Jws.decodePlainObjectPayload(message.attestation);
492
+ const { descriptorCid } = payloadJson;
493
+ // `descriptorCid` validation - ensure that the provided descriptorCid matches the CID of the actual message
494
+ const expectedDescriptorCid = yield Cid.computeCid(message.descriptor);
495
+ if (descriptorCid !== expectedDescriptorCid) {
496
+ throw new DwnError(DwnErrorCode.RecordsWriteAttestationIntegrityDescriptorCidMismatch, `descriptorCid ${descriptorCid} does not match expected descriptorCid ${expectedDescriptorCid}`);
497
+ }
498
+ // check to ensure that no other unexpected properties exist in payload.
499
+ const propertyCount = Object.keys(payloadJson).length;
500
+ if (propertyCount > 1) {
501
+ throw new DwnError(DwnErrorCode.RecordsWriteAttestationIntegrityInvalidPayloadProperty, `Only 'descriptorCid' is allowed in attestation payload, but got ${propertyCount} properties.`);
502
+ }
503
+ });
504
+ }
505
+ ;
506
+ /**
507
+ * Computes the deterministic Entry ID of this message.
508
+ */
509
+ getEntryId() {
510
+ return __awaiter(this, void 0, void 0, function* () {
511
+ const entryId = yield RecordsWrite.getEntryId(this.author, this.message.descriptor);
512
+ return entryId;
513
+ });
514
+ }
515
+ ;
516
+ /**
517
+ * Computes the deterministic Entry ID of this message.
518
+ */
519
+ static getEntryId(author, descriptor) {
520
+ return __awaiter(this, void 0, void 0, function* () {
521
+ if (author === undefined) {
522
+ throw new DwnError(DwnErrorCode.RecordsWriteGetEntryIdUndefinedAuthor, 'Property `author` is needed to compute entry ID.');
523
+ }
524
+ const entryIdInput = Object.assign({}, descriptor);
525
+ entryIdInput.author = author;
526
+ const cid = yield Cid.computeCid(entryIdInput);
527
+ return cid;
528
+ });
529
+ }
530
+ ;
531
+ /**
532
+ * Checks if the given message is the initial entry of a record.
533
+ */
534
+ isInitialWrite() {
535
+ return __awaiter(this, void 0, void 0, function* () {
536
+ const entryId = yield this.getEntryId();
537
+ return (entryId === this.message.recordId);
538
+ });
539
+ }
540
+ constructIndexes(isLatestBaseState) {
541
+ return __awaiter(this, void 0, void 0, function* () {
542
+ const message = this.message;
543
+ // we want to process tags separately from the rest of descriptors as it is an object and not a primitive KeyValue type.
544
+ const _a = message.descriptor, { tags } = _a, descriptor = __rest(_a, ["tags"]);
545
+ delete descriptor.published; // handle `published` specifically further down
546
+ let indexes = Object.assign(Object.assign({}, descriptor), { isLatestBaseState, published: !!message.descriptor.published, author: this.author, recordId: message.recordId, entryId: yield RecordsWrite.getEntryId(this.author, this.message.descriptor) });
547
+ // in order to avoid name clashes with first-class index keys
548
+ // we build the indexes with `tag.property_name` for each tag property.
549
+ // we only index tags if the message is the latest base state, as that's the only time filtering for tags is relevant.
550
+ if (tags !== undefined && isLatestBaseState === true) {
551
+ const flattenedTags = Records.buildTagIndexes(Object.assign({}, tags));
552
+ indexes = Object.assign(Object.assign({}, indexes), flattenedTags);
553
+ }
554
+ // add additional indexes to optional values if given
555
+ // TODO: index multi-attesters to be unblocked by #205 - Revisit database interfaces (https://github.com/TBD54566975/dwn-sdk-js/issues/205)
556
+ if (this.attesters.length > 0) {
557
+ indexes.attester = this.attesters[0];
558
+ }
559
+ if (message.contextId !== undefined) {
560
+ indexes.contextId = message.contextId;
561
+ }
562
+ return indexes;
563
+ });
564
+ }
565
+ /**
566
+ * Authorizes the author-delegate who signed this message.
567
+ * @param messageStore Used to check if the grant has been revoked.
568
+ */
569
+ authorizeAuthorDelegate(messageStore) {
570
+ return __awaiter(this, void 0, void 0, function* () {
571
+ const delegatedGrant = yield PermissionGrant.parse(this.message.authorization.authorDelegatedGrant);
572
+ yield RecordsGrantAuthorization.authorizeWrite({
573
+ recordsWriteMessage: this.message,
574
+ expectedGrantor: this.author,
575
+ expectedGrantee: this.signer,
576
+ permissionGrant: delegatedGrant,
577
+ messageStore
578
+ });
579
+ });
580
+ }
581
+ /**
582
+ * Authorizes the owner-delegate who signed this message.
583
+ * @param messageStore Used to check if the grant has been revoked.
584
+ */
585
+ authorizeOwnerDelegate(messageStore) {
586
+ return __awaiter(this, void 0, void 0, function* () {
587
+ const delegatedGrant = yield PermissionGrant.parse(this.message.authorization.ownerDelegatedGrant);
588
+ yield RecordsGrantAuthorization.authorizeWrite({
589
+ recordsWriteMessage: this.message,
590
+ expectedGrantor: this.owner,
591
+ expectedGrantee: this.ownerSignatureSigner,
592
+ permissionGrant: delegatedGrant,
593
+ messageStore
594
+ });
595
+ });
596
+ }
597
+ /**
598
+ * Checks if the given message is the initial entry of a record.
599
+ */
600
+ static isInitialWrite(message) {
601
+ return __awaiter(this, void 0, void 0, function* () {
602
+ // can't be the initial write if the message is not a Records Write
603
+ if (message.descriptor.interface !== DwnInterfaceName.Records ||
604
+ message.descriptor.method !== DwnMethodName.Write) {
605
+ return false;
606
+ }
607
+ const recordsWriteMessage = message;
608
+ const author = Message.getAuthor(recordsWriteMessage);
609
+ const entryId = yield RecordsWrite.getEntryId(author, recordsWriteMessage.descriptor);
610
+ return (entryId === recordsWriteMessage.recordId);
611
+ });
612
+ }
613
+ /**
614
+ * Creates the `encryption` property if encryption input is given. Else `undefined` is returned.
615
+ * @param descriptor Descriptor of the `RecordsWrite` message which contains the information need by key path derivation schemes.
616
+ */
617
+ static createEncryptionProperty(descriptor, encryptionInput) {
618
+ return __awaiter(this, void 0, void 0, function* () {
619
+ var _a, _b;
620
+ if (encryptionInput === undefined) {
621
+ return undefined;
622
+ }
623
+ // encrypt the data encryption key once per encryption input
624
+ const keyEncryption = [];
625
+ for (const keyEncryptionInput of encryptionInput.keyEncryptionInputs) {
626
+ if (keyEncryptionInput.derivationScheme === KeyDerivationScheme.ProtocolPath && descriptor.protocol === undefined) {
627
+ throw new DwnError(DwnErrorCode.RecordsWriteMissingProtocol, '`protocols` encryption scheme cannot be applied to record without the `protocol` property.');
628
+ }
629
+ if (keyEncryptionInput.derivationScheme === KeyDerivationScheme.Schemas && descriptor.schema === undefined) {
630
+ throw new DwnError(DwnErrorCode.RecordsWriteMissingSchema, '`schemas` encryption scheme cannot be applied to record without the `schema` property.');
631
+ }
632
+ // NOTE: right now only `ECIES-ES256K` algorithm is supported for asymmetric encryption,
633
+ // so we will assume that's the algorithm without additional switch/if statements
634
+ const publicKeyBytes = Secp256k1.publicJwkToBytes(keyEncryptionInput.publicKey);
635
+ const keyEncryptionOutput = yield Encryption.eciesSecp256k1Encrypt(publicKeyBytes, encryptionInput.key);
636
+ const encryptedKey = Encoder.bytesToBase64Url(keyEncryptionOutput.ciphertext);
637
+ const ephemeralPublicKey = yield Secp256k1.publicKeyToJwk(keyEncryptionOutput.ephemeralPublicKey);
638
+ const keyEncryptionInitializationVector = Encoder.bytesToBase64Url(keyEncryptionOutput.initializationVector);
639
+ const messageAuthenticationCode = Encoder.bytesToBase64Url(keyEncryptionOutput.messageAuthenticationCode);
640
+ const encryptedKeyData = {
641
+ rootKeyId: keyEncryptionInput.publicKeyId,
642
+ algorithm: (_a = keyEncryptionInput.algorithm) !== null && _a !== void 0 ? _a : EncryptionAlgorithm.EciesSecp256k1,
643
+ derivationScheme: keyEncryptionInput.derivationScheme,
644
+ ephemeralPublicKey,
645
+ initializationVector: keyEncryptionInitializationVector,
646
+ messageAuthenticationCode,
647
+ encryptedKey
648
+ };
649
+ // we need to attach the actual public key if derivation scheme is protocol-context,
650
+ // so that the responder to this message is able to encrypt the message/symmetric key using the same protocol-context derived public key,
651
+ // without needing the knowledge of the corresponding private key
652
+ if (keyEncryptionInput.derivationScheme === KeyDerivationScheme.ProtocolContext) {
653
+ encryptedKeyData.derivedPublicKey = keyEncryptionInput.publicKey;
654
+ }
655
+ keyEncryption.push(encryptedKeyData);
656
+ }
657
+ const encryption = {
658
+ algorithm: (_b = encryptionInput.algorithm) !== null && _b !== void 0 ? _b : EncryptionAlgorithm.Aes256Ctr,
659
+ initializationVector: Encoder.bytesToBase64Url(encryptionInput.initializationVector),
660
+ keyEncryption
661
+ };
662
+ return encryption;
663
+ });
664
+ }
665
+ /**
666
+ * Creates the `attestation` property of a RecordsWrite message if given signature inputs; returns `undefined` otherwise.
667
+ */
668
+ static createAttestation(descriptorCid, signers) {
669
+ return __awaiter(this, void 0, void 0, function* () {
670
+ if (signers === undefined || signers.length === 0) {
671
+ return undefined;
672
+ }
673
+ const attestationPayload = { descriptorCid };
674
+ const attestationPayloadBytes = Encoder.objectToBytes(attestationPayload);
675
+ const builder = yield GeneralJwsBuilder.create(attestationPayloadBytes, signers);
676
+ return builder.getJws();
677
+ });
678
+ }
679
+ /**
680
+ * Creates the `signature` property in the `authorization` of a `RecordsWrite` message.
681
+ */
682
+ static createSignerSignature(input) {
683
+ return __awaiter(this, void 0, void 0, function* () {
684
+ const { recordId, contextId, descriptorCid, attestation, encryption, signer, delegatedGrantId, permissionGrantId, protocolRole } = input;
685
+ const attestationCid = attestation ? yield Cid.computeCid(attestation) : undefined;
686
+ const encryptionCid = encryption ? yield Cid.computeCid(encryption) : undefined;
687
+ const signaturePayload = {
688
+ recordId,
689
+ descriptorCid,
690
+ contextId,
691
+ attestationCid,
692
+ encryptionCid,
693
+ delegatedGrantId,
694
+ permissionGrantId,
695
+ protocolRole
696
+ };
697
+ removeUndefinedProperties(signaturePayload);
698
+ const signaturePayloadBytes = Encoder.objectToBytes(signaturePayload);
699
+ const builder = yield GeneralJwsBuilder.create(signaturePayloadBytes, [signer]);
700
+ const signature = builder.getJws();
701
+ return signature;
702
+ });
703
+ }
704
+ /**
705
+ * Gets the initial write from the given list of `RecordsWrite`.
706
+ */
707
+ static getInitialWrite(messages) {
708
+ return __awaiter(this, void 0, void 0, function* () {
709
+ for (const message of messages) {
710
+ if (yield RecordsWrite.isInitialWrite(message)) {
711
+ return message;
712
+ }
713
+ }
714
+ throw new DwnError(DwnErrorCode.RecordsWriteGetInitialWriteNotFound, `Initial write is not found.`);
715
+ });
716
+ }
717
+ /**
718
+ * Verifies that immutable properties of the two given messages are identical.
719
+ * @throws {Error} if immutable properties between two RecordsWrite message
720
+ */
721
+ static verifyEqualityOfImmutableProperties(existingWriteMessage, newMessage) {
722
+ const mutableDescriptorProperties = ['dataCid', 'dataSize', 'dataFormat', 'datePublished', 'published', 'messageTimestamp', 'tags'];
723
+ // get distinct property names that exist in either the existing message given or new message
724
+ let descriptorPropertyNames = [];
725
+ descriptorPropertyNames.push(...Object.keys(existingWriteMessage.descriptor));
726
+ descriptorPropertyNames.push(...Object.keys(newMessage.descriptor));
727
+ descriptorPropertyNames = [...new Set(descriptorPropertyNames)]; // step to remove duplicates
728
+ // ensure all immutable properties are not modified
729
+ for (const descriptorPropertyName of descriptorPropertyNames) {
730
+ // if property is supposed to be immutable
731
+ if (mutableDescriptorProperties.indexOf(descriptorPropertyName) === -1) {
732
+ const valueInExistingWrite = existingWriteMessage.descriptor[descriptorPropertyName];
733
+ const valueInNewMessage = newMessage.descriptor[descriptorPropertyName];
734
+ if (valueInNewMessage !== valueInExistingWrite) {
735
+ throw new DwnError(DwnErrorCode.RecordsWriteImmutablePropertyChanged, `${descriptorPropertyName} is an immutable property: cannot change '${valueInExistingWrite}' to '${valueInNewMessage}'`);
736
+ }
737
+ }
738
+ }
739
+ return true;
740
+ }
741
+ /**
742
+ * Gets the DID of the attesters of the given message.
743
+ */
744
+ static getAttesters(message) {
745
+ var _a, _b;
746
+ const attestationSignatures = (_b = (_a = message.attestation) === null || _a === void 0 ? void 0 : _a.signatures) !== null && _b !== void 0 ? _b : [];
747
+ const attesters = attestationSignatures.map((signature) => Jws.getSignerDid(signature));
748
+ return attesters;
749
+ }
750
+ static fetchNewestRecordsWrite(messageStore, tenant, recordId) {
751
+ return __awaiter(this, void 0, void 0, function* () {
752
+ // get existing RecordsWrite messages matching the `recordId`
753
+ const query = {
754
+ interface: DwnInterfaceName.Records,
755
+ method: DwnMethodName.Write,
756
+ recordId: recordId
757
+ };
758
+ const { messages: existingMessages } = yield messageStore.query(tenant, [query]);
759
+ const newestWrite = yield Message.getNewestMessage(existingMessages);
760
+ if (newestWrite !== undefined) {
761
+ return newestWrite;
762
+ }
763
+ throw new DwnError(DwnErrorCode.RecordsWriteGetNewestWriteRecordNotFound, 'record not found');
764
+ });
765
+ }
766
+ /**
767
+ * Fetches the initial RecordsWrite of a record.
768
+ * @returns The initial RecordsWrite if found; `undefined` otherwise.
769
+ */
770
+ static fetchInitialRecordsWrite(messageStore, tenant, recordId) {
771
+ return __awaiter(this, void 0, void 0, function* () {
772
+ const initialRecordsWriteMessage = yield RecordsWrite.fetchInitialRecordsWriteMessage(messageStore, tenant, recordId);
773
+ if (initialRecordsWriteMessage === undefined) {
774
+ return undefined;
775
+ }
776
+ const initialRecordsWrite = yield RecordsWrite.parse(initialRecordsWriteMessage);
777
+ return initialRecordsWrite;
778
+ });
779
+ }
780
+ /**
781
+ * Fetches the initial RecordsWrite message of a record.
782
+ * @returns The initial RecordsWriteMessage if found; `undefined` otherwise.
783
+ */
784
+ static fetchInitialRecordsWriteMessage(messageStore, tenant, recordId) {
785
+ return __awaiter(this, void 0, void 0, function* () {
786
+ const query = { entryId: recordId };
787
+ const { messages } = yield messageStore.query(tenant, [query]);
788
+ if (messages.length === 0) {
789
+ return undefined;
790
+ }
791
+ return messages[0];
792
+ });
793
+ }
794
+ }
795
+ //# sourceMappingURL=records-write.js.map