Skip to content

feat(wallet): experimental built-in Bitcoin wallet and paying from the chat (not audited) - #51

Merged
Henner4746 merged 6 commits into
mainfrom
feat/wallet
Nov 30, 2026
Merged

Henner4746 merged 6 commits into
mainfrom
feat/wallet

Conversation

@Henner4746

Copy link
Copy Markdown
Owner

Stacked on #50 (base feat/zahlungsanfrage). Stages 3 and 4 of the crypto plan. Experimental, not audited, off by default. Do not release this for real money before an independent audit.

Stage 3: built-in Bitcoin wallet (lib/core/wallet/)

  • Own keys: 12 new BIP39 words from their own entropy (Bip39.generate), never the identity words. Restoring the identity's words as a wallet is refused. Stored under a separate key (bitdm_wallet_v1) in the system key store; a test checks the module imports nothing from key derivation, the identity store or the lock.
  • Crypto, pure Dart on pointycastle (no new dependency): BIP32, BIP84 (native SegWit bc1q), secp256k1 ECDSA with RFC 6979 and low S, DER, BIP143 sighash, every signature verified before broadcast, RBF sequence, version 2.
  • Spending: coin selection (confirmed first, largest first), change, dust folded into the fee, "send all", fee rates from the server (slow/normal/fast), any standard destination (P2WPKH, P2WSH, P2TR, P2PKH, P2SH) of the wallet's network only.
  • Network: an Esplora server (mempool.space by default, editable). The UI says the server sees the wallet's addresses and IP. Networks: signet (default), testnet4, regtest, mainnet. Mainnet only after ticking "not audited, I can lose real money". Not in the browser.
  • Screen: Settings → Bitcoin wallet: create/restore, show the words once with a warning, balance (+ pending), receive address with QR, history, send with a confirmation (full address, amount, fee choice, total), show words, delete.
  • Keys leave memory when the app locks. "Delete everything", remote wipe and the panic password delete the wallet too (the UI says so when the words are shown).

Stage 4: pay in the chat

  • A Bitcoin payment request gets "Pay with BitDM wallet" when the wallet runs on the same network and the contact is accepted. A request without an amount asks for one (never "send all"). Same confirmation as above, plus "a receipt goes to this chat".
  • After broadcasting, a payment receipt goes to the chat (new kind zahlungsbeleg, index 4, no schema change): txid, amount, address, reference to the request. It travels in its own payload field zb, so feat(payments): payment requests as messages, handed to the user's wallet #50-only apps (which read z) never mistake it for a request; 2.0.1 shows the readable text.
  • The recipient presses Check: their own wallet asks its server for the transaction and shows confirmations and how much reached the address. A receipt that claims more than arrived is flagged. A receipt alone proves nothing, and the card says so.
  • Payment requests can now carry an explicit test network (t). Without it test addresses are rejected as in feat(payments): payment requests as messages, handed to the user's wallet #50; with it only that network's addresses pass, and the card and text say "test network, not real money".

