UNPKG

flexbuf

Version:
33 lines 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Utils = void 0; const low_level_1 = require("low-level"); const crypto_1 = require("crypto"); class Utils { static splitNTimes(str, delim, count) { const parts = str.split(delim); const tail = parts.slice(count).join(delim); const result = parts.slice(0, count); if (tail) result.push(tail); return result; } static encodeLengthForUnlimited(length) { const lenStr = length.toString(15) + "F"; return low_level_1.Uint.from((lenStr.length % 2 === 0) ? lenStr : ("0" + lenStr)); } static decodeLengthFromUnlimited(hexData) { const base15Length = this.splitNTimes(hexData.toHex().toUpperCase(), "F", 1)[0]; return [ parseInt(base15Length, 15), Math.ceil((base15Length.length + 1) / 2) ]; } static sha256(input) { return new low_level_1.Uint256((0, crypto_1.createHash)('sha3-256') .update(input.getRaw()) .digest()); } } exports.Utils = Utils; //# sourceMappingURL=utils.js.map