@unicitylabs/sphere-sdk 0.3.8 → 0.4.0

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 (49) 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 +2744 -56
  8. package/dist/core/index.cjs.map +1 -1
  9. package/dist/core/index.d.cts +277 -3
  10. package/dist/core/index.d.ts +277 -3
  11. package/dist/core/index.js +2740 -52
  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 +583 -45
  20. package/dist/impl/browser/index.cjs.map +1 -1
  21. package/dist/impl/browser/index.js +587 -46
  22. package/dist/impl/browser/index.js.map +1 -1
  23. package/dist/impl/browser/ipfs.cjs.map +1 -1
  24. package/dist/impl/browser/ipfs.js.map +1 -1
  25. package/dist/impl/nodejs/connect/index.cjs +372 -0
  26. package/dist/impl/nodejs/connect/index.cjs.map +1 -0
  27. package/dist/impl/nodejs/connect/index.d.cts +178 -0
  28. package/dist/impl/nodejs/connect/index.d.ts +178 -0
  29. package/dist/impl/nodejs/connect/index.js +333 -0
  30. package/dist/impl/nodejs/connect/index.js.map +1 -0
  31. package/dist/impl/nodejs/index.cjs +266 -12
  32. package/dist/impl/nodejs/index.cjs.map +1 -1
  33. package/dist/impl/nodejs/index.d.cts +96 -0
  34. package/dist/impl/nodejs/index.d.ts +96 -0
  35. package/dist/impl/nodejs/index.js +270 -13
  36. package/dist/impl/nodejs/index.js.map +1 -1
  37. package/dist/index.cjs +2761 -56
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +375 -5
  40. package/dist/index.d.ts +375 -5
  41. package/dist/index.js +2750 -52
  42. package/dist/index.js.map +1 -1
  43. package/dist/l1/index.cjs +5 -1
  44. package/dist/l1/index.cjs.map +1 -1
  45. package/dist/l1/index.d.cts +2 -1
  46. package/dist/l1/index.d.ts +2 -1
  47. package/dist/l1/index.js +5 -1
  48. package/dist/l1/index.js.map +1 -1
  49. package/package.json +31 -1
