UNPKG

@metamask/eth-ledger-bridge-keyring

Version:
30 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTransactionSelector = void 0; const tx_1 = require("@ethereumjs/tx"); const util_1 = require("@ethereumjs/util"); const utils_1 = require("@metamask/utils"); /** * Returns the 4-byte selector from raw serialized transaction hex or undefined if not present. * Supports legacy RLP and EIP-2718 typed transactions (via `@ethereumjs/tx`). * * @param rawTxHex - Raw serialized transaction hex (with or without `0x` prefix). * @returns The selector (`0x` + 8 hex digits, lowercased) or undefined if parsing fails or no calldata. */ function getTransactionSelector(rawTxHex) { try { const prefixedHex = (0, utils_1.add0x)(rawTxHex); const tx = tx_1.TransactionFactory.fromSerializedData((0, util_1.hexToBytes)(prefixedHex)); const dataHex = (0, util_1.bytesToHex)(tx.data); const selectorSize = 2 /* 0x */ + 4 * 2; /* 4 bytes (hex) */ if (dataHex.length >= selectorSize) { return dataHex.slice(0, selectorSize).toLowerCase(); } } catch { // ignore parse errors } return undefined; } exports.getTransactionSelector = getTransactionSelector; //# sourceMappingURL=utils.cjs.map