Socket
Socket
Sign inDemoInstall

@ethereumjs/tx

Package Overview
Dependencies
Maintainers
6
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethereumjs/tx - npm Package Compare versions

Comparing version 3.1.4 to 3.2.0

dist.browser/eip1559Transaction.d.ts

45

CHANGELOG.md

@@ -9,2 +9,47 @@ # Changelog

## 3.2.0 - 2021-05-26
### London HF Support
This `Tx` release comes with full support for the `london` hardfork. There is a new [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) transaction type `FeeMarketEIP1559Transaction` (type `2`) added together with the new data types `FeeMarketEIP1559TxData` (for instantiation with the `fromTxData()` static constructor method) and `FeeMarketEIP1559ValuesArray` (for instantiation with `fromValuesArray()`), see PR [#1148](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1148) for the main implementation work.
An `EIP-1559` tx inherits the access list feature from the `AccessListEIP2930Transaction` (type `1`) but comes with its own gas fee market mechanism. There is no `gasPrice` field in favor of two new gas related properties `maxFeePerGas` - which represents the total gas fee the tx sender is willing to pay for the tx (including the priority fee) - and the `maxPriorityFeePerGas` property - which represents the fee the sender is willing to give as some tip to the miner to prioritize a tx.
An `EIP-1559` tx can be instantiated with:
```typescript
import Common from '@ethereumjs/common'
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
const common = new Common({ chain: 'mainnet', hardfork: 'london' })
const txData = {
"data": "0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x02625a00",
"maxPriorityFeePerGas": "0x01",
"maxFeePerGas": "0xff",
"nonce": "0x00",
"to": "0xcccccccccccccccccccccccccccccccccccccccc",
"value": "0x0186a0",
"v": "0x01",
"r": "0xafb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9",
"s": "0x479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64",
"chainId": "0x01",
"accessList": [],
"type": "0x02"
}
const tx = FeeMarketEIP1559Transaction.fromTxData(txData, { common })
```
Please note that the default HF is still set to `istanbul`. You therefore need to explicitly set the `hardfork` parameter for instantiating a `Tx` instance with a `london` HF activated.
### Bug Fixes
- Fixed `getMessageToSign()` return type for typed txs, PR [#1255](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1255)
### Other Changes
- Deprecated `TransactionFactory.getTransactionClass()` method, PR [#1148](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1148)
## 3.1.4 - 2021-04-22

@@ -11,0 +56,0 @@

11

dist.browser/baseTransaction.d.ts

@@ -5,3 +5,3 @@ /// <reference types="bn.js" />

import { Address, BN } from 'ethereumjs-util';
import { TxData, TxOptions, JsonTx, AccessListEIP2930ValuesArray, AccessListEIP2930TxData } from './types';
import { TxData, TxOptions, JsonTx, AccessListEIP2930ValuesArray, AccessListEIP2930TxData, FeeMarketEIP1559ValuesArray, FeeMarketEIP1559TxData, TxValuesArray } from './types';
/**

@@ -18,3 +18,2 @@ * This base class will likely be subject to further

readonly gasLimit: BN;
readonly gasPrice: BN;
readonly to?: Address;

@@ -27,3 +26,3 @@ readonly value: BN;

readonly s?: BN;
constructor(txData: TxData | AccessListEIP2930TxData, txOptions?: TxOptions);
constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, txOptions?: TxOptions);
/**

@@ -55,3 +54,3 @@ * Returns the transaction type

*/
getUpfrontCost(): BN;
abstract getUpfrontCost(): BN;
/**

@@ -64,3 +63,3 @@ * If the tx's `to` is to the creation address

*/
abstract raw(): Buffer[] | AccessListEIP2930ValuesArray;
abstract raw(): TxValuesArray | AccessListEIP2930ValuesArray | FeeMarketEIP1559ValuesArray;
/**

@@ -75,3 +74,3 @@ * Returns the encoding of the transaction.

*/
abstract getMessageToSign(hashMessage: false): Buffer[];
abstract getMessageToSign(hashMessage: false): Buffer | Buffer[];
abstract getMessageToSign(hashMessage?: true): Buffer;

@@ -78,0 +77,0 @@ abstract hash(): Buffer;

@@ -47,10 +47,4 @@ "use strict";

var _a, _b;
var nonce = txData.nonce, gasLimit = txData.gasLimit, gasPrice = txData.gasPrice, to = txData.to, value = txData.value, data = txData.data, v = txData.v, r = txData.r, s = txData.s;
var type = txData.type;
if (type !== undefined) {
this._type = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(type)).toNumber();
}
else {
this._type = 0;
}
var nonce = txData.nonce, gasLimit = txData.gasLimit, to = txData.to, value = txData.value, data = txData.data, v = txData.v, r = txData.r, s = txData.s, type = txData.type;
this._type = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(type)).toNumber();
var toB = ethereumjs_util_1.toBuffer(to === '' ? '0x' : to);

@@ -61,3 +55,2 @@ var vB = ethereumjs_util_1.toBuffer(v === '' ? '0x' : v);

this.nonce = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(nonce === '' ? '0x' : nonce));
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice === '' ? '0x' : gasPrice));
this.gasLimit = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasLimit === '' ? '0x' : gasLimit));

@@ -72,5 +65,6 @@ this.to = toB.length > 0 ? new ethereumjs_util_1.Address(toB) : undefined;

nonce: this.nonce,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
value: this.value,
r: this.r,
s: this.s,
});

@@ -133,8 +127,2 @@ this.common = (_b = (_a = txOptions.common) === null || _a === void 0 ? void 0 : _a.copy()) !== null && _b !== void 0 ? _b : new common_1.default({ chain: 'mainnet' });

/**
* The up front amount that an account must have for this transaction to be valid
*/
BaseTransaction.prototype.getUpfrontCost = function () {
return this.gasLimit.mul(this.gasPrice).add(this.value);
};
/**
* If the tx's `to` is to the creation address

@@ -147,3 +135,18 @@ */

var _a = this, v = _a.v, r = _a.r, s = _a.s;
return !!v && !!r && !!s;
if (this.type === 0) {
if (!v || !r || !s) {
return false;
}
else {
return true;
}
}
else {
if (v === undefined || !r || !s) {
return false;
}
else {
return true;
}
}
};