@@ -46,6 +46,11 @@ interface Identity {
46
46
  interface FullIdentity extends Identity {
47
47
  readonly privateKey: string;
48
48
  }
49
+ interface ComposingIndicator {
50
+ readonly senderPubkey: string;
51
+ readonly senderNametag?: string;
52
+ readonly expiresIn: number;
53
+ }
49
54
  /**
50
55
  * Minimal data stored in persistent storage for a tracked address.
51
56
  * Only contains user state — derived fields are computed on load.
@@ -422,6 +427,38 @@ interface TransportProvider extends BaseProvider {
422
427
  * @returns Unsubscribe function
423
428
  */
424
429
  onPaymentRequestResponse?(handler: PaymentRequestResponseHandler): () => void;
430
+ /**
431
+ * Send a read receipt for a message
432
+ * @param recipientTransportPubkey - Transport pubkey of the message sender
433
+ * @param messageEventId - Event ID of the message being acknowledged
434
+ */
435
+ sendReadReceipt?(recipientTransportPubkey: string, messageEventId: string): Promise<void>;
436
+ /**
437
+ * Subscribe to incoming read receipts
438
+ * @returns Unsubscribe function
439
+ */
440
+ onReadReceipt?(handler: ReadReceiptHandler): () => void;
441
+ /**
442
+ * Send typing indicator to a recipient
443
+ * @param recipientTransportPubkey - Transport pubkey of the conversation partner
444
+ */
445
+ sendTypingIndicator?(recipientTransportPubkey: string): Promise<void>;
446
+ /**
447
+ * Subscribe to incoming typing indicators
448
+ * @returns Unsubscribe function
449
+ */
450
+ onTypingIndicator?(handler: TypingIndicatorHandler): () => void;
451
+ /**
452
+ * Send composing indicator to a recipient using NIP-44 encrypted gift wrap
453
+ * @param recipientTransportPubkey - Transport pubkey of the conversation partner
454
+ * @param content - JSON payload with senderNametag and expiresIn
455
+ */
456
+ sendComposingIndicator?(recipientTransportPubkey: string, content: string): Promise<void>;
457
+ /**
458
+ * Subscribe to incoming composing indicators
459
+ * @returns Unsubscribe function
460
+ */
461
+ onComposing?(handler: ComposingHandler): () => void;
425
462
  /**
426
463
  * Get list of configured relay URLs
427
464
  */
@@ -511,6 +548,10 @@ interface IncomingMessage {
511
548
  content: string;
512
549
  timestamp: number;
513
550
  encrypted: boolean;
551
+ /** Set when this is a self-wrap replay (sent message recovered from relay) */
552
+ isSelfWrap?: boolean;
553
+ /** Recipient pubkey — only present on self-wrap replays */
554
+ recipientTransportPubkey?: string;
514
555
  }
515
556
  type MessageHandler = (message: IncomingMessage) => void;
516
557
  interface TokenTransferPayload {
@@ -632,6 +673,25 @@ interface PeerInfo {
632
673
  /** Event timestamp */
633
674
  timestamp: number;
634
675
  }
676
+ interface IncomingReadReceipt {
677
+ /** Transport-specific pubkey of the sender who read the message */
678
+ senderTransportPubkey: string;
679
+ /** Event ID of the message that was read */
680
+ messageEventId: string;
681
+ /** Timestamp */
682
+ timestamp: number;
683
+ }
684
+ type ReadReceiptHandler = (receipt: IncomingReadReceipt) => void;
685
+ interface IncomingTypingIndicator {
686
+ /** Transport-specific pubkey of the sender who is typing */
687
+ senderTransportPubkey: string;
688
+ /** Sender's nametag (if known) */
689
+ senderNametag?: string;
690
+ /** Timestamp */
691
+ timestamp: number;
692
+ }
693
+ type TypingIndicatorHandler = (indicator: IncomingTypingIndicator) => void;
694
+ type ComposingHandler = (indicator: ComposingIndicator) => void;
635
695
 
636
696
  /**
637
697
  * WebSocket Abstraction
@@ -724,6 +784,10 @@ declare class NostrTransportProvider implements TransportProvider {
724
784
  private transferHandlers;
725
785
  private paymentRequestHandlers;
726
786
  private paymentRequestResponseHandlers;
787
+ private readReceiptHandlers;
788
+ private typingIndicatorHandlers;
789
+ private composingHandlers;
790
+ private pendingMessages;
727
791
  private broadcastHandlers;
728
792
  private eventCallbacks;
729
793
  constructor(config: NostrTransportProviderConfig);
@@ -773,6 +837,12 @@ declare class NostrTransportProvider implements TransportProvider {
773
837
  onPaymentRequest(handler: PaymentRequestHandler): () => void;
774
838
  sendPaymentRequestResponse(recipientPubkey: string, payload: PaymentRequestResponsePayload): Promise<string>;
775
839
  onPaymentRequestResponse(handler: PaymentRequestResponseHandler): () => void;
840
+ sendReadReceipt(recipientTransportPubkey: string, messageEventId: string): Promise<void>;
841
+ onReadReceipt(handler: ReadReceiptHandler): () => void;
842
+ sendTypingIndicator(recipientTransportPubkey: string): Promise<void>;
843
+ onTypingIndicator(handler: TypingIndicatorHandler): () => void;
844
+ onComposing(handler: ComposingHandler): () => void;
845
+ sendComposingIndicator(recipientPubkey: string, content: string): Promise<void>;
776
846
  /**
777
847
  * Resolve any identifier to full peer information.
778
848
  * Routes to the appropriate specific resolve method based on identifier format.
@@ -846,6 +916,12 @@ declare class NostrTransportProvider implements TransportProvider {
846
916
  private ensureConnected;
847
917
  private ensureReady;
848
918
  private emitEvent;
919
+ /**
920
+ * Create a NIP-17 gift wrap with a custom inner rumor kind.
921
+ * Replicates the three-layer NIP-59 envelope (rumor → seal → gift wrap)
922
+ * because NIP17.createGiftWrap hardcodes kind 14 for the inner rumor.
923
+ */
924
+ private createCustomKindGiftWrap;
849
925
  private log;
850
926
  }
851
927
 
@@ -1316,6 +1392,15 @@ interface BasePriceConfig {
1316
1392
  /** Enable debug logging */
1317
1393
  debug?: boolean;
1318
1394
  }
1395
+ /**
1396
+ * Base market module configuration
1397
+ */
1398
+ interface BaseMarketConfig {
1399
+ /** Market API base URL (default: https://market-api.unicity.network) */
1400
+ apiUrl?: string;
1401
+ /** Request timeout in ms (default: 30000) */
1402
+ timeout?: number;
1403
+ }
1319
1404
  /**
1320
1405
  * Base providers result
1321
1406
  * Common structure for all platforms
@@ -1331,6 +1416,13 @@ interface BaseProviders {
1331
1416
  price?: PriceProvider;
1332
1417
  }
1333
1418
 
1419
+ interface MarketModuleConfig {
1420
+ /** Market API base URL (default: https://market-api.unicity.network) */
1421
+ apiUrl?: string;
1422
+ /** Request timeout in ms (default: 30000) */
1423
+ timeout?: number;
1424
+ }
1425
+
1334
1426
  /** IPFS storage provider configuration */
