@unicitylabs/sphere-sdk 0.3.7 → 0.3.9

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 (45) hide show
  1. package/dist/connect/index.cjs +770 -0
  2. package/dist/connect/index.cjs.map +1 -0
  3. package/dist/connect/index.d.cts +312 -0
  4. package/dist/connect/index.d.ts +312 -0
  5. package/dist/connect/index.js +747 -0
  6. package/dist/connect/index.js.map +1 -0
  7. package/dist/core/index.cjs +90 -2502
  8. package/dist/core/index.cjs.map +1 -1
  9. package/dist/core/index.d.cts +10 -165
  10. package/dist/core/index.d.ts +10 -165
  11. package/dist/core/index.js +86 -2498
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/impl/browser/connect/index.cjs +271 -0
  14. package/dist/impl/browser/connect/index.cjs.map +1 -0
  15. package/dist/impl/browser/connect/index.d.cts +137 -0
  16. package/dist/impl/browser/connect/index.d.ts +137 -0
  17. package/dist/impl/browser/connect/index.js +248 -0
  18. package/dist/impl/browser/connect/index.js.map +1 -0
  19. package/dist/impl/browser/index.cjs +201 -28
  20. package/dist/impl/browser/index.cjs.map +1 -1
  21. package/dist/impl/browser/index.js +201 -28
  22. package/dist/impl/browser/index.js.map +1 -1
  23. package/dist/impl/browser/ipfs.cjs +6 -1
  24. package/dist/impl/browser/ipfs.cjs.map +1 -1
  25. package/dist/impl/browser/ipfs.js +6 -1
  26. package/dist/impl/browser/ipfs.js.map +1 -1
  27. package/dist/impl/nodejs/connect/index.cjs +372 -0
  28. package/dist/impl/nodejs/connect/index.cjs.map +1 -0
  29. package/dist/impl/nodejs/connect/index.d.cts +178 -0
  30. package/dist/impl/nodejs/connect/index.d.ts +178 -0
  31. package/dist/impl/nodejs/connect/index.js +333 -0
  32. package/dist/impl/nodejs/connect/index.js.map +1 -0
  33. package/dist/impl/nodejs/index.cjs +201 -28
  34. package/dist/impl/nodejs/index.cjs.map +1 -1
  35. package/dist/impl/nodejs/index.d.cts +2 -21
  36. package/dist/impl/nodejs/index.d.ts +2 -21
  37. package/dist/impl/nodejs/index.js +201 -28
  38. package/dist/impl/nodejs/index.js.map +1 -1
  39. package/dist/index.cjs +232 -2513
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +59 -169
  42. package/dist/index.d.ts +59 -169
  43. package/dist/index.js +228 -2506
  44. package/dist/index.js.map +1 -1
  45. package/package.json +31 -1