@@ -150,0 +153,0 @@ /**

@@ -16,2 +16,3 @@ /// <reference types="bn.js" />

readonly AccessListJSON: AccessList;
readonly gasPrice: BN;
/**

@@ -69,2 +70,6 @@ * EIP-2930 alias for `r`

/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost(): BN;
/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.

@@ -84,4 +89,3 @@ *

*/
getMessageToSign(hashMessage: false): Buffer[];
getMessageToSign(hashMessage?: true): Buffer;
getMessageToSign(hashMessage?: boolean): Buffer;
/**

@@ -88,0 +92,0 @@ * Computes a sha3-256 hash of the serialized tx

@@ -46,3 +46,5 @@ "use strict";

var types_1 = require("./types");
var emptyAccessList = [];
var util_1 = require("./util");
var TRANSACTION_TYPE = 1;
var TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex');
/**

@@ -67,4 +69,4 @@ * Typed transaction with optional access lists

var _this = this;
var chainId = txData.chainId, accessList = txData.accessList;
_this = _super.call(this, __assign(__assign({}, txData), { type: 1 }), opts) || this;
var chainId = txData.chainId, accessList = txData.accessList, gasPrice = txData.gasPrice;
_this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE }), opts) || this;
// EIP-2718 check is done in Common

@@ -74,39 +76,11 @@ if (!_this.common.isActivatedEIP(2930)) {

}
// check the type of AccessList. If it's a JSON-type, we have to convert it to a Buffer.
var usedAccessList;
if (accessList && types_1.isAccessList(accessList)) {
_this.AccessListJSON = accessList;
var newAccessList = [];
for (var i = 0; i < accessList.length; i++) {
var item = accessList[i];
var addressBuffer = ethereumjs_util_1.toBuffer(item.address);
var storageItems = [];
for (var index = 0; index < item.storageKeys.length; index++) {
storageItems.push(ethereumjs_util_1.toBuffer(item.storageKeys[index]));
}
newAccessList.push([addressBuffer, storageItems]);
}
usedAccessList = newAccessList;
}
else {
usedAccessList = accessList !== null && accessList !== void 0 ? accessList : [];
// build the JSON
var json = [];
for (var i = 0; i < usedAccessList.length; i++) {
var data = usedAccessList[i];
var address = ethereumjs_util_1.bufferToHex(data[0]);
var storageKeys = [];
for (var item = 0; item < data[1].length; item++) {
storageKeys.push(ethereumjs_util_1.bufferToHex(data[1][item]));
}
var jsonItem = {
address: address,
storageKeys: storageKeys,
};
json.push(jsonItem);
}
_this.AccessListJSON = json;
}
// Populate the access list fields
var accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);
_this.accessList = accessListData.accessList;
_this.AccessListJSON = accessListData.AccessListJSON;
// Verify the access list format.
util_1.AccessLists.verifyAccessList(_this.accessList);
_this.chainId = chainId ? new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId)) : _this.common.chainIdBN();
_this.accessList = usedAccessList;
_this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice === '' ? '0x' : gasPrice));
_this._validateCannotExceedMaxInteger({ gasPrice: _this.gasPrice });
if (!_this.chainId.eq(_this.common.chainIdBN())) {

@@ -121,19 +95,2 @@ throw new Error('The chain ID does not match the chain ID of Common');

}
// Verify the access list format.
for (var key = 0; key < _this.accessList.length; key++) {
var accessListItem = _this.accessList[key];
var address = accessListItem[0];
var storageSlots = accessListItem[1];
if (accessListItem[2] !== undefined) {
throw new Error('Access list item cannot have 3 elements. It can only have an address, and an array of storage slots.');
}
if (address.length != 20) {
throw new Error('Invalid EIP-2930 transaction: address length should be 20 bytes');
}
for (var storageSlot = 0; storageSlot < storageSlots.length; storageSlot++) {
if (storageSlots[storageSlot].length != 32) {
throw new Error('Invalid EIP-2930 transaction: storage slot length should be 32 bytes');
}
}
}
var freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;

@@ -189,4 +146,6 @@ if (freeze) {

if (opts === void 0) { opts = {}; }
if (serialized[0] !== 1) {
throw new Error("Invalid serialized tx input: not an EIP-2930 transaction (wrong tx type, expected: 1, received: " + serialized[0]);
if (!serialized.slice(0, 1).equals(TRANSACTION_TYPE_BUFFER)) {
throw new Error("Invalid serialized tx input: not an EIP-2930 transaction (wrong tx type, expected: " + TRANSACTION_TYPE + ", received: " + serialized
.slice(0, 1)
.toString('hex'));
}

@@ -224,2 +183,3 @@ var values = ethereumjs_util_1.rlp.decode(serialized.slice(1));

var _a = __read(values, 11), chainId = _a[0], nonce = _a[1], gasPrice = _a[2], gasLimit = _a[3], to = _a[4], value = _a[5], data = _a[6], accessList = _a[7], v = _a[8], r = _a[9], s = _a[10];
var emptyAccessList = [];
return new AccessListEIP2930Transaction({

@@ -244,15 +204,12 @@ chainId: new ethereumjs_util_1.BN(chainId),

var cost = _super.prototype.getDataFee.call(this);
var accessListStorageKeyCost = this.common.param('gasPrices', 'accessListStorageKeyCost');
var accessListAddressCost = this.common.param('gasPrices', 'accessListAddressCost');
var slots = 0;
for (var index = 0; index < this.accessList.length; index++) {
var item = this.accessList[index];
var storageSlots = item[1];
slots += storageSlots.length;
}
var addresses = this.accessList.length;
cost.iaddn(addresses * accessListAddressCost + slots * accessListStorageKeyCost);
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
return cost;
};
/**
* The up front amount that an account must have for this transaction to be valid
*/
AccessListEIP2930Transaction.prototype.getUpfrontCost = function () {
return this.gasLimit.mul(this.gasPrice).add(this.value);
};
/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.

@@ -282,8 +239,13 @@ *

