Skip to content

feat: minimal sweep WIF QR-code implementation#53

Open
psychemist wants to merge 5 commits into
bitcoindevkit:variant/2.0from
psychemist:feat/wif-sweep-qrcode
Open

feat: minimal sweep WIF QR-code implementation#53
psychemist wants to merge 5 commits into
bitcoindevkit:variant/2.0from
psychemist:feat/wif-sweep-qrcode

Conversation

@psychemist

@psychemist psychemist commented Apr 22, 2026

Copy link
Copy Markdown

Description

This PR adds the ability to sweep funds from an external WIF private key into the user's wallet by scanning a QR code or copy-pasting the raw WIF string.

What This Does

  • Scan a QR code containing a WIF private key (or type/paste it manually)
  • App derives all standard address types (wpkh, pkh, tr, sh-wpkh) from the key, scans each for funds, and sweeps any balance into the user's wallet
  • Supports mainnet (K/L/5) and testnet (c/9) WIF formats
  • Accepts raw WIF, wif: prefix, and bitcoin:?wif= URI formats

Flow

  • Send screen → "Sweep WIF" button → QR scanner dialog
  • Scanned value parsed by WifParser.extract() and validated
  • SendViewModel dispatches TransactionType.SWEEP on IO thread
  • Wallet.sweep() iterates over descriptors, fully scans each via Esplora, and drains any with balance (confirmed + unconfirmed)
  • Success/error toast via existing broadcastResult state flow

Testing

  1. Unit tests (JVM, no device needed)
    ./gradlew :app:testDebugUnitTest

  2. Install on device/emulator
    ./gradlew installDebug

  3. Manual: send testnet4 coins to the wpkh address derived from a test WIF then sweep. Check in-app logs for balance details per descriptor.
    Check out test sweep transaction on testnet4 here:

Screenshots IMG_6321 IMG_6322 Screenshot_20260418-180945 Screenshot_20260418-181206

@ItoroD

ItoroD commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@psychemist Hi thanks for the PR.

Not quite sure we want to add a WIF feature for the sample app. IMO adding WIF is a big jump from where the wallet is atm. @thunderbiscuit might have a different opinion.

Don't mind me asking, what was your rationale the for adding WIF ? are you use in your projects somewhere?

@reez

reez commented Jun 16, 2026

Copy link
Copy Markdown

have a contributor who added it for BDK iOS bitcoindevkit/BDKSwiftExampleWallet#355 so let me know if we're doing anything different from ya'll here if you do add it

@psychemist

Copy link
Copy Markdown
Author

@ItoroD i saw the contribution on the iOS repo so i thought it would be a nice addition here. unfortunately, i thought about raising the issue AFTER i was done building

@ItoroD

ItoroD commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

have a contributor who added it for BDK iOS bitcoindevkit/BDKSwiftExampleWallet#355 so let me know if we're doing anything different from ya'll here if you do add it

Ahhh I see! Thanks for the input.

@ItoroD

ItoroD commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@ItoroD i saw the contribution on the iOS repo so i thought it would be a nice addition here. unfortunately, i thought about raising the issue AFTER i was done building

No worries! When I saw camera permissions and QR scanning I had to look a little harder. I know IOS has been using those for a while already. I think we do not even have camera scanning for QR anywhere yet not even for scanning addresses. Probably good to start now. I will run the test and do a proper review.

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.

3 participants