Repository navigation
Reject a private-key hex string with a non-hex digit - #473
Merged
Merged
Conversation
hexToBytes already rejects an odd length, but 0G still decoded to the same byte as 10.
aharoitx
approved these changes
Oct 9, 2026
Contributor
|
Thanks for the fix, Sasha. I checked it: on the current code "0G" decodes to the same byte as "10", so a bad key turns into a different key without any error. Your test fails on 10.3.x and passes with the change. It also matches what the C# SDK already does. Tests and checkstyle pass on Java 8. I'll fix the small import conflict with 10.3.x and merge after CI passes. |
Contributor
Author
|
Thanks for checking it on 10.3.x and for merging it. A bad hex digit was becoming a different key, and rejecting it matches the C# SDK. |
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
hexToBytesthrows when the length is odd, and it accepts any other character.hexToBytes("0G")returned.Gis not a hex digit. The nibble math maps it to 16, so0Gdecodes to the same byte as10.BitPayGenericException.0123456789abcdefstill decodes.Test plan
it_should_reject_a_non_hex_key_digitexpectedBitPayGenericExceptionand nothing was thrownmvn -Dtest=KeyUtilsTest testis 6 tests, 0 failuresMade with Cursor