UNPKG

opstack-kit-chains

Version:
74 lines 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertTransactionLegacy = exports.assertTransactionEIP2930 = exports.assertTransactionEIP1559 = exports.assertTransactionEIP4844 = void 0; const kzg_js_1 = require("../../constants/kzg.js"); const address_js_1 = require("../../errors/address.js"); const base_js_1 = require("../../errors/base.js"); const blob_js_1 = require("../../errors/blob.js"); const chain_js_1 = require("../../errors/chain.js"); const node_js_1 = require("../../errors/node.js"); const isAddress_js_1 = require("../address/isAddress.js"); const size_js_1 = require("../data/size.js"); const slice_js_1 = require("../data/slice.js"); const fromHex_js_1 = require("../encoding/fromHex.js"); function assertTransactionEIP4844(transaction) { const { blobVersionedHashes } = transaction; if (blobVersionedHashes) { if (blobVersionedHashes.length === 0) throw new blob_js_1.EmptyBlobError(); for (const hash of blobVersionedHashes) { const size_ = (0, size_js_1.size)(hash); const version = (0, fromHex_js_1.hexToNumber)((0, slice_js_1.slice)(hash, 0, 1)); if (size_ !== 32) throw new blob_js_1.InvalidVersionedHashSizeError({ hash, size: size_ }); if (version !== kzg_js_1.versionedHashVersionKzg) throw new blob_js_1.InvalidVersionedHashVersionError({ hash, version, }); } } assertTransactionEIP1559(transaction); } exports.assertTransactionEIP4844 = assertTransactionEIP4844; function assertTransactionEIP1559(transaction) { const { chainId, maxPriorityFeePerGas, maxFeePerGas, to } = transaction; if (chainId <= 0) throw new chain_js_1.InvalidChainIdError({ chainId }); if (to && !(0, isAddress_js_1.isAddress)(to)) throw new address_js_1.InvalidAddressError({ address: to }); if (maxFeePerGas && maxFeePerGas > 2n ** 256n - 1n) throw new node_js_1.FeeCapTooHighError({ maxFeePerGas }); if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas) throw new node_js_1.TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas }); } exports.assertTransactionEIP1559 = assertTransactionEIP1559; function assertTransactionEIP2930(transaction) { const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction; if (chainId <= 0) throw new chain_js_1.InvalidChainIdError({ chainId }); if (to && !(0, isAddress_js_1.isAddress)(to)) throw new address_js_1.InvalidAddressError({ address: to }); if (maxPriorityFeePerGas || maxFeePerGas) throw new base_js_1.BaseError('`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.'); if (gasPrice && gasPrice > 2n ** 256n - 1n) throw new node_js_1.FeeCapTooHighError({ maxFeePerGas: gasPrice }); } exports.assertTransactionEIP2930 = assertTransactionEIP2930; function assertTransactionLegacy(transaction) { const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to, accessList, } = transaction; if (to && !(0, isAddress_js_1.isAddress)(to)) throw new address_js_1.InvalidAddressError({ address: to }); if (typeof chainId !== 'undefined' && chainId <= 0) throw new chain_js_1.InvalidChainIdError({ chainId }); if (maxPriorityFeePerGas || maxFeePerGas) throw new base_js_1.BaseError('`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.'); if (gasPrice && gasPrice > 2n ** 256n - 1n) throw new node_js_1.FeeCapTooHighError({ maxFeePerGas: gasPrice }); if (accessList) throw new base_js_1.BaseError('`accessList` is not a valid Legacy Transaction attribute.'); } exports.assertTransactionLegacy = assertTransactionLegacy; //# sourceMappingURL=assertTransaction.js.map