UNPKG

@harmoniclabs/plu-ts-onchain

Version:

An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript

33 lines (32 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.positiveBigIntAsBytes = exports.positiveIntAsBytes = void 0; var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils"); /** * writes the number in a new `Uint8Array` Big Endian */ function positiveIntAsBytes(n) { if (typeof n === "bigint") { return positiveBigIntAsBytes(n); } if (!Number.isSafeInteger(n) || n < 0) { console.log(n); console.trace(); // some help throw new Error("how did you end up here? the name of the function explicitly says 'positiveIntAsBytes'"); } var str = n.toString(16); str = str.length % 2 === 0 ? str : "0" + str; return (0, uint8array_utils_1.fromHex)(str); } exports.positiveIntAsBytes = positiveIntAsBytes; function positiveBigIntAsBytes(n) { if (n < 0 || typeof n !== "bigint") { console.log(n); console.trace(); // some help throw new Error("how did you end up here? the name of the function explicitly says 'positiveBigIntAsBytes'"); } var strHex = n.toString(16); strHex = strHex.length % 2 === 0 ? strHex : "0" + strHex; return (0, uint8array_utils_1.fromHex)(strHex); } exports.positiveBigIntAsBytes = positiveBigIntAsBytes;