@unicitylabs/sphere-sdk 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/connect/index.cjs +3 -1
  2. package/dist/connect/index.cjs.map +1 -1
  3. package/dist/connect/index.js +3 -1
  4. package/dist/connect/index.js.map +1 -1
  5. package/dist/core/index.cjs +669 -277
  6. package/dist/core/index.cjs.map +1 -1
  7. package/dist/core/index.d.cts +57 -2
  8. package/dist/core/index.d.ts +57 -2
  9. package/dist/core/index.js +669 -277
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/impl/browser/connect/index.cjs +3 -1
  12. package/dist/impl/browser/connect/index.cjs.map +1 -1
  13. package/dist/impl/browser/connect/index.js +3 -1
  14. package/dist/impl/browser/connect/index.js.map +1 -1
  15. package/dist/impl/browser/index.cjs +11 -3
  16. package/dist/impl/browser/index.cjs.map +1 -1
  17. package/dist/impl/browser/index.js +11 -3
  18. package/dist/impl/browser/index.js.map +1 -1
  19. package/dist/impl/browser/ipfs.cjs +9 -2
  20. package/dist/impl/browser/ipfs.cjs.map +1 -1
  21. package/dist/impl/browser/ipfs.js +9 -2
  22. package/dist/impl/browser/ipfs.js.map +1 -1
  23. package/dist/impl/nodejs/connect/index.cjs +3 -1
  24. package/dist/impl/nodejs/connect/index.cjs.map +1 -1
  25. package/dist/impl/nodejs/connect/index.js +3 -1
  26. package/dist/impl/nodejs/connect/index.js.map +1 -1
  27. package/dist/impl/nodejs/index.cjs +11 -3
  28. package/dist/impl/nodejs/index.cjs.map +1 -1
  29. package/dist/impl/nodejs/index.d.cts +7 -0
  30. package/dist/impl/nodejs/index.d.ts +7 -0
  31. package/dist/impl/nodejs/index.js +11 -3
  32. package/dist/impl/nodejs/index.js.map +1 -1
  33. package/dist/index.cjs +671 -277
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +128 -3
  36. package/dist/index.d.ts +128 -3
  37. package/dist/index.js +670 -277
  38. package/dist/index.js.map +1 -1
  39. package/dist/l1/index.cjs +3 -1
  40. package/dist/l1/index.cjs.map +1 -1
  41. package/dist/l1/index.js +3 -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
@@ -1080,6 +1088,7 @@ interface TxfStorageDataBase {
1080
1088
  _outbox?: TxfOutboxEntry[];
1081
1089
  _sent?: TxfSentEntry[];
1082
1090
  _invalid?: TxfInvalidEntry[];
1091
+ _history?: HistoryRecord[];
1083
1092
  [key: `_${string}`]: unknown;
1084
1093
  }
