@dcl/content-hash-tree
Version:
Lib to generate and validate a merkle tree of content hashes
32 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateRoot = exports.verifyProof = exports.generateTree = void 0;
const content_hash_tree_1 = require("./content-hash-tree");
function generateTree(contentHashes) {
const sortedContentHashes = contentHashes.sort();
// construct a tree
const tree = new content_hash_tree_1.ContentHashTree(sortedContentHashes);
// generate proofs
const proofs = sortedContentHashes.reduce((memo, contentHash, index) => {
memo[contentHash] = {
index,
proof: tree.getProof(index, contentHash)
};
return memo;
}, {});
return {
merkleRoot: tree.getHexRoot(),
total: contentHashes.length,
proofs
};
}
exports.generateTree = generateTree;
function verifyProof(index, contentHash, proof, root) {
return content_hash_tree_1.ContentHashTree.verifyProof(index, contentHash, proof, root);
}
exports.verifyProof = verifyProof;
function generateRoot(index, contentHash, proof) {
return content_hash_tree_1.ContentHashTree.generateRoot(index, contentHash, proof);
}
exports.generateRoot = generateRoot;
//# sourceMappingURL=index.js.map