holosphere 2.0.0-alpha8 → 2.0.0-alpha9

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 (321) hide show
  1. package/CHANGELOG.md +446 -0
  2. package/FEATURES.md +431 -0
  3. package/LICENSE +29 -166
  4. package/LICENSE-AGPL.md +180 -0
  5. package/dist/cdn/holosphere.min.js +55 -0
  6. package/dist/cdn/holosphere.min.js.map +1 -0
  7. package/dist/cjs/holosphere.cjs +1 -1
  8. package/dist/esm/holosphere.js +1 -1
  9. package/dist/{index-CKffQDmQ.cjs → index-DDGt_V9o.cjs} +2 -2
  10. package/dist/{index-CKffQDmQ.cjs.map → index-DDGt_V9o.cjs.map} +1 -1
  11. package/dist/{index-4XHHKe6S.js → index-DJXftyvB.js} +1905 -337
  12. package/dist/index-DJXftyvB.js.map +1 -0
  13. package/dist/{index-Dz5kOZMI.cjs → index-DMbdcMtK.cjs} +17 -4
  14. package/dist/index-DMbdcMtK.cjs.map +1 -0
  15. package/dist/{index-BjP1TXGz.js → index-DeZ1xz_s.js} +2 -2
  16. package/dist/{index-BjP1TXGz.js.map → index-DeZ1xz_s.js.map} +1 -1
  17. package/dist/{indexeddb-storage-lExjjFlV.js → indexeddb-storage-BFt6hMeF.js} +48 -4
  18. package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
  19. package/dist/{indexeddb-storage-DD7EFBVc.cjs → indexeddb-storage-BK5tv4Sh.cjs} +2 -2
  20. package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
  21. package/dist/{memory-storage-C68adso2.js → memory-storage-C9HuoL2E.js} +44 -4
  22. package/dist/memory-storage-C9HuoL2E.js.map +1 -0
  23. package/dist/{memory-storage-DD_6yyXT.cjs → memory-storage-Dao7jfYG.cjs} +2 -2
  24. package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
  25. package/dist/{secp256k1-DYELiqgx.cjs → secp256k1-BbKzbLtD.cjs} +2 -2
  26. package/dist/{secp256k1-DYELiqgx.cjs.map → secp256k1-BbKzbLtD.cjs.map} +1 -1
  27. package/dist/{secp256k1-OM8siPyy.js → secp256k1-CreY7Pcl.js} +2 -2
  28. package/dist/{secp256k1-OM8siPyy.js.map → secp256k1-CreY7Pcl.js.map} +1 -1
  29. package/docs/api/ai_aggregation.js.html +333 -0
  30. package/docs/api/ai_breakdown.js.html +524 -0
  31. package/docs/api/ai_classifier.js.html +231 -0
  32. package/docs/api/ai_council.js.html +246 -0
  33. package/docs/api/ai_embeddings.js.html +304 -0
  34. package/docs/api/ai_federation-ai.js.html +338 -0
  35. package/docs/api/ai_h3-ai.js.html +970 -0
  36. package/docs/api/ai_index.js.html +124 -0
  37. package/docs/api/ai_json-ops.js.html +241 -0
  38. package/docs/api/ai_llm-service.js.html +239 -0
  39. package/docs/api/ai_nl-query.js.html +236 -0
  40. package/docs/api/ai_relationships.js.html +367 -0
  41. package/docs/api/ai_schema-extractor.js.html +235 -0
  42. package/docs/api/ai_spatial.js.html +307 -0
  43. package/docs/api/ai_tts.js.html +214 -0
  44. package/docs/api/content_social-protocols.js.html +180 -0
  45. package/docs/api/core_holosphere.js.html +757 -0
  46. package/docs/api/crypto_nostr-utils.js.html +306 -0
  47. package/docs/api/crypto_secp256k1.js.html +267 -0
  48. package/docs/api/data/search.json +1 -0
  49. package/docs/api/federation_discovery.js.html +337 -0
  50. package/docs/api/federation_handshake.js.html +478 -0
  51. package/docs/api/federation_hologram.js.html +1053 -0
  52. package/docs/api/federation_registry.js.html +389 -0
  53. package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
  54. package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
  55. package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
  56. package/docs/api/global.html +3 -0
  57. package/docs/api/hierarchical_upcast.js.html +128 -0
  58. package/docs/api/index.html +265 -0
  59. package/docs/api/index.js.html +1868 -0
  60. package/docs/api/lib_ai-methods.js.html +660 -0
  61. package/docs/api/lib_contract-methods.js.html +445 -0
  62. package/docs/api/lib_errors.js.html +56 -0
  63. package/docs/api/lib_federation-methods.js.html +348 -0
  64. package/docs/api/lib_index.js.html +33 -0
  65. package/docs/api/module-ai.html +5 -0
  66. package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
  67. package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
  68. package/docs/api/module-ai_aggregation.html +3 -0
  69. package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
  70. package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
  71. package/docs/api/module-ai_breakdown.html +3 -0
  72. package/docs/api/module-ai_classifier-Classifier.html +6 -0
  73. package/docs/api/module-ai_classifier.Classifier.html +3 -0
  74. package/docs/api/module-ai_classifier.html +3 -0
  75. package/docs/api/module-ai_council-Council.html +6 -0
  76. package/docs/api/module-ai_council.Council.html +3 -0
  77. package/docs/api/module-ai_council.html +3 -0
  78. package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
  79. package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
  80. package/docs/api/module-ai_embeddings.html +3 -0
  81. package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
  82. package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
  83. package/docs/api/module-ai_federation-ai.html +3 -0
  84. package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
  85. package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
  86. package/docs/api/module-ai_h3-ai.html +3 -0
  87. package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
  88. package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
  89. package/docs/api/module-ai_json-ops.html +3 -0
  90. package/docs/api/module-ai_llm-service-LLMService.html +5 -0
  91. package/docs/api/module-ai_llm-service.LLMService.html +3 -0
  92. package/docs/api/module-ai_llm-service.html +3 -0
  93. package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
  94. package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
  95. package/docs/api/module-ai_nl-query.html +3 -0
  96. package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
  97. package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
  98. package/docs/api/module-ai_relationships.html +3 -0
  99. package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
  100. package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
  101. package/docs/api/module-ai_schema-extractor.html +3 -0
  102. package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
  103. package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
  104. package/docs/api/module-ai_spatial.html +3 -0
  105. package/docs/api/module-ai_tts-TTS.html +5 -0
  106. package/docs/api/module-ai_tts.TTS.html +3 -0
  107. package/docs/api/module-ai_tts.html +3 -0
  108. package/docs/api/module-content_social-protocols.html +3 -0
  109. package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
  110. package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
  111. package/docs/api/module-core_holosphere.html +3 -0
  112. package/docs/api/module-crypto_nostr-utils.html +3 -0
  113. package/docs/api/module-crypto_secp256k1.html +3 -0
  114. package/docs/api/module-federation_hologram.html +3 -0
  115. package/docs/api/module-hierarchical_upcast.html +3 -0
  116. package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
  117. package/docs/api/module-holosphere.html +3 -0
  118. package/docs/api/module-lib_ai-methods.html +3 -0
  119. package/docs/api/module-lib_contract-methods.html +3 -0
  120. package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
  121. package/docs/api/module-lib_errors-ValidationError.html +3 -0
  122. package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
  123. package/docs/api/module-lib_errors.ValidationError.html +3 -0
  124. package/docs/api/module-lib_errors.html +3 -0
  125. package/docs/api/module-lib_federation-methods.html +3 -0
  126. package/docs/api/module-lib_index.html +3 -0
  127. package/docs/api/module-schema_validator-ValidationError.html +3 -0
  128. package/docs/api/module-schema_validator.ValidationError.html +3 -0
  129. package/docs/api/module-schema_validator.html +3 -0
  130. package/docs/api/module-spatial_h3-operations.html +4 -0
  131. package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
  132. package/docs/api/module-storage_backend-factory.html +3 -0
  133. package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
  134. package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
  135. package/docs/api/module-storage_backend-interface.html +3 -0
  136. package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
  137. package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
  138. package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
  139. package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
  140. package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
  141. package/docs/api/module-storage_backends_activitypub_server.html +3 -0
  142. package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
  143. package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
  144. package/docs/api/module-storage_backends_gundb-backend.html +3 -0
  145. package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
  146. package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
  147. package/docs/api/module-storage_backends_nostr-backend.html +3 -0
  148. package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
  149. package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
  150. package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
  151. package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
  152. package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
  153. package/docs/api/module-storage_filesystem-storage.html +3 -0
  154. package/docs/api/module-storage_global-tables.html +3 -0
  155. package/docs/api/module-storage_gun-async.html +3 -0
  156. package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
  157. package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
  158. package/docs/api/module-storage_gun-auth.html +3 -0
  159. package/docs/api/module-storage_gun-federation.html +3 -0
  160. package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
  161. package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
  162. package/docs/api/module-storage_gun-references.html +3 -0
  163. package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
  164. package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
  165. package/docs/api/module-storage_gun-schema.html +3 -0
  166. package/docs/api/module-storage_gun-wrapper.html +11 -0
  167. package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
  168. package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
  169. package/docs/api/module-storage_indexeddb-storage.html +3 -0
  170. package/docs/api/module-storage_key-storage-simple.html +3 -0
  171. package/docs/api/module-storage_key-storage.html +4 -0
  172. package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
  173. package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
  174. package/docs/api/module-storage_memory-storage.html +3 -0
  175. package/docs/api/module-storage_migration-MigrationTool.html +6 -0
  176. package/docs/api/module-storage_migration.MigrationTool.html +3 -0
  177. package/docs/api/module-storage_migration.html +3 -0
  178. package/docs/api/module-storage_nostr-async.html +18 -0
  179. package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
  180. package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
  181. package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
  182. package/docs/api/module-storage_nostr-client.html +6 -0
  183. package/docs/api/module-storage_nostr-wrapper.html +3 -0
  184. package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
  185. package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
  186. package/docs/api/module-storage_outbox-queue.html +3 -0
  187. package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
  188. package/docs/api/module-storage_persistent-storage.html +4 -0
  189. package/docs/api/module-storage_sync-service-SyncService.html +5 -0
  190. package/docs/api/module-storage_sync-service.SyncService.html +3 -0
  191. package/docs/api/module-storage_sync-service.html +3 -0
  192. package/docs/api/module-storage_unified-storage.html +3 -0
  193. package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
  194. package/docs/api/module-subscriptions_manager.html +3 -0
  195. package/docs/api/schema_validator.js.html +113 -0
  196. package/docs/api/scripts/core.js +726 -0
  197. package/docs/api/scripts/core.min.js +23 -0
  198. package/docs/api/scripts/resize.js +90 -0
  199. package/docs/api/scripts/search.js +265 -0
  200. package/docs/api/scripts/search.min.js +6 -0
  201. package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
  202. package/docs/api/scripts/third-party/fuse.js +9 -0
  203. package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
  204. package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
  205. package/docs/api/scripts/third-party/hljs-original.js +5171 -0
  206. package/docs/api/scripts/third-party/hljs.js +1 -0
  207. package/docs/api/scripts/third-party/popper.js +5 -0
  208. package/docs/api/scripts/third-party/tippy.js +1 -0
  209. package/docs/api/scripts/third-party/tocbot.js +672 -0
  210. package/docs/api/scripts/third-party/tocbot.min.js +1 -0
  211. package/docs/api/spatial_h3-operations.js.html +129 -0
  212. package/docs/api/storage_backend-factory.js.html +133 -0
  213. package/docs/api/storage_backend-interface.js.html +164 -0
  214. package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
  215. package/docs/api/storage_backends_activitypub_server.js.html +678 -0
  216. package/docs/api/storage_backends_gundb-backend.js.html +878 -0
  217. package/docs/api/storage_backends_nostr-backend.js.html +254 -0
  218. package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
  219. package/docs/api/storage_filesystem-storage.js.html +207 -0
  220. package/docs/api/storage_global-tables.js.html +116 -0
  221. package/docs/api/storage_gun-async.js.html +344 -0
  222. package/docs/api/storage_gun-auth.js.html +376 -0
  223. package/docs/api/storage_gun-federation.js.html +788 -0
  224. package/docs/api/storage_gun-references.js.html +212 -0
  225. package/docs/api/storage_gun-schema.js.html +309 -0
  226. package/docs/api/storage_gun-wrapper.js.html +645 -0
  227. package/docs/api/storage_indexeddb-storage.js.html +224 -0
  228. package/docs/api/storage_key-storage-simple.js.html +102 -0
  229. package/docs/api/storage_key-storage.js.html +171 -0
  230. package/docs/api/storage_memory-storage.js.html +128 -0
  231. package/docs/api/storage_migration.js.html +354 -0
  232. package/docs/api/storage_nostr-async.js.html +1076 -0
  233. package/docs/api/storage_nostr-client.js.html +1598 -0
  234. package/docs/api/storage_nostr-wrapper.js.html +218 -0
  235. package/docs/api/storage_outbox-queue.js.html +248 -0
  236. package/docs/api/storage_persistent-storage.js.html +160 -0
  237. package/docs/api/storage_sync-service.js.html +201 -0
  238. package/docs/api/storage_unified-storage.js.html +157 -0
  239. package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
  240. package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
  241. package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
  242. package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  243. package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  244. package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
  245. package/docs/api/subscriptions_manager.js.html +162 -0
  246. package/jsdoc.json +26 -0
  247. package/package.json +14 -3
  248. package/src/ai/aggregation.js +13 -2
  249. package/src/ai/breakdown.js +12 -2
  250. package/src/ai/classifier.js +14 -3
  251. package/src/ai/council.js +22 -7
  252. package/src/ai/embeddings.js +37 -15
  253. package/src/ai/federation-ai.js +13 -2
  254. package/src/ai/h3-ai.js +14 -2
  255. package/src/ai/index.js +16 -7
  256. package/src/ai/json-ops.js +18 -5
  257. package/src/ai/llm-service.js +62 -31
  258. package/src/ai/nl-query.js +12 -2
  259. package/src/ai/relationships.js +13 -2
  260. package/src/ai/schema-extractor.js +24 -10
  261. package/src/ai/spatial.js +13 -2
  262. package/src/ai/tts.js +25 -8
  263. package/src/content/social-protocols.js +34 -25
  264. package/src/contracts/chain-manager.js +68 -40
  265. package/src/contracts/deployer.js +70 -42
  266. package/src/contracts/event-listener.js +61 -29
  267. package/src/contracts/holon-contracts.js +46 -31
  268. package/src/contracts/index.js +5 -6
  269. package/src/contracts/networks.js +19 -14
  270. package/src/contracts/operations.js +58 -41
  271. package/src/contracts/queries.js +54 -20
  272. package/src/core/holosphere.js +35 -6
  273. package/src/crypto/nostr-utils.js +82 -76
  274. package/src/crypto/secp256k1.js +7 -2
  275. package/src/federation/handshake.js +7 -7
  276. package/src/federation/hologram.js +9 -1
  277. package/src/hierarchical/upcast.js +34 -20
  278. package/src/index.js +655 -5
  279. package/src/lib/ai-methods.js +352 -3
  280. package/src/lib/contract-methods.js +152 -3
  281. package/src/lib/errors.js +31 -1
  282. package/src/lib/federation-methods.js +110 -3
  283. package/src/lib/index.js +9 -5
  284. package/src/schema/validator.js +22 -3
  285. package/src/spatial/h3-operations.js +17 -1
  286. package/src/storage/backend-factory.js +7 -2
  287. package/src/storage/backend-interface.js +21 -2
  288. package/src/storage/backends/activitypub/server.js +25 -3
  289. package/src/storage/backends/activitypub-backend.js +25 -2
  290. package/src/storage/backends/gundb-backend.js +29 -2
  291. package/src/storage/backends/nostr-backend.js +116 -1
  292. package/src/storage/filesystem-storage-browser.js +42 -2
  293. package/src/storage/filesystem-storage.js +72 -5
  294. package/src/storage/global-tables.js +7 -2
  295. package/src/storage/gun-async.js +20 -11
  296. package/src/storage/gun-auth.js +15 -4
  297. package/src/storage/gun-federation.js +14 -5
  298. package/src/storage/gun-references.js +16 -5
  299. package/src/storage/gun-schema.js +25 -10
  300. package/src/storage/gun-wrapper.js +99 -36
  301. package/src/storage/indexeddb-storage.js +65 -4
  302. package/src/storage/key-storage-simple.js +32 -9
  303. package/src/storage/key-storage.js +45 -13
  304. package/src/storage/memory-storage.js +65 -4
  305. package/src/storage/migration.js +20 -7
  306. package/src/storage/nostr-async.js +157 -67
  307. package/src/storage/nostr-client.js +173 -49
  308. package/src/storage/nostr-wrapper.js +6 -2
  309. package/src/storage/outbox-queue.js +55 -18
  310. package/src/storage/persistent-storage.js +56 -13
  311. package/src/storage/sync-service.js +51 -17
  312. package/src/storage/unified-storage.js +7 -2
  313. package/src/subscriptions/manager.js +33 -16
  314. package/dist/index-4XHHKe6S.js.map +0 -1
  315. package/dist/index-Dz5kOZMI.cjs.map +0 -1
  316. package/dist/indexeddb-storage-DD7EFBVc.cjs.map +0 -1
  317. package/dist/indexeddb-storage-lExjjFlV.js.map +0 -1
  318. package/dist/memory-storage-C68adso2.js.map +0 -1
  319. package/dist/memory-storage-DD_6yyXT.cjs.map +0 -1
  320. /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
  321. /package/{test-ai-real-api.js → scripts/test-ai-real-api.js} +0 -0
@@ -1,9 +1,21 @@
1
1
  /**
2
- * ContractOperations - All contract functions exposed with clear parameters
3
- * Provides a unified interface for interacting with all Holosphere contract types
2
+ * @fileoverview Unified operations interface for all Holosphere contract types.
3
+ * Provides a clean API for member management, fund distribution, and contract-specific operations.
4
+ * @module contracts/operations
4
5
  */
5
6
 
7
+ /**
8
+ * Provides a unified interface for interacting with all Holosphere contract types.
9
+ * Wraps contract functions with clear parameters and type checking.
10
+ * @class
11
+ */
6
12
  export class ContractOperations {
13
+ /**
14
+ * Create a new ContractOperations instance.
15
+ * @param {Object} contract - Ethers.js Contract instance
16
+ * @param {string} type - Contract type (Splitter, Managed, Zoned, Appreciative, Bundle)
17
+ * @param {ChainManager} chainManager - Chain manager instance
18
+ */
7
19
  constructor(contract, type, chainManager) {
8
20
  this.contract = contract;
9
21
  this.type = type;
@@ -12,8 +24,9 @@ export class ContractOperations {
12
24
  }
13
25
 
14
26
  /**
15
- * Load ethers dynamically
27
+ * Load ethers.js library dynamically.
16
28
  * @private
29
+ * @returns {Promise<Object>} Ethers.js module
17
30
  */
18
31
  async _loadEthers() {
19
32
  if (!this.ethers) {
@@ -27,9 +40,9 @@ export class ContractOperations {
27
40
  // ========================================================================
28
41
 
29
42
  /**
30
- * Add a single member to the contract
43
+ * Add a single member to the contract.
31
44
  * @param {string} userId - User identifier (string-based, e.g., 'alice', 'telegram_12345')
32
- * @returns {Promise<{txHash, receipt}>}
45
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
33
46
  */
34
47
  async addMember(userId) {
35
48
  const tx = await this.contract.addMember(userId);
@@ -38,9 +51,9 @@ export class ContractOperations {
38
51
  }
39
52
 
40
53
  /**
41
- * Add multiple members at once (batch operation)
54
+ * Add multiple members at once (batch operation).
42
55
  * @param {string[]} userIds - Array of user identifiers
43
- * @returns {Promise<{txHash, receipt}>}
56
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
44
57
  */
45
58
  async addMembers(userIds) {
46
59
  const tx = await this.contract.addMembers(userIds);
@@ -49,8 +62,8 @@ export class ContractOperations {
49
62
  }
50
63
 
51
64
  /**
52
- * Get all member user IDs
53
- * @returns {Promise<string[]>}
65
+ * Get all member user IDs.
66
+ * @returns {Promise<string[]>} Array of user IDs
54
67
  */
55
68
  async getMembers() {
56
69
  const userIds = await this.contract.userIds();
@@ -75,9 +88,9 @@ export class ContractOperations {
75
88
  }
76
89
 
77
90
  /**
78
- * Check if a user is a member
91
+ * Check if a user is a member.
79
92
  * @param {string} userId - User identifier
80
- * @returns {Promise<boolean>}
93
+ * @returns {Promise<boolean>} True if user is a member
81
94
  */
82
95
  async isMember(userId) {
83
96
  try {
@@ -92,7 +105,7 @@ export class ContractOperations {
92
105
  }
93
106
 
94
107
  /**
95
- * Get the address associated with a user ID
108
+ * Get the Ethereum address associated with a user ID.
96
109
  * @param {string} userId - User identifier
97
110
  * @returns {Promise<string>} Ethereum address (or zero address if not set)
98
111
  */
@@ -105,10 +118,10 @@ export class ContractOperations {
105
118
  // ========================================================================
106
119
 
107
120
  /**
108
- * Trigger reward distribution for ERC20 tokens
121
+ * Trigger reward distribution for ERC20 tokens.
109
122
  * @param {string} tokenAddress - ERC20 token contract address
110
123
  * @param {string|bigint} amount - Amount in wei (or token's smallest unit)
111
- * @returns {Promise<{txHash, receipt}>}
124
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
112
125
  */
113
126
  async reward(tokenAddress, amount) {
114
127
  const ethers = await this._loadEthers();
@@ -119,9 +132,9 @@ export class ContractOperations {
119
132
  }
120
133
 
121
134
  /**
122
- * Trigger reward distribution for ETH
135
+ * Trigger reward distribution for ETH.
123
136
  * @param {string} amount - Amount in ETH (e.g., '1.5' for 1.5 ETH)
124
- * @returns {Promise<{txHash, receipt}>}
137
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
125
138
  */
126
139
  async rewardEth(amount) {
127
140
  const ethers = await this._loadEthers();
@@ -136,9 +149,9 @@ export class ContractOperations {
136
149
  }
137
150
 
138
151
  /**
139
- * Send ETH directly to contract (triggers receive/fallback)
152
+ * Send ETH directly to contract (triggers receive/fallback).
140
153
  * @param {string} amount - Amount in ETH
141
- * @returns {Promise<{txHash, receipt}>}
154
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
142
155
  */
143
156
  async sendEth(amount) {
144
157
  const ethers = await this._loadEthers();
@@ -153,10 +166,10 @@ export class ContractOperations {
153
166
  }
154
167
 
155
168
  /**
156
- * Claim accumulated rewards for a user
169
+ * Claim accumulated rewards for a user.
157
170
  * @param {string} userId - User identifier
158
171
  * @param {string} beneficiaryAddress - Ethereum address to receive funds
159
- * @returns {Promise<{txHash, receipt}>}
172
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
160
173
  */
161
174
  async claim(userId, beneficiaryAddress) {
162
175
  const tx = await this.contract.claim(userId, beneficiaryAddress);
@@ -165,9 +178,9 @@ export class ContractOperations {
165
178
  }
166
179
 
167
180
  /**
168
- * Get ETH balance for a user
181
+ * Get ETH balance for a user.
169
182
  * @param {string} userId - User identifier
170
- * @returns {Promise<string>} Balance in ETH
183
+ * @returns {Promise<string>} Balance in ETH as decimal string
171
184
  */
172
185
  async getEthBalance(userId) {
173
186
  const ethers = await this._loadEthers();
@@ -176,10 +189,10 @@ export class ContractOperations {
176
189
  }
177
190
 
178
191
  /**
179
- * Get ERC20 token balance for a user
192
+ * Get ERC20 token balance for a user.
180
193
  * @param {string} userId - User identifier
181
194
  * @param {string} tokenAddress - ERC20 token address
182
- * @returns {Promise<string>} Balance in tokens (18 decimals assumed)
195
+ * @returns {Promise<string>} Balance in tokens (18 decimals assumed) as decimal string
183
196
  */
184
197
  async getTokenBalance(userId, tokenAddress) {
185
198
  const ethers = await this._loadEthers();
@@ -188,18 +201,18 @@ export class ContractOperations {
188
201
  }
189
202
 
190
203
  /**
191
- * Check if user has already claimed
204
+ * Check if user has already claimed rewards.
192
205
  * @param {string} userId - User identifier
193
- * @returns {Promise<boolean>}
206
+ * @returns {Promise<boolean>} True if user has claimed
194
207
  */
195
208
  async hasClaimed(userId) {
196
209
  return this.contract.hasClaimed(userId);
197
210
  }
198
211
 
199
212
  /**
200
- * Get total deposited amount for a token
213
+ * Get total deposited amount for a token.
201
214
  * @param {string} tokenAddress - Token address (use zero address for ETH)
202
- * @returns {Promise<string>}
215
+ * @returns {Promise<string>} Total deposited as decimal string
203
216
  */
204
217
  async getTotalDeposited(tokenAddress) {
205
218
  const ethers = await this._loadEthers();
@@ -212,10 +225,11 @@ export class ContractOperations {
212
225
  // ========================================================================
213
226
 
214
227
  /**
215
- * Set the internal/external split percentages (Splitter only)
228
+ * Set the internal/external split percentages (Splitter only).
216
229
  * @param {number} internalPct - Internal percentage (0-100)
217
230
  * @param {number} externalPct - External percentage (0-100, must sum to 100 with internal)
218
- * @returns {Promise<{txHash, receipt}>}
231
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
232
+ * @throws {Error} If percentages don't sum to 100 or not a Splitter contract
219
233
  */
220
234
  async setContractSplit(internalPct, externalPct) {
221
235
  this._requireType(['Splitter']);
@@ -228,8 +242,9 @@ export class ContractOperations {
228
242
  }
229
243
 
230
244
  /**
231
- * Get current split percentages (Splitter only)
232
- * @returns {Promise<{internal: number, external: number}>}
245
+ * Get current split percentages (Splitter only).
246
+ * @returns {Promise<{internal: number, external: number}>} Split percentages
247
+ * @throws {Error} If not a Splitter contract
233
248
  */
234
249
  async getContractSplit() {
235
250
  this._requireType(['Splitter']);
@@ -627,8 +642,10 @@ export class ContractOperations {
627
642
  // ========================================================================
628
643
 
629
644
  /**
630
- * Require specific contract type(s)
645
+ * Require specific contract type(s).
631
646
  * @private
647
+ * @param {string[]} allowedTypes - Array of allowed contract types
648
+ * @throws {Error} If contract type doesn't match
632
649
  */
633
650
  _requireType(allowedTypes) {
634
651
  if (!allowedTypes.includes(this.type)) {
@@ -637,28 +654,28 @@ export class ContractOperations {
637
654
  }
638
655
 
639
656
  /**
640
- * Get raw contract instance for advanced usage
641
- * @returns {Contract}
657
+ * Get raw contract instance for advanced usage.
658
+ * @returns {Object} Ethers.js Contract instance
642
659
  */
643
660
  getRawContract() {
644
661
  return this.contract;
645
662
  }
646
663
 
647
664
  /**
648
- * Execute a raw contract call
665
+ * Execute a raw contract call.
649
666
  * @param {string} method - Method name
650
- * @param {Array} args - Method arguments
651
- * @returns {Promise<any>}
667
+ * @param {...*} args - Method arguments
668
+ * @returns {Promise<*>} Method return value
652
669
  */
653
670
  async call(method, ...args) {
654
671
  return this.contract[method](...args);
655
672
  }
656
673
 
657
674
  /**
658
- * Execute a raw contract transaction
675
+ * Execute a raw contract transaction.
659
676
  * @param {string} method - Method name
660
- * @param {Array} args - Method arguments
661
- * @returns {Promise<{txHash, receipt}>}
677
+ * @param {...*} args - Method arguments
678
+ * @returns {Promise<{txHash: string, receipt: Object}>} Transaction details
662
679
  */
663
680
  async send(method, ...args) {
664
681
  const tx = await this.contract[method](...args);
@@ -1,8 +1,7 @@
1
1
  /**
2
- * Contract Query Utilities
3
- *
4
- * Utility kit for directly querying contract state:
5
- * zones, splits, appreciation, members, balances, etc.
2
+ * @fileoverview Contract query utilities for reading contract state.
3
+ * Provides read-only queries for zones, splits, appreciation, members, balances, and more.
4
+ * @module contracts/queries
6
5
  */
7
6
 
8
7
  import { ethers } from 'ethers';
@@ -24,35 +23,45 @@ const ContractABIs = {
24
23
  };
25
24
 
26
25
  /**
27
- * Helper to format wei to ETH
26
+ * Helper to format wei to ETH.
27
+ * @private
28
+ * @param {bigint} wei - Wei amount
29
+ * @returns {string} ETH as decimal string
28
30
  */
29
31
  function formatEth(wei) {
30
32
  return ethers.formatEther(wei);
31
33
  }
32
34
 
33
35
  /**
34
- * Helper to format wei to ETH as number
36
+ * Helper to format wei to ETH as number.
37
+ * @private
38
+ * @param {bigint} wei - Wei amount
39
+ * @returns {number} ETH as number
35
40
  */
36
41
  function formatEthNumber(wei) {
37
42
  return Number(ethers.formatEther(wei));
38
43
  }
39
44
 
40
45
  /**
41
- * ContractQueries - Query utilities for all contract types
46
+ * Query utilities for all Holosphere contract types.
47
+ * Provides read-only access to contract state without requiring a signer.
48
+ * @class
42
49
  */
43
50
  export class ContractQueries {
44
51
  /**
45
- * @param {ethers.Provider} provider - ethers.js provider
52
+ * Create a new ContractQueries instance.
53
+ * @param {Object} provider - Ethers.js provider instance
46
54
  */
47
55
  constructor(provider) {
48
56
  this.provider = provider;
49
57
  }
50
58
 
51
59
  /**
52
- * Get a contract instance with the appropriate ABI
60
+ * Get a contract instance with the appropriate ABI.
53
61
  * @param {string} address - Contract address
54
- * @param {string} flavor - Contract flavor (Splitter, Managed, Zoned, Appreciative, Bundle)
55
- * @returns {ethers.Contract}
62
+ * @param {string} flavor - Contract flavor (Splitter, Managed, Zoned, Appreciative, Bundle, Holons)
63
+ * @returns {Object} Ethers.js Contract instance
64
+ * @throws {Error} If unknown contract flavor
56
65
  */
57
66
  getContract(address, flavor) {
58
67
  const abi = ContractABIs[flavor];
@@ -63,9 +72,9 @@ export class ContractQueries {
63
72
  }
64
73
 
65
74
  /**
66
- * Auto-detect contract flavor by calling flavor()
75
+ * Auto-detect contract flavor by calling flavor() method.
67
76
  * @param {string} address - Contract address
68
- * @returns {Promise<string>} Contract flavor
77
+ * @returns {Promise<string>} Contract flavor or 'Unknown'
69
78
  */
70
79
  async detectFlavor(address) {
71
80
  // Try with a minimal ABI that has flavor()
@@ -84,7 +93,10 @@ export class ContractQueries {
84
93
  // ==================== COMMON QUERIES ====================
85
94
 
86
95
  /**
87
- * Get basic contract info
96
+ * Get basic contract information.
97
+ * @param {string} address - Contract address
98
+ * @param {string} flavor - Contract flavor
99
+ * @returns {Promise<{address: string, name: string, flavor: string, version: string, creator: string, memberCount: number}>} Contract info
88
100
  */
89
101
  async getContractInfo(address, flavor) {
90
102
  const contract = this.getContract(address, flavor);
@@ -107,7 +119,10 @@ export class ContractQueries {
107
119
  }
108
120
 
109
121
  /**
110
- * Get all members (userIds)
122
+ * Get all member user IDs.
123
+ * @param {string} address - Contract address
124
+ * @param {string} flavor - Contract flavor
125
+ * @returns {Promise<string[]>} Array of user IDs
111
126
  */
112
127
  async getMembers(address, flavor) {
113
128
  const contract = this.getContract(address, flavor);
@@ -121,7 +136,11 @@ export class ContractQueries {
121
136
  }
122
137
 
123
138
  /**
124
- * Get user's ETH balance
139
+ * Get user's ETH balance in the contract.
140
+ * @param {string} address - Contract address
141
+ * @param {string} flavor - Contract flavor
142
+ * @param {string} userId - User identifier
143
+ * @returns {Promise<{wei: string, eth: number}>} Balance in wei and ETH
125
144
  */
126
145
  async getUserEthBalance(address, flavor, userId) {
127
146
  const contract = this.getContract(address, flavor);
@@ -133,7 +152,12 @@ export class ContractQueries {
133
152
  }
134
153
 
135
154
  /**
136
- * Get user's token balance
155
+ * Get user's ERC20 token balance in the contract.
156
+ * @param {string} address - Contract address
157
+ * @param {string} flavor - Contract flavor
158
+ * @param {string} userId - User identifier
159
+ * @param {string} tokenAddress - ERC20 token address
160
+ * @returns {Promise<{wei: string, formatted: number}>} Token balance
137
161
  */
138
162
  async getUserTokenBalance(address, flavor, userId, tokenAddress) {
139
163
  const contract = this.getContract(address, flavor);
@@ -145,7 +169,11 @@ export class ContractQueries {
145
169
  }
146
170
 
147
171
  /**
148
- * Get total deposited for a token
172
+ * Get total deposited amount for a token.
173
+ * @param {string} address - Contract address
174
+ * @param {string} flavor - Contract flavor
175
+ * @param {string} [tokenAddress] - Token address (defaults to ETH/zero address)
176
+ * @returns {Promise<{wei: string, formatted: number}>} Total deposited
149
177
  */
150
178
  async getTotalDeposited(address, flavor, tokenAddress) {
151
179
  const contract = this.getContract(address, flavor);
@@ -159,7 +187,11 @@ export class ContractQueries {
159
187
  }
160
188
 
161
189
  /**
162
- * Check if user has claimed
190
+ * Check if user has claimed their rewards.
191
+ * @param {string} address - Contract address
192
+ * @param {string} flavor - Contract flavor
193
+ * @param {string} userId - User identifier
194
+ * @returns {Promise<boolean>} True if claimed
163
195
  */
164
196
  async hasClaimed(address, flavor, userId) {
165
197
  const contract = this.getContract(address, flavor);
@@ -539,7 +571,9 @@ export class ContractQueries {
539
571
  // ==================== FULL SNAPSHOT ====================
540
572
 
541
573
  /**
542
- * Get complete contract state snapshot
574
+ * Get complete contract state snapshot including all members and configuration.
575
+ * @param {string} address - Contract address
576
+ * @returns {Promise<Object>} Complete contract state
543
577
  */
544
578
  async getFullSnapshot(address) {
545
579
  const flavor = await this.detectFlavor(address);
@@ -1,3 +1,14 @@
1
+ /**
2
+ * @fileoverview Core HoloSphere class providing the foundational infrastructure
3
+ * for holonic geospatial communication.
4
+ *
5
+ * This module implements the core HoloSphere class that supports multiple storage
6
+ * backends (Nostr, GunDB, ActivityPub) and provides essential operations for
7
+ * distributed P2P communication and data management.
8
+ *
9
+ * @module core/holosphere
10
+ */
11
+
1
12
  import { createClient } from '../storage/nostr-client.js';
2
13
  import { BackendFactory } from '../storage/backend-factory.js';
3
14
  import * as gunWrapper from '../storage/gun-wrapper.js';
@@ -5,12 +16,16 @@ import * as gunFederation from '../storage/gun-federation.js';
5
16
  import { GunDBBackend } from '../storage/backends/gundb-backend.js';
6
17
  import pkg from '../../package.json' with { type: 'json' };
7
18
 
8
- // Gun will be loaded dynamically when needed
19
+ /** @type {Function|null} Gun constructor, loaded dynamically */
9
20
  let Gun = null;
21
+ /** @type {Promise<Function>|null} Promise for Gun loading */
10
22
  let gunLoadPromise = null;
11
23
 
12
24
  /**
13
- * Load Gun module dynamically
25
+ * Dynamically loads the Gun module.
26
+ * Uses lazy loading to reduce initial bundle size and improve startup time.
27
+ *
28
+ * @private
14
29
  * @returns {Promise<Function>} Gun constructor
15
30
  */
16
31
  async function loadGun() {
@@ -50,9 +65,20 @@ function getDefaultRelays() {
50
65
  }
51
66
 
52
67
  /**
53
- * HoloSphere - Holonic Geospatial Communication Infrastructure
54
- * Combines H3 hexagonal indexing with distributed P2P storage
55
- * Supports multiple storage backends: nostr, gundb, activitypub
68
+ * HoloSphere - Holonic Geospatial Communication Infrastructure.
69
+ *
70
+ * The core class that combines H3 hexagonal indexing with distributed P2P storage.
71
+ * Supports multiple storage backends including Nostr, GunDB, and ActivityPub.
72
+ *
73
+ * @class HoloSphere
74
+ * @example
75
+ * // Create with Nostr backend (default)
76
+ * const hs = new HoloSphere({ appName: 'myapp', relays: ['wss://relay.example.com'] });
77
+ *
78
+ * @example
79
+ * // Create with GunDB backend
80
+ * const hs = new HoloSphere({ appName: 'myapp', backend: 'gundb' });
81
+ * await hs.ready(); // Wait for async initialization
56
82
  */
57
83
  export class HoloSphere {
58
84
  /**
@@ -712,7 +738,10 @@ export class HoloSphere {
712
738
  // ============================================================================
713
739
 
714
740
  /**
715
- * Close the backend and clean up resources
741
+ * Closes the backend and cleans up resources.
742
+ * Should be called when done using the HoloSphere instance.
743
+ *
744
+ * @returns {void}
716
745
  */
717
746
  close() {
718
747
  if (this._backend) {