@@ -1728,6 +1728,7 @@ interface MintResult {
1728
1728
  * Platform-independent abstraction for fetching token market prices.
1729
1729
  * Does not extend BaseProvider — stateless HTTP client with internal caching.
1730
1730
  */
1731
+
1731
1732
  /**
1732
1733
  * Supported price provider platforms
1733
1734
  */
@@ -1772,7 +1773,7 @@ interface PriceProvider {
1772
1773
  /**
1773
1774
  * Get price for a single token
1774
1775
  * @param tokenName - Token name (e.g., 'bitcoin')
1775
- * @returns Token price or null if not available
1776
+ * @returns Token price (zero-price entry for tokens not listed on the platform), or null on network error with no cache
1776
1777
  */
1777
1778
  getPrice(tokenName: string): Promise<TokenPrice | null>;
1778
1779
  /**
@@ -2760,154 +2761,6 @@ declare class GroupChatModule {
2760
2761
  private randomId;
2761
2762
  }
2762
2763
 
2763
- /**
2764
- * Market Module Types
2765
- * Intent bulletin board for posting and discovering intents,
2766
- * plus real-time feed subscription.
2767
- */
2768
- type IntentType = 'buy' | 'sell' | 'service' | 'announcement' | 'other' | (string & {});
2769
- type IntentStatus = 'active' | 'closed' | 'expired';
2770
- interface MarketModuleConfig {
2771
- /** Market API base URL (default: https://market-api.unicity.network) */
2772
- apiUrl?: string;
2773
- /** Request timeout in ms (default: 30000) */
2774
- timeout?: number;
2775
- }
2776
- interface MarketModuleDependencies {
2777
- identity: FullIdentity;
2778
- emitEvent: <T extends SphereEventType>(type: T, data: SphereEventMap[T]) => void;
2779
- }
2780
- interface PostIntentRequest {
2781
- description: string;
2782
- intentType: IntentType;
2783
- category?: string;
2784
- price?: number;
2785
- currency?: string;
2786
- location?: string;
2787
- contactHandle?: string;
2788
- expiresInDays?: number;
2789
- }
2790
- interface PostIntentResult {
2791
- intentId: string;
2792
- message: string;
2793
- expiresAt: string;
2794
- }
2795
- interface MarketIntent {
2796
- id: string;
2797
- intentType: IntentType;
2798
- category?: string;
2799
- price?: string;
2800
- currency: string;
2801
- location?: string;
2802
- status: IntentStatus;
2803
- createdAt: string;
2804
- expiresAt: string;
2805
- }
2806
- interface SearchIntentResult {
2807
- id: string;
2808
- score: number;
2809
- agentNametag?: string;
2810
- agentPublicKey: string;
2811
- description: string;
2812
- intentType: IntentType;
2813
- category?: string;
2814
- price?: number;
2815
- currency: string;
2816
- location?: string;
2817
- contactMethod: string;
2818
- contactHandle?: string;
2819
- createdAt: string;
2820
- expiresAt: string;
2821
- }
2822
- interface SearchFilters {
2823
- intentType?: IntentType;
2824
- category?: string;
2825
- minPrice?: number;
2826
- maxPrice?: number;
2827
- location?: string;
2828
- /** Minimum similarity score (0–1). Results below this threshold are excluded (client-side). */
2829
- minScore?: number;
2830
- }
2831
- interface SearchOptions {
2832
- filters?: SearchFilters;
2833
- limit?: number;
2834
- }
2835
- interface SearchResult {
2836
- intents: SearchIntentResult[];
2837
- count: number;
2838
- }
2839
- /** A listing broadcast on the live feed */
2840
- interface FeedListing {
2841
- id: string;
2842
- title: string;
2843
- descriptionPreview: string;
2844
- agentName: string;
2845
- agentId: number;
2846
- type: IntentType;
2847
- createdAt: string;
2848
- }
2849
- /** WebSocket message: initial batch of recent listings */
2850
- interface FeedInitialMessage {
2851
- type: 'initial';
2852
- listings: FeedListing[];
2853
- }
2854
- /** WebSocket message: single new listing */
2855
- interface FeedNewMessage {
2856
- type: 'new';
2857
- listing: FeedListing;
2858
- }
2859
- type FeedMessage = FeedInitialMessage | FeedNewMessage;
2860
- /** Callback for live feed events */
2861
- type FeedListener = (message: FeedMessage) => void;
2862
-
2863
- /**
2864
- * Market Module
2865
- *
2866
- * Intent bulletin board — post and discover intents (buy, sell,
2867
- * service, announcement, other) with secp256k1-signed requests
2868
- * tied to the wallet identity. Includes real-time feed via WebSocket.
2869
- */
2870
-
2871
- declare class MarketModule {
2872
- private readonly apiUrl;
2873
- private readonly timeout;
2874
- private identity;
2875
- private registered;
2876
- constructor(config?: MarketModuleConfig);
2877
- /** Called by Sphere after construction */
2878
- initialize(deps: MarketModuleDependencies): void;
2879
- /** No-op — stateless module */
2880
- load(): Promise<void>;
2881
- /** No-op — stateless module */
2882
- destroy(): void;
2883
- /** Post a new intent (agent is auto-registered on first post) */
2884
- postIntent(intent: PostIntentRequest): Promise<PostIntentResult>;
2885
- /** Semantic search for intents (public — no auth required) */
2886
- search(query: string, opts?: SearchOptions): Promise<SearchResult>;
2887
- /** List own intents (authenticated) */
2888
- getMyIntents(): Promise<MarketIntent[]>;
2889
- /** Close (delete) an intent */
2890
- closeIntent(intentId: string): Promise<void>;
2891
- /** Fetch the most recent listings via REST (public — no auth required) */
2892
- getRecentListings(): Promise<FeedListing[]>;
2893
- /**
2894
- * Subscribe to the live listing feed via WebSocket.
2895
- * Returns an unsubscribe function that closes the connection.
2896
- *
2897
- * Requires a WebSocket implementation — works natively in browsers
2898
- * and in Node.js 21+ (or with the `ws` package).
2899
- */
2900
- subscribeFeed(listener: FeedListener): () => void;
2901
- private ensureIdentity;
2902
- /** Register the agent's public key with the server (idempotent) */
2903
- private ensureRegistered;
2904
- private parseResponse;
2905
- private apiPost;
2906
- private apiGet;
2907
- private apiDelete;
2908
- private apiPublicPost;
2909
- }
2910
-
2911
2764
  /** Network configurations */
2912
2765
  declare const NETWORKS: {
2913
2766
  readonly mainnet: {
@@ -3053,8 +2906,6 @@ interface SphereCreateOptions {
3053
2906
  groupChat?: GroupChatModuleConfig | boolean;
3054
2907
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
3055
2908
  password?: string;
3056
- /** Market module configuration. true = enable with defaults, object = custom config. */
3057
- market?: MarketModuleConfig | boolean;
3058
2909
  }
3059
2910
  /** Options for loading existing wallet */
3060
2911
  interface SphereLoadOptions {
@@ -3080,8 +2931,6 @@ interface SphereLoadOptions {
3080
2931
  groupChat?: GroupChatModuleConfig | boolean;
3081
2932
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
3082
2933
  password?: string;
3083
- /** Market module configuration. true = enable with defaults, object = custom config. */
3084
- market?: MarketModuleConfig | boolean;
3085
2934
  }
3086
2935
  /** Options for importing a wallet */
3087
2936
  interface SphereImportOptions {
@@ -3115,8 +2964,6 @@ interface SphereImportOptions {
3115
2964
  groupChat?: GroupChatModuleConfig | boolean;
3116
2965
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
3117
2966
  password?: string;
3118
- /** Market module configuration. true = enable with defaults, object = custom config. */
3119
- market?: MarketModuleConfig | boolean;
3120
2967
  }
3121
2968
  /** L1 (ALPHA blockchain) configuration */
3122
2969
  interface L1Config {
@@ -3164,8 +3011,6 @@ interface SphereInitOptions {
3164
3011
  groupChat?: GroupChatModuleConfig | boolean;
3165
3012
  /** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
3166
3013
  password?: string;
3167
- /** Market module configuration. true = enable with defaults, object = custom config. */
3168
- market?: MarketModuleConfig | boolean;
3169
3014
  }
3170
3015
  /** Result of init operation */
3171
3016
  interface SphereInitResult {
@@ -3203,7 +3048,6 @@ declare class Sphere {
3203
3048
  private _payments;
3204
3049
  private _communications;
3205
3050
  private _groupChat;
3206
- private _market;
3207
3051
  private eventHandlers;
3208
3052
  private _disabledProviders;
3209
3053
  private _providerEventCleanups;
@@ -3252,12 +3096,15 @@ declare class Sphere {
3252
3096
  */
3253
3097
  private static resolveGroupChatConfig;
3254
3098
  /**
3255
- * Resolve market module config from Sphere.init() options.
3256
- * - `true` → enable with default API URL
3257
- * - `MarketModuleConfig` pass through with defaults
3258
- * - `undefined` no market module
3099
+ * Configure TokenRegistry in the main bundle context.
3100
+ *
3101
+ * The provider factory functions (createBrowserProviders / createNodeProviders)
3102
+ * are compiled into separate bundles by tsup, each with their own inlined copy
3103
+ * of TokenRegistry. Their TokenRegistry.configure() call configures a different
3104
+ * singleton than the one used by PaymentsModule (which lives in the main bundle).
3105
+ * This method ensures the main bundle's TokenRegistry is properly configured.
3259
3106
  */
3260
- private static resolveMarketConfig;
3107
+ private static configureTokenRegistry;
3261
3108
  /**
3262
3109
  * Create new wallet with mnemonic
3263
3110
  */
@@ -3316,8 +3163,6 @@ declare class Sphere {
3316
3163
  get communications(): CommunicationsModule;
3317
3164
  /** Group chat module (NIP-29). Null if not configured. */
3318
3165
  get groupChat(): GroupChatModule | null;
3319
- /** Market module (intent bulletin board). Null if not configured. */
3320
- get market(): MarketModule | null;
3321
3166
  /** Current identity (public info only) */
3322
3167
  get identity(): Identity | null;
3323
3168
  /** Is ready */
@@ -1728,6 +1728,7 @@ interface MintResult {
1728
1728
  * Platform-independent abstraction for fetching token market prices.
1729
1729
  * Does not extend BaseProvider — stateless HTTP client with internal caching.
1730
1730
  */
1731
+
1731
1732
  /**
1732
1733
  * Supported price provider platforms
1733
1734
  */
@@ -1772,7 +1773,7 @@ interface PriceProvider {
1772
1773
  /**
1773
1774
  * Get price for a single token
1774
1775
  * @param tokenName - Token name (e.g., 'bitcoin')
1775
- * @returns Token price or null if not available
1776
+ * @returns Token price (zero-price entry for tokens not listed on the platform), or null on network error with no cache
1776
1777
  */
1777
1778
  getPrice(tokenName: string): Promise<TokenPrice | null>;
1778
1779
  /**
@@ -2760,154 +2761,6 @@ declare class GroupChatModule {
2760
2761
  private randomId;
2761
2762
  }
2762
2763
 
2763
- /**
2764
- * Market Module Types
2765
- * Intent bulletin board for posting and discovering intents,
2766
- * plus real-time feed subscription.
2767
- */
2768
- type IntentType = 'buy' | 'sell' | 'service' | 'announcement' | 'other' | (string & {});
2769
- type IntentStatus = 'active' | 'closed' | 'expired';
2770
- interface MarketModuleConfig {
2771
- /** Market API base URL (default: https://market-api.unicity.network) */
2772
- apiUrl?: string;
2773
- /** Request timeout in ms (default: 30000) */
2774
- timeout?: number;
2775
- }
2776
- interface MarketModuleDependencies {
2777
- identity: FullIdentity;
2778
- emitEvent: <T extends SphereEventType>(type: T, data: SphereEventMap[T]) => void;
2779
- }
2780
- interface PostIntentRequest {
2781
- description: string;
2782
- intentType: IntentType;
2783
- category?: string;
2784
- price?: number;
2785
- currency?: string;
2786
- location?: string;
2787
- contactHandle?: string;
2788
- expiresInDays?: number;
2789
- }
2790
- interface PostIntentResult {
2791
- intentId: string;
2792
- message: string;
2793
- expiresAt: string;
2794
- }
2795
- interface MarketIntent {
2796
- id: string;
2797
- intentType: IntentType;
2798
- category?: string;
2799
- price?: string;
2800
- currency: string;
2801
- location?: string;
2802
- status: IntentStatus;
2803
- createdAt: string;
2804
- expiresAt: string;
2805
- }
2806
- interface SearchIntentResult {
2807
- id: string;
2808
- score: number;
2809
- agentNametag?: string;
2810
- agentPublicKey: string;
2811
- description: string;
2812
- intentType: IntentType;
2813
- category?: string;
2814
- price?: number;
2815
- currency: string;
2816
- location?: string;
2817
- contactMethod: string;
2818
- contactHandle?: string;
2819
- createdAt: string;
2820
- expiresAt: string;
2821
- }
2822
- interface SearchFilters {
2823
- intentType?: IntentType;
2824
- category?: string;
2825
- minPrice?: number;
2826
- maxPrice?: number;
2827
- location?: string;
2828
- /** Minimum similarity score (0–1). Results below this threshold are excluded (client-side). */
2829
- minScore?: number;
2830
- }
2831
- interface SearchOptions {
2832
- filters?: SearchFilters;
2833
- limit?: number;
2834
- }
2835
- interface SearchResult {
2836
- intents: SearchIntentResult[];
2837
- count: number;
2838
- }
2839
- /** A listing broadcast on the live feed */
2840
- interface FeedListing {
2841
- id: string;
2842
- title: string;
2843
- descriptionPreview: string;
2844
- agentName: string;
2845
- agentId: number;
2846
- type: IntentType;
2847
- createdAt: string;
2848
- }
2849
- /** WebSocket message: initial batch of recent listings */
2850
- interface FeedInitialMessage {
2851
- type: 'initial';
2852
- listings: FeedListing[];
2853
- }
2854
- /** WebSocket message: single new listing */
2855
- interface FeedNewMessage {
2856
- type: 'new';
2857
- listing: FeedListing;
2858
- }
2859
- type FeedMessage = FeedInitialMessage | FeedNewMessage;
2860
- /** Callback for live feed events */
2861
- type FeedListener = (message: FeedMessage) => void;
2862
-
2863
- /**
2864
- * Market Module
2865
- *
2866
- * Intent bulletin board — post and discover intents (buy, sell,
2867
- * service, announcement, other) with secp256k1-signed requests
2868
- * tied to the wallet identity. Includes real-time feed via WebSocket.
2869
- */
2870
-
2871
- declare class MarketModule {
2872
- private readonly apiUrl;
2873
- private readonly timeout;
2874
- private identity;
2875
- private registered;
2876
- constructor(config?: MarketModuleConfig);
2877
- /** Called by Sphere after construction */
2878
- initialize(deps: MarketModuleDependencies): void;
2879
- /** No-op — stateless module */
2880
- load(): Promise<void>;
2881
- /** No-op — stateless module */
2882
- destroy(): void;
2883
- /** Post a new intent (agent is auto-registered on first post) */
2884
- postIntent(intent: PostIntentRequest): Promise<PostIntentResult>;
2885
- /** Semantic search for intents (public — no auth required) */
2886
- search(query: string, opts?: SearchOptions): Promise<SearchResult>;
2887
- /** List own intents (authenticated) */
2888
- getMyIntents(): Promise<MarketIntent[]>;
2889
- /** Close (delete) an intent */
2890
- closeIntent(intentId: string): Promise<void>;
2891
- /** Fetch the most recent listings via REST (public — no auth required) */
2892
- getRecentListings(): Promise<FeedListing[]>;
2893
- /**
2894
- * Subscribe to the live listing feed via WebSocket.
2895
- * Returns an unsubscribe function that closes the connection.
2896
- *
2897
- * Requires a WebSocket implementation — works natively in browsers
2898
- * and in Node.js 21+ (or with the `ws` package).
2899
- */
2900
- subscribeFeed(listener: FeedListener): () => void;
2901
- private ensureIdentity;
2902
- /** Register the agent's public key with the server (idempotent) */
2903
- private ensureRegistered;
2904
- private parseResponse;
2905
- private apiPost;
2906
- private apiGet;
2907
- private apiDelete;
2908
- private apiPublicPost;
2909
- }
2910
-
2911
2764
  /** Network configurations */
2912
2765
  declare const NETWORKS: {
2913
2766
  readonly mainnet: {
@@ -3053,8 +2906,6 @@ interface SphereCreateOptions {
3053
2906
  groupChat?: GroupChatModuleConfig | boolean;
3054
2907
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
3055
2908
  password?: string;
3056
- /** Market module configuration. true = enable with defaults, object = custom config. */
3057
- market?: MarketModuleConfig | boolean;
3058
2909
  }
3059
2910
  /** Options for loading existing wallet */
3060
2911
  interface SphereLoadOptions {
@@ -3080,8 +2931,6 @@ interface SphereLoadOptions {
3080
2931
  groupChat?: GroupChatModuleConfig | boolean;
3081
2932
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
3082
2933
  password?: string;
3083
- /** Market module configuration. true = enable with defaults, object = custom config. */
3084
- market?: MarketModuleConfig | boolean;
3085
2934
  }
3086
2935
  /** Options for importing a wallet */
3087
2936
  interface SphereImportOptions {
@@ -3115,8 +2964,6 @@ interface SphereImportOptions {
3115
2964
  groupChat?: GroupChatModuleConfig | boolean;
3116
2965
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
3117
2966
  password?: string;
3118
- /** Market module configuration. true = enable with defaults, object = custom config. */
3119
- market?: MarketModuleConfig | boolean;
3120
2967
  }
3121
2968
  /** L1 (ALPHA blockchain) configuration */
3122
2969
  interface L1Config {
@@ -3164,8 +3011,6 @@ interface SphereInitOptions {
3164
3011
  groupChat?: GroupChatModuleConfig | boolean;
3165
3012
  /** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
3166
3013
  password?: string;
3167
- /** Market module configuration. true = enable with defaults, object = custom config. */
3168
- market?: MarketModuleConfig | boolean;
3169
3014
  }
3170
3015
  /** Result of init operation */
3171
3016
  interface SphereInitResult {
@@ -3203,7 +3048,6 @@ declare class Sphere {
3203
3048
  private _payments;
3204
3049
  private _communications;
3205
3050
  private _groupChat;
3206
- private _market;
3207
3051
  private eventHandlers;
3208
3052
  private _disabledProviders;
3209
3053
  private _providerEventCleanups;
@@ -3252,12 +3096,15 @@ declare class Sphere {
3252
3096
  */
3253
3097
  private static resolveGroupChatConfig;
3254
3098
  /**
3255
- * Resolve market module config from Sphere.init() options.
3256
- * - `true` → enable with default API URL
3257
- * - `MarketModuleConfig` pass through with defaults
3258
- * - `undefined` no market module
3099
+ * Configure TokenRegistry in the main bundle context.
3100
+ *
3101
+ * The provider factory functions (createBrowserProviders / createNodeProviders)
3102
+ * are compiled into separate bundles by tsup, each with their own inlined copy
3103
+ * of TokenRegistry. Their TokenRegistry.configure() call configures a different
3104
+ * singleton than the one used by PaymentsModule (which lives in the main bundle).
3105
+ * This method ensures the main bundle's TokenRegistry is properly configured.
3259
3106
  */
3260
- private static resolveMarketConfig;
3107
+ private static configureTokenRegistry;
3261
3108
  /**
3262
3109
  * Create new wallet with mnemonic
3263
3110
  */
@@ -3316,8 +3163,6 @@ declare class Sphere {
3316
3163
  get communications(): CommunicationsModule;
3317
3164
  /** Group chat module (NIP-29). Null if not configured. */
3318
3165
  get groupChat(): GroupChatModule | null;
3319
- /** Market module (intent bulletin board). Null if not configured. */
3320
- get market(): MarketModule | null;
3321
3166
  /** Current identity (public info only) */
3322
3167
  get identity(): Identity | null;
3323
3168
  /** Is ready */