Skip to content

Merkle Tree and Merkle proofs implementation in Kotlin

License

Notifications You must be signed in to change notification settings

avoloshko/merkle-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Merkle Tree and Merkle proofs implementation in Kotlin

MerkleTree is implemented in Kotlin with kotlin-platform-common plugin which allows to compile the code to JavaScript.

Implemented methods:

MerkleTree(input: List<ByteArray>, hash: (ByteArray) -> ByteArray)
  root(): ByteArray
  hexRoot(): ByteArray
  containsLeaf(el: ByteArray): Boolean
  containsElement(el: ByteArray): Boolean
  proofForLeaf(el: ByteArray): List<ByteArray>
  hexProofForLeaf(el: ByteArray): List<ByteArray>
  proofForElement(el: ByteArray): List<ByteArray>
  hexProofForElement(el: ByteArray): List<ByteArray>MerkleTree

MerkleTree.verifyProof(proof: List<ByteArray>, root: ByteArray, leaf: ByteArray, hash: (ByteArray) -> ByteArray): Boolean
SparseMerkleTree(input: Map<Int, ByteArray>, val depth: Int, hash: (ByteArray) -> ByteArray)
  root(): ByteArray
  hexRoot(): ByteArray
  containsLeaf(el: ByteArray): Boolean
  containsElement(el: ByteArray): Boolean
  proofForLeaf(el: ByteArray): List<ByteArray>
  hexProofForLeaf(el: ByteArray): List<ByteArray>
  proofForElement(el: ByteArray): List<ByteArray>
  hexProofForElement(el: ByteArray): List<ByteArray>MerkleTree
  proofForIndex(idx: Int): List<ByteArray>
  hexProofForIndex(idx: Int): List<ByteArray>MerkleTree

MerkleTree.verifyProof(proof: List<ByteArray>, root: ByteArray, leaf: ByteArray, idx: Int): Boolean

SHA-256 implementation is provided.

val merkleTree = MerkleTree(elements, { data -> SHA256Digest.instance.digest(data) })

About

Merkle Tree and Merkle proofs implementation in Kotlin

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages