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.
- package/CHANGELOG.md +446 -0
- package/FEATURES.md +431 -0
- package/LICENSE +29 -166
- package/LICENSE-AGPL.md +180 -0
- package/dist/cdn/holosphere.min.js +55 -0
- package/dist/cdn/holosphere.min.js.map +1 -0
- package/dist/cjs/holosphere.cjs +1 -1
- package/dist/esm/holosphere.js +1 -1
- package/dist/{index-CKffQDmQ.cjs → index-DDGt_V9o.cjs} +2 -2
- package/dist/{index-CKffQDmQ.cjs.map → index-DDGt_V9o.cjs.map} +1 -1
- package/dist/{index-4XHHKe6S.js → index-DJXftyvB.js} +1905 -337
- package/dist/index-DJXftyvB.js.map +1 -0
- package/dist/{index-Dz5kOZMI.cjs → index-DMbdcMtK.cjs} +17 -4
- package/dist/index-DMbdcMtK.cjs.map +1 -0
- package/dist/{index-BjP1TXGz.js → index-DeZ1xz_s.js} +2 -2
- package/dist/{index-BjP1TXGz.js.map → index-DeZ1xz_s.js.map} +1 -1
- package/dist/{indexeddb-storage-lExjjFlV.js → indexeddb-storage-BFt6hMeF.js} +48 -4
- package/dist/indexeddb-storage-BFt6hMeF.js.map +1 -0
- package/dist/{indexeddb-storage-DD7EFBVc.cjs → indexeddb-storage-BK5tv4Sh.cjs} +2 -2
- package/dist/indexeddb-storage-BK5tv4Sh.cjs.map +1 -0
- package/dist/{memory-storage-C68adso2.js → memory-storage-C9HuoL2E.js} +44 -4
- package/dist/memory-storage-C9HuoL2E.js.map +1 -0
- package/dist/{memory-storage-DD_6yyXT.cjs → memory-storage-Dao7jfYG.cjs} +2 -2
- package/dist/memory-storage-Dao7jfYG.cjs.map +1 -0
- package/dist/{secp256k1-DYELiqgx.cjs → secp256k1-BbKzbLtD.cjs} +2 -2
- package/dist/{secp256k1-DYELiqgx.cjs.map → secp256k1-BbKzbLtD.cjs.map} +1 -1
- package/dist/{secp256k1-OM8siPyy.js → secp256k1-CreY7Pcl.js} +2 -2
- package/dist/{secp256k1-OM8siPyy.js.map → secp256k1-CreY7Pcl.js.map} +1 -1
- package/docs/api/ai_aggregation.js.html +333 -0
- package/docs/api/ai_breakdown.js.html +524 -0
- package/docs/api/ai_classifier.js.html +231 -0
- package/docs/api/ai_council.js.html +246 -0
- package/docs/api/ai_embeddings.js.html +304 -0
- package/docs/api/ai_federation-ai.js.html +338 -0
- package/docs/api/ai_h3-ai.js.html +970 -0
- package/docs/api/ai_index.js.html +124 -0
- package/docs/api/ai_json-ops.js.html +241 -0
- package/docs/api/ai_llm-service.js.html +239 -0
- package/docs/api/ai_nl-query.js.html +236 -0
- package/docs/api/ai_relationships.js.html +367 -0
- package/docs/api/ai_schema-extractor.js.html +235 -0
- package/docs/api/ai_spatial.js.html +307 -0
- package/docs/api/ai_tts.js.html +214 -0
- package/docs/api/content_social-protocols.js.html +180 -0
- package/docs/api/core_holosphere.js.html +757 -0
- package/docs/api/crypto_nostr-utils.js.html +306 -0
- package/docs/api/crypto_secp256k1.js.html +267 -0
- package/docs/api/data/search.json +1 -0
- package/docs/api/federation_discovery.js.html +337 -0
- package/docs/api/federation_handshake.js.html +478 -0
- package/docs/api/federation_hologram.js.html +1053 -0
- package/docs/api/federation_registry.js.html +389 -0
- package/docs/api/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/api/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/api/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/api/global.html +3 -0
- package/docs/api/hierarchical_upcast.js.html +128 -0
- package/docs/api/index.html +265 -0
- package/docs/api/index.js.html +1868 -0
- package/docs/api/lib_ai-methods.js.html +660 -0
- package/docs/api/lib_contract-methods.js.html +445 -0
- package/docs/api/lib_errors.js.html +56 -0
- package/docs/api/lib_federation-methods.js.html +348 -0
- package/docs/api/lib_index.js.html +33 -0
- package/docs/api/module-ai.html +5 -0
- package/docs/api/module-ai_aggregation-SmartAggregation.html +6 -0
- package/docs/api/module-ai_aggregation.SmartAggregation.html +3 -0
- package/docs/api/module-ai_aggregation.html +3 -0
- package/docs/api/module-ai_breakdown-TaskBreakdown.html +5 -0
- package/docs/api/module-ai_breakdown.TaskBreakdown.html +3 -0
- package/docs/api/module-ai_breakdown.html +3 -0
- package/docs/api/module-ai_classifier-Classifier.html +6 -0
- package/docs/api/module-ai_classifier.Classifier.html +3 -0
- package/docs/api/module-ai_classifier.html +3 -0
- package/docs/api/module-ai_council-Council.html +6 -0
- package/docs/api/module-ai_council.Council.html +3 -0
- package/docs/api/module-ai_council.html +3 -0
- package/docs/api/module-ai_embeddings-Embeddings.html +5 -0
- package/docs/api/module-ai_embeddings.Embeddings.html +3 -0
- package/docs/api/module-ai_embeddings.html +3 -0
- package/docs/api/module-ai_federation-ai-FederationAdvisor.html +6 -0
- package/docs/api/module-ai_federation-ai.FederationAdvisor.html +3 -0
- package/docs/api/module-ai_federation-ai.html +3 -0
- package/docs/api/module-ai_h3-ai-H3AI.html +6 -0
- package/docs/api/module-ai_h3-ai.H3AI.html +3 -0
- package/docs/api/module-ai_h3-ai.html +3 -0
- package/docs/api/module-ai_json-ops-JSONOps.html +5 -0
- package/docs/api/module-ai_json-ops.JSONOps.html +3 -0
- package/docs/api/module-ai_json-ops.html +3 -0
- package/docs/api/module-ai_llm-service-LLMService.html +5 -0
- package/docs/api/module-ai_llm-service.LLMService.html +3 -0
- package/docs/api/module-ai_llm-service.html +3 -0
- package/docs/api/module-ai_nl-query-NLQuery.html +5 -0
- package/docs/api/module-ai_nl-query.NLQuery.html +3 -0
- package/docs/api/module-ai_nl-query.html +3 -0
- package/docs/api/module-ai_relationships-RelationshipDiscovery.html +6 -0
- package/docs/api/module-ai_relationships.RelationshipDiscovery.html +3 -0
- package/docs/api/module-ai_relationships.html +3 -0
- package/docs/api/module-ai_schema-extractor-SchemaExtractor.html +5 -0
- package/docs/api/module-ai_schema-extractor.SchemaExtractor.html +3 -0
- package/docs/api/module-ai_schema-extractor.html +3 -0
- package/docs/api/module-ai_spatial-SpatialAnalysis.html +6 -0
- package/docs/api/module-ai_spatial.SpatialAnalysis.html +3 -0
- package/docs/api/module-ai_spatial.html +3 -0
- package/docs/api/module-ai_tts-TTS.html +5 -0
- package/docs/api/module-ai_tts.TTS.html +3 -0
- package/docs/api/module-ai_tts.html +3 -0
- package/docs/api/module-content_social-protocols.html +3 -0
- package/docs/api/module-core_holosphere-HoloSphere.html +6 -0
- package/docs/api/module-core_holosphere.HoloSphere.html +3 -0
- package/docs/api/module-core_holosphere.html +3 -0
- package/docs/api/module-crypto_nostr-utils.html +3 -0
- package/docs/api/module-crypto_secp256k1.html +3 -0
- package/docs/api/module-federation_hologram.html +3 -0
- package/docs/api/module-hierarchical_upcast.html +3 -0
- package/docs/api/module-holosphere-HoloSphereBase.html +3 -0
- package/docs/api/module-holosphere.html +3 -0
- package/docs/api/module-lib_ai-methods.html +3 -0
- package/docs/api/module-lib_contract-methods.html +3 -0
- package/docs/api/module-lib_errors-AuthorizationError.html +3 -0
- package/docs/api/module-lib_errors-ValidationError.html +3 -0
- package/docs/api/module-lib_errors.AuthorizationError.html +3 -0
- package/docs/api/module-lib_errors.ValidationError.html +3 -0
- package/docs/api/module-lib_errors.html +3 -0
- package/docs/api/module-lib_federation-methods.html +3 -0
- package/docs/api/module-lib_index.html +3 -0
- package/docs/api/module-schema_validator-ValidationError.html +3 -0
- package/docs/api/module-schema_validator.ValidationError.html +3 -0
- package/docs/api/module-schema_validator.html +3 -0
- package/docs/api/module-spatial_h3-operations.html +4 -0
- package/docs/api/module-storage_backend-factory.BackendFactory.html +3 -0
- package/docs/api/module-storage_backend-factory.html +3 -0
- package/docs/api/module-storage_backend-interface-StorageBackend.html +3 -0
- package/docs/api/module-storage_backend-interface.StorageBackend.html +3 -0
- package/docs/api/module-storage_backend-interface.html +3 -0
- package/docs/api/module-storage_backends_activitypub-backend-ActivityPubBackend.html +7 -0
- package/docs/api/module-storage_backends_activitypub-backend.ActivityPubBackend.html +3 -0
- package/docs/api/module-storage_backends_activitypub-backend.html +3 -0
- package/docs/api/module-storage_backends_activitypub_server-ActivityPubServer.html +8 -0
- package/docs/api/module-storage_backends_activitypub_server.ActivityPubServer.html +3 -0
- package/docs/api/module-storage_backends_activitypub_server.html +3 -0
- package/docs/api/module-storage_backends_gundb-backend-GunDBBackend.html +7 -0
- package/docs/api/module-storage_backends_gundb-backend.GunDBBackend.html +3 -0
- package/docs/api/module-storage_backends_gundb-backend.html +3 -0
- package/docs/api/module-storage_backends_nostr-backend-NostrBackend.html +8 -0
- package/docs/api/module-storage_backends_nostr-backend.NostrBackend.html +3 -0
- package/docs/api/module-storage_backends_nostr-backend.html +3 -0
- package/docs/api/module-storage_filesystem-storage-FileSystemStorage.html +5 -0
- package/docs/api/module-storage_filesystem-storage-browser-FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage-browser.FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage-browser.html +3 -0
- package/docs/api/module-storage_filesystem-storage.FileSystemStorage.html +3 -0
- package/docs/api/module-storage_filesystem-storage.html +3 -0
- package/docs/api/module-storage_global-tables.html +3 -0
- package/docs/api/module-storage_gun-async.html +3 -0
- package/docs/api/module-storage_gun-auth-GunAuth.html +5 -0
- package/docs/api/module-storage_gun-auth.GunAuth.html +3 -0
- package/docs/api/module-storage_gun-auth.html +3 -0
- package/docs/api/module-storage_gun-federation.html +3 -0
- package/docs/api/module-storage_gun-references-GunReferenceHandler.html +5 -0
- package/docs/api/module-storage_gun-references.GunReferenceHandler.html +3 -0
- package/docs/api/module-storage_gun-references.html +3 -0
- package/docs/api/module-storage_gun-schema-GunSchemaValidator.html +5 -0
- package/docs/api/module-storage_gun-schema.GunSchemaValidator.html +3 -0
- package/docs/api/module-storage_gun-schema.html +3 -0
- package/docs/api/module-storage_gun-wrapper.html +11 -0
- package/docs/api/module-storage_indexeddb-storage-IndexedDBStorage.html +5 -0
- package/docs/api/module-storage_indexeddb-storage.IndexedDBStorage.html +3 -0
- package/docs/api/module-storage_indexeddb-storage.html +3 -0
- package/docs/api/module-storage_key-storage-simple.html +3 -0
- package/docs/api/module-storage_key-storage.html +4 -0
- package/docs/api/module-storage_memory-storage-MemoryStorage.html +5 -0
- package/docs/api/module-storage_memory-storage.MemoryStorage.html +3 -0
- package/docs/api/module-storage_memory-storage.html +3 -0
- package/docs/api/module-storage_migration-MigrationTool.html +6 -0
- package/docs/api/module-storage_migration.MigrationTool.html +3 -0
- package/docs/api/module-storage_migration.html +3 -0
- package/docs/api/module-storage_nostr-async.html +18 -0
- package/docs/api/module-storage_nostr-client-LRUCache.html +3 -0
- package/docs/api/module-storage_nostr-client-NostrClient.html +7 -0
- package/docs/api/module-storage_nostr-client.NostrClient.html +15 -0
- package/docs/api/module-storage_nostr-client.html +6 -0
- package/docs/api/module-storage_nostr-wrapper.html +3 -0
- package/docs/api/module-storage_outbox-queue-OutboxQueue.html +4 -0
- package/docs/api/module-storage_outbox-queue.OutboxQueue.html +3 -0
- package/docs/api/module-storage_outbox-queue.html +3 -0
- package/docs/api/module-storage_persistent-storage-PersistentStorage.html +3 -0
- package/docs/api/module-storage_persistent-storage.html +4 -0
- package/docs/api/module-storage_sync-service-SyncService.html +5 -0
- package/docs/api/module-storage_sync-service.SyncService.html +3 -0
- package/docs/api/module-storage_sync-service.html +3 -0
- package/docs/api/module-storage_unified-storage.html +3 -0
- package/docs/api/module-subscriptions_manager.SubscriptionRegistry.html +3 -0
- package/docs/api/module-subscriptions_manager.html +3 -0
- package/docs/api/schema_validator.js.html +113 -0
- package/docs/api/scripts/core.js +726 -0
- package/docs/api/scripts/core.min.js +23 -0
- package/docs/api/scripts/resize.js +90 -0
- package/docs/api/scripts/search.js +265 -0
- package/docs/api/scripts/search.min.js +6 -0
- package/docs/api/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/api/scripts/third-party/fuse.js +9 -0
- package/docs/api/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/api/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/api/scripts/third-party/hljs-original.js +5171 -0
- package/docs/api/scripts/third-party/hljs.js +1 -0
- package/docs/api/scripts/third-party/popper.js +5 -0
- package/docs/api/scripts/third-party/tippy.js +1 -0
- package/docs/api/scripts/third-party/tocbot.js +672 -0
- package/docs/api/scripts/third-party/tocbot.min.js +1 -0
- package/docs/api/spatial_h3-operations.js.html +129 -0
- package/docs/api/storage_backend-factory.js.html +133 -0
- package/docs/api/storage_backend-interface.js.html +164 -0
- package/docs/api/storage_backends_activitypub-backend.js.html +298 -0
- package/docs/api/storage_backends_activitypub_server.js.html +678 -0
- package/docs/api/storage_backends_gundb-backend.js.html +878 -0
- package/docs/api/storage_backends_nostr-backend.js.html +254 -0
- package/docs/api/storage_filesystem-storage-browser.js.html +83 -0
- package/docs/api/storage_filesystem-storage.js.html +207 -0
- package/docs/api/storage_global-tables.js.html +116 -0
- package/docs/api/storage_gun-async.js.html +344 -0
- package/docs/api/storage_gun-auth.js.html +376 -0
- package/docs/api/storage_gun-federation.js.html +788 -0
- package/docs/api/storage_gun-references.js.html +212 -0
- package/docs/api/storage_gun-schema.js.html +309 -0
- package/docs/api/storage_gun-wrapper.js.html +645 -0
- package/docs/api/storage_indexeddb-storage.js.html +224 -0
- package/docs/api/storage_key-storage-simple.js.html +102 -0
- package/docs/api/storage_key-storage.js.html +171 -0
- package/docs/api/storage_memory-storage.js.html +128 -0
- package/docs/api/storage_migration.js.html +354 -0
- package/docs/api/storage_nostr-async.js.html +1076 -0
- package/docs/api/storage_nostr-client.js.html +1598 -0
- package/docs/api/storage_nostr-wrapper.js.html +218 -0
- package/docs/api/storage_outbox-queue.js.html +248 -0
- package/docs/api/storage_persistent-storage.js.html +160 -0
- package/docs/api/storage_sync-service.js.html +201 -0
- package/docs/api/storage_unified-storage.js.html +157 -0
- package/docs/api/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/api/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/api/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/api/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/api/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/api/styles/clean-jsdoc-theme.min.css +1 -0
- package/docs/api/subscriptions_manager.js.html +162 -0
- package/jsdoc.json +26 -0
- package/package.json +14 -3
- package/src/ai/aggregation.js +13 -2
- package/src/ai/breakdown.js +12 -2
- package/src/ai/classifier.js +14 -3
- package/src/ai/council.js +22 -7
- package/src/ai/embeddings.js +37 -15
- package/src/ai/federation-ai.js +13 -2
- package/src/ai/h3-ai.js +14 -2
- package/src/ai/index.js +16 -7
- package/src/ai/json-ops.js +18 -5
- package/src/ai/llm-service.js +62 -31
- package/src/ai/nl-query.js +12 -2
- package/src/ai/relationships.js +13 -2
- package/src/ai/schema-extractor.js +24 -10
- package/src/ai/spatial.js +13 -2
- package/src/ai/tts.js +25 -8
- package/src/content/social-protocols.js +34 -25
- package/src/contracts/chain-manager.js +68 -40
- package/src/contracts/deployer.js +70 -42
- package/src/contracts/event-listener.js +61 -29
- package/src/contracts/holon-contracts.js +46 -31
- package/src/contracts/index.js +5 -6
- package/src/contracts/networks.js +19 -14
- package/src/contracts/operations.js +58 -41
- package/src/contracts/queries.js +54 -20
- package/src/core/holosphere.js +35 -6
- package/src/crypto/nostr-utils.js +82 -76
- package/src/crypto/secp256k1.js +7 -2
- package/src/federation/handshake.js +7 -7
- package/src/federation/hologram.js +9 -1
- package/src/hierarchical/upcast.js +34 -20
- package/src/index.js +655 -5
- package/src/lib/ai-methods.js +352 -3
- package/src/lib/contract-methods.js +152 -3
- package/src/lib/errors.js +31 -1
- package/src/lib/federation-methods.js +110 -3
- package/src/lib/index.js +9 -5
- package/src/schema/validator.js +22 -3
- package/src/spatial/h3-operations.js +17 -1
- package/src/storage/backend-factory.js +7 -2
- package/src/storage/backend-interface.js +21 -2
- package/src/storage/backends/activitypub/server.js +25 -3
- package/src/storage/backends/activitypub-backend.js +25 -2
- package/src/storage/backends/gundb-backend.js +29 -2
- package/src/storage/backends/nostr-backend.js +116 -1
- package/src/storage/filesystem-storage-browser.js +42 -2
- package/src/storage/filesystem-storage.js +72 -5
- package/src/storage/global-tables.js +7 -2
- package/src/storage/gun-async.js +20 -11
- package/src/storage/gun-auth.js +15 -4
- package/src/storage/gun-federation.js +14 -5
- package/src/storage/gun-references.js +16 -5
- package/src/storage/gun-schema.js +25 -10
- package/src/storage/gun-wrapper.js +99 -36
- package/src/storage/indexeddb-storage.js +65 -4
- package/src/storage/key-storage-simple.js +32 -9
- package/src/storage/key-storage.js +45 -13
- package/src/storage/memory-storage.js +65 -4
- package/src/storage/migration.js +20 -7
- package/src/storage/nostr-async.js +157 -67
- package/src/storage/nostr-client.js +173 -49
- package/src/storage/nostr-wrapper.js +6 -2
- package/src/storage/outbox-queue.js +55 -18
- package/src/storage/persistent-storage.js +56 -13
- package/src/storage/sync-service.js +51 -17
- package/src/storage/unified-storage.js +7 -2
- package/src/subscriptions/manager.js +33 -16
- package/dist/index-4XHHKe6S.js.map +0 -1
- package/dist/index-Dz5kOZMI.cjs.map +0 -1
- package/dist/indexeddb-storage-DD7EFBVc.cjs.map +0 -1
- package/dist/indexeddb-storage-lExjjFlV.js.map +0 -1
- package/dist/memory-storage-C68adso2.js.map +0 -1
- package/dist/memory-storage-DD_6yyXT.cjs.map +0 -1
- /package/{cleanup-test-data.js → scripts/cleanup-test-data.js} +0 -0
- /package/{test-ai-real-api.js → scripts/test-ai-real-api.js} +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview Blockchain contract methods mixin for HoloSphere.
|
|
3
|
+
* Provides comprehensive smart contract operations including deployment, member management,
|
|
4
|
+
* fund distribution, and governance features across multiple contract types.
|
|
5
|
+
* @module lib/contract-methods
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
import { ChainManager } from '../contracts/chain-manager.js';
|
|
@@ -9,16 +11,28 @@ import { HolonContracts } from '../contracts/holon-contracts.js';
|
|
|
9
11
|
import * as networks from '../contracts/networks.js';
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* Mixin that adds contract methods to a HoloSphere class
|
|
14
|
+
* Mixin that adds blockchain contract methods to a HoloSphere class.
|
|
15
|
+
* Provides initialization, deployment, and interaction with Ethereum smart contracts
|
|
16
|
+
* including Splitter, Managed, Zoned, Appreciative, and Bundle contract types.
|
|
13
17
|
* @param {Class} Base - Base class to extend
|
|
14
18
|
* @returns {Class} Extended class with contract methods
|
|
15
19
|
*/
|
|
16
20
|
export function withContractMethods(Base) {
|
|
17
21
|
return class extends Base {
|
|
22
|
+
/**
|
|
23
|
+
* Check if contracts are initialized.
|
|
24
|
+
* @returns {boolean} True if contracts initialized
|
|
25
|
+
*/
|
|
18
26
|
hasContracts() {
|
|
19
27
|
return this._contracts !== null;
|
|
20
28
|
}
|
|
21
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Ensure contracts are initialized, throw if not.
|
|
32
|
+
* @private
|
|
33
|
+
* @returns {Object} Contracts object
|
|
34
|
+
* @throws {Error} If contracts not initialized
|
|
35
|
+
*/
|
|
22
36
|
_requireContracts() {
|
|
23
37
|
if (!this._contracts) {
|
|
24
38
|
throw new Error('Contracts not initialized. Call initContracts() first.');
|
|
@@ -26,6 +40,14 @@ export function withContractMethods(Base) {
|
|
|
26
40
|
return this._contracts;
|
|
27
41
|
}
|
|
28
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Initialize contracts with server-side configuration (Node.js).
|
|
45
|
+
* @param {Object} config - Contract configuration
|
|
46
|
+
* @param {string} config.network - Network name (mainnet, sepolia, hardhat, etc.)
|
|
47
|
+
* @param {string} config.privateKey - Private key for signing transactions
|
|
48
|
+
* @param {string} [config.rpcUrl] - Optional custom RPC URL
|
|
49
|
+
* @returns {Promise<Object>} Connection info with network details and address
|
|
50
|
+
*/
|
|
29
51
|
async initContracts(config) {
|
|
30
52
|
const chainManager = new ChainManager(config);
|
|
31
53
|
const connectionInfo = await chainManager.connect(
|
|
@@ -50,6 +72,11 @@ export function withContractMethods(Base) {
|
|
|
50
72
|
};
|
|
51
73
|
}
|
|
52
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Initialize contracts with browser wallet (MetaMask, etc.).
|
|
77
|
+
* @param {string} network - Network name to connect to
|
|
78
|
+
* @returns {Promise<Object>} Connection info with network details
|
|
79
|
+
*/
|
|
53
80
|
async initContractsBrowser(network) {
|
|
54
81
|
const chainManager = new ChainManager();
|
|
55
82
|
const connectionInfo = await chainManager.connectBrowser(network);
|
|
@@ -67,56 +94,113 @@ export function withContractMethods(Base) {
|
|
|
67
94
|
return connectionInfo;
|
|
68
95
|
}
|
|
69
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Deploy all core contracts (factory, templates, etc.).
|
|
99
|
+
* @param {Object} [options={}] - Deployment options
|
|
100
|
+
* @returns {Promise<Object>} Deployment result with addresses
|
|
101
|
+
*/
|
|
70
102
|
async deployContracts(options = {}) {
|
|
71
103
|
const { deployer } = this._requireContracts();
|
|
72
104
|
return deployer.deployAll(options);
|
|
73
105
|
}
|
|
74
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Load previously deployed contract addresses.
|
|
109
|
+
* @param {Object} addresses - Map of contract names to addresses
|
|
110
|
+
*/
|
|
75
111
|
loadDeployedContracts(addresses) {
|
|
76
112
|
const { deployer } = this._requireContracts();
|
|
77
113
|
deployer.loadDeployedAddresses(addresses);
|
|
78
114
|
}
|
|
79
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Get all deployed contract addresses.
|
|
118
|
+
* @returns {Object} Map of contract names to addresses
|
|
119
|
+
*/
|
|
80
120
|
getDeployedContracts() {
|
|
81
121
|
const { deployer } = this._requireContracts();
|
|
82
122
|
return deployer.getDeployedAddresses();
|
|
83
123
|
}
|
|
84
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Deploy a new contract for a holon.
|
|
127
|
+
* @param {string} holonId - Holon ID to deploy contract for
|
|
128
|
+
* @param {string} [type='Splitter'] - Contract type (Splitter, Managed, Zoned, Appreciative, Bundle)
|
|
129
|
+
* @param {Object} [options={}] - Deployment options
|
|
130
|
+
* @returns {Promise<Object>} Deployment result with contract address
|
|
131
|
+
*/
|
|
85
132
|
async deployHolonContract(holonId, type = 'Splitter', options = {}) {
|
|
86
133
|
const { holonContracts } = this._requireContracts();
|
|
87
134
|
return holonContracts.deploy(holonId, type, options);
|
|
88
135
|
}
|
|
89
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Link an existing contract to a holon.
|
|
139
|
+
* @param {string} holonId - Holon ID to link
|
|
140
|
+
* @param {string} contractAddress - Contract address to link
|
|
141
|
+
* @param {string} [type='Splitter'] - Contract type
|
|
142
|
+
* @returns {Promise<void>}
|
|
143
|
+
*/
|
|
90
144
|
async linkHolonContract(holonId, contractAddress, type = 'Splitter') {
|
|
91
145
|
const { holonContracts } = this._requireContracts();
|
|
92
146
|
return holonContracts.link(holonId, contractAddress, type);
|
|
93
147
|
}
|
|
94
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Unlink contract from a holon.
|
|
151
|
+
* @param {string} holonId - Holon ID to unlink
|
|
152
|
+
* @returns {Promise<void>}
|
|
153
|
+
*/
|
|
95
154
|
async unlinkHolonContract(holonId) {
|
|
96
155
|
const { holonContracts } = this._requireContracts();
|
|
97
156
|
return holonContracts.unlink(holonId);
|
|
98
157
|
}
|
|
99
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Get contract instance for a holon.
|
|
161
|
+
* @param {string} holonId - Holon ID
|
|
162
|
+
* @returns {Object|null} Contract instance or null if not found
|
|
163
|
+
*/
|
|
100
164
|
getHolonContract(holonId) {
|
|
101
165
|
if (!this._contracts) return null;
|
|
102
166
|
return this._contracts.holonContracts.getContract(holonId);
|
|
103
167
|
}
|
|
104
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Get contract address for a holon.
|
|
171
|
+
* @param {string} holonId - Holon ID
|
|
172
|
+
* @returns {string|null} Contract address or null if not found
|
|
173
|
+
*/
|
|
105
174
|
getHolonContractAddress(holonId) {
|
|
106
175
|
if (!this._contracts) return null;
|
|
107
176
|
return this._contracts.holonContracts.getAddress(holonId);
|
|
108
177
|
}
|
|
109
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Check if holon has a linked contract.
|
|
181
|
+
* @param {string} holonId - Holon ID to check
|
|
182
|
+
* @returns {boolean} True if contract exists
|
|
183
|
+
*/
|
|
110
184
|
hasHolonContract(holonId) {
|
|
111
185
|
if (!this._contracts) return false;
|
|
112
186
|
return this._contracts.holonContracts.hasContract(holonId);
|
|
113
187
|
}
|
|
114
188
|
|
|
189
|
+
/**
|
|
190
|
+
* List all holon contracts.
|
|
191
|
+
* @returns {Array<{holonId: string, address: string, type: string}>} Array of holon contract info
|
|
192
|
+
*/
|
|
115
193
|
listHolonContracts() {
|
|
116
194
|
if (!this._contracts) return [];
|
|
117
195
|
return this._contracts.holonContracts.listAll();
|
|
118
196
|
}
|
|
119
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Get operations interface for a holon contract.
|
|
200
|
+
* @param {string} holonId - Holon ID
|
|
201
|
+
* @returns {Object} Operations object with contract methods
|
|
202
|
+
* @throws {Error} If holon has no contract
|
|
203
|
+
*/
|
|
120
204
|
getHolonOperations(holonId) {
|
|
121
205
|
const { holonContracts } = this._requireContracts();
|
|
122
206
|
return holonContracts.requireOperations(holonId);
|
|
@@ -124,40 +208,97 @@ export function withContractMethods(Base) {
|
|
|
124
208
|
|
|
125
209
|
// ========== MEMBER MANAGEMENT ==========
|
|
126
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Add a member to holon contract.
|
|
213
|
+
* @param {string} holonId - Holon ID
|
|
214
|
+
* @param {string} userId - User ID to add
|
|
215
|
+
* @returns {Promise<Object>} Transaction result
|
|
216
|
+
*/
|
|
127
217
|
async contractAddMember(holonId, userId) {
|
|
128
218
|
return this.getHolonOperations(holonId).addMember(userId);
|
|
129
219
|
}
|
|
130
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Add multiple members to holon contract.
|
|
223
|
+
* @param {string} holonId - Holon ID
|
|
224
|
+
* @param {string[]} userIds - Array of user IDs to add
|
|
225
|
+
* @returns {Promise<Object>} Transaction result
|
|
226
|
+
*/
|
|
131
227
|
async contractAddMembers(holonId, userIds) {
|
|
132
228
|
return this.getHolonOperations(holonId).addMembers(userIds);
|
|
133
229
|
}
|
|
134
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Check if user is a member of holon contract.
|
|
233
|
+
* @param {string} holonId - Holon ID
|
|
234
|
+
* @param {string} userId - User ID to check
|
|
235
|
+
* @returns {Promise<boolean>} True if user is member
|
|
236
|
+
*/
|
|
135
237
|
async contractIsMember(holonId, userId) {
|
|
136
238
|
return this.getHolonOperations(holonId).isMember(userId);
|
|
137
239
|
}
|
|
138
240
|
|
|
139
241
|
// ========== FUND DISTRIBUTION ==========
|
|
140
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Distribute ERC20 token rewards to contract members.
|
|
245
|
+
* @param {string} holonId - Holon ID
|
|
246
|
+
* @param {string} tokenAddress - ERC20 token contract address
|
|
247
|
+
* @param {string|number} amount - Amount to distribute
|
|
248
|
+
* @returns {Promise<Object>} Transaction result
|
|
249
|
+
*/
|
|
141
250
|
async contractReward(holonId, tokenAddress, amount) {
|
|
142
251
|
return this.getHolonOperations(holonId).reward(tokenAddress, amount);
|
|
143
252
|
}
|
|
144
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Distribute ETH rewards to contract members.
|
|
256
|
+
* @param {string} holonId - Holon ID
|
|
257
|
+
* @param {string|number} amount - Amount of ETH to distribute (in wei)
|
|
258
|
+
* @returns {Promise<Object>} Transaction result
|
|
259
|
+
*/
|
|
145
260
|
async contractRewardEth(holonId, amount) {
|
|
146
261
|
return this.getHolonOperations(holonId).rewardEth(amount);
|
|
147
262
|
}
|
|
148
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Send ETH to holon contract.
|
|
266
|
+
* @param {string} holonId - Holon ID
|
|
267
|
+
* @param {string|number} amount - Amount of ETH to send (in wei)
|
|
268
|
+
* @returns {Promise<Object>} Transaction result
|
|
269
|
+
*/
|
|
149
270
|
async contractSendEth(holonId, amount) {
|
|
150
271
|
return this.getHolonOperations(holonId).sendEth(amount);
|
|
151
272
|
}
|
|
152
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Claim user's share of distributed funds.
|
|
276
|
+
* @param {string} holonId - Holon ID
|
|
277
|
+
* @param {string} userId - User ID claiming funds
|
|
278
|
+
* @param {string} beneficiaryAddress - Address to send claimed funds to
|
|
279
|
+
* @returns {Promise<Object>} Transaction result
|
|
280
|
+
*/
|
|
153
281
|
async contractClaim(holonId, userId, beneficiaryAddress) {
|
|
154
282
|
return this.getHolonOperations(holonId).claim(userId, beneficiaryAddress);
|
|
155
283
|
}
|
|
156
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Get user's claimable ETH balance.
|
|
287
|
+
* @param {string} holonId - Holon ID
|
|
288
|
+
* @param {string} userId - User ID to check
|
|
289
|
+
* @returns {Promise<string>} ETH balance in wei
|
|
290
|
+
*/
|
|
157
291
|
async contractGetEthBalance(holonId, userId) {
|
|
158
292
|
return this.getHolonOperations(holonId).getEthBalance(userId);
|
|
159
293
|
}
|
|
160
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Get user's claimable token balance.
|
|
297
|
+
* @param {string} holonId - Holon ID
|
|
298
|
+
* @param {string} userId - User ID to check
|
|
299
|
+
* @param {string} tokenAddress - Token contract address
|
|
300
|
+
* @returns {Promise<string>} Token balance
|
|
301
|
+
*/
|
|
161
302
|
async contractGetTokenBalance(holonId, userId, tokenAddress) {
|
|
162
303
|
return this.getHolonOperations(holonId).getTokenBalance(userId, tokenAddress);
|
|
163
304
|
}
|
|
@@ -280,10 +421,18 @@ export function withContractMethods(Base) {
|
|
|
280
421
|
return this.getHolonOperations(holonId).getTotalDeposited(tokenAddress);
|
|
281
422
|
}
|
|
282
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Get network utility functions.
|
|
426
|
+
* @returns {Object} Network utilities module
|
|
427
|
+
*/
|
|
283
428
|
getNetworkUtils() {
|
|
284
429
|
return networks;
|
|
285
430
|
}
|
|
286
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Get the chain manager instance.
|
|
434
|
+
* @returns {Object|null} ChainManager instance or null if not initialized
|
|
435
|
+
*/
|
|
287
436
|
getChainManager() {
|
|
288
437
|
return this._contracts?.chainManager || null;
|
|
289
438
|
}
|
package/src/lib/errors.js
CHANGED
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HoloSphere Error Classes
|
|
2
|
+
* @fileoverview HoloSphere Custom Error Classes.
|
|
3
|
+
*
|
|
4
|
+
* Provides specialized error types for authorization and validation failures.
|
|
5
|
+
*
|
|
6
|
+
* @module lib/errors
|
|
3
7
|
*/
|
|
4
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when an operation fails due to insufficient permissions.
|
|
11
|
+
*
|
|
12
|
+
* @class AuthorizationError
|
|
13
|
+
* @extends Error
|
|
14
|
+
*/
|
|
5
15
|
export class AuthorizationError extends Error {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new AuthorizationError.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} message - Error message describing the authorization failure
|
|
20
|
+
* @param {string|null} [requiredPermission=null] - The permission that was required
|
|
21
|
+
*/
|
|
6
22
|
constructor(message, requiredPermission = null) {
|
|
7
23
|
super(message);
|
|
24
|
+
/** @type {string} */
|
|
8
25
|
this.name = 'AuthorizationError';
|
|
26
|
+
/** @type {string|null} */
|
|
9
27
|
this.requiredPermission = requiredPermission;
|
|
10
28
|
}
|
|
11
29
|
}
|
|
12
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Error thrown when data validation fails.
|
|
33
|
+
*
|
|
34
|
+
* @class ValidationError
|
|
35
|
+
* @extends Error
|
|
36
|
+
*/
|
|
13
37
|
export class ValidationError extends Error {
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new ValidationError.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} message - Error message describing the validation failure
|
|
42
|
+
*/
|
|
14
43
|
constructor(message) {
|
|
15
44
|
super(message);
|
|
45
|
+
/** @type {string} */
|
|
16
46
|
this.name = 'ValidationError';
|
|
17
47
|
}
|
|
18
48
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Federation
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview Federation methods mixin for cross-HoloSphere federation and Nostr discovery.
|
|
3
|
+
* Provides federated data access, capability-based authorization, and federation request protocols
|
|
4
|
+
* for connecting multiple HoloSphere instances.
|
|
5
|
+
* @module lib/federation-methods
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
import * as registry from '../federation/registry.js';
|
|
@@ -14,7 +16,9 @@ import { sha256 } from '@noble/hashes/sha256';
|
|
|
14
16
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
|
-
* Mixin that adds federation methods to a HoloSphere class
|
|
19
|
+
* Mixin that adds federation methods to a HoloSphere class.
|
|
20
|
+
* Enables cross-HoloSphere federation with capability-based access control,
|
|
21
|
+
* hologram creation, and Nostr-based discovery protocols.
|
|
18
22
|
* @param {Class} Base - Base class to extend
|
|
19
23
|
* @returns {Class} Extended class with federation methods
|
|
20
24
|
*/
|
|
@@ -22,6 +26,13 @@ export function withFederationMethods(Base) {
|
|
|
22
26
|
return class extends Base {
|
|
23
27
|
// === Cross-Holosphere Federation ===
|
|
24
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Add a federated HoloSphere partner by public key.
|
|
31
|
+
* @param {string} pubKey - Public key (hex) of the federated HoloSphere
|
|
32
|
+
* @param {Object} [options={}] - Federation options (metadata, capabilities, etc.)
|
|
33
|
+
* @returns {Promise<Object>} Federation registration result
|
|
34
|
+
* @throws {ValidationError} If pubKey is invalid
|
|
35
|
+
*/
|
|
25
36
|
async addFederatedHolosphere(pubKey, options = {}) {
|
|
26
37
|
if (!pubKey || typeof pubKey !== 'string') {
|
|
27
38
|
throw new ValidationError('pubKey must be a valid public key string');
|
|
@@ -34,6 +45,11 @@ export function withFederationMethods(Base) {
|
|
|
34
45
|
);
|
|
35
46
|
}
|
|
36
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Remove a federated HoloSphere partner.
|
|
50
|
+
* @param {string} pubKey - Public key of the partner to remove
|
|
51
|
+
* @returns {Promise<void>}
|
|
52
|
+
*/
|
|
37
53
|
async removeFederatedHolosphere(pubKey) {
|
|
38
54
|
return registry.removeFederatedPartner(
|
|
39
55
|
this.client,
|
|
@@ -42,6 +58,10 @@ export function withFederationMethods(Base) {
|
|
|
42
58
|
);
|
|
43
59
|
}
|
|
44
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Get all federated HoloSphere public keys.
|
|
63
|
+
* @returns {Promise<string[]>} Array of federated public keys
|
|
64
|
+
*/
|
|
45
65
|
async getFederatedHolospheres() {
|
|
46
66
|
return registry.getFederatedAuthors(
|
|
47
67
|
this.client,
|
|
@@ -49,6 +69,10 @@ export function withFederationMethods(Base) {
|
|
|
49
69
|
);
|
|
50
70
|
}
|
|
51
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Get the complete federation registry.
|
|
74
|
+
* @returns {Promise<Object>} Federation registry with all partners and capabilities
|
|
75
|
+
*/
|
|
52
76
|
async getFederationRegistry() {
|
|
53
77
|
return registry.getFederationRegistry(
|
|
54
78
|
this.client,
|
|
@@ -56,6 +80,12 @@ export function withFederationMethods(Base) {
|
|
|
56
80
|
);
|
|
57
81
|
}
|
|
58
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Store an inbound capability token from a federated partner.
|
|
85
|
+
* @param {string} partnerPubKey - Partner's public key
|
|
86
|
+
* @param {Object} capabilityInfo - Capability token and metadata
|
|
87
|
+
* @returns {Promise<void>}
|
|
88
|
+
*/
|
|
59
89
|
async storeInboundCapability(partnerPubKey, capabilityInfo) {
|
|
60
90
|
return registry.storeInboundCapability(
|
|
61
91
|
this.client,
|
|
@@ -65,6 +95,15 @@ export function withFederationMethods(Base) {
|
|
|
65
95
|
);
|
|
66
96
|
}
|
|
67
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Read data from a federated source with capability verification.
|
|
100
|
+
* @param {string} sourcePubKey - Source HoloSphere public key
|
|
101
|
+
* @param {string} holonId - Holon ID to read from
|
|
102
|
+
* @param {string} lensName - Lens name to read from
|
|
103
|
+
* @param {string|null} [dataId=null] - Optional specific data ID (null for all)
|
|
104
|
+
* @returns {Promise<Object|Object[]>} Data from federated source
|
|
105
|
+
* @throws {AuthorizationError} If capability verification fails
|
|
106
|
+
*/
|
|
68
107
|
async readFromFederatedSource(sourcePubKey, holonId, lensName, dataId = null) {
|
|
69
108
|
const capabilityEntry = await registry.getCapabilityForAuthor(
|
|
70
109
|
this.client,
|
|
@@ -102,6 +141,19 @@ export function withFederationMethods(Base) {
|
|
|
102
141
|
}
|
|
103
142
|
}
|
|
104
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Create a cross-HoloSphere hologram reference.
|
|
146
|
+
* Links data from another HoloSphere into this one using capability-based access.
|
|
147
|
+
* @param {string} sourcePubKey - Source HoloSphere public key
|
|
148
|
+
* @param {string} sourceHolon - Source holon ID
|
|
149
|
+
* @param {string} lensName - Lens name
|
|
150
|
+
* @param {string} dataId - Data ID
|
|
151
|
+
* @param {string} targetHolon - Target holon in this HoloSphere
|
|
152
|
+
* @param {Object} [options={}] - Hologram options
|
|
153
|
+
* @param {boolean} [options.embedCapability=true] - Embed capability in hologram
|
|
154
|
+
* @returns {Promise<Object>} Created hologram
|
|
155
|
+
* @throws {AuthorizationError} If no valid capability exists
|
|
156
|
+
*/
|
|
105
157
|
async createCrossHolosphereHologram(sourcePubKey, sourceHolon, lensName, dataId, targetHolon, options = {}) {
|
|
106
158
|
const { embedCapability = true } = options;
|
|
107
159
|
|
|
@@ -134,6 +186,17 @@ export function withFederationMethods(Base) {
|
|
|
134
186
|
return hologram;
|
|
135
187
|
}
|
|
136
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Issue a capability token for federated access.
|
|
191
|
+
* Grants another HoloSphere permission to access data with specified scope.
|
|
192
|
+
* @param {string} targetPubKey - Target HoloSphere public key to grant access to
|
|
193
|
+
* @param {Object} scope - Access scope (holonId, lensName, dataId patterns)
|
|
194
|
+
* @param {string[]} permissions - Array of permissions ('read', 'write', etc.)
|
|
195
|
+
* @param {Object} [options={}] - Capability options
|
|
196
|
+
* @param {number} [options.expiresIn=3600000] - Expiration time in milliseconds
|
|
197
|
+
* @param {boolean} [options.trackInRegistry=true] - Store in federation registry
|
|
198
|
+
* @returns {Promise<string>} Capability token
|
|
199
|
+
*/
|
|
137
200
|
async issueCapabilityForFederation(targetPubKey, scope, permissions, options = {}) {
|
|
138
201
|
const { expiresIn = 3600000, trackInRegistry = true } = options;
|
|
139
202
|
|
|
@@ -179,6 +242,12 @@ export function withFederationMethods(Base) {
|
|
|
179
242
|
return token;
|
|
180
243
|
}
|
|
181
244
|
|
|
245
|
+
/**
|
|
246
|
+
* Hash a capability token for storage.
|
|
247
|
+
* @private
|
|
248
|
+
* @param {string} token - Capability token to hash
|
|
249
|
+
* @returns {Promise<string>} SHA256 hash of token
|
|
250
|
+
*/
|
|
182
251
|
async _hashToken(token) {
|
|
183
252
|
const encoder = new TextEncoder();
|
|
184
253
|
return bytesToHex(sha256(encoder.encode(token)));
|
|
@@ -186,6 +255,12 @@ export function withFederationMethods(Base) {
|
|
|
186
255
|
|
|
187
256
|
// === Nostr Discovery Protocol ===
|
|
188
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Send a federation request to another HoloSphere via Nostr.
|
|
260
|
+
* @param {string} targetPubKey - Target HoloSphere public key
|
|
261
|
+
* @param {Object} [options={}] - Request options (message, metadata, etc.)
|
|
262
|
+
* @returns {Promise<Object>} Request event
|
|
263
|
+
*/
|
|
189
264
|
async sendFederationRequest(targetPubKey, options = {}) {
|
|
190
265
|
return discovery.sendFederationRequest(
|
|
191
266
|
this.client,
|
|
@@ -195,10 +270,21 @@ export function withFederationMethods(Base) {
|
|
|
195
270
|
);
|
|
196
271
|
}
|
|
197
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Subscribe to incoming federation requests.
|
|
275
|
+
* @param {Function} callback - Callback function (request) => void
|
|
276
|
+
* @returns {Promise<Object>} Subscription object with unsubscribe method
|
|
277
|
+
*/
|
|
198
278
|
async subscribeFederationRequests(callback) {
|
|
199
279
|
return discovery.subscribeFederationRequests(this.client, callback);
|
|
200
280
|
}
|
|
201
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Accept a federation request and establish partnership.
|
|
284
|
+
* @param {Object} request - Federation request object
|
|
285
|
+
* @param {Object} [options={}] - Acceptance options (capabilities to grant, etc.)
|
|
286
|
+
* @returns {Promise<Object>} Acceptance event
|
|
287
|
+
*/
|
|
202
288
|
async acceptFederationRequest(request, options = {}) {
|
|
203
289
|
return discovery.acceptFederationRequest(
|
|
204
290
|
this.client,
|
|
@@ -208,6 +294,12 @@ export function withFederationMethods(Base) {
|
|
|
208
294
|
);
|
|
209
295
|
}
|
|
210
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Decline a federation request.
|
|
299
|
+
* @param {Object} request - Federation request object
|
|
300
|
+
* @param {string} [reason=''] - Optional reason for declining
|
|
301
|
+
* @returns {Promise<Object>} Decline event
|
|
302
|
+
*/
|
|
211
303
|
async declineFederationRequest(request, reason = '') {
|
|
212
304
|
return discovery.declineFederationRequest(
|
|
213
305
|
this.client,
|
|
@@ -217,6 +309,11 @@ export function withFederationMethods(Base) {
|
|
|
217
309
|
);
|
|
218
310
|
}
|
|
219
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Subscribe to federation request acceptances.
|
|
314
|
+
* @param {Function} callback - Callback function (acceptance) => void
|
|
315
|
+
* @returns {Promise<Object>} Subscription object with unsubscribe method
|
|
316
|
+
*/
|
|
220
317
|
async subscribeFederationAcceptances(callback) {
|
|
221
318
|
return discovery.subscribeFederationAcceptances(
|
|
222
319
|
this.client,
|
|
@@ -225,10 +322,20 @@ export function withFederationMethods(Base) {
|
|
|
225
322
|
);
|
|
226
323
|
}
|
|
227
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Subscribe to federation request declines.
|
|
327
|
+
* @param {Function} callback - Callback function (decline) => void
|
|
328
|
+
* @returns {Promise<Object>} Subscription object with unsubscribe method
|
|
329
|
+
*/
|
|
228
330
|
async subscribeFederationDeclines(callback) {
|
|
229
331
|
return discovery.subscribeFederationDeclines(this.client, callback);
|
|
230
332
|
}
|
|
231
333
|
|
|
334
|
+
/**
|
|
335
|
+
* Get all pending federation requests.
|
|
336
|
+
* @param {Object} [options={}] - Query options (limit, since, etc.)
|
|
337
|
+
* @returns {Promise<Object[]>} Array of pending requests
|
|
338
|
+
*/
|
|
232
339
|
async getPendingFederationRequests(options = {}) {
|
|
233
340
|
return discovery.getPendingFederationRequests(this.client, options);
|
|
234
341
|
}
|
package/src/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HoloSphere
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview HoloSphere library modules and mixin composition utilities.
|
|
3
|
+
* Exports AI, contract, and federation method mixins for extending the base HoloSphere class.
|
|
4
|
+
* @module lib/index
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
export { withAIMethods } from './ai-methods.js';
|
|
@@ -9,10 +10,13 @@ export { withFederationMethods } from './federation-methods.js';
|
|
|
9
10
|
export { AuthorizationError, ValidationError } from './errors.js';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Compose multiple mixins into a single class
|
|
13
|
+
* Compose multiple mixins into a single class.
|
|
14
|
+
* Applies mixins in order from left to right.
|
|
13
15
|
* @param {Class} BaseClass - Base class to extend
|
|
14
|
-
* @param {...Function} mixins - Mixin functions to apply
|
|
15
|
-
* @returns {Class} Composed class
|
|
16
|
+
* @param {...Function} mixins - Mixin functions to apply sequentially
|
|
17
|
+
* @returns {Class} Composed class with all mixins applied
|
|
18
|
+
* @example
|
|
19
|
+
* const EnhancedClass = compose(BaseClass, withAIMethods, withContractMethods);
|
|
16
20
|
*/
|
|
17
21
|
export function compose(BaseClass, ...mixins) {
|
|
18
22
|
return mixins.reduce((acc, mixin) => mixin(acc), BaseClass);
|
package/src/schema/validator.js
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSON Schema Validation with Ajv and caching
|
|
2
|
+
* @fileoverview JSON Schema Validation with Ajv and caching.
|
|
3
|
+
*
|
|
4
|
+
* Provides JSON Schema validation using Ajv (Another JSON Schema Validator)
|
|
5
|
+
* with schema compilation caching for improved performance on repeated validations.
|
|
6
|
+
*
|
|
7
|
+
* @module schema/validator
|
|
3
8
|
*/
|
|
4
9
|
|
|
5
10
|
import Ajv from 'ajv';
|
|
6
11
|
|
|
12
|
+
/** @type {Ajv} Ajv instance configured for validation */
|
|
7
13
|
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
14
|
+
|
|
15
|
+
/** @type {Map<string, {validator: Function, timestamp: number}>} Schema cache */
|
|
8
16
|
const schemaCache = new Map();
|
|
9
|
-
|
|
17
|
+
|
|
18
|
+
/** @constant {number} Cache TTL in milliseconds (1 hour) */
|
|
19
|
+
const CACHE_TTL = 3600000;
|
|
10
20
|
|
|
11
21
|
/**
|
|
12
|
-
*
|
|
22
|
+
* Custom error class for validation failures.
|
|
23
|
+
*
|
|
24
|
+
* @class ValidationError
|
|
25
|
+
* @extends Error
|
|
13
26
|
*/
|
|
14
27
|
export class ValidationError extends Error {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new ValidationError.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} message - Error message
|
|
32
|
+
* @param {Array} [errors=[]] - Array of Ajv error objects
|
|
33
|
+
*/
|
|
15
34
|
constructor(message, errors = []) {
|
|
16
35
|
super(message);
|
|
17
36
|
this.name = 'ValidationError';
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview H3 Hexagonal Spatial Operations.
|
|
3
|
+
*
|
|
4
|
+
* Provides functions for working with H3 hexagonal hierarchical spatial indexing.
|
|
5
|
+
* H3 divides the world into hexagonal cells at 16 resolution levels (0-15),
|
|
6
|
+
* where resolution 0 covers the entire globe and resolution 15 provides
|
|
7
|
+
* approximately 0.5 square meter precision.
|
|
8
|
+
*
|
|
9
|
+
* @module spatial/h3-operations
|
|
10
|
+
* @see {@link https://h3geo.org/ H3 Spatial Indexing}
|
|
11
|
+
*/
|
|
12
|
+
|
|
1
13
|
import {
|
|
2
14
|
latLngToCell,
|
|
3
15
|
cellToParent,
|
|
@@ -7,7 +19,11 @@ import {
|
|
|
7
19
|
} from 'h3-js';
|
|
8
20
|
|
|
9
21
|
/**
|
|
10
|
-
*
|
|
22
|
+
* Converts geographic coordinates to an H3 holon ID.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Get H3 cell for a location at resolution 9
|
|
26
|
+
* const holonId = toHolon(40.7128, -74.0060, 9); // New York City
|
|
11
27
|
* @param {number} lat - Latitude (-90 to 90)
|
|
12
28
|
* @param {number} lng - Longitude (-180 to 180)
|
|
13
29
|
* @param {number} resolution - H3 resolution (0-15)
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Factory for
|
|
3
|
-
*
|
|
2
|
+
* @fileoverview Factory for Creating Storage Backends.
|
|
3
|
+
*
|
|
4
|
+
* Provides a factory pattern for creating and managing storage backend instances.
|
|
5
|
+
* Supports lazy loading of backend implementations to reduce initial bundle size.
|
|
6
|
+
*
|
|
7
|
+
* @module storage/backend-factory
|
|
4
8
|
*/
|
|
5
9
|
|
|
10
|
+
/** @type {Object<string, string>} Map of backend types to their module paths */
|
|
6
11
|
const BACKEND_MODULES = {
|
|
7
12
|
nostr: './backends/nostr-backend.js',
|
|
8
13
|
gundb: './backends/gundb-backend.js',
|