Socket
Socket
Sign inDemoInstall

@ethereumjs/tx

Package Overview
Dependencies
9
Maintainers
4
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.2.1 to 5.3.0

6

dist/cjs/baseTransaction.d.ts

@@ -84,2 +84,8 @@ import { Chain, Common } from '@ethereumjs/common';

/**
* Returns the effective priority fee. This is the priority fee which the coinbase will receive
* once it is included in the block
* @param baseFee Optional baseFee of the block. Note for EIP1559 and EIP4844 this is required.
*/
abstract getEffectivePriorityFee(baseFee: bigint | undefined): bigint;
/**
* The up front amount that an account must have for this transaction to be valid

@@ -86,0 +92,0 @@ */

1

dist/cjs/capabilities/eip1559.d.ts
import type { EIP1559CompatibleTx } from '../types.js';
export declare function getUpfrontCost(tx: EIP1559CompatibleTx, baseFee: bigint): bigint;
export declare function getEffectivePriorityFee(tx: EIP1559CompatibleTx, baseFee: bigint | undefined): bigint;
//# sourceMappingURL=eip1559.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUpfrontCost = void 0;
exports.getEffectivePriorityFee = exports.getUpfrontCost = void 0;
function getUpfrontCost(tx, baseFee) {

@@ -12,2 +12,11 @@ const prio = tx.maxPriorityFeePerGas;

exports.getUpfrontCost = getUpfrontCost;
function getEffectivePriorityFee(tx, baseFee) {
if (baseFee === undefined || baseFee > tx.maxFeePerGas) {
throw new Error('Tx cannot pay baseFee');
}
// The remaining fee for the coinbase, which can take up to this value, capped at `maxPriorityFeePerGas`
const remainingFee = tx.maxFeePerGas - baseFee;
return tx.maxPriorityFeePerGas < remainingFee ? tx.maxPriorityFeePerGas : remainingFee;
}
exports.getEffectivePriorityFee = getEffectivePriorityFee;
//# sourceMappingURL=eip1559.js.map

@@ -15,2 +15,3 @@ import type { LegacyTxInterface } from '../types.js';

export declare function getSenderPublicKey(tx: LegacyTxInterface): Uint8Array;
export declare function getEffectivePriorityFee(gasPrice: bigint, baseFee: bigint | undefined): bigint;
//# sourceMappingURL=legacy.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSenderPublicKey = exports.validateHighS = exports.hash = exports.getDataFee = exports.isSigned = exports.errorMsg = void 0;
exports.getEffectivePriorityFee = exports.getSenderPublicKey = exports.validateHighS = exports.hash = exports.getDataFee = exports.isSigned = exports.errorMsg = void 0;
const util_1 = require("@ethereumjs/util");

@@ -87,2 +87,12 @@ const keccak_js_1 = require("ethereum-cryptography/keccak.js");

exports.getSenderPublicKey = getSenderPublicKey;
function getEffectivePriorityFee(gasPrice, baseFee) {
if (baseFee !== undefined && baseFee > gasPrice) {
throw new Error('Tx cannot pay baseFee');
}
if (baseFee === undefined) {
return gasPrice;
}
return gasPrice - baseFee;
}
exports.getEffectivePriorityFee = getEffectivePriorityFee;
//# sourceMappingURL=legacy.js.map

@@ -58,2 +58,7 @@ import { BaseTransaction } from './baseTransaction.js';

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee: bigint): bigint;
/**
* The up front amount that an account must have for this transaction to be valid

@@ -60,0 +65,0 @@ * @param baseFee The base fee of the block (will be set to 0 if not provided)

@@ -129,2 +129,9 @@ "use strict";

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee) {
return EIP1559.getEffectivePriorityFee(this, baseFee);
}
/**
* The up front amount that an account must have for this transaction to be valid

@@ -131,0 +138,0 @@ * @param baseFee The base fee of the block (will be set to 0 if not provided)

@@ -52,2 +52,3 @@ import { BaseTransaction } from './baseTransaction.js';

constructor(txData: TxData, opts?: TxOptions);
getEffectivePriorityFee(baseFee?: bigint): bigint;
/**

@@ -54,0 +55,0 @@ * The amount of gas paid for the data in this tx

@@ -116,2 +116,5 @@ "use strict";

}
getEffectivePriorityFee(baseFee) {
return Legacy.getEffectivePriorityFee(this.gasPrice, baseFee);
}
/**

@@ -118,0 +121,0 @@ * The amount of gas paid for the data in this tx

@@ -35,2 +35,7 @@ import { BaseTransaction } from './baseTransaction.js';

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee: bigint): bigint;
/**
* Creates the minimal representation of a blob transaction from the network wrapper version.

@@ -37,0 +42,0 @@ * The minimal representation is used when adding transactions to an execution payload/block

23

dist/cjs/eip4844Transaction.js

@@ -120,2 +120,6 @@ "use strict";

static fromTxData(txData, opts) {
if (opts?.common?.customCrypto?.kzg === undefined) {
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}
const kzg = opts.common.customCrypto.kzg;
if (txData.blobsData !== undefined) {

@@ -135,5 +139,5 @@ if (txData.blobs !== undefined) {

txData.blobs = (0, util_1.getBlobs)(txData.blobsData.reduce((acc, cur) => acc + cur));
txData.kzgCommitments = (0, util_1.blobsToCommitments)(txData.blobs);
txData.kzgCommitments = (0, util_1.blobsToCommitments)(kzg, txData.blobs);
txData.blobVersionedHashes = (0, util_1.commitmentsToVersionedHashes)(txData.kzgCommitments);
txData.kzgProofs = (0, util_1.blobsToProofs)(txData.blobs, txData.kzgCommitments);
txData.kzgProofs = (0, util_1.blobsToProofs)(kzg, txData.blobs, txData.kzgCommitments);
}

@@ -143,2 +147,9 @@ return new BlobEIP4844Transaction(txData, opts);

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee) {
return EIP1559.getEffectivePriorityFee(this, baseFee);
}
/**
* Creates the minimal representation of a blob transaction from the network wrapper version.

@@ -152,3 +163,3 @@ * The minimal representation is used when adding transactions to an execution payload/block

if (opts?.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -169,3 +180,3 @@ const tx = BlobEIP4844Transaction.fromTxData({

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -189,3 +200,3 @@ if ((0, util_1.equalsBytes)(serialized.subarray(0, 1), (0, util_js_1.txTypeBytes)(types_js_1.TransactionType.BlobEIP4844)) === false) {

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -236,3 +247,3 @@ if (values.length !== 11 && values.length !== 14) {

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -239,0 +250,0 @@ if ((0, util_1.equalsBytes)(serialized.subarray(0, 1), (0, util_js_1.txTypeBytes)(types_js_1.TransactionType.BlobEIP4844)) === false) {

@@ -43,2 +43,3 @@ import { BaseTransaction } from './baseTransaction.js';

constructor(txData: TxData, opts?: TxOptions);
getEffectivePriorityFee(baseFee?: bigint): bigint;
/**

@@ -45,0 +46,0 @@ * Returns a Uint8Array Array of the raw Bytes of the legacy transaction, in order.

@@ -106,2 +106,5 @@ "use strict";

}
getEffectivePriorityFee(baseFee) {
return Legacy.getEffectivePriorityFee(this.gasPrice, baseFee);
}
/**

@@ -108,0 +111,0 @@ * Returns a Uint8Array Array of the raw Bytes of the legacy transaction, in order.

@@ -84,2 +84,8 @@ import { Chain, Common } from '@ethereumjs/common';

/**
* Returns the effective priority fee. This is the priority fee which the coinbase will receive
* once it is included in the block
* @param baseFee Optional baseFee of the block. Note for EIP1559 and EIP4844 this is required.
*/
abstract getEffectivePriorityFee(baseFee: bigint | undefined): bigint;
/**
* The up front amount that an account must have for this transaction to be valid

@@ -86,0 +92,0 @@ */

