@pkcprotocol/pkc-js 0.0.11

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 (843) hide show
  1. package/LICENSE +339 -0
  2. package/README.md +1663 -0
  3. package/dist/browser/challenges.d.ts +1 -0
  4. package/dist/browser/challenges.js +2 -0
  5. package/dist/browser/challenges.js.map +1 -0
  6. package/dist/browser/clients/base-client-manager.d.ts +126 -0
  7. package/dist/browser/clients/base-client-manager.js +673 -0
  8. package/dist/browser/clients/base-client-manager.js.map +1 -0
  9. package/dist/browser/clients/name-resolver-client.d.ts +8 -0
  10. package/dist/browser/clients/name-resolver-client.js +10 -0
  11. package/dist/browser/clients/name-resolver-client.js.map +1 -0
  12. package/dist/browser/clients/pkc-typed-emitter.d.ts +9 -0
  13. package/dist/browser/clients/pkc-typed-emitter.js +52 -0
  14. package/dist/browser/clients/pkc-typed-emitter.js.map +1 -0
  15. package/dist/browser/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
  16. package/dist/browser/clients/rpc-client/decode-rpc-response-util.js +53 -0
  17. package/dist/browser/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
  18. package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
  19. package/dist/browser/clients/rpc-client/pkc-rpc-client.js +404 -0
  20. package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -0
  21. package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +147 -0
  22. package/dist/browser/clients/rpc-client/rpc-schema-util.js +11 -0
  23. package/dist/browser/clients/rpc-client/rpc-schema-util.js.map +1 -0
  24. package/dist/browser/clients/rpc-client/schema.d.ts +433 -0
  25. package/dist/browser/clients/rpc-client/schema.js +49 -0
  26. package/dist/browser/clients/rpc-client/schema.js.map +1 -0
  27. package/dist/browser/clients/rpc-client/types.d.ts +8 -0
  28. package/dist/browser/clients/rpc-client/types.js +2 -0
  29. package/dist/browser/clients/rpc-client/types.js.map +1 -0
  30. package/dist/browser/community/community-client-manager.d.ts +60 -0
  31. package/dist/browser/community/community-client-manager.js +717 -0
  32. package/dist/browser/community/community-client-manager.js.map +1 -0
  33. package/dist/browser/community/community-clients.d.ts +18 -0
  34. package/dist/browser/community/community-clients.js +12 -0
  35. package/dist/browser/community/community-clients.js.map +1 -0
  36. package/dist/browser/community/community-wire.d.ts +20 -0
  37. package/dist/browser/community/community-wire.js +38 -0
  38. package/dist/browser/community/community-wire.js.map +1 -0
  39. package/dist/browser/community/remote-community.d.ts +110 -0
  40. package/dist/browser/community/remote-community.js +555 -0
  41. package/dist/browser/community/remote-community.js.map +1 -0
  42. package/dist/browser/community/rpc-local-community.d.ts +41 -0
  43. package/dist/browser/community/rpc-local-community.js +289 -0
  44. package/dist/browser/community/rpc-local-community.js.map +1 -0
  45. package/dist/browser/community/rpc-remote-community.d.ts +18 -0
  46. package/dist/browser/community/rpc-remote-community.js +286 -0
  47. package/dist/browser/community/rpc-remote-community.js.map +1 -0
  48. package/dist/browser/community/schema.d.ts +4217 -0
  49. package/dist/browser/community/schema.js +289 -0
  50. package/dist/browser/community/schema.js.map +1 -0
  51. package/dist/browser/community/types.d.ts +135 -0
  52. package/dist/browser/community/types.js +2 -0
  53. package/dist/browser/community/types.js.map +1 -0
  54. package/dist/browser/constants.d.ts +6 -0
  55. package/dist/browser/constants.js +9 -0
  56. package/dist/browser/constants.js.map +1 -0
  57. package/dist/browser/decorator-util.d.ts +1 -0
  58. package/dist/browser/decorator-util.js +35 -0
  59. package/dist/browser/decorator-util.js.map +1 -0
  60. package/dist/browser/errors.d.ts +343 -0
  61. package/dist/browser/errors.js +358 -0
  62. package/dist/browser/errors.js.map +1 -0
  63. package/dist/browser/general-util/limited-set.d.ts +15 -0
  64. package/dist/browser/general-util/limited-set.js +66 -0
  65. package/dist/browser/general-util/limited-set.js.map +1 -0
  66. package/dist/browser/generated-version.d.ts +1 -0
  67. package/dist/browser/generated-version.js +3 -0
  68. package/dist/browser/generated-version.js.map +1 -0
  69. package/dist/browser/generic-state-client.d.ts +6 -0
  70. package/dist/browser/generic-state-client.js +11 -0
  71. package/dist/browser/generic-state-client.js.map +1 -0
  72. package/dist/browser/helia/helia-for-pkc.d.ts +3 -0
  73. package/dist/browser/helia/helia-for-pkc.js +255 -0
  74. package/dist/browser/helia/helia-for-pkc.js.map +1 -0
  75. package/dist/browser/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
  76. package/dist/browser/helia/ipns-over-pubsub-with-fetch.js +229 -0
  77. package/dist/browser/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
  78. package/dist/browser/helia/libp2pjsClient.d.ts +27 -0
  79. package/dist/browser/helia/libp2pjsClient.js +15 -0
  80. package/dist/browser/helia/libp2pjsClient.js.map +1 -0
  81. package/dist/browser/helia/types.d.ts +19 -0
  82. package/dist/browser/helia/types.js +2 -0
  83. package/dist/browser/helia/types.js.map +1 -0
  84. package/dist/browser/helia/util.d.ts +13 -0
  85. package/dist/browser/helia/util.js +98 -0
  86. package/dist/browser/helia/util.js.map +1 -0
  87. package/dist/browser/index.d.ts +244 -0
  88. package/dist/browser/index.js +36 -0
  89. package/dist/browser/index.js.map +1 -0
  90. package/dist/browser/logger.d.ts +12 -0
  91. package/dist/browser/logger.js +11 -0
  92. package/dist/browser/logger.js.map +1 -0
  93. package/dist/browser/pages/pages-client-manager.d.ts +159 -0
  94. package/dist/browser/pages/pages-client-manager.js +334 -0
  95. package/dist/browser/pages/pages-client-manager.js.map +1 -0
  96. package/dist/browser/pages/pages-clients.d.ts +11 -0
  97. package/dist/browser/pages/pages-clients.js +10 -0
  98. package/dist/browser/pages/pages-clients.js.map +1 -0
  99. package/dist/browser/pages/pages.d.ts +107 -0
  100. package/dist/browser/pages/pages.js +262 -0
  101. package/dist/browser/pages/pages.js.map +1 -0
  102. package/dist/browser/pages/schema-util.d.ts +3 -0
  103. package/dist/browser/pages/schema-util.js +3 -0
  104. package/dist/browser/pages/schema-util.js.map +1 -0
  105. package/dist/browser/pages/schema.d.ts +719 -0
  106. package/dist/browser/pages/schema.js +32 -0
  107. package/dist/browser/pages/schema.js.map +1 -0
  108. package/dist/browser/pages/types.d.ts +44 -0
  109. package/dist/browser/pages/types.js +2 -0
  110. package/dist/browser/pages/types.js.map +1 -0
  111. package/dist/browser/pages/util.d.ts +56 -0
  112. package/dist/browser/pages/util.js +446 -0
  113. package/dist/browser/pages/util.js.map +1 -0
  114. package/dist/browser/pkc/pkc-client-manager.d.ts +44 -0
  115. package/dist/browser/pkc/pkc-client-manager.js +156 -0
  116. package/dist/browser/pkc/pkc-client-manager.js.map +1 -0
  117. package/dist/browser/pkc/pkc-clients.d.ts +11 -0
  118. package/dist/browser/pkc/pkc-clients.js +8 -0
  119. package/dist/browser/pkc/pkc-clients.js.map +1 -0
  120. package/dist/browser/pkc/pkc-with-rpc-client.d.ts +19 -0
  121. package/dist/browser/pkc/pkc-with-rpc-client.js +128 -0
  122. package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -0
  123. package/dist/browser/pkc/pkc.d.ts +137 -0
  124. package/dist/browser/pkc/pkc.js +888 -0
  125. package/dist/browser/pkc/pkc.js.map +1 -0
  126. package/dist/browser/pkc/tracked-instance-registry-util.d.ts +44 -0
  127. package/dist/browser/pkc/tracked-instance-registry-util.js +106 -0
  128. package/dist/browser/pkc/tracked-instance-registry-util.js.map +1 -0
  129. package/dist/browser/pkc/tracked-instance-registry.d.ts +18 -0
  130. package/dist/browser/pkc/tracked-instance-registry.js +134 -0
  131. package/dist/browser/pkc/tracked-instance-registry.js.map +1 -0
  132. package/dist/browser/pkc-error.d.ts +65 -0
  133. package/dist/browser/pkc-error.js +137 -0
  134. package/dist/browser/pkc-error.js.map +1 -0
  135. package/dist/browser/publications/comment/comment-client-manager.d.ts +86 -0
  136. package/dist/browser/publications/comment/comment-client-manager.js +908 -0
  137. package/dist/browser/publications/comment/comment-client-manager.js.map +1 -0
  138. package/dist/browser/publications/comment/comment-clients.d.ts +19 -0
  139. package/dist/browser/publications/comment/comment-clients.js +12 -0
  140. package/dist/browser/publications/comment/comment-clients.js.map +1 -0
  141. package/dist/browser/publications/comment/comment-util.d.ts +10 -0
  142. package/dist/browser/publications/comment/comment-util.js +202 -0
  143. package/dist/browser/publications/comment/comment-util.js.map +1 -0
  144. package/dist/browser/publications/comment/comment.d.ts +147 -0
  145. package/dist/browser/publications/comment/comment.js +1044 -0
  146. package/dist/browser/publications/comment/comment.js.map +1 -0
  147. package/dist/browser/publications/comment/schema.d.ts +1237 -0
  148. package/dist/browser/publications/comment/schema.js +184 -0
  149. package/dist/browser/publications/comment/schema.js.map +1 -0
  150. package/dist/browser/publications/comment/types.d.ts +100 -0
  151. package/dist/browser/publications/comment/types.js +2 -0
  152. package/dist/browser/publications/comment/types.js.map +1 -0
  153. package/dist/browser/publications/comment-edit/comment-edit.d.ts +41 -0
  154. package/dist/browser/publications/comment-edit/comment-edit.js +63 -0
  155. package/dist/browser/publications/comment-edit/comment-edit.js.map +1 -0
  156. package/dist/browser/publications/comment-edit/schema.d.ts +295 -0
  157. package/dist/browser/publications/comment-edit/schema.js +55 -0
  158. package/dist/browser/publications/comment-edit/schema.js.map +1 -0
  159. package/dist/browser/publications/comment-edit/types.d.ts +25 -0
  160. package/dist/browser/publications/comment-edit/types.js +2 -0
  161. package/dist/browser/publications/comment-edit/types.js.map +1 -0
  162. package/dist/browser/publications/comment-moderation/comment-moderation.d.ts +36 -0
  163. package/dist/browser/publications/comment-moderation/comment-moderation.js +53 -0
  164. package/dist/browser/publications/comment-moderation/comment-moderation.js.map +1 -0
  165. package/dist/browser/publications/comment-moderation/schema.d.ts +315 -0
  166. package/dist/browser/publications/comment-moderation/schema.js +62 -0
  167. package/dist/browser/publications/comment-moderation/schema.js.map +1 -0
  168. package/dist/browser/publications/comment-moderation/types.d.ts +22 -0
  169. package/dist/browser/publications/comment-moderation/types.js +2 -0
  170. package/dist/browser/publications/comment-moderation/types.js.map +1 -0
  171. package/dist/browser/publications/community-edit/community-edit.d.ts +35 -0
  172. package/dist/browser/publications/community-edit/community-edit.js +50 -0
  173. package/dist/browser/publications/community-edit/community-edit.js.map +1 -0
  174. package/dist/browser/publications/community-edit/schema.d.ts +467 -0
  175. package/dist/browser/publications/community-edit/schema.js +36 -0
  176. package/dist/browser/publications/community-edit/schema.js.map +1 -0
  177. package/dist/browser/publications/community-edit/types.d.ts +19 -0
  178. package/dist/browser/publications/community-edit/types.js +2 -0
  179. package/dist/browser/publications/community-edit/types.js.map +1 -0
  180. package/dist/browser/publications/publication-author.d.ts +22 -0
  181. package/dist/browser/publications/publication-author.js +66 -0
  182. package/dist/browser/publications/publication-author.js.map +1 -0
  183. package/dist/browser/publications/publication-client-manager.d.ts +62 -0
  184. package/dist/browser/publications/publication-client-manager.js +257 -0
  185. package/dist/browser/publications/publication-client-manager.js.map +1 -0
  186. package/dist/browser/publications/publication-clients.d.ts +19 -0
  187. package/dist/browser/publications/publication-clients.js +12 -0
  188. package/dist/browser/publications/publication-clients.js.map +1 -0
  189. package/dist/browser/publications/publication-community.d.ts +55 -0
  190. package/dist/browser/publications/publication-community.js +87 -0
  191. package/dist/browser/publications/publication-community.js.map +1 -0
  192. package/dist/browser/publications/publication.d.ts +120 -0
  193. package/dist/browser/publications/publication.js +950 -0
  194. package/dist/browser/publications/publication.js.map +1 -0
  195. package/dist/browser/publications/types.d.ts +26 -0
  196. package/dist/browser/publications/types.js +2 -0
  197. package/dist/browser/publications/types.js.map +1 -0
  198. package/dist/browser/publications/vote/schema.d.ts +150 -0
  199. package/dist/browser/publications/vote/schema.js +44 -0
  200. package/dist/browser/publications/vote/schema.js.map +1 -0
  201. package/dist/browser/publications/vote/types.d.ts +21 -0
  202. package/dist/browser/publications/vote/types.js +2 -0
  203. package/dist/browser/publications/vote/types.js.map +1 -0
  204. package/dist/browser/publications/vote/vote.d.ts +36 -0
  205. package/dist/browser/publications/vote/vote.js +49 -0
  206. package/dist/browser/publications/vote/vote.js.map +1 -0
  207. package/dist/browser/pubsub-messages/schema.d.ts +964 -0
  208. package/dist/browser/pubsub-messages/schema.js +98 -0
  209. package/dist/browser/pubsub-messages/schema.js.map +1 -0
  210. package/dist/browser/pubsub-messages/types.d.ts +81 -0
  211. package/dist/browser/pubsub-messages/types.js +2 -0
  212. package/dist/browser/pubsub-messages/types.js.map +1 -0
  213. package/dist/browser/rpc/src/index.d.ts +483 -0
  214. package/dist/browser/rpc/src/index.js +1267 -0
  215. package/dist/browser/rpc/src/index.js.map +1 -0
  216. package/dist/browser/rpc/src/json-rpc-util.d.ts +1 -0
  217. package/dist/browser/rpc/src/json-rpc-util.js +19 -0
  218. package/dist/browser/rpc/src/json-rpc-util.js.map +1 -0
  219. package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +132 -0
  220. package/dist/browser/rpc/src/lib/pkc-js/index.js +29 -0
  221. package/dist/browser/rpc/src/lib/pkc-js/index.js.map +1 -0
  222. package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
  223. package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
  224. package/dist/browser/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
  225. package/dist/browser/rpc/src/schema.d.ts +843 -0
  226. package/dist/browser/rpc/src/schema.js +28 -0
  227. package/dist/browser/rpc/src/schema.js.map +1 -0
  228. package/dist/browser/rpc/src/types.d.ts +24 -0
  229. package/dist/browser/rpc/src/types.js +2 -0
  230. package/dist/browser/rpc/src/types.js.map +1 -0
  231. package/dist/browser/rpc/src/utils.d.ts +7 -0
  232. package/dist/browser/rpc/src/utils.js +58 -0
  233. package/dist/browser/rpc/src/utils.js.map +1 -0
  234. package/dist/browser/runtime/browser/community/challenges/index.d.ts +6 -0
  235. package/dist/browser/runtime/browser/community/challenges/index.js +7 -0
  236. package/dist/browser/runtime/browser/community/challenges/index.js.map +1 -0
  237. package/dist/browser/runtime/browser/community/local-community.d.ts +3 -0
  238. package/dist/browser/runtime/browser/community/local-community.js +6 -0
  239. package/dist/browser/runtime/browser/community/local-community.js.map +1 -0
  240. package/dist/browser/runtime/browser/db-handler.d.ts +4 -0
  241. package/dist/browser/runtime/browser/db-handler.js +8 -0
  242. package/dist/browser/runtime/browser/db-handler.js.map +1 -0
  243. package/dist/browser/runtime/browser/localforage-lru.d.ts +15 -0
  244. package/dist/browser/runtime/browser/localforage-lru.js +140 -0
  245. package/dist/browser/runtime/browser/localforage-lru.js.map +1 -0
  246. package/dist/browser/runtime/browser/lru-storage.d.ts +14 -0
  247. package/dist/browser/runtime/browser/lru-storage.js +34 -0
  248. package/dist/browser/runtime/browser/lru-storage.js.map +1 -0
  249. package/dist/browser/runtime/browser/native-functions.d.ts +3 -0
  250. package/dist/browser/runtime/browser/native-functions.js +6 -0
  251. package/dist/browser/runtime/browser/native-functions.js.map +1 -0
  252. package/dist/browser/runtime/browser/polyfill.d.ts +3 -0
  253. package/dist/browser/runtime/browser/polyfill.js +37 -0
  254. package/dist/browser/runtime/browser/polyfill.js.map +1 -0
  255. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
  256. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
  257. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  258. package/dist/browser/runtime/browser/storage.d.ts +13 -0
  259. package/dist/browser/runtime/browser/storage.js +37 -0
  260. package/dist/browser/runtime/browser/storage.js.map +1 -0
  261. package/dist/browser/runtime/browser/util.d.ts +14 -0
  262. package/dist/browser/runtime/browser/util.js +61 -0
  263. package/dist/browser/runtime/browser/util.js.map +1 -0
  264. package/dist/browser/runtime/node/address-rewriter-db.d.ts +31 -0
  265. package/dist/browser/runtime/node/address-rewriter-db.js +156 -0
  266. package/dist/browser/runtime/node/address-rewriter-db.js.map +1 -0
  267. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
  268. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +493 -0
  269. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
  270. package/dist/browser/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
  271. package/dist/browser/runtime/node/community/challenges/exclude/exclude.js +280 -0
  272. package/dist/browser/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
  273. package/dist/browser/runtime/node/community/challenges/exclude/index.d.ts +3 -0
  274. package/dist/browser/runtime/node/community/challenges/exclude/index.js +4 -0
  275. package/dist/browser/runtime/node/community/challenges/exclude/index.js.map +1 -0
  276. package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
  277. package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
  278. package/dist/browser/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
  279. package/dist/browser/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
  280. package/dist/browser/runtime/node/community/challenges/exclude/utils.js +52 -0
  281. package/dist/browser/runtime/node/community/challenges/exclude/utils.js.map +1 -0
  282. package/dist/browser/runtime/node/community/challenges/index.d.ts +32 -0
  283. package/dist/browser/runtime/node/community/challenges/index.js +307 -0
  284. package/dist/browser/runtime/node/community/challenges/index.js.map +1 -0
  285. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
  286. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
  287. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
  288. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
  289. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
  290. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
  291. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
  292. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
  293. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
  294. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
  295. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
  296. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
  297. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
  298. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
  299. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
  300. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
  301. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
  302. package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
  303. package/dist/browser/runtime/node/community/db-handler-types.d.ts +19 -0
  304. package/dist/browser/runtime/node/community/db-handler-types.js +2 -0
  305. package/dist/browser/runtime/node/community/db-handler-types.js.map +1 -0
  306. package/dist/browser/runtime/node/community/db-handler.d.ts +226 -0
  307. package/dist/browser/runtime/node/community/db-handler.js +2462 -0
  308. package/dist/browser/runtime/node/community/db-handler.js.map +1 -0
  309. package/dist/browser/runtime/node/community/db-row-parser.d.ts +19 -0
  310. package/dist/browser/runtime/node/community/db-row-parser.js +40 -0
  311. package/dist/browser/runtime/node/community/db-row-parser.js.map +1 -0
  312. package/dist/browser/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
  313. package/dist/browser/runtime/node/community/keyv-better-sqlite3.js +251 -0
  314. package/dist/browser/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
  315. package/dist/browser/runtime/node/community/local-community.d.ts +129 -0
  316. package/dist/browser/runtime/node/community/local-community.js +2978 -0
  317. package/dist/browser/runtime/node/community/local-community.js.map +1 -0
  318. package/dist/browser/runtime/node/community/page-generator.d.ts +433 -0
  319. package/dist/browser/runtime/node/community/page-generator.js +441 -0
  320. package/dist/browser/runtime/node/community/page-generator.js.map +1 -0
  321. package/dist/browser/runtime/node/lru-storage.d.ts +14 -0
  322. package/dist/browser/runtime/node/lru-storage.js +40 -0
  323. package/dist/browser/runtime/node/lru-storage.js.map +1 -0
  324. package/dist/browser/runtime/node/native-functions.d.ts +3 -0
  325. package/dist/browser/runtime/node/native-functions.js +7 -0
  326. package/dist/browser/runtime/node/native-functions.js.map +1 -0
  327. package/dist/browser/runtime/node/polyfill.d.ts +3 -0
  328. package/dist/browser/runtime/node/polyfill.js +20 -0
  329. package/dist/browser/runtime/node/polyfill.js.map +1 -0
  330. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
  331. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
  332. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  333. package/dist/browser/runtime/node/sqlite-lru-cache.d.ts +52 -0
  334. package/dist/browser/runtime/node/sqlite-lru-cache.js +127 -0
  335. package/dist/browser/runtime/node/sqlite-lru-cache.js.map +1 -0
  336. package/dist/browser/runtime/node/storage.d.ts +14 -0
  337. package/dist/browser/runtime/node/storage.js +52 -0
  338. package/dist/browser/runtime/node/storage.js.map +1 -0
  339. package/dist/browser/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
  340. package/dist/browser/runtime/node/test/helpers/hanging-runner.js +157 -0
  341. package/dist/browser/runtime/node/test/helpers/hanging-runner.js.map +1 -0
  342. package/dist/browser/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
  343. package/dist/browser/runtime/node/test/helpers/run-hanging-node.js +68 -0
  344. package/dist/browser/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
  345. package/dist/browser/runtime/node/test/mock-http-router.d.ts +54 -0
  346. package/dist/browser/runtime/node/test/mock-http-router.js +397 -0
  347. package/dist/browser/runtime/node/test/mock-http-router.js.map +1 -0
  348. package/dist/browser/runtime/node/util.d.ts +43 -0
  349. package/dist/browser/runtime/node/util.js +384 -0
  350. package/dist/browser/runtime/node/util.js.map +1 -0
  351. package/dist/browser/schema/schema-util.d.ts +2751 -0
  352. package/dist/browser/schema/schema-util.js +562 -0
  353. package/dist/browser/schema/schema-util.js.map +1 -0
  354. package/dist/browser/schema/schema.d.ts +237 -0
  355. package/dist/browser/schema/schema.js +128 -0
  356. package/dist/browser/schema/schema.js.map +1 -0
  357. package/dist/browser/schema.d.ts +1142 -0
  358. package/dist/browser/schema.js +104 -0
  359. package/dist/browser/schema.js.map +1 -0
  360. package/dist/browser/signer/constants.d.ts +2 -0
  361. package/dist/browser/signer/constants.js +3 -0
  362. package/dist/browser/signer/constants.js.map +1 -0
  363. package/dist/browser/signer/encryption.d.ts +21 -0
  364. package/dist/browser/signer/encryption.js +122 -0
  365. package/dist/browser/signer/encryption.js.map +1 -0
  366. package/dist/browser/signer/index.d.ts +21 -0
  367. package/dist/browser/signer/index.js +49 -0
  368. package/dist/browser/signer/index.js.map +1 -0
  369. package/dist/browser/signer/signatures.d.ts +200 -0
  370. package/dist/browser/signer/signatures.js +594 -0
  371. package/dist/browser/signer/signatures.js.map +1 -0
  372. package/dist/browser/signer/types.d.ts +20 -0
  373. package/dist/browser/signer/types.js +2 -0
  374. package/dist/browser/signer/types.js.map +1 -0
  375. package/dist/browser/signer/util.d.ts +14 -0
  376. package/dist/browser/signer/util.js +156 -0
  377. package/dist/browser/signer/util.js.map +1 -0
  378. package/dist/browser/stats.d.ts +15 -0
  379. package/dist/browser/stats.js +64 -0
  380. package/dist/browser/stats.js.map +1 -0
  381. package/dist/browser/test/mock-ipfs-client.d.ts +34 -0
  382. package/dist/browser/test/mock-ipfs-client.js +208 -0
  383. package/dist/browser/test/mock-ipfs-client.js.map +1 -0
  384. package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
  385. package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
  386. package/dist/browser/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
  387. package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
  388. package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
  389. package/dist/browser/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
  390. package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
  391. package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
  392. package/dist/browser/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
  393. package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
  394. package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
  395. package/dist/browser/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
  396. package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
  397. package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
  398. package/dist/browser/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
  399. package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
  400. package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
  401. package/dist/browser/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
  402. package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
  403. package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
  404. package/dist/browser/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
  405. package/dist/browser/test/test-util.d.ts +1019 -0
  406. package/dist/browser/test/test-util.js +1886 -0
  407. package/dist/browser/test/test-util.js.map +1 -0
  408. package/dist/browser/types.d.ts +165 -0
  409. package/dist/browser/types.js +2 -0
  410. package/dist/browser/types.js.map +1 -0
  411. package/dist/browser/util/inflight-fetch-manager.d.ts +11 -0
  412. package/dist/browser/util/inflight-fetch-manager.js +41 -0
  413. package/dist/browser/util/inflight-fetch-manager.js.map +1 -0
  414. package/dist/browser/util.d.ts +120 -0
  415. package/dist/browser/util.js +816 -0
  416. package/dist/browser/util.js.map +1 -0
  417. package/dist/browser/version.d.ts +7 -0
  418. package/dist/browser/version.js +12 -0
  419. package/dist/browser/version.js.map +1 -0
  420. package/dist/browser/zod-error-map.d.ts +1 -0
  421. package/dist/browser/zod-error-map.js +10 -0
  422. package/dist/browser/zod-error-map.js.map +1 -0
  423. package/dist/node/challenges.d.ts +1 -0
  424. package/dist/node/challenges.js +2 -0
  425. package/dist/node/challenges.js.map +1 -0
  426. package/dist/node/clients/base-client-manager.d.ts +126 -0
  427. package/dist/node/clients/base-client-manager.js +673 -0
  428. package/dist/node/clients/base-client-manager.js.map +1 -0
  429. package/dist/node/clients/name-resolver-client.d.ts +8 -0
  430. package/dist/node/clients/name-resolver-client.js +10 -0
  431. package/dist/node/clients/name-resolver-client.js.map +1 -0
  432. package/dist/node/clients/pkc-typed-emitter.d.ts +9 -0
  433. package/dist/node/clients/pkc-typed-emitter.js +52 -0
  434. package/dist/node/clients/pkc-typed-emitter.js.map +1 -0
  435. package/dist/node/clients/rpc-client/decode-rpc-response-util.d.ts +8 -0
  436. package/dist/node/clients/rpc-client/decode-rpc-response-util.js +53 -0
  437. package/dist/node/clients/rpc-client/decode-rpc-response-util.js.map +1 -0
  438. package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +68 -0
  439. package/dist/node/clients/rpc-client/pkc-rpc-client.js +404 -0
  440. package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -0
  441. package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +147 -0
  442. package/dist/node/clients/rpc-client/rpc-schema-util.js +11 -0
  443. package/dist/node/clients/rpc-client/rpc-schema-util.js.map +1 -0
  444. package/dist/node/clients/rpc-client/schema.d.ts +433 -0
  445. package/dist/node/clients/rpc-client/schema.js +49 -0
  446. package/dist/node/clients/rpc-client/schema.js.map +1 -0
  447. package/dist/node/clients/rpc-client/types.d.ts +8 -0
  448. package/dist/node/clients/rpc-client/types.js +2 -0
  449. package/dist/node/clients/rpc-client/types.js.map +1 -0
  450. package/dist/node/community/community-client-manager.d.ts +60 -0
  451. package/dist/node/community/community-client-manager.js +717 -0
  452. package/dist/node/community/community-client-manager.js.map +1 -0
  453. package/dist/node/community/community-clients.d.ts +18 -0
  454. package/dist/node/community/community-clients.js +12 -0
  455. package/dist/node/community/community-clients.js.map +1 -0
  456. package/dist/node/community/community-wire.d.ts +20 -0
  457. package/dist/node/community/community-wire.js +38 -0
  458. package/dist/node/community/community-wire.js.map +1 -0
  459. package/dist/node/community/remote-community.d.ts +110 -0
  460. package/dist/node/community/remote-community.js +555 -0
  461. package/dist/node/community/remote-community.js.map +1 -0
  462. package/dist/node/community/rpc-local-community.d.ts +41 -0
  463. package/dist/node/community/rpc-local-community.js +289 -0
  464. package/dist/node/community/rpc-local-community.js.map +1 -0
  465. package/dist/node/community/rpc-remote-community.d.ts +18 -0
  466. package/dist/node/community/rpc-remote-community.js +286 -0
  467. package/dist/node/community/rpc-remote-community.js.map +1 -0
  468. package/dist/node/community/schema.d.ts +4217 -0
  469. package/dist/node/community/schema.js +289 -0
  470. package/dist/node/community/schema.js.map +1 -0
  471. package/dist/node/community/types.d.ts +135 -0
  472. package/dist/node/community/types.js +2 -0
  473. package/dist/node/community/types.js.map +1 -0
  474. package/dist/node/constants.d.ts +6 -0
  475. package/dist/node/constants.js +9 -0
  476. package/dist/node/constants.js.map +1 -0
  477. package/dist/node/decorator-util.d.ts +1 -0
  478. package/dist/node/decorator-util.js +35 -0
  479. package/dist/node/decorator-util.js.map +1 -0
  480. package/dist/node/errors.d.ts +343 -0
  481. package/dist/node/errors.js +358 -0
  482. package/dist/node/errors.js.map +1 -0
  483. package/dist/node/general-util/limited-set.d.ts +15 -0
  484. package/dist/node/general-util/limited-set.js +66 -0
  485. package/dist/node/general-util/limited-set.js.map +1 -0
  486. package/dist/node/generated-version.d.ts +1 -0
  487. package/dist/node/generated-version.js +3 -0
  488. package/dist/node/generated-version.js.map +1 -0
  489. package/dist/node/generic-state-client.d.ts +6 -0
  490. package/dist/node/generic-state-client.js +11 -0
  491. package/dist/node/generic-state-client.js.map +1 -0
  492. package/dist/node/helia/helia-for-pkc.d.ts +3 -0
  493. package/dist/node/helia/helia-for-pkc.js +255 -0
  494. package/dist/node/helia/helia-for-pkc.js.map +1 -0
  495. package/dist/node/helia/ipns-over-pubsub-with-fetch.d.ts +36 -0
  496. package/dist/node/helia/ipns-over-pubsub-with-fetch.js +229 -0
  497. package/dist/node/helia/ipns-over-pubsub-with-fetch.js.map +1 -0
  498. package/dist/node/helia/libp2pjsClient.d.ts +27 -0
  499. package/dist/node/helia/libp2pjsClient.js +15 -0
  500. package/dist/node/helia/libp2pjsClient.js.map +1 -0
  501. package/dist/node/helia/types.d.ts +19 -0
  502. package/dist/node/helia/types.js +2 -0
  503. package/dist/node/helia/types.js.map +1 -0
  504. package/dist/node/helia/util.d.ts +13 -0
  505. package/dist/node/helia/util.js +98 -0
  506. package/dist/node/helia/util.js.map +1 -0
  507. package/dist/node/index.d.ts +244 -0
  508. package/dist/node/index.js +36 -0
  509. package/dist/node/index.js.map +1 -0
  510. package/dist/node/logger.d.ts +12 -0
  511. package/dist/node/logger.js +11 -0
  512. package/dist/node/logger.js.map +1 -0
  513. package/dist/node/pages/pages-client-manager.d.ts +159 -0
  514. package/dist/node/pages/pages-client-manager.js +334 -0
  515. package/dist/node/pages/pages-client-manager.js.map +1 -0
  516. package/dist/node/pages/pages-clients.d.ts +11 -0
  517. package/dist/node/pages/pages-clients.js +10 -0
  518. package/dist/node/pages/pages-clients.js.map +1 -0
  519. package/dist/node/pages/pages.d.ts +107 -0
  520. package/dist/node/pages/pages.js +262 -0
  521. package/dist/node/pages/pages.js.map +1 -0
  522. package/dist/node/pages/schema-util.d.ts +3 -0
  523. package/dist/node/pages/schema-util.js +3 -0
  524. package/dist/node/pages/schema-util.js.map +1 -0
  525. package/dist/node/pages/schema.d.ts +719 -0
  526. package/dist/node/pages/schema.js +32 -0
  527. package/dist/node/pages/schema.js.map +1 -0
  528. package/dist/node/pages/types.d.ts +44 -0
  529. package/dist/node/pages/types.js +2 -0
  530. package/dist/node/pages/types.js.map +1 -0
  531. package/dist/node/pages/util.d.ts +56 -0
  532. package/dist/node/pages/util.js +446 -0
  533. package/dist/node/pages/util.js.map +1 -0
  534. package/dist/node/pkc/pkc-client-manager.d.ts +44 -0
  535. package/dist/node/pkc/pkc-client-manager.js +156 -0
  536. package/dist/node/pkc/pkc-client-manager.js.map +1 -0
  537. package/dist/node/pkc/pkc-clients.d.ts +11 -0
  538. package/dist/node/pkc/pkc-clients.js +8 -0
  539. package/dist/node/pkc/pkc-clients.js.map +1 -0
  540. package/dist/node/pkc/pkc-with-rpc-client.d.ts +19 -0
  541. package/dist/node/pkc/pkc-with-rpc-client.js +128 -0
  542. package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -0
  543. package/dist/node/pkc/pkc.d.ts +137 -0
  544. package/dist/node/pkc/pkc.js +888 -0
  545. package/dist/node/pkc/pkc.js.map +1 -0
  546. package/dist/node/pkc/tracked-instance-registry-util.d.ts +44 -0
  547. package/dist/node/pkc/tracked-instance-registry-util.js +106 -0
  548. package/dist/node/pkc/tracked-instance-registry-util.js.map +1 -0
  549. package/dist/node/pkc/tracked-instance-registry.d.ts +18 -0
  550. package/dist/node/pkc/tracked-instance-registry.js +134 -0
  551. package/dist/node/pkc/tracked-instance-registry.js.map +1 -0
  552. package/dist/node/pkc-error.d.ts +65 -0
  553. package/dist/node/pkc-error.js +137 -0
  554. package/dist/node/pkc-error.js.map +1 -0
  555. package/dist/node/publications/comment/comment-client-manager.d.ts +86 -0
  556. package/dist/node/publications/comment/comment-client-manager.js +908 -0
  557. package/dist/node/publications/comment/comment-client-manager.js.map +1 -0
  558. package/dist/node/publications/comment/comment-clients.d.ts +19 -0
  559. package/dist/node/publications/comment/comment-clients.js +12 -0
  560. package/dist/node/publications/comment/comment-clients.js.map +1 -0
  561. package/dist/node/publications/comment/comment-util.d.ts +10 -0
  562. package/dist/node/publications/comment/comment-util.js +202 -0
  563. package/dist/node/publications/comment/comment-util.js.map +1 -0
  564. package/dist/node/publications/comment/comment.d.ts +147 -0
  565. package/dist/node/publications/comment/comment.js +1044 -0
  566. package/dist/node/publications/comment/comment.js.map +1 -0
  567. package/dist/node/publications/comment/schema.d.ts +1237 -0
  568. package/dist/node/publications/comment/schema.js +184 -0
  569. package/dist/node/publications/comment/schema.js.map +1 -0
  570. package/dist/node/publications/comment/types.d.ts +100 -0
  571. package/dist/node/publications/comment/types.js +2 -0
  572. package/dist/node/publications/comment/types.js.map +1 -0
  573. package/dist/node/publications/comment-edit/comment-edit.d.ts +41 -0
  574. package/dist/node/publications/comment-edit/comment-edit.js +63 -0
  575. package/dist/node/publications/comment-edit/comment-edit.js.map +1 -0
  576. package/dist/node/publications/comment-edit/schema.d.ts +295 -0
  577. package/dist/node/publications/comment-edit/schema.js +55 -0
  578. package/dist/node/publications/comment-edit/schema.js.map +1 -0
  579. package/dist/node/publications/comment-edit/types.d.ts +25 -0
  580. package/dist/node/publications/comment-edit/types.js +2 -0
  581. package/dist/node/publications/comment-edit/types.js.map +1 -0
  582. package/dist/node/publications/comment-moderation/comment-moderation.d.ts +36 -0
  583. package/dist/node/publications/comment-moderation/comment-moderation.js +53 -0
  584. package/dist/node/publications/comment-moderation/comment-moderation.js.map +1 -0
  585. package/dist/node/publications/comment-moderation/schema.d.ts +315 -0
  586. package/dist/node/publications/comment-moderation/schema.js +62 -0
  587. package/dist/node/publications/comment-moderation/schema.js.map +1 -0
  588. package/dist/node/publications/comment-moderation/types.d.ts +22 -0
  589. package/dist/node/publications/comment-moderation/types.js +2 -0
  590. package/dist/node/publications/comment-moderation/types.js.map +1 -0
  591. package/dist/node/publications/community-edit/community-edit.d.ts +35 -0
  592. package/dist/node/publications/community-edit/community-edit.js +50 -0
  593. package/dist/node/publications/community-edit/community-edit.js.map +1 -0
  594. package/dist/node/publications/community-edit/schema.d.ts +467 -0
  595. package/dist/node/publications/community-edit/schema.js +36 -0
  596. package/dist/node/publications/community-edit/schema.js.map +1 -0
  597. package/dist/node/publications/community-edit/types.d.ts +19 -0
  598. package/dist/node/publications/community-edit/types.js +2 -0
  599. package/dist/node/publications/community-edit/types.js.map +1 -0
  600. package/dist/node/publications/publication-author.d.ts +22 -0
  601. package/dist/node/publications/publication-author.js +66 -0
  602. package/dist/node/publications/publication-author.js.map +1 -0
  603. package/dist/node/publications/publication-client-manager.d.ts +62 -0
  604. package/dist/node/publications/publication-client-manager.js +257 -0
  605. package/dist/node/publications/publication-client-manager.js.map +1 -0
  606. package/dist/node/publications/publication-clients.d.ts +19 -0
  607. package/dist/node/publications/publication-clients.js +12 -0
  608. package/dist/node/publications/publication-clients.js.map +1 -0
  609. package/dist/node/publications/publication-community.d.ts +55 -0
  610. package/dist/node/publications/publication-community.js +87 -0
  611. package/dist/node/publications/publication-community.js.map +1 -0
  612. package/dist/node/publications/publication.d.ts +120 -0
  613. package/dist/node/publications/publication.js +950 -0
  614. package/dist/node/publications/publication.js.map +1 -0
  615. package/dist/node/publications/types.d.ts +26 -0
  616. package/dist/node/publications/types.js +2 -0
  617. package/dist/node/publications/types.js.map +1 -0
  618. package/dist/node/publications/vote/schema.d.ts +150 -0
  619. package/dist/node/publications/vote/schema.js +44 -0
  620. package/dist/node/publications/vote/schema.js.map +1 -0
  621. package/dist/node/publications/vote/types.d.ts +21 -0
  622. package/dist/node/publications/vote/types.js +2 -0
  623. package/dist/node/publications/vote/types.js.map +1 -0
  624. package/dist/node/publications/vote/vote.d.ts +36 -0
  625. package/dist/node/publications/vote/vote.js +49 -0
  626. package/dist/node/publications/vote/vote.js.map +1 -0
  627. package/dist/node/pubsub-messages/schema.d.ts +964 -0
  628. package/dist/node/pubsub-messages/schema.js +98 -0
  629. package/dist/node/pubsub-messages/schema.js.map +1 -0
  630. package/dist/node/pubsub-messages/types.d.ts +81 -0
  631. package/dist/node/pubsub-messages/types.js +2 -0
  632. package/dist/node/pubsub-messages/types.js.map +1 -0
  633. package/dist/node/rpc/src/index.d.ts +483 -0
  634. package/dist/node/rpc/src/index.js +1267 -0
  635. package/dist/node/rpc/src/index.js.map +1 -0
  636. package/dist/node/rpc/src/json-rpc-util.d.ts +1 -0
  637. package/dist/node/rpc/src/json-rpc-util.js +19 -0
  638. package/dist/node/rpc/src/json-rpc-util.js.map +1 -0
  639. package/dist/node/rpc/src/lib/pkc-js/index.d.ts +132 -0
  640. package/dist/node/rpc/src/lib/pkc-js/index.js +29 -0
  641. package/dist/node/rpc/src/lib/pkc-js/index.js.map +1 -0
  642. package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.d.ts +1 -0
  643. package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js +472 -0
  644. package/dist/node/rpc/src/lib/pkc-js/pkc-js-mock.js.map +1 -0
  645. package/dist/node/rpc/src/schema.d.ts +843 -0
  646. package/dist/node/rpc/src/schema.js +28 -0
  647. package/dist/node/rpc/src/schema.js.map +1 -0
  648. package/dist/node/rpc/src/types.d.ts +24 -0
  649. package/dist/node/rpc/src/types.js +2 -0
  650. package/dist/node/rpc/src/types.js.map +1 -0
  651. package/dist/node/rpc/src/utils.d.ts +7 -0
  652. package/dist/node/rpc/src/utils.js +58 -0
  653. package/dist/node/rpc/src/utils.js.map +1 -0
  654. package/dist/node/runtime/browser/community/challenges/index.d.ts +6 -0
  655. package/dist/node/runtime/browser/community/challenges/index.js +7 -0
  656. package/dist/node/runtime/browser/community/challenges/index.js.map +1 -0
  657. package/dist/node/runtime/browser/community/local-community.d.ts +3 -0
  658. package/dist/node/runtime/browser/community/local-community.js +6 -0
  659. package/dist/node/runtime/browser/community/local-community.js.map +1 -0
  660. package/dist/node/runtime/browser/db-handler.d.ts +4 -0
  661. package/dist/node/runtime/browser/db-handler.js +8 -0
  662. package/dist/node/runtime/browser/db-handler.js.map +1 -0
  663. package/dist/node/runtime/browser/localforage-lru.d.ts +15 -0
  664. package/dist/node/runtime/browser/localforage-lru.js +140 -0
  665. package/dist/node/runtime/browser/localforage-lru.js.map +1 -0
  666. package/dist/node/runtime/browser/lru-storage.d.ts +14 -0
  667. package/dist/node/runtime/browser/lru-storage.js +34 -0
  668. package/dist/node/runtime/browser/lru-storage.js.map +1 -0
  669. package/dist/node/runtime/browser/native-functions.d.ts +3 -0
  670. package/dist/node/runtime/browser/native-functions.js +6 -0
  671. package/dist/node/runtime/browser/native-functions.js.map +1 -0
  672. package/dist/node/runtime/browser/polyfill.d.ts +3 -0
  673. package/dist/node/runtime/browser/polyfill.js +37 -0
  674. package/dist/node/runtime/browser/polyfill.js.map +1 -0
  675. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
  676. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
  677. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  678. package/dist/node/runtime/browser/storage.d.ts +13 -0
  679. package/dist/node/runtime/browser/storage.js +37 -0
  680. package/dist/node/runtime/browser/storage.js.map +1 -0
  681. package/dist/node/runtime/browser/util.d.ts +14 -0
  682. package/dist/node/runtime/browser/util.js +61 -0
  683. package/dist/node/runtime/browser/util.js.map +1 -0
  684. package/dist/node/runtime/node/address-rewriter-db.d.ts +31 -0
  685. package/dist/node/runtime/node/address-rewriter-db.js +156 -0
  686. package/dist/node/runtime/node/address-rewriter-db.js.map +1 -0
  687. package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +45 -0
  688. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +493 -0
  689. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
  690. package/dist/node/runtime/node/community/challenges/exclude/exclude.d.ts +8 -0
  691. package/dist/node/runtime/node/community/challenges/exclude/exclude.js +280 -0
  692. package/dist/node/runtime/node/community/challenges/exclude/exclude.js.map +1 -0
  693. package/dist/node/runtime/node/community/challenges/exclude/index.d.ts +3 -0
  694. package/dist/node/runtime/node/community/challenges/exclude/index.js +4 -0
  695. package/dist/node/runtime/node/community/challenges/exclude/index.js.map +1 -0
  696. package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.d.ts +5 -0
  697. package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js +127 -0
  698. package/dist/node/runtime/node/community/challenges/exclude/rate-limiter.js.map +1 -0
  699. package/dist/node/runtime/node/community/challenges/exclude/utils.d.ts +13 -0
  700. package/dist/node/runtime/node/community/challenges/exclude/utils.js +52 -0
  701. package/dist/node/runtime/node/community/challenges/exclude/utils.js.map +1 -0
  702. package/dist/node/runtime/node/community/challenges/index.d.ts +32 -0
  703. package/dist/node/runtime/node/community/challenges/index.js +307 -0
  704. package/dist/node/runtime/node/community/challenges/index.js.map +1 -0
  705. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.d.ts +5 -0
  706. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +118 -0
  707. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -0
  708. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.d.ts +5 -0
  709. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js +26 -0
  710. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/fail.js.map +1 -0
  711. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.d.ts +5 -0
  712. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +135 -0
  713. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -0
  714. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.d.ts +5 -0
  715. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js +66 -0
  716. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -0
  717. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.d.ts +5 -0
  718. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js +61 -0
  719. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/text-math.js.map +1 -0
  720. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.d.ts +5 -0
  721. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +118 -0
  722. package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -0
  723. package/dist/node/runtime/node/community/db-handler-types.d.ts +19 -0
  724. package/dist/node/runtime/node/community/db-handler-types.js +2 -0
  725. package/dist/node/runtime/node/community/db-handler-types.js.map +1 -0
  726. package/dist/node/runtime/node/community/db-handler.d.ts +226 -0
  727. package/dist/node/runtime/node/community/db-handler.js +2462 -0
  728. package/dist/node/runtime/node/community/db-handler.js.map +1 -0
  729. package/dist/node/runtime/node/community/db-row-parser.d.ts +19 -0
  730. package/dist/node/runtime/node/community/db-row-parser.js +40 -0
  731. package/dist/node/runtime/node/community/db-row-parser.js.map +1 -0
  732. package/dist/node/runtime/node/community/keyv-better-sqlite3.d.ts +68 -0
  733. package/dist/node/runtime/node/community/keyv-better-sqlite3.js +251 -0
  734. package/dist/node/runtime/node/community/keyv-better-sqlite3.js.map +1 -0
  735. package/dist/node/runtime/node/community/local-community.d.ts +129 -0
  736. package/dist/node/runtime/node/community/local-community.js +2978 -0
  737. package/dist/node/runtime/node/community/local-community.js.map +1 -0
  738. package/dist/node/runtime/node/community/page-generator.d.ts +433 -0
  739. package/dist/node/runtime/node/community/page-generator.js +441 -0
  740. package/dist/node/runtime/node/community/page-generator.js.map +1 -0
  741. package/dist/node/runtime/node/lru-storage.d.ts +14 -0
  742. package/dist/node/runtime/node/lru-storage.js +40 -0
  743. package/dist/node/runtime/node/lru-storage.js.map +1 -0
  744. package/dist/node/runtime/node/native-functions.d.ts +3 -0
  745. package/dist/node/runtime/node/native-functions.js +7 -0
  746. package/dist/node/runtime/node/native-functions.js.map +1 -0
  747. package/dist/node/runtime/node/polyfill.d.ts +3 -0
  748. package/dist/node/runtime/node/polyfill.js +20 -0
  749. package/dist/node/runtime/node/polyfill.js.map +1 -0
  750. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
  751. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js +240 -0
  752. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  753. package/dist/node/runtime/node/sqlite-lru-cache.d.ts +52 -0
  754. package/dist/node/runtime/node/sqlite-lru-cache.js +127 -0
  755. package/dist/node/runtime/node/sqlite-lru-cache.js.map +1 -0
  756. package/dist/node/runtime/node/storage.d.ts +14 -0
  757. package/dist/node/runtime/node/storage.js +52 -0
  758. package/dist/node/runtime/node/storage.js.map +1 -0
  759. package/dist/node/runtime/node/test/helpers/hanging-runner.d.ts +1 -0
  760. package/dist/node/runtime/node/test/helpers/hanging-runner.js +157 -0
  761. package/dist/node/runtime/node/test/helpers/hanging-runner.js.map +1 -0
  762. package/dist/node/runtime/node/test/helpers/run-hanging-node.d.ts +7 -0
  763. package/dist/node/runtime/node/test/helpers/run-hanging-node.js +68 -0
  764. package/dist/node/runtime/node/test/helpers/run-hanging-node.js.map +1 -0
  765. package/dist/node/runtime/node/test/mock-http-router.d.ts +54 -0
  766. package/dist/node/runtime/node/test/mock-http-router.js +397 -0
  767. package/dist/node/runtime/node/test/mock-http-router.js.map +1 -0
  768. package/dist/node/runtime/node/util.d.ts +43 -0
  769. package/dist/node/runtime/node/util.js +384 -0
  770. package/dist/node/runtime/node/util.js.map +1 -0
  771. package/dist/node/schema/schema-util.d.ts +2751 -0
  772. package/dist/node/schema/schema-util.js +562 -0
  773. package/dist/node/schema/schema-util.js.map +1 -0
  774. package/dist/node/schema/schema.d.ts +237 -0
  775. package/dist/node/schema/schema.js +128 -0
  776. package/dist/node/schema/schema.js.map +1 -0
  777. package/dist/node/schema.d.ts +1142 -0
  778. package/dist/node/schema.js +104 -0
  779. package/dist/node/schema.js.map +1 -0
  780. package/dist/node/signer/constants.d.ts +2 -0
  781. package/dist/node/signer/constants.js +3 -0
  782. package/dist/node/signer/constants.js.map +1 -0
  783. package/dist/node/signer/encryption.d.ts +21 -0
  784. package/dist/node/signer/encryption.js +122 -0
  785. package/dist/node/signer/encryption.js.map +1 -0
  786. package/dist/node/signer/index.d.ts +21 -0
  787. package/dist/node/signer/index.js +49 -0
  788. package/dist/node/signer/index.js.map +1 -0
  789. package/dist/node/signer/signatures.d.ts +200 -0
  790. package/dist/node/signer/signatures.js +594 -0
  791. package/dist/node/signer/signatures.js.map +1 -0
  792. package/dist/node/signer/types.d.ts +20 -0
  793. package/dist/node/signer/types.js +2 -0
  794. package/dist/node/signer/types.js.map +1 -0
  795. package/dist/node/signer/util.d.ts +14 -0
  796. package/dist/node/signer/util.js +156 -0
  797. package/dist/node/signer/util.js.map +1 -0
  798. package/dist/node/stats.d.ts +15 -0
  799. package/dist/node/stats.js +64 -0
  800. package/dist/node/stats.js.map +1 -0
  801. package/dist/node/test/mock-ipfs-client.d.ts +34 -0
  802. package/dist/node/test/mock-ipfs-client.js +208 -0
  803. package/dist/node/test/mock-ipfs-client.js.map +1 -0
  804. package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.d.ts +8 -0
  805. package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js +21 -0
  806. package/dist/node/test/node/hanging-test/scenarios/comment-publish-pending.scenario.js.map +1 -0
  807. package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.d.ts +8 -0
  808. package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js +19 -0
  809. package/dist/node/test/node/hanging-test/scenarios/comment-publish.scenario.js.map +1 -0
  810. package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.d.ts +8 -0
  811. package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js +22 -0
  812. package/dist/node/test/node/hanging-test/scenarios/comment-update.scenario.js.map +1 -0
  813. package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.d.ts +8 -0
  814. package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js +23 -0
  815. package/dist/node/test/node/hanging-test/scenarios/community-start.scenario.js.map +1 -0
  816. package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.d.ts +8 -0
  817. package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js +21 -0
  818. package/dist/node/test/node/hanging-test/scenarios/community-update.scenario.js.map +1 -0
  819. package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.d.ts +7 -0
  820. package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js +15 -0
  821. package/dist/node/test/node/hanging-test/scenarios/destroy-only.scenario.js.map +1 -0
  822. package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.d.ts +30 -0
  823. package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js +46 -0
  824. package/dist/node/test/node/hanging-test/scenarios/hanging-test-util.js.map +1 -0
  825. package/dist/node/test/test-util.d.ts +1019 -0
  826. package/dist/node/test/test-util.js +1886 -0
  827. package/dist/node/test/test-util.js.map +1 -0
  828. package/dist/node/types.d.ts +165 -0
  829. package/dist/node/types.js +2 -0
  830. package/dist/node/types.js.map +1 -0
  831. package/dist/node/util/inflight-fetch-manager.d.ts +11 -0
  832. package/dist/node/util/inflight-fetch-manager.js +41 -0
  833. package/dist/node/util/inflight-fetch-manager.js.map +1 -0
  834. package/dist/node/util.d.ts +120 -0
  835. package/dist/node/util.js +816 -0
  836. package/dist/node/util.js.map +1 -0
  837. package/dist/node/version.d.ts +7 -0
  838. package/dist/node/version.js +12 -0
  839. package/dist/node/version.js.map +1 -0
  840. package/dist/node/zod-error-map.d.ts +1 -0
  841. package/dist/node/zod-error-map.js +10 -0
  842. package/dist/node/zod-error-map.js.map +1 -0
  843. package/package.json +212 -0
@@ -0,0 +1,950 @@
1
+ import assert from "assert";
2
+ import { decryptEd25519AesGcm, encryptEd25519AesGcm } from "../signer/index.js";
3
+ import Logger from "../logger.js";
4
+ import env from "../version.js";
5
+ import { cleanUpBeforePublishing, signChallengeAnswer, signChallengeRequest, verifyChallengeMessage, verifyChallengeVerification } from "../signer/signatures.js";
6
+ import { deepMergeRuntimeFields, hideClassPrivateProps, isStringDomain, shortifyAddress, timestamp } from "../util.js";
7
+ import { TypedEmitter } from "tiny-typed-emitter";
8
+ import { Comment } from "./comment/comment.js";
9
+ import { PKCError } from "../pkc-error.js";
10
+ import { getBufferedPKCAddressFromPublicKey } from "../signer/util.js";
11
+ import * as cborg from "cborg";
12
+ import * as remeda from "remeda";
13
+ import { findStartedCommunity, findUpdatingCommunity } from "../pkc/tracked-instance-registry-util.js";
14
+ import { parseDecryptedChallengeAnswerWithPKCErrorIfItFails, parseDecryptedChallengeVerification, parseDecryptedChallengeWithPKCErrorIfItFails, parseJsonWithPKCErrorIfFails } from "../schema/schema-util.js";
15
+ import { ChallengeRequestMessageSchema, ChallengeAnswerMessageSchema, ChallengeMessageSchema, ChallengeVerificationMessageSchema } from "../pubsub-messages/schema.js";
16
+ import { decodeRpcChallengeAnswerPubsubMsg, decodeRpcChallengePubsubMsg, decodeRpcChallengeRequestPubsubMsg, decodeRpcChallengeVerificationPubsubMsg } from "../clients/rpc-client/decode-rpc-response-util.js";
17
+ import { PublicationClientsManager } from "./publication-client-manager.js";
18
+ import { buildRuntimeAuthor } from "./publication-author.js";
19
+ import { buildRuntimeCommunityFields, normalizeCommunityInputFromCommunity } from "./publication-community.js";
20
+ class Publication extends TypedEmitter {
21
+ constructor(pkc) {
22
+ super();
23
+ this.raw = {};
24
+ // private
25
+ this._community = undefined; // will be used for publishing
26
+ this._challengeExchanges = {};
27
+ this._rpcPublishSubscriptionId = undefined;
28
+ this._pkc = pkc;
29
+ this._updatePublishingStateWithEmission("stopped");
30
+ this._setStateWithEmission("stopped");
31
+ this._initClients();
32
+ this._handleChallengeExchange = this._handleChallengeExchange.bind(this);
33
+ this.publish = this.publish.bind(this);
34
+ this.on("error", (...args) => this.listenerCount("error") === 1 && this._pkc.emit("error", ...args)); // only bubble up to pkc if no other listeners are attached
35
+ this._publishToDifferentProviderThresholdSeconds = 10;
36
+ this._setProviderFailureThresholdSeconds = 60 * 2; // Two minutes
37
+ // public method should be bound
38
+ this.publishChallengeAnswers = this.publishChallengeAnswers.bind(this);
39
+ hideClassPrivateProps(this);
40
+ }
41
+ _initClients() {
42
+ this._clientsManager = new PublicationClientsManager(this);
43
+ this.clients = this._clientsManager.clients;
44
+ }
45
+ setCommunityAddress(communityAddress) {
46
+ this.communityAddress = communityAddress;
47
+ this.shortCommunityAddress = shortifyAddress(communityAddress);
48
+ }
49
+ _initBaseRemoteProps(props) {
50
+ const communityFields = buildRuntimeCommunityFields({ publication: props });
51
+ this.setCommunityAddress(communityFields.communityAddress);
52
+ this.communityPublicKey = communityFields.communityPublicKey;
53
+ this.communityName = communityFields.communityName;
54
+ this.timestamp = props.timestamp;
55
+ this.signature = props.signature;
56
+ const runtimeAuthor = buildRuntimeAuthor({
57
+ author: props.author,
58
+ signaturePublicKey: props.signature.publicKey
59
+ });
60
+ this.author = { ...runtimeAuthor, shortAddress: shortifyAddress(runtimeAuthor.address) };
61
+ this.protocolVersion = props.protocolVersion;
62
+ }
63
+ _initUnsignedLocalProps(opts) {
64
+ this.raw.unsignedPublicationOptions = opts.unsignedOptions;
65
+ this.challengeRequest = opts.challengeRequest;
66
+ this.signer = opts.unsignedOptions.signer;
67
+ this.communityAddress = opts.unsignedOptions.communityAddress;
68
+ this.shortCommunityAddress = shortifyAddress(opts.unsignedOptions.communityAddress);
69
+ // Derive communityName/communityPublicKey from communityAddress if not explicitly provided
70
+ if (opts.unsignedOptions.communityPublicKey)
71
+ this.communityPublicKey = opts.unsignedOptions.communityPublicKey;
72
+ else if (!isStringDomain(opts.unsignedOptions.communityAddress))
73
+ this.communityPublicKey = opts.unsignedOptions.communityAddress;
74
+ if (opts.unsignedOptions.communityName)
75
+ this.communityName = opts.unsignedOptions.communityName;
76
+ else if (isStringDomain(opts.unsignedOptions.communityAddress))
77
+ this.communityName = opts.unsignedOptions.communityAddress;
78
+ this.timestamp = opts.unsignedOptions.timestamp;
79
+ this.protocolVersion = opts.unsignedOptions.protocolVersion;
80
+ const runtimeAuthor = buildRuntimeAuthor({
81
+ author: opts.unsignedOptions.author,
82
+ signaturePublicKey: opts.unsignedOptions.signer.publicKey
83
+ });
84
+ this.author = { ...runtimeAuthor, shortAddress: shortifyAddress(runtimeAuthor.address) };
85
+ }
86
+ async _signPublicationOptionsToPublish(_cleanedPublication) {
87
+ throw new Error(`Should be implemented by children of Publication`);
88
+ }
89
+ async _signPublication({ communityFields }) {
90
+ if (!this.raw.unsignedPublicationOptions)
91
+ throw Error("No unsigned publication options to sign");
92
+ const optionsWithCommunity = {
93
+ ...this.raw.unsignedPublicationOptions,
94
+ ...communityFields
95
+ };
96
+ const cleaned = cleanUpBeforePublishing(optionsWithCommunity);
97
+ const signature = await this._signPublicationOptionsToPublish(cleaned);
98
+ const signedPublicationFields = Object.fromEntries(signature.signedPropertyNames.map((propertyName) => [propertyName, cleaned[propertyName]]));
99
+ const signedPublication = {
100
+ ...signedPublicationFields,
101
+ signature
102
+ };
103
+ this.raw.pubsubMessageToPublish = signedPublication;
104
+ delete this.raw.unsignedPublicationOptions;
105
+ this._initBaseRemoteProps(signedPublication);
106
+ }
107
+ async _signPublicationWithCommunityFields() {
108
+ if (!this._community)
109
+ throw Error("Community must be loaded before signing");
110
+ const communityFields = normalizeCommunityInputFromCommunity({ communityInstance: this._community });
111
+ await this._signPublication({ communityFields });
112
+ }
113
+ async _signPublicationWithKnownCommunityFieldsIfAvailable() {
114
+ if (!this.communityPublicKey || this.raw.pubsubMessageToPublish || !this.raw.unsignedPublicationOptions)
115
+ return;
116
+ await this._signPublication({
117
+ communityFields: {
118
+ communityPublicKey: this.communityPublicKey,
119
+ ...(this.communityName ? { communityName: this.communityName } : {})
120
+ }
121
+ });
122
+ }
123
+ async _validateSignatureHook() {
124
+ // Subclasses override to validate signature after signing
125
+ }
126
+ async _verifyDecryptedChallengeVerificationAndUpdateCommentProps(decryptedVerification) {
127
+ throw Error("should be handled in comment, not publication");
128
+ }
129
+ getType() {
130
+ throw new Error(`Should be implemented by children of Publication`);
131
+ }
132
+ toJSONPubsubRequestToEncrypt() {
133
+ if (!this.raw.pubsubMessageToPublish)
134
+ throw Error("raw.pubsubMessageToPublish must be defined before calling toJSONPubsubRequestToEncrypt");
135
+ return {
136
+ [this.getType()]: this.raw.pubsubMessageToPublish,
137
+ ...this.challengeRequest
138
+ };
139
+ }
140
+ async _handleRpcChallengeVerification(verification, runtimeFields) {
141
+ const log = Logger("pkc-js:publication:_handleRpcChallengeVerification");
142
+ if (verification.comment)
143
+ await this._verifyDecryptedChallengeVerificationAndUpdateCommentProps(verification);
144
+ if (this instanceof Comment && runtimeFields)
145
+ deepMergeRuntimeFields(this, runtimeFields);
146
+ this._setRpcClientState("stopped");
147
+ const newPublishingState = verification.challengeSuccess ? "succeeded" : "failed";
148
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
149
+ newPublishingState,
150
+ newState: "stopped",
151
+ event: {
152
+ name: "challengeverification",
153
+ args: [verification, this instanceof Comment && verification.comment ? this : undefined]
154
+ }
155
+ });
156
+ if (this._rpcPublishSubscriptionId) {
157
+ try {
158
+ await this._pkc._pkcRpcClient.unsubscribe(this._rpcPublishSubscriptionId);
159
+ }
160
+ catch (e) {
161
+ log.error("Failed to unsubscribe from publication publish", e);
162
+ }
163
+ this._rpcPublishSubscriptionId = undefined;
164
+ }
165
+ }
166
+ async _handleIncomingChallengePubsubMessage(msg) {
167
+ const log = Logger("pkc-js:publication:_handleIncomingChallengePubsubMessage");
168
+ if (Object.values(this._challengeExchanges).some((exchange) => exchange.challenge))
169
+ return; // We only process one challenge
170
+ const challengeMsgValidity = await verifyChallengeMessage({
171
+ challenge: msg,
172
+ pubsubTopic: this._communityPubsubTopicWithFallback(),
173
+ validateTimestampRange: true
174
+ });
175
+ if (!challengeMsgValidity.valid) {
176
+ const error = new PKCError("ERR_CHALLENGE_SIGNATURE_IS_INVALID", {
177
+ pubsubMsg: msg,
178
+ reason: challengeMsgValidity.reason
179
+ });
180
+ log.error("received challenge message with invalid signature", error.toString());
181
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
182
+ newPublishingState: "failed",
183
+ event: { name: "error", args: [error] }
184
+ });
185
+ return;
186
+ }
187
+ log(`Received encrypted challenges. Will decrypt and emit them on "challenge" event. User shoud publish solution by calling publishChallengeAnswers`);
188
+ const pubsubSigner = this._challengeExchanges[msg.challengeRequestId.toString()].signer;
189
+ if (!pubsubSigner)
190
+ throw Error("Signer is undefined for this challenge exchange");
191
+ let decryptedRawString;
192
+ try {
193
+ decryptedRawString = await decryptEd25519AesGcm(msg.encrypted, pubsubSigner.privateKey, this._community.encryption.publicKey);
194
+ }
195
+ catch (e) {
196
+ const pkcError = new PKCError("ERR_PUBLICATION_FAILED_TO_DECRYPT_CHALLENGE", { decryptErr: e });
197
+ log.error("could not decrypt challengemessage.encrypted", pkcError.toString());
198
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
199
+ newPublishingState: "failed",
200
+ event: { name: "error", args: [pkcError] }
201
+ });
202
+ return;
203
+ }
204
+ let decryptedJson;
205
+ try {
206
+ decryptedJson = await parseJsonWithPKCErrorIfFails(decryptedRawString);
207
+ }
208
+ catch (e) {
209
+ log.error("could not parse decrypted challengemessage.encrypted as a json", String(e));
210
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
211
+ newPublishingState: "failed",
212
+ event: { name: "error", args: [e] }
213
+ });
214
+ return;
215
+ }
216
+ let decryptedChallenge;
217
+ try {
218
+ decryptedChallenge = parseDecryptedChallengeWithPKCErrorIfItFails(decryptedJson);
219
+ }
220
+ catch (e) {
221
+ log.error("could not parse z challengemessage.encrypted as a json", String(e));
222
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
223
+ newPublishingState: "failed",
224
+ event: { name: "error", args: [e] }
225
+ });
226
+ return;
227
+ }
228
+ const decryptedChallengeMsg = {
229
+ ...msg,
230
+ ...decryptedChallenge
231
+ };
232
+ this._challengeExchanges[msg.challengeRequestId.toString()].challenge = decryptedChallengeMsg;
233
+ this._updatePublishingStateWithEmission("waiting-challenge-answers");
234
+ const subscribedProviders = Object.entries(this._clientsManager.pubsubProviderSubscriptions)
235
+ .filter(([, pubsubTopics]) => pubsubTopics.includes(this._communityPubsubTopicWithFallback()))
236
+ .map(([provider]) => provider);
237
+ subscribedProviders.forEach((provider) => this._updatePubsubState("waiting-challenge-answers", provider));
238
+ this.emit("challenge", decryptedChallengeMsg);
239
+ }
240
+ async _handleIncomingChallengeVerificationPubsubMessage(msg) {
241
+ const log = Logger("pkc-js:publication:_handleIncomingChallengeVerificationPubsubMessage");
242
+ if (this._challengeExchanges[msg.challengeRequestId.toString()].challengeVerification)
243
+ return;
244
+ const signatureValidation = await verifyChallengeVerification({
245
+ verification: msg,
246
+ pubsubTopic: this._communityPubsubTopicWithFallback(),
247
+ validateTimestampRange: true
248
+ });
249
+ if (!signatureValidation.valid) {
250
+ const error = new PKCError("ERR_CHALLENGE_VERIFICATION_SIGNATURE_IS_INVALID", {
251
+ pubsubMsg: msg,
252
+ reason: signatureValidation.reason
253
+ });
254
+ log.error("Publication received a challenge verification with invalid signature", error);
255
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
256
+ newPublishingState: "failed",
257
+ event: { name: "error", args: [error] }
258
+ });
259
+ return;
260
+ }
261
+ let decryptedChallengeVerification;
262
+ let newPublishingState;
263
+ if (msg.challengeSuccess) {
264
+ newPublishingState = "succeeded";
265
+ log(`Received a challengeverification with challengeSuccess=true`, "for publication", this.getType());
266
+ if (msg.encrypted) {
267
+ let decryptedRawString;
268
+ const pubsubSigner = this._challengeExchanges[msg.challengeRequestId.toString()].signer;
269
+ if (!pubsubSigner)
270
+ throw Error("Signer is undefined for this challenge exchange");
271
+ try {
272
+ decryptedRawString = await decryptEd25519AesGcm(msg.encrypted, pubsubSigner.privateKey, this._community.encryption.publicKey);
273
+ }
274
+ catch (e) {
275
+ const pkcError = new PKCError("ERR_INVALID_CHALLENGE_VERIFICATION_DECRYPTED_SCHEMA", {
276
+ decryptErr: e,
277
+ challenegVerificationMsg: msg
278
+ });
279
+ log.error("could not decrypt challengeverification.encrypted", pkcError);
280
+ this.emit("error", pkcError);
281
+ return;
282
+ }
283
+ let decryptedJson;
284
+ try {
285
+ decryptedJson = await parseJsonWithPKCErrorIfFails(decryptedRawString);
286
+ }
287
+ catch (e) {
288
+ log.error("could not parse decrypted challengeverification.encrypted as a json", e);
289
+ this.emit("error", e);
290
+ return;
291
+ }
292
+ try {
293
+ decryptedChallengeVerification = parseDecryptedChallengeVerification(decryptedJson);
294
+ }
295
+ catch (e) {
296
+ log.error("could not parse challengeverification.encrypted due to invalid schema", e);
297
+ this.emit("error", e);
298
+ return;
299
+ }
300
+ if (decryptedChallengeVerification.comment) {
301
+ await this._verifyDecryptedChallengeVerificationAndUpdateCommentProps(decryptedChallengeVerification);
302
+ log("Updated the props of this instance with challengeverification.encrypted");
303
+ }
304
+ }
305
+ }
306
+ else {
307
+ newPublishingState = "failed";
308
+ log.error(`Challenge exchange with publication`, this.getType(), `has failed to pass`, "Challenge errors", msg.challengeErrors, `reason`, msg.reason);
309
+ }
310
+ const challengeVerificationMsg = { ...msg, ...decryptedChallengeVerification };
311
+ this._challengeExchanges[msg.challengeRequestId.toString()].challengeVerification = challengeVerificationMsg;
312
+ Object.values(this._challengeExchanges).forEach((exchange) => this._updatePubsubState("stopped", exchange.providerUrl));
313
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
314
+ newPublishingState,
315
+ newState: "stopped",
316
+ event: {
317
+ name: "challengeverification",
318
+ args: [challengeVerificationMsg, this instanceof Comment && decryptedChallengeVerification ? this : undefined]
319
+ }
320
+ });
321
+ await this._postSucessOrFailurePublishing();
322
+ }
323
+ async _handleChallengeExchange(pubsubMsg) {
324
+ const log = Logger("pkc-js:publication:handleChallengeExchange");
325
+ let decodedJson;
326
+ try {
327
+ decodedJson = cborg.decode(pubsubMsg.data);
328
+ }
329
+ catch (e) {
330
+ log.error("Failed to decode pubsub message", e);
331
+ return;
332
+ }
333
+ const pubsubSchemas = [
334
+ ChallengeVerificationMessageSchema.loose(),
335
+ ChallengeMessageSchema.loose(),
336
+ ChallengeRequestMessageSchema.loose(),
337
+ ChallengeAnswerMessageSchema.loose()
338
+ ];
339
+ let pubsubMsgParsed;
340
+ for (const pubsubSchema of pubsubSchemas) {
341
+ const parseRes = pubsubSchema.safeParse(decodedJson);
342
+ if (parseRes.success) {
343
+ pubsubMsgParsed = parseRes.data;
344
+ break;
345
+ }
346
+ }
347
+ if (!pubsubMsgParsed) {
348
+ log.error(`Failed to parse the schema of decoded pubsub message`, decodedJson);
349
+ return;
350
+ }
351
+ if (pubsubMsgParsed.type === "CHALLENGEREQUEST" || pubsubMsgParsed.type === "CHALLENGEANSWER") {
352
+ log.trace("Received unrelated pubsub message of type", pubsubMsgParsed.type);
353
+ }
354
+ else if (!Object.values(this._challengeExchanges).some((exchange) => remeda.isDeepEqual(pubsubMsgParsed.challengeRequestId, exchange.challengeRequest.challengeRequestId))) {
355
+ log.trace(`Received pubsub message with different challenge request id, ignoring it`);
356
+ }
357
+ else if (pubsubMsgParsed.type === "CHALLENGE")
358
+ return this._handleIncomingChallengePubsubMessage(pubsubMsgParsed);
359
+ else if (pubsubMsgParsed.type === "CHALLENGEVERIFICATION")
360
+ return this._handleIncomingChallengeVerificationPubsubMessage(pubsubMsgParsed);
361
+ }
362
+ _updatePubsubState(pubsubState, keyOrUrl) {
363
+ if (this._publishingToLocalCommunity)
364
+ return; // there's no pubsub for local community
365
+ const kuboOrHelia = this._clientsManager.getDefaultPubsubKuboRpcClientOrHelia();
366
+ if ("_helia" in kuboOrHelia)
367
+ this._clientsManager.updateLibp2pJsClientState(pubsubState, keyOrUrl);
368
+ else
369
+ this._clientsManager.updateKuboRpcPubsubState(pubsubState, keyOrUrl);
370
+ }
371
+ async publishChallengeAnswers(challengeAnswers) {
372
+ const log = Logger("pkc-js:publication:publishChallengeAnswers");
373
+ const toEncryptAnswers = parseDecryptedChallengeAnswerWithPKCErrorIfItFails({
374
+ challengeAnswers: challengeAnswers
375
+ });
376
+ if (this._pkc._pkcRpcClient && typeof this._rpcPublishSubscriptionId === "number") {
377
+ return this._pkc._pkcRpcClient.publishChallengeAnswers(this._rpcPublishSubscriptionId, toEncryptAnswers.challengeAnswers);
378
+ }
379
+ const challengeExchangesWithChallenge = Object.values(this._challengeExchanges).filter((exchange) => exchange.challenge);
380
+ if (challengeExchangesWithChallenge.length === 0)
381
+ throw Error("No challenge exchanges with challenge");
382
+ if (challengeExchangesWithChallenge.length > 1)
383
+ throw Error("We should only have one challenge exchange with challenge");
384
+ const challengeExchange = challengeExchangesWithChallenge[0];
385
+ assert(this._community, "Local pkc-js needs publication._community to be defined to publish challenge answer");
386
+ if (!challengeExchange.signer)
387
+ throw Error("Signer is undefined for this challenge exchange");
388
+ const encryptedChallengeAnswers = await encryptEd25519AesGcm(JSON.stringify(toEncryptAnswers), challengeExchange.signer.privateKey, this._community.encryption.publicKey);
389
+ const toSignAnswer = cleanUpBeforePublishing({
390
+ type: "CHALLENGEANSWER",
391
+ challengeRequestId: challengeExchange.challengeRequest.challengeRequestId,
392
+ encrypted: encryptedChallengeAnswers,
393
+ userAgent: this._pkc.userAgent,
394
+ protocolVersion: env.PROTOCOL_VERSION,
395
+ timestamp: timestamp()
396
+ });
397
+ const answerMsgToPublish = {
398
+ ...toSignAnswer,
399
+ signature: await signChallengeAnswer({ challengeAnswer: toSignAnswer, signer: challengeExchange.signer })
400
+ };
401
+ // TODO should be handling multiple providers with publishing challenge answer?
402
+ // For now, let's just publish to the provider that got us the challenge and its request
403
+ this._updatePublishingStateWithEmission("publishing-challenge-answer");
404
+ this._updatePubsubState("publishing-challenge-answer", challengeExchange.providerUrl);
405
+ if (this._publishingToLocalCommunity) {
406
+ try {
407
+ await this._publishingToLocalCommunity.handleChallengeAnswer(answerMsgToPublish);
408
+ }
409
+ catch (e) {
410
+ this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishError =
411
+ e;
412
+ this._updatePublishingStateWithEmission("failed");
413
+ this._updatePubsubState("stopped", challengeExchange.providerUrl);
414
+ throw e;
415
+ }
416
+ }
417
+ else {
418
+ try {
419
+ await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), answerMsgToPublish, challengeExchange.providerUrl);
420
+ }
421
+ catch (e) {
422
+ this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishError =
423
+ e;
424
+ this._updatePublishingStateWithEmission("failed");
425
+ this._updatePubsubState("stopped", challengeExchange.providerUrl);
426
+ throw e;
427
+ }
428
+ }
429
+ const decryptedChallengeAnswer = {
430
+ ...toEncryptAnswers,
431
+ ...answerMsgToPublish
432
+ };
433
+ this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswer =
434
+ decryptedChallengeAnswer;
435
+ this._challengeExchanges[challengeExchange.challengeRequest.challengeRequestId.toString()].challengeAnswerPublishTimestamp =
436
+ timestamp();
437
+ this._updatePublishingStateWithEmission("waiting-challenge-verification");
438
+ const providers = Object.entries(this._clientsManager.pubsubProviderSubscriptions)
439
+ .filter(([, pubsubTopics]) => pubsubTopics.includes(this._communityPubsubTopicWithFallback()))
440
+ .map(([provider]) => provider);
441
+ providers.forEach((provider) => this._updatePubsubState("waiting-challenge-verification", provider));
442
+ log(`Responded to challenge with answers`, challengeAnswers);
443
+ this.emit("challengeanswer", decryptedChallengeAnswer);
444
+ }
445
+ _validatePublicationFields() {
446
+ if (typeof this.timestamp !== "number" || this.timestamp < 0)
447
+ throw new PKCError("ERR_PUBLICATION_MISSING_FIELD", { type: this.getType, timestamp: this.timestamp });
448
+ if (typeof this.author?.address !== "string")
449
+ throw new PKCError("ERR_PUBLICATION_MISSING_FIELD", { type: this.getType(), authorAddress: this.author?.address });
450
+ if (typeof this.communityAddress !== "string")
451
+ throw new PKCError("ERR_PUBLICATION_MISSING_FIELD", { type: this.getType(), communityAddress: this.communityAddress });
452
+ }
453
+ _validateCommunityFields() {
454
+ if (typeof this._community?.encryption?.publicKey !== "string")
455
+ throw new PKCError("ERR_COMMUNITY_MISSING_FIELD", { communityPublicKey: this._community?.encryption?.publicKey });
456
+ if (typeof this._communityPubsubTopicWithFallback() !== "string")
457
+ throw new PKCError("ERR_COMMUNITY_MISSING_FIELD", {
458
+ pubsubTopic: this._community?.pubsubTopic,
459
+ address: this._community?.address
460
+ });
461
+ }
462
+ _updatePublishingStateNoEmission(newState) {
463
+ this.publishingState = newState;
464
+ }
465
+ _updatePublishingStateWithEmission(newState) {
466
+ if (this.publishingState === newState)
467
+ return;
468
+ this.publishingState = newState;
469
+ this.emit("publishingstatechange", this.publishingState);
470
+ }
471
+ _updateRpcClientStateFromPublishingState(publishingState) {
472
+ // We're deriving the the rpc state from publishing state
473
+ const mapper = {
474
+ failed: ["stopped"],
475
+ "fetching-community-ipfs": ["fetching-community-ipfs"],
476
+ "fetching-community-ipns": ["fetching-community-ipns"],
477
+ "publishing-challenge-answer": ["publishing-challenge-answer"],
478
+ "publishing-challenge-request": ["subscribing-pubsub", "publishing-challenge-request"],
479
+ "resolving-community-name": ["resolving-community-name"],
480
+ stopped: ["stopped"],
481
+ succeeded: ["stopped"],
482
+ "waiting-challenge": ["waiting-challenge"],
483
+ "waiting-challenge-answers": ["waiting-challenge-answers"],
484
+ "waiting-challenge-verification": ["waiting-challenge-verification"]
485
+ };
486
+ const newRpcClientState = mapper[publishingState] || [publishingState]; // In case RPC server transmitted a state we don't know about
487
+ newRpcClientState.forEach(this._setRpcClientState.bind(this));
488
+ }
489
+ _setStateNoEmission(newState) {
490
+ if (newState === this.state)
491
+ return;
492
+ this.state = newState;
493
+ }
494
+ _setStateWithEmission(newState) {
495
+ if (newState === this.state)
496
+ return;
497
+ this.state = newState;
498
+ this.emit("statechange", newState);
499
+ }
500
+ _setRpcClientState(newState) {
501
+ const currentRpcUrl = remeda.keys.strict(this.clients.pkcRpcClients)[0];
502
+ if (newState === this.clients.pkcRpcClients[currentRpcUrl].state)
503
+ return;
504
+ this.clients.pkcRpcClients[currentRpcUrl].state = newState;
505
+ this.clients.pkcRpcClients[currentRpcUrl].emit("statechange", newState);
506
+ }
507
+ _communityPubsubTopicWithFallback() {
508
+ const pubsubTopic = this._community?.pubsubTopic || this._community?.address;
509
+ if (typeof pubsubTopic !== "string")
510
+ throw Error("Failed to load the pubsub topic of community");
511
+ return pubsubTopic;
512
+ }
513
+ _getCommunityCache() {
514
+ const cached = this._pkc._memCaches.communityForPublishing.get(this.communityAddress, { allowStale: true });
515
+ if (cached)
516
+ return cached;
517
+ const subInstance = findUpdatingCommunity(this._pkc, { address: this.communityAddress }) ||
518
+ findStartedCommunity(this._pkc, { address: this.communityAddress });
519
+ const subIpfs = subInstance?.raw.communityIpfs;
520
+ if (subIpfs && subInstance.publicKey)
521
+ return {
522
+ address: subInstance.address,
523
+ publicKey: subInstance.publicKey,
524
+ name: subInstance.name,
525
+ encryption: subIpfs.encryption,
526
+ pubsubTopic: subIpfs.pubsubTopic
527
+ };
528
+ return undefined;
529
+ }
530
+ async _fetchCommunityForPublishing() {
531
+ const log = Logger("pkc-js:publish:_fetchCommunityForPublishing");
532
+ const cachedCommunity = this._getCommunityCache();
533
+ if (cachedCommunity) {
534
+ // We will use the cached community even though it's stale
535
+ // And in the background we will fetch a new one and update the cache
536
+ // cache.has will return false if the item is stale
537
+ if (!this._pkc._memCaches.communityForPublishing.has(this.communityAddress)) {
538
+ log("The cache of community is stale, we will use the cached and update in the background");
539
+ this._pkc
540
+ .getCommunity({ address: this.communityAddress })
541
+ .catch((e) => log.error("Failed to update cache of community", this.communityAddress, e));
542
+ }
543
+ return cachedCommunity;
544
+ }
545
+ else
546
+ return this._clientsManager.fetchCommunityForPublishingWithCacheGuard();
547
+ }
548
+ async stop() {
549
+ await this._postSucessOrFailurePublishing();
550
+ this._updatePublishingStateWithEmission("stopped");
551
+ }
552
+ _isAllAttemptsExhausted(maxNumOfChallengeExchanges) {
553
+ // When all providers failed to publish
554
+ // OR they're done with waiting
555
+ if (Object.keys(this._challengeExchanges).length !== maxNumOfChallengeExchanges)
556
+ return false;
557
+ return Object.values(this._challengeExchanges).every((exchange) => {
558
+ if (exchange.challengeRequestPublishError || exchange.challengeAnswerPublishError)
559
+ return true;
560
+ const doneWaitingForChallenge = typeof exchange.challengeRequestPublishTimestamp === "number" &&
561
+ exchange.challengeRequestPublishTimestamp + this._setProviderFailureThresholdSeconds <= timestamp();
562
+ return doneWaitingForChallenge;
563
+ });
564
+ }
565
+ async _postSucessOrFailurePublishing() {
566
+ const log = Logger("pkc-js:publication:_postSucessOrFailurePublishing");
567
+ this._setStateWithEmission("stopped");
568
+ if (this._rpcPublishSubscriptionId) {
569
+ try {
570
+ await this._pkc._pkcRpcClient.unsubscribe(this._rpcPublishSubscriptionId);
571
+ }
572
+ catch (e) {
573
+ log.error("Failed to unsubscribe from publication publish", e);
574
+ }
575
+ this._rpcPublishSubscriptionId = undefined;
576
+ this._setRpcClientState("stopped");
577
+ }
578
+ else if (this._community) {
579
+ // the client is publishing to pubsub without using PKC RPC
580
+ await this._clientsManager.pubsubUnsubscribe(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange);
581
+ Object.values(this._challengeExchanges).forEach((exchange) => this._updatePubsubState("stopped", exchange.providerUrl));
582
+ }
583
+ }
584
+ _handleIncomingChallengeRequestFromRpc(args) {
585
+ const encodedRequest = args.params.result;
586
+ const request = decodeRpcChallengeRequestPubsubMsg(encodedRequest);
587
+ this._challengeExchanges[request.challengeRequestId.toString()] = {
588
+ ...this._challengeExchanges[request.challengeRequestId.toString()],
589
+ challengeRequest: request,
590
+ challengeRequestPublishTimestamp: timestamp(),
591
+ providerUrl: Object.keys(this.clients.pkcRpcClients)[0]
592
+ };
593
+ this.emit("challengerequest", request);
594
+ }
595
+ _handleIncomingChallengeFromRpc(args) {
596
+ const encodedChallenge = args.params.result;
597
+ const challenge = decodeRpcChallengePubsubMsg(encodedChallenge);
598
+ this._challengeExchanges[challenge.challengeRequestId.toString()] = {
599
+ ...this._challengeExchanges[challenge.challengeRequestId.toString()],
600
+ challenge,
601
+ challengeRequestPublishTimestamp: timestamp()
602
+ };
603
+ this.emit("challenge", challenge);
604
+ }
605
+ _handleIncomingChallengeAnswerFromRpc(args) {
606
+ const encodedChallengeAnswer = args.params.result;
607
+ const challengeAnswerMsg = decodeRpcChallengeAnswerPubsubMsg(encodedChallengeAnswer);
608
+ this._challengeExchanges[challengeAnswerMsg.challengeRequestId.toString()] = {
609
+ ...this._challengeExchanges[challengeAnswerMsg.challengeRequestId.toString()],
610
+ challengeAnswer: challengeAnswerMsg,
611
+ challengeAnswerPublishTimestamp: timestamp()
612
+ };
613
+ this.emit("challengeanswer", challengeAnswerMsg);
614
+ }
615
+ async _handleIncomingChallengeVerificationFromRpc(args) {
616
+ const { challengeVerification: encoded, runtimeFields } = args.params.result;
617
+ const decoded = decodeRpcChallengeVerificationPubsubMsg(encoded);
618
+ this._challengeExchanges[decoded.challengeRequestId.toString()] = {
619
+ ...this._challengeExchanges[decoded.challengeRequestId.toString()],
620
+ challengeVerification: decoded
621
+ };
622
+ await this._handleRpcChallengeVerification(decoded, runtimeFields);
623
+ }
624
+ _handleIncomingPublishingStateFromRpc(args) {
625
+ const publishState = args.params.result.state; // we're optimistic that RPC server transmitted a correct string
626
+ if (publishState === this.publishingState)
627
+ this.emit("publishingstatechange", publishState);
628
+ else
629
+ this._updatePublishingStateWithEmission(publishState);
630
+ this._updateRpcClientStateFromPublishingState(publishState);
631
+ }
632
+ _handleIncomingStateFromRpc(args) {
633
+ const state = args.params.result.state; // optimistic here, we're not validating it via schema
634
+ }
635
+ async _handleIncomingErrorFromRpc(args) {
636
+ const log = Logger("pkc-js:publication:publish:_publishWithRpc:_handleIncomingErrorFromRpc");
637
+ const error = args.params.result;
638
+ if (error.details?.newPublishingState)
639
+ this._updatePublishingStateNoEmission(error.details.newPublishingState);
640
+ if (error.details?.publishThrowError) {
641
+ log.error("RPC server threw an error on publish(), will stop publication", error);
642
+ await this._postSucessOrFailurePublishing();
643
+ }
644
+ this.emit("error", error);
645
+ }
646
+ async _publishWithRpc() {
647
+ if (!this._pkc._pkcRpcClient)
648
+ throw Error("Can't publish to RPC without publication.pkc.pkcRpcClient being defined");
649
+ this._setStateWithEmission("publishing");
650
+ const pubNameToPublishFunction = {
651
+ comment: this._pkc._pkcRpcClient.publishComment,
652
+ vote: this._pkc._pkcRpcClient.publishVote,
653
+ commentEdit: this._pkc._pkcRpcClient.publishCommentEdit,
654
+ commentModeration: this._pkc._pkcRpcClient.publishCommentModeration,
655
+ communityEdit: this._pkc._pkcRpcClient.publishCommunityEdit
656
+ };
657
+ // PKCRpcClient will take care of zod parsing for us
658
+ this._rpcPublishSubscriptionId = await pubNameToPublishFunction[this.getType()].bind(this._pkc._pkcRpcClient)(this.toJSONPubsubRequestToEncrypt());
659
+ if (typeof this._rpcPublishSubscriptionId !== "number") {
660
+ this._updatePublishingStateWithEmission("failed");
661
+ await this._postSucessOrFailurePublishing();
662
+ throw Error("Failed to find the type of publication");
663
+ }
664
+ this._pkc._pkcRpcClient
665
+ .getSubscription(this._rpcPublishSubscriptionId)
666
+ .on("challengerequest", this._handleIncomingChallengeRequestFromRpc.bind(this))
667
+ .on("challenge", this._handleIncomingChallengeFromRpc.bind(this))
668
+ .on("challengeanswer", this._handleIncomingChallengeAnswerFromRpc.bind(this))
669
+ .on("challengeverification", this._handleIncomingChallengeVerificationFromRpc.bind(this))
670
+ .on("publishingstatechange", this._handleIncomingPublishingStateFromRpc.bind(this))
671
+ .on("statechange", this._handleIncomingStateFromRpc.bind(this))
672
+ .on("error", this._handleIncomingErrorFromRpc.bind(this));
673
+ this._pkc._pkcRpcClient.emitAllPendingMessages(this._rpcPublishSubscriptionId);
674
+ }
675
+ _changePublicationStateEmitEventEmitStateChangeEvent(opts) {
676
+ // this code block is only called on a community whose update loop is already started
677
+ // never called in a community that is mirroring a community with an update loop
678
+ const shouldEmitStateChange = opts.newState && opts.newState !== this.state;
679
+ const shouldEmitPublishingstatechange = opts.newPublishingState && opts.newPublishingState !== this.publishingState;
680
+ if (opts.newState)
681
+ this._setStateNoEmission(opts.newState);
682
+ if (opts.newPublishingState)
683
+ this._updatePublishingStateNoEmission(opts.newPublishingState);
684
+ this.emit(opts.event.name, ...opts.event.args);
685
+ if (shouldEmitStateChange)
686
+ this.emit("statechange", this.state);
687
+ if (shouldEmitPublishingstatechange)
688
+ this.emit("publishingstatechange", this.publishingState);
689
+ }
690
+ async _signAndValidateChallengeRequestBeforePublishing(toSignMsg, pubsubSigner) {
691
+ // No validation for now, we might add in the future
692
+ return {
693
+ ...toSignMsg,
694
+ signature: await signChallengeRequest({ request: toSignMsg, signer: pubsubSigner })
695
+ };
696
+ }
697
+ _didWeReceiveChallengeOrChallengeVerification() {
698
+ return Object.values(this._challengeExchanges).some((exchange) => exchange.challenge || exchange.challengeVerification);
699
+ }
700
+ async _generateChallengeRequestToPublish(providerUrl, acceptedChallengeTypes) {
701
+ const log = Logger("pkc-js:publication:publish:_generateChallengeRequestToPublish");
702
+ const pubsubMessageSigner = await this._pkc.createSigner();
703
+ const pubsubMsgToEncrypt = this.toJSONPubsubRequestToEncrypt();
704
+ const encrypted = await encryptEd25519AesGcm(JSON.stringify(pubsubMsgToEncrypt), pubsubMessageSigner.privateKey, this._community.encryption.publicKey);
705
+ const challengeRequestId = await getBufferedPKCAddressFromPublicKey(pubsubMessageSigner.publicKey);
706
+ const toSignMsg = cleanUpBeforePublishing({
707
+ type: "CHALLENGEREQUEST",
708
+ encrypted,
709
+ challengeRequestId,
710
+ acceptedChallengeTypes,
711
+ userAgent: this._pkc.userAgent,
712
+ protocolVersion: env.PROTOCOL_VERSION,
713
+ timestamp: timestamp()
714
+ });
715
+ const challengeRequest = await this._signAndValidateChallengeRequestBeforePublishing(toSignMsg, pubsubMessageSigner);
716
+ log("Attempting to publish", this.getType(), "to pubsub topic", this._communityPubsubTopicWithFallback(), "with provider", providerUrl, "request.encrypted=", pubsubMsgToEncrypt);
717
+ const decryptedChallengeRequest = { ...challengeRequest, ...pubsubMsgToEncrypt };
718
+ this._challengeExchanges[challengeRequestId.toString()] = {
719
+ challengeRequest: decryptedChallengeRequest,
720
+ signer: pubsubMessageSigner,
721
+ providerUrl
722
+ };
723
+ return challengeRequest;
724
+ }
725
+ async _initCommunity() {
726
+ if (this._community)
727
+ return;
728
+ try {
729
+ this._community = await this._fetchCommunityForPublishing();
730
+ this._validateCommunityFields();
731
+ }
732
+ catch (e) {
733
+ this._setStateWithEmission("stopped");
734
+ this._updatePublishingStateWithEmission("failed");
735
+ throw e;
736
+ }
737
+ }
738
+ _challengeExchangesFormattedForErrors() {
739
+ return Object.values(this._challengeExchanges).map((exchange) => ({
740
+ ...exchange,
741
+ timedoutWaitingForChallengeRequestResponse: !exchange.challengeVerification &&
742
+ !exchange.challenge &&
743
+ typeof exchange.challengeRequestPublishTimestamp === "number" &&
744
+ exchange.challengeRequestPublishTimestamp + this._setProviderFailureThresholdSeconds <= timestamp()
745
+ }));
746
+ }
747
+ async _handleNotReceivingResponseToChallengeRequest({ providers, currentPubsubProviderIndex, acceptedChallengeTypes }) {
748
+ await new Promise((resolve) => setTimeout(resolve, this._publishToDifferentProviderThresholdSeconds * 1000));
749
+ if (this._didWeReceiveChallengeOrChallengeVerification())
750
+ return;
751
+ // this provider did not get us a challenge or challenge verification
752
+ const currentPubsubProvider = providers[currentPubsubProviderIndex];
753
+ this._pkc._stats.recordGatewayFailure(currentPubsubProvider, "pubsub-publish");
754
+ this._pkc._stats.recordGatewayFailure(currentPubsubProvider, "pubsub-subscribe");
755
+ const log = Logger("pkc-js:publication:publish:_handleNotReceivingResponseToChallengeRequest");
756
+ if (this._isAllAttemptsExhausted(providers.length)) {
757
+ // pkc-js tried all providers and still no response is received
758
+ log.error(`Failed to receive any response for publication`, this.getType());
759
+ await this._postSucessOrFailurePublishing();
760
+ const error = new PKCError("ERR_PUBSUB_DID_NOT_RECEIVE_RESPONSE_AFTER_PUBLISHING_CHALLENGE_REQUEST", {
761
+ challengeExchanges: this._challengeExchangesFormattedForErrors(),
762
+ publishToDifferentProviderThresholdSeconds: this._publishToDifferentProviderThresholdSeconds
763
+ });
764
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
765
+ newPublishingState: "failed",
766
+ event: { name: "error", args: [error] }
767
+ });
768
+ }
769
+ else if (this.state === "stopped") {
770
+ log.error(`Publication is stopped, will not re-publish`);
771
+ await this._postSucessOrFailurePublishing();
772
+ }
773
+ else {
774
+ if (currentPubsubProviderIndex + 1 === providers.length) {
775
+ log.error(`Failed to receive any response for publication`, this.getType(), "after publishing to all providers", providers);
776
+ await this._postSucessOrFailurePublishing();
777
+ }
778
+ else {
779
+ // let's publish to the next provider
780
+ log(`Re-publishing publication after ${this._publishToDifferentProviderThresholdSeconds}s of not receiving challenge from provider (${currentPubsubProvider})`);
781
+ currentPubsubProviderIndex += 1;
782
+ while (!this._didWeReceiveChallengeOrChallengeVerification() && currentPubsubProviderIndex < providers.length) {
783
+ const providerUrl = providers[currentPubsubProviderIndex];
784
+ const challengeRequest = await this._generateChallengeRequestToPublish(providerUrl, acceptedChallengeTypes);
785
+ this._updatePublishingStateWithEmission("publishing-challenge-request");
786
+ this._updatePubsubState("subscribing-pubsub", providerUrl);
787
+ try {
788
+ await this._clientsManager.pubsubSubscribeOnProvider(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange, providerUrl);
789
+ this._updatePubsubState("publishing-challenge-request", providerUrl);
790
+ await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), challengeRequest, providerUrl);
791
+ this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp =
792
+ timestamp();
793
+ }
794
+ catch (e) {
795
+ log.error("Failed to publish challenge request using provider ", providerUrl, e);
796
+ this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishError = e;
797
+ continue;
798
+ }
799
+ finally {
800
+ currentPubsubProviderIndex += 1;
801
+ }
802
+ const decryptedRequest = this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequest;
803
+ this._updatePubsubState("waiting-challenge", providerUrl);
804
+ this._updatePublishingStateWithEmission("waiting-challenge");
805
+ log(`Published a challenge request of publication`, this.getType(), "with provider", providerUrl);
806
+ this.emit("challengerequest", decryptedRequest);
807
+ if (currentPubsubProviderIndex !== providers.length)
808
+ await new Promise((resolve) => setTimeout(resolve, this._publishToDifferentProviderThresholdSeconds * 1000));
809
+ }
810
+ await new Promise((resolve) => setTimeout(resolve, this._setProviderFailureThresholdSeconds * 1000));
811
+ if (this._isAllAttemptsExhausted(providers.length)) {
812
+ await this._postSucessOrFailurePublishing();
813
+ const allAttemptsFailedError = new PKCError("ERR_ALL_PUBSUB_PROVIDERS_THROW_ERRORS", {
814
+ challengeExchanges: this._challengeExchangesFormattedForErrors(),
815
+ pubsubTopic: this._communityPubsubTopicWithFallback()
816
+ });
817
+ log.error("All attempts to publish", this.getType(), "has failed", allAttemptsFailedError);
818
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
819
+ newPublishingState: "failed",
820
+ event: { name: "error", args: [allAttemptsFailedError] }
821
+ });
822
+ return;
823
+ }
824
+ }
825
+ }
826
+ }
827
+ _getPubsubProviders() {
828
+ const providers = this.clients.libp2pJsClients && remeda.keys.strict(this.clients.libp2pJsClients).length > 0
829
+ ? remeda.keys.strict(this.clients.libp2pJsClients)
830
+ : remeda.keys.strict(this.clients.pubsubKuboRpcClients);
831
+ if (providers.length === 0)
832
+ throw new PKCError("ERR_NO_PUBSUB_PROVIDERS_AVAILABLE_TO_PUBLISH_OVER_PUBSUB", { providers });
833
+ if (providers.length === 1)
834
+ providers.push(providers[0]); // Same provider should be retried twice if publishing fails
835
+ return providers;
836
+ }
837
+ async _publishWithLocalCommunity(community, challengeRequest) {
838
+ this._publishingToLocalCommunity = community;
839
+ const log = Logger("pkc-js:publication:publish:_publishWithLocalCommunity");
840
+ log("Community is local, will not publish over pubsub, and instead will publish directly to the community by accessing pkc._startedCommunities");
841
+ const communityChallengeListener = async (challenge) => {
842
+ if (challenge.challengeRequestId.toString() === challengeRequest.challengeRequestId.toString()) {
843
+ // need to remove encrypted fields from challenge otherwise _handleIncomingChallengePubsubMessage will throw
844
+ const encryptedFields = ["challenges"];
845
+ log("Received a challenge from the local community", challenge);
846
+ await this._handleIncomingChallengePubsubMessage(remeda.omit(challenge, encryptedFields));
847
+ }
848
+ };
849
+ community.on("challenge", communityChallengeListener);
850
+ const communityChallengeVerificationListener = async (decryptedChallengeVerification) => {
851
+ if (decryptedChallengeVerification.challengeRequestId.toString() === challengeRequest.challengeRequestId.toString()) {
852
+ log("Received a challenge verification from the local community", decryptedChallengeVerification);
853
+ // need to remove publicatioon fields from challenge verification otherwise verifyChallengeVerification will throw
854
+ const publicationFieldsToRemove = ["comment", "commentUpdate"];
855
+ await this._handleIncomingChallengeVerificationPubsubMessage(remeda.omit(decryptedChallengeVerification, publicationFieldsToRemove));
856
+ }
857
+ };
858
+ community.on("challengeverification", communityChallengeVerificationListener);
859
+ this.emit("challengerequest", challengeRequest);
860
+ community
861
+ .handleChallengeRequest(challengeRequest, true)
862
+ .then(() => {
863
+ this._challengeExchanges[challengeRequest.challengeRequestId.toString()] = {
864
+ ...this._challengeExchanges[challengeRequest.challengeRequestId.toString()],
865
+ challengeRequestPublishTimestamp: timestamp()
866
+ };
867
+ })
868
+ .catch((e) => {
869
+ log.error("Failed to handle challenge request with local community", e);
870
+ this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishError = e;
871
+ throw e;
872
+ })
873
+ .finally(() => {
874
+ community.removeListener("challenge", communityChallengeListener);
875
+ community.removeListener("challengeverification", communityChallengeVerificationListener);
876
+ });
877
+ }
878
+ async publish() {
879
+ const log = Logger("pkc-js:publication:publish");
880
+ this._validatePublicationFields();
881
+ this._setStateWithEmission("publishing");
882
+ // Fetch community for BOTH RPC and non-RPC paths (needed for signing)
883
+ await this._initCommunity();
884
+ // Sign the publication with community fields if not yet signed
885
+ if (this.raw.unsignedPublicationOptions && !this.raw.pubsubMessageToPublish) {
886
+ await this._signPublicationWithCommunityFields();
887
+ }
888
+ await this._validateSignatureHook();
889
+ if (this._pkc._pkcRpcClient)
890
+ return this._publishWithRpc();
891
+ const options = { acceptedChallengeTypes: [] };
892
+ const providers = this._getPubsubProviders();
893
+ const startedCommunity = findStartedCommunity(this._pkc, { address: this.communityAddress });
894
+ if (startedCommunity) {
895
+ return this._publishWithLocalCommunity(startedCommunity, await this._generateChallengeRequestToPublish("publishing directly to local community instance", options.acceptedChallengeTypes));
896
+ }
897
+ let currentPubsubProviderIndex = 0;
898
+ while (!this._didWeReceiveChallengeOrChallengeVerification() && currentPubsubProviderIndex < providers.length) {
899
+ const providerUrl = providers[currentPubsubProviderIndex];
900
+ const challengeRequest = await this._generateChallengeRequestToPublish(providerUrl, options.acceptedChallengeTypes);
901
+ this._updatePublishingStateWithEmission("publishing-challenge-request");
902
+ this._updatePubsubState("subscribing-pubsub", providerUrl);
903
+ try {
904
+ // this will throw if we succeed in subscribing first attempt, but then fail to publish
905
+ await this._clientsManager.pubsubSubscribeOnProvider(this._communityPubsubTopicWithFallback(), this._handleChallengeExchange, providerUrl);
906
+ this._updatePubsubState("publishing-challenge-request", providerUrl);
907
+ await this._clientsManager.pubsubPublishOnProvider(this._communityPubsubTopicWithFallback(), challengeRequest, providerUrl);
908
+ this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishTimestamp = timestamp();
909
+ }
910
+ catch (e) {
911
+ this._updatePubsubState("stopped", providerUrl);
912
+ log.error("Failed to publish challenge request using provider ", providerUrl, e);
913
+ currentPubsubProviderIndex += 1;
914
+ this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequestPublishError = e;
915
+ if (this._isAllAttemptsExhausted(providers.length)) {
916
+ await this._postSucessOrFailurePublishing();
917
+ const allAttemptsFailedError = new PKCError("ERR_ALL_PUBSUB_PROVIDERS_THROW_ERRORS", {
918
+ challengeExchanges: this._challengeExchangesFormattedForErrors(),
919
+ pubsubTopic: this._communityPubsubTopicWithFallback()
920
+ });
921
+ log.error("All attempts to publish", this.getType(), "has failed", allAttemptsFailedError);
922
+ this._changePublicationStateEmitEventEmitStateChangeEvent({
923
+ newPublishingState: "failed",
924
+ event: { name: "error", args: [allAttemptsFailedError] }
925
+ });
926
+ throw allAttemptsFailedError;
927
+ }
928
+ else
929
+ continue;
930
+ }
931
+ const decryptedRequest = this._challengeExchanges[challengeRequest.challengeRequestId.toString()].challengeRequest;
932
+ this._updatePubsubState("waiting-challenge", providerUrl);
933
+ this._updatePublishingStateWithEmission("waiting-challenge");
934
+ log(`Published a challenge request of publication`, this.getType(), "with provider", providerUrl);
935
+ this.emit("challengerequest", decryptedRequest);
936
+ break;
937
+ }
938
+ // to handle cases where request is published but we didn't receive response within certain timeframe (20s for now)
939
+ // Maybe the community didn't receive the request, or the provider did not relay the challenge from community for some reason
940
+ this._handleNotReceivingResponseToChallengeRequest({
941
+ providers,
942
+ currentPubsubProviderIndex,
943
+ acceptedChallengeTypes: options.acceptedChallengeTypes
944
+ }).catch((err) => {
945
+ log.error("Failed to handle not receiving response to challenge request", err);
946
+ });
947
+ }
948
+ }
949
+ export default Publication;
950
+ //# sourceMappingURL=publication.js.map