@bitsocial/bitsocial-react-hooks 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +1365 -0
  3. package/dist/hooks/accounts/accounts.d.ts +64 -0
  4. package/dist/hooks/accounts/accounts.d.ts.map +1 -0
  5. package/dist/hooks/accounts/accounts.js +706 -0
  6. package/dist/hooks/accounts/accounts.js.map +1 -0
  7. package/dist/hooks/accounts/index.d.ts +2 -0
  8. package/dist/hooks/accounts/index.d.ts.map +1 -0
  9. package/dist/hooks/accounts/index.js +2 -0
  10. package/dist/hooks/accounts/index.js.map +1 -0
  11. package/dist/hooks/accounts/utils.d.ts +6 -0
  12. package/dist/hooks/accounts/utils.d.ts.map +1 -0
  13. package/dist/hooks/accounts/utils.js +226 -0
  14. package/dist/hooks/accounts/utils.js.map +1 -0
  15. package/dist/hooks/actions/actions.d.ts +19 -0
  16. package/dist/hooks/actions/actions.d.ts.map +1 -0
  17. package/dist/hooks/actions/actions.js +552 -0
  18. package/dist/hooks/actions/actions.js.map +1 -0
  19. package/dist/hooks/actions/index.d.ts +2 -0
  20. package/dist/hooks/actions/index.d.ts.map +1 -0
  21. package/dist/hooks/actions/index.js +2 -0
  22. package/dist/hooks/actions/index.js.map +1 -0
  23. package/dist/hooks/authors/author-avatars.d.ts +28 -0
  24. package/dist/hooks/authors/author-avatars.d.ts.map +1 -0
  25. package/dist/hooks/authors/author-avatars.js +191 -0
  26. package/dist/hooks/authors/author-avatars.js.map +1 -0
  27. package/dist/hooks/authors/authors.d.ts +37 -0
  28. package/dist/hooks/authors/authors.d.ts.map +1 -0
  29. package/dist/hooks/authors/authors.js +509 -0
  30. package/dist/hooks/authors/authors.js.map +1 -0
  31. package/dist/hooks/authors/index.d.ts +2 -0
  32. package/dist/hooks/authors/index.d.ts.map +1 -0
  33. package/dist/hooks/authors/index.js +2 -0
  34. package/dist/hooks/authors/index.js.map +1 -0
  35. package/dist/hooks/authors/utils.d.ts +4 -0
  36. package/dist/hooks/authors/utils.d.ts.map +1 -0
  37. package/dist/hooks/authors/utils.js +21 -0
  38. package/dist/hooks/authors/utils.js.map +1 -0
  39. package/dist/hooks/comments.d.ts +17 -0
  40. package/dist/hooks/comments.d.ts.map +1 -0
  41. package/dist/hooks/comments.js +351 -0
  42. package/dist/hooks/comments.js.map +1 -0
  43. package/dist/hooks/communities.d.ts +31 -0
  44. package/dist/hooks/communities.d.ts.map +1 -0
  45. package/dist/hooks/communities.js +389 -0
  46. package/dist/hooks/communities.js.map +1 -0
  47. package/dist/hooks/feeds/feeds.d.ts +18 -0
  48. package/dist/hooks/feeds/feeds.d.ts.map +1 -0
  49. package/dist/hooks/feeds/feeds.js +315 -0
  50. package/dist/hooks/feeds/feeds.js.map +1 -0
  51. package/dist/hooks/feeds/index.d.ts +2 -0
  52. package/dist/hooks/feeds/index.d.ts.map +1 -0
  53. package/dist/hooks/feeds/index.js +2 -0
  54. package/dist/hooks/feeds/index.js.map +1 -0
  55. package/dist/hooks/pkc-rpc.d.ts +7 -0
  56. package/dist/hooks/pkc-rpc.d.ts.map +1 -0
  57. package/dist/hooks/pkc-rpc.js +88 -0
  58. package/dist/hooks/pkc-rpc.js.map +1 -0
  59. package/dist/hooks/replies.d.ts +5 -0
  60. package/dist/hooks/replies.d.ts.map +1 -0
  61. package/dist/hooks/replies.js +155 -0
  62. package/dist/hooks/replies.js.map +1 -0
  63. package/dist/hooks/states.d.ts +15 -0
  64. package/dist/hooks/states.d.ts.map +1 -0
  65. package/dist/hooks/states.js +213 -0
  66. package/dist/hooks/states.js.map +1 -0
  67. package/dist/hooks/utils/use-interval.d.ts +3 -0
  68. package/dist/hooks/utils/use-interval.d.ts.map +1 -0
  69. package/dist/hooks/utils/use-interval.js +36 -0
  70. package/dist/hooks/utils/use-interval.js.map +1 -0
  71. package/dist/hooks/utils/use-previous.d.ts +1 -0
  72. package/dist/hooks/utils/use-previous.js +10 -0
  73. package/dist/index.d.ts +82 -0
  74. package/dist/index.d.ts.map +1 -0
  75. package/dist/index.js +128 -0
  76. package/dist/index.js.map +1 -0
  77. package/dist/lib/chain/chain.d.ts +36 -0
  78. package/dist/lib/chain/chain.d.ts.map +1 -0
  79. package/dist/lib/chain/chain.js +195 -0
  80. package/dist/lib/chain/chain.js.map +1 -0
  81. package/dist/lib/chain/index.d.ts +4 -0
  82. package/dist/lib/chain/index.d.ts.map +1 -0
  83. package/dist/lib/chain/index.js +4 -0
  84. package/dist/lib/chain/index.js.map +1 -0
  85. package/dist/lib/community-address.d.ts +6 -0
  86. package/dist/lib/community-address.d.ts.map +1 -0
  87. package/dist/lib/community-address.js +26 -0
  88. package/dist/lib/community-address.js.map +1 -0
  89. package/dist/lib/community-ref.d.ts +23 -0
  90. package/dist/lib/community-ref.d.ts.map +1 -0
  91. package/dist/lib/community-ref.js +113 -0
  92. package/dist/lib/community-ref.js.map +1 -0
  93. package/dist/lib/debug-utils.d.ts +9 -0
  94. package/dist/lib/debug-utils.d.ts.map +1 -0
  95. package/dist/lib/debug-utils.js +21 -0
  96. package/dist/lib/debug-utils.js.map +1 -0
  97. package/dist/lib/feed-sort-type.d.ts +2 -0
  98. package/dist/lib/feed-sort-type.d.ts.map +1 -0
  99. package/dist/lib/feed-sort-type.js +22 -0
  100. package/dist/lib/feed-sort-type.js.map +1 -0
  101. package/dist/lib/localforage-lru/index.d.ts +3 -0
  102. package/dist/lib/localforage-lru/index.d.ts.map +1 -0
  103. package/dist/lib/localforage-lru/index.js +46 -0
  104. package/dist/lib/localforage-lru/index.js.map +1 -0
  105. package/dist/lib/localforage-lru/localforage-lru.d.ts +6 -0
  106. package/dist/lib/localforage-lru/localforage-lru.d.ts.map +1 -0
  107. package/dist/lib/localforage-lru/localforage-lru.js +182 -0
  108. package/dist/lib/localforage-lru/localforage-lru.js.map +1 -0
  109. package/dist/lib/pkc-compat.d.ts +25 -0
  110. package/dist/lib/pkc-compat.d.ts.map +1 -0
  111. package/dist/lib/pkc-compat.js +131 -0
  112. package/dist/lib/pkc-compat.js.map +1 -0
  113. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts +3 -0
  114. package/dist/lib/pkc-js/fixtures/markdown-example.d.ts.map +1 -0
  115. package/dist/lib/pkc-js/fixtures/markdown-example.js +280 -0
  116. package/dist/lib/pkc-js/fixtures/markdown-example.js.map +1 -0
  117. package/dist/lib/pkc-js/index.d.ts +11 -0
  118. package/dist/lib/pkc-js/index.d.ts.map +1 -0
  119. package/dist/lib/pkc-js/index.js +85 -0
  120. package/dist/lib/pkc-js/index.js.map +1 -0
  121. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts +3 -0
  122. package/dist/lib/pkc-js/pkc-js-mock-content.d.ts.map +1 -0
  123. package/dist/lib/pkc-js/pkc-js-mock-content.js +1235 -0
  124. package/dist/lib/pkc-js/pkc-js-mock-content.js.map +1 -0
  125. package/dist/lib/pkc-js/pkc-js-mock.d.ts +137 -0
  126. package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -0
  127. package/dist/lib/pkc-js/pkc-js-mock.js +644 -0
  128. package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -0
  129. package/dist/lib/polyfill.d.ts +3 -0
  130. package/dist/lib/polyfill.d.ts.map +1 -0
  131. package/dist/lib/polyfill.js +14 -0
  132. package/dist/lib/polyfill.js.map +1 -0
  133. package/dist/lib/protocol-compat.d.ts +14 -0
  134. package/dist/lib/protocol-compat.d.ts.map +1 -0
  135. package/dist/lib/protocol-compat.js +67 -0
  136. package/dist/lib/protocol-compat.js.map +1 -0
  137. package/dist/lib/test-utils.d.ts +29 -0
  138. package/dist/lib/test-utils.d.ts.map +1 -0
  139. package/dist/lib/test-utils.js +184 -0
  140. package/dist/lib/test-utils.js.map +1 -0
  141. package/dist/lib/utils/comment-moderation.d.ts +4 -0
  142. package/dist/lib/utils/comment-moderation.d.ts.map +1 -0
  143. package/dist/lib/utils/comment-moderation.js +56 -0
  144. package/dist/lib/utils/comment-moderation.js.map +1 -0
  145. package/dist/lib/utils/index.d.ts +4 -0
  146. package/dist/lib/utils/index.d.ts.map +1 -0
  147. package/dist/lib/utils/index.js +4 -0
  148. package/dist/lib/utils/index.js.map +1 -0
  149. package/dist/lib/utils/utils.d.ts +23 -0
  150. package/dist/lib/utils/utils.d.ts.map +1 -0
  151. package/dist/lib/utils/utils.js +375 -0
  152. package/dist/lib/utils/utils.js.map +1 -0
  153. package/dist/lib/validator.d.ts +30 -0
  154. package/dist/lib/validator.d.ts.map +1 -0
  155. package/dist/lib/validator.js +307 -0
  156. package/dist/lib/validator.js.map +1 -0
  157. package/dist/stores/accounts/account-generator.d.ts +51 -0
  158. package/dist/stores/accounts/account-generator.d.ts.map +1 -0
  159. package/dist/stores/accounts/account-generator.js +160 -0
  160. package/dist/stores/accounts/account-generator.js.map +1 -0
  161. package/dist/stores/accounts/accounts-actions-internal.d.ts +8 -0
  162. package/dist/stores/accounts/accounts-actions-internal.d.ts.map +1 -0
  163. package/dist/stores/accounts/accounts-actions-internal.js +403 -0
  164. package/dist/stores/accounts/accounts-actions-internal.js.map +1 -0
  165. package/dist/stores/accounts/accounts-actions.d.ts +46 -0
  166. package/dist/stores/accounts/accounts-actions.d.ts.map +1 -0
  167. package/dist/stores/accounts/accounts-actions.js +1341 -0
  168. package/dist/stores/accounts/accounts-actions.js.map +1 -0
  169. package/dist/stores/accounts/accounts-database.d.ts +34 -0
  170. package/dist/stores/accounts/accounts-database.d.ts.map +1 -0
  171. package/dist/stores/accounts/accounts-database.js +685 -0
  172. package/dist/stores/accounts/accounts-database.js.map +1 -0
  173. package/dist/stores/accounts/accounts-store.d.ts +32 -0
  174. package/dist/stores/accounts/accounts-store.d.ts.map +1 -0
  175. package/dist/stores/accounts/accounts-store.js +169 -0
  176. package/dist/stores/accounts/accounts-store.js.map +1 -0
  177. package/dist/stores/accounts/index.d.ts +4 -0
  178. package/dist/stores/accounts/index.d.ts.map +1 -0
  179. package/dist/stores/accounts/index.js +4 -0
  180. package/dist/stores/accounts/index.js.map +1 -0
  181. package/dist/stores/accounts/utils.d.ts +49 -0
  182. package/dist/stores/accounts/utils.d.ts.map +1 -0
  183. package/dist/stores/accounts/utils.js +419 -0
  184. package/dist/stores/accounts/utils.js.map +1 -0
  185. package/dist/stores/authors-comments/authors-comments-store.d.ts +37 -0
  186. package/dist/stores/authors-comments/authors-comments-store.d.ts.map +1 -0
  187. package/dist/stores/authors-comments/authors-comments-store.js +338 -0
  188. package/dist/stores/authors-comments/authors-comments-store.js.map +1 -0
  189. package/dist/stores/authors-comments/index.d.ts +4 -0
  190. package/dist/stores/authors-comments/index.d.ts.map +1 -0
  191. package/dist/stores/authors-comments/index.js +4 -0
  192. package/dist/stores/authors-comments/index.js.map +1 -0
  193. package/dist/stores/authors-comments/utils.d.ts +14 -0
  194. package/dist/stores/authors-comments/utils.d.ts.map +1 -0
  195. package/dist/stores/authors-comments/utils.js +81 -0
  196. package/dist/stores/authors-comments/utils.js.map +1 -0
  197. package/dist/stores/comments/comments-store.d.ts +19 -0
  198. package/dist/stores/comments/comments-store.d.ts.map +1 -0
  199. package/dist/stores/comments/comments-store.js +385 -0
  200. package/dist/stores/comments/comments-store.js.map +1 -0
  201. package/dist/stores/comments/index.d.ts +4 -0
  202. package/dist/stores/comments/index.d.ts.map +1 -0
  203. package/dist/stores/comments/index.js +4 -0
  204. package/dist/stores/comments/index.js.map +1 -0
  205. package/dist/stores/communities/communities-store.d.ts +17 -0
  206. package/dist/stores/communities/communities-store.d.ts.map +1 -0
  207. package/dist/stores/communities/communities-store.js +304 -0
  208. package/dist/stores/communities/communities-store.js.map +1 -0
  209. package/dist/stores/communities/index.d.ts +4 -0
  210. package/dist/stores/communities/index.d.ts.map +1 -0
  211. package/dist/stores/communities/index.js +4 -0
  212. package/dist/stores/communities/index.js.map +1 -0
  213. package/dist/stores/communities-pages/communities-pages-store.d.ts +23 -0
  214. package/dist/stores/communities-pages/communities-pages-store.d.ts.map +1 -0
  215. package/dist/stores/communities-pages/communities-pages-store.js +316 -0
  216. package/dist/stores/communities-pages/communities-pages-store.js.map +1 -0
  217. package/dist/stores/communities-pages/index.d.ts +4 -0
  218. package/dist/stores/communities-pages/index.d.ts.map +1 -0
  219. package/dist/stores/communities-pages/index.js +4 -0
  220. package/dist/stores/communities-pages/index.js.map +1 -0
  221. package/dist/stores/feeds/feed-sorter.d.ts +5 -0
  222. package/dist/stores/feeds/feed-sorter.d.ts.map +1 -0
  223. package/dist/stores/feeds/feed-sorter.js +135 -0
  224. package/dist/stores/feeds/feed-sorter.js.map +1 -0
  225. package/dist/stores/feeds/feeds-store.d.ts +25 -0
  226. package/dist/stores/feeds/feeds-store.d.ts.map +1 -0
  227. package/dist/stores/feeds/feeds-store.js +459 -0
  228. package/dist/stores/feeds/feeds-store.js.map +1 -0
  229. package/dist/stores/feeds/index.d.ts +4 -0
  230. package/dist/stores/feeds/index.d.ts.map +1 -0
  231. package/dist/stores/feeds/index.js +4 -0
  232. package/dist/stores/feeds/index.js.map +1 -0
  233. package/dist/stores/feeds/utils.d.ts +43 -0
  234. package/dist/stores/feeds/utils.d.ts.map +1 -0
  235. package/dist/stores/feeds/utils.js +736 -0
  236. package/dist/stores/feeds/utils.js.map +1 -0
  237. package/dist/stores/replies/index.d.ts +4 -0
  238. package/dist/stores/replies/index.d.ts.map +1 -0
  239. package/dist/stores/replies/index.js +4 -0
  240. package/dist/stores/replies/index.js.map +1 -0
  241. package/dist/stores/replies/replies-comments-store.d.ts +8 -0
  242. package/dist/stores/replies/replies-comments-store.d.ts.map +1 -0
  243. package/dist/stores/replies/replies-comments-store.js +23 -0
  244. package/dist/stores/replies/replies-comments-store.js.map +1 -0
  245. package/dist/stores/replies/replies-store.d.ts +29 -0
  246. package/dist/stores/replies/replies-store.d.ts.map +1 -0
  247. package/dist/stores/replies/replies-store.js +413 -0
  248. package/dist/stores/replies/replies-store.js.map +1 -0
  249. package/dist/stores/replies/utils.d.ts +25 -0
  250. package/dist/stores/replies/utils.d.ts.map +1 -0
  251. package/dist/stores/replies/utils.js +549 -0
  252. package/dist/stores/replies/utils.js.map +1 -0
  253. package/dist/stores/replies-pages/index.d.ts +4 -0
  254. package/dist/stores/replies-pages/index.d.ts.map +1 -0
  255. package/dist/stores/replies-pages/index.js +4 -0
  256. package/dist/stores/replies-pages/index.js.map +1 -0
  257. package/dist/stores/replies-pages/replies-pages-store.d.ts +20 -0
  258. package/dist/stores/replies-pages/replies-pages-store.d.ts.map +1 -0
  259. package/dist/stores/replies-pages/replies-pages-store.js +270 -0
  260. package/dist/stores/replies-pages/replies-pages-store.js.map +1 -0
  261. package/dist/stores/replies-pages/utils.d.ts +3 -0
  262. package/dist/stores/replies-pages/utils.d.ts.map +1 -0
  263. package/dist/stores/replies-pages/utils.js +43 -0
  264. package/dist/stores/replies-pages/utils.js.map +1 -0
  265. package/dist/types.d.ts +638 -0
  266. package/dist/types.d.ts.map +1 -0
  267. package/dist/types.js +3 -0
  268. package/dist/types.js.map +1 -0
  269. package/package.json +160 -0
