From a1693fc2a3190d3b8d4b08074214e903f00de8ec Mon Sep 17 00:00:00 2001 From: Gregory Fong Date: Mon, 16 Nov 2026 15:17:38 -0800 Subject: [PATCH] feat: opt-in payment alerts on mainnet and for view-only wallets (#61) Decided 16 Nov: mainnet wallets, view-only ones included, may lend their Orchard viewing key to Lantern Zero for payment alerts, only after a yes on the consent sheet. The sheet already names what a breach or court order could see, and adds a line for view-only wallets (#102). Engine: alerts_allowed is gone, so connect/set_scanning/wake no longer refuse on mainnet or for view-only wallets, and wakes lend the IVK whenever scanning is on. The host-only host-mainnet-alerts feature from #100 is no longer needed and is removed; examples/lantern --mainnet connect --scan now lends directly. App: alertsAvailable is removed from the status on both platforms; Notifications always asks for consent before lending, the mainnet-only "wake-ups only" copy goes, and Me's row is "Payment alerts" on both networks. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 3 - engine/Cargo.toml | 4 - engine/examples/lantern.rs | 31 +----- engine/src/engine.rs | 99 +++---------------- engine/src/ffi.rs | 9 -- mobile/app/(tabs)/me.tsx | 6 +- mobile/app/notifications.tsx | 21 ++-- scripts/check.sh | 2 - .../wizard/wallet/WalletSettings.kt | 3 +- .../wizard/wallet/WizardWalletModule.kt | 7 +- wallet-native/ios/WizardWalletModule.swift | 7 +- wallet-native/src/native.ts | 5 - 12 files changed, 29 insertions(+), 168 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6741a7f..81eb182 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,11 +47,8 @@ jobs: - run: rustup toolchain install stable --profile minimal --component rustfmt,clippy - run: cargo fmt --check - run: cargo clippy --all-targets --locked -- -D warnings - # The host tool's mainnet key lending (wizard#61); never in an app build. - - run: cargo clippy --all-targets --locked --features host-mainnet-alerts -- -D warnings # Tests that need a lightwalletd server are #[ignore]d. - run: cargo test --locked - - run: cargo test --locked --lib --features host-mainnet-alerts rust-msrv: name: Engine on Rust 1.89 (minimum) diff --git a/engine/Cargo.toml b/engine/Cargo.toml index d473546..a538051 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -78,10 +78,6 @@ ohttp = { version = "0.8", default-features = false, features = ["client", "serv [features] # The `uniffi-bindgen` binary, for generating Swift and Kotlin. Never linked into an app. bindgen = ["uniffi/cli", "uniffi/cargo-metadata"] -# Host tool only (wizard#61): lets `examples/lantern --mainnet --lend-key` -# lend a throwaway mainnet wallet's viewing key, for Lantern Zero's production -# key-storage check. Never enabled in an app build. -host-mainnet-alerts = [] [[bin]] name = "uniffi-bindgen" diff --git a/engine/examples/lantern.rs b/engine/examples/lantern.rs index 8780d12..3354e8e 100644 --- a/engine/examples/lantern.rs +++ b/engine/examples/lantern.rs @@ -13,16 +13,8 @@ //! //! `--mainnet` uses the wallet in `data/mainnet//` (made with `smoke //! --mainnet ... view`) and production: relay `lz-api`, gateway -//! push.lanternzero.com. Wake-ups only, as in the app (wizard#13). -//! -//! For Lantern Zero's production key-storage check (wizard#61) a throwaway -//! mainnet wallet can lend its viewing key, which the app never does: -//! -//! smoke --mainnet throwaway-ufvk | smoke --mainnet --wallet lend view --birthday H -//! cargo run --features host-mainnet-alerts --example lantern -- \ -//! --mainnet --lend-key --wallet lend connect --scan -//! -//! Never pass `--lend-key` for a wallet that watches real money. +//! push.lanternzero.com. `connect --scan` lends the wallet's viewing key on +//! mainnet too (wizard#61), so use a throwaway wallet for tests. use std::path::PathBuf; @@ -52,7 +44,6 @@ fn main() -> Result<()> { args.drain(i..=i + 1); } let mainnet = take_flag(&mut args, "--mainnet"); - let lend_key = take_flag(&mut args, "--lend-key"); let mut dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data"); if mainnet { dir = dir.join("mainnet"); @@ -69,13 +60,6 @@ fn main() -> Result<()> { data_dir: dir.to_string_lossy().into_owned(), server_url: std::env::var("WIZARD_SERVER").unwrap_or_else(|_| server.to_owned()), })?; - if lend_key { - if !mainnet { - bail!("--lend-key is for --mainnet; testnet wallets lend with `connect --scan`"); - } - lend_mainnet_key(&engine)?; - eprintln!("--lend-key: wallet {wallet}'s mainnet viewing key may be lent. Throwaway wallets only."); - } // Push keys for the host, kept beside the URL (git-ignored), made on first use. let push_file = dir.join("lantern-push.secret"); let secrets = || -> Result { @@ -155,14 +139,3 @@ fn main() -> Result<()> { } Ok(()) } - -#[cfg(feature = "host-mainnet-alerts")] -fn lend_mainnet_key(engine: &WalletEngine) -> Result<()> { - engine.host_lend_mainnet_key(); - Ok(()) -} - -#[cfg(not(feature = "host-mainnet-alerts"))] -fn lend_mainnet_key(_: &WalletEngine) -> Result<()> { - bail!("--lend-key needs `cargo run --features host-mainnet-alerts --example lantern`") -} diff --git a/engine/src/engine.rs b/engine/src/engine.rs index 22c5e38..6239d4e 100644 --- a/engine/src/engine.rs +++ b/engine/src/engine.rs @@ -167,9 +167,6 @@ pub struct WalletEngine { lantern: Mutex, /// Bumped to stop a running long-poll without waiting for its lock. lantern_stop: AtomicU64, - /// Host tool only (wizard#61): see `host_lend_mainnet_key`. - #[cfg(feature = "host-mainnet-alerts")] - host_lend_mainnet: AtomicBool, } impl std::fmt::Debug for WalletEngine { @@ -260,13 +257,11 @@ impl WalletEngine { names: zns::registry(&network).map(|r| Names::new(HttpTransport::new(&r), r)), lantern, lantern_stop: AtomicU64::new(0), - #[cfg(feature = "host-mainnet-alerts")] - host_lend_mainnet: AtomicBool::new(false), }) } - /// Mainnet is view-only in this build (zspace#481): no phrase accounts, no - /// payments, no Lantern Zero. Refused here, in Rust, whatever the app shows. + /// Mainnet is view-only in this build (zspace#481): no phrase accounts and + /// no payments. Refused here, in Rust, whatever the app shows. fn testnet_only(&self, what: &'static str) -> Result<(), EngineError> { match self.network { Network::TestNetwork => Ok(()), @@ -278,40 +273,6 @@ impl WalletEngine { self.network } - /// Lantern Zero on mainnet is wake-ups only (wizard#13, option "A-lite"): - /// payment alerts would lend the Orchard IVK, and a mainnet wallet is - /// view-only, so that key is the one thing the person trusted Wizard to - /// keep. Refuses turning alerts on there; wake-ups lend nothing. A - /// view-only wallet on testnet never lends its key either (issue #11). - fn alerts_allowed(&self, scanning: bool) -> Result<(), EngineError> { - if self.host_lends_mainnet() { - return Ok(()); - } - if scanning && self.network == Network::MainNetwork { - return Err(EngineError::MainnetViewOnly("Payment alerts")); - } - if scanning && self.has_account()? && self.is_view_only()? { - return Err(EngineError::ViewOnly); - } - Ok(()) - } - - /// Host tool only (wizard#61, feature `host-mainnet-alerts`, never in an - /// app): lifts the mainnet and view-only rules above so a throwaway - /// mainnet wallet can lend its viewing key, for Lantern Zero's - /// production key-storage check. Lasts until this engine closes. - #[cfg(feature = "host-mainnet-alerts")] - pub fn host_lend_mainnet_key(&self) { - self.host_lend_mainnet.store(true, Ordering::SeqCst); - } - - fn host_lends_mainnet(&self) -> bool { - #[cfg(feature = "host-mainnet-alerts")] - return self.host_lend_mainnet.load(Ordering::SeqCst); - #[cfg(not(feature = "host-mainnet-alerts"))] - false - } - /// A connected client, after checking once that the server is on this /// engine's network. fn client(&self) -> Result { @@ -830,7 +791,6 @@ impl WalletEngine { scanning: bool, instant: bool, ) -> Result<(), EngineError> { - self.alerts_allowed(scanning)?; lock(&self.lantern).connect(&self.runtime, secrets, relay_url, push, scanning, instant) } @@ -850,23 +810,20 @@ impl WalletEngine { } /// One wake. With scanning on, lends the Orchard IVK from what the - /// wallet has scanned; never on mainnet (`lantern_wake_keys`). + /// wallet has scanned (`lantern_wake_keys`). pub fn lantern_wake(&self, secrets: &lantern::Secrets) -> Result { - // A mainnet account with scanning saved on (only possible from an - // older build or a hand-edited state file) must not wake as if alerts work. - self.alerts_allowed(Lantern::status_at(&self.data_dir)?.scanning)?; let k = self.lantern_wake_keys(); lock(&self.lantern).wake(&self.runtime, secrets, k.ivk, k.scanned_height, k.amounts.as_ref()) } /// What a wake lends (the Orchard IVK, from what the wallet has scanned) - /// and reads alerts' amounts with. On mainnet the IVK stays home: no - /// viewing key is ever lent from a mainnet wallet. + /// and reads alerts' amounts with. The IVK is only sent while scanning is + /// on, which the person turns on from the consent sheet: on every network + /// and for view-only wallets too (wizard#61). fn lantern_wake_keys(&self) -> lantern::WakeKeys { let db = lock(&self.db); - let lend = self.network == Network::TestNetwork || self.host_lends_mainnet(); lantern::WakeKeys { - ivk: if lend { store::orchard_uivk(&db).ok() } else { None }, + ivk: store::orchard_uivk(&db).ok(), scanned_height: store::balance(&db).ok().and_then(|b| b.fully_scanned_height).map(u64::from), amounts: store::orchard_ivk(&db).ok(), } @@ -914,7 +871,6 @@ impl WalletEngine { } pub fn lantern_set_scanning(&self, on: bool) -> Result<(), EngineError> { - self.alerts_allowed(on)?; lock(&self.lantern).set_scanning(on) } @@ -1091,47 +1047,20 @@ mod tests { } #[test] - fn a_mainnet_view_only_wallet_never_lends_its_key() { - // The rule the app ships with (wizard#61 keeps it): even with an - // account whose key could be lent, nothing is. + fn a_mainnet_view_only_wallet_can_lend_its_key_once_asked() { + // wizard#61: opt-in alerts on mainnet and for view-only wallets. let (e, dir) = mainnet_view_only(); - assert!(store::orchard_uivk(&lock(&e.db)).is_ok()); - assert!(e.lantern_wake_keys().ivk.is_none()); - assert!(matches!(e.lantern_set_scanning(true), Err(EngineError::MainnetViewOnly(_)))); - let _ = std::fs::remove_dir_all(dir); - } - - #[cfg(feature = "host-mainnet-alerts")] - #[test] - fn the_host_tool_can_lend_a_throwaway_mainnet_key() { - let (e, dir) = mainnet_view_only(); - e.host_lend_mainnet_key(); - assert!(e.alerts_allowed(true).is_ok()); - let ivk = e.lantern_wake_keys().ivk.expect("lent"); - assert!(ivk.starts_with("uivk1"), "a mainnet Orchard IVK"); - let _ = std::fs::remove_dir_all(dir); - } - - #[test] - fn mainnet_allows_wakeups_but_never_lends_a_key() { - let (e, dir) = temp_engine("mainnet"); let secrets = lantern::Secrets { connection_url: zeroize::Zeroizing::new("lanternzero://127.0.0.1:9#lzt_x".into()), push: None, }; - // Alerts are refused before anything is sent. - assert!(matches!( - e.lantern_connect(&secrets, "https://127.0.0.1:9", None, true, false), - Err(EngineError::MainnetViewOnly(_)) - )); - assert!(matches!(e.lantern_set_scanning(true), Err(EngineError::MainnetViewOnly(_)))); - // Wake-ups get past the network check (and fail later, on the URL). + // Nothing refuses alerts up front (it fails later, on the URL). assert!(!matches!( - e.lantern_connect(&secrets, "https://127.0.0.1:9", None, false, false), - Err(EngineError::MainnetViewOnly(_)) + e.lantern_connect(&secrets, "https://127.0.0.1:9", None, true, false), + Err(EngineError::MainnetViewOnly(_) | EngineError::ViewOnly) )); - // A wake from a mainnet wallet carries no viewing key. - assert!(e.lantern_wake_keys().ivk.is_none()); + let ivk = e.lantern_wake_keys().ivk.expect("a key to lend once scanning is on"); + assert!(ivk.starts_with("uivk1"), "a mainnet Orchard IVK"); let _ = std::fs::remove_dir_all(dir); } diff --git a/engine/src/ffi.rs b/engine/src/ffi.rs index 76d2175..134f9c8 100644 --- a/engine/src/ffi.rs +++ b/engine/src/ffi.rs @@ -472,15 +472,6 @@ pub struct WalletEngine { inner: engine::WalletEngine, } -/// Not exported to Swift or Kotlin. -#[cfg(feature = "host-mainnet-alerts")] -impl WalletEngine { - /// Host tool only (wizard#61): `engine::WalletEngine::host_lend_mainnet_key`. - pub fn host_lend_mainnet_key(&self) { - self.inner.host_lend_mainnet_key(); - } -} - #[uniffi::export] impl WalletEngine { #[uniffi::constructor] diff --git a/mobile/app/(tabs)/me.tsx b/mobile/app/(tabs)/me.tsx index c73854f..9e84540 100644 --- a/mobile/app/(tabs)/me.tsx +++ b/mobile/app/(tabs)/me.tsx @@ -27,8 +27,6 @@ const PRIVACY_URL = 'https://wizardwallet.app/privacy'; function alertsValue(st: LanternStatus | null): string | undefined { if (!st) return undefined; if (!st.connected) return 'Off'; - // Mainnet is wake-ups only (wizard#13). - if (!st.alertsAvailable) return 'On'; // Which alert mode (zspace#442): private unless the person chose instant. return st.scanning ? (st.instant ? 'Instant' : 'Private') : 'Wake-ups only'; } @@ -193,10 +191,10 @@ export default function Me() { value={myName === undefined ? undefined : (myName ?? 'Not set')} onPress={() => router.push('/your-name')} /> - {/* Both networks (wizard#13); mainnet is wake-ups only, so it's named for what it does. */} + {/* Both networks (wizard#13), payment alerts on both (wizard#61). */} router.push('/notifications')} /> diff --git a/mobile/app/notifications.tsx b/mobile/app/notifications.tsx index b35c766..07f8950 100644 --- a/mobile/app/notifications.tsx +++ b/mobile/app/notifications.tsx @@ -263,8 +263,8 @@ export default function Notifications() { const turnOn = () => act(async () => { - // Mainnet is wake-ups only (wizard#13): no key is lent, so no consent sheet. - const c = status?.alertsAvailable ? await ask() : { lend: false, instant: false }; + // Lending the key needs a yes first, on every network (wizard#61). + const c = await ask(); await Wallet.lanternConnect(c.lend, c.instant); haptic.success(); }); @@ -342,9 +342,8 @@ export default function Notifications() { router.back()} /> - {status?.network === 'mainnet' - ? 'A Lantern Zero server can wake Wizard in the background, so it checks for payments and keeps your balance fresh without you opening it.' - : 'Wizard can tell you when you’ve been paid, through a Lantern Zero server. A payment shows as unconfirmed until Wizard’s own sync finds it.'} + Wizard can tell you when you’ve been paid, through a Lantern Zero server. A payment shows + as unconfirmed until Wizard’s own sync finds it. {status && !status.hasConnection ? ( @@ -382,13 +381,7 @@ export default function Notifications() { /> } /> - {on && !status.alertsAvailable ? ( - - ) : null} - {on && status.alertsAvailable ? ( + {on ? ( - {status.alertsAvailable - ? `Requests travel through ${relayHost(status.relay) ?? 'a relay'}, run by someone else, so the server never sees this phone’s address. The server sees your account and, with payment alerts on, the payments coming to you. Never your recovery phrase, and never what you send.` - : `Requests travel through ${relayHost(status.relay) ?? 'a relay'}, run by someone else, so the server never sees this phone’s address. The server sees your account and when it wakes this phone. Never your viewing key, your payments or your balance.`} + {`Requests travel through ${relayHost(status.relay) ?? 'a relay'}, run by someone else, so the server never sees this phone’s address. The server sees your account and, with payment alerts on, the payments coming to you. Never your recovery phrase, and never what you send.`} {!status.pushAvailable diff --git a/scripts/check.sh b/scripts/check.sh index 8e8a75d..d4eec89 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -41,10 +41,8 @@ if [ "$what" = all ] || [ "$what" = rust ]; then cargo fmt --check step "cargo clippy" cargo clippy --all-targets -- -D warnings - cargo clippy --all-targets --features host-mainnet-alerts -- -D warnings step "cargo test" cargo test - cargo test --lib --features host-mainnet-alerts if command -v cargo-deny >/dev/null; then step "cargo deny" cargo deny check diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt index b67a802..33dce34 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WalletSettings.kt @@ -122,8 +122,7 @@ object WalletSettings { /** * Lantern Zero (issue zspace#336), on the active network (wizard#13): the - * OHTTP relay, and the push gateway (empty: none). Mainnet is wake-ups only; - * the engine refuses payment alerts there. + * OHTTP relay, and the push gateway (empty: none). */ val lanternRelay get() = if (testnet) get("wallet_native_lantern_relay_testnet", "https://relay.oblivious.network/lz-staging") diff --git a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WizardWalletModule.kt b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WizardWalletModule.kt index e2a5847..7e46b98 100644 --- a/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WizardWalletModule.kt +++ b/wallet-native/android/src/main/java/com/principlezerolabs/wizard/wallet/WizardWalletModule.kt @@ -968,12 +968,9 @@ class WizardWalletModule : Module() { "connected" to false, "scanning" to false, "deviceRegistered" to false, "instant" to false, "modeChosen" to false, "showAmounts" to LanternPush.showAmounts(context), "lastWakeMs" to null, "lastError" to null, - // Both networks (wizard#13); payment alerts testnet only: mainnet is - // wake-ups only, and the engine refuses alerts there. A view-only - // wallet never lends its key either (issue #11). + // Both networks (wizard#13); payment alerts on both too, view-only + // wallets included, after the consent sheet (wizard#61). "available" to true, - "alertsAvailable" to (WalletSettings.testnet && - !(EngineHost.hasData(context) && runCatching { getEngine().isViewOnly() }.getOrDefault(false))), "network" to WalletSettings.network, ) if (EngineHost.hasData(context)) { diff --git a/wallet-native/ios/WizardWalletModule.swift b/wallet-native/ios/WizardWalletModule.swift index 72658bd..0f049f8 100644 --- a/wallet-native/ios/WizardWalletModule.swift +++ b/wallet-native/ios/WizardWalletModule.swift @@ -703,12 +703,9 @@ public final class WizardWalletModule: Module { "instant": false, "modeChosen": false, "showAmounts": LanternPush.showAmounts, "lastWakeMs": NSNull(), "lastError": NSNull(), ] - // Both networks (wizard#13); payment alerts testnet only: mainnet is - // wake-ups only, and the engine refuses alerts there. A view-only - // wallet never lends its key either (issue #11). + // Both networks (wizard#13); payment alerts on both too, view-only + // wallets included, after the consent sheet (wizard#61). out["available"] = true - let viewOnly = EngineHost.hasData() && ((try? self.getEngine().isViewOnly()) ?? false) - out["alertsAvailable"] = WalletSettings.testnet && !viewOnly out["network"] = WalletSettings.network if EngineHost.hasData() { let s = try self.getEngine().lanternStatus() diff --git a/wallet-native/src/native.ts b/wallet-native/src/native.ts index d1dc42a..216c151 100644 --- a/wallet-native/src/native.ts +++ b/wallet-native/src/native.ts @@ -183,11 +183,6 @@ export type LanternAlert = { export type LanternStatus = { /** Lantern Zero works on this network (both networks since wizard#13). */ available: boolean; - /** - * Payment alerts can be turned on here. False on mainnet: a mainnet wallet is - * view-only, so Wizard never lends its viewing key (wizard#13); wake-ups only. - */ - alertsAvailable: boolean; /** The network this status is for. */ network: 'mainnet' | 'testnet'; /** A connection URL is stored on this phone. */