UNPKG

@swtc/serializer

Version:
52 lines 3.87 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sort_fields = exports.readAndSum = exports.isString = exports.isNumber = exports.isHexHASH256String = exports.isHexInt64String = exports.hex_str_to_byte_array = exports.get_ledger_entry_type = exports.get_transaction_result = exports.get_transaction_type = exports.get_dec_from_hexchar = exports.get_char_from_num = exports.convertStringToHex = exports.convertHexToString = exports.convertIntegerToByteArray = exports.convertByteArrayToHex = exports.serializeHex = exports.convertHexToByteArray = void 0; const bn_plus_js_1 = __importDefault(require("bn-plus.js")); const SerializedType_1 = __importDefault(require("./types/SerializedType")); /* * Input: HEX data in string format * Output: byte array */ const serializeHex = (so, hexData, noLength) => { const byteData = convertHexToByteArray(hexData); // bytes.fromBits(hex.toBits(hexData)); if (!noLength) { SerializedType_1.default.serialize_varint(so, byteData.length); } so.append(byteData); }; exports.serializeHex = serializeHex; /* * Convert a HEX string to byte array * for a string, returns as byte array * Input is not even, add 0 to the end. * a0c -> a0 c0 */ const convertHexToByteArray = in_str => { // If the input HEX string is odd, if (in_str.length % 2 !== 0) { in_str = in_str + "0"; } return new bn_plus_js_1.default(in_str, 16).toArray(undefined, in_str.length / 2); }; exports.convertHexToByteArray = convertHexToByteArray; var common_1 = require("@swtc/common"); Object.defineProperty(exports, "convertByteArrayToHex", { enumerable: true, get: function () { return common_1.convertByteArrayToHex; } }); Object.defineProperty(exports, "convertIntegerToByteArray", { enumerable: true, get: function () { return common_1.convertIntegerToByteArray; } }); Object.defineProperty(exports, "convertHexToString", { enumerable: true, get: function () { return common_1.convertHexToString; } }); Object.defineProperty(exports, "convertStringToHex", { enumerable: true, get: function () { return common_1.convertStringToHex; } }); Object.defineProperty(exports, "get_char_from_num", { enumerable: true, get: function () { return common_1.get_char_from_num; } }); Object.defineProperty(exports, "get_dec_from_hexchar", { enumerable: true, get: function () { return common_1.get_dec_from_hexchar; } }); Object.defineProperty(exports, "get_transaction_type", { enumerable: true, get: function () { return common_1.get_transaction_type; } }); Object.defineProperty(exports, "get_transaction_result", { enumerable: true, get: function () { return common_1.get_transaction_result; } }); Object.defineProperty(exports, "get_ledger_entry_type", { enumerable: true, get: function () { return common_1.get_ledger_entry_type; } }); Object.defineProperty(exports, "hex_str_to_byte_array", { enumerable: true, get: function () { return common_1.hex_str_to_byte_array; } }); Object.defineProperty(exports, "isHexInt64String", { enumerable: true, get: function () { return common_1.isHexInt64String; } }); Object.defineProperty(exports, "isHexHASH256String", { enumerable: true, get: function () { return common_1.isHexHASH256String; } }); Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return common_1.isNumber; } }); Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return common_1.isString; } }); Object.defineProperty(exports, "readAndSum", { enumerable: true, get: function () { return common_1.readAndSum; } }); Object.defineProperty(exports, "sort_fields", { enumerable: true, get: function () { return common_1.sort_fields; } }); //# sourceMappingURL=Utils.js.map