From 257385e6f4fc8562e1063e007c970f6ac1159006 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Fri, 22 Dec 2023 17:15:12 -0600 Subject: [PATCH] add digest for multihash --- codex/utils/digest.nim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/codex/utils/digest.nim b/codex/utils/digest.nim index bff1106e..a89c1659 100644 --- a/codex/utils/digest.nim +++ b/codex/utils/digest.nim @@ -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