var base = this.raw();
return Buffer.concat([Buffer.from('01', 'hex'), ethereumjs_util_1.rlp.encode(base)]);
return Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
};
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
*
* @param hashMessage - Return hashed message if set to true (default: true)
*/
AccessListEIP2930Transaction.prototype.getMessageToSign = function (hashMessage) {
if (hashMessage === void 0) { hashMessage = true; }
var base = this.raw().slice(0, 8);
var message = Buffer.concat([Buffer.from('01', 'hex'), ethereumjs_util_1.rlp.encode(base)]);
var message = Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
if (hashMessage) {

@@ -320,4 +282,4 @@ return ethereumjs_util_1.keccak256(message);

var msgHash = this.getMessageToVerifySignature();
// All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// TODO: verify if this is the case for EIP-2930
// EIP-2: All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// Reasoning: https://ethereum.stackexchange.com/a/55728
if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {

@@ -327,5 +289,2 @@ throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');

var _b = this, yParity = _b.yParity, r = _b.r, s = _b.s;
if (yParity === undefined || !r || !s) {
throw new Error('Missing values to derive sender public key from signed tx');
}
try {

@@ -361,16 +320,3 @@ return ethereumjs_util_1.ecrecover(msgHash, yParity.addn(27), // Recover the 27 which was stripped from ecsign

AccessListEIP2930Transaction.prototype.toJSON = function () {
var accessListJSON = [];
for (var index = 0; index < this.accessList.length; index++) {
var item = this.accessList[index];
var JSONItem = {
address: '0x' + ethereumjs_util_1.setLengthLeft(item[0], 20).toString('hex'),
storageKeys: [],
};
var storageSlots = item[1];
for (var slot = 0; slot < storageSlots.length; slot++) {
var storageSlot = storageSlots[slot];
JSONItem.storageKeys.push('0x' + ethereumjs_util_1.setLengthLeft(storageSlot, 32).toString('hex'));
}
accessListJSON.push(JSONItem);
}
var accessListJSON = util_1.AccessLists.getAccessListJSON(this.accessList);
return {

@@ -385,2 +331,5 @@ chainId: ethereumjs_util_1.bnToHex(this.chainId),

accessList: accessListJSON,
v: this.v !== undefined ? ethereumjs_util_1.bnToHex(this.v) : undefined,
r: this.r !== undefined ? ethereumjs_util_1.bnToHex(this.r) : undefined,
s: this.s !== undefined ? ethereumjs_util_1.bnToHex(this.s) : undefined,
};

@@ -387,0 +336,0 @@ };

export { default as Transaction } from './legacyTransaction';
export { default as AccessListEIP2930Transaction } from './eip2930Transaction';
export { default as TransactionFactory } from './transactionFactory';
export { default as FeeMarketEIP1559Transaction } from './eip1559Transaction';
export * from './types';

@@ -19,3 +19,5 @@ "use strict";

Object.defineProperty(exports, "TransactionFactory", { enumerable: true, get: function () { return transactionFactory_1.default; } });
var eip1559Transaction_1 = require("./eip1559Transaction");
Object.defineProperty(exports, "FeeMarketEIP1559Transaction", { enumerable: true, get: function () { return eip1559Transaction_1.default; } });
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

@@ -0,3 +1,5 @@

/// <reference types="bn.js" />
/// <reference types="node" />
import { TxOptions, TxData, JsonTx } from './types';
import { BN } from 'ethereumjs-util';
import { TxOptions, TxData, JsonTx, TxValuesArray } from './types';
import { BaseTransaction } from './baseTransaction';

@@ -8,2 +10,3 @@ /**

export default class Transaction extends BaseTransaction<Transaction> {
readonly gasPrice: BN;
/**

@@ -31,3 +34,3 @@ * Instantiate a transaction from a data dictionary

*/
static fromValuesArray(values: Buffer[], opts?: TxOptions): Transaction;
static fromValuesArray(values: TxValuesArray, opts?: TxOptions): Transaction;
/**

@@ -44,3 +47,3 @@ * This constructor takes the values, validates them, assigns them and freezes the object.

*/
raw(): Buffer[];
raw(): TxValuesArray;
/**

@@ -60,2 +63,6 @@ * Returns the rlp encoding of the transaction.

/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost(): BN;
/**
* Computes a sha3-256 hash of the serialized tx

@@ -62,0 +69,0 @@ */

@@ -15,2 +15,13 @@ "use strict";

})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {

@@ -36,2 +47,3 @@ var m = typeof Symbol === "function" && o[Symbol.iterator];

var baseTransaction_1 = require("./baseTransaction");
var TRANSACTION_TYPE = 0;
/**

@@ -52,4 +64,5 @@ * An Ethereum non-typed (legacy) transaction

var _a;
var _this = _super.call(this, txData, opts) || this;
_this._validateCannotExceedMaxInteger({ r: _this.r, s: _this.s });
var _this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE }), opts) || this;
_this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(txData.gasPrice === '' ? '0x' : txData.gasPrice));
_this._validateCannotExceedMaxInteger({ gasPrice: _this.gasPrice });
_this._validateTxV(_this.v);

@@ -169,2 +182,8 @@ var freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;

/**
* The up front amount that an account must have for this transaction to be valid
*/
Transaction.prototype.getUpfrontCost = function () {
return this.gasLimit.mul(this.gasPrice).add(this.value);
};
/**
* Computes a sha3-256 hash of the serialized tx

@@ -189,3 +208,4 @@ */

var msgHash = this.getMessageToVerifySignature();
// All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// EIP-2: All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// Reasoning: https://ethereum.stackexchange.com/a/55728
if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {

@@ -195,5 +215,2 @@ throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');

var _b = this, v = _b.v, r = _b.r, s = _b.s;
if (!v || !r || !s) {
throw new Error('Missing values to derive sender public key from signed tx');
}
try {

@@ -200,0 +217,0 @@ return ethereumjs_util_1.ecrecover(msgHash, v, ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s), this._signedTxImplementsEIP155() ? this.common.chainIdBN() : undefined);

/// <reference types="node" />
import Common from '@ethereumjs/common';
import { default as Transaction } from './legacyTransaction';
import { default as AccessListEIP2930Transaction } from './eip2930Transaction';
import { TxOptions, TypedTransaction, TxData, AccessListEIP2930TxData } from './types';
import { TxOptions, TypedTransaction, TxData, AccessListEIP2930TxData, FeeMarketEIP1559TxData } from './types';
import { Transaction, AccessListEIP2930Transaction, FeeMarketEIP1559Transaction } from '.';
export default class TransactionFactory {

@@ -14,3 +13,3 @@ private constructor();

*/
static fromTxData(txData: TxData | AccessListEIP2930TxData, txOptions?: TxOptions): TypedTransaction;
static fromTxData(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, txOptions?: TxOptions): TypedTransaction;
/**

@@ -36,7 +35,7 @@ * This method tries to decode serialized data.

* If transactionID is undefined, returns the legacy transaction class.
*
* @deprecated - This method is deprecated and will be removed on the next major release
* @param transactionID
* @param common
*/
static getTransactionClass(transactionID?: number, common?: Common): typeof Transaction | typeof AccessListEIP2930Transaction;
static getTransactionClass(transactionID?: number, common?: Common): typeof Transaction | typeof AccessListEIP2930Transaction | typeof FeeMarketEIP1559Transaction;
}

@@ -8,4 +8,3 @@ "use strict";

var common_1 = __importDefault(require("@ethereumjs/common"));
var legacyTransaction_1 = __importDefault(require("./legacyTransaction"));
var eip2930Transaction_1 = __importDefault(require("./eip2930Transaction"));
var _1 = require(".");
var DEFAULT_COMMON = new common_1.default({ chain: 'mainnet' });

@@ -23,12 +22,21 @@ var TransactionFactory = /** @class */ (function () {

TransactionFactory.fromTxData = function (txData, txOptions) {
var _a;
if (txOptions === void 0) { txOptions = {}; }
var common = (_a = txOptions.common) !== null && _a !== void 0 ? _a : DEFAULT_COMMON;
if (!('type' in txData) || txData.type === undefined) {
// Assume legacy transaction
return legacyTransaction_1.default.fromTxData(txData, txOptions);
return _1.Transaction.fromTxData(txData, txOptions);
}
else {
var txType = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(txData.type)).toNumber();
return TransactionFactory.getTransactionClass(txType, common).fromTxData(txData, txOptions);
if (txType === 0) {
return _1.Transaction.fromTxData(txData, txOptions);
}
else if (txType === 1) {
return _1.AccessListEIP2930Transaction.fromTxData(txData, txOptions);
}
else if (txType === 2) {
return _1.FeeMarketEIP1559Transaction.fromTxData(txData, txOptions);
}
else {
throw new Error("Tx instantiation with type " + txType + " not supported");
}
}

@@ -57,2 +65,5 @@ };

break;
case 2:
EIP = 1559;
break;
default:

@@ -64,6 +75,12 @@ throw new Error("TypedTransaction with ID " + data[0] + " unknown");

}
return eip2930Transaction_1.default.fromSerializedTx(data, txOptions);
if (EIP === 1559) {
return _1.FeeMarketEIP1559Transaction.fromSerializedTx(data, txOptions);
}
else {
// EIP === 2930
return _1.AccessListEIP2930Transaction.fromSerializedTx(data, txOptions);
}
}
else {
return legacyTransaction_1.default.fromSerializedTx(data, txOptions);
return _1.Transaction.fromSerializedTx(data, txOptions);
}

@@ -87,3 +104,3 @@ };

// It is a legacy transaction
return legacyTransaction_1.default.fromValuesArray(data, txOptions);
return _1.Transaction.fromValuesArray(data, txOptions);
}

@@ -97,3 +114,3 @@ else {

* If transactionID is undefined, returns the legacy transaction class.
*
* @deprecated - This method is deprecated and will be removed on the next major release
* @param transactionID

@@ -112,7 +129,9 @@ * @param common

if (legacyTxn) {
return legacyTransaction_1.default;
return _1.Transaction;
}
switch (transactionID) {
case 1:
return eip2930Transaction_1.default;
return _1.AccessListEIP2930Transaction;
case 2:
return _1.FeeMarketEIP1559Transaction;
default:

@@ -119,0 +138,0 @@ throw new Error("TypedTransaction with ID " + transactionID + " unknown");

@@ -7,2 +7,3 @@ /// <reference types="node" />

import { default as AccessListEIP2930Transaction } from './eip2930Transaction';
import { default as FeeMarketEIP1559Transaction } from './eip1559Transaction';
/**

@@ -44,3 +45,12 @@ * The options for initializing a Transaction.

export declare function isAccessList(input: AccessListBuffer | AccessList): input is AccessList;
export declare type TypedTransaction = Transaction | AccessListEIP2930Transaction;
/**
* Encompassing type for all transaction types.
*
* Note that this also includes legacy txs which are
* referenced as `Transaction` for compatibility reasons.
*/
export declare type TypedTransaction = Transaction | AccessListEIP2930Transaction | FeeMarketEIP1559Transaction;
/**
* Legacy Transaction Data
*/
export declare type TxData = {

@@ -83,5 +93,9 @@ /**

s?: BNLike;
/**
* The transaction type
*/
type?: BNLike;
};
/**
* An object with an optional field with each of the transaction's values.
* Access list EIP2930 tx data.
*/

@@ -97,11 +111,32 @@ export interface AccessListEIP2930TxData extends TxData {

accessList?: AccessListBuffer | AccessList;
}
/**
* Fee marked EIP1559 tx data.
*/
export interface FeeMarketEIP1559TxData extends AccessListEIP2930TxData {
/**
* The transaction type
* The transaction's gas price.
*/
type?: BNLike;
gasPrice?: never;
/**
* The maximum inclusion fee per gas (this fee is given to the miner)
*/
maxPriorityFeePerGas?: BNLike;
/**
* The maximum total fee
*/
maxFeePerGas?: BNLike;
}
/**
* Buffer values array for EIP2930 transaction
* Buffer values array for a legacy transaction
*/
export declare type TxValuesArray = Buffer[];
/**
* Buffer values array for an EIP2930 transaction
*/
export declare type AccessListEIP2930ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];
/**
* Buffer values array for an EIP1559 transaction
*/
export declare type FeeMarketEIP1559ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];
declare type JsonAccessListItem = {

@@ -112,3 +147,8 @@ address: string;

/**
* An object with all of the transaction's values represented as strings.
* Generic interface for all tx types with a
* JSON representation of a transaction.
*
* Note that all values are marked as optional
* and not all the values are present on all tx types
* (an EIP1559 tx e.g. lacks a `gasPrice`).
*/

@@ -128,2 +168,4 @@ export interface JsonTx {

type?: string;
maxPriorityFeePerGas?: string;
maxFeePerGas?: string;
}

@@ -130,0 +172,0 @@ /**

@@ -5,3 +5,3 @@ /// <reference types="bn.js" />

import { Address, BN } from 'ethereumjs-util';
import { TxData, TxOptions, JsonTx, AccessListEIP2930ValuesArray, AccessListEIP2930TxData } from './types';
import { TxData, TxOptions, JsonTx, AccessListEIP2930ValuesArray, AccessListEIP2930TxData, FeeMarketEIP1559ValuesArray, FeeMarketEIP1559TxData, TxValuesArray } from './types';
/**

@@ -18,3 +18,2 @@ * This base class will likely be subject to further

readonly gasLimit: BN;
readonly gasPrice: BN;
readonly to?: Address;

@@ -27,3 +26,3 @@ readonly value: BN;

readonly s?: BN;
constructor(txData: TxData | AccessListEIP2930TxData, txOptions?: TxOptions);
constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, txOptions?: TxOptions);
/**

@@ -55,3 +54,3 @@ * Returns the transaction type

*/
getUpfrontCost(): BN;
abstract getUpfrontCost(): BN;
/**

@@ -64,3 +63,3 @@ * If the tx's `to` is to the creation address

*/
abstract raw(): Buffer[] | AccessListEIP2930ValuesArray;
abstract raw(): TxValuesArray | AccessListEIP2930ValuesArray | FeeMarketEIP1559ValuesArray;
/**

@@ -75,3 +74,3 @@ * Returns the encoding of the transaction.

*/
abstract getMessageToSign(hashMessage: false): Buffer[];
abstract getMessageToSign(hashMessage: false): Buffer | Buffer[];
abstract getMessageToSign(hashMessage?: true): Buffer;

@@ -78,0 +77,0 @@ abstract hash(): Buffer;

@@ -19,10 +19,4 @@ "use strict";

var _a, _b;
const { nonce, gasLimit, gasPrice, to, value, data, v, r, s } = txData;
const type = txData.type;
if (type !== undefined) {
this._type = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(type)).toNumber();
}
else {
this._type = 0;
}
const { nonce, gasLimit, to, value, data, v, r, s, type } = txData;
this._type = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(type)).toNumber();
const toB = ethereumjs_util_1.toBuffer(to === '' ? '0x' : to);

@@ -33,3 +27,2 @@ const vB = ethereumjs_util_1.toBuffer(v === '' ? '0x' : v);

this.nonce = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(nonce === '' ? '0x' : nonce));
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice === '' ? '0x' : gasPrice));
this.gasLimit = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasLimit === '' ? '0x' : gasLimit));