Not done (honestly)

  • Lightning and Monero wallets: requests and hand-off to external wallets work (feat(payments): payment requests as messages, handed to the user's wallet #50); sending them from inside BitDM would need a Lightning node (LDK) or a Monero wallet library and servers. Out of reach for one night, and the riskiest part.
  • Wallet words are behind the system key store, not behind the app lock / unlock factors. Must change before mainnet use.
  • Esplora queries go directly, not through Tor.
  • No independent audit. No hardware wallet, no PSBT, no RBF bump UI, no address-book.

Tests

  • test/wallet/wallet_test.dart: BIP84 vector and embit 0.8.0 addresses (mainnet, signet, regtest). A transaction signed by both: everything up to the witnesses and the second witness are byte-identical; the first signature differs only because its R is above 2^255 and embit (like Bitcoin Core) grinds for a low R. Low S, verification, network separation, scanning, change, sweep, dust, insufficient funds, wrong network, txid check on broadcast.
  • test/wallet/wallet_regtest_test.dart (runs only with BITDM_REGTEST_ESPLORA): against a real bitcoind 28.1 (official binary, SHA256SUMS checked) with a small Esplora shim (tool/wallet_regtest/). bitcoind accepted the transactions: receive 0.5, pay 0.1234 with change, mempool then 1 confirmation, balance and history correct, sweep to zero, garbage rejected. Green in CT 107.
  • test/zahlung/zahlungsbeleg_test.dart, test/oberflaeche/wallet_ui_test.dart (create, refuse identity words, pay from the chat → receipt with the server's txid, receipt check incl. a short payment), real-core E2E for receipts, identity-separation test.
  • Whole suite in CT 107: 1664 passed; the one failure (remote-wipe UI test waiting on the unmocked key store) is fixed and re-run green.

🤖 Generated with Claude Code

Henner4746 and others added 4 commits November 30, 2026 01:14
…ng, Esplora)

Pure Dart on pointycastle, no new dependency: separate BIP39 words with their
own entropy (never the identity words), BIP32/BIP84 native SegWit accounts,
secp256k1 ECDSA with RFC 6979 and low S, BIP143 signing with a self-check,
RBF sequence, coin selection with change and dust handling, sweep, fee rates
and broadcast through an Esplora server. Mainnet, testnet4, signet and regtest.

Checked against embit (addresses and BIP84 vector; the transaction matches
byte for byte except one signature, where embit grinds for a low R) and
against a real bitcoind 28.1 in regtest: receive, pay with change, confirm,
sweep (tool/wallet_regtest/).

Not audited. The words live in the system key store, not behind the app lock.

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

Stage 3 UI: Settings → Bitcoin wallet (experimental). Create or restore a
wallet with its own 12 words, choose signet (default), testnet4, regtest or
mainnet (mainnet only after ticking "not audited, I can lose real money"),
set the Esplora server. Balance, receive address with QR, history, send with
a confirmation that shows the full address, amount, fee choice and total.
Restoring the identity's own words is refused. The keys leave memory when
the app locks; "delete everything" and the panic password delete the wallet.

Stage 4: a Bitcoin payment request in the chat gets "Pay with BitDM wallet"
when the wallet runs on the same network. Without an amount in the request
the user is asked for one (never "send all"). After broadcasting, a payment
receipt (txid, amount, address) goes to the chat as a new message kind in
its own payload field "zb", so an app that only knows requests never reads
it as a request. The recipient checks it with their own wallet: confirmations
and how much actually arrived at the address; a short payment is flagged.

Payment requests may now carry an explicit test network ("t"); without it
test addresses are rejected as before, with it only that network's addresses
are accepted, and the card says "test network, not real money".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (Linux, Android)

Drives the compiled app through card, confirmation, hand-off to the system,
Monero card, the request dialog with a typo, the wallet screen and paying
from the chat, saving images rendered by the app itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n Android

flutter test uninstalls the app afterwards, so on Android the images also go
to the log as base64. The root layer already carries the device pixel ratio.

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, Linux (Xvfb) and Android 15 (emulator), both green.

  • Station 6: wallet screen (regtest, server stub): "test network regtest: not real money", balance 0.25 BTC, receive address with QR, history, show words / delete.
  • Station 7: a regtest payment request in the chat → Pay with BitDM wallet → confirmation with the requester's full BitDM address, the full Bitcoin address in groups, fee choice (1/3/6 sat/vB), amount 0.001, fee 0.00000423 (141 vB), total. The stub server refuses to broadcast on purpose: here nothing is sent.

Real broadcasting is proven separately against bitcoind 28.1 in regtest (test/wallet/wallet_regtest_test.dart, green): bitcoind accepted the wallet's transactions (receive, pay with change, confirmation, sweep to zero).

Images are with Henrik (local drop folder).

Henner4746 and others added 2 commits November 30, 2026 02:05
…ceipts flagged

From the review of this PR:
- With Tor on, the wallet asks no server at all (TorGesperrt) instead of
  bypassing Tor with the real IP; the screen says why.
- Showing the wallet words needs a fresh unlock and the secret screen flag,
  like the identity words.
- A receipt whose transaction is older than the request is flagged as
  proving an earlier payment.
- Spent coins leave the wallet state right after broadcasting.
- The send dialog builds and signs once per fee rate, not per frame.
- Receipt check results are cleared on lock; the wallet entry deletion is
  awaited briefly on wipe; Esplora needs https except locally or .onion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Henner4746
Henner4746 changed the base branch from feat/zahlungsanfrage to main November 30, 2026 01:14
@Henner4746
Henner4746 merged commit d89f766 into main Nov 30, 2026
10 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)
3.3% Duplication on New Code (required ≤ 3%)
D Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@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