Skip to content

Hex digests vs buffers #9

Open
Open
@stephan83

Description

@stephan83

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions