@unicitylabs/sphere-sdk 0.9.1-dev.10 → 0.9.1-dev.12

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/index.d.cts CHANGED
@@ -1890,6 +1890,26 @@ type WalletApiPaymentRequestsPage = {
1890
1890
  cursor: string | null;
1891
1891
  syncEpoch: bigint;
1892
1892
  };
1893
+ /**
1894
+ * One §16 history wire record (§10 — the server never writes history rows).
1895
+ * `memo` / `counterpartyNametag` are S6 `enc1.` envelopes, verbatim (§8.3) —
1896
+ * encrypted on POST, returned encrypted on GET, decrypted by the owner only.
1897
+ */
1898
+ interface WalletApiHistoryRecord {
1899
+ dedupKey: string;
1900
+ id: string;
1901
+ type: string;
1902
+ ts: string;
1903
+ assets: {
1904
+ coinId: string;
1905
+ amount: string;
1906
+ }[];
1907
+ transferId?: string;
1908
+ tokenId?: string;
1909
+ counterpartyPubkey?: string;
1910
+ memo?: string;
1911
+ counterpartyNametag?: string;
1912
+ }
1893
1913
  /**
1894
1914
  * The narrow, STRUCTURAL slice of the wallet-api client this module needs:
1895
1915
  * the E.3 intent lifecycle, blob uploads for spend outputs, and the §10
@@ -1924,21 +1944,24 @@ interface PaymentsWalletApiPort {
1924
1944
  /** Upload to a presigned PUT (a 412 = already present = success — §5.2). */
1925
1945
  uploadBlob(putUrl: string, bytes: Uint8Array): Promise<void>;
1926
1946
  /** §10: client-asserted history records (§16 wire shape), deduped by dedupKey server-side. */
1927
- postHistoryRecords(records: {
1928
- dedupKey: string;
1929
- id: string;
1930
- type: string;
1931
- ts: string;
1932
- assets: {
1933
- coinId: string;
1934
- amount: string;
1935
- }[];
1936
- transferId?: string;
1937
- tokenId?: string;
1938
- counterpartyPubkey?: string;
1939
- memo?: string;
1940
- counterpartyNametag?: string;
1941
- }[]): Promise<void>;
1947
+ postHistoryRecords(records: WalletApiHistoryRecord[]): Promise<void>;
1948
+ /**
1949
+ * §10/§16: read the client-written history log back — newest-first keyset
1950
+ * pages (`{records, more, cursor, syncEpoch}`). The READ side of the §10 log:
1951
+ * a reloaded thin wallet rebuilds its history from here (the in-memory cache
1952
+ * is process-lifetime; the durable log lives on the server). `memo` /
1953
+ * `counterpartyNametag` come back as the verbatim S6 `enc1.` envelopes — the
1954
+ * owner decrypts them with its own field key on display (§8.3).
1955
+ */
1956
+ listHistory(options?: {
1957
+ before?: string;
1958
+ limit?: number;
1959
+ }): Promise<{
1960
+ records: WalletApiHistoryRecord[];
1961
+ more: boolean;
1962
+ cursor: string | null;
1963
+ syncEpoch: bigint;
1964
+ }>;
1942
1965
  /** Network name — scopes the persisted payment-request cursor (mirrors the mailbox cursor). */
1943
1966
  readonly network?: string;
1944
1967
  /** `POST /v1/payment-requests` (§16) — `memo` MUST already be an S6 envelope (§8.3). */
