arnaucube
arnaucube/asmtPublic Self-hosted repository
add method VerifyInclusionWithRoot

Signed-off-by: p4u <pau@dabax.net>
p4u pau@dabax.net
Mon, 22 Mar 2021 11:01:59 +0100
commit

6fb3b028ac718d2a0248175bd0443c7bf8b68702

parent

40ddcbf3f2b7aa01eba611f71caafbbb388f27ad

1 files changed, 6 insertions(+), 0 deletions(-)

jump to
M trie_merkle_proof.go → trie_merkle_proof.go

@@ -122,6 +122,12 @@ leafHash := s.hash(key, value, []byte{byte(s.TrieHeight - len(ap))})

return bytes.Equal(s.Root, s.verifyInclusion(ap, 0, key, leafHash)) } +// VerifyInclusionWithRoot verifies that key/value is included in the trie with provided root +func (s *Trie) VerifyInclusionWithRoot(root []byte, ap [][]byte, key, value []byte) bool { + leafHash := s.hash(key, value, []byte{byte(s.TrieHeight - len(ap))}) + return bytes.Equal(root, s.verifyInclusion(ap, 0, key, leafHash)) +} + // verifyInclusion returns the merkle root by hashing the merkle proof items func (s *Trie) verifyInclusion(ap [][]byte, keyIndex int, key, leafHash []byte) []byte { if keyIndex == len(ap) {