Skip to content

feat: share invoices, quickpay spend and open sends between phone and watch - #2196

Draft
jvsena42 wants to merge 13 commits into
feat/wear-phone-pairingfrom
feat/wear-shared-guards
Draft

jvsena42 wants to merge 13 commits into
feat/wear-phone-pairingfrom
feat/wear-shared-guards

Conversation

@jvsena42

Copy link
Copy Markdown
Member

Part of #2105
Source: team, #2105

Warning

Do not publish the Wear app until #2152 ships. The watch runs the same Spark wallet as the phone, and Spark real-time sync is off (realTimeSyncServerUrl = null), so two live instances share no state. Mainnet is also gated off in this build (Env.IS_MAINNET_ENABLED = false), and the phone's Watch row is hidden on mainnet (Env.isWatchLinkEnabled).

Stacked on #2195 (feat/wear-phone-pairing). Part 2 of 3 of phone–watch pairing: once paired, the phone and the watch share what each needs to keep the other from paying wrongly. Part 3 adds watch management from the phone.

Description

  • Shares each device's own invoice hashes with the other, so neither pays an invoice the other made ("Can't pay own invoice" on the watch, the existing toast on the phone). Each side keeps the other's hashes in their own set, which every new document replaces (at most 1 000, expiries clamped to 7 days ahead), apart from its own; a set it never received or can't read blocks nothing.
  • Shares each device's QuickPay spend for the day, so phone and watch together stay within the phone's daily limit: each adds the other's cents when the day matches. The watch says no to QuickPay when it can't read the phone's count (the wearer holds to pay instead); the phone never writes the watch's cents into its own ledger.
  • Shares open sends: a device refuses with the existing Pending message when the other has an open send for that invoice, for at most 5 minutes from its start (the ~3 min settle window plus margin), or sooner when the other drops it or Spark lists the attempt failed. A start later than the reader's clock counts as stale, and a re-listed send keeps its first start.
  • Sends everything as app-encrypted documents over feat: pair the watch with the phone and send it the wallet #2195's channel, each with one publisher; the phone republishes all three when a pairing completes, the watch when the phone's status says paired. Unpairing, re-pairing and wiping clear the other side's state on both devices, and each reads it only while paired.
  • Adds docs (docs/wear.md › Pairing › Shared guards), two journeys, a README section on running two apps on one wallet (local stack, throwaway funds only), and a manual test over the real Data Layer.

Out of Scope

  • wear/app: per-device watch QuickPay caps, and watch QuickPay off until the phone enables it — pairing part 3.
  • wear/app: apart, each side uses the other's last known count, so together they can exceed the daily limit by what the other spent since.
  • wear/app: a payment cut off on one device and then paid by the other under the same key counts on both (it only restricts more).
  • wear/app: an invoice started on both devices within the moment a document takes to cross is refused by neither; Spark still pays it once, since both derive the same key per attempt.
  • wear/app: Spark-address transfers use a random key per device, so before the phone publishes payee entries (it publishes none today) the watch must reuse the phone's key or hold without the time limit.
  • wear/app: a failed publish waits for the next change, request or app start.

Design

N/A — no UI changes. Both apps reuse their existing pending and own-invoice messages.

Preview

Phone Bitkit_Phone_API36 (Android 16) and watch Wear_Large_Round_API37 (Wear OS 7), paired over the debug socket, both on the local ./spark stack, app commit d961f2853.

Watch refuses the phone's invoice Phone refuses the watch's invoice Phone asks for the swipe after the watch's QuickPay
Can't pay own invoice with OK Cannot Pay Own Invoice toast Swipe to pay review on the phone

Recordings (both stopped at the emulator's 170 s cap, so they are partial):

  • The watch refuses the phone's invoice:
send-phone-invoice-guard.mp4
  • The phone's QuickPay settings and the watch's QuickPay payment; the phone's swipe came after the cap:
quickpay-shared-daily-limit.mp4

QA Notes

Setup

  • Both apps built for the local ./spark stack and paired over the debug socket: journeys/wear/README.md › Local ./spark stack, › Phone and watch over the debug socket, and › Two apps on one wallet (a throwaway wallet, local stack only, never hosted regtest). Phone PIN 1111, biometrics off; pair with pair-receive-wallet.xml.
  • Check both emulators' clocks agree before the QuickPay journey (adb -s <serial> shell date): an emulator booted from a snapshot can run hours behind, and devices on different days don't share their counts. Cold-boot to fix.
  • Physical test: a Wear OS watch paired in the Wear OS app with an Android phone, dev builds on both (journeys/wear/README.md › On a physical watch).

Journeys

  • J1: new send-phone-invoice-guard.xml — the watch refuses the phone's invoice and the phone refuses the watch's
  • J2: new quickpay-shared-daily-limit.xml — after the watch pays $3 by QuickPay, the phone's $3 asks for the swipe and logs the shared count

Manual Tests

  • 1. Shared guards over the real Data Layer: J1 and J2 with the devices paired through the system's Data Layer instead of the debug socket (manual test 10 in journeys/wear/README.md)

Automated Checks

  • added LinkGuardsTest.kt — same-day counts, the 5-minute open-send hold, stale and future starts, kept starts, expiry clamps, document limits and the format byte
  • added PeerGuardStoreTest.kt — the watch's store of the phone's state: replace, clear on unpair, nothing read without a pairing, an undecodable stored list replaced
  • updated WatchLinkRepoTest.kt, PhoneLinkRepoTest.kt, SettingsPhoneStateSinkTest.kt — publishing, republish at pairing, clearing on unpair and wipe, a failing clear
  • updated SparkRepoTest.kt, QuickPayRepoTest.kt (both apps), QuickPaySpendStoreTest.kt — the phone refuses the watch's invoices and open sends, counts the watch's cents only in its checks, the day turning between read and write
  • updated PaymentsRepoTest.kt, SelfSendGuardTest.kt, UncertainSendStoreTest.kt, OwnInvoiceStoreTest.kt — the watch's own-invoice, pending and QuickPay rules with the phone's state, the payment hash in stored notes
  • updated LightningRepoTest.kt, SettingsSyncRepoTest.kt — constructor changes

Evidence

  • Gate on d961f2853: just compile, just test (with :wear:testDevDebugUnitTest --rerun), just lint all passed.
  • J1 and J2 passed on Bitkit_Phone_API36 (Android 16) and Wear_Large_Round_API37 (Wear OS 7) at d961f2853 on the local ./spark stack. J2's phone log showed "daily spend '300' + '300' exceeds cap '500'". pair-settings-push.xml, pair-unpair-from-phone.xml and send-own-invoice-guard.xml passed as regressions.
  • J2's first run failed: the watch emulator had booted from a snapshot with its clock 10 hours behind, so the two counted different days, and the phone logged the watch's count document as rejected ("not newer"); the phone paid by QuickPay. After a cold boot, a wipe and a new pairing on a fresh wallet, J2 passed.
  • Three review rounds: payment rules (Fable), and protocol, stores, docs and journeys (Opus); the last round of each found only Lows, which are fixed.

Gaps

  • Manual test 1 needs physical devices; none were available.
  • Clock or day differences between the devices silently stop the shared count (each counts alone); the "not newer" rejection in J2's first run suggests the snapshot also restored older link counters, which would stop that device's documents being taken until a new pairing (not confirmed). Both were seen only on emulators.
  • The Spark balances of the two devices were not compared after the run.
  • No changelog fragment: the phone's Watch row is hidden on mainnet until feat: run one wallet on two devices #2152.

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: medium)
  • Implementation: claude-opus-5-5 (reasoning: medium), claude-fable-5-2 (reasoning: medium)
  • Review: claude-fable-5-2 (reasoning: medium), claude-opus-5-5 (reasoning: medium)
  • Review rounds: 3
  • Journey runs: claude-sonnet-5-5 (reasoning: medium)

🤖 Generated with Claude Code

jvsena42 and others added 13 commits November 29, 2026 05:57
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… watch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Regtest APK

Built from d961f28 (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant