-
Notifications
You must be signed in to change notification settings - Fork 272
toBuffer now throws if strings aren't 0x-prefixed hex values #197
Conversation
Travis is failing with node 6 because the autoformat sometimes adds commas after the last argument in a function call. This is not supported in node 6. This is an example of that pattern: assert.equal(
ethUtils.MAX_INTEGER.toString('hex'),
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
) Are we still supporting node 6? It's not maintained anymore. |
Thanks for the PR, had a first look but need some more time to answer. One first thing: can you please generally don't reformat code and remove the commit with the format changes in the tests file? Some broader first note: maybe we want to take this occasion and generally do the API overhaul discussed here #172, eventually you already want to have a look and give this your own thoughts. This goes a bit in the direction of this PR, things have to be re-read a bit since we won't use a special HexString class for now which I proposed there. @s1na do we eventually do this API overhaul a two-step process and first start with updates similar to the one being done in this PR and do integrations of your new types like the Address type #186 as a second step on top? |
I personally agree with this approach (and probably would go further and limit the APIs to only
Yeah, I think that makes sense. They can even be possibly worked on in parallel as there's no conflict in between. |
Sure! I thought the idea was to always reformat everything with I updated it.
I'll go through that issue. Thanks for the link.
I'd love this, but wouldn't that mean breaking changes in all of ethereumjs? |
0a96299
to
cb86ba9
Compare
@alcuadrado With The |
@alcuadrado can you please rebase your branch for a review? |
This test was using the previous behavior of toBuffer, which tis PR is meant to remove.
This type was already require by Buffer.concat.
They were using the previous behavior of toBuffer unnecessarily.
cb86ba9
to
f0df622
Compare
Then, I agree with using
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks! 😄
I made this in response to the conversation we had in this other PR.
As we agreed three,
toBuffer
had a surprising and error-prone behavior when a string other than 0x-prefixed hex one was given. This PR removes that behavior, throwing a clear error instead.There were a few tests using this older behavior (i.e. passing utf-8 string), but that was not necessary and they were harder to read, so I replaced with equivalent 0x-prefixed hex strings.
keccak
was also using and exposing this behavior, which makes sense as people sometimes hash strings. I implemented it insidekeccack
and documented it.Finally,
hashPersonalMessage
was using it internally, but not exposing it, so I just updated it to an equivalent lower-level implementation.Technically, this PR introduces a breaking change in
toBuffer
, but I think virtually all of the uses oftoBuffer
with non-hex strings were errors, as its behavior was unexpected and undocumented.