UNPKG

postchain-client

Version:

Client library for accessing a Postchain node through REST.

61 lines 2.51 kB
"use strict"; var MerkleHashCalculator = require('../merklehashcalculator').MerkleHashCalculator; var MerkleHashSummaryFactory = require('./merklehashsummaryfactory').MerkleHashSummaryFactory; var BinaryTreeFactory = require('../binarytreefactory').BinaryTreeFactory; var MerkleProofTreeFactory = require('./merkleprooftreefactory').MerkleProofTreeFactory; var treeFactory = new BinaryTreeFactory(); var proofFactory = new MerkleProofTreeFactory(); var PathSet = require('../path').PathSet; var MerkleProofTree = require('./merkleprooftree').MerkleProofTree; /** * Calculates the merkle root hash of the structure. * * @param {any} value * @param {MerkleHashCalculator} calculator describes the method we use for hashing and serialization * @return the merkle root hash (32 bytes) of the data structure. */ function merkleHash(value, calculator, merkleHashVersion) { return merkleHashSummary(value, calculator, merkleHashVersion).merkleHash; } /** * * @param {MerkleProofTree} tree * @param {MerkleHashCalculator} calculator */ function merkleTreeHash(tree, calculator, merkleHashVersion) { return merkleProofHashSummary(tree, calculator, merkleHashVersion).merkleHash; } /** * Calculates the merkle root hash of the structure * * @param {any} value * @param {MerkleHashCalculator} calculator describes the method we use for hashing and serialization * @return the merkle root hash summary */ function merkleHashSummary(value, calculator, merkleHashVersion) { var summaryFactory = new MerkleHashSummaryFactory(treeFactory, proofFactory); return summaryFactory.calculateMerkleRoot(value, calculator, merkleHashVersion); } /** * * @param {MerkleProofTree} tree * @param {MerkleHashCalculator} calculator * @param {number} merkleHashVersion */ function merkleProofHashSummary(tree, calculator, merkleHashVersion) { var summaryFactory = new MerkleHashSummaryFactory(treeFactory, proofFactory); return summaryFactory.calculateMerkleTreeRoot(tree, calculator, merkleHashVersion); } /** * * @param {any} value * @param {PathSet} pathSet * @param {MerkleHashCalculator} calculator * @param {number} merkleHashVersion */ function generateProof(value, pathSet, calculator, merkleHashVersion) { var binaryTree = treeFactory.buildWithPath(value, pathSet, merkleHashVersion); return proofFactory.buildFromBinaryTree(binaryTree, calculator); } module.exports = { merkleHash, merkleTreeHash, merkleHashSummary, generateProof }; //# sourceMappingURL=merkleproof.js.map