@@ -44,5 +37,6 @@ this.to = toB.length > 0 ? new ethereumjs_util_1.Address(toB) : undefined;

nonce: this.nonce,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
value: this.value,
r: this.r,
s: this.s,
});

@@ -96,8 +90,2 @@ this.common = (_b = (_a = txOptions.common) === null || _a === void 0 ? void 0 : _a.copy()) !== null && _b !== void 0 ? _b : new common_1.default({ chain: 'mainnet' });

/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost() {
return this.gasLimit.mul(this.gasPrice).add(this.value);
}
/**
* If the tx's `to` is to the creation address

@@ -110,3 +98,18 @@ */

const { v, r, s } = this;
return !!v && !!r && !!s;
if (this.type === 0) {
if (!v || !r || !s) {
return false;
}
else {
return true;
}
}
else {
if (v === undefined || !r || !s) {
return false;
}
else {
return true;
}
}
}

@@ -113,0 +116,0 @@ /**

@@ -16,2 +16,3 @@ /// <reference types="bn.js" />

readonly AccessListJSON: AccessList;
readonly gasPrice: BN;
/**

@@ -69,2 +70,6 @@ * EIP-2930 alias for `r`

/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost(): BN;
/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.

@@ -84,4 +89,3 @@ *

*/
getMessageToSign(hashMessage: false): Buffer[];
getMessageToSign(hashMessage?: true): Buffer;
getMessageToSign(hashMessage?: boolean): Buffer;
/**

@@ -88,0 +92,0 @@ * Computes a sha3-256 hash of the serialized tx

@@ -6,3 +6,5 @@ "use strict";

const types_1 = require("./types");
const emptyAccessList = [];
const util_1 = require("./util");
const TRANSACTION_TYPE = 1;
const TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex');
/**

@@ -24,4 +26,4 @@ * Typed transaction with optional access lists

var _a, _b;
const { chainId, accessList } = txData;
super(Object.assign(Object.assign({}, txData), { type: 1 }), opts);
const { chainId, accessList, gasPrice } = txData;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
// EIP-2718 check is done in Common

@@ -31,39 +33,11 @@ if (!this.common.isActivatedEIP(2930)) {

}
// check the type of AccessList. If it's a JSON-type, we have to convert it to a Buffer.
let usedAccessList;
if (accessList && types_1.isAccessList(accessList)) {
this.AccessListJSON = accessList;
const newAccessList = [];
for (let i = 0; i < accessList.length; i++) {
const item = accessList[i];
const addressBuffer = ethereumjs_util_1.toBuffer(item.address);
const storageItems = [];
for (let index = 0; index < item.storageKeys.length; index++) {
storageItems.push(ethereumjs_util_1.toBuffer(item.storageKeys[index]));
}
newAccessList.push([addressBuffer, storageItems]);
}
usedAccessList = newAccessList;
}
else {
usedAccessList = accessList !== null && accessList !== void 0 ? accessList : [];
// build the JSON
const json = [];
for (let i = 0; i < usedAccessList.length; i++) {
const data = usedAccessList[i];
const address = ethereumjs_util_1.bufferToHex(data[0]);
const storageKeys = [];
for (let item = 0; item < data[1].length; item++) {
storageKeys.push(ethereumjs_util_1.bufferToHex(data[1][item]));
}
const jsonItem = {
address,
storageKeys,
};
json.push(jsonItem);
}
this.AccessListJSON = json;
}
// Populate the access list fields
const accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);
this.accessList = accessListData.accessList;
this.AccessListJSON = accessListData.AccessListJSON;
// Verify the access list format.
util_1.AccessLists.verifyAccessList(this.accessList);
this.chainId = chainId ? new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId)) : this.common.chainIdBN();
this.accessList = usedAccessList;
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice === '' ? '0x' : gasPrice));
this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice });
if (!this.chainId.eq(this.common.chainIdBN())) {

@@ -78,19 +52,2 @@ throw new Error('The chain ID does not match the chain ID of Common');

}
// Verify the access list format.
for (let key = 0; key < this.accessList.length; key++) {
const accessListItem = this.accessList[key];
const address = accessListItem[0];
const storageSlots = accessListItem[1];
if (accessListItem[2] !== undefined) {
throw new Error('Access list item cannot have 3 elements. It can only have an address, and an array of storage slots.');
}
if (address.length != 20) {
throw new Error('Invalid EIP-2930 transaction: address length should be 20 bytes');
}
for (let storageSlot = 0; storageSlot < storageSlots.length; storageSlot++) {
if (storageSlots[storageSlot].length != 32) {
throw new Error('Invalid EIP-2930 transaction: storage slot length should be 32 bytes');
}
}
}
const freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;

@@ -131,4 +88,6 @@ if (freeze) {

static fromSerializedTx(serialized, opts = {}) {
if (serialized[0] !== 1) {
throw new Error(`Invalid serialized tx input: not an EIP-2930 transaction (wrong tx type, expected: 1, received: ${serialized[0]}`);
if (!serialized.slice(0, 1).equals(TRANSACTION_TYPE_BUFFER)) {
throw new Error(`Invalid serialized tx input: not an EIP-2930 transaction (wrong tx type, expected: ${TRANSACTION_TYPE}, received: ${serialized
.slice(0, 1)
.toString('hex')}`);
}

@@ -164,2 +123,3 @@ const values = ethereumjs_util_1.rlp.decode(serialized.slice(1));

const [chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, v, r, s] = values;
const emptyAccessList = [];
return new AccessListEIP2930Transaction({

@@ -184,15 +144,12 @@ chainId: new ethereumjs_util_1.BN(chainId),

const cost = super.getDataFee();
const accessListStorageKeyCost = this.common.param('gasPrices', 'accessListStorageKeyCost');
const accessListAddressCost = this.common.param('gasPrices', 'accessListAddressCost');
let slots = 0;
for (let index = 0; index < this.accessList.length; index++) {
const item = this.accessList[index];
const storageSlots = item[1];
slots += storageSlots.length;
}
const addresses = this.accessList.length;
cost.iaddn(addresses * accessListAddressCost + slots * accessListStorageKeyCost);
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
return cost;
}
/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost() {
return this.gasLimit.mul(this.gasPrice).add(this.value);
}
/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.

@@ -222,7 +179,12 @@ *

const base = this.raw();
return Buffer.concat([Buffer.from('01', 'hex'), ethereumjs_util_1.rlp.encode(base)]);
return Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
}
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
*
* @param hashMessage - Return hashed message if set to true (default: true)
*/
getMessageToSign(hashMessage = true) {
const base = this.raw().slice(0, 8);
const message = Buffer.concat([Buffer.from('01', 'hex'), ethereumjs_util_1.rlp.encode(base)]);
const message = Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
if (hashMessage) {

@@ -259,4 +221,4 @@ return ethereumjs_util_1.keccak256(message);

const msgHash = this.getMessageToVerifySignature();
// All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// TODO: verify if this is the case for EIP-2930
// EIP-2: All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// Reasoning: https://ethereum.stackexchange.com/a/55728
if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {

@@ -266,5 +228,2 @@ throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');

const { yParity, r, s } = this;
if (yParity === undefined || !r || !s) {
throw new Error('Missing values to derive sender public key from signed tx');
}
try {

@@ -300,16 +259,3 @@ return ethereumjs_util_1.ecrecover(msgHash, yParity.addn(27), // Recover the 27 which was stripped from ecsign

toJSON() {
const accessListJSON = [];
for (let index = 0; index < this.accessList.length; index++) {
const item = this.accessList[index];
const JSONItem = {
address: '0x' + ethereumjs_util_1.setLengthLeft(item[0], 20).toString('hex'),
storageKeys: [],
};
const storageSlots = item[1];
for (let slot = 0; slot < storageSlots.length; slot++) {
const storageSlot = storageSlots[slot];
JSONItem.storageKeys.push('0x' + ethereumjs_util_1.setLengthLeft(storageSlot, 32).toString('hex'));
}
accessListJSON.push(JSONItem);
}
const accessListJSON = util_1.AccessLists.getAccessListJSON(this.accessList);
return {

@@ -324,2 +270,5 @@ chainId: ethereumjs_util_1.bnToHex(this.chainId),

accessList: accessListJSON,
v: this.v !== undefined ? ethereumjs_util_1.bnToHex(this.v) : undefined,
r: this.r !== undefined ? ethereumjs_util_1.bnToHex(this.r) : undefined,
s: this.s !== undefined ? ethereumjs_util_1.bnToHex(this.s) : undefined,
};

@@ -326,0 +275,0 @@ }

export { default as Transaction } from './legacyTransaction';
export { default as AccessListEIP2930Transaction } from './eip2930Transaction';
export { default as TransactionFactory } from './transactionFactory';
export { default as FeeMarketEIP1559Transaction } from './eip1559Transaction';
export * from './types';

@@ -19,3 +19,5 @@ "use strict";

Object.defineProperty(exports, "TransactionFactory", { enumerable: true, get: function () { return transactionFactory_1.default; } });
var eip1559Transaction_1 = require("./eip1559Transaction");
Object.defineProperty(exports, "FeeMarketEIP1559Transaction", { enumerable: true, get: function () { return eip1559Transaction_1.default; } });
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

@@ -0,3 +1,5 @@

/// <reference types="bn.js" />
/// <reference types="node" />
import { TxOptions, TxData, JsonTx } from './types';
import { BN } from 'ethereumjs-util';
import { TxOptions, TxData, JsonTx, TxValuesArray } from './types';
import { BaseTransaction } from './baseTransaction';

@@ -8,2 +10,3 @@ /**

export default class Transaction extends BaseTransaction<Transaction> {
readonly gasPrice: BN;
/**

@@ -31,3 +34,3 @@ * Instantiate a transaction from a data dictionary

*/
static fromValuesArray(values: Buffer[], opts?: TxOptions): Transaction;
static fromValuesArray(values: TxValuesArray, opts?: TxOptions): Transaction;
/**

@@ -44,3 +47,3 @@ * This constructor takes the values, validates them, assigns them and freezes the object.

*/
raw(): Buffer[];
raw(): TxValuesArray;
/**

@@ -60,2 +63,6 @@ * Returns the rlp encoding of the transaction.

/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost(): BN;
/**
* Computes a sha3-256 hash of the serialized tx

@@ -62,0 +69,0 @@ */

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

const baseTransaction_1 = require("./baseTransaction");
const TRANSACTION_TYPE = 0;
/**

@@ -12,2 +13,20 @@ * An Ethereum non-typed (legacy) transaction

/**
* This constructor takes the values, validates them, assigns them and freezes the object.
*
* It is not recommended to use this constructor directly. Instead use
* the static factory methods to assist in creating a Transaction object from
* varying data types.
*/
constructor(txData, opts = {}) {
var _a;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(txData.gasPrice === '' ? '0x' : txData.gasPrice));
this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice });
this._validateTxV(this.v);
const freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;
if (freeze) {
Object.freeze(this);
}
}
/**
* Instantiate a transaction from a data dictionary

@@ -64,19 +83,2 @@ */

/**
* This constructor takes the values, validates them, assigns them and freezes the object.
*
* It is not recommended to use this constructor directly. Instead use
* the static factory methods to assist in creating a Transaction object from
* varying data types.
*/
constructor(txData, opts = {}) {
var _a;
super(txData, opts);
this._validateCannotExceedMaxInteger({ r: this.r, s: this.s });
this._validateTxV(this.v);
const freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;
if (freeze) {
Object.freeze(this);
}
}
/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.

@@ -132,2 +134,8 @@ */

/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost() {
return this.gasLimit.mul(this.gasPrice).add(this.value);
}
/**
* Computes a sha3-256 hash of the serialized tx

@@ -152,3 +160,4 @@ */

const msgHash = this.getMessageToVerifySignature();
// All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// EIP-2: All transaction signatures whose s-value is greater than secp256k1n/2 are considered invalid.
// Reasoning: https://ethereum.stackexchange.com/a/55728
if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {

@@ -158,5 +167,2 @@ throw new Error('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');

const { v, r, s } = this;
if (!v || !r || !s) {
throw new Error('Missing values to derive sender public key from signed tx');
}
try {

@@ -163,0 +169,0 @@ return ethereumjs_util_1.ecrecover(msgHash, v, ethereumjs_util_1.bnToRlp(r), ethereumjs_util_1.bnToRlp(s), this._signedTxImplementsEIP155() ? this.common.chainIdBN() : undefined);

/// <reference types="node" />
import Common from '@ethereumjs/common';
import { default as Transaction } from './legacyTransaction';
import { default as AccessListEIP2930Transaction } from './eip2930Transaction';
import { TxOptions, TypedTransaction, TxData, AccessListEIP2930TxData } from './types';
import { TxOptions, TypedTransaction, TxData, AccessListEIP2930TxData, FeeMarketEIP1559TxData } from './types';
import { Transaction, AccessListEIP2930Transaction, FeeMarketEIP1559Transaction } from '.';
export default class TransactionFactory {

@@ -14,3 +13,3 @@ private constructor();

*/
static fromTxData(txData: TxData | AccessListEIP2930TxData, txOptions?: TxOptions): TypedTransaction;
static fromTxData(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, txOptions?: TxOptions): TypedTransaction;
/**

@@ -36,7 +35,7 @@ * This method tries to decode serialized data.

* If transactionID is undefined, returns the legacy transaction class.
*
* @deprecated - This method is deprecated and will be removed on the next major release
* @param transactionID
* @param common
*/
static getTransactionClass(transactionID?: number, common?: Common): typeof Transaction | typeof AccessListEIP2930Transaction;
static getTransactionClass(transactionID?: number, common?: Common): typeof Transaction | typeof AccessListEIP2930Transaction | typeof FeeMarketEIP1559Transaction;
}

@@ -8,4 +8,3 @@ "use strict";

const common_1 = __importDefault(require("@ethereumjs/common"));
const legacyTransaction_1 = __importDefault(require("./legacyTransaction"));
const eip2930Transaction_1 = __importDefault(require("./eip2930Transaction"));
const _1 = require(".");
const DEFAULT_COMMON = new common_1.default({ chain: 'mainnet' });

@@ -22,11 +21,20 @@ class TransactionFactory {

static fromTxData(txData, txOptions = {}) {
var _a;
const common = (_a = txOptions.common) !== null && _a !== void 0 ? _a : DEFAULT_COMMON;
if (!('type' in txData) || txData.type === undefined) {
// Assume legacy transaction
return legacyTransaction_1.default.fromTxData(txData, txOptions);
return _1.Transaction.fromTxData(txData, txOptions);
}
else {
const txType = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(txData.type)).toNumber();
return TransactionFactory.getTransactionClass(txType, common).fromTxData(txData, txOptions);
if (txType === 0) {
return _1.Transaction.fromTxData(txData, txOptions);
}
else if (txType === 1) {
return _1.AccessListEIP2930Transaction.fromTxData(txData, txOptions);
}
else if (txType === 2) {
return _1.FeeMarketEIP1559Transaction.fromTxData(txData, txOptions);
}
else {
throw new Error(`Tx instantiation with type ${txType} not supported`);
}
}

@@ -54,2 +62,5 @@ }

break;
case 2:
EIP = 1559;
break;
default:

@@ -61,6 +72,12 @@ throw new Error(`TypedTransaction with ID ${data[0]} unknown`);

}
return eip2930Transaction_1.default.fromSerializedTx(data, txOptions);
if (EIP === 1559) {
return _1.FeeMarketEIP1559Transaction.fromSerializedTx(data, txOptions);
}
else {
// EIP === 2930
return _1.AccessListEIP2930Transaction.fromSerializedTx(data, txOptions);
}
}
else {
return legacyTransaction_1.default.fromSerializedTx(data, txOptions);
return _1.Transaction.fromSerializedTx(data, txOptions);
}

@@ -83,3 +100,3 @@ }

// It is a legacy transaction
return legacyTransaction_1.default.fromValuesArray(data, txOptions);
return _1.Transaction.fromValuesArray(data, txOptions);
}