1085
1094
  interface TxfMeta {
@@ -1933,6 +1942,7 @@ declare class PaymentsModule {
1933
1942
  private loadedPromise;
1934
1943
  private loaded;
1935
1944
  private processedSplitGroupIds;
1945
+ private processedCombinedTransferIds;
1936
1946
  private storageEventUnsubscribers;
1937
1947
  private syncDebounceTimer;
1938
1948
  private static readonly SYNC_DEBOUNCE_MS;
@@ -2002,6 +2012,43 @@ declare class PaymentsModule {
2002
2012
  * @returns InstantSplitResult with timing info
2003
2013
  */
2004
2014
  sendInstant(request: TransferRequest, options?: InstantSplitOptions): Promise<InstantSplitResult>;
2015
+ /**
2016
+ * Save a V5 split bundle as an unconfirmed token (shared by V5 standalone and V6 combined).
2017
+ * Returns the created UI token, or null if deduped.
2018
+ *
2019
+ * @param deferPersistence - If true, skip addToken/save calls (caller batches them).
2020
+ * The token is still added to the in-memory map for dedup; caller must call save().
2021
+ */
2022
+ private saveUnconfirmedV5Token;
2023
+ /**
2024
+ * Save a commitment-only (NOSTR-FIRST) token and start proof polling.
2025
+ * Shared by standalone NOSTR-FIRST handler and V6 combined handler.
2026
+ * Returns the created UI token, or null if deduped/tombstoned.
2027
+ *
2028
+ * @param deferPersistence - If true, skip save() and commitment submission
2029
+ * (caller batches them). Token is added to in-memory map + proof polling is queued.
2030
+ * @param skipGenesisDedup - If true, skip genesis-ID-only dedup. V6 handler sets this
2031
+ * because bundle-level dedup protects against replays, and split children share genesis IDs.
2032
+ */
2033
+ private saveCommitmentOnlyToken;
2034
+ /**
2035
+ * Process a received COMBINED_TRANSFER V6 bundle.
2036
+ *
2037
+ * Unpacks a single Nostr message into its component tokens:
2038
+ * - Optional V5 split bundle (saved as unconfirmed, resolved lazily)
2039
+ * - Zero or more direct tokens (saved as unconfirmed, proof-polled)
2040
+ *
2041
+ * Emits ONE transfer:incoming event and records ONE history entry.
2042
+ */
2043
+ private processCombinedTransferBundle;
2044
+ /**
2045
+ * Persist processed combined transfer IDs to KV storage.
2046
+ */
2047
+ private saveProcessedCombinedTransferIds;
2048
+ /**
2049
+ * Load processed combined transfer IDs from KV storage.
2050
+ */
2051
+ private loadProcessedCombinedTransferIds;
2005
2052
  /**
2006
2053
  * Process a received INSTANT_SPLIT bundle.
2007
2054
  *
@@ -2192,7 +2239,8 @@ declare class PaymentsModule {
2192
2239
  getAssets(coinId?: string): Promise<Asset[]>;
2193
2240
  /**
2194
2241
  * Aggregate tokens by coinId with confirmed/unconfirmed breakdown.
2195
- * Excludes tokens with status 'spent', 'invalid', or 'transferring'.
2242
+ * Excludes tokens with status 'spent' or 'invalid'.
2243
+ * Tokens with status 'transferring' are counted as unconfirmed (visible in UI as "Sending").
2196
2244
  */
2197
2245
  private aggregateTokens;
2198
2246
  /**
@@ -2443,6 +2491,13 @@ declare class PaymentsModule {
2443
2491
  * Also performs one-time migration from legacy KV storage.
2444
2492
  */
2445
2493
  loadHistory(): Promise<void>;
2494
+ /**
2495
+ * Import history entries from remote TXF data into local store.
2496
+ * Delegates to the local TokenStorageProvider's importHistoryEntries() for
2497
+ * persistent storage, with in-memory fallback.
2498
+ * Reused by both load() (initial IPFS fetch) and _doSync() (merge result).
2499
+ */
2500
+ private importRemoteHistoryEntries;
2446
2501
  /**
2447
2502
  * Get the first local token storage provider (for history operations).
2448
2503
  */
@@ -2592,7 +2647,7 @@ declare class PaymentsModule {
2592
2647
  /**
2593
2648
  * Handle NOSTR-FIRST commitment-only transfer (recipient side)
2594
2649
  * This is called when receiving a transfer with only commitmentData and no proof yet.
2595
- * We create the token as 'submitted', submit commitment (idempotent), and poll for proof.
2650
+ * Delegates to saveCommitmentOnlyToken() helper, then emits event + records history.
2596
2651
  */
2597
2652
  private handleCommitmentOnlyTransfer;
2598
2653
  /**
@@ -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
@@ -1080,6 +1088,7 @@ interface TxfStorageDataBase {
1080
1088
  _outbox?: TxfOutboxEntry[];
1081
1089
  _sent?: TxfSentEntry[];
1082
1090
  _invalid?: TxfInvalidEntry[];
1091
+ _history?: HistoryRecord[];
1083
1092
  [key: `_${string}`]: unknown;
1084
1093
  }
1085
1094
  interface TxfMeta {
@@ -1933,6 +1942,7 @@ declare class PaymentsModule {
1933
1942
  private loadedPromise;
1934
1943
  private loaded;
1935
1944
  private processedSplitGroupIds;
1945
+ private processedCombinedTransferIds;
1936
1946
  private storageEventUnsubscribers;
1937
1947
  private syncDebounceTimer;
1938
1948
  private static readonly SYNC_DEBOUNCE_MS;
@@ -2002,6 +2012,43 @@ declare class PaymentsModule {
2002
2012
  * @returns InstantSplitResult with timing info
2003
2013
  */
2004
2014
  sendInstant(request: TransferRequest, options?: InstantSplitOptions): Promise<InstantSplitResult>;
2015
+ /**
2016
+ * Save a V5 split bundle as an unconfirmed token (shared by V5 standalone and V6 combined).
2017
+ * Returns the created UI token, or null if deduped.
2018
+ *
2019
+ * @param deferPersistence - If true, skip addToken/save calls (caller batches them).
2020
+ * The token is still added to the in-memory map for dedup; caller must call save().
2021
+ */
2022
+ private saveUnconfirmedV5Token;
2023
+ /**
2024
+ * Save a commitment-only (NOSTR-FIRST) token and start proof polling.
2025
+ * Shared by standalone NOSTR-FIRST handler and V6 combined handler.
2026
+ * Returns the created UI token, or null if deduped/tombstoned.
2027
+ *
2028
+ * @param deferPersistence - If true, skip save() and commitment submission
2029
+ * (caller batches them). Token is added to in-memory map + proof polling is queued.
2030
+ * @param skipGenesisDedup - If true, skip genesis-ID-only dedup. V6 handler sets this
2031
+ * because bundle-level dedup protects against replays, and split children share genesis IDs.
2032
+ */
2033
+ private saveCommitmentOnlyToken;
2034
+ /**
2035
+ * Process a received COMBINED_TRANSFER V6 bundle.
2036
+ *
2037
+ * Unpacks a single Nostr message into its component tokens:
2038
+ * - Optional V5 split bundle (saved as unconfirmed, resolved lazily)
2039
+ * - Zero or more direct tokens (saved as unconfirmed, proof-polled)
2040
+ *
2041
+ * Emits ONE transfer:incoming event and records ONE history entry.
2042
+ */
2043
+ private processCombinedTransferBundle;
2044
+ /**
2045
+ * Persist processed combined transfer IDs to KV storage.
2046
+ */
2047
+ private saveProcessedCombinedTransferIds;
2048
+ /**
2049
+ * Load processed combined transfer IDs from KV storage.
2050
+ */
2051
+ private loadProcessedCombinedTransferIds;
2005
2052
  /**
2006
2053
  * Process a received INSTANT_SPLIT bundle.
2007
2054
  *
@@ -2192,7 +2239,8 @@ declare class PaymentsModule {
2192
2239
  getAssets(coinId?: string): Promise<Asset[]>;
2193
2240
  /**
2194
2241
  * Aggregate tokens by coinId with confirmed/unconfirmed breakdown.
2195
- * Excludes tokens with status 'spent', 'invalid', or 'transferring'.
2242
+ * Excludes tokens with status 'spent' or 'invalid'.
2243
+ * Tokens with status 'transferring' are counted as unconfirmed (visible in UI as "Sending").
2196
2244
  */
2197
2245
  private aggregateTokens;
2198
2246
  /**
@@ -2443,6 +2491,13 @@ declare class PaymentsModule {
2443
2491
  * Also performs one-time migration from legacy KV storage.
2444
2492
  */
2445
2493
  loadHistory(): Promise<void>;
2494
+ /**
2495
+ * Import history entries from remote TXF data into local store.
2496
+ * Delegates to the local TokenStorageProvider's importHistoryEntries() for
2497
+ * persistent storage, with in-memory fallback.
2498
+ * Reused by both load() (initial IPFS fetch) and _doSync() (merge result).
2499
+ */
2500
+ private importRemoteHistoryEntries;
2446
2501
  /**
2447
2502
  * Get the first local token storage provider (for history operations).
2448
2503
  */
@@ -2592,7 +2647,7 @@ declare class PaymentsModule {
2592
2647
  /**
2593
2648
  * Handle NOSTR-FIRST commitment-only transfer (recipient side)
2594
2649
  * This is called when receiving a transfer with only commitmentData and no proof yet.
2595
- * We create the token as 'submitted', submit commitment (idempotent), and poll for proof.
2650
+ * Delegates to saveCommitmentOnlyToken() helper, then emits event + records history.
2596
2651
  */
2597
2652
  private handleCommitmentOnlyTransfer;
2598
2653
  /**