UNPKG

@aeternity/aepp-calldata

Version:
34 lines (33 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.int2ByteArray = exports.byteArray2IntBE = exports.byteArray2Int = exports.byteArray2Hex = void 0; const int2ByteArray = value => { const bigInt = BigInt(value); if (bigInt < 256n) { return new Uint8Array([Number(bigInt)]); } return new Uint8Array([...int2ByteArray(bigInt >> 8n), Number(bigInt & 0xffn)]); }; exports.int2ByteArray = int2ByteArray; const byteArrayToHexArray = data => { return [...data].map(x => x.toString(16).padStart(2, '0')); }; const byteArray2Int = data => { if (data.length === 0) { return 0n; } const hex = byteArrayToHexArray(data); return BigInt('0x' + hex.join('')); }; exports.byteArray2Int = byteArray2Int; const byteArray2IntBE = data => { const hex = byteArrayToHexArray(data).reverse(); return BigInt('0x' + hex.join('')); }; exports.byteArray2IntBE = byteArray2IntBE; const byteArray2Hex = data => { return byteArrayToHexArray(data).join(''); }; exports.byteArray2Hex = byteArray2Hex;