feat(sync): NWC wallet sync (opt-in, spend-gated) + shared opt-in flags

Adds encrypted cross-login sync for the NWC wallet connection (todo #15),
reusing the encrypted-sync core under d-tag "bitvid:nwc".

- js/services/settingsSyncFlags.js: shared per-pubkey opt-in flag store
  (storage/wallet); storageSyncService refactored onto it (identical behavior,
  tests still green).
- js/services/walletSyncService.js: factory (NwcSettingsService is per-app, not a
  singleton). push() syncs the current nwcUri (+defaultZap); pull() applies it via
  updateActiveNwcSettings; disable() wipes the note.
- Wallet pane (components/profile-modal.html + ProfileWalletController): opt-in
  toggle + Restore button + a strong SPENDING warning, shown only when a signer
  can encrypt. Enabling requires an explicit window.confirm (the URI can spend).
  Re-pushes on save when enabled; and on wallet DISCONNECT while synced it clears
  the note so a removed spending URI doesn't linger (encrypted) on relays.

tests/wallet-sync-service.test.mjs: enable-pushes-uri, pull-restores-via-
updateActiveNwcSettings, disable-clears, no-wallet-doesn't-publish. Mutation-
verified (skip-apply + skip-clear both fail).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.8 committed 2026-06-21 17:57:39 -04:00
1 parent c651271af3
commit d552e9017c
6 files changed
+504 -42

No files matched your search

+27
View File
@@ -836,6 +836,33 @@
role="status"
aria-live="polite"
></p>
<div id="profileWalletSync" class="mt-2 rounded-lg border border-default p-4 space-y-3 hidden">
<div class="space-y-1">
<h4 class="text-sm font-semibold text-text">Cross-device sync</h4>
<p class="text-xs text-muted">
Save an <strong>encrypted</strong> copy of your wallet
connection to your Nostr account so you can use it on other
devices without re-pasting the URI.
</p>
</div>
<label class="flex items-start gap-2 text-sm text-muted-strong">
<input id="walletSyncToggle" type="checkbox" class="checkbox mt-0.5" />
<span>Sync my wallet connection to my Nostr account (encrypted)</span>
</label>
<p class="text-xs text-status-danger">
<strong>Spending warning:</strong> a wallet connect URI can spend
from your wallet. The encrypted copy lives on public relays —
anyone who controls your Nostr key could decrypt it and spend
from this wallet. Only enable this if you accept that risk.
</p>
<div class="flex flex-wrap items-center gap-3">
<button id="walletSyncRestoreBtn" type="button" class="btn-ghost focus-ring">
Restore from my Nostr account
</button>
</div>
<p id="walletSyncStatus" class="text-xs" role="status" aria-live="polite"></p>
</div>
</div>
</section>