@unicitylabs/sphere-sdk 0.6.1 → 0.6.3
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/dist/core/index.cjs +1371 -52
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +369 -4
- package/dist/core/index.d.ts +369 -4
- package/dist/core/index.js +1377 -48
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +137 -11
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +137 -11
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +38 -10
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +38 -10
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +133 -11
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +54 -0
- package/dist/impl/nodejs/index.d.ts +54 -0
- package/dist/impl/nodejs/index.js +133 -11
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +1354 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -3
- package/dist/index.d.ts +70 -3
- package/dist/index.js +1353 -50
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Token as Token$1 } from '@unicitylabs/state-transition-sdk/lib/token/Token';
|
|
2
|
+
import { NostrClient, NostrKeyManager } from '@unicitylabs/nostr-js-sdk';
|
|
2
3
|
import elliptic from 'elliptic';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -63,6 +64,17 @@ interface GroupChatModuleConfig {
|
|
|
63
64
|
/** Max reconnect attempts (default: 5) */
|
|
64
65
|
maxReconnectAttempts?: number;
|
|
65
66
|
}
|
|
67
|
+
interface GroupMessagesPage {
|
|
68
|
+
messages: GroupMessageData[];
|
|
69
|
+
hasMore: boolean;
|
|
70
|
+
oldestTimestamp: number | null;
|
|
71
|
+
}
|
|
72
|
+
interface GetGroupMessagesPageOptions {
|
|
73
|
+
/** Max messages to return (default: 20) */
|
|
74
|
+
limit?: number;
|
|
75
|
+
/** Return messages older than this timestamp */
|
|
76
|
+
before?: number;
|
|
77
|
+
}
|
|
66
78
|
interface CreateGroupOptions {
|
|
67
79
|
name: string;
|
|
68
80
|
description?: string;
|
|
@@ -762,7 +774,7 @@ interface TrackedAddress extends TrackedAddressEntry {
|
|
|
762
774
|
/** Primary nametag (from nametag cache, without @ prefix) */
|
|
763
775
|
readonly nametag?: string;
|
|
764
776
|
}
|
|
765
|
-
type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:read' | 'message:typing' | 'composing:started' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed' | 'address:activated' | 'address:hidden' | 'address:unhidden' | 'sync:remote-update' | 'groupchat:message' | 'groupchat:joined' | 'groupchat:left' | 'groupchat:kicked' | 'groupchat:group_deleted' | 'groupchat:updated' | 'groupchat:connection' | 'history:updated';
|
|
777
|
+
type SphereEventType = 'transfer:incoming' | 'transfer:confirmed' | 'transfer:failed' | 'payment_request:incoming' | 'payment_request:accepted' | 'payment_request:rejected' | 'payment_request:paid' | 'payment_request:response' | 'message:dm' | 'message:read' | 'message:typing' | 'composing:started' | 'message:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed' | 'address:activated' | 'address:hidden' | 'address:unhidden' | 'sync:remote-update' | 'groupchat:message' | 'groupchat:joined' | 'groupchat:left' | 'groupchat:kicked' | 'groupchat:group_deleted' | 'groupchat:updated' | 'groupchat:connection' | 'groupchat:ready' | 'communications:ready' | 'history:updated';
|
|
766
778
|
interface SphereEventMap {
|
|
767
779
|
'transfer:incoming': IncomingTransfer;
|
|
768
780
|
'transfer:confirmed': TransferResult;
|
|
@@ -862,6 +874,12 @@ interface SphereEventMap {
|
|
|
862
874
|
'groupchat:connection': {
|
|
863
875
|
connected: boolean;
|
|
864
876
|
};
|
|
877
|
+
'groupchat:ready': {
|
|
878
|
+
groupCount: number;
|
|
879
|
+
};
|
|
880
|
+
'communications:ready': {
|
|
881
|
+
conversationCount: number;
|
|
882
|
+
};
|
|
865
883
|
'history:updated': TransactionHistoryEntry;
|
|
866
884
|
}
|
|
867
885
|
type SphereEventHandler<T extends SphereEventType> = (data: SphereEventMap[T]) => void;
|
|
@@ -1127,6 +1145,13 @@ interface TokenStorageProvider<TData = unknown> extends BaseProvider {
|
|
|
1127
1145
|
* Clear all data
|
|
1128
1146
|
*/
|
|
1129
1147
|
clear?(): Promise<boolean>;
|
|
1148
|
+
/**
|
|
1149
|
+
* Create a new independent instance of this provider for a different address.
|
|
1150
|
+
* Used by per-address module architecture — each address gets its own
|
|
1151
|
+
* TokenStorageProvider instance to avoid cross-address data contamination.
|
|
1152
|
+
* If not implemented, the provider cannot be used in multi-address mode.
|
|
1153
|
+
*/
|
|
1154
|
+
createForAddress?(): TokenStorageProvider<TData>;
|
|
1130
1155
|
/**
|
|
1131
1156
|
* Subscribe to storage events
|
|
1132
1157
|
*/
|
|
@@ -1383,12 +1408,30 @@ interface TransportProvider extends BaseProvider {
|
|
|
1383
1408
|
* @returns Unsubscribe function
|
|
1384
1409
|
*/
|
|
1385
1410
|
onInstantSplitReceived?(handler: InstantSplitBundleHandler): () => void;
|
|
1411
|
+
/**
|
|
1412
|
+
* Set fallback 'since' timestamp for event subscriptions.
|
|
1413
|
+
* Used when switching to an address that has never subscribed before.
|
|
1414
|
+
* The transport uses this instead of 'now' as the initial since filter,
|
|
1415
|
+
* ensuring events sent while the address was inactive are not missed.
|
|
1416
|
+
* Consumed once by the next subscription setup, then cleared.
|
|
1417
|
+
*
|
|
1418
|
+
* @param sinceSeconds - Unix timestamp in seconds
|
|
1419
|
+
*/
|
|
1420
|
+
setFallbackSince?(sinceSeconds: number): void;
|
|
1386
1421
|
/**
|
|
1387
1422
|
* Fetch pending events from transport (one-shot query).
|
|
1388
1423
|
* Creates a temporary subscription, processes events through normal handlers,
|
|
1389
1424
|
* and resolves after EOSE (End Of Stored Events).
|
|
1390
1425
|
*/
|
|
1391
1426
|
fetchPendingEvents?(): Promise<void>;
|
|
1427
|
+
/**
|
|
1428
|
+
* Register a handler to be called when the chat subscription receives EOSE
|
|
1429
|
+
* (End Of Stored Events), indicating that historical DMs have been delivered.
|
|
1430
|
+
* The handler fires at most once per subscription lifecycle.
|
|
1431
|
+
*
|
|
1432
|
+
* @returns Unsubscribe function
|
|
1433
|
+
*/
|
|
1434
|
+
onChatReady?(handler: () => void): () => void;
|
|
1392
1435
|
}
|
|
1393
1436
|
/**
|
|
1394
1437
|
* Payload for sending instant split bundles
|
|
@@ -1526,6 +1569,14 @@ interface IncomingBroadcast {
|
|
|
1526
1569
|
timestamp: number;
|
|
1527
1570
|
}
|
|
1528
1571
|
type BroadcastHandler = (broadcast: IncomingBroadcast) => void;
|
|
1572
|
+
type TransportEventType = 'transport:connected' | 'transport:disconnected' | 'transport:reconnecting' | 'transport:error' | 'transport:relay_added' | 'transport:relay_removed' | 'message:received' | 'message:sent' | 'transfer:received' | 'transfer:sent';
|
|
1573
|
+
interface TransportEvent {
|
|
1574
|
+
type: TransportEventType;
|
|
1575
|
+
timestamp: number;
|
|
1576
|
+
data?: unknown;
|
|
1577
|
+
error?: string;
|
|
1578
|
+
}
|
|
1579
|
+
type TransportEventCallback = (event: TransportEvent) => void;
|
|
1529
1580
|
/**
|
|
1530
1581
|
* Resolved peer identity information.
|
|
1531
1582
|
* Returned by resolve methods — contains all public address formats for a peer.
|
|
@@ -1567,6 +1618,280 @@ interface IncomingTypingIndicator {
|
|
|
1567
1618
|
type TypingIndicatorHandler = (indicator: IncomingTypingIndicator) => void;
|
|
1568
1619
|
type ComposingHandler = (indicator: ComposingIndicator) => void;
|
|
1569
1620
|
|
|
1621
|
+
/**
|
|
1622
|
+
* WebSocket Abstraction
|
|
1623
|
+
* Platform-independent WebSocket interface for cross-platform support
|
|
1624
|
+
*/
|
|
1625
|
+
/**
|
|
1626
|
+
* Minimal WebSocket interface compatible with browser and Node.js
|
|
1627
|
+
*/
|
|
1628
|
+
interface IWebSocket {
|
|
1629
|
+
readonly readyState: number;
|
|
1630
|
+
send(data: string): void;
|
|
1631
|
+
close(code?: number, reason?: string): void;
|
|
1632
|
+
onopen: ((event: unknown) => void) | null;
|
|
1633
|
+
onclose: ((event: unknown) => void) | null;
|
|
1634
|
+
onerror: ((event: unknown) => void) | null;
|
|
1635
|
+
onmessage: ((event: IMessageEvent) => void) | null;
|
|
1636
|
+
}
|
|
1637
|
+
interface IMessageEvent {
|
|
1638
|
+
data: string;
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Factory function to create WebSocket instances
|
|
1642
|
+
* Different implementations for browser (native) vs Node.js (ws package)
|
|
1643
|
+
*/
|
|
1644
|
+
type WebSocketFactory = (url: string) => IWebSocket;
|
|
1645
|
+
/**
|
|
1646
|
+
* Generate a unique ID (platform-independent)
|
|
1647
|
+
* Browser: crypto.randomUUID()
|
|
1648
|
+
* Node: crypto.randomUUID() or uuid package
|
|
1649
|
+
*/
|
|
1650
|
+
type UUIDGenerator = () => string;
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* Nostr Transport Provider
|
|
1654
|
+
* Platform-independent implementation using Nostr protocol for P2P messaging
|
|
1655
|
+
*
|
|
1656
|
+
* Uses @unicitylabs/nostr-js-sdk for:
|
|
1657
|
+
* - Real secp256k1 event signing
|
|
1658
|
+
* - NIP-04 encryption/decryption
|
|
1659
|
+
* - Event ID calculation
|
|
1660
|
+
* - NostrClient for reliable connection management (ping, reconnect, NIP-42)
|
|
1661
|
+
*
|
|
1662
|
+
* WebSocket is injected via factory for cross-platform support
|
|
1663
|
+
*/
|
|
1664
|
+
|
|
1665
|
+
/**
|
|
1666
|
+
* Minimal key-value storage interface for transport persistence.
|
|
1667
|
+
* Used to persist the last processed event timestamp across sessions.
|
|
1668
|
+
*/
|
|
1669
|
+
interface TransportStorageAdapter {
|
|
1670
|
+
get(key: string): Promise<string | null>;
|
|
1671
|
+
set(key: string, value: string): Promise<void>;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* Multi-Address Transport Multiplexer
|
|
1676
|
+
*
|
|
1677
|
+
* Wraps a single NostrTransportProvider to support multiple HD addresses
|
|
1678
|
+
* simultaneously. Each address gets a lightweight AddressTransportAdapter
|
|
1679
|
+
* that implements TransportProvider but shares the single WebSocket connection.
|
|
1680
|
+
*
|
|
1681
|
+
* Event routing:
|
|
1682
|
+
* - Wallet events (kind 4, 31113, 31115, 31116): routed by #p tag (recipient pubkey)
|
|
1683
|
+
* - Chat events (kind 1059 gift wrap): try decrypt with each address keyManager
|
|
1684
|
+
*
|
|
1685
|
+
* Sending: each adapter delegates to the inner transport with its own keyManager.
|
|
1686
|
+
*/
|
|
1687
|
+
|
|
1688
|
+
interface MultiAddressTransportMuxConfig {
|
|
1689
|
+
relays?: string[];
|
|
1690
|
+
timeout?: number;
|
|
1691
|
+
autoReconnect?: boolean;
|
|
1692
|
+
reconnectDelay?: number;
|
|
1693
|
+
maxReconnectAttempts?: number;
|
|
1694
|
+
createWebSocket: WebSocketFactory;
|
|
1695
|
+
generateUUID?: UUIDGenerator;
|
|
1696
|
+
storage?: TransportStorageAdapter;
|
|
1697
|
+
}
|
|
1698
|
+
declare class MultiAddressTransportMux {
|
|
1699
|
+
private config;
|
|
1700
|
+
private storage;
|
|
1701
|
+
private nostrClient;
|
|
1702
|
+
private primaryKeyManager;
|
|
1703
|
+
private status;
|
|
1704
|
+
private addresses;
|
|
1705
|
+
private pubkeyToIndex;
|
|
1706
|
+
private walletSubscriptionId;
|
|
1707
|
+
private chatSubscriptionId;
|
|
1708
|
+
private chatEoseFired;
|
|
1709
|
+
private chatEoseHandlers;
|
|
1710
|
+
private processedEventIds;
|
|
1711
|
+
private eventCallbacks;
|
|
1712
|
+
constructor(config: MultiAddressTransportMuxConfig);
|
|
1713
|
+
/**
|
|
1714
|
+
* Add an address to the multiplexer.
|
|
1715
|
+
* Creates an AddressTransportAdapter for this address.
|
|
1716
|
+
* If already connected, updates subscriptions to include the new pubkey.
|
|
1717
|
+
*/
|
|
1718
|
+
addAddress(index: number, identity: FullIdentity, resolveDelegate?: TransportProvider | null): Promise<AddressTransportAdapter>;
|
|
1719
|
+
/**
|
|
1720
|
+
* Remove an address from the multiplexer.
|
|
1721
|
+
* Stops routing events to this address.
|
|
1722
|
+
*/
|
|
1723
|
+
removeAddress(index: number): Promise<void>;
|
|
1724
|
+
/**
|
|
1725
|
+
* Get adapter for a specific address index.
|
|
1726
|
+
*/
|
|
1727
|
+
getAdapter(index: number): AddressTransportAdapter | undefined;
|
|
1728
|
+
/**
|
|
1729
|
+
* Set fallback 'since' for an address (consumed once on next subscription setup).
|
|
1730
|
+
*/
|
|
1731
|
+
setFallbackSince(index: number, sinceSeconds: number): void;
|
|
1732
|
+
connect(): Promise<void>;
|
|
1733
|
+
disconnect(): Promise<void>;
|
|
1734
|
+
isConnected(): boolean;
|
|
1735
|
+
getStatus(): ProviderStatus;
|
|
1736
|
+
getRelays(): string[];
|
|
1737
|
+
getConnectedRelays(): string[];
|
|
1738
|
+
addRelay(relayUrl: string): Promise<boolean>;
|
|
1739
|
+
removeRelay(relayUrl: string): Promise<boolean>;
|
|
1740
|
+
hasRelay(relayUrl: string): boolean;
|
|
1741
|
+
isRelayConnected(relayUrl: string): boolean;
|
|
1742
|
+
/**
|
|
1743
|
+
* Update Nostr subscriptions to listen for events on ALL registered address pubkeys.
|
|
1744
|
+
* Called whenever addresses are added/removed.
|
|
1745
|
+
*/
|
|
1746
|
+
private updateSubscriptions;
|
|
1747
|
+
/**
|
|
1748
|
+
* Determine 'since' timestamp for an address entry.
|
|
1749
|
+
*/
|
|
1750
|
+
private getAddressSince;
|
|
1751
|
+
/**
|
|
1752
|
+
* Route an incoming Nostr event to the correct address adapter.
|
|
1753
|
+
*/
|
|
1754
|
+
private handleEvent;
|
|
1755
|
+
/**
|
|
1756
|
+
* Extract recipient pubkey from event's #p tag.
|
|
1757
|
+
* Returns the first #p value that matches a known address pubkey,
|
|
1758
|
+
* or the first #p value if none match.
|
|
1759
|
+
*/
|
|
1760
|
+
private extractRecipientPubkey;
|
|
1761
|
+
/**
|
|
1762
|
+
* Route a gift wrap event by trying decryption with each address keyManager.
|
|
1763
|
+
*/
|
|
1764
|
+
private routeGiftWrap;
|
|
1765
|
+
/**
|
|
1766
|
+
* Dispatch a wallet event (non-gift-wrap) to the correct address adapter.
|
|
1767
|
+
*/
|
|
1768
|
+
private dispatchWalletEvent;
|
|
1769
|
+
private handleTokenTransfer;
|
|
1770
|
+
private handlePaymentRequest;
|
|
1771
|
+
private handlePaymentRequestResponse;
|
|
1772
|
+
private decryptContent;
|
|
1773
|
+
private stripContentPrefix;
|
|
1774
|
+
/**
|
|
1775
|
+
* Create an encrypted event using a specific address's keyManager.
|
|
1776
|
+
* Used by AddressTransportAdapter for sending.
|
|
1777
|
+
*/
|
|
1778
|
+
createAndPublishEncryptedEvent(addressIndex: number, kind: number, content: string, tags: string[][]): Promise<string>;
|
|
1779
|
+
/**
|
|
1780
|
+
* Create and publish a NIP-17 gift wrap message for a specific address.
|
|
1781
|
+
*/
|
|
1782
|
+
sendGiftWrap(addressIndex: number, recipientPubkey: string, content: string): Promise<string>;
|
|
1783
|
+
/**
|
|
1784
|
+
* Publish a raw event (e.g., identity binding, broadcast).
|
|
1785
|
+
*/
|
|
1786
|
+
publishRawEvent(addressIndex: number, kind: number, content: string, tags: string[][]): Promise<string>;
|
|
1787
|
+
/**
|
|
1788
|
+
* Get the NostrClient for resolve operations.
|
|
1789
|
+
* Adapters use this for resolve*, publishIdentityBinding, etc.
|
|
1790
|
+
*/
|
|
1791
|
+
getNostrClient(): NostrClient | null;
|
|
1792
|
+
/**
|
|
1793
|
+
* Get keyManager for a specific address (used by adapters for resolve/binding).
|
|
1794
|
+
*/
|
|
1795
|
+
getKeyManager(addressIndex: number): NostrKeyManager | null;
|
|
1796
|
+
/**
|
|
1797
|
+
* Get identity for a specific address.
|
|
1798
|
+
*/
|
|
1799
|
+
getIdentity(addressIndex: number): FullIdentity | null;
|
|
1800
|
+
private updateLastEventTimestamp;
|
|
1801
|
+
onTransportEvent(callback: TransportEventCallback): () => void;
|
|
1802
|
+
onChatReady(handler: () => void): () => void;
|
|
1803
|
+
private emitEvent;
|
|
1804
|
+
/**
|
|
1805
|
+
* Clear processed event IDs (e.g., on address change or periodic cleanup).
|
|
1806
|
+
*/
|
|
1807
|
+
clearProcessedEvents(): void;
|
|
1808
|
+
/**
|
|
1809
|
+
* Get the storage adapter (for adapters that need it).
|
|
1810
|
+
*/
|
|
1811
|
+
getStorage(): TransportStorageAdapter | null;
|
|
1812
|
+
/**
|
|
1813
|
+
* Get the UUID generator.
|
|
1814
|
+
*/
|
|
1815
|
+
getUUIDGenerator(): UUIDGenerator;
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* Lightweight TransportProvider implementation for a single address.
|
|
1819
|
+
* Does NOT own a WebSocket — delegates to MultiAddressTransportMux.
|
|
1820
|
+
* Each per-address module (PaymentsModule, CommunicationsModule) uses one of these.
|
|
1821
|
+
*/
|
|
1822
|
+
declare class AddressTransportAdapter implements TransportProvider {
|
|
1823
|
+
readonly id: string;
|
|
1824
|
+
readonly name: string;
|
|
1825
|
+
readonly type: "p2p";
|
|
1826
|
+
readonly description: string;
|
|
1827
|
+
private mux;
|
|
1828
|
+
private addressIndex;
|
|
1829
|
+
private identity;
|
|
1830
|
+
private resolveDelegate;
|
|
1831
|
+
private messageHandlers;
|
|
1832
|
+
private transferHandlers;
|
|
1833
|
+
private paymentRequestHandlers;
|
|
1834
|
+
private paymentRequestResponseHandlers;
|
|
1835
|
+
private readReceiptHandlers;
|
|
1836
|
+
private typingIndicatorHandlers;
|
|
1837
|
+
private composingHandlers;
|
|
1838
|
+
private instantSplitBundleHandlers;
|
|
1839
|
+
private broadcastHandlers;
|
|
1840
|
+
private eventCallbacks;
|
|
1841
|
+
private pendingMessages;
|
|
1842
|
+
private chatEoseHandlers;
|
|
1843
|
+
constructor(mux: MultiAddressTransportMux, addressIndex: number, identity: FullIdentity, resolveDelegate?: TransportProvider | null);
|
|
1844
|
+
connect(): Promise<void>;
|
|
1845
|
+
disconnect(): Promise<void>;
|
|
1846
|
+
isConnected(): boolean;
|
|
1847
|
+
getStatus(): ProviderStatus;
|
|
1848
|
+
setIdentity(identity: FullIdentity): Promise<void>;
|
|
1849
|
+
sendMessage(recipientPubkey: string, content: string): Promise<string>;
|
|
1850
|
+
sendTokenTransfer(recipientPubkey: string, payload: TokenTransferPayload): Promise<string>;
|
|
1851
|
+
sendPaymentRequest(recipientPubkey: string, payload: PaymentRequestPayload): Promise<string>;
|
|
1852
|
+
sendPaymentRequestResponse(recipientPubkey: string, response: PaymentRequestResponsePayload): Promise<string>;
|
|
1853
|
+
sendReadReceipt(recipientPubkey: string, messageEventId: string): Promise<void>;
|
|
1854
|
+
sendTypingIndicator(recipientPubkey: string): Promise<void>;
|
|
1855
|
+
sendComposingIndicator(recipientPubkey: string, content: string): Promise<void>;
|
|
1856
|
+
sendInstantSplitBundle(recipientPubkey: string, bundle: InstantSplitBundlePayload): Promise<string>;
|
|
1857
|
+
onMessage(handler: MessageHandler): () => void;
|
|
1858
|
+
onTokenTransfer(handler: TokenTransferHandler): () => void;
|
|
1859
|
+
onPaymentRequest(handler: PaymentRequestHandler): () => void;
|
|
1860
|
+
onPaymentRequestResponse(handler: PaymentRequestResponseHandler): () => void;
|
|
1861
|
+
onReadReceipt(handler: ReadReceiptHandler): () => void;
|
|
1862
|
+
onTypingIndicator(handler: TypingIndicatorHandler): () => void;
|
|
1863
|
+
onComposing(handler: ComposingHandler): () => void;
|
|
1864
|
+
onInstantSplitReceived(handler: InstantSplitBundleHandler): () => void;
|
|
1865
|
+
subscribeToBroadcast(tags: string[], handler: BroadcastHandler): () => void;
|
|
1866
|
+
publishBroadcast(content: string, tags?: string[]): Promise<string>;
|
|
1867
|
+
resolve(identifier: string): Promise<PeerInfo | null>;
|
|
1868
|
+
resolveNametag(nametag: string): Promise<string | null>;
|
|
1869
|
+
resolveNametagInfo(nametag: string): Promise<PeerInfo | null>;
|
|
1870
|
+
resolveAddressInfo(address: string): Promise<PeerInfo | null>;
|
|
1871
|
+
resolveTransportPubkeyInfo(transportPubkey: string): Promise<PeerInfo | null>;
|
|
1872
|
+
discoverAddresses(transportPubkeys: string[]): Promise<PeerInfo[]>;
|
|
1873
|
+
recoverNametag(): Promise<string | null>;
|
|
1874
|
+
publishIdentityBinding(chainPubkey: string, l1Address: string, directAddress: string, nametag?: string): Promise<boolean>;
|
|
1875
|
+
getRelays(): string[];
|
|
1876
|
+
getConnectedRelays(): string[];
|
|
1877
|
+
addRelay(relayUrl: string): Promise<boolean>;
|
|
1878
|
+
removeRelay(relayUrl: string): Promise<boolean>;
|
|
1879
|
+
hasRelay(relayUrl: string): boolean;
|
|
1880
|
+
isRelayConnected(relayUrl: string): boolean;
|
|
1881
|
+
setFallbackSince(sinceSeconds: number): void;
|
|
1882
|
+
fetchPendingEvents(): Promise<void>;
|
|
1883
|
+
onChatReady(handler: () => void): () => void;
|
|
1884
|
+
dispatchMessage(message: IncomingMessage): void;
|
|
1885
|
+
dispatchTokenTransfer(transfer: IncomingTokenTransfer): void;
|
|
1886
|
+
dispatchPaymentRequest(request: IncomingPaymentRequest): void;
|
|
1887
|
+
dispatchPaymentRequestResponse(response: IncomingPaymentRequestResponse): void;
|
|
1888
|
+
dispatchReadReceipt(receipt: IncomingReadReceipt): void;
|
|
1889
|
+
dispatchTypingIndicator(indicator: IncomingTypingIndicator): void;
|
|
1890
|
+
dispatchComposingIndicator(indicator: any): void;
|
|
1891
|
+
dispatchInstantSplitBundle(bundle: IncomingInstantSplitBundle): void;
|
|
1892
|
+
emitTransportEvent(event: TransportEvent): void;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1570
1895
|
/**
|
|
1571
1896
|
* L1 Payments Sub-Module
|
|
1572
1897
|
*
|
|
@@ -2951,6 +3276,7 @@ declare class GroupChatModule {
|
|
|
2951
3276
|
getGroups(): GroupData[];
|
|
2952
3277
|
getGroup(groupId: string): GroupData | null;
|
|
2953
3278
|
getMessages(groupId: string): GroupMessageData[];
|
|
3279
|
+
getMessagesPage(groupId: string, options?: GetGroupMessagesPageOptions): GroupMessagesPage;
|
|
2954
3280
|
getMembers(groupId: string): GroupMemberData[];
|
|
2955
3281
|
getMember(groupId: string, pubkey: string): GroupMemberData | null;
|
|
2956
3282
|
getTotalUnreadCount(): number;
|
|
@@ -3568,6 +3894,21 @@ interface SphereInitResult {
|
|
|
3568
3894
|
/** Generated mnemonic (only if autoGenerate was used) */
|
|
3569
3895
|
generatedMnemonic?: string;
|
|
3570
3896
|
}
|
|
3897
|
+
/**
|
|
3898
|
+
* Holds all per-address module instances.
|
|
3899
|
+
* Each HD address gets its own set so modules can run independently in background.
|
|
3900
|
+
*/
|
|
3901
|
+
interface AddressModuleSet {
|
|
3902
|
+
index: number;
|
|
3903
|
+
identity: FullIdentity;
|
|
3904
|
+
payments: PaymentsModule;
|
|
3905
|
+
communications: CommunicationsModule;
|
|
3906
|
+
groupChat: GroupChatModule | null;
|
|
3907
|
+
market: MarketModule | null;
|
|
3908
|
+
transportAdapter: AddressTransportAdapter | null;
|
|
3909
|
+
tokenStorageProviders: Map<string, TokenStorageProvider<TxfStorageDataBase>>;
|
|
3910
|
+
initialized: boolean;
|
|
3911
|
+
}
|
|
3571
3912
|
declare class Sphere {
|
|
3572
3913
|
private static instance;
|
|
3573
3914
|
private _initialized;
|
|
@@ -3596,6 +3937,11 @@ declare class Sphere {
|
|
|
3596
3937
|
private _communications;
|
|
3597
3938
|
private _groupChat;
|
|
3598
3939
|
private _market;
|
|
3940
|
+
private _addressModules;
|
|
3941
|
+
private _transportMux;
|
|
3942
|
+
private _l1Config;
|
|
3943
|
+
private _groupChatConfig;
|
|
3944
|
+
private _marketConfig;
|
|
3599
3945
|
private eventHandlers;
|
|
3600
3946
|
private _disabledProviders;
|
|
3601
3947
|
private _providerEventCleanups;
|
|
@@ -3991,9 +4337,28 @@ declare class Sphere {
|
|
|
3991
4337
|
*/
|
|
3992
4338
|
private postSwitchSync;
|
|
3993
4339
|
/**
|
|
3994
|
-
*
|
|
4340
|
+
* Create a new set of per-address modules for the given index.
|
|
4341
|
+
* Each address gets its own PaymentsModule, CommunicationsModule, etc.
|
|
4342
|
+
* Modules are fully independent — they have their own token storage,
|
|
4343
|
+
* and can sync/finalize/split in background regardless of active address.
|
|
4344
|
+
*
|
|
4345
|
+
* @param index - HD address index
|
|
4346
|
+
* @param identity - Full identity for this address
|
|
4347
|
+
* @param tokenStorageProviders - Token storage providers for this address
|
|
4348
|
+
*/
|
|
4349
|
+
private initializeAddressModules;
|
|
4350
|
+
/**
|
|
4351
|
+
* Ensure the transport multiplexer exists and register an address.
|
|
4352
|
+
* Creates the mux on first call. Returns an AddressTransportAdapter
|
|
4353
|
+
* that routes events for this address independently.
|
|
4354
|
+
* @returns AddressTransportAdapter or null if transport is not Nostr-based
|
|
4355
|
+
*/
|
|
4356
|
+
private ensureTransportMux;
|
|
4357
|
+
/**
|
|
4358
|
+
* Get per-address modules for any address index (creates lazily if needed).
|
|
4359
|
+
* This allows accessing any address's modules without switching.
|
|
3995
4360
|
*/
|
|
3996
|
-
|
|
4361
|
+
getAddressPayments(index: number): PaymentsModule | undefined;
|
|
3997
4362
|
/**
|
|
3998
4363
|
* Derive address at a specific index
|
|
3999
4364
|
*
|
|
@@ -4724,4 +5089,4 @@ interface CheckNetworkHealthOptions {
|
|
|
4724
5089
|
*/
|
|
4725
5090
|
declare function checkNetworkHealth(network?: NetworkType, options?: CheckNetworkHealthOptions): Promise<NetworkHealthResult>;
|
|
4726
5091
|
|
|
4727
|
-
export { type AddressInfo, CHARSET, type CheckNetworkHealthOptions, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type EncryptedData, type EncryptionOptions, type InitProgress, type InitProgressCallback, type InitProgressStep, type KeyPair, type L1Config, type LogHandler, type LogLevel, type LoggerConfig, type MasterKey, SIGN_MESSAGE_PREFIX, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, checkNetworkHealth, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, discoverAddressesImpl, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hashSignMessage, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isSphereError, isValidBech32, isValidNametag, isValidPrivateKey, loadSphere, logger, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, signMessage, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic, verifySignedMessage };
|
|
5092
|
+
export { type AddressInfo, type AddressModuleSet, CHARSET, type CheckNetworkHealthOptions, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type EncryptedData, type EncryptionOptions, type InitProgress, type InitProgressCallback, type InitProgressStep, type KeyPair, type L1Config, type LogHandler, type LogLevel, type LoggerConfig, type MasterKey, SIGN_MESSAGE_PREFIX, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, checkNetworkHealth, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, discoverAddressesImpl, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hashSignMessage, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isSphereError, isValidBech32, isValidNametag, isValidPrivateKey, loadSphere, logger, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, signMessage, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic, verifySignedMessage };
|