@unicitylabs/sphere-sdk 0.2.2 → 0.2.5
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/README.md +73 -79
- package/dist/core/index.cjs +1220 -275
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +422 -221
- package/dist/core/index.d.ts +422 -221
- package/dist/core/index.js +1219 -275
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +2077 -14
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +2077 -14
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +1877 -513
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +1877 -513
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +2222 -172
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +84 -3
- package/dist/impl/nodejs/index.d.ts +84 -3
- package/dist/impl/nodejs/index.js +2222 -172
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +1231 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +440 -67
- package/dist/index.d.ts +440 -67
- package/dist/index.js +1231 -265
- package/dist/index.js.map +1 -1
- package/package.json +25 -5
package/dist/core/index.d.ts
CHANGED
|
@@ -272,147 +272,6 @@ interface TombstoneEntry {
|
|
|
272
272
|
timestamp: number;
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
/**
|
|
276
|
-
* INSTANT_SPLIT V5 Types
|
|
277
|
-
*
|
|
278
|
-
* Optimized token split transfer types that achieve ~2.3s critical path latency
|
|
279
|
-
* instead of the standard ~42s sequential flow.
|
|
280
|
-
*
|
|
281
|
-
* Key Insight: TransferCommitment.create() only needs token.state, NOT the mint proof.
|
|
282
|
-
* This allows creating transfer commitments immediately after mint data creation,
|
|
283
|
-
* without waiting for mint proofs.
|
|
284
|
-
*
|
|
285
|
-
* V5 Flow (Production Mode):
|
|
286
|
-
* 1. Create burn commitment, submit to aggregator
|
|
287
|
-
* 2. Wait for burn inclusion proof (~2s - unavoidable)
|
|
288
|
-
* 3. Create mint commitments with proper SplitMintReason (requires burn proof)
|
|
289
|
-
* 4. Create transfer commitment from mint data (no mint proof needed)
|
|
290
|
-
* 5. Package bundle -> send via Nostr -> SUCCESS (~2.3s total!)
|
|
291
|
-
* 6. Background: submit mints, wait for proofs, save change token, sync storage
|
|
292
|
-
*/
|
|
293
|
-
type SdkToken = any;
|
|
294
|
-
/**
|
|
295
|
-
* Bundle payload for INSTANT_SPLIT V5 (Production Mode)
|
|
296
|
-
*
|
|
297
|
-
* V5 achieves ~2.3s sender latency while working with production aggregators:
|
|
298
|
-
* - Burn proof is required for creating SplitMintReason
|
|
299
|
-
* - Transfer commitment is created from mint data WITHOUT waiting for mint proof
|
|
300
|
-
* - Mints are submitted in background after Nostr delivery
|
|
301
|
-
*
|
|
302
|
-
* Security: Burn is proven on-chain before mints can be created, preventing double-spend.
|
|
303
|
-
*/
|
|
304
|
-
interface InstantSplitBundleV5 {
|
|
305
|
-
/** Bundle version - V5 is production mode (proper SplitMintReason) */
|
|
306
|
-
version: '5.0';
|
|
307
|
-
/** Bundle type identifier */
|
|
308
|
-
type: 'INSTANT_SPLIT';
|
|
309
|
-
/**
|
|
310
|
-
* Burn TRANSACTION JSON (WITH inclusion proof!)
|
|
311
|
-
* V5 sends the proven burn transaction so recipient can verify burn completed.
|
|
312
|
-
*/
|
|
313
|
-
burnTransaction: string;
|
|
314
|
-
/**
|
|
315
|
-
* Recipient's MintTransactionData JSON (contains proper SplitMintReason in V5)
|
|
316
|
-
* The SplitMintReason references the burn transaction.
|
|
317
|
-
*/
|
|
318
|
-
recipientMintData: string;
|
|
319
|
-
/**
|
|
320
|
-
* Pre-created TransferCommitment JSON (recipient submits and waits for proof)
|
|
321
|
-
* Created from mint data WITHOUT any proofs.
|
|
322
|
-
*/
|
|
323
|
-
transferCommitment: string;
|
|
324
|
-
/** Payment amount (display metadata) */
|
|
325
|
-
amount: string;
|
|
326
|
-
/** Coin ID hex */
|
|
327
|
-
coinId: string;
|
|
328
|
-
/** Token type hex */
|
|
329
|
-
tokenTypeHex: string;
|
|
330
|
-
/** Split group ID for recovery correlation */
|
|
331
|
-
splitGroupId: string;
|
|
332
|
-
/** Sender's pubkey for acknowledgment */
|
|
333
|
-
senderPubkey: string;
|
|
334
|
-
/** Salt for recipient predicate creation (hex) */
|
|
335
|
-
recipientSaltHex: string;
|
|
336
|
-
/** Salt for transfer commitment creation (hex) */
|
|
337
|
-
transferSaltHex: string;
|
|
338
|
-
/**
|
|
339
|
-
* Serialized TokenState JSON for the intermediate minted token.
|
|
340
|
-
*
|
|
341
|
-
* In V5, the mint is to sender's address first, then transferred to recipient.
|
|
342
|
-
* The recipient needs this state to reconstruct the minted token before applying transfer.
|
|
343
|
-
* Without this, the recipient can't create a matching predicate (they don't have sender's signing key).
|
|
344
|
-
*/
|
|
345
|
-
mintedTokenStateJson: string;
|
|
346
|
-
/**
|
|
347
|
-
* Serialized TokenState JSON for the final recipient state (after transfer).
|
|
348
|
-
*
|
|
349
|
-
* The sender creates the transfer commitment targeting the recipient's PROXY address.
|
|
350
|
-
* The recipient can't recreate this state correctly because their signingService
|
|
351
|
-
* creates predicates for their DIRECT address, not the PROXY address.
|
|
352
|
-
* This is optional - recipient can create their own if they have the correct address.
|
|
353
|
-
*/
|
|
354
|
-
finalRecipientStateJson: string;
|
|
355
|
-
/**
|
|
356
|
-
* Serialized recipient address JSON (PROXY or DIRECT).
|
|
357
|
-
*
|
|
358
|
-
* Used by the recipient to identify which nametag token is being targeted.
|
|
359
|
-
* For PROXY address transfers, the recipient needs to find the matching
|
|
360
|
-
* nametag token and pass it to finalizeTransaction() for verification.
|
|
361
|
-
*/
|
|
362
|
-
recipientAddressJson: string;
|
|
363
|
-
/**
|
|
364
|
-
* Serialized nametag token JSON (for PROXY address transfers).
|
|
365
|
-
*
|
|
366
|
-
* For PROXY address transfers, the sender includes the nametag token
|
|
367
|
-
* so the recipient can verify they're authorized to receive at this address.
|
|
368
|
-
* This is REQUIRED for PROXY addresses - transfers without this will fail.
|
|
369
|
-
*/
|
|
370
|
-
nametagTokenJson?: string;
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Bundle payload for INSTANT_SPLIT V4 (Dev Mode Only - True Nostr-First Split)
|
|
374
|
-
*
|
|
375
|
-
* V4 achieves near-zero sender latency (~0.3s) by:
|
|
376
|
-
* 1. Creating ALL commitments locally BEFORE any aggregator submission
|
|
377
|
-
* 2. Persisting via Nostr FIRST
|
|
378
|
-
* 3. Then submitting ALL to aggregator in background
|
|
379
|
-
*
|
|
380
|
-
* NOTE: V4 only works in dev mode. Production requires V5 with proper SplitMintReason.
|
|
381
|
-
*/
|
|
382
|
-
interface InstantSplitBundleV4 {
|
|
383
|
-
/** Bundle version - V4 is true Nostr-first (dev mode only) */
|
|
384
|
-
version: '4.0';
|
|
385
|
-
/** Bundle type identifier */
|
|
386
|
-
type: 'INSTANT_SPLIT';
|
|
387
|
-
/**
|
|
388
|
-
* Burn commitment JSON (NOT transaction - no proof yet!)
|
|
389
|
-
* Both sender and recipient submit this to aggregator.
|
|
390
|
-
*/
|
|
391
|
-
burnCommitment: string;
|
|
392
|
-
/** Recipient's MintTransactionData JSON (they recreate commitment and submit) */
|
|
393
|
-
recipientMintData: string;
|
|
394
|
-
/**
|
|
395
|
-
* Pre-created TransferCommitment JSON (recipient submits and waits for proof)
|
|
396
|
-
* Created from mint data WITHOUT any proofs.
|
|
397
|
-
*/
|
|
398
|
-
transferCommitment: string;
|
|
399
|
-
/** Payment amount (display metadata) */
|
|
400
|
-
amount: string;
|
|
401
|
-
/** Coin ID hex */
|
|
402
|
-
coinId: string;
|
|
403
|
-
/** Token type hex */
|
|
404
|
-
tokenTypeHex: string;
|
|
405
|
-
/** Split group ID for recovery correlation */
|
|
406
|
-
splitGroupId: string;
|
|
407
|
-
/** Sender's pubkey for acknowledgment */
|
|
408
|
-
senderPubkey: string;
|
|
409
|
-
/** Salt for recipient predicate creation (hex) */
|
|
410
|
-
recipientSaltHex: string;
|
|
411
|
-
/** Salt for transfer commitment creation (hex) */
|
|
412
|
-
transferSaltHex: string;
|
|
413
|
-
}
|
|
414
|
-
/** Union type for all InstantSplit bundle versions */
|
|
415
|
-
type InstantSplitBundle = InstantSplitBundleV4 | InstantSplitBundleV5;
|
|
416
275
|
/**
|
|
417
276
|
* Result of an instant split send operation
|
|
418
277
|
*/
|
|
@@ -429,19 +288,8 @@ interface InstantSplitResult {
|
|
|
429
288
|
error?: string;
|
|
430
289
|
/** Whether background processing was started */
|
|
431
290
|
backgroundStarted?: boolean;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
* Result from processing an INSTANT_SPLIT bundle (recipient side)
|
|
435
|
-
*/
|
|
436
|
-
interface InstantSplitProcessResult {
|
|
437
|
-
/** Whether processing succeeded */
|
|
438
|
-
success: boolean;
|
|
439
|
-
/** The finalized SDK token (if successful) */
|
|
440
|
-
token?: SdkToken;
|
|
441
|
-
/** Error message (if failed) */
|
|
442
|
-
error?: string;
|
|
443
|
-
/** Processing duration in ms */
|
|
444
|
-
durationMs: number;
|
|
291
|
+
/** Promise that resolves when background processing completes (change token saved) */
|
|
292
|
+
backgroundPromise?: Promise<void>;
|
|
445
293
|
}
|
|
446
294
|
/**
|
|
447
295
|
* Options for instant split send operation
|
|
@@ -476,6 +324,17 @@ interface BackgroundProgressStatus {
|
|
|
476
324
|
message: string;
|
|
477
325
|
error?: string;
|
|
478
326
|
}
|
|
327
|
+
/** Result of resolveUnconfirmed() */
|
|
328
|
+
interface UnconfirmedResolutionResult {
|
|
329
|
+
resolved: number;
|
|
330
|
+
stillPending: number;
|
|
331
|
+
failed: number;
|
|
332
|
+
details: Array<{
|
|
333
|
+
tokenId: string;
|
|
334
|
+
stage: string;
|
|
335
|
+
status: 'resolved' | 'pending' | 'failed';
|
|
336
|
+
}>;
|
|
337
|
+
}
|
|
479
338
|
|
|
480
339
|
/**
|
|
481
340
|
* SDK2 Core Types
|
|
@@ -529,6 +388,14 @@ interface Asset {
|
|
|
529
388
|
readonly iconUrl?: string;
|
|
530
389
|
readonly totalAmount: string;
|
|
531
390
|
readonly tokenCount: number;
|
|
391
|
+
/** Sum of confirmed token amounts (smallest units) */
|
|
392
|
+
readonly confirmedAmount: string;
|
|
393
|
+
/** Sum of unconfirmed (submitted/pending) token amounts (smallest units) */
|
|
394
|
+
readonly unconfirmedAmount: string;
|
|
395
|
+
/** Number of confirmed tokens aggregated */
|
|
396
|
+
readonly confirmedTokenCount: number;
|
|
397
|
+
/** Number of unconfirmed tokens aggregated */
|
|
398
|
+
readonly unconfirmedTokenCount: number;
|
|
532
399
|
/** Price per whole unit in USD (null if PriceProvider not configured) */
|
|
533
400
|
readonly priceUsd: number | null;
|
|
534
401
|
/** Price per whole unit in EUR (null if PriceProvider not configured) */
|
|
@@ -542,6 +409,7 @@ interface Asset {
|
|
|
542
409
|
}
|
|
543
410
|
type TransferStatus = 'pending' | 'submitted' | 'confirmed' | 'delivered' | 'completed' | 'failed';
|
|
544
411
|
type AddressMode = 'auto' | 'direct' | 'proxy';
|
|
412
|
+
type TransferMode = 'instant' | 'conservative';
|
|
545
413
|
interface TransferRequest {
|
|
546
414
|
readonly coinId: string;
|
|
547
415
|
readonly amount: string;
|
|
@@ -549,12 +417,31 @@ interface TransferRequest {
|
|
|
549
417
|
readonly memo?: string;
|
|
550
418
|
/** Address mode: 'auto' (default) uses directAddress if available, 'direct' forces DIRECT, 'proxy' forces PROXY */
|
|
551
419
|
readonly addressMode?: AddressMode;
|
|
420
|
+
/** Transfer mode: 'instant' (default) sends via Nostr immediately, 'conservative' collects all proofs first */
|
|
421
|
+
readonly transferMode?: TransferMode;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Per-token transfer detail tracking the on-chain commitment or split operation
|
|
425
|
+
* for each source token involved in a transfer.
|
|
426
|
+
*/
|
|
427
|
+
interface TokenTransferDetail {
|
|
428
|
+
/** Source token ID that was consumed in this transfer */
|
|
429
|
+
readonly sourceTokenId: string;
|
|
430
|
+
/** Transfer method used for this token */
|
|
431
|
+
readonly method: 'direct' | 'split';
|
|
432
|
+
/** Aggregator commitment request ID hex (for direct transfers) */
|
|
433
|
+
readonly requestIdHex?: string;
|
|
434
|
+
/** Split group ID (for split transfers — correlates sender/recipient/change tokens) */
|
|
435
|
+
readonly splitGroupId?: string;
|
|
436
|
+
/** Nostr event ID (for split transfers delivered via Nostr) */
|
|
437
|
+
readonly nostrEventId?: string;
|
|
552
438
|
}
|
|
553
439
|
interface TransferResult {
|
|
554
440
|
readonly id: string;
|
|
555
441
|
status: TransferStatus;
|
|
556
442
|
readonly tokens: Token[];
|
|
557
|
-
|
|
443
|
+
/** Per-token transfer details — one entry per source token consumed */
|
|
444
|
+
readonly tokenTransfers: TokenTransferDetail[];
|
|
558
445
|
error?: string;
|
|
559
446
|
}
|
|
560
447
|
interface IncomingTransfer {
|
|
@@ -578,7 +465,7 @@ interface PaymentRequest {
|
|
|
578
465
|
readonly coinId: string;
|
|
579
466
|
/** Optional message/memo */
|
|
580
467
|
readonly message?: string;
|
|
581
|
-
/**
|
|
468
|
+
/** Where tokens should be sent */
|
|
582
469
|
readonly recipientNametag?: string;
|
|
583
470
|
/** Custom metadata */
|
|
584
471
|
readonly metadata?: Record<string, unknown>;
|
|
@@ -605,7 +492,7 @@ interface IncomingPaymentRequest$1 {
|
|
|
605
492
|
readonly symbol: string;
|
|
606
493
|
/** Message from sender */
|
|
607
494
|
readonly message?: string;
|
|
608
|
-
/**
|
|
495
|
+
/** Requester's nametag (where tokens should be sent) */
|
|
609
496
|
readonly recipientNametag?: string;
|
|
610
497
|
/** Original request ID from sender */
|
|
611
498
|
readonly requestId: string;
|
|
@@ -731,7 +618,7 @@ interface TrackedAddress extends TrackedAddressEntry {
|
|
|
731
618
|
/** Primary nametag (from nametag cache, without @ prefix) */
|
|
732
619
|
readonly nametag?: string;
|
|
733
620
|
}
|
|
734
|
-
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:broadcast' | 'sync:started' | 'sync:completed' | 'sync:provider' | 'sync:error' | 'connection:changed' | 'nametag:registered' | 'nametag:recovered' | 'identity:changed' | 'address:activated' | 'address:hidden' | 'address:unhidden';
|
|
621
|
+
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: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';
|
|
735
622
|
interface SphereEventMap {
|
|
736
623
|
'transfer:incoming': IncomingTransfer;
|
|
737
624
|
'transfer:confirmed': TransferResult;
|
|
@@ -790,6 +677,14 @@ interface SphereEventMap {
|
|
|
790
677
|
index: number;
|
|
791
678
|
addressId: string;
|
|
792
679
|
};
|
|
680
|
+
'sync:remote-update': {
|
|
681
|
+
providerId: string;
|
|
682
|
+
name: string;
|
|
683
|
+
sequence: number;
|
|
684
|
+
cid: string;
|
|
685
|
+
added: number;
|
|
686
|
+
removed: number;
|
|
687
|
+
};
|
|
793
688
|
}
|
|
794
689
|
type SphereEventHandler<T extends SphereEventType> = (data: SphereEventMap[T]) => void;
|
|
795
690
|
/**
|
|
@@ -1012,6 +907,12 @@ interface TransportProvider extends BaseProvider {
|
|
|
1012
907
|
* @returns Unsubscribe function
|
|
1013
908
|
*/
|
|
1014
909
|
onInstantSplitReceived?(handler: InstantSplitBundleHandler): () => void;
|
|
910
|
+
/**
|
|
911
|
+
* Fetch pending events from transport (one-shot query).
|
|
912
|
+
* Creates a temporary subscription, processes events through normal handlers,
|
|
913
|
+
* and resolves after EOSE (End Of Stored Events).
|
|
914
|
+
*/
|
|
915
|
+
fetchPendingEvents?(): Promise<void>;
|
|
1015
916
|
}
|
|
1016
917
|
/**
|
|
1017
918
|
* Payload for sending instant split bundles
|
|
@@ -1076,7 +977,7 @@ interface IncomingTokenTransfer {
|
|
|
1076
977
|
payload: TokenTransferPayload;
|
|
1077
978
|
timestamp: number;
|
|
1078
979
|
}
|
|
1079
|
-
type TokenTransferHandler = (transfer: IncomingTokenTransfer) => void
|
|
980
|
+
type TokenTransferHandler = (transfer: IncomingTokenTransfer) => void | Promise<void>;
|
|
1080
981
|
interface PaymentRequestPayload {
|
|
1081
982
|
/** Amount requested (in smallest units) */
|
|
1082
983
|
amount: string | bigint;
|
|
@@ -1094,6 +995,8 @@ interface IncomingPaymentRequest {
|
|
|
1094
995
|
id: string;
|
|
1095
996
|
/** Transport-specific pubkey of sender */
|
|
1096
997
|
senderTransportPubkey: string;
|
|
998
|
+
/** Sender's nametag (if included in encrypted content) */
|
|
999
|
+
senderNametag?: string;
|
|
1097
1000
|
/** Parsed request data */
|
|
1098
1001
|
request: {
|
|
1099
1002
|
requestId: string;
|
|
@@ -1252,6 +1155,12 @@ declare class L1PaymentsModule {
|
|
|
1252
1155
|
private _transport?;
|
|
1253
1156
|
constructor(config?: L1PaymentsModuleConfig);
|
|
1254
1157
|
initialize(deps: L1PaymentsModuleDependencies): Promise<void>;
|
|
1158
|
+
/**
|
|
1159
|
+
* Ensure the Fulcrum WebSocket is connected. Called lazily before any
|
|
1160
|
+
* operation that needs the network. If the singleton is already connected
|
|
1161
|
+
* (e.g. by the address scanner), this is a no-op.
|
|
1162
|
+
*/
|
|
1163
|
+
private ensureConnected;
|
|
1255
1164
|
destroy(): void;
|
|
1256
1165
|
/**
|
|
1257
1166
|
* Check if a string looks like an L1 address (alpha1... or alphat1...)
|
|
@@ -1261,7 +1170,7 @@ declare class L1PaymentsModule {
|
|
|
1261
1170
|
* Resolve recipient to L1 address
|
|
1262
1171
|
* Supports: L1 address (alpha1...), nametag (with or without @)
|
|
1263
1172
|
*/
|
|
1264
|
-
|
|
1173
|
+
resolveL1Address(recipient: string): Promise<string>;
|
|
1265
1174
|
/**
|
|
1266
1175
|
* Resolve nametag to L1 address using transport provider
|
|
1267
1176
|
*/
|
|
@@ -1434,7 +1343,7 @@ interface TokenStorageProvider<TData = unknown> extends BaseProvider {
|
|
|
1434
1343
|
*/
|
|
1435
1344
|
deleteToken?(tokenId: string): Promise<void>;
|
|
1436
1345
|
}
|
|
1437
|
-
type StorageEventType = 'storage:saving' | 'storage:saved' | 'storage:loading' | 'storage:loaded' | 'storage:error' | 'sync:started' | 'sync:completed' | 'sync:conflict' | 'sync:error';
|
|
1346
|
+
type StorageEventType = 'storage:saving' | 'storage:saved' | 'storage:loading' | 'storage:loaded' | 'storage:error' | 'storage:remote-updated' | 'sync:started' | 'sync:completed' | 'sync:conflict' | 'sync:error';
|
|
1438
1347
|
interface StorageEvent {
|
|
1439
1348
|
type: StorageEventType;
|
|
1440
1349
|
timestamp: number;
|
|
@@ -1690,7 +1599,30 @@ interface TransactionHistoryEntry {
|
|
|
1690
1599
|
timestamp: number;
|
|
1691
1600
|
recipientNametag?: string;
|
|
1692
1601
|
senderPubkey?: string;
|
|
1693
|
-
|
|
1602
|
+
/** TransferResult.id that created this entry (links history to transfer operation) */
|
|
1603
|
+
transferId?: string;
|
|
1604
|
+
}
|
|
1605
|
+
interface ReceiveOptions {
|
|
1606
|
+
/** Wait for all unconfirmed tokens to be finalized (default: false).
|
|
1607
|
+
* When false, calls resolveUnconfirmed() once to submit pending commitments.
|
|
1608
|
+
* When true, polls resolveUnconfirmed() + load() until all confirmed or timeout. */
|
|
1609
|
+
finalize?: boolean;
|
|
1610
|
+
/** Finalization timeout in ms (default: 60000). Only used when finalize=true. */
|
|
1611
|
+
timeout?: number;
|
|
1612
|
+
/** Poll interval in ms (default: 2000). Only used when finalize=true. */
|
|
1613
|
+
pollInterval?: number;
|
|
1614
|
+
/** Progress callback after each resolveUnconfirmed() poll. Only used when finalize=true. */
|
|
1615
|
+
onProgress?: (result: UnconfirmedResolutionResult) => void;
|
|
1616
|
+
}
|
|
1617
|
+
interface ReceiveResult {
|
|
1618
|
+
/** Newly received incoming transfers. */
|
|
1619
|
+
transfers: IncomingTransfer[];
|
|
1620
|
+
/** Finalization result (from resolveUnconfirmed). */
|
|
1621
|
+
finalization?: UnconfirmedResolutionResult;
|
|
1622
|
+
/** Whether finalization timed out (only when finalize=true). */
|
|
1623
|
+
timedOut?: boolean;
|
|
1624
|
+
/** Duration of finalization in ms (only when finalize=true). */
|
|
1625
|
+
finalizationDurationMs?: number;
|
|
1694
1626
|
}
|
|
1695
1627
|
interface PaymentsModuleConfig {
|
|
1696
1628
|
/** Auto-sync after operations */
|
|
@@ -1703,8 +1635,8 @@ interface PaymentsModuleConfig {
|
|
|
1703
1635
|
maxRetries?: number;
|
|
1704
1636
|
/** Enable debug logging */
|
|
1705
1637
|
debug?: boolean;
|
|
1706
|
-
/** L1 (ALPHA blockchain) configuration */
|
|
1707
|
-
l1?: L1PaymentsModuleConfig;
|
|
1638
|
+
/** L1 (ALPHA blockchain) configuration. Set to null to explicitly disable L1. */
|
|
1639
|
+
l1?: L1PaymentsModuleConfig | null;
|
|
1708
1640
|
}
|
|
1709
1641
|
interface PaymentsModuleDependencies {
|
|
1710
1642
|
identity: FullIdentity;
|
|
@@ -1730,6 +1662,7 @@ declare class PaymentsModule {
|
|
|
1730
1662
|
readonly l1: L1PaymentsModule | null;
|
|
1731
1663
|
private tokens;
|
|
1732
1664
|
private pendingTransfers;
|
|
1665
|
+
private pendingBackgroundTasks;
|
|
1733
1666
|
private tombstones;
|
|
1734
1667
|
private archivedTokens;
|
|
1735
1668
|
private forkedTokens;
|
|
@@ -1747,8 +1680,17 @@ declare class PaymentsModule {
|
|
|
1747
1680
|
private proofPollingInterval;
|
|
1748
1681
|
private static readonly PROOF_POLLING_INTERVAL_MS;
|
|
1749
1682
|
private static readonly PROOF_POLLING_MAX_ATTEMPTS;
|
|
1683
|
+
private storageEventUnsubscribers;
|
|
1684
|
+
private syncDebounceTimer;
|
|
1685
|
+
private static readonly SYNC_DEBOUNCE_MS;
|
|
1686
|
+
/** Sync coalescing: concurrent sync() calls share the same operation */
|
|
1687
|
+
private _syncInProgress;
|
|
1750
1688
|
constructor(config?: PaymentsModuleConfig);
|
|
1751
|
-
/**
|
|
1689
|
+
/**
|
|
1690
|
+
* Get the current module configuration (excluding L1 config).
|
|
1691
|
+
*
|
|
1692
|
+
* @returns Resolved configuration with all defaults applied.
|
|
1693
|
+
*/
|
|
1752
1694
|
getConfig(): Omit<Required<PaymentsModuleConfig>, 'l1'>;
|
|
1753
1695
|
/** Price provider (optional) */
|
|
1754
1696
|
private priceProvider;
|
|
@@ -1758,11 +1700,18 @@ declare class PaymentsModule {
|
|
|
1758
1700
|
*/
|
|
1759
1701
|
initialize(deps: PaymentsModuleDependencies): void;
|
|
1760
1702
|
/**
|
|
1761
|
-
* Load
|
|
1703
|
+
* Load all token data from storage providers and restore wallet state.
|
|
1704
|
+
*
|
|
1705
|
+
* Loads tokens, nametag data, transaction history, and pending transfers
|
|
1706
|
+
* from configured storage providers. Restores pending V5 tokens and
|
|
1707
|
+
* triggers a fire-and-forget {@link resolveUnconfirmed} call.
|
|
1762
1708
|
*/
|
|
1763
1709
|
load(): Promise<void>;
|
|
1764
1710
|
/**
|
|
1765
|
-
* Cleanup
|
|
1711
|
+
* Cleanup all subscriptions, polling jobs, and pending resolvers.
|
|
1712
|
+
*
|
|
1713
|
+
* Should be called when the wallet is being shut down or the module is
|
|
1714
|
+
* no longer needed. Also destroys the L1 sub-module if present.
|
|
1766
1715
|
*/
|
|
1767
1716
|
destroy(): void;
|
|
1768
1717
|
/**
|
|
@@ -1814,11 +1763,19 @@ declare class PaymentsModule {
|
|
|
1814
1763
|
* @param senderPubkey - Sender's public key for verification
|
|
1815
1764
|
* @returns Processing result with finalized token
|
|
1816
1765
|
*/
|
|
1817
|
-
processInstantSplitBundle
|
|
1766
|
+
private processInstantSplitBundle;
|
|
1818
1767
|
/**
|
|
1819
|
-
*
|
|
1768
|
+
* Synchronous V4 bundle processing (dev mode only).
|
|
1769
|
+
* Kept for backward compatibility with V4 bundles.
|
|
1820
1770
|
*/
|
|
1821
|
-
|
|
1771
|
+
private processInstantSplitBundleSync;
|
|
1772
|
+
/**
|
|
1773
|
+
* Type-guard: check whether a payload is a valid {@link InstantSplitBundle} (V4 or V5).
|
|
1774
|
+
*
|
|
1775
|
+
* @param payload - The object to test.
|
|
1776
|
+
* @returns `true` if the payload matches the InstantSplitBundle shape.
|
|
1777
|
+
*/
|
|
1778
|
+
private isInstantSplitBundle;
|
|
1822
1779
|
/**
|
|
1823
1780
|
* Send a payment request to someone
|
|
1824
1781
|
* @param recipientPubkeyOrNametag - Recipient's pubkey or @nametag
|
|
@@ -1840,27 +1797,45 @@ declare class PaymentsModule {
|
|
|
1840
1797
|
status?: PaymentRequestStatus;
|
|
1841
1798
|
}): IncomingPaymentRequest$1[];
|
|
1842
1799
|
/**
|
|
1843
|
-
* Get
|
|
1800
|
+
* Get the count of payment requests with status `'pending'`.
|
|
1801
|
+
*
|
|
1802
|
+
* @returns Number of pending incoming payment requests.
|
|
1844
1803
|
*/
|
|
1845
1804
|
getPendingPaymentRequestsCount(): number;
|
|
1846
1805
|
/**
|
|
1847
|
-
* Accept a payment request
|
|
1806
|
+
* Accept a payment request and notify the requester.
|
|
1807
|
+
*
|
|
1808
|
+
* Marks the request as `'accepted'` and sends a response via transport.
|
|
1809
|
+
* The caller should subsequently call {@link send} to fulfill the payment.
|
|
1810
|
+
*
|
|
1811
|
+
* @param requestId - ID of the incoming payment request to accept.
|
|
1848
1812
|
*/
|
|
1849
1813
|
acceptPaymentRequest(requestId: string): Promise<void>;
|
|
1850
1814
|
/**
|
|
1851
|
-
* Reject a payment request
|
|
1815
|
+
* Reject a payment request and notify the requester.
|
|
1816
|
+
*
|
|
1817
|
+
* @param requestId - ID of the incoming payment request to reject.
|
|
1852
1818
|
*/
|
|
1853
1819
|
rejectPaymentRequest(requestId: string): Promise<void>;
|
|
1854
1820
|
/**
|
|
1855
|
-
* Mark a payment request as paid (
|
|
1821
|
+
* Mark a payment request as paid (local status update only).
|
|
1822
|
+
*
|
|
1823
|
+
* Typically called after a successful {@link send} to record that the
|
|
1824
|
+
* request has been fulfilled.
|
|
1825
|
+
*
|
|
1826
|
+
* @param requestId - ID of the incoming payment request to mark as paid.
|
|
1856
1827
|
*/
|
|
1857
1828
|
markPaymentRequestPaid(requestId: string): void;
|
|
1858
1829
|
/**
|
|
1859
|
-
*
|
|
1830
|
+
* Remove all non-pending incoming payment requests from memory.
|
|
1831
|
+
*
|
|
1832
|
+
* Keeps only requests with status `'pending'`.
|
|
1860
1833
|
*/
|
|
1861
1834
|
clearProcessedPaymentRequests(): void;
|
|
1862
1835
|
/**
|
|
1863
|
-
* Remove a specific payment request
|
|
1836
|
+
* Remove a specific incoming payment request by ID.
|
|
1837
|
+
*
|
|
1838
|
+
* @param requestId - ID of the payment request to remove.
|
|
1864
1839
|
*/
|
|
1865
1840
|
removePaymentRequest(requestId: string): void;
|
|
1866
1841
|
/**
|
|
@@ -1891,15 +1866,21 @@ declare class PaymentsModule {
|
|
|
1891
1866
|
*/
|
|
1892
1867
|
waitForPaymentResponse(requestId: string, timeoutMs?: number): Promise<PaymentRequestResponse>;
|
|
1893
1868
|
/**
|
|
1894
|
-
* Cancel
|
|
1869
|
+
* Cancel an active {@link waitForPaymentResponse} call.
|
|
1870
|
+
*
|
|
1871
|
+
* The pending promise is rejected with a `'Cancelled'` error.
|
|
1872
|
+
*
|
|
1873
|
+
* @param requestId - The outgoing request ID whose wait should be cancelled.
|
|
1895
1874
|
*/
|
|
1896
1875
|
cancelWaitForPaymentResponse(requestId: string): void;
|
|
1897
1876
|
/**
|
|
1898
|
-
* Remove an outgoing payment request
|
|
1877
|
+
* Remove an outgoing payment request and cancel any pending wait.
|
|
1878
|
+
*
|
|
1879
|
+
* @param requestId - ID of the outgoing request to remove.
|
|
1899
1880
|
*/
|
|
1900
1881
|
removeOutgoingPaymentRequest(requestId: string): void;
|
|
1901
1882
|
/**
|
|
1902
|
-
*
|
|
1883
|
+
* Remove all outgoing payment requests that are `'paid'`, `'rejected'`, or `'expired'`.
|
|
1903
1884
|
*/
|
|
1904
1885
|
clearCompletedOutgoingPaymentRequests(): void;
|
|
1905
1886
|
private handlePaymentRequestResponse;
|
|
@@ -1907,36 +1888,141 @@ declare class PaymentsModule {
|
|
|
1907
1888
|
* Send a response to a payment request (used internally by accept/reject/pay methods)
|
|
1908
1889
|
*/
|
|
1909
1890
|
private sendPaymentRequestResponse;
|
|
1891
|
+
/**
|
|
1892
|
+
* Fetch and process pending incoming transfers from the transport layer.
|
|
1893
|
+
*
|
|
1894
|
+
* Performs a one-shot query to fetch all pending events, processes them
|
|
1895
|
+
* through the existing pipeline, and resolves after all stored events
|
|
1896
|
+
* are handled. Useful for batch/CLI apps that need explicit receive.
|
|
1897
|
+
*
|
|
1898
|
+
* When `finalize` is true, polls resolveUnconfirmed() + load() until all
|
|
1899
|
+
* tokens are confirmed or the timeout expires. Otherwise calls
|
|
1900
|
+
* resolveUnconfirmed() once to submit pending commitments.
|
|
1901
|
+
*
|
|
1902
|
+
* @param options - Optional receive options including finalization control
|
|
1903
|
+
* @param callback - Optional callback invoked for each newly received transfer
|
|
1904
|
+
* @returns ReceiveResult with transfers and finalization metadata
|
|
1905
|
+
*/
|
|
1906
|
+
receive(options?: ReceiveOptions, callback?: (transfer: IncomingTransfer) => void): Promise<ReceiveResult>;
|
|
1910
1907
|
/**
|
|
1911
1908
|
* Set or update price provider
|
|
1912
1909
|
*/
|
|
1913
1910
|
setPriceProvider(provider: PriceProvider): void;
|
|
1914
1911
|
/**
|
|
1915
|
-
*
|
|
1916
|
-
*
|
|
1912
|
+
* Wait for all pending background operations (e.g., instant split change token creation).
|
|
1913
|
+
* Call this before process exit to ensure all tokens are saved.
|
|
1914
|
+
*/
|
|
1915
|
+
waitForPendingOperations(): Promise<void>;
|
|
1916
|
+
/**
|
|
1917
|
+
* Get total portfolio value in USD.
|
|
1918
|
+
* Returns null if PriceProvider is not configured.
|
|
1919
|
+
*/
|
|
1920
|
+
getFiatBalance(): Promise<number | null>;
|
|
1921
|
+
/**
|
|
1922
|
+
* Get token balances grouped by coin type.
|
|
1923
|
+
*
|
|
1924
|
+
* Returns an array of {@link Asset} objects, one per coin type held.
|
|
1925
|
+
* Each entry includes confirmed and unconfirmed breakdowns. Tokens with
|
|
1926
|
+
* status `'spent'`, `'invalid'`, or `'transferring'` are excluded.
|
|
1927
|
+
*
|
|
1928
|
+
* This is synchronous — no price data is included. Use {@link getAssets}
|
|
1929
|
+
* for the async version with fiat pricing.
|
|
1930
|
+
*
|
|
1931
|
+
* @param coinId - Optional coin ID to filter by (e.g. hex string). When omitted, all coin types are returned.
|
|
1932
|
+
* @returns Array of balance summaries (synchronous — no await needed).
|
|
1917
1933
|
*/
|
|
1918
|
-
getBalance():
|
|
1934
|
+
getBalance(coinId?: string): Asset[];
|
|
1919
1935
|
/**
|
|
1920
|
-
* Get aggregated assets (tokens grouped by coinId) with price data
|
|
1921
|
-
*
|
|
1936
|
+
* Get aggregated assets (tokens grouped by coinId) with price data.
|
|
1937
|
+
* Includes both confirmed and unconfirmed tokens with breakdown.
|
|
1922
1938
|
*/
|
|
1923
1939
|
getAssets(coinId?: string): Promise<Asset[]>;
|
|
1924
1940
|
/**
|
|
1925
|
-
*
|
|
1941
|
+
* Aggregate tokens by coinId with confirmed/unconfirmed breakdown.
|
|
1942
|
+
* Excludes tokens with status 'spent', 'invalid', or 'transferring'.
|
|
1943
|
+
*/
|
|
1944
|
+
private aggregateTokens;
|
|
1945
|
+
/**
|
|
1946
|
+
* Get all tokens, optionally filtered by coin type and/or status.
|
|
1947
|
+
*
|
|
1948
|
+
* @param filter - Optional filter criteria.
|
|
1949
|
+
* @param filter.coinId - Return only tokens of this coin type.
|
|
1950
|
+
* @param filter.status - Return only tokens with this status (e.g. `'submitted'` for unconfirmed).
|
|
1951
|
+
* @returns Array of matching {@link Token} objects (synchronous).
|
|
1926
1952
|
*/
|
|
1927
1953
|
getTokens(filter?: {
|
|
1928
1954
|
coinId?: string;
|
|
1929
1955
|
status?: TokenStatus;
|
|
1930
1956
|
}): Token[];
|
|
1931
1957
|
/**
|
|
1932
|
-
* Get single token
|
|
1958
|
+
* Get a single token by its local ID.
|
|
1959
|
+
*
|
|
1960
|
+
* @param id - The local UUID assigned when the token was added.
|
|
1961
|
+
* @returns The token, or `undefined` if not found.
|
|
1933
1962
|
*/
|
|
1934
1963
|
getToken(id: string): Token | undefined;
|
|
1935
1964
|
/**
|
|
1936
|
-
*
|
|
1937
|
-
*
|
|
1938
|
-
*
|
|
1939
|
-
*
|
|
1965
|
+
* Attempt to resolve unconfirmed (status `'submitted'`) tokens by acquiring
|
|
1966
|
+
* their missing aggregator proofs.
|
|
1967
|
+
*
|
|
1968
|
+
* Each unconfirmed V5 token progresses through stages:
|
|
1969
|
+
* `RECEIVED` → `MINT_SUBMITTED` → `MINT_PROVEN` → `TRANSFER_SUBMITTED` → `FINALIZED`
|
|
1970
|
+
*
|
|
1971
|
+
* Uses 500 ms quick-timeouts per proof check so the call returns quickly even
|
|
1972
|
+
* when proofs are not yet available. Tokens that exceed 50 failed attempts are
|
|
1973
|
+
* marked `'invalid'`.
|
|
1974
|
+
*
|
|
1975
|
+
* Automatically called (fire-and-forget) by {@link load}.
|
|
1976
|
+
*
|
|
1977
|
+
* @returns Summary with counts of resolved, still-pending, and failed tokens plus per-token details.
|
|
1978
|
+
*/
|
|
1979
|
+
resolveUnconfirmed(): Promise<UnconfirmedResolutionResult>;
|
|
1980
|
+
/**
|
|
1981
|
+
* Process a single V5 token through its finalization stages with quick-timeout proof checks.
|
|
1982
|
+
*/
|
|
1983
|
+
private resolveV5Token;
|
|
1984
|
+
/**
|
|
1985
|
+
* Non-blocking proof check with 500ms timeout.
|
|
1986
|
+
*/
|
|
1987
|
+
private quickProofCheck;
|
|
1988
|
+
/**
|
|
1989
|
+
* Perform V5 bundle finalization from stored bundle data and proofs.
|
|
1990
|
+
* Extracted from InstantSplitProcessor.processV5Bundle() steps 4-10.
|
|
1991
|
+
*/
|
|
1992
|
+
private finalizeFromV5Bundle;
|
|
1993
|
+
/**
|
|
1994
|
+
* Parse pending finalization metadata from token's sdkData.
|
|
1995
|
+
*/
|
|
1996
|
+
private parsePendingFinalization;
|
|
1997
|
+
/**
|
|
1998
|
+
* Update pending finalization metadata in token's sdkData.
|
|
1999
|
+
* Creates a new token object since sdkData is readonly.
|
|
2000
|
+
*/
|
|
2001
|
+
private updatePendingFinalization;
|
|
2002
|
+
/**
|
|
2003
|
+
* Save pending V5 tokens to key-value storage.
|
|
2004
|
+
* These tokens can't be serialized to TXF format (no genesis/state),
|
|
2005
|
+
* so we persist them separately and restore on load().
|
|
2006
|
+
*/
|
|
2007
|
+
private savePendingV5Tokens;
|
|
2008
|
+
/**
|
|
2009
|
+
* Load pending V5 tokens from key-value storage and merge into tokens map.
|
|
2010
|
+
* Called during load() to restore tokens that TXF format can't represent.
|
|
2011
|
+
*/
|
|
2012
|
+
private loadPendingV5Tokens;
|
|
2013
|
+
/**
|
|
2014
|
+
* Add a token to the wallet.
|
|
2015
|
+
*
|
|
2016
|
+
* Tokens are uniquely identified by a `(tokenId, stateHash)` composite key.
|
|
2017
|
+
* Duplicate detection:
|
|
2018
|
+
* - **Tombstoned** — rejected if the exact `(tokenId, stateHash)` pair has a tombstone.
|
|
2019
|
+
* - **Exact duplicate** — rejected if a token with the same composite key already exists.
|
|
2020
|
+
* - **State replacement** — if the same `tokenId` exists with a *different* `stateHash`,
|
|
2021
|
+
* the old state is archived and replaced with the incoming one.
|
|
2022
|
+
*
|
|
2023
|
+
* @param token - The token to add.
|
|
2024
|
+
* @param skipHistory - When `true`, do not create a `RECEIVED` transaction history entry (default `false`).
|
|
2025
|
+
* @returns `true` if the token was added, `false` if rejected as duplicate or tombstoned.
|
|
1940
2026
|
*/
|
|
1941
2027
|
addToken(token: Token, skipHistory?: boolean): Promise<boolean>;
|
|
1942
2028
|
/**
|
|
@@ -1951,11 +2037,24 @@ declare class PaymentsModule {
|
|
|
1951
2037
|
*/
|
|
1952
2038
|
private loadTokensFromFileStorage;
|
|
1953
2039
|
/**
|
|
1954
|
-
* Update an existing token
|
|
2040
|
+
* Update an existing token or add it if not found.
|
|
2041
|
+
*
|
|
2042
|
+
* Looks up the token by genesis `tokenId` (from `sdkData`) first, then by
|
|
2043
|
+
* `token.id`. If no match is found, falls back to {@link addToken}.
|
|
2044
|
+
*
|
|
2045
|
+
* @param token - The token with updated data. Must include a valid `id`.
|
|
1955
2046
|
*/
|
|
1956
2047
|
updateToken(token: Token): Promise<void>;
|
|
1957
2048
|
/**
|
|
1958
|
-
* Remove a token
|
|
2049
|
+
* Remove a token from the wallet.
|
|
2050
|
+
*
|
|
2051
|
+
* The token is archived first, then a tombstone `(tokenId, stateHash)` is
|
|
2052
|
+
* created to prevent re-addition via Nostr re-delivery. A `SENT` history
|
|
2053
|
+
* entry is created unless `skipHistory` is `true`.
|
|
2054
|
+
*
|
|
2055
|
+
* @param tokenId - Local UUID of the token to remove.
|
|
2056
|
+
* @param recipientNametag - Optional nametag of the transfer recipient (for history).
|
|
2057
|
+
* @param skipHistory - When `true`, skip creating a transaction history entry (default `false`).
|
|
1959
2058
|
*/
|
|
1960
2059
|
removeToken(tokenId: string, recipientNametag?: string, skipHistory?: boolean): Promise<void>;
|
|
1961
2060
|
/**
|
|
@@ -1964,78 +2063,145 @@ declare class PaymentsModule {
|
|
|
1964
2063
|
*/
|
|
1965
2064
|
private deleteTokenFiles;
|
|
1966
2065
|
/**
|
|
1967
|
-
* Get all
|
|
2066
|
+
* Get all tombstone entries.
|
|
2067
|
+
*
|
|
2068
|
+
* Each tombstone is keyed by `(tokenId, stateHash)` and prevents a spent
|
|
2069
|
+
* token state from being re-added (e.g. via Nostr re-delivery).
|
|
2070
|
+
*
|
|
2071
|
+
* @returns A shallow copy of the tombstone array.
|
|
1968
2072
|
*/
|
|
1969
2073
|
getTombstones(): TombstoneEntry[];
|
|
1970
2074
|
/**
|
|
1971
|
-
* Check
|
|
2075
|
+
* Check whether a specific `(tokenId, stateHash)` combination is tombstoned.
|
|
2076
|
+
*
|
|
2077
|
+
* @param tokenId - The genesis token ID.
|
|
2078
|
+
* @param stateHash - The state hash of the token version to check.
|
|
2079
|
+
* @returns `true` if the exact combination has been tombstoned.
|
|
1972
2080
|
*/
|
|
1973
2081
|
isStateTombstoned(tokenId: string, stateHash: string): boolean;
|
|
1974
2082
|
/**
|
|
1975
|
-
* Merge remote
|
|
1976
|
-
*
|
|
2083
|
+
* Merge tombstones received from a remote sync source.
|
|
2084
|
+
*
|
|
2085
|
+
* Any local token whose `(tokenId, stateHash)` matches a remote tombstone is
|
|
2086
|
+
* removed. The remote tombstones are then added to the local set (union merge).
|
|
2087
|
+
*
|
|
2088
|
+
* @param remoteTombstones - Tombstone entries from the remote source.
|
|
2089
|
+
* @returns Number of local tokens that were removed.
|
|
1977
2090
|
*/
|
|
1978
2091
|
mergeTombstones(remoteTombstones: TombstoneEntry[]): Promise<number>;
|
|
1979
2092
|
/**
|
|
1980
|
-
*
|
|
2093
|
+
* Remove tombstones older than `maxAge` and cap the list at 100 entries.
|
|
2094
|
+
*
|
|
2095
|
+
* @param maxAge - Maximum age in milliseconds (default: 30 days).
|
|
1981
2096
|
*/
|
|
1982
2097
|
pruneTombstones(maxAge?: number): Promise<void>;
|
|
1983
2098
|
/**
|
|
1984
|
-
* Get archived tokens
|
|
2099
|
+
* Get all archived (spent/superseded) tokens in TXF format.
|
|
2100
|
+
*
|
|
2101
|
+
* Archived tokens are kept for recovery and sync purposes. The map key is
|
|
2102
|
+
* the genesis token ID.
|
|
2103
|
+
*
|
|
2104
|
+
* @returns A shallow copy of the archived token map.
|
|
1985
2105
|
*/
|
|
1986
2106
|
getArchivedTokens(): Map<string, TxfToken>;
|
|
1987
2107
|
/**
|
|
1988
|
-
* Get best archived version of a token
|
|
2108
|
+
* Get the best (most committed transactions) archived version of a token.
|
|
2109
|
+
*
|
|
2110
|
+
* Searches both archived and forked token maps and returns the version with
|
|
2111
|
+
* the highest number of committed transactions.
|
|
2112
|
+
*
|
|
2113
|
+
* @param tokenId - The genesis token ID to look up.
|
|
2114
|
+
* @returns The best TXF token version, or `null` if not found.
|
|
1989
2115
|
*/
|
|
1990
2116
|
getBestArchivedVersion(tokenId: string): TxfToken | null;
|
|
1991
2117
|
/**
|
|
1992
|
-
* Merge remote
|
|
1993
|
-
*
|
|
2118
|
+
* Merge archived tokens from a remote sync source.
|
|
2119
|
+
*
|
|
2120
|
+
* For each remote token:
|
|
2121
|
+
* - If missing locally, it is added.
|
|
2122
|
+
* - If the remote version is an incremental update of the local, it replaces it.
|
|
2123
|
+
* - If the histories diverge (fork), the remote version is stored via {@link storeForkedToken}.
|
|
2124
|
+
*
|
|
2125
|
+
* @param remoteArchived - Map of genesis token ID → TXF token from remote.
|
|
2126
|
+
* @returns Number of tokens that were updated or added locally.
|
|
1994
2127
|
*/
|
|
1995
2128
|
mergeArchivedTokens(remoteArchived: Map<string, TxfToken>): Promise<number>;
|
|
1996
2129
|
/**
|
|
1997
|
-
* Prune archived tokens
|
|
2130
|
+
* Prune archived tokens to keep at most `maxCount` entries.
|
|
2131
|
+
*
|
|
2132
|
+
* Oldest entries (by insertion order) are removed first.
|
|
2133
|
+
*
|
|
2134
|
+
* @param maxCount - Maximum number of archived tokens to retain (default: 100).
|
|
1998
2135
|
*/
|
|
1999
2136
|
pruneArchivedTokens(maxCount?: number): Promise<void>;
|
|
2000
2137
|
/**
|
|
2001
|
-
* Get forked
|
|
2138
|
+
* Get all forked token versions.
|
|
2139
|
+
*
|
|
2140
|
+
* Forked tokens represent alternative histories detected during sync.
|
|
2141
|
+
* The map key is `{tokenId}_{stateHash}`.
|
|
2142
|
+
*
|
|
2143
|
+
* @returns A shallow copy of the forked tokens map.
|
|
2002
2144
|
*/
|
|
2003
2145
|
getForkedTokens(): Map<string, TxfToken>;
|
|
2004
2146
|
/**
|
|
2005
|
-
* Store a forked token
|
|
2147
|
+
* Store a forked token version (alternative history).
|
|
2148
|
+
*
|
|
2149
|
+
* No-op if the exact `(tokenId, stateHash)` key already exists.
|
|
2150
|
+
*
|
|
2151
|
+
* @param tokenId - Genesis token ID.
|
|
2152
|
+
* @param stateHash - State hash of this forked version.
|
|
2153
|
+
* @param txfToken - The TXF token data to store.
|
|
2006
2154
|
*/
|
|
2007
2155
|
storeForkedToken(tokenId: string, stateHash: string, txfToken: TxfToken): Promise<void>;
|
|
2008
2156
|
/**
|
|
2009
|
-
* Merge remote
|
|
2010
|
-
*
|
|
2157
|
+
* Merge forked tokens from a remote sync source. Only new keys are added.
|
|
2158
|
+
*
|
|
2159
|
+
* @param remoteForked - Map of `{tokenId}_{stateHash}` → TXF token from remote.
|
|
2160
|
+
* @returns Number of new forked tokens added.
|
|
2011
2161
|
*/
|
|
2012
2162
|
mergeForkedTokens(remoteForked: Map<string, TxfToken>): Promise<number>;
|
|
2013
2163
|
/**
|
|
2014
|
-
* Prune forked tokens
|
|
2164
|
+
* Prune forked tokens to keep at most `maxCount` entries.
|
|
2165
|
+
*
|
|
2166
|
+
* @param maxCount - Maximum number of forked tokens to retain (default: 50).
|
|
2015
2167
|
*/
|
|
2016
2168
|
pruneForkedTokens(maxCount?: number): Promise<void>;
|
|
2017
2169
|
/**
|
|
2018
|
-
* Get transaction history
|
|
2170
|
+
* Get the transaction history sorted newest-first.
|
|
2171
|
+
*
|
|
2172
|
+
* @returns Array of {@link TransactionHistoryEntry} objects in descending timestamp order.
|
|
2019
2173
|
*/
|
|
2020
2174
|
getHistory(): TransactionHistoryEntry[];
|
|
2021
2175
|
/**
|
|
2022
|
-
*
|
|
2176
|
+
* Append an entry to the transaction history.
|
|
2177
|
+
*
|
|
2178
|
+
* A unique `id` is auto-generated. The entry is immediately persisted to storage.
|
|
2179
|
+
*
|
|
2180
|
+
* @param entry - History entry fields (without `id`).
|
|
2023
2181
|
*/
|
|
2024
2182
|
addToHistory(entry: Omit<TransactionHistoryEntry, 'id'>): Promise<void>;
|
|
2025
2183
|
/**
|
|
2026
|
-
* Set nametag for current identity
|
|
2184
|
+
* Set the nametag data for the current identity.
|
|
2185
|
+
*
|
|
2186
|
+
* Persists to both key-value storage and file storage (lottery compatibility).
|
|
2187
|
+
*
|
|
2188
|
+
* @param nametag - The nametag data including minted token JSON.
|
|
2027
2189
|
*/
|
|
2028
2190
|
setNametag(nametag: NametagData): Promise<void>;
|
|
2029
2191
|
/**
|
|
2030
|
-
* Get nametag
|
|
2192
|
+
* Get the current nametag data.
|
|
2193
|
+
*
|
|
2194
|
+
* @returns The nametag data, or `null` if no nametag is set.
|
|
2031
2195
|
*/
|
|
2032
2196
|
getNametag(): NametagData | null;
|
|
2033
2197
|
/**
|
|
2034
|
-
* Check
|
|
2198
|
+
* Check whether a nametag is currently set.
|
|
2199
|
+
*
|
|
2200
|
+
* @returns `true` if nametag data is present.
|
|
2035
2201
|
*/
|
|
2036
2202
|
hasNametag(): boolean;
|
|
2037
2203
|
/**
|
|
2038
|
-
*
|
|
2204
|
+
* Remove the current nametag data from memory and storage.
|
|
2039
2205
|
*/
|
|
2040
2206
|
clearNametag(): Promise<void>;
|
|
2041
2207
|
/**
|
|
@@ -2062,30 +2228,60 @@ declare class PaymentsModule {
|
|
|
2062
2228
|
*/
|
|
2063
2229
|
isNametagAvailable(nametag: string): Promise<boolean>;
|
|
2064
2230
|
/**
|
|
2065
|
-
* Sync with all token storage providers (IPFS,
|
|
2066
|
-
*
|
|
2231
|
+
* Sync local token state with all configured token storage providers (IPFS, file, etc.).
|
|
2232
|
+
*
|
|
2233
|
+
* For each provider, the local data is packaged into TXF storage format, sent
|
|
2234
|
+
* to the provider's `sync()` method, and the merged result is applied locally.
|
|
2235
|
+
* Emits `sync:started`, `sync:completed`, and `sync:error` events.
|
|
2236
|
+
*
|
|
2237
|
+
* @returns Summary with counts of tokens added and removed during sync.
|
|
2067
2238
|
*/
|
|
2068
2239
|
sync(): Promise<{
|
|
2069
2240
|
added: number;
|
|
2070
2241
|
removed: number;
|
|
2071
2242
|
}>;
|
|
2243
|
+
private _doSync;
|
|
2244
|
+
/**
|
|
2245
|
+
* Subscribe to 'storage:remote-updated' events from all token storage providers.
|
|
2246
|
+
* When a provider emits this event, a debounced sync is triggered.
|
|
2247
|
+
*/
|
|
2248
|
+
private subscribeToStorageEvents;
|
|
2249
|
+
/**
|
|
2250
|
+
* Unsubscribe from all storage provider events and clear debounce timer.
|
|
2251
|
+
*/
|
|
2252
|
+
private unsubscribeStorageEvents;
|
|
2253
|
+
/**
|
|
2254
|
+
* Debounced sync triggered by a storage:remote-updated event.
|
|
2255
|
+
* Waits 500ms to batch rapid updates, then performs sync.
|
|
2256
|
+
*/
|
|
2257
|
+
private debouncedSyncFromRemoteUpdate;
|
|
2072
2258
|
/**
|
|
2073
2259
|
* Get all active token storage providers
|
|
2074
2260
|
*/
|
|
2075
2261
|
private getTokenStorageProviders;
|
|
2076
2262
|
/**
|
|
2077
|
-
*
|
|
2263
|
+
* Replace the set of token storage providers at runtime.
|
|
2264
|
+
*
|
|
2265
|
+
* Use when providers are added or removed dynamically (e.g. IPFS node started).
|
|
2266
|
+
*
|
|
2267
|
+
* @param providers - New map of provider ID → TokenStorageProvider.
|
|
2078
2268
|
*/
|
|
2079
2269
|
updateTokenStorageProviders(providers: Map<string, TokenStorageProvider<TxfStorageDataBase>>): void;
|
|
2080
2270
|
/**
|
|
2081
|
-
* Validate tokens
|
|
2271
|
+
* Validate all tokens against the aggregator (oracle provider).
|
|
2272
|
+
*
|
|
2273
|
+
* Tokens that fail validation or are detected as spent are marked `'invalid'`.
|
|
2274
|
+
*
|
|
2275
|
+
* @returns Object with arrays of valid and invalid tokens.
|
|
2082
2276
|
*/
|
|
2083
2277
|
validate(): Promise<{
|
|
2084
2278
|
valid: Token[];
|
|
2085
2279
|
invalid: Token[];
|
|
2086
2280
|
}>;
|
|
2087
2281
|
/**
|
|
2088
|
-
* Get pending transfers
|
|
2282
|
+
* Get all in-progress (pending) outgoing transfers.
|
|
2283
|
+
*
|
|
2284
|
+
* @returns Array of {@link TransferResult} objects for transfers that have not yet completed.
|
|
2089
2285
|
*/
|
|
2090
2286
|
getPendingTransfers(): TransferResult[];
|
|
2091
2287
|
/**
|
|
@@ -2357,6 +2553,8 @@ type LegacyFileType = 'dat' | 'txt' | 'json' | 'mnemonic' | 'unknown';
|
|
|
2357
2553
|
*/
|
|
2358
2554
|
type DecryptionProgressCallback = (iteration: number, total: number) => Promise<void> | void;
|
|
2359
2555
|
|
|
2556
|
+
declare function isValidNametag(nametag: string): boolean;
|
|
2557
|
+
|
|
2360
2558
|
/** Options for creating a new wallet */
|
|
2361
2559
|
interface SphereCreateOptions {
|
|
2362
2560
|
/** BIP39 mnemonic (12 or 24 words) */
|
|
@@ -2710,6 +2908,7 @@ declare class Sphere {
|
|
|
2710
2908
|
transport: TransportProvider;
|
|
2711
2909
|
oracle: OracleProvider;
|
|
2712
2910
|
tokenStorage?: TokenStorageProvider<TxfStorageDataBase>;
|
|
2911
|
+
l1?: L1Config;
|
|
2713
2912
|
}): Promise<{
|
|
2714
2913
|
success: boolean;
|
|
2715
2914
|
mnemonic?: string;
|
|
@@ -2764,6 +2963,8 @@ declare class Sphere {
|
|
|
2764
2963
|
tokenStorage?: TokenStorageProvider<TxfStorageDataBase>;
|
|
2765
2964
|
/** Optional nametag to register */
|
|
2766
2965
|
nametag?: string;
|
|
2966
|
+
/** L1 (ALPHA blockchain) configuration */
|
|
2967
|
+
l1?: L1Config;
|
|
2767
2968
|
}): Promise<{
|
|
2768
2969
|
success: boolean;
|
|
2769
2970
|
sphere?: Sphere;
|
|
@@ -3084,9 +3285,9 @@ declare class Sphere {
|
|
|
3084
3285
|
*/
|
|
3085
3286
|
private recoverNametagFromTransport;
|
|
3086
3287
|
/**
|
|
3087
|
-
*
|
|
3288
|
+
* Strip @ prefix and normalize a nametag (lowercase, phone E.164, strip @unicity suffix).
|
|
3088
3289
|
*/
|
|
3089
|
-
private
|
|
3290
|
+
private cleanNametag;
|
|
3090
3291
|
destroy(): Promise<void>;
|
|
3091
3292
|
private storeMnemonic;
|
|
3092
3293
|
private storeMasterKey;
|
|
@@ -3367,4 +3568,4 @@ declare function randomHex(byteLength: number): string;
|
|
|
3367
3568
|
*/
|
|
3368
3569
|
declare function randomUUID(): string;
|
|
3369
3570
|
|
|
3370
|
-
export { type AddressInfo, CHARSET, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type EncryptedData, type EncryptionOptions, type KeyPair, type L1Config, type MasterKey, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isValidBech32, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
|
|
3571
|
+
export { type AddressInfo, CHARSET, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type EncryptedData, type EncryptionOptions, type KeyPair, type L1Config, type MasterKey, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isValidBech32, isValidNametag, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
|