@chainsafe/eth2.0-utils
Version:
Utilities required across multiple lodestar packages
29 lines (23 loc) • 716 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.verifyMerkleBranch = verifyMerkleBranch;
var _math = require("../math");
var _crypto = require("../crypto");
/**
* Verify that the given ``leaf`` is on the merkle branch ``proof``
* starting with the given ``root``.
*/
function verifyMerkleBranch(leaf, proof, depth, index, root) {
let value = Buffer.from(leaf);
for (let i = 0; i < depth; i++) {
if ((0, _math.intDiv)(index, 2 ** i) % 2) {
value = (0, _crypto.hash)(Buffer.concat([proof[i], value]));
} else {
value = (0, _crypto.hash)(Buffer.concat([value, proof[i]]));
}
}
return value.equals(root);
}
//# sourceMappingURL=utils.js.map