@unicitylabs/sphere-sdk 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/connect/index.cjs +5 -1
  2. package/dist/connect/index.cjs.map +1 -1
  3. package/dist/connect/index.js +5 -1
  4. package/dist/connect/index.js.map +1 -1
  5. package/dist/core/index.cjs +813 -309
  6. package/dist/core/index.cjs.map +1 -1
  7. package/dist/core/index.d.cts +71 -2
  8. package/dist/core/index.d.ts +71 -2
  9. package/dist/core/index.js +813 -309
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/impl/browser/connect/index.cjs +5 -1
  12. package/dist/impl/browser/connect/index.cjs.map +1 -1
  13. package/dist/impl/browser/connect/index.js +5 -1
  14. package/dist/impl/browser/connect/index.js.map +1 -1
  15. package/dist/impl/browser/index.cjs +7 -2
  16. package/dist/impl/browser/index.cjs.map +1 -1
  17. package/dist/impl/browser/index.js +7 -2
  18. package/dist/impl/browser/index.js.map +1 -1
  19. package/dist/impl/browser/ipfs.cjs +5 -1
  20. package/dist/impl/browser/ipfs.cjs.map +1 -1
  21. package/dist/impl/browser/ipfs.js +5 -1
  22. package/dist/impl/browser/ipfs.js.map +1 -1
  23. package/dist/impl/nodejs/connect/index.cjs +5 -1
  24. package/dist/impl/nodejs/connect/index.cjs.map +1 -1
  25. package/dist/impl/nodejs/connect/index.js +5 -1
  26. package/dist/impl/nodejs/connect/index.js.map +1 -1
  27. package/dist/impl/nodejs/index.cjs +7 -2
  28. package/dist/impl/nodejs/index.cjs.map +1 -1
  29. package/dist/impl/nodejs/index.d.cts +6 -0
  30. package/dist/impl/nodejs/index.d.ts +6 -0
  31. package/dist/impl/nodejs/index.js +7 -2
  32. package/dist/impl/nodejs/index.js.map +1 -1
  33. package/dist/index.cjs +815 -309
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +144 -3
  36. package/dist/index.d.ts +144 -3
  37. package/dist/index.js +814 -309
  38. package/dist/index.js.map +1 -1
  39. package/dist/l1/index.cjs +5 -1
  40. package/dist/l1/index.cjs.map +1 -1
  41. package/dist/l1/index.js +5 -1
  42. package/dist/l1/index.js.map +1 -1
  43. package/package.json +1 -1
