Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 2 additions & 29 deletions engine/examples/lantern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,8 @@
//!
//! `--mainnet` uses the wallet in `data/mainnet/<NAME>/` (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;

Expand Down Expand Up @@ -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");
Expand All @@ -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<LanternSecrets> {
Expand Down Expand Up @@ -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`")
}
99 changes: 14 additions & 85 deletions engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ pub struct WalletEngine {
lantern: Mutex<Lantern>,
/// 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 {
Expand Down Expand Up @@ -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(()),
Expand All @@ -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<Client, EngineError> {
Expand Down Expand Up @@ -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)
}

Expand All @@ -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<lantern::WakeReport, EngineError> {
// 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(),
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 0 additions & 9 deletions engine/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions mobile/app/(tabs)/me.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -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). */}
<Item
mark="mark/lantern"
title={testnet ? 'Payment alerts' : 'Wake-ups'}
title="Payment alerts"
value={alertsValue(lantern)}
onPress={() => router.push('/notifications')}
/>
Expand Down
21 changes: 6 additions & 15 deletions mobile/app/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -342,9 +342,8 @@ export default function Notifications() {
<ScreenHeader title="Notifications" onBack={() => router.back()} />
<ScrollView contentContainerStyle={{ paddingBottom: 40 }}>
<T kind="dust" style={s.lead}>
{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.
</T>

{status && !status.hasConnection ? (
Expand Down Expand Up @@ -382,13 +381,7 @@ export default function Notifications() {
/>
}
/>
{on && !status.alertsAvailable ? (
<Row
title="Payment alerts"
detail="Not on mainnet yet. Wizard can only view a mainnet wallet, and it never lends that wallet’s viewing key. The server wakes Wizard, and Wizard checks for payments itself."
/>
) : null}
{on && status.alertsAvailable ? (
{on ? (
<Row
title="Payment alerts"
detail={
Expand Down Expand Up @@ -450,9 +443,7 @@ export default function Notifications() {
What’s shared
</T>
<T kind="dust" style={s.para}>
{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.`}
</T>
<T kind="dust" style={s.para}>
{!status.pushAvailable
Expand Down
2 changes: 0 additions & 2 deletions scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 2 additions & 5 deletions wallet-native/ios/WizardWalletModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 0 additions & 5 deletions wallet-native/src/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Loading