@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,888 @@
1
+ import { getDefaultDataPath, listCommunitiesSync as nodeListCommunities, createKuboRpcClient, monitorCommunitiesDirectory, tryToDeleteCommunitiesThatFailedToBeDeletedBefore } from "../runtime/node/util.js";
2
+ import { Comment } from "../publications/comment/comment.js";
3
+ import { waitForUpdateInCommunityInstanceWithErrorAndTimeout, areEquivalentCommunityAddresses, deepMergeRuntimeFields, doesDomainAddressHaveCapitalLetter, hideClassPrivateProps, isStringDomain, removeUndefinedValuesRecursively, timestamp, resolveWhenPredicateIsTrue } from "../util.js";
4
+ import Vote from "../publications/vote/vote.js";
5
+ import { createSigner } from "../signer/index.js";
6
+ import { CommentEdit } from "../publications/comment-edit/comment-edit.js";
7
+ import Logger from "../logger.js";
8
+ import env from "../version.js";
9
+ import { verifyCommentIpfs, verifyCommentUpdate } from "../signer/signatures.js";
10
+ import Stats from "../stats.js";
11
+ import Storage from "../runtime/node/storage.js";
12
+ import { PKCClientsManager } from "./pkc-client-manager.js";
13
+ import PKCRpcClient from "../clients/rpc-client/pkc-rpc-client.js";
14
+ import { PKCError } from "../pkc-error.js";
15
+ import { InflightFetchManager } from "../util/inflight-fetch-manager.js";
16
+ import LRUStorage from "../runtime/node/lru-storage.js";
17
+ import { RemoteCommunity } from "../community/remote-community.js";
18
+ import { LocalCommunity } from "../runtime/node/community/local-community.js";
19
+ import { extractCommunityRuntimeFieldsFromParsedPages } from "../pages/util.js";
20
+ import pTimeout, { TimeoutError } from "p-timeout";
21
+ import * as remeda from "remeda";
22
+ import { PubsubTopicSchema, CommunityIpfsSchema } from "../community/schema.js";
23
+ import { parseCidStringSchemaWithPKCErrorIfItFails, parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, parseCommentIpfsSchemaWithPKCErrorIfItFails, parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, parsePKCUserOptionsSchemaWithPKCErrorIfItFails, parseCommunityAddressWithPKCErrorIfItFails, parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails } from "../schema/schema-util.js";
24
+ import { CommentModeration } from "../publications/comment-moderation/comment-moderation.js";
25
+ import { setupKuboAddressesRewriterAndHttpRouters } from "../runtime/node/setup-kubo-address-rewriter-and-http-router.js";
26
+ import CommunityEdit from "../publications/community-edit/community-edit.js";
27
+ import { LRUCache } from "lru-cache";
28
+ import { PKCTypedEmitter } from "../clients/pkc-typed-emitter.js";
29
+ import { createLibp2pJsClientOrUseExistingOne } from "../helia/helia-for-pkc.js";
30
+ import { parseRpcAuthorNameParam, parseRpcCidParam, parseRpcCommunityLookupParam } from "../clients/rpc-client/rpc-schema-util.js";
31
+ import { cleanWireAuthor, normalizeCreatePublicationAuthor } from "../publications/publication-author.js";
32
+ import { TrackedInstanceRegistry } from "./tracked-instance-registry.js";
33
+ import { findUpdatingCommunity, listStartedCommunities, listUpdatingComments, listUpdatingCommunities } from "./tracked-instance-registry-util.js";
34
+ export class PKC extends PKCTypedEmitter {
35
+ constructor(options) {
36
+ super();
37
+ this._pubsubSubscriptions = {};
38
+ this._updatingCommunities = new TrackedInstanceRegistry(); // storing community instances that are getting updated rn
39
+ this._updatingComments = new TrackedInstanceRegistry(); // storing comment instancse that are getting updated rn
40
+ this._startedCommunities = new TrackedInstanceRegistry(); // storing community instances that are started rn
41
+ this.destroyed = false;
42
+ this._storageLRUs = {}; // Cache name to storage interface
43
+ this._timeouts = {
44
+ "community-ipns": 5 * 60 * 1000, // 5min, for resolving community IPNS, or fetching community from gateways
45
+ "community-ipfs": 60 * 1000, // 1min, for fetching community cid P2P
46
+ "comment-ipfs": 60 * 1000, // 1 min
47
+ "comment-update-ipfs": 2 * 60 * 1000, // 2 min
48
+ "page-ipfs": 30 * 1000, // 30s for pages
49
+ "generic-ipfs": 30 * 1000 // 30s generic ipfs
50
+ }; // timeout in ms for each load type when we're loading from kubo/helia/gateway
51
+ this._userPKCOptions = options;
52
+ this.parsedPKCOptions = parsePKCUserOptionsSchemaWithPKCErrorIfItFails(options);
53
+ // Make nameResolver function props non-enumerable so they're excluded from JSON serialization and spread
54
+ if (this.parsedPKCOptions.nameResolvers) {
55
+ for (const resolver of this.parsedPKCOptions.nameResolvers) {
56
+ Object.defineProperty(resolver, "resolve", {
57
+ enumerable: false,
58
+ value: resolver.resolve,
59
+ writable: true,
60
+ configurable: true
61
+ });
62
+ Object.defineProperty(resolver, "canResolve", {
63
+ enumerable: false,
64
+ value: resolver.canResolve,
65
+ writable: true,
66
+ configurable: true
67
+ });
68
+ if (resolver.destroy) {
69
+ Object.defineProperty(resolver, "destroy", {
70
+ enumerable: false,
71
+ value: resolver.destroy,
72
+ writable: true,
73
+ configurable: true
74
+ });
75
+ }
76
+ }
77
+ }
78
+ // initializing fields
79
+ this.pkcRpcClientsOptions = this.parsedPKCOptions.pkcRpcClientsOptions;
80
+ this.ipfsGatewayUrls = this.parsedPKCOptions.ipfsGatewayUrls =
81
+ this.pkcRpcClientsOptions || !this.parsedPKCOptions.ipfsGatewayUrls?.length ? undefined : this.parsedPKCOptions.ipfsGatewayUrls;
82
+ this.kuboRpcClientsOptions = this.parsedPKCOptions.kuboRpcClientsOptions = this.pkcRpcClientsOptions
83
+ ? undefined
84
+ : this.parsedPKCOptions.kuboRpcClientsOptions;
85
+ // We default for ipfsHttpClientsOptions first, but if it's not defined we use the default from schema
86
+ this.pubsubKuboRpcClientsOptions = this.parsedPKCOptions.pubsubKuboRpcClientsOptions = this.pkcRpcClientsOptions
87
+ ? undefined
88
+ : this._userPKCOptions.pubsubKuboRpcClientsOptions // did the user provide their own pubsub options
89
+ ? this.parsedPKCOptions.pubsubKuboRpcClientsOptions // if not, then we use ipfsHttpClientOptions or defaults
90
+ : this.parsedPKCOptions.kuboRpcClientsOptions || this.parsedPKCOptions.pubsubKuboRpcClientsOptions;
91
+ this.libp2pJsClientsOptions = this.parsedPKCOptions.libp2pJsClientsOptions;
92
+ if (this.libp2pJsClientsOptions && (this.kuboRpcClientsOptions?.length || this.pubsubKuboRpcClientsOptions?.length))
93
+ throw new PKCError("ERR_CAN_NOT_HAVE_BOTH_KUBO_AND_LIBP2P_JS_CLIENTS_DEFINED", {
94
+ libp2pJsClientsOptions: this.libp2pJsClientsOptions,
95
+ kuboRpcClientsOptions: this.kuboRpcClientsOptions,
96
+ pubsubKuboRpcClientsOptions: this.pubsubKuboRpcClientsOptions
97
+ });
98
+ this.resolveAuthorNames = this.parsedPKCOptions.resolveAuthorNames;
99
+ this.publishInterval = this.parsedPKCOptions.publishInterval;
100
+ this.updateInterval = this.parsedPKCOptions.updateInterval;
101
+ this.noData = this.parsedPKCOptions.noData;
102
+ this.validatePages = this.parsedPKCOptions.validatePages;
103
+ this.userAgent = this.parsedPKCOptions.userAgent;
104
+ this.httpRoutersOptions = this.parsedPKCOptions.httpRoutersOptions;
105
+ this.settings = {
106
+ challenges: this.parsedPKCOptions.challenges
107
+ };
108
+ // nameResolvers contains functions that can't be serialized over RPC, so skip for RPC clients
109
+ this.nameResolvers = this.pkcRpcClientsOptions ? undefined : this.parsedPKCOptions.nameResolvers;
110
+ this.on("communitieschange", (newCommunities) => {
111
+ this.communities = newCommunities;
112
+ });
113
+ this._promiseToWaitForFirstCommunitieschangeEvent = new Promise((resolve) => this.once("communitieschange", resolve));
114
+ //@ts-expect-error
115
+ this.clients = {};
116
+ this._initKuboRpcClientsIfNeeded();
117
+ this._initKuboPubsubClientsIfNeeded();
118
+ this._initRpcClientsIfNeeded();
119
+ this._initIpfsGatewaysIfNeeded();
120
+ this._initMemCaches();
121
+ this._inflightFetchManager = new InflightFetchManager();
122
+ if (!this.noData && !this.pkcRpcClientsOptions)
123
+ this.dataPath = this.parsedPKCOptions.dataPath =
124
+ "dataPath" in this.parsedPKCOptions ? this.parsedPKCOptions.dataPath : getDefaultDataPath();
125
+ }
126
+ _initMemCaches() {
127
+ this._memCaches = {
128
+ communityVerificationCache: new LRUCache({ max: 100 }),
129
+ pageVerificationCache: new LRUCache({ max: 1000 }),
130
+ commentVerificationCache: new LRUCache({ max: 5000 }),
131
+ commentUpdateVerificationCache: new LRUCache({ max: 100_000 }),
132
+ commentIpfs: new LRUCache({ max: 10 }),
133
+ communityForPublishing: new LRUCache({
134
+ max: 100,
135
+ ttl: 600000
136
+ }),
137
+ pageCidToSortTypes: new LRUCache({ max: 5000 }),
138
+ pagesMaxSize: new LRUCache({ max: 50000 }),
139
+ nameResolvedCache: new LRUCache({ max: 5000 })
140
+ };
141
+ }
142
+ _initKuboRpcClientsIfNeeded() {
143
+ this.clients.kuboRpcClients = {};
144
+ if (!this.kuboRpcClientsOptions)
145
+ return;
146
+ for (const clientOptions of this.kuboRpcClientsOptions) {
147
+ const kuboRpcClient = createKuboRpcClient(clientOptions);
148
+ this.clients.kuboRpcClients[clientOptions.url.toString()] = {
149
+ _client: kuboRpcClient,
150
+ _clientOptions: clientOptions,
151
+ peers: kuboRpcClient.swarm.peers,
152
+ url: clientOptions.url.toString(),
153
+ destroy: async () => { }
154
+ };
155
+ }
156
+ }
157
+ _initKuboPubsubClientsIfNeeded() {
158
+ this.clients.pubsubKuboRpcClients = {};
159
+ if (!this.pubsubKuboRpcClientsOptions)
160
+ return;
161
+ for (const clientOptions of this.pubsubKuboRpcClientsOptions) {
162
+ const kuboRpcClient = createKuboRpcClient(clientOptions);
163
+ this.clients.pubsubKuboRpcClients[clientOptions.url.toString()] = {
164
+ _client: kuboRpcClient,
165
+ _clientOptions: clientOptions,
166
+ peers: async () => {
167
+ const topics = await kuboRpcClient.pubsub.ls();
168
+ const topicPeers = remeda.flattenDeep(await Promise.all(topics.map((topic) => kuboRpcClient.pubsub.peers(topic))));
169
+ const peers = remeda.unique(topicPeers.map((topicPeer) => topicPeer.toString()));
170
+ return peers;
171
+ },
172
+ url: clientOptions.url.toString(),
173
+ destroy: async () => { }
174
+ };
175
+ }
176
+ }
177
+ async _initLibp2pJsClientsIfNeeded() {
178
+ this.clients.libp2pJsClients = {};
179
+ if (!this.libp2pJsClientsOptions)
180
+ return;
181
+ if (!this.httpRoutersOptions)
182
+ throw Error("httpRoutersOptions is required for libp2pJsClient");
183
+ for (const clientOptions of this.libp2pJsClientsOptions) {
184
+ const heliaNode = await createLibp2pJsClientOrUseExistingOne({
185
+ ...clientOptions,
186
+ httpRoutersOptions: this.httpRoutersOptions
187
+ });
188
+ this.clients.libp2pJsClients[clientOptions.key] = heliaNode;
189
+ }
190
+ }
191
+ _initRpcClientsIfNeeded() {
192
+ this.clients.pkcRpcClients = {};
193
+ if (!this.pkcRpcClientsOptions)
194
+ return;
195
+ for (const rpcUrl of this.pkcRpcClientsOptions)
196
+ this.clients.pkcRpcClients[rpcUrl] = new PKCRpcClient(rpcUrl);
197
+ }
198
+ _initIpfsGatewaysIfNeeded() {
199
+ // If user did not provide ipfsGatewayUrls
200
+ this.clients.ipfsGateways = {};
201
+ if (!this.ipfsGatewayUrls)
202
+ return;
203
+ for (const gatewayUrl of this.ipfsGatewayUrls)
204
+ this.clients.ipfsGateways[gatewayUrl] = {};
205
+ }
206
+ async _setupHttpRoutersWithKuboNodeInBackground() {
207
+ const log = Logger("pkc-js:pkc:_initHttpRoutersWithIpfsInBackground");
208
+ if (this.destroyed)
209
+ return;
210
+ if (this.httpRoutersOptions?.length && this.kuboRpcClientsOptions?.length && this._canCreateNewLocalCommunity()) {
211
+ // only for node
212
+ const setupPromise = setupKuboAddressesRewriterAndHttpRouters(this)
213
+ .then(async (addressesRewriterProxyServer) => {
214
+ if (this.destroyed) {
215
+ await addressesRewriterProxyServer.destroy();
216
+ return;
217
+ }
218
+ log("Set http router options and their proxies successfully on all connected ipfs", Object.keys(this.clients.kuboRpcClients));
219
+ this._addressRewriterDestroy = addressesRewriterProxyServer.destroy;
220
+ })
221
+ .catch((e) => {
222
+ if (this.destroyed)
223
+ return;
224
+ log.error("Failed to set http router options and their proxies on ipfs nodes due to error", e);
225
+ this.emit("error", e);
226
+ });
227
+ this._addressRewriterSetupPromise = setupPromise;
228
+ }
229
+ }
230
+ async _init() {
231
+ const log = Logger("pkc-js:pkc:_init");
232
+ // Init storage
233
+ this._storage = new Storage(this);
234
+ await this._storage.init();
235
+ // Init stats
236
+ this._stats = new Stats({ _storage: this._storage, clients: this.clients });
237
+ // Init clients manager
238
+ // pkc-with-rpc-client will subscribe to communitieschange and settingschange for us
239
+ if (this._canCreateNewLocalCommunity() && !this.pkcRpcClientsOptions) {
240
+ await tryToDeleteCommunitiesThatFailedToBeDeletedBefore(this, log);
241
+ this._communityFsWatchAbort = await monitorCommunitiesDirectory(this);
242
+ await this._waitForCommunitiesToBeDefined();
243
+ }
244
+ else {
245
+ this.communities = []; // communities = [] on browser
246
+ }
247
+ await this._setupHttpRoutersWithKuboNodeInBackground();
248
+ await this._initLibp2pJsClientsIfNeeded();
249
+ this._clientsManager = new PKCClientsManager(this);
250
+ hideClassPrivateProps(this);
251
+ }
252
+ async getCommunity(getCommunityArgs) {
253
+ const parsedArgs = parseRpcCommunityLookupParam(getCommunityArgs);
254
+ const community = await this.createCommunity(parsedArgs);
255
+ if (typeof community.createdAt === "number")
256
+ return community; // It's a local community, and already has been loaded, no need to wait
257
+ const timeoutMs = this._timeouts["community-ipns"];
258
+ await waitForUpdateInCommunityInstanceWithErrorAndTimeout(community, timeoutMs);
259
+ return community;
260
+ }
261
+ async getComment(cid) {
262
+ const log = Logger("pkc-js:pkc:getComment");
263
+ const parsedGetCommentArgs = parseRpcCidParam(cid);
264
+ // getComment is interested in loading CommentIpfs only
265
+ const comment = await this.createComment(parsedGetCommentArgs);
266
+ let lastUpdateError;
267
+ const errorListener = (err) => (lastUpdateError = err);
268
+ comment.on("error", errorListener);
269
+ const commentTimeout = this._timeouts["comment-ipfs"];
270
+ try {
271
+ await pTimeout(comment._attemptInfintelyToLoadCommentIpfs(), {
272
+ milliseconds: commentTimeout,
273
+ message: lastUpdateError ||
274
+ new TimeoutError(`pkc.getComment({cid: ${parsedGetCommentArgs}}) timed out after ${commentTimeout}ms`)
275
+ });
276
+ if (!comment.signature)
277
+ throw Error("Failed to load CommentIpfs");
278
+ return comment;
279
+ }
280
+ catch (e) {
281
+ if (lastUpdateError)
282
+ throw lastUpdateError;
283
+ throw e;
284
+ }
285
+ finally {
286
+ comment.removeListener("error", errorListener);
287
+ await comment.stop();
288
+ }
289
+ }
290
+ async _initMissingFieldsOfPublicationBeforeSigning(pubOptions, log) {
291
+ const finalOptions = remeda.clone(pubOptions);
292
+ if (!finalOptions.signer)
293
+ throw Error("User did not provide a signer to create a local publication");
294
+ const normalizedAuthor = normalizeCreatePublicationAuthor(finalOptions.author);
295
+ let cleanedAuthor = cleanWireAuthor(normalizedAuthor);
296
+ // Strip empty objects from author — empty {} should not be signed
297
+ if (cleanedAuthor) {
298
+ for (const key of Object.keys(cleanedAuthor)) {
299
+ const val = cleanedAuthor[key];
300
+ if (typeof val === "object" && val !== null && !Array.isArray(val) && Object.keys(val).length === 0)
301
+ delete cleanedAuthor[key];
302
+ }
303
+ if (remeda.isEmpty(cleanedAuthor))
304
+ cleanedAuthor = undefined;
305
+ }
306
+ const filledTimestamp = typeof finalOptions.timestamp !== "number" ? timestamp() : finalOptions.timestamp;
307
+ const filledSigner = await this.createSigner(finalOptions.signer);
308
+ const filledProtocolVersion = finalOptions.protocolVersion || env.PROTOCOL_VERSION;
309
+ return {
310
+ ...finalOptions,
311
+ timestamp: filledTimestamp,
312
+ signer: filledSigner,
313
+ author: cleanedAuthor,
314
+ protocolVersion: filledProtocolVersion
315
+ };
316
+ }
317
+ async _createCommentInstanceFromAnotherCommentInstance(options) {
318
+ const commentInstance = new Comment(this);
319
+ if (options.cid)
320
+ commentInstance.setCid(options.cid);
321
+ if (options.communityAddress)
322
+ commentInstance.setCommunityAddress(options.communityAddress);
323
+ if (options.raw?.commentUpdate?.cid)
324
+ commentInstance.setCid(options.raw?.commentUpdate?.cid);
325
+ if ("pubsubMessageToPublish" in options.raw && options.raw.pubsubMessageToPublish && "signer" in options && options.signer)
326
+ commentInstance._initLocalProps({
327
+ comment: options.raw.pubsubMessageToPublish,
328
+ signer: options.signer,
329
+ challengeRequest: options.challengeRequest
330
+ });
331
+ else if ("signer" in options && options.signer) {
332
+ const unsignedOpts = options.raw.unsignedPublicationOptions;
333
+ if (unsignedOpts) {
334
+ const log = Logger("pkc-js:pkc:createComment");
335
+ const finalOptions = (await this._initMissingFieldsOfPublicationBeforeSigning({ ...unsignedOpts, signer: options.signer }, log));
336
+ commentInstance._initUnsignedLocalProps({
337
+ unsignedOptions: finalOptions,
338
+ challengeRequest: options.challengeRequest
339
+ });
340
+ await commentInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
341
+ }
342
+ }
343
+ if (options.raw.comment)
344
+ commentInstance._initIpfsProps(options.raw.comment);
345
+ // can only get one CommentUpdate
346
+ if ("commentUpdateFromChallengeVerification" in options.raw && options.raw.commentUpdateFromChallengeVerification)
347
+ commentInstance._initCommentUpdateFromChallengeVerificationProps(options.raw.commentUpdateFromChallengeVerification);
348
+ if (options.raw.commentUpdate)
349
+ commentInstance._initCommentUpdate(options.raw.commentUpdate);
350
+ // nameResolved is strictly runtime — never carry it over when cloning
351
+ if (commentInstance.author?.nameResolved !== undefined)
352
+ delete commentInstance.author.nameResolved;
353
+ return commentInstance;
354
+ }
355
+ async createComment(options) {
356
+ const log = Logger("pkc-js:pkc:createComment");
357
+ if ("clients" in options || "raw" in options || "original" in options || options instanceof Comment)
358
+ return this._createCommentInstanceFromAnotherCommentInstance(options); // CommentJson
359
+ const commentInstance = new Comment(this);
360
+ if ("communityAddress" in options && options.communityAddress)
361
+ commentInstance.setCommunityAddress(parseCommunityAddressWithPKCErrorIfItFails(options.communityAddress));
362
+ else if ("subplebbitAddress" in options && options.subplebbitAddress)
363
+ commentInstance.setCommunityAddress(parseCommunityAddressWithPKCErrorIfItFails(options.subplebbitAddress));
364
+ if ("communityPublicKey" in options && typeof options.communityPublicKey === "string")
365
+ commentInstance.communityPublicKey = options.communityPublicKey;
366
+ else if (commentInstance.communityAddress && !isStringDomain(commentInstance.communityAddress))
367
+ commentInstance.communityPublicKey = commentInstance.communityAddress;
368
+ if ("communityName" in options && typeof options.communityName === "string")
369
+ commentInstance.communityName = options.communityName;
370
+ else if (commentInstance.communityAddress && isStringDomain(commentInstance.communityAddress))
371
+ commentInstance.communityName = commentInstance.communityAddress;
372
+ if ("depth" in options) {
373
+ // Options is CommentIpfs | CommentIpfsWithCidDefined | MinimumCommentFieldsToFetchPages
374
+ if ("cid" in options)
375
+ commentInstance.setCid(parseCidStringSchemaWithPKCErrorIfItFails(options.cid));
376
+ //@ts-expect-error
377
+ const commentIpfs = remeda.omit(options, ["cid"]); // remove cid to make sure if options:CommentIpfsWithCidDefined that cid doesn't become part of comment.raw.comment
378
+ // if it has signature it means it's a full CommentIpfs
379
+ if (!("signature" in options))
380
+ Object.assign(commentInstance, options);
381
+ else
382
+ commentInstance._initIpfsProps(parseCommentIpfsSchemaWithPKCErrorIfItFails(commentIpfs));
383
+ // nameResolved is strictly runtime — never carry it over
384
+ if (commentInstance.author?.nameResolved !== undefined)
385
+ delete commentInstance.author.nameResolved;
386
+ }
387
+ else if ("signature" in options) {
388
+ // parsedOptions is CommentPubsubMessage
389
+ const parsedOptions = parseCommentPubsubMessagePublicationWithPKCErrorIfItFails(options);
390
+ commentInstance._initPubsubMessageProps(parsedOptions);
391
+ }
392
+ else if ("signer" in options) {
393
+ // options is CreateCommentOptions
394
+ const parsedOptions = parseCreateCommentOptionsSchemaWithPKCErrorIfItFails(options);
395
+ // Defer signing to publish() — just fill missing fields and store unsigned options
396
+ const fieldsFilled = await this._initMissingFieldsOfPublicationBeforeSigning(parsedOptions, log);
397
+ commentInstance._initUnsignedLocalProps({
398
+ unsignedOptions: fieldsFilled,
399
+ challengeRequest: parsedOptions.challengeRequest
400
+ });
401
+ await commentInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
402
+ }
403
+ else if ("cid" in options) {
404
+ // {cid: string, communityAddress?: string} (also accepts subplebbitAddress for backward compat)
405
+ commentInstance.setCid(parseCidStringSchemaWithPKCErrorIfItFails(options.cid));
406
+ }
407
+ else {
408
+ throw Error("Make sure you provided a remote comment props or signer to create a new local comment");
409
+ }
410
+ if (commentInstance.cid) {
411
+ commentInstance._useUpdatePropsFromUpdatingStartedCommunityIfPossible();
412
+ commentInstance._useUpdatePropsFromUpdatingCommentIfPossible();
413
+ }
414
+ return commentInstance;
415
+ }
416
+ _canCreateNewLocalCommunity() {
417
+ // TODO check if we have a connection to kubo rpc node for IPFS and pubsub
418
+ const isNode = typeof process?.versions?.node !== "undefined";
419
+ return isNode && Boolean(this.dataPath);
420
+ }
421
+ async _setCommunityIpfsOnInstanceIfPossible(community, options) {
422
+ await community.initRemoteCommunityPropsNoMerge(options);
423
+ const preservedRuntimeFields = extractCommunityRuntimeFieldsFromParsedPages({
424
+ postsPages: community.posts.pages,
425
+ modQueuePages: community.modQueue.pages
426
+ });
427
+ const reapplyPreservedRuntimeFields = () => {
428
+ if (preservedRuntimeFields)
429
+ deepMergeRuntimeFields(community, preservedRuntimeFields);
430
+ };
431
+ if ("raw" in options && options.raw.communityIpfs) {
432
+ await community.initCommunityIpfsPropsNoMerge(options.raw.communityIpfs); // we're setting CommunityIpfs
433
+ reapplyPreservedRuntimeFields();
434
+ }
435
+ if ("updateCid" in options && options.updateCid)
436
+ community.updateCid = options.updateCid;
437
+ if (!community.raw.communityIpfs) {
438
+ // we didn't receive options that we can parse into CommunityIpfs
439
+ // let's try using _updatingCommunities
440
+ await community._setCommunityIpfsPropsFromUpdatingCommunitiesIfPossible();
441
+ if (community.raw.communityIpfs)
442
+ reapplyPreservedRuntimeFields();
443
+ }
444
+ // last resort to set community ipfs props
445
+ if (!community.raw.communityIpfs) {
446
+ if (options.signature) {
447
+ const resParseCommunityIpfs = CommunityIpfsSchema.loose().safeParse(remeda.pick(options, [...options.signature.signedPropertyNames, "signature"]));
448
+ if (resParseCommunityIpfs.success) {
449
+ const cleanedRecord = removeUndefinedValuesRecursively(resParseCommunityIpfs.data); // safe way to replicate JSON.stringify() which is done before adding record to ipfs
450
+ await community.initCommunityIpfsPropsNoMerge(cleanedRecord);
451
+ reapplyPreservedRuntimeFields();
452
+ }
453
+ }
454
+ }
455
+ // Backward compat: old serialized instances have raw.subplebbitIpfs instead of raw.communityIpfs
456
+ if (!community.raw.communityIpfs && "raw" in options) {
457
+ const legacyRaw = options.raw.subplebbitIpfs;
458
+ if (legacyRaw) {
459
+ community.raw.communityIpfs = legacyRaw;
460
+ }
461
+ }
462
+ }
463
+ async _waitForCommunitiesToBeDefined() {
464
+ // we're just wait until this.communities is either defined, or communitieschange is emitted
465
+ await this._promiseToWaitForFirstCommunitieschangeEvent;
466
+ if (!Array.isArray(this.communities))
467
+ throw Error("pkc.communities should be defined after communitieschange event");
468
+ }
469
+ async _awaitCommunitiesToIncludeCommunity(communityAddress) {
470
+ if (this.communities.includes(communityAddress))
471
+ return;
472
+ else
473
+ await resolveWhenPredicateIsTrue({
474
+ toUpdate: this,
475
+ predicate: () => this.communities.includes(communityAddress),
476
+ eventName: "communitieschange"
477
+ });
478
+ }
479
+ async _createRemoteCommunityInstance(options) {
480
+ const log = Logger("pkc-js:pkc:createRemoteCommunity");
481
+ log.trace("Received community options to create a remote community instance:", options);
482
+ const community = new RemoteCommunity(this);
483
+ await this._setCommunityIpfsOnInstanceIfPossible(community, options);
484
+ log.trace(`Created remote community instance (${community.address})`);
485
+ return community;
486
+ }
487
+ async _createLocalCommunity(options) {
488
+ const log = Logger("pkc-js:pkc:createLocalCommunity");
489
+ log.trace("Received community options to create a local community instance:", options);
490
+ const canCreateLocalCommunity = this._canCreateNewLocalCommunity();
491
+ if (!canCreateLocalCommunity)
492
+ throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
493
+ const localCommunities = await nodeListCommunities(this);
494
+ const isLocalCommunity = localCommunities.includes(options.address); // Community exists already, only pass address so we don't override other props
495
+ const community = new LocalCommunity(this);
496
+ if (isLocalCommunity) {
497
+ // If the community is already created before, then load it with address only. We don't care about other props
498
+ community.setAddress(options.address);
499
+ await community._updateInstancePropsWithStartedCommunityOrDb();
500
+ log.trace(`Created instance of existing local community (${community.address}) with props:`);
501
+ community.emit("update", community);
502
+ return community;
503
+ }
504
+ else if ("signer" in options) {
505
+ // This is a new community
506
+ const parsedOptions = options;
507
+ await community.initNewLocalCommunityPropsNoMerge(parsedOptions); // We're initializing a new local community props here
508
+ await community._createNewLocalCommunityDb();
509
+ log.trace(`Created a new local community (${community.address}) with props:`);
510
+ community.emit("update", community);
511
+ await this._awaitCommunitiesToIncludeCommunity(community.address);
512
+ return community;
513
+ }
514
+ else
515
+ throw Error("Are you trying to create a local community with no address or signer? This is a critical error");
516
+ }
517
+ async _createCommunityInstanceFromJsonifiedCommunity(jsonfied) {
518
+ // jsonfied = JSON.parse(JSON.stringify(communityInstance))
519
+ // should probably exclude internal and instance-exclusive props like states
520
+ if (this.communities.includes(jsonfied.address))
521
+ return this._createLocalCommunity(jsonfied);
522
+ else
523
+ return this._createRemoteCommunityInstance(jsonfied);
524
+ }
525
+ async createCommunity(options = {}) {
526
+ const log = Logger("pkc-js:pkc:createCommunity");
527
+ if ("clients" in options)
528
+ return this._createCommunityInstanceFromJsonifiedCommunity(options);
529
+ const parsedOptions = options;
530
+ log.trace("Received options: ", parsedOptions);
531
+ const hasAddress = "address" in parsedOptions && typeof parsedOptions.address === "string";
532
+ const hasName = "name" in parsedOptions && typeof parsedOptions.name === "string";
533
+ const hasPublicKey = "publicKey" in parsedOptions && typeof parsedOptions.publicKey === "string";
534
+ const hasSigner = "signer" in parsedOptions && parsedOptions.signer !== undefined;
535
+ const hasIdentifier = hasAddress || hasName || hasPublicKey; // can identify an existing community
536
+ // Derive effective address for local-vs-remote checks
537
+ const effectiveAddress = parsedOptions.address ||
538
+ parsedOptions.name ||
539
+ parsedOptions.publicKey;
540
+ if (effectiveAddress && doesDomainAddressHaveCapitalLetter(effectiveAddress))
541
+ throw new PKCError("ERR_COMMUNITY_NAME_HAS_CAPITAL_LETTER", { ...parsedOptions });
542
+ // Creating a community when we're connected to RPC will be handled in pkc-with-rpc-client
543
+ // Code below is for NodeJS and browser using IPFS-P2P/gateway
544
+ const canCreateLocalCommunity = this._canCreateNewLocalCommunity(); // this is true if we're on NodeJS and have a dataPath
545
+ if (hasSigner && !canCreateLocalCommunity)
546
+ throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", {
547
+ pkcOptions: this._userPKCOptions,
548
+ isEnvNode: Boolean(process),
549
+ hasDataPath: Boolean(this.dataPath)
550
+ });
551
+ if (!canCreateLocalCommunity) {
552
+ // we're either on browser or on NodeJS with no dataPath
553
+ const parsedRemoteOptions = parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails(options);
554
+ return this._createRemoteCommunityInstance(parsedRemoteOptions);
555
+ }
556
+ if (hasIdentifier && !hasSigner) {
557
+ // community is already created, need to check if it's local or remote
558
+ const localCommunities = await nodeListCommunities(this);
559
+ // Check for exact match or .eth/.bso alias match
560
+ const localCommunityAddress = localCommunities.find((localAddr) => areEquivalentCommunityAddresses(localAddr, effectiveAddress));
561
+ if (localCommunityAddress)
562
+ return this._createLocalCommunity({ address: localCommunityAddress });
563
+ else {
564
+ const parsedRemoteOptions = parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails(options);
565
+ return this._createRemoteCommunityInstance(parsedRemoteOptions);
566
+ }
567
+ }
568
+ else if (!hasIdentifier && !hasSigner) {
569
+ // no identifier, no signer, create signer and assign address to signer.address
570
+ const signer = await this.createSigner();
571
+ const localOptions = { ...parsedOptions, signer, address: signer.address };
572
+ log(`Did not provide CreateCommunityOptions.signer, generated random signer with address (${localOptions.address})`);
573
+ return this._createLocalCommunity(localOptions);
574
+ }
575
+ else if (!hasIdentifier && hasSigner) {
576
+ const signerInput = parsedOptions.signer;
577
+ const signer = await this.createSigner(signerInput);
578
+ const localOptions = {
579
+ ...parsedOptions,
580
+ address: signer.address,
581
+ signer
582
+ };
583
+ return this._createLocalCommunity(localOptions);
584
+ }
585
+ else if (hasIdentifier && hasSigner)
586
+ return this._createLocalCommunity(parsedOptions);
587
+ else
588
+ throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { parsedOptions });
589
+ }
590
+ async _createVoteInstanceFromJsonfiedVote(jsonfied) {
591
+ const voteInstance = new Vote(this);
592
+ const unsignedOpts = jsonfied.raw.unsignedPublicationOptions;
593
+ if (jsonfied.raw.pubsubMessageToPublish)
594
+ voteInstance._initLocalProps({
595
+ vote: jsonfied.raw.pubsubMessageToPublish,
596
+ signer: jsonfied.signer,
597
+ challengeRequest: jsonfied.challengeRequest
598
+ });
599
+ else if (unsignedOpts && jsonfied.signer) {
600
+ const log = Logger("pkc-js:pkc:createVote");
601
+ const finalOptions = (await this._initMissingFieldsOfPublicationBeforeSigning({ ...unsignedOpts, signer: jsonfied.signer }, log));
602
+ voteInstance._initUnsignedLocalProps({
603
+ unsignedOptions: finalOptions,
604
+ challengeRequest: jsonfied.challengeRequest
605
+ });
606
+ await voteInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
607
+ }
608
+ return voteInstance;
609
+ }
610
+ async createVote(options) {
611
+ const log = Logger("pkc-js:pkc:createVote");
612
+ if ("clients" in options)
613
+ return this._createVoteInstanceFromJsonfiedVote(options);
614
+ const voteInstance = new Vote(this);
615
+ if ("signature" in options) {
616
+ const parsedOptions = parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails(options);
617
+ voteInstance._initRemoteProps(parsedOptions);
618
+ }
619
+ else {
620
+ const parsedOptions = parseCreateVoteOptionsSchemaWithPKCErrorIfItFails(options);
621
+ const finalOptions = await this._initMissingFieldsOfPublicationBeforeSigning(parsedOptions, log);
622
+ voteInstance._initUnsignedLocalProps({
623
+ unsignedOptions: finalOptions,
624
+ challengeRequest: parsedOptions.challengeRequest
625
+ });
626
+ await voteInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
627
+ }
628
+ return voteInstance;
629
+ }
630
+ async _createCommentEditInstanceFromJsonfiedCommentEdit(jsonfied) {
631
+ const editInstance = new CommentEdit(this);
632
+ const unsignedOpts = jsonfied.raw.unsignedPublicationOptions;
633
+ if (jsonfied.raw.pubsubMessageToPublish)
634
+ editInstance._initLocalProps({
635
+ commentEdit: jsonfied.raw.pubsubMessageToPublish,
636
+ signer: jsonfied.signer,
637
+ challengeRequest: jsonfied.challengeRequest
638
+ });
639
+ else if (unsignedOpts && jsonfied.signer) {
640
+ const log = Logger("pkc-js:pkc:createCommentEdit");
641
+ const finalOptions = (await this._initMissingFieldsOfPublicationBeforeSigning({ ...unsignedOpts, signer: jsonfied.signer }, log));
642
+ editInstance._initUnsignedLocalProps({
643
+ unsignedOptions: finalOptions,
644
+ challengeRequest: jsonfied.challengeRequest
645
+ });
646
+ await editInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
647
+ }
648
+ return editInstance;
649
+ }
650
+ async createCommentEdit(options) {
651
+ const log = Logger("pkc-js:pkc:createCommentEdit");
652
+ if ("clients" in options)
653
+ return this._createCommentEditInstanceFromJsonfiedCommentEdit(options);
654
+ const editInstance = new CommentEdit(this);
655
+ if ("signature" in options) {
656
+ const parsedOptions = parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails(options);
657
+ editInstance._initPubsubPublicationProps(parsedOptions); // User just wants to instantiate a CommentEdit object, not publish
658
+ }
659
+ else {
660
+ const parsedOptions = parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails(options);
661
+ const finalOptions = await this._initMissingFieldsOfPublicationBeforeSigning(options, log);
662
+ editInstance._initUnsignedLocalProps({
663
+ unsignedOptions: finalOptions,
664
+ challengeRequest: parsedOptions.challengeRequest
665
+ });
666
+ await editInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
667
+ }
668
+ return editInstance;
669
+ }
670
+ async _createCommentModerationInstanceFromJsonfiedCommentModeration(jsonfied) {
671
+ const modInstance = new CommentModeration(this);
672
+ const unsignedOpts = jsonfied.raw.unsignedPublicationOptions;
673
+ if (jsonfied.raw.pubsubMessageToPublish)
674
+ modInstance._initLocalProps({
675
+ commentModeration: jsonfied.raw.pubsubMessageToPublish,
676
+ signer: jsonfied.signer,
677
+ challengeRequest: jsonfied.challengeRequest
678
+ });
679
+ else if (unsignedOpts && jsonfied.signer) {
680
+ const log = Logger("pkc-js:pkc:createCommentModeration");
681
+ const finalOptions = (await this._initMissingFieldsOfPublicationBeforeSigning({ ...unsignedOpts, signer: jsonfied.signer }, log));
682
+ modInstance._initUnsignedLocalProps({
683
+ unsignedOptions: finalOptions,
684
+ challengeRequest: jsonfied.challengeRequest
685
+ });
686
+ await modInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
687
+ }
688
+ return modInstance;
689
+ }
690
+ async createCommentModeration(options) {
691
+ const log = Logger("pkc-js:pkc:createCommentEdit");
692
+ if ("clients" in options)
693
+ return this._createCommentModerationInstanceFromJsonfiedCommentModeration(options);
694
+ const modInstance = new CommentModeration(this);
695
+ if ("signature" in options) {
696
+ const parsedOptions = parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails(options);
697
+ modInstance._initPubsubPublication(parsedOptions); // User just wants to instantiate a CommentEdit object, not publish
698
+ }
699
+ else {
700
+ const parsedOptions = parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails(options);
701
+ const finalOptions = (await this._initMissingFieldsOfPublicationBeforeSigning(parsedOptions, log));
702
+ modInstance._initUnsignedLocalProps({
703
+ unsignedOptions: finalOptions,
704
+ challengeRequest: parsedOptions.challengeRequest
705
+ });
706
+ await modInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
707
+ }
708
+ return modInstance;
709
+ }
710
+ async _createCommunityEditInstanceFromJsonfiedCommunityEdit(jsonfied) {
711
+ const communityEditInstance = new CommunityEdit(this);
712
+ const unsignedOpts = jsonfied.raw.unsignedPublicationOptions;
713
+ if (jsonfied.raw.pubsubMessageToPublish)
714
+ communityEditInstance._initLocalProps({
715
+ communityEdit: jsonfied.raw.pubsubMessageToPublish,
716
+ signer: jsonfied.signer,
717
+ challengeRequest: jsonfied.challengeRequest
718
+ });
719
+ else if (unsignedOpts && jsonfied.signer) {
720
+ const log = Logger("pkc-js:pkc:createCommunityEdit");
721
+ const finalOptions = (await this._initMissingFieldsOfPublicationBeforeSigning({ ...unsignedOpts, signer: jsonfied.signer }, log));
722
+ communityEditInstance._initUnsignedLocalProps({
723
+ unsignedOptions: finalOptions,
724
+ challengeRequest: jsonfied.challengeRequest
725
+ });
726
+ await communityEditInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
727
+ }
728
+ return communityEditInstance;
729
+ }
730
+ async createCommunityEdit(options) {
731
+ const log = Logger("pkc-js:pkc:createCommunityEdit");
732
+ if ("clients" in options)
733
+ return this._createCommunityEditInstanceFromJsonfiedCommunityEdit(options);
734
+ const communityEditInstance = new CommunityEdit(this);
735
+ if ("signature" in options) {
736
+ const parsedOptions = parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails(options);
737
+ communityEditInstance._initRemoteProps(parsedOptions);
738
+ }
739
+ else {
740
+ const parsedOptions = parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails(options);
741
+ const finalOptions = (await this._initMissingFieldsOfPublicationBeforeSigning(parsedOptions, log));
742
+ communityEditInstance._initUnsignedLocalProps({
743
+ unsignedOptions: finalOptions,
744
+ challengeRequest: parsedOptions.challengeRequest
745
+ });
746
+ await communityEditInstance._signPublicationWithKnownCommunityFieldsIfAvailable();
747
+ }
748
+ return communityEditInstance;
749
+ }
750
+ createSigner(createSignerOptions) {
751
+ return createSigner(createSignerOptions);
752
+ }
753
+ async fetchCid(fetchCidArgs) {
754
+ // pkc-with-rpc-client will handle if user is connected to rpc client
755
+ const parsedArgs = parseRpcCidParam(fetchCidArgs);
756
+ return this._clientsManager.fetchCid(parsedArgs.cid);
757
+ }
758
+ // Used to pre-subscribe so publishing on pubsub would be faster
759
+ async pubsubSubscribe(pubsubTopic) {
760
+ const parsedTopic = PubsubTopicSchema.parse(pubsubTopic);
761
+ if (this._pubsubSubscriptions[parsedTopic])
762
+ return;
763
+ const handler = () => { };
764
+ await this._clientsManager.pubsubSubscribe(parsedTopic, handler);
765
+ this._pubsubSubscriptions[parsedTopic] = handler;
766
+ }
767
+ async pubsubUnsubscribe(pubsubTopic) {
768
+ const parsedTopic = PubsubTopicSchema.parse(pubsubTopic);
769
+ if (!this._pubsubSubscriptions[parsedTopic])
770
+ return;
771
+ await this._clientsManager.pubsubUnsubscribe(parsedTopic, this._pubsubSubscriptions[parsedTopic]);
772
+ delete this._pubsubSubscriptions[parsedTopic];
773
+ }
774
+ async resolveAuthorName(resolveAuthorAddressArgs) {
775
+ const parsedArgs = parseRpcAuthorNameParam(resolveAuthorAddressArgs);
776
+ const resolved = await this._clientsManager.resolveAuthorNameIfNeeded({ authorAddress: parsedArgs.address });
777
+ return resolved;
778
+ }
779
+ async validateComment(comment, opts) {
780
+ const commentIpfs = comment.raw.comment;
781
+ const commentUpdate = comment.raw.commentUpdate;
782
+ const commentCid = comment.cid;
783
+ const postCid = comment.postCid;
784
+ if (!commentCid)
785
+ throw new PKCError("ERR_COMMENT_MISSING_CID", { comment, commentCid });
786
+ if (!commentIpfs)
787
+ throw new PKCError("ERR_COMMENT_MISSING_IPFS", { comment, commentIpfs });
788
+ if (!commentUpdate)
789
+ throw new PKCError("ERR_COMMENT_MISSING_UPDATE", { comment, commentUpdate });
790
+ if (!postCid)
791
+ throw new PKCError("ERR_COMMENT_MISSING_POST_CID", { comment, postCid }); // postCid should always be defined if you have CommentIpfs
792
+ const commentIpfsVerificationOpts = {
793
+ comment: commentIpfs,
794
+ resolveAuthorNames: this.resolveAuthorNames,
795
+ clientsManager: this._clientsManager,
796
+ calculatedCommentCid: commentCid
797
+ };
798
+ const commentIpfsValidity = await verifyCommentIpfs(commentIpfsVerificationOpts);
799
+ if (!commentIpfsValidity.valid)
800
+ throw new PKCError("ERR_INVALID_COMMENT_IPFS", {
801
+ commentIpfsVerificationOpts,
802
+ commentIpfsValidity
803
+ });
804
+ const communityIpfs = findUpdatingCommunity(this, { address: comment.communityAddress })?.raw?.communityIpfs;
805
+ const community = communityIpfs
806
+ ? { address: comment.communityAddress, signature: communityIpfs.signature }
807
+ : { address: comment.communityAddress };
808
+ const commentUpdateVerificationOpts = {
809
+ update: commentUpdate,
810
+ resolveAuthorNames: this.resolveAuthorNames,
811
+ clientsManager: this._clientsManager,
812
+ community,
813
+ validatePages: typeof opts?.validateReplies === "boolean" ? opts.validateReplies : this.validatePages,
814
+ comment: { ...commentIpfs, cid: commentCid, postCid },
815
+ validateUpdateSignature: true
816
+ };
817
+ const commentUpdateValidity = await verifyCommentUpdate(commentUpdateVerificationOpts);
818
+ if (!commentUpdateValidity.valid)
819
+ throw new PKCError("ERR_INVALID_COMMENT_UPDATE", {
820
+ commentUpdateVerificationOpts,
821
+ commentUpdateValidity
822
+ });
823
+ }
824
+ async _createStorageLRU(opts) {
825
+ // should add the storage LRU to an array, so we can destroy all of them on pkc.destroy
826
+ if (!this._storageLRUs[opts.cacheName]) {
827
+ this._storageLRUs[opts.cacheName] = new LRUStorage({ ...opts, pkc: this });
828
+ await this._storageLRUs[opts.cacheName].init();
829
+ }
830
+ return this._storageLRUs[opts.cacheName];
831
+ }
832
+ async destroy() {
833
+ const log = Logger("pkc-js:pkc:destroy");
834
+ if (this.destroyed)
835
+ return;
836
+ this.destroyed = true;
837
+ // Clean up connections
838
+ for (const comment of listUpdatingComments(this))
839
+ await comment.stop();
840
+ for (const community of listUpdatingCommunities(this))
841
+ await community.stop();
842
+ await Promise.all(listStartedCommunities(this).map((community) => community.stop()));
843
+ if (this._communityFsWatchAbort)
844
+ this._communityFsWatchAbort.abort();
845
+ if (this._addressRewriterSetupPromise) {
846
+ await this._addressRewriterSetupPromise;
847
+ this._addressRewriterSetupPromise = undefined;
848
+ }
849
+ if (this._addressRewriterDestroy) {
850
+ await this._addressRewriterDestroy();
851
+ this._addressRewriterDestroy = undefined;
852
+ }
853
+ await this._storage.destroy();
854
+ for (const storage of Object.values(this._storageLRUs))
855
+ await storage.destroy();
856
+ Object.values(this._memCaches).forEach((cache) => cache.clear());
857
+ if (Object.keys(this._pubsubSubscriptions).length > 0) {
858
+ for (const client of Object.values(this.clients.pubsubKuboRpcClients)) {
859
+ try {
860
+ const subscribedPubsubTopics = await client._client.pubsub.ls();
861
+ for (const topic of subscribedPubsubTopics) {
862
+ await client._client.pubsub.unsubscribe(topic);
863
+ }
864
+ }
865
+ catch (e) {
866
+ log.error("Error unsubscribing from pubsub topics", e);
867
+ }
868
+ }
869
+ }
870
+ const kuboClients = [...Object.values(this.clients.kuboRpcClients), ...Object.values(this.clients.pubsubKuboRpcClients)];
871
+ await Promise.all(kuboClients.map(async (client) => client.destroy()));
872
+ await Promise.all(Object.values(this.clients.libp2pJsClients).map((client) => client.heliaWithKuboRpcClientFunctions.stop()));
873
+ await Promise.all(Object.values(this.clients.pkcRpcClients).map((client) => client.destroy()));
874
+ if (this.nameResolvers) {
875
+ await Promise.all(this.nameResolvers.map((resolver) => resolver.destroy?.()));
876
+ }
877
+ // Get all methods on the instance and override them to throw errors if used after destruction
878
+ Object.getOwnPropertyNames(Object.getPrototypeOf(this))
879
+ .filter((prop) => typeof this[prop] === "function")
880
+ .forEach((method) => {
881
+ this[method] = () => {
882
+ throw new PKCError("ERR_PKC_IS_DESTROYED");
883
+ };
884
+ });
885
+ log("Destroyed pkc instance");
886
+ }
887
+ }
888
+ //# sourceMappingURL=pkc.js.map