UNPKG

vasku

Version:

TVM-Solidity contract development framework

64 lines (63 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.numberToHex = exports.stringsToHex = exports.stringToHex = exports.abiToHex = exports.x0 = void 0; /** * Add `0x` to string or number * @param number * @example * x0('123') * @return * '0x123' */ function x0(number) { return `0x${number.toString()}`; } exports.x0 = x0; /** * Convert abi to hex * @param abi * @example * abiToHex('{ABI ver...') * @return * '7b0a0922...' */ function abiToHex(abi) { return stringToHex(JSON.stringify(abi)); } exports.abiToHex = abiToHex; /** * Convert string to hex * @param string * @example * stringToHex('XYZ123') * @return * '58595a313233' */ function stringToHex(string) { return string.split('').map((x) => x.charCodeAt(0).toString(16)).join(''); } exports.stringToHex = stringToHex; /** * Convert array of strings to hex. Actual for string[] or bytes[] parameter in Solidity * @param strings * @example * stringsToHex(['XYZ123', 'ABC456']) * @return * ['58595a313233', '414243343536'] */ function stringsToHex(strings) { return strings.map((x) => stringToHex(x)); } exports.stringsToHex = stringsToHex; /** * Convert number to hex * @param number * @example * numberToHex(1_000_000_000) * @return * '0x3b9aca00' */ function numberToHex(number) { return x0(number.toString(16)); } exports.numberToHex = numberToHex;