add digest for multihash

This commit is contained in:
Dmitriy Ryajov 2023-12-22 17:15:12 -06:00
parent 7579409c7d
commit 257385e6f4
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4

View File

@ -10,6 +10,7 @@
import pkg/poseidon2
import pkg/poseidon2/io
import pkg/questionable/results
import pkg/libp2p/multihash
import ../merkletree
@ -38,3 +39,15 @@ func digest*(
##
(? Poseidon2Tree.digestTree(bytes, chunkSize)).root
func digestMhash*(
_: type Poseidon2Tree,
bytes: openArray[byte], chunkSize: int): ?!MultiHash =
## Hashes chunks of data with a sponge of rate 2 and
## returns the multihash of the root
##
let
hash = ? Poseidon2Tree.digest(bytes, chunkSize)
? MultiHash.init(Pos2Bn128MrklCodec, hash).mapFailure