import type { EIP1559CompatibleTx } from '../types.js';
export declare function getUpfrontCost(tx: EIP1559CompatibleTx, baseFee: bigint): bigint;
export declare function getEffectivePriorityFee(tx: EIP1559CompatibleTx, baseFee: bigint | undefined): bigint;
//# sourceMappingURL=eip1559.d.ts.map

@@ -8,2 +8,10 @@ export function getUpfrontCost(tx, baseFee) {

}
export function getEffectivePriorityFee(tx, baseFee) {
if (baseFee === undefined || baseFee > tx.maxFeePerGas) {
throw new Error('Tx cannot pay baseFee');
}
// The remaining fee for the coinbase, which can take up to this value, capped at `maxPriorityFeePerGas`
const remainingFee = tx.maxFeePerGas - baseFee;
return tx.maxPriorityFeePerGas < remainingFee ? tx.maxPriorityFeePerGas : remainingFee;
}
//# sourceMappingURL=eip1559.js.map

@@ -15,2 +15,3 @@ import type { LegacyTxInterface } from '../types.js';

export declare function getSenderPublicKey(tx: LegacyTxInterface): Uint8Array;
export declare function getEffectivePriorityFee(gasPrice: bigint, baseFee: bigint | undefined): bigint;
//# sourceMappingURL=legacy.d.ts.map

