Skip to content

feat(payments): payment requests as messages, handed to the user's wallet - #50

Merged
Henner4746 merged 2 commits into
mainfrom
feat/zahlungsanfrage
Nov 30, 2026
Merged

Henner4746 merged 2 commits into
mainfrom
feat/zahlungsanfrage

Conversation

@Henner4746

Copy link
Copy Markdown
Owner

What

Stages 1 and 2 of the crypto plan: a payment request as an end-to-end encrypted message, and handing it to the wallet app the user already has. BitDM holds no money, no private keys, and asks no server about balances.

  • Send: + → Request payment. Currency (Bitcoin on-chain, Lightning, Monero), address or invoice (paste button; a pasted bitcoin:…?amount= link is split up), optional amount and note. Pasting an address of another currency switches the currency.
  • Card in the chat: currency, sender (identicon + short address), amount (Lightning: from the invoice, also in sat), note, a QR code drawn on the device (zxing2, no network), the address in groups of four, Copy, Pay. Lightning shows the expiry; an expired invoice cannot be paid.
  • Pay: a confirmation dialog shows the sender's full address, the full target address/invoice in groups of four, the amount and the sender's note, then Open wallet hands a BIP21 bitcoin: / lightning: / monero: link (amount filled in, note not passed on) to the system. Nothing opens without that second tap. If no app takes the link: "No wallet found … copy the address".
  • Pay is disabled for a contact whose request has not been accepted yet, and on your own requests.

Validation (lib/core/zahlung/, pure Dart, offline)

  • Bitcoin: Bech32 (SegWit v0, 20/32 bytes) and Bech32m (Taproot, 32 bytes) with checksum, Base58Check P2PKH/P2SH. Testnet/regtest rejected with their own message; mixed case rejected; witness v2+ rejected (not spendable today).
  • Lightning (BOLT11): mainnet lnbc only (lnbcrt is checked before lnbc), Bech32 checksum, amount multipliers incl. pico with the sub-msat rule, exactly one p and one s, n length, expiry. The signature is not verified (the wallet does that; we do not know the node).
  • Monero: block Base58, Keccak-256 checksum (original Keccak, not SHA3), network byte 18/42/19; testnet/stagenet rejected.
  • Amounts: decimal only, comma accepted, no exponent, not beyond supply or precision (sat, piconero).
  • Input cleanup: whitespace, zero-width, bidi controls (RLO etc.), tag characters; homoglyphs (Cyrillic а) fail. Notes: same filter, one line, ≤ 140 chars.
  • Recovery words are refused: six or more BIP39 words in the address or note field (a common scam: "send me your words so I can pay you").
  • The 12 identity words are never used: nothing under lib/core/zahlung/ imports key derivation, the secret store or the lock; a test reads the import lines.

