//! The approval card: a device joining an object whose vault another device //! founded asks, and a device that already holds the vault lets it in. The //! same flow iPhone's Keys › Devices runs over `vault.keys`, //! `vault.approveDevice` and `vault.refuseDevice`, answered here as one card so //! a shell with no Devices deck (Android's Messages, whose face is the chat) //! only draws it. Every word is `kits/shell/lines/unlock.json` `approval.*`. //! //! ```text //! vault.approval {} → {waiting: null, mine: {deviceId, line, act} | null, pollSeconds: 10 | null} //! ``` //! //! Since 22 Nov 2026 (GETTING-IN.md) `waiting` is always null and `mine` opens the new device's page; see [`card`]. //! What follows is how it stood before, kept for its reasons. //! //! NO APPROVE ON A TAP (19 Nov 2026). A device is let into //! the vault only by the typed-code compare of a sign-in ask //! (`signin_approval.rs`), never by a tap and a fingerprint read by eye. //! //! - `waiting`: on a device whose own wrap is in hand, the oldest other device //! that published its key and has no wrap: who it is, and `how` it is let in //! (on that device, Approve on another device; the code it shows is typed on //! the `signin.asks` card). Refuse is `vault.refuseDevice {deviceId}` after //! `confirm`. There is no Approve. //! - `mine`: on a device that published its key and has no wrap while another //! device holds the vault: the line saying so and `ask`, the button that makes //! an ask for this number with this device's vault key (`personal.ask`, whose //! card shows the code to type on the other device). A device founding a //! vault nobody holds yet waits on the object, not on a person, so it has no //! `mine`. Its `deviceId` is this device's. //! - `pollSeconds`: while `mine` waits, the shell syncs this often, so the wrap //! an approval wrote reaches it. use serde_json::{json, Value}; use cotton_client::vault::devices::{self, DeviceKey}; use cotton_core::rules::shell_lines::resolve; use crate::methods::MethodError; use crate::shell::client::ClientController; /// How often a device waiting for its approval syncs. pub const POLL_SECONDS: u64 = 10; fn say(line: &str, fills: &[(&str, &str)]) -> String { resolve("unlock", &format!("approval.{line}"), &[], fills).unwrap_or_default() } /// What `vault.approveDevice`'s refusal says: how a device is let in now. pub fn code_needed() -> String { say("code_needed", &[]) } /// `vault.approval`. pub fn approval(client: &ClientController) -> Result { let this = client.self_device_id(); let keys = client .with_file(|replica| devices::keys(replica.driver, replica.workspace_id)) .map_err(|reason| MethodError::new("unreadable", reason))?; Ok(card(this.as_deref(), &keys)) } /// The card over the vault's rows, as this device reads them. /// /// ONE CARD SINCE 22 NOV 2026 (assets/design/shared/GETTING-IN.md). A device that holds the key is asked by the new /// device's own ask, on `signin.asks` ("Your Mac wants to sign in to your Cotton", Approve to scan, Not me), so /// `waiting` is always null here: the card that said "{name} asks to read your private records" with only Refuse is /// gone. A waiting device's `mine` is the slim line over the app with its one act, which opens `gettingIn.screen`; /// the page asks by itself, so there is no button that asks. pub fn card(this: Option<&str>, keys: &[DeviceKey]) -> Value { let asking = super::getting_in::waits(this, keys).then(|| { let me = this.unwrap_or_default(); // `ask` stays for a shell from before the page (the iPhone until it draws `gettingIn.screen`): its button // makes the ask whose code the other device takes, as it did. json!({ "deviceId": me, "line": signin("slim"), "act": signin("slim_act"), "ask": signin("slim_act") }) }); let poll = asking.as_ref().map(|_| json!(POLL_SECONDS)).unwrap_or(Value::Null); json!({ "waiting": Value::Null, "mine": asking, "pollSeconds": poll }) } fn signin(line: &str) -> String { resolve("signin", &format!("getting_in.{line}"), &[], &[]).unwrap_or_default() }