@@ -78,2 +78,11 @@ import { SECP256K1_ORDER_DIV_2, bigIntToUnpaddedBytes, ecrecover } from '@ethereumjs/util';

}
export function getEffectivePriorityFee(gasPrice, baseFee) {
if (baseFee !== undefined && baseFee > gasPrice) {
throw new Error('Tx cannot pay baseFee');
}
if (baseFee === undefined) {
return gasPrice;
}
return gasPrice - baseFee;
}
//# sourceMappingURL=legacy.js.map

@@ -58,2 +58,7 @@ import { BaseTransaction } from './baseTransaction.js';

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee: bigint): bigint;
/**
* The up front amount that an account must have for this transaction to be valid

@@ -60,0 +65,0 @@ * @param baseFee The base fee of the block (will be set to 0 if not provided)

@@ -126,2 +126,9 @@ import { RLP } from '@ethereumjs/rlp';

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee) {
return EIP1559.getEffectivePriorityFee(this, baseFee);
}
/**
* The up front amount that an account must have for this transaction to be valid

@@ -128,0 +135,0 @@ * @param baseFee The base fee of the block (will be set to 0 if not provided)

@@ -52,2 +52,3 @@ import { BaseTransaction } from './baseTransaction.js';

constructor(txData: TxData, opts?: TxOptions);
getEffectivePriorityFee(baseFee?: bigint): bigint;
/**

@@ -54,0 +55,0 @@ * The amount of gas paid for the data in this tx

@@ -113,2 +113,5 @@ import { RLP } from '@ethereumjs/rlp';

}
getEffectivePriorityFee(baseFee) {
return Legacy.getEffectivePriorityFee(this.gasPrice, baseFee);
}
/**

@@ -115,0 +118,0 @@ * The amount of gas paid for the data in this tx

@@ -35,2 +35,7 @@ import { BaseTransaction } from './baseTransaction.js';

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee: bigint): bigint;
/**
* Creates the minimal representation of a blob transaction from the network wrapper version.

@@ -37,0 +42,0 @@ * The minimal representation is used when adding transactions to an execution payload/block

@@ -117,2 +117,6 @@ import { RLP } from '@ethereumjs/rlp';

static fromTxData(txData, opts) {
if (opts?.common?.customCrypto?.kzg === undefined) {
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}
const kzg = opts.common.customCrypto.kzg;
if (txData.blobsData !== undefined) {

@@ -132,5 +136,5 @@ if (txData.blobs !== undefined) {

txData.blobs = getBlobs(txData.blobsData.reduce((acc, cur) => acc + cur));
txData.kzgCommitments = blobsToCommitments(txData.blobs);
txData.kzgCommitments = blobsToCommitments(kzg, txData.blobs);
txData.blobVersionedHashes = commitmentsToVersionedHashes(txData.kzgCommitments);
txData.kzgProofs = blobsToProofs(txData.blobs, txData.kzgCommitments);
txData.kzgProofs = blobsToProofs(kzg, txData.blobs, txData.kzgCommitments);
}

@@ -140,2 +144,9 @@ return new BlobEIP4844Transaction(txData, opts);

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee) {
return EIP1559.getEffectivePriorityFee(this, baseFee);
}
/**
* Creates the minimal representation of a blob transaction from the network wrapper version.

@@ -149,3 +160,3 @@ * The minimal representation is used when adding transactions to an execution payload/block

if (opts?.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -166,3 +177,3 @@ const tx = BlobEIP4844Transaction.fromTxData({

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -186,3 +197,3 @@ if (equalsBytes(serialized.subarray(0, 1), txTypeBytes(TransactionType.BlobEIP4844)) === false) {

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -233,3 +244,3 @@ if (values.length !== 11 && values.length !== 14) {

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx');
throw new Error('A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx');
}

@@ -236,0 +247,0 @@ if (equalsBytes(serialized.subarray(0, 1), txTypeBytes(TransactionType.BlobEIP4844)) === false) {

@@ -43,2 +43,3 @@ import { BaseTransaction } from './baseTransaction.js';

constructor(txData: TxData, opts?: TxOptions);
getEffectivePriorityFee(baseFee?: bigint): bigint;
/**

@@ -45,0 +46,0 @@ * Returns a Uint8Array Array of the raw Bytes of the legacy transaction, in order.

@@ -103,2 +103,5 @@ import { RLP } from '@ethereumjs/rlp';

}
getEffectivePriorityFee(baseFee) {
return Legacy.getEffectivePriorityFee(this.gasPrice, baseFee);
}
/**

@@ -105,0 +108,0 @@ * Returns a Uint8Array Array of the raw Bytes of the legacy transaction, in order.

{
"name": "@ethereumjs/tx",
"version": "5.2.1",
"version": "5.3.0",
"description": "Implementation of the various Ethereum Transaction Types",

@@ -60,18 +60,11 @@ "keywords": [

"dependencies": {
"@ethereumjs/common": "^4.2.0",
"@ethereumjs/common": "^4.3.0",
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/util": "^9.0.2",
"@ethereumjs/util": "^9.0.3",
"ethereum-cryptography": "^2.1.3"
},
"peerDependencies": {
"c-kzg": "^2.1.2"
},
"peerDependenciesMeta": {
"c-kzg": {
"optional": true
}
},
"devDependencies": {
"@types/minimist": "^1.2.0",
"@types/node-dir": "^0.0.34",
"kzg-wasm": "^0.3.1",
"minimist": "^1.2.0",

@@ -78,0 +71,0 @@ "node-dir": "^0.1.16"

@@ -26,38 +26,39 @@ # @ethereumjs/tx

This library supports an experimental version of `EIP-4844` blob transactions (see usage instructions below) starting with `v4.1.0`.
This library now fully supports `EIP-4844` blob transactions (see usage instructions below) starting with `v5.2.0`.
For blob transactions and other KZG related proof functionality (e.g. for EVM precompiles) KZG has to be manually installed and initialized in the `common` instance to be used in instantiating blob transactions.
#### Manual Installation
Note: starting with the `v5.3` release of this library and associated releases of upstream EthereumJS libraries the old `c-kzg` centered recommended setup has been replaced by using our own WASM build of the `c-kzg` library which has been released as a separate package [kzg-wasm](https://github.com/ethereumjs/kzg-wasm) on npm.
The following two manual installation steps for a KZG library and the trusted setup are needed.
This new setup is now both browser compatible 🎉 and the official KZG setup file has been integrated by default and the new setup is now the default recommended setup to be used.
1. Install an additional dependency that supports the `kzg` interface defined in [the kzg interface](./src/kzg/kzg.ts). You can install the default option [c-kzg](https://github.com/ethereum/c-kzg-4844) by simply running `npm install c-kzg`.
2. Download the trusted setup required for the KZG module. It can be found [here](../client/src/trustedSetups/trusted_setup.txt) within the client package.
#### KZG Initialization
Initialization can then be done like this (using the `c-kzg` module for our KZG dependency):
As a first step add the `kzg-wasm` package as a dependency to your `package.json` file and install the library.
Initialization can then be done like the following:
```ts
// ./examples/initKzg.ts
import * as kzg from 'c-kzg'
import { loadKZG } from 'kzg-wasm'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { initKZG } from '@ethereumjs/util'
// Instantiate KZG
initKZG(kzg, __dirname + '/../../client/src/trustedSetups/official.txt')
const main = async () => {
const kzg = await loadKZG()
// Instantiate `common`
const common = new Common({
chain: Chain.Mainnet,
hardfork: Hardfork.Cancun,
customCrypto: { kzg },
})
// Instantiate `common`
const common = new Common({
chain: Chain.Mainnet,
hardfork: Hardfork.Cancun,
customCrypto: { kzg },
})
console.log(common.customCrypto.kzg) // should output the KZG API as an object
console.log(common.customCrypto.kzg) // should output the KZG API as an object
}
main()
```
At the moment using the Node.js bindings for the `c-kzg` library is the only option to get KZG related functionality to work, note that this solution is not browser compatible. We are currently working on a WASM build of that respective library which can hopefully be released soon [TM].
Note: Manual addition is necessary because we did not want to bundle our libraries with WASM code by default, since some projects are then prevented from using our libraries.

@@ -128,35 +129,39 @@ ## Usage

import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import { bytesToHex, initKZG } from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { bytesToHex } from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
initKZG(kzg, __dirname + '/../../client/src/trustedSetups/devnet6.txt')
const main = async () => {
const kzg = await loadKZG()
const common = new Common({
chain: Chain.Mainnet,
hardfork: Hardfork.Shanghai,
eips: [4844],
customCrypto: { kzg },
})
const common = new Common({
chain: Chain.Mainnet,
hardfork: Hardfork.Shanghai,
eips: [4844],
customCrypto: { kzg },
})
const txData = {
data: '0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
gasLimit: '0x02625a00',
maxPriorityFeePerGas: '0x01',
maxFeePerGas: '0xff',
maxFeePerDataGas: '0xfff',
nonce: '0x00',
to: '0xcccccccccccccccccccccccccccccccccccccccc',
value: '0x0186a0',
v: '0x01',
r: '0xafb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9',
s: '0x479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64',
chainId: '0x01',
accessList: [],
type: '0x05',
blobsData: ['abcd'],
const txData = {
data: '0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
gasLimit: '0x02625a00',
maxPriorityFeePerGas: '0x01',
maxFeePerGas: '0xff',
maxFeePerDataGas: '0xfff',
nonce: '0x00',
to: '0xcccccccccccccccccccccccccccccccccccccccc',
value: '0x0186a0',
v: '0x01',
r: '0xafb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9',
s: '0x479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64',
chainId: '0x01',
accessList: [],
type: '0x05',
blobsData: ['abcd'],
}
const tx = BlobEIP4844Transaction.fromTxData(txData, { common })
console.log(bytesToHex(tx.hash())) //0x3c3e7c5e09c250d2200bcc3530f4a9088d7e3fb4ea3f4fccfd09f535a3539e84
}
const tx = BlobEIP4844Transaction.fromTxData(txData, { common })
console.log(bytesToHex(tx.hash())) //0x3c3e7c5e09c250d2200bcc3530f4a9088d7e3fb4ea3f4fccfd09f535a3539e84
main()
```

@@ -163,0 +168,0 @@

@@ -209,2 +209,9 @@ import { Chain, Common } from '@ethereumjs/common'

/**
* Returns the effective priority fee. This is the priority fee which the coinbase will receive
* once it is included in the block
* @param baseFee Optional baseFee of the block. Note for EIP1559 and EIP4844 this is required.
*/
abstract getEffectivePriorityFee(baseFee: bigint | undefined): bigint
/**
* The up front amount that an account must have for this transaction to be valid

@@ -211,0 +218,0 @@ */

@@ -10,1 +10,15 @@ import type { EIP1559CompatibleTx } from '../types.js'

}
export function getEffectivePriorityFee(
tx: EIP1559CompatibleTx,
baseFee: bigint | undefined
): bigint {
if (baseFee === undefined || baseFee > tx.maxFeePerGas) {
throw new Error('Tx cannot pay baseFee')
}
// The remaining fee for the coinbase, which can take up to this value, capped at `maxPriorityFeePerGas`
const remainingFee = tx.maxFeePerGas - baseFee
return tx.maxPriorityFeePerGas < remainingFee ? tx.maxPriorityFeePerGas : remainingFee
}

@@ -104,1 +104,13 @@ import { SECP256K1_ORDER_DIV_2, bigIntToUnpaddedBytes, ecrecover } from '@ethereumjs/util'

}
export function getEffectivePriorityFee(gasPrice: bigint, baseFee: bigint | undefined): bigint {
if (baseFee !== undefined && baseFee > gasPrice) {
throw new Error('Tx cannot pay baseFee')
}
if (baseFee === undefined) {
return gasPrice
}
return gasPrice - baseFee
}

@@ -210,2 +210,10 @@ import { RLP } from '@ethereumjs/rlp'

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee: bigint): bigint {
return EIP1559.getEffectivePriorityFee(this, baseFee)
}
/**
* The up front amount that an account must have for this transaction to be valid

@@ -212,0 +220,0 @@ * @param baseFee The base fee of the block (will be set to 0 if not provided)

@@ -176,2 +176,6 @@ import { RLP } from '@ethereumjs/rlp'

getEffectivePriorityFee(baseFee?: bigint): bigint {
return Legacy.getEffectivePriorityFee(this.gasPrice, baseFee)
}
/**

@@ -178,0 +182,0 @@ * The amount of gas paid for the data in this tx

@@ -193,2 +193,8 @@ import { RLP } from '@ethereumjs/rlp'

public static fromTxData(txData: TxData, opts?: TxOptions) {
if (opts?.common?.customCrypto?.kzg === undefined) {
throw new Error(
'A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx'
)
}
const kzg = opts!.common!.customCrypto!.kzg!
if (txData.blobsData !== undefined) {

@@ -208,3 +214,3 @@ if (txData.blobs !== undefined) {

txData.blobs = getBlobs(txData.blobsData.reduce((acc, cur) => acc + cur))
txData.kzgCommitments = blobsToCommitments(txData.blobs as Uint8Array[])
txData.kzgCommitments = blobsToCommitments(kzg, txData.blobs as Uint8Array[])
txData.blobVersionedHashes = commitmentsToVersionedHashes(

@@ -214,2 +220,3 @@ txData.kzgCommitments as Uint8Array[]

txData.kzgProofs = blobsToProofs(
kzg,
txData.blobs as Uint8Array[],

@@ -224,2 +231,10 @@ txData.kzgCommitments as Uint8Array[]

/**
* Returns the minimum of calculated priority fee (from maxFeePerGas and baseFee) and maxPriorityFeePerGas
* @param baseFee Base fee retrieved from block
*/
getEffectivePriorityFee(baseFee: bigint): bigint {
return EIP1559.getEffectivePriorityFee(this, baseFee)
}
/**
* Creates the minimal representation of a blob transaction from the network wrapper version.

@@ -236,3 +251,5 @@ * The minimal representation is used when adding transactions to an execution payload/block

if (opts?.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx')
throw new Error(
'A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx'
)
}

@@ -258,3 +275,5 @@

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx')
throw new Error(
'A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx'
)
}

@@ -289,3 +308,5 @@

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx')
throw new Error(
'A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx'
)
}

@@ -366,3 +387,5 @@

if (opts.common?.customCrypto?.kzg === undefined) {
throw new Error('kzg instance required to instantiate blob tx')
throw new Error(
'A common object with customCrypto.kzg initialized required to instantiate a 4844 blob tx'
)
}

@@ -369,0 +392,0 @@

@@ -150,2 +150,6 @@ import { RLP } from '@ethereumjs/rlp'

getEffectivePriorityFee(baseFee?: bigint): bigint {
return Legacy.getEffectivePriorityFee(this.gasPrice, baseFee)
}
/**

@@ -152,0 +156,0 @@ * Returns a Uint8Array Array of the raw Bytes of the legacy transaction, in order.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc