UNPKG

@iden3/js-merkletree

Version:

javascript sparse merkle tree library

26 lines (25 loc) 786 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bigIntToUINT8Array = exports.bigint2Array = void 0; const constants_1 = require("../../constants"); const bigint2Array = (bigNum, radix) => { return bigNum .toString(radix ? radix : 10) .split('') .map((n) => { return parseInt(n); }); }; exports.bigint2Array = bigint2Array; const bigIntToUINT8Array = (bigNum) => { const n256 = BigInt(256); const bytes = new Uint8Array(constants_1.HASH_BYTES_LENGTH); let i = 0; while (bigNum > BigInt(0)) { bytes[constants_1.HASH_BYTES_LENGTH - 1 - i] = Number(bigNum % n256); bigNum = bigNum / n256; i += 1; } return bytes; }; exports.bigIntToUINT8Array = bigIntToUINT8Array;