BM-2773: Improve private key validation in setup wizard#1843
Open
BM-2773: Improve private key validation in setup wizard#1843
Conversation
- Add validate_private_key() that strips whitespace, invisible chars, and 0x prefix before validating hex format and length - Better error messages for invalid keys (shows bad char position, expected vs actual length) - Verify key is valid secp256k1 before accepting - Add unit tests for validation edge cases
Expand test coverage for validate_private_key() and process_private_key(): - Uppercase 0X prefix handling - Mixed case hex (verifies lowercase normalization) - Tabs, carriage returns, embedded spaces - Zero-width spaces and BOM chars (Unicode invisible chars from paste) - Empty, whitespace-only, 0x-only inputs - Too short and too long keys (with exact char count in error) - Invalid char position reporting - All-zeros key (valid hex but invalid secp256k1 key) - process_private_key address derivation and error propagation Also fix validate_private_key to use is_ascii_graphic() filter instead of is_whitespace()+is_control(), which missed zero-width spaces and other non-ASCII invisible characters.
capossele
approved these changes
Apr 6, 2026
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.
I opened this PR, because I found I had copy and pasted a private key into
boundless requestor setupnot quite right (some characters cut off) and it accepted it and saved it. Once I went to do something with said key in the CLI, it didn't work. Not sure if all the tests are over the top, but I felt that's better safe than sorry.Changes
Note
Low Risk
Low risk CLI-only change that tightens private-key input validation; main risk is rejecting previously accepted (but malformed) pasted keys or differing whitespace handling.
Overview
Improves Boundless CLI setup flows to strictly validate Ethereum private keys before saving them, including stripping whitespace/invisible characters, enforcing hex-only content and 32-byte length, and rejecting invalid secp256k1 keys with clearer error messages.
Adds
validate_private_key(and updatesprocess_private_keyto returnResult) plus avalidated_pkhelper in the setup wizard to apply the same validation across requestor/prover/rewards paths, backed by extensive unit tests covering common copy/paste failure cases.Written by Cursor Bugbot for commit f47cc27. This will update automatically on new commits. Configure here.