@@ -0,0 +1,1235 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import markdownExample from "./fixtures/markdown-example.js";
11
+ import EventEmitter from "events";
12
+ import assert from "assert";
13
+ import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
14
+ import { toString as uint8ArrayToString } from "uint8arrays/to-string";
15
+ // changeable with env variable so the frontend can test with different latencies
16
+ const doubleMedia = Boolean(process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_MOCK_CONTENT_DOUBLE_MEDIA);
17
+ const loadingTime = Number(process.env.REACT_APP_BITSOCIAL_REACT_HOOKS_MOCK_CONTENT_LOADING_TIME || 100);
18
+ const simulateLoadingTime = () => new Promise((r) => setTimeout(r, loadingTime));
19
+ const NOW = 1679800000;
20
+ const DAY = 60 * 60 * 24;
21
+ // TODO: should delete this eventually to reduce npm package size
22
+ let captchaImageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAJYAAAAyCAMAAACJUtIoAAAAY1BMVEX////y8vLm5ub39/fr7Ozf39/a29u/6c256MjV8N7v+fL0+/bU1dXO7tnp9+7e8+TJ7NTOzs7E69Gt5L+I26ag4bfk9en3/fmS3Kyo4rx42J2Z37LI38/AwMDR5tip1Li+1cUdWDCzAAAEkElEQVRYw+1Y6ZKjIBBuGuTyPqKZHLP7/k+5KrhIUEwms1X7Y76pMYVg23x9IvzgZfQN/I/QXavhP0SXyh6+AdQbEYS3UJ1TkC/zlbDxEtOD7Q8JnQRMFxYzooL0A46APhlZEizw71A2X+kyu5pBHC8JMUJ3ITqpu0O6GPqbRU8l3CM1CdnCjC0a8Yil80pdLinEMXBc5BMCuwaMUejYimzHoZSgzzJ90oaY8HCW7BmD0ug9QmAXxWlULW9yM+IbgqyHUjJJsuZYyWZu6xEwc3keaqTqCoUJx5puCx1vo1GAWPUf1GI8CRhk6IZZQM8RdCu6HiBvlgCCjaetWhZYo28JkvmvpBO/iD5bNLBFHPnsW1oq7mQGoGSlosdqYB+bARiDb4H6NRiZ6AkM+SdG8Vf9BckXK6RQxsVrStF3etxx5Vf8BdGLlBfQS233xXx6SODRHm9oh6HeSLcyScJejIAmn0mgFMoEvWISS+wZcT8ecPpngVrInmPMLdGymKvSubv9TVLM5gVzY8ObOVt+aIJe0kRqdHPp5wVDUveIyRVQFvKTgI1rV6LjIIDJlCsy3IoXDiEyElUrI7UbpbI05jRVjK2oPwJmWcLgzk0W3u/Jnt8p8UplMZLGs0DaEdgcLEiMX3tlHHcKSHQeWIZr71aikfWdvdOoIkdMVtGM0QxG79v2rDPf96vLZ2j5/c33Hyp4EyO46UbJhulIzR55JOSv5zC27DftVFvs2/yxAKVdc833wps9MJBs+A4NWk/3GJ34tQ91AyhRPHeoYAnvAPKT3qE2XpFqujVh5lzcWSHXG7KIYo9qXfTUvqU7mWMPSW3UigO5YzXlk4LPKKYrKcWlVRrKFg4RngQyAnEkuC6opqDFFUuVEGriSKoiF+KSD48+ovTDzr36QP1WarclQPBhFbMFRxt9zfaGUohKr6spVB/NeK9fc9OdWzW4Vsz3SqSmPfsK+NRcm/iXp/EX61FO34im91Sfr+3E4OcvISxJjJ3Up7z+FcXhDYS009+zKZWsTnnye6SkBA/WrfL5yjiAzsW4KAX4uAWd29tAuiQDnH2saNP8apzJZEzqKukp78tz5XVCfSVkdzOLLHnBoeor4HSdqKpWXiq918SneXv+NQStwulyFv2R+GNEtkMR2ip1mShoE5DMqcjDR6mbk5B58RBcizHCCvlqX0ZwDLWT1IAJCfdpKxglj2oZ32ukKNdFp1DDs0ffY5QSegW0RrZLMIRqWfGlkJVeeC26czMNCI00Wc5PWRL7mpCezS2vC6Cx7VVnWawdUEqFprjz26l85qOKVSvqYH45DuMrnKG31q+Vn0I2o6YdRxi2zjCIkQO0I9FbpfX+p6wQDGcy9eB9nmCQKgmncpee0KoB8LhvHuhO2xM6Dnd32ms+uIS9xp0cbpvgYfBiQDh/KK585TdkWSSr6qpgA/SehQY8BllUQePfPFjACa53SO7rjo5YCqoKoBgng+xHMoQvIJtOJJMkNPI43fIGut0H0toOmJJLQDF4C+6d098XwZcn+9ZmsO9SC96Bc5TUSvvBD/49/gDEMCEP8TccuAAAAABJRU5ErkJggg==";
23
+ const commentTitles = [
24
+ `Own a Piece of Digital History- Winamp Is Now Selling Its Original 1.0 Skin as an NFT, Iconic Player “was the go-to music player everybody was using at the beginning of the history of digital music and was instrumental in helping the .mp3 become mainstream”.`,
25
+ 'Buyer of "Pepe the Frog" NFT files US$500,000 lawsuit after creator releases identical NFTs for free',
26
+ "$5,100,000,000 Bitcoin Whale enters massive crypto accumulation mode",
27
+ "Two Big Developments in Brave Browser",
28
+ "🤡",
29
+ ];
30
+ const commentContents = [
31
+ `First of all, the sentiment in this sub concerning moons seems very __polarized__. Some people think they are a genius idea and others think they are making this sub this sub worse because of “moon farming.” which camp are you in?
32
+
33
+ Second, how/where can you sell them. And third c/eEY1MhxPNyvt, how many upvotes=one moon, some people have so many when I’m sitting here at 17.
34
+
35
+ **Personally** I think Reddit is ahead of the _curve_, in a couple years I could easily see every social media platform incorporating their own coin into their interface.
36
+
37
+ Think about it; it costs the company next to nothing, encourages users to spend more time and be more active on the platform, and capitalizes on their existing user base, skipping any need for marketing.
38
+
39
+ u/BPNgj2dfHSn8 From the companies point of view it seems like a no brainer. p/reddit-screenshots.eth/c/QmeEY1MhxPNyvt5i8GVxZwqi11yweKuYFWyk1ST4GTKRnm
40
+
41
+ Can people think of issues with this approach? For either the company or the consumer, because besides increased levels of spamming I don’t see much downside.`,
42
+ "What kind of messes up world is this. *Even* if they stop you, they would need some sort of seed phrase or private key to your account in order to get the funds.",
43
+ "🤡",
44
+ `So real fast u/estebanabaroa.eth/c/QmeEY1MhxPNyvt5i8GVxZwqi11yweKuYFWyk1ST4GTKRnm, I'm not a legal person and this isn't legal advice. I'm just sharing what I found out. What is civil forfeiture In the USA basically the cops can take things if the suspect it could of been used in a crime (any crime even if there is no crime going on now or in the area and any evidence). Lets put it this way, in CA there is pot shops that used armor trucks to move their money (which many stores use). Pot shops in CA is legal, but the cops on a regular bases stopped the truck for stupid things like using the turn signal too early. They use civil forfeiture to take the cash. From there in all cases they send the stuff to the gov, and the gov gives the local cops a major amount of the value of the assets. Note in some states this is illegal like NC. But I seen in the past years where federal wants to cause a loophole using DEA to force cops by law to do it. But note if you travel through states with this being legal. Note this is actually is a huge problem in the USA. Even more for unbanked people and homeless. ALL lawyers and all people I talked to in legal/law thinks this is the ultimate forum of government theft, and this should be federally illegal. That the system is proven to be extremely abused just for the reason of bonuses and the ones taking the money keep a ton of it after it went through the system. My question Can the gov force you to unlock your phone in a civil forfeiture? This giving them access to your hot wallets. Can the gov take your crypto in a civil forfeiture since it is on the blockchain? It should be noted that with 2, there is no clear answer to this. Basically it came down to it has to be tested in courts or a law maker needs to make laws clearing this up. NOTE FOR ANY LAW MAKERS THAT WANT TO HELP WHO THEY REPRESENT, AND WANT TO MAKE A BILL TO HELP THEM GET REELECTED. FIX THIS What I found out So can they take your phone or hardware wallet? The answer to this seems to be yes. Can they force you to unlock your phone? The answer to this seems to be not without a warrant. Can they brute force, hack, or do whatever to get in after they taken the device in a civil forfeiture? The answer seems to be yes. Basically, the idea is that when this happens it now becomes gov property. And if the gov wants to break in their own property or wipe their end. There isn't jack you can do to stop them expect remote format the device (seriously look into this. You can do this with most phones.) Are they likely to break into your phone/hardware wallet if they take it? While there isn't really evidence of this happening yet. The likely if it was to happen then yes. The question is, do they know of a 0 day which will allow them to get in, and that answer to this is maybe. Like I've seen videos of people recovering their funds from their hardware wallet through taking apart something like a ledger, hooking up to given things, and doing a few other things. So lets not rule out they will have some way of doing just this. Because it is likely if they take one, then they most likely are taking as many as they see. Can the gov use civil forfeiture to get the crypto itself without going after the phone/hardware wallet? Chances are is no. Like they can't demand for the given crypto since they have no way of knowing the wallet address unless if you show them or after they taken the device. They have to prove in court they suspected x was used in some way with a crime. Not knowing the address prior to rules this out. So basically, don't talk to the legal people without a lawyer and don't give them more info than needed. Note: if they use the law to take the phone or hardware wallet, then they can make a case that maybe the crypto is part of the taking since you have direct control of the crypto using your phone. Therefore the crypto could've also been used in crime in some way in the same way the phone could've been. Basically, it is the argument of can they take the truck and the music CD inside thing. How to handle the situation? Don't talk to the cops about anything you don't have to. Note the laws, but in general if they ask you to get out of the car ask if it is a command. If they say yes, then get out. If they asked for documents, then give it (don't be an idiot, just give it to them even the technical bits you don't need to. You will just PO the cop which can cause problems.) Ask them if you can leave, and that you would like to leave. This indicates you aren't volunteering your stay, and in many states they have to be reasonable about the length of the stop and many cases they won't have enough time to do something stupid. When asked questions you don't have to answer say a lawyer friend told you to not talk to the cops while being questioned or at a stop. Never agree to them searching your car or you without a warrant. Never argue with them on the side of the road, the day for that is in court (meaning if they decided to arrest you, then let them and then wait to fight it in court since it is likely you can get a big paycheck if done right). Never be open about what you have. If they take the item using civil forfeiture, then it is likely any cash will be gone forever since some of these court cases can last for years. But you can and should fight them in court because there is a growing amount of cases which is forcing judges and others to look more into this and treat it more serious. If you can't afford a lawyer to fight, then there is a few groups that you can call depending on if you have military background, extreme poverty, and so on. But to be blunt, the best way to fight this risk is by getting law makers to make civil forfeiture illegal. BTW for people visiting the USA, you could face this problem.`,
45
+ markdownExample,
46
+ ];
47
+ const commentLinks = [
48
+ "https://fortune.com/2022/03/16/bitcoin-200k-price-prediction-crypto-outlook/",
49
+ "https://finance.yahoo.com/news/c2x-announces-25-million-funding-120000728.html",
50
+ "https://finance.yahoo.com/news/adopting-crypto-legal-tender-signify-101309571.html",
51
+ "https://x.com/pkcprotocol/status/1632113706015309825",
52
+ "https://www.youtube.com/watch?v=jfKfPfyJRdk",
53
+ ];
54
+ const mediaLinks = [
55
+ "https://upload.wikimedia.org/wikipedia/en/transcoded/b/bd/Exorcist_angiogram_scene.webm/Exorcist_angiogram_scene.webm.480p.vp9.webm",
56
+ "https://upload.wikimedia.org/wikipedia/en/f/fa/2001_space_travel.ogv",
57
+ "https://upload.wikimedia.org/wikipedia/en/e/e1/Don%27t_Look_Now_love_scene_.ogg",
58
+ "https://upload.wikimedia.org/wikipedia/en/8/8a/Ellen_comes_out_airport.mp3",
59
+ "https://upload.wikimedia.org/wikipedia/en/b/bf/Dave_Niehaus_Winning_Call_1995_AL_Division_Series.ogg",
60
+ ];
61
+ const communityTitles = [
62
+ "The Ethereum investment community",
63
+ "Cryptography news and discussions",
64
+ "Memes",
65
+ "🤡",
66
+ ];
67
+ const communityDescriptions = [
68
+ "Welcome to /r/EthTrader, a 100% community driven sub. Here you can discuss Ethereum news, memes, investing, trading, miscellaneous market-related subjects and other relevant technology.",
69
+ "Cryptography is the art of creating mathematical assurances for who can do what with data, including but not limited to encryption of messages such that only the key-holder can read it. Cryptography lives at an intersection of math and computer science. This subreddit covers the theory and practice of modern and *strong* cryptography, and it is a technical subreddit focused on the algorithms and implementations of cryptography.",
70
+ "Memes",
71
+ "🤡",
72
+ ];
73
+ const urlSuffixes = [
74
+ "",
75
+ "",
76
+ "",
77
+ "",
78
+ "",
79
+ "",
80
+ "",
81
+ "",
82
+ "",
83
+ "",
84
+ "",
85
+ "#",
86
+ "#/",
87
+ "#?",
88
+ "?",
89
+ "?query",
90
+ "#hash-value",
91
+ "#hash-value?",
92
+ "#hash-value?query=string",
93
+ "#hash-value?query=string&yes=1",
94
+ "?query=string",
95
+ "?query=string&yes=1",
96
+ ];
97
+ const firstNames = [
98
+ "james",
99
+ "robert",
100
+ "john",
101
+ "michael",
102
+ "william",
103
+ "david",
104
+ "richard",
105
+ "joseph",
106
+ "thomas",
107
+ "charles",
108
+ "christopher",
109
+ "daniel",
110
+ "matthew",
111
+ "anthony",
112
+ "mark",
113
+ "donald",
114
+ "steven",
115
+ "paul",
116
+ "andrew",
117
+ "joshua",
118
+ ];
119
+ const displayNames = [
120
+ "COVERCADIGMENTS!",
121
+ "Everco__Evidehovi",
122
+ "fermind-flashyte",
123
+ "FlirtyraForeguiGoldhil_",
124
+ "Hanmiddie Headro Herdman",
125
+ "Hurigher Irongmug",
126
+ "Islandvi Jumbinte",
127
+ "Lackapac Lorvalow",
128
+ "MarsEdgyMedprin",
129
+ "parispn!!!",
130
+ "personna",
131
+ " popic😃",
132
+ "Riderix\n",
133
+ "Romantec__",
134
+ "Sellakuk23",
135
+ "--TickoAim2$",
136
+ "Transia4\t",
137
+ "Trippah+512",
138
+ "😃",
139
+ "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
140
+ "aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa",
141
+ ];
142
+ const postFlairs = [
143
+ { text: "Analysis" },
144
+ { text: "ADVICE", textColor: "#000000", backgroundColor: "#252850" },
145
+ { text: "comedy", textColor: "#FFFFFF", backgroundColor: "#23282B" },
146
+ { text: "General News" },
147
+ {
148
+ text: "Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam Probably a scam!!!!!!!!!!!!!!!!!!!!!!",
149
+ textColor: "#FFFFFF",
150
+ backgroundColor: "#5B3A29",
151
+ },
152
+ { text: "education", textColor: "#000000", backgroundColor: "#4A192C" },
153
+ { text: "MARKETS", backgroundColor: "#F8F32B" },
154
+ { text: "IMPORTANT!!!", backgroundColor: "#C35831" },
155
+ {
156
+ text: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
157
+ backgroundColor: "#AF2B1E",
158
+ },
159
+ { text: "MOON 🌕", backgroundColor: "#D36E70" },
160
+ { text: "video", backgroundColor: "#924E7D" },
161
+ ];
162
+ const authorFlairs = [
163
+ { text: "SCAMMER" },
164
+ { text: "Medical Doctor", textColor: "#000000", backgroundColor: "#252850" },
165
+ { text: "pro", textColor: "#FFFFFF", backgroundColor: "#23282B" },
166
+ {
167
+ text: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
168
+ },
169
+ { text: "Probably a scammer", textColor: "#FFFFFF", backgroundColor: "#5B3A29" },
170
+ { text: "loser", textColor: "#000000", backgroundColor: "#4A192C" },
171
+ { text: "WINNER", backgroundColor: "#F8F32B" },
172
+ { text: "IMPORTANT VIP!!!", backgroundColor: "#C35831" },
173
+ {
174
+ text: "BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN BE CAREFUL OF THIS MAN!!!!!!!!!!!!!!!!!!",
175
+ backgroundColor: "#AF2B1E",
176
+ },
177
+ { text: "🌕", backgroundColor: "#D36E70" },
178
+ { text: "creator", backgroundColor: "#924E7D" },
179
+ ];
180
+ const reasons = [
181
+ "SPAM",
182
+ "this is spam",
183
+ "repeated spamming",
184
+ "User is a known scammer",
185
+ "NSFW",
186
+ "SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM",
187
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
188
+ ];
189
+ const getCidHash = (string) => __awaiter(void 0, void 0, void 0, function* () {
190
+ assert(string && typeof string === "string", `can't getCidHash '${string} not a string'`);
191
+ const seed = yield getNumberHash(string);
192
+ const cid = yield seedToCid(seed);
193
+ return cid;
194
+ });
195
+ const seedToCid = (seed) => __awaiter(void 0, void 0, void 0, function* () {
196
+ assert(typeof seed === "number" && !Number.isNaN(seed) && seed >= 0, `seedToCid seed argument must be positive number not '${seed}'`);
197
+ let base10Seed = String(seed);
198
+ // seed base10 string is usually too small for a cid, make it longer
199
+ // the cid is usually around 46 chars in base58, so 80 chars in base10
200
+ const base10SeedLength = 80;
201
+ while (base10Seed.length < base10SeedLength) {
202
+ base10Seed += base10Seed;
203
+ }
204
+ base10Seed = base10Seed.substring(0, base10SeedLength);
205
+ const uint8Array = uint8ArrayFromString(base10Seed, "base10");
206
+ const base58Cid = uint8ArrayToString(uint8Array, "base58btc");
207
+ return base58Cid;
208
+ });
209
+ // fake hash with lots of collision for speed
210
+ const getNumberHash = (string) => __awaiter(void 0, void 0, void 0, function* () {
211
+ assert(string && typeof string === "string", `can't getNumberHash '${string} not a string'`);
212
+ let hash = 0;
213
+ for (let i = 0; i < string.length; i++) {
214
+ const char = string.charCodeAt(i);
215
+ hash = (hash << 5) - hash + char;
216
+ hash &= hash; // Convert to 32bit integer
217
+ }
218
+ return Math.abs(hash);
219
+ });
220
+ class _SeedIncrementer {
221
+ constructor(seed) {
222
+ this.index = 0;
223
+ assert(typeof seed === "number" && !Number.isNaN(seed) && seed >= 0, `getNumberBetween seed argument must be positive number not '${seed}'`);
224
+ this.seed = seed;
225
+ this.numbers = String(seed)
226
+ .split("")
227
+ .map((number) => Number(number));
228
+ }
229
+ increment() {
230
+ this.index++;
231
+ const divider = this.numbers[this.index % this.numbers.length] + this.index;
232
+ return Math.round(this.seed / divider);
233
+ }
234
+ }
235
+ const SeedIncrementer = (seed) => new _SeedIncrementer(seed);
236
+ const getNumberBetween = (min, max, seed) => __awaiter(void 0, void 0, void 0, function* () {
237
+ assert(typeof seed === "number" && !Number.isNaN(seed) && seed >= 0, `getNumberBetween seed argument must be positive number not '${seed}'`);
238
+ // if the string is exponent, remove chars
239
+ if (String(seed).match(/[^0-9]/)) {
240
+ throw Error(`getNumberBetween seed too large '${seed}'`);
241
+ }
242
+ const number = Number("0." + seed);
243
+ return Math.floor(number * (max - min + 1) + min);
244
+ });
245
+ const getArrayItem = (array, seed) => __awaiter(void 0, void 0, void 0, function* () {
246
+ // const index = await getNumberBetween(0, array.length - 1, seed)
247
+ const index = seed % array.length;
248
+ return array[index];
249
+ });
250
+ const getImageUrl = (_seed) => __awaiter(void 0, void 0, void 0, function* () {
251
+ assert(typeof _seed === "number" && !Number.isNaN(_seed) && _seed >= 0, `getImageUrl seed argument must be positive number not '${_seed}'`);
252
+ const seed = SeedIncrementer(_seed);
253
+ const jpg = `https://picsum.photos/seed/${yield getNumberBetween(10, 2000, seed.increment())}/${yield getNumberBetween(10, 2000, seed.increment())}/${yield getNumberBetween(10, 2000, seed.increment())}.jpg`;
254
+ const webp = `https://picsum.photos/seed/${yield getNumberBetween(10, 2000, seed.increment())}/${yield getNumberBetween(10, 2000, seed.increment())}/${yield getNumberBetween(10, 2000, seed.increment())}.webp`;
255
+ const imageUrls = [
256
+ // jpg & webp
257
+ jpg,
258
+ jpg,
259
+ webp,
260
+ webp,
261
+ "https://samplelib.com/lib/preview/png/sample-bumblebee-400x300.png", // png
262
+ "https://c.tenor.com/WHs8ooxWJUIAAAAM/really-great-example-right-here-echo-gaming.gif", // gif
263
+ "https://filesamples.com/samples/image/bmp/sample_640%C3%97426.bmp", // bmp
264
+ "https://brokensite.xyz/images/dog.png", // broken image
265
+ "https://brokensite.xyz/images/dog.jpeg", // broken jpeg
266
+ ];
267
+ const imageUrl = (yield getArrayItem(imageUrls, seed.increment())) +
268
+ (yield getArrayItem(urlSuffixes, seed.increment()));
269
+ return imageUrl;
270
+ });
271
+ const getAuthorAddress = (_seed) => __awaiter(void 0, void 0, void 0, function* () {
272
+ assert(typeof _seed === "number" && !Number.isNaN(_seed) && _seed >= 0, `getAuthorAddress seed argument must be positive number not '${_seed}'`);
273
+ const seed = SeedIncrementer(_seed);
274
+ const hasEns = yield getArrayItem([true, false, false, false], seed.increment());
275
+ if (hasEns) {
276
+ const text = yield getArrayItem([...firstNames, ...displayNames], seed.increment());
277
+ return (text.toLowerCase().replace(/[^a-z0-9]/g, "") || "john") + ".eth";
278
+ }
279
+ else {
280
+ const address = yield seedToCid(seed.increment());
281
+ return address;
282
+ }
283
+ });
284
+ const getAuthor = (seed) => __awaiter(void 0, void 0, void 0, function* () {
285
+ const authorNumberSeed = SeedIncrementer(yield getNumberHash(seed));
286
+ const author = {
287
+ address: yield getAuthorAddress(authorNumberSeed.increment()),
288
+ };
289
+ author.shortAddress = author.address.endsWith(".eth")
290
+ ? author.address
291
+ : author.address.substring(8, 20);
292
+ const hasDisplayName = yield getArrayItem([true, true, true, false], authorNumberSeed.increment());
293
+ if (hasDisplayName) {
294
+ author.displayName = yield getArrayItem(displayNames, authorNumberSeed.increment());
295
+ }
296
+ const rareTrue = [true, false, false, false, false, false, false, false];
297
+ const hasNftAvatar = yield getArrayItem(rareTrue, authorNumberSeed.increment());
298
+ if (hasNftAvatar) {
299
+ author.avatar = {
300
+ chainTicker: "eth",
301
+ address: yield getArrayItem([
302
+ "0xed5af388653567af2f388e6224dc7c4b3241c544",
303
+ "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
304
+ "0x60e4d786628fea6478f785a6d7e704777c86a7c6",
305
+ "0x79fcdef22feed20eddacbb2587640e45491b757f",
306
+ "0x0000000000000000000000000000000000000dead",
307
+ ], authorNumberSeed.increment()),
308
+ index: yield getNumberBetween(1, 2000, authorNumberSeed.increment()),
309
+ };
310
+ }
311
+ const hasFlair = yield getArrayItem(rareTrue, authorNumberSeed.increment());
312
+ if (hasFlair) {
313
+ author.flair = yield getArrayItem(authorFlairs, authorNumberSeed.increment());
314
+ }
315
+ return author;
316
+ });
317
+ const getPostContent = (seed) => __awaiter(void 0, void 0, void 0, function* () {
318
+ var _a;
319
+ const postNumberSeed = SeedIncrementer(yield getNumberHash(seed));
320
+ const postContent = {
321
+ depth: 0,
322
+ author: yield getAuthor(String(postNumberSeed)),
323
+ title: yield getArrayItem(commentTitles, postNumberSeed.increment()),
324
+ };
325
+ const hasFlair = yield getArrayItem([true, false, false, false], postNumberSeed.increment());
326
+ if (hasFlair) {
327
+ postContent.flair = yield getArrayItem(postFlairs, postNumberSeed.increment());
328
+ }
329
+ let isLinkPost = yield getArrayItem([true, false], postNumberSeed.increment());
330
+ if (doubleMedia && !isLinkPost) {
331
+ isLinkPost = yield getArrayItem([true, false], postNumberSeed.increment());
332
+ }
333
+ if (isLinkPost) {
334
+ postContent.link = yield getArrayItem(commentLinks, postNumberSeed.increment());
335
+ let linkIsImage = yield getArrayItem([true, false], postNumberSeed.increment());
336
+ if (doubleMedia && !linkIsImage) {
337
+ linkIsImage = yield getArrayItem([true, false], postNumberSeed.increment());
338
+ }
339
+ if (linkIsImage) {
340
+ postContent.link = yield getImageUrl(postNumberSeed.increment());
341
+ // add video and audio
342
+ const imageIsMedia = yield getArrayItem([true, false, false, false], postNumberSeed.increment());
343
+ if (imageIsMedia) {
344
+ postContent.link = yield getArrayItem(mediaLinks, postNumberSeed.increment());
345
+ // add at least one example of video with width and height
346
+ if (postContent.link === mediaLinks[0]) {
347
+ postContent.linkWidth = 852;
348
+ postContent.linkHeight = 480;
349
+ }
350
+ }
351
+ // if link is image, add width and height
352
+ else {
353
+ const [, linkWidth, linkHeight] = (((_a = postContent.link.match(/\d+\/\d+\/\d+/)) === null || _a === void 0 ? void 0 : _a[0]) || "").split("/");
354
+ postContent.linkWidth = Number(linkWidth);
355
+ postContent.linkHeight = Number(linkHeight);
356
+ }
357
+ }
358
+ const hasThumbnail = yield getArrayItem([true, true, true, false], postNumberSeed.increment());
359
+ if (!linkIsImage && hasThumbnail) {
360
+ postContent.thumbnailUrl = yield getImageUrl(postNumberSeed.increment());
361
+ }
362
+ }
363
+ // else is text post
364
+ else {
365
+ postContent.content = yield getArrayItem(commentContents, postNumberSeed.increment());
366
+ const hasQuote = yield getArrayItem([true, false, false, false], postNumberSeed.increment());
367
+ if (hasQuote) {
368
+ const max = 7;
369
+ const lines = postContent.content.split("\n");
370
+ for (const i in lines) {
371
+ const lineIsQuote = yield getArrayItem([true, false], postNumberSeed.increment());
372
+ if (lineIsQuote) {
373
+ lines[i] = ">" + lines[i];
374
+ }
375
+ if (Number(i) > max) {
376
+ break;
377
+ }
378
+ }
379
+ postContent.content = lines.join("\n");
380
+ }
381
+ }
382
+ return postContent;
383
+ });
384
+ const getReplyContent = (getReplyContentOptions, seed) => __awaiter(void 0, void 0, void 0, function* () {
385
+ const replyNumberSeed = SeedIncrementer(yield getNumberHash(seed));
386
+ const { depth, parentCid, postCid } = getReplyContentOptions;
387
+ const author = yield getAuthor(String(replyNumberSeed.seed));
388
+ let content = yield getArrayItem(commentContents, replyNumberSeed.increment());
389
+ const hasQuote = yield getArrayItem([true, false, false, false], replyNumberSeed.increment());
390
+ if (hasQuote) {
391
+ const max = 7;
392
+ const lines = content.split("\n");
393
+ for (const i in lines) {
394
+ const lineIsQuote = yield getArrayItem([true, false], replyNumberSeed.increment());
395
+ if (lineIsQuote) {
396
+ lines[i] = ">" + lines[i];
397
+ }
398
+ if (Number(i) > max) {
399
+ break;
400
+ }
401
+ }
402
+ content = lines.join("\n");
403
+ }
404
+ const replyContent = { content, author, depth, parentCid, postCid };
405
+ const hasLink = yield getArrayItem([true, false, false, false], replyNumberSeed.increment());
406
+ if (hasLink) {
407
+ replyContent.link = yield getArrayItem(commentLinks, replyNumberSeed.increment());
408
+ const linkIsImage = yield getArrayItem([true, false], replyNumberSeed.increment());
409
+ if (linkIsImage) {
410
+ replyContent.link = yield getImageUrl(replyNumberSeed.increment());
411
+ // add video and audio
412
+ const imageIsMedia = yield getArrayItem([true, false, false, false], replyNumberSeed.increment());
413
+ if (imageIsMedia) {
414
+ replyContent.link = yield getArrayItem(mediaLinks, replyNumberSeed.increment());
415
+ }
416
+ }
417
+ const hasThumbnail = yield getArrayItem([true, true, true, false], replyNumberSeed.increment());
418
+ if (!linkIsImage && hasThumbnail) {
419
+ replyContent.thumbnailUrl = yield getImageUrl(replyNumberSeed.increment());
420
+ }
421
+ }
422
+ const hasTitle = yield getArrayItem([true, false, false, false, false, false, false], replyNumberSeed.increment());
423
+ if (hasTitle) {
424
+ replyContent.title = yield getArrayItem(commentTitles, replyNumberSeed.increment());
425
+ }
426
+ return replyContent;
427
+ });
428
+ const getCommunityContent = (seed) => __awaiter(void 0, void 0, void 0, function* () {
429
+ var _a;
430
+ const communityNumberSeed = SeedIncrementer(yield getNumberHash(seed));
431
+ const community = {
432
+ pubsubTopic: yield seedToCid(communityNumberSeed.seed),
433
+ };
434
+ const hasChallengeTypes = yield getArrayItem([true, false], communityNumberSeed.increment());
435
+ if (hasChallengeTypes) {
436
+ community.challengeTypes = ["image"];
437
+ }
438
+ const hasRoles = yield getArrayItem([true, false], communityNumberSeed.increment());
439
+ if (hasRoles) {
440
+ community.roles = {
441
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "owner" },
442
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "admin" },
443
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "moderator" },
444
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "moderator" },
445
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "moderator" },
446
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "moderator" },
447
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "moderator" },
448
+ [yield getAuthorAddress(communityNumberSeed.increment())]: { role: "moderator" },
449
+ };
450
+ }
451
+ const title = yield getArrayItem([undefined, ...communityTitles], communityNumberSeed.increment());
452
+ if (title) {
453
+ community.title = title;
454
+ }
455
+ const description = yield getArrayItem([undefined, ...communityDescriptions], communityNumberSeed.increment());
456
+ if (description) {
457
+ community.description = description;
458
+ }
459
+ const hasPostFlairs = yield getArrayItem([true, false], communityNumberSeed.increment());
460
+ if (hasPostFlairs) {
461
+ community.flairs = { post: postFlairs };
462
+ }
463
+ const hasAuthorFlairs = yield getArrayItem([true, false], communityNumberSeed.increment());
464
+ if (hasAuthorFlairs) {
465
+ community.flairs = { post: (_a = community.flairs) === null || _a === void 0 ? void 0 : _a.post, author: authorFlairs };
466
+ }
467
+ const hasSuggested = yield getArrayItem([true, false], communityNumberSeed.increment());
468
+ if (hasSuggested) {
469
+ community.suggested = {
470
+ primaryColor: (yield getArrayItem(postFlairs, communityNumberSeed.increment()))
471
+ .backgroundColor,
472
+ secondaryColor: (yield getArrayItem(postFlairs, communityNumberSeed.increment()))
473
+ .backgroundColor,
474
+ avatarUrl: yield getArrayItem([undefined, yield getImageUrl(communityNumberSeed.increment())], communityNumberSeed.increment()),
475
+ bannerUrl: yield getArrayItem([undefined, yield getImageUrl(communityNumberSeed.increment())], communityNumberSeed.increment()),
476
+ backgroundUrl: yield getArrayItem([undefined, yield getImageUrl(communityNumberSeed.increment())], communityNumberSeed.increment()),
477
+ language: yield getArrayItem([undefined, undefined, "en", "en", "es", "ru"], communityNumberSeed.increment()),
478
+ };
479
+ }
480
+ const hasFeatures = yield getArrayItem([true, false], communityNumberSeed.increment());
481
+ if (hasFeatures) {
482
+ community.features = {
483
+ noVideos: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
484
+ noSpoilers: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
485
+ noImages: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
486
+ noVideoReplies: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
487
+ noSpoilerReplies: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
488
+ noImageReplies: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
489
+ noPolls: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
490
+ noCrossposts: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
491
+ noUpvotes: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
492
+ noDownvotes: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
493
+ noAuthors: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
494
+ anonymousAuthors: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
495
+ noNestedReplies: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
496
+ safeForWork: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
497
+ authorFlairs: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
498
+ requireAuthorFlairs: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
499
+ postFlairs: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
500
+ requirePostFlairs: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
501
+ noMarkdownImages: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
502
+ noMarkdownVideos: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
503
+ markdownImageReplies: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
504
+ markdownVideoReplies: yield getArrayItem([undefined, undefined, true, false], communityNumberSeed.increment()),
505
+ };
506
+ }
507
+ const hasRules = yield getArrayItem([true, false], communityNumberSeed.increment());
508
+ if (hasRules) {
509
+ community.rules = [
510
+ "no spam",
511
+ "be nice",
512
+ "Do not link to CNN.",
513
+ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
514
+ "OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO OOOOOOOOOO ",
515
+ ];
516
+ }
517
+ const isOnline = yield getArrayItem([true, false], communityNumberSeed.increment());
518
+ if (isOnline) {
519
+ // updated in last 1h
520
+ community.updatedAt =
521
+ Math.round(Date.now() / 1000) -
522
+ (yield getNumberBetween(1, 60 * 60, communityNumberSeed.increment()));
523
+ }
524
+ else {
525
+ // updated in last month
526
+ community.updatedAt =
527
+ Math.round(Date.now() / 1000) -
528
+ (yield getNumberBetween(60 * 60, 60 * 60 * 24 * 30, communityNumberSeed.increment()));
529
+ }
530
+ community.createdAt =
531
+ community.updatedAt -
532
+ (yield getNumberBetween(1, 60 * 60 * 24 * 3000, communityNumberSeed.increment()));
533
+ return community;
534
+ });
535
+ // for debugging slow bulk reply generation
536
+ let replyLoopCount = 0;
537
+ const getCommentUpdateContent = (comment) => __awaiter(void 0, void 0, void 0, function* () {
538
+ const commentUpdateSeedNumber = SeedIncrementer(yield getNumberHash(comment.cid));
539
+ const upvotesPerUpdate = yield getNumberBetween(1, 1000, commentUpdateSeedNumber.increment());
540
+ const downvotesPerUpdate = yield getNumberBetween(1, 1000, commentUpdateSeedNumber.increment());
541
+ const commentUpdateContent = {};
542
+ // simulate finding vote counts on an IPNS record
543
+ commentUpdateContent.upvoteCount =
544
+ typeof comment.upvoteCount === "number"
545
+ ? comment.upvoteCount + upvotesPerUpdate
546
+ : upvotesPerUpdate;
547
+ commentUpdateContent.downvoteCount =
548
+ typeof comment.downvoteCount === "number"
549
+ ? comment.downvoteCount + downvotesPerUpdate
550
+ : downvotesPerUpdate;
551
+ // find the number of replies
552
+ commentUpdateContent.replyCount = 0;
553
+ const hasReplies = yield getArrayItem([true, false, false, false], commentUpdateSeedNumber.increment());
554
+ if (hasReplies) {
555
+ commentUpdateContent.replyCount = yield getNumberBetween(0, 30, commentUpdateSeedNumber.increment());
556
+ if (comment.depth > 0) {
557
+ commentUpdateContent.replyCount = commentUpdateContent.replyCount / (comment.depth + 1) ** 2;
558
+ }
559
+ if (commentUpdateContent.replyCount < 1) {
560
+ commentUpdateContent.replyCount = 0;
561
+ }
562
+ commentUpdateContent.replyCount = Math.round(commentUpdateContent.replyCount);
563
+ }
564
+ // simulate finding replies from IPNS record
565
+ commentUpdateContent.replies = new Pages({ comment });
566
+ commentUpdateContent.replies.pages.best = { nextCid: undefined, comments: [] };
567
+ const getReplyContentOptions = {
568
+ depth: comment.depth + 1,
569
+ parentCid: comment.cid,
570
+ postCid: comment.cid,
571
+ };
572
+ let replyCount = commentUpdateContent.replyCount;
573
+ const replyCids = new Set();
574
+ while (replyCount-- > 0) {
575
+ // console.log({replyLoopCount: replyLoopCount++, replyCount: commentUpdateContent.replyCount, depth: comment.depth, cid: comment.cid, index: replyCount})
576
+ const cid = yield seedToCid(yield getNumberHash(comment.cid + replyCount));
577
+ const replyContent = yield getReplyContent(getReplyContentOptions, cid + "replycontent" + replyCount);
578
+ const reply = Object.assign(Object.assign({ cid, shortCid: cid.substring(2, 14), timestamp: yield getNumberBetween(comment.timestamp, NOW, commentUpdateSeedNumber.increment()) }, replyContent), { communityAddress: comment.communityAddress || "memes.eth" });
579
+ if (replyCids.has(reply.cid)) {
580
+ console.error(`mock content error: duplicate reply cid '${reply.cid}'`);
581
+ }
582
+ replyCids.add(reply.cid);
583
+ const replyUpdateContent = yield getCommentUpdateContent(reply);
584
+ commentUpdateContent.replies.pages.best.comments.push(Object.assign(Object.assign({}, reply), replyUpdateContent));
585
+ }
586
+ // if post with lots of replies, add replies pages
587
+ if (commentUpdateContent.replyCount >= 15 && comment.depth === 0) {
588
+ commentUpdateContent.replies.pages.best.nextCid = yield seedToCid(yield getNumberHash(comment.cid + "bestpagecid2"));
589
+ commentUpdateContent.replies.pageCids = {
590
+ new: yield seedToCid(yield getNumberHash(comment.cid + "newpagecid")),
591
+ old: yield seedToCid(yield getNumberHash(comment.cid + "oldpagecid")),
592
+ };
593
+ }
594
+ const rareTrue = [
595
+ true,
596
+ false,
597
+ false,
598
+ false,
599
+ false,
600
+ false,
601
+ false,
602
+ false,
603
+ false,
604
+ false,
605
+ false,
606
+ false,
607
+ false,
608
+ false,
609
+ false,
610
+ false,
611
+ false,
612
+ false,
613
+ false,
614
+ false,
615
+ false,
616
+ ];
617
+ const isSpoiler = yield getArrayItem(rareTrue, commentUpdateSeedNumber.increment());
618
+ if (isSpoiler) {
619
+ commentUpdateContent.spoiler = true;
620
+ }
621
+ const isEdited = yield getArrayItem(rareTrue, commentUpdateSeedNumber.increment());
622
+ if (isEdited && !comment.edit) {
623
+ commentUpdateContent.edit = {
624
+ commentCid: comment.cid,
625
+ timestamp: comment.timestamp + 60 * 30,
626
+ reason: "I wanted to know why the downvotes?",
627
+ author: comment.author,
628
+ };
629
+ commentUpdateContent.original = {
630
+ content: comment.content,
631
+ };
632
+ commentUpdateContent.content = (comment.content || "") + " WHY DOWNVOTES!?";
633
+ }
634
+ const isDeleted = yield getArrayItem(rareTrue, commentUpdateSeedNumber.increment());
635
+ const isPinned = yield getArrayItem(rareTrue, commentUpdateSeedNumber.increment());
636
+ const isRemoved = yield getArrayItem(rareTrue, commentUpdateSeedNumber.increment());
637
+ const isLocked = yield getArrayItem(rareTrue, commentUpdateSeedNumber.increment());
638
+ const isPurged = yield getArrayItem(rareTrue, commentUpdateSeedNumber.increment());
639
+ if (isDeleted) {
640
+ commentUpdateContent.deleted = true;
641
+ }
642
+ else if (isPinned) {
643
+ commentUpdateContent.pinned = true;
644
+ }
645
+ else if (isRemoved) {
646
+ commentUpdateContent.removed = true;
647
+ const hasReason = yield getArrayItem([true, false], commentUpdateSeedNumber.increment());
648
+ if (hasReason) {
649
+ commentUpdateContent.reason = yield getArrayItem(reasons, commentUpdateSeedNumber.increment());
650
+ }
651
+ }
652
+ else if (isLocked && comment.depth === 0) {
653
+ commentUpdateContent.locked = true;
654
+ const hasReason = yield getArrayItem([true, false], commentUpdateSeedNumber.increment());
655
+ if (hasReason) {
656
+ commentUpdateContent.reason = yield getArrayItem(reasons, commentUpdateSeedNumber.increment());
657
+ }
658
+ }
659
+ else if (isPurged) {
660
+ commentUpdateContent.purged = true;
661
+ const hasReason = yield getArrayItem([true, false], commentUpdateSeedNumber.increment());
662
+ if (hasReason) {
663
+ commentUpdateContent.reason = yield getArrayItem(reasons, commentUpdateSeedNumber.increment());
664
+ }
665
+ }
666
+ commentUpdateContent.updatedAt = Math.round(Date.now() / 1000);
667
+ return commentUpdateContent;
668
+ });
669
+ const pageCommentCids = new Set();
670
+ const getCommentsPage = (pageCid, communityOrComment) => __awaiter(void 0, void 0, void 0, function* () {
671
+ const communityAddress = communityOrComment.address || communityOrComment.communityAddress;
672
+ const commentsPageSeedNumber = SeedIncrementer(yield getNumberHash(pageCid));
673
+ const page = {
674
+ nextCid: yield seedToCid(commentsPageSeedNumber.increment()),
675
+ comments: [],
676
+ };
677
+ const postCount = 100;
678
+ let index = 0;
679
+ const pkc = new PKC();
680
+ while (index++ < postCount) {
681
+ const cid = yield seedToCid(yield getNumberHash(pageCid + index));
682
+ // debug message
683
+ if (pageCommentCids.has(cid)) {
684
+ console.error(`mock content error: duplicate page comment cid '${cid}'`);
685
+ }
686
+ pageCommentCids.add(cid);
687
+ // comment = {...comment, ...(await getPostContent(comment.cid)), ...(await getCommentUpdateContent(comment))}
688
+ const comment = yield pkc.getComment({ cid });
689
+ comment.communityAddress = communityAddress;
690
+ const commentUpdateContent = yield getCommentUpdateContent(comment);
691
+ for (const prop in commentUpdateContent) {
692
+ comment[prop] = commentUpdateContent[prop];
693
+ }
694
+ page.comments.push(comment);
695
+ }
696
+ return page;
697
+ });
698
+ // array of communities probably created by the user
699
+ const createdCommunities = {};
700
+ class NameResolverClient extends EventEmitter {
701
+ constructor() {
702
+ super(...arguments);
703
+ this.state = "stopped";
704
+ }
705
+ }
706
+ class PKC extends EventEmitter {
707
+ constructor(options = {}) {
708
+ super();
709
+ this.clients = (() => {
710
+ const pkcRpcClients = {
711
+ "http://localhost:9138": new PkcRpcClient(),
712
+ };
713
+ return {
714
+ pkcRpcClients,
715
+ };
716
+ })();
717
+ this.nameResolvers = (options === null || options === void 0 ? void 0 : options.nameResolvers) || [];
718
+ this._clientsManager = {
719
+ clients: {
720
+ nameResolvers: this.nameResolvers.reduce((resolverClients, resolver) => (Object.assign(Object.assign({}, resolverClients), { [resolver.key]: new NameResolverClient() })), {}),
721
+ },
722
+ };
723
+ }
724
+ createSigner() {
725
+ return __awaiter(this, void 0, void 0, function* () {
726
+ return {
727
+ privateKey: "private key",
728
+ address: yield getCidHash(String(Math.random())),
729
+ };
730
+ });
731
+ }
732
+ resolveAuthorAddress(options) {
733
+ return __awaiter(this, void 0, void 0, function* () {
734
+ const resolver = this.nameResolvers.find((nameResolver) => { var _a; return (_a = nameResolver === null || nameResolver === void 0 ? void 0 : nameResolver.canResolve) === null || _a === void 0 ? void 0 : _a.call(nameResolver, { name: options.address }); });
735
+ const resolverClient = resolver && this._clientsManager.clients.nameResolvers[resolver.key];
736
+ if (resolverClient) {
737
+ resolverClient.state = "resolving-author-name";
738
+ resolverClient.emit("statechange", resolverClient.state);
739
+ }
740
+ yield new Promise((resolve) => setTimeout(resolve, 10));
741
+ if (resolverClient) {
742
+ resolverClient.state = "stopped";
743
+ resolverClient.emit("statechange", resolverClient.state);
744
+ }
745
+ return "resolved author address";
746
+ });
747
+ }
748
+ resolveAuthorName(options) {
749
+ return __awaiter(this, void 0, void 0, function* () {
750
+ return this.resolveAuthorAddress(options);
751
+ });
752
+ }
753
+ createCommunity(createCommunityOptions) {
754
+ return __awaiter(this, void 0, void 0, function* () {
755
+ const communityIdentifier = (createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.address) ||
756
+ (createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.name) ||
757
+ (createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.publicKey);
758
+ // if the only argument is {address}, the user didn't create the sub, it's a fetched sub
759
+ if ((createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.address) && Object.keys(createCommunityOptions).length === 1) {
760
+ return new Community(createCommunityOptions);
761
+ }
762
+ const signer = yield this.createSigner();
763
+ const community = new Community(Object.assign({ signer }, createCommunityOptions));
764
+ // keep a list of communities the user probably created himself to use with pkc.communities
765
+ if (!communityIdentifier) {
766
+ createdCommunities[community.address || ""] = community;
767
+ }
768
+ return community;
769
+ });
770
+ }
771
+ getCommunity(options) {
772
+ return __awaiter(this, void 0, void 0, function* () {
773
+ const address = options === null || options === void 0 ? void 0 : options.address;
774
+ const createCommunityOptions = { address };
775
+ const community = new Community(createCommunityOptions);
776
+ const hotPageCid = yield seedToCid(yield getNumberHash(address + "hotpagecid"));
777
+ community.posts.pages.hot = yield getCommentsPage(hotPageCid, community);
778
+ community.posts.pageCids = {
779
+ hot: yield seedToCid(yield getNumberHash(address + "hotpagecid2")),
780
+ topAll: yield seedToCid(yield getNumberHash(address + "topallpagecid")),
781
+ new: yield seedToCid(yield getNumberHash(address + "newpagecid")),
782
+ active: yield seedToCid(yield getNumberHash(address + "activepagecid")),
783
+ };
784
+ const communityContent = yield getCommunityContent(address);
785
+ // add extra props
786
+ for (const prop in communityContent) {
787
+ community[prop] = communityContent[prop];
788
+ }
789
+ return community;
790
+ });
791
+ }
792
+ // TODO: implement event communitieschange
793
+ get communities() {
794
+ const communityAddresses = Object.keys(createdCommunities);
795
+ return communityAddresses;
796
+ }
797
+ createComment(createCommentOptions) {
798
+ return __awaiter(this, void 0, void 0, function* () {
799
+ return new Comment(createCommentOptions);
800
+ });
801
+ }
802
+ getComment(options) {
803
+ return __awaiter(this, void 0, void 0, function* () {
804
+ const cid = options === null || options === void 0 ? void 0 : options.cid;
805
+ const commentSeedNumber = SeedIncrementer(yield getNumberHash(cid + "getcomment"));
806
+ let commentContent = yield getPostContent(cid + "postcontent");
807
+ const isReply = cid.endsWith("reply");
808
+ if (isReply) {
809
+ const depth = yield getNumberBetween(1, 10, commentSeedNumber.increment());
810
+ const parentCid = yield seedToCid(commentSeedNumber.increment());
811
+ const postCid = depth === 1 ? parentCid : yield seedToCid(commentSeedNumber.increment());
812
+ const getReplyContentOptions = { depth, parentCid, postCid };
813
+ commentContent = yield getReplyContent(getReplyContentOptions, cid + "replycontent");
814
+ }
815
+ const createCommentOptions = Object.assign({ cid, timestamp: yield getNumberBetween(NOW - DAY * 30, NOW, commentSeedNumber.increment()), communityAddress: "memes.eth" }, commentContent);
816
+ const comment = new Comment(createCommentOptions);
817
+ // add missing props from createCommentOptions
818
+ for (const prop in createCommentOptions) {
819
+ // @ts-ignore
820
+ comment[prop] = createCommentOptions[prop];
821
+ }
822
+ return comment;
823
+ });
824
+ }
825
+ createVote(publishVoteOptions) {
826
+ return __awaiter(this, void 0, void 0, function* () {
827
+ return new Vote(publishVoteOptions);
828
+ });
829
+ }
830
+ createCommentEdit(publishCommentEditOptions) {
831
+ return __awaiter(this, void 0, void 0, function* () {
832
+ return new CommentEdit(publishCommentEditOptions);
833
+ });
834
+ }
835
+ createCommunityEdit() {
836
+ return __awaiter(this, void 0, void 0, function* () {
837
+ return new CommunityEdit();
838
+ });
839
+ }
840
+ fetchCid(options) {
841
+ return __awaiter(this, void 0, void 0, function* () {
842
+ const cid = options === null || options === void 0 ? void 0 : options.cid;
843
+ if (cid === null || cid === void 0 ? void 0 : cid.startsWith("statscid")) {
844
+ return JSON.stringify({
845
+ hourActiveUserCount: 1,
846
+ dayActiveUserCount: 11,
847
+ weekActiveUserCount: 111,
848
+ monthActiveUserCount: 1111,
849
+ yearActiveUserCount: 11111,
850
+ allActiveUserCount: 111111,
851
+ hourPostCount: 2,
852
+ dayPostCount: 22,
853
+ weekPostCount: 222,
854
+ monthPostCount: 2222,
855
+ yearPostCount: 22222,
856
+ allPostCount: 222222,
857
+ });
858
+ }
859
+ throw Error(`pkc.fetchCid not implemented in mock content for cid '${cid}'`);
860
+ });
861
+ }
862
+ pubsubSubscribe(communityAddress) {
863
+ return __awaiter(this, void 0, void 0, function* () { });
864
+ }
865
+ pubsubUnsubscribe(communityAddress) {
866
+ return __awaiter(this, void 0, void 0, function* () { });
867
+ }
868
+ validateComment(comment, validateCommentOptions) {
869
+ return __awaiter(this, void 0, void 0, function* () { });
870
+ }
871
+ }
872
+ class PkcRpcClient extends EventEmitter {
873
+ constructor() {
874
+ super();
875
+ this.state = "connecting";
876
+ this.settings = undefined;
877
+ // simulate connecting to the rpc
878
+ setTimeout(() => {
879
+ this.state = "connected";
880
+ this.settings = { challenges: { "text-math": {} } };
881
+ this.emit("statechange", this.state);
882
+ this.emit("settingschange", this.settings);
883
+ }, 5000);
884
+ }
885
+ setSettings(settings) {
886
+ return __awaiter(this, void 0, void 0, function* () {
887
+ this.settings = settings;
888
+ this.emit("settingschange", this.settings);
889
+ });
890
+ }
891
+ }
892
+ class Pages {
893
+ constructor(pagesOptions) {
894
+ this.pageCids = {};
895
+ this.pages = {};
896
+ Object.defineProperty(this, "community", {
897
+ value: pagesOptions === null || pagesOptions === void 0 ? void 0 : pagesOptions.community,
898
+ enumerable: false,
899
+ });
900
+ Object.defineProperty(this, "comment", { value: pagesOptions === null || pagesOptions === void 0 ? void 0 : pagesOptions.comment, enumerable: false });
901
+ }
902
+ getPage(options) {
903
+ return __awaiter(this, void 0, void 0, function* () {
904
+ const cid = options === null || options === void 0 ? void 0 : options.cid;
905
+ // need to wait twice otherwise react renders too fast and fetches too many pages in advance
906
+ yield simulateLoadingTime();
907
+ return getCommentsPage(cid, this.community || this.comment);
908
+ });
909
+ }
910
+ validatePage(page) {
911
+ return __awaiter(this, void 0, void 0, function* () { });
912
+ }
913
+ }
914
+ class Community extends EventEmitter {
915
+ constructor(createCommunityOptions) {
916
+ var _a, _b, _c, _d, _e, _f, _g;
917
+ super();
918
+ this._getCommunityOnFirstUpdate = false;
919
+ this.address =
920
+ (createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.address) ||
921
+ (createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.name) ||
922
+ (createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.publicKey);
923
+ this.pubsubTopic = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.pubsubTopic;
924
+ this.createdAt = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.createdAt;
925
+ this.updatedAt = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.updatedAt;
926
+ this.challengeTypes = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.challengeTypes;
927
+ this.roles = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.roles;
928
+ this.flairs = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.flairs;
929
+ this.suggested = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.suggested;
930
+ this.features = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.features;
931
+ this.rules = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.rules;
932
+ this.title = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.title;
933
+ this.description = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.description;
934
+ this.statsCid = "statscid";
935
+ for (const prop in createCommunityOptions) {
936
+ if (createCommunityOptions[prop] !== undefined) {
937
+ // @ts-ignore
938
+ this[prop] = createCommunityOptions[prop];
939
+ }
940
+ }
941
+ this.posts = new Pages({ community: this });
942
+ // add community.posts from createCommunityOptions
943
+ if ((_a = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.posts) === null || _a === void 0 ? void 0 : _a.pages) {
944
+ this.posts.pages = (_b = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.posts) === null || _b === void 0 ? void 0 : _b.pages;
945
+ }
946
+ if ((_c = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.posts) === null || _c === void 0 ? void 0 : _c.pageCids) {
947
+ this.posts.pageCids = (_d = createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.posts) === null || _d === void 0 ? void 0 : _d.pageCids;
948
+ }
949
+ if (!this.address && ((_e = this.signer) === null || _e === void 0 ? void 0 : _e.address)) {
950
+ this.address = this.signer.address;
951
+ }
952
+ this.shortAddress = ((_f = this.address) === null || _f === void 0 ? void 0 : _f.endsWith(".eth"))
953
+ ? this.address
954
+ : (_g = this.address) === null || _g === void 0 ? void 0 : _g.substring(8, 20);
955
+ Object.defineProperty(this, "updating", { enumerable: false, writable: true });
956
+ // @ts-ignore
957
+ this.updating = false;
958
+ // if the only argument is {address}, it means the first update should use getCommunity()
959
+ if ((createCommunityOptions === null || createCommunityOptions === void 0 ? void 0 : createCommunityOptions.address) && Object.keys(createCommunityOptions).length === 1) {
960
+ this._getCommunityOnFirstUpdate = true;
961
+ }
962
+ }
963
+ edit(editCommunityOptions) {
964
+ return __awaiter(this, void 0, void 0, function* () {
965
+ assert(editCommunityOptions && typeof editCommunityOptions === "object", `invalid editCommunityOptions '${editCommunityOptions}'`);
966
+ for (const prop in editCommunityOptions) {
967
+ if (editCommunityOptions[prop] !== undefined) {
968
+ // @ts-ignore
969
+ this[prop] = editCommunityOptions[prop];
970
+ }
971
+ }
972
+ });
973
+ }
974
+ update() {
975
+ return __awaiter(this, void 0, void 0, function* () {
976
+ if (!this.address) {
977
+ throw Error(`can't update without community.address`);
978
+ }
979
+ // don't update twice
980
+ // @ts-ignore
981
+ if (this.updating) {
982
+ return;
983
+ }
984
+ // @ts-ignore
985
+ this.updating = true;
986
+ this.updatingState = "fetching-ipns";
987
+ this.emit("updatingstatechange", "fetching-ipns");
988
+ simulateLoadingTime().then(() => {
989
+ this.simulateUpdateEvent();
990
+ });
991
+ });
992
+ }
993
+ delete() {
994
+ return __awaiter(this, void 0, void 0, function* () {
995
+ if (this.address) {
996
+ delete createdCommunities[this.address];
997
+ }
998
+ });
999
+ }
1000
+ simulateUpdateEvent() {
1001
+ if (this._getCommunityOnFirstUpdate) {
1002
+ return this.simulateGetCommunityOnFirstUpdateEvent();
1003
+ }
1004
+ this.emit("update", this);
1005
+ }
1006
+ simulateGetCommunityOnFirstUpdateEvent() {
1007
+ return __awaiter(this, void 0, void 0, function* () {
1008
+ this._getCommunityOnFirstUpdate = false;
1009
+ // @ts-ignore
1010
+ const community = yield new PKC().getCommunity({ address: this.address });
1011
+ const props = JSON.parse(JSON.stringify(community));
1012
+ for (const prop in props) {
1013
+ if (prop.startsWith("_")) {
1014
+ continue;
1015
+ }
1016
+ // @ts-ignore
1017
+ this[prop] = props[prop];
1018
+ }
1019
+ this.posts.getPage = community.posts.getPage;
1020
+ this.updatingState = "succeeded";
1021
+ this.emit("update", this);
1022
+ this.emit("updatingstatechange", "succeeded");
1023
+ this.simulateUpdateEvent();
1024
+ });
1025
+ }
1026
+ }
1027
+ let challengeRequestCount = 0;
1028
+ let challengeAnswerCount = 0;
1029
+ class Publication extends EventEmitter {
1030
+ constructor() {
1031
+ super();
1032
+ Object.defineProperty(this, "challengeRequestId", { enumerable: false, writable: true });
1033
+ Object.defineProperty(this, "challengeAnswerId", { enumerable: false, writable: true });
1034
+ this.challengeRequestId = `r${++challengeRequestCount}`;
1035
+ this.challengeAnswerId = `a${++challengeAnswerCount}`;
1036
+ }
1037
+ publish() {
1038
+ return __awaiter(this, void 0, void 0, function* () {
1039
+ yield simulateLoadingTime();
1040
+ yield this.simulateChallengeEvent();
1041
+ });
1042
+ }
1043
+ simulateChallengeEvent() {
1044
+ return __awaiter(this, void 0, void 0, function* () {
1045
+ const challenges = [];
1046
+ const challengeCount = yield getNumberBetween(1, 3, yield getNumberHash(this.challengeRequestId));
1047
+ while (challenges.length < challengeCount) {
1048
+ challenges.push({ type: "image/png", challenge: captchaImageBase64 });
1049
+ }
1050
+ const challengeMessage = {
1051
+ type: "CHALLENGE",
1052
+ challengeRequestId: this.challengeRequestId,
1053
+ challenges,
1054
+ };
1055
+ this.emit("challenge", challengeMessage, this);
1056
+ });
1057
+ }
1058
+ publishChallengeAnswers(challengeAnswers) {
1059
+ return __awaiter(this, void 0, void 0, function* () {
1060
+ yield simulateLoadingTime();
1061
+ this.simulateChallengeVerificationEvent();
1062
+ });
1063
+ }
1064
+ simulateChallengeVerificationEvent() {
1065
+ return __awaiter(this, void 0, void 0, function* () {
1066
+ var _a, _b, _c;
1067
+ // if publication has content, create cid for this content and add it to comment and challengeVerificationMessage
1068
+ const cidSeed = `${(_a = this.content) !== null && _a !== void 0 ? _a : ""}${(_b = this.title) !== null && _b !== void 0 ? _b : ""}${(_c = this.link) !== null && _c !== void 0 ? _c : ""}`;
1069
+ this.cid = cidSeed.length > 0 ? yield getCidHash(`${cidSeed}cid`) : undefined;
1070
+ const commentUpdate = this.cid && { cid: this.cid };
1071
+ const challengeVerificationMessage = {
1072
+ type: "CHALLENGEVERIFICATION",
1073
+ challengeRequestId: this.challengeRequestId,
1074
+ challengeAnswerId: this.challengeAnswerId,
1075
+ challengeSuccess: true,
1076
+ commentUpdate,
1077
+ };
1078
+ this.emit("challengeverification", challengeVerificationMessage, this);
1079
+ });
1080
+ }
1081
+ stop() {
1082
+ if (this.updating || this.updatingState !== "stopped") {
1083
+ this.state = "stopped";
1084
+ this.updating = false;
1085
+ this.updatingState = "stopped";
1086
+ this.emit("statechange", "stopped");
1087
+ this.emit("updatingstatechange", "stopped");
1088
+ }
1089
+ }
1090
+ }
1091
+ class Comment extends Publication {
1092
+ constructor(createCommentOptions) {
1093
+ super();
1094
+ this._getCommentOnFirstUpdate = false;
1095
+ this.cid = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.cid;
1096
+ this.upvoteCount = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.upvoteCount;
1097
+ this.downvoteCount = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.downvoteCount;
1098
+ this.content = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.content;
1099
+ this.author = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.author;
1100
+ this.timestamp = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.timestamp;
1101
+ this.parentCid = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.parentCid;
1102
+ this.postCid = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.postCid;
1103
+ this.parentCid = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.parentCid;
1104
+ this.depth = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.depth;
1105
+ this.spoiler = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.spoiler;
1106
+ this.flair = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.flair;
1107
+ this.pinned = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.pinned;
1108
+ this.locked = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.locked;
1109
+ this.deleted = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.deleted;
1110
+ this.removed = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.removed;
1111
+ this.purged = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.purged;
1112
+ this.reason = createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.reason;
1113
+ this.replies = new Pages({ comment: this });
1114
+ if (this.cid) {
1115
+ this.shortCid = this.cid.substring(2, 14);
1116
+ }
1117
+ Object.defineProperty(this, "updating", { enumerable: false, writable: true });
1118
+ // @ts-ignore
1119
+ this.updating = false;
1120
+ // add missing props from createCommentOptions
1121
+ for (const prop in createCommentOptions) {
1122
+ // @ts-ignore
1123
+ this[prop] = createCommentOptions[prop];
1124
+ }
1125
+ // if the only argument is {cid}, it means the first update should use getComment()
1126
+ if ((createCommentOptions === null || createCommentOptions === void 0 ? void 0 : createCommentOptions.cid) && Object.keys(createCommentOptions).length === 1) {
1127
+ this._getCommentOnFirstUpdate = true;
1128
+ }
1129
+ if (this.communityAddress) {
1130
+ this.shortCommunityAddress = this.communityAddress.substring(0, 12);
1131
+ }
1132
+ }
1133
+ update() {
1134
+ return __awaiter(this, void 0, void 0, function* () {
1135
+ // don't update twice
1136
+ // @ts-ignore
1137
+ if (this.updating) {
1138
+ return;
1139
+ }
1140
+ // @ts-ignore
1141
+ this.updating = true;
1142
+ this.updatingState = "fetching-ipfs";
1143
+ this.emit("updatingstatechange", "fetching-ipfs");
1144
+ (() => __awaiter(this, void 0, void 0, function* () {
1145
+ while (this.updating) {
1146
+ yield simulateLoadingTime();
1147
+ yield simulateLoadingTime();
1148
+ yield simulateLoadingTime();
1149
+ if (!this.updating) {
1150
+ return;
1151
+ }
1152
+ this.simulateUpdateEvent();
1153
+ }
1154
+ }))();
1155
+ });
1156
+ }
1157
+ simulateUpdateEvent() {
1158
+ return __awaiter(this, void 0, void 0, function* () {
1159
+ if (!this.updating) {
1160
+ return;
1161
+ }
1162
+ assert(this.cid, `invalid comment.cid '${this.cid}' can't simulateUpdateEvent`);
1163
+ if (this._getCommentOnFirstUpdate) {
1164
+ return this.simulateGetCommentOnFirstUpdateEvent();
1165
+ }
1166
+ const commentUpdateContent = yield getCommentUpdateContent(this);
1167
+ for (const prop in commentUpdateContent) {
1168
+ // @ts-ignore
1169
+ this[prop] = commentUpdateContent[prop];
1170
+ }
1171
+ this.shortCid = this.cid.substring(2, 14);
1172
+ this.updatingState = "succeeded";
1173
+ this.emit("update", this);
1174
+ this.emit("updatingstatechange", "succeeded");
1175
+ });
1176
+ }
1177
+ simulateGetCommentOnFirstUpdateEvent() {
1178
+ return __awaiter(this, void 0, void 0, function* () {
1179
+ if (!this.updating) {
1180
+ return;
1181
+ }
1182
+ this._getCommentOnFirstUpdate = false;
1183
+ // @ts-ignore
1184
+ const comment = yield new PKC().getComment({ cid: this.cid });
1185
+ if (!this.updating) {
1186
+ return;
1187
+ }
1188
+ const props = JSON.parse(JSON.stringify(comment));
1189
+ for (const prop in props) {
1190
+ if (prop.startsWith("_")) {
1191
+ continue;
1192
+ }
1193
+ // @ts-ignore
1194
+ this[prop] = props[prop];
1195
+ }
1196
+ this.emit("update", this);
1197
+ });
1198
+ }
1199
+ }
1200
+ class Vote extends Publication {
1201
+ constructor(publishVoteOptions) {
1202
+ super();
1203
+ for (const prop in publishVoteOptions) {
1204
+ // @ts-ignore
1205
+ this[prop] = publishVoteOptions[prop];
1206
+ }
1207
+ }
1208
+ }
1209
+ class CommentEdit extends Publication {
1210
+ constructor(publishCommentEditOptions) {
1211
+ super();
1212
+ for (const prop in publishCommentEditOptions) {
1213
+ // @ts-ignore
1214
+ this[prop] = publishCommentEditOptions[prop];
1215
+ }
1216
+ }
1217
+ }
1218
+ class CommunityEdit extends Publication {
1219
+ }
1220
+ const createPkc = (...args) => __awaiter(void 0, void 0, void 0, function* () {
1221
+ return new PKC(...args);
1222
+ });
1223
+ createPkc.getShortAddress = (options) => {
1224
+ const address = options === null || options === void 0 ? void 0 : options.address;
1225
+ if (address.includes(".")) {
1226
+ return address;
1227
+ }
1228
+ return address.substring(0, 12);
1229
+ };
1230
+ createPkc.getShortCid = (options) => {
1231
+ const cid = options === null || options === void 0 ? void 0 : options.cid;
1232
+ return cid.substring(0, 12);
1233
+ };
1234
+ export default createPkc;
1235
+ //# sourceMappingURL=pkc-js-mock-content.js.map