1335
1427
  interface IpfsStorageConfig {
1336
1428
  /** Gateway URLs for HTTP API (defaults to Unicity dedicated nodes) */
@@ -1423,6 +1515,8 @@ interface NodeProvidersConfig {
1423
1515
  enabled?: boolean;
1424
1516
  relays?: string[];
1425
1517
  } | boolean;
1518
+ /** Market module configuration. true = enable with defaults, object = custom config */
1519
+ market?: BaseMarketConfig | boolean;
1426
1520
  }
1427
1521
  interface NodeProviders {
1428
1522
  storage: StorageProvider;
@@ -1437,6 +1531,8 @@ interface NodeProviders {
1437
1531
  ipfsTokenStorage?: TokenStorageProvider<TxfStorageDataBase>;
1438
1532
  /** Group chat config (resolved, for passing to Sphere.init) */
1439
1533
  groupChat?: GroupChatModuleConfig | boolean;
1534
+ /** Market module config (resolved, for passing to Sphere.init) */
1535
+ market?: MarketModuleConfig | boolean;
1440
1536
  }
1441
1537
  /**
1442
1538
  * Create all Node.js providers with default configuration
@@ -46,6 +46,11 @@ interface Identity {
46
46
  interface FullIdentity extends Identity {
47
47
  readonly privateKey: string;
48
48
  }
49
+ interface ComposingIndicator {
50
+ readonly senderPubkey: string;
51
+ readonly senderNametag?: string;
52
+ readonly expiresIn: number;
53
+ }
49
54
  /**
50
55
  * Minimal data stored in persistent storage for a tracked address.
51
56
  * Only contains user state — derived fields are computed on load.
@@ -422,6 +427,38 @@ interface TransportProvider extends BaseProvider {
422
427
  * @returns Unsubscribe function
423
428
  */
424
429
  onPaymentRequestResponse?(handler: PaymentRequestResponseHandler): () => void;
430
+ /**
431
+ * Send a read receipt for a message
432
+ * @param recipientTransportPubkey - Transport pubkey of the message sender
433
+ * @param messageEventId - Event ID of the message being acknowledged
434
+ */
435
+ sendReadReceipt?(recipientTransportPubkey: string, messageEventId: string): Promise<void>;
436
+ /**
437
+ * Subscribe to incoming read receipts
438
+ * @returns Unsubscribe function
439
+ */
440
+ onReadReceipt?(handler: ReadReceiptHandler): () => void;
441
+ /**
442
+ * Send typing indicator to a recipient
443
+ * @param recipientTransportPubkey - Transport pubkey of the conversation partner
444
+ */
445
+ sendTypingIndicator?(recipientTransportPubkey: string): Promise<void>;
446
+ /**
447
+ * Subscribe to incoming typing indicators
448
+ * @returns Unsubscribe function
449
+ */
450
+ onTypingIndicator?(handler: TypingIndicatorHandler): () => void;
451
+ /**
452
+ * Send composing indicator to a recipient using NIP-44 encrypted gift wrap
453
+ * @param recipientTransportPubkey - Transport pubkey of the conversation partner
454
+ * @param content - JSON payload with senderNametag and expiresIn
455
+ */
456
+ sendComposingIndicator?(recipientTransportPubkey: string, content: string): Promise<void>;
457
+ /**
458
+ * Subscribe to incoming composing indicators
459
+ * @returns Unsubscribe function
460
+ */
461
+ onComposing?(handler: ComposingHandler): () => void;
425
462
  /**
426
463
  * Get list of configured relay URLs
427
464
  */
@@ -511,6 +548,10 @@ interface IncomingMessage {
511
548
  content: string;
512
549
  timestamp: number;
513
550
  encrypted: boolean;
551
+ /** Set when this is a self-wrap replay (sent message recovered from relay) */
552
+ isSelfWrap?: boolean;
553
+ /** Recipient pubkey — only present on self-wrap replays */
554
+ recipientTransportPubkey?: string;
514
555
  }
515
556
  type MessageHandler = (message: IncomingMessage) => void;
516
557
  interface TokenTransferPayload {
@@ -632,6 +673,25 @@ interface PeerInfo {
632
673
  /** Event timestamp */
633
674
  timestamp: number;
634
675
  }
676
+ interface IncomingReadReceipt {
677
+ /** Transport-specific pubkey of the sender who read the message */
678
+ senderTransportPubkey: string;
679
+ /** Event ID of the message that was read */
680
+ messageEventId: string;
681
+ /** Timestamp */
682
+ timestamp: number;
683
+ }
684
+ type ReadReceiptHandler = (receipt: IncomingReadReceipt) => void;
685
+ interface IncomingTypingIndicator {
686
+ /** Transport-specific pubkey of the sender who is typing */
687
+ senderTransportPubkey: string;
688
+ /** Sender's nametag (if known) */
689
+ senderNametag?: string;
690
+ /** Timestamp */
691
+ timestamp: number;
692
+ }
693
+ type TypingIndicatorHandler = (indicator: IncomingTypingIndicator) => void;
694
+ type ComposingHandler = (indicator: ComposingIndicator) => void;
635
695
 
636
696
  /**
637
697
  * WebSocket Abstraction
@@ -724,6 +784,10 @@ declare class NostrTransportProvider implements TransportProvider {
724
784
  private transferHandlers;
725
785
  private paymentRequestHandlers;
726
786
  private paymentRequestResponseHandlers;
787
+ private readReceiptHandlers;
788
+ private typingIndicatorHandlers;
789
+ private composingHandlers;
790
+ private pendingMessages;
727
791
  private broadcastHandlers;
728
792
  private eventCallbacks;
729
793
  constructor(config: NostrTransportProviderConfig);
@@ -773,6 +837,12 @@ declare class NostrTransportProvider implements TransportProvider {
773
837
  onPaymentRequest(handler: PaymentRequestHandler): () => void;
774
838
  sendPaymentRequestResponse(recipientPubkey: string, payload: PaymentRequestResponsePayload): Promise<string>;
775
839
  onPaymentRequestResponse(handler: PaymentRequestResponseHandler): () => void;
840
+ sendReadReceipt(recipientTransportPubkey: string, messageEventId: string): Promise<void>;
841
+ onReadReceipt(handler: ReadReceiptHandler): () => void;
842
+ sendTypingIndicator(recipientTransportPubkey: string): Promise<void>;
843
+ onTypingIndicator(handler: TypingIndicatorHandler): () => void;
844
+ onComposing(handler: ComposingHandler): () => void;
845
+ sendComposingIndicator(recipientPubkey: string, content: string): Promise<void>;
776
846
  /**
777
847
  * Resolve any identifier to full peer information.
778
848
  * Routes to the appropriate specific resolve method based on identifier format.
@@ -846,6 +916,12 @@ declare class NostrTransportProvider implements TransportProvider {
846
916
  private ensureConnected;
847
917
  private ensureReady;
848
918
  private emitEvent;
919
+ /**
920
+ * Create a NIP-17 gift wrap with a custom inner rumor kind.
921
+ * Replicates the three-layer NIP-59 envelope (rumor → seal → gift wrap)
922
+ * because NIP17.createGiftWrap hardcodes kind 14 for the inner rumor.
923
+ */
924
+ private createCustomKindGiftWrap;
849
925
  private log;
850
926
  }
851
927
 
@@ -1316,6 +1392,15 @@ interface BasePriceConfig {
1316
1392
  /** Enable debug logging */
1317
1393
  debug?: boolean;
1318
1394
  }
1395
+ /**
1396
+ * Base market module configuration
1397
+ */
1398
+ interface BaseMarketConfig {
1399
+ /** Market API base URL (default: https://market-api.unicity.network) */
1400
+ apiUrl?: string;
1401
+ /** Request timeout in ms (default: 30000) */
1402
+ timeout?: number;
1403
+ }
1319
1404
  /**
1320
1405
  * Base providers result
1321
1406
  * Common structure for all platforms
@@ -1331,6 +1416,13 @@ interface BaseProviders {
1331
1416
  price?: PriceProvider;
1332
1417
  }
1333
1418
 
1419
+ interface MarketModuleConfig {
1420
+ /** Market API base URL (default: https://market-api.unicity.network) */
1421
+ apiUrl?: string;
1422
+ /** Request timeout in ms (default: 30000) */
1423
+ timeout?: number;
1424
+ }
1425
+
1334
1426
  /** IPFS storage provider configuration */
1335
1427
  interface IpfsStorageConfig {
1336
1428
  /** Gateway URLs for HTTP API (defaults to Unicity dedicated nodes) */
@@ -1423,6 +1515,8 @@ interface NodeProvidersConfig {
1423
1515
  enabled?: boolean;
1424
1516
  relays?: string[];
1425
1517
  } | boolean;
1518
+ /** Market module configuration. true = enable with defaults, object = custom config */
1519
+ market?: BaseMarketConfig | boolean;
1426
1520
  }
1427
1521
  interface NodeProviders {
1428
1522
  storage: StorageProvider;
@@ -1437,6 +1531,8 @@ interface NodeProviders {
1437
1531
  ipfsTokenStorage?: TokenStorageProvider<TxfStorageDataBase>;
1438
1532
  /** Group chat config (resolved, for passing to Sphere.init) */
1439
1533
  groupChat?: GroupChatModuleConfig | boolean;
1534
+ /** Market module config (resolved, for passing to Sphere.init) */
1535
+ market?: MarketModuleConfig | boolean;
1440
1536
  }
1441
1537
  /**
1442
1538
  * Create all Node.js providers with default configuration