tahoe-chk-0.1.0.2: The Tahoe-LAFS' Content-Hash-Key (CHK) cryptographic protocol.
Safe HaskellNone
LanguageHaskell2010

Tahoe.CHK.Merkle

Synopsis

Documentation

data MerkleTree Source #

Instances

Instances details
Eq MerkleTree Source # 
Instance details

Defined in Tahoe.CHK.Merkle

Ord MerkleTree Source # 
Instance details

Defined in Tahoe.CHK.Merkle

Show MerkleTree Source # 
Instance details

Defined in Tahoe.CHK.Merkle

Generic MerkleTree Source # 
Instance details

Defined in Tahoe.CHK.Merkle

Associated Types

type Rep MerkleTree :: Type -> Type #

Binary MerkleTree Source #

Serialize a MerkleTree to bytes by concatenating all of the leaf hashes left to right.

This serialization includes no framing so the only thing we can do is consume all available input. Use this instance with isolate and bring your own framing mechanism to determine how many bytes to process.

Instance details

Defined in Tahoe.CHK.Merkle

ToExpr MerkleTree Source # 
Instance details

Defined in Tahoe.CHK.Merkle

Methods

toExpr :: MerkleTree -> Expr

listToExpr :: [MerkleTree] -> Expr

type Rep MerkleTree Source # 
Instance details

Defined in Tahoe.CHK.Merkle

data Direction Source #

Represent a direction to take when walking down a binary tree.

Constructors

TurnLeft 
TurnRight 

Instances

Instances details
Eq Direction Source # 
Instance details

Defined in Tahoe.CHK.Merkle

Ord Direction Source # 
Instance details

Defined in Tahoe.CHK.Merkle

Show Direction Source # 
Instance details

Defined in Tahoe.CHK.Merkle

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.

merklePathLengthForSize :: Int -> Int Source #

Compute the length of a merkle path through a tree of the given height.

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.

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.

treeFromRows Source #

Arguments

:: [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