# 02 — Capture, splits, QR Platba, sharing (day 2) Written before the code. Everything here is pure, like day 1: no I/O, no clock, no randomness. The app (Fiscus `docs/02_phones_sharing.md`) moves these events through Fundamentum; the core only defines them, applies them and checks them. ## New events (`fiscus-ledger`) A **personal log** (your own devices, the Fundamentum *self group*) holds every event. A **shared budget** is a log of its own (one MLS group): its members see exactly what was put into it, nothing else. | Event | Where | Effect | |:--|:--|:--| | `payment.shared` | shared budget | a member put one payment into this budget: `payment, budget, amount, date, merchant, category, origin`. Creates the payment in this log, or reassigns it after an unshare | | `payment.unshared` | shared budget | takes it out again (it stays in the log, unassigned) | | `budget.shared` | personal | a shared budget (created here or joined): like `budget.created`, but **never the default budget** | | `split.created` | either | `split, payment, payer, shares: [{person, name, amount}]`. Rejected unless the shares sum **exactly** to the payment's amount, every amount has the payment's sign, people are unique, and the payer is one of them | | `split.settled` | either | `split, person, how` (`qr`, `marked`). Rejected for an unknown split or person, the payer, or a second settlement | | `capture.token_added` / `capture.token_revoked` | personal | a phone's capture token: only its SHA-256 (`token`), a `name` and the `kind` (`iphone`, `android`). The token itself lives in Custos | | `share.link_created` | personal | a share link for one person of one split: only the SHA-256 of the link token, `split`, `person`, `expires` | | `account.set` | personal | the account for QR Platba (`iban`, `name`); the log is encrypted everywhere it is stored | `apply()` stays total: anything that does not fit is recorded in `state.rejected` with the reason. **Only an explicit `payment.assigned` shares a payment** (`share::shared_payment`). A payment that falls into a budget as the default is never sent anywhere. ### The split rule `split_equal(total, people)`: the people are **sorted by id and deduplicated first**, then split with equal weights by the day-1 largest-remainder `split()`. Every device computes the same shares in whatever order the people were picked, and the shares always sum to the total. The leftover haléře go to the first people in id order. A **share link** is open while its split is not settled for that person and `today <= expires` (`share_link_open`). The page shows exactly `ShareView { name, amount, merchant, date, spayd }` and nothing else. ## `fiscus-capture`: what the phones send Both are **hostile input**. Each yields a `Capture { amount (an outflow, negative), date, merchant, card }` or a typed error, never a partial payment. **The iPhone Shortcut post.** We write the Shortcut, so this is our format, not a bank's. It is a JSON object with exactly `amount`, `merchant`, `card`, `time`, plus an optional `currency`. Anything else is an error. - `amount`: a positive number, or a string in the form Shortcuts writes in Czech or English (`129`, `129,5`, `1 234,50`, `129.00`, optionally `Kč`/`CZK` before or after). It is parsed from its text, never as a float. `currency`, if present, must be `CZK`. - `merchant`: 1–200 characters, no control characters. `card`: 0–60 characters. - `time`: ISO 8601 with an offset (`2026-11-03T14:05:00+01:00`); the payment's date is the local date in it. - At most 4 KiB. *(assumption)* Apple's exact `amount` text is checked against the first real post. **Android bank notifications.** `recognise(app, title, text, selected)`: 1. If `app` is not one of the bank apps the person selected → `NotSelected`. The listener calls this only for selected apps; the core checks again. 2. Otherwise each template **for that app** is tried in turn. A template is literal text with `{amount}`, `{merchant}`, `{card}` and `{_}` holes, matched exactly (no regexes, no fuzziness). 3. No template matches → `Unknown`. The app counts it and shows the count in Settings; it is **never guessed**. **The template registry is empty**: no bank notification samples exist yet. Templates are written only from real samples in `fixtures/notifications//` (see `fixtures/README.md`). The engine is tested with synthetic templates that live only in the tests. ## QR Platba (`fiscus_ledger::pay`) - `Iban::parse` takes `CZ65 0800 0000 1920 0014 5399` or a Czech account `19-2000145399/0800`. Both checks are strict: the IBAN's mod-97, and for a Czech account the weighted mod-11 of the prefix and the number. Only CZ accounts (24 characters). - `spayd(iban, amount, message, vs)` gives `SPD*1.0*ACC:*AM:*CC:CZK*MSG:[*X-VS:]`. - The amount must be positive. It is written from haléře with two decimals (`450.00`), never through a float. - The message is at most 60 characters, and `*` is written as `%2A`. - The variable symbol is 1–10 digits. ## Household duplicates (`fiscus-insight`) `household_duplicates(&[(member, names)])`: the subscription merchant keys two or more members share, each with its members. It runs only on names members chose to share into the household group (opt-in, asked once). Nobody's names are read without that.