evm-blockchain-tools
Version:
This is a collection of resuseable tools to support development for EVM-powered blockchains
41 lines • 1.74 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidTronTxFormat = exports.isValidEvmTxFormat = exports.convertAddressToBytes32 = exports.areAddressesSame = exports.parseAddressByNetwork = void 0;
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;
}
exports.parseAddressByNetwork = parseAddressByNetwork;
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();
}
exports.areAddressesSame = areAddressesSame;
function convertAddressToBytes32(address) {
const rawAddress = address.replace("0x", "");
return `0x000000000000000000000000${rawAddress}`;
}
exports.convertAddressToBytes32 = convertAddressToBytes32;
function isValidEvmTxFormat(txId) {
const regex = /^0x[a-zA-z0-9]{64}$/;
return regex.test(txId);
}
exports.isValidEvmTxFormat = isValidEvmTxFormat;
function isValidTronTxFormat(txId) {
const regex = /^[a-zA-z0-9]{64}$/;
return regex.test(txId);
}
exports.isValidTronTxFormat = isValidTronTxFormat;
//# sourceMappingURL=address-utils.js.map