Skip to content
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

Hex digests vs buffers #9

Open
stephan83 opened this issue Mar 6, 2016 · 4 comments
Open

Hex digests vs buffers #9

stephan83 opened this issue Mar 6, 2016 · 4 comments
Milestone

Comments

@stephan83
Copy link

The current implementation stores the hashes as hexadecimal strings and computes parent hashes doing something like this:

parentHashHex = hash(new Buffer(leftHex + rightHex, 'hex')).toString('hex')

I'm not sure if this is a standard, but it means that the parent hash is encoding dependent.

To me, it makes more sense to use buffers and concatenate the binary data directly:

parentHashBuf = hash(Buffer.concat([leftBuf, rightBuf]))

This way, the computation does not rely on encoding. Since it decouples encoding, it also makes it possible to use other encodings such as base64 and still get the same parent hashes.

@c-geek
Copy link
Owner

c-geek commented Mar 6, 2016

Thanks for your comment.

Indeed, it seems more correct to use binary nodes & leaves instead of encoded data since binary is a more deep and common form for data.

However this would be a breaking change I guess. So, we could include this for a major version.

@c-geek c-geek added this to the 1.0.0 milestone Mar 6, 2016
@stephan83
Copy link
Author

Yes it is indeed a very breaking change, since it also results in different hashes. Maybe it would be better to make it optional and introduce it as a non-breaking change?

@c-geek
Copy link
Owner

c-geek commented Mar 7, 2016

Yes we can for current version, however I plan to make a v1.0.0 some day along with code cleaning, so we could make breaking changes that time.

@stephan83
Copy link
Author

Great, it seems fine for 1.0.0, no need to introduce complexity in the current version. In the meantime I have a branch that does it that I can use for now. Let me know if you need help for 1.0.0.

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

No branches or pull requests

2 participants