@unicitylabs/sphere-sdk 0.3.4 → 0.3.6

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.
@@ -2704,6 +2704,154 @@ declare class GroupChatModule {
2704
2704
  private randomId;
2705
2705
  }
2706
2706
 
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
+
2707
2855
  /** Network configurations */
2708
2856
  declare const NETWORKS: {
2709
2857
  readonly mainnet: {
@@ -2713,6 +2861,7 @@ declare const NETWORKS: {
2713
2861
  readonly ipfsGateways: readonly ["https://unicity-ipfs1.dyndns.org"];
2714
2862
  readonly electrumUrl: "wss://fulcrum.alpha.unicity.network:50004";
2715
2863
  readonly groupRelays: readonly ["wss://sphere-relay.unicity.network"];
2864
+ readonly tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet.json";
2716
2865
  };
2717
2866
  readonly testnet: {
2718
2867
  readonly name: "Testnet";
@@ -2721,6 +2870,7 @@ declare const NETWORKS: {
2721
2870
  readonly ipfsGateways: readonly ["https://unicity-ipfs1.dyndns.org"];
2722
2871
  readonly electrumUrl: "wss://fulcrum.alpha.testnet.unicity.network:50004";
2723
2872
  readonly groupRelays: readonly ["wss://sphere-relay.unicity.network"];
2873
+ readonly tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet.json";
2724
2874
  };
2725
2875
  readonly dev: {
2726
2876
  readonly name: "Development";
@@ -2729,6 +2879,7 @@ declare const NETWORKS: {
2729
2879
  readonly ipfsGateways: readonly ["https://unicity-ipfs1.dyndns.org"];
2730
2880
  readonly electrumUrl: "wss://fulcrum.alpha.testnet.unicity.network:50004";
2731
2881
  readonly groupRelays: readonly ["wss://sphere-relay.unicity.network"];
2882
+ readonly tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet.json";
2732
2883
  };
2733
2884
  };
2734
2885
  type NetworkType = keyof typeof NETWORKS;
@@ -2846,6 +2997,8 @@ interface SphereCreateOptions {
2846
2997
  groupChat?: GroupChatModuleConfig | boolean;
2847
2998
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
2848
2999
  password?: string;
3000
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3001
+ market?: MarketModuleConfig | boolean;
2849
3002
  }
2850
3003
  /** Options for loading existing wallet */
2851
3004
  interface SphereLoadOptions {
@@ -2871,6 +3024,8 @@ interface SphereLoadOptions {
2871
3024
  groupChat?: GroupChatModuleConfig | boolean;
2872
3025
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
2873
3026
  password?: string;
3027
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3028
+ market?: MarketModuleConfig | boolean;
2874
3029
  }
2875
3030
  /** Options for importing a wallet */
2876
3031
  interface SphereImportOptions {
@@ -2904,6 +3059,8 @@ interface SphereImportOptions {
2904
3059
  groupChat?: GroupChatModuleConfig | boolean;
2905
3060
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
2906
3061
  password?: string;
3062
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3063
+ market?: MarketModuleConfig | boolean;
2907
3064
  }
2908
3065
  /** L1 (ALPHA blockchain) configuration */
2909
3066
  interface L1Config {
@@ -2951,6 +3108,8 @@ interface SphereInitOptions {
2951
3108
  groupChat?: GroupChatModuleConfig | boolean;
2952
3109
  /** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
2953
3110
  password?: string;
3111
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3112
+ market?: MarketModuleConfig | boolean;
2954
3113
  }
2955
3114
  /** Result of init operation */
2956
3115
  interface SphereInitResult {
@@ -2988,6 +3147,7 @@ declare class Sphere {
2988
3147
  private _payments;
2989
3148
  private _communications;
2990
3149
  private _groupChat;
3150
+ private _market;
2991
3151
  private eventHandlers;
2992
3152
  private _disabledProviders;
2993
3153
  private _providerEventCleanups;
@@ -3035,6 +3195,13 @@ declare class Sphere {
3035
3195
  * (different input shape: { enabled?, relays? }). Both fill relay URLs from network defaults.
3036
3196
  */
3037
3197
  private static resolveGroupChatConfig;
3198
+ /**
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
3203
+ */
3204
+ private static resolveMarketConfig;
3038
3205
  /**
3039
3206
  * Create new wallet with mnemonic
3040
3207
  */
@@ -3093,6 +3260,8 @@ declare class Sphere {
3093
3260
  get communications(): CommunicationsModule;
3094
3261
  /** Group chat module (NIP-29). Null if not configured. */
3095
3262
  get groupChat(): GroupChatModule | null;
3263
+ /** Market module (intent bulletin board). Null if not configured. */
3264
+ get market(): MarketModule | null;
3096
3265
  /** Current identity (public info only) */
3097
3266
  get identity(): Identity | null;
3098
3267
  /** Is ready */
@@ -2704,6 +2704,154 @@ declare class GroupChatModule {
2704
2704
  private randomId;
2705
2705
  }
2706
2706
 
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
+
2707
2855
  /** Network configurations */
2708
2856
  declare const NETWORKS: {
2709
2857
  readonly mainnet: {
@@ -2713,6 +2861,7 @@ declare const NETWORKS: {
2713
2861
  readonly ipfsGateways: readonly ["https://unicity-ipfs1.dyndns.org"];
2714
2862
  readonly electrumUrl: "wss://fulcrum.alpha.unicity.network:50004";
2715
2863
  readonly groupRelays: readonly ["wss://sphere-relay.unicity.network"];
2864
+ readonly tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet.json";
2716
2865
  };
2717
2866
  readonly testnet: {
2718
2867
  readonly name: "Testnet";
@@ -2721,6 +2870,7 @@ declare const NETWORKS: {
2721
2870
  readonly ipfsGateways: readonly ["https://unicity-ipfs1.dyndns.org"];
2722
2871
  readonly electrumUrl: "wss://fulcrum.alpha.testnet.unicity.network:50004";
2723
2872
  readonly groupRelays: readonly ["wss://sphere-relay.unicity.network"];
2873
+ readonly tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet.json";
2724
2874
  };
2725
2875
  readonly dev: {
2726
2876
  readonly name: "Development";
@@ -2729,6 +2879,7 @@ declare const NETWORKS: {
2729
2879
  readonly ipfsGateways: readonly ["https://unicity-ipfs1.dyndns.org"];
2730
2880
  readonly electrumUrl: "wss://fulcrum.alpha.testnet.unicity.network:50004";
2731
2881
  readonly groupRelays: readonly ["wss://sphere-relay.unicity.network"];
2882
+ readonly tokenRegistryUrl: "https://raw.githubusercontent.com/unicitynetwork/unicity-ids/refs/heads/main/unicity-ids.testnet.json";
2732
2883
  };
2733
2884
  };
2734
2885
  type NetworkType = keyof typeof NETWORKS;
@@ -2846,6 +2997,8 @@ interface SphereCreateOptions {
2846
2997
  groupChat?: GroupChatModuleConfig | boolean;
2847
2998
  /** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
2848
2999
  password?: string;
3000
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3001
+ market?: MarketModuleConfig | boolean;
2849
3002
  }
2850
3003
  /** Options for loading existing wallet */
2851
3004
  interface SphereLoadOptions {
@@ -2871,6 +3024,8 @@ interface SphereLoadOptions {
2871
3024
  groupChat?: GroupChatModuleConfig | boolean;
2872
3025
  /** Optional password to decrypt the wallet. Must match the password used during creation. */
2873
3026
  password?: string;
3027
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3028
+ market?: MarketModuleConfig | boolean;
2874
3029
  }
2875
3030
  /** Options for importing a wallet */
2876
3031
  interface SphereImportOptions {
@@ -2904,6 +3059,8 @@ interface SphereImportOptions {
2904
3059
  groupChat?: GroupChatModuleConfig | boolean;
2905
3060
  /** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
2906
3061
  password?: string;
3062
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3063
+ market?: MarketModuleConfig | boolean;
2907
3064
  }
2908
3065
  /** L1 (ALPHA blockchain) configuration */
2909
3066
  interface L1Config {
@@ -2951,6 +3108,8 @@ interface SphereInitOptions {
2951
3108
  groupChat?: GroupChatModuleConfig | boolean;
2952
3109
  /** Optional password to encrypt/decrypt the wallet. If omitted, mnemonic is stored as plaintext. */
2953
3110
  password?: string;
3111
+ /** Market module configuration. true = enable with defaults, object = custom config. */
3112
+ market?: MarketModuleConfig | boolean;
2954
3113
  }
2955
3114
  /** Result of init operation */
2956
3115
  interface SphereInitResult {
@@ -2988,6 +3147,7 @@ declare class Sphere {
2988
3147
  private _payments;
2989
3148
  private _communications;
2990
3149
  private _groupChat;
3150
+ private _market;
2991
3151
  private eventHandlers;
2992
3152
  private _disabledProviders;
2993
3153
  private _providerEventCleanups;
@@ -3035,6 +3195,13 @@ declare class Sphere {
3035
3195
  * (different input shape: { enabled?, relays? }). Both fill relay URLs from network defaults.
3036
3196
  */
3037
3197
  private static resolveGroupChatConfig;
3198
+ /**
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
3203
+ */
3204
+ private static resolveMarketConfig;
3038
3205
  /**
3039
3206
  * Create new wallet with mnemonic
3040
3207
  */
@@ -3093,6 +3260,8 @@ declare class Sphere {
3093
3260
  get communications(): CommunicationsModule;
3094
3261
  /** Group chat module (NIP-29). Null if not configured. */
3095
3262
  get groupChat(): GroupChatModule | null;
3263
+ /** Market module (intent bulletin board). Null if not configured. */
3264
+ get market(): MarketModule | null;
3096
3265
  /** Current identity (public info only) */
3097
3266
  get identity(): Identity | null;
3098
3267
  /** Is ready */