merkle-t
Version:
Merkle Tree with Poseidon Hash in TypeScript
25 lines • 867 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toDecimal = exports.toBinary = exports.zip = exports.chunk = void 0;
const chunk = (arr, size) => {
return Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size));
};
exports.chunk = chunk;
const zip = (arr1, arr2) => {
return arr1.map((_, i) => [arr1[i], arr2[i]]);
};
exports.zip = zip;
const toBinary = (decimal, depth) => {
const binary = (decimal >>> 0).toString(2).split("");
const diff = depth - binary.length;
for (let i = 0; i < diff; i++) {
binary.unshift("0");
}
return binary.map((bit) => (bit === "0" ? "0" : "1"));
};
exports.toBinary = toBinary;
const toDecimal = (binary) => {
return parseInt(binary.join(""), 2);
};
exports.toDecimal = toDecimal;
//# sourceMappingURL=utils.js.map