Reject malformed BTC_PRIVATE_KEY with clear error#126
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BitcoinProvider.get_wif()trusted whatever was inBTC_PRIVATE_KEYand returned it verbatim. If the value wasn't a WIF (e.g. an address pasted by mistake), signing failed downstream into_mainnet_wif()withInvalid character '0'— not actionable.5/K/Lmainnet,9/ctest/regtest) and log the reason, returningNoneso the caller hits the existing "no key available" path.Test plan
BTC_PRIVATE_KEY=bcrt1q...→BTC sign_from_proof failed: Invalid character '0'BTC_PRIVATE_KEY is not a valid WIF (prefix 'bcrt'); expected 5/K/L (mainnet) or 9/c (test/regtest)ruff format/ruff checkclean