-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Merkle Hash Tree -- -- Purely functional Merkle hash tree which implements appe nd-only logs -- and provides both inclusion proof and consistency proof. @package hash-tree @version 0.0.0 -- | Two-way (binary) Merkle Hash Trees which implements append-only logs -- and provides both inclusion proof and consistency proof. The API -- design is inspired by Certificate Transparency defined in RFC 6962. module Data.HashTree -- | Settings for Merkle Hash Trees. The first parameter is input data -- type. The second one is digest data type. -- -- To create this, use defaultSettings: -- --
-- defaultSettings { hash0 = ..., hash1 = ..., hash2 = ... }
--
data Settings inp ha
-- | A default Settings with ByteString and SHA256. This can
-- be used for CT(Certificate Transparency) defined in RFC 6962.
defaultSettings :: Settings ByteString SHA256
-- | A hash value for non input element.
hash0 :: Settings inp ha -> Digest ha
-- | A hash function for one input element to calculate the leaf digest.
hash1 :: Settings inp ha -> inp -> Digest ha
-- | A hash function for two input elements to calculate the internal
-- digest.
hash2 :: Settings inp ha -> Digest ha -> Digest ha -> Digest ha
-- | The data type for Merkle Hash Trees. The first parameter is input data
-- type. The second one is digest data type.
data MerkleHashTrees inp ha
-- | Getting the root information of the Merkle Hash Tree. A pair of the
-- current size and the current Merle Tree Hash is returned.
info :: MerkleHashTrees inp ha -> (TreeSize, Digest ha)
-- | Getting the log size
size :: MerkleHashTrees inp ha -> TreeSize
-- | Getting the Merkle Tree Hash.
digest :: TreeSize -> MerkleHashTrees inp ha -> Maybe (Digest ha)
-- | The size of hash tree.
type TreeSize = Int
-- | The position of the target element from 0.
type Index = Int
-- | Creating an empty MerkleHashTrees.
--
-- -- >>> info $ empty defaultSettings -- (0,e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855) --empty :: Settings inp ha -> MerkleHashTrees inp ha -- | Creating a Merkle Hash Tree from a list of elements. O(n log n) -- --
-- >>> info $ fromList defaultSettings ["0","1","2"] -- (3,725d5230db68f557470dc35f1d8865813acd7ebb07ad152774141decbae71327) --fromList :: (ByteArrayAccess inp, HashAlgorithm ha) => Settings inp ha -> [inp] -> MerkleHashTrees inp ha -- | Adding (appending) an element. O(log n) -- --
-- >>> info $ add "1" $ empty defaultSettings -- (1,2215e8ac4e2b871c2a48189e79738c956c081e23ac2f2415bf77da199dfd920c) --add :: (ByteArrayAccess inp, HashAlgorithm ha) => inp -> MerkleHashTrees inp ha -> MerkleHashTrees inp ha -- | The type for inclusion proof (aka audit proof). data InclusionProof ha -- | The default value for InclusionProof just to create a new -- value. defaultInclusionProof :: InclusionProof ha -- | The index for the target. leafIndex :: InclusionProof ha -> Index -- | The hash tree size. treeSize :: InclusionProof ha -> TreeSize -- | A list of digest for inclusion. inclusion :: InclusionProof ha -> [Digest ha] -- | Generating InclusionProof for the target at the server side. generateInclusionProof :: Digest ha -> TreeSize -> MerkleHashTrees inp ha -> Maybe (InclusionProof ha) -- | Verifying InclusionProof at the client side. -- --
-- >>> let target = "3" -- -- >>> let mht = fromList defaultSettings ["0","1","2",target,"4","5","6"] -- -- >>> let treeSize = 5 -- -- >>> let leafDigest = hash1 defaultSettings target -- -- >>> let Just proof = generateInclusionProof leafDigest treeSize mht -- -- >>> let Just rootDigest = digest treeSize mht -- -- >>> verifyInclusionProof defaultSettings leafDigest rootDigest proof -- True --verifyInclusionProof :: (ByteArrayAccess inp, HashAlgorithm ha) => Settings inp ha -> Digest ha -> Digest ha -> InclusionProof ha -> Bool -- | The type for consistency proof. data ConsistencyProof ha -- | The default value for ConsistencyProof just to create a new -- value. defaultConsistencyProof :: ConsistencyProof ha -- | The first hash tree size. firstTreeSize :: ConsistencyProof ha -> TreeSize -- | The second hash tree size. secondTreeSize :: ConsistencyProof ha -> TreeSize -- | A list of digest for consistency. consistency :: ConsistencyProof ha -> [Digest ha] -- | Generating ConsistencyProof for the target at the server side. generateConsistencyProof :: TreeSize -> TreeSize -> MerkleHashTrees inp ha -> Maybe (ConsistencyProof ha) -- | Verifying ConsistencyProof at the client side. -- --
-- >>> let mht0 = fromList defaultSettings ["0","1","2","3"] -- -- >>> let (m, digestM) = info mht0 -- -- >>> let mht1 = add "6" $ add "5" $ add "4" mht0 -- -- >>> let (n, digestN) = info mht1 -- -- >>> let Just proof = generateConsistencyProof m n mht1 -- -- >>> verifyConsistencyProof defaultSettings digestM digestN proof -- True --verifyConsistencyProof :: (ByteArrayAccess inp, HashAlgorithm ha) => Settings inp ha -> Digest ha -> Digest ha -> ConsistencyProof ha -> Bool