merkle-tree icon indicating copy to clipboard operation
merkle-tree copied to clipboard

Issues implementing custom nodeHash without etherjs dependency

Open kevzzsk opened this issue 6 months ago • 2 comments

I am trying to create a merkle tree outside of EVM context so I am using SimpleMerkleTree. While the consumer are free to implement the leafHash function, the nodeHash is proving to be difficult to deal with without depending on @ethersproject/bytes package because of the type BytesLike.

for instance,

    const v1 = sha256(Buffer.from("8d6cd2a958c38796bbf791ef81835a92e0c85539771b37a12cd249886daf2136", "hex"));
    const v2 = sha256(Buffer.from("cde8ec76677273a270af18285503ce3075b59f7921c0906bee59366bc9d4b8b3", "hex"));
    const tree2 = SimpleMerkleTree.of([v1, v2], {
      nodeHash: (left, right) => sha256(Buffer.concat([Buffer.from(left), Buffer.from(right)])).toString("hex"),
    });

There is a typing issue because BytesLike cannot be converted easily to buffer

is there any ways to write custom nodeHash function with sha256 and does not have dependency on the etherjs lib?

kevzzsk avatar Aug 16 '24 09:08 kevzzsk