UNPKG

iota-ternary

Version:

Fast utility functions for conversion between trytes, trits and bytes

22 lines (21 loc) 669 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function tritsToBytes(trits) { var i, j, value; const size = Math.ceil(trits.length / 5); const bytes = Buffer.alloc(size); for (i = 0, value = 0; i < size; ++i) { value = ((3 ** 0) * (trits[i * 5 + 0] || 0) + (3 ** 1) * (trits[i * 5 + 1] || 0) + (3 ** 2) * (trits[i * 5 + 2] || 0) + (3 ** 3) * (trits[i * 5 + 3] || 0) + (3 ** 4) * (trits[i * 5 + 4] || 0)); bytes.writeInt8(value, i); } return bytes; } exports.tritsToBytes = tritsToBytes;