@@ -465,6 +465,8 @@ interface Asset {
465
465
  readonly confirmedTokenCount: number;
466
466
  /** Number of unconfirmed tokens aggregated */
467
467
  readonly unconfirmedTokenCount: number;
468
+ /** Number of tokens currently being sent */
469
+ readonly transferringTokenCount: number;
468
470
  /** Price per whole unit in USD (null if PriceProvider not configured) */
469
471
  readonly priceUsd: number | null;
470
472
  /** Price per whole unit in EUR (null if PriceProvider not configured) */
@@ -989,6 +991,12 @@ interface HistoryRecord {
989
991
  recipientNametag?: string;
990
992
  /** Optional memo/message attached to the transfer */
991
993
  memo?: string;
994
+ /** All token IDs in a combined transfer (V6 bundle breakdown) */
995
+ tokenIds?: Array<{
996
+ id: string;
997
+ amount: string;
998
+ source: 'split' | 'direct';
999
+ }>;
992
1000
  }
993
1001
  /**
994
1002
  * Storage result types
@@ -1928,6 +1936,12 @@ declare class PaymentsModule {
1928
1936
  private proofPollingInterval;
1929
1937
  private static readonly PROOF_POLLING_INTERVAL_MS;
1930
1938
  private static readonly PROOF_POLLING_MAX_ATTEMPTS;
1939
+ private resolveUnconfirmedTimer;
1940
+ private static readonly RESOLVE_UNCONFIRMED_INTERVAL_MS;
1941
+ private loadedPromise;
1942
+ private loaded;
1943
+ private processedSplitGroupIds;
1944
+ private processedCombinedTransferIds;
1931
1945
  private storageEventUnsubscribers;
1932
1946
  private syncDebounceTimer;
1933
1947
  private static readonly SYNC_DEBOUNCE_MS;
@@ -1997,6 +2011,43 @@ declare class PaymentsModule {
1997
2011
  * @returns InstantSplitResult with timing info
1998
2012
  */
1999
2013
  sendInstant(request: TransferRequest, options?: InstantSplitOptions): Promise<InstantSplitResult>;
2014
+ /**
2015
+ * Save a V5 split bundle as an unconfirmed token (shared by V5 standalone and V6 combined).
2016
+ * Returns the created UI token, or null if deduped.
2017
+ *
2018
+ * @param deferPersistence - If true, skip addToken/save calls (caller batches them).
2019
+ * The token is still added to the in-memory map for dedup; caller must call save().
2020
+ */
2021
+ private saveUnconfirmedV5Token;
2022
+ /**
2023
+ * Save a commitment-only (NOSTR-FIRST) token and start proof polling.
2024
+ * Shared by standalone NOSTR-FIRST handler and V6 combined handler.
2025
+ * Returns the created UI token, or null if deduped/tombstoned.
2026
+ *
2027
+ * @param deferPersistence - If true, skip save() and commitment submission
2028
+ * (caller batches them). Token is added to in-memory map + proof polling is queued.
2029
+ * @param skipGenesisDedup - If true, skip genesis-ID-only dedup. V6 handler sets this
2030
+ * because bundle-level dedup protects against replays, and split children share genesis IDs.
2031
+ */
2032
+ private saveCommitmentOnlyToken;
2033
+ /**
2034
+ * Process a received COMBINED_TRANSFER V6 bundle.
2035
+ *
2036
+ * Unpacks a single Nostr message into its component tokens:
2037
+ * - Optional V5 split bundle (saved as unconfirmed, resolved lazily)
2038
+ * - Zero or more direct tokens (saved as unconfirmed, proof-polled)
2039
+ *
2040
+ * Emits ONE transfer:incoming event and records ONE history entry.
2041
+ */
2042
+ private processCombinedTransferBundle;
2043
+ /**
2044
+ * Persist processed combined transfer IDs to KV storage.
2045
+ */
2046
+ private saveProcessedCombinedTransferIds;
2047
+ /**
2048
+ * Load processed combined transfer IDs from KV storage.
2049
+ */
2050
+ private loadProcessedCombinedTransferIds;
2000
2051
  /**
2001
2052
  * Process a received INSTANT_SPLIT bundle.
2002
2053
  *
@@ -2187,7 +2238,8 @@ declare class PaymentsModule {
2187
2238
  getAssets(coinId?: string): Promise<Asset[]>;
2188
2239
  /**
2189
2240
  * Aggregate tokens by coinId with confirmed/unconfirmed breakdown.
2190
- * Excludes tokens with status 'spent', 'invalid', or 'transferring'.
2241
+ * Excludes tokens with status 'spent' or 'invalid'.
2242
+ * Tokens with status 'transferring' are counted as unconfirmed (visible in UI as "Sending").
2191
2243
  */
2192
2244
  private aggregateTokens;
2193
2245
  /**
@@ -2225,6 +2277,13 @@ declare class PaymentsModule {
2225
2277
  * @returns Summary with counts of resolved, still-pending, and failed tokens plus per-token details.
2226
2278
  */
2227
2279
  resolveUnconfirmed(): Promise<UnconfirmedResolutionResult>;
2280
+ /**
2281
+ * Start a periodic interval that retries resolveUnconfirmed() until all
2282
+ * tokens are confirmed or failed. Stops automatically when nothing is
2283
+ * pending and is cleaned up by destroy().
2284
+ */
2285
+ private scheduleResolveUnconfirmed;
2286
+ private stopResolveUnconfirmedPolling;
2228
2287
  /**
2229
2288
  * Process a single V5 token through its finalization stages with quick-timeout proof checks.
2230
2289
  */
@@ -2258,6 +2317,16 @@ declare class PaymentsModule {
2258
2317
  * Called during load() to restore tokens that TXF format can't represent.
2259
2318
  */
2260
2319
  private loadPendingV5Tokens;
2320
+ /**
2321
+ * Persist the set of processed splitGroupIds to KV storage.
2322
+ * This ensures Nostr re-deliveries are ignored across page reloads,
2323
+ * even when the confirmed token's in-memory ID differs from v5split_{id}.
2324
+ */
2325
+ private saveProcessedSplitGroupIds;
2326
+ /**
2327
+ * Load processed splitGroupIds from KV storage.
2328
+ */
2329
+ private loadProcessedSplitGroupIds;
2261
2330
  /**
2262
2331
  * Add a token to the wallet.
2263
2332
  *
@@ -2570,7 +2639,7 @@ declare class PaymentsModule {
2570
2639
  /**
2571
2640
  * Handle NOSTR-FIRST commitment-only transfer (recipient side)
2572
2641
  * This is called when receiving a transfer with only commitmentData and no proof yet.
2573
- * We create the token as 'submitted', submit commitment (idempotent), and poll for proof.
2642
+ * Delegates to saveCommitmentOnlyToken() helper, then emits event + records history.
2574
2643
  */
2575
2644
  private handleCommitmentOnlyTransfer;
2576
2645
  /**
@@ -465,6 +465,8 @@ interface Asset {
465
465
  readonly confirmedTokenCount: number;
466
466
  /** Number of unconfirmed tokens aggregated */
467
467
  readonly unconfirmedTokenCount: number;
468
+ /** Number of tokens currently being sent */
469
+ readonly transferringTokenCount: number;
468
470
  /** Price per whole unit in USD (null if PriceProvider not configured) */
469
471
  readonly priceUsd: number | null;
470
472
  /** Price per whole unit in EUR (null if PriceProvider not configured) */
@@ -989,6 +991,12 @@ interface HistoryRecord {
989
991
  recipientNametag?: string;
990
992
  /** Optional memo/message attached to the transfer */
991
993
  memo?: string;
994
+ /** All token IDs in a combined transfer (V6 bundle breakdown) */
995
+ tokenIds?: Array<{
996
+ id: string;
997
+ amount: string;
998
+ source: 'split' | 'direct';
999
+ }>;
992
1000
  }
993
1001
  /**
994
1002
  * Storage result types
@@ -1928,6 +1936,12 @@ declare class PaymentsModule {
1928
1936
  private proofPollingInterval;
1929
1937
  private static readonly PROOF_POLLING_INTERVAL_MS;
1930
1938
  private static readonly PROOF_POLLING_MAX_ATTEMPTS;
1939
+ private resolveUnconfirmedTimer;
1940
+ private static readonly RESOLVE_UNCONFIRMED_INTERVAL_MS;
1941
+ private loadedPromise;
1942
+ private loaded;
1943
+ private processedSplitGroupIds;
1944
+ private processedCombinedTransferIds;
1931
1945
  private storageEventUnsubscribers;
1932
1946
  private syncDebounceTimer;
1933
1947
  private static readonly SYNC_DEBOUNCE_MS;
@@ -1997,6 +2011,43 @@ declare class PaymentsModule {
1997
2011
  * @returns InstantSplitResult with timing info
1998
2012
  */
1999
2013
  sendInstant(request: TransferRequest, options?: InstantSplitOptions): Promise<InstantSplitResult>;
2014
+ /**
2015
+ * Save a V5 split bundle as an unconfirmed token (shared by V5 standalone and V6 combined).
2016
+ * Returns the created UI token, or null if deduped.
2017
+ *
2018
+ * @param deferPersistence - If true, skip addToken/save calls (caller batches them).
2019
+ * The token is still added to the in-memory map for dedup; caller must call save().
2020
+ */
2021
+ private saveUnconfirmedV5Token;
2022
+ /**
2023
+ * Save a commitment-only (NOSTR-FIRST) token and start proof polling.
2024
+ * Shared by standalone NOSTR-FIRST handler and V6 combined handler.
2025
+ * Returns the created UI token, or null if deduped/tombstoned.
2026
+ *
2027
+ * @param deferPersistence - If true, skip save() and commitment submission
2028
+ * (caller batches them). Token is added to in-memory map + proof polling is queued.
2029
+ * @param skipGenesisDedup - If true, skip genesis-ID-only dedup. V6 handler sets this
2030
+ * because bundle-level dedup protects against replays, and split children share genesis IDs.
2031
+ */
2032
+ private saveCommitmentOnlyToken;
2033
+ /**
2034
+ * Process a received COMBINED_TRANSFER V6 bundle.
2035
+ *
2036
+ * Unpacks a single Nostr message into its component tokens:
2037
+ * - Optional V5 split bundle (saved as unconfirmed, resolved lazily)
2038
+ * - Zero or more direct tokens (saved as unconfirmed, proof-polled)
2039
+ *
2040
+ * Emits ONE transfer:incoming event and records ONE history entry.
2041
+ */
2042
+ private processCombinedTransferBundle;
2043
+ /**
2044
+ * Persist processed combined transfer IDs to KV storage.
2045
+ */
2046
+ private saveProcessedCombinedTransferIds;
2047
+ /**
2048
+ * Load processed combined transfer IDs from KV storage.
2049
+ */
2050
+ private loadProcessedCombinedTransferIds;
2000
2051
  /**
2001
2052
  * Process a received INSTANT_SPLIT bundle.
2002
2053
  *
@@ -2187,7 +2238,8 @@ declare class PaymentsModule {
2187
2238
  getAssets(coinId?: string): Promise<Asset[]>;
2188
2239
  /**
2189
2240
  * Aggregate tokens by coinId with confirmed/unconfirmed breakdown.
2190
- * Excludes tokens with status 'spent', 'invalid', or 'transferring'.
2241
+ * Excludes tokens with status 'spent' or 'invalid'.
2242
+ * Tokens with status 'transferring' are counted as unconfirmed (visible in UI as "Sending").
2191
2243
  */
2192
2244
  private aggregateTokens;
2193
2245
  /**
@@ -2225,6 +2277,13 @@ declare class PaymentsModule {
2225
2277
  * @returns Summary with counts of resolved, still-pending, and failed tokens plus per-token details.
2226
2278
  */
2227
2279
  resolveUnconfirmed(): Promise<UnconfirmedResolutionResult>;
2280
+ /**
2281
+ * Start a periodic interval that retries resolveUnconfirmed() until all
2282
+ * tokens are confirmed or failed. Stops automatically when nothing is
2283
+ * pending and is cleaned up by destroy().
2284
+ */
2285
+ private scheduleResolveUnconfirmed;
2286
+ private stopResolveUnconfirmedPolling;
2228
2287
  /**
2229
2288
  * Process a single V5 token through its finalization stages with quick-timeout proof checks.
2230
2289
  */
@@ -2258,6 +2317,16 @@ declare class PaymentsModule {
2258
2317
  * Called during load() to restore tokens that TXF format can't represent.
2259
2318
  */
2260
2319
  private loadPendingV5Tokens;
2320
+ /**
2321
+ * Persist the set of processed splitGroupIds to KV storage.
2322
+ * This ensures Nostr re-deliveries are ignored across page reloads,
2323
+ * even when the confirmed token's in-memory ID differs from v5split_{id}.
2324
+ */
2325
+ private saveProcessedSplitGroupIds;
2326
+ /**
2327
+ * Load processed splitGroupIds from KV storage.
2328
+ */
2329
+ private loadProcessedSplitGroupIds;
2261
2330
  /**
2262
2331
  * Add a token to the wallet.
2263
2332
  *
@@ -2570,7 +2639,7 @@ declare class PaymentsModule {
2570
2639
  /**
2571
2640
  * Handle NOSTR-FIRST commitment-only transfer (recipient side)
2572
2641
  * This is called when receiving a transfer with only commitmentData and no proof yet.
2573
- * We create the token as 'submitted', submit commitment (idempotent), and poll for proof.
2642
+ * Delegates to saveCommitmentOnlyToken() helper, then emits event + records history.
2574
2643
  */
2575
2644
  private handleCommitmentOnlyTransfer;
2576
2645
  /**