Nostro/AGENTS.consumer.md
Jorijn van der Graaf b43ab124a6
feat: open payto links on the pay form, and take the checkout over D-Bus out
An app could have nostrod pay an order: it called Pay of
net.catcrafts.Nostro1.Checkout on the system bus, and nostrod paid from
an account the user had chosen, after a dialog of its own. On 2026-11-22
the owner decided that a link takes its place. The app registers for
payto links (RFC 8905), so that an app or a website can hand one to the
desktop, and shows a link as its pay form filled in.

The link:

- The app's desktop entry takes the scheme (Exec=nostro-app %u,
  MimeType=x-scheme-handler/payto), and nostro-app takes an argument
  that is no option as a link: it overwrites it in argv and hands it to
  App::Open once the app has started.
- ReadPaymentLink (Nostro.App:Forms) reads payto://iban/<IBAN> with the
  options amount, receiver-name and message, and refuses a link rather
  than guess at it, in a sentence of the app's own with nothing of the
  link in it. Among what it refuses: an IBAN whose check digits do not
  hold, one of the three options given twice, instruction, a comma in
  the amount, and a name or a message with a code point that is Unshown,
  or Blank and no plain space.
- A link that is read waits until the accounts are read and
  DefaultCheckoutAccount has answered or failed, with a line on the
  accounts' page. Then App::TakeLink fills in the pay form, which says
  in a banner that a link filled it in, and with more than one account
  opens it under the choice of accounts that the form's From row has. A
  link pays nothing: the form's button sends, and polkit's dialog
  confirms as for any payment (design rule 12, and 14, which is new).
- Unshown and Blank are the two tables the worker's Shown() works from.
  They move into Nostro:Utils, where the app's reader asks them too.
  The move is within the library. The reader holds a link's name to
  those two and to no more of Shown(): a name with an & is read, and
  the dialog shows it with a + as it does any name.

The checkout:

- nostrod serves one interface under one bus name. Gone are
  net.catcrafts.Nostro1.Checkout with its XML and its activation file,
  the polkit action Checkout, the module Nostro.Checkout with
  --product=checkout, and the worker's record of orders. That changes
  the published contract after a release, 0.0.0, and design rule 10
  records it as the owner's decision.
- DefaultCheckoutAccount and SetDefaultCheckoutAccount keep their names
  and signatures. The account they keep is where a link's pay form
  starts: nostrod's dialog for choosing it says "have pay links start
  from", the app's setting reads "Pay links start from", and `nostro
  checkout account` prints "pay links start from".
- The D-Bus policy still lets nostrod own the old name: the nostrod of
  0.0.0 asks for it when it starts, and the system files can be newer
  than the Flatpak it runs from. install.sh removes the old name's
  activation file. A user's checkouts.cdb is read by nothing any more,
  and is left where it is.
- The Arch package stops installing the checkout's two files, and its
  pkgrel goes up to 2. Where makepkg -si finds a package of the version
  already built it installs that one again, which would bring the
  activation file back. The guide now says that pkgrel goes up with a
  change to what the package installs.
- Bus::Interface goes too: the worker called it in two places, to tell
  a call to the checkout from one to the main interface.

The review's own files follow. gate0 loses the build of
--product=checkout, and the three lens sections that named the checkout
no longer do, and ask about a link.

The README has "Pay links" in place of "Checkout for apps", and
AGENTS.consumer.md says what the app reads of a link. Its line on
lib/json.hpp no longer gives a release: the file is of none, and the
guide names its commit. The pay form and the accounts' page change only
by a banner each, shown while a link is in play, which
docs/screenshots/take.sh never has: the README's pictures stand.

Tests: ShouldValidateForms reads and refuses links and fills the form
from one. ShouldDriveTheApp opens links against a real nostrod on the
fake bus: before the accounts are known, with no account, with one and
with several, with the accounts known and the system bus gone, for a
second user whose first connection pays their own accounts only, one
that cannot be read, one whose name has an &, and through polkit's
dialog to the payment. It now counts nostrod's answers to hold that the
account pay links start from is read again once a connection is
removed: the check it had there passed without that.
ShouldHandleMoneyAndText holds the two tables at the ends of their
ranges. ShouldServeEveryUser holds that nostrod serves no checkout, that
the bus's policy lets an older nostrod own the old name, and the account
pay links start from. ShouldRunCommands holds the CLI's wording.

The review's gate0 passes at this commit: the version check, 17 tests,
the builds of the CLI, the library, nostrod, the fake system, the app
and its --debug-api build, and five lint runs that report nothing.
tests/coverage.sh reports lines, functions and regions at 100.00%.

Looked at on 2026-11-22 on the made-up system (run fake), on a desktop
(KWin at a scale of 1.85). At 420x760, at --scale 3 --size 360x760 and
at 1100x720 in the light look: a link's pay form under the choice of
accounts, the form after a tap beside that choice, and the accounts'
page while a link waits, its line above the rows that stand in for the
accounts (--bank-delay 10000). At 420x760: that line above what the
page says when the accounts cannot be read (--polkit deny) and above
the accounts themselves (--polkit slow, the link opened in the running
app), the settings' row and page for the account pay links start from,
the sheet for a link that cannot be read, and with --empty the sheet
for no account.
2026-11-22 13:35:51 +01:00

35 KiB

nostro

nostro is a banking client for Linux in four parts. The library is a C++26 module, import Nostro;, that talks to a bank's API directly (bunq so far), keeps the credentials in one private JSON file, caches transactions in Crafter.DB tables, and lists, syncs, pays, requests and schedules. nostrod is a system daemon that runs that library for every local user, one worker process each, behind D-Bus and polkit. The nostro CLI and the Nostro app, a window for a phone or a desktop, are clients of nostrod. The app's own modules (Nostro.Ui, Nostro.App, Nostro.Ui.Shell) are built for the app and its tests alone, and are GPL-3.0-only where the library is LGPL-3.0-only: --lib does not hand them to a consumer. A consumer does one of two things:

  • links the library and holds the credentials itself, in its own process (--lib --banks=bunq);
  • or talks to nostrod through Nostro::Client (--lib --banks=bunq --dbus), as the CLI does.

An app that only wants a customer to pay an order links nothing of nostro: it opens a link, see "Having a customer pay".

Everything is in namespace Nostro: the OpenSSL helpers in Nostro::Crypto, the D-Bus names and wire in Nostro::Bus. Linux only (Crafter.DB, the POSIX calls in its file layer, libsystemd), built by crafter-build's clang 23 with import std;. LGPL-3.0-only; lib/json.hpp is nlohmann/json (MIT). The README is the user-facing manual; these notes are its AGENTS.consumer.md: a fix to them goes there, not into the copy crafter-build writes.

Building against it

  • GitProject with nostro's repository, or LocalProject({ .projectFile = "<checkout>/project.cpp", .args = nostroArgs }) for a checkout, into cfg.dependencies. nostroArgs is your own ProjectArgs() plus --lib and --banks=bunq, built once inside CrafterBuildProject: without --lib nostro's project.cpp returns the CLI executable configuration (with the library as its dependency, which you cannot import from), and without --banks= it throws "must enable atleast one bank" and the whole build stops at load. --banks= is a comma-separated list and bunq is the only name it accepts.
  • --dbus with --lib adds the partitions that talk to nostrod, :Bus, :Client and :Daemon, and links -lsystemd (sd-bus) for you; it needs bunq on, since the wire carries bunq's types. Without it the library does not depend on libsystemd.
  • nostro strips its own args (--lib, --banks=, --dbus, --product=, --debug-api, --coverage, --profile-runtime=) from what it hands its dependencies and forwards the rest, adding --no-quic for Crafter.Network: nostro speaks HTTP/1.1 only, and msquic would tie the binary to the building user's cache. A consumer that also loads Crafter.Network gives it that same list, --no-quic included, and Crafter.DB the list without it, or the build stops with two loads that disagree on their args.
  • nostro's project.cpp loads two build helpers by #pragma crafter dependency, Crafter.LintRules and, at a pinned commit, Crafter.Debug's: loading nostro fetches and builds both for the host, whatever is built of it. Crafter.Debug's library itself is only in nostro's own app, under --debug-api.
  • What comes with it: Crafter.Network (with Crafter.Thread behind it), Crafter.DB, -lssl -lcrypto, and with --dbus -lsystemd, all as link flags you do not declare. Nothing in nostro uses the thread pool, so ThreadPool::Start() is not needed for it.
  • Defines do not cross a dependency. nostro compiles with NOSTRO_BUNQ_ENABLED, NOSTRO_OPENSSL_ENABLED and, under --dbus, NOSTRO_DBUS_ENABLED, and the PCMs carry the result: import Nostro; exports BunqConnector and Client, and EnabledBanks lists bunq, whatever your configuration defines (nostro's own CLI compiles without them). Your own #ifdef NOSTRO_BUNQ_ENABLED sees it only when you push the same Define into your cfg.defines, as nostro's CLI configuration does with execfg.defines = libcfg.defines.
  • import Nostro; is enough for everything below; nothing exposed needs import Crafter.Network; or import Crafter.DB;. The raw bunq calls (Get, Post, Put, Delete, List) take and return nlohmann::json: hold the result in auto, and include lib/json.hpp where you have to name or build one.
  • Static initialisers run at load: Nostro::configPath and cachePath read XDG_CONFIG_HOME and XDG_CACHE_HOME, else HOME, and throw (so std::terminate) when neither is set. The HTTPS clients are function-local statics, made on the first bunq call.

Money, currencies and time

  • Currency is an enum class with Euro alone. GetCurrency("EUR") (or "eur") is the only parse; anything else throws std::runtime_error("unsupported currency '…'"). RefreshAccounts skips a bank account in another currency with a Note instead. GetCurrencyCode gives "EUR", GetCurrencySymbol "€", GetCurrencyDecimals 2; std::format("{}", Currency::Euro) is the symbol. All constexpr.
  • Amounts and balances are std::int64_t in the minor unit, so 1250 is €12.50, outgoing negative. ParseAmount("12.50", Currency::Euro) is 1250: an optional leading -, digits, an optional . with at most decimals digits, nothing else, or std::runtime_error("malformed amount '…'"). FormatAmount(1250, Currency::Euro) is "12.50", FormatAmount(-5, …) "-0.05", and FormatMoney(-102, …) "-€1.02", the sign before the symbol. All constexpr.
  • ParseTimestamp("2026-10-31 12:34:56.123456") is a std::chrono::system_clock::time_point, read as UTC: exactly YYYY-MM-DD HH:MM:SS, optionally . and one to six fraction digits, no zone, or std::runtime_error("malformed timestamp '…'"). FormatTimestamp is its inverse, bunq's format. libc++'s system_clock ticks in microseconds, which is also what the tables store.
  • For dates a person types: ParseLocalDate("2026-10-31") or ParseLocalDate("2026-10-31 09:30") in the local time zone (through mktime), or std::runtime_error naming the format; ParseLocalDate(day, 1) is the midnight that ends day, counted by the calendar, so a day the clocks change is 23 or 25 hours, and ParseLocalDateEnd(text) the last moment a range ending at text includes (the end of that day for a date alone). FormatLocalTime(time) is "YYYY-MM-DD hh:mm" in local time.
  • UrlEncode percent-encodes all but RFC 3986's unreserved characters; UrlDecode undoes it and reads + as a space; QueryParameter(url, name) is the decoded value from the query string, or std::nullopt. EscB(text) escapes text for inside a JSON string literal; nostro itself no longer builds JSON by hand.
  • Unshown(codePoint) is whether a Unicode code point draws nothing or tells text where to go, and Blank(codePoint) whether it is a space of any width, U+0020 among them, or U+2800, the Braille pattern without a dot. Both are constexpr and noexcept and take a std::uint32_t; decoding UTF-8 is yours. nostrod's worker drops the first from what it puts into a password dialog, and turns a run of the second into one plain space, none leading or trailing.

Connectors, the config file and the process

  • Connector::LoadConnectors() reads <config>/connectors.json. A missing file is no connectors yet, not an error. It fills every bank's connectors first and then calls RefreshAccounts() on each, a network round trip per connector. A connector whose refresh throws keeps no accounts and is reported through Note (bunq connector '<name>' is unavailable: …), so the others stay usable. A file that is not JSON throws std::runtime_error("<path> is not valid JSON (it breaks at byte N)"), which never quotes the file, as nlohmann's own message could quote a private key (since 2026-11-01; it was a nlohmann::json::parse_error). Valid JSON with a missing or mistyped key still throws nlohmann's json::exception. Call it once at start-up, on the thread that will do the bank calls.
  • Connector::SaveConnectors() writes the file for every enabled bank: to connectors.json.tmp-<pid> (0600 in a 0700 directory, through CreatePrivateFile), fsync, rename over the old file, fsync of the directory. A crash or power cut leaves one whole file. Create does not call it. nostro does, by itself, after it renews a session and after it fetches a missing server key, so the connectors you hold must be the ones in BunqConnector::connectors. The file holds the API key or OAuth token, both tokens and the unencrypted RSA private key PEM, per connector environment, apiKey, installationToken, sessionToken, sessionId, privateKey, serverPublicKey, userType, name, id, ownerId; treat it accordingly and never commit one. Files from before 2026-10-31 lack environment, sessionId, serverPublicKey, userType and ownerId; they load as sandbox connectors, the only host then.
  • Both take an exclusive flock on <config>/connectors.lock and hold it until the process ends. A second nostro process blocks in its first load or save, after the Note waiting for another nostro process to finish. A long-running front end therefore makes every CLI run wait for it to exit.
  • Note(text) is where the library's warnings go: a connector that could not be refreshed, an account skipped, a request made but not read back, the wait for the lock. It calls the global noteSink, a std::function<void(std::string_view)> that prints a line on stderr until you replace it: collect them instead to show them in your own UI, as a daemon does to send them to its client.
  • <config> is GetConfigPath(): $XDG_CONFIG_HOME/.config/nostro when XDG_CONFIG_HOME is set (the .config is inserted, as of 2026-10-31), else $HOME/.config/nostro. <cache> is GetCachePath(): $XDG_CACHE_HOME/nostro, else $HOME/.cache/nostro. The globals configPath and cachePath are those values, read once at load; a test redirects both through the environment before the process starts.
  • ReadSecret(prompt) reads a trimmed line from stdin; on a terminal it prompts on stderr and turns echo off, so a key stays out of shell history and the process list. It throws std::runtime_error when stdin ends first.
  • Generic code over the enabled banks is tuple_for<EnabledBanks>([&]<typename Bank>() { for (Bank& bank : Bank::connectors) { … } });, a template lambda. Every Bank has static constexpr std::string connectorId ("bunq"), static std::deque<Bank> connectors, using Account, std::vector<Account> accounts, std::string name, TestConnector(), RefreshAccounts(), RefreshSession(), GetNewTransactions() and GetNewTransactions(account), Logout(), StorageKey(), a static Create(…) and Remove(bank), and formats as its name. Its accounts have StorageKey() and format as name<TAB>bic iban<TAB>€12.50 (std::format works on Account and on every type derived from it). Anything else, such as requests or cards, is bunq's own; if constexpr (requires { account.Requests(); }) is how nostro's CLI asks.
  • Account { name, bic, iban, currency, balance } plus the transaction store, keyed by a storage key you pass as the connector argument. For bunq that is account.StorageKey(), bunq/<production|sandbox>/<user id>/<account id>.
    • GetLastTransactionTime(key): the newest stored timePoint, time_point::min() for an empty or new table.
    • SaveTransactions(key, std::vector<Transaction>): sorts by time, appends the rows newer than the last stored one and flushes; a call that brings nothing new writes nothing. At the last stored timestamp a row is appended when its id is not stored there yet. When a row stored there has no id (version 1 data), everything at that timestamp is taken as stored. Older rows are dropped silently.
    • FindTransactions(key, TransactionQuery): newest first, at most limit. TransactionQuery takes designated initialisers: .search (ASCII case-insensitive substring of the counterparty name, the description or the IBAN; empty matches all), .amount (std::optional<std::int64_t>, exact, minor units, negative for outgoing), .from and .to (inclusive time_points, the whole range by default), .limit (100), and .stored (false), which is for nostrod and which FindTransactions does not look at: it never asks a bank. The time range is a binary search on the ordered table; the rest is a backwards scan that stops at limit: measured at 1.5 µs over 20 rows and 4 ms over 100 000 when nothing matches.
    • The tables are <cache>/transactions/<key>/<account name>.cdb, with a / in the name written as _, opened on first use and kept open for the rest of the process, or until Account::ForgetTransactions(key) closes and deletes every table under key (a connector's storage key covers all its accounts; Remove calls it). A renamed account starts a new table and syncs again. Tables written before 2026-10-31 sit at <cache>/transactions/bunq/<account name>.cdb and are no longer read.
  • Transaction { name, bic, iban, description, currency, amount, timePoint, id, kind } is an aggregate and the on-disk row type (version = 2, orderedBy = timePoint, 120 bytes). id is the bank's own id as text and kind its classification (bunq's "MASTERCARD/PAYMENT", "EBA_SDD/SDD"); both are empty in rows migrated from version 1. A version 1 table migrates on its first open and keeps <file>.v1.bak. Do not add members to it from outside.

The bunq connector

  • Two environments. BunqConnector::environment is BunqEnvironment::Production (api.bunq.com, real money) or Sandbox (public-api.sandbox.bunq.com). BunqConnector::EnvironmentOfKey(key) is Sandbox for a key starting sandbox_; an OAuth token does not say, so the caller decides. Production has been used to connect and to read since 2026-11-19; before that only the sandbox was. BunqConnector::Endpoint(environment) is the BunqEndpoint (host, port, caPem) its calls go to. Each endpoint has one ClientHTTP1, shared by its connectors; every call is synchronous on the calling thread and the client serves one caller at a time, so keep bunq calls on one thread.
  • For tests: BunqConnector::RedirectTo(BunqEndpoint{.host = "127.0.0.1", .port = …, .caPem = …}) sends every API and OAuth token call there for the rest of the process, whatever the environment. nostro's own tests point it at tests/Support/FakeBunq.inc, an in-process bunq that a consumer's test can include as well (after lib/json.hpp, import std;, import Nostro; and import Crafter.Network;).
  • BunqConnector::Create(std::string&& apiKey, std::string_view allowedIps, BunqEnvironment environment) registers an installation with a fresh RSA-2048 key, the device with the key and opens a session. allowedIps is a plain comma-separated list ("203.0.113.4, 198.51.100.7"), "*" for any address (it makes the key a wildcard key, which a phone with a changing address needs), or empty for the address the call comes from. It returns a reference into BunqConnector::connectors, a std::deque, so a later Create leaves earlier references and every account's connector pointer valid. The same bunq user (ownerId) in the same environment connected the same way replaces the old connector, logging its session out: that is how a key is renewed. Connected the other way (API key against OAuth), Create logs the new session out and throws, because every account would otherwise be listed twice. Follow it with Connector::SaveConnectors() or the connector is gone at exit.
  • BunqConnector::Remove(connector) deletes its stored transactions (through Account::ForgetTransactions, which first closes the tables this process has open, so the same user added again syncs into new files) and erases it from connectors, re-pointing the remaining accounts; references to other connectors you held are invalidated, as with any deque::erase in the middle. It does not log out: call Logout() first (DELETE /v1/session/{sessionId}, not renewed; a session already gone counts as logged out). Then SaveConnectors().
  • After LoadConnectors or Create a connector has environment, name (bunq's display_name of the user; for OAuth of the user who granted access), id (the user id in API paths; for OAuth the UserApiKey's own), ownerId, userType (UserPerson, UserCompany, UserApiKey or UserPaymentServiceProvider; IsOAuth() is UserApiKey), sessionToken, sessionId, installationToken, privateKey and serverPublicKey (Crypto::Key, a std::shared_ptr<EVP_PKEY>), apiKey, and accounts of BunqAccount (Account plus id, bunq's object type such as MonetaryAccountSavings, and a connector back-pointer).
  • Every call goes through Get, Post, Put or Delete (a path below /v1, or a pagination URL) and List (every item of a listing, pages of 200 followed through older_url, newest first). Bodies are signed. Every 2xx must carry a valid x-bunq-server-signature for the stored server key, which an old connector fetches before its first call, or the call throws. A 429 is waited out: 3 s up to five times, 31 s up to twice for session-server. A 401, or a 403 "Insufficient authentication.", opens a new session once, saves, and retries. A POST, PUT or DELETE goes over a new connection, because ClientHTTP1 would replay one on a reused connection after a read timeout. When the outcome of such a write is unknown (a transport error, a 5xx, an unreadable or unverifiable answer), the error ends in ; the request may have been carried out, check before trying again, which is BunqError::maybeCarriedOut. Any other error response is a BunqError.
  • RefreshAccounts() rebuilds accounts from scratch (references into it go stale): every MonetaryAccount… type whose status is ACTIVE or BLOCKED, the IBAN alias as iban, BUNQNL2A as bic for a bunq IBAN. TestConnector() is GET /v1/user/{id} and returns false on any exception rather than throwing. GetNewTransactions(account) (and GetNewTransactions() for all) pages the payments newest first until one older than the last stored row, fills id and kind ("<type>/<sub_type>"), and calls SaveTransactions(account.StorageKey(), …); the first sync walks the whole history, 200 a call.
  • On a BunqAccount, amounts are positive minor units, or std::invalid_argument. Counterparties go through BunqCounterparty::Parse(value, name): an @ makes an e-mail address, a leading + a phone number (spaces, dashes and brackets dropped), anything else an IBAN. An IBAN is upper-cased, has its spaces removed and its check digits verified, so a typo throws std::invalid_argument before anything is sent. bunq needs name for an IBAN outside bunq.
    • Send, Draft (one-entry draft payment, paid once someone accepts it) and Schedule(…, BunqSchedule) return bunq's id. BunqSchedule { start, end, unit ("ONCE", "HOURLY", "DAILY", "WEEKLY", "MONTHLY", "YEARLY"), every } is UTC; an unknown unit or every == 0 throws std::invalid_argument. BunqSchedule::UnitFromWord("monthly") is "MONTHLY", for a unit a person typed.
    • Request(from, name, amount, currency, description) asks for money with bunq.me allowed and returns a BunqPaymentRequest, whose shareUrl anyone can pay through. When reading it back fails, the request still exists: it comes back PENDING without a share URL, with a Note.
    • The listings, newest first: Requests() (sent, BunqPaymentRequest), IncomingRequests() (BunqIncomingRequest, incoming SEPA direct debits included as DIRECT_DEBIT), ScheduledPayments(), DraftPayments(). One of each, as bunq has it now: IncomingRequest(id) and DraftPayment(id). The answers: RevokeRequest(id), CancelScheduledPayment(id), and two that take the object you showed the user: RespondToRequest(shown, accept) pays shown.amount and shown.currency, whatever the request asks by then, and RespondToDraftPayment(shown, accept) sends shown.updated (bunq's own timestamp, kept as text), so bunq refuses an answer to a draft that changed since. Read it, show it, answer with what you read. A request has one id on each side: the asker's inquiry id is not the payer's response id.
  • Cards() lists the user's cards (BunqCard: id, status, orderStatus, productType, lastFour, expiry, the paying iban, …). status is bunq's, and is about the plastic: card.State() is how the card stands in one word, which is status except for a virtual card (card.Virtual(): its orderStatus is VIRTUAL_DELIVERY), which is VIRTUAL until it is gone for good. bunq has a virtual card as DEACTIVATED however well it pays, and nothing says whether one is frozen. The std::formatter prints State(). SetCardStatus(id, "DEACTIVATED" | "ACTIVE" | "LOST" | "STOLEN") returns the card as bunq has it afterwards, which can differ from the request without an error: a card that was never activated stays DEACTIVATED, and a virtual card is left as it is when asked to freeze or unfreeze. card.ExpectStatus(asked) throws std::runtime_error saying so in either case. Through nostrod, Client::SetCardStatus refuses to freeze or unfreeze a virtual card with std::invalid_argument, before anyone is asked for a password.
  • OAuth instead of an API key: OAuthAuthorizationUrl(environment, clientId, redirectUri, state) is where the user approves with the bunq app. bunq then redirects to redirectUri with code and state: OAuthCodeFromRedirect(redirectedAddress, state) returns the code, or throws std::runtime_error when bunq did not authorize (error=), the address has no code, or its state is another. OAuthExchangeCode(environment, clientId, clientSecret, redirectUri, code) returns the access token, which Create takes in place of an API key. bunq grants OAuth payments between the user's own accounts, draft payments, cards, and creating requests, but no paying of incoming ones. The exchange was verified up to bunq refusing a fake code; a full approval needs a person and the bunq app.
  • Every type above formats with std::format as one tab-separated line (a draft adds a line per entry), the way nostro's CLI prints them.

nostrod, through Nostro::Client

nostrod is the system daemon that holds every local user's connectors, in a worker process per user under its own state directory, which the users cannot read. It answers net.catcrafts.Nostro1 on the system bus (published as packaging/dbus/net.catcrafts.Nostro1.xml), for the calling user only, after asking polkit: as shipped only viewing passes in an active session, and everything else asks for the user's password each time, a draft saved, a request for money and a card frozen as much as a payment. An administrator's rule may ask for less. A call that names an account, a card, a request, a draft or a connector, and is not a call to see it, is checked twice: for viewing, before nostrod looks up what it names, and then for what it does. So a caller polkit does not let see the accounts gets AccessDenied for it, whether what it named is there or not. A front end that should not hold the credentials itself (--dbus) talks to it through Nostro::Client:

  • Client::System(timeout = 10min) connects to the system bus with interactive authorization allowed, so polkit can ask for the password, and a call timeout long enough for the user and for bunq's rate limits. D-Bus starts nostrod with the first call. Keep one Client per thread; it is not shared between threads.
  • One method per D-Bus method, with nostro's own types: Connectors() (ConnectorSummary: name, bank, environment, auth "api key" or "oauth", working), AddBunq(apiKey, allowedIps, environment) and AddBunqOAuth(environment, clientId, clientSecret, redirectUri, code) (AddedConnector; for AddBunq leave the environment empty: nostrod takes the one the key is of, and naming one only has a key of the other refused with std::invalid_argument, before anything is sent), RemoveConnector(name or number), Accounts() (ConnectorAccounts), Transactions(account, TransactionQuery) (nostrod asks the bank for what is new first, a call to the bank that takes its time and that the bank counts; with .stored = true it answers from what it has stored alone, in milliseconds: for a search in a list just read, or more of it. A nostrod from before 2026-11-19 ignores stored and asks the bank), Send, Schedule, Draft (Created: bunq's id and the currency), Request (BunqPaymentRequest), the listings, RevokeRequest, RespondToRequest(account, id, accept), CancelScheduledPayment, RespondToDraftPayment(account, id, accept), Cards() (ConnectorCards), SetCardStatus(card, status), DefaultCheckoutAccount() (std::optional<Account>) and SetDefaultCheckoutAccount(account). account is an account's name or IBAN. Accepting a request or a draft pays it as nostrod read it to show the user.
  • TakeNotes() returns, and clears, the library's warnings from the calls so far (a connector unavailable, a request made but not read back): show them.
  • Every method also has an asynchronous form, for a program with an event loop that must not wait minutes on a password dialog: client.Attach(sd_event*) once (a second Attach throws), then call the method with a last argument Then<T> (std::function<void(Answer<T>)>; std::monostate for a method that answers nothing). It returns a [[nodiscard]] Client::Pending at once and calls then from the loop when nostrod answers. Answer<T> holds the result or the std::exception_ptr the blocking call would have thrown (Get() returns the one or rethrows the other, Failed(), Error()), and that call's notes; an error answer carries none, and notes are collected per user by nostrod's worker, so they can be another call's of the same user. Destroying the Pending, or Cancel(), drops the answer (then is not called) without undoing the call, which nostrod and bunq carry on with; Active() says whether then is still to come. A then that throws is reported through Note. Calling one without Attach throws std::logic_error. Once the connection is gone (Connected() false), make a new client: a closed connection answers nothing it still awaited.
  • Errors: std::invalid_argument for what nostrod refused before doing anything (it names the problem, as the library's own messages do). That includes an e-mail address to pay or ask that the password dialog could not show exactly as it is: one with an &, a < or a > in it, with a character that draws nothing, or longer than 254 characters. A name is never refused for that: the dialog shows it without what draws nothing, with &, < and > replaced, and cut at 64 characters. DaemonError, a std::runtime_error with the D-Bus error name, for the rest: Bus::errorBank (bunq's refusal, as bunq said it), Bus::errorOAuthCannotPay, Bus::errorCancelled (the user closed the password dialog), Bus::errorFailed, org.freedesktop.DBus.Error.AccessDenied (the system's policy, or polkit not answering) and InteractiveAuthorizationRequired. A missing nostrod is DaemonMissing, a std::runtime_error saying it is not running. A call that moves money or changes something and gets no answer in time, or that bunq answered with an error ending in BunqError::maybeCarriedOut (a 5xx: the payment may have been made), is OutcomeUnknown, a std::runtime_error saying it may have been carried out: check before trying again. Text that is not UTF-8 is a std::invalid_argument before anything is sent.
  • The API key and the OAuth client secret travel once, in messages marked sensitive. Read them with ReadSecret, never from argv, which every local user can read and polkit logs.

Having a customer pay

An app that wants a customer to pay an order links nothing of nostro and calls nothing of nostrod: it opens a payto://iban/… link (RFC 8905), and the Nostro app shows it as its pay form filled in, for the user to check, change and confirm with their password. What the app reads of a link:

  • payto://iban/<IBAN>?amount=EUR:12.50&receiver-name=<name>&message=<what it is for>, the values percent-encoded, which UrlEncode does. A BIC and a / may come before the IBAN, and are left out. The amount is EUR, a colon and digits, with a point and one or two more digits or without, as FormatAmount(1250, Currency::Euro) writes one (12.50); without amount the user fills it in. The name is at most 70 code points, the message 140, and the link 4096 bytes.
  • A link the app refuses gets a sentence of the app's own, with nothing of the link in it. Among what it refuses: an IBAN whose check digits do not hold; amount, receiver-name or message given twice, where an option's name counts with its escapes undone and in small letters; instruction; a #; a % that is no escape in one of those values; a name or a message that is not UTF-8, or has a code point in it that is Unshown, a noncharacter (the last two of a plane), or Blank and no plain space; a currency other than EUR; an amount that is zero, or has a sign, a space or a comma in it. Other options are passed over.
  • A + in a value is read as a space (UrlDecode): write %20 for a space and %2B for a plus.
  • The app tells whoever opened the link nothing. See the payment arrive at your own bank.
  • The checkout over D-Bus that 0.0.0 has is gone: net.catcrafts.Nostro1.Checkout, the module Nostro.Checkout and --product=checkout, which is now an unknown product, and with them Bus::actionCheckout, Bus::checkoutMethods and Bus::errorNoCheckoutAccount. Client::DefaultCheckoutAccount and SetDefaultCheckoutAccount stayed: the account they keep is where the app's pay form starts for a link.

Errors

  • BunqError is a std::runtime_error with the HTTP status (bunq also uses 466, 490 and 491), its message bunq <METHOD> <path>: <error_description> (<status>).
  • std::invalid_argument is for input refused before anything is sent: an IBAN, amount or schedule.
  • Everything else nostro throws is a std::runtime_error: an unverifiable or unreadable bunq answer, "unsupported currency '…'", "malformed amount '…'", "malformed timestamp '…'", "bunq response has no '<key>' object", "openssl error" (after ERR_print_errors_fp(stderr)), "XDG_CONFIG_HOME and HOME not set".
  • Around it come:
    • nlohmann::json::exceptions from a connectors.json or a bank response with a missing key or a wrong type (a std::exception, not a runtime_error).
    • std::system_error from the file layer and the lock.
    • Crafter.Network's SocketErrorException, SocketTimeoutException, TLSException and HTTP1::HTTP1ProtocolError from a GET (a write wraps them as above).
    • Crafter.DB's Error family from the tables.
  • Catch std::exception at the top of a command, as nostro's main does.

Testing a consumer

  • Point XDG_CONFIG_HOME and XDG_CACHE_HOME at a scratch directory before the process starts, or set Nostro::configPath and cachePath first thing in main. No connectors.json needs seeding.
  • A consumer of Client needs nostrod on a system bus, and a build sandbox has none. nostro's tests/Support/FakeBus.inc is one in the test's own process: the bus driver, logind and polkit (with scripted answers: allow, a password, deny, a closed dialog, absent, silent or slow), giving each connection of the test's own process a uid of the test's choosing (nostrod's keep their own). Set DBUS_SYSTEM_BUS_ADDRESS to Fake::Bus::Address(path) before any thread starts, and start nostrod as a process of its own: tests/ShouldServeEveryUser compiles implementations/nostrod.cpp in with its main renamed and runs its own executable again as nostrod (Fake::StartNostrod), pointed at a fake bunq through the environment (Fake::Bunq::ExportRedirect, RedirectFromEnvironment).
  • Without bunq: RedirectTo a fake (see "For tests" above), as every one of nostro's own tests does.
  • A throwaway bunq user: POST https://public-api.sandbox.bunq.com/v1/sandbox-user-person (or -company) without authentication returns Response[0].ApiKey.api_key. Pass it to Create with "*" and EnvironmentOfKey(key), then SaveConnectors(). The new account holds €0; account.Request("sugardaddy@bunq.com", "Sugar Daddy", 50000, Currency::Euro, "…") is paid within seconds, and the payment appears in the next GetNewTransactions(account). A second user to pay to comes from the same endpoint: its IBAN is on its account, and its e-mail and phone aliases are in the creation response.
  • Rate limits are waited out, but a burst slows everything down; keep test runs light, and let one process end before the next starts (the lock makes it wait anyway).
  • nostro's own implementations/main.cpp exercises every call above, and its README lists the commands; its tests (tests/) show each call against the fake, failures included.

Names to get right

Connector::LoadConnectors and SaveConnectors are statics on a struct with nothing else. On BunqConnector: connectorId is "bunq", connectors the static deque, Create and Remove the static constructor and remover, plus EnvironmentOfKey, OAuthAuthorizationUrl, OAuthCodeFromRedirect and OAuthExchangeCode, Get/Post/Put/Delete/List, RefreshSession, RefreshAccounts, GetNewTransactions, TestConnector, Logout, Cards, SetCardStatus, StorageKey, IsOAuth, Endpoint and RedirectTo. On BunqAccount: Send, Draft, Schedule, Request, Requests, IncomingRequests, ScheduledPayments, DraftPayments, IncomingRequest, DraftPayment, RevokeRequest, RespondToRequest, CancelScheduledPayment, RespondToDraftPayment, Path and StorageKey. On Account, the static ForgetTransactions. The warnings: Note and noteSink. Other names:

  • the bunq types: BunqEnvironment, BunqEndpoint, BunqError, BunqCounterparty, BunqLabel, BunqPaymentRequest, BunqIncomingRequest, BunqSchedule, BunqScheduledPayment, BunqDraftPayment, BunqCard;
  • EnabledBanks and tuple_for in :Banks;
  • ParseAmount, FormatAmount, FormatMoney, GetCurrency, GetCurrencyCode, GetCurrencySymbol and GetCurrencyDecimals;
  • in :Utils: ParseTimestamp, FormatTimestamp, ParseLocalDate, ParseLocalDateEnd, FormatLocalTime, UrlEncode, UrlDecode, QueryParameter, Unshown, Blank and EscB;
  • FindTransactions (not Query, Load or List), SaveTransactions and GetLastTransactionTime;
  • TransactionQuery with search, amount, from, to, limit and stored;
  • in Nostro::Crypto: Key, OwnKey, SignBody, VerifyBody, CreateKey (a std::tuple<EVP_PKEY*, std::string>, the public PEM second), LoadKeyFromPem, LoadPublicKeyFromPem, PrivateKeyToPem, PublicKeyToPem, RandomHex and ThrowOnOpenssl;
  • configPath, cachePath, CreatePrivateFile and ReadSecret;
  • for nostrod: Client (System, Attach, Connected, TakeNotes, DefaultCheckoutAccount, SetDefaultCheckoutAccount, and Client::Pending and Client::Then), Answer, DaemonError, DaemonMissing, OutcomeUnknown, ConnectorSummary, AddedConnector, ConnectorAccounts, ConnectorCards, Created, and Bus::busName, Bus::errorBank and the other Bus::error… names.