@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.
@@ -1950,6 +1950,26 @@ type WalletApiPaymentRequestsPage = {
1950
1950
  cursor: string | null;
1951
1951
  syncEpoch: bigint;
1952
1952
  };
1953
+ /**
1954
+ * One §16 history wire record (§10 — the server never writes history rows).
1955
+ * `memo` / `counterpartyNametag` are S6 `enc1.` envelopes, verbatim (§8.3) —
1956
+ * encrypted on POST, returned encrypted on GET, decrypted by the owner only.
1957
+ */
1958
+ interface WalletApiHistoryRecord {
1959
+ dedupKey: string;
1960
+ id: string;
1961
+ type: string;
1962
+ ts: string;
1963
+ assets: {
1964
+ coinId: string;
1965
+ amount: string;
1966
+ }[];
1967
+ transferId?: string;
1968
+ tokenId?: string;
1969
+ counterpartyPubkey?: string;
1970
+ memo?: string;
1971
+ counterpartyNametag?: string;
1972
+ }
1953
1973
  /**
1954
1974
  * The narrow, STRUCTURAL slice of the wallet-api client this module needs:
1955
1975
  * the E.3 intent lifecycle, blob uploads for spend outputs, and the §10
@@ -1984,21 +2004,24 @@ interface PaymentsWalletApiPort {
1984
2004
  /** Upload to a presigned PUT (a 412 = already present = success — §5.2). */
1985
2005
  uploadBlob(putUrl: string, bytes: Uint8Array): Promise<void>;
1986
2006
  /** §10: client-asserted history records (§16 wire shape), deduped by dedupKey server-side. */
1987
- postHistoryRecords(records: {
1988
- dedupKey: string;
1989
- id: string;
1990
- type: string;
1991
- ts: string;
1992
- assets: {
1993
- coinId: string;
1994
- amount: string;
1995
- }[];
1996
- transferId?: string;
1997
- tokenId?: string;
1998
- counterpartyPubkey?: string;
1999
- memo?: string;
2000
- counterpartyNametag?: string;
2001
- }[]): Promise<void>;
2007
+ postHistoryRecords(records: WalletApiHistoryRecord[]): Promise<void>;
2008
+ /**
2009
+ * §10/§16: read the client-written history log back — newest-first keyset
2010
+ * pages (`{records, more, cursor, syncEpoch}`). The READ side of the §10 log:
2011
+ * a reloaded thin wallet rebuilds its history from here (the in-memory cache
2012
+ * is process-lifetime; the durable log lives on the server). `memo` /
2013
+ * `counterpartyNametag` come back as the verbatim S6 `enc1.` envelopes — the
2014
+ * owner decrypts them with its own field key on display (§8.3).
2015
+ */
2016
+ listHistory(options?: {
2017
+ before?: string;
2018
+ limit?: number;
2019
+ }): Promise<{
2020
+ records: WalletApiHistoryRecord[];
2021
+ more: boolean;
2022
+ cursor: string | null;
2023
+ syncEpoch: bigint;
2024
+ }>;
2002
2025
  /** Network name — scopes the persisted payment-request cursor (mirrors the mailbox cursor). */
2003
2026
  readonly network?: string;
2004
2027
  /** `POST /v1/payment-requests` (§16) — `memo` MUST already be an S6 envelope (§8.3). */
@@ -2598,10 +2621,39 @@ declare class PaymentsModule {
2598
2621
  */
2599
2622
  addToHistory(entry: Omit<TransactionHistoryEntry, 'id' | 'dedupKey'>): Promise<void>;
2600
2623
  /**
2601
- * Load history from the local token storage provider into the in-memory cache.
2602
- * Also performs one-time migration from legacy KV storage.
2624
+ * Load history into the in-memory cache.
2625
+ *
2626
+ * In the wallet-api composition (the `walletApi` client is present) the
2627
+ * durable §10 history log lives on the SERVER — the thin storage provider
2628
+ * keeps none — so the cache is rebuilt from `walletApi.listHistory()`. The
2629
+ * twin of the #521 inventory reload bug: `_historyCache` is process-lifetime,
2630
+ * so a reload (tab refresh) must re-pull it or render an empty history.
2631
+ * Compositions WITHOUT `walletApi` keep the legacy local path below.
2603
2632
  */
2604
2633
  loadHistory(): Promise<void>;
2634
+ /**
2635
+ * Rebuild `_historyCache` from the server's §10 history log (the wallet-api
2636
+ * composition). Pages newest-first via the keyset cursor until `more:false`
2637
+ * or the page cap; dedups by `dedupKey` (a hydrate-then-receive in the same
2638
+ * session must not double-list). The S6 `memo` / `counterpartyNametag`
2639
+ * envelopes are decrypted with the owner's own field key on the way in.
2640
+ *
2641
+ * Best-effort, like the §10 history POST: history is untrusted DISPLAY data,
2642
+ * so a backend outage during hydration must NEVER fail `load()` (the money
2643
+ * path) — the in-session cache is left intact and the pull retries next load.
2644
+ */
2645
+ private hydrateHistoryFromServer;
2646
+ /**
2647
+ * Map one §16 history wire record onto the display
2648
+ * {@link TransactionHistoryEntry}. `counterpartyNametag` lands on the role-
2649
+ * appropriate field (sender for RECEIVED, recipient otherwise); the S6 memo +
2650
+ * nametag envelopes decrypt under THIS wallet's field key (self-scoped at
2651
+ * rest — §8.3), surfaced as absent if they don't decrypt rather than as
2652
+ * ciphertext (same rule as mailbox/payment-request memos).
2653
+ */
2654
+ private historyEntryFromWire;
2655
+ /** S6 field decrypt that surfaces an undecryptable envelope as absent (§8.3). */
2656
+ private tryDecryptField;
2605
2657
  /**
2606
2658
  * Import history entries from remote TXF data into local store.
2607
2659
  * Delegates to the local TokenStorageProvider's importHistoryEntries() for
@@ -2820,6 +2872,16 @@ declare class PaymentsModule {
2820
2872
  * ones are not re-surfaced.
2821
2873
  */
2822
2874
  private pumpIncomingPaymentRequests;
2875
+ /**
2876
+ * Decrypt a payment-request's recipient-addressed memo envelope into
2877
+ * `{ memo, senderNametag }` (the requester's message + nametag). The key is
2878
+ * the ECDH shared secret between THIS wallet (the payer) and the requester's
2879
+ * chain pubkey (`wire.fromPubkey`) — symmetric with the requester's
2880
+ * create-time derivation. Returns an empty bundle (and logs at debug) on any
2881
+ * absence/failure so the incoming view never wedges on an unreadable memo
2882
+ * (PR twin of #546/#547).
2883
+ */
2884
+ private decryptPaymentRequestMemo;
2823
2885
  /**
2824
2886
  * Map a §16 wire request onto the public {@link IncomingPaymentRequest}
2825
2887
  * surface and notify (event + handlers). Only `open` requests are
@@ -1950,6 +1950,26 @@ type WalletApiPaymentRequestsPage = {
1950
1950
  cursor: string | null;
1951
1951
  syncEpoch: bigint;
1952
1952
  };
1953
+ /**
1954
+ * One §16 history wire record (§10 — the server never writes history rows).
1955
+ * `memo` / `counterpartyNametag` are S6 `enc1.` envelopes, verbatim (§8.3) —
1956
+ * encrypted on POST, returned encrypted on GET, decrypted by the owner only.
1957
+ */
1958
+ interface WalletApiHistoryRecord {
1959
+ dedupKey: string;
1960
+ id: string;
1961
+ type: string;
1962
+ ts: string;
1963
+ assets: {
1964
+ coinId: string;
1965
+ amount: string;
1966
+ }[];
1967
+ transferId?: string;
1968
+ tokenId?: string;
1969
+ counterpartyPubkey?: string;
1970
+ memo?: string;
1971
+ counterpartyNametag?: string;
1972
+ }
1953
1973
  /**
1954
1974
  * The narrow, STRUCTURAL slice of the wallet-api client this module needs:
1955
1975
  * the E.3 intent lifecycle, blob uploads for spend outputs, and the §10
@@ -1984,21 +2004,24 @@ interface PaymentsWalletApiPort {
1984
2004
  /** Upload to a presigned PUT (a 412 = already present = success — §5.2). */
1985
2005
  uploadBlob(putUrl: string, bytes: Uint8Array): Promise<void>;
1986
2006
  /** §10: client-asserted history records (§16 wire shape), deduped by dedupKey server-side. */
1987
- postHistoryRecords(records: {
1988
- dedupKey: string;
1989
- id: string;
1990
- type: string;
1991
- ts: string;
1992
- assets: {
1993
- coinId: string;
1994
- amount: string;
1995
- }[];
1996
- transferId?: string;
1997
- tokenId?: string;
1998
- counterpartyPubkey?: string;
1999
- memo?: string;
2000
- counterpartyNametag?: string;
2001
- }[]): Promise<void>;
2007
+ postHistoryRecords(records: WalletApiHistoryRecord[]): Promise<void>;
2008
+ /**
2009
+ * §10/§16: read the client-written history log back — newest-first keyset
2010
+ * pages (`{records, more, cursor, syncEpoch}`). The READ side of the §10 log:
2011
+ * a reloaded thin wallet rebuilds its history from here (the in-memory cache
2012
+ * is process-lifetime; the durable log lives on the server). `memo` /
2013
+ * `counterpartyNametag` come back as the verbatim S6 `enc1.` envelopes — the
2014
+ * owner decrypts them with its own field key on display (§8.3).
2015
+ */
2016
+ listHistory(options?: {
2017
+ before?: string;
2018
+ limit?: number;
2019
+ }): Promise<{
2020
+ records: WalletApiHistoryRecord[];
2021
+ more: boolean;
2022
+ cursor: string | null;
2023
+ syncEpoch: bigint;
2024
+ }>;
2002
2025
  /** Network name — scopes the persisted payment-request cursor (mirrors the mailbox cursor). */
2003
2026
  readonly network?: string;
2004
2027
  /** `POST /v1/payment-requests` (§16) — `memo` MUST already be an S6 envelope (§8.3). */
@@ -2598,10 +2621,39 @@ declare class PaymentsModule {
2598
2621
  */
2599
2622
  addToHistory(entry: Omit<TransactionHistoryEntry, 'id' | 'dedupKey'>): Promise<void>;
2600
2623
  /**
2601
- * Load history from the local token storage provider into the in-memory cache.
2602
- * Also performs one-time migration from legacy KV storage.
2624
+ * Load history into the in-memory cache.
2625
+ *
2626
+ * In the wallet-api composition (the `walletApi` client is present) the
2627
+ * durable §10 history log lives on the SERVER — the thin storage provider
2628
+ * keeps none — so the cache is rebuilt from `walletApi.listHistory()`. The
2629
+ * twin of the #521 inventory reload bug: `_historyCache` is process-lifetime,
2630
+ * so a reload (tab refresh) must re-pull it or render an empty history.
2631
+ * Compositions WITHOUT `walletApi` keep the legacy local path below.
2603
2632
  */
2604
2633
  loadHistory(): Promise<void>;
2634
+ /**
2635
+ * Rebuild `_historyCache` from the server's §10 history log (the wallet-api
2636
+ * composition). Pages newest-first via the keyset cursor until `more:false`
2637
+ * or the page cap; dedups by `dedupKey` (a hydrate-then-receive in the same
2638
+ * session must not double-list). The S6 `memo` / `counterpartyNametag`
2639
+ * envelopes are decrypted with the owner's own field key on the way in.
2640
+ *
2641
+ * Best-effort, like the §10 history POST: history is untrusted DISPLAY data,
2642
+ * so a backend outage during hydration must NEVER fail `load()` (the money
2643
+ * path) — the in-session cache is left intact and the pull retries next load.
2644
+ */
2645
+ private hydrateHistoryFromServer;
2646
+ /**
2647
+ * Map one §16 history wire record onto the display
2648
+ * {@link TransactionHistoryEntry}. `counterpartyNametag` lands on the role-
2649
+ * appropriate field (sender for RECEIVED, recipient otherwise); the S6 memo +
2650
+ * nametag envelopes decrypt under THIS wallet's field key (self-scoped at
2651
+ * rest — §8.3), surfaced as absent if they don't decrypt rather than as
2652
+ * ciphertext (same rule as mailbox/payment-request memos).
2653
+ */
2654
+ private historyEntryFromWire;
2655
+ /** S6 field decrypt that surfaces an undecryptable envelope as absent (§8.3). */
2656
+ private tryDecryptField;
2605
2657
  /**
2606
2658
  * Import history entries from remote TXF data into local store.
2607
2659
  * Delegates to the local TokenStorageProvider's importHistoryEntries() for
@@ -2820,6 +2872,16 @@ declare class PaymentsModule {
2820
2872
  * ones are not re-surfaced.
2821
2873
  */
2822
2874
  private pumpIncomingPaymentRequests;
2875
+ /**
2876
+ * Decrypt a payment-request's recipient-addressed memo envelope into
2877
+ * `{ memo, senderNametag }` (the requester's message + nametag). The key is
2878
+ * the ECDH shared secret between THIS wallet (the payer) and the requester's
2879
+ * chain pubkey (`wire.fromPubkey`) — symmetric with the requester's
2880
+ * create-time derivation. Returns an empty bundle (and logs at debug) on any
2881
+ * absence/failure so the incoming view never wedges on an unreadable memo
2882
+ * (PR twin of #546/#547).
2883
+ */
2884
+ private decryptPaymentRequestMemo;
2823
2885
  /**
2824
2886
  * Map a §16 wire request onto the public {@link IncomingPaymentRequest}
2825
2887
  * surface and notify (event + handlers). Only `open` requests are