Skip to content

Reject malformed BTC_PRIVATE_KEY with clear error#126

Merged
entrius merged 1 commit into
testfrom
fix/btc-wif-validation
Apr 20, 2026
Merged

Reject malformed BTC_PRIVATE_KEY with clear error#126
entrius merged 1 commit into
testfrom
fix/btc-wif-validation

Conversation

@LandynDev
Copy link
Copy Markdown
Collaborator

Summary

  • BitcoinProvider.get_wif() trusted whatever was in BTC_PRIVATE_KEY and returned it verbatim. If the value wasn't a WIF (e.g. an address pasted by mistake), signing failed downstream in to_mainnet_wif() with Invalid character '0' — not actionable.
  • Validate the prefix (5/K/L mainnet, 9/c test/regtest) and log the reason, returning None so the caller hits the existing "no key available" path.

Test plan

  • Reproduced the original failure: BTC_PRIVATE_KEY=bcrt1q...BTC sign_from_proof failed: Invalid character '0'
  • With the fix: clear error BTC_PRIVATE_KEY is not a valid WIF (prefix 'bcrt'); expected 5/K/L (mainnet) or 9/c (test/regtest)
  • ruff format / ruff check clean
  • E2E suite 02 happy path: swap initiated successfully against local regtest (validators reserved, ID assigned)

If BTC_PRIVATE_KEY holds a non-WIF value (e.g. an address pasted in
by mistake), signing failed downstream in to_mainnet_wif() with a
cryptic base58 "Invalid character" error. Validate the prefix up
front and surface the reason.
@entrius entrius merged commit 87c5036 into test Apr 20, 2026
2 checks passed
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.

2 participants