Reputation: 6474
I have the following:
static combinedHash(first: Buffer, second: Buffer): Buffer {
if (!first) {
return second
}
if (!second) {
return first
}
return keccak256(MerkleTree.sortAndConcat(first, second))
}
keccak256
is imported from ethereumjs-utils
It seems like that keccak256
returns Buffer
.
What I am trying to do is I want to change keccak256
from ethereumjs-utils
to ethers/lib/utils
, but new keccak256
doesn't return buffer. I tried lots of things, but the results are different. any ideas ? The final result should be that combinedHash
function returns the same thing in the end so it should return Buffer
.
Any ideas ?
Upvotes: 1
Views: 433
Reputation: 43581
ethers/lib/utils
function keccak256()
returns 0x
prefixed hex string representation of the hash.
So you need to create a buffer from this hex without the 0x
prefix.
const keccakString = keccak256(MerkleTree.sortAndConcat(first, second))
return Buffer.from(keccakString.slice('0x'.length), 'hex')
Upvotes: 1