@unicitylabs/sphere-sdk 0.3.6 → 0.3.8

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.
@@ -1676,6 +1676,7 @@ interface MintResult {
1676
1676
  * Platform-independent abstraction for fetching token market prices.
1677
1677
  * Does not extend BaseProvider — stateless HTTP client with internal caching.
1678
1678
  */
1679
+
1679
1680
  /**
1680
1681
  * Supported price provider platforms
1681
1682
  */
@@ -1720,7 +1721,7 @@ interface PriceProvider {
1720
1721
  /**
1721
1722
  * Get price for a single token
1722
1723
  * @param tokenName - Token name (e.g., 'bitcoin')
1723
- * @returns Token price or null if not available
1724
+ * @returns Token price (zero-price entry for tokens not listed on the platform), or null on network error with no cache
1724
1725
  */
1725
1726
  getPrice(tokenName: string): Promise<TokenPrice | null>;
1726
1727
  /**
@@ -2704,154 +2705,6 @@ declare class GroupChatModule {
2704
2705
  private randomId;
2705
2706
  }
2706
2707
 
2707
- /**
2708
- * Market Module Types
2709
- * Intent bulletin board for posting and discovering intents,
2710
- * plus real-time feed subscription.
2711
- */
2712
- type IntentType = 'buy' | 'sell' | 'service' | 'announcement' | 'other' | (string & {});
2713
- type IntentStatus = 'active' | 'closed' | 'expired';
2714
- interface MarketModuleConfig {
2715
- /** Market API base URL (default: https://market-api.unicity.network) */
2716
- apiUrl?: string;
2717
- /** Request timeout in ms (default: 30000) */
2718
- timeout?: number;
2719
- }
2720
- interface MarketModuleDependencies {
2721
- identity: FullIdentity;
2722
- emitEvent: <T extends SphereEventType>(type: T, data: SphereEventMap[T]) => void;
2723
- }
2724
- interface PostIntentRequest {
2725
- description: string;
2726
- intentType: IntentType;
2727
- category?: string;
2728
- price?: number;
2729
- currency?: string;
2730
- location?: string;
2731
- contactHandle?: string;
2732
- expiresInDays?: number;
2733
- }
2734
- interface PostIntentResult {
2735
- intentId: string;
2736
- message: string;
2737
- expiresAt: string;
2738
- }
2739
- interface MarketIntent {
2740
- id: string;
2741
- intentType: IntentType;
2742
- category?: string;
2743
- price?: string;
2744
- currency: string;
2745
- location?: string;
2746
- status: IntentStatus;
2747
- createdAt: string;
2748
- expiresAt: string;
2749
- }
2750
- interface SearchIntentResult {
2751
- id: string;
2752
- score: number;
2753
- agentNametag?: string;
2754
- agentPublicKey: string;
2755
- description: string;
2756
- intentType: IntentType;
2757
- category?: string;
2758
- price?: number;
2759
- currency: string;
2760
- location?: string;
2761
- contactMethod: string;
2762
- contactHandle?: string;
2763
- createdAt: string;
2764
- expiresAt: string;
2765
- }
2766
- interface SearchFilters {
2767
- intentType?: IntentType;
2768
- category?: string;
2769
- minPrice?: number;
2770
- maxPrice?: number;
2771
- location?: string;
2772
- /** Minimum similarity score (0–1). Results below this threshold are excluded (client-side). */
2773
- minScore?: number;
2774
- }
2775
- interface SearchOptions {
2776
- filters?: SearchFilters;
2777
- limit?: number;
2778
- }
2779
- interface SearchResult {
2780
- intents: SearchIntentResult[];
2781
- count: number;
2782
- }
2783
- /** A listing broadcast on the live feed */
2784
- interface FeedListing {
2785
- id: string;
2786
- title: string;
2787
- descriptionPreview: string;
2788
- agentName: string;
2789
- agentId: number;
2790
- type: IntentType;
2791
- createdAt: string;
2792
- }
2793
- /** WebSocket message: initial batch of recent listings */
2794
- interface FeedInitialMessage {
2795
- type: 'initial';
2796
- listings: FeedListing[];
2797
- }
2798
- /** WebSocket message: single new listing */
2799
- interface FeedNewMessage {
2800
- type: 'new';
2801
- listing: FeedListing;
2802
- }
2803
- type FeedMessage = FeedInitialMessage | FeedNewMessage;
2804
- /** Callback for live feed events */
2805
- type FeedListener = (message: FeedMessage) => void;
2806
-
2807
- /**
2808
- * Market Module
2809
- *
2810
- * Intent bulletin board — post and discover intents (buy, sell,
2811
- * service, announcement, other) with secp256k1-signed requests
2812
- * tied to the wallet identity. Includes real-time feed via WebSocket.
2813
- */
2814
-
2815
- declare class MarketModule {
2816
- private readonly apiUrl;
2817
- private readonly timeout;
2818
- private identity;
2819
- private registered;
2820
- constructor(config?: MarketModuleConfig);
2821
- /** Called by Sphere after construction */
2822
- initialize(deps: MarketModuleDependencies): void;
2823
- /** No-op — stateless module */
2824
- load(): Promise<void>;
2825
- /** No-op — stateless module */
2826
- destroy(): void;
2827
- /** Post a new intent (agent is auto-registered on first post) */
2828
- postIntent(intent: PostIntentRequest): Promise<PostIntentResult>;
2829
- /** Semantic search for intents (public — no auth required) */
2830
- search(query: string, opts?: SearchOptions): Promise<SearchResult>;
2831
- /** List own intents (authenticated) */
2832
- getMyIntents(): Promise<MarketIntent[]>;
2833
- /** Close (delete) an intent */
2834
- closeIntent(intentId: string): Promise<void>;
2835
- /** Fetch the most recent listings via REST (public — no auth required) */
2836
- getRecentListings(): Promise<FeedListing[]>;
2837
- /**
2838
- * Subscribe to the live listing feed via WebSocket.
2839
- * Returns an unsubscribe function that closes the connection.
2840
- *
2841
- * Requires a WebSocket implementation — works natively in browsers
2842
- * and in Node.js 21+ (or with the `ws` package).
2843
- */
2844
- subscribeFeed(listener: FeedListener): () => void;
2845
- private ensureIdentity;
2846
- /** Register the agent's public key with the server (idempotent) */
2847
- private ensureRegistered;
2848
- private parseResponse;
2849
- private apiPost;
2850
- private apiGet;
2851
- private apiDelete;
2852
- private apiPublicPost;
2853
- }
2854
-
2855
2708
  /** Network configurations */
2856
2709
  declare const NETWORKS: {
2857
2710
  readonly mainnet: {
@@ -2997,8 +2850,6 @@ interface SphereCreateOptions {
2997
2850
  groupChat?: GroupChatModuleConfig | boolean;
2998
2851
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
2999
2852
  password?: string;
3000
- /** Market module configuration. true = enable with defaults, object = custom config. */
3001
- market?: MarketModuleConfig | boolean;
3002
2853
  }
3003
2854
  /** Options for loading existing wallet */
3004
2855
  interface SphereLoadOptions {
@@ -3024,8 +2875,6 @@ interface SphereLoadOptions {
3024
2875
  groupChat?: GroupChatModuleConfig | boolean;
3025
2876
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
3026
2877
  password?: string;
3027
- /** Market module configuration. true = enable with defaults, object = custom config. */
3028
- market?: MarketModuleConfig | boolean;
3029
2878
  }
3030
2879
  /** Options for importing a wallet */
3031
2880
  interface SphereImportOptions {
@@ -3059,8 +2908,6 @@ interface SphereImportOptions {
3059
2908
  groupChat?: GroupChatModuleConfig | boolean;
3060
2909
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
3061
2910
  password?: string;
3062
- /** Market module configuration. true = enable with defaults, object = custom config. */
3063
- market?: MarketModuleConfig | boolean;
3064
2911
  }
3065
2912
  /** L1 (ALPHA blockchain) configuration */
3066
2913
  interface L1Config {
@@ -3108,8 +2955,6 @@ interface SphereInitOptions {
3108
2955
  groupChat?: GroupChatModuleConfig | boolean;
3109
2956
  /** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
3110
2957
  password?: string;
3111
- /** Market module configuration. true = enable with defaults, object = custom config. */
3112
- market?: MarketModuleConfig | boolean;
3113
2958
  }
3114
2959
  /** Result of init operation */
3115
2960
  interface SphereInitResult {
@@ -3147,7 +2992,6 @@ declare class Sphere {
3147
2992
  private _payments;
3148
2993
  private _communications;
3149
2994
  private _groupChat;
3150
- private _market;
3151
2995
  private eventHandlers;
3152
2996
  private _disabledProviders;
3153
2997
  private _providerEventCleanups;
@@ -3196,12 +3040,15 @@ declare class Sphere {
3196
3040
  */
3197
3041
  private static resolveGroupChatConfig;
3198
3042
  /**
3199
- * Resolve market module config from Sphere.init() options.
3200
- * - `true` → enable with default API URL
3201
- * - `MarketModuleConfig` pass through with defaults
3202
- * - `undefined` no market module
3043
+ * Configure TokenRegistry in the main bundle context.
3044
+ *
3045
+ * The provider factory functions (createBrowserProviders / createNodeProviders)
3046
+ * are compiled into separate bundles by tsup, each with their own inlined copy
3047
+ * of TokenRegistry. Their TokenRegistry.configure() call configures a different
3048
+ * singleton than the one used by PaymentsModule (which lives in the main bundle).
3049
+ * This method ensures the main bundle's TokenRegistry is properly configured.
3203
3050
  */
3204
- private static resolveMarketConfig;
3051
+ private static configureTokenRegistry;
3205
3052
  /**
3206
3053
  * Create new wallet with mnemonic
3207
3054
  */
@@ -3260,8 +3107,6 @@ declare class Sphere {
3260
3107
  get communications(): CommunicationsModule;
3261
3108
  /** Group chat module (NIP-29). Null if not configured. */
3262
3109
  get groupChat(): GroupChatModule | null;
3263
- /** Market module (intent bulletin board). Null if not configured. */
3264
- get market(): MarketModule | null;
3265
3110
  /** Current identity (public info only) */
3266
3111
  get identity(): Identity | null;
3267
3112
  /** Is ready */
@@ -1676,6 +1676,7 @@ interface MintResult {
1676
1676
  * Platform-independent abstraction for fetching token market prices.
1677
1677
  * Does not extend BaseProvider — stateless HTTP client with internal caching.
1678
1678
  */
1679
+
1679
1680
  /**
1680
1681
  * Supported price provider platforms
1681
1682
  */
@@ -1720,7 +1721,7 @@ interface PriceProvider {
1720
1721
  /**
1721
1722
  * Get price for a single token
1722
1723
  * @param tokenName - Token name (e.g., 'bitcoin')
1723
- * @returns Token price or null if not available
1724
+ * @returns Token price (zero-price entry for tokens not listed on the platform), or null on network error with no cache
1724
1725
  */
1725
1726
  getPrice(tokenName: string): Promise<TokenPrice | null>;
1726
1727
  /**
@@ -2704,154 +2705,6 @@ declare class GroupChatModule {
2704
2705
  private randomId;
2705
2706
  }
2706
2707
 
2707
- /**
2708
- * Market Module Types
2709
- * Intent bulletin board for posting and discovering intents,
2710
- * plus real-time feed subscription.
2711
- */
2712
- type IntentType = 'buy' | 'sell' | 'service' | 'announcement' | 'other' | (string & {});
2713
- type IntentStatus = 'active' | 'closed' | 'expired';
2714
- interface MarketModuleConfig {
2715
- /** Market API base URL (default: https://market-api.unicity.network) */
2716
- apiUrl?: string;
2717
- /** Request timeout in ms (default: 30000) */
2718
- timeout?: number;
2719
- }
2720
- interface MarketModuleDependencies {
2721
- identity: FullIdentity;
2722
- emitEvent: <T extends SphereEventType>(type: T, data: SphereEventMap[T]) => void;
2723
- }
2724
- interface PostIntentRequest {
2725
- description: string;
2726
- intentType: IntentType;
2727
- category?: string;
2728
- price?: number;
2729
- currency?: string;
2730
- location?: string;
2731
- contactHandle?: string;
2732
- expiresInDays?: number;
2733
- }
2734
- interface PostIntentResult {
2735
- intentId: string;
2736
- message: string;
2737
- expiresAt: string;
2738
- }
2739
- interface MarketIntent {
2740
- id: string;
2741
- intentType: IntentType;
2742
- category?: string;
2743
- price?: string;
2744
- currency: string;
2745
- location?: string;
2746
- status: IntentStatus;
2747
- createdAt: string;
2748
- expiresAt: string;
2749
- }
2750
- interface SearchIntentResult {
2751
- id: string;
2752
- score: number;
2753
- agentNametag?: string;
2754
- agentPublicKey: string;
2755
- description: string;
2756
- intentType: IntentType;
2757
- category?: string;
2758
- price?: number;
2759
- currency: string;
2760
- location?: string;
2761
- contactMethod: string;
2762
- contactHandle?: string;
2763
- createdAt: string;
2764
- expiresAt: string;
2765
- }
2766
- interface SearchFilters {
2767
- intentType?: IntentType;
2768
- category?: string;
2769
- minPrice?: number;
2770
- maxPrice?: number;
2771
- location?: string;
2772
- /** Minimum similarity score (0–1). Results below this threshold are excluded (client-side). */
2773
- minScore?: number;
2774
- }
2775
- interface SearchOptions {
2776
- filters?: SearchFilters;
2777
- limit?: number;
2778
- }
2779
- interface SearchResult {
2780
- intents: SearchIntentResult[];
2781
- count: number;
2782
- }
2783
- /** A listing broadcast on the live feed */
2784
- interface FeedListing {
2785
- id: string;
2786
- title: string;
2787
- descriptionPreview: string;
2788
- agentName: string;
2789
- agentId: number;
2790
- type: IntentType;
2791
- createdAt: string;
2792
- }
2793
- /** WebSocket message: initial batch of recent listings */
2794
- interface FeedInitialMessage {
2795
- type: 'initial';
2796
- listings: FeedListing[];
2797
- }
2798
- /** WebSocket message: single new listing */
2799
- interface FeedNewMessage {
2800
- type: 'new';
2801
- listing: FeedListing;
2802
- }
2803
- type FeedMessage = FeedInitialMessage | FeedNewMessage;
2804
- /** Callback for live feed events */
2805
- type FeedListener = (message: FeedMessage) => void;
2806
-
2807
- /**
2808
- * Market Module
2809
- *
2810
- * Intent bulletin board — post and discover intents (buy, sell,
2811
- * service, announcement, other) with secp256k1-signed requests
2812
- * tied to the wallet identity. Includes real-time feed via WebSocket.
2813
- */
2814
-
2815
- declare class MarketModule {
2816
- private readonly apiUrl;
2817
- private readonly timeout;
2818
- private identity;
2819
- private registered;
2820
- constructor(config?: MarketModuleConfig);
2821
- /** Called by Sphere after construction */
2822
- initialize(deps: MarketModuleDependencies): void;
2823
- /** No-op — stateless module */
2824
- load(): Promise<void>;
2825
- /** No-op — stateless module */
2826
- destroy(): void;
2827
- /** Post a new intent (agent is auto-registered on first post) */
2828
- postIntent(intent: PostIntentRequest): Promise<PostIntentResult>;
2829
- /** Semantic search for intents (public — no auth required) */
2830
- search(query: string, opts?: SearchOptions): Promise<SearchResult>;
2831
- /** List own intents (authenticated) */
2832
- getMyIntents(): Promise<MarketIntent[]>;
2833
- /** Close (delete) an intent */
2834
- closeIntent(intentId: string): Promise<void>;
2835
- /** Fetch the most recent listings via REST (public — no auth required) */
2836
- getRecentListings(): Promise<FeedListing[]>;
2837
- /**
2838
- * Subscribe to the live listing feed via WebSocket.
2839
- * Returns an unsubscribe function that closes the connection.
2840
- *
2841
- * Requires a WebSocket implementation — works natively in browsers
2842
- * and in Node.js 21+ (or with the `ws` package).
2843
- */
2844
- subscribeFeed(listener: FeedListener): () => void;
2845
- private ensureIdentity;
2846
- /** Register the agent's public key with the server (idempotent) */
2847
- private ensureRegistered;
2848
- private parseResponse;
2849
- private apiPost;
2850
- private apiGet;
2851
- private apiDelete;
2852
- private apiPublicPost;
2853
- }
2854
-
2855
2708
  /** Network configurations */
2856
2709
  declare const NETWORKS: {
2857
2710
  readonly mainnet: {
@@ -2997,8 +2850,6 @@ interface SphereCreateOptions {
2997
2850
  groupChat?: GroupChatModuleConfig | boolean;
2998
2851
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
2999
2852
  password?: string;
3000
- /** Market module configuration. true = enable with defaults, object = custom config. */
3001
- market?: MarketModuleConfig | boolean;
3002
2853
  }
3003
2854
  /** Options for loading existing wallet */
3004
2855
  interface SphereLoadOptions {
@@ -3024,8 +2875,6 @@ interface SphereLoadOptions {
3024
2875
  groupChat?: GroupChatModuleConfig | boolean;
3025
2876
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
3026
2877
  password?: string;
3027
- /** Market module configuration. true = enable with defaults, object = custom config. */
3028
- market?: MarketModuleConfig | boolean;
3029
2878
  }
3030
2879
  /** Options for importing a wallet */
3031
2880
  interface SphereImportOptions {
@@ -3059,8 +2908,6 @@ interface SphereImportOptions {
3059
2908
  groupChat?: GroupChatModuleConfig | boolean;
3060
2909
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
3061
2910
  password?: string;
3062
- /** Market module configuration. true = enable with defaults, object = custom config. */
3063
- market?: MarketModuleConfig | boolean;
3064
2911
  }
3065
2912
  /** L1 (ALPHA blockchain) configuration */
3066
2913
  interface L1Config {
@@ -3108,8 +2955,6 @@ interface SphereInitOptions {
3108
2955
  groupChat?: GroupChatModuleConfig | boolean;
3109
2956
  /** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
3110
2957
  password?: string;
3111
- /** Market module configuration. true = enable with defaults, object = custom config. */
3112
- market?: MarketModuleConfig | boolean;
3113
2958
  }
3114
2959
  /** Result of init operation */
3115
2960
  interface SphereInitResult {
@@ -3147,7 +2992,6 @@ declare class Sphere {
3147
2992
  private _payments;
3148
2993
  private _communications;
3149
2994
  private _groupChat;
3150
- private _market;
3151
2995
  private eventHandlers;
3152
2996
  private _disabledProviders;
3153
2997
  private _providerEventCleanups;
@@ -3196,12 +3040,15 @@ declare class Sphere {
3196
3040
  */
3197
3041
  private static resolveGroupChatConfig;
3198
3042
  /**
3199
- * Resolve market module config from Sphere.init() options.
3200
- * - `true` → enable with default API URL
3201
- * - `MarketModuleConfig` pass through with defaults
3202
- * - `undefined` no market module
3043
+ * Configure TokenRegistry in the main bundle context.
3044
+ *
3045
+ * The provider factory functions (createBrowserProviders / createNodeProviders)
3046
+ * are compiled into separate bundles by tsup, each with their own inlined copy
3047
+ * of TokenRegistry. Their TokenRegistry.configure() call configures a different
3048
+ * singleton than the one used by PaymentsModule (which lives in the main bundle).
3049
+ * This method ensures the main bundle's TokenRegistry is properly configured.
3203
3050
  */
3204
- private static resolveMarketConfig;
3051
+ private static configureTokenRegistry;
3205
3052
  /**
3206
3053
  * Create new wallet with mnemonic
3207
3054
  */
@@ -3260,8 +3107,6 @@ declare class Sphere {
3260
3107
  get communications(): CommunicationsModule;
3261
3108
  /** Group chat module (NIP-29). Null if not configured. */
3262
3109
  get groupChat(): GroupChatModule | null;
3263
- /** Market module (intent bulletin board). Null if not configured. */
3264
- get market(): MarketModule | null;
3265
3110
  /** Current identity (public info only) */
3266
3111
  get identity(): Identity | null;
3267
3112
  /** Is ready */