UNPKG

@iden3/js-merkletree

Version:

javascript sparse merkle tree library

24 lines (23 loc) 889 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.siblings2Bytes = exports.getPath = void 0; // const siblingBytes = bs.slice(this.notEmpties.length + PROOF_FLAG_LEN); const constants_1 = require("../../constants"); const bytes_1 = require("./bytes"); const getPath = (numLevels, k) => { const path = new Array(numLevels); for (let idx = 0; idx < numLevels; idx += 1) { path[idx] = (0, bytes_1.testBit)(k, idx); } return path; }; exports.getPath = getPath; const siblings2Bytes = (siblings) => { const siblingBytesBuff = new ArrayBuffer(constants_1.HASH_BYTES_LENGTH * siblings.length); const siblingBytes = new Uint8Array(siblingBytesBuff); siblings.forEach((v, i) => { siblingBytes.set(v.value, i * constants_1.HASH_BYTES_LENGTH); }); return siblingBytes; }; exports.siblings2Bytes = siblings2Bytes;