@abaxxtech/id 0.0.0

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