Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data MerkleTree
- data Direction
- leaf :: ByteString -> MerkleTree
- leafNumberToNodeNumber :: MerkleTree -> Int -> Int
- breadthFirstList :: MerkleTree -> [ByteString]
- merklePathLengthForSize :: Int -> Int
- makeTree :: [ByteString] -> Maybe MerkleTree
- makeTreePartial :: [ByteString] -> MerkleTree
- merkleProof :: MerkleTree -> Int -> Maybe [(Int, ByteString)]
- neededHashes :: MerkleTree -> Int -> Maybe [(Int, ByteString)]
- firstLeafNum :: MerkleTree -> Int
- rootHash :: MerkleTree -> ByteString
- pairHash :: ByteString -> ByteString -> ByteString
- emptyLeafHash :: Int -> ByteString
- size :: MerkleTree -> Int
- height :: MerkleTree -> Int
- mapTree :: (MerkleTree -> a) -> MerkleTree -> [a]
- merklePath :: Int -> Int -> [Direction]
- leafHashes :: MerkleTree -> [ByteString]
- treeFromRows :: [MerkleTree] -> [[ByteString]] -> [MerkleTree]
- buildTreeOutOfAllTheNodes :: [ByteString] -> Maybe MerkleTree
Documentation
data MerkleTree Source #
Instances
Represent a direction to take when walking down a binary tree.
leaf :: ByteString -> MerkleTree Source #
A constructor for a MerkleLeaf that enforces correct byte string length (error on incorrect length).
leafNumberToNodeNumber :: MerkleTree -> Int -> Int Source #
Translate a leaf number to a node number. Leaf numbers are zero indexed and identify leaves of a tree from left to right. Node numbers are one indexed and identify nodes of a tree from top to bottom, left to right.
breadthFirstList :: MerkleTree -> [ByteString] Source #
merklePathLengthForSize :: Int -> Int Source #
Compute the length of a merkle path through a tree of the given height.
makeTree :: [ByteString] -> Maybe MerkleTree Source #
makeTreePartial :: [ByteString] -> MerkleTree Source #
merkleProof :: MerkleTree -> Int -> Maybe [(Int, ByteString)] Source #
Return a list of tuples of node numbers and corresponding merkle hashes. The node numbers correspond to a numbering of the nodes in the tree where the root node is numbered 1, each node's left child is the node's number times two, and the node's right child is the node's number times two plus one.
neededHashes :: MerkleTree -> Int -> Maybe [(Int, ByteString)] Source #
Get a merkle proof but re-number the node numbers to be zero-indexed instead of one-indexed.
firstLeafNum :: MerkleTree -> Int Source #
Determine the smallest index into the breadth first list for the given tree where a leaf may be found.
rootHash :: MerkleTree -> ByteString Source #
pairHash :: ByteString -> ByteString -> ByteString Source #
emptyLeafHash :: Int -> ByteString Source #
size :: MerkleTree -> Int Source #
Count the number of nodes in a tree.
height :: MerkleTree -> Int Source #
Measure the height of a tree.
mapTree :: (MerkleTree -> a) -> MerkleTree -> [a] Source #
merklePath :: Int -> Int -> [Direction] Source #
Compute the path to a leaf from the root of a merkle tree of a certain height.
leafHashes :: MerkleTree -> [ByteString] Source #
Get a list of all of the leaf hashes of a tree from left to right.
:: [MerkleTree] | Some children to attach to a list of nodes representing the next shallowest level of the tree. |
-> [[ByteString]] | The values of the nodes to create at the next shallowest level of the tree. |
-> [MerkleTree] | The nodes forming the shallowest level of the tree. If we built a full tree, there will be exactly one node here. |
Given some children
buildTreeOutOfAllTheNodes :: [ByteString] -> Maybe MerkleTree Source #
Make a merkle tree out of a flat list of all nodes (start from root, then first two children, etc .. [0, 1, 2] is a two-layer tree, [0, 1, 2, 3, 4, 5, 6] is three-layer, etc