@@ -2538,10 +2561,39 @@ declare class PaymentsModule {
2538
2561
  */
2539
2562
  addToHistory(entry: Omit<TransactionHistoryEntry, 'id' | 'dedupKey'>): Promise<void>;
2540
2563
  /**
2541
- * Load history from the local token storage provider into the in-memory cache.
2542
- * Also performs one-time migration from legacy KV storage.
2564
+ * Load history into the in-memory cache.
2565
+ *
2566
+ * In the wallet-api composition (the `walletApi` client is present) the
2567
+ * durable §10 history log lives on the SERVER — the thin storage provider
2568
+ * keeps none — so the cache is rebuilt from `walletApi.listHistory()`. The
2569
+ * twin of the #521 inventory reload bug: `_historyCache` is process-lifetime,
2570
+ * so a reload (tab refresh) must re-pull it or render an empty history.
2571
+ * Compositions WITHOUT `walletApi` keep the legacy local path below.
2543
2572
  */
2544
2573
  loadHistory(): Promise<void>;
2574
+ /**
2575
+ * Rebuild `_historyCache` from the server's §10 history log (the wallet-api
2576
+ * composition). Pages newest-first via the keyset cursor until `more:false`
2577
+ * or the page cap; dedups by `dedupKey` (a hydrate-then-receive in the same
2578
+ * session must not double-list). The S6 `memo` / `counterpartyNametag`
2579
+ * envelopes are decrypted with the owner's own field key on the way in.
2580
+ *
2581
+ * Best-effort, like the §10 history POST: history is untrusted DISPLAY data,
2582
+ * so a backend outage during hydration must NEVER fail `load()` (the money
2583
+ * path) — the in-session cache is left intact and the pull retries next load.
2584
+ */
2585
+ private hydrateHistoryFromServer;
2586
+ /**
2587
+ * Map one §16 history wire record onto the display
2588
+ * {@link TransactionHistoryEntry}. `counterpartyNametag` lands on the role-
2589
+ * appropriate field (sender for RECEIVED, recipient otherwise); the S6 memo +
2590
+ * nametag envelopes decrypt under THIS wallet's field key (self-scoped at
2591
+ * rest — §8.3), surfaced as absent if they don't decrypt rather than as
2592
+ * ciphertext (same rule as mailbox/payment-request memos).
2593
+ */
2594
+ private historyEntryFromWire;
2595
+ /** S6 field decrypt that surfaces an undecryptable envelope as absent (§8.3). */
2596
+ private tryDecryptField;
2545
2597
  /**
2546
2598
  * Import history entries from remote TXF data into local store.
2547
2599
  * Delegates to the local TokenStorageProvider's importHistoryEntries() for
@@ -2760,6 +2812,16 @@ declare class PaymentsModule {
2760
2812
  * ones are not re-surfaced.
2761
2813
  */
2762
2814
  private pumpIncomingPaymentRequests;
2815
+ /**
2816
+ * Decrypt a payment-request's recipient-addressed memo envelope into
2817
+ * `{ memo, senderNametag }` (the requester's message + nametag). The key is
2818
+ * the ECDH shared secret between THIS wallet (the payer) and the requester's
2819
+ * chain pubkey (`wire.fromPubkey`) — symmetric with the requester's
2820
+ * create-time derivation. Returns an empty bundle (and logs at debug) on any
2821
+ * absence/failure so the incoming view never wedges on an unreadable memo
2822
+ * (PR twin of #546/#547).
2823
+ */
2824
+ private decryptPaymentRequestMemo;
2763
2825
  /**
2764
2826
  * Map a §16 wire request onto the public {@link IncomingPaymentRequest}
2765
2827
  * surface and notify (event + handlers). Only `open` requests are
package/dist/index.d.ts CHANGED
@@ -1890,6 +1890,26 @@ type WalletApiPaymentRequestsPage = {
1890
1890
  cursor: string | null;
1891
1891
  syncEpoch: bigint;
1892
1892
  };
1893
+ /**
1894
+ * One §16 history wire record (§10 — the server never writes history rows).
1895
+ * `memo` / `counterpartyNametag` are S6 `enc1.` envelopes, verbatim (§8.3) —
1896
+ * encrypted on POST, returned encrypted on GET, decrypted by the owner only.
1897
+ */
1898
+ interface WalletApiHistoryRecord {
1899
+ dedupKey: string;
1900
+ id: string;
1901
+ type: string;
1902
+ ts: string;
1903
+ assets: {
1904
+ coinId: string;
1905
+ amount: string;
1906
+ }[];
1907
+ transferId?: string;
1908
+ tokenId?: string;
1909
+ counterpartyPubkey?: string;
1910
+ memo?: string;
1911
+ counterpartyNametag?: string;
1912
+ }
1893
1913
  /**
1894
1914
  * The narrow, STRUCTURAL slice of the wallet-api client this module needs:
1895
1915
  * the E.3 intent lifecycle, blob uploads for spend outputs, and the §10
@@ -1924,21 +1944,24 @@ interface PaymentsWalletApiPort {
1924
1944
  /** Upload to a presigned PUT (a 412 = already present = success — §5.2). */
1925
1945
  uploadBlob(putUrl: string, bytes: Uint8Array): Promise<void>;
1926
1946
  /** §10: client-asserted history records (§16 wire shape), deduped by dedupKey server-side. */
1927
- postHistoryRecords(records: {
1928
- dedupKey: string;
1929
- id: string;
1930
- type: string;
1931
- ts: string;
1932
- assets: {
1933
- coinId: string;
1934
- amount: string;
1935
- }[];
1936
- transferId?: string;
1937
- tokenId?: string;
1938
- counterpartyPubkey?: string;
1939
- memo?: string;
1940
- counterpartyNametag?: string;
1941
- }[]): Promise<void>;
1947
+ postHistoryRecords(records: WalletApiHistoryRecord[]): Promise<void>;
1948
+ /**
1949
+ * §10/§16: read the client-written history log back — newest-first keyset
1950
+ * pages (`{records, more, cursor, syncEpoch}`). The READ side of the §10 log:
1951
+ * a reloaded thin wallet rebuilds its history from here (the in-memory cache
1952
+ * is process-lifetime; the durable log lives on the server). `memo` /
1953
+ * `counterpartyNametag` come back as the verbatim S6 `enc1.` envelopes — the
1954
+ * owner decrypts them with its own field key on display (§8.3).
1955
+ */
1956
+ listHistory(options?: {
1957
+ before?: string;
1958
+ limit?: number;
1959
+ }): Promise<{
1960
+ records: WalletApiHistoryRecord[];
1961
+ more: boolean;
1962
+ cursor: string | null;
1963
+ syncEpoch: bigint;
1964
+ }>;
1942
1965
  /** Network name — scopes the persisted payment-request cursor (mirrors the mailbox cursor). */
1943
1966
  readonly network?: string;
1944
1967
  /** `POST /v1/payment-requests` (§16) — `memo` MUST already be an S6 envelope (§8.3). */
@@ -2538,10 +2561,39 @@ declare class PaymentsModule {
2538
2561
  */
2539
2562
  addToHistory(entry: Omit<TransactionHistoryEntry, 'id' | 'dedupKey'>): Promise<void>;
2540
2563
  /**
2541
- * Load history from the local token storage provider into the in-memory cache.
2542
- * Also performs one-time migration from legacy KV storage.
2564
+ * Load history into the in-memory cache.
2565
+ *
2566
+ * In the wallet-api composition (the `walletApi` client is present) the
2567
+ * durable §10 history log lives on the SERVER — the thin storage provider
2568
+ * keeps none — so the cache is rebuilt from `walletApi.listHistory()`. The
2569
+ * twin of the #521 inventory reload bug: `_historyCache` is process-lifetime,
2570
+ * so a reload (tab refresh) must re-pull it or render an empty history.
2571
+ * Compositions WITHOUT `walletApi` keep the legacy local path below.
2543
2572
  */
2544
2573
  loadHistory(): Promise<void>;
2574
+ /**
2575
+ * Rebuild `_historyCache` from the server's §10 history log (the wallet-api
2576
+ * composition). Pages newest-first via the keyset cursor until `more:false`
2577
+ * or the page cap; dedups by `dedupKey` (a hydrate-then-receive in the same
2578
+ * session must not double-list). The S6 `memo` / `counterpartyNametag`
2579
+ * envelopes are decrypted with the owner's own field key on the way in.
2580
+ *
2581
+ * Best-effort, like the §10 history POST: history is untrusted DISPLAY data,
2582
+ * so a backend outage during hydration must NEVER fail `load()` (the money
2583
+ * path) — the in-session cache is left intact and the pull retries next load.
2584
+ */
2585
+ private hydrateHistoryFromServer;
2586
+ /**
2587
+ * Map one §16 history wire record onto the display
2588
+ * {@link TransactionHistoryEntry}. `counterpartyNametag` lands on the role-
2589
+ * appropriate field (sender for RECEIVED, recipient otherwise); the S6 memo +
2590
+ * nametag envelopes decrypt under THIS wallet's field key (self-scoped at
2591
+ * rest — §8.3), surfaced as absent if they don't decrypt rather than as
2592
+ * ciphertext (same rule as mailbox/payment-request memos).
2593
+ */
2594
+ private historyEntryFromWire;
2595
+ /** S6 field decrypt that surfaces an undecryptable envelope as absent (§8.3). */
2596
+ private tryDecryptField;
2545
2597
  /**
2546
2598
  * Import history entries from remote TXF data into local store.
2547
2599
  * Delegates to the local TokenStorageProvider's importHistoryEntries() for
@@ -2760,6 +2812,16 @@ declare class PaymentsModule {
2760
2812
  * ones are not re-surfaced.
2761
2813
  */
2762
2814
  private pumpIncomingPaymentRequests;
2815
+ /**
2816
+ * Decrypt a payment-request's recipient-addressed memo envelope into
2817
+ * `{ memo, senderNametag }` (the requester's message + nametag). The key is
2818
+ * the ECDH shared secret between THIS wallet (the payer) and the requester's
2819
+ * chain pubkey (`wire.fromPubkey`) — symmetric with the requester's
2820
+ * create-time derivation. Returns an empty bundle (and logs at debug) on any
2821
+ * absence/failure so the incoming view never wedges on an unreadable memo
2822
+ * (PR twin of #546/#547).
2823
+ */
2824
+ private decryptPaymentRequestMemo;
2763
2825
  /**
2764
2826
  * Map a §16 wire request onto the public {@link IncomingPaymentRequest}
2765
2827
  * surface and notify (event + handlers). Only `open` requests are