Skip to content

BM-2773: Improve private key validation in setup wizard#1843

Open
unforsook wants to merge 2 commits intomainfrom
sasha/improve-key-validation
Open

BM-2773: Improve private key validation in setup wizard#1843
unforsook wants to merge 2 commits intomainfrom
sasha/improve-key-validation

Conversation

@unforsook
Copy link
Copy Markdown
Contributor

@unforsook unforsook commented Apr 2, 2026

I opened this PR, because I found I had copy and pasted a private key into boundless requestor setup not 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

  • Improve private key validation in setup wizard: strips whitespace/invisible chars, validates hex format and length, better error messages
  • Thorough unit tests for private key validation

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 updates process_private_key to return Result) plus a validated_pk helper 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.

- 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.
@github-actions github-actions bot changed the title Improve private key validation in setup wizard BM-2773: Improve private key validation in setup wizard Apr 2, 2026
@linear
Copy link
Copy Markdown

linear bot commented Apr 2, 2026

@unforsook unforsook marked this pull request as ready for review April 2, 2026 10:42
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