-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore leading zeroes in hexToPaddedByteArray #86
base: master
Are you sure you want to change the base?
Conversation
When converting hex strings into fixed size byte arrays, the function `hexToPaddedByteArray` is commonly used to deal with the input data being shorter than the target buffer. However, the opposite case of the input data having extra leading zeroes leads to an error. This patch allows leading zeroes in `hexToPaddedByteArray`, ignoring them when the input string is longer than the destination array.
I noticed this limitation when using nim-blscurve to import a private key from the Ethereum 2.0 spec, i.e., https://github.com/ethereum/eth2.0-specs/blob/dev/tests/generators/bls/main.py#L45-L51 nim-blscurve's BLST |
So, the intention here is that you want to be able to decode a string such as "0x0000ffff" into a 3-element array and get the result |
Anytime a number is imported. The semantics are same regardless of number of leading zeroes. The function already does the opposite of padding with extra zeroes, e.g., passing "0xffff" to the 3-element array would also result in Example use case was given above, the Eth2 sample private keys contain a lot of extra zeroes, which does not make them invalid as it is still representing the same number, but putting them as is into the |
Interesting. Perhaps the name of the function should then reveal that a big endian number is being loaded. The name |
Well, |
When converting hex strings into fixed size byte arrays, the function
hexToPaddedByteArray
is commonly used to deal with the input databeing shorter than the target buffer. However, the opposite case of the
input data having extra leading zeroes leads to an error.
This patch allows leading zeroes in
hexToPaddedByteArray
, ignoringthem when the input string is longer than the destination array.