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.
This commit is contained in:
parent
25d991658f
commit
b43ab124a6
42 changed files with 1234 additions and 994 deletions
|
|
@ -37,7 +37,6 @@
|
|||
"crafter-build --banks=bunq --lib",
|
||||
"crafter-build --banks=bunq --product=daemon",
|
||||
"CPLUS_INCLUDE_PATH=/app/include/c++/v1 crafter-build lint --banks=bunq --product=daemon",
|
||||
"crafter-build --product=checkout",
|
||||
"crafter-build --banks=bunq --product=fake-system",
|
||||
"CPLUS_INCLUDE_PATH=/app/include/c++/v1 crafter-build lint --banks=bunq --product=fake-system",
|
||||
"crafter-build --banks=bunq --product=app",
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ the range.
|
|||
|
||||
The layers are the guide's "Project overview": the library and its
|
||||
connectors, nostrod's front and its workers, the CLI,
|
||||
`Nostro.Checkout`, the toolkit, the app, the window, `project.cpp`, the
|
||||
the toolkit, the app, the window, `project.cpp`, the
|
||||
packaging and the one workflow. Read there, and in design rules 1, 8,
|
||||
11, 12 and 13, what belongs in which before judging where a change
|
||||
sits. The questions this repository adds to the charter's:
|
||||
|
|
@ -27,9 +27,10 @@ sits. The questions this repository adds to the charter's:
|
|||
- Does the window (`Nostro.Ui.Shell`, `implementations/nostro-app.cpp`,
|
||||
`Nostro.DebugCommands`) decide something that design rule 11 wants in
|
||||
the toolkit or the app, as a function a test can call?
|
||||
- Does anything of the library, nostrod, the CLI or `Nostro.Checkout`
|
||||
import or include anything of the app (design rule 13)?
|
||||
- Does anything of the library, nostrod or the CLI import or include
|
||||
anything of the app (design rule 13)?
|
||||
- Does a bank's own code sit where the guide's "Adding a bank" puts it?
|
||||
- Does a link do more than fill in the pay form (design rule 14)?
|
||||
|
||||
Search first:
|
||||
- The partitions' own helpers, which the guide's "Project overview"
|
||||
|
|
|
|||
|
|
@ -22,19 +22,19 @@ the code disagree, the code wins.
|
|||
`implementations/Nostro-Bunq.cpp`. Read there what is sent again and
|
||||
when, what is verified and what is not, and what a failure says about
|
||||
whether a write went through. Then ask, for the path the range
|
||||
touches, what a second sending pays twice. The checkout's record
|
||||
(`PayOrder`) is the same question on disk.
|
||||
touches, what a second sending pays twice.
|
||||
- Money, text and time from outside: amounts (`ParseAmount`,
|
||||
`FormatAmount`; design rule 3), text from the bank or a caller on its
|
||||
way to a dialog, a terminal or a screen (`Shown()`, the toolkit's
|
||||
`:Text` and `:Edit`), JSON from the bank, and days a person typed
|
||||
`:Text` and `:Edit`), a link (`ReadPaymentLink`), JSON from the bank,
|
||||
and days a person typed
|
||||
(`ParseLocalDate`, `ParseLocalDateEnd`). Attack the edges: overflow,
|
||||
a sign, zero, bytes that are not UTF-8, a DST change, a time zone
|
||||
that is not the test's.
|
||||
- Files: `connectors.json` and its lock
|
||||
(`implementations/Nostro-Connector.cpp`), the Crafter.DB tables
|
||||
(`implementations/Nostro-Account.cpp`, and the checkout's in the
|
||||
worker), a state directory an earlier release wrote. What Crafter.DB
|
||||
(`implementations/Nostro-Account.cpp`),
|
||||
a state directory an earlier release wrote. What Crafter.DB
|
||||
does about a second writer, an order, a flush and a migration is its
|
||||
own: read it, do not recall it.
|
||||
- The app (`Nostro.App` on `Nostro.Ui`): state changed by nostrod's
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
## This repository: Nostro
|
||||
|
||||
Nostro holds people's bank keys and moves their money. Its stated
|
||||
security model is `README.md` ("How Nostro runs", "Checkout for apps",
|
||||
security model is `README.md` ("How Nostro runs", "Pay links",
|
||||
"Security"), the contributor guide `AGENTS.template.md` ("nostrod end
|
||||
to end", design rules 4, 9, 10 and 12, "Security considerations";
|
||||
to end", design rules 4, 9, 10, 12 and 14, "Security considerations";
|
||||
`AGENTS.md` is generated from it and is not in the tree) and the files
|
||||
that are the model as shipped:
|
||||
`packaging/system/net.catcrafts.Nostro1.policy` (each polkit action and
|
||||
|
|
@ -26,7 +26,8 @@ unit's hardening and a file's mode.
|
|||
The actors to write down, each with what the model above lets it do: a
|
||||
local user, whom nostrod knows by the uid the bus gives for the caller;
|
||||
any program that user runs, the CLI and the app among them, which
|
||||
neither polkit nor nostrod can tell apart; an app at checkout; the
|
||||
neither polkit nor nostrod can tell apart; whoever wrote a link the app
|
||||
is opened with; the
|
||||
bank; polkit and its agent; an administrator, and root; a build, which
|
||||
runs each dependency's `project.cpp`; the workflow's two jobs.
|
||||
|
||||
|
|
@ -46,10 +47,9 @@ The decision points, each with where to read it:
|
|||
a control or bidirectional character, a line break, a second amount
|
||||
or payee. A detail that can differ from what the call then does is a
|
||||
way past an administrator's rule.
|
||||
- The checkout (`Order::Read`, `ChooseAccount`, `PayOrder`,
|
||||
`ErrorFor`), which the guide states as the exception to design
|
||||
rule 9: what does an app learn that the README's "Checkout for apps"
|
||||
does not already give it?
|
||||
- A link (`ReadPaymentLink`, `App::Open`, `TakeLink`; design rule 14):
|
||||
what does whoever wrote one decide that the pay form does not show
|
||||
the user, and what does it learn back?
|
||||
- Secrets (design rule 4): where a key, a token or the private key is
|
||||
read, kept and passed (`CreatePrivateFile`, `ReadSecret`, a `Secret`
|
||||
field, the sensitive mark on a message), and where one could surface:
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
## 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 three things:
|
||||
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`);
|
||||
- talks to nostrod through `Nostro::Client` (`--lib --banks=bunq --dbus`), as the CLI does;
|
||||
- or, as an app that only needs a customer to pay an order, links the `Nostro.Checkout` module alone (`--product=checkout`), see "Checkout".
|
||||
- or talks to nostrod through `Nostro::Client` (`--lib --banks=bunq --dbus`), as the CLI does.
|
||||
|
||||
Everything is in `namespace Nostro`: the OpenSSL helpers in `Nostro::Crypto`, the D-Bus names and wire in `Nostro::Bus`, the checkout in `Nostro::Checkout`. 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 3.12.0 (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.
|
||||
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. `--product=checkout` instead returns the `nostro-checkout` library alone: the module `Nostro.Checkout`, needing neither `--lib` nor `--banks=`, and linking libsystemd and nothing else of nostro's (no OpenSSL, Crafter.Network or Crafter.DB).
|
||||
- `--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.
|
||||
|
|
@ -26,6 +27,7 @@ Everything is in `namespace Nostro`: the OpenSSL helpers in `Nostro::Crypto`, th
|
|||
- `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
|
||||
|
||||
|
|
@ -68,18 +70,18 @@ nostrod is the system daemon that holds every local user's connectors, in a work
|
|||
- 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::errorNoCheckoutAccount`, `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.
|
||||
- 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.
|
||||
|
||||
### Checkout
|
||||
### Having a customer pay
|
||||
|
||||
An app that only needs a customer to pay an order links `Nostro.Checkout` (`--product=checkout`, `import Nostro.Checkout;`), which has nothing of the library in it. nostrod pays the order from the account the user chose with `nostro checkout account <account>`, once the user has confirmed it at a password prompt that shows the amount, the payee, the reference and that account. The app never names nor sees the account.
|
||||
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:
|
||||
|
||||
- `Nostro::Checkout::Pay(Order{.payeeIban, .payeeName, .amount, .currency = "EUR", .reference}, timeout = 10min)` returns `Paid{paymentId, repeated}`. It blocks until the user has answered: call it off the UI thread. The payee is an IBAN alone, the amount positive minor units, the reference not empty.
|
||||
- An order is paid once: `Pay` again with the same IBAN and reference, after a timeout or a crash, answers with the first payment and `repeated` set, without asking the user, and while the first call is still at the prompt the second waits for it. The same reference with another amount is refused, without a word on which amount the order has. Any app the user runs with access to the checkout can learn this way whether an order was paid, so references should be hard to guess.
|
||||
- It throws `Checkout::Cancelled` (the user did not confirm) and `Checkout::NoCheckoutAccount` (none chosen, or the chosen one is gone), both `Checkout::Error`, which every other refusal is, with the D-Bus `name`: `Checkout::errorInvalidArgument`, `errorBank` (its message is `bunq: ` and what bunq said, without the call it answered, which would name the user's account; it says when it may have paid all the same), `errorFailed` (also for an earlier call whose outcome was lost, which may have paid), `org.freedesktop.DBus.Error.AccessDenied`, and `ServiceUnknown`, which means nostro is not installed. No answer within `timeout` is an `Error` saying the order may have been paid, and asking again is safe. Text that is not UTF-8 is a `std::invalid_argument`; a failure of the bus itself a `std::system_error`.
|
||||
- On the wire it is `net.catcrafts.Nostro1.Checkout`, its own bus name, with one method, `Pay(ssxssa{sv}) -> (ta{sv})`, published as `packaging/dbus/net.catcrafts.Nostro1.Checkout.xml` for apps in other languages. Options and results are dictionaries so they can grow: nostrod ignores options it does not know, and the client skips results it does not know. A Flatpak app asks for `--system-talk-name=net.catcrafts.Nostro1.Checkout`, which reaches nothing else of nostrod: the name is served by a connection of its own.
|
||||
- A payment id is the paying bank's: confirm the money arrived with your own bank.
|
||||
- `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
|
||||
|
||||
|
|
@ -96,7 +98,7 @@ An app that only needs a customer to pay an order links `Nostro.Checkout` (`--pr
|
|||
### 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` or of `Nostro.Checkout` 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, none, slow), giving each connection a uid of the test's choosing. 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`).
|
||||
- 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).
|
||||
|
|
@ -108,10 +110,9 @@ An app that only needs a customer to pay an order links `Nostro.Checkout` (`--pr
|
|||
- 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` and `EscB`;
|
||||
- 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;
|
||||
- for checkout: `Nostro::Checkout::Pay`, `Order`, `Paid`, `Error`, `Cancelled`, `NoCheckoutAccount`, and the module `Nostro.Checkout`, with a dot.
|
||||
- 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.
|
||||
|
|
|
|||
|
|
@ -6,36 +6,34 @@ Guidance for coding agents and contributors working on nostro itself. The [READM
|
|||
|
||||
nostro is a banking client for Linux, phones first: a library that talks to bank APIs directly; nostrod, a system daemon that runs it for every local user behind D-Bus and polkit, so no program of the user's can read the bank's secrets or move money without the user's password; a small CLI that only talks to nostrod; and the app, a window for a phone or a desktop that only talks to nostrod too and does everything the CLI does. Linux phones have no banking apps; nostro is the open-source answer, one connector per bank.
|
||||
|
||||
Five C++26 modules, and a sixth in one build:
|
||||
Four C++26 modules, and a fifth in one build:
|
||||
|
||||
- `Nostro`, the library: twelve partitions behind the umbrella and ten implementation units.
|
||||
- `Nostro.Checkout`, for apps that have nostrod pay an order.
|
||||
- `Nostro.Ui`, the toolkit the app's screens are built with. It imports `std` alone.
|
||||
- `Nostro.App`, the app without its window: what it knows, what is filled in, and its screens.
|
||||
- `Nostro.Ui.Shell`, which puts the toolkit on a display, on Crafter.Graphics and one sd-event loop.
|
||||
- `Nostro.DebugCommands`, what an agent drives the app with: in the app's `--debug-api` build and no other.
|
||||
|
||||
`project.cpp` makes one product per build: the static library `nostro` with the CLI `nostro` (`implementations/main.cpp`), `nostrod` (`--product=daemon`, `implementations/nostrod.cpp`), the app `nostro-app` (`--product=app`, `implementations/nostro-app.cpp`), the static library `nostro-checkout` (`--product=checkout`), or `nostro-fake-system` (`--product=fake-system`, `tests/FakeSystem/main.cpp`), a made-up system to look at the app against. The bunq connector is the only bank so far and the model for the next one. The library depends on Crafter.Network (HTTPS to the bank), Crafter.DB (the local transaction tables and the checkout record), OpenSSL (request signing, response verification), libsystemd (sd-bus and sd-event, for nostrod and its clients) and a vendored nlohmann/json; the app adds Crafter.Graphics (a Wayland window, Vulkan, the input) and two Noto Sans fonts. It ships as two Flatpaks: `net.catcrafts.Nostrod`, that systemd runs nostrod from as the system user `nostro` and that holds the CLI, and `net.catcrafts.Nostro`, the app.
|
||||
`project.cpp` makes one product per build: the static library `nostro` with the CLI `nostro` (`implementations/main.cpp`), `nostrod` (`--product=daemon`, `implementations/nostrod.cpp`), the app `nostro-app` (`--product=app`, `implementations/nostro-app.cpp`), or `nostro-fake-system` (`--product=fake-system`, `tests/FakeSystem/main.cpp`), a made-up system to look at the app against. The bunq connector is the only bank so far and the model for the next one. The library depends on Crafter.Network (HTTPS to the bank), Crafter.DB (the local transaction tables), OpenSSL (request signing, response verification), libsystemd (sd-bus and sd-event, for nostrod and its clients) and a vendored nlohmann/json; the app adds Crafter.Graphics (a Wayland window, Vulkan, the input) and two Noto Sans fonts. It ships as two Flatpaks: `net.catcrafts.Nostrod`, that systemd runs nostrod from as the system user `nostro` and that holds the CLI, and `net.catcrafts.Nostro`, the app.
|
||||
|
||||
| Path | What lives there |
|
||||
|---|---|
|
||||
| `interfaces/Nostro.cppm` | The umbrella: `export import`s every partition; `:Bunq` and `:Crypto` only under their defines, `:Bus`, `:Client` and `:Daemon` only under `NOSTRO_DBUS_ENABLED`. |
|
||||
| `interfaces/Nostro-<Partition>.cppm` | One partition per file, `Nostro:<Partition>`. |
|
||||
| `implementations/Nostro-<Partition>.cpp` | The implementation units, `Nostro:<Partition>_impl`: `Account`, `File` and `Connector` always; `Bunq`, `BunqPayments` (`Nostro-Bunq-Payments.cpp`: counterparties, payments, drafts, requests, schedules) and `Crypto` when their bank is enabled; `Bus`, `Client`, `Daemon` (nostrod's front) and `DaemonWorker` (`Nostro-Daemon-Worker.cpp`: a user's worker, the polkit gate, the checkout) under D-Bus. |
|
||||
| `interfaces/Nostro.Checkout.cppm`, `implementations/Nostro.Checkout.cpp` | The module `Nostro.Checkout`: the checkout's names and wire, and a blocking `Pay` over sd-bus. A module of its own, so `--product=checkout` builds it without the rest. |
|
||||
| `implementations/Nostro-<Partition>.cpp` | The implementation units, `Nostro:<Partition>_impl`: `Account`, `File` and `Connector` always; `Bunq`, `BunqPayments` (`Nostro-Bunq-Payments.cpp`: counterparties, payments, drafts, requests, schedules) and `Crypto` when their bank is enabled; `Bus`, `Client`, `Daemon` (nostrod's front) and `DaemonWorker` (`Nostro-Daemon-Worker.cpp`: a user's worker and the polkit gate) under D-Bus. |
|
||||
| `implementations/main.cpp` | The CLI, a client of nostrod: `argv` parsing (positional arguments, `--name value` options, `--sandbox`), one function per command over `Client`, output through the `std::formatter`s, the notes on stderr, errors caught in `main` and printed with exit status 1. |
|
||||
| `implementations/nostrod.cpp` | nostrod's `main`: `--state`, `--idle`, `--prompt-timeout`, and `--worker <uid> <name>` for the worker processes it starts itself. |
|
||||
| `interfaces/Nostro.Ui.cppm`, `interfaces/Nostro.Ui-<Partition>.cppm`, `implementations/Nostro.Ui-<Partition>.cpp` | The toolkit, `Nostro.Ui`: ten partitions, seven of them with an implementation unit. Ported from imsd-messages (ca5cd72d), which is Catcrafts' and GPL-3.0-only like it. |
|
||||
| `interfaces/Nostro.App.cppm`, `interfaces/Nostro.App-<Partition>.cppm`, `implementations/Nostro.App-<Partition>.cpp` | `Nostro.App`: `:Banks`, `:Format`, `:Forms`, `:Errors` and `:App`. `:App` has three implementation units: `Nostro.App-App.cpp` (state, nostrod's answers, navigation, actions), `Nostro.App-Screens.cpp` (the screens) and `Nostro.App-Bunq.cpp` (bunq's two forms for adding a connection, and what their buttons do). |
|
||||
| `interfaces/Nostro.Ui.Shell.cppm`, `interfaces/Nostro.Ui.Shell-<Partition>.cppm`, `implementations/Nostro.Ui.Shell-<Partition>.cpp` | `Nostro.Ui.Shell`: `:Loop`, `:Canvas`, `:Window` and `:Portal`. The one part that needs a compositor and a graphics device. |
|
||||
| `implementations/nostro-app.cpp` | The app's `main`: the command line, the parts put together, the toolkit's gallery (`--gallery`) and a player of input scripts (`--poke`). |
|
||||
| `implementations/nostro-app.cpp` | The app's `main`: the command line, with the link the desktop starts it with, the parts put together, the toolkit's gallery (`--gallery`) and a player of input scripts (`--poke`). |
|
||||
| `interfaces/Nostro.DebugCommands.cppm`, `implementations/Nostro.DebugCommands.cpp` | The commands, watches, events and checks of the app's `--debug-api` build; see "Looking at the app". |
|
||||
| `assets/` | Noto Sans Regular and Medium with their licence (`OFL.txt`); the app's build puts the fonts beside the executable. |
|
||||
| `project.cpp` | The build description: reads `--banks=`, `--lib`, `--dbus`, `--product=`, `--debug-api`, `--coverage` and `--profile-runtime=`, forwards the other args to the dependencies (with `--no-quic` for Crafter.Network, except in the app's debug build), returns the product. It names each dependency at a commit ("Dev environment"). It also holds what the app is as a Flatpak (`app.flatpak`) and the `fake` run script. |
|
||||
| `packaging/dbus/` | The published D-Bus interfaces, `net.catcrafts.Nostro1.xml` and `net.catcrafts.Nostro1.Checkout.xml`. |
|
||||
| `packaging/dbus/` | The published D-Bus interface, `net.catcrafts.Nostro1.xml`. |
|
||||
| `packaging/system/` | What a Flatpak cannot install: the polkit policy, the D-Bus policy and activation files, `nostrod.service`, the sysusers entry, the `nostro` command, `install.sh` and `uninstall.sh`. |
|
||||
| `.forgejo/workflows/flatpak.yaml` | The one workflow: the tests and both aarch64 Flatpaks for a pull request or a run by hand, and for a signed tag `X.Y.Z` their publication; see "Releasing". |
|
||||
| `packaging/flatpak/`, `packaging/licenses/`, `packaging/arch/` | nostrod's Flatpak manifest (on crafter-build's Flatpak as its base app), each Flatpak's metainfo and `.flatpakref`, the app's desktop entry and icon, the two scripts that cross-build both Flatpaks for aarch64, and `release-version.sh`, which checks what a tree releases; the licence texts the Flatpaks carry, with a `NOTICE` of what each covers; the Arch package of the system files, `nostro-system`. |
|
||||
| `packaging/flatpak/`, `packaging/licenses/`, `packaging/arch/` | nostrod's Flatpak manifest (on crafter-build's Flatpak as its base app), each Flatpak's metainfo and `.flatpakref`, the app's desktop entry (which is also what registers it for `payto` links) and icon, the two scripts that cross-build both Flatpaks for aarch64, and `release-version.sh`, which checks what a tree releases; the licence texts the Flatpaks carry, with a `NOTICE` of what each covers; the Arch package of the system files, `nostro-system`. |
|
||||
| `lib/json.hpp` | nlohmann/json (MIT), included in the global module fragment of `:Bunq` and of the `Connector`, `Bunq` and `BunqPayments` implementation units. Not a release: `single_include/nlohmann/json.hpp` as upstream's `develop` had it at commit `95e9a5931c828cd7306eff36090a5b38e0e3f598` (2026-09-25), which still calls itself 3.12.0, the release of 2025-04-11. It is that file byte for byte, so `git hash-object lib/json.hpp` gives its id there, `4981c3b02e0367e22419b17c37345873d7813076`: keep it so, and name the commit here and in `packaging/licenses/NOTICE` when it is replaced. |
|
||||
| `tests/<Name>/main.cpp`, `tests/Support/`, `tests/FakeSystem/`, `tests/coverage.sh` | The tests, their checks, fake bunq and fake system bus, the made-up system built from those, and the coverage run; see "Testing instructions". |
|
||||
| `docs/screenshots/` | The README's pictures of the app, on a phone's screen and in a desktop window, and `take.sh`, which takes them again on the made-up system; see "Looking at the app". |
|
||||
|
|
@ -43,12 +41,12 @@ Five C++26 modules, and a sixth in one build:
|
|||
| `AGENTS.template.md`, `AGENTS.consumer.md` | The source of this file, and the notes for consumers. `AGENTS.md` is gitignored: edit the template. |
|
||||
| `.review-gates/` | The pre-push review's `config.json` and this repository's lens sections (`lenses/`), read by Crafter.Review. Its `push/` and `trees/` are generated and gitignored. |
|
||||
| `.vscode/` | A build task and an lldb launch configuration, both stale; see "Gotchas". |
|
||||
| `bin/`, `build/` | Generated and gitignored. The library and the CLI are both named `nostro`, so one build leaves two `bin/nostro-<target>-<march>-<mtune>-<hash>/` directories: the library's (`libnostro.a`, the PCMs, `std.pcm`) and the executable's (`nostro`). Glob for the one holding `nostro`. nostrod builds into `bin/nostrod-…/`, the checkout library into `bin/nostro-checkout-…/`, the app into `bin/nostro-app-…/` with its fonts and Crafter.Graphics' shaders beside it (`bin/nostro-app-core-…/` is `Nostro.App`'s library), or under `files/bin/` there when it is packaged as a Flatpak. `build/crafter-debug` is the launcher of Crafter.Debug's client, `build/fake-system/` the state of the made-up system `run fake` starts, `build/flatpak-apps/` what `install` and `bundle` make of the app. |
|
||||
| `bin/`, `build/` | Generated and gitignored. The library and the CLI are both named `nostro`, so one build leaves two `bin/nostro-<target>-<march>-<mtune>-<hash>/` directories: the library's (`libnostro.a`, the PCMs, `std.pcm`) and the executable's (`nostro`). Glob for the one holding `nostro`. nostrod builds into `bin/nostrod-…/`, the app into `bin/nostro-app-…/` with its fonts and Crafter.Graphics' shaders beside it (`bin/nostro-app-core-…/` is `Nostro.App`'s library), or under `files/bin/` there when it is packaged as a Flatpak. `build/crafter-debug` is the launcher of Crafter.Debug's client, `build/fake-system/` the state of the made-up system `run fake` starts, `build/flatpak-apps/` what `install` and `bundle` make of the app. |
|
||||
|
||||
Partitions, from the bottom up (each imports only the ones above it):
|
||||
|
||||
- `:Currency`: `Currency` (an `enum class : std::uint16_t` with `Euro` alone), `GetCurrency` (from `"EUR"` or `"eur"`, throws for anything else), `GetCurrencyCode`, `GetCurrencySymbol`, `GetCurrencyDecimals`, `ParseAmount` (decimal string to minor units), `FormatAmount` (back) and `FormatMoney` (`-€1.02`), all `constexpr`, and `std::formatter<Currency>`, which prints the symbol.
|
||||
- `:Utils`: `ParseTimestamp` and `FormatTimestamp` (bunq's `YYYY-MM-DD HH:MM:SS[.ffffff]`, UTC), `ParseLocalDate`, `ParseLocalDateEnd` and `FormatLocalTime` (dates a person types and reads, local time through `mktime`/`localtime`), `UrlEncode`, `UrlDecode` and `QueryParameter` (for OAuth), `EscB` (JSON string escaping, no longer used by nostro itself), and `Note` with its replaceable `noteSink`, where every warning of the library goes (stderr by default).
|
||||
- `:Utils`: `ParseTimestamp` and `FormatTimestamp` (bunq's `YYYY-MM-DD HH:MM:SS[.ffffff]`, UTC), `ParseLocalDate`, `ParseLocalDateEnd` and `FormatLocalTime` (dates a person types and reads, local time through `mktime`/`localtime`), `UrlEncode`, `UrlDecode` and `QueryParameter` (for OAuth; the app reads a link's options with `UrlDecode` too), `Unshown` and `Blank` (code points that draw nothing or place text, and spaces of any width: the worker's `Shown()` and the app's `ReadPaymentLink` both ask them), `EscB` (JSON string escaping, no longer used by nostro itself), and `Note` with its replaceable `noteSink`, where the library's warnings go (stderr by default).
|
||||
- `:Transaction`: the `Transaction` aggregate, which is also the row type of the Crafter.DB tables: `version = 2` (`id` and `kind` added on 2026-10-31), `orderedBy = &Transaction::timePoint`, `using Previous = TransactionV1` (unexported, kept for the migration), and its `std::formatter` (one tab-separated line).
|
||||
- `:Account`: `TransactionQuery` and `Account` (`name`, `bic`, `iban`, `currency`, `balance` in minor units) with the three methods over the transaction store and the static `ForgetTransactions` (which closes this process's open tables under a storage key before deleting them), and the `std::formatter` for `Account` and everything derived from it. The implementation unit owns the Crafter.DB tables and pins the schema with two `static_assert`s.
|
||||
- `:File`: `GetConfigPath`, `GetCachePath`, the globals `configPath` and `cachePath` they initialise at static-init time, `CreatePrivateFile` (a `0600` file in a `0700` directory), and `ReadSecret` (a line from stdin, not echoed on a terminal).
|
||||
|
|
@ -56,12 +54,10 @@ Partitions, from the bottom up (each imports only the ones above it):
|
|||
- `:Bunq` (under `NOSTRO_BUNQ_ENABLED`; `json.hpp` and `openssl/types.h` in the global module fragment; the implementation units import Crafter.Network): `BunqEnvironment`, `BunqError` (with `maybeCarriedOut`, the end of an error to a write that may have happened all the same), `BunqCounterparty`, the listing types (`BunqLabel`, `BunqPaymentRequest`, `BunqIncomingRequest`, `BunqSchedule`, `BunqScheduledPayment`, `BunqDraftPayment`, `BunqCard`) and their formatters, `BunqAccount : Account` (`id`, `type`, `connector`, the payment calls), `BunqConnector` (environment, keys, tokens, user, `accounts`, the raw `Get`/`Post`/`Put`/`Delete`/`List`, the static deque `connectors`, `Create`, `Remove`, the OAuth helpers, and `Endpoint`/`RedirectTo` with `BunqEndpoint`), `to_json`/`from_json`, and the unexported `BunqJson` helpers both implementation units share.
|
||||
- `:Banks`: `tuple_for<Tuple>(f)` and `EnabledBanks`, the `std::tuple` of enabled connector types; every generic loop in the CLI and in `:Connector` is a `tuple_for<EnabledBanks>`.
|
||||
- `:Connector`: `Connector::SaveConnectors()` and `LoadConnectors()`, `connectors.json` out (synced, then renamed into place) and in, both under the process-wide `connectors.lock`.
|
||||
- `:Bus` (under `NOSTRO_DBUS_ENABLED`; `sd-bus.h` in the global module fragment): the wire nostrod and its clients share. The names, the error names (the checkout's from `Nostro.Checkout`), the polkit actions, the method tables `methods` and `checkoutMethods` (member, signatures, argument names, sensitive), the result structs (`ConnectorSummary`, `AddedConnector`, `ConnectorAccounts`, `ConnectorCards`, `Created`), `Wire<T>` with `Append` and `Read` for every type that travels (a struct as its members, a time as microseconds, a currency as its code, an optional as an array of zero or one), `AppendQuery`/`ReadQuery`, `Vtable`, `ThrowOnSdBus`, and the `BusPtr`/`MessagePtr`/`Error` owners.
|
||||
- `:Bus` (under `NOSTRO_DBUS_ENABLED`; `sd-bus.h` in the global module fragment): the wire nostrod and its clients share. The names, the error names, the polkit actions, the method table `methods` (member, signatures, argument names, sensitive), the result structs (`ConnectorSummary`, `AddedConnector`, `ConnectorAccounts`, `ConnectorCards`, `Created`), `Wire<T>` with `Append` and `Read` for every type that travels (a struct as its members, a time as microseconds, a currency as its code, an optional as an array of zero or one), `AppendQuery`/`ReadQuery`, `Vtable`, `ThrowOnSdBus`, and the `BusPtr`/`MessagePtr`/`Error` owners.
|
||||
- `:Client`: `Client::System()`, one method per method of `net.catcrafts.Nostro1` in a blocking and an asynchronous form (`Attach`, `Client::Pending`, `Answer`), `TakeNotes()`, `DaemonError`, `DaemonMissing` and `OutcomeUnknown`.
|
||||
- `:Daemon`: `DaemonOptions`, `RunDaemon` (the front) and `RunWorker` (one user's worker).
|
||||
|
||||
`Nostro.Checkout`, a module of its own that imports nothing of `Nostro`: the checkout's bus name, interface, `Pay`'s signatures and argument names, the error names apps tell apart, `Order`, `Paid`, `Error` with `Cancelled` and `NoCheckoutAccount`, and `Pay`. `:Bus` and the daemon take their names from it.
|
||||
|
||||
`Nostro.Ui`, in `namespace Nostro::Ui`, draws nothing and reads no device: a screen is a function that fills a `Frame`. Its partitions, from the bottom up:
|
||||
|
||||
- `:Geometry`: `Point`, `Box`, `Insets`, `Color`, `Metrics` (the display's scale, `Dp()`) and `SizeClass`: compact under 600 dp wide, medium under 900, expanded from there. Everything is in physical pixels; dp exists in the design's constants and is turned into pixels where it is used (`frame.Dp()`).
|
||||
|
|
@ -79,7 +75,7 @@ Partitions, from the bottom up (each imports only the ones above it):
|
|||
|
||||
- `:Banks`: what is a bank's own, for each bank the app can connect: `Bank` (what nostrod calls it, its name, its ways in) and `Way` (a way to connect: its title, the form it is filled in on, where what was given is revoked, and whether a connection made that way pays between the user's own accounts only). They are found by nostrod's names for them (`Banks`, `FindBank`, `FindWay`, `BankName`, `WayName`, `OwnAccountsOnly`, `Revoking`); a bank or a way that nostrod has and the app does not know is said by nostrod's name for it. Not the library's `Nostro:Banks`, which is the banks a build has.
|
||||
- `:Format`: how the app words what a bank gives it: `Money` (`€12,500.00`), `GroupIban`, `PartyName`, `DayLabel`, `ShortDate`, `KindLabel`, `StatusLabel`, `CardExpiry`, `ScheduleLabel`, `Fingerprint`. English only; every such wording is here, and none of it names a bank.
|
||||
- `:Forms`: what is typed, read (`ReadAmount`, `ReadParty`, `ReadDay`, `ReadCount`), and the forms with their checks: `PaymentForm`, `RequestForm` and `FilterForm`, which are any bank's, and the two a connection to bunq is made with, `BunqKeyForm` and `BunqOAuthForm`.
|
||||
- `:Forms`: what is typed, read (`ReadAmount`, `ReadParty`, `ReadDay`, `ReadCount`), what a link that asks for a payment is read as or refused for (`ReadPaymentLink`, `PaymentLink`), and the forms with their checks: `PaymentForm`, `RequestForm` and `FilterForm`, which are any bank's, and the two a connection to bunq is made with, `BunqKeyForm` and `BunqOAuthForm`.
|
||||
- `:Errors`: `Operation`, the polkit action of each (`ActionOf`) and whether money leaves an account by it (`MovesMoney`), and `Explain(error, operation)`, which turns an answer's error into `Guidance`. There is no asking whether an operation takes a password: as shipped every one but a reading does.
|
||||
- `:App`: `Host` (what the program around the app gives it), `Loadable<T>`, `Connection`, and the class `App`.
|
||||
|
||||
|
|
@ -101,15 +97,15 @@ The bunq connector end to end:
|
|||
|
||||
nostrod end to end:
|
||||
|
||||
- **The front** (`implementations/Nostro-Daemon.cpp`, `RunDaemon`) is one sd-event loop with two system bus connections. One owns `net.catcrafts.Nostro1` and serves that interface. The other owns `net.catcrafts.Nostro1.Checkout` and serves the checkout alone: a Flatpak allowed to talk to that name can call its owner's unique name too, and on that connection there is nothing else. Every method of both is one forwarding handler. It asks the bus for the caller's uid (`GetConnectionCredentials`), and logind for that uid's name, starts the uid's worker if there is none (`posix_spawn` of `/proc/self/exe --worker <uid> <name> …`, a socketpair end as fd 3, D-Bus peer to peer over it), and passes a copy of the call on, from the caller's unique name and allowing a dialog only when the caller did. The answer is relayed when it comes, so one user's open dialog holds up nobody. A worker that dies under a call is answered `Failed` with "may have been carried out". It holds no connector and no secret. It ends once idle with no worker left, on SIGTERM, or when the bus goes; D-Bus activation starts it again.
|
||||
- **The front** (`implementations/Nostro-Daemon.cpp`, `RunDaemon`) is one sd-event loop with one system bus connection, which owns `net.catcrafts.Nostro1` and serves that interface. Every method is one forwarding handler. It asks the bus for the caller's uid (`GetConnectionCredentials`), and logind for that uid's name, starts the uid's worker if there is none (`posix_spawn` of `/proc/self/exe --worker <uid> <name> …`, a socketpair end as fd 3, D-Bus peer to peer over it), and passes a copy of the call on, from the caller's unique name and allowing a dialog only when the caller did. The answer is relayed when it comes, so one user's open dialog holds up nobody. A worker that dies under a call is answered `Failed` with "may have been carried out". It holds no connector and no secret. It ends once idle with no worker left, on SIGTERM, or when the bus goes; D-Bus activation starts it again.
|
||||
- **A worker** (`implementations/Nostro-Daemon-Worker.cpp`, `RunWorker`) is one user's library: `configPath` and `cachePath` are `<state>/users/<uid>`, and it is not dumpable. A directory records whose it is (`owner`): a uid that logind now names differently, after a user was deleted and another given their uid, is refused.
|
||||
- Every handler reads and checks the call first (the account, the counterparty, what is to be paid, or for a request or a draft the object as bunq has it), builds a `Prompt` (the polkit action, a summary from its own data, and details for polkit rules), and hands it to `Gate`. `Gate` asks polkit asynchronously (`CheckAuthorization` about the caller's bus name, cancelled if it does not answer in time) and runs the call's work only once polkit says yes.
|
||||
- On the main interface nothing of the user's is read, and the bank is asked nothing, for a caller polkit has not said yes to. A call that sees something (`Transactions`, the listings) looks its account up in its work, after the yes. A call that must look something up to word its own question (a payment's account, a card, a request, a draft, a connector) goes through `HandleLookup`: polkit is asked for `View` first, worded as the listing of what is looked up, and the handler's body runs on its yes. So such a call makes two checks, of which the first has no dialog in an active session as shipped; where `View` takes a password it asks twice. The connectors themselves are read (`Load`, which refreshes each one's accounts at the bank) on the first yes, or for the first new order at checkout, and not on the first call.
|
||||
- On the main interface nothing of the user's is read, and the bank is asked nothing, for a caller polkit has not said yes to. A call that sees something (`Transactions`, the listings) looks its account up in its work, after the yes. A call that must look something up to word its own question (a payment's account, a card, a request, a draft, a connector) goes through `HandleLookup`: polkit is asked for `View` first, worded as the listing of what is looked up, and the handler's body runs on its yes. So such a call makes two checks, of which the first has no dialog in an active session as shipped; where `View` takes a password it asks twice. The connectors themselves are read (`Load`, which refreshes each one's accounts at the bank) on the first yes, and not on the first call.
|
||||
- It fails closed: no polkit, an error or a timeout is `AccessDenied`. A dialog the user closed is `Cancelled`, which polkit says with `polkit.dismissed` or, from Plasma's agent, `polkit.result` `auth_…`. A challenge to a call that allowed no dialog is `InteractiveAuthorizationRequired`. Every answer of the main interface ends with the notes.
|
||||
- A summary's text from a caller or the bank goes through `Shown()`: nothing that draws nothing or places text (control and format characters, line and paragraph separators, what Unicode ignores by default, private use), any kind of space as one plain space, `<`, `>` and `&` replaced by `‹`, `›` and `+`, `$(` broken, 64 characters at most. The `&` matters as much as the brackets: GNOME's older agent and MATE's read the message as Pango markup, and show an empty dialog for one with a bare `&`. A summary names the address before the name. An address a caller gives is not made fit but held to it (`Counterparty`): one `Shown()` would change, up to 254 characters, is refused before anyone is asked, since an address shown otherwise than it is could be somebody else's.
|
||||
- The worker ends once idle with no dialog open, on SIGTERM, or when the front goes.
|
||||
- **Checkout** (the same file): `Order::Read` refuses a payee that is not an IBAN, an amount that is not positive, an unknown currency or an empty reference. An order already in `checkouts.cdb` (a Crafter.DB table, `CheckoutRecord`) is answered with its payment, `repeated`, without a dialog, or refused when its amount differs, or when its payment is still 0: a payment whose outcome was lost. An order being paid makes the next call for it wait, and `Settle` gives it the first call's answer. `ChooseAccount` picks the account (the one in `checkout-account`, set by `SetDefaultCheckoutAccount`; an account of an OAuth connector is refused there) and answers through a continuation, so an account picker can take its place later. The dialog (`net.catcrafts.Nostro1.Checkout`) shows the order and that account. `PayOrder` records the order, with no payment, before it pays, and takes the record away again only when bunq refused before doing anything, below 500. An app at checkout is someone else than the user, and is told less: a refusal for another amount does not say which amount the order has, and an error of the connector's reaches it as `bunq: …`, without the call it answered, whose path names the user and the account at bunq (`ErrorFor`). The checkout is also the one place that reads before polkit is asked: an order it knows is answered from its record, and the account that pays a new one is chosen for the dialog to name.
|
||||
- **The client** (`implementations/Nostro-Client.cpp`) allows interactive authorization and waits 10 minutes by default. Each method is one `MethodCall` (member, whether it changes anything, how its answer is read) and one append helper, shared by the blocking form (`Run`: `sd_bus_call`) and the asynchronous one (`Start`: `sd_bus_call_async` on a bus attached to the caller's sd-event loop, whose non-floating slot the returned `Pending` owns; the slot frees what waits for the answer, and `OnReply` reads the answer into an `Answer` and calls `then`, never throwing into sd-bus). nostrod's `InvalidArgument` becomes `std::invalid_argument`, `ServiceUnknown` `DaemonMissing`, a write without an answer, or one bunq answered with an error ending in `BunqError::maybeCarriedOut`, `OutcomeUnknown`, and the rest a `DaemonError` with its name. `Nostro.Checkout`'s `Pay` does the same for the checkout with its own types.
|
||||
- **The account pay links start from** (the same file): `SetDefaultCheckoutAccount` writes the chosen account to `checkout-account`, as its connector's storage key and its id, under the `Connectors` action, and refuses an account of an OAuth connector. `DefaultCheckoutAccount` reads it back under `View`: none when none is chosen, or when the account is gone. The worker does nothing else with it: it is where the app's pay form starts when a link opens it (design rule 14). The two methods and the file are named after the checkout over D-Bus that paid from that account until it was taken out (design rule 10).
|
||||
- **The client** (`implementations/Nostro-Client.cpp`) allows interactive authorization and waits 10 minutes by default. Each method is one `MethodCall` (member, whether it changes anything, how its answer is read) and one append helper, shared by the blocking form (`Run`: `sd_bus_call`) and the asynchronous one (`Start`: `sd_bus_call_async` on a bus attached to the caller's sd-event loop, whose non-floating slot the returned `Pending` owns; the slot frees what waits for the answer, and `OnReply` reads the answer into an `Answer` and calls `then`, never throwing into sd-bus). nostrod's `InvalidArgument` becomes `std::invalid_argument`, `ServiceUnknown` `DaemonMissing`, a write without an answer, or one bunq answered with an error ending in `BunqError::maybeCarriedOut`, `OutcomeUnknown`, and the rest a `DaemonError` with its name.
|
||||
|
||||
The app end to end:
|
||||
|
||||
|
|
@ -124,9 +120,10 @@ The app end to end:
|
|||
- Accounts go to nostrod by IBAN, by name where the bank gave none; a connection by name, or by its number from a fresh `Accounts` listing when two share a name.
|
||||
- Which bank an account is with makes no difference outside the settings. No screen there names a bank, or a way to connect to one, in the app's own words: it says "your bank". `ShouldDriveTheApp` fails on a frame that does, excepting what nostrod and the bank say themselves: a note about a connector, a refusal with the call it refused, a link the bank made. What does differ by bank is asked of `:Banks`: a connection that pays between the user's own accounts only, as bunq's through OAuth, is `Connection::ownAccountsOnly`. It is marked Limited, a payment from it to anyone else is saved as a draft, and it cannot pay a request or a shop.
|
||||
- Adding a connection is three pages, from the settings and from the welcome alike: the banks (`add`), the bank's ways (`add:bunq`) and the way's form (`add:bunq:key`). The first two are built from `:Banks`. The form is the bank's own to draw and to check, in a file of the bank's (`Nostro.App-Bunq.cpp`), and its button ends in `App::Connect`, which is every bank's.
|
||||
- A link fills in the pay form, and does nothing else (design rule 14). `Open(link)` has `ReadPaymentLink` read it: a link that cannot be read gets a sheet with the reason (`…+link`), over wherever the user is. One that can be read is kept apart from the form (`waiting`), with a line on the accounts' page saying that it waits, until the accounts have been read and `DefaultCheckoutAccount` has answered or failed. Then `TakeLink` fills the form in (`PaymentForm::Fill`) and opens it, from that account where one is chosen, else from the first account whose connection pays anybody. With more than one account the form opens under its choice of accounts (`pay+accounts`, `Picking::PayFrom`): a tap beside that sheet or Escape keeps the account the form started from. The form says that a link filled it in (`PaymentForm::linked`, the banner `pay.linked`). A user who is no longer on the accounts' page when the accounts arrive is told that the link was not opened, and keeps their place; with no account to pay from a sheet says so.
|
||||
- **The screens** (`implementations/Nostro.App-Screens.cpp`, and a bank's own forms in that bank's file) are functions from that state to a frame. A window under 600 dp wide shows one page at a time, with the app's places along its bottom; a wider one has them down its left side, and from 900 dp the accounts too. A screen that shows the bank's own state (the accounts, an account, the cards) reads it again four ways, all one action (`Refresher`): Refresh in the bar, F5, Ctrl+R, and the page pulled down at its top.
|
||||
- **The window** (`Nostro.Ui.Shell`) is one sd-event loop that carries the compositor's connection, nostrod's bus, the desktop portal's bus and the timers. `Window` turns Crafter.Graphics' events into the `Context`'s, bringing time up to each and building a stale frame again first, and does what the `Context` wants afterwards (`Settle`, which the loop calls from a post source after every source that ran). A frame is drawn only when the compositor asks for one after something changed, or when it waits for one itself, having asked for another size (`onFrameOwed`): an idle window draws nothing. `Canvas` turns a `DrawList` into Crafter.Graphics' items, one dispatch per batch, from a pool of buffers per frame in flight. `Portal` reads the desktop's colour scheme and accent, and asks the desktop to open an address.
|
||||
- **`nostro-app`** puts them together, and has what looking at the window without a hand on it takes: `--size`, `--scale` (a phone's density on a desktop's display), `--theme`, `--route`, `--screenshot`, `--poke` and `--gallery`. It makes itself undumpable once the portal has seen it. Closing the window while a change is under way takes the window down and keeps the process until the answer has come.
|
||||
- **`nostro-app`** puts them together, and has what looking at the window without a hand on it takes: `--size`, `--scale` (a phone's density on a desktop's display), `--theme`, `--route`, `--screenshot`, `--poke` and `--gallery`. An argument that is no option is a link: it is overwritten in `argv` once it is copied, and handed to `App::Open` when the app has started. It makes itself undumpable once the portal has seen it. Closing the window while a change is under way takes the window down and keeps the process until the answer has come.
|
||||
|
||||
## Dev environment
|
||||
|
||||
|
|
@ -136,7 +133,7 @@ crafter-build is the only build tool. It compiles with its clang 23 and libc++,
|
|||
- Three things still follow a branch, so a build still needs the network. Crafter.Thread comes behind Crafter.Network, whose own project file names it without a commit: pinning it is Crafter.Network's to do. Crafter.Event, Crafter.Math, Crafter.Asset and the Khronos headers come behind Crafter.Graphics in the same way. And the app's `--debug-api` build takes Crafter.Network without a commit, because Crafter.Debug does: with one library named two ways crafter-build stops with "module Crafter.Network is built twice for nostro-app", as tried on 2026-11-19.
|
||||
- The app needs a Wayland compositor and a Vulkan device to run, and nothing else of nostro does. No test opens a window. Until 2026-11-20 `--product=app` took a checkout of Crafter.Graphics to build against (`--graphics=`), for a change that was not on its master yet. The flag is gone: `project.cpp` passes one it is given on to the dependencies like any arg it does not know.
|
||||
- The app's `--debug-api` build links Crafter.Debug, which talks QUIC: that one build has Crafter.Network with msquic (crafter-build builds it with CMake once, for minutes, and keeps it in its cache), and its binaries carry a runpath into that cache.
|
||||
- Where the connectors live depends on who runs the library. nostrod's worker keeps each user's under `<state>/users/<uid>/`: `connectors.json`, the transaction tables, `checkouts.cdb`, `checkout-account` and `owner`, with `<state>` from `--state`, else `$XDG_DATA_HOME`, else `$HOME/.local/share`. Installed, that is `/var/lib/nostro/.var/app/net.catcrafts.Nostrod/data/`, readable by the user `nostro` alone. The library used directly reads `connectors.json` from `$XDG_CONFIG_HOME/.config/nostro/` (sic, see "Gotchas") or `$HOME/.config/nostro/`, and keeps the transaction tables under `$XDG_CACHE_HOME/nostro/transactions/` or `$HOME/.cache/nostro/transactions/`. A real connectors file holds a real API key: point every experiment elsewhere.
|
||||
- Where the connectors live depends on who runs the library. nostrod's worker keeps each user's under `<state>/users/<uid>/`: `connectors.json`, the transaction tables, `checkout-account` and `owner`, with `<state>` from `--state`, else `$XDG_DATA_HOME`, else `$HOME/.local/share`. Installed, that is `/var/lib/nostro/.var/app/net.catcrafts.Nostrod/data/`, readable by the user `nostro` alone. The library used directly reads `connectors.json` from `$XDG_CONFIG_HOME/.config/nostro/` (sic, see "Gotchas") or `$HOME/.config/nostro/`, and keeps the transaction tables under `$XDG_CACHE_HOME/nostro/transactions/` or `$HOME/.cache/nostro/transactions/`. A real connectors file holds a real API key: point every experiment elsewhere.
|
||||
- No test uses the system bus: they run on `tests/Support/FakeBus.inc`. Running anything by hand that talks to `net.catcrafts.Nostro1` reaches the installed nostrod, if there is one, and its dialogs: the CLI, and the app, which reads the accounts as soon as it starts. A Flatpak sandbox with the system bus (`flatpak run`) sets `DBUS_SYSTEM_BUS_ADDRESS` itself, over an `--env` of yours: keep a sandboxed experiment off the bus with `--nosocket=system-bus`. To look at the app, run it on the made-up system, `nostro-fake-system`, which sets that address for what it starts ("Looking at the app").
|
||||
- To read a `constexpr` value such as `DB::Layout<Transaction>::fingerprint`, `static_assert(x == 0)` it and read "expression evaluates to" in the error.
|
||||
|
||||
|
|
@ -145,7 +142,6 @@ crafter-build is the only build tool. It compiles with its clang 23 and libc++,
|
|||
```bash
|
||||
crafter-build --banks=bunq # the library, then the CLI: bin/nostro-<variant>/nostro
|
||||
crafter-build --banks=bunq --product=daemon # nostrod: bin/nostrod-<variant>/nostrod
|
||||
crafter-build --product=checkout # the Nostro.Checkout library alone; no bank needed
|
||||
crafter-build --banks=bunq --lib # the library alone (what a consumer builds), without D-Bus
|
||||
crafter-build --banks=bunq --lib --dbus # the library with :Bus, :Client and :Daemon
|
||||
crafter-build --banks=bunq --product=app # the app: bin/nostro-app-<variant>/nostro-app
|
||||
|
|
@ -165,7 +161,7 @@ crafter-build --banks=bunq --product=app --packaging=flatpak --march=x86-64-v3 -
|
|||
packaging/flatpak/make-aarch64-sysroot.sh && packaging/flatpak/build-aarch64.sh <repo> # both Flatpaks for aarch64, into a repository
|
||||
```
|
||||
|
||||
`--banks=` is mandatory except for `--product=checkout`: without it `project.cpp` throws "must enable atleast one bank" and nothing is built; an unknown name throws "unknown connector", an unknown product "unknown product". flatpak-builder needs crafter-build's own Flatpak (`net.catcrafts.CrafterBuild`, stable) installed as its base app, the network during the build, and, run as a Flatpak itself, `--filesystem=` for a build directory outside your home, or the build commands cannot find it. Install the result for a test with `sudo packaging/system/install.sh --repo <dir>/repo`. CI is `.forgejo/workflows/flatpak.yaml` ("Releasing" below): it runs for a pull request, by hand and for a release's tag, so a plain push is tested by nobody but whoever pushed it. The tests run every line, function and region of the library, the CLI, nostrod, the toolkit and the app without its window (2026-11-19), and a change keeps them doing so; the README's rule for contributed connectors applies on top: not blind, also tried against the sandbox or the live API ("Testing instructions").
|
||||
`--banks=` is mandatory: without it `project.cpp` throws "must enable atleast one bank" and nothing is built; an unknown name throws "unknown connector", an unknown product "unknown product". flatpak-builder needs crafter-build's own Flatpak (`net.catcrafts.CrafterBuild`, stable) installed as its base app, the network during the build, and, run as a Flatpak itself, `--filesystem=` for a build directory outside your home, or the build commands cannot find it. Install the result for a test with `sudo packaging/system/install.sh --repo <dir>/repo`. CI is `.forgejo/workflows/flatpak.yaml` ("Releasing" below): it runs for a pull request, by hand and for a release's tag, so a plain push is tested by nobody but whoever pushed it. The tests run every line, function and region of the library, the CLI, nostrod, the toolkit and the app without its window (2026-11-19), and a change keeps them doing so; the README's rule for contributed connectors applies on top: not blind, also tried against the sandbox or the live API ("Testing instructions").
|
||||
|
||||
The app's packaging: `--packaging=flatpak` makes `bin/nostro-app-<variant>/files/` (the program with its fonts and shaders in `bin/`, the C++ runtime in `lib/`, the desktop entry, icon, metainfo and licences in `share/`), `bundle` a `.flatpak` beside it and `install` an installation for the user who runs it; both print the permissions, which `project.cpp` lists. That is x86_64, on the Platform crafter-build's Flatpak runs on. For aarch64, a phone, there is no crafter-build to build with, so both Flatpaks are cross builds: `make-aarch64-sysroot.sh` makes a sysroot of the Freedesktop Sdk for aarch64 with LLVM's libc++ (in `~/.cache/nostro-flatpak`, or `$NOSTRO_FLATPAK_CACHE`), and `build-aarch64.sh <repo>` builds the CLI, nostrod and the app against it and assembles `net.catcrafts.Nostrod` and `net.catcrafts.Nostro` into an OSTree repository, which `install.sh --repo <repo> --app` installs on the phone. The app's permissions are in two places because of it, `project.cpp` and that script: change them together.
|
||||
|
||||
|
|
@ -200,7 +196,7 @@ Only aarch64 is published, a phone's architecture. An x86_64 machine builds its
|
|||
| `ShouldTalkToBunq` | the connector: every user type, signatures, rate limits, session renewal, errors, accounts, the sync, cards, OAuth, old connectors |
|
||||
| `ShouldMoveMoney` | payments, drafts, schedules and requests, and their formatters |
|
||||
| `ShouldRunCommands` | the CLI: `implementations/main.cpp` compiled in with its `main` renamed, every command run in-process against a real nostrod on the fake bus |
|
||||
| `ShouldServeEveryUser` | nostrod: users kept apart, a uid handed to a new user, every polkit answer and what each dialog says, what a dialog is kept free of and which addresses are refused for it, that a caller polkit refuses is told nothing of what is there and has the bank asked nothing, calls that wait on each other or do not, the checkout and its retries, the checkout client, workers that die, idle exits, every error as the client gets it, and the published contract (the XML, and the polkit policy with its defaults: only seeing passes without a password) |
|
||||
| `ShouldServeEveryUser` | nostrod: users kept apart, a uid handed to a new user, every polkit answer and what each dialog says, what a dialog is kept free of and which addresses are refused for it, that a caller polkit refuses is told nothing of what is there and has the bank asked nothing, that a dialog left open holds up no other call, the account pay links start from, workers that die, idle exits, every error as the client gets it, and the published contract (the XML, and the polkit policy with its defaults: only seeing passes without a password) |
|
||||
| `ShouldAnswerAsynchronously` | the client's asynchronous calls from an sd-event loop: each method once against a real nostrod on the fake bus, every way an answer fails (refused, cancelled, bunq's refusal, a 5xx to a payment, no answer in time, no nostrod, an answer that cannot be read), notes in the answer, and dropping, cancelling, moving and assigning a `Pending` |
|
||||
| `ShouldWrapText` | `Nostro.Ui:Text`: UTF-8, measuring, cutting with an ellipsis, wrapping and its cache |
|
||||
| `ShouldEditText` | `:Edit`: typing, the cursor and the selection, each kind of field and what it refuses, the composing text, a secret wiped |
|
||||
|
|
@ -243,9 +239,10 @@ What a test cannot show (that the window draws what the frame says, in the right
|
|||
- Without a hand on it: `nostro-app --size 420x760 --theme light --route account:<IBAN> --poke "wait:2500;tap:110,200;shot:<file.png>"` plays input into the window library's own events, so the window's listeners run as for a real pointer, and writes screenshots. Steps are separated by `;` and positions are in dp: `tap:x,y`, `hold:x,y,ms`, `drag:x1,y1,x2,y2,ms`, `move:x,y`, `press:x,y` and `release` (a finger kept down between them), `right:x,y`, `wheel:x,y,detents`, `key:Name`, `text:…`, `preedit:…`, `delete:before,after`, `resize:w,h`, `wait:ms`, `shot:file`. `--scale 3 --size 360x760` draws a phone's screen on a desktop's display. `--gallery widgets|list|text` shows the toolkit's widgets in the app's place and asks nostrod nothing. The player stamps what it plays with the host's clock, and what a real pointer sends carries the compositor's: a pointer that crosses the window while a script runs can make the script's taps miss, as one did on 2026-11-20, so keep it off the window, and read a run that went wrong for a `wl_pointer.enter` (`WAYLAND_DEBUG=1`).
|
||||
- With an agent's hand on it: the `--debug-api` build and `./build/crafter-debug` (the Crafter.Debug notes at the end of this file). `crafter-build … --debug-api run fake [the fake system's options] [-- the app's options]` starts the app on the fake system, in the background since it does not exit. Then:
|
||||
- `get app.screen`, `get ui.texts` (every line the screen shows), `get ui.regions` (what can be pressed, by key, in dp), `get 'window.*'`;
|
||||
- `call Ui_Tap key=account.pay`, `Ui_Type text=…` into the field that has the focus, `Ui_Key key=Tab`, `Ui_LongPress`, `Ui_Focus`, `Ui_TapAt`, `Ui_Drag`, `Ui_Wheel`, `App_Navigate route=cards`, `Ui_Theme scheme=dark`, `Window_Resize width= height=`;
|
||||
- `call Ui_Tap key=account.pay`, `Ui_Type text=…` into the field that has the focus, `Ui_Key key=Tab`, `Ui_LongPress`, `Ui_Focus`, `Ui_TapAt`, `Ui_Drag`, `Ui_Wheel`, `App_Navigate route=cards`, `App_Open link=payto://iban/…`, `Ui_Theme scheme=dark`, `Window_Resize width= height=`;
|
||||
- `wait 'app.busy == false'` after anything that asks nostrod, `wait 'app.changing == false'` after a change; the events are `Screen`, `AnswerArrived`, `Changing` and `FrameRendered`;
|
||||
- `screenshot`, and `log --level warn` for the checks: a frame that overflowed the window's buffers, something pressable under 48 dp on a phone's size.
|
||||
- A link is looked at by starting the app with one, after `--` like the app's options: `… run fake -- --size 420x760 'payto://iban/NL36BUNQ2100000044?amount=EUR:12.50&receiver-name=Swift%20Cycles&message=Order%201234'`, whose IBAN is an account at the made-up bank. `get app.screen` is then `pay+accounts`.
|
||||
- The README's screenshots are taken that way too, on the made-up system so that nobody's bank is in them: `docs/screenshots/take.sh <nostro-fake-system> <nostro-app>` plays one `--poke` script per picture and writes the five files beside itself. It names what it taps by its place, so it is looked over, picture by picture, after a change to a screen it shows. The made-up bank dates its payments back from now: every taking has other days and times in it. Four of the five are in the dark look and one in the light one, and everything the made-up bank holds is in English, people's names too, as the app is: both as asked for on 2026-11-19, so new made-up data is written in English.
|
||||
- A region's key is its name in the tests too: `nav.accounts`, `account.<IBAN>`, `account.pay`, `tabs.1`, `pay.to`, `pay.submit`, `request.submit`, `confirm.yes`, `done.close`, `card.<id>`, `settings.connections`, `connections.add`, `bank.bunq`, `way.key`, and `copy.<label>` for a line of a sheet (`copy.IBAN`), which a press copies. `get ui.regions` lists a screen's.
|
||||
|
||||
|
|
@ -255,7 +252,7 @@ What a test cannot show (that the window draws what the frame says, in the right
|
|||
- The first two lines of every source are `// SPDX-License-Identifier: LGPL-3.0-only`, or `GPL-3.0-only` in a source of the app (design rule 13 says which is which), and `// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®`, then a blank line. `project.cpp` carries them too.
|
||||
- Four-space indentation, LF, K&R braces with `} else {`, one declaration per statement. `if(`, `for(`, `while(`, `switch(` without a space in most files (`:Utils` has the space; match the file). Lines run long rather than wrap.
|
||||
- `import std;` everywhere; `#include`s only in a global module fragment (`module;` first), and only for OpenSSL, the vendored `json.hpp`, sd-bus and sd-event, and the POSIX calls of `:File`, `:Connector` and nostrod. `namespace fs = std::filesystem;` where paths appear.
|
||||
- Interfaces are `export module Nostro:<P>;` with `export namespace Nostro { … }` when the partition is free functions (`:Currency`, `:Utils`, `:File`, `:Crypto`) and `namespace Nostro { export struct … }` when it is types. A `std::formatter` specialisation sits after the namespace, unexported, which importers still find. Implementation units are `module Nostro:<P>_impl;` followed by `import :<P>;`. `Nostro.Checkout` is a module of its own (`export module Nostro.Checkout;`, implemented in `module Nostro.Checkout;`) because a shop app links it without the rest. The app's modules follow the same shape (`export module Nostro.Ui:<P>;`, `module Nostro.Ui:<P>_impl;`), with definitions in implementation units.
|
||||
- Interfaces are `export module Nostro:<P>;` with `export namespace Nostro { … }` when the partition is free functions (`:Currency`, `:Utils`, `:File`, and `:Crypto` with `Nostro::Crypto`) and `namespace Nostro { export struct … }` when it is types. A `std::formatter` specialisation sits after the namespace, unexported, which importers still find. Implementation units are `module Nostro:<P>_impl;` followed by `import :<P>;`. The app's modules follow the same shape (`export module Nostro.Ui:<P>;`, `module Nostro.Ui:<P>_impl;`), with definitions in implementation units.
|
||||
- In the toolkit and the app: geometry is in physical pixels, and a size of the design is a dp constant turned into pixels where it is used (`frame.Dp(Size::gutter)`). A widget is a function that draws into a frame and names its regions; it keeps nothing. A region's key names it across frames, for the focus, a press, a test and a debugger: a row of a list has what it is about in its key, never its place. A press acts on a frame that is still true: whoever changes what the screens are built from calls `Context::Invalidate`.
|
||||
- In the window (`Nostro.Ui.Shell`): everything sd-event or libwayland calls back runs under `Loop::Guard`, for the same reason. What cannot be done inside a listener waits for the loop (`Defer`): reading the clipboard, taking the window down.
|
||||
- An sd-bus callback returns 0 or more and never throws: a negative result closes the connection it came on, and an exception would unwind through C. Every worker handler catches everything (`Handle`) and answers with an error instead.
|
||||
|
|
@ -274,13 +271,17 @@ What a test cannot show (that the window draws what the frame says, in the right
|
|||
6. **Synchronous HTTPS, one client per bank host.** `ClientHTTP1::Send` on the calling thread, a persistent connection for reads and a fresh one for every write, no thread pool, default TLS verification. A bank's own request function owns the protocol: signing, verifying, waiting out rate limits and renewing an expired session once. Every other error is an exception; whether to retry a write is the caller's decision, and an unknown outcome is reported as such. (Revised 2026-10-31: the retries moved from the transaction sync into the request function.)
|
||||
7. **Signing is opt-in per bank.** `:Crypto` and `-lssl -lcrypto` are pulled in by `opensslEnabled`, the OR of the banks that sign; a bank that does not sign must not make the build depend on OpenSSL.
|
||||
8. **The library is the product; the CLI and the app are thin clients.** `--lib` returns the library configuration; the CLI adds `main.cpp` alone, which parses `argv`, calls nostrod through `Client` and prints through the formatters, and nostrod adds `nostrod.cpp` alone. Logic goes into a partition (the daemon's into `:Daemon`), not into `main.cpp`. What the CLI and the app both need is the library's, not written twice: reading the address an OAuth redirect lands on, the end of a day a person typed, a card's status as bunq kept it (the check; what the app then says it words itself, in no bank's name). The app decides nothing nostrod should: what an account, a payee or an amount may be is nostrod's to refuse, and the app's own checks only spare the user a round trip. (Revised 2026-11-01: the CLI talks to nostrod, not to the bank. Revised 2026-11-19 for the app.)
|
||||
9. **nostrod answers each caller for their own money, and asks polkit first.** The front maps a caller's uid, asked of the bus, to that uid's own worker process; nothing of one user's is ever in another's process. Every method has one polkit action, decided by what the call does (`View`, `Change`, `Pay`, `UnfreezeCard`, `BlockCard`, `Connectors`, `Checkout`), and the dialog's summary and details are built from the worker's own data after the call is read and checked, never from text the caller formatted: what the dialog shows is what gets paid. Before polkit's yes a worker reads nothing of the user's for the caller and asks the bank nothing: a call that has to look something up to word its question needs `View` first (`HandleLookup`), so it has two actions, and a caller who may not see the accounts cannot find out what is there, or have the bank asked, by trying to change it. The checkout, whose caller is an app, is the stated exception (see "Checkout" above). Every action is owned by `unix-user:nostro` in the policy, or polkit refuses nostrod's checks. Every method is `SD_BUS_VTABLE_UNPRIVILEGED`, since polkit decides, not sd-bus. It fails closed. Secure by default: as shipped only `View` passes without the user's password in an active session, and every other action asks for it every time (`auth_self`), `Change` too, down to a draft saved and a card frozen. That was decided on 2026-11-19; until then `Change` passed, on the reasoning that it pays nobody, which left any program of the user's free to cancel a scheduled payment or ask for money in their name. Loosening is an administrator's choice, made with a rule, and `ShouldServeEveryUser` holds the policy file to these defaults. No action keeps an authorization: polkit keeps one per process, so the CLI would ask every time anyway, and the app, which lives for hours, would not: an administrator's rule that keeps one (`auth_self_keep`) lets a running app pay for minutes without a password, and polkit's manual says a kept one holds whatever the next check's details are.
|
||||
10. **The wire is a published contract.** `packaging/dbus/*.xml` is what nostrod serves (`ShouldServeEveryUser` compares them with its introspection), and apps in other languages generate their proxies from it. A method may be added; changing a method's signature or meaning means a new interface (`…Nostro2`). The checkout's `options` and `results` are dictionaries so that it can grow without one: unknown options are ignored, unknown results skipped. So is the query of `Transactions`: `stored` was added to it on 2026-11-19, and a nostrod from before ignores it and asks the bank, which is slower and no less right. A client must not lean on a new key for anything but speed. One meaning was narrowed all the same, on 2026-11-19, while no release had been published: `AddBunq`'s `environment` used to choose the environment over what the key says, and now only has a key of the other one refused. Four more were that day, after a security review and for the same reason: an e-mail address that the password dialog could not show as it is (`to`, `from`) is refused; a call that names an account, a card, a request, a draft or a connector, and is not a call to see it, needs `View` as well as its own action; the checkout's errors say less (no amount of the order on record, no call to the bank); and the policy has `Change` ask for the password in an active session, as every action but `View` does. After a release each would have been `…Nostro2`'s to do, or for the policy a change of defaults under users who had come to rely on the old ones.
|
||||
9. **nostrod answers each caller for their own money, and asks polkit first.** The front maps a caller's uid, asked of the bus, to that uid's own worker process; nothing of one user's is ever in another's process. Every method has its polkit action, decided by what the call does (`View`, `Change`, `Pay`, `UnfreezeCard`, `BlockCard`, `Connectors`), and the dialog's summary and details are built from the worker's own data after the call is read and checked, never from text the caller formatted: what the dialog shows is what gets paid. Before polkit's yes a worker reads nothing of the user's for the caller and asks the bank nothing: a call that has to look something up to word its question needs `View` first (`HandleLookup`), so it has two actions, and a caller who may not see the accounts cannot find out what is there, or have the bank asked, by trying to change it. Every action is owned by `unix-user:nostro` in the policy, or polkit refuses nostrod's checks. Every method is `SD_BUS_VTABLE_UNPRIVILEGED`, since polkit decides, not sd-bus. It fails closed. Secure by default: as shipped only `View` passes without the user's password in an active session, and every other action asks for it every time (`auth_self`), `Change` too, down to a draft saved and a card frozen. That was decided on 2026-11-19; until then `Change` passed, on the reasoning that it pays nobody, which left any program of the user's free to cancel a scheduled payment or ask for money in their name. Loosening is an administrator's choice, made with a rule, and `ShouldServeEveryUser` holds the policy file to these defaults. No action keeps an authorization: polkit keeps one per process, so the CLI would ask every time anyway, and the app, which lives for hours, would not: an administrator's rule that keeps one (`auth_self_keep`) lets a running app pay for minutes without a password, and polkit's manual says a kept one holds whatever the next check's details are.
|
||||
10. **The wire is a published contract.** `packaging/dbus/net.catcrafts.Nostro1.xml` is what nostrod serves (`ShouldServeEveryUser` compares it with nostrod's introspection). A method may be added; changing a method's signature or meaning means a new interface (`…Nostro2`). The query of `Transactions` is a dictionary so that it can grow without one: `stored` was added to it on 2026-11-19, and a nostrod from before ignores it and asks the bank, which is slower and no less right. A client must not lean on a new key for anything but speed. One meaning was narrowed all the same, on 2026-11-19, while no release had been published: `AddBunq`'s `environment` used to choose the environment over what the key says, and now only has a key of the other one refused. Four more were that day, after a security review and for the same reason: an e-mail address that the password dialog could not show as it is (`to`, `from`) is refused; a call that names an account, a card, a request, a draft or a connector, and is not a call to see it, needs `View` as well as its own action; the errors of the checkout there was then said less (no amount of the order on record, no call to the bank); and the policy has `Change` ask for the password in an active session, as every action but `View` does. After a release each would have been `…Nostro2`'s to do, or for the policy a change of defaults under users who had come to rely on the old ones.
|
||||
|
||||
One interface was taken away after a release, on 2026-11-22 and by the owner's decision: the checkout over D-Bus that 0.0.0 has, `net.catcrafts.Nostro1.Checkout` with its method `Pay`, its bus name, the polkit action `Checkout` and the module `Nostro.Checkout`. A shop is paid through a link instead (rule 14). `DefaultCheckoutAccount` and `SetDefaultCheckoutAccount` kept their names and signatures: the account they keep is where the app's pay form starts for a link. `packaging/system/net.catcrafts.Nostro1.conf` still lets nostrod own the old name, which the nostrod of 0.0.0 asks for when it starts, and `install.sh` removes that name's activation file.
|
||||
|
||||
11. **The app's logic is pure, and its window is thin.** `Nostro.Ui` and `Nostro.App` import no window library and read no device: a screen is a function from state to a frame, so a test builds it, reads what it says and taps it by name, and both stay at the coverage the library has. `Nostro.Ui.Shell`, `nostro-app.cpp` and the debug commands are the only code that needs a compositor. They decide nothing about money, are checked by looking ("Looking at the app"), and are outside the coverage figure. What would need a decision there goes into the toolkit or the app as a function a test can call. Crafter.Debug stays in the executable: `Debug::Use` reaches that configuration alone, and the window and the app only offer hooks.
|
||||
12. **The app holds no secret and no say.** It has no key, no token and no file of its own, and its Flatpak no network. A key typed into it lives in a `Secret` field, which is drawn as dots, shown otherwise only as a fingerprint (`Fingerprint`: how it begins and how long it is, and never how it ends, since the end of a key being typed by hand is what was typed last), never copied, and wiped when the form goes; it is passed to nostrod once, in a message marked sensitive. What moves money is confirmed in polkit's dialog, which nostrod words from its own data, and nowhere else: the pay form's button sends, and a program that drove the window would still meet the dialog. So what stands between a press and a payment is the system's policy for the `Pay` action, which asks for the password every time as shipped, as the policy for every other action but `View` does. Under an administrator's rule that answers it without asking, one press on Pay pays.
|
||||
|
||||
13. **The library is LGPL, the app is GPL.** LGPL-3.0-only: the module `Nostro`, `Nostro.Checkout`, the CLI, nostrod, their tests, the tests' fakes and the fake system, `project.cpp` and the packaging. A program under any licence can be built on the library and the checkout. GPL-3.0-only: `Nostro.Ui`, `Nostro.App`, `Nostro.Ui.Shell`, `nostro-app.cpp`, `Nostro.DebugCommands`, their seven tests and `tests/Support/Ui.inc`, the app's desktop entry and icon, and `docs/screenshots/`, the pictures of the app and the script that takes them: a program built from any of it is under the GPL as a whole. A new file gets the licence of what it is part of, in its first line. The dependency runs one way, and has to: nothing of the library imports or includes anything of the app, or the library could no longer be used under the LGPL. Code moves from the library into the app as it is; the other way it changes licence, which is Catcrafts' to decide for what Catcrafts wrote, and the author's for a patch that came in under the GPL alone. (Decided 2026-11-19.)
|
||||
13. **The library is LGPL, the app is GPL.** LGPL-3.0-only: the module `Nostro`, the CLI, nostrod, their tests, the tests' fakes and the fake system, `project.cpp` and the packaging. A program under any licence can be built on the library. GPL-3.0-only: `Nostro.Ui`, `Nostro.App`, `Nostro.Ui.Shell`, `nostro-app.cpp`, `Nostro.DebugCommands`, their seven tests and `tests/Support/Ui.inc`, the app's desktop entry and icon, and `docs/screenshots/`, the pictures of the app and the script that takes them: a program built from any of it is under the GPL as a whole. A new file gets the licence of what it is part of, in its first line. The dependency runs one way, and has to: nothing of the library imports or includes anything of the app, or the library could no longer be used under the LGPL. Code moves from the library into the app as it is; the other way it changes licence, which is Catcrafts' to decide for what Catcrafts wrote, and the author's for a patch that came in under the GPL alone. (Decided 2026-11-19.)
|
||||
|
||||
14. **A link fills in a form, and nothing more.** A website or an app can have the desktop open the app with a `payto://iban/…` link (RFC 8905), and whoever wrote the link chose every character of it. So it is read by one function, `ReadPaymentLink`, which refuses a link rather than guess at it: a name or a description with a code point that is `Unshown`, or `Blank` and no plain space, is refused among the rest. A refusal is in the app's own words, with nothing of the link in them. What is read becomes the pay form filled in, and from there rule 12 holds: the form's button sends, polkit's dialog confirms, and the app asks nothing of its own in between. A link pays nothing by itself: no payment is sent before the form's button is pressed. What the app does ask, where the user has more than one account, is which of them pays: the form opens under its choice of accounts, on the account `DefaultCheckoutAccount` gives where the user chose one. Outside the `--debug-api` build a link reaches the app only as an argument of a new process, so it cannot change a form in a window that is open. The format is a published contract as the wire is (rule 10), written down in `AGENTS.consumer.md` ("Having a customer pay"): an option may be added, since unknown ones are passed over, and what a link means does not change. The owner's decisions: the scheme is `payto` alone, with none of the app's own (2026-11-21); and the form starts from the account chosen in the settings, with the app asking which account pays (2026-11-22). Two departures from RFC 8905 are deliberate: a comma in an amount is refused, where the RFC has a reader pass over it, and a `+` in an option's value is read as a space, as a browser's form encoding writes one, where the RFC has it stand for itself.
|
||||
|
||||
## Adding a bank
|
||||
|
||||
|
|
@ -295,12 +296,13 @@ The checklist, from the bunq connector:
|
|||
## Commit and PR guidelines
|
||||
|
||||
- Patches go by mail to jorijnvdgraaf@catcrafts.net, as the README says. Branch off `master`.
|
||||
- Take the commit voice from the sibling Crafter repositories: `type(scope): imperative summary` with `feat`, `fix`, `refactor`, `docs` or `build`, and the partition or the CLI as the scope (`bunq`, `account`, `currency`, `connector`, `file`, `bus`, `client`, `daemon`, `checkout`, `cli`, `ui`, `app`, `shell`, `debug`, `build`, `packaging`). The body says what was wrong, why, and how it was verified against the sandbox.
|
||||
- Take the commit voice from the sibling Crafter repositories: `type(scope): imperative summary` with `feat`, `fix`, `refactor`, `docs` or `build`, and the partition or the CLI as the scope (`bunq`, `account`, `currency`, `connector`, `file`, `bus`, `client`, `daemon`, `cli`, `ui`, `app`, `shell`, `debug`, `build`, `packaging`). The body says what was wrong, why, and how it was verified against the sandbox.
|
||||
- The README is the manual, and is kept short: keep its CLI section true to `main.cpp` and what it says of the app true to the screens, and give a new feature a line there, or none. What a standard says is linked, not retold. How a screen works goes into this guide, what a caller needs into `AGENTS.consumer.md`, and what an administrator needs into the comment of `packaging/system/net.catcrafts.Nostro1.policy`. Update `AGENTS.consumer.md` in the same change when a signature, a path, a default, a file format or an error behaviour consumers lean on changes; consumers pick it up on their next build.
|
||||
- A change to how the app looks or is laid out says in its commit how it was looked at: which screens, at which sizes, on what. When it changes a screen the README shows, the pictures are taken again (`docs/screenshots/take.sh`) in the same commit.
|
||||
- The app's version is `NOSTRO_VERSION` in `project.cpp`, and the newest release in `packaging/flatpak/net.catcrafts.Nostro.metainfo.xml` is the same: `packaging/flatpak/release-version.sh` fails on a tree where they differ, and CI runs it first.
|
||||
- A change to `Transaction` is a schema change (design rule 5), and the commit message says so.
|
||||
- A change to the D-Bus interfaces or the polkit policy changes the published contract (design rule 10); the XML, the policy and the test that holds them change together.
|
||||
- A change to what the Arch package installs, the files `packaging/arch/PKGBUILD` names, raises its `pkgrel`: where `makepkg -si` finds a package of that version already built (beside the `PKGBUILD`, unless `PKGDEST` names another place), it installs that one again and builds nothing.
|
||||
- A change that moves code between the library and the app moves it between two licences (design rule 13), and its commit message says so.
|
||||
- Every push of new commits to `master` goes through Crafter.Review's pre-push review first, and goes out only once the owner approves the frozen hash. Run `crafter-review init` once in a fresh checkout or worktree: it writes the `/prepush` skill that drives the review, and the skill stays untracked. The lenses it runs are the approach, the bug-prover, the security lens and the commit truth, each with this repository's own section (`.review-gates/lenses/`): a lesson of a review that is nostro's goes into the section of the lens that should have caught it. CI does not run for a plain push, so the review's gate0, the commands in `.review-gates/config.json`, is the check before one: the version check, the tests, a build of each product, and the five lint runs "Code style" names.
|
||||
- Every commit of a pushed range is GPG-signed and carries neither a `Co-Authored-By:` nor an `Assisted-by:` trailer in its message, whoever the trailer names. `freeze` refuses a range with a commit that breaks either (`requireSigned` and `aiTrailers` in `.review-gates/config.json`). The config names no `authors`, so who wrote a commit is not checked: a patch that came by mail keeps its author.
|
||||
|
|
@ -313,8 +315,9 @@ The checklist, from the bunq connector:
|
|||
- What the shipped policy leaves open is looking: `View` needs no password in an active session, so any program of the user's there can read the accounts, payments, requests and cards. Everything else asks, `Change` included since 2026-11-19 (design rule 9). The README's "How Nostro runs" and "Security" say both plainly, and the policy file's comment how a rule loosens it. polkit cannot tell the app from another program of the user's, so a rule that loosens an action loosens it for all of them; neither can nostrod, since whatever marks a process as the app (its executable, its Flatpak id, a unit's name) another program of the same user can wear, by starting the real app with its own code in it or on a display of its own.
|
||||
- A worker makes itself undumpable, and the service sets `LimitCORE=0`: a core dump would hold the keys. A text that reaches a dialog goes through `Shown()`, so neither a payee's name nor a description can fake another amount or payee in it, start a line of its own, or leave an agent that reads its message as markup with nothing to show. What it cannot stop is a name that reads like part of the sentence ("Bob) from NL00… (Savings"): the summary puts the amount first and the paying account last for that reason.
|
||||
- The app is one of the programs nostrod keeps the user's bank from: it sees accounts and payments, which `View` allows any program of the user's in an active session, and nothing that could pay or change anything at the bank without the dialog. Its Flatpak has the compositor, the graphics device and `net.catcrafts.Nostro1` on the system bus, and no network, no files and no session bus beyond the portals. It makes itself undumpable, so another program of the user's cannot read a key out of it while it is typed. It writes no amount, IBAN or name to its log, which lands in the user's journal.
|
||||
- A link is text from a stranger that ends up in front of the user as a payment to make. Design rule 14 keeps it to filling in the pay form, which says that a link filled it in. That does not keep out a payee who is not who the page says: the name in a link is its writer's to choose. Under an administrator's rule that lets `Pay` pass without a password, one press on a form a link filled in pays; under one that lets `Change` pass, the same press saves a draft from a connection that pays the user's own accounts only.
|
||||
- A link is an argument of the app's process, and a process's arguments are open to the other users of the machine (`/proc/<pid>/cmdline`): who is to be paid, how much and what for. `nostro-app` overwrites the link in its own `argv` once it has copied it. A process that started the app with the link, a Flatpak's sandbox among them, keeps its own copy.
|
||||
- A build with `--debug-api` is none of that: every program of the user's can drive it and read what it shows, it logs what it is told, and a debugger can attach to it. It is for the made-up system and bunq's sandbox. `Ui_Type` refuses to type into a field that hides what it holds unless the text is a sandbox key (`sandbox_…`); nothing stops a hand from typing a real one into such a build, so do not. No Flatpak is made of it.
|
||||
- The checkout answers a repeated order with its payment id without a dialog, so any app with access to the checkout can learn whether the user paid an order whose IBAN, reference and amount it knows.
|
||||
- A connector's `environment` decides between `api.bunq.com`, where `send` moves real money, and the sandbox. An API key says itself which it is of: a sandbox key starts with `sandbox_`, and anything else is production. Nobody chooses it: nostrod takes the key's own, and refuses an environment named otherwise before the key goes anywhere, so a real key is not sent to the sandbox by a slip (`OnAddBunq`); the CLI has no flag for it and the app's form no choice. An OAuth client has no such mark, so there the environment is named (`--sandbox`, the form's Production or Sandbox). Since 2026-11-19 production has been used to connect and to read accounts, payments and cards; these notes record no payment made on it, so try that with small amounts first.
|
||||
- Request bodies are `nlohmann::json` values serialised once (`dump` with invalid UTF-8 replaced), and the signature covers those exact bytes; nothing is spliced into JSON text by hand. Responses are used only after their server signature verifies.
|
||||
- A write is never replayed by the transport (fresh connection) and only resent by nostro after a 429, which bunq refuses before acting. An IBAN's check digits are verified before anything is sent.
|
||||
|
|
@ -326,10 +329,15 @@ The checklist, from the bunq connector:
|
|||
|
||||
## Gotchas
|
||||
|
||||
The state of the code on 2026-11-19; each is a fact to work with.
|
||||
Each is a fact to work with.
|
||||
|
||||
- `project.cpp` returns one configuration per run, so nostrod, the app, the checkout library and the fake system are products chosen with `--product=`, as in imsd. The library is one shared `Configuration*`: two configurations exporting the same module in one build are an error. The toolkit's and the app's libraries are declared in every product and built only for what depends on them: their tests, and the app.
|
||||
- `project.cpp` returns one configuration per run, so nostrod, the app and the fake system are products chosen with `--product=`, as in imsd. The library is one shared `Configuration*`: two configurations exporting the same module in one build are an error. The toolkit's and the app's libraries are declared in every product and built only for what depends on them: their tests, and the app.
|
||||
- `crafter-build -r` passes the program it runs no arguments, and the app has a few: that is what the `fake` script is for, and `--poke` with `--screenshot` for a run without a hand on it.
|
||||
- `run fake` keeps the made-up system's state in `build/fake-system` from one run to the next (`RunOnFakeSystem` in `project.cpp`): delete it before a run with `--empty`.
|
||||
- The app is no single instance: every start, a link's among them, is a process and a window of its own.
|
||||
- The desktop entry claims the `payto` scheme whole (`x-scheme-handler/payto`), and `ReadPaymentLink` refuses a link that is not `payto://iban/…`.
|
||||
- In a link's options a `+` is read as a space, since `UrlDecode` reads one so: a plus sign is written `%2B`.
|
||||
- The fake bank lists a user's accounts newest first (`FakeBunq.inc`): of Main and Savings, made in that order, Savings is the first account the app knows.
|
||||
- Crafter.Debug counts a frame each time it is given the loop's thread, every 50 ms, whatever the window drew: `wait --frames` measures time there. Wait for the event `FrameRendered` for a frame, and for a condition (`wait 'app.busy == false'`) for an answer: `wait --event AnswerArrived` only hears an answer that comes after it started, and nostrod's has often come by then.
|
||||
- `crafter-debug screenshot -o <file>` writes inside the client's sandbox, whose `/tmp` is its own: leave `-o` out, for `build/crafter-debug-shots/`, or name a path the sandbox shares with the host.
|
||||
- A size the compositor asks for (a dragged border, a tile, a phone's on-screen keyboard) is Crafter.Graphics' to take, and it takes it with a frame: the configure only keeps the size and fires `onFrameOwed`, and the next `Render()` makes the window's images again, fires `onResize` from inside itself, and answers the compositor with that frame's buffer. The window draws on demand, so `Shell::Window` asks for that frame from `onFrameOwed`: without it the compositor waits, and the window keeps its old size until something else changes on it. Its `onResize` listener lays the screens out again while that frame is being started, which is why `Canvas::Render` reads its list late. `Canvas::Reconcile` sizes the window only where the library does not, and two of the three reach into the library's own state, to be taken out again once the library does them: the size that comes with a new window, which is the whole screen on a phone (Crafter.Graphics #166; handed over in `deferredLogicalWidth`, where the library's listener keeps every later one), and a scale the display changes to by itself (#165; `RebuildSwapchain`). The third is the app's own size (`--size`, `SetSize`), which goes through `Resize`, in pixels: where dp times the scale is not a whole number the window comes out a dp larger than asked, 421 dp at a scale of 1.85 as 422. Looked at on 2026-11-20 on a desktop, KWin at a scale of 1.85, with the window resized by a KWin script and what the surface was sent read with `WAYLAND_DEBUG=1`. The two that are a phone's, the first size and a scale that comes late, were only tried there with the values put in by hand: on a phone they are still to be looked at.
|
||||
|
|
@ -345,9 +353,8 @@ The state of the code on 2026-11-19; each is a fact to work with.
|
|||
- systemd's hardening and bubblewrap, which flatpak runs nostrod in, disagree in places, found on 2026-11-01 under `systemd-run --user`: bubblewrap needs `AF_NETLINK` (it brings up loopback), `@mount`, `unshare` and `setns`, and a `/proc` of its own; `RestrictSUIDSGID=` makes systemd answer `openat2()` with ENOSYS, which bubblewrap 0.13 does not fall back from. `nostrod.service` says which options are left out and why.
|
||||
- polkit as seen on that day (polkit 127, Plasma): closing Plasma's dialog sends no `polkit.dismissed`, only `polkit.result` `auth_self`, so `Cancelled` is read from either; a kept authorization is the calling process's alone; the command line of the process asking is logged.
|
||||
- Agents do not agree on what a message is. GNOME Shell's, Phosh's and LXDE's show it as plain text. polkit-gnome (the older GTK agent many desktops without one of their own start) and mate-polkit put it into Pango markup without escaping it, as read in their sources on 2026-11-19: a `<` starts a tag there, and a bare `&` makes the whole message fail to parse, which leaves the dialog without one. That is why `Shown()` replaces `&` as it does `<` and `>`, and cannot escape them instead: an agent that shows plain text would show the escape. How Plasma's agent reads its message was not established that day. Whatever is added to a summary goes through `Shown()`.
|
||||
- sd-bus holds a vtable method's answer to the signature the vtable declares: an answer of another shape becomes `System.Error.ENOMSG`. A test that must send a malformed answer (`FakeCheckout` in `ShouldServeEveryUser`) registers a plain object (`sd_bus_add_object`) instead.
|
||||
- A worker or nostrod killed with SIGKILL writes no coverage counts; both handle SIGTERM (systemd's stop signal too) by ending the loop, and the tests stop them that way.
|
||||
- `--product=checkout` returns before the bank check, so it needs no `--banks=`; every other product does.
|
||||
- A `checkouts.cdb` beside a user's `connectors.json` is the record of orders that the checkout over D-Bus of 0.0.0 kept. Nothing reads it any more, and nostrod leaves it where it is.
|
||||
- nostrod's Flatpak was `net.catcrafts.Nostro` until 2026-11-01, when the coming Nostro app took that id and nostrod's became `net.catcrafts.Nostrod`. flatpak keeps an app's data under its id, so nostrod's state followed: `install.sh` stops nostrod, moves `/var/lib/nostro/.var/app/net.catcrafts.Nostro` to `…/net.catcrafts.Nostrod` (refusing when both exist), and removes the old Flatpak, which it tells from the app by its command, `nostro`. The Arch package only prints those steps, since the package and the Flatpaks update independently.
|
||||
|
||||
- **`GetConfigPath()` with `XDG_CONFIG_HOME` set returns `$XDG_CONFIG_HOME/.config/nostro`**, not `$XDG_CONFIG_HOME/nostro`; the cache path has no such insertion. An open bug, kept as is so existing files are still found; the sandbox recipe above accounts for it.
|
||||
|
|
|
|||
18
README.md
18
README.md
|
|
@ -33,6 +33,7 @@ The accounts and the people in these pictures are made up.
|
|||
|
||||
- The Pay and Request forms send on their button, and your system's password dialog is where you confirm it: read what it says. Closing the dialog pays nothing.
|
||||
- A connection that its bank lets pay between your own accounts only, as bunq does one made through OAuth, is marked Limited. A payment from it to anyone else is saved as a draft, to approve in your bank's app.
|
||||
- A `payto://iban/…` link opens the Pay form filled in, see Pay links.
|
||||
- Press a line of a payment's, a request's or a card's details to copy it.
|
||||
- With a keyboard: Tab moves, Enter presses, Escape goes back, F5 reads the screen again and Ctrl+F searches.
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ nostro scheduled {account} [cancel {id}]
|
|||
nostro draft {account} {to} {name} {amount} {description, optional}
|
||||
nostro drafts {account} [accept|reject {id}]
|
||||
nostro cards [freeze|unfreeze|lost|stolen {card id}]
|
||||
nostro checkout account [{account}] # the account apps may ask you to pay from, see Checkout
|
||||
nostro checkout account [{account}] # the account a pay link's form starts from in the app
|
||||
```
|
||||
|
||||
- `{account}` is an account's name or its IBAN. `{to}` and `{from}` are an IBAN, an e-mail address, or a phone number starting with `+`.
|
||||
|
|
@ -84,9 +85,17 @@ nostro checkout account [{account}] # the account apps may ask y
|
|||
|
||||
[Bunq](https://doc.bunq.com/api-reference/start-here)
|
||||
|
||||
## Checkout for apps
|
||||
## Pay links
|
||||
|
||||
An app, such as a shop, can have Nostro pay an order from the account you chose for that, in the app's settings or with `nostro checkout account {account}`, once you confirm the payment with your password. It calls `Pay` of `net.catcrafts.Nostro1.Checkout` on the system bus, which [packaging/dbus/net.catcrafts.Nostro1.Checkout.xml](packaging/dbus/net.catcrafts.Nostro1.Checkout.xml) documents, or links the `Nostro.Checkout` module (`crafter-build --product=checkout`). It gets a payment id back, which is not a receipt: confirm the money arrived with your own bank.
|
||||
A website or an app can offer a `payto://` link ([RFC 8905](https://www.rfc-editor.org/rfc/rfc8905)) that pays an IBAN, and Nostro opens it on its Pay form, filled in:
|
||||
|
||||
```
|
||||
payto://iban/NL91ABNA0417164300?amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234
|
||||
```
|
||||
|
||||
Nostro reads `amount` (in EUR), `receiver-name` and `message`, and refuses a link it cannot read. A link only fills in the form: nothing is paid until you press Pay and confirm it with your password. Whoever offered the link hears nothing back, and sees the payment arrive at their own bank.
|
||||
|
||||
Links take the place of the checkout over D-Bus that Nostro 0.0.0 had (`net.catcrafts.Nostro1.Checkout`), which is gone.
|
||||
|
||||
## Contributing
|
||||
|
||||
|
|
@ -107,13 +116,14 @@ What Nostro protects you from, and what it does not:
|
|||
- Programs you run cannot read your bank connections, and cannot pay or change anything at your bank without your password. They can look: in your desktop session any of them can read your accounts, payments, requests and cards.
|
||||
- The app is one of those programs. It holds no key, and its Flatpak has no network and none of your files.
|
||||
- The password dialog is your desktop's. A program could draw one that looks the same, so type your password only for something you asked for, and read what the dialog says.
|
||||
- A link only fills in the Pay form, but what it fills in is its writer's choice: read who is paid and how much. A link is passed to the app as a program argument, and other users of the computer can read those.
|
||||
- Over SSH, or in any session without a polkit agent, nothing can ask for your password, so whatever needs it is refused.
|
||||
- The bank connections are not encrypted on disk: use full-disk encryption.
|
||||
- An administrator can change what asks for a password, with polkit rules for the actions in [the policy](packaging/system/net.catcrafts.Nostro1.policy). A rule cannot tell Nostro from any other program you run, and one that lets `Pay` or `Change` pass makes one press on a form a payment or a draft.
|
||||
|
||||
## License
|
||||
|
||||
The library, nostrod, the `nostro` command and the checkout library are LGPL-3.0-only, see [LICENSE](LICENSE). The app is GPL-3.0-only, see [LICENSE.GPL](LICENSE.GPL): the modules `Nostro.Ui`, `Nostro.App` and `Nostro.Ui.Shell`, and `nostro-app`.
|
||||
The library, nostrod and the `nostro` command are LGPL-3.0-only, see [LICENSE](LICENSE). The app is GPL-3.0-only, see [LICENSE.GPL](LICENSE.GPL): the modules `Nostro.Ui`, `Nostro.App` and `Nostro.Ui.Shell`, and `nostro-app`.
|
||||
|
||||
The app is set in Noto Sans, under the SIL Open Font License ([assets/OFL.txt](assets/OFL.txt)); [packaging/licenses/NOTICE](packaging/licenses/NOTICE) lists what else the Flatpaks carry.
|
||||
|
||||
|
|
|
|||
|
|
@ -36,10 +36,6 @@ std::string Bus::Sender(sd_bus_message* message) {
|
|||
return Text(sd_bus_message_get_sender(message));
|
||||
}
|
||||
|
||||
std::string Bus::Interface(sd_bus_message* message) {
|
||||
return Text(sd_bus_message_get_interface(message));
|
||||
}
|
||||
|
||||
std::string Bus::Member(sd_bus_message* message) {
|
||||
return Text(sd_bus_message_get_member(message));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ namespace {
|
|||
if(changes && (name == SD_BUS_ERROR_NO_REPLY || name == SD_BUS_ERROR_TIMEOUT)) {
|
||||
throw OutcomeUnknown(std::format("nostrod did not answer in time ({}): what you asked for may have been carried out, check before trying again", message));
|
||||
}
|
||||
// bunq's error to a write that may have gone through all the same says so at its end, as the checkout's
|
||||
// published interface documents for net.catcrafts.Nostro1.Error.Bank.
|
||||
// bunq's error to a write that may have gone through all the same says so at its end, as the published
|
||||
// interface documents for net.catcrafts.Nostro1.Error.Bank.
|
||||
if(changes && name == errorBank && message.ends_with(BunqError::maybeCarriedOut)) {
|
||||
throw OutcomeUnknown(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ module;
|
|||
|
||||
module Nostro:DaemonWorker_impl;
|
||||
import std;
|
||||
import Crafter.DB;
|
||||
import Nostro.Checkout;
|
||||
import :Daemon;
|
||||
import :Bus;
|
||||
import :Account;
|
||||
|
|
@ -27,48 +25,17 @@ import :Utils;
|
|||
|
||||
using namespace Nostro;
|
||||
using namespace Nostro::Bus;
|
||||
using namespace Crafter;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// One user's worker. Every call is read and checked first (the account, the counterparty, what is to be paid), then
|
||||
// polkit decides with a summary built from the worker's own data, and only then does the call run. On nostrod's own
|
||||
// interface nothing of the user's is read, and the bank is asked nothing, for a caller polkit has not said yes to: a
|
||||
// call that must look something up to word its question asks first whether the caller may see the accounts
|
||||
// (HandleLookup). The checkout is the one that reads before it asks: an order it knows is answered from its record,
|
||||
// and the account that pays a new one is chosen for the dialog to name (OnPay). The wire carries bunq's types, so the
|
||||
// worker works with bunq's connector directly.
|
||||
// polkit decides with a summary built from the worker's own data, and only then does the call run. Nothing of the
|
||||
// user's is read, and the bank is asked nothing, for a caller polkit has not said yes to: a call that must look
|
||||
// something up to word its question asks first whether the caller may see the accounts (HandleLookup). That has no
|
||||
// exception: the one it had, a checkout over D-Bus that answered an order it knew before anyone was asked, went on
|
||||
// 2026-11-22. The wire carries bunq's types, so the worker works with bunq's connector directly.
|
||||
|
||||
namespace {
|
||||
using Work = std::function<void(sd_bus_message* reply)>;
|
||||
// What runs once a call that went through polkit is answered, with the answer it got.
|
||||
using After = std::function<void(sd_bus_message* answer)>;
|
||||
|
||||
// An order paid at checkout, or being paid, which makes a retry safe. It is written before the payment is sent,
|
||||
// with no payment yet, so a worker that dies or a bank whose answer is lost leaves it saying the order may have been
|
||||
// paid. This is the table's schema: a change to it bumps `version` (see the Crafter.DB notes).
|
||||
struct CheckoutRecord {
|
||||
std::string payee; // the payee's IBAN, without spaces
|
||||
std::string reference; // the app's reference for the order
|
||||
std::int64_t amount = 0; // in the currency's minor unit
|
||||
Currency currency = Currency::Euro;
|
||||
std::string account; // the IBAN it is paid from
|
||||
std::uint64_t payment = 0; // the bank's id of the payment, 0 while the bank's answer is unknown
|
||||
std::chrono::system_clock::time_point time;
|
||||
|
||||
static constexpr std::uint32_t version = 1;
|
||||
};
|
||||
static_assert(DB::Layout<CheckoutRecord>::rowSize == 80);
|
||||
static_assert(DB::Layout<CheckoutRecord>::fingerprint == 0x87a27f8a68f38c52);
|
||||
|
||||
// Orders are told apart by payee and reference: an app's references are its own.
|
||||
using OrderKey = std::pair<std::string, std::string>;
|
||||
|
||||
// An order whose call is under way, and the calls for the same order that wait for its answer.
|
||||
struct Paying {
|
||||
std::int64_t amount = 0;
|
||||
Currency currency = Currency::Euro;
|
||||
std::vector<MessagePtr> waiting;
|
||||
};
|
||||
|
||||
struct Worker {
|
||||
DaemonOptions options;
|
||||
|
|
@ -76,9 +43,8 @@ namespace {
|
|||
std::string name;
|
||||
fs::path directory;
|
||||
sd_event* event = nullptr;
|
||||
// Before the connection they are registered with, which then goes first however RunWorker ends.
|
||||
// Before the connection it is registered with, which then goes first however RunWorker ends.
|
||||
std::vector<sd_bus_vtable> vtable;
|
||||
std::vector<sd_bus_vtable> checkoutVtable;
|
||||
BusPtr link;
|
||||
BusPtr system;
|
||||
sd_event_source* idle = nullptr;
|
||||
|
|
@ -87,9 +53,6 @@ namespace {
|
|||
bool loaded = false;
|
||||
std::size_t checking = 0;
|
||||
std::uint64_t checks = 0;
|
||||
// The checkouts paid, opened with the first; and the orders being paid now.
|
||||
std::optional<DB::Table<CheckoutRecord>> records;
|
||||
std::map<OrderKey, Paying> paying;
|
||||
};
|
||||
|
||||
// Answered as AccessDenied.
|
||||
|
|
@ -102,11 +65,6 @@ namespace {
|
|||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
// A checkout, and no account to pay it from.
|
||||
struct NoCheckoutAccount : std::runtime_error {
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
// The library's warnings, sent with the next answer that is not an error. The process's own, as noteSink is.
|
||||
std::vector<std::string> notes;
|
||||
|
||||
|
|
@ -150,9 +108,6 @@ namespace {
|
|||
} catch(const Refused& e) {
|
||||
name = SD_BUS_ERROR_ACCESS_DENIED;
|
||||
message = e.what();
|
||||
} catch(const NoCheckoutAccount& e) {
|
||||
name = errorNoCheckoutAccount;
|
||||
message = e.what();
|
||||
} catch(const OAuthPaymentRefused& e) {
|
||||
name = errorOAuthCannotPay;
|
||||
message = e.what();
|
||||
|
|
@ -165,13 +120,6 @@ namespace {
|
|||
} catch(const std::exception& e) {
|
||||
message = e.what();
|
||||
}
|
||||
// The connector says which call went wrong, "bunq POST /user/…/monetary-account/…/payment: …", and that names
|
||||
// the user and the account at the bank. An app at checkout never sees the account, so it is told what the bank
|
||||
// said and whether the payment may have been made all the same, and not what was asked of the bank.
|
||||
const std::size_t said = message.find(": ");
|
||||
if(Interface(call) == Checkout::interfaceName && message.starts_with("bunq ") && said != std::string::npos) {
|
||||
message.replace(0, said, "bunq");
|
||||
}
|
||||
return ErrorReply(call, name, message);
|
||||
}
|
||||
|
||||
|
|
@ -179,38 +127,18 @@ namespace {
|
|||
sd_bus_send(nullptr, answer.get(), nullptr);
|
||||
}
|
||||
|
||||
// The most a password dialog shows of a name, a description or a reference, in characters; and of an address,
|
||||
// which it shows whole: the longest an e-mail address gets.
|
||||
// The most a password dialog shows of a name, in characters; and of an address, which it shows whole: the longest
|
||||
// an e-mail address gets.
|
||||
constexpr std::size_t shownLimit = 64;
|
||||
constexpr std::size_t addressLimit = 254;
|
||||
|
||||
using Range = std::pair<std::uint32_t, std::uint32_t>;
|
||||
|
||||
// What draws nothing, or tells the reader's own text where to go: control and format characters, the line and
|
||||
// paragraph separators, what Unicode leaves out of a display by default (soft hyphens, joiners, fillers, variation
|
||||
// selectors, tags), surrogates, private use, and what is no character at all.
|
||||
constexpr std::array<Range, 31> unshown = {{
|
||||
{0x0000, 0x001F}, {0x007F, 0x009F}, {0x00AD, 0x00AD}, {0x034F, 0x034F}, {0x0600, 0x0605}, {0x061C, 0x061C}, {0x06DD, 0x06DD}, {0x070F, 0x070F},
|
||||
{0x0890, 0x0891}, {0x08E2, 0x08E2}, {0x115F, 0x1160}, {0x17B4, 0x17B5}, {0x180B, 0x180F}, {0x200B, 0x200F}, {0x2028, 0x202E}, {0x2060, 0x206F},
|
||||
{0x3164, 0x3164}, {0xD800, 0xF8FF}, {0xFDD0, 0xFDEF}, {0xFE00, 0xFE0F}, {0xFEFF, 0xFEFF}, {0xFFA0, 0xFFA0}, {0xFFF0, 0xFFFC}, {0xFFFE, 0xFFFF},
|
||||
{0x110BD, 0x110BD}, {0x110CD, 0x110CD}, {0x13430, 0x1343F}, {0x1BCA0, 0x1BCA3}, {0x1D173, 0x1D17A}, {0xE0000, 0xE0FFF}, {0xF0000, 0xFFFFFFFF},
|
||||
}};
|
||||
|
||||
// A space of any width, and the Braille pattern without a dot, which is one to the eye.
|
||||
constexpr std::array<Range, 8> blank = {{
|
||||
{0x0020, 0x0020}, {0x00A0, 0x00A0}, {0x1680, 0x1680}, {0x2000, 0x200A}, {0x202F, 0x202F}, {0x205F, 0x205F}, {0x2800, 0x2800}, {0x3000, 0x3000},
|
||||
}};
|
||||
|
||||
bool Among(std::span<const Range> ranges, std::uint32_t code) {
|
||||
return std::ranges::any_of(ranges, [code](const Range& range) { return code >= range.first && code <= range.second; });
|
||||
}
|
||||
|
||||
// Text from a caller or a bank, made fit for a password dialog, which is where the user reads what a password is
|
||||
// for. Nothing of `unshown`, so no text hides, turns around or starts a line of its own; a space of any kind is one
|
||||
// plain space, and none leads or trails, so none pushes what follows onto another line; nothing a dialog could take
|
||||
// for markup, or polkit for one of its $(…) fields; and at most `limit` characters, so a long name cannot push what
|
||||
// matters out of sight. An & goes with < and >: an agent that reads its message as Pango markup, as GNOME's older
|
||||
// one and MATE's do, shows nothing at all of a message with a bare & in it, the amount included.
|
||||
// for. Nothing that is Unshown (the library's list, which the app holds a link's text to as well), so no text
|
||||
// hides, turns around or starts a line of its own; a space of any kind, whatever is Blank, is one plain space, and
|
||||
// none leads or trails, so none pushes what follows onto another line; nothing a dialog could take for markup, or
|
||||
// polkit for one of its $(…) fields; and at most `limit` characters, so a long name cannot push what matters out
|
||||
// of sight. An & goes with < and >: an agent that reads its message as Pango markup, as GNOME's older one and
|
||||
// MATE's do, shows nothing at all of a message with a bare & in it, the amount included.
|
||||
std::string Shown(std::string_view text, std::size_t limit = shownLimit) {
|
||||
// Each character as it is shown, up to the first that does not fit, which is there to say that there is more.
|
||||
std::vector<std::string_view> shown;
|
||||
|
|
@ -227,10 +155,10 @@ namespace {
|
|||
}
|
||||
const std::string_view character = text.substr(i, length);
|
||||
i += length;
|
||||
if(Among(unshown, code)) {
|
||||
if(Unshown(code)) {
|
||||
continue;
|
||||
}
|
||||
if(Among(blank, code)) {
|
||||
if(Blank(code)) {
|
||||
spaced = !shown.empty();
|
||||
continue;
|
||||
}
|
||||
|
|
@ -399,8 +327,8 @@ namespace {
|
|||
throw std::invalid_argument(std::format("no account is called or has IBAN '{}'", key));
|
||||
}
|
||||
|
||||
// The user's connectors, read for the first call polkit says yes to, or the first new order at checkout: that call
|
||||
// also records whose directory this is. Reading them refreshes each one's accounts, which asks the bank.
|
||||
// The user's connectors, read for the first call polkit says yes to: that call also records whose directory this
|
||||
// is. Reading them refreshes each one's accounts, which asks the bank.
|
||||
void Load(Worker& worker) {
|
||||
if(worker.loaded) {
|
||||
return;
|
||||
|
|
@ -415,17 +343,13 @@ namespace {
|
|||
worker.loaded = true;
|
||||
}
|
||||
|
||||
// Runs `work` and makes the answer to `call` of what it appended, and of the notes, which only nostrod's own
|
||||
// interface carries: they are the user's, and an app at checkout is someone else.
|
||||
// Runs `work` and makes the answer to `call` of what it appended, and of the notes.
|
||||
MessagePtr Answer(sd_bus_message* call, const Work& work) {
|
||||
sd_bus_message* raw = nullptr;
|
||||
ThrowOnSdBus(sd_bus_message_new_method_return(call, &raw), "answer a call");
|
||||
MessagePtr reply(raw);
|
||||
work(raw);
|
||||
const std::vector<std::string> said = std::exchange(notes, {});
|
||||
if(Interface(call) == interfaceName) {
|
||||
Append(raw, said);
|
||||
}
|
||||
Append(raw, std::exchange(notes, {}));
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
|
@ -433,7 +357,6 @@ namespace {
|
|||
Worker* worker = nullptr;
|
||||
MessagePtr call;
|
||||
Work work;
|
||||
After after;
|
||||
// What a yes is followed by in place of an answer: the rest of a call that asked before it looked (HandleLookup).
|
||||
std::function<void()> next;
|
||||
std::string action;
|
||||
|
|
@ -492,17 +415,13 @@ namespace {
|
|||
answer = ErrorFor(call, std::current_exception());
|
||||
}
|
||||
Deliver(answer);
|
||||
if(check->after) {
|
||||
check->after(answer.get());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Asks polkit whether the caller may do what `prompt` says. On a yes it runs `next` when there is one, which
|
||||
// answers the call itself, and else runs `work` and answers with what that appended; on anything else it answers
|
||||
// why not. Then it runs `after` with the answer it gave. The check does not block: other calls are served while a
|
||||
// password dialog is open.
|
||||
std::int32_t Ask(Worker& worker, sd_bus_message* call, const Prompt& prompt, Work work, After after, std::function<void()> next) {
|
||||
// why not. The check does not block: other calls are served while a password dialog is open.
|
||||
std::int32_t Ask(Worker& worker, sd_bus_message* call, const Prompt& prompt, Work work, std::function<void()> next) {
|
||||
const bool interactive = sd_bus_message_get_allow_interactive_authorization(call) > 0;
|
||||
sd_bus_message* raw = nullptr;
|
||||
ThrowOnSdBus(sd_bus_message_new_method_call(worker.system.get(), &raw, "org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority", "org.freedesktop.PolicyKit1.Authority", "CheckAuthorization"), "ask polkit");
|
||||
|
|
@ -536,7 +455,7 @@ namespace {
|
|||
std::string cancellation = std::format("nostro-{}-{}", getpid(), ++worker.checks);
|
||||
Append(raw, cancellation);
|
||||
|
||||
std::unique_ptr<Check> check = std::make_unique<Check>(&worker, MessagePtr(sd_bus_message_ref(call)), std::move(work), std::move(after), std::move(next), std::string(prompt.action), interactive, std::move(cancellation));
|
||||
std::unique_ptr<Check> check = std::make_unique<Check>(&worker, MessagePtr(sd_bus_message_ref(call)), std::move(work), std::move(next), std::string(prompt.action), interactive, std::move(cancellation));
|
||||
ThrowOnSdBus(sd_bus_call_async(worker.system.get(), nullptr, raw, OnChecked, check.get(), Microseconds(worker.options.promptTimeout)), "ask polkit");
|
||||
// OnChecked owns it now.
|
||||
check.release();
|
||||
|
|
@ -544,10 +463,9 @@ namespace {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Asks polkit whether the caller may do what `prompt` says, then runs `work` and answers; or answers why not; and
|
||||
// then runs `after` with the answer.
|
||||
std::int32_t Gate(Worker& worker, sd_bus_message* call, const Prompt& prompt, Work work, After after = {}) {
|
||||
return Ask(worker, call, prompt, std::move(work), std::move(after), {});
|
||||
// Asks polkit whether the caller may do what `prompt` says, then runs `work` and answers; or answers why not.
|
||||
std::int32_t Gate(Worker& worker, sd_bus_message* call, const Prompt& prompt, Work work) {
|
||||
return Ask(worker, call, prompt, std::move(work), {});
|
||||
}
|
||||
|
||||
// Runs `body` for `call`: it answers through Gate, or throws, and then the call is answered with the error. Nothing
|
||||
|
|
@ -576,7 +494,7 @@ namespace {
|
|||
template<typename Body>
|
||||
std::int32_t HandleLookup(sd_bus_message* call, void* userdata, std::string_view seen, Body body) {
|
||||
return Handle(call, userdata, [call, seen, &body](Worker& worker) {
|
||||
return Ask(worker, call, Prompt{actionView, std::string(seen), {}}, {}, {}, [&worker, body = std::move(body)] {
|
||||
return Ask(worker, call, Prompt{actionView, std::string(seen), {}}, {}, [&worker, body = std::move(body)] {
|
||||
body(worker);
|
||||
});
|
||||
});
|
||||
|
|
@ -927,12 +845,12 @@ namespace {
|
|||
});
|
||||
}
|
||||
|
||||
// Checkout (Nostro.Checkout): an app has nostrod pay an order. The order is read and checked, the account that
|
||||
// pays it is chosen, the user confirms both at a password prompt, and it is paid and recorded. The record answers a
|
||||
// retry with the first payment, and a retry while the first call is still under way waits for its answer.
|
||||
|
||||
// The account chosen to pay checkouts from, kept beside connectors.json as its connector's storage key and its id:
|
||||
// none when none is chosen, or it is gone.
|
||||
// The account a pay link's form starts from in the app, which the user chooses once: "Pay links start from" in
|
||||
// its settings. It is where a form starts and no more: the app asks which account pays when a link opens, the
|
||||
// form's own row changes which account pays, and what a link pays is a payment like any other, asked about as
|
||||
// one. nostrod only keeps it, and pays nothing from it by itself. Until 2026-11-22 it was the account that paid an
|
||||
// app's order at a checkout over D-Bus, which is where these methods and the file have their names from. It is
|
||||
// kept beside connectors.json as its connector's storage key and its id: none when none is chosen, or it is gone.
|
||||
const BunqAccount* CheckoutAccount(const Worker& worker) {
|
||||
std::ifstream in(worker.directory / "checkout-account");
|
||||
AccountKey key;
|
||||
|
|
@ -951,7 +869,7 @@ namespace {
|
|||
|
||||
std::int32_t OnDefaultCheckoutAccount(sd_bus_message* call, void* userdata, sd_bus_error*) {
|
||||
return Handle(call, userdata, [call](Worker& worker) {
|
||||
return Gate(worker, call, Prompt{actionView, "see which account pays at checkout", {}}, [&worker](sd_bus_message* reply) {
|
||||
return Gate(worker, call, Prompt{actionView, "see which account pay links start from", {}}, [&worker](sd_bus_message* reply) {
|
||||
const BunqAccount* chosen = CheckoutAccount(worker);
|
||||
Append(reply, chosen ? std::optional<Account>(*chosen) : std::nullopt);
|
||||
});
|
||||
|
|
@ -961,11 +879,12 @@ namespace {
|
|||
std::int32_t OnSetDefaultCheckoutAccount(sd_bus_message* call, void* userdata, sd_bus_error*) {
|
||||
return HandleLookup(call, userdata, "see your accounts and balances", [call](Worker& worker) {
|
||||
const BunqAccount& account = FindAccount(Read<std::string>(call));
|
||||
// bunq lets an OAuth connection pay the user's own accounts only, so through one no shop could be paid.
|
||||
// bunq lets an OAuth connection pay the user's own accounts only: from one, what a shop's link asks for
|
||||
// could do no more than become a draft.
|
||||
if(account.connector->IsOAuth()) {
|
||||
throw std::invalid_argument(std::format("'{}' is reached through OAuth, which pays only your own accounts: checkouts need an account added with an API key", account.name));
|
||||
throw std::invalid_argument(std::format("'{}' is reached through OAuth, which pays only your own accounts: a shop's pay link needs an account added with an API key", account.name));
|
||||
}
|
||||
const Prompt prompt{actionConnectors, std::format("let apps ask you to pay from {} at checkout", Party(account)), {{"account_iban", account.iban}, {"environment", std::string(EnvironmentName(account.connector->environment))}}};
|
||||
const Prompt prompt{actionConnectors, std::format("have pay links start from {}", Party(account)), {{"account_iban", account.iban}, {"environment", std::string(EnvironmentName(account.connector->environment))}}};
|
||||
return Gate(worker, call, prompt, [&worker, key = KeyOf(account)](sd_bus_message* reply) {
|
||||
const BunqAccount& chosen = AccountBy(key);
|
||||
const fs::path file = worker.directory / "checkout-account";
|
||||
|
|
@ -977,173 +896,6 @@ namespace {
|
|||
});
|
||||
}
|
||||
|
||||
// An order, as Pay() reads and checks it. The options after its arguments are not read: there are none yet, and
|
||||
// those of a later nostro this one does not know.
|
||||
struct Order {
|
||||
BunqCounterparty payee; // an IBAN, and the name given
|
||||
std::int64_t amount = 0;
|
||||
Currency currency = Currency::Euro;
|
||||
std::string reference;
|
||||
|
||||
OrderKey Key() const {
|
||||
return {payee.value, reference};
|
||||
}
|
||||
|
||||
static Order Read(sd_bus_message* call) {
|
||||
const std::string iban = Bus::Read<std::string>(call);
|
||||
const std::string name = Bus::Read<std::string>(call);
|
||||
Order order;
|
||||
order.amount = Bus::Read<std::int64_t>(call);
|
||||
const std::string currency = Bus::Read<std::string>(call);
|
||||
order.reference = Bus::Read<std::string>(call);
|
||||
order.payee = BunqCounterparty::Parse(iban, name);
|
||||
if(order.payee.type != "IBAN") {
|
||||
throw std::invalid_argument(std::format("checkout pays an IBAN, and '{}' is none", iban));
|
||||
}
|
||||
RequirePositive(order.amount);
|
||||
try {
|
||||
order.currency = GetCurrency(currency);
|
||||
} catch(const std::runtime_error& e) {
|
||||
throw std::invalid_argument(e.what());
|
||||
}
|
||||
if(order.reference.empty()) {
|
||||
throw std::invalid_argument("an order needs a reference, such as its number: it is what keeps paying it again from paying twice");
|
||||
}
|
||||
return order;
|
||||
}
|
||||
};
|
||||
|
||||
// One reference to one payee is one order, of one amount. Which amount the order has is not said: any app that
|
||||
// knows the payee and the reference of an order another app had paid would learn from it what was paid for it.
|
||||
void RequireSameOrder(std::int64_t amount, Currency currency, const Order& order) {
|
||||
if(amount != order.amount || currency != order.currency) {
|
||||
throw std::invalid_argument(std::format("reference {} to {} is an order of another amount than {}: another order needs another reference", Shown(order.reference), order.payee.value, FormatMoney(order.amount, order.currency)));
|
||||
}
|
||||
}
|
||||
|
||||
DB::Table<CheckoutRecord>& Records(Worker& worker) {
|
||||
if(!worker.records) {
|
||||
// A few rows per order: a reservation of a gigabyte, where the transaction tables take Crafter.DB's 32.
|
||||
worker.records.emplace(worker.directory / "checkouts.cdb", DB::OpenOptions{.reserveBytes = std::uint64_t(1) << 30});
|
||||
}
|
||||
return *worker.records;
|
||||
}
|
||||
|
||||
// Pay()'s answer: the payment, and the results, of which `repeated` says the payment was made by an earlier call.
|
||||
void AppendPaid(sd_bus_message* reply, std::uint64_t payment, bool repeated) {
|
||||
ThrowOnSdBus(sd_bus_message_append(reply, "ta{sv}", payment, 1u, "repeated", "b", static_cast<std::int32_t>(repeated)), "answer a call");
|
||||
}
|
||||
|
||||
// Answers a call for an order paid before, or being paid, and returns true; false for an order not seen before.
|
||||
bool AnswerKnownOrder(Worker& worker, sd_bus_message* call, const Order& order) {
|
||||
static constexpr DB::Column<&CheckoutRecord::payee> payee{};
|
||||
static constexpr DB::Column<&CheckoutRecord::reference> reference{};
|
||||
if(const std::optional<DB::Row<CheckoutRecord>> record = Records(worker).Where(payee == order.payee.value && reference == order.reference).First()) {
|
||||
RequireSameOrder((*record)[&CheckoutRecord::amount], (*record)[&CheckoutRecord::currency], order);
|
||||
const std::uint64_t payment = (*record)[&CheckoutRecord::payment];
|
||||
if(payment == 0) {
|
||||
throw std::runtime_error(std::format("order {} to {} may have been paid already: the bank's answer to it was lost, so check whether the payment arrived before paying it under another reference", Shown(order.reference), order.payee.value));
|
||||
}
|
||||
Deliver(Answer(call, [payment](sd_bus_message* reply) { AppendPaid(reply, payment, true); }));
|
||||
return true;
|
||||
}
|
||||
if(const auto paying = worker.paying.find(order.Key()); paying != worker.paying.end()) {
|
||||
RequireSameOrder(paying->second.amount, paying->second.currency, order);
|
||||
paying->second.waiting.push_back(MessagePtr(sd_bus_message_ref(call)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// The order's call is answered: the calls that waited for it get the same answer, the payment marked as made by
|
||||
// an earlier call. The order is there: it went in before its account was chosen, and only this takes it out.
|
||||
// Answering fails only when memory runs out, and then the callers' own timeouts answer for them.
|
||||
void Settle(Worker& worker, const OrderKey& key, sd_bus_message* answer) {
|
||||
const std::vector<MessagePtr> waiting = std::move(worker.paying.extract(key).mapped().waiting);
|
||||
const bool paid = sd_bus_message_is_method_error(answer, nullptr) == 0;
|
||||
std::uint64_t payment = 0;
|
||||
sd_bus_message_rewind(answer, 1);
|
||||
sd_bus_message_read_basic(answer, 't', &payment);
|
||||
for(const MessagePtr& call : waiting) {
|
||||
if(paid) {
|
||||
sd_bus_reply_method_return(call.get(), "ta{sv}", payment, 1u, "repeated", "b", 1);
|
||||
} else {
|
||||
sd_bus_reply_method_error(call.get(), sd_bus_message_get_error(answer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pays an order the user confirmed, and records it. The record goes first, with no payment, so should the worker
|
||||
// die or the bank's answer be lost, a retry finds it and is refused rather than paid twice. Only a refusal bunq
|
||||
// gives before doing anything (below 500) takes it away again.
|
||||
std::uint64_t PayOrder(Worker& worker, const BunqAccount& account, const Order& order) {
|
||||
DB::Table<CheckoutRecord>& records = Records(worker);
|
||||
const DB::RowId row = records.Append(CheckoutRecord{order.payee.value, order.reference, order.amount, order.currency, account.iban, 0, std::chrono::system_clock::now()});
|
||||
records.Flush();
|
||||
std::uint64_t payment = 0;
|
||||
try {
|
||||
payment = account.Send(order.payee.value, order.payee.name, order.amount, order.currency, order.reference);
|
||||
} catch(const BunqError& e) {
|
||||
if(e.status < 500) {
|
||||
records.Erase(row);
|
||||
records.Flush();
|
||||
}
|
||||
throw;
|
||||
}
|
||||
records.Set<&CheckoutRecord::payment>(row, payment);
|
||||
records.Flush();
|
||||
return payment;
|
||||
}
|
||||
|
||||
// Which account pays an order. Today the one the user chose for checkouts; an account picker, once nostro has a
|
||||
// GUI, asks the user here instead, through an agent in their session, and may take its time. It answers through
|
||||
// `then`, with the account or with what the call is to be refused with, and nothing else of a checkout changes with
|
||||
// it. One that answers later keeps a reference to `call` until it does.
|
||||
using Choice = std::variant<AccountKey, std::exception_ptr>;
|
||||
void ChooseAccount(const Worker& worker, sd_bus_message*, const Order&, const std::function<void(const Choice&)>& then) {
|
||||
if(const BunqAccount* chosen = CheckoutAccount(worker)) {
|
||||
then(KeyOf(*chosen));
|
||||
} else {
|
||||
then(std::make_exception_ptr(NoCheckoutAccount("no account is chosen to pay checkouts from, or it is gone: choose one in Nostro's settings, or with `nostro checkout account`")));
|
||||
}
|
||||
}
|
||||
|
||||
std::int32_t OnPay(sd_bus_message* call, void* userdata, sd_bus_error*) {
|
||||
return Handle(call, userdata, [call](Worker& worker) {
|
||||
const Order order = Order::Read(call);
|
||||
if(AnswerKnownOrder(worker, call, order)) {
|
||||
return 1;
|
||||
}
|
||||
// The account that pays is chosen before the user is asked, since the dialog names it: an order not seen
|
||||
// before has the connectors read for it, which no call of nostrod's own interface does before polkit's yes.
|
||||
Load(worker);
|
||||
// From here on, a call for the same order waits for this one, and Settle answers it.
|
||||
worker.paying[order.Key()] = Paying{order.amount, order.currency, {}};
|
||||
ChooseAccount(worker, call, order, [&worker, call, order](const Choice& choice) {
|
||||
try {
|
||||
if(const std::exception_ptr* refusal = std::get_if<std::exception_ptr>(&choice)) {
|
||||
std::rethrow_exception(*refusal);
|
||||
}
|
||||
const AccountKey key = std::get<AccountKey>(choice);
|
||||
const BunqAccount& account = AccountBy(key);
|
||||
std::vector<std::pair<std::string, std::string>> details = PaymentDetails(account, order.amount, order.currency, order.payee.value);
|
||||
details.emplace_back("reference", Shown(order.reference));
|
||||
const Prompt prompt{actionCheckout, std::format("pay {} to {} from {}, as an app asks at checkout, reference {}", FormatMoney(order.amount, order.currency), Party(order.payee), Party(account), Shown(order.reference)), std::move(details)};
|
||||
Gate(worker, call, prompt, [&worker, key, order](sd_bus_message* reply) {
|
||||
AppendPaid(reply, PayOrder(worker, AccountBy(key), order), false);
|
||||
}, [&worker, settled = order.Key()](sd_bus_message* answer) {
|
||||
Settle(worker, settled, answer);
|
||||
});
|
||||
} catch(...) {
|
||||
const MessagePtr answer = ErrorFor(call, std::current_exception());
|
||||
Deliver(answer);
|
||||
Settle(worker, order.Key(), answer.get());
|
||||
}
|
||||
});
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
const std::map<std::string_view, sd_bus_message_handler_t> handlers = {
|
||||
{"Connectors", OnConnectors},
|
||||
{"AddBunq", OnAddBunq},
|
||||
|
|
@ -1214,8 +966,6 @@ std::int32_t Nostro::RunWorker(std::int32_t fd, std::uint32_t uid, std::string_v
|
|||
ThrowOnSdBus(sd_bus_start(link), "serve the front");
|
||||
worker.vtable = Vtable(methods, [](std::string_view member) { return handlers.at(member); });
|
||||
ThrowOnSdBus(sd_bus_add_object_vtable(link, nullptr, objectPath.data(), interfaceName.data(), worker.vtable.data(), &worker), "serve the front");
|
||||
worker.checkoutVtable = Vtable(checkoutMethods, [](std::string_view) { return &OnPay; });
|
||||
ThrowOnSdBus(sd_bus_add_object_vtable(link, nullptr, objectPath.data(), Checkout::interfaceName.data(), worker.checkoutVtable.data(), &worker), "serve the front");
|
||||
ThrowOnSdBus(sd_bus_match_signal(link, nullptr, "org.freedesktop.DBus.Local", "/org/freedesktop/DBus/Local", "org.freedesktop.DBus.Local", "Disconnected", OnFrontGone, &worker), "watch the front");
|
||||
ThrowOnSdBus(sd_bus_attach_event(link, worker.event, SD_EVENT_PRIORITY_NORMAL), "serve the front");
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ module;
|
|||
|
||||
module Nostro:Daemon_impl;
|
||||
import std;
|
||||
import Nostro.Checkout;
|
||||
import :Daemon;
|
||||
import :Bus;
|
||||
|
||||
|
|
@ -49,14 +48,9 @@ namespace {
|
|||
struct Front {
|
||||
DaemonOptions options;
|
||||
sd_event* event = nullptr;
|
||||
// Before the connections, so the connection each is registered with goes first however RunDaemon ends.
|
||||
// Before the connection it is registered with, which then goes first however RunDaemon ends.
|
||||
std::vector<sd_bus_vtable> vtable;
|
||||
std::vector<sd_bus_vtable> checkoutVtable;
|
||||
BusPtr bus;
|
||||
// Checkout::busName, with net.catcrafts.Nostro1.Checkout alone, on a connection of its own: an app allowed to
|
||||
// talk to that name and no other (a Flatpak's --system-talk-name) may call its owner's unique name too, and this
|
||||
// one serves nothing else.
|
||||
BusPtr checkout;
|
||||
std::map<std::uint32_t, std::unique_ptr<Worker>> workers;
|
||||
std::size_t inFlight = 0;
|
||||
sd_event_source* idle = nullptr;
|
||||
|
|
@ -305,16 +299,16 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
// A system bus connection that serves `interface` under `name`, every method passed on by Forward, and ends the
|
||||
// loop when the bus goes.
|
||||
BusPtr Serve(Front& front, std::string_view description, std::string_view name, std::string_view interface, std::vector<sd_bus_vtable>& vtable) {
|
||||
// The system bus connection that serves nostrod's interface under its name, every method passed on by Forward, and
|
||||
// ends the loop when the bus goes.
|
||||
BusPtr Serve(Front& front) {
|
||||
sd_bus* bus = nullptr;
|
||||
ThrowOnSdBus(sd_bus_open_system_with_description(&bus, description.data()), "connect to the system bus");
|
||||
ThrowOnSdBus(sd_bus_open_system_with_description(&bus, "nostrod"), "connect to the system bus");
|
||||
BusPtr owned(bus);
|
||||
ThrowOnSdBus(sd_bus_add_object_vtable(bus, nullptr, objectPath.data(), interface.data(), vtable.data(), &front), std::format("serve {}", interface));
|
||||
ThrowOnSdBus(sd_bus_add_object_vtable(bus, nullptr, objectPath.data(), interfaceName.data(), front.vtable.data(), &front), std::format("serve {}", interfaceName));
|
||||
ThrowOnSdBus(sd_bus_match_signal(bus, nullptr, "org.freedesktop.DBus.Local", "/org/freedesktop/DBus/Local", "org.freedesktop.DBus.Local", "Disconnected", OnBusGone, &front), "watch the system bus");
|
||||
ThrowOnSdBus(sd_bus_request_name(bus, name.data(), 0), std::format("own {}", name));
|
||||
ThrowOnSdBus(sd_bus_attach_event(bus, front.event, SD_EVENT_PRIORITY_NORMAL), std::format("serve {}", interface));
|
||||
ThrowOnSdBus(sd_bus_request_name(bus, busName.data(), 0), std::format("own {}", busName));
|
||||
ThrowOnSdBus(sd_bus_attach_event(bus, front.event, SD_EVENT_PRIORITY_NORMAL), std::format("serve {}", interfaceName));
|
||||
return owned;
|
||||
}
|
||||
}
|
||||
|
|
@ -331,10 +325,7 @@ std::int32_t Nostro::RunDaemon(const DaemonOptions& options) {
|
|||
ThrowOnSdBus(sd_event_add_signal(front.event, nullptr, SIGTERM, nullptr, nullptr), "watch for SIGTERM");
|
||||
|
||||
front.vtable = Vtable(methods, [](std::string_view) { return &Forward; });
|
||||
front.checkoutVtable = Vtable(checkoutMethods, [](std::string_view) { return &Forward; });
|
||||
// The main name last: systemd counts the service as started once it is owned, and by then both are.
|
||||
front.checkout = Serve(front, "nostrod checkout", Checkout::busName, Checkout::interfaceName, front.checkoutVtable);
|
||||
front.bus = Serve(front, "nostrod", busName, interfaceName, front.vtable);
|
||||
front.bus = Serve(front);
|
||||
ThrowOnSdBus(sd_event_add_time_relative(front.event, &front.idle, CLOCK_MONOTONIC, Microseconds(options.idle), 0, OnIdle, &front), "set the idle timer");
|
||||
|
||||
const std::int32_t result = sd_event_loop(front.event);
|
||||
|
|
@ -346,7 +337,6 @@ std::int32_t Nostro::RunDaemon(const DaemonOptions& options) {
|
|||
}
|
||||
front.workers.clear();
|
||||
front.bus.reset();
|
||||
front.checkout.reset();
|
||||
sd_event_source_unref(front.idle);
|
||||
sd_event_unref(front.event);
|
||||
ThrowOnSdBus(result, "run the event loop");
|
||||
|
|
|
|||
|
|
@ -213,6 +213,11 @@ namespace Nostro::App {
|
|||
} else {
|
||||
overview.state = LoadState::Loading;
|
||||
}
|
||||
// A link that waits for the accounts starts from the one chosen for pay links: where that could not be read
|
||||
// either, it is read again with them.
|
||||
if(waiting && checkout.state == LoadState::Failed) {
|
||||
LoadCheckout();
|
||||
}
|
||||
Fetch<std::vector<ConnectorSummary>>("overview", "Connectors", [](Client& bank, Client::Then<std::vector<ConnectorSummary>> then) { return bank.Connectors(std::move(then)); }, [this, again](Answer<std::vector<ConnectorSummary>> answer) {
|
||||
if(answer.Failed()) {
|
||||
OverviewFailed(Explain(answer.Error(), Operation::Load));
|
||||
|
|
@ -276,6 +281,10 @@ namespace Nostro::App {
|
|||
if(!Find(filtering)) {
|
||||
filtering.clear();
|
||||
}
|
||||
// A link's payment waited for this. Last, so that it finds the accounts and the pages as they now are.
|
||||
if(waiting) {
|
||||
TakeLink();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -400,10 +409,14 @@ namespace Nostro::App {
|
|||
if(answer.Failed()) {
|
||||
checkout.state = LoadState::Failed;
|
||||
checkout.problem = Explain(answer.Error(), Operation::Load);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
checkout.value = std::move(answer.Get());
|
||||
checkout.state = LoadState::Loaded;
|
||||
}
|
||||
// A link's payment starts from this account, and waited to hear which it is, or that it cannot be read.
|
||||
if(waiting) {
|
||||
TakeLink();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -575,6 +588,34 @@ namespace Nostro::App {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool App::Open(std::string_view link) {
|
||||
// Not from under a change, as no place is gone to from under one.
|
||||
if(changing) {
|
||||
return false;
|
||||
}
|
||||
Read<PaymentLink> read = ReadPaymentLink(link);
|
||||
if(!read.value) {
|
||||
// Said over wherever the user is, with nothing of the link in it: what a stranger wrote is not shown as
|
||||
// the app's own words. A link that waits is left waiting.
|
||||
Dialog problem;
|
||||
problem.kind = Dialog::Kind::Problem;
|
||||
problem.name = "link";
|
||||
problem.title = "This link cannot be opened";
|
||||
problem.text = {std::move(read.error)};
|
||||
problem.choices.push_back({"link.close", "Close", Ui::ButtonKind::Tonal, true, {}, [this] { Close(); }});
|
||||
Show(std::move(problem));
|
||||
return true;
|
||||
}
|
||||
Go(Place::Accounts);
|
||||
waiting = std::move(*read.value);
|
||||
// The form starts from the account the user chose for pay links to start from, so that is read if it was not.
|
||||
if(checkout.state == LoadState::Idle || checkout.state == LoadState::Failed) {
|
||||
LoadCheckout();
|
||||
}
|
||||
TakeLink();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string App::Screen() const {
|
||||
static constexpr std::array<std::string_view, 3> places = {"accounts", "cards", "settings"};
|
||||
// The three steps of adding a connection are one name, as far as it has been gone: "add:bunq:key".
|
||||
|
|
@ -624,6 +665,57 @@ namespace Nostro::App {
|
|||
Push(Page::Request);
|
||||
}
|
||||
|
||||
// Tried when a link is opened, and again as the accounts and the account pay links start from are read: it goes
|
||||
// ahead once both are known, or the second is known not to be readable. It is safe to try again: a reading that
|
||||
// fails at once, as one without a system bus does, has tried it already by the time whoever asked for the reading
|
||||
// tries it, and then no link waits any more.
|
||||
void App::TakeLink() {
|
||||
if(!waiting || overview.state != LoadState::Loaded || checkout.state == LoadState::Loading) {
|
||||
return;
|
||||
}
|
||||
const PaymentLink link = std::move(*waiting);
|
||||
waiting.reset();
|
||||
// The user went elsewhere while the accounts were read, or is being told something: what they are doing is not
|
||||
// taken from under them for what a link asks. The link is theirs to open again.
|
||||
if(place != Place::Accounts || !stack.empty() || dialog.has_value()) {
|
||||
Tell("The link's payment was not opened: open the link again");
|
||||
return;
|
||||
}
|
||||
// No bank connected, or none whose accounts could be read: there is nothing to pay from, and no form to show.
|
||||
if(Accounts().empty()) {
|
||||
Dialog none;
|
||||
none.kind = Dialog::Kind::Problem;
|
||||
none.name = "link";
|
||||
none.title = "No account to pay from";
|
||||
none.text = {"This link asks for a payment, and there is no account to pay it from. Once your bank is connected and its accounts show here, open the link again."};
|
||||
none.choices.push_back({"link.close", "Close", Ui::ButtonKind::Tonal, true, {}, [this] { Close(); }});
|
||||
Show(std::move(none));
|
||||
return;
|
||||
}
|
||||
// From the account the user chose in the settings for pay links to start from. Without one, from the first
|
||||
// whose connection pays anybody: one that pays between the user's own accounts only could do no more than
|
||||
// save a draft.
|
||||
std::string from;
|
||||
if(checkout.state == LoadState::Loaded && checkout.value && Find(AccountKey(*checkout.value))) {
|
||||
from = AccountKey(*checkout.value);
|
||||
} else {
|
||||
for(const AccountRef& account : Accounts()) {
|
||||
if(!account.connection->ownAccountsOnly) {
|
||||
from = account.key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
payment.Fill(link);
|
||||
OpenPay(std::move(from));
|
||||
// Which account pays is the user's to say, and a link is where that is asked rather than assumed: the form
|
||||
// opens with its choice of accounts over it, the one it starts from marked, and a tap beside the choice keeps
|
||||
// that one. With one account there is nothing to choose, and the form opens as it is.
|
||||
if(Accounts().size() > 1) {
|
||||
picking = Picking::PayFrom;
|
||||
}
|
||||
}
|
||||
|
||||
// The pay form's button: what is filled in is checked, and sent. The app asks nothing more itself: a payment, a
|
||||
// schedule and a draft are each confirmed in the system's password dialog, which nostrod words from its own data,
|
||||
// and a draft is not paid until it is accepted, which is confirmed there once more.
|
||||
|
|
@ -1010,8 +1102,8 @@ namespace Nostro::App {
|
|||
Change<std::string>(Operation::RemoveConnection, "RemoveConnector", std::format("Removing {}", name), {}, [connector](Client& bank, Client::Then<std::string> then) { return bank.RemoveConnector(connector, std::move(then)); }, [this](std::string& removed) {
|
||||
dialog.reset();
|
||||
Tell(std::format("Removed {}", removed));
|
||||
// Its cards and its say at checkout went with it: the cards are read when they are next looked at, the
|
||||
// checkout's account now, the settings being where connections are removed from.
|
||||
// Its cards went with it, and it may have held the account pay links start from: the cards are read
|
||||
// when they are next looked at, that account now, the settings being where connections are removed from.
|
||||
cards = {};
|
||||
LoadCheckout();
|
||||
Refresh();
|
||||
|
|
@ -1094,11 +1186,11 @@ namespace Nostro::App {
|
|||
}
|
||||
|
||||
void App::ChooseCheckout(const std::string& key, const std::string& name) {
|
||||
Change<Account>(Operation::SetCheckoutAccount, "SetDefaultCheckoutAccount", std::format("Letting apps ask you to pay from {}", name), {}, [key](Client& bank, Client::Then<Account> then) { return bank.SetDefaultCheckoutAccount(key, std::move(then)); }, [this](Account& chosen) {
|
||||
Change<Account>(Operation::SetCheckoutAccount, "SetDefaultCheckoutAccount", std::format("Having pay links start from {}", name), {}, [key](Client& bank, Client::Then<Account> then) { return bank.SetDefaultCheckoutAccount(key, std::move(then)); }, [this](Account& chosen) {
|
||||
checkout.value = chosen;
|
||||
checkout.state = LoadState::Loaded;
|
||||
dialog.reset();
|
||||
Tell(std::format("Apps now ask you to pay from {}", chosen.name));
|
||||
Tell(std::format("Pay links now start from {}", chosen.name));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,67 @@ namespace {
|
|||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// The most of a link that is read, in bytes, and of the name and the description in one, in characters: SEPA's
|
||||
// limits for the name of an account's holder and for what a payment is for, the second of which RFC 8905 gives for
|
||||
// an IBAN's message. A form's field shows what fits its width and no more: what is longer than a bank carries is
|
||||
// refused, not cut, since what is cut off is still sent. The system's password dialog shows less of a name than
|
||||
// this takes, 64 characters: nostrod cuts a longer one short there.
|
||||
constexpr std::size_t linkLimit = 4096;
|
||||
constexpr std::size_t nameLimit = 70;
|
||||
constexpr std::size_t messageLimit = 140;
|
||||
|
||||
bool Digits(std::string_view text) {
|
||||
return !text.empty() && std::ranges::all_of(text, [](char c) { return c >= '0' && c <= '9'; });
|
||||
}
|
||||
|
||||
bool Alphanumeric(std::string_view text) {
|
||||
return !text.empty() && std::ranges::all_of(text, [](char c) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); });
|
||||
}
|
||||
|
||||
// In small letters, as far as ASCII has them: a link's scheme and its options' names are in that.
|
||||
std::string Lowered(std::string_view text) {
|
||||
std::string lowered(text);
|
||||
for(char& c : lowered) {
|
||||
if(c >= 'A' && c <= 'Z') {
|
||||
c = static_cast<char>(c - 'A' + 'a');
|
||||
}
|
||||
}
|
||||
return lowered;
|
||||
}
|
||||
|
||||
// Whether every % in `text` begins an escape, two hex digits: UrlDecode leaves one that does not as it is, which
|
||||
// is a guess at what was meant.
|
||||
bool Escaped(std::string_view text) {
|
||||
const auto hex = [](char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); };
|
||||
for(std::size_t i = 0; i < text.size(); i++) {
|
||||
if(text[i] == '%' && !(i + 2 < text.size() && hex(text[i + 1]) && hex(text[i + 2]))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Whether `text` is fit to be a link's name or description: UTF-8 as the bus takes it, each character in its
|
||||
// shortest form and none that is no character, none that the system's password dialog leaves out as drawing
|
||||
// nothing or turning text around, and no space but the ordinary one. The toolkit's decoder takes a sequence longer
|
||||
// than its character needs, which reads as that character and is not valid: the bus refuses it, after the form
|
||||
// has shown it.
|
||||
bool Plain(std::string_view text) {
|
||||
for(std::size_t i = 0; i < text.size();) {
|
||||
const std::size_t at = i;
|
||||
const std::uint32_t code = Ui::DecodeUtf8(text, i);
|
||||
const std::size_t shortest = code < 0x80 ? 1 : code < 0x800 ? 2 : code < 0x10000 ? 3 : 4;
|
||||
// U+FFFD is what the decoder gives for bytes that are no character, and what text that was damaged before
|
||||
// it got here holds. The last two code points of every plane are no characters either, and sd-bus refuses
|
||||
// text with one as it does a sequence that is too long: Unshown has those of the first plane and of the
|
||||
// two planes of private use, not the rest.
|
||||
if(code == 0xFFFD || i - at != shortest || Unshown(code) || (Blank(code) && code != ' ') || (code & 0xFFFEU) == 0xFFFEU) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Read<std::int64_t> App::ReadAmount(std::string_view text, Currency currency) {
|
||||
|
|
@ -110,6 +171,103 @@ Read<std::uint32_t> App::ReadCount(std::string_view text) {
|
|||
return {count, {}};
|
||||
}
|
||||
|
||||
Read<PaymentLink> App::ReadPaymentLink(std::string_view link) {
|
||||
constexpr std::string_view scheme = "payto://iban/";
|
||||
constexpr std::string_view notOne = "It is not a link to pay an IBAN, which is the kind Nostro reads.";
|
||||
constexpr std::string_view damaged = "It is not written as such a link is: something in it is there twice, or cannot be read.";
|
||||
constexpr std::string_view unreadable = "The amount in it cannot be read.";
|
||||
// The scheme and the kind of account it pays may be in capitals. A # begins a part of an address that such a link
|
||||
// does not have.
|
||||
if(link.size() > linkLimit || link.contains('#') || Lowered(link.substr(0, scheme.size())) != scheme) {
|
||||
return {std::nullopt, std::string(notOne)};
|
||||
}
|
||||
const std::string_view rest = link.substr(scheme.size());
|
||||
const std::size_t question = rest.find('?');
|
||||
std::string_view path = rest.substr(0, question);
|
||||
// A bank's code may come before the IBAN, "payto://iban/ABNANL2A/NL91…". Nostro pays without one: it is held to
|
||||
// its shape and left out.
|
||||
if(const std::size_t slash = path.find('/'); slash != std::string_view::npos) {
|
||||
const std::string_view code = path.substr(0, slash);
|
||||
if(!Alphanumeric(code) || (code.size() != 8 && code.size() != 11)) {
|
||||
return {std::nullopt, std::string(notOne)};
|
||||
}
|
||||
path.remove_prefix(slash + 1);
|
||||
}
|
||||
// Letters and digits and nothing else: no escape that reads otherwise than it looks, and nothing ReadParty would
|
||||
// take for an e-mail address or a phone number. What is left is an IBAN whose check digits hold, or nothing.
|
||||
const Read<BunqCounterparty> party = Alphanumeric(path) ? ReadParty(path) : Read<BunqCounterparty>{};
|
||||
if(!party.value) {
|
||||
return {std::nullopt, "The IBAN in it is not a valid one."};
|
||||
}
|
||||
PaymentLink asked;
|
||||
asked.iban = party.value->value;
|
||||
|
||||
// The options are walked here, and not asked of the library's QueryParameter: that gives the first of a name that
|
||||
// is there twice, and takes a name's letters as they are written. A link is refused for the one, and its options
|
||||
// are known in capitals too.
|
||||
std::vector<std::string> said;
|
||||
const std::string_view options = question == std::string_view::npos ? std::string_view() : rest.substr(question + 1);
|
||||
for(const auto part : std::views::split(options, '&')) {
|
||||
const std::string_view option(part.begin(), part.end());
|
||||
const std::size_t equals = option.find('=');
|
||||
// An option's name as any reader of the link takes it, its escapes undone and in small letters: "AMOUNT" and
|
||||
// "%61mount" are the amount, so a link cannot say one amount to Nostro and another to whoever reads it next.
|
||||
const std::string name = Lowered(UrlDecode(option.substr(0, equals)));
|
||||
// The sender's name is the user's own to give, and what Nostro does not know may be a later version's.
|
||||
if(name != "amount" && name != "receiver-name" && name != "message" && name != "instruction") {
|
||||
continue;
|
||||
}
|
||||
if(std::ranges::contains(said, name)) {
|
||||
return {std::nullopt, std::string(damaged)};
|
||||
}
|
||||
said.push_back(name);
|
||||
// An instruction is for the payee's bank to pass on unchanged, which no bank Nostro pays through is asked to
|
||||
// do: RFC 8905 has a link refused whose instruction cannot be kept, rather than paid without it.
|
||||
if(name == "instruction") {
|
||||
return {std::nullopt, "It asks for a reference of a kind Nostro cannot send along."};
|
||||
}
|
||||
const std::string_view written = equals == std::string_view::npos ? std::string_view() : option.substr(equals + 1);
|
||||
if(!Escaped(written)) {
|
||||
return {std::nullopt, std::string(damaged)};
|
||||
}
|
||||
const std::string value = UrlDecode(written);
|
||||
if(name == "amount") {
|
||||
// "EUR:12.50": the currency, and digits with at most one point among them and digits on both sides of it.
|
||||
// No sign and no space. And no comma: RFC 8905 has a reader pass over commas, by which "EUR:12,50" is
|
||||
// twelve hundred and fifty, and whoever wrote that meant twelve and a half. It is refused, not guessed at.
|
||||
const std::size_t colon = value.find(':');
|
||||
const std::string_view sum = colon == std::string::npos ? std::string_view() : std::string_view(value).substr(colon + 1);
|
||||
const std::size_t point = sum.find('.');
|
||||
if(!Digits(sum.substr(0, point)) || (point != std::string_view::npos && !Digits(sum.substr(point + 1)))) {
|
||||
return {std::nullopt, std::string(unreadable)};
|
||||
}
|
||||
try {
|
||||
// The one currency there is. With a second one the form's amount, which is read in the paying account's
|
||||
// currency, has to be held to the link's as well.
|
||||
asked.currency = GetCurrency(std::string_view(value).substr(0, colon));
|
||||
} catch(const std::runtime_error&) {
|
||||
return {std::nullopt, "It asks for a currency Nostro does not pay in."};
|
||||
}
|
||||
// What the form itself refuses: nothing, more decimals than the currency has, more than it can hold.
|
||||
asked.amount = ReadAmount(sum, asked.currency).value;
|
||||
if(!asked.amount) {
|
||||
return {std::nullopt, std::string(unreadable)};
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(!Plain(value)) {
|
||||
return {std::nullopt, "The name or the description in it holds what a payment cannot carry."};
|
||||
}
|
||||
const std::string_view text = Trimmed(value);
|
||||
const bool message = name == "message";
|
||||
if(Ui::CountCodepoints(text) > (message ? messageLimit : nameLimit)) {
|
||||
return {std::nullopt, "The name or the description in it is too long."};
|
||||
}
|
||||
(message ? asked.description : asked.name) = std::string(text);
|
||||
}
|
||||
return {std::move(asked), {}};
|
||||
}
|
||||
|
||||
bool PaymentForm::Errors::Any() const noexcept {
|
||||
return !to.empty() || !name.empty() || !amount.empty() || !day.empty() || !time.empty() || !every.empty() || !until.empty();
|
||||
}
|
||||
|
|
@ -163,6 +321,17 @@ PaymentForm::Errors PaymentForm::Check(Currency currency, Moment now, PaymentOrd
|
|||
return errors;
|
||||
}
|
||||
|
||||
void PaymentForm::Fill(const PaymentLink& link) {
|
||||
Clear();
|
||||
to.Set(link.iban);
|
||||
name.Set(link.name);
|
||||
if(link.amount) {
|
||||
amount.Set(FormatAmount(*link.amount, link.currency));
|
||||
}
|
||||
description.Set(link.description);
|
||||
linked = true;
|
||||
}
|
||||
|
||||
void PaymentForm::Clear() {
|
||||
to.Clear();
|
||||
name.Clear();
|
||||
|
|
@ -175,6 +344,7 @@ void PaymentForm::Clear() {
|
|||
every.Clear();
|
||||
until.Clear();
|
||||
tried = false;
|
||||
linked = false;
|
||||
}
|
||||
|
||||
bool RequestForm::Errors::Any() const noexcept {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Nostro::App {
|
|||
return std::string(places[std::to_underlying(place)]);
|
||||
}
|
||||
const Route& top = stack.back();
|
||||
static constexpr std::array<std::string_view, 9> pages = {"Account", "Pay", "Request", "Bank connections", "Add a connection", "", "", "Pay at checkout", "About and security"};
|
||||
static constexpr std::array<std::string_view, 9> pages = {"Account", "Pay", "Request", "Bank connections", "Add a connection", "", "", "Pay links", "About and security"};
|
||||
std::string title(pages[std::to_underlying(top.page)]);
|
||||
// An account's page is called what the account is.
|
||||
if(const std::optional<AccountRef> account = Find(top.account)) {
|
||||
|
|
@ -238,6 +238,11 @@ namespace Nostro::App {
|
|||
|
||||
void App::HomePage(Ui::Frame& frame, Ui::Column& column) {
|
||||
const Theme& theme = frame.Colors();
|
||||
// A link's payment that waits for the accounts is said to, above whatever stands where they will be: its form
|
||||
// is not sprung on a user who was never told that one is coming.
|
||||
if(waiting) {
|
||||
column.Advance(Banner(frame, Padded(frame, column.Next()), {.key = "link", .text = "A link asks for a payment. Its form opens once your accounts have been read."}));
|
||||
}
|
||||
if(overview.state == LoadState::Failed) {
|
||||
Trouble(frame, column, overview.problem, "overview", [this] { Refresh(); });
|
||||
return;
|
||||
|
|
@ -456,6 +461,12 @@ namespace Nostro::App {
|
|||
}
|
||||
PaymentOrder unused;
|
||||
const PaymentForm::Errors errors = payment.tried ? payment.Check(currency, Today(), unused) : PaymentForm::Errors();
|
||||
// What a link filled in was chosen by whoever wrote the link, the payee and the amount among it. The form says
|
||||
// so for as long as it holds that, and that is all the app does about it: the form's button still sends, and
|
||||
// the system's password dialog still confirms.
|
||||
if(payment.linked) {
|
||||
column.Advance(Banner(frame, Padded(frame, column.Next()), {.key = "pay.linked", .kind = BannerKind::Warning, .text = "A link filled this in, not you. Check who is paid and how much."}));
|
||||
}
|
||||
AccountField(frame, column, "pay.from", "From", payFrom, Picking::PayFrom);
|
||||
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.to, {.key = "pay.to", .label = "To", .placeholder = "An IBAN, an e-mail address or a phone number", .error = errors.to, .helper = PartyKind(payment.to.value)}));
|
||||
column.Advance(TextField(frame, Padded(frame, column.Next()), payment.name, {.key = "pay.name", .label = "Name", .placeholder = "Who the account belongs to", .error = errors.name, .purpose = TextPurpose::Name}));
|
||||
|
|
@ -556,7 +567,9 @@ namespace Nostro::App {
|
|||
} else if(checkout.state == LoadState::Failed) {
|
||||
paying = checkout.problem.title;
|
||||
}
|
||||
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = "settings.checkout", .title = "Pay at checkout from", .subtitle = std::move(paying), .chevron = true, .onTap = [this] { Push(Page::Checkout); }});
|
||||
// The account a link's pay form starts from. Its names in the code are the wire's (DefaultCheckoutAccount), from
|
||||
// the checkout over D-Bus it was first chosen for.
|
||||
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = "settings.checkout", .title = "Pay links start from", .subtitle = std::move(paying), .chevron = true, .onTap = [this] { Push(Page::Checkout); }});
|
||||
ListRow(frame, column.Take(frame.Dp(Size::row)), {.key = "settings.about", .title = "About and security", .subtitle = host.version.empty() ? std::string("Nostro") : std::format("Nostro {}", host.version), .chevron = true, .onTap = [this] { Push(Page::About); }});
|
||||
}
|
||||
|
||||
|
|
@ -599,7 +612,7 @@ namespace Nostro::App {
|
|||
}
|
||||
|
||||
void App::CheckoutPage(Ui::Frame& frame, Ui::Column& column) {
|
||||
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "Other apps can ask Nostro to pay an order at their checkout. Every such payment still asks for your password, and says what is paid and to whom. This is the account they are paid from.", Body(frame)));
|
||||
column.Advance(Paragraph(frame, Padded(frame, column.Next()), "A shop's pay link opens Nostro with the payment filled in. This is the account its form starts from. You can choose another one when it opens, and nothing is paid before you press Pay and confirm it with your password.", Body(frame)));
|
||||
if(checkout.state == LoadState::Failed) {
|
||||
Trouble(frame, column, checkout.problem, "checkout.problem", [this] { LoadCheckout(); });
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,121 +0,0 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
module;
|
||||
|
||||
#include <systemd/sd-bus.h>
|
||||
#include <errno.h>
|
||||
|
||||
module Nostro.Checkout;
|
||||
import std;
|
||||
|
||||
using namespace Nostro;
|
||||
|
||||
Checkout::Error::Error(std::string name, const std::string& message) : std::runtime_error(message), name(std::move(name)) {
|
||||
}
|
||||
|
||||
namespace {
|
||||
// What sd-bus hands out, freed at the end of the scope.
|
||||
struct Connection {
|
||||
sd_bus* bus = nullptr;
|
||||
Connection() = default;
|
||||
Connection(const Connection&) = delete;
|
||||
Connection& operator=(const Connection&) = delete;
|
||||
~Connection() {
|
||||
sd_bus_flush_close_unref(bus);
|
||||
}
|
||||
};
|
||||
|
||||
struct Message {
|
||||
sd_bus_message* message = nullptr;
|
||||
Message() = default;
|
||||
Message(const Message&) = delete;
|
||||
Message& operator=(const Message&) = delete;
|
||||
~Message() {
|
||||
sd_bus_message_unref(message);
|
||||
}
|
||||
};
|
||||
|
||||
struct BusError {
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
BusError() = default;
|
||||
BusError(const BusError&) = delete;
|
||||
BusError& operator=(const BusError&) = delete;
|
||||
~BusError() {
|
||||
sd_bus_error_free(&error);
|
||||
}
|
||||
};
|
||||
|
||||
// Throws a std::system_error naming `what` when an sd-bus call returned a negative errno; returns the result.
|
||||
std::int32_t ThrowOn(std::int32_t result, std::string_view what) {
|
||||
if(result < 0) {
|
||||
throw std::system_error(-result, std::generic_category(), std::format("cannot {}", what));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// sd-bus hands strings out as C strings, the ones of an error possibly none.
|
||||
// lint-disable-next-line no-char-pointer
|
||||
std::string Text(const char* text) {
|
||||
return text ? std::string(text) : std::string();
|
||||
}
|
||||
|
||||
std::string ReadString(sd_bus_message* message) {
|
||||
// lint-disable-next-line no-char-pointer
|
||||
const char* text = nullptr;
|
||||
ThrowOn(sd_bus_message_read_basic(message, 's', &text), "read nostrod's answer");
|
||||
return Text(text);
|
||||
}
|
||||
}
|
||||
|
||||
Checkout::Paid Checkout::Pay(const Order& order, std::chrono::seconds timeout) {
|
||||
Connection connection;
|
||||
ThrowOn(sd_bus_open_system_with_description(&connection.bus, "nostro checkout"), "connect to the system bus");
|
||||
// The user confirms the order at a password prompt.
|
||||
ThrowOn(sd_bus_set_allow_interactive_authorization(connection.bus, 1), "connect to the system bus");
|
||||
Message call;
|
||||
ThrowOn(sd_bus_message_new_method_call(connection.bus, &call.message, busName.data(), objectPath.data(), interfaceName.data(), "Pay"), "call nostrod");
|
||||
// No options yet; a nostrod skips the ones it does not know, so adding one breaks no older nostrod.
|
||||
const std::int32_t appended = sd_bus_message_append(call.message, "ssxssa{sv}", order.payeeIban.c_str(), order.payeeName.c_str(), order.amount, order.currency.c_str(), order.reference.c_str(), 0u);
|
||||
if(appended == -EINVAL) {
|
||||
throw std::invalid_argument("text that is not UTF-8 cannot be sent to nostrod");
|
||||
}
|
||||
ThrowOn(appended, "call nostrod");
|
||||
|
||||
BusError error;
|
||||
Message reply;
|
||||
if(sd_bus_call(connection.bus, call.message, static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(timeout).count()), &error.error, &reply.message) < 0) {
|
||||
std::string name = Text(error.error.name);
|
||||
const std::string message = Text(error.error.message);
|
||||
if(name == errorCancelled) {
|
||||
throw Cancelled(std::move(name), message);
|
||||
}
|
||||
if(name == errorNoCheckoutAccount) {
|
||||
throw NoCheckoutAccount(std::move(name), message);
|
||||
}
|
||||
if(name == SD_BUS_ERROR_SERVICE_UNKNOWN) {
|
||||
throw Error(std::move(name), std::format("nostro is not installed, or the system bus cannot start it ({})", message));
|
||||
}
|
||||
if(name == SD_BUS_ERROR_NO_REPLY || name == SD_BUS_ERROR_TIMEOUT) {
|
||||
throw Error(std::move(name), std::format("nostrod did not answer in time ({}): the order may have been paid, and paying the same order again answers with its payment rather than paying twice", message));
|
||||
}
|
||||
throw Error(std::move(name), message);
|
||||
}
|
||||
|
||||
Paid paid;
|
||||
ThrowOn(sd_bus_message_read_basic(reply.message, 't', &paid.paymentId), "read nostrod's answer");
|
||||
// The results: a later nostrod may add to them, and what this one does not know it skips.
|
||||
ThrowOn(sd_bus_message_enter_container(reply.message, 'a', "{sv}"), "read nostrod's answer");
|
||||
while(ThrowOn(sd_bus_message_enter_container(reply.message, 'e', "sv"), "read nostrod's answer") > 0) {
|
||||
if(ReadString(reply.message) == "repeated") {
|
||||
std::int32_t repeated = 0;
|
||||
ThrowOn(sd_bus_message_read(reply.message, "v", "b", &repeated), "read nostrod's answer");
|
||||
paid.repeated = repeated != 0;
|
||||
} else {
|
||||
ThrowOn(sd_bus_message_skip(reply.message, "v"), "read nostrod's answer");
|
||||
}
|
||||
ThrowOn(sd_bus_message_exit_container(reply.message), "read nostrod's answer");
|
||||
}
|
||||
ThrowOn(sd_bus_message_exit_container(reply.message), "read nostrod's answer");
|
||||
return paid;
|
||||
}
|
||||
|
|
@ -62,6 +62,10 @@ namespace {
|
|||
Debug::Required<std::string> route;
|
||||
};
|
||||
|
||||
struct LinkArgs {
|
||||
Debug::Required<std::string> link;
|
||||
};
|
||||
|
||||
struct ThemeArgs {
|
||||
Debug::Required<std::string> scheme;
|
||||
};
|
||||
|
|
@ -329,6 +333,20 @@ void Debugger::Register() {
|
|||
}
|
||||
return {};
|
||||
});
|
||||
// The app's own path for a link, the one the program's argument takes: a debugger opens one in a window that is
|
||||
// already there, which no browser can.
|
||||
Debug::Command("App_Open", "Open a payment link as the app does one it is started with: payto://iban/<IBAN>?amount=EUR:12.50&receiver-name=<name>&message=<what for>. The pay form opens filled in once the accounts are known, under the choice of the account that pays where there is more than one (wait 'app.screen == \"pay+accounts\"', or 'app.screen == \"pay\"' with a single account); a link the app cannot read gets a sheet saying why (app.screen ends in +link). Nothing is sent.", [this](const LinkArgs& args) -> Debug::Result<> {
|
||||
if(targets.app == nullptr) {
|
||||
return Debug::Error{"NoApp", "the toolkit's gallery is shown, not the app; start without --gallery"};
|
||||
}
|
||||
if(Debug::Result<> ready = Ready(); !ready) {
|
||||
return ready;
|
||||
}
|
||||
if(!targets.app->Open(*args.link)) {
|
||||
return Debug::Error{"Changing", "a change is under way, which the screen waits out; wait 'app.changing == false' first"};
|
||||
}
|
||||
return {};
|
||||
});
|
||||
|
||||
// -- what can be read ----------------------------------------------------------------------------------------
|
||||
Debug::Watch("ui.regions", [this, &context, scale] {
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ namespace {
|
|||
nostro draft <account> <to> <name> <amount> [description]
|
||||
nostro drafts <account> [accept|reject <id>]
|
||||
nostro cards [freeze|unfreeze|lost|stolen <card id>]
|
||||
nostro checkout account [<account>] the account apps may ask you to pay from at checkout
|
||||
nostro checkout account [<account>] the account a pay link's form starts from in the Nostro app
|
||||
|
||||
<account> is an account's name or IBAN. <to> and <from> are an IBAN, an e-mail address, or a phone number
|
||||
starting with +. Amounts are in the smallest unit of the account's currency: 1250 is 12.50. Dates are
|
||||
YYYY-MM-DD or "YYYY-MM-DD hh:mm", in local time. A sandbox API key is recognised by its prefix.
|
||||
nostrod does the work, and asks for your password before it pays or changes anything, a checkout included.)";
|
||||
nostrod does the work, and asks for your password before it pays or changes anything.)";
|
||||
|
||||
// Positional arguments, with "--name value" options (and the "--sandbox" and "--help" flags) taken out wherever they are.
|
||||
struct Arguments {
|
||||
|
|
@ -311,18 +311,20 @@ nostrod does the work, and asks for your password before it pays or changes anyt
|
|||
std::println("card {} is now {}", id, card.status);
|
||||
}
|
||||
|
||||
// Apps pay at checkout from one account, and the user confirms each payment with their password.
|
||||
// The account a shop's pay link is paid from to begin with: where the Nostro app's pay form starts when a
|
||||
// payto:// link opens it. A choice kept for the user and no more: the form changes it, and nothing is paid from it
|
||||
// without the user's press and password.
|
||||
void CheckoutAccount(Client& client, const Arguments& args) {
|
||||
const std::string_view verb = args.At(1, "checkout command");
|
||||
if(verb != "account") {
|
||||
throw std::invalid_argument(std::format("unknown checkout command '{}'", verb));
|
||||
}
|
||||
if(args.positional.size() > 2) {
|
||||
std::println("checkouts pay from {}", client.SetDefaultCheckoutAccount(args.positional[2]));
|
||||
std::println("pay links start from {}", client.SetDefaultCheckoutAccount(args.positional[2]));
|
||||
} else if(const std::optional<Account> chosen = client.DefaultCheckoutAccount()) {
|
||||
std::println("{}", *chosen);
|
||||
} else {
|
||||
std::println("no account pays at checkout: `nostro checkout account <account>` chooses one");
|
||||
std::println("no account is chosen for pay links to start from: `nostro checkout account <account>` chooses one");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@
|
|||
// fonts, the toolkit's Context, the desktop portal, the app (Nostro.App) and the window that shows it.
|
||||
// nostro-app [--size <width>x<height>] [--scale <scale>] [--theme light|dark] [--route <place>] [--verbose]
|
||||
// [--screenshot <file.png>] [--screenshot-after <seconds>] [--poke <script>] [--quit-after <seconds>]
|
||||
// [--gallery <widgets|list|text>]
|
||||
// [--gallery <widgets|list|text>] [<link>]
|
||||
// A link is a payment to make, "payto://iban/NL91…?amount=EUR:12.50&receiver-name=…&message=…", as the desktop hands
|
||||
// one on from a website's pay button (the desktop entry's %u): the app opens its pay form filled in, and sends nothing
|
||||
// by itself. The window decides nothing about it: the link goes to the app as it came (App::Open).
|
||||
// --size is in dp and holds where the compositor leaves the size to the app. --route starts on a place of the app:
|
||||
// accounts, cards, settings, connections, checkout, about, account:<IBAN>, or a step of adding a connection: add,
|
||||
// add:<bank> or add:<bank>:<way>, as in add:bunq:key. The rest is for looking at the window without a hand on it.
|
||||
|
|
@ -474,6 +477,7 @@ int main(int argc, char* argv[]) {
|
|||
float screenshotAfter = 1;
|
||||
std::optional<float> quitAfter;
|
||||
std::string route;
|
||||
std::string link;
|
||||
std::string galleryPlace;
|
||||
std::string poke;
|
||||
bool verbose = false;
|
||||
|
|
@ -508,10 +512,24 @@ int main(int argc, char* argv[]) {
|
|||
poke = value(++i);
|
||||
} else if(args[i] == "--verbose") {
|
||||
verbose = true;
|
||||
} else if(!args[i].starts_with('-') && link.empty()) {
|
||||
// What is no option is a link to open. It says who is to be paid, how much and what for, and a command
|
||||
// line is there for every local user to read for as long as the program runs, and is what polkit
|
||||
// writes to its log of who asked for a password. So it is taken off it once it is kept: the bytes of
|
||||
// this argument are the program's own to overwrite. What started the program may still show it, as
|
||||
// the sandbox of a Flatpak does its command.
|
||||
link = args[i];
|
||||
std::fill_n(argv[i + 1], link.size(), '\0');
|
||||
} else if(!args[i].starts_with('-')) {
|
||||
// Neither this nor the next names what was given: a link is not for the log.
|
||||
throw std::invalid_argument("a second link was given: one is opened at a time");
|
||||
} else {
|
||||
throw std::invalid_argument(std::format("unknown argument '{}'", args[i]));
|
||||
}
|
||||
}
|
||||
if(!link.empty() && (!route.empty() || !galleryPlace.empty())) {
|
||||
throw std::invalid_argument("a link goes to its own place of the app: it is not opened with --route or --gallery");
|
||||
}
|
||||
options.assets = AssetDirectory();
|
||||
options.cache = CacheDirectory();
|
||||
|
||||
|
|
@ -616,6 +634,11 @@ int main(int argc, char* argv[]) {
|
|||
if(!route.empty() && app->Navigate(route)) {
|
||||
route.clear();
|
||||
}
|
||||
// The link the program was started with. The app reads it, and opens its form once it knows the
|
||||
// accounts: nothing is waited for or decided here.
|
||||
if(!link.empty()) {
|
||||
app->Open(link);
|
||||
}
|
||||
}
|
||||
window->Start();
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ export module Nostro:Bus;
|
|||
#ifdef NOSTRO_DBUS_ENABLED
|
||||
|
||||
import std;
|
||||
import Nostro.Checkout;
|
||||
import :Account;
|
||||
import :Bunq;
|
||||
import :Currency;
|
||||
|
|
@ -64,14 +63,12 @@ export namespace Nostro::Bus {
|
|||
inline constexpr std::string_view objectPath = "/net/catcrafts/Nostro1";
|
||||
inline constexpr std::string_view interfaceName = "net.catcrafts.Nostro1";
|
||||
|
||||
// What nostrod answers with besides the standard AccessDenied and InteractiveAuthorizationRequired. The ones an app
|
||||
// at checkout tells apart too are Nostro.Checkout's.
|
||||
inline constexpr std::string_view errorInvalidArgument = Checkout::errorInvalidArgument; // refused before anything was sent
|
||||
inline constexpr std::string_view errorBank = Checkout::errorBank; // the bank answered with an error
|
||||
// What nostrod answers with besides the standard AccessDenied and InteractiveAuthorizationRequired.
|
||||
inline constexpr std::string_view errorInvalidArgument = "net.catcrafts.Nostro1.Error.InvalidArgument"; // refused before anything was sent
|
||||
inline constexpr std::string_view errorBank = "net.catcrafts.Nostro1.Error.Bank"; // the bank answered with an error
|
||||
inline constexpr std::string_view errorOAuthCannotPay = "net.catcrafts.Nostro1.Error.OAuthCannotPay"; // bunq refused to pay through an OAuth connector
|
||||
inline constexpr std::string_view errorCancelled = Checkout::errorCancelled; // the user did not authenticate at the prompt
|
||||
inline constexpr std::string_view errorNoCheckoutAccount = Checkout::errorNoCheckoutAccount; // a checkout, and no account chosen to pay it
|
||||
inline constexpr std::string_view errorFailed = Checkout::errorFailed; // anything else
|
||||
inline constexpr std::string_view errorCancelled = "net.catcrafts.Nostro1.Error.Cancelled"; // the user did not authenticate at the prompt
|
||||
inline constexpr std::string_view errorFailed = "net.catcrafts.Nostro1.Error.Failed"; // anything else
|
||||
|
||||
// The polkit actions, declared in packaging/system/net.catcrafts.Nostro1.policy.
|
||||
inline constexpr std::string_view actionView = "net.catcrafts.Nostro1.View";
|
||||
|
|
@ -80,7 +77,6 @@ export namespace Nostro::Bus {
|
|||
inline constexpr std::string_view actionUnfreezeCard = "net.catcrafts.Nostro1.UnfreezeCard";
|
||||
inline constexpr std::string_view actionBlockCard = "net.catcrafts.Nostro1.BlockCard";
|
||||
inline constexpr std::string_view actionConnectors = "net.catcrafts.Nostro1.Connectors";
|
||||
inline constexpr std::string_view actionCheckout = "net.catcrafts.Nostro1.Checkout";
|
||||
}
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
|
@ -121,18 +117,11 @@ namespace Nostro::Bus {
|
|||
Method{"SetDefaultCheckoutAccount", "s", "(ssssx)as", "account\0chosen\0notes\0"sv},
|
||||
};
|
||||
|
||||
// net.catcrafts.Nostro1.Checkout, which nostrod serves under a bus name of its own (Checkout::busName). Its reply
|
||||
// carries no notes: they are the user's, and the app that asks is someone else.
|
||||
inline constexpr std::array checkoutMethods = {
|
||||
Method{"Pay", Checkout::payArguments, Checkout::payReply, Checkout::payNames},
|
||||
};
|
||||
|
||||
// Throws a std::system_error naming `what` when an sd-bus call returned a negative errno; returns the result.
|
||||
std::int32_t ThrowOnSdBus(std::int32_t result, std::string_view what);
|
||||
|
||||
// The header fields and error texts sd-bus hands out as C strings, as strings: empty when there are none.
|
||||
std::string Sender(sd_bus_message* message);
|
||||
std::string Interface(sd_bus_message* message);
|
||||
std::string Member(sd_bus_message* message);
|
||||
std::string ErrorName(const sd_bus_error& error);
|
||||
std::string ErrorMessage(const sd_bus_error& error);
|
||||
|
|
@ -160,8 +149,8 @@ namespace Nostro::Bus {
|
|||
~Error();
|
||||
};
|
||||
|
||||
// A vtable of every method of `table` (methods or checkoutMethods), all of them unprivileged (polkit decides, not
|
||||
// sd-bus), each handled by `handler(member)`. It must outlive the object it is registered for.
|
||||
// A vtable of every method of `table`, all of them unprivileged (polkit decides, not sd-bus), each handled by
|
||||
// `handler(member)`. It must outlive the object it is registered for.
|
||||
std::vector<sd_bus_vtable> Vtable(std::span<const Method> table, const std::function<sd_bus_message_handler_t(std::string_view member)>& handler);
|
||||
|
||||
// Enters a container, or throws when the message holds something else there.
|
||||
|
|
|
|||
|
|
@ -154,7 +154,9 @@ namespace Nostro {
|
|||
BunqCard SetCardStatus(std::uint64_t card, std::string_view status);
|
||||
[[nodiscard]] Pending SetCardStatus(std::uint64_t card, std::string_view status, Then<BunqCard> then);
|
||||
|
||||
// The account apps' checkouts (Nostro.Checkout) pay from: none until one is chosen, or once it is gone.
|
||||
// The account a pay link's form starts from in the app: none until one is chosen, or once it is gone. It is
|
||||
// where that form starts and no more; nostrod pays nothing from it by itself. The name is from what it was
|
||||
// until 2026-11-22: the account that paid an app's order at a checkout over D-Bus, which went that day.
|
||||
std::optional<Account> DefaultCheckoutAccount();
|
||||
[[nodiscard]] Pending DefaultCheckoutAccount(Then<std::optional<Account>> then);
|
||||
// Chooses it, and returns it. An account reached through OAuth cannot pay a shop, and is refused.
|
||||
|
|
|
|||
|
|
@ -172,6 +172,41 @@ export namespace Nostro {
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Whether a code point draws nothing, or tells the reader's own text where to go: control and format characters,
|
||||
// the line and paragraph separators, what Unicode leaves out of a display by default (soft hyphens, joiners,
|
||||
// fillers, variation selectors, tags), surrogates, private use, and what is no character at all. nostrod keeps a
|
||||
// password dialog free of them, and the app refuses a link whose name or description holds one.
|
||||
constexpr bool Unshown(std::uint32_t code) noexcept {
|
||||
using Range = std::pair<std::uint32_t, std::uint32_t>;
|
||||
static constexpr std::array<Range, 31> ranges = {{
|
||||
{0x0000, 0x001F}, {0x007F, 0x009F}, {0x00AD, 0x00AD}, {0x034F, 0x034F}, {0x0600, 0x0605}, {0x061C, 0x061C}, {0x06DD, 0x06DD}, {0x070F, 0x070F},
|
||||
{0x0890, 0x0891}, {0x08E2, 0x08E2}, {0x115F, 0x1160}, {0x17B4, 0x17B5}, {0x180B, 0x180F}, {0x200B, 0x200F}, {0x2028, 0x202E}, {0x2060, 0x206F},
|
||||
{0x3164, 0x3164}, {0xD800, 0xF8FF}, {0xFDD0, 0xFDEF}, {0xFE00, 0xFE0F}, {0xFEFF, 0xFEFF}, {0xFFA0, 0xFFA0}, {0xFFF0, 0xFFFC}, {0xFFFE, 0xFFFF},
|
||||
{0x110BD, 0x110BD}, {0x110CD, 0x110CD}, {0x13430, 0x1343F}, {0x1BCA0, 0x1BCA3}, {0x1D173, 0x1D17A}, {0xE0000, 0xE0FFF}, {0xF0000, 0xFFFFFFFF},
|
||||
}};
|
||||
for(const Range& range : ranges) {
|
||||
if(code >= range.first && code <= range.second) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Whether a code point is a space of any width, the ordinary one among them, or the Braille pattern without a dot,
|
||||
// which is one to the eye.
|
||||
constexpr bool Blank(std::uint32_t code) noexcept {
|
||||
using Range = std::pair<std::uint32_t, std::uint32_t>;
|
||||
static constexpr std::array<Range, 8> ranges = {{
|
||||
{0x0020, 0x0020}, {0x00A0, 0x00A0}, {0x1680, 0x1680}, {0x2000, 0x200A}, {0x202F, 0x202F}, {0x205F, 0x205F}, {0x2800, 0x2800}, {0x3000, 0x3000},
|
||||
}};
|
||||
for(const Range& range : ranges) {
|
||||
if(code >= range.first && code <= range.second) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Where the library's warnings go: a connector that could not be refreshed, an account it skipped, a request made
|
||||
// but not read back. A line on stderr unless the program replaces it; a daemon sends them to the client that made
|
||||
// the call instead, as on stderr they would only reach its journal.
|
||||
|
|
|
|||
|
|
@ -105,6 +105,15 @@ export namespace Nostro::App {
|
|||
// "add:<bank>:<way>" for a way's form, as in "add:bunq:key". False for a name that is none of them, and while
|
||||
// a change is under way, which the screen waits out.
|
||||
bool Navigate(std::string_view route);
|
||||
// Opens a link the program was started with, as a browser hands one on from a website's pay button: a payment
|
||||
// to make, which ReadPaymentLink reads. Its pay form opens filled in once the accounts are known, with the
|
||||
// choice of which account pays over it where there is more than one, starting from the account the user
|
||||
// chose for pay links where they chose one; until then the accounts' page says that it will. That is all a
|
||||
// link does.
|
||||
// Nothing is sent before the user presses the form's button, and the system's password dialog confirms it as
|
||||
// it does any payment: there is no say in a link. One that cannot be read is said to be so, with why. False
|
||||
// while a change is under way, which the screen waits out.
|
||||
bool Open(std::string_view link);
|
||||
// Where the user is, as a name of the same kind, with what is open over it after a '+': "account:NL…+filter".
|
||||
std::string Screen() const;
|
||||
// The connections and accounts as they are known.
|
||||
|
|
@ -127,7 +136,7 @@ export namespace Nostro::App {
|
|||
Banks, // adding a connection: the banks to choose from
|
||||
Ways, // the ways to connect to the bank that was chosen
|
||||
Connect, // the form of the way that was chosen
|
||||
Checkout,
|
||||
Checkout, // the account pay links start from: named, as its route is, after the wire's DefaultCheckoutAccount
|
||||
About
|
||||
};
|
||||
struct Route {
|
||||
|
|
@ -251,6 +260,8 @@ export namespace Nostro::App {
|
|||
// -- what the user asks for ----------------------------------------------------------------------------------
|
||||
void OpenPay(std::string account);
|
||||
void OpenRequest(std::string account);
|
||||
// The pay form for the link that waits, once what it starts from has been read.
|
||||
void TakeLink();
|
||||
void SubmitPayment();
|
||||
void SendPayment(const std::string& key, Currency currency, const PaymentOrder& order);
|
||||
void SubmitRequest();
|
||||
|
|
@ -323,6 +334,7 @@ export namespace Nostro::App {
|
|||
Loadable<std::vector<Connection>> overview;
|
||||
std::map<std::string, AccountData, std::less<>> accounts;
|
||||
Loadable<std::vector<ConnectorCards>> cards;
|
||||
// The account a link's pay form starts from, where the user chose one (nostrod's DefaultCheckoutAccount).
|
||||
Loadable<std::optional<Account>> checkout;
|
||||
|
||||
Place place = Place::Accounts;
|
||||
|
|
@ -333,6 +345,9 @@ export namespace Nostro::App {
|
|||
|
||||
PaymentForm payment;
|
||||
std::string payFrom;
|
||||
// A link that was read, whose pay form opens once the accounts are known. It is kept apart from the form until
|
||||
// then: a form that holds what a link said is shown as a link's, never found filled in later.
|
||||
std::optional<PaymentLink> waiting;
|
||||
RequestForm request;
|
||||
std::string requestInto;
|
||||
BunqKeyForm bunqKey;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import Nostro.Ui;
|
|||
// whole: each field's error is a line for under that field, and a form without errors gives an order, the values
|
||||
// nostrod is asked with. Nothing here talks to nostrod; nostrod checks everything again. The forms a payment, a
|
||||
// request and a filter are filled in on are any bank's; what a bank asks for to be connected is its own, and so is
|
||||
// the form for it, named for its bank.
|
||||
// the form for it, named for its bank. A form can also be filled in by a link, which is read here too: more strictly
|
||||
// than anything typed, since whoever wrote it is a stranger.
|
||||
|
||||
export namespace Nostro::App {
|
||||
// What a field's text was read as, or why it could not be.
|
||||
|
|
@ -33,6 +34,27 @@ export namespace Nostro::App {
|
|||
// A whole number above zero.
|
||||
Read<std::uint32_t> ReadCount(std::string_view text);
|
||||
|
||||
// A payment a link asks for, as a website's pay button hands one on to whichever program pays: who is paid, and
|
||||
// what the link says of how much and what for.
|
||||
struct PaymentLink {
|
||||
std::string iban; // in capitals and without spaces, its check digits verified
|
||||
std::string name; // the account's holder; empty when the link names nobody
|
||||
std::optional<std::int64_t> amount; // in the currency's smallest unit; none: the user says how much
|
||||
Currency currency = Currency::Euro;
|
||||
std::string description;
|
||||
};
|
||||
// Reads a link of RFC 8905, "payto://iban/NL91…?amount=EUR:12.50&receiver-name=…&message=…": the IBAN, with a
|
||||
// bank's code before it or not, and of its options the amount, the holder's name and what the payment is for.
|
||||
// An option it does not know is passed over, so that the format can grow. Everything else that is not as it
|
||||
// should be is refused: a link is a stranger's text, and what comes of it is put before the user as a payment to
|
||||
// make. So it has one IBAN that checks out, each thing said once, an amount written in one way only, and a name
|
||||
// and a description of plain text: nothing in them that would hide, turn text around or break a line, and no
|
||||
// space other than the plain one, so the name on the form is the name the bank gets. The system's password dialog
|
||||
// shows the name the way nostrod makes any name fit: cut at 64 characters, with &, < and > replaced, and after the
|
||||
// IBAN, which it shows whole. The error says what is wrong in words of the app's own, with nothing of the link in
|
||||
// them.
|
||||
Read<PaymentLink> ReadPaymentLink(std::string_view link);
|
||||
|
||||
// How often a scheduled payment runs, as the form offers it and as nostrod is told it.
|
||||
struct ScheduleUnit {
|
||||
std::string_view label;
|
||||
|
|
@ -70,6 +92,8 @@ export namespace Nostro::App {
|
|||
Ui::EditState until{Ui::FieldKind::Plain};
|
||||
// Errors show once the user has tried to go on: an empty form is not a list of mistakes.
|
||||
bool tried = false;
|
||||
// A link filled it in, not the user: the form says so for as long as it holds what the link put there.
|
||||
bool linked = false;
|
||||
|
||||
struct Errors {
|
||||
std::string to;
|
||||
|
|
@ -83,6 +107,9 @@ export namespace Nostro::App {
|
|||
};
|
||||
// Every field's error, and into `order` what the form asks for when there is none.
|
||||
Errors Check(Currency currency, std::chrono::system_clock::time_point now, PaymentOrder& order) const;
|
||||
// Puts what a link asks for in place of whatever the form held. It is a form filled in and no more: the user
|
||||
// can change every field, and nothing is sent until they press its button.
|
||||
void Fill(const PaymentLink& link);
|
||||
void Clear();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
export module Nostro.Checkout;
|
||||
import std;
|
||||
|
||||
// Checkout: how a shop app has the user's nostro pay an order, and nothing else of nostro. nostrod pays the order from
|
||||
// the account the user chose for checkouts, once the user has confirmed it at a password prompt that shows the order and
|
||||
// that account; the app never names nor sees an account, and learns only the payment's id. A module of its own, so
|
||||
// `--product=checkout` builds it without nostro's bank code, OpenSSL, Crafter.Network or Crafter.DB: it needs libsystemd
|
||||
// alone. Apps in other languages use packaging/dbus/net.catcrafts.Nostro1.Checkout.xml instead.
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
export namespace Nostro::Checkout {
|
||||
// String views of literals, so `.data()` is NUL-terminated as sd-bus wants it.
|
||||
inline constexpr std::string_view busName = "net.catcrafts.Nostro1.Checkout";
|
||||
inline constexpr std::string_view objectPath = "/net/catcrafts/Nostro1";
|
||||
inline constexpr std::string_view interfaceName = "net.catcrafts.Nostro1.Checkout";
|
||||
|
||||
// Pay(payeeIban, payeeName, amount, currency, reference, options) -> (paymentId, results): the arguments' signature,
|
||||
// the reply's, and their names, each ended by a NUL.
|
||||
inline constexpr std::string_view payArguments = "ssxssa{sv}";
|
||||
inline constexpr std::string_view payReply = "ta{sv}";
|
||||
inline constexpr std::string_view payNames = "payeeIban\0payeeName\0amount\0currency\0reference\0options\0paymentId\0results\0"sv;
|
||||
|
||||
// The errors an app tells apart, besides org.freedesktop.DBus.Error.AccessDenied (the system's policy refused),
|
||||
// ServiceUnknown (no nostro) and InteractiveAuthorizationRequired. nostrod's other interface uses the same names.
|
||||
inline constexpr std::string_view errorCancelled = "net.catcrafts.Nostro1.Error.Cancelled"; // the user did not confirm: nothing was paid
|
||||
inline constexpr std::string_view errorNoCheckoutAccount = "net.catcrafts.Nostro1.Error.NoCheckoutAccount"; // the user has no account to pay checkouts from
|
||||
inline constexpr std::string_view errorInvalidArgument = "net.catcrafts.Nostro1.Error.InvalidArgument"; // refused before anything was paid
|
||||
inline constexpr std::string_view errorBank = "net.catcrafts.Nostro1.Error.Bank"; // the bank refused
|
||||
inline constexpr std::string_view errorFailed = "net.catcrafts.Nostro1.Error.Failed"; // anything else
|
||||
|
||||
// An order to pay.
|
||||
struct Order {
|
||||
std::string payeeIban; // who is paid: an IBAN, the only kind of payee checkout pays
|
||||
std::string payeeName; // their name, as the bank and the prompt show it
|
||||
std::int64_t amount = 0; // in the currency's smallest unit: 1250 is 12.50
|
||||
std::string currency = "EUR"; // ISO 4217
|
||||
std::string reference; // the order's own number: the payment's description, and what tells orders apart
|
||||
};
|
||||
|
||||
// What became of an order.
|
||||
struct Paid {
|
||||
std::uint64_t paymentId = 0; // the bank's id of the payment
|
||||
bool repeated = false; // paid before, by an earlier call with the same order: nothing was paid now
|
||||
};
|
||||
|
||||
// An error nostrod answered with, by its D-Bus name: errorBank, org.freedesktop.DBus.Error.AccessDenied, ...
|
||||
struct Error : std::runtime_error {
|
||||
std::string name;
|
||||
Error(std::string name, const std::string& message);
|
||||
};
|
||||
|
||||
// The user did not confirm the order: nothing was paid.
|
||||
struct Cancelled : Error {
|
||||
using Error::Error;
|
||||
};
|
||||
|
||||
// The user has no account to pay checkouts from (`nostro checkout account <account>` chooses one): nothing was paid.
|
||||
struct NoCheckoutAccount : Error {
|
||||
using Error::Error;
|
||||
};
|
||||
|
||||
// Has the user's nostro pay `order`, and waits for it: for nostrod to start, for the user to read the order and
|
||||
// confirm it with their password, and for the bank, up to `timeout`; so call it off the UI thread. An order is paid
|
||||
// once: the same payee and reference again, after a timeout or a crash, answers with the first payment
|
||||
// (Paid::repeated), or waits for it while the user is still at the prompt, and the same reference with another
|
||||
// amount is refused. Throws Cancelled, NoCheckoutAccount, std::invalid_argument for text that is not UTF-8, and
|
||||
// Error for the rest; an Error named org.freedesktop.DBus.Error.ServiceUnknown means nostro is not installed.
|
||||
Paid Pay(const Order& order, std::chrono::seconds timeout = std::chrono::minutes(10));
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
# Build in this directory: makepkg -si
|
||||
pkgname=nostro-system
|
||||
pkgver=0.1.0
|
||||
pkgrel=1
|
||||
pkgrel=2
|
||||
pkgdesc="System files for nostro, a banking client for Linux whose daemon runs from a Flatpak"
|
||||
arch=(any)
|
||||
license=(LGPL-3.0-only)
|
||||
|
|
@ -19,10 +19,8 @@ package() {
|
|||
install -Dm644 "$system/nostro.sysusers" "$pkgdir/usr/lib/sysusers.d/nostro.conf"
|
||||
install -Dm644 "$system/net.catcrafts.Nostro1.conf" "$pkgdir/usr/share/dbus-1/system.d/net.catcrafts.Nostro1.conf"
|
||||
install -Dm644 "$system/net.catcrafts.Nostro1.service" "$pkgdir/usr/share/dbus-1/system-services/net.catcrafts.Nostro1.service"
|
||||
install -Dm644 "$system/net.catcrafts.Nostro1.Checkout.service" "$pkgdir/usr/share/dbus-1/system-services/net.catcrafts.Nostro1.Checkout.service"
|
||||
install -Dm644 "$system/net.catcrafts.Nostro1.policy" "$pkgdir/usr/share/polkit-1/actions/net.catcrafts.Nostro1.policy"
|
||||
install -Dm644 "$system/nostrod.service" "$pkgdir/usr/lib/systemd/system/nostrod.service"
|
||||
install -Dm755 "$system/nostro" "$pkgdir/usr/bin/nostro"
|
||||
install -Dm644 "$startdir/../dbus/net.catcrafts.Nostro1.xml" "$pkgdir/usr/share/dbus-1/interfaces/net.catcrafts.Nostro1.xml"
|
||||
install -Dm644 "$startdir/../dbus/net.catcrafts.Nostro1.Checkout.xml" "$pkgdir/usr/share/dbus-1/interfaces/net.catcrafts.Nostro1.Checkout.xml"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<!-- SPDX-License-Identifier: LGPL-3.0-only -->
|
||||
<!-- SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® -->
|
||||
<!-- nostro's checkout: how an app has the user's nostro pay an order. The bus name net.catcrafts.Nostro1.Checkout on
|
||||
the system bus, at /net/catcrafts/Nostro1; a Flatpak app asks for it with the finish-arg
|
||||
system-talk-name=net.catcrafts.Nostro1.Checkout. C++ programs can use the module Nostro.Checkout (nostro built with
|
||||
product=checkout) instead. A test in nostro keeps this file the interface nostrod serves.
|
||||
|
||||
Pay(payeeIban, payeeName, amount, currency, reference, options) returns (paymentId, results)
|
||||
payeeIban who is paid: an IBAN, the only payee checkout pays
|
||||
payeeName their name, as the bank and the prompt show it
|
||||
amount in the currency's smallest unit (1250 is 12.50), more than zero
|
||||
currency an ISO code: "EUR"
|
||||
reference the order's own number, not empty: the payment's description, and what tells orders apart
|
||||
options none yet; keys nostrod does not know are ignored
|
||||
paymentId the paying bank's id of the payment
|
||||
results repeated (b): the order was paid by an earlier call, and nothing was paid now. Later versions may
|
||||
add keys: ignore the ones you do not know.
|
||||
|
||||
nostrod pays the order from the account the user chose for checkouts (nostro checkout account), once the user has
|
||||
confirmed it at a password prompt that shows the amount, the payee, the reference and that account. The app never
|
||||
names nor sees the account. Allow interactive authorization on the call, make it asynchronously, and give it a
|
||||
timeout of minutes: the user may take a while.
|
||||
|
||||
An order is paid once. Pay with the same payeeIban and reference again, after a timeout or a crash, answers with
|
||||
the first payment (repeated is true) without asking the user, or waits for the first call while the user is still
|
||||
at the prompt; the same reference with another amount is refused. A payment id is not a receipt: confirm the money
|
||||
arrived with your own bank.
|
||||
|
||||
Errors:
|
||||
net.catcrafts.Nostro1.Error.Cancelled the user did not confirm: nothing was paid
|
||||
net.catcrafts.Nostro1.Error.NoCheckoutAccount the user has no account chosen to pay checkouts from: nothing was paid
|
||||
net.catcrafts.Nostro1.Error.InvalidArgument the order was refused before anything was paid
|
||||
net.catcrafts.Nostro1.Error.Bank the bank refused; its message says when it may have paid all the same
|
||||
net.catcrafts.Nostro1.Error.Failed anything else, such as an earlier call for this order whose outcome was
|
||||
lost: it may have been paid
|
||||
org.freedesktop.DBus.Error.AccessDenied the system's policy refused
|
||||
org.freedesktop.DBus.Error.InteractiveAuthorizationRequired the call did not allow a password prompt
|
||||
org.freedesktop.DBus.Error.ServiceUnknown nostro is not installed -->
|
||||
<node>
|
||||
<interface name="net.catcrafts.Nostro1.Checkout">
|
||||
<method name="Pay">
|
||||
<arg type="s" name="payeeIban" direction="in"/>
|
||||
<arg type="s" name="payeeName" direction="in"/>
|
||||
<arg type="x" name="amount" direction="in"/>
|
||||
<arg type="s" name="currency" direction="in"/>
|
||||
<arg type="s" name="reference" direction="in"/>
|
||||
<arg type="a{sv}" name="options" direction="in"/>
|
||||
<arg type="t" name="paymentId" direction="out"/>
|
||||
<arg type="a{sv}" name="results" direction="out"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
|
|
@ -54,17 +54,21 @@
|
|||
well it pays, so that status says nothing of it until it is LOST, STOLEN,
|
||||
CANCELLED or EXPIRED. SetCardStatus refuses to set such a card ACTIVE or
|
||||
DEACTIVATED (InvalidArgument): bunq would leave it as it is, without an error
|
||||
account / chosen (ssssx): the account apps' checkouts pay from (net.catcrafts.Nostro1.Checkout),
|
||||
as in Accounts; DefaultCheckoutAccount has none until one is chosen, or once
|
||||
it is gone. An account reached through OAuth cannot pay a shop, and is refused.
|
||||
account / chosen (ssssx): the account a pay link's form starts from in the Nostro app, as in
|
||||
Accounts; DefaultCheckoutAccount has none until one is chosen, or once it is
|
||||
gone. An account reached through OAuth cannot pay a shop, and is refused.
|
||||
nostrod pays nothing from it by itself: it is a choice kept for the user.
|
||||
Until 2026-11-22 it paid an app's order at net.catcrafts.Nostro1.Checkout, an
|
||||
interface nostrod no longer has: a website or an app that wants to be paid
|
||||
opens a payto:// link, which the Nostro app shows as a payment to make.
|
||||
|
||||
Errors, besides org.freedesktop.DBus.Error.AccessDenied (refused, or polkit did not answer) and
|
||||
org.freedesktop.DBus.Error.InteractiveAuthorizationRequired:
|
||||
net.catcrafts.Nostro1.Error.InvalidArgument refused before anything was sent
|
||||
net.catcrafts.Nostro1.Error.Cancelled the user did not authenticate: nothing was done
|
||||
net.catcrafts.Nostro1.Error.Bank the bank's own refusal
|
||||
net.catcrafts.Nostro1.Error.Bank the bank's own refusal; its message says when what was asked for
|
||||
may have been carried out all the same
|
||||
net.catcrafts.Nostro1.Error.OAuthCannotPay an OAuth connection may only pay the user's own accounts
|
||||
net.catcrafts.Nostro1.Error.NoCheckoutAccount (checkout) no account is chosen to pay checkouts from
|
||||
net.catcrafts.Nostro1.Error.Failed anything else; a payment that failed this way may have been made -->
|
||||
<node>
|
||||
<interface name="net.catcrafts.Nostro1">
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ Type=Application
|
|||
Name=Nostro
|
||||
GenericName=Banking
|
||||
Comment=See your bank accounts and pay from them
|
||||
Exec=nostro-app
|
||||
Exec=nostro-app %u
|
||||
Icon=net.catcrafts.Nostro
|
||||
Terminal=false
|
||||
Categories=Office;Finance;
|
||||
Keywords=bank;banking;bunq;payment;money;IBAN;
|
||||
MimeType=x-scheme-handler/payto;
|
||||
StartupNotify=false
|
||||
SingleMainWindow=true
|
||||
X-KDE-FormFactor=handset;tablet;desktop;
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@
|
|||
bank connections where no program of theirs can read them; the nostro command and the Nostro app ask it over the
|
||||
system bus, and your password is asked for before anything is paid or changed.
|
||||
</p>
|
||||
<p>
|
||||
Apps can have Nostro pay an order at checkout, from an account you chose, once you have confirmed the payment.
|
||||
</p>
|
||||
</description>
|
||||
<url type="homepage">https://catcrafts.net</url>
|
||||
<provides>
|
||||
|
|
|
|||
|
|
@ -12,8 +12,10 @@
|
|||
# themselves instead)
|
||||
#
|
||||
# Running it again updates. nostrod's Flatpak was net.catcrafts.Nostro until the app took that id: this moves the state a
|
||||
# nostrod installed under it kept, and removes that Flatpak. packaging/arch/PKGBUILD installs the same system files from
|
||||
# a package; uninstall.sh removes them.
|
||||
# nostrod installed under it kept, and removes that Flatpak. It also takes away the activation file of
|
||||
# net.catcrafts.Nostro1.Checkout, a second bus name nostrod had until it lost its checkout over D-Bus: left behind, the
|
||||
# bus would start nostrod for a name nostrod no longer takes. packaging/arch/PKGBUILD installs the same system files
|
||||
# from a package; uninstall.sh removes them.
|
||||
set -eu
|
||||
here=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
|
|
@ -31,7 +33,7 @@ install -Dm644 "$here/nostro.sysusers" /usr/lib/sysusers.d/nostro.conf
|
|||
systemd-sysusers /usr/lib/sysusers.d/nostro.conf
|
||||
install -Dm644 "$here/net.catcrafts.Nostro1.conf" /usr/share/dbus-1/system.d/net.catcrafts.Nostro1.conf
|
||||
install -Dm644 "$here/net.catcrafts.Nostro1.service" /usr/share/dbus-1/system-services/net.catcrafts.Nostro1.service
|
||||
install -Dm644 "$here/net.catcrafts.Nostro1.Checkout.service" /usr/share/dbus-1/system-services/net.catcrafts.Nostro1.Checkout.service
|
||||
rm -f /usr/share/dbus-1/system-services/net.catcrafts.Nostro1.Checkout.service
|
||||
install -Dm644 "$here/net.catcrafts.Nostro1.policy" /usr/share/polkit-1/actions/net.catcrafts.Nostro1.policy
|
||||
install -Dm644 "$here/nostrod.service" /etc/systemd/system/nostrod.service
|
||||
install -Dm755 "$here/nostro" /usr/local/bin/nostro
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
# SPDX-License-Identifier: LGPL-3.0-only
|
||||
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
# An app's first checkout starts nostrod, through systemd. Install: /usr/share/dbus-1/system-services/
|
||||
[D-BUS Service]
|
||||
Name=net.catcrafts.Nostro1.Checkout
|
||||
Exec=/bin/false
|
||||
User=nostro
|
||||
SystemdService=nostrod.service
|
||||
|
|
@ -3,8 +3,12 @@
|
|||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<!-- SPDX-License-Identifier: LGPL-3.0-only -->
|
||||
<!-- SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® -->
|
||||
<!-- nostrod owns its two names as the user nostro, and anyone may call them: nostrod answers each caller for their own
|
||||
bank connections alone, and asks polkit first (net.catcrafts.Nostro1.policy).
|
||||
<!-- nostrod owns its name as the user nostro, and anyone may call it: nostrod answers each caller for their own bank
|
||||
connections alone, and asks polkit first (net.catcrafts.Nostro1.policy).
|
||||
|
||||
The second name is one nostrod no longer takes. The nostrod of 0.0.0 asks for it when it starts, for a checkout
|
||||
over D-Bus that later versions do not have, and ends when it is refused: these files may be newer than the
|
||||
Flatpak nostrod runs from, so it may still own the name. This file lets nobody call it.
|
||||
Install: /usr/share/dbus-1/system.d/net.catcrafts.Nostro1.conf -->
|
||||
<busconfig>
|
||||
<policy user="nostro">
|
||||
|
|
@ -13,6 +17,5 @@
|
|||
</policy>
|
||||
<policy context="default">
|
||||
<allow send_destination="net.catcrafts.Nostro1"/>
|
||||
<allow send_destination="net.catcrafts.Nostro1.Checkout"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
Every action is owned by unix-user:nostro, the user nostrod runs as: polkit lets only root or an action's owner
|
||||
check a call made by another user, or pass the details the dialog shows. $(summary) is what nostrod read for the
|
||||
call itself, such as the amount, the payee and the account of a payment; the details amount_minor, currency,
|
||||
counterparty, account_iban, environment, at checkout reference, and for a card card (its id) and status (ACTIVE,
|
||||
DEACTIVATED, LOST or STOLEN) are there for rules (an amount above which an administrator must approve, say).
|
||||
counterparty, account_iban, environment, and for a card card (its id) and status (ACTIVE, DEACTIVATED, LOST or
|
||||
STOLEN) are there for rules (an amount above which an administrator must approve, say).
|
||||
|
||||
No action keeps an authorization: polkit ties a kept one to the calling process, so the CLI would ask every time
|
||||
anyway. Viewing is free in an active session, and nothing else is. Whatever pays (an app's checkout included),
|
||||
whatever changes anything at the bank (a request for money, a draft, a schedule cancelled, a card frozen), and
|
||||
whatever changes the bank connections or the account checkouts pay from asks for the user's password every time.
|
||||
anyway. Viewing is free in an active session, and nothing else is. Whatever pays, whatever changes anything at
|
||||
the bank (a request for money, a draft, a schedule cancelled, a card frozen), and whatever changes the bank
|
||||
connections or the account a pay link's form starts from asks for the user's password every time.
|
||||
|
||||
That is the default, and it is the strict one on purpose: no program of the user's does anything at their bank
|
||||
without them. Loosening it is an administrator's choice, made with a rule, and polkit cannot tell one program of
|
||||
|
|
@ -89,18 +89,7 @@
|
|||
</action>
|
||||
|
||||
<action id="net.catcrafts.Nostro1.Connectors">
|
||||
<description>Add or remove a bank connection, or choose the account apps may ask you to pay from</description>
|
||||
<message>Authentication is required to $(summary)</message>
|
||||
<defaults>
|
||||
<allow_any>auth_self</allow_any>
|
||||
<allow_inactive>auth_self</allow_inactive>
|
||||
<allow_active>auth_self</allow_active>
|
||||
</defaults>
|
||||
<annotate key="org.freedesktop.policykit.owner">unix-user:nostro</annotate>
|
||||
</action>
|
||||
|
||||
<action id="net.catcrafts.Nostro1.Checkout">
|
||||
<description>Pay an order an app asks you to pay</description>
|
||||
<description>Add or remove a bank connection, or choose the account a pay link's form starts from</description>
|
||||
<message>Authentication is required to $(summary)</message>
|
||||
<defaults>
|
||||
<allow_any>auth_self</allow_any>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
# SPDX-License-Identifier: LGPL-3.0-only
|
||||
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
#
|
||||
# nostrod: every local user's bank connections, one worker process per user, behind net.catcrafts.Nostro1 and
|
||||
# net.catcrafts.Nostro1.Checkout on the system bus. The first call starts it (D-Bus activation), and it ends by itself
|
||||
# once idle, so an updated Flatpak takes over at the next call. It runs from the net.catcrafts.Nostrod Flatpak as the
|
||||
# system user nostro, whose home, the state directory, holds the connections: no other user can read it.
|
||||
# nostrod: every local user's bank connections, one worker process per user, behind net.catcrafts.Nostro1 on the
|
||||
# system bus. The first call starts it (D-Bus activation), and it ends by itself once idle, so an updated Flatpak takes
|
||||
# over at the next call. It runs from the net.catcrafts.Nostrod Flatpak as the system user nostro, whose home, the
|
||||
# state directory, holds the connections: no other user can read it.
|
||||
#
|
||||
# The hardening is what bubblewrap, which flatpak runs the daemon in, works under. Not here, because it breaks it:
|
||||
# RestrictSUIDSGID= (systemd answers openat2() with ENOSYS for it, and bubblewrap 0.13 has no fallback; NoNewPrivileges=
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ if flatpak info --system --show-metadata net.catcrafts.Nostro 2>/dev/null | grep
|
|||
flatpak uninstall --system -y --noninteractive net.catcrafts.Nostro 2>/dev/null
|
||||
fi
|
||||
flatpak remote-delete --system nostro-local 2>/dev/null
|
||||
# The Checkout file among them is one an install from before the checkout over D-Bus went left behind.
|
||||
rm -f /usr/share/dbus-1/system.d/net.catcrafts.Nostro1.conf \
|
||||
/usr/share/dbus-1/system-services/net.catcrafts.Nostro1.service \
|
||||
/usr/share/dbus-1/system-services/net.catcrafts.Nostro1.Checkout.service \
|
||||
|
|
|
|||
38
project.cpp
38
project.cpp
|
|
@ -14,25 +14,6 @@ import Crafter.Debug.Build;
|
|||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
// Nostro.Checkout: what a shop app links to have nostrod pay an order, as a library of its own that needs no bank code,
|
||||
// OpenSSL, Crafter.Network or Crafter.DB, only libsystemd. `--product=checkout` builds it alone; nostrod takes its names
|
||||
// from it.
|
||||
static Configuration CheckoutLibrary(std::span<const std::string_view> args, const std::vector<std::string>& compileFlags) {
|
||||
Configuration checkout;
|
||||
checkout.path = "./";
|
||||
checkout.name = "nostro-checkout";
|
||||
checkout.outputName = "nostro-checkout";
|
||||
checkout.type = ConfigurationType::LibraryStatic;
|
||||
checkout.linkFlags.push_back("-lsystemd");
|
||||
ApplyStandardArgs(checkout, args);
|
||||
checkout.compileFlags.insert(checkout.compileFlags.end(), compileFlags.begin(), compileFlags.end());
|
||||
std::array<fs::path, 1> interfaces = {"interfaces/Nostro.Checkout"};
|
||||
std::array<fs::path, 1> implementations = {"implementations/Nostro.Checkout"};
|
||||
checkout.GetInterfacesAndImplementations(interfaces, implementations);
|
||||
LintRules::AddLiteRules(checkout);
|
||||
return checkout;
|
||||
}
|
||||
|
||||
// Nostro.Ui: the toolkit the app's screens are built with. It imports std alone, so its tests need no window, no bank
|
||||
// and no bus, and it is built only for what depends on it: those tests, and the app.
|
||||
static Configuration UiLibrary(std::span<const std::string_view> args, const std::vector<std::string>& compileFlags) {
|
||||
|
|
@ -179,8 +160,8 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
bool coverage = false;
|
||||
std::string profileRuntime;
|
||||
constexpr std::string_view profileRuntimeArgName = "--profile-runtime=";
|
||||
// What a build makes: the CLI by default, "daemon" for nostrod, "app" for the window, "checkout" for the checkout
|
||||
// client library, or "fake-system" for a made-up system to look at the app against.
|
||||
// What a build makes: the CLI by default, "daemon" for nostrod, "app" for the window, or "fake-system" for a
|
||||
// made-up system to look at the app against.
|
||||
std::string product;
|
||||
constexpr std::string_view productArgName = "--product=";
|
||||
// The app with Crafter.Debug in it, for an agent to drive: nostro's own flag, which no dependency is handed.
|
||||
|
|
@ -234,9 +215,6 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
}
|
||||
libcfg.compileFlags.insert(libcfg.compileFlags.end(), coverageCompileFlags.begin(), coverageCompileFlags.end());
|
||||
|
||||
if(product == "checkout") {
|
||||
return CheckoutLibrary(args, coverageCompileFlags);
|
||||
}
|
||||
if(!product.empty() && product != "daemon" && product != "app" && product != "fake-system") {
|
||||
throw std::runtime_error(std::format("unknown product '{}' in {}", product, productArgName));
|
||||
}
|
||||
|
|
@ -257,7 +235,6 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
if(dbusEnabled) {
|
||||
libcfg.defines.push_back({"NOSTRO_DBUS_ENABLED"});
|
||||
}
|
||||
Configuration* checkout = new Configuration(CheckoutLibrary(args, coverageCompileFlags));
|
||||
Configuration* ui = new Configuration(UiLibrary(args, coverageCompileFlags));
|
||||
|
||||
// nostro uses Crafter.Network's HTTP/1.1 client alone: --no-quic leaves out msquic, its CMake build, and the runpath
|
||||
|
|
@ -291,9 +268,6 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
libcfg.outputName = "nostro";
|
||||
libcfg.type = ConfigurationType::LibraryStatic;
|
||||
libcfg.dependencies = {network, db};
|
||||
if(dbusEnabled) {
|
||||
libcfg.dependencies.push_back(checkout);
|
||||
}
|
||||
|
||||
if(opensslEnabled) {
|
||||
libcfg.linkFlags.push_back("-lssl");
|
||||
|
|
@ -372,7 +346,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
}
|
||||
|
||||
if(product == "fake-system") {
|
||||
return FakeSystem(args, defines, { library, network, db, checkout });
|
||||
return FakeSystem(args, defines, { library, network, db });
|
||||
}
|
||||
|
||||
// nostro-app: the window. Its fonts go beside it, where the window library's shaders are put too.
|
||||
|
|
@ -420,7 +394,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
if(Debug::Use(app, { .enabled = debugApi, .flag = std::string(debugApiArgName), .define = "NOSTRO_DEBUG_API", .args = depArgs })) {
|
||||
appInterfaces.emplace_back("interfaces/Nostro.DebugCommands");
|
||||
appImplementations.emplace_back("implementations/Nostro.DebugCommands");
|
||||
app.dependencies.push_back(new Configuration(FakeSystem(args, defines, { library, network, db, checkout })));
|
||||
app.dependencies.push_back(new Configuration(FakeSystem(args, defines, { library, network, db })));
|
||||
app.scripts.push_back({"fake", RunOnFakeSystem});
|
||||
}
|
||||
app.GetInterfacesAndImplementations(appInterfaces, appImplementations);
|
||||
|
|
@ -473,7 +447,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
"ShouldServeEveryUser",
|
||||
"ShouldAnswerAsynchronously",
|
||||
};
|
||||
addTests(libraryTests, { library, network, db, checkout });
|
||||
addTests(libraryTests, { library, network, db });
|
||||
// The toolkit's, which need the toolkit alone.
|
||||
constexpr std::array<std::string_view, 5> uiTests = {
|
||||
"ShouldWrapText",
|
||||
|
|
@ -488,7 +462,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
|
|||
"ShouldValidateForms",
|
||||
"ShouldDriveTheApp",
|
||||
};
|
||||
addTests(appTests, { appCore, ui, library, network, db, checkout });
|
||||
addTests(appTests, { appCore, ui, library, network, db });
|
||||
|
||||
LintRules::AddLiteRules(execfg);
|
||||
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ namespace {
|
|||
Check(!Result<std::vector<ConnectorCards>>(loop, [&client](auto then) { return client.Cards(std::move(then)); }).at(0).cards.empty(), "the cards");
|
||||
Equal(Result<BunqCard>(loop, [&client, card](auto then) { return client.SetCardStatus(card, "DEACTIVATED", std::move(then)); }).status, std::string("DEACTIVATED"), "a card frozen");
|
||||
|
||||
Check(!Result<std::optional<Account>>(loop, [&client](auto then) { return client.DefaultCheckoutAccount(std::move(then)); }).has_value(), "no account pays checkouts yet");
|
||||
Check(!Result<std::optional<Account>>(loop, [&client](auto then) { return client.DefaultCheckoutAccount(std::move(then)); }).has_value(), "no account is the one pay links start from yet");
|
||||
Equal(Result<Account>(loop, [&client](auto then) { return client.SetDefaultCheckoutAccount(aliceMain, std::move(then)); }).iban, aliceMain, "until one is chosen");
|
||||
|
||||
const AddedConnector oauth = Result<AddedConnector>(loop, [&client, &bunq](auto then) { return client.AddBunqOAuth("production", bunq.clientId, bunq.clientSecret, "http://127.0.0.1/cb", "code-carol", std::move(then)); });
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@ namespace fs = std::filesystem;
|
|||
namespace {
|
||||
constexpr std::uint16_t port = 47307;
|
||||
constexpr std::uint32_t uid = 4242;
|
||||
// A second user of the machine, with connections of their own.
|
||||
constexpr std::uint32_t erinUid = 4243;
|
||||
constexpr std::string_view busName = "net.catcrafts.Nostro1";
|
||||
const std::string aliceKey = "key-alice-0123456789abcdef";
|
||||
const std::string aliceMain = "NL23BUNQ2025123456";
|
||||
|
|
@ -63,6 +65,8 @@ namespace {
|
|||
const std::string daveIban = "NL06BUNQ2025444444";
|
||||
const std::string otherAliceIban = "NL25BUNQ2025555555";
|
||||
const std::string strangerIban = "NL44BUNQ2025666666";
|
||||
// A link as a website's pay button opens one: to Bob's account, under a shop's name, with what is owed and for what.
|
||||
const std::string shopLink = std::format("payto://iban/{}?amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234", bobIban);
|
||||
|
||||
void SetPolkit(Fake::Bus& bus, Fake::Polkit outcome, std::string_view action = {}) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
|
|
@ -313,6 +317,26 @@ namespace {
|
|||
return change == std::views::reverse(bus.checks).end() ? std::string() : change->action;
|
||||
}
|
||||
|
||||
// What the system's dialog said that change was: nostrod's own words for it, from its own data.
|
||||
std::string Summary(Fake::Bus& bus) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
const auto change = std::ranges::find_if(std::views::reverse(bus.checks), [](const Fake::PolkitCheck& check) { return check.action != Bus::actionView; });
|
||||
return change == std::views::reverse(bus.checks).end() || !change->details.contains("summary") ? std::string() : change->details.at("summary");
|
||||
}
|
||||
|
||||
// How often polkit was asked about a change: what a screen reads is a check too, for looking.
|
||||
std::size_t Changes(Fake::Bus& bus) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
return static_cast<std::size_t>(std::ranges::count_if(bus.checks, [](const Fake::PolkitCheck& check) { return check.action != Bus::actionView; }));
|
||||
}
|
||||
|
||||
// What the bank was last sent as a payment or a draft of one.
|
||||
std::string LastPayment(Fake::Bunq& bunq) {
|
||||
const std::vector<Fake::Logged> log = bunq.Log();
|
||||
const auto sent = std::ranges::find_if(std::views::reverse(log), [](const Fake::Logged& entry) { return entry.method == "POST" && entry.path.contains("payment"); });
|
||||
return sent == std::views::reverse(log).end() ? std::string() : sent->body;
|
||||
}
|
||||
|
||||
// Before nostrod runs: no system bus at all, then a bus without nostrod, then nostrod without a connection.
|
||||
void Starting(Driver& d, pid_t& nostrod, const fs::path& state) {
|
||||
d.noBus = true;
|
||||
|
|
@ -339,6 +363,18 @@ namespace {
|
|||
Check(Has(d, "nav.accounts") && Has(d, "nav.cards") && Has(d, "nav.settings"), "the app's places are along the bottom");
|
||||
Equal(d.connects, 2, "one connection to the bus is all it took");
|
||||
|
||||
// A link that asks for a payment, and no account to pay it from: that is said, and no form is opened.
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("accounts+link"), "a link opens no form where there is no account to pay from");
|
||||
Shows(d.ui, "No account to pay from", "which is said");
|
||||
Shows(d.ui, "This link asks for a payment", "with what the link was for");
|
||||
Hides(d.ui, "Shop BV", "and with nothing of what the link said");
|
||||
Tap(d, "link.close");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "closed, it leaves the welcome");
|
||||
Shows(d.ui, "Welcome to Nostro", "where a bank can be connected");
|
||||
Hides(d.ui, "A link asks for a payment", "and the link waits for nothing");
|
||||
|
||||
// Every place says so when it has nothing to show.
|
||||
Press(d, "nav.cards");
|
||||
Shows(d.ui, "No cards", "no cards");
|
||||
|
|
@ -348,7 +384,7 @@ namespace {
|
|||
Shows(d.ui, "No bank is connected yet", "none to list");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "settings.checkout");
|
||||
Shows(d.ui, "No accounts to choose from", "and no account to pay at checkout from");
|
||||
Shows(d.ui, "No accounts to choose from", "and no account for a pay link to start from");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.accounts");
|
||||
// A connection without an account: there is nothing to pay from.
|
||||
|
|
@ -366,6 +402,19 @@ namespace {
|
|||
other.RemoveConnector("Eve");
|
||||
Press(d, "bar.refresh");
|
||||
Shows(d.ui, "Welcome to Nostro", "without it the welcome is back");
|
||||
// One account in all: a link's form opens from it at once, since there is nothing to choose between.
|
||||
other.AddBunq(daveKey, "*", "");
|
||||
Press(d, "bar.refresh");
|
||||
Shows(d.ui, "Play money", "a single account");
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "with one account a link opens its form without asking which account pays");
|
||||
Shows(d.ui, "Play money", "from the one there is");
|
||||
Shows(d.ui, "Shop BV", "filled in");
|
||||
Tap(d, "bar.back");
|
||||
other.RemoveConnector("Dave");
|
||||
Press(d, "bar.refresh");
|
||||
Shows(d.ui, "Welcome to Nostro", "and with that account gone the welcome is back");
|
||||
// Connecting a bank from there: which bank first, then how, and then the form of that way.
|
||||
Check(Has(d, "welcome.connect") && d.ui.Find("welcome.connect")->label == "Connect a bank", "which offers to connect a bank, whichever");
|
||||
Tap(d, "welcome.connect");
|
||||
|
|
@ -450,7 +499,7 @@ namespace {
|
|||
Hides(d.ui, "Welcome to Nostro", "the welcome is over");
|
||||
Check(Has(d, "home.pay") && Has(d, "home.request"), "paying and asking are at hand");
|
||||
Tap(d, "nav.settings");
|
||||
Shows(d.ui, "No account chosen", "no account pays at checkout yet");
|
||||
Shows(d.ui, "No account chosen", "no account is chosen for pay links to start from yet");
|
||||
Tap(d, "settings.connections");
|
||||
Check(Has(d, "connections.add") && d.ui.Find("connections.add")->label == "Add a connection", "the settings add a connection too, of whichever bank");
|
||||
Adding(d, "key");
|
||||
|
|
@ -811,6 +860,7 @@ namespace {
|
|||
d.ui.KeyDown(Key::Escape, {});
|
||||
Check(!d.ui.Tap("pay.submit") && !d.ui.Tap("bar.back") && d.ui.Focused().empty(), "under which the form is out of reach: of a finger, and of the key that sent it");
|
||||
Check(!d.app.Navigate("cards") && d.app.Screen() == "pay+working", "nor is the screen left by name while it is under way");
|
||||
Check(!d.app.Open(shopLink) && d.app.Screen() == "pay+working", "or for a link that asks for another payment");
|
||||
Settle(d);
|
||||
Shows(d.ui, "Paid €12.50 to Bob", "the payment made is said");
|
||||
Check(Has(d, "copy.Payment") && !Test::Says(d.ui, "Press a line to copy it"), "with the bank's number of it, which can be copied without a word about it");
|
||||
|
|
@ -906,6 +956,27 @@ namespace {
|
|||
Equal(d.app.Screen(), page, "which shows the account");
|
||||
Shows(d.ui, "Today", "and its payments");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// A link that asks for a payment, while no account is chosen for links to start from: its form starts from
|
||||
// the first account that pays anyone, which the bank lists the savings as, whichever account paid last. Which
|
||||
// account pays is the first thing asked, over the form, and a tap beside the question keeps that one.
|
||||
Tap(d, "home.pay");
|
||||
Shows(d.ui, "Main", "the pay form pays from the account that paid last");
|
||||
Tap(d, "bar.back");
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and opens the pay form, with the choice of the account that pays over it");
|
||||
Shows(d.ui, "Choose an account", "which asks for one");
|
||||
Check(Has(d, std::format("pick.{}", aliceMain)) && Has(d, std::format("pick.{}", aliceSavings)), "of every account there is");
|
||||
Check(!d.ui.Tap("pay.submit") && !d.ui.Tap("bar.back"), "and covers the form, its button too");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "a tap beside it leaves the form");
|
||||
Shows(d.ui, "Savings", "paying from the first account, where none was chosen for links to start from");
|
||||
Hides(d.ui, "Main", "not from the one the form paid from last");
|
||||
Tap(d, "pay.from");
|
||||
Tap(d, std::format("pick.{}", aliceMain));
|
||||
Tap(d, "bar.back");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "the way back from it leads to the accounts");
|
||||
}
|
||||
|
||||
// Asking for money, and the request sent looked at and revoked.
|
||||
|
|
@ -1300,11 +1371,11 @@ namespace {
|
|||
Tap(d, "nav.accounts");
|
||||
}
|
||||
|
||||
// The settings: the account that pays at checkout, what the app is, and the connections, removed by name and,
|
||||
// where two have one name, by number.
|
||||
// The settings: the account a pay link's form starts from, what the app is, and the connections, removed by name
|
||||
// and, where two have one name, by number.
|
||||
void Settings(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||||
Tap(d, "nav.settings");
|
||||
for(const std::string_view said : {"Bank connections", "2 connected", "Pay at checkout from", "No account chosen", "About and security", "Nostro 1.2.3"}) {
|
||||
for(const std::string_view said : {"Bank connections", "2 connected", "Pay links start from", "No account chosen", "About and security", "Nostro 1.2.3"}) {
|
||||
Shows(d.ui, said, "the settings are listed");
|
||||
}
|
||||
Tap(d, "settings.about");
|
||||
|
|
@ -1316,15 +1387,19 @@ namespace {
|
|||
Tap(d, "bar.back");
|
||||
|
||||
Tap(d, "settings.checkout");
|
||||
Equal(d.app.Screen(), std::string("checkout"), "the account that pays at checkout has a page");
|
||||
Shows(d.ui, "Play money", "which lists the accounts");
|
||||
Equal(d.app.Screen(), std::string("checkout"), "the account pay links start from has a page");
|
||||
Shows(d.ui, "Pay links", "called after what it is for");
|
||||
Shows(d.ui, "A shop's pay link opens Nostro", "which says what a pay link is");
|
||||
Shows(d.ui, "choose another one", "and that the account is only where its form starts");
|
||||
Shows(d.ui, "Play money", "and lists the accounts");
|
||||
SetPolkit(bus, Fake::Polkit::Password, Bus::actionConnectors);
|
||||
Tap(d, std::format("checkout.{}", aliceMain));
|
||||
Shows(d.ui, "Letting apps ask you to pay from Main", "choosing one is under way");
|
||||
Shows(d.ui, "Having pay links start from Main", "choosing one is under way");
|
||||
Shows(d.ui, "Confirm it in your system's password dialog.", "and needs the password");
|
||||
Settle(d);
|
||||
Shows(d.ui, "Apps now ask you to pay from Main", "the choice is said");
|
||||
Shows(d.ui, "Pay links now start from Main", "the choice is said");
|
||||
Equal(Action(bus), std::string(Bus::actionConnectors), "after the password for changing connections");
|
||||
Equal(Summary(bus), std::format("have pay links start from {} (Main)", aliceMain), "which the system's dialog asked for in nostrod's words for it");
|
||||
Tap(d, "bar.back");
|
||||
Shows(d.ui, std::format("Main · {}", GroupIban(aliceMain)), "and shown in the settings");
|
||||
|
||||
|
|
@ -1350,6 +1425,7 @@ namespace {
|
|||
Shows(d.ui, "The API key itself stays valid", "with what stays valid at its bank, by the way it was connected");
|
||||
Tap(d, "confirm.no");
|
||||
Equal(d.app.Screen(), std::string("connections"), "and can be thought better of");
|
||||
const std::size_t reads = Answers(d, "DefaultCheckoutAccount ok");
|
||||
Tap(d, dave);
|
||||
Tap(d, "detail.remove");
|
||||
Tap(d, "confirm.yes");
|
||||
|
|
@ -1360,7 +1436,7 @@ namespace {
|
|||
Check(!Has(d, dave), "and no longer listed");
|
||||
Tap(d, "bar.back");
|
||||
Shows(d.ui, "1 connected", "one is left");
|
||||
Shows(d.ui, "Pay at checkout from", "and the checkout's account is read again");
|
||||
Equal(Answers(d, "DefaultCheckoutAccount ok"), reads + 1, "and the account pay links start from is read again: the connection may have held it");
|
||||
|
||||
// Two connections of one name: the one to remove is told apart by its accounts, and removed by its number.
|
||||
Client other = Client::System();
|
||||
|
|
@ -1548,12 +1624,301 @@ namespace {
|
|||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.settings");
|
||||
Tap(d, "settings.checkout");
|
||||
Check(!d.ui.Find(std::format("checkout.{}", carolIban))->enabled && d.ui.Find(std::format("checkout.{}", aliceMain))->enabled, "nor can it pay at a checkout");
|
||||
Check(!d.ui.Find(std::format("checkout.{}", carolIban))->enabled && d.ui.Find(std::format("checkout.{}", aliceMain))->enabled, "nor can a pay link be set to start from it");
|
||||
Shows(d.ui, "Pays your own accounts only", "which is said");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.accounts");
|
||||
}
|
||||
|
||||
// A link that asks for a payment, as a website's pay button opens one. It fills in the pay form and does no more:
|
||||
// whoever wrote it chose the payee and the amount, so nothing is sent before the user presses the form's button
|
||||
// and the system's password dialog has said, in nostrod's own words, what is paid to whom.
|
||||
void Linking(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||||
// One the app cannot read is said to be so over wherever the user is, with why, in the app's own words.
|
||||
Check(d.app.Open("payto://iban/NL00MARK?message=MARK"), "a link that cannot be read is taken all the same");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("accounts+link"), "and said to be one, over the accounts");
|
||||
Shows(d.ui, "This link cannot be opened", "by name");
|
||||
Shows(d.ui, "The IBAN in it is not a valid one.", "with why");
|
||||
Hides(d.ui, "MARK", "and with nothing of the link itself");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("accounts"), "a tap beside it closes it");
|
||||
Check(d.app.Navigate("cards"), "the cards");
|
||||
Settle(d);
|
||||
Check(d.app.Open("https://example.org/pay"), "any other address is no payment");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("cards+link"), "which is said over the place the user is at: nothing is gone to for it");
|
||||
Shows(d.ui, "It is not a link to pay an IBAN", "with why");
|
||||
Tap(d, "link.close");
|
||||
Equal(d.app.Screen(), std::string("cards"), "and closed again");
|
||||
|
||||
// A link that can be read, from a page gone into: the pay form, filled in, and nothing asked or sent. Which
|
||||
// account pays is asked first, over the form, with the one chosen for pay links to start from as what the
|
||||
// form holds: Main, since the settings were gone through, which is not the account the bank lists first.
|
||||
Tap(d, "nav.settings");
|
||||
Tap(d, "settings.checkout");
|
||||
Equal(d.app.Screen(), std::string("checkout"), "a page of the settings");
|
||||
const std::size_t posts = bunq.Count("POST", "/user/");
|
||||
const std::size_t changes = Changes(bus);
|
||||
Check(d.app.Open(shopLink), "a link is taken from wherever the user is");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and opens the pay form, asking first which account pays");
|
||||
Shows(d.ui, "Choose an account", "in a list of the accounts");
|
||||
Check(Has(d, std::format("pick.{}", aliceMain)) && Has(d, std::format("pick.{}", aliceSavings)) && Has(d, std::format("pick.{}", carolIban)), "every one of them, whichever connection it is of");
|
||||
Shows(d.ui, "A link filled this in, not you.", "the form under it says that a link filled it in");
|
||||
for(const std::string_view said : {std::string_view(bobIban), std::string_view("Shop BV"), std::string_view("12.50"), std::string_view("Order 1234")}) {
|
||||
Shows(d.ui, said, "with what the link said, in the form's own fields");
|
||||
}
|
||||
// The question covers the form, as any sheet covers its page: the form's button cannot be pressed through it,
|
||||
// by a finger or by a key.
|
||||
d.ui.KeyDown(Key::Enter, {});
|
||||
d.ui.KeyDown(Key::Space, {});
|
||||
Check(!d.ui.Tap("pay.submit") && !d.ui.Tap("bar.back") && !d.ui.Tap("pay.to"), "the form is out of reach until the account is settled");
|
||||
Settle(d);
|
||||
Check(d.app.Screen() == "pay+accounts" && bunq.Count("POST", "/user/") == posts && Changes(bus) == changes && !d.app.Changing(), "nothing is sent, and the user is asked for no password: a link fills in a form");
|
||||
d.ui.KeyDown(Key::Escape, {});
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "Escape leaves the question");
|
||||
Shows(d.ui, "Main", "and the form paying from the account chosen for pay links to start from");
|
||||
Hides(d.ui, "Savings", "not from the first one");
|
||||
Bottom(d);
|
||||
Equal(d.ui.Find("pay.submit")->label, std::string("Pay"), "its button pays, as any pay form's does");
|
||||
|
||||
// The system's password dialog is where it is confirmed. Closed, nothing is paid, and the form is still the link's.
|
||||
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionPay);
|
||||
Press(d, "pay.submit");
|
||||
Equal(d.app.Screen(), std::string("pay+problem"), "the button sends it to that dialog, with no question of the app's own before it");
|
||||
Shows(d.ui, "Not confirmed", "and a dialog closed is a payment not made");
|
||||
Equal(bunq.Count("POST", "/user/"), posts, "of which the bank hears nothing");
|
||||
Equal(Summary(bus), std::format("pay €12.50 to {} (Shop BV) from {} (Main)", bobIban, aliceMain), "the dialog said what the link asks for in nostrod's own words: the amount, the address before the name, and the account the form showed");
|
||||
Press(d, "problem.close");
|
||||
Top(d);
|
||||
Shows(d.ui, "A link filled this in, not you.", "the form is still said to be a link's");
|
||||
Shows(d.ui, "Order 1234", "and is as the link filled it in");
|
||||
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||||
Bottom(d);
|
||||
Press(d, "pay.submit");
|
||||
Shows(d.ui, "Paid €12.50 to Shop BV", "confirmed there, it is paid");
|
||||
Equal(Action(bus), std::string(Bus::actionPay), "after the password for paying");
|
||||
Equal(bunq.Count("POST", "/user/"), posts + 1, "once");
|
||||
const std::string sent = LastPayment(bunq);
|
||||
Check(sent.contains(bobIban) && sent.contains("Shop BV") && sent.contains("12.50") && sent.contains("Order 1234"), "and the bank is sent what the form showed");
|
||||
Press(d, "done.close");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "which leads to the accounts");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "A link filled this in", "the next pay form is nobody's but the user's");
|
||||
Hides(d.ui, "Order 1234", "and empty");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// An account picked from the choice a link opens with is the one that pays: the form shows it, and the
|
||||
// system's dialog names it. A tap beside the choice, like Escape, keeps the one the form started from.
|
||||
Check(d.app.Open(shopLink), "the link again");
|
||||
Tap(d, std::format("pick.{}", aliceSavings));
|
||||
Equal(d.app.Screen(), std::string("pay"), "an account picked there closes the choice");
|
||||
Shows(d.ui, "Savings", "and is the one the form pays from");
|
||||
Hides(d.ui, "Main", "in place of the one it started from");
|
||||
Shows(d.ui, "A link filled this in, not you.", "which leaves the form a link's");
|
||||
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionPay);
|
||||
Bottom(d);
|
||||
Press(d, "pay.submit");
|
||||
Equal(Summary(bus), std::format("pay €12.50 to {} (Shop BV) from {} (Savings)", bobIban, aliceSavings), "the dialog names the account that was picked");
|
||||
SetPolkit(bus, Fake::Polkit::Password, Bus::actionPay);
|
||||
Press(d, "problem.close");
|
||||
Tap(d, "bar.back");
|
||||
Check(d.app.Open(shopLink), "and again");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "a tap beside the choice closes it too");
|
||||
Shows(d.ui, "Main", "with the account the form started from");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// A link that says no more than who is paid: the rest is the user's to fill in, and the form is checked as any.
|
||||
Check(d.app.Open(std::format("payto://iban/{}", bobIban)), "a link with an IBAN alone");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, bobIban, "fills in who is paid");
|
||||
Bottom(d);
|
||||
Tap(d, "pay.submit");
|
||||
Top(d);
|
||||
Shows(d.ui, "The name of the account's holder", "and its form still lacks a name");
|
||||
Shows(d.ui, "Enter an amount", "and an amount");
|
||||
Check(!d.app.Changing() && bunq.Count("POST", "/user/") == posts + 1, "so nothing is sent");
|
||||
Tap(d, "bar.back");
|
||||
|
||||
// A name with an & in it, which the system's dialog does not show as it is: the form and the bank have the
|
||||
// link's name, and the dialog has it the way nostrod makes any name fit to show there, after the IBAN.
|
||||
Check(d.app.Open(std::format("payto://iban/{}?amount=EUR:1&receiver-name=Fish%20%26%20Chips", bobIban)), "a link whose name has an &");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Fish & Chips", "has that name on its form as the link has it");
|
||||
Bottom(d);
|
||||
Press(d, "pay.submit");
|
||||
Shows(d.ui, "Paid €1.00 to Fish & Chips", "and is paid under it");
|
||||
Equal(Summary(bus), std::format("pay €1.00 to {} (Fish + Chips) from {} (Main)", bobIban, aliceMain), "the dialog showed the name in nostrod's way, after the IBAN it shows whole");
|
||||
Check(LastPayment(bunq).contains("Fish & Chips"), "and the bank is sent the name as the form had it");
|
||||
Press(d, "done.close");
|
||||
|
||||
// From an account whose connection pays between the user's own accounts only, what a link asks for is saved as
|
||||
// a draft, as anything paid to someone else from there is. The choice a link opens with offers that account
|
||||
// too, as the form's own does.
|
||||
Check(d.app.Open(shopLink), "the link again");
|
||||
Tap(d, std::format("pick.{}", carolIban));
|
||||
Shows(d.ui, "A payment to anyone else", "the form says what becomes of it from such an account");
|
||||
Bottom(d);
|
||||
Equal(d.ui.Find("pay.submit")->label, std::string("Save as draft"), "and its button that it saves a draft");
|
||||
Press(d, "pay.submit");
|
||||
Shows(d.ui, "Drafted €12.50 to Shop BV", "which it does");
|
||||
Equal(Action(bus), std::string(Bus::actionChange), "as a change that moves no money");
|
||||
Press(d, "done.close");
|
||||
|
||||
// A wide window has the app's places beside every page. A link's form left sideways is not opened again by
|
||||
// itself, and when the user goes back to it, what it holds is still said to be a link's.
|
||||
d.size = {0, 0, 1280, 800};
|
||||
Check(d.app.Open(shopLink), "the link in a wide window");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "opens its form there too, under the same question");
|
||||
Check(!d.ui.Tap("nav.accounts") && !d.ui.Tap("pay.submit"), "which covers the places beside the form as well as the form");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "and is left by a tap beside it");
|
||||
Press(d, "nav.accounts");
|
||||
Press(d, "bar.refresh");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "the accounts read again do not bring it back");
|
||||
Hides(d.ui, "A link asks for a payment", "and nothing waits");
|
||||
Tap(d, "home.pay");
|
||||
Shows(d.ui, "A link filled this in, not you.", "gone back to, the form is still said to be a link's");
|
||||
Shows(d.ui, "Order 1234", "for as long as it holds what the link said");
|
||||
Tap(d, "bar.back");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "A link filled this in", "which the way back empties it of");
|
||||
Tap(d, "bar.back");
|
||||
d.size = {0, 0, 400, 800};
|
||||
Build(d);
|
||||
}
|
||||
|
||||
// A link the app is started with is read before anything of the accounts is known: its form waits for them, and for
|
||||
// which of them pay links start from, and the accounts' page says that it does.
|
||||
void LinkWaiting(Fake::Bus& bus, sd_event* loop) {
|
||||
{
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link is taken before the accounts are known");
|
||||
Build(d);
|
||||
Check(d.app.Busy() && d.app.Screen() == "accounts", "and waits for them, on the page they will be on");
|
||||
Shows(d.ui, "A link asks for a payment.", "which says that it does");
|
||||
Hides(d.ui, "Shop BV", "and nothing of what the link asks, which the form is for");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "its form opens once they are known, asking which of them pays");
|
||||
Shows(d.ui, "A link filled this in, not you.", "as a link's");
|
||||
Shows(d.ui, "Order 1234", "filled in");
|
||||
TapBeside(d);
|
||||
Equal(d.app.Screen(), std::string("pay"), "a tap beside the question leaves the form");
|
||||
Shows(d.ui, "Main", "paying from the account pay links start from");
|
||||
Hides(d.ui, "Savings", "which is not the first one");
|
||||
Tap(d, "bar.back");
|
||||
Hides(d.ui, "A link asks for a payment", "and the accounts' page has no more to say of it");
|
||||
}
|
||||
{
|
||||
// The accounts known, and which of them pay links start from not: that is read first.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Settle(d);
|
||||
Check(d.app.Open(shopLink), "a link is taken once the accounts are known");
|
||||
Build(d);
|
||||
Check(d.app.Busy() && d.app.Screen() == "accounts", "and waits to hear which of them pay links start from");
|
||||
Shows(d.ui, "A link asks for a payment.", "saying so above the accounts");
|
||||
Shows(d.ui, "Savings", "which are listed meanwhile");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and then opens its form, with the question over it");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Main", "which pays from that account when it is left as it is");
|
||||
Hides(d.ui, "Savings", "and from no other");
|
||||
}
|
||||
{
|
||||
// No system bus: the link waits until the accounts can be read, which is tried again by hand.
|
||||
Driver d(bus, loop);
|
||||
d.noBus = true;
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link is taken without a system bus");
|
||||
Build(d);
|
||||
Shows(d.ui, "The system bus cannot be reached", "which is said as ever");
|
||||
Shows(d.ui, "A link asks for a payment.", "above the link that waits");
|
||||
d.noBus = false;
|
||||
Press(d, "overview.action");
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "a link whose accounts could not be read opens when they can be");
|
||||
Shows(d.ui, "Order 1234", "as the link filled it in");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Main", "from the account pay links start from, which is read with them");
|
||||
Hides(d.ui, "Savings", "and not from the first");
|
||||
}
|
||||
{
|
||||
// The user gone elsewhere while the accounts are read: what they are doing is not taken from them.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link is taken");
|
||||
Tap(d, "nav.cards");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("cards"), "a user who went to another place meanwhile stays there");
|
||||
Shows(d.ui, "The link's payment was not opened", "and is told that the link was not opened");
|
||||
Tap(d, "nav.accounts");
|
||||
Hides(d.ui, "A link asks for a payment", "the link is dropped");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "A link filled this in", "and nothing of it is in the pay form");
|
||||
Hides(d.ui, "Order 1234", "which is empty");
|
||||
}
|
||||
{
|
||||
// The user being told something when the accounts arrive: the form is not opened over that either.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink) && d.app.Open("payto://iban/NL00MARK"), "a link that cannot be read, after one that waits");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("accounts+link"), "is said to be one, and stays said");
|
||||
Shows(d.ui, "This link cannot be opened", "by name");
|
||||
Tap(d, "link.close");
|
||||
Equal(d.app.Screen(), std::string("accounts"), "and the link that waited is not opened under it");
|
||||
Tap(d, "home.pay");
|
||||
Hides(d.ui, "Order 1234", "nor left in the pay form");
|
||||
}
|
||||
{
|
||||
// The accounts known, and the system bus gone by the time the link comes: the reading of the account pay
|
||||
// links start from fails at once, inside the call that opens the link. The form opens all the same, once.
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Settle(d);
|
||||
d.noBus = true;
|
||||
bus.DisconnectOwn();
|
||||
RunUntil(d.loop, [] { return false; }, std::chrono::seconds(1));
|
||||
Check(d.app.Open(shopLink), "a link is taken with the accounts known and the system bus gone");
|
||||
Build(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "and opens its form from the accounts as they were known");
|
||||
Hides(d.ui, "The link's payment was not opened", "which is not said to be unopened over its own form");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Order 1234", "and is filled in as the link has it");
|
||||
}
|
||||
{
|
||||
// Another user of the machine, who chose no account for pay links to start from, and whose first connection
|
||||
// pays between their own accounts only: the form starts from the first account that pays anybody, which is
|
||||
// their second connection's.
|
||||
{
|
||||
std::lock_guard lock(bus.mutex);
|
||||
bus.clientUid = erinUid;
|
||||
bus.logindNames[erinUid] = "erin";
|
||||
}
|
||||
Client erin = Client::System();
|
||||
erin.AddBunqOAuth("production", "fake-client", "fake-secret", "http://127.0.0.1/cb", "code-carol-erin");
|
||||
erin.AddBunq(daveKey, "*", "");
|
||||
Driver d(bus, loop);
|
||||
d.app.Start();
|
||||
Check(d.app.Open(shopLink), "a link for a user who chose no account to start from");
|
||||
Settle(d);
|
||||
Equal(d.app.Screen(), std::string("pay+accounts"), "opens its form under the choice of their accounts");
|
||||
Check(Has(d, std::format("pick.{}", carolIban)) && Has(d, std::format("pick.{}", daveIban)), "both of them");
|
||||
TapBeside(d);
|
||||
Shows(d.ui, "Play money", "and starts from the first account that pays anybody");
|
||||
Hides(d.ui, "Shared", "which is not their first account: that one's connection pays their own accounts only");
|
||||
{
|
||||
std::lock_guard lock(bus.mutex);
|
||||
bus.clientUid = uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An account that goes while the app is looking at it: nostrod no longer knows it, and the app looks again.
|
||||
void Vanishing(Driver& d, Fake::Bus& bus, Fake::Bunq& bunq) {
|
||||
Client other = Client::System();
|
||||
|
|
@ -1648,7 +2013,7 @@ namespace {
|
|||
Tap(d, "bar.back");
|
||||
Tap(d, "nav.accounts");
|
||||
Shows(d.ui, "No answer yet", "where it is said too");
|
||||
// The settings while the account that pays at checkout cannot be read.
|
||||
// The settings while the account pay links start from cannot be read.
|
||||
SetPolkit(bus, Fake::Polkit::Deny, Bus::actionView);
|
||||
Check(d.app.Navigate("settings"), "the settings");
|
||||
Build(d);
|
||||
|
|
@ -1857,6 +2222,7 @@ int main(int argc, char* argv[]) {
|
|||
const std::uint64_t carol = bunq.AddPerson("Carol", "key-carol");
|
||||
bunq.AddAccount(carol, carolIban, "Shared", 500);
|
||||
bunq.AddGrant(carol, "code-carol", "token-carol");
|
||||
bunq.AddGrant(carol, "code-carol-erin", "token-carol-erin");
|
||||
const std::uint64_t dave = bunq.AddPerson("Dave", daveKey);
|
||||
bunq.AddAccount(dave, daveIban, "Play money", 12345);
|
||||
bunq.AddAccount(bunq.AddPerson("Alice", "key-alice-two"), otherAliceIban, "Other", 100);
|
||||
|
|
@ -1877,11 +2243,13 @@ int main(int argc, char* argv[]) {
|
|||
Cards(d, bus, bunq, alice);
|
||||
Settings(d, bus, bunq);
|
||||
OAuth(d, bus, bunq);
|
||||
Linking(d, bus, bunq);
|
||||
Vanishing(d, bus, bunq);
|
||||
Sizes(d);
|
||||
Routes(d);
|
||||
Late(bus, loop);
|
||||
Bare(bus, loop);
|
||||
LinkWaiting(bus, loop);
|
||||
Reconnecting(bus, loop);
|
||||
Gone(d, bus, nostrod);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// Currencies and amounts (Nostro:Currency) and the text helpers (Nostro:Utils): every parse with what it refuses,
|
||||
// every format, and the local-time helpers with a fixed time zone so the expectations hold anywhere.
|
||||
// every format, the local-time helpers with a fixed time zone so the expectations hold anywhere, and which characters
|
||||
// draw nothing or are a space.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
|
@ -93,6 +94,35 @@ namespace {
|
|||
Check(!QueryParameter(url, "missing"), "a parameter that is not there");
|
||||
Check(!QueryParameter("https://example.com/cb", "code"), "a URL without a query");
|
||||
}
|
||||
|
||||
using Range = std::pair<std::uint32_t, std::uint32_t>;
|
||||
|
||||
// What a password dialog is kept free of, written out again: a change to the library's list shows here.
|
||||
constexpr std::array<Range, 31> unshown = {{
|
||||
{0x0000, 0x001F}, {0x007F, 0x009F}, {0x00AD, 0x00AD}, {0x034F, 0x034F}, {0x0600, 0x0605}, {0x061C, 0x061C}, {0x06DD, 0x06DD}, {0x070F, 0x070F},
|
||||
{0x0890, 0x0891}, {0x08E2, 0x08E2}, {0x115F, 0x1160}, {0x17B4, 0x17B5}, {0x180B, 0x180F}, {0x200B, 0x200F}, {0x2028, 0x202E}, {0x2060, 0x206F},
|
||||
{0x3164, 0x3164}, {0xD800, 0xF8FF}, {0xFDD0, 0xFDEF}, {0xFE00, 0xFE0F}, {0xFEFF, 0xFEFF}, {0xFFA0, 0xFFA0}, {0xFFF0, 0xFFFC}, {0xFFFE, 0xFFFF},
|
||||
{0x110BD, 0x110BD}, {0x110CD, 0x110CD}, {0x13430, 0x1343F}, {0x1BCA0, 0x1BCA3}, {0x1D173, 0x1D17A}, {0xE0000, 0xE0FFF}, {0xF0000, 0xFFFFFFFF},
|
||||
}};
|
||||
constexpr std::array<Range, 8> blank = {{
|
||||
{0x0020, 0x0020}, {0x00A0, 0x00A0}, {0x1680, 0x1680}, {0x2000, 0x200A}, {0x202F, 0x202F}, {0x205F, 0x205F}, {0x2800, 0x2800}, {0x3000, 0x3000},
|
||||
}};
|
||||
|
||||
// Each range at both of its ends, and not what lies just outside it.
|
||||
void Characters() {
|
||||
for(const Range& range : unshown) {
|
||||
Check(Unshown(range.first) && Unshown(range.second), std::format("U+{:04X} to U+{:04X} draw nothing", range.first, range.second));
|
||||
Check((range.first == 0 || !Unshown(range.first - 1)) && (range.second == 0xFFFFFFFF || !Unshown(range.second + 1)), std::format("and what is beside U+{:04X} to U+{:04X} is drawn", range.first, range.second));
|
||||
}
|
||||
for(const std::uint32_t drawn : {0x41U, 0xE9U, 0x20ACU, 0xFFFDU, 0x1F600U}) {
|
||||
Check(!Unshown(drawn), std::format("U+{:04X} is drawn", drawn));
|
||||
}
|
||||
for(const Range& range : blank) {
|
||||
Check(Blank(range.first) && Blank(range.second), std::format("U+{:04X} to U+{:04X} are spaces", range.first, range.second));
|
||||
Check(!Blank(range.first - 1) && !Blank(range.second + 1), std::format("and what is beside U+{:04X} to U+{:04X} is none", range.first, range.second));
|
||||
}
|
||||
Check(!Blank('a') && !Blank(0x200B), "a letter is no space, and neither is a space without a width, which draws nothing");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
@ -102,5 +132,6 @@ int main() {
|
|||
Timestamps();
|
||||
LocalTime();
|
||||
Urls();
|
||||
Characters();
|
||||
return Test::Result();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,9 +264,10 @@ namespace {
|
|||
Fails({"cards", "freeze"}, "card id not provided");
|
||||
}
|
||||
|
||||
void Checkouts() {
|
||||
Works({"checkout", "account"}, "no account pays at checkout: `nostro checkout account <account>` chooses one");
|
||||
Works({"checkout", "account", annIban}, std::format("checkouts pay from Main\tBUNQNL2A {}\t€", annIban));
|
||||
// The account a pay link's form starts from in the app, which the command line can choose too.
|
||||
void PayLinkAccount() {
|
||||
Works({"checkout", "account"}, "no account is chosen for pay links to start from: `nostro checkout account <account>` chooses one");
|
||||
Works({"checkout", "account", annIban}, std::format("pay links start from Main\tBUNQNL2A {}\t€", annIban));
|
||||
Works({"checkout", "account"}, std::format("Main\tBUNQNL2A {}", annIban));
|
||||
Fails({"checkout", "account", std::string(carolIban)}, "is reached through OAuth, which pays only your own accounts");
|
||||
Fails({"checkout", "accounts"}, "unknown checkout command 'accounts'");
|
||||
|
|
@ -337,11 +338,10 @@ int main(int argc, char* argv[]) {
|
|||
Paying(bunq);
|
||||
Requesting();
|
||||
Cards(bunq, ann);
|
||||
Checkouts();
|
||||
PayLinkAccount();
|
||||
Removing(bunq);
|
||||
|
||||
bus.Disconnect("net.catcrafts.Nostro1");
|
||||
Equal(Fake::Wait(nostrod), 0, "nostrod ends when the bus goes");
|
||||
Check(bus.WaitForName("net.catcrafts.Nostro1.Checkout", false), "and its checkout with it");
|
||||
return Test::Result();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
// nostrod on a fake system bus (tests/Support/FakeBus.inc) in front of a fake bunq (tests/Support/FakeBunq.inc): the
|
||||
// daemon and its workers are this executable again (nostrod's main is compiled in), every call goes through
|
||||
// Nostro::Client or Nostro::Checkout, and the bus plays each user by the uid it gives a connection. Users kept apart, a
|
||||
// uid handed to a new user, every polkit answer and what the dialog is told, calls that wait on each other or do not,
|
||||
// checkouts and their retries, workers that die, idle exits, and how each error reaches the client.
|
||||
// Nostro::Client, and the bus plays each user by the uid it gives a connection. Users kept apart, a uid handed to a new
|
||||
// user, every polkit answer and what the dialog is told, calls that wait on each other or do not, the account pay
|
||||
// links start from, workers that die, idle exits, and how each error reaches the client.
|
||||
|
||||
#include "../../lib/json.hpp"
|
||||
#include <poll.h>
|
||||
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
import std;
|
||||
import Nostro;
|
||||
import Nostro.Checkout;
|
||||
import Crafter.Network;
|
||||
|
||||
#define main NostrodMain
|
||||
|
|
@ -46,6 +45,7 @@ namespace {
|
|||
constexpr std::uint32_t aliceUid = 4242;
|
||||
constexpr std::uint32_t bobUid = 4343;
|
||||
constexpr std::string_view name = "net.catcrafts.Nostro1";
|
||||
// The second name nostrod had until 2026-11-22, for a checkout over D-Bus that is gone.
|
||||
constexpr std::string_view checkoutName = "net.catcrafts.Nostro1.Checkout";
|
||||
const std::string aliceMain = "NL23BUNQ2025123456";
|
||||
const std::string aliceOther = "NL46BUNQ2025111111";
|
||||
|
|
@ -76,8 +76,6 @@ namespace {
|
|||
call();
|
||||
} catch(const DaemonError& e) {
|
||||
return Failure{e.name, e.what()};
|
||||
} catch(const Checkout::Error& e) {
|
||||
return Failure{e.name, e.what()};
|
||||
} catch(const std::exception& e) {
|
||||
return Failure{"exception", e.what()};
|
||||
}
|
||||
|
|
@ -203,22 +201,25 @@ namespace {
|
|||
return served;
|
||||
}
|
||||
|
||||
// The published contract: packaging/dbus/net.catcrafts.Nostro1.xml and net.catcrafts.Nostro1.Checkout.xml are the
|
||||
// interfaces nostrod serves, each under its own name alone, and the polkit policy declares every action nostrod asks
|
||||
// about and no other, each owned by the user nostrod runs as, with a dialog that uses no detail nostrod does not set,
|
||||
// and each but seeing asking for the user's password as it is shipped.
|
||||
// The published contract: packaging/dbus/net.catcrafts.Nostro1.xml is the interface nostrod serves, under the one
|
||||
// name it has, and the polkit policy declares every action nostrod asks about and no other, each owned by the user
|
||||
// nostrod runs as, with a dialog that uses no detail nostrod does not set, and each but seeing asking for the
|
||||
// user's password as it is shipped.
|
||||
void Contract(Fake::Bus& bus) {
|
||||
const std::string served = Introspect(bus, name);
|
||||
Check(Interface(served, name) == Interface(Slurp("packaging/dbus/net.catcrafts.Nostro1.xml"), name), std::format("packaging/dbus/net.catcrafts.Nostro1.xml is the interface nostrod serves, which is:\n{}", served));
|
||||
const std::string checkout = Introspect(bus, checkoutName);
|
||||
Check(Interface(checkout, checkoutName) == Interface(Slurp("packaging/dbus/net.catcrafts.Nostro1.Checkout.xml"), checkoutName), std::format("packaging/dbus/net.catcrafts.Nostro1.Checkout.xml is the checkout nostrod serves, which is:\n{}", checkout));
|
||||
// An app allowed to talk to the checkout's name reaches nothing else through it.
|
||||
Check(Interface(served, checkoutName).empty() && Interface(checkout, name).empty(), "each name serves its own interface alone");
|
||||
Check(!Raw(bus, checkoutName, name, "Connectors", true, [](sd_bus_message*) {}).empty(), "the checkout's name answers no other method");
|
||||
const std::string payHere = Raw(bus, name, checkoutName, "Pay", true, [](sd_bus_message* call) {
|
||||
// nostrod has no checkout: the interface that paid an app's order is gone, with its name. What a shop wants
|
||||
// paid reaches the user as a link, which only the app shows, and only as a form.
|
||||
const auto order = [](sd_bus_message* call) {
|
||||
sd_bus_message_append(call, "ssxssa{sv}", shopIban.c_str(), "Shop", std::int64_t{100}, "EUR", "1", 0u);
|
||||
});
|
||||
Check(!payHere.empty(), "and the other name pays no checkout");
|
||||
};
|
||||
Check(Interface(served, checkoutName).empty() && !fs::exists("packaging/dbus/net.catcrafts.Nostro1.Checkout.xml"), "nostrod serves no checkout, and none is published");
|
||||
Equal(Raw(bus, checkoutName, checkoutName, "Pay", true, order), std::string(SD_BUS_ERROR_SERVICE_UNKNOWN), "nobody owns the name a checkout had");
|
||||
Check(!Raw(bus, name, checkoutName, "Pay", true, order).empty() && !Raw(bus, name, name, "Pay", true, order).empty(), "and nostrod's own name pays no order");
|
||||
// The bus's policy still lets nostrod own that name: the nostrod of 0.0.0 asks for it when it starts, and the
|
||||
// system files may be newer than the Flatpak it runs from. It lets nobody call it.
|
||||
const std::string busPolicy = Slurp("packaging/system/net.catcrafts.Nostro1.conf");
|
||||
Check(busPolicy.contains(std::format("<allow own=\"{}\"/>", checkoutName)) && !busPolicy.contains(std::format("send_destination=\"{}\"", checkoutName)), "the bus's policy lets an older nostrod own the name it had, and lets nobody call it");
|
||||
|
||||
const std::string policy = Slurp("packaging/system/net.catcrafts.Nostro1.policy");
|
||||
std::vector<std::string> declared;
|
||||
|
|
@ -235,7 +236,7 @@ namespace {
|
|||
Check(action.substr(key).starts_with("$(summary)"), std::format("{} shows only details nostrod sets", declared.back()));
|
||||
}
|
||||
}
|
||||
const std::vector<std::string> asked = {std::string(Bus::actionView), std::string(Bus::actionChange), std::string(Bus::actionPay), std::string(Bus::actionUnfreezeCard), std::string(Bus::actionBlockCard), std::string(Bus::actionConnectors), std::string(Bus::actionCheckout)};
|
||||
const std::vector<std::string> asked = {std::string(Bus::actionView), std::string(Bus::actionChange), std::string(Bus::actionPay), std::string(Bus::actionUnfreezeCard), std::string(Bus::actionBlockCard), std::string(Bus::actionConnectors)};
|
||||
Check(std::ranges::is_permutation(declared, asked), "the policy declares the actions nostrod asks about, and no other");
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +459,7 @@ namespace {
|
|||
{"answering a request", [&alice] { alice.RespondToRequest(aliceMain, 1, true); }, "see your incoming requests for money"},
|
||||
{"answering a draft", [&alice] { alice.RespondToDraftPayment(aliceMain, 1, false); }, "see your draft payments"},
|
||||
{"a card's status", [&alice] { alice.SetCardStatus(1, "LOST"); }, "see your cards"},
|
||||
{"the account that pays at checkout", [&alice] { alice.SetDefaultCheckoutAccount("Nope"); }, accounts},
|
||||
{"the account pay links start from", [&alice] { alice.SetDefaultCheckoutAccount("Nope"); }, accounts},
|
||||
{"removing a connector", [&alice] { alice.RemoveConnector("Nobody"); }, "see your bank connectors"},
|
||||
{"the transactions of an account nobody has", [&alice] { alice.Transactions("Nope", {}); }, "see your transactions"},
|
||||
{"a listing of one", [&alice] { alice.Requests("Nope"); }, "see your requests for money"},
|
||||
|
|
@ -602,216 +603,26 @@ namespace {
|
|||
Equal(unknown, std::string(), "a query key nostrod does not know");
|
||||
}
|
||||
|
||||
// A stand-in for nostrod's checkout, for answers nostrod never gives, chosen by the order's reference: "extra", a
|
||||
// result the client does not know; "shape", an answer of another shape; "odd", an error of another name; "bare", an
|
||||
// error without a message; anything else, no answer at all. A plain object rather than a vtable, whose answers sd-bus would hold to its signature.
|
||||
class FakeCheckout {
|
||||
public:
|
||||
FakeCheckout() {
|
||||
sd_bus_open_system(&bus);
|
||||
sd_bus_add_object(bus, nullptr, "/net/catcrafts/Nostro1", OnCall, nullptr);
|
||||
sd_bus_request_name(bus, "net.catcrafts.Nostro1.Checkout", 0);
|
||||
thread = std::thread([this] {
|
||||
while(!stop) {
|
||||
while(sd_bus_process(bus, nullptr) > 0) {
|
||||
}
|
||||
sd_bus_wait(bus, 20000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FakeCheckout(const FakeCheckout&) = delete;
|
||||
FakeCheckout& operator=(const FakeCheckout&) = delete;
|
||||
|
||||
~FakeCheckout() {
|
||||
stop = true;
|
||||
thread.join();
|
||||
sd_bus_flush_close_unref(bus);
|
||||
}
|
||||
|
||||
private:
|
||||
static std::int32_t OnCall(sd_bus_message* call, void*, sd_bus_error*) {
|
||||
if(!sd_bus_message_is_method_call(call, "net.catcrafts.Nostro1.Checkout", "Pay")) {
|
||||
return 0;
|
||||
}
|
||||
sd_bus_message_skip(call, "ssxs");
|
||||
// sd-bus hands strings out as C strings.
|
||||
// lint-disable-next-line no-char-pointer
|
||||
const char* reference = nullptr;
|
||||
sd_bus_message_read_basic(call, 's', &reference);
|
||||
const std::string_view kind(reference);
|
||||
if(kind == "extra") {
|
||||
return sd_bus_reply_method_return(call, "ta{sv}", std::uint64_t{7}, 2u, "colour", "s", "blue", "repeated", "b", 1);
|
||||
}
|
||||
if(kind == "shape") {
|
||||
return sd_bus_reply_method_return(call, "s", "nonsense");
|
||||
}
|
||||
if(kind == "odd") {
|
||||
return sd_bus_reply_method_errorf(call, "org.example.Odd", "an error of another name");
|
||||
}
|
||||
if(kind == "bare") {
|
||||
const sd_bus_error bare = {"org.example.Bare", nullptr, 0};
|
||||
return sd_bus_reply_method_error(call, &bare);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sd_bus* bus = nullptr;
|
||||
std::thread thread;
|
||||
std::atomic<bool> stop{false};
|
||||
};
|
||||
|
||||
// Nostro.Checkout's own side: with no nostro on the bus, and against a stand-in for nostrod's checkout.
|
||||
void CheckoutClient(Fake::Bus& bus) {
|
||||
Checkout::Order order{.payeeIban = shopIban, .payeeName = "Shop", .amount = 1250, .reference = "1"};
|
||||
const Failure missing = FailureOf([&order] { Checkout::Pay(order); });
|
||||
Check(missing.name == SD_BUS_ERROR_SERVICE_UNKNOWN && missing.message.contains("nostro is not installed"), std::format("a checkout without nostro: {}", missing.message));
|
||||
Throws<std::invalid_argument>([] { Checkout::Pay({.payeeIban = "\xFF", .amount = 1, .reference = "1"}); }, "not UTF-8", "an order that is not UTF-8");
|
||||
|
||||
const auto pay = [&order](std::string_view reference, std::chrono::seconds timeout) {
|
||||
order.reference = std::string(reference);
|
||||
return Checkout::Pay(order, timeout);
|
||||
};
|
||||
{
|
||||
const FakeCheckout stand;
|
||||
Check(bus.WaitForName(checkoutName), "a stand-in for nostrod's checkout");
|
||||
const Checkout::Paid extra = pay("extra", std::chrono::seconds(20));
|
||||
Check(extra.paymentId == 7 && extra.repeated, "results the client does not know are skipped");
|
||||
Throws<std::system_error>([&pay] { pay("shape", std::chrono::seconds(20)); }, "cannot read nostrod's answer", "an answer of another shape");
|
||||
const Failure odd = FailureOf([&pay] { pay("odd", std::chrono::seconds(20)); });
|
||||
Check(odd.name == "org.example.Odd" && odd.message == "an error of another name", "an error of another name, as it came");
|
||||
const Failure bare = FailureOf([&pay] { pay("bare", std::chrono::seconds(20)); });
|
||||
Check(bare.name == "org.example.Bare" && bare.message.empty(), "and one without a message");
|
||||
const Failure late = FailureOf([&pay] { pay("silent", std::chrono::seconds(1)); });
|
||||
Check(late.name == SD_BUS_ERROR_TIMEOUT && late.message.contains("the order may have been paid"), std::format("no answer in time: {}", late.message));
|
||||
}
|
||||
Check(bus.WaitForName(checkoutName, false), "and the stand-in gone");
|
||||
}
|
||||
|
||||
// nostrod's side of a checkout: the account that pays, the prompt, the record that answers a retry, and every way an
|
||||
// order is refused.
|
||||
void Checkouts(Fake::Bus& bus, Fake::Bunq& bunq, const Bank& bank) {
|
||||
// The account a pay link's form starts from in the app, which nostrod keeps for the user and pays nothing from by
|
||||
// itself: none until one is chosen, never one that could pay no shop, chosen with the password that changing the
|
||||
// connections takes, and no longer chosen once the account is gone.
|
||||
void CheckoutAccount(Fake::Bus& bus, Fake::Bunq& bunq, const Bank& bank) {
|
||||
Client alice = As(bus, aliceUid);
|
||||
const auto pay = [&bus](const Checkout::Order& order) {
|
||||
{
|
||||
std::lock_guard lock(bus.mutex);
|
||||
bus.clientUid = aliceUid;
|
||||
}
|
||||
return Checkout::Pay(order);
|
||||
};
|
||||
const auto checks = [&bus](std::string_view reference) {
|
||||
std::lock_guard lock(bus.mutex);
|
||||
return std::ranges::count_if(bus.checks, [reference](const Fake::PolkitCheck& check) { return check.details.contains("reference") && check.details.at("reference") == reference; });
|
||||
};
|
||||
const std::string payments = std::format("/user/{}/monetary-account/{}/payment", bank.alice, bank.aliceMainId);
|
||||
const Checkout::Order order{.payeeIban = shopIban, .payeeName = "Shop", .amount = 1250, .reference = "order-1"};
|
||||
|
||||
Check(!alice.DefaultCheckoutAccount().has_value() && Summary(bus) == "see which account pays at checkout", "no account pays at checkout until one is chosen");
|
||||
Throws<Checkout::NoCheckoutAccount>([&pay, &order] { pay(order); }, "no account is chosen to pay checkouts from", "a checkout before an account is chosen");
|
||||
Check(!alice.DefaultCheckoutAccount().has_value() && Summary(bus) == "see which account pay links start from", "no account is the one pay links start from until one is chosen");
|
||||
Throws<std::invalid_argument>([&alice] { alice.SetDefaultCheckoutAccount(carolIban); }, "is reached through OAuth, which pays only your own accounts", "an account that could pay no shop");
|
||||
const Account chosen = alice.SetDefaultCheckoutAccount(aliceMain);
|
||||
Check(chosen.iban == aliceMain && chosen.name == "Main", "an account chosen, and shown");
|
||||
Check(bus.LastCheck().action == "net.catcrafts.Nostro1.Connectors" && Summary(bus) == std::format("let apps ask you to pay from {} (Main) at checkout", aliceMain), "choosing it is a change to the connections");
|
||||
Equal(alice.DefaultCheckoutAccount().value_or(Account{}).iban, aliceMain, "the account checkouts pay from");
|
||||
|
||||
const std::size_t before = bunq.Count("POST", payments);
|
||||
const Checkout::Paid paid = pay(order);
|
||||
Check(paid.paymentId != 0 && !paid.repeated, "an order paid");
|
||||
const Fake::PolkitCheck check = bus.LastCheck();
|
||||
Equal(check.action, std::string("net.catcrafts.Nostro1.Checkout"), "paying at checkout is an action of its own");
|
||||
Equal(check.details.at("summary"), std::format("pay €12.50 to {} (Shop) from {} (Main), as an app asks at checkout, reference order-1", shopIban, aliceMain), "the dialog shows the order, and the account that pays it");
|
||||
Check(check.details.at("reference") == "order-1" && check.details.at("amount_minor") == "1250" && check.details.at("account_iban") == aliceMain && check.details.at("counterparty") == shopIban, "and gives polkit rules the details");
|
||||
Equal(bunq.Count("POST", payments), before + 1, "one payment");
|
||||
Check(check.action == "net.catcrafts.Nostro1.Connectors" && Summary(bus) == std::format("have pay links start from {} (Main)", aliceMain), "choosing it is a change to the connections, and the dialog says what is chosen");
|
||||
Check(check.details.at("account_iban") == aliceMain && check.details.at("environment") == "production", "with the details a rule can test");
|
||||
Equal(alice.DefaultCheckoutAccount().value_or(Account{}).iban, aliceMain, "the account pay links start from");
|
||||
|
||||
const Checkout::Paid again = pay(order);
|
||||
Check(again.paymentId == paid.paymentId && again.repeated, "the same order again answers with its payment");
|
||||
Check(checks("order-1") == 1 && bunq.Count("POST", payments) == before + 1, "without asking, or paying, again");
|
||||
|
||||
const auto refused = [&pay](Checkout::Order changed, std::string_view part, std::string_view what) {
|
||||
const Failure failure = FailureOf([&pay, &changed] { pay(changed); });
|
||||
Check(failure.name == Checkout::errorInvalidArgument && failure.message.contains(part), std::format("{}: {}", what, failure.message));
|
||||
};
|
||||
Checkout::Order changed = order;
|
||||
changed.amount = 1300;
|
||||
refused(changed, "reference order-1 to NL91ABNA0417164300 is an order of another amount than €13.00", "a reference paid for another amount");
|
||||
// Which amount it was paid for is not said: whoever knows an order's payee and reference could ask for it.
|
||||
const Failure other = FailureOf([&pay, &changed] { pay(changed); });
|
||||
Check(!other.message.contains("12.50") && !other.message.contains("1250"), std::format("and not for which amount: {}", other.message));
|
||||
changed = order;
|
||||
changed.payeeIban = "shop@example.com";
|
||||
refused(changed, "checkout pays an IBAN, and 'shop@example.com' is none", "a payee that is no IBAN");
|
||||
changed.payeeIban = "NL00BUNQ0000000000";
|
||||
refused(changed, "is not a valid IBAN", "an IBAN with a typo");
|
||||
changed = order;
|
||||
changed.amount = 0;
|
||||
refused(changed, "more than zero", "nothing to pay");
|
||||
changed = order;
|
||||
changed.currency = "USD";
|
||||
refused(changed, "unsupported currency 'USD'", "a currency nostro does not pay in");
|
||||
changed = order;
|
||||
changed.reference = "";
|
||||
refused(changed, "an order needs a reference", "an order without a reference");
|
||||
|
||||
// bunq refusing it before doing anything: the order was not paid, and is paid when asked again.
|
||||
Checkout::Order refusedOrder = order;
|
||||
refusedOrder.reference = "order-2";
|
||||
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 400, .body = R"({"Error":[{"error_description":"Not enough money."}]})"});
|
||||
const Failure poor = FailureOf([&pay, &refusedOrder] { pay(refusedOrder); });
|
||||
Check(poor.name == Checkout::errorBank && poor.message.contains("bunq: Not enough money. (400)"), std::format("bunq's refusal: {}", poor.message));
|
||||
// The app is told what the bank said, and not which call it said it to: that names the user and the account.
|
||||
const auto namesNoAccount = [](const Failure& failure) {
|
||||
return !failure.message.contains("/user/") && !failure.message.contains("monetary-account") && !failure.message.contains(aliceMain);
|
||||
};
|
||||
Check(namesNoAccount(poor), std::format("without the user or the account at the bank: {}", poor.message));
|
||||
Check(!pay(refusedOrder).repeated, "and the order paid when asked again");
|
||||
|
||||
// bunq's answer lost: the order may have been paid, and is not paid again.
|
||||
Checkout::Order lostOrder = order;
|
||||
lostOrder.reference = "order-3";
|
||||
bunq.Fail(Fault{.method = "POST", .path = "/user/", .status = 500, .body = R"({"Error":[{"error_description":"Hiccup."}]})"});
|
||||
const Failure hiccup = FailureOf([&pay, &lostOrder] { pay(lostOrder); });
|
||||
Check(hiccup.name == Checkout::errorBank && hiccup.message.contains("may have been carried out") && namesNoAccount(hiccup), std::format("an answer that may hide a payment, also without the account: {}", hiccup.message));
|
||||
const Failure lost = FailureOf([&pay, &lostOrder] { pay(lostOrder); });
|
||||
Check(lost.name == Checkout::errorFailed && lost.message.contains("order order-3 to NL91ABNA0417164300 may have been paid already") && !lost.message.contains(aliceMain), std::format("such an order asked again, without the account: {}", lost.message));
|
||||
|
||||
Checkout::Order unconfirmed = order;
|
||||
unconfirmed.reference = "order-4";
|
||||
SetPolkit(bus, Fake::Polkit::Dismiss, Bus::actionCheckout);
|
||||
Throws<Checkout::Cancelled>([&pay, &unconfirmed] { pay(unconfirmed); }, "you did not authenticate", "an order the user did not confirm");
|
||||
|
||||
// Asked again while the user is still at the prompt: the second call waits for the first, and gets its answer.
|
||||
SetPolkit(bus, Fake::Polkit::Slow, Bus::actionCheckout);
|
||||
Checkout::Paid first;
|
||||
std::thread paying([&pay, &unconfirmed, &first] { first = pay(unconfirmed); });
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
changed = unconfirmed;
|
||||
changed.amount = 99;
|
||||
refused(changed, "is an order of another amount than €0.99", "another amount while the order is being paid");
|
||||
const Checkout::Paid waited = pay(unconfirmed);
|
||||
paying.join();
|
||||
Check(first.paymentId != 0 && waited.paymentId == first.paymentId && !first.repeated && waited.repeated, "a retry while the first call is at the prompt gets the first call's payment");
|
||||
Equal(checks("order-4"), std::ptrdiff_t{2}, "and the user is asked once for it, after the dismissed dialog");
|
||||
|
||||
SetPolkit(bus, Fake::Polkit::Silent, Bus::actionCheckout);
|
||||
Checkout::Order unanswered = order;
|
||||
unanswered.reference = "order-5";
|
||||
Failure gaveUp;
|
||||
std::thread asking([&pay, &unanswered, &gaveUp] { gaveUp = FailureOf([&pay, &unanswered] { pay(unanswered); }); });
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
const Failure alsoGaveUp = FailureOf([&pay, &unanswered] { pay(unanswered); });
|
||||
asking.join();
|
||||
Check(gaveUp.name == SD_BUS_ERROR_ACCESS_DENIED && alsoGaveUp.name == gaveUp.name && alsoGaveUp.message == gaveUp.message, "and the first call's refusal, when it is refused");
|
||||
SetPolkit(bus, Fake::Polkit::Allow);
|
||||
|
||||
// An account chosen and since closed pays no checkout.
|
||||
// An account chosen and since closed is chosen no more.
|
||||
const std::uint64_t brief = bunq.AddAccount(bank.alice, briefIban, "Brief", 1000);
|
||||
Equal(alice.SetDefaultCheckoutAccount(briefIban).iban, briefIban, "an account opened since");
|
||||
bunq.ChangeAccount(brief, json{{"status", "CANCELLED"}});
|
||||
alice.Accounts();
|
||||
Check(!alice.DefaultCheckoutAccount().has_value(), "a closed account pays at checkout no more");
|
||||
Checkout::Order orphan = order;
|
||||
orphan.reference = "order-6";
|
||||
Throws<Checkout::NoCheckoutAccount>([&pay, &orphan] { pay(orphan); }, "or it is gone", "nor does a checkout pay from it");
|
||||
Check(!alice.DefaultCheckoutAccount().has_value(), "a closed account is the one pay links start from no more");
|
||||
alice.SetDefaultCheckoutAccount(aliceMain);
|
||||
}
|
||||
|
||||
|
|
@ -872,7 +683,7 @@ namespace {
|
|||
Fake::Limit(limited, RLIMIT_NPROC, processes);
|
||||
bus.Disconnect(name);
|
||||
Equal(Fake::Wait(limited), 0, "it ends with the bus");
|
||||
Check(bus.WaitForName(name, false) && bus.WaitForName(checkoutName, false), "and lets go of its names");
|
||||
Check(bus.WaitForName(name, false), "and lets go of its name");
|
||||
}
|
||||
|
||||
void Idle(Fake::Bus& bus, const fs::path& state) {
|
||||
|
|
@ -922,7 +733,6 @@ int main(int argc, char* argv[]) {
|
|||
bunq.AddAccount(bunq.AddPerson("Dave", "key-dave"), daveIban, "Dave's", 100);
|
||||
|
||||
NotRunning(bus);
|
||||
CheckoutClient(bus);
|
||||
const pid_t nostrod = Fake::StartNostrod({"--state", state.string(), "--idle", "60", "--prompt-timeout", "2"});
|
||||
Check(bus.WaitForName(name), "nostrod owns its name");
|
||||
Contract(bus);
|
||||
|
|
@ -933,12 +743,12 @@ int main(int argc, char* argv[]) {
|
|||
Lookups(bus, bunq, nostrod);
|
||||
Concurrency(bus, bunq, bank);
|
||||
Errors(bus, bunq, bank, state);
|
||||
Checkouts(bus, bunq, bank);
|
||||
CheckoutAccount(bus, bunq, bank);
|
||||
Workers(bus, nostrod);
|
||||
Notes(bus, bunq);
|
||||
bus.Disconnect(name);
|
||||
Equal(Fake::Wait(nostrod), 0, "nostrod ends when the bus goes, after its workers");
|
||||
Check(bus.WaitForName(name, false) && bus.WaitForName(checkoutName, false), "and lets go of its names");
|
||||
Check(bus.WaitForName(name, false), "and lets go of its name");
|
||||
|
||||
SpawnFailure(bus, state);
|
||||
Idle(bus, state);
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
// Nostro.App without nostrod: how money, days and the bank's capitals are worded (in a fixed time zone, so the
|
||||
// expectations hold anywhere), what each form reads from what was typed and what it refuses, what every error
|
||||
// nostrod can answer with is explained as, and what the app knows of each bank it can connect.
|
||||
// expectations hold anywhere), what each form reads from what was typed and what it refuses, what a link that asks
|
||||
// for a payment is read as and everything it is refused for, what every error nostrod can answer with is explained
|
||||
// as, and what the app knows of each bank it can connect.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
|
@ -228,6 +229,182 @@ namespace {
|
|||
Check(form.to.value.empty() && form.amount.value.empty() && form.when == When::Now && form.unit == 0 && form.day.value.empty() && !form.tried, "a cleared form is as new");
|
||||
}
|
||||
|
||||
// A link that asks for a payment, as a website's pay button opens one: what is read from it, everything it is
|
||||
// refused for, and the form it fills in. Whoever wrote the link chose every character of it.
|
||||
void Linking() {
|
||||
const std::string to = std::format("payto://iban/{}", iban);
|
||||
const auto times = [](std::string_view text, std::size_t count) {
|
||||
std::string repeated;
|
||||
for(std::size_t i = 0; i < count; i++) {
|
||||
repeated += text;
|
||||
}
|
||||
return repeated;
|
||||
};
|
||||
// The link with options after it.
|
||||
const auto with = [&to](std::string_view options) { return std::format("{}?{}", to, options); };
|
||||
|
||||
struct Asked {
|
||||
std::string link;
|
||||
std::string name;
|
||||
std::optional<std::int64_t> amount;
|
||||
std::string description;
|
||||
std::string_view what;
|
||||
};
|
||||
const std::vector<Asked> read = {
|
||||
{to, "", std::nullopt, "", "an IBAN alone: how much and what for are the user's to say"},
|
||||
{"PAYTO://IBAN/nl91abna0417164300", "", std::nullopt, "", "the scheme in capitals and the IBAN in small letters"},
|
||||
{std::format("payto://iban/ABNANL2A/{}", iban), "", std::nullopt, "", "a bank's code of eight before the IBAN, which is left out"},
|
||||
{std::format("payto://iban/ABNANL2AXXX/{}", iban), "", std::nullopt, "", "or one of eleven"},
|
||||
{with(""), "", std::nullopt, "", "a question mark with nothing after it"},
|
||||
{with("amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234"), "Shop BV", 1250, "Order 1234", "who, how much and what for"},
|
||||
{with("amount=EUR%3A12.5"), "", 1250, "", "the amount's colon as an escape, as a browser's own writer of queries has it"},
|
||||
{with("amount=eur:12"), "", 1200, "", "the currency in small letters, and no cents"},
|
||||
{with("amount=EUR:0012.50"), "", 1250, "", "zeros before it"},
|
||||
{with("amount=EUR:999999999999.99"), "", 99999999999999, "", "the most a form takes"},
|
||||
{with("message=a+b%2Bc"), "", std::nullopt, "a b+c", "a plus for a space, and an escaped one for a plus"},
|
||||
{with("receiver-name=%20Bob%20"), "Bob", std::nullopt, "", "spaces around a name are not part of it"},
|
||||
{with("message"), "", std::nullopt, "", "an option without a value says nothing"},
|
||||
{with("AMOUNT=EUR:1&%6Dessage=x&Receiver-Name=Bob"), "Bob", 100, "x", "an option's name in capitals or as escapes is that option"},
|
||||
{with("utm_source=mail&sender-name=Eve&flag&=x&&amount=EUR:5&"), "", 500, "", "what Nostro does not know is passed over, wherever it stands"},
|
||||
{with("message=caf%C3%A9%20%E2%82%AC%20%F0%9F%98%80"), "", std::nullopt, "café € 😀", "characters of two, three and four bytes, as escapes"},
|
||||
{with("receiver-name=Café René"), "Café René", std::nullopt, "", "or as they are"},
|
||||
{with("receiver-name=Fish%20%26%20Chips%20%3CNL%3E&message=5%20%24(each)"), "Fish & Chips <NL>", std::nullopt, "5 $(each)", "an &, a <, a > and a $( are a name's and a description's to have: only the system's dialog shows a name otherwise"},
|
||||
{std::format("{}?receiver-name={}&message={}", to, times("a", 70), times("b", 140)), times("a", 70), std::nullopt, times("b", 140), "a name of 70 characters and a description of 140"},
|
||||
{std::format("{}?receiver-name={}&message={}", to, times("%C3%A9", 70), times("%E2%82%AC", 140)), times("é", 70), std::nullopt, times("€", 140), "counted in characters, not in bytes"},
|
||||
};
|
||||
for(const Asked& asked : read) {
|
||||
const Read<PaymentLink> link = ReadPaymentLink(asked.link);
|
||||
Check(link.value && link.error.empty() && link.value->iban == iban && link.value->name == asked.name && link.value->amount == asked.amount && link.value->currency == euro && link.value->description == asked.description, std::format("a link is read: {}", asked.what));
|
||||
// What is read is what the form then holds, to the letter, and what its order asks nostrod for.
|
||||
PaymentForm form;
|
||||
form.Fill(link.value.value_or(PaymentLink()));
|
||||
Check(form.linked && form.to.value == iban && form.name.value == asked.name && form.description.value == asked.description && ReadAmount(form.amount.value, euro).value == asked.amount, std::format("and fills the form in with just that: {}", asked.what));
|
||||
}
|
||||
|
||||
constexpr std::string_view notOne = "It is not a link to pay an IBAN";
|
||||
constexpr std::string_view noIban = "The IBAN in it is not a valid one";
|
||||
constexpr std::string_view damaged = "something in it is there twice, or cannot be read";
|
||||
constexpr std::string_view instruction = "a reference of a kind Nostro cannot send along";
|
||||
constexpr std::string_view noAmount = "The amount in it cannot be read";
|
||||
constexpr std::string_view noCurrency = "a currency Nostro does not pay in";
|
||||
constexpr std::string_view notPlain = "holds what a payment cannot carry";
|
||||
constexpr std::string_view tooLong = "is too long";
|
||||
const std::vector<std::tuple<std::string, std::string_view, std::string_view>> refused = {
|
||||
{"", notOne, "nothing"},
|
||||
{"https://example.org/pay?to=MARK", notOne, "a web address"},
|
||||
{"payto:iban/NL91ABNA0417164300", notOne, "a scheme without its slashes"},
|
||||
{"payto://bic/ABNANL2A", notOne, "a bank's code and no account"},
|
||||
{"payto://bitcoin/1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", notOne, "something that is no IBAN"},
|
||||
{"payto://user@iban/NL91ABNA0417164300", notOne, "a user before the kind of account"},
|
||||
{"payto://pay/iban/NL91ABNA0417164300", notOne, "a kind of account that is none"},
|
||||
{"nostro://iban/NL91ABNA0417164300", notOne, "a scheme of Nostro's own, which there is none of"},
|
||||
{std::format(" {}", to), notOne, "a space before it"},
|
||||
{std::format("{}#MARK", to), notOne, "a fragment"},
|
||||
{with("message=a#MARK"), notOne, "a fragment after the options"},
|
||||
{with(std::format("x={}", times("a", 4096))), notOne, "a link longer than any that asks for a payment"},
|
||||
{std::format("payto://iban/ABNANL2/{}", iban), notOne, "a bank's code of seven"},
|
||||
{std::format("payto://iban/ABNANL2AX/{}", iban), notOne, "one of nine"},
|
||||
{std::format("payto://iban/ABNA-L2A/{}", iban), notOne, "one that is not letters and digits"},
|
||||
{std::format("payto://iban//{}", iban), notOne, "an empty one"},
|
||||
{"payto://iban/", noIban, "no IBAN"},
|
||||
{"payto://iban/?amount=EUR:1", noIban, "no IBAN before the options"},
|
||||
{"payto://iban/NL91ABNA0417164301", noIban, "an IBAN whose check digits do not hold"},
|
||||
{"payto://iban/NL91%41BNA0417164300", noIban, "an escape in the IBAN"},
|
||||
{"payto://iban/NL91 ABNA 0417 1643 00", noIban, "spaces in it"},
|
||||
{"payto://iban/bob@example.org", noIban, "an e-mail address"},
|
||||
{"payto://iban/+31612345678", noIban, "a phone number"},
|
||||
{std::format("payto://iban/ABNANL2A/ABNANL2A/{}", iban), noIban, "two banks' codes"},
|
||||
{"payto://iban/ABNANL2A/", noIban, "a bank's code and nothing after it"},
|
||||
{with("amount=EUR:1&amount=EUR:2"), damaged, "two amounts"},
|
||||
{with("amount=EUR:1&AMOUNT=EUR:1000"), damaged, "a second amount in capitals"},
|
||||
{with("%61mount=EUR:1000&amount=EUR:1"), damaged, "a first amount behind an escape"},
|
||||
{with("message=a&x=1&message=MARK"), damaged, "two descriptions"},
|
||||
{with("receiver-name=a&receiver-name=MARK"), damaged, "two names"},
|
||||
{with("message=100%"), damaged, "a percent sign that begins no escape"},
|
||||
{with("message=MARK%4"), damaged, "an escape cut short"},
|
||||
{with("receiver-name=%zzMARK"), damaged, "an escape that is no number"},
|
||||
{with("receiver-name=%4zMARK"), damaged, "an escape that is half a number"},
|
||||
{with("amount=EUR%3"), damaged, "an escape cut short in the amount"},
|
||||
{with("instruction=RF18539007547034"), instruction, "a reference for the payee's bank to pass on"},
|
||||
{with("instruction="), instruction, "an empty one"},
|
||||
{with("instruction"), instruction, "one without a value"},
|
||||
{with("INSTRUCTION=MARK"), instruction, "one in capitals"},
|
||||
{with("amount=12.50"), noAmount, "an amount without its currency"},
|
||||
{with("amount=EUR"), noAmount, "a currency without an amount"},
|
||||
{with("amount=EUR:"), noAmount, "a currency and a colon"},
|
||||
{with("amount="), noAmount, "an empty amount"},
|
||||
{with("amount"), noAmount, "an amount without a value"},
|
||||
{with("amount=EUR:12,50"), noAmount, "a comma for the point: twelve hundred and fifty by the letter of RFC 8905, twelve and a half to whoever wrote it"},
|
||||
{with("amount=EUR:1,250.00"), noAmount, "a comma between the thousands"},
|
||||
{with("amount=EUR:-1"), noAmount, "less than nothing"},
|
||||
{with("amount=EUR:+1"), noAmount, "a plus, which reads as a space"},
|
||||
{with("amount=EUR:%201"), noAmount, "a space"},
|
||||
{with("amount=EUR:12."), noAmount, "a point with nothing after it"},
|
||||
{with("amount=EUR:.5"), noAmount, "a point with nothing before it"},
|
||||
{with("amount=EUR:1.2.3"), noAmount, "two points"},
|
||||
{with("amount=EUR:1e3"), noAmount, "a power of ten"},
|
||||
{with("amount=EUR:%D9%A1%D9%A2"), noAmount, "digits of another script"},
|
||||
{with("amount=EUR:1.234"), noAmount, "more decimals than the euro has"},
|
||||
{with("amount=EUR:0"), noAmount, "nothing"},
|
||||
{with("amount=EUR:0.00"), noAmount, "nothing, to the cent"},
|
||||
{with("amount=EUR:1234567890123"), noAmount, "more than a form takes"},
|
||||
{with("amount=USD:1"), noCurrency, "another currency"},
|
||||
{with("amount=Eur:1"), noCurrency, "a currency in neither capitals nor small letters"},
|
||||
{with("amount=EURO:1"), noCurrency, "a currency's name"},
|
||||
{with("amount=:1"), noCurrency, "no currency before the colon"},
|
||||
{with("message=MARK%00"), notPlain, "a zero byte"},
|
||||
{with("message=MARK%0AMARK"), notPlain, "a new line"},
|
||||
{with("message=MARK%09"), notPlain, "a tab"},
|
||||
{with("receiver-name=MARK%7F"), notPlain, "a delete"},
|
||||
{with("receiver-name=MARK%C2%85"), notPlain, "a control of the second kind"},
|
||||
{with("receiver-name=MA%E2%80%8BRK"), notPlain, "a space without a width"},
|
||||
{with("receiver-name=%E2%80%AEMARK"), notPlain, "a mark that turns the text around"},
|
||||
{with("receiver-name=MARK%C2%A0BV"), notPlain, "a space that is not the ordinary one"},
|
||||
{with("message=MARK%C2%AD"), notPlain, "a soft hyphen"},
|
||||
{with("message=%EF%BB%BFMARK"), notPlain, "a byte order mark"},
|
||||
{with("message=%EE%80%80MARK"), notPlain, "a character of private use"},
|
||||
{with("message=M%C1%81RK"), notPlain, "an A written in two bytes, which reads as one and is none"},
|
||||
{with("message=%E0%80%AFMARK"), notPlain, "a slash written in three"},
|
||||
{with("message=%F0%80%80%AFMARK"), notPlain, "and in four"},
|
||||
{with("message=%ED%A0%80MARK"), notPlain, "half of a pair"},
|
||||
{with("message=%F4%90%80%80MARK"), notPlain, "a character beyond the last there is"},
|
||||
{with("message=MARK%F0%9F%BF%BE"), notPlain, "the last but one of the second plane, which is no character and which the bus refuses"},
|
||||
{with("receiver-name=MARK%F3%AF%BF%BF"), notPlain, "and the last of the fifteenth"},
|
||||
{with("message=%F8%88%80%80%80MARK"), notPlain, "five bytes, which begin no character"},
|
||||
{with("message=MARK%C3"), notPlain, "a character cut short"},
|
||||
{with("message=%FFMARK"), notPlain, "a byte that is in no character"},
|
||||
{with("message=MARK%EF%BF%BD"), notPlain, "the mark that stands for what could not be read"},
|
||||
{std::format("{}?receiver-name={}", to, times("a", 71)), tooLong, "a name of 71 characters"},
|
||||
{std::format("{}?message={}", to, times("%C3%A9", 141)), tooLong, "a description of 141"},
|
||||
};
|
||||
for(const auto& [link, why, what] : refused) {
|
||||
const Read<PaymentLink> none = ReadPaymentLink(link);
|
||||
Check(!none.value && none.error.contains(why), std::format("a link is refused for {}: {}", what, why));
|
||||
// Why it was refused is said in the app's own words: nothing of a stranger's link comes back in them.
|
||||
Check(!none.error.contains("MARK") && !none.error.contains("NL91") && !none.error.contains("payto"), std::format("and what says so holds nothing of the link: {}", what));
|
||||
}
|
||||
|
||||
// The form a link fills in: all of it the link's, in place of whatever was there, and none of it sent.
|
||||
const Moment now = ParseLocalDate("2026-11-19 15:00");
|
||||
PaymentForm form;
|
||||
form.to.Set("bob@example.org");
|
||||
form.description.Set("lunch");
|
||||
form.when = When::Scheduled;
|
||||
form.day.Set("2026-12-01");
|
||||
form.unit = 3;
|
||||
form.every.Set("2");
|
||||
form.tried = true;
|
||||
form.Fill(*ReadPaymentLink(with("amount=EUR:12.50&receiver-name=Shop%20BV&message=Order%201234")).value);
|
||||
PaymentOrder order;
|
||||
Check(!form.Check(euro, now, order).Any() && order.to.type == "IBAN" && order.to.value == iban && order.to.name == "Shop BV" && order.amount == 1250 && order.description == "Order 1234" && order.when == When::Now, "a link's form asks for what the link said, now");
|
||||
Check(form.linked && !form.tried && form.day.value.empty() && form.unit == 0 && form.every.value.empty(), "with nothing left of what the form held before, and marked as a link's");
|
||||
form.Fill(*ReadPaymentLink(to).value);
|
||||
const PaymentForm::Errors errors = form.Check(euro, now, order);
|
||||
Check(form.linked && form.amount.value.empty() && form.name.value.empty() && errors.amount == "Enter an amount" && errors.name == "The name of the account's holder", "a link that says no more than who is paid leaves the rest to the user");
|
||||
form.Clear();
|
||||
Check(!form.linked && form.to.value.empty(), "a cleared form is nobody's");
|
||||
}
|
||||
|
||||
void Asking() {
|
||||
RequestForm form;
|
||||
RequestOrder order;
|
||||
|
|
@ -428,6 +605,7 @@ int main() {
|
|||
Words();
|
||||
Reading();
|
||||
Paying();
|
||||
Linking();
|
||||
Asking();
|
||||
Filtering();
|
||||
Connecting();
|
||||
|
|
|
|||
Loading…
Reference in a new issue