@@ -93,3 +110,3 @@ else {

* If transactionID is undefined, returns the legacy transaction class.
*
* @deprecated - This method is deprecated and will be removed on the next major release
* @param transactionID

@@ -107,7 +124,9 @@ * @param common

if (legacyTxn) {
return legacyTransaction_1.default;
return _1.Transaction;
}
switch (transactionID) {
case 1:
return eip2930Transaction_1.default;
return _1.AccessListEIP2930Transaction;
case 2:
return _1.FeeMarketEIP1559Transaction;
default:

@@ -114,0 +133,0 @@ throw new Error(`TypedTransaction with ID ${transactionID} unknown`);

@@ -7,2 +7,3 @@ /// <reference types="node" />

import { default as AccessListEIP2930Transaction } from './eip2930Transaction';
import { default as FeeMarketEIP1559Transaction } from './eip1559Transaction';
/**

@@ -44,3 +45,12 @@ * The options for initializing a Transaction.

export declare function isAccessList(input: AccessListBuffer | AccessList): input is AccessList;
export declare type TypedTransaction = Transaction | AccessListEIP2930Transaction;
/**
* Encompassing type for all transaction types.
*
* Note that this also includes legacy txs which are
* referenced as `Transaction` for compatibility reasons.
*/
export declare type TypedTransaction = Transaction | AccessListEIP2930Transaction | FeeMarketEIP1559Transaction;
/**
* Legacy Transaction Data
*/
export declare type TxData = {

@@ -83,5 +93,9 @@ /**

s?: BNLike;
/**
* The transaction type
*/
type?: BNLike;
};
/**
* An object with an optional field with each of the transaction's values.
* Access list EIP2930 tx data.
*/

@@ -97,11 +111,32 @@ export interface AccessListEIP2930TxData extends TxData {

accessList?: AccessListBuffer | AccessList;
}
/**
* Fee marked EIP1559 tx data.
*/
export interface FeeMarketEIP1559TxData extends AccessListEIP2930TxData {
/**
* The transaction type
* The transaction's gas price.
*/
type?: BNLike;
gasPrice?: never;
/**
* The maximum inclusion fee per gas (this fee is given to the miner)
*/
maxPriorityFeePerGas?: BNLike;
/**
* The maximum total fee
*/
maxFeePerGas?: BNLike;
}
/**
* Buffer values array for EIP2930 transaction
* Buffer values array for a legacy transaction
*/
export declare type TxValuesArray = Buffer[];
/**
* Buffer values array for an EIP2930 transaction
*/
export declare type AccessListEIP2930ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];
/**
* Buffer values array for an EIP1559 transaction
*/
export declare type FeeMarketEIP1559ValuesArray = [Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, Buffer, AccessListBuffer, Buffer?, Buffer?, Buffer?];
declare type JsonAccessListItem = {

@@ -112,3 +147,8 @@ address: string;

/**
* An object with all of the transaction's values represented as strings.
* Generic interface for all tx types with a
* JSON representation of a transaction.
*
* Note that all values are marked as optional
* and not all the values are present on all tx types
* (an EIP1559 tx e.g. lacks a `gasPrice`).
*/

@@ -128,2 +168,4 @@ export interface JsonTx {

type?: string;
maxPriorityFeePerGas?: string;
maxFeePerGas?: string;
}

@@ -130,0 +172,0 @@ /**

{
"name": "@ethereumjs/tx",
"version": "3.1.4",
"version": "3.2.0",
"description": "A simple module for creating, manipulating and signing Ethereum transactions",

@@ -35,3 +35,3 @@ "license": "MPL-2.0",

"dependencies": {
"@ethereumjs/common": "^2.2.0",
"@ethereumjs/common": "^2.3.0",
"ethereumjs-util": "^7.0.10"

@@ -38,0 +38,0 @@ },

@@ -36,2 +36,3 @@ # @ethereumjs/tx

- `FeeMarketEIP1559Transaction` ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559), gas fee market)
- `AccessListEIP2930Transaction` ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930), optional access lists)

@@ -42,2 +43,35 @@ - `Transaction`, the Ethereum standard tx up to `berlin`, now referred to as legacy txs with the introduction of tx types

#### Gas Fee Market Transactions (EIP-1559)
- Class: `FeeMarketEIP1559Transaction`
- Activation: `london`
- Type: `2`
This is the recommended tx type starting with the activation of the `london` HF, see the following code snipped for an example on how to instantiate:
```typescript
import Common from '@ethereumjs/common'
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
const common = new Common({ chain: 'mainnet', hardfork: 'london' })
const txData = {
"data": "0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x02625a00",
"maxPriorityFeePerGas": "0x01",
"maxFeePerGas": "0xff",
"nonce": "0x00",
"to": "0xcccccccccccccccccccccccccccccccccccccccc",
"value": "0x0186a0",
"v": "0x01",
"r": "0xafb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9",
"s": "0x479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64",
"chainId": "0x01",
"accessList": [],
"type": "0x02"
}
const tx = FeeMarketEIP1559Transaction.fromTxData(txData, { common })
```
#### Access List Transactions (EIP-2930)

@@ -47,4 +81,5 @@

- Activation: `berlin`
- Type: `1`
This is the recommended tx type starting with the activation of the `berlin` HF, see the following code snipped for an example on how to instantiate:
This transaction type has been introduced along the `berlin` HF. See the following code snipped for an example on how to instantiate:

@@ -83,3 +118,4 @@ ```typescript

A mechanism to generate access lists from tx data based on a certain network state is not part of this library.
For generating access lists from tx data based on a certain network state there is a `reportAccessList` option
on the `Vm.runTx()` method of the `@ethereumjs/vm` `TypeScript` VM implementation.

@@ -90,2 +126,3 @@ ### Legacy Transactions

- Activation: `chainstart` (with modifications along the road, see HF section below)
- Type: `0` (internal)

@@ -177,2 +214,3 @@ Legacy transaction are still valid transaction within Ethereum `mainnet` but will likely be deprecated at some point.

--- | --- | ---
`london` | `v3.2.0` | `EIP-1559` Transactions
`berlin` | `v3.1.0` | `EIP-2718` Typed Transactions, Optional Access Lists Tx Type `EIP-2930`

@@ -179,0 +217,0 @@ `muirGlacier` | `v2.1.2` | -

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc