feat(app): add the Nostro app, a window for phones and desktops
Linux phones have no banking apps, and a command line is no answer on a phone. The app does everything the nostro command does and, like it, only talks to nostrod: it holds no key and no token. - Nostro.Ui, a toolkit whose screens are functions that fill a frame, ported from imsd-messages ca5cd72d; Nostro.App, the app's state, forms and screens; Nostro.Ui.Shell, which puts them on a Wayland window with Crafter.Graphics; nostro-app; and Nostro.DebugCommands for the --debug-api build. - Client: every method also in an asynchronous form for an sd-event loop, with DaemonMissing and OutcomeUnknown. - nostrod's Flatpak is net.catcrafts.Nostrod now and the app takes net.catcrafts.Nostro; install.sh moves the state. The app's Flatpak, both Flatpaks cross-built for aarch64, and the licence texts they carry. - nostro-fake-system, a made-up bus and bank with a real nostrod on them, to look at the app against. The README's screenshots are taken on it. - The nostro command: an API key's environment is the key's own to say, so --sandbox is for bunq-oauth alone, and a virtual card is listed as VIRTUAL. The published contract changes in three places, before any release (design rule 10): - Transactions' query takes `stored`: answered from what nostrod has stored, without asking the bank. The app searches with it; before, every search was a call to bunq. - AddBunq's `environment` no longer chooses over what the key says of itself: a key of the other environment is refused. - SetCardStatus refuses to freeze or unfreeze a virtual card. bunq reports one as DEACTIVATED however well it pays, and leaves it as it is when asked, without an error. The app is GPL-3.0-only, the library stays LGPL-3.0-only, and no code moved from one to the other (design rule 13). Transaction's schema is unchanged. Verified: the 17 tests pass with every line, function and region of what they link run, and the five lint runs are clean. Every screen was looked at on the made-up system, at a phone's and a desktop's sizes in the light and the dark look, on Plasma under Wayland. What is said of bunq's cards comes from its sandbox, with throwaway users, and from one real virtual card. Known to have been used against production: connecting, and reading accounts, payments and cards. Not known to have been tried: a payment from the app against bunq, OAuth against bunq, and anything on a phone. Building the app takes --graphics=, a Crafter.Graphics checkout on its branch claude/nostro-app, until that branch is merged and pinned here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
1ea50c50bc
commit
5b4037955b
106 changed files with 17804 additions and 289 deletions
|
|
@ -27,7 +27,7 @@ std::deque<BunqConnector> BunqConnector::connectors;
|
|||
|
||||
namespace {
|
||||
constexpr std::string_view userAgent = "Nostro";
|
||||
constexpr std::string_view maybeCarriedOut = "; the request may have been carried out, check before trying again";
|
||||
constexpr std::string_view maybeCarriedOut = BunqError::maybeCarriedOut;
|
||||
|
||||
// Where BunqConnector::RedirectTo sends everything.
|
||||
std::optional<BunqEndpoint>& Redirected() {
|
||||
|
|
@ -424,6 +424,21 @@ std::string BunqConnector::OAuthAuthorizationUrl(BunqEnvironment environment, st
|
|||
return std::format("https://{}/auth?response_type=code&client_id={}&redirect_uri={}&state={}", environment == BunqEnvironment::Production ? "oauth.bunq.com" : "oauth.sandbox.bunq.com", UrlEncode(clientId), UrlEncode(redirectUri), UrlEncode(state));
|
||||
}
|
||||
|
||||
std::string BunqConnector::OAuthCodeFromRedirect(std::string_view redirected, std::string_view state) {
|
||||
if(const std::optional<std::string> error = QueryParameter(redirected, "error")) {
|
||||
throw std::runtime_error(std::format("bunq did not authorize: {} {}", *error, QueryParameter(redirected, "error_description").value_or("")));
|
||||
}
|
||||
const std::optional<std::string> code = QueryParameter(redirected, "code");
|
||||
if(!code || code->empty()) {
|
||||
throw std::runtime_error("that address has no code= in it");
|
||||
}
|
||||
// `state` ties the redirect to this authorization.
|
||||
if(QueryParameter(redirected, "state") != state) {
|
||||
throw std::runtime_error("that address is not the answer to this authorization (its state differs): start again");
|
||||
}
|
||||
return *code;
|
||||
}
|
||||
|
||||
BunqEndpoint BunqConnector::Endpoint(BunqEnvironment environment) {
|
||||
return Redirected().value_or(BunqEndpoint{.host = environment == BunqEnvironment::Production ? "api.bunq.com" : "public-api.sandbox.bunq.com", .port = 443, .caPem = std::string()});
|
||||
}
|
||||
|
|
@ -620,6 +635,27 @@ BunqCard BunqConnector::SetCardStatus(std::uint64_t card, std::string_view statu
|
|||
throw std::runtime_error("bunq did not return the card it updated");
|
||||
}
|
||||
|
||||
bool BunqCard::Virtual() const noexcept {
|
||||
return orderStatus == "VIRTUAL_DELIVERY";
|
||||
}
|
||||
|
||||
std::string_view BunqCard::State() const noexcept {
|
||||
// Gone for good is said of a virtual card as of any other; working or frozen is not said of it at all.
|
||||
const bool undecided = status == "DEACTIVATED" || status == "ACTIVE";
|
||||
return Virtual() && undecided ? std::string_view("VIRTUAL") : std::string_view(status);
|
||||
}
|
||||
|
||||
void BunqCard::ExpectStatus(std::string_view wanted) const {
|
||||
// A virtual card is DEACTIVATED before and after it is asked to freeze or to unfreeze: having the status that was
|
||||
// asked for does not show that anything was done.
|
||||
if(State() == "VIRTUAL" && (wanted == "ACTIVE" || wanted == "DEACTIVATED")) {
|
||||
throw std::runtime_error(std::format("bunq left card {} as it was: it is a virtual card, which bunq does not freeze or unfreeze when asked. Do that in the bunq app", id));
|
||||
}
|
||||
if(status != wanted) {
|
||||
throw std::runtime_error(std::format("bunq kept card {} {} (its order status is {}): a card can only be frozen or unfrozen once it has been activated", id, status, orderStatus));
|
||||
}
|
||||
}
|
||||
|
||||
std::string BunqConnector::StorageKey() const {
|
||||
return std::format("{}/{}/{}", connectorId, environment == BunqEnvironment::Production ? "production" : "sandbox", id);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue