Exemple #1
0
        public MerkleProofElement BuildFromBinaryTreeInternal(BinaryTreeElement currentElement, MerkleHashCalculator calculator)
        {
            if (currentElement is EmptyLeaf)
            {
                return(new ProofHashedLeaf(new byte[32]));
            }
            else if (currentElement is Leaf)
            {
                var leafElement = (Leaf)currentElement;
                var pathElem    = currentElement.PathElem;
                if (!(pathElem is null))
                {
                    if (pathElem is PathLeafElement)
                    {
                        return(new ProofValueLeaf(leafElement.Content, pathElem.Previous));
                    }
                    else
                    {
                        throw new System.Exception("The path and structure don't match. We are at a leaf, but path elem is not a leaf: " + pathElem);
                    }
                }
                else
                {
                    var hash = calculator.CalculateLeafHash(leafElement.Content);

                    return(new ProofHashedLeaf(hash));
                }
            }
Exemple #2
0
        public MerkleProofTree BuildFromBinaryTree(BinaryTree originalTree, MerkleHashCalculator calculator)
        {
            var rootElem = this.BuildFromBinaryTreeInternal(originalTree.Root, calculator);

            return(new MerkleProofTree(rootElem));
        }