UNPKG

@iden3/js-merkletree

Version:

javascript sparse merkle tree library

19 lines (18 loc) 674 B
// const siblingBytes = bs.slice(this.notEmpties.length + PROOF_FLAG_LEN); import { HASH_BYTES_LENGTH } from '../../constants'; import { testBit } from './bytes'; export const getPath = (numLevels, k) => { const path = new Array(numLevels); for (let idx = 0; idx < numLevels; idx += 1) { path[idx] = testBit(k, idx); } return path; }; export const siblings2Bytes = (siblings) => { const siblingBytesBuff = new ArrayBuffer(HASH_BYTES_LENGTH * siblings.length); const siblingBytes = new Uint8Array(siblingBytesBuff); siblings.forEach((v, i) => { siblingBytes.set(v.value, i * HASH_BYTES_LENGTH); }); return siblingBytes; };