Compatibility

  • On the wire it is an ordinary text payload (kind 1). The text is a readable, bilingual version with the link in backticks; the data travels in a new field z. 2.0.1 ignores z and shows the text. A new payload kind would have been dropped silently by every older app.
  • z is validated on receipt (v must be 1); anything else stays a text message. A future v: 2 therefore arrives as text, not as a half-understood card.
  • Stored as MessageKind.zahlung (index 3) in the existing kind column, no schema bump (no clash with schema 17 in fix(groups): a member who left can be added back by the admin #33).
  • Backups write payment requests as text with the data next to it (zahlung key). An older app inserts only its known columns and gets readable text instead of an unknown kind; this app turns it back into a card. Unknown kinds from a later version become text on restore.
  • Payment requests cannot be edited (the repository only edits kind = text), so an address cannot be swapped after the recipient has checked it.

Tests

  • test/zahlung/zahlungsanfrage_test.dart: official BIP173/BIP350 and BOLT11 vectors (valid and invalid), plus vectors from independent libraries (tool/zahlung/vektoren.py: bech32, embit, base58, monero, pycryptodomex), typo detection, amounts, notes, recovery words, format round trip, QR round trip through the app's own reader for all three currencies. Side note: PyPI bech32 1.2.0 has no Bech32m and produces an invalid Taproot address; the validator rejected it, it is now a negative vector.
  • test/zahlung/zahlung_nutzlast_test.dart: wire format, the 2.0.1 view of the same bytes, invalid z, mirror/group wrapping, resend, no editing, backup both ways.
  • test/zahlung/zahlung_ende_zu_ende_test.dart: two/three real cores, real relay, real libsignal, 1:1 and group.
  • test/zahlung/zahlung_ohne_identitaet_test.dart: no identity imports.
  • test/oberflaeche/zahlung_ui_test.dart: create (typo, recovery words, auto-switch), card, confirmation with full address, wallet hand-off, no-wallet hint, pending contact, expired and fresh Lightning invoice.
  • test/core/fremde_eingaben_test.dart: the resend loop over all kinds now uses a valid request for the new kind.

Run in CT 107 (Flutter 3.44.8, Linux): flutter analyze only the 29 known infos; whole suite before the last fixes 1637 passed, 2 skipped, 3 failed (two font-scan tests about invisible characters in a regex literal and the resend loop above); all three fixed and re-run green together with the 81 new tests. Proof from the real app on Linux and Android follows as a comment.

Not in this PR

A built-in wallet and paying from the chat (stages 3/4) come in a separate PR: they carry real risk and need an independent audit before anything is released.

🤖 Generated with Claude Code

…nded to the user's wallet

A contact can send a Bitcoin address, a Lightning invoice (BOLT11) or a
Monero address, with an optional amount and note. The chat shows it as a
card with a QR code generated on the device, a copy button and "Pay".
"Pay" asks first, shows the sender, the full address in groups of four and
the amount, and only a second tap hands a bitcoin:/lightning:/monero: link
to the system. Without a matching app there is a clear hint to copy the
address instead. BitDM holds no money and no keys and asks no server.

Validation is strict and offline: Bech32/Bech32m and Base58Check checksums,
SegWit v0 and Taproot only, Lightning invoices with exactly one payment hash
and secret, Monero with the Keccak checksum and network byte. Testnet,
regtest and stagenet are rejected, as are expired invoices, homoglyphs,
amounts beyond supply or precision, and anything that looks like recovery
words. Bidi and other control characters are removed from notes.

Wire format: an ordinary text payload (kind 1) whose text is a readable,
bilingual version with the payment link, plus the data in a new field "z".
2.0.1 ignores the field and shows the text; a new kind would have been
dropped silently. "z" is validated on receipt; anything that does not pass
stays a text message. Stored as MessageKind.zahlung (index 3) without a
schema change; backups write it as text with the data beside it, so an
older app restoring one does not hit an unknown kind. Payment requests
cannot be edited. Pay is disabled for a contact that has not been accepted.

Tests use the official BIP173/BIP350 and BOLT11 vectors and vectors made
with independent libraries (tool/zahlung/vektoren.py).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Henner4746

Copy link
Copy Markdown
Owner Author

Proof from the real app (30.11.2026, CT 107) — integration_test/zahlung_nachweis_test.dart (on the stacked branch #51, it covers this PR's screens too), Linux under Xvfb and Android 15 in the emulator, both green. Images are rendered by the app itself; the counterpart is the draft core, the wallet hand-off is the device's real url_launcher.

Station Linux Android
1 Bitcoin card (QR, groups of four, amount, note, Copy/Pay) ✓ ✓
2 Confirmation: sender's full address, full target address, amount, note ✓ ✓
3 Open wallet url_launcher returned true (xdg-open accepted the link; no wallet installed, so nothing visible opened) no app takes bitcoin: → "No wallet found … copy the address"
4 Monero card (real Monero General Fund address) ✓ ✓
5 Request dialog with a one-character typo → "checksum does not match" ✓ ✓

Images are with Henrik (local drop folder); not attached here.

The end-to-end protocol (two/three real cores, real relay, libsignal) is covered by test/zahlung/zahlung_ende_zu_ende_test.dart. CI app (Windows, whole suite) green; SonarCloud red as on every PR with Dart code (no Dart coverage upload).

…oup senders must be contacts

From the review of this PR:
- On Linux and Windows launchUrl reports success for any scheme (xdg-open,
  ShellExecute), so "No wallet found" never showed. Ask xdg-mime / the
  registry for a handler first.
- An expired Lightning invoice is refused again when Pay is pressed and
  before the hand-off; the card only checked while drawing.
- In groups the sender, not the group, must be an accepted contact.
- "Valid until" shows the year when it is not the current one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@Henner4746
Henner4746 merged commit a4ef488 into main Nov 30, 2026
11 of 12 checks passed
@Henner4746 Henner4746 mentioned this pull request Nov 30, 2026
Henner4746 added a commit that referenced this pull request Nov 30, 2026
…dialog

The tests from #41, #50 and #51 were written before #46 added the
"Continue without protection?" question, and the payment test pinned
schema 16, which #33 raised to 17 for group re-adds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant