UNPKG

evm-blockchain-tools

Version:

This is a collection of resuseable tools to support development for EVM-powered blockchains

40 lines 1.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseAddressByNetwork = parseAddressByNetwork; exports.areAddressesSame = areAddressesSame; exports.convertAddressToBytes32 = convertAddressToBytes32; exports.isValidEvmTxFormat = isValidEvmTxFormat; exports.isValidTronTxFormat = isValidTronTxFormat; const tronweb_1 = __importDefault(require("tronweb")); const constants_1 = require("../common/constants"); function parseAddressByNetwork(address, network) { if (network === constants_1.APP_NETWORK.TRON) { return tronweb_1.default.address.fromHex(address); } return address; } function areAddressesSame(address1, address2) { if (!(address1 === null || address1 === void 0 ? void 0 : address1.length)) { throw new Error("address1 must not be empty"); } if (!(address2 === null || address2 === void 0 ? void 0 : address2.length)) { throw new Error("address2 must not be empty"); } return address1.toLowerCase() === address2.toLowerCase(); } function convertAddressToBytes32(address) { const rawAddress = address.replace("0x", ""); return `0x000000000000000000000000${rawAddress}`; } function isValidEvmTxFormat(txId) { const regex = /^0x[a-zA-z0-9]{64}$/; return regex.test(txId); } function isValidTronTxFormat(txId) { const regex = /^[a-zA-z0-9]{64}$/; return regex.test(txId); } //# sourceMappingURL=address-utils.js.map