@unicitylabs/sphere-sdk 0.4.9 → 0.5.1
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/connect/index.cjs +3 -1
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +3 -1
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +384 -119
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +244 -194
- package/dist/core/index.d.ts +244 -194
- package/dist/core/index.js +384 -119
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +3 -1
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +3 -1
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +67 -3
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +67 -3
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +3 -1
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +3 -1
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/connect/index.cjs +3 -1
- package/dist/impl/nodejs/connect/index.cjs.map +1 -1
- package/dist/impl/nodejs/connect/index.js +3 -1
- package/dist/impl/nodejs/connect/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +64 -5
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +668 -628
- package/dist/impl/nodejs/index.d.ts +668 -628
- package/dist/impl/nodejs/index.js +64 -5
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +384 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +248 -194
- package/dist/index.d.ts +248 -194
- package/dist/index.js +384 -119
- package/dist/index.js.map +1 -1
- package/dist/l1/index.cjs +3 -1
- package/dist/l1/index.cjs.map +1 -1
- package/dist/l1/index.js +3 -1
- package/dist/l1/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,420 +3,116 @@ import { AggregatorClient } from '@unicitylabs/state-transition-sdk/lib/api/Aggr
|
|
|
3
3
|
import { RootTrustBase } from '@unicitylabs/state-transition-sdk/lib/bft/RootTrustBase';
|
|
4
4
|
import { TransferCommitment as TransferCommitment$1 } from '@unicitylabs/state-transition-sdk/lib/transaction/TransferCommitment';
|
|
5
5
|
|
|
6
|
-
interface GroupChatModuleConfig {
|
|
7
|
-
/** Override relay URLs (default: from network config) */
|
|
8
|
-
relays?: string[];
|
|
9
|
-
/** Default message fetch limit (default: 50) */
|
|
10
|
-
defaultMessageLimit?: number;
|
|
11
|
-
/** Max previous message IDs in ordering tags (default: 3) */
|
|
12
|
-
maxPreviousTags?: number;
|
|
13
|
-
/** Reconnect delay in ms (default: 3000) */
|
|
14
|
-
reconnectDelayMs?: number;
|
|
15
|
-
/** Max reconnect attempts (default: 5) */
|
|
16
|
-
maxReconnectAttempts?: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* SDK2 Core Types
|
|
21
|
-
* Platform-independent type definitions
|
|
22
|
-
*/
|
|
23
|
-
type ProviderStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
24
|
-
interface ProviderMetadata {
|
|
25
|
-
readonly id: string;
|
|
26
|
-
readonly name: string;
|
|
27
|
-
readonly type: 'local' | 'cloud' | 'p2p' | 'network';
|
|
28
|
-
readonly description?: string;
|
|
29
|
-
}
|
|
30
|
-
interface BaseProvider extends ProviderMetadata {
|
|
31
|
-
connect(config?: unknown): Promise<void>;
|
|
32
|
-
disconnect(): Promise<void>;
|
|
33
|
-
isConnected(): boolean;
|
|
34
|
-
getStatus(): ProviderStatus;
|
|
35
|
-
}
|
|
36
|
-
interface Identity {
|
|
37
|
-
/** 33-byte compressed secp256k1 public key (for L3 chain) */
|
|
38
|
-
readonly chainPubkey: string;
|
|
39
|
-
/** L1 address (alpha1...) */
|
|
40
|
-
readonly l1Address: string;
|
|
41
|
-
/** L3 DIRECT address (DIRECT://...) */
|
|
42
|
-
readonly directAddress?: string;
|
|
43
|
-
readonly ipnsName?: string;
|
|
44
|
-
readonly nametag?: string;
|
|
45
|
-
}
|
|
46
|
-
interface FullIdentity extends Identity {
|
|
47
|
-
readonly privateKey: string;
|
|
48
|
-
}
|
|
49
|
-
interface ComposingIndicator {
|
|
50
|
-
readonly senderPubkey: string;
|
|
51
|
-
readonly senderNametag?: string;
|
|
52
|
-
readonly expiresIn: number;
|
|
53
|
-
}
|
|
54
6
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
interface TrackedAddressEntry {
|
|
59
|
-
/** HD derivation index (0, 1, 2, ...) */
|
|
60
|
-
readonly index: number;
|
|
61
|
-
/** Whether this address is hidden from UI display */
|
|
62
|
-
hidden: boolean;
|
|
63
|
-
/** Timestamp (ms) when this address was first activated */
|
|
64
|
-
readonly createdAt: number;
|
|
65
|
-
/** Timestamp (ms) of last modification */
|
|
66
|
-
updatedAt: number;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Storage Provider Interface
|
|
71
|
-
* Platform-independent storage abstraction
|
|
7
|
+
* Transport Provider Interface
|
|
8
|
+
* Platform-independent P2P messaging abstraction
|
|
72
9
|
*/
|
|
73
10
|
|
|
74
11
|
/**
|
|
75
|
-
*
|
|
76
|
-
* All operations are async for platform flexibility
|
|
12
|
+
* P2P messaging transport provider
|
|
77
13
|
*/
|
|
78
|
-
interface
|
|
14
|
+
interface TransportProvider extends BaseProvider {
|
|
79
15
|
/**
|
|
80
|
-
* Set identity for
|
|
16
|
+
* Set identity for signing/encryption.
|
|
17
|
+
* If the transport is already connected, reconnects with the new identity.
|
|
81
18
|
*/
|
|
82
|
-
setIdentity(identity: FullIdentity): void
|
|
19
|
+
setIdentity(identity: FullIdentity): void | Promise<void>;
|
|
83
20
|
/**
|
|
84
|
-
*
|
|
21
|
+
* Send encrypted direct message
|
|
22
|
+
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
23
|
+
* @returns Event ID
|
|
85
24
|
*/
|
|
86
|
-
|
|
25
|
+
sendMessage(recipientTransportPubkey: string, content: string): Promise<string>;
|
|
87
26
|
/**
|
|
88
|
-
*
|
|
27
|
+
* Subscribe to incoming direct messages
|
|
28
|
+
* @returns Unsubscribe function
|
|
89
29
|
*/
|
|
90
|
-
|
|
30
|
+
onMessage(handler: MessageHandler): () => void;
|
|
91
31
|
/**
|
|
92
|
-
*
|
|
32
|
+
* Send token transfer payload
|
|
33
|
+
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
34
|
+
* @returns Event ID
|
|
93
35
|
*/
|
|
94
|
-
|
|
36
|
+
sendTokenTransfer(recipientTransportPubkey: string, payload: TokenTransferPayload): Promise<string>;
|
|
95
37
|
/**
|
|
96
|
-
*
|
|
38
|
+
* Subscribe to incoming token transfers
|
|
39
|
+
* @returns Unsubscribe function
|
|
97
40
|
*/
|
|
98
|
-
|
|
41
|
+
onTokenTransfer(handler: TokenTransferHandler): () => void;
|
|
99
42
|
/**
|
|
100
|
-
*
|
|
43
|
+
* Resolve any identifier to full peer information.
|
|
44
|
+
* Accepts @nametag, bare nametag, DIRECT://, PROXY://, L1 address, chain pubkey, or transport pubkey.
|
|
45
|
+
* @param identifier - Any supported identifier format
|
|
46
|
+
* @returns PeerInfo or null if not found
|
|
101
47
|
*/
|
|
102
|
-
|
|
48
|
+
resolve?(identifier: string): Promise<PeerInfo | null>;
|
|
103
49
|
/**
|
|
104
|
-
*
|
|
50
|
+
* Resolve nametag to public key
|
|
105
51
|
*/
|
|
106
|
-
|
|
52
|
+
resolveNametag?(nametag: string): Promise<string | null>;
|
|
107
53
|
/**
|
|
108
|
-
*
|
|
54
|
+
* Resolve nametag to full peer information
|
|
55
|
+
* Returns transportPubkey, chainPubkey, l1Address, directAddress, proxyAddress
|
|
109
56
|
*/
|
|
110
|
-
|
|
57
|
+
resolveNametagInfo?(nametag: string): Promise<PeerInfo | null>;
|
|
111
58
|
/**
|
|
112
|
-
*
|
|
59
|
+
* Resolve a DIRECT://, PROXY://, or L1 address to full peer info.
|
|
60
|
+
* Performs reverse lookup: address → binding event → PeerInfo.
|
|
61
|
+
* @param address - L3 address (DIRECT://... or PROXY://...) or L1 address (alpha1...)
|
|
62
|
+
* @returns PeerInfo or null if no binding found for this address
|
|
113
63
|
*/
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Storage result types
|
|
118
|
-
*/
|
|
119
|
-
interface SaveResult {
|
|
120
|
-
success: boolean;
|
|
121
|
-
cid?: string;
|
|
122
|
-
error?: string;
|
|
123
|
-
timestamp: number;
|
|
124
|
-
}
|
|
125
|
-
interface LoadResult<T = unknown> {
|
|
126
|
-
success: boolean;
|
|
127
|
-
data?: T;
|
|
128
|
-
error?: string;
|
|
129
|
-
source: 'local' | 'remote' | 'cache';
|
|
130
|
-
timestamp: number;
|
|
131
|
-
}
|
|
132
|
-
interface SyncResult<T = unknown> {
|
|
133
|
-
success: boolean;
|
|
134
|
-
merged?: T;
|
|
135
|
-
added: number;
|
|
136
|
-
removed: number;
|
|
137
|
-
conflicts: number;
|
|
138
|
-
error?: string;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Token-specific storage provider
|
|
142
|
-
* Handles token persistence with sync capabilities
|
|
143
|
-
*/
|
|
144
|
-
interface TokenStorageProvider<TData = unknown> extends BaseProvider {
|
|
64
|
+
resolveAddressInfo?(address: string): Promise<PeerInfo | null>;
|
|
145
65
|
/**
|
|
146
|
-
*
|
|
66
|
+
* Resolve transport pubkey to full peer info.
|
|
67
|
+
* Queries binding events authored by the given transport pubkey.
|
|
68
|
+
* @param transportPubkey - Transport-specific pubkey (e.g. 64-char hex string)
|
|
69
|
+
* @returns PeerInfo or null if no binding found
|
|
147
70
|
*/
|
|
148
|
-
|
|
71
|
+
resolveTransportPubkeyInfo?(transportPubkey: string): Promise<PeerInfo | null>;
|
|
149
72
|
/**
|
|
150
|
-
*
|
|
73
|
+
* Batch-resolve multiple transport pubkeys to peer info.
|
|
74
|
+
* Used for HD address discovery: derives transport pubkeys for indices 0..N
|
|
75
|
+
* and queries binding events in a single batch.
|
|
76
|
+
* @param transportPubkeys - Array of transport-specific pubkeys to look up
|
|
77
|
+
* @returns Array of PeerInfo for pubkeys that have binding events (may be shorter than input)
|
|
151
78
|
*/
|
|
152
|
-
|
|
79
|
+
discoverAddresses?(transportPubkeys: string[]): Promise<PeerInfo[]>;
|
|
153
80
|
/**
|
|
154
|
-
*
|
|
81
|
+
* Recover nametag for current identity by decrypting stored encrypted nametag
|
|
82
|
+
* Used after wallet import to recover associated nametag
|
|
83
|
+
* @returns Decrypted nametag or null if none found
|
|
155
84
|
*/
|
|
156
|
-
|
|
85
|
+
recoverNametag?(): Promise<string | null>;
|
|
157
86
|
/**
|
|
158
|
-
*
|
|
87
|
+
* Publish identity binding event.
|
|
88
|
+
* Without nametag: publishes base binding (chainPubkey, l1Address, directAddress).
|
|
89
|
+
* With nametag: adds nametag hash, proxy address, encrypted nametag for recovery.
|
|
90
|
+
* Uses parameterized replaceable event (kind 30078, d=hash(nostrPubkey)).
|
|
91
|
+
* @returns true if successful, false if nametag is taken by another pubkey
|
|
159
92
|
*/
|
|
160
|
-
|
|
93
|
+
publishIdentityBinding?(chainPubkey: string, l1Address: string, directAddress: string, nametag?: string): Promise<boolean>;
|
|
161
94
|
/**
|
|
162
|
-
*
|
|
95
|
+
* @deprecated Use publishIdentityBinding instead
|
|
96
|
+
* Register a nametag for this identity
|
|
163
97
|
*/
|
|
164
|
-
|
|
98
|
+
registerNametag?(nametag: string, chainPubkey: string, directAddress: string): Promise<boolean>;
|
|
165
99
|
/**
|
|
166
|
-
*
|
|
100
|
+
* @deprecated Use publishIdentityBinding instead
|
|
101
|
+
* Publish nametag binding
|
|
167
102
|
*/
|
|
168
|
-
|
|
103
|
+
publishNametag?(nametag: string, address: string): Promise<void>;
|
|
169
104
|
/**
|
|
170
|
-
*
|
|
105
|
+
* Subscribe to broadcast messages (global/channel)
|
|
171
106
|
*/
|
|
172
|
-
|
|
107
|
+
subscribeToBroadcast?(tags: string[], handler: BroadcastHandler): () => void;
|
|
173
108
|
/**
|
|
174
|
-
*
|
|
109
|
+
* Publish broadcast message
|
|
175
110
|
*/
|
|
176
|
-
|
|
111
|
+
publishBroadcast?(content: string, tags?: string[]): Promise<string>;
|
|
177
112
|
/**
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
type StorageEventType = 'storage:saving' | 'storage:saved' | 'storage:loading' | 'storage:loaded' | 'storage:error' | 'storage:remote-updated' | 'sync:started' | 'sync:completed' | 'sync:conflict' | 'sync:error';
|
|
183
|
-
interface StorageEvent {
|
|
184
|
-
type: StorageEventType;
|
|
185
|
-
timestamp: number;
|
|
186
|
-
data?: unknown;
|
|
187
|
-
error?: string;
|
|
188
|
-
}
|
|
189
|
-
type StorageEventCallback = (event: StorageEvent) => void;
|
|
190
|
-
interface TxfStorageDataBase {
|
|
191
|
-
_meta: TxfMeta;
|
|
192
|
-
_tombstones?: TxfTombstone[];
|
|
193
|
-
_outbox?: TxfOutboxEntry[];
|
|
194
|
-
_sent?: TxfSentEntry[];
|
|
195
|
-
_invalid?: TxfInvalidEntry[];
|
|
196
|
-
[key: `_${string}`]: unknown;
|
|
197
|
-
}
|
|
198
|
-
interface TxfMeta {
|
|
199
|
-
version: number;
|
|
200
|
-
address: string;
|
|
201
|
-
ipnsName?: string;
|
|
202
|
-
formatVersion: string;
|
|
203
|
-
updatedAt: number;
|
|
204
|
-
}
|
|
205
|
-
interface TxfTombstone {
|
|
206
|
-
tokenId: string;
|
|
207
|
-
stateHash: string;
|
|
208
|
-
timestamp: number;
|
|
209
|
-
}
|
|
210
|
-
interface TxfOutboxEntry {
|
|
211
|
-
id: string;
|
|
212
|
-
status: string;
|
|
213
|
-
tokenId: string;
|
|
214
|
-
recipient: string;
|
|
215
|
-
createdAt: number;
|
|
216
|
-
data: unknown;
|
|
217
|
-
}
|
|
218
|
-
interface TxfSentEntry {
|
|
219
|
-
tokenId: string;
|
|
220
|
-
recipient: string;
|
|
221
|
-
txHash: string;
|
|
222
|
-
sentAt: number;
|
|
223
|
-
}
|
|
224
|
-
interface TxfInvalidEntry {
|
|
225
|
-
tokenId: string;
|
|
226
|
-
reason: string;
|
|
227
|
-
detectedAt: number;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* File Storage Provider for Node.js
|
|
232
|
-
* Stores wallet data in JSON files
|
|
233
|
-
*/
|
|
234
|
-
|
|
235
|
-
interface FileStorageProviderConfig {
|
|
236
|
-
/** Directory to store wallet data */
|
|
237
|
-
dataDir: string;
|
|
238
|
-
/** File name for key-value data (default: 'wallet.json') */
|
|
239
|
-
fileName?: string;
|
|
240
|
-
}
|
|
241
|
-
declare class FileStorageProvider implements StorageProvider {
|
|
242
|
-
readonly id = "file-storage";
|
|
243
|
-
readonly name = "File Storage";
|
|
244
|
-
readonly type: "local";
|
|
245
|
-
private dataDir;
|
|
246
|
-
private filePath;
|
|
247
|
-
private isTxtMode;
|
|
248
|
-
private data;
|
|
249
|
-
private status;
|
|
250
|
-
private _identity;
|
|
251
|
-
constructor(config: FileStorageProviderConfig | string);
|
|
252
|
-
setIdentity(identity: FullIdentity): void;
|
|
253
|
-
getIdentity(): FullIdentity | null;
|
|
254
|
-
connect(): Promise<void>;
|
|
255
|
-
disconnect(): Promise<void>;
|
|
256
|
-
isConnected(): boolean;
|
|
257
|
-
getStatus(): ProviderStatus;
|
|
258
|
-
get(key: string): Promise<string | null>;
|
|
259
|
-
set(key: string, value: string): Promise<void>;
|
|
260
|
-
remove(key: string): Promise<void>;
|
|
261
|
-
has(key: string): Promise<boolean>;
|
|
262
|
-
keys(prefix?: string): Promise<string[]>;
|
|
263
|
-
clear(prefix?: string): Promise<void>;
|
|
264
|
-
saveTrackedAddresses(entries: TrackedAddressEntry[]): Promise<void>;
|
|
265
|
-
loadTrackedAddresses(): Promise<TrackedAddressEntry[]>;
|
|
266
|
-
/**
|
|
267
|
-
* Get full storage key with address prefix for per-address keys
|
|
268
|
-
*/
|
|
269
|
-
private getFullKey;
|
|
270
|
-
private save;
|
|
271
|
-
}
|
|
272
|
-
declare function createFileStorageProvider(config: FileStorageProviderConfig | string): FileStorageProvider;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* File Token Storage Provider for Node.js
|
|
276
|
-
* Stores tokens as individual JSON files in per-address subdirectories
|
|
277
|
-
*/
|
|
278
|
-
|
|
279
|
-
interface FileTokenStorageConfig {
|
|
280
|
-
/** Directory to store token files */
|
|
281
|
-
tokensDir: string;
|
|
282
|
-
}
|
|
283
|
-
declare class FileTokenStorageProvider implements TokenStorageProvider<TxfStorageDataBase> {
|
|
284
|
-
readonly id = "file-token-storage";
|
|
285
|
-
readonly name = "File Token Storage";
|
|
286
|
-
readonly type: "local";
|
|
287
|
-
private baseTokensDir;
|
|
288
|
-
private status;
|
|
289
|
-
private identity;
|
|
290
|
-
constructor(config: FileTokenStorageConfig | string);
|
|
291
|
-
setIdentity(identity: FullIdentity): void;
|
|
292
|
-
/**
|
|
293
|
-
* Get tokens directory for current address
|
|
294
|
-
* Format: {baseTokensDir}/{addressId}/
|
|
295
|
-
*/
|
|
296
|
-
private get tokensDir();
|
|
297
|
-
initialize(): Promise<boolean>;
|
|
298
|
-
shutdown(): Promise<void>;
|
|
299
|
-
connect(): Promise<void>;
|
|
300
|
-
disconnect(): Promise<void>;
|
|
301
|
-
isConnected(): boolean;
|
|
302
|
-
getStatus(): ProviderStatus;
|
|
303
|
-
load(): Promise<LoadResult<TxfStorageDataBase>>;
|
|
304
|
-
save(data: TxfStorageDataBase): Promise<SaveResult>;
|
|
305
|
-
sync(localData: TxfStorageDataBase): Promise<SyncResult<TxfStorageDataBase>>;
|
|
306
|
-
clear(): Promise<boolean>;
|
|
307
|
-
}
|
|
308
|
-
declare function createFileTokenStorageProvider(config: FileTokenStorageConfig | string): FileTokenStorageProvider;
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Transport Provider Interface
|
|
312
|
-
* Platform-independent P2P messaging abstraction
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* P2P messaging transport provider
|
|
317
|
-
*/
|
|
318
|
-
interface TransportProvider extends BaseProvider {
|
|
319
|
-
/**
|
|
320
|
-
* Set identity for signing/encryption.
|
|
321
|
-
* If the transport is already connected, reconnects with the new identity.
|
|
322
|
-
*/
|
|
323
|
-
setIdentity(identity: FullIdentity): void | Promise<void>;
|
|
324
|
-
/**
|
|
325
|
-
* Send encrypted direct message
|
|
326
|
-
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
327
|
-
* @returns Event ID
|
|
328
|
-
*/
|
|
329
|
-
sendMessage(recipientTransportPubkey: string, content: string): Promise<string>;
|
|
330
|
-
/**
|
|
331
|
-
* Subscribe to incoming direct messages
|
|
332
|
-
* @returns Unsubscribe function
|
|
333
|
-
*/
|
|
334
|
-
onMessage(handler: MessageHandler): () => void;
|
|
335
|
-
/**
|
|
336
|
-
* Send token transfer payload
|
|
337
|
-
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
338
|
-
* @returns Event ID
|
|
339
|
-
*/
|
|
340
|
-
sendTokenTransfer(recipientTransportPubkey: string, payload: TokenTransferPayload): Promise<string>;
|
|
341
|
-
/**
|
|
342
|
-
* Subscribe to incoming token transfers
|
|
343
|
-
* @returns Unsubscribe function
|
|
344
|
-
*/
|
|
345
|
-
onTokenTransfer(handler: TokenTransferHandler): () => void;
|
|
346
|
-
/**
|
|
347
|
-
* Resolve any identifier to full peer information.
|
|
348
|
-
* Accepts @nametag, bare nametag, DIRECT://, PROXY://, L1 address, chain pubkey, or transport pubkey.
|
|
349
|
-
* @param identifier - Any supported identifier format
|
|
350
|
-
* @returns PeerInfo or null if not found
|
|
351
|
-
*/
|
|
352
|
-
resolve?(identifier: string): Promise<PeerInfo | null>;
|
|
353
|
-
/**
|
|
354
|
-
* Resolve nametag to public key
|
|
355
|
-
*/
|
|
356
|
-
resolveNametag?(nametag: string): Promise<string | null>;
|
|
357
|
-
/**
|
|
358
|
-
* Resolve nametag to full peer information
|
|
359
|
-
* Returns transportPubkey, chainPubkey, l1Address, directAddress, proxyAddress
|
|
360
|
-
*/
|
|
361
|
-
resolveNametagInfo?(nametag: string): Promise<PeerInfo | null>;
|
|
362
|
-
/**
|
|
363
|
-
* Resolve a DIRECT://, PROXY://, or L1 address to full peer info.
|
|
364
|
-
* Performs reverse lookup: address → binding event → PeerInfo.
|
|
365
|
-
* @param address - L3 address (DIRECT://... or PROXY://...) or L1 address (alpha1...)
|
|
366
|
-
* @returns PeerInfo or null if no binding found for this address
|
|
367
|
-
*/
|
|
368
|
-
resolveAddressInfo?(address: string): Promise<PeerInfo | null>;
|
|
369
|
-
/**
|
|
370
|
-
* Resolve transport pubkey to full peer info.
|
|
371
|
-
* Queries binding events authored by the given transport pubkey.
|
|
372
|
-
* @param transportPubkey - Transport-specific pubkey (e.g. 64-char hex string)
|
|
373
|
-
* @returns PeerInfo or null if no binding found
|
|
374
|
-
*/
|
|
375
|
-
resolveTransportPubkeyInfo?(transportPubkey: string): Promise<PeerInfo | null>;
|
|
376
|
-
/**
|
|
377
|
-
* Batch-resolve multiple transport pubkeys to peer info.
|
|
378
|
-
* Used for HD address discovery: derives transport pubkeys for indices 0..N
|
|
379
|
-
* and queries binding events in a single batch.
|
|
380
|
-
* @param transportPubkeys - Array of transport-specific pubkeys to look up
|
|
381
|
-
* @returns Array of PeerInfo for pubkeys that have binding events (may be shorter than input)
|
|
382
|
-
*/
|
|
383
|
-
discoverAddresses?(transportPubkeys: string[]): Promise<PeerInfo[]>;
|
|
384
|
-
/**
|
|
385
|
-
* Recover nametag for current identity by decrypting stored encrypted nametag
|
|
386
|
-
* Used after wallet import to recover associated nametag
|
|
387
|
-
* @returns Decrypted nametag or null if none found
|
|
388
|
-
*/
|
|
389
|
-
recoverNametag?(): Promise<string | null>;
|
|
390
|
-
/**
|
|
391
|
-
* Publish identity binding event.
|
|
392
|
-
* Without nametag: publishes base binding (chainPubkey, l1Address, directAddress).
|
|
393
|
-
* With nametag: adds nametag hash, proxy address, encrypted nametag for recovery.
|
|
394
|
-
* Uses parameterized replaceable event (kind 30078, d=hash(nostrPubkey)).
|
|
395
|
-
* @returns true if successful, false if nametag is taken by another pubkey
|
|
396
|
-
*/
|
|
397
|
-
publishIdentityBinding?(chainPubkey: string, l1Address: string, directAddress: string, nametag?: string): Promise<boolean>;
|
|
398
|
-
/**
|
|
399
|
-
* @deprecated Use publishIdentityBinding instead
|
|
400
|
-
* Register a nametag for this identity
|
|
401
|
-
*/
|
|
402
|
-
registerNametag?(nametag: string, chainPubkey: string, directAddress: string): Promise<boolean>;
|
|
403
|
-
/**
|
|
404
|
-
* @deprecated Use publishIdentityBinding instead
|
|
405
|
-
* Publish nametag binding
|
|
406
|
-
*/
|
|
407
|
-
publishNametag?(nametag: string, address: string): Promise<void>;
|
|
408
|
-
/**
|
|
409
|
-
* Subscribe to broadcast messages (global/channel)
|
|
410
|
-
*/
|
|
411
|
-
subscribeToBroadcast?(tags: string[], handler: BroadcastHandler): () => void;
|
|
412
|
-
/**
|
|
413
|
-
* Publish broadcast message
|
|
414
|
-
*/
|
|
415
|
-
publishBroadcast?(content: string, tags?: string[]): Promise<string>;
|
|
416
|
-
/**
|
|
417
|
-
* Send payment request to a recipient
|
|
418
|
-
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
419
|
-
* @returns Event ID
|
|
113
|
+
* Send payment request to a recipient
|
|
114
|
+
* @param recipientTransportPubkey - Transport-specific pubkey for messaging
|
|
115
|
+
* @returns Event ID
|
|
420
116
|
*/
|
|
421
117
|
sendPaymentRequest?(recipientTransportPubkey: string, request: PaymentRequestPayload): Promise<string>;
|
|
422
118
|
/**
|
|
@@ -939,258 +635,662 @@ declare class NostrTransportProvider implements TransportProvider {
|
|
|
939
635
|
}
|
|
940
636
|
|
|
941
637
|
/**
|
|
942
|
-
*
|
|
943
|
-
*
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
*
|
|
638
|
+
* Oracle Provider Interface
|
|
639
|
+
* Platform-independent Unicity oracle abstraction
|
|
640
|
+
*
|
|
641
|
+
* The oracle is a trusted third-party service that provides verifiable truth
|
|
642
|
+
* about the state of tokens in the Unicity network. It aggregates state
|
|
643
|
+
* transitions into rounds and provides inclusion proofs that cryptographically
|
|
644
|
+
* verify token ownership and transfers.
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Unicity state transition oracle provider
|
|
649
|
+
*
|
|
650
|
+
* The oracle serves as the source of truth for:
|
|
651
|
+
* - Token state validation (spent/unspent)
|
|
652
|
+
* - State transition inclusion proofs
|
|
653
|
+
* - Round-based commitment aggregation
|
|
654
|
+
*/
|
|
655
|
+
interface OracleProvider extends BaseProvider {
|
|
656
|
+
/**
|
|
657
|
+
* Initialize with trust base
|
|
658
|
+
*/
|
|
659
|
+
initialize(trustBase?: unknown): Promise<void>;
|
|
660
|
+
/**
|
|
661
|
+
* Submit transfer commitment
|
|
662
|
+
*/
|
|
663
|
+
submitCommitment(commitment: TransferCommitment): Promise<SubmitResult>;
|
|
664
|
+
/**
|
|
665
|
+
* Get inclusion proof for a request
|
|
666
|
+
*/
|
|
667
|
+
getProof(requestId: string): Promise<InclusionProof | null>;
|
|
668
|
+
/**
|
|
669
|
+
* Wait for inclusion proof with polling
|
|
670
|
+
*/
|
|
671
|
+
waitForProof(requestId: string, options?: WaitOptions): Promise<InclusionProof>;
|
|
672
|
+
/**
|
|
673
|
+
* Validate token against aggregator
|
|
674
|
+
*/
|
|
675
|
+
validateToken(tokenData: unknown): Promise<ValidationResult>;
|
|
676
|
+
/**
|
|
677
|
+
* Check if token state is spent
|
|
678
|
+
*/
|
|
679
|
+
isSpent(stateHash: string): Promise<boolean>;
|
|
680
|
+
/**
|
|
681
|
+
* Get token state
|
|
682
|
+
*/
|
|
683
|
+
getTokenState(tokenId: string): Promise<TokenState | null>;
|
|
684
|
+
/**
|
|
685
|
+
* Get current round number
|
|
686
|
+
*/
|
|
687
|
+
getCurrentRound(): Promise<number>;
|
|
688
|
+
/**
|
|
689
|
+
* Mint new tokens (for faucet/testing)
|
|
690
|
+
*/
|
|
691
|
+
mint?(params: MintParams): Promise<MintResult>;
|
|
692
|
+
/**
|
|
693
|
+
* Get underlying StateTransitionClient (if available)
|
|
694
|
+
* Used for advanced SDK operations like commitment creation
|
|
695
|
+
*/
|
|
696
|
+
getStateTransitionClient?(): unknown;
|
|
697
|
+
/**
|
|
698
|
+
* Get underlying AggregatorClient (if available)
|
|
699
|
+
* Used for direct aggregator API access
|
|
700
|
+
*/
|
|
701
|
+
getAggregatorClient?(): unknown;
|
|
702
|
+
/**
|
|
703
|
+
* Wait for inclusion proof using SDK commitment (if available)
|
|
704
|
+
* Used for transfer flows with SDK TransferCommitment
|
|
705
|
+
*/
|
|
706
|
+
waitForProofSdk?(commitment: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
707
|
+
}
|
|
708
|
+
interface TransferCommitment {
|
|
709
|
+
/** Source token (SDK format) */
|
|
710
|
+
sourceToken: unknown;
|
|
711
|
+
/** Recipient address/predicate */
|
|
712
|
+
recipient: string;
|
|
713
|
+
/** Random salt (non-reproducible) */
|
|
714
|
+
salt: Uint8Array;
|
|
715
|
+
/** Optional additional data */
|
|
716
|
+
data?: unknown;
|
|
717
|
+
}
|
|
718
|
+
interface SubmitResult {
|
|
719
|
+
success: boolean;
|
|
720
|
+
requestId?: string;
|
|
721
|
+
error?: string;
|
|
722
|
+
timestamp: number;
|
|
723
|
+
}
|
|
724
|
+
interface InclusionProof {
|
|
725
|
+
requestId: string;
|
|
726
|
+
roundNumber: number;
|
|
727
|
+
proof: unknown;
|
|
728
|
+
timestamp: number;
|
|
729
|
+
}
|
|
730
|
+
interface WaitOptions {
|
|
731
|
+
/** Timeout in ms (default: 30000) */
|
|
732
|
+
timeout?: number;
|
|
733
|
+
/** Poll interval in ms (default: 1000) */
|
|
734
|
+
pollInterval?: number;
|
|
735
|
+
/** Callback on each poll attempt */
|
|
736
|
+
onPoll?: (attempt: number) => void;
|
|
737
|
+
}
|
|
738
|
+
interface ValidationResult {
|
|
739
|
+
valid: boolean;
|
|
740
|
+
spent: boolean;
|
|
741
|
+
error?: string;
|
|
742
|
+
stateHash?: string;
|
|
743
|
+
}
|
|
744
|
+
interface TokenState {
|
|
745
|
+
tokenId: string;
|
|
746
|
+
stateHash: string;
|
|
747
|
+
spent: boolean;
|
|
748
|
+
roundNumber?: number;
|
|
749
|
+
lastUpdated: number;
|
|
750
|
+
}
|
|
751
|
+
interface MintParams {
|
|
752
|
+
coinId: string;
|
|
753
|
+
amount: string;
|
|
754
|
+
recipientAddress: string;
|
|
755
|
+
recipientPubkey?: string;
|
|
756
|
+
}
|
|
757
|
+
interface MintResult {
|
|
758
|
+
success: boolean;
|
|
759
|
+
requestId?: string;
|
|
760
|
+
tokenId?: string;
|
|
761
|
+
error?: string;
|
|
762
|
+
}
|
|
763
|
+
type OracleEventType = 'oracle:connected' | 'oracle:disconnected' | 'oracle:error' | 'commitment:submitted' | 'proof:received' | 'validation:completed';
|
|
764
|
+
interface OracleEvent {
|
|
765
|
+
type: OracleEventType;
|
|
766
|
+
timestamp: number;
|
|
767
|
+
data?: unknown;
|
|
768
|
+
error?: string;
|
|
769
|
+
}
|
|
770
|
+
type OracleEventCallback = (event: OracleEvent) => void;
|
|
771
|
+
/**
|
|
772
|
+
* Trust base loader interface for platform-specific loading
|
|
773
|
+
* Browser: fetch from URL
|
|
774
|
+
* Node.js: read from file
|
|
775
|
+
*/
|
|
776
|
+
interface TrustBaseLoader$1 {
|
|
777
|
+
/**
|
|
778
|
+
* Load trust base JSON data
|
|
779
|
+
* @returns Trust base data or null if not available
|
|
780
|
+
*/
|
|
781
|
+
load(): Promise<unknown | null>;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Unicity Aggregator Provider
|
|
786
|
+
* Platform-independent implementation using @unicitylabs/state-transition-sdk
|
|
787
|
+
*
|
|
788
|
+
* The oracle is a trusted service that provides verifiable truth
|
|
789
|
+
* about token state through cryptographic inclusion proofs.
|
|
790
|
+
*
|
|
791
|
+
* TrustBaseLoader is injected for platform-specific loading:
|
|
792
|
+
* - Browser: fetch from URL
|
|
793
|
+
* - Node.js: read from file
|
|
794
|
+
*/
|
|
795
|
+
|
|
796
|
+
interface SdkMintCommitment {
|
|
797
|
+
requestId?: {
|
|
798
|
+
toString(): string;
|
|
799
|
+
};
|
|
800
|
+
[key: string]: unknown;
|
|
801
|
+
}
|
|
802
|
+
interface UnicityAggregatorProviderConfig {
|
|
803
|
+
/** Aggregator URL */
|
|
804
|
+
url: string;
|
|
805
|
+
/** API key for authentication */
|
|
806
|
+
apiKey?: string;
|
|
807
|
+
/** Request timeout (ms) */
|
|
808
|
+
timeout?: number;
|
|
809
|
+
/** Skip trust base verification (dev only) */
|
|
810
|
+
skipVerification?: boolean;
|
|
811
|
+
/** Enable debug logging */
|
|
812
|
+
debug?: boolean;
|
|
813
|
+
/** Trust base loader (platform-specific) */
|
|
814
|
+
trustBaseLoader?: TrustBaseLoader$1;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Unicity Aggregator Provider
|
|
818
|
+
* Concrete implementation of OracleProvider using Unicity's aggregator service
|
|
819
|
+
*/
|
|
820
|
+
declare class UnicityAggregatorProvider implements OracleProvider {
|
|
821
|
+
readonly id = "unicity-aggregator";
|
|
822
|
+
readonly name = "Unicity Aggregator";
|
|
823
|
+
readonly type: "network";
|
|
824
|
+
readonly description = "Unicity state transition aggregator (oracle implementation)";
|
|
825
|
+
private config;
|
|
826
|
+
private status;
|
|
827
|
+
private eventCallbacks;
|
|
828
|
+
private aggregatorClient;
|
|
829
|
+
private stateTransitionClient;
|
|
830
|
+
private trustBase;
|
|
831
|
+
/** Get the current trust base */
|
|
832
|
+
getTrustBase(): RootTrustBase | null;
|
|
833
|
+
/** Get the state transition client */
|
|
834
|
+
getStateTransitionClient(): StateTransitionClient | null;
|
|
835
|
+
/** Get the aggregator client */
|
|
836
|
+
getAggregatorClient(): AggregatorClient | null;
|
|
837
|
+
private spentCache;
|
|
838
|
+
constructor(config: UnicityAggregatorProviderConfig);
|
|
839
|
+
connect(): Promise<void>;
|
|
840
|
+
disconnect(): Promise<void>;
|
|
841
|
+
isConnected(): boolean;
|
|
842
|
+
getStatus(): ProviderStatus;
|
|
843
|
+
initialize(trustBase?: RootTrustBase): Promise<void>;
|
|
844
|
+
/**
|
|
845
|
+
* Submit a transfer commitment to the aggregator.
|
|
846
|
+
* Accepts either an SDK TransferCommitment or a simple commitment object.
|
|
847
|
+
*/
|
|
848
|
+
submitCommitment(commitment: TransferCommitment | TransferCommitment$1): Promise<SubmitResult>;
|
|
849
|
+
/**
|
|
850
|
+
* Submit a mint commitment to the aggregator (SDK only)
|
|
851
|
+
* @param commitment - SDK MintCommitment instance
|
|
852
|
+
*/
|
|
853
|
+
submitMintCommitment(commitment: SdkMintCommitment): Promise<SubmitResult>;
|
|
854
|
+
private isSdkTransferCommitment;
|
|
855
|
+
getProof(requestId: string): Promise<InclusionProof | null>;
|
|
856
|
+
waitForProof(requestId: string, options?: WaitOptions): Promise<InclusionProof>;
|
|
857
|
+
validateToken(tokenData: unknown): Promise<ValidationResult>;
|
|
858
|
+
/**
|
|
859
|
+
* Wait for inclusion proof using SDK (for SDK commitments)
|
|
860
|
+
*/
|
|
861
|
+
waitForProofSdk(commitment: TransferCommitment$1 | SdkMintCommitment, signal?: AbortSignal): Promise<unknown>;
|
|
862
|
+
isSpent(stateHash: string): Promise<boolean>;
|
|
863
|
+
getTokenState(tokenId: string): Promise<TokenState | null>;
|
|
864
|
+
getCurrentRound(): Promise<number>;
|
|
865
|
+
mint(params: MintParams): Promise<MintResult>;
|
|
866
|
+
onEvent(callback: OracleEventCallback): () => void;
|
|
867
|
+
private rpcCall;
|
|
868
|
+
private ensureConnected;
|
|
869
|
+
private emitEvent;
|
|
870
|
+
private log;
|
|
871
|
+
}
|
|
872
|
+
/** @deprecated Use UnicityAggregatorProvider instead */
|
|
873
|
+
declare const UnicityOracleProvider: typeof UnicityAggregatorProvider;
|
|
874
|
+
/** @deprecated Use UnicityAggregatorProviderConfig instead */
|
|
875
|
+
type UnicityOracleProviderConfig = UnicityAggregatorProviderConfig;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Price Provider Interface
|
|
879
|
+
*
|
|
880
|
+
* Platform-independent abstraction for fetching token market prices.
|
|
881
|
+
* Does not extend BaseProvider — stateless HTTP client with internal caching.
|
|
882
|
+
*/
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Supported price provider platforms
|
|
886
|
+
*/
|
|
887
|
+
type PricePlatform = 'coingecko';
|
|
888
|
+
/**
|
|
889
|
+
* Price data for a single token
|
|
890
|
+
*/
|
|
891
|
+
interface TokenPrice {
|
|
892
|
+
/** Token name used by the price platform (e.g., "bitcoin") */
|
|
893
|
+
readonly tokenName: string;
|
|
894
|
+
/** Price in USD */
|
|
895
|
+
readonly priceUsd: number;
|
|
896
|
+
/** Price in EUR (if available) */
|
|
897
|
+
readonly priceEur?: number;
|
|
898
|
+
/** 24h price change percentage (if available) */
|
|
899
|
+
readonly change24h?: number;
|
|
900
|
+
/** Timestamp when this price was fetched */
|
|
901
|
+
readonly timestamp: number;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Price data provider
|
|
905
|
+
*
|
|
906
|
+
* Fetches current market prices for tokens. Implementations handle
|
|
907
|
+
* caching internally to avoid excessive API calls.
|
|
908
|
+
*
|
|
909
|
+
* @example
|
|
910
|
+
* ```ts
|
|
911
|
+
* const provider = new CoinGeckoPriceProvider({ apiKey: 'CG-xxx' });
|
|
912
|
+
* const prices = await provider.getPrices(['bitcoin', 'ethereum']);
|
|
913
|
+
* console.log(prices.get('bitcoin')?.priceUsd); // 97500
|
|
914
|
+
* ```
|
|
915
|
+
*/
|
|
916
|
+
interface PriceProvider {
|
|
917
|
+
/** Platform identifier (e.g., 'coingecko') */
|
|
918
|
+
readonly platform: PricePlatform;
|
|
919
|
+
/**
|
|
920
|
+
* Get prices for multiple tokens by their platform-compatible names
|
|
921
|
+
* @param tokenNames - Array of token names (e.g., ['bitcoin', 'ethereum'])
|
|
922
|
+
* @returns Map of token name to price data
|
|
923
|
+
*/
|
|
924
|
+
getPrices(tokenNames: string[]): Promise<Map<string, TokenPrice>>;
|
|
925
|
+
/**
|
|
926
|
+
* Get price for a single token
|
|
927
|
+
* @param tokenName - Token name (e.g., 'bitcoin')
|
|
928
|
+
* @returns Token price (zero-price entry for tokens not listed on the platform), or null on network error with no cache
|
|
929
|
+
*/
|
|
930
|
+
getPrice(tokenName: string): Promise<TokenPrice | null>;
|
|
931
|
+
/**
|
|
932
|
+
* Clear cached prices
|
|
933
|
+
*/
|
|
934
|
+
clearCache(): void;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
interface GroupChatModuleConfig {
|
|
938
|
+
/** Override relay URLs (default: from network config) */
|
|
939
|
+
relays?: string[];
|
|
940
|
+
/** Default message fetch limit (default: 50) */
|
|
941
|
+
defaultMessageLimit?: number;
|
|
942
|
+
/** Max previous message IDs in ordering tags (default: 3) */
|
|
943
|
+
maxPreviousTags?: number;
|
|
944
|
+
/** Reconnect delay in ms (default: 3000) */
|
|
945
|
+
reconnectDelayMs?: number;
|
|
946
|
+
/** Max reconnect attempts (default: 5) */
|
|
947
|
+
maxReconnectAttempts?: number;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* SDK2 Core Types
|
|
952
|
+
* Platform-independent type definitions
|
|
948
953
|
*/
|
|
949
|
-
|
|
954
|
+
type ProviderStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
955
|
+
interface ProviderMetadata {
|
|
956
|
+
readonly id: string;
|
|
957
|
+
readonly name: string;
|
|
958
|
+
readonly type: 'local' | 'cloud' | 'p2p' | 'network';
|
|
959
|
+
readonly description?: string;
|
|
960
|
+
}
|
|
961
|
+
interface BaseProvider extends ProviderMetadata {
|
|
962
|
+
connect(config?: unknown): Promise<void>;
|
|
963
|
+
disconnect(): Promise<void>;
|
|
964
|
+
isConnected(): boolean;
|
|
965
|
+
getStatus(): ProviderStatus;
|
|
966
|
+
}
|
|
967
|
+
interface Identity {
|
|
968
|
+
/** 33-byte compressed secp256k1 public key (for L3 chain) */
|
|
969
|
+
readonly chainPubkey: string;
|
|
970
|
+
/** L1 address (alpha1...) */
|
|
971
|
+
readonly l1Address: string;
|
|
972
|
+
/** L3 DIRECT address (DIRECT://...) */
|
|
973
|
+
readonly directAddress?: string;
|
|
974
|
+
readonly ipnsName?: string;
|
|
975
|
+
readonly nametag?: string;
|
|
976
|
+
}
|
|
977
|
+
interface FullIdentity extends Identity {
|
|
978
|
+
readonly privateKey: string;
|
|
979
|
+
}
|
|
980
|
+
interface ComposingIndicator {
|
|
981
|
+
readonly senderPubkey: string;
|
|
982
|
+
readonly senderNametag?: string;
|
|
983
|
+
readonly expiresIn: number;
|
|
984
|
+
}
|
|
950
985
|
/**
|
|
951
|
-
*
|
|
986
|
+
* Minimal data stored in persistent storage for a tracked address.
|
|
987
|
+
* Only contains user state — derived fields are computed on load.
|
|
952
988
|
*/
|
|
953
|
-
|
|
989
|
+
interface TrackedAddressEntry {
|
|
990
|
+
/** HD derivation index (0, 1, 2, ...) */
|
|
991
|
+
readonly index: number;
|
|
992
|
+
/** Whether this address is hidden from UI display */
|
|
993
|
+
hidden: boolean;
|
|
994
|
+
/** Timestamp (ms) when this address was first activated */
|
|
995
|
+
readonly createdAt: number;
|
|
996
|
+
/** Timestamp (ms) of last modification */
|
|
997
|
+
updatedAt: number;
|
|
998
|
+
}
|
|
954
999
|
|
|
955
1000
|
/**
|
|
956
|
-
*
|
|
957
|
-
* Platform-independent
|
|
958
|
-
*
|
|
959
|
-
* The oracle is a trusted third-party service that provides verifiable truth
|
|
960
|
-
* about the state of tokens in the Unicity network. It aggregates state
|
|
961
|
-
* transitions into rounds and provides inclusion proofs that cryptographically
|
|
962
|
-
* verify token ownership and transfers.
|
|
1001
|
+
* Storage Provider Interface
|
|
1002
|
+
* Platform-independent storage abstraction
|
|
963
1003
|
*/
|
|
964
1004
|
|
|
965
1005
|
/**
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
* The oracle serves as the source of truth for:
|
|
969
|
-
* - Token state validation (spent/unspent)
|
|
970
|
-
* - State transition inclusion proofs
|
|
971
|
-
* - Round-based commitment aggregation
|
|
1006
|
+
* Basic key-value storage provider
|
|
1007
|
+
* All operations are async for platform flexibility
|
|
972
1008
|
*/
|
|
973
|
-
interface
|
|
974
|
-
/**
|
|
975
|
-
* Initialize with trust base
|
|
976
|
-
*/
|
|
977
|
-
initialize(trustBase?: unknown): Promise<void>;
|
|
978
|
-
/**
|
|
979
|
-
* Submit transfer commitment
|
|
980
|
-
*/
|
|
981
|
-
submitCommitment(commitment: TransferCommitment): Promise<SubmitResult>;
|
|
982
|
-
/**
|
|
983
|
-
* Get inclusion proof for a request
|
|
984
|
-
*/
|
|
985
|
-
getProof(requestId: string): Promise<InclusionProof | null>;
|
|
1009
|
+
interface StorageProvider extends BaseProvider {
|
|
986
1010
|
/**
|
|
987
|
-
*
|
|
1011
|
+
* Set identity for scoped storage
|
|
988
1012
|
*/
|
|
989
|
-
|
|
1013
|
+
setIdentity(identity: FullIdentity): void;
|
|
990
1014
|
/**
|
|
991
|
-
*
|
|
1015
|
+
* Get value by key
|
|
992
1016
|
*/
|
|
993
|
-
|
|
1017
|
+
get(key: string): Promise<string | null>;
|
|
994
1018
|
/**
|
|
995
|
-
*
|
|
1019
|
+
* Set value by key
|
|
996
1020
|
*/
|
|
997
|
-
|
|
1021
|
+
set(key: string, value: string): Promise<void>;
|
|
998
1022
|
/**
|
|
999
|
-
*
|
|
1023
|
+
* Remove key
|
|
1000
1024
|
*/
|
|
1001
|
-
|
|
1025
|
+
remove(key: string): Promise<void>;
|
|
1002
1026
|
/**
|
|
1003
|
-
*
|
|
1027
|
+
* Check if key exists
|
|
1004
1028
|
*/
|
|
1005
|
-
|
|
1029
|
+
has(key: string): Promise<boolean>;
|
|
1006
1030
|
/**
|
|
1007
|
-
*
|
|
1031
|
+
* Get all keys with optional prefix filter
|
|
1008
1032
|
*/
|
|
1009
|
-
|
|
1033
|
+
keys(prefix?: string): Promise<string[]>;
|
|
1010
1034
|
/**
|
|
1011
|
-
*
|
|
1012
|
-
* Used for advanced SDK operations like commitment creation
|
|
1035
|
+
* Clear all keys with optional prefix filter
|
|
1013
1036
|
*/
|
|
1014
|
-
|
|
1037
|
+
clear(prefix?: string): Promise<void>;
|
|
1015
1038
|
/**
|
|
1016
|
-
*
|
|
1017
|
-
* Used for direct aggregator API access
|
|
1039
|
+
* Save tracked addresses (only user state: index, hidden, timestamps)
|
|
1018
1040
|
*/
|
|
1019
|
-
|
|
1041
|
+
saveTrackedAddresses(entries: TrackedAddressEntry[]): Promise<void>;
|
|
1020
1042
|
/**
|
|
1021
|
-
*
|
|
1022
|
-
* Used for transfer flows with SDK TransferCommitment
|
|
1043
|
+
* Load tracked addresses
|
|
1023
1044
|
*/
|
|
1024
|
-
|
|
1045
|
+
loadTrackedAddresses(): Promise<TrackedAddressEntry[]>;
|
|
1025
1046
|
}
|
|
1026
|
-
interface
|
|
1027
|
-
/**
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1047
|
+
interface HistoryRecord {
|
|
1048
|
+
/** Composite dedup key (primary key) — e.g. "RECEIVED_v5split_abc123" */
|
|
1049
|
+
dedupKey: string;
|
|
1050
|
+
/** UUID for public API consumption */
|
|
1051
|
+
id: string;
|
|
1052
|
+
type: 'SENT' | 'RECEIVED' | 'SPLIT' | 'MINT';
|
|
1053
|
+
amount: string;
|
|
1054
|
+
coinId: string;
|
|
1055
|
+
symbol: string;
|
|
1056
|
+
timestamp: number;
|
|
1057
|
+
transferId?: string;
|
|
1058
|
+
/** Genesis tokenId this entry relates to (used for dedup) */
|
|
1059
|
+
tokenId?: string;
|
|
1060
|
+
senderPubkey?: string;
|
|
1061
|
+
senderAddress?: string;
|
|
1062
|
+
senderNametag?: string;
|
|
1063
|
+
recipientPubkey?: string;
|
|
1064
|
+
recipientAddress?: string;
|
|
1065
|
+
recipientNametag?: string;
|
|
1066
|
+
/** Optional memo/message attached to the transfer */
|
|
1067
|
+
memo?: string;
|
|
1035
1068
|
}
|
|
1036
|
-
|
|
1069
|
+
/**
|
|
1070
|
+
* Storage result types
|
|
1071
|
+
*/
|
|
1072
|
+
interface SaveResult {
|
|
1037
1073
|
success: boolean;
|
|
1038
|
-
|
|
1074
|
+
cid?: string;
|
|
1039
1075
|
error?: string;
|
|
1040
1076
|
timestamp: number;
|
|
1041
1077
|
}
|
|
1042
|
-
interface
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1078
|
+
interface LoadResult<T = unknown> {
|
|
1079
|
+
success: boolean;
|
|
1080
|
+
data?: T;
|
|
1081
|
+
error?: string;
|
|
1082
|
+
source: 'local' | 'remote' | 'cache';
|
|
1046
1083
|
timestamp: number;
|
|
1047
1084
|
}
|
|
1048
|
-
interface
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
onPoll?: (attempt: number) => void;
|
|
1055
|
-
}
|
|
1056
|
-
interface ValidationResult {
|
|
1057
|
-
valid: boolean;
|
|
1058
|
-
spent: boolean;
|
|
1085
|
+
interface SyncResult<T = unknown> {
|
|
1086
|
+
success: boolean;
|
|
1087
|
+
merged?: T;
|
|
1088
|
+
added: number;
|
|
1089
|
+
removed: number;
|
|
1090
|
+
conflicts: number;
|
|
1059
1091
|
error?: string;
|
|
1060
|
-
stateHash?: string;
|
|
1061
|
-
}
|
|
1062
|
-
interface TokenState {
|
|
1063
|
-
tokenId: string;
|
|
1064
|
-
stateHash: string;
|
|
1065
|
-
spent: boolean;
|
|
1066
|
-
roundNumber?: number;
|
|
1067
|
-
lastUpdated: number;
|
|
1068
1092
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1093
|
+
/**
|
|
1094
|
+
* Token-specific storage provider
|
|
1095
|
+
* Handles token persistence with sync capabilities
|
|
1096
|
+
*/
|
|
1097
|
+
interface TokenStorageProvider<TData = unknown> extends BaseProvider {
|
|
1098
|
+
/**
|
|
1099
|
+
* Set identity for storage scope
|
|
1100
|
+
*/
|
|
1101
|
+
setIdentity(identity: FullIdentity): void;
|
|
1102
|
+
/**
|
|
1103
|
+
* Initialize provider (called once after identity is set)
|
|
1104
|
+
*/
|
|
1105
|
+
initialize(): Promise<boolean>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Shutdown provider
|
|
1108
|
+
*/
|
|
1109
|
+
shutdown(): Promise<void>;
|
|
1110
|
+
/**
|
|
1111
|
+
* Save token data
|
|
1112
|
+
*/
|
|
1113
|
+
save(data: TData): Promise<SaveResult>;
|
|
1114
|
+
/**
|
|
1115
|
+
* Load token data
|
|
1116
|
+
*/
|
|
1117
|
+
load(identifier?: string): Promise<LoadResult<TData>>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Sync local data with remote
|
|
1120
|
+
*/
|
|
1121
|
+
sync(localData: TData): Promise<SyncResult<TData>>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Check if data exists
|
|
1124
|
+
*/
|
|
1125
|
+
exists?(identifier?: string): Promise<boolean>;
|
|
1126
|
+
/**
|
|
1127
|
+
* Clear all data
|
|
1128
|
+
*/
|
|
1129
|
+
clear?(): Promise<boolean>;
|
|
1130
|
+
/**
|
|
1131
|
+
* Subscribe to storage events
|
|
1132
|
+
*/
|
|
1133
|
+
onEvent?(callback: StorageEventCallback): () => void;
|
|
1134
|
+
/** Store a history entry (upsert by dedupKey) */
|
|
1135
|
+
addHistoryEntry?(entry: HistoryRecord): Promise<void>;
|
|
1136
|
+
/** Get all history entries sorted by timestamp descending */
|
|
1137
|
+
getHistoryEntries?(): Promise<HistoryRecord[]>;
|
|
1138
|
+
/** Check if a history entry exists by dedupKey */
|
|
1139
|
+
hasHistoryEntry?(dedupKey: string): Promise<boolean>;
|
|
1140
|
+
/** Clear all history entries */
|
|
1141
|
+
clearHistory?(): Promise<void>;
|
|
1142
|
+
/** Bulk import history entries (skip existing dedupKeys). Returns count of newly imported. */
|
|
1143
|
+
importHistoryEntries?(entries: HistoryRecord[]): Promise<number>;
|
|
1074
1144
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1145
|
+
type StorageEventType = 'storage:saving' | 'storage:saved' | 'storage:loading' | 'storage:loaded' | 'storage:error' | 'storage:remote-updated' | 'sync:started' | 'sync:completed' | 'sync:conflict' | 'sync:error';
|
|
1146
|
+
interface StorageEvent {
|
|
1147
|
+
type: StorageEventType;
|
|
1148
|
+
timestamp: number;
|
|
1149
|
+
data?: unknown;
|
|
1079
1150
|
error?: string;
|
|
1080
1151
|
}
|
|
1081
|
-
type
|
|
1082
|
-
interface
|
|
1083
|
-
|
|
1152
|
+
type StorageEventCallback = (event: StorageEvent) => void;
|
|
1153
|
+
interface TxfStorageDataBase {
|
|
1154
|
+
_meta: TxfMeta;
|
|
1155
|
+
_tombstones?: TxfTombstone[];
|
|
1156
|
+
_outbox?: TxfOutboxEntry[];
|
|
1157
|
+
_sent?: TxfSentEntry[];
|
|
1158
|
+
_invalid?: TxfInvalidEntry[];
|
|
1159
|
+
[key: `_${string}`]: unknown;
|
|
1160
|
+
}
|
|
1161
|
+
interface TxfMeta {
|
|
1162
|
+
version: number;
|
|
1163
|
+
address: string;
|
|
1164
|
+
ipnsName?: string;
|
|
1165
|
+
formatVersion: string;
|
|
1166
|
+
updatedAt: number;
|
|
1167
|
+
}
|
|
1168
|
+
interface TxfTombstone {
|
|
1169
|
+
tokenId: string;
|
|
1170
|
+
stateHash: string;
|
|
1084
1171
|
timestamp: number;
|
|
1085
|
-
data?: unknown;
|
|
1086
|
-
error?: string;
|
|
1087
1172
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1173
|
+
interface TxfOutboxEntry {
|
|
1174
|
+
id: string;
|
|
1175
|
+
status: string;
|
|
1176
|
+
tokenId: string;
|
|
1177
|
+
recipient: string;
|
|
1178
|
+
createdAt: number;
|
|
1179
|
+
data: unknown;
|
|
1180
|
+
}
|
|
1181
|
+
interface TxfSentEntry {
|
|
1182
|
+
tokenId: string;
|
|
1183
|
+
recipient: string;
|
|
1184
|
+
txHash: string;
|
|
1185
|
+
sentAt: number;
|
|
1186
|
+
}
|
|
1187
|
+
interface TxfInvalidEntry {
|
|
1188
|
+
tokenId: string;
|
|
1189
|
+
reason: string;
|
|
1190
|
+
detectedAt: number;
|
|
1100
1191
|
}
|
|
1101
1192
|
|
|
1102
1193
|
/**
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1106
|
-
* The oracle is a trusted service that provides verifiable truth
|
|
1107
|
-
* about token state through cryptographic inclusion proofs.
|
|
1108
|
-
*
|
|
1109
|
-
* TrustBaseLoader is injected for platform-specific loading:
|
|
1110
|
-
* - Browser: fetch from URL
|
|
1111
|
-
* - Node.js: read from file
|
|
1194
|
+
* File Storage Provider for Node.js
|
|
1195
|
+
* Stores wallet data in JSON files
|
|
1112
1196
|
*/
|
|
1113
1197
|
|
|
1114
|
-
interface
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
}
|
|
1120
|
-
interface UnicityAggregatorProviderConfig {
|
|
1121
|
-
/** Aggregator URL */
|
|
1122
|
-
url: string;
|
|
1123
|
-
/** API key for authentication */
|
|
1124
|
-
apiKey?: string;
|
|
1125
|
-
/** Request timeout (ms) */
|
|
1126
|
-
timeout?: number;
|
|
1127
|
-
/** Skip trust base verification (dev only) */
|
|
1128
|
-
skipVerification?: boolean;
|
|
1129
|
-
/** Enable debug logging */
|
|
1130
|
-
debug?: boolean;
|
|
1131
|
-
/** Trust base loader (platform-specific) */
|
|
1132
|
-
trustBaseLoader?: TrustBaseLoader$1;
|
|
1198
|
+
interface FileStorageProviderConfig {
|
|
1199
|
+
/** Directory to store wallet data */
|
|
1200
|
+
dataDir: string;
|
|
1201
|
+
/** File name for key-value data (default: 'wallet.json') */
|
|
1202
|
+
fileName?: string;
|
|
1133
1203
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
readonly description = "Unicity state transition aggregator (oracle implementation)";
|
|
1143
|
-
private config;
|
|
1204
|
+
declare class FileStorageProvider implements StorageProvider {
|
|
1205
|
+
readonly id = "file-storage";
|
|
1206
|
+
readonly name = "File Storage";
|
|
1207
|
+
readonly type: "local";
|
|
1208
|
+
private dataDir;
|
|
1209
|
+
private filePath;
|
|
1210
|
+
private isTxtMode;
|
|
1211
|
+
private data;
|
|
1144
1212
|
private status;
|
|
1145
|
-
private
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
/** Get the current trust base */
|
|
1150
|
-
getTrustBase(): RootTrustBase | null;
|
|
1151
|
-
/** Get the state transition client */
|
|
1152
|
-
getStateTransitionClient(): StateTransitionClient | null;
|
|
1153
|
-
/** Get the aggregator client */
|
|
1154
|
-
getAggregatorClient(): AggregatorClient | null;
|
|
1155
|
-
private spentCache;
|
|
1156
|
-
constructor(config: UnicityAggregatorProviderConfig);
|
|
1213
|
+
private _identity;
|
|
1214
|
+
constructor(config: FileStorageProviderConfig | string);
|
|
1215
|
+
setIdentity(identity: FullIdentity): void;
|
|
1216
|
+
getIdentity(): FullIdentity | null;
|
|
1157
1217
|
connect(): Promise<void>;
|
|
1158
1218
|
disconnect(): Promise<void>;
|
|
1159
1219
|
isConnected(): boolean;
|
|
1160
1220
|
getStatus(): ProviderStatus;
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1221
|
+
get(key: string): Promise<string | null>;
|
|
1222
|
+
set(key: string, value: string): Promise<void>;
|
|
1223
|
+
remove(key: string): Promise<void>;
|
|
1224
|
+
has(key: string): Promise<boolean>;
|
|
1225
|
+
keys(prefix?: string): Promise<string[]>;
|
|
1226
|
+
clear(prefix?: string): Promise<void>;
|
|
1227
|
+
saveTrackedAddresses(entries: TrackedAddressEntry[]): Promise<void>;
|
|
1228
|
+
loadTrackedAddresses(): Promise<TrackedAddressEntry[]>;
|
|
1167
1229
|
/**
|
|
1168
|
-
*
|
|
1169
|
-
* @param commitment - SDK MintCommitment instance
|
|
1230
|
+
* Get full storage key with address prefix for per-address keys
|
|
1170
1231
|
*/
|
|
1171
|
-
|
|
1172
|
-
private
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1232
|
+
private getFullKey;
|
|
1233
|
+
private save;
|
|
1234
|
+
}
|
|
1235
|
+
declare function createFileStorageProvider(config: FileStorageProviderConfig | string): FileStorageProvider;
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* File Token Storage Provider for Node.js
|
|
1239
|
+
* Stores tokens as individual JSON files in per-address subdirectories
|
|
1240
|
+
*/
|
|
1241
|
+
|
|
1242
|
+
interface FileTokenStorageConfig {
|
|
1243
|
+
/** Directory to store token files */
|
|
1244
|
+
tokensDir: string;
|
|
1245
|
+
}
|
|
1246
|
+
declare class FileTokenStorageProvider implements TokenStorageProvider<TxfStorageDataBase> {
|
|
1247
|
+
readonly id = "file-token-storage";
|
|
1248
|
+
readonly name = "File Token Storage";
|
|
1249
|
+
readonly type: "local";
|
|
1250
|
+
private baseTokensDir;
|
|
1251
|
+
private status;
|
|
1252
|
+
private identity;
|
|
1253
|
+
constructor(config: FileTokenStorageConfig | string);
|
|
1254
|
+
setIdentity(identity: FullIdentity): void;
|
|
1176
1255
|
/**
|
|
1177
|
-
*
|
|
1256
|
+
* Get tokens directory for current address
|
|
1257
|
+
* Format: {baseTokensDir}/{addressId}/
|
|
1178
1258
|
*/
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1259
|
+
private get tokensDir();
|
|
1260
|
+
initialize(): Promise<boolean>;
|
|
1261
|
+
shutdown(): Promise<void>;
|
|
1262
|
+
connect(): Promise<void>;
|
|
1263
|
+
disconnect(): Promise<void>;
|
|
1264
|
+
isConnected(): boolean;
|
|
1265
|
+
getStatus(): ProviderStatus;
|
|
1266
|
+
load(): Promise<LoadResult<TxfStorageDataBase>>;
|
|
1267
|
+
save(data: TxfStorageDataBase): Promise<SaveResult>;
|
|
1268
|
+
sync(localData: TxfStorageDataBase): Promise<SyncResult<TxfStorageDataBase>>;
|
|
1269
|
+
clear(): Promise<boolean>;
|
|
1270
|
+
private get historyPath();
|
|
1271
|
+
private readHistoryFile;
|
|
1272
|
+
private writeHistoryFile;
|
|
1273
|
+
addHistoryEntry(entry: HistoryRecord): Promise<void>;
|
|
1274
|
+
getHistoryEntries(): Promise<HistoryRecord[]>;
|
|
1275
|
+
hasHistoryEntry(dedupKey: string): Promise<boolean>;
|
|
1276
|
+
clearHistory(): Promise<void>;
|
|
1277
|
+
importHistoryEntries(entries: HistoryRecord[]): Promise<number>;
|
|
1189
1278
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
/**
|
|
1193
|
-
|
|
1279
|
+
declare function createFileTokenStorageProvider(config: FileTokenStorageConfig | string): FileTokenStorageProvider;
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Node.js Transport Exports
|
|
1283
|
+
* Re-exports shared transport with Node.js WebSocket
|
|
1284
|
+
*/
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* Create WebSocket factory for Node.js using 'ws' package
|
|
1288
|
+
*/
|
|
1289
|
+
declare function createNodeWebSocketFactory(): WebSocketFactory;
|
|
1290
|
+
/**
|
|
1291
|
+
* Create NostrTransportProvider with Node.js WebSocket
|
|
1292
|
+
*/
|
|
1293
|
+
declare function createNostrTransportProvider(config: Omit<NostrTransportProviderConfig, 'createWebSocket'>): NostrTransportProvider;
|
|
1194
1294
|
|
|
1195
1295
|
/** Network configurations */
|
|
1196
1296
|
declare const NETWORKS: {
|
|
@@ -1273,66 +1373,6 @@ declare function createUnicityAggregatorProvider(config: Omit<UnicityAggregatorP
|
|
|
1273
1373
|
/** @deprecated Use createUnicityAggregatorProvider instead */
|
|
1274
1374
|
declare const createUnicityOracleProvider: typeof createUnicityAggregatorProvider;
|
|
1275
1375
|
|
|
1276
|
-
/**
|
|
1277
|
-
* Price Provider Interface
|
|
1278
|
-
*
|
|
1279
|
-
* Platform-independent abstraction for fetching token market prices.
|
|
1280
|
-
* Does not extend BaseProvider — stateless HTTP client with internal caching.
|
|
1281
|
-
*/
|
|
1282
|
-
|
|
1283
|
-
/**
|
|
1284
|
-
* Supported price provider platforms
|
|
1285
|
-
*/
|
|
1286
|
-
type PricePlatform = 'coingecko';
|
|
1287
|
-
/**
|
|
1288
|
-
* Price data for a single token
|
|
1289
|
-
*/
|
|
1290
|
-
interface TokenPrice {
|
|
1291
|
-
/** Token name used by the price platform (e.g., "bitcoin") */
|
|
1292
|
-
readonly tokenName: string;
|
|
1293
|
-
/** Price in USD */
|
|
1294
|
-
readonly priceUsd: number;
|
|
1295
|
-
/** Price in EUR (if available) */
|
|
1296
|
-
readonly priceEur?: number;
|
|
1297
|
-
/** 24h price change percentage (if available) */
|
|
1298
|
-
readonly change24h?: number;
|
|
1299
|
-
/** Timestamp when this price was fetched */
|
|
1300
|
-
readonly timestamp: number;
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Price data provider
|
|
1304
|
-
*
|
|
1305
|
-
* Fetches current market prices for tokens. Implementations handle
|
|
1306
|
-
* caching internally to avoid excessive API calls.
|
|
1307
|
-
*
|
|
1308
|
-
* @example
|
|
1309
|
-
* ```ts
|
|
1310
|
-
* const provider = new CoinGeckoPriceProvider({ apiKey: 'CG-xxx' });
|
|
1311
|
-
* const prices = await provider.getPrices(['bitcoin', 'ethereum']);
|
|
1312
|
-
* console.log(prices.get('bitcoin')?.priceUsd); // 97500
|
|
1313
|
-
* ```
|
|
1314
|
-
*/
|
|
1315
|
-
interface PriceProvider {
|
|
1316
|
-
/** Platform identifier (e.g., 'coingecko') */
|
|
1317
|
-
readonly platform: PricePlatform;
|
|
1318
|
-
/**
|
|
1319
|
-
* Get prices for multiple tokens by their platform-compatible names
|
|
1320
|
-
* @param tokenNames - Array of token names (e.g., ['bitcoin', 'ethereum'])
|
|
1321
|
-
* @returns Map of token name to price data
|
|
1322
|
-
*/
|
|
1323
|
-
getPrices(tokenNames: string[]): Promise<Map<string, TokenPrice>>;
|
|
1324
|
-
/**
|
|
1325
|
-
* Get price for a single token
|
|
1326
|
-
* @param tokenName - Token name (e.g., 'bitcoin')
|
|
1327
|
-
* @returns Token price (zero-price entry for tokens not listed on the platform), or null on network error with no cache
|
|
1328
|
-
*/
|
|
1329
|
-
getPrice(tokenName: string): Promise<TokenPrice | null>;
|
|
1330
|
-
/**
|
|
1331
|
-
* Clear cached prices
|
|
1332
|
-
*/
|
|
1333
|
-
clearCache(): void;
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
1376
|
/**
|
|
1337
1377
|
* Shared Configuration Interfaces
|
|
1338
1378
|
* Base types extended by platform-specific implementations
|