bitcoinjs-lib
Version:
Client-side Bitcoin JavaScript library
23 lines (22 loc) • 730 B
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
exports.fastMerkleRoot = void 0;
function fastMerkleRoot(values, digestFn) {
if (!Array.isArray(values)) throw TypeError('Expected values Array');
if (typeof digestFn !== 'function')
throw TypeError('Expected digest Function');
let length = values.length;
const results = values.concat();
while (length > 1) {
let j = 0;
for (let i = 0; i < length; i += 2, ++j) {
const left = results[i];
const right = i + 1 === length ? left : results[i + 1];
const data = Buffer.concat([left, right]);
results[j] = digestFn(data);
}
length = j;
}
return results[0];
}
exports.fastMerkleRoot = fastMerkleRoot;
;