feat(app): add the Nostro app, a window for phones and desktops

Linux phones have no banking apps, and a command line is no answer on a
phone. The app does everything the nostro command does and, like it, only
talks to nostrod: it holds no key and no token.

- Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported
  from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens;
  Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics;
  nostro-app; and Nostro.DebugCommands for the --debug-api build.
- Client: every method also in an asynchronous form for an sd-event loop,
  with DaemonMissing and OutcomeUnknown.
- nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes
  net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both
  Flatpaks cross-built for aarch64, and the licence texts they carry.
- nostro-fake-system, a made-up bus and bank with a real nostrod on them, to
  look at the app against. The README's screenshots are taken on it.
- The nostro command: an API key's environment is the key's own to say, so
  --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL.

The published contract changes in three places, before any release (design
rule 10):
- Transactions' query takes `stored`: answered from what nostrod has stored,
  without asking the bank. The app searches with it; before, every search was
  a call to bunq.
- AddBunq's `environment` no longer chooses over what the key says of itself:
  a key of the other environment is refused.
- SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one
  as DEACTIVATED however well it pays, and leaves it as it is when asked,
  without an error.

The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved
from one to the other (design rule 13). Transaction's schema is unchanged.

Verified: the 17 tests pass with every line, function and region of what they
link run, and the five lint runs are clean. Every screen was looked at on the
made-up system, at a phone's and a desktop's sizes in the light and the dark
look, on Plasma under Wayland. What is said of bunq's cards comes from its
sandbox, with throwaway users, and from one real virtual card. Known to have
been used against production: connecting, and reading accounts, payments and
cards. Not known to have been tried: a payment from the app against bunq,
OAuth against bunq, and anything on a phone.

Building the app takes --graphics=, a Crafter.Graphics checkout on its branch
claude/nostro-app, until that branch is merged and pinned here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-11-19 12:27:14 +01:00
commit 5b4037955b
106 changed files with 17804 additions and 289 deletions

View file

@ -9,7 +9,7 @@ using namespace Nostro;
namespace {
constexpr std::string_view usage = R"(usage:
nostro connectors list connectors and whether they work
nostro connectors add bunq [allowed ips] [--sandbox] asks for the API key; ips default to *
nostro connectors add bunq [allowed ips] asks for the API key; ips default to *
nostro connectors add bunq-oauth <client id> <redirect uri> [--sandbox] asks for the client secret
nostro connectors remove <name or number> log out and forget a connector and its stored transactions
nostro accounts
@ -89,11 +89,6 @@ nostrod does the work, and asks for your password before anything that moves mon
return ParseNumber<std::int64_t>(text, "amount");
}
// The end of the day for a date without a time, so "--to 2026-10-31" includes that day.
std::chrono::system_clock::time_point ParseEnd(std::string_view text) {
return text.size() == 10 ? ParseLocalDate(text, 1) - std::chrono::microseconds(1) : ParseLocalDate(text);
}
// The arguments a payment, a draft, a schedule and a request share, read in order so a missing one is named the
// same way every time.
struct Payment {
@ -120,10 +115,15 @@ nostrod does the work, and asks for your password before anything that moves mon
}
void AddBunq(Client& client, const Arguments& args) {
// An API key says itself which environment it is of, by how it starts: there is nothing to choose, and a
// real key is not to be sent to the sandbox by a flag. Said before the key is asked for.
if(args.sandbox) {
throw std::invalid_argument("--sandbox goes with bunq-oauth: an API key is a sandbox key when it starts with sandbox_");
}
// Read at a prompt, or from stdin, never from the command line: every local user can read a process's
// arguments, and polkit writes them to the journal.
const std::string key = ReadSecret("bunq API key: ");
const AddedConnector added = client.AddBunq(key, args.Or(3, "*"), args.sandbox ? "sandbox" : "");
const AddedConnector added = client.AddBunq(key, args.Or(3, "*"), "");
std::println("added {} ({}, {} accounts)", added.name, added.environment, added.accounts);
}
@ -142,19 +142,10 @@ nostrod does the work, and asks for your password before anything that moves mon
if(!std::getline(std::cin, redirected)) {
throw std::runtime_error("no address given");
}
if(const std::optional<std::string> error = QueryParameter(redirected, "error")) {
throw std::runtime_error(std::format("bunq did not authorize: {} {}", *error, QueryParameter(redirected, "error_description").value_or("")));
}
const std::optional<std::string> code = QueryParameter(redirected, "code");
if(!code || code->empty()) {
throw std::runtime_error("that address has no code= in it");
}
if(QueryParameter(redirected, "state") != state) {
throw std::runtime_error("that address is not the answer to this authorization (its state differs): start again");
}
const std::string code = BunqConnector::OAuthCodeFromRedirect(redirected, state);
// nostrod exchanges the code for its token and keeps it; the token never comes here.
const AddedConnector added = client.AddBunqOAuth(args.sandbox ? "sandbox" : "production", clientId, clientSecret, redirectUri, *code);
const AddedConnector added = client.AddBunqOAuth(args.sandbox ? "sandbox" : "production", clientId, clientSecret, redirectUri, code);
std::println("added {} through OAuth ({}, {} accounts)", added.name, added.environment, added.accounts);
}
@ -197,7 +188,7 @@ nostrod does the work, and asks for your password before anything that moves mon
query.from = ParseLocalDate(*from);
}
if(const std::optional<std::string_view> to = args.Option("--to")) {
query.to = ParseEnd(*to);
query.to = ParseLocalDateEnd(*to);
}
if(const std::optional<std::string_view> limit = args.Option("--limit")) {
query.limit = ParseNumber<std::size_t>(*limit, "limit");
@ -255,13 +246,12 @@ nostrod does the work, and asks for your password before anything that moves mon
const Payment payment(args, "recipient", "recipient name", 7);
BunqSchedule schedule;
schedule.start = ParseLocalDate(args.At(5, "start date"));
schedule.unit = std::string(args.At(6, "recurrence"));
std::ranges::transform(schedule.unit, schedule.unit.begin(), [](char c) { return static_cast<char>(std::toupper(static_cast<std::uint8_t>(c))); });
schedule.unit = BunqSchedule::UnitFromWord(args.At(6, "recurrence"));
if(const std::optional<std::string_view> every = args.Option("--every")) {
schedule.every = ParseNumber<std::uint32_t>(*every, "--every");
}
if(const std::optional<std::string_view> until = args.Option("--until")) {
schedule.end = ParseEnd(*until);
schedule.end = ParseLocalDateEnd(*until);
}
const Created scheduled = client.Schedule(payment.account, payment.counterparty, payment.name, payment.amount, payment.description, schedule);
std::println("scheduled {} to {} (schedule {})", FormatMoney(payment.amount, scheduled.currency), payment.name, scheduled.id);
@ -317,9 +307,7 @@ nostrod does the work, and asks for your password before anything that moves mon
}
const std::uint64_t id = ParseNumber<std::uint64_t>(args.At(2, "card id"), "card id");
const BunqCard card = client.SetCardStatus(id, status->second);
if(card.status != status->second) {
throw std::runtime_error(std::format("bunq kept card {} {} (its order status is {}): a card can only be frozen or unfrozen once it has been activated", id, card.status, card.orderStatus));
}
card.ExpectStatus(status->second);
std::println("card {} is now {}", id, card.status);
}