Socket
Socket
Sign inDemoInstall

@ethereumjs/tx

Package Overview
Dependencies
Maintainers
3
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.5.2 to 4.0.0-beta.1

dist/baseTransaction.d.ts.map

46

dist/baseTransaction.d.ts

@@ -1,5 +0,4 @@

/// <reference types="bn.js" />
/// <reference types="node" />
import Common, { Chain, Hardfork } from '@ethereumjs/common';
import { Address, BN, BNLike } from 'ethereumjs-util';
import { Address, BigIntLike } from '@ethereumjs/util';
import { TxData, JsonTx, AccessListEIP2930ValuesArray, AccessListEIP2930TxData, FeeMarketEIP1559ValuesArray, FeeMarketEIP1559TxData, TxValuesArray, Capability, TxOptions } from './types';

@@ -9,3 +8,3 @@ interface TransactionCache {

dataFee?: {
value: BN;
value: bigint;
hardfork: string | Hardfork;

@@ -23,10 +22,10 @@ };

private readonly _type;
readonly nonce: BN;
readonly gasLimit: BN;
readonly nonce: bigint;
readonly gasLimit: bigint;
readonly to?: Address;
readonly value: BN;
readonly value: bigint;
readonly data: Buffer;
readonly v?: BN;
readonly r?: BN;
readonly s?: BN;
readonly v?: bigint;
readonly r?: bigint;
readonly s?: bigint;
readonly common: Common;

@@ -59,8 +58,2 @@ protected cache: TransactionCache;

/**
* Alias for {@link BaseTransaction.type}
*
* @deprecated Use `type` instead
*/
get transactionType(): number;
/**
* Returns the transaction type.

@@ -95,14 +88,20 @@ *

validate(stringError: true): string[];
protected _validateYParity(): void;
/**
* EIP-2: All transaction signatures whose s-value is greater than secp256k1n/2are considered invalid.
* Reasoning: https://ethereum.stackexchange.com/a/55728
*/
protected _validateHighS(): void;
/**
* The minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
*/
getBaseFee(): BN;
getBaseFee(): bigint;
/**
* The amount of gas paid for the data in this tx
*/
getDataFee(): BN;
getDataFee(): bigint;
/**
* The up front amount that an account must have for this transaction to be valid
*/
abstract getUpfrontCost(): BN;
abstract getUpfrontCost(): bigint;
/**

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

abstract toJSON(): JsonTx;
protected abstract _processSignature(v: number, r: Buffer, s: Buffer): TransactionObject;
protected abstract _processSignature(v: bigint, r: Buffer, s: Buffer): TransactionObject;
/**

@@ -168,6 +167,6 @@ * Does chain ID checks on common and returns a common

*/
protected _getCommon(common?: Common, chainId?: BNLike): Common;
protected _getCommon(common?: Common, chainId?: BigIntLike): Common;
/**
* Validates that an object with BN values cannot exceed the specified bit limit.
* @param values Object containing string keys and BN values
* Validates that an object with BigInt values cannot exceed the specified bit limit.
* @param values Object containing string keys and BigInt values
* @param bits Number of bits to check (64 or 256)

@@ -177,3 +176,3 @@ * @param cannotEqual Pass true if the number also cannot equal one less the maximum value

protected _validateCannotExceedMaxInteger(values: {
[key: string]: BN | undefined;
[key: string]: bigint | undefined;
}, bits?: number, cannotEqual?: boolean): void;

@@ -198,1 +197,2 @@ /**

export {};
//# sourceMappingURL=baseTransaction.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseTransaction = void 0;
const common_1 = __importStar(require("@ethereumjs/common"));
const ethereumjs_util_1 = require("ethereumjs-util");
const common_1 = require("@ethereumjs/common");
const util_1 = require("@ethereumjs/util");
const types_1 = require("./types");

@@ -64,18 +41,18 @@ /**

*/
this.DEFAULT_HARDFORK = common_1.Hardfork.Istanbul;
this.DEFAULT_HARDFORK = common_1.Hardfork.London;
const { nonce, gasLimit, to, value, data, v, r, s, type } = txData;
this._type = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(type)).toNumber();
this._type = Number((0, util_1.bufferToBigInt)((0, util_1.toBuffer)(type)));
this.txOptions = opts;
const toB = (0, ethereumjs_util_1.toBuffer)(to === '' ? '0x' : to);
const vB = (0, ethereumjs_util_1.toBuffer)(v === '' ? '0x' : v);
const rB = (0, ethereumjs_util_1.toBuffer)(r === '' ? '0x' : r);
const sB = (0, ethereumjs_util_1.toBuffer)(s === '' ? '0x' : s);
this.nonce = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(nonce === '' ? '0x' : nonce));
this.gasLimit = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(gasLimit === '' ? '0x' : gasLimit));
this.to = toB.length > 0 ? new ethereumjs_util_1.Address(toB) : undefined;
this.value = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(value === '' ? '0x' : value));
this.data = (0, ethereumjs_util_1.toBuffer)(data === '' ? '0x' : data);
this.v = vB.length > 0 ? new ethereumjs_util_1.BN(vB) : undefined;
this.r = rB.length > 0 ? new ethereumjs_util_1.BN(rB) : undefined;
this.s = sB.length > 0 ? new ethereumjs_util_1.BN(sB) : undefined;
const toB = (0, util_1.toBuffer)(to === '' ? '0x' : to);
const vB = (0, util_1.toBuffer)(v === '' ? '0x' : v);
const rB = (0, util_1.toBuffer)(r === '' ? '0x' : r);
const sB = (0, util_1.toBuffer)(s === '' ? '0x' : s);
this.nonce = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(nonce === '' ? '0x' : nonce));
this.gasLimit = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(gasLimit === '' ? '0x' : gasLimit));
this.to = toB.length > 0 ? new util_1.Address(toB) : undefined;
this.value = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(value === '' ? '0x' : value));
this.data = (0, util_1.toBuffer)(data === '' ? '0x' : data);
this.v = vB.length > 0 ? (0, util_1.bufferToBigInt)(vB) : undefined;
this.r = rB.length > 0 ? (0, util_1.bufferToBigInt)(rB) : undefined;
this.s = sB.length > 0 ? (0, util_1.bufferToBigInt)(sB) : undefined;
this._validateCannotExceedMaxInteger({ value: this.value, r: this.r, s: this.s });

@@ -88,10 +65,2 @@ // geth limits gasLimit to 2^64-1

/**
* Alias for {@link BaseTransaction.type}
*
* @deprecated Use `type` instead
*/
get transactionType() {
return this.type;
}
/**
* Returns the transaction type.

@@ -125,3 +94,3 @@ *

const errors = [];
if (this.getBaseFee().gt(this.gasLimit)) {
if (this.getBaseFee() > this.gasLimit) {
errors.push(`gasLimit is too low. given ${this.gasLimit}, need at least ${this.getBaseFee()}`);

@@ -134,9 +103,32 @@ }

}
_validateYParity() {
const { v } = this;
if (v !== undefined && v !== BigInt(0) && v !== BigInt(1)) {
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1');
throw new Error(msg);
}
}
/**
* EIP-2: All transaction signatures whose s-value is greater than secp256k1n/2are considered invalid.
* Reasoning: https://ethereum.stackexchange.com/a/55728
*/
_validateHighS() {
const { s } = this;
if (this.common.gteHardfork('homestead') && s !== undefined && s > util_1.SECP256K1_ORDER_DIV_2) {
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}
}
/**
* The minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
*/
getBaseFee() {
const fee = this.getDataFee().addn(this.common.param('gasPrices', 'tx'));
const txFee = this.common.param('gasPrices', 'tx');
let fee = this.getDataFee();
if (txFee)
fee += txFee;
if (this.common.gteHardfork('homestead') && this.toCreationAddress()) {
fee.iaddn(this.common.param('gasPrices', 'txCreation'));
const txCreationFee = this.common.param('gasPrices', 'txCreation');
if (txCreationFee)
fee += txCreationFee;
}

@@ -151,11 +143,10 @@ return fee;

const txDataNonZero = this.common.param('gasPrices', 'txDataNonZero');
let cost = 0;
let cost = BigInt(0);
for (let i = 0; i < this.data.length; i++) {
this.data[i] === 0 ? (cost += txDataZero) : (cost += txDataNonZero);
}
cost = new ethereumjs_util_1.BN(cost);
if ((this.to === undefined || this.to === null) && this.common.isActivatedEIP(3860)) {
const dataLength = Math.ceil(this.data.length / 32);
const initCodeCost = new ethereumjs_util_1.BN(this.common.param('gasPrices', 'initCodeWordCost')).imuln(dataLength);
cost.iadd(initCodeCost);
const dataLength = BigInt(Math.ceil(this.data.length / 32));
const initCodeCost = this.common.param('gasPrices', 'initCodeWordCost') * dataLength;
cost += initCodeCost;
}

@@ -172,17 +163,7 @@ return cost;

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

@@ -197,3 +178,3 @@ }

const publicKey = this.getSenderPublicKey();
return (0, ethereumjs_util_1.unpadBuffer)(publicKey).length !== 0;
return (0, util_1.unpadBuffer)(publicKey).length !== 0;
}

@@ -208,3 +189,3 @@ catch (e) {

getSenderAddress() {
return new ethereumjs_util_1.Address((0, ethereumjs_util_1.publicToAddress)(this.getSenderPublicKey()));
return new util_1.Address((0, util_1.publicToAddress)(this.getSenderPublicKey()));
}

@@ -237,3 +218,3 @@ /**

const msgHash = this.getMessageToSign(true);
const { v, r, s } = (0, ethereumjs_util_1.ecsign)(msgHash, privateKey);
const { v, r, s } = (0, util_1.ecsign)(msgHash, privateKey);
const tx = this._processSignature(v, r, s);

@@ -258,8 +239,7 @@ // Hack part 2

_getCommon(common, chainId) {
var _a;
// Chain ID provided
if (chainId) {
const chainIdBN = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(chainId));
const chainIdBigInt = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(chainId));
if (common) {
if (!common.chainIdBN().eq(chainIdBN)) {
if (common.chainId() !== chainIdBigInt) {
const msg = this._errorMsg('The chain ID does not match the chain ID of Common');

@@ -273,6 +253,6 @@ throw new Error(msg);

else {
if (common_1.default.isSupportedChainId(chainIdBN)) {
if (common_1.default.isSupportedChainId(chainIdBigInt)) {
// No Common, chain ID supported by Common
// -> Instantiate Common with chain ID
return new common_1.default({ chain: chainIdBN, hardfork: this.DEFAULT_HARDFORK });
return new common_1.default({ chain: chainIdBigInt, hardfork: this.DEFAULT_HARDFORK });
}

@@ -282,7 +262,7 @@ else {

// -> Instantiate custom Common derived from DEFAULT_CHAIN
return common_1.default.forCustomChain(this.DEFAULT_CHAIN, {
return common_1.default.custom({
name: 'custom-chain',
networkId: chainIdBN,
chainId: chainIdBN,
}, this.DEFAULT_HARDFORK);
networkId: chainIdBigInt,
chainId: chainIdBigInt,
}, { baseChain: this.DEFAULT_CHAIN, hardfork: this.DEFAULT_HARDFORK });
}

@@ -294,8 +274,8 @@ }

// -> return Common provided or create new default Common
return ((_a = common === null || common === void 0 ? void 0 : common.copy()) !== null && _a !== void 0 ? _a : new common_1.default({ chain: this.DEFAULT_CHAIN, hardfork: this.DEFAULT_HARDFORK }));
return (common?.copy() ?? new common_1.default({ chain: this.DEFAULT_CHAIN, hardfork: this.DEFAULT_HARDFORK }));
}
}
/**
* Validates that an object with BN values cannot exceed the specified bit limit.
* @param values Object containing string keys and BN values
* Validates that an object with BigInt values cannot exceed the specified bit limit.
* @param values Object containing string keys and BigInt values
* @param bits Number of bits to check (64 or 256)

@@ -309,3 +289,3 @@ * @param cannotEqual Pass true if the number also cannot equal one less the maximum value

if (cannotEqual) {
if (value === null || value === void 0 ? void 0 : value.gte(ethereumjs_util_1.MAX_UINT64)) {
if (value !== undefined && value >= util_1.MAX_UINT64) {
const msg = this._errorMsg(`${key} cannot equal or exceed MAX_UINT64 (2^64-1), given ${value}`);

@@ -316,3 +296,3 @@ throw new Error(msg);

else {
if (value === null || value === void 0 ? void 0 : value.gt(ethereumjs_util_1.MAX_UINT64)) {
if (value !== undefined && value > util_1.MAX_UINT64) {
const msg = this._errorMsg(`${key} cannot exceed MAX_UINT64 (2^64-1), given ${value}`);

@@ -325,3 +305,3 @@ throw new Error(msg);

if (cannotEqual) {
if (value === null || value === void 0 ? void 0 : value.gte(ethereumjs_util_1.MAX_INTEGER)) {
if (value !== undefined && value >= util_1.MAX_INTEGER) {
const msg = this._errorMsg(`${key} cannot equal or exceed MAX_INTEGER (2^256-1), given ${value}`);

@@ -332,3 +312,3 @@ throw new Error(msg);

else {
if (value === null || value === void 0 ? void 0 : value.gt(ethereumjs_util_1.MAX_INTEGER)) {
if (value !== undefined && value > util_1.MAX_INTEGER) {
const msg = this._errorMsg(`${key} cannot exceed MAX_INTEGER (2^256-1), given ${value}`);

@@ -353,3 +333,3 @@ throw new Error(msg);

try {
hash = this.isSigned() ? (0, ethereumjs_util_1.bufferToHex)(this.hash()) : 'not available (unsigned)';
hash = this.isSigned() ? (0, util_1.bufferToHex)(this.hash()) : 'not available (unsigned)';
}

@@ -356,0 +336,0 @@ catch (e) {

@@ -1,4 +0,2 @@

/// <reference types="bn.js" />
/// <reference types="node" />
import { BN } from 'ethereumjs-util';
import Common from '@ethereumjs/common';

@@ -14,7 +12,7 @@ import { BaseTransaction } from './baseTransaction';

export default class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP1559Transaction> {
readonly chainId: BN;
readonly chainId: bigint;
readonly accessList: AccessListBuffer;
readonly AccessListJSON: AccessList;
readonly maxPriorityFeePerGas: BN;
readonly maxFeePerGas: BN;
readonly maxPriorityFeePerGas: bigint;
readonly maxFeePerGas: bigint;
readonly common: Common;

@@ -29,20 +27,2 @@ /**

/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/
get senderR(): BN | undefined;
/**
* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/
get senderS(): BN | undefined;
/**
* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity(): BN | undefined;
/**
* Instantiate a transaction from a data dictionary.

@@ -66,12 +46,2 @@ *

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link FeeMarketEIP1559Transaction.fromSerializedTx})
*
* Note: This means that the Buffer should start with 0x01.
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link FeeMarketEIP1559Transaction.fromSerializedTx} constructor
*/
static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): FeeMarketEIP1559Transaction;
/**
* Create a transaction from a values array.

@@ -94,3 +64,3 @@ *

*/
getDataFee(): BN;
getDataFee(): bigint;
/**

@@ -100,3 +70,3 @@ * The up front amount that an account must have for this transaction to be valid

*/
getUpfrontCost(baseFee?: BN): BN;
getUpfrontCost(baseFee?: bigint): bigint;
/**

@@ -156,3 +126,3 @@ * Returns a Buffer Array of the raw Buffers of the EIP-1559 transaction, in order.

getSenderPublicKey(): Buffer;
_processSignature(v: number, r: Buffer, s: Buffer): FeeMarketEIP1559Transaction;
_processSignature(v: bigint, r: Buffer, s: Buffer): FeeMarketEIP1559Transaction;
/**

@@ -174,1 +144,2 @@ * Returns an object with the JSON representation of the transaction

}
//# sourceMappingURL=eip1559Transaction.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ethereumjs_util_1 = require("ethereumjs-util");
const keccak_1 = require("ethereum-cryptography/keccak");
const util_1 = require("@ethereumjs/util");
const rlp_1 = require("rlp");
const baseTransaction_1 = require("./baseTransaction");
const types_1 = require("./types");
const util_1 = require("./util");
const util_2 = require("./util");
const TRANSACTION_TYPE = 2;

@@ -24,4 +25,3 @@ const TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex');

constructor(txData, opts = {}) {
var _a, _b;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
super({ ...txData, type: TRANSACTION_TYPE }, opts);
/**

@@ -36,3 +36,3 @@ * The default HF if the tx type is active on that HF

this.common = this._getCommon(opts.common, chainId);
this.chainId = this.common.chainIdBN();
this.chainId = this.common.chainId();
if (!this.common.isActivatedEIP(1559)) {

@@ -43,9 +43,9 @@ throw new Error('EIP-1559 not enabled on Common');

// Populate the access list fields
const accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);
const accessListData = util_2.AccessLists.getAccessListData(accessList ?? []);
this.accessList = accessListData.accessList;
this.AccessListJSON = accessListData.AccessListJSON;
// Verify the access list format.
util_1.AccessLists.verifyAccessList(this.accessList);
this.maxFeePerGas = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(maxFeePerGas === '' ? '0x' : maxFeePerGas));
this.maxPriorityFeePerGas = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(maxPriorityFeePerGas === '' ? '0x' : maxPriorityFeePerGas));
util_2.AccessLists.verifyAccessList(this.accessList);
this.maxFeePerGas = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(maxFeePerGas === '' ? '0x' : maxFeePerGas));
this.maxPriorityFeePerGas = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(maxPriorityFeePerGas === '' ? '0x' : maxPriorityFeePerGas));
this._validateCannotExceedMaxInteger({

@@ -55,22 +55,16 @@ maxFeePerGas: this.maxFeePerGas,

});
if (this.gasLimit.mul(this.maxFeePerGas).gt(ethereumjs_util_1.MAX_INTEGER)) {
if (this.gasLimit * this.maxFeePerGas > util_1.MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)');
throw new Error(msg);
}
if (this.maxFeePerGas.lt(this.maxPriorityFeePerGas)) {
if (this.maxFeePerGas < this.maxPriorityFeePerGas) {
const msg = this._errorMsg('maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)');
throw new Error(msg);
}
if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1');
throw new Error(msg);
}
if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}
this._validateYParity();
this._validateHighS();
if (this.common.isActivatedEIP(3860)) {
(0, util_1.checkMaxInitCodeSize)(this.common, this.data.length);
(0, util_2.checkMaxInitCodeSize)(this.common, this.data.length);
}
const freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;
const freeze = opts?.freeze ?? true;
if (freeze) {

@@ -81,26 +75,2 @@ Object.freeze(this);

/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/
get senderR() {
return this.r;
}
/**
* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/
get senderS() {
return this.s;
}
/**
* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity() {
return this.v;
}
/**
* Instantiate a transaction from a data dictionary.

@@ -130,3 +100,3 @@ *

}
const values = ethereumjs_util_1.rlp.decode(serialized.slice(1));
const values = (0, util_1.arrToBufArr)(rlp_1.default.decode(serialized.slice(1)));
if (!Array.isArray(values)) {

@@ -138,14 +108,2 @@ throw new Error('Invalid serialized tx input: must be array');

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link FeeMarketEIP1559Transaction.fromSerializedTx})
*
* Note: This means that the Buffer should start with 0x01.
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link FeeMarketEIP1559Transaction.fromSerializedTx} constructor
*/
static fromRlpSerializedTx(serialized, opts = {}) {
return FeeMarketEIP1559Transaction.fromSerializedTx(serialized, opts);
}
/**
* Create a transaction from a values array.

@@ -161,5 +119,5 @@ *

const [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, v, r, s,] = values;
(0, ethereumjs_util_1.validateNoLeadingZeroes)({ nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, value, v, r, s });
(0, util_1.validateNoLeadingZeroes)({ nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, value, v, r, s });
return new FeeMarketEIP1559Transaction({
chainId: new ethereumjs_util_1.BN(chainId),
chainId: (0, util_1.bufferToBigInt)(chainId),
nonce,

@@ -172,4 +130,4 @@ maxPriorityFeePerGas,

data,
accessList: accessList !== null && accessList !== void 0 ? accessList : [],
v: v !== undefined ? new ethereumjs_util_1.BN(v) : undefined,
accessList: accessList ?? [],
v: v !== undefined ? (0, util_1.bufferToBigInt)(v) : undefined,
r,

@@ -186,4 +144,4 @@ s,

}
const cost = super.getDataFee();
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
let cost = super.getDataFee();
cost += BigInt(util_2.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
if (Object.isFrozen(this)) {

@@ -201,6 +159,8 @@ this.cache.dataFee = {

*/
getUpfrontCost(baseFee = new ethereumjs_util_1.BN(0)) {
const inclusionFeePerGas = ethereumjs_util_1.BN.min(this.maxPriorityFeePerGas, this.maxFeePerGas.sub(baseFee));
const gasPrice = inclusionFeePerGas.add(baseFee);
return this.gasLimit.mul(gasPrice).add(this.value);
getUpfrontCost(baseFee = BigInt(0)) {
const prio = this.maxPriorityFeePerGas;
const maxBase = this.maxFeePerGas - baseFee;
const inclusionFeePerGas = prio < maxBase ? prio : maxBase;
const gasPrice = inclusionFeePerGas + baseFee;
return this.gasLimit * gasPrice + this.value;
}

@@ -222,14 +182,14 @@ /**

return [
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.chainId),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.nonce),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.maxPriorityFeePerGas),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.maxFeePerGas),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.gasLimit),
(0, util_1.bigIntToUnpaddedBuffer)(this.chainId),
(0, util_1.bigIntToUnpaddedBuffer)(this.nonce),
(0, util_1.bigIntToUnpaddedBuffer)(this.maxPriorityFeePerGas),
(0, util_1.bigIntToUnpaddedBuffer)(this.maxFeePerGas),
(0, util_1.bigIntToUnpaddedBuffer)(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.value),
(0, util_1.bigIntToUnpaddedBuffer)(this.value),
this.data,
this.accessList,
this.v !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.v) : Buffer.from([]),
this.r !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.r) : Buffer.from([]),
this.s !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.s) : Buffer.from([]),
this.v !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.v) : Buffer.from([]),
this.r !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.r) : Buffer.from([]),
this.s !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.s) : Buffer.from([]),
];

@@ -249,3 +209,6 @@ }

const base = this.raw();
return Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
return Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(rlp_1.default.encode((0, util_1.bufArrToArr)(base))),
]);
}

@@ -267,5 +230,8 @@ /**

const base = this.raw().slice(0, 9);
const message = Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
const message = Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(rlp_1.default.encode((0, util_1.bufArrToArr)(base))),
]);
if (hashMessage) {
return (0, ethereumjs_util_1.keccak256)(message);
return Buffer.from((0, keccak_1.keccak256)(message));
}

@@ -289,7 +255,7 @@ else {

if (!this.cache.hash) {
this.cache.hash = (0, ethereumjs_util_1.keccak256)(this.serialize());
this.cache.hash = Buffer.from((0, keccak_1.keccak256)(this.serialize()));
}
return this.cache.hash;
}
return (0, ethereumjs_util_1.keccak256)(this.serialize());
return Buffer.from((0, keccak_1.keccak256)(this.serialize()));
}

@@ -306,3 +272,2 @@ /**

getSenderPublicKey() {
var _a;
if (!this.isSigned()) {

@@ -313,12 +278,7 @@ const msg = this._errorMsg('Cannot call this method if transaction is not signed');

const msgHash = this.getMessageToVerifySignature();
// 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))) {
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}
const { v, r, s } = this;
this._validateHighS();
try {
return (0, ethereumjs_util_1.ecrecover)(msgHash, v.addn(27), // Recover the 27 which was stripped from ecsign
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(r), (0, ethereumjs_util_1.bnToUnpaddedBuffer)(s));
return (0, util_1.ecrecover)(msgHash, v + BigInt(27), // Recover the 27 which was stripped from ecsign
(0, util_1.bigIntToUnpaddedBuffer)(r), (0, util_1.bigIntToUnpaddedBuffer)(s));
}

@@ -331,3 +291,3 @@ catch (e) {

_processSignature(v, r, s) {
const opts = Object.assign(Object.assign({}, this.txOptions), { common: this.common });
const opts = { ...this.txOptions, common: this.common };
return FeeMarketEIP1559Transaction.fromTxData({

@@ -343,5 +303,5 @@ chainId: this.chainId,

accessList: this.accessList,
v: new ethereumjs_util_1.BN(v - 27),
r: new ethereumjs_util_1.BN(r),
s: new ethereumjs_util_1.BN(s),
v: v - BigInt(27),
r: (0, util_1.bufferToBigInt)(r),
s: (0, util_1.bufferToBigInt)(s),
}, opts);

@@ -353,16 +313,16 @@ }

toJSON() {
const accessListJSON = util_1.AccessLists.getAccessListJSON(this.accessList);
const accessListJSON = util_2.AccessLists.getAccessListJSON(this.accessList);
return {
chainId: (0, ethereumjs_util_1.bnToHex)(this.chainId),
nonce: (0, ethereumjs_util_1.bnToHex)(this.nonce),
maxPriorityFeePerGas: (0, ethereumjs_util_1.bnToHex)(this.maxPriorityFeePerGas),
maxFeePerGas: (0, ethereumjs_util_1.bnToHex)(this.maxFeePerGas),
gasLimit: (0, ethereumjs_util_1.bnToHex)(this.gasLimit),
chainId: (0, util_1.bigIntToHex)(this.chainId),
nonce: (0, util_1.bigIntToHex)(this.nonce),
maxPriorityFeePerGas: (0, util_1.bigIntToHex)(this.maxPriorityFeePerGas),
maxFeePerGas: (0, util_1.bigIntToHex)(this.maxFeePerGas),
gasLimit: (0, util_1.bigIntToHex)(this.gasLimit),
to: this.to !== undefined ? this.to.toString() : undefined,
value: (0, ethereumjs_util_1.bnToHex)(this.value),
value: (0, util_1.bigIntToHex)(this.value),
data: '0x' + this.data.toString('hex'),
accessList: accessListJSON,
v: this.v !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.v) : undefined,
r: this.r !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.r) : undefined,
s: this.s !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.s) : undefined,
v: this.v !== undefined ? (0, util_1.bigIntToHex)(this.v) : undefined,
r: this.r !== undefined ? (0, util_1.bigIntToHex)(this.r) : undefined,
s: this.s !== undefined ? (0, util_1.bigIntToHex)(this.s) : undefined,
};

@@ -369,0 +329,0 @@ }

@@ -1,4 +0,2 @@

/// <reference types="bn.js" />
/// <reference types="node" />
import { BN } from 'ethereumjs-util';
import Common from '@ethereumjs/common';

@@ -14,6 +12,6 @@ import { BaseTransaction } from './baseTransaction';

export default class AccessListEIP2930Transaction extends BaseTransaction<AccessListEIP2930Transaction> {
readonly chainId: BN;
readonly chainId: bigint;
readonly accessList: AccessListBuffer;
readonly AccessListJSON: AccessList;
readonly gasPrice: BN;
readonly gasPrice: bigint;
readonly common: Common;

@@ -28,20 +26,2 @@ /**

/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/
get senderR(): BN | undefined;
/**
* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/
get senderS(): BN | undefined;
/**
* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity(): BN | undefined;
/**
* Instantiate a transaction from a data dictionary.

@@ -65,12 +45,2 @@ *

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link AccessListEIP2930Transaction.fromSerializedTx})
*
* Note: This means that the Buffer should start with 0x01.
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link AccessListEIP2930Transaction.fromSerializedTx} constructor
*/
static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): AccessListEIP2930Transaction;
/**
* Create a transaction from a values array.

@@ -93,7 +63,7 @@ *

*/
getDataFee(): BN;
getDataFee(): bigint;
/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost(): BN;
getUpfrontCost(): bigint;
/**

@@ -153,3 +123,3 @@ * Returns a Buffer Array of the raw Buffers of the EIP-2930 transaction, in order.

getSenderPublicKey(): Buffer;
_processSignature(v: number, r: Buffer, s: Buffer): AccessListEIP2930Transaction;
_processSignature(v: bigint, r: Buffer, s: Buffer): AccessListEIP2930Transaction;
/**

@@ -171,1 +141,2 @@ * Returns an object with the JSON representation of the transaction

}
//# sourceMappingURL=eip2930Transaction.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ethereumjs_util_1 = require("ethereumjs-util");
const keccak_1 = require("ethereum-cryptography/keccak");
const util_1 = require("@ethereumjs/util");
const rlp_1 = require("rlp");
const baseTransaction_1 = require("./baseTransaction");
const types_1 = require("./types");
const util_1 = require("./util");
const util_2 = require("./util");
const TRANSACTION_TYPE = 1;

@@ -24,4 +25,3 @@ const TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex');

constructor(txData, opts = {}) {
var _a, _b;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
super({ ...txData, type: TRANSACTION_TYPE }, opts);
/**

@@ -36,3 +36,3 @@ * The default HF if the tx type is active on that HF

this.common = this._getCommon(opts.common, chainId);
this.chainId = this.common.chainIdBN();
this.chainId = this.common.chainId();
// EIP-2718 check is done in Common

@@ -44,27 +44,21 @@ if (!this.common.isActivatedEIP(2930)) {

// Populate the access list fields
const accessListData = util_1.AccessLists.getAccessListData(accessList !== null && accessList !== void 0 ? accessList : []);
const accessListData = util_2.AccessLists.getAccessListData(accessList ?? []);
this.accessList = accessListData.accessList;
this.AccessListJSON = accessListData.AccessListJSON;
// Verify the access list format.
util_1.AccessLists.verifyAccessList(this.accessList);
this.gasPrice = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(gasPrice === '' ? '0x' : gasPrice));
util_2.AccessLists.verifyAccessList(this.accessList);
this.gasPrice = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(gasPrice === '' ? '0x' : gasPrice));
this._validateCannotExceedMaxInteger({
gasPrice: this.gasPrice,
});
if (this.gasPrice.mul(this.gasLimit).gt(ethereumjs_util_1.MAX_INTEGER)) {
if (this.gasPrice * this.gasLimit > util_1.MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * gasPrice cannot exceed MAX_INTEGER');
throw new Error(msg);
}
if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1');
throw new Error(msg);
}
if (this.common.gteHardfork('homestead') && ((_a = this.s) === null || _a === void 0 ? void 0 : _a.gt(types_1.N_DIV_2))) {
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}
this._validateYParity();
this._validateHighS();
if (this.common.isActivatedEIP(3860)) {
(0, util_1.checkMaxInitCodeSize)(this.common, this.data.length);
(0, util_2.checkMaxInitCodeSize)(this.common, this.data.length);
}
const freeze = (_b = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _b !== void 0 ? _b : true;
const freeze = opts?.freeze ?? true;
if (freeze) {

@@ -75,26 +69,2 @@ Object.freeze(this);

/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/
get senderR() {
return this.r;
}
/**
* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/
get senderS() {
return this.s;
}
/**
* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity() {
return this.v;
}
/**
* Instantiate a transaction from a data dictionary.

@@ -124,3 +94,3 @@ *

}
const values = ethereumjs_util_1.rlp.decode(serialized.slice(1));
const values = (0, util_1.arrToBufArr)(rlp_1.default.decode(Uint8Array.from(serialized.slice(1))));
if (!Array.isArray(values)) {

@@ -132,14 +102,2 @@ throw new Error('Invalid serialized tx input: must be array');

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link AccessListEIP2930Transaction.fromSerializedTx})
*
* Note: This means that the Buffer should start with 0x01.
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link AccessListEIP2930Transaction.fromSerializedTx} constructor
*/
static fromRlpSerializedTx(serialized, opts = {}) {
return AccessListEIP2930Transaction.fromSerializedTx(serialized, opts);
}
/**
* Create a transaction from a values array.

@@ -155,6 +113,6 @@ *

const [chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, v, r, s] = values;
(0, ethereumjs_util_1.validateNoLeadingZeroes)({ nonce, gasPrice, gasLimit, value, v, r, s });
(0, util_1.validateNoLeadingZeroes)({ nonce, gasPrice, gasLimit, value, v, r, s });
const emptyAccessList = [];
return new AccessListEIP2930Transaction({
chainId: new ethereumjs_util_1.BN(chainId),
chainId: (0, util_1.bufferToBigInt)(chainId),
nonce,

@@ -166,4 +124,4 @@ gasPrice,

data,
accessList: accessList !== null && accessList !== void 0 ? accessList : emptyAccessList,
v: v !== undefined ? new ethereumjs_util_1.BN(v) : undefined,
accessList: accessList ?? emptyAccessList,
v: v !== undefined ? (0, util_1.bufferToBigInt)(v) : undefined,
r,

@@ -180,4 +138,4 @@ s,

}
const cost = super.getDataFee();
cost.iaddn(util_1.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
let cost = super.getDataFee();
cost += BigInt(util_2.AccessLists.getDataFeeEIP2930(this.accessList, this.common));
if (Object.isFrozen(this)) {

@@ -195,3 +153,3 @@ this.cache.dataFee = {

getUpfrontCost() {
return this.gasLimit.mul(this.gasPrice).add(this.value);
return this.gasLimit * this.gasPrice + this.value;
}

@@ -213,13 +171,13 @@ /**

return [
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.chainId),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.nonce),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.gasPrice),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.gasLimit),
(0, util_1.bigIntToUnpaddedBuffer)(this.chainId),
(0, util_1.bigIntToUnpaddedBuffer)(this.nonce),
(0, util_1.bigIntToUnpaddedBuffer)(this.gasPrice),
(0, util_1.bigIntToUnpaddedBuffer)(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.value),
(0, util_1.bigIntToUnpaddedBuffer)(this.value),
this.data,
this.accessList,
this.v !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.v) : Buffer.from([]),
this.r !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.r) : Buffer.from([]),
this.s !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.s) : Buffer.from([]),
this.v !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.v) : Buffer.from([]),
this.r !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.r) : Buffer.from([]),
this.s !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.s) : Buffer.from([]),
];

@@ -239,3 +197,6 @@ }

const base = this.raw();
return Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
return Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(rlp_1.default.encode((0, util_1.bufArrToArr)(base))),
]);
}

@@ -257,5 +218,8 @@ /**

const base = this.raw().slice(0, 8);
const message = Buffer.concat([TRANSACTION_TYPE_BUFFER, ethereumjs_util_1.rlp.encode(base)]);
const message = Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(rlp_1.default.encode((0, util_1.bufArrToArr)(base))),
]);
if (hashMessage) {
return (0, ethereumjs_util_1.keccak256)(message);
return Buffer.from((0, keccak_1.keccak256)(message));
}

@@ -279,7 +243,7 @@ else {

if (!this.cache.hash) {
this.cache.hash = (0, ethereumjs_util_1.keccak256)(this.serialize());
this.cache.hash = Buffer.from((0, keccak_1.keccak256)(this.serialize()));
}
return this.cache.hash;
}
return (0, ethereumjs_util_1.keccak256)(this.serialize());
return Buffer.from((0, keccak_1.keccak256)(this.serialize()));
}

@@ -296,3 +260,2 @@ /**

getSenderPublicKey() {
var _a;
if (!this.isSigned()) {

@@ -303,12 +266,7 @@ const msg = this._errorMsg('Cannot call this method if transaction is not signed');

const msgHash = this.getMessageToVerifySignature();
// 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))) {
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}
const { yParity, r, s } = this;
const { v, r, s } = this;
this._validateHighS();
try {
return (0, ethereumjs_util_1.ecrecover)(msgHash, yParity.addn(27), // Recover the 27 which was stripped from ecsign
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(r), (0, ethereumjs_util_1.bnToUnpaddedBuffer)(s));
return (0, util_1.ecrecover)(msgHash, v + BigInt(27), // Recover the 27 which was stripped from ecsign
(0, util_1.bigIntToUnpaddedBuffer)(r), (0, util_1.bigIntToUnpaddedBuffer)(s));
}

@@ -321,3 +279,3 @@ catch (e) {

_processSignature(v, r, s) {
const opts = Object.assign(Object.assign({}, this.txOptions), { common: this.common });
const opts = { ...this.txOptions, common: this.common };
return AccessListEIP2930Transaction.fromTxData({

@@ -332,5 +290,5 @@ chainId: this.chainId,

accessList: this.accessList,
v: new ethereumjs_util_1.BN(v - 27),
r: new ethereumjs_util_1.BN(r),
s: new ethereumjs_util_1.BN(s),
v: v - BigInt(27),
r: (0, util_1.bufferToBigInt)(r),
s: (0, util_1.bufferToBigInt)(s),
}, opts);

@@ -342,15 +300,15 @@ }

toJSON() {
const accessListJSON = util_1.AccessLists.getAccessListJSON(this.accessList);
const accessListJSON = util_2.AccessLists.getAccessListJSON(this.accessList);
return {
chainId: (0, ethereumjs_util_1.bnToHex)(this.chainId),
nonce: (0, ethereumjs_util_1.bnToHex)(this.nonce),
gasPrice: (0, ethereumjs_util_1.bnToHex)(this.gasPrice),
gasLimit: (0, ethereumjs_util_1.bnToHex)(this.gasLimit),
chainId: (0, util_1.bigIntToHex)(this.chainId),
nonce: (0, util_1.bigIntToHex)(this.nonce),
gasPrice: (0, util_1.bigIntToHex)(this.gasPrice),
gasLimit: (0, util_1.bigIntToHex)(this.gasLimit),
to: this.to !== undefined ? this.to.toString() : undefined,
value: (0, ethereumjs_util_1.bnToHex)(this.value),
value: (0, util_1.bigIntToHex)(this.value),
data: '0x' + this.data.toString('hex'),
accessList: accessListJSON,
v: this.v !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.v) : undefined,
r: this.r !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.r) : undefined,
s: this.s !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.s) : undefined,
v: this.v !== undefined ? (0, util_1.bigIntToHex)(this.v) : undefined,
r: this.r !== undefined ? (0, util_1.bigIntToHex)(this.r) : undefined,
s: this.s !== undefined ? (0, util_1.bigIntToHex)(this.s) : undefined,
};

@@ -362,6 +320,5 @@ }

errorStr() {
var _a, _b;
let errorStr = this._getSharedErrorPostfix();
// Keep ? for this.accessList since this otherwise causes Hardhat E2E tests to fail
errorStr += ` gasPrice=${this.gasPrice} accessListCount=${(_b = (_a = this.accessList) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0}`;
errorStr += ` gasPrice=${this.gasPrice} accessListCount=${this.accessList?.length ?? 0}`;
return errorStr;

@@ -368,0 +325,0 @@ }

@@ -6,1 +6,2 @@ export { default as Transaction } from './legacyTransaction';

export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -16,16 +16,13 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeeMarketEIP1559Transaction = exports.TransactionFactory = exports.AccessListEIP2930Transaction = exports.Transaction = void 0;
var legacyTransaction_1 = require("./legacyTransaction");
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return __importDefault(legacyTransaction_1).default; } });
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return legacyTransaction_1.default; } });
var eip2930Transaction_1 = require("./eip2930Transaction");
Object.defineProperty(exports, "AccessListEIP2930Transaction", { enumerable: true, get: function () { return __importDefault(eip2930Transaction_1).default; } });
Object.defineProperty(exports, "AccessListEIP2930Transaction", { enumerable: true, get: function () { return eip2930Transaction_1.default; } });
var transactionFactory_1 = require("./transactionFactory");
Object.defineProperty(exports, "TransactionFactory", { enumerable: true, get: function () { return __importDefault(transactionFactory_1).default; } });
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 __importDefault(eip1559Transaction_1).default; } });
Object.defineProperty(exports, "FeeMarketEIP1559Transaction", { enumerable: true, get: function () { return eip1559Transaction_1.default; } });
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

@@ -1,4 +0,2 @@

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

@@ -11,3 +9,3 @@ import { BaseTransaction } from './baseTransaction';

export default class Transaction extends BaseTransaction<Transaction> {
readonly gasPrice: BN;
readonly gasPrice: bigint;
readonly common: Common;

@@ -30,10 +28,2 @@ /**

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link Transaction.fromSerializedTx})
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link Transaction.fromSerializedTx} constructor
*/
static fromRlpSerializedTx(serialized: Buffer, opts?: TxOptions): Transaction;
/**
* Create a transaction from a values array.

@@ -85,5 +75,6 @@ *

* ```javascript
* import { rlp } from 'ethereumjs-util'
* import { bufArrToArr } from '@ethereumjs/util'
* import RLP from 'rlp'
* const message = tx.getMessageToSign(false)
* const serializedMessage = rlp.encode(message) // use this for the HW wallet input
* const serializedMessage = Buffer.from(RLP.encode(bufArrToArr(message))) // use this for the HW wallet input
* ```

@@ -98,7 +89,7 @@ *

*/
getDataFee(): BN;
getDataFee(): bigint;
/**
* The up front amount that an account must have for this transaction to be valid
*/
getUpfrontCost(): BN;
getUpfrontCost(): bigint;
/**

@@ -122,3 +113,3 @@ * Computes a sha3-256 hash of the serialized tx.

*/
protected _processSignature(v: number, r: Buffer, s: Buffer): Transaction;
protected _processSignature(v: bigint, r: Buffer, s: Buffer): Transaction;
/**

@@ -133,10 +124,2 @@ * Returns an object with the JSON representation of the transaction.

/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
private _unsignedTxImplementsEIP155;
/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
private _signedTxImplementsEIP155;
/**
* Return a compact error string representation of the object

@@ -153,1 +136,2 @@ */

}
//# sourceMappingURL=legacyTransaction.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ethereumjs_util_1 = require("ethereumjs-util");
const keccak_1 = require("ethereum-cryptography/keccak");
const util_1 = require("@ethereumjs/util");
const rlp_1 = require("rlp");
const types_1 = require("./types");
const baseTransaction_1 = require("./baseTransaction");
const util_1 = require("./util");
const util_2 = require("./util");
const TRANSACTION_TYPE = 0;
function meetsEIP155(_v, chainId) {
const v = Number(_v);
const chainIdDoubled = Number(chainId) * 2;
return v === chainIdDoubled + 35 || v === chainIdDoubled + 36;
}
/**

@@ -20,7 +27,6 @@ * An Ethereum non-typed (legacy) transaction

constructor(txData, opts = {}) {
var _a;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
super({ ...txData, type: TRANSACTION_TYPE }, opts);
this.common = this._validateTxV(this.v, opts.common);
this.gasPrice = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(txData.gasPrice === '' ? '0x' : txData.gasPrice));
if (this.gasPrice.mul(this.gasLimit).gt(ethereumjs_util_1.MAX_INTEGER)) {
this.gasPrice = (0, util_1.bufferToBigInt)((0, util_1.toBuffer)(txData.gasPrice === '' ? '0x' : txData.gasPrice));
if (this.gasPrice * this.gasLimit > util_1.MAX_INTEGER) {
const msg = this._errorMsg('gas limit * gasPrice cannot exceed MAX_INTEGER (2^256-1)');

@@ -40,6 +46,4 @@ throw new Error(msg);

// hash nine elements, with v replaced by CHAIN_ID, r = 0 and s = 0.
const v = this.v;
const chainIdDoubled = this.common.chainIdBN().muln(2);
// v and chain ID meet EIP-155 conditions
if (v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36))) {
if (meetsEIP155(this.v, this.common.chainId())) {
this.activeCapabilities.push(types_1.Capability.EIP155ReplayProtection);

@@ -50,5 +54,5 @@ }

if (this.common.isActivatedEIP(3860)) {
(0, util_1.checkMaxInitCodeSize)(this.common, this.data.length);
(0, util_2.checkMaxInitCodeSize)(this.common, this.data.length);
}
const freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;
const freeze = opts?.freeze ?? true;
if (freeze) {

@@ -75,3 +79,3 @@ Object.freeze(this);

static fromSerializedTx(serialized, opts = {}) {
const values = ethereumjs_util_1.rlp.decode(serialized);
const values = (0, util_1.arrToBufArr)(rlp_1.default.decode(Uint8Array.from(serialized)));
if (!Array.isArray(values)) {

@@ -83,12 +87,2 @@ throw new Error('Invalid serialized tx input. Must be array');

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link Transaction.fromSerializedTx})
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link Transaction.fromSerializedTx} constructor
*/
static fromRlpSerializedTx(serialized, opts = {}) {
return Transaction.fromSerializedTx(serialized, opts);
}
/**
* Create a transaction from a values array.

@@ -105,3 +99,3 @@ *

const [nonce, gasPrice, gasLimit, to, value, data, v, r, s] = values;
(0, ethereumjs_util_1.validateNoLeadingZeroes)({ nonce, gasPrice, gasLimit, value, v, r, s });
(0, util_1.validateNoLeadingZeroes)({ nonce, gasPrice, gasLimit, value, v, r, s });
return new Transaction({

@@ -134,11 +128,11 @@ nonce,

return [
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.nonce),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.gasPrice),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.gasLimit),
(0, util_1.bigIntToUnpaddedBuffer)(this.nonce),
(0, util_1.bigIntToUnpaddedBuffer)(this.gasPrice),
(0, util_1.bigIntToUnpaddedBuffer)(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.value),
(0, util_1.bigIntToUnpaddedBuffer)(this.value),
this.data,
this.v !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.v) : Buffer.from([]),
this.r !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.r) : Buffer.from([]),
this.s !== undefined ? (0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.s) : Buffer.from([]),
this.v !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.v) : Buffer.from([]),
this.r !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.r) : Buffer.from([]),
this.s !== undefined ? (0, util_1.bigIntToUnpaddedBuffer)(this.s) : Buffer.from([]),
];

@@ -156,17 +150,17 @@ }

serialize() {
return ethereumjs_util_1.rlp.encode(this.raw());
return Buffer.from(rlp_1.default.encode((0, util_1.bufArrToArr)(this.raw())));
}
_getMessageToSign() {
const values = [
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.nonce),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.gasPrice),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.gasLimit),
(0, util_1.bigIntToUnpaddedBuffer)(this.nonce),
(0, util_1.bigIntToUnpaddedBuffer)(this.gasPrice),
(0, util_1.bigIntToUnpaddedBuffer)(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
(0, ethereumjs_util_1.bnToUnpaddedBuffer)(this.value),
(0, util_1.bigIntToUnpaddedBuffer)(this.value),
this.data,
];
if (this.supports(types_1.Capability.EIP155ReplayProtection)) {
values.push((0, ethereumjs_util_1.toBuffer)(this.common.chainIdBN()));
values.push((0, ethereumjs_util_1.unpadBuffer)((0, ethereumjs_util_1.toBuffer)(0)));
values.push((0, ethereumjs_util_1.unpadBuffer)((0, ethereumjs_util_1.toBuffer)(0)));
values.push((0, util_1.toBuffer)(this.common.chainId()));
values.push((0, util_1.unpadBuffer)((0, util_1.toBuffer)(0)));
values.push((0, util_1.unpadBuffer)((0, util_1.toBuffer)(0)));
}

@@ -178,3 +172,3 @@ return values;

if (hashMessage) {
return (0, ethereumjs_util_1.rlphash)(message);
return Buffer.from((0, keccak_1.keccak256)(rlp_1.default.encode((0, util_1.bufArrToArr)(message))));
}

@@ -204,3 +198,3 @@ else {

getUpfrontCost() {
return this.gasLimit.mul(this.gasPrice).add(this.value);
return this.gasLimit * this.gasPrice + this.value;
}

@@ -214,23 +208,13 @@ /**

hash() {
// In contrast to the tx type transaction implementations the `hash()` function
// for the legacy tx does not throw if the tx is not signed.
// This has been considered for inclusion but lead to unexpected backwards
// compatibility problems (no concrete reference found, needs validation).
//
// For context see also https://github.com/ethereumjs/ethereumjs-monorepo/pull/1445,
// September, 2021 as well as work done before.
//
// This should be updated along the next major version release by adding:
//
//if (!this.isSigned()) {
// const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
// throw new Error(msg)
//}
if (!this.isSigned()) {
const msg = this._errorMsg('Cannot call hash method if transaction is not signed');
throw new Error(msg);
}
if (Object.isFrozen(this)) {
if (!this.cache.hash) {
this.cache.hash = (0, ethereumjs_util_1.rlphash)(this.raw());
this.cache.hash = Buffer.from((0, keccak_1.keccak256)(rlp_1.default.encode((0, util_1.bufArrToArr)(this.raw()))));
}
return this.cache.hash;
}
return (0, ethereumjs_util_1.rlphash)(this.raw());
return Buffer.from((0, keccak_1.keccak256)(rlp_1.default.encode((0, util_1.bufArrToArr)(this.raw()))));
}

@@ -246,3 +230,3 @@ /**

const message = this._getMessageToSign();
return (0, ethereumjs_util_1.rlphash)(message);
return Buffer.from((0, keccak_1.keccak256)(rlp_1.default.encode((0, util_1.bufArrToArr)(message))));
}

@@ -253,13 +237,7 @@ /**

getSenderPublicKey() {
var _a;
const msgHash = this.getMessageToVerifySignature();
// 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))) {
const msg = this._errorMsg('Invalid Signature: s-values greater than secp256k1n/2 are considered invalid');
throw new Error(msg);
}
const { v, r, s } = this;
this._validateHighS();
try {
return (0, ethereumjs_util_1.ecrecover)(msgHash, v, (0, ethereumjs_util_1.bnToUnpaddedBuffer)(r), (0, ethereumjs_util_1.bnToUnpaddedBuffer)(s), this.supports(types_1.Capability.EIP155ReplayProtection) ? this.common.chainIdBN() : undefined);
return (0, util_1.ecrecover)(msgHash, v, (0, util_1.bigIntToUnpaddedBuffer)(r), (0, util_1.bigIntToUnpaddedBuffer)(s), this.supports(types_1.Capability.EIP155ReplayProtection) ? this.common.chainId() : undefined);
}

@@ -275,7 +253,6 @@ catch (e) {

_processSignature(v, r, s) {
const vBN = new ethereumjs_util_1.BN(v);
if (this.supports(types_1.Capability.EIP155ReplayProtection)) {
vBN.iadd(this.common.chainIdBN().muln(2).addn(8));
v += this.common.chainId() * BigInt(2) + BigInt(8);
}
const opts = Object.assign(Object.assign({}, this.txOptions), { common: this.common });
const opts = { ...this.txOptions, common: this.common };
return Transaction.fromTxData({

@@ -288,5 +265,5 @@ nonce: this.nonce,

data: this.data,
v: vBN,
r: new ethereumjs_util_1.BN(r),
s: new ethereumjs_util_1.BN(s),
v,
r: (0, util_1.bufferToBigInt)(r),
s: (0, util_1.bufferToBigInt)(s),
}, opts);

@@ -299,11 +276,11 @@ }

return {
nonce: (0, ethereumjs_util_1.bnToHex)(this.nonce),
gasPrice: (0, ethereumjs_util_1.bnToHex)(this.gasPrice),
gasLimit: (0, ethereumjs_util_1.bnToHex)(this.gasLimit),
nonce: (0, util_1.bigIntToHex)(this.nonce),
gasPrice: (0, util_1.bigIntToHex)(this.gasPrice),
gasLimit: (0, util_1.bigIntToHex)(this.gasLimit),
to: this.to !== undefined ? this.to.toString() : undefined,
value: (0, ethereumjs_util_1.bnToHex)(this.value),
value: (0, util_1.bigIntToHex)(this.value),
data: '0x' + this.data.toString('hex'),
v: this.v !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.v) : undefined,
r: this.r !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.r) : undefined,
s: this.s !== undefined ? (0, ethereumjs_util_1.bnToHex)(this.s) : undefined,
v: this.v !== undefined ? (0, util_1.bigIntToHex)(this.v) : undefined,
r: this.r !== undefined ? (0, util_1.bigIntToHex)(this.r) : undefined,
s: this.s !== undefined ? (0, util_1.bigIntToHex)(this.s) : undefined,
};

@@ -314,3 +291,5 @@ }

*/
_validateTxV(v, common) {
_validateTxV(_v, common) {
let chainIdBigInt;
const v = _v !== undefined ? Number(_v) : undefined;
// Check for valid v values in the scope of a signed legacy tx

@@ -320,17 +299,15 @@ if (v !== undefined) {

// v is 2. not matching the classic v=27 or v=28 case
if (v.ltn(37) && !v.eqn(27) && !v.eqn(28)) {
if (v < 37 && v !== 27 && v !== 28) {
throw new Error(`Legacy txs need either v = 27/28 or v >= 37 (EIP-155 replay protection), got v = ${v}`);
}
}
let chainIdBN;
// No unsigned tx and EIP-155 activated and chain ID included
if (v !== undefined &&
v !== 0 &&
(!common || common.gteHardfork('spuriousDragon')) &&
!v.eqn(27) &&
!v.eqn(28)) {
v !== 27 &&
v !== 28) {
if (common) {
const chainIdDoubled = common.chainIdBN().muln(2);
const isValidEIP155V = v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36));
if (!isValidEIP155V) {
throw new Error(`Incompatible EIP155-based V ${v} and chain id ${common.chainIdBN()}. See the Common parameter of the Transaction constructor to set the chain id.`);
if (!meetsEIP155(BigInt(v), common.chainId())) {
throw new Error(`Incompatible EIP155-based V ${v} and chain id ${common.chainId()}. See the Common parameter of the Transaction constructor to set the chain id.`);
}

@@ -341,3 +318,3 @@ }

let numSub;
if (v.subn(35).isEven()) {
if ((v - 35) % 2 === 0) {
numSub = 35;

@@ -349,30 +326,8 @@ }

// Use derived chain ID to create a proper Common
chainIdBN = v.subn(numSub).divn(2);
chainIdBigInt = BigInt(v - numSub) / BigInt(2);
}
}
return this._getCommon(common, chainIdBN);
return this._getCommon(common, chainIdBigInt);
}
/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
_unsignedTxImplementsEIP155() {
return this.common.gteHardfork('spuriousDragon');
}
/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
_signedTxImplementsEIP155() {
if (!this.isSigned()) {
const msg = this._errorMsg('This transaction is not signed');
throw new Error(msg);
}
const onEIP155BlockOrLater = this.common.gteHardfork('spuriousDragon');
// EIP155 spec:
// If block.number >= 2,675,000 and v = CHAIN_ID * 2 + 35 or v = CHAIN_ID * 2 + 36, then when computing the hash of a transaction for purposes of signing or recovering, instead of hashing only the first six elements (i.e. nonce, gasprice, startgas, to, value, data), hash nine elements, with v replaced by CHAIN_ID, r = 0 and s = 0.
const v = this.v;
const chainIdDoubled = this.common.chainIdBN().muln(2);
const vAndChainIdMeetEIP155Conditions = v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36));
return vAndChainIdMeetEIP155Conditions && onEIP155BlockOrLater;
}
/**
* Return a compact error string representation of the object

@@ -379,0 +334,0 @@ */

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

@@ -31,10 +29,3 @@ private constructor();

static fromBlockBodyData(data: Buffer | Buffer[], txOptions?: TxOptions): TypedTransaction;
/**
* This helper method allows one to retrieve the class which matches the transactionID
* 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 - This option is not used
*/
static getTransactionClass(transactionID?: number, _common?: Common): typeof Transaction | typeof AccessListEIP2930Transaction | typeof FeeMarketEIP1559Transaction;
}
//# sourceMappingURL=transactionFactory.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ethereumjs_util_1 = require("ethereumjs-util");
const util_1 = require("@ethereumjs/util");
const _1 = require(".");

@@ -20,3 +20,3 @@ class TransactionFactory {

else {
const txType = new ethereumjs_util_1.BN((0, ethereumjs_util_1.toBuffer)(txData.type)).toNumber();
const txType = Number((0, util_1.bufferToBigInt)((0, util_1.toBuffer)(txData.type)));
if (txType === 0) {

@@ -89,25 +89,4 @@ return _1.Transaction.fromTxData(txData, txOptions);

}
/**
* This helper method allows one to retrieve the class which matches the transactionID
* 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 - This option is not used
*/
static getTransactionClass(transactionID = 0, _common) {
const legacyTxn = transactionID == 0 || (transactionID >= 0x80 && transactionID <= 0xff);
if (legacyTxn) {
return _1.Transaction;
}
switch (transactionID) {
case 1:
return _1.AccessListEIP2930Transaction;
case 2:
return _1.FeeMarketEIP1559Transaction;
default:
throw new Error(`TypedTransaction with ID ${transactionID} unknown`);
}
}
}
exports.default = TransactionFactory;
//# sourceMappingURL=transactionFactory.js.map
/// <reference types="node" />
/// <reference types="bn.js" />
import { BN, AddressLike, BNLike, BufferLike, PrefixedHexString } from 'ethereumjs-util';
import { AddressLike, BigIntLike, BufferLike, PrefixedHexString } from '@ethereumjs/util';
import Common from '@ethereumjs/common';

@@ -85,11 +84,11 @@ import { default as Transaction } from './legacyTransaction';

*/
nonce?: BNLike;
nonce?: BigIntLike;
/**
* The transaction's gas price.
*/
gasPrice?: BNLike;
gasPrice?: BigIntLike;
/**
* The transaction's gas limit.
*/
gasLimit?: BNLike;
gasLimit?: BigIntLike;
/**

@@ -102,3 +101,3 @@ * The transaction's the address is sent to.

*/
value?: BNLike;
value?: BigIntLike;
/**

@@ -111,15 +110,15 @@ * This will contain the data of the message or the init of a contract.

*/
v?: BNLike;
v?: BigIntLike;
/**
* EC signature parameter.
*/
r?: BNLike;
r?: BigIntLike;
/**
* EC signature parameter.
*/
s?: BNLike;
s?: BigIntLike;
/**
* The transaction type
*/
type?: BNLike;
type?: BigIntLike;
};

@@ -133,3 +132,3 @@ /**

*/
chainId?: BNLike;
chainId?: BigIntLike;
/**

@@ -152,7 +151,7 @@ * The access list which contains the addresses/storage slots which the transaction wishes to access

*/
maxPriorityFeePerGas?: BNLike;
maxPriorityFeePerGas?: BigIntLike;
/**
* The maximum total fee
*/
maxFeePerGas?: BNLike;
maxFeePerGas?: BigIntLike;
}

@@ -224,6 +223,3 @@ /**

}
/**
* A const defining secp256k1n/2
*/
export declare const N_DIV_2: BN;
export {};
//# sourceMappingURL=types.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.N_DIV_2 = exports.isAccessList = exports.isAccessListBuffer = exports.Capability = void 0;
const ethereumjs_util_1 = require("ethereumjs-util");
exports.isAccessList = exports.isAccessListBuffer = exports.Capability = void 0;
/**

@@ -47,6 +46,2 @@ * Can be used in conjunction with {@link Transaction.supports}

exports.isAccessList = isAccessList;
/**
* A const defining secp256k1n/2
*/
exports.N_DIV_2 = new ethereumjs_util_1.BN('7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0', 16);
//# sourceMappingURL=types.js.map

@@ -13,1 +13,2 @@ import Common from '@ethereumjs/common';

}
//# sourceMappingURL=util.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccessLists = exports.checkMaxInitCodeSize = void 0;
const ethereumjs_util_1 = require("ethereumjs-util");
const util_1 = require("@ethereumjs/util");
const types_1 = require("./types");
function checkMaxInitCodeSize(common, length) {
if (length > common.param('vm', 'maxInitCodeSize')) {
const maxInitCodeSize = common.param('vm', 'maxInitCodeSize');
if (maxInitCodeSize && BigInt(length) > maxInitCodeSize) {
throw new Error(`the initcode size of this transaction is too large: it is ${length} while the max is ${common.param('vm', 'maxInitCodeSize')}`);

@@ -21,6 +22,6 @@ }

const item = accessList[i];
const addressBuffer = (0, ethereumjs_util_1.toBuffer)(item.address);
const addressBuffer = (0, util_1.toBuffer)(item.address);
const storageItems = [];
for (let index = 0; index < item.storageKeys.length; index++) {
storageItems.push((0, ethereumjs_util_1.toBuffer)(item.storageKeys[index]));
storageItems.push((0, util_1.toBuffer)(item.storageKeys[index]));
}

@@ -32,3 +33,3 @@ newAccessList.push([addressBuffer, storageItems]);

else {
bufferAccessList = accessList !== null && accessList !== void 0 ? accessList : [];
bufferAccessList = accessList ?? [];
// build the JSON

@@ -38,6 +39,6 @@ const json = [];

const data = bufferAccessList[i];
const address = (0, ethereumjs_util_1.bufferToHex)(data[0]);
const address = (0, util_1.bufferToHex)(data[0]);
const storageKeys = [];
for (let item = 0; item < data[1].length; item++) {
storageKeys.push((0, ethereumjs_util_1.bufferToHex)(data[1][item]));
storageKeys.push((0, util_1.bufferToHex)(data[1][item]));
}

@@ -80,3 +81,3 @@ const jsonItem = {

const JSONItem = {
address: '0x' + (0, ethereumjs_util_1.setLengthLeft)(item[0], 20).toString('hex'),
address: '0x' + (0, util_1.setLengthLeft)(item[0], 20).toString('hex'),
storageKeys: [],

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

const storageSlot = storageSlots[slot];
JSONItem.storageKeys.push('0x' + (0, ethereumjs_util_1.setLengthLeft)(storageSlot, 32).toString('hex'));
JSONItem.storageKeys.push('0x' + (0, util_1.setLengthLeft)(storageSlot, 32).toString('hex'));
}

@@ -104,3 +105,3 @@ accessListJSON.push(JSONItem);

const addresses = accessList.length;
return addresses * accessListAddressCost + slots * accessListStorageKeyCost;
return addresses * Number(accessListAddressCost) + slots * Number(accessListStorageKeyCost);
}

@@ -107,0 +108,0 @@ }

{
"name": "@ethereumjs/tx",
"version": "3.5.2",
"version": "4.0.0-beta.1",
"description": "A simple module for creating, manipulating and signing Ethereum transactions",

@@ -13,3 +13,2 @@ "license": "MPL-2.0",

"dist",
"dist.browser",
"src"

@@ -19,7 +18,4 @@ ],

"types": "dist/index.d.ts",
"browser": "dist.browser/index.js",
"scripts": {
"build": "npm run build:node && npm run build:browser",
"build:node": "../../config/cli/ts-build.sh node",
"build:browser": "../../config/cli/ts-build.sh browser",
"build": "../../config/cli/ts-build.sh",
"prepublishOnly": "../../config/cli/prepublish.sh",

@@ -39,4 +35,6 @@ "clean": "../../config/cli/clean-package.sh",

"dependencies": {
"@ethereumjs/common": "^2.6.4",
"ethereumjs-util": "^7.1.5"
"@ethereumjs/common": "3.0.0-beta.1",
"@ethereumjs/util": "8.0.0-beta.1",
"ethereum-cryptography": "^1.0.3",
"rlp": "4.0.0-beta.1"
},

@@ -43,0 +41,0 @@ "devDependencies": {

@@ -38,3 +38,3 @@ # @ethereumjs/tx

Base default HF (determined by `Common`): `istanbul`
Base default HF (determined by `Common`): `london`

@@ -71,4 +71,2 @@ Starting with `v3.2.1` the tx library now deviates from the default HF for typed tx using the following rule: "The default HF is the default HF from `Common` if the tx type is active on that HF. Otherwise it is set to the first greater HF where the tx is active."

Please note that up to `v3.2.0` you mandatorily had to use a `Common` instance for typed tx instantiation and set the `hardfork` in `Common` to minimally `berlin` (`EIP-2930`) respectively `london` (`EIP-1559`) to allow for typed tx instantiation, since the current `Common` release series v2 (tx type support introduced with `v2.2.0`) still defaults to `istanbul` for backwards-compatibility reasons (also see tx default HF section below).
#### Gas Fee Market Transactions (EIP-1559)

@@ -160,3 +158,3 @@

```typescript
import Common, { Chain } from '@ethereumjs/common'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import { Transaction } from '@ethereumjs/tx'

@@ -173,3 +171,3 @@

const common = new Common({ chain: Chain.Mainnet })
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
const tx = Transaction.fromTxData(txParams, { common })

@@ -275,3 +273,4 @@

import Common, { Chain } from '@ethereumjs/common'
import { rlp } from 'ethereumjs-util'
import { bufArrToArr } from '@ethereumjs/util'
import RLP from 'rlp'
import Eth from '@ledgerhq/hw-app-eth'

@@ -292,3 +291,3 @@

unsignedTx = tx.getMessageToSign(false)
unsignedTx = rlp.encode(unsignedTx) // ledger signTransaction API expects it to be serialized
unsignedTx = Buffer.from(RLP.encode(bufArrToArr(unsignedTx))) // ledger signTransaction API expects it to be serialized
let { v, r, s } = await eth.signTransaction(bip32Path, unsignedTx)

@@ -316,6 +315,6 @@ txData = { ...txData, v, r, s }

Creating a fake transaction for use in e.g. `VM.runTx()` is simple, just overwrite `getSenderAddress()` with a custom [`Address`](https://github.com/ethereumjs/ethereumjs-util/blob/master/docs/classes/_address_.address.md) like so:
Creating a fake transaction for use in e.g. `VM.runTx()` is simple, just overwrite `getSenderAddress()` with a custom [`Address`](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/docs/classes/Address.md) like so:
```typescript
import { Address } from 'ethereumjs-util'
import { Address } from '@ethereumjs/util'
import { Transaction } from '@ethereumjs/tx'

@@ -322,0 +321,0 @@

import Common, { Chain, Hardfork } from '@ethereumjs/common'
import {
Address,
BN,
BigIntLike,
toBuffer,

@@ -11,5 +11,6 @@ MAX_INTEGER,

publicToAddress,
BNLike,
bufferToHex,
} from 'ethereumjs-util'
bufferToBigInt,
SECP256K1_ORDER_DIV_2,
} from '@ethereumjs/util'
import {

@@ -30,3 +31,3 @@ TxData,

dataFee?: {
value: BN
value: bigint
hardfork: string | Hardfork

@@ -46,11 +47,11 @@ }

public readonly nonce: BN
public readonly gasLimit: BN
public readonly nonce: bigint
public readonly gasLimit: bigint
public readonly to?: Address
public readonly value: BN
public readonly value: bigint
public readonly data: Buffer
public readonly v?: BN
public readonly r?: BN
public readonly s?: BN
public readonly v?: bigint
public readonly r?: bigint
public readonly s?: bigint

@@ -89,7 +90,7 @@ public readonly common!: Common

*/
protected DEFAULT_HARDFORK: string | Hardfork = Hardfork.Istanbul
protected DEFAULT_HARDFORK: string | Hardfork = Hardfork.London
constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, opts: TxOptions) {
const { nonce, gasLimit, to, value, data, v, r, s, type } = txData
this._type = new BN(toBuffer(type)).toNumber()
this._type = Number(bufferToBigInt(toBuffer(type)))

@@ -103,11 +104,11 @@ this.txOptions = opts

this.nonce = new BN(toBuffer(nonce === '' ? '0x' : nonce))
this.gasLimit = new BN(toBuffer(gasLimit === '' ? '0x' : gasLimit))
this.nonce = bufferToBigInt(toBuffer(nonce === '' ? '0x' : nonce))
this.gasLimit = bufferToBigInt(toBuffer(gasLimit === '' ? '0x' : gasLimit))
this.to = toB.length > 0 ? new Address(toB) : undefined
this.value = new BN(toBuffer(value === '' ? '0x' : value))
this.value = bufferToBigInt(toBuffer(value === '' ? '0x' : value))
this.data = toBuffer(data === '' ? '0x' : data)
this.v = vB.length > 0 ? new BN(vB) : undefined
this.r = rB.length > 0 ? new BN(rB) : undefined
this.s = sB.length > 0 ? new BN(sB) : undefined
this.v = vB.length > 0 ? bufferToBigInt(vB) : undefined
this.r = rB.length > 0 ? bufferToBigInt(rB) : undefined
this.s = sB.length > 0 ? bufferToBigInt(sB) : undefined

@@ -124,11 +125,2 @@ this._validateCannotExceedMaxInteger({ value: this.value, r: this.r, s: this.s })

/**
* Alias for {@link BaseTransaction.type}
*
* @deprecated Use `type` instead
*/
get transactionType(): number {
return this.type
}
/**
* Returns the transaction type.

@@ -172,3 +164,3 @@ *

if (this.getBaseFee().gt(this.gasLimit)) {
if (this.getBaseFee() > this.gasLimit) {
errors.push(`gasLimit is too low. given ${this.gasLimit}, need at least ${this.getBaseFee()}`)

@@ -184,9 +176,34 @@ }

protected _validateYParity() {
const { v } = this
if (v !== undefined && v !== BigInt(0) && v !== BigInt(1)) {
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1')
throw new Error(msg)
}
}
/**
* EIP-2: All transaction signatures whose s-value is greater than secp256k1n/2are considered invalid.
* Reasoning: https://ethereum.stackexchange.com/a/55728
*/
protected _validateHighS() {
const { s } = this
if (this.common.gteHardfork('homestead') && s !== undefined && s > SECP256K1_ORDER_DIV_2) {
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}
}
/**
* The minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
*/
getBaseFee(): BN {
const fee = this.getDataFee().addn(this.common.param('gasPrices', 'tx'))
getBaseFee(): bigint {
const txFee = this.common.param('gasPrices', 'tx')
let fee = this.getDataFee()
if (txFee) fee += txFee
if (this.common.gteHardfork('homestead') && this.toCreationAddress()) {
fee.iaddn(this.common.param('gasPrices', 'txCreation'))
const txCreationFee = this.common.param('gasPrices', 'txCreation')
if (txCreationFee) fee += txCreationFee
}

@@ -199,7 +216,7 @@ return fee

*/
getDataFee(): BN {
getDataFee(): bigint {
const txDataZero = this.common.param('gasPrices', 'txDataZero')
const txDataNonZero = this.common.param('gasPrices', 'txDataNonZero')
let cost: number | BN = 0
let cost = BigInt(0)
for (let i = 0; i < this.data.length; i++) {

@@ -209,9 +226,6 @@ this.data[i] === 0 ? (cost += txDataZero) : (cost += txDataNonZero)

cost = new BN(cost)
if ((this.to === undefined || this.to === null) && this.common.isActivatedEIP(3860)) {
const dataLength = Math.ceil(this.data.length / 32)
const initCodeCost = new BN(this.common.param('gasPrices', 'initCodeWordCost')).imuln(
dataLength
)
cost.iadd(initCodeCost)
const dataLength = BigInt(Math.ceil(this.data.length / 32))
const initCodeCost = this.common.param('gasPrices', 'initCodeWordCost') * dataLength
cost += initCodeCost
}

@@ -225,3 +239,3 @@

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

@@ -265,14 +279,6 @@ /**

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

@@ -356,3 +362,3 @@ }

// Accept the v,r,s values from the `sign` method, and convert this into a TransactionObject
protected abstract _processSignature(v: number, r: Buffer, s: Buffer): TransactionObject
protected abstract _processSignature(v: bigint, r: Buffer, s: Buffer): TransactionObject

@@ -367,8 +373,8 @@ /**

*/
protected _getCommon(common?: Common, chainId?: BNLike) {
protected _getCommon(common?: Common, chainId?: BigIntLike) {
// Chain ID provided
if (chainId) {
const chainIdBN = new BN(toBuffer(chainId))
const chainIdBigInt = bufferToBigInt(toBuffer(chainId))
if (common) {
if (!common.chainIdBN().eq(chainIdBN)) {
if (common.chainId() !== chainIdBigInt) {
const msg = this._errorMsg('The chain ID does not match the chain ID of Common')

@@ -381,17 +387,16 @@ throw new Error(msg)

} else {
if (Common.isSupportedChainId(chainIdBN)) {
if (Common.isSupportedChainId(chainIdBigInt)) {
// No Common, chain ID supported by Common
// -> Instantiate Common with chain ID
return new Common({ chain: chainIdBN, hardfork: this.DEFAULT_HARDFORK })
return new Common({ chain: chainIdBigInt, hardfork: this.DEFAULT_HARDFORK })
} else {
// No Common, chain ID not supported by Common
// -> Instantiate custom Common derived from DEFAULT_CHAIN
return Common.forCustomChain(
this.DEFAULT_CHAIN,
return Common.custom(
{
name: 'custom-chain',
networkId: chainIdBN,
chainId: chainIdBN,
networkId: chainIdBigInt,
chainId: chainIdBigInt,
},
this.DEFAULT_HARDFORK
{ baseChain: this.DEFAULT_CHAIN, hardfork: this.DEFAULT_HARDFORK }
)

@@ -410,4 +415,4 @@ }

/**
* Validates that an object with BN values cannot exceed the specified bit limit.
* @param values Object containing string keys and BN values
* Validates that an object with BigInt values cannot exceed the specified bit limit.
* @param values Object containing string keys and BigInt values
* @param bits Number of bits to check (64 or 256)

@@ -417,3 +422,3 @@ * @param cannotEqual Pass true if the number also cannot equal one less the maximum value

protected _validateCannotExceedMaxInteger(
values: { [key: string]: BN | undefined },
values: { [key: string]: bigint | undefined },
bits = 256,

@@ -426,3 +431,3 @@ cannotEqual = false

if (cannotEqual) {
if (value?.gte(MAX_UINT64)) {
if (value !== undefined && value >= MAX_UINT64) {
const msg = this._errorMsg(

@@ -434,3 +439,3 @@ `${key} cannot equal or exceed MAX_UINT64 (2^64-1), given ${value}`

} else {
if (value?.gt(MAX_UINT64)) {
if (value !== undefined && value > MAX_UINT64) {
const msg = this._errorMsg(`${key} cannot exceed MAX_UINT64 (2^64-1), given ${value}`)

@@ -443,3 +448,3 @@ throw new Error(msg)

if (cannotEqual) {
if (value?.gte(MAX_INTEGER)) {
if (value !== undefined && value >= MAX_INTEGER) {
const msg = this._errorMsg(

@@ -451,3 +456,3 @@ `${key} cannot equal or exceed MAX_INTEGER (2^256-1), given ${value}`

} else {
if (value?.gt(MAX_INTEGER)) {
if (value !== undefined && value > MAX_INTEGER) {
const msg = this._errorMsg(

@@ -454,0 +459,0 @@ `${key} cannot exceed MAX_INTEGER (2^256-1), given ${value}`

@@ -0,12 +1,14 @@

import { keccak256 } from 'ethereum-cryptography/keccak'
import {
BN,
bnToHex,
bnToUnpaddedBuffer,
arrToBufArr,
bigIntToHex,
bigIntToUnpaddedBuffer,
bufArrToArr,
bufferToBigInt,
ecrecover,
keccak256,
MAX_INTEGER,
rlp,
toBuffer,
validateNoLeadingZeroes,
} from 'ethereumjs-util'
} from '@ethereumjs/util'
import RLP from 'rlp'
import Common from '@ethereumjs/common'

@@ -20,3 +22,2 @@ import { BaseTransaction } from './baseTransaction'

JsonTx,
N_DIV_2,
TxOptions,

@@ -36,7 +37,7 @@ } from './types'

export default class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP1559Transaction> {
public readonly chainId: BN
public readonly chainId: bigint
public readonly accessList: AccessListBuffer
public readonly AccessListJSON: AccessList
public readonly maxPriorityFeePerGas: BN
public readonly maxFeePerGas: BN
public readonly maxPriorityFeePerGas: bigint
public readonly maxFeePerGas: bigint

@@ -54,29 +55,2 @@ public readonly common: Common

/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/
get senderR() {
return this.r
}
/**
* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/
get senderS() {
return this.s
}
/**
* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity() {
return this.v
}
/**
* Instantiate a transaction from a data dictionary.

@@ -110,3 +84,3 @@ *

const values = rlp.decode(serialized.slice(1))
const values = arrToBufArr(RLP.decode(serialized.slice(1)))

@@ -121,15 +95,2 @@ if (!Array.isArray(values)) {

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link FeeMarketEIP1559Transaction.fromSerializedTx})
*
* Note: This means that the Buffer should start with 0x01.
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link FeeMarketEIP1559Transaction.fromSerializedTx} constructor
*/
public static fromRlpSerializedTx(serialized: Buffer, opts: TxOptions = {}) {
return FeeMarketEIP1559Transaction.fromSerializedTx(serialized, opts)
}
/**
* Create a transaction from a values array.

@@ -166,3 +127,3 @@ *

{
chainId: new BN(chainId),
chainId: bufferToBigInt(chainId),
nonce,

@@ -176,3 +137,3 @@ maxPriorityFeePerGas,

accessList: accessList ?? [],
v: v !== undefined ? new BN(v) : undefined, // EIP2930 supports v's with value 0 (empty Buffer)
v: v !== undefined ? bufferToBigInt(v) : undefined, // EIP2930 supports v's with value 0 (empty Buffer)
r,

@@ -197,3 +158,3 @@ s,

this.common = this._getCommon(opts.common, chainId)
this.chainId = this.common.chainIdBN()
this.chainId = this.common.chainId()

@@ -212,4 +173,4 @@ if (!this.common.isActivatedEIP(1559)) {

this.maxFeePerGas = new BN(toBuffer(maxFeePerGas === '' ? '0x' : maxFeePerGas))
this.maxPriorityFeePerGas = new BN(
this.maxFeePerGas = bufferToBigInt(toBuffer(maxFeePerGas === '' ? '0x' : maxFeePerGas))
this.maxPriorityFeePerGas = bufferToBigInt(
toBuffer(maxPriorityFeePerGas === '' ? '0x' : maxPriorityFeePerGas)

@@ -223,3 +184,3 @@ )

if (this.gasLimit.mul(this.maxFeePerGas).gt(MAX_INTEGER)) {
if (this.gasLimit * this.maxFeePerGas > MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * maxFeePerGas cannot exceed MAX_INTEGER (2^256-1)')

@@ -229,3 +190,3 @@ throw new Error(msg)

if (this.maxFeePerGas.lt(this.maxPriorityFeePerGas)) {
if (this.maxFeePerGas < this.maxPriorityFeePerGas) {
const msg = this._errorMsg(

@@ -237,14 +198,5 @@ 'maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)'

if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1')
throw new Error(msg)
}
this._validateYParity()
this._validateHighS()
if (this.common.gteHardfork('homestead') && this.s?.gt(N_DIV_2)) {
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}
if (this.common.isActivatedEIP(3860)) {

@@ -263,3 +215,3 @@ checkMaxInitCodeSize(this.common, this.data.length)

*/
getDataFee(): BN {
getDataFee(): bigint {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {

@@ -269,4 +221,4 @@ return this.cache.dataFee.value

const cost = super.getDataFee()
cost.iaddn(AccessLists.getDataFeeEIP2930(this.accessList, this.common))
let cost = super.getDataFee()
cost += BigInt(AccessLists.getDataFeeEIP2930(this.accessList, this.common))

@@ -287,6 +239,8 @@ if (Object.isFrozen(this)) {

*/
getUpfrontCost(baseFee: BN = new BN(0)): BN {
const inclusionFeePerGas = BN.min(this.maxPriorityFeePerGas, this.maxFeePerGas.sub(baseFee))
const gasPrice = inclusionFeePerGas.add(baseFee)
return this.gasLimit.mul(gasPrice).add(this.value)
getUpfrontCost(baseFee: bigint = BigInt(0)): bigint {
const prio = this.maxPriorityFeePerGas
const maxBase = this.maxFeePerGas - baseFee
const inclusionFeePerGas = prio < maxBase ? prio : maxBase
const gasPrice = inclusionFeePerGas + baseFee
return this.gasLimit * gasPrice + this.value
}

@@ -309,14 +263,14 @@

return [
bnToUnpaddedBuffer(this.chainId),
bnToUnpaddedBuffer(this.nonce),
bnToUnpaddedBuffer(this.maxPriorityFeePerGas),
bnToUnpaddedBuffer(this.maxFeePerGas),
bnToUnpaddedBuffer(this.gasLimit),
bigIntToUnpaddedBuffer(this.chainId),
bigIntToUnpaddedBuffer(this.nonce),
bigIntToUnpaddedBuffer(this.maxPriorityFeePerGas),
bigIntToUnpaddedBuffer(this.maxFeePerGas),
bigIntToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
bnToUnpaddedBuffer(this.value),
bigIntToUnpaddedBuffer(this.value),
this.data,
this.accessList,
this.v !== undefined ? bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? bnToUnpaddedBuffer(this.s) : Buffer.from([]),
this.v !== undefined ? bigIntToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? bigIntToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? bigIntToUnpaddedBuffer(this.s) : Buffer.from([]),
]

@@ -337,3 +291,6 @@ }

const base = this.raw()
return Buffer.concat([TRANSACTION_TYPE_BUFFER, rlp.encode(base as any)])
return Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(RLP.encode(bufArrToArr(base as Buffer[]))),
])
}

@@ -356,5 +313,8 @@

const base = this.raw().slice(0, 9)
const message = Buffer.concat([TRANSACTION_TYPE_BUFFER, rlp.encode(base as any)])
const message = Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(RLP.encode(bufArrToArr(base as Buffer[]))),
])
if (hashMessage) {
return keccak256(message)
return Buffer.from(keccak256(message))
} else {

@@ -379,3 +339,3 @@ return message

if (!this.cache.hash) {
this.cache.hash = keccak256(this.serialize())
this.cache.hash = Buffer.from(keccak256(this.serialize()))
}

@@ -385,3 +345,3 @@ return this.cache.hash

return keccak256(this.serialize())
return Buffer.from(keccak256(this.serialize()))
}

@@ -406,19 +366,12 @@

const msgHash = this.getMessageToVerifySignature()
const { v, r, s } = this
// 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') && this.s?.gt(N_DIV_2)) {
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}
this._validateHighS()
const { v, r, s } = this
try {
return ecrecover(
msgHash,
v!.addn(27), // Recover the 27 which was stripped from ecsign
bnToUnpaddedBuffer(r!),
bnToUnpaddedBuffer(s!)
v! + BigInt(27), // Recover the 27 which was stripped from ecsign
bigIntToUnpaddedBuffer(r!),
bigIntToUnpaddedBuffer(s!)
)

@@ -431,3 +384,3 @@ } catch (e: any) {

_processSignature(v: number, r: Buffer, s: Buffer) {
_processSignature(v: bigint, r: Buffer, s: Buffer) {
const opts = { ...this.txOptions, common: this.common }

@@ -446,5 +399,5 @@

accessList: this.accessList,
v: new BN(v - 27), // This looks extremely hacky: ethereumjs-util actually adds 27 to the value, the recovery bit is either 0 or 1.
r: new BN(r),
s: new BN(s),
v: v - BigInt(27), // This looks extremely hacky: @ethereumjs/util actually adds 27 to the value, the recovery bit is either 0 or 1.
r: bufferToBigInt(r),
s: bufferToBigInt(s),
},

@@ -462,14 +415,14 @@ opts

return {
chainId: bnToHex(this.chainId),
nonce: bnToHex(this.nonce),
maxPriorityFeePerGas: bnToHex(this.maxPriorityFeePerGas),
maxFeePerGas: bnToHex(this.maxFeePerGas),
gasLimit: bnToHex(this.gasLimit),
chainId: bigIntToHex(this.chainId),
nonce: bigIntToHex(this.nonce),
maxPriorityFeePerGas: bigIntToHex(this.maxPriorityFeePerGas),
maxFeePerGas: bigIntToHex(this.maxFeePerGas),
gasLimit: bigIntToHex(this.gasLimit),
to: this.to !== undefined ? this.to.toString() : undefined,
value: bnToHex(this.value),
value: bigIntToHex(this.value),
data: '0x' + this.data.toString('hex'),
accessList: accessListJSON,
v: this.v !== undefined ? bnToHex(this.v) : undefined,
r: this.r !== undefined ? bnToHex(this.r) : undefined,
s: this.s !== undefined ? bnToHex(this.s) : undefined,
v: this.v !== undefined ? bigIntToHex(this.v) : undefined,
r: this.r !== undefined ? bigIntToHex(this.r) : undefined,
s: this.s !== undefined ? bigIntToHex(this.s) : undefined,
}

@@ -476,0 +429,0 @@ }

@@ -0,12 +1,14 @@

import { keccak256 } from 'ethereum-cryptography/keccak'
import {
BN,
bnToHex,
bnToUnpaddedBuffer,
arrToBufArr,
bigIntToHex,
bigIntToUnpaddedBuffer,
bufArrToArr,
bufferToBigInt,
ecrecover,
keccak256,
MAX_INTEGER,
rlp,
toBuffer,
validateNoLeadingZeroes,
} from 'ethereumjs-util'
} from '@ethereumjs/util'
import RLP from 'rlp'
import Common from '@ethereumjs/common'

@@ -21,3 +23,2 @@ import { BaseTransaction } from './baseTransaction'

TxOptions,
N_DIV_2,
} from './types'

@@ -37,6 +38,6 @@

export default class AccessListEIP2930Transaction extends BaseTransaction<AccessListEIP2930Transaction> {
public readonly chainId: BN
public readonly chainId: bigint
public readonly accessList: AccessListBuffer
public readonly AccessListJSON: AccessList
public readonly gasPrice: BN
public readonly gasPrice: bigint

@@ -54,29 +55,2 @@ public readonly common: Common

/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/
get senderR() {
return this.r
}
/**
* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/
get senderS() {
return this.s
}
/**
* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity() {
return this.v
}
/**
* Instantiate a transaction from a data dictionary.

@@ -110,3 +84,3 @@ *

const values = rlp.decode(serialized.slice(1))
const values = arrToBufArr(RLP.decode(Uint8Array.from(serialized.slice(1))))

@@ -121,15 +95,2 @@ if (!Array.isArray(values)) {

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link AccessListEIP2930Transaction.fromSerializedTx})
*
* Note: This means that the Buffer should start with 0x01.
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link AccessListEIP2930Transaction.fromSerializedTx} constructor
*/
public static fromRlpSerializedTx(serialized: Buffer, opts: TxOptions = {}) {
return AccessListEIP2930Transaction.fromSerializedTx(serialized, opts)
}
/**
* Create a transaction from a values array.

@@ -155,3 +116,3 @@ *

{
chainId: new BN(chainId),
chainId: bufferToBigInt(chainId),
nonce,

@@ -164,3 +125,3 @@ gasPrice,

accessList: accessList ?? emptyAccessList,
v: v !== undefined ? new BN(v) : undefined, // EIP2930 supports v's with value 0 (empty Buffer)
v: v !== undefined ? bufferToBigInt(v) : undefined, // EIP2930 supports v's with value 0 (empty Buffer)
r,

@@ -185,3 +146,3 @@ s,

this.common = this._getCommon(opts.common, chainId)
this.chainId = this.common.chainIdBN()
this.chainId = this.common.chainId()

@@ -201,3 +162,3 @@ // EIP-2718 check is done in Common

this.gasPrice = new BN(toBuffer(gasPrice === '' ? '0x' : gasPrice))
this.gasPrice = bufferToBigInt(toBuffer(gasPrice === '' ? '0x' : gasPrice))

@@ -208,17 +169,9 @@ this._validateCannotExceedMaxInteger({

if (this.gasPrice.mul(this.gasLimit).gt(MAX_INTEGER)) {
if (this.gasPrice * this.gasLimit > MAX_INTEGER) {
const msg = this._errorMsg('gasLimit * gasPrice cannot exceed MAX_INTEGER')
throw new Error(msg)
}
if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {
const msg = this._errorMsg('The y-parity of the transaction should either be 0 or 1')
throw new Error(msg)
}
if (this.common.gteHardfork('homestead') && this.s?.gt(N_DIV_2)) {
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}
this._validateYParity()
this._validateHighS()

@@ -237,3 +190,3 @@ if (this.common.isActivatedEIP(3860)) {

*/
getDataFee(): BN {
getDataFee(): bigint {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {

@@ -243,4 +196,4 @@ return this.cache.dataFee.value

const cost = super.getDataFee()
cost.iaddn(AccessLists.getDataFeeEIP2930(this.accessList, this.common))
let cost = super.getDataFee()
cost += BigInt(AccessLists.getDataFeeEIP2930(this.accessList, this.common))

@@ -260,4 +213,4 @@ if (Object.isFrozen(this)) {

*/
getUpfrontCost(): BN {
return this.gasLimit.mul(this.gasPrice).add(this.value)
getUpfrontCost(): bigint {
return this.gasLimit * this.gasPrice + this.value
}

@@ -280,13 +233,13 @@

return [
bnToUnpaddedBuffer(this.chainId),
bnToUnpaddedBuffer(this.nonce),
bnToUnpaddedBuffer(this.gasPrice),
bnToUnpaddedBuffer(this.gasLimit),
bigIntToUnpaddedBuffer(this.chainId),
bigIntToUnpaddedBuffer(this.nonce),
bigIntToUnpaddedBuffer(this.gasPrice),
bigIntToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
bnToUnpaddedBuffer(this.value),
bigIntToUnpaddedBuffer(this.value),
this.data,
this.accessList,
this.v !== undefined ? bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? bnToUnpaddedBuffer(this.s) : Buffer.from([]),
this.v !== undefined ? bigIntToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? bigIntToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? bigIntToUnpaddedBuffer(this.s) : Buffer.from([]),
]

@@ -307,3 +260,6 @@ }

const base = this.raw()
return Buffer.concat([TRANSACTION_TYPE_BUFFER, rlp.encode(base as any)])
return Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(RLP.encode(bufArrToArr(base as Buffer[]))),
])
}

@@ -326,5 +282,8 @@

const base = this.raw().slice(0, 8)
const message = Buffer.concat([TRANSACTION_TYPE_BUFFER, rlp.encode(base as any)])
const message = Buffer.concat([
TRANSACTION_TYPE_BUFFER,
Buffer.from(RLP.encode(bufArrToArr(base as Buffer[]))),
])
if (hashMessage) {
return keccak256(message)
return Buffer.from(keccak256(message))
} else {

@@ -349,3 +308,3 @@ return message

if (!this.cache.hash) {
this.cache.hash = keccak256(this.serialize())
this.cache.hash = Buffer.from(keccak256(this.serialize()))
}

@@ -355,3 +314,3 @@ return this.cache.hash

return keccak256(this.serialize())
return Buffer.from(keccak256(this.serialize()))
}

@@ -376,19 +335,12 @@

const msgHash = this.getMessageToVerifySignature()
const { v, r, s } = this
// 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') && this.s?.gt(N_DIV_2)) {
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}
this._validateHighS()
const { yParity, r, s } = this
try {
return ecrecover(
msgHash,
yParity!.addn(27), // Recover the 27 which was stripped from ecsign
bnToUnpaddedBuffer(r!),
bnToUnpaddedBuffer(s!)
v! + BigInt(27), // Recover the 27 which was stripped from ecsign
bigIntToUnpaddedBuffer(r!),
bigIntToUnpaddedBuffer(s!)
)

@@ -401,3 +353,3 @@ } catch (e: any) {

_processSignature(v: number, r: Buffer, s: Buffer) {
_processSignature(v: bigint, r: Buffer, s: Buffer) {
const opts = { ...this.txOptions, common: this.common }

@@ -415,5 +367,5 @@

accessList: this.accessList,
v: new BN(v - 27), // This looks extremely hacky: ethereumjs-util actually adds 27 to the value, the recovery bit is either 0 or 1.
r: new BN(r),
s: new BN(s),
v: v - BigInt(27), // This looks extremely hacky: @ethereumjs/util actually adds 27 to the value, the recovery bit is either 0 or 1.
r: bufferToBigInt(r),
s: bufferToBigInt(s),
},

@@ -431,13 +383,13 @@ opts

return {
chainId: bnToHex(this.chainId),
nonce: bnToHex(this.nonce),
gasPrice: bnToHex(this.gasPrice),
gasLimit: bnToHex(this.gasLimit),
chainId: bigIntToHex(this.chainId),
nonce: bigIntToHex(this.nonce),
gasPrice: bigIntToHex(this.gasPrice),
gasLimit: bigIntToHex(this.gasLimit),
to: this.to !== undefined ? this.to.toString() : undefined,
value: bnToHex(this.value),
value: bigIntToHex(this.value),
data: '0x' + this.data.toString('hex'),
accessList: accessListJSON,
v: this.v !== undefined ? bnToHex(this.v) : undefined,
r: this.r !== undefined ? bnToHex(this.r) : undefined,
s: this.s !== undefined ? bnToHex(this.s) : undefined,
v: this.v !== undefined ? bigIntToHex(this.v) : undefined,
r: this.r !== undefined ? bigIntToHex(this.r) : undefined,
s: this.s !== undefined ? bigIntToHex(this.s) : undefined,
}

@@ -444,0 +396,0 @@ }

@@ -0,14 +1,16 @@

import { keccak256 } from 'ethereum-cryptography/keccak'
import {
BN,
bnToHex,
bnToUnpaddedBuffer,
bigIntToHex,
bigIntToUnpaddedBuffer,
bufferToBigInt,
arrToBufArr,
bufArrToArr,
ecrecover,
MAX_INTEGER,
rlp,
rlphash,
toBuffer,
unpadBuffer,
validateNoLeadingZeroes,
} from 'ethereumjs-util'
import { TxOptions, TxData, JsonTx, N_DIV_2, TxValuesArray, Capability } from './types'
} from '@ethereumjs/util'
import RLP from 'rlp'
import { TxOptions, TxData, JsonTx, TxValuesArray, Capability } from './types'
import { BaseTransaction } from './baseTransaction'

@@ -20,2 +22,8 @@ import Common from '@ethereumjs/common'

function meetsEIP155(_v: bigint, chainId: bigint) {
const v = Number(_v)
const chainIdDoubled = Number(chainId) * 2
return v === chainIdDoubled + 35 || v === chainIdDoubled + 36
}
/**

@@ -25,3 +33,3 @@ * An Ethereum non-typed (legacy) transaction

export default class Transaction extends BaseTransaction<Transaction> {
public readonly gasPrice: BN
public readonly gasPrice: bigint

@@ -48,3 +56,3 @@ public readonly common: Common

public static fromSerializedTx(serialized: Buffer, opts: TxOptions = {}) {
const values = rlp.decode(serialized)
const values = arrToBufArr(RLP.decode(Uint8Array.from(serialized))) as Buffer[]

@@ -59,13 +67,2 @@ if (!Array.isArray(values)) {

/**
* Instantiate a transaction from the serialized tx.
* (alias of {@link Transaction.fromSerializedTx})
*
* @deprecated this constructor alias is deprecated and will be removed
* in favor of the {@link Transaction.fromSerializedTx} constructor
*/
public static fromRlpSerializedTx(serialized: Buffer, opts: TxOptions = {}) {
return Transaction.fromSerializedTx(serialized, opts)
}
/**
* Create a transaction from a values array.

@@ -116,5 +113,5 @@ *

this.gasPrice = new BN(toBuffer(txData.gasPrice === '' ? '0x' : txData.gasPrice))
this.gasPrice = bufferToBigInt(toBuffer(txData.gasPrice === '' ? '0x' : txData.gasPrice))
if (this.gasPrice.mul(this.gasLimit).gt(MAX_INTEGER)) {
if (this.gasPrice * this.gasLimit > MAX_INTEGER) {
const msg = this._errorMsg('gas limit * gasPrice cannot exceed MAX_INTEGER (2^256-1)')

@@ -134,7 +131,4 @@ throw new Error(msg)

// hash nine elements, with v replaced by CHAIN_ID, r = 0 and s = 0.
const v = this.v!
const chainIdDoubled = this.common.chainIdBN().muln(2)
// v and chain ID meet EIP-155 conditions
if (v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36))) {
if (meetsEIP155(this.v!, this.common.chainId())) {
this.activeCapabilities.push(Capability.EIP155ReplayProtection)

@@ -170,11 +164,11 @@ }

return [
bnToUnpaddedBuffer(this.nonce),
bnToUnpaddedBuffer(this.gasPrice),
bnToUnpaddedBuffer(this.gasLimit),
bigIntToUnpaddedBuffer(this.nonce),
bigIntToUnpaddedBuffer(this.gasPrice),
bigIntToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
bnToUnpaddedBuffer(this.value),
bigIntToUnpaddedBuffer(this.value),
this.data,
this.v !== undefined ? bnToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? bnToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? bnToUnpaddedBuffer(this.s) : Buffer.from([]),
this.v !== undefined ? bigIntToUnpaddedBuffer(this.v) : Buffer.from([]),
this.r !== undefined ? bigIntToUnpaddedBuffer(this.r) : Buffer.from([]),
this.s !== undefined ? bigIntToUnpaddedBuffer(this.s) : Buffer.from([]),
]

@@ -193,3 +187,3 @@ }

serialize(): Buffer {
return rlp.encode(this.raw())
return Buffer.from(RLP.encode(bufArrToArr(this.raw())))
}

@@ -199,7 +193,7 @@

const values = [
bnToUnpaddedBuffer(this.nonce),
bnToUnpaddedBuffer(this.gasPrice),
bnToUnpaddedBuffer(this.gasLimit),
bigIntToUnpaddedBuffer(this.nonce),
bigIntToUnpaddedBuffer(this.gasPrice),
bigIntToUnpaddedBuffer(this.gasLimit),
this.to !== undefined ? this.to.buf : Buffer.from([]),
bnToUnpaddedBuffer(this.value),
bigIntToUnpaddedBuffer(this.value),
this.data,

@@ -209,3 +203,3 @@ ]

if (this.supports(Capability.EIP155ReplayProtection)) {
values.push(toBuffer(this.common.chainIdBN()))
values.push(toBuffer(this.common.chainId()))
values.push(unpadBuffer(toBuffer(0)))

@@ -226,5 +220,6 @@ values.push(unpadBuffer(toBuffer(0)))

* ```javascript
* import { rlp } from 'ethereumjs-util'
* import { bufArrToArr } from '@ethereumjs/util'
* import RLP from 'rlp'
* const message = tx.getMessageToSign(false)
* const serializedMessage = rlp.encode(message) // use this for the HW wallet input
* const serializedMessage = Buffer.from(RLP.encode(bufArrToArr(message))) // use this for the HW wallet input
* ```

@@ -239,3 +234,3 @@ *

if (hashMessage) {
return rlphash(message)
return Buffer.from(keccak256(RLP.encode(bufArrToArr(message))))
} else {

@@ -249,3 +244,3 @@ return message

*/
getDataFee(): BN {
getDataFee(): bigint {
if (this.cache.dataFee && this.cache.dataFee.hardfork === this.common.hardfork()) {

@@ -268,4 +263,4 @@ return this.cache.dataFee.value

*/
getUpfrontCost(): BN {
return this.gasLimit.mul(this.gasPrice).add(this.value)
getUpfrontCost(): bigint {
return this.gasLimit * this.gasPrice + this.value
}

@@ -280,20 +275,10 @@

hash(): Buffer {
// In contrast to the tx type transaction implementations the `hash()` function
// for the legacy tx does not throw if the tx is not signed.
// This has been considered for inclusion but lead to unexpected backwards
// compatibility problems (no concrete reference found, needs validation).
//
// For context see also https://github.com/ethereumjs/ethereumjs-monorepo/pull/1445,
// September, 2021 as well as work done before.
//
// This should be updated along the next major version release by adding:
//
//if (!this.isSigned()) {
// const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
// throw new Error(msg)
//}
if (!this.isSigned()) {
const msg = this._errorMsg('Cannot call hash method if transaction is not signed')
throw new Error(msg)
}
if (Object.isFrozen(this)) {
if (!this.cache.hash) {
this.cache.hash = rlphash(this.raw())
this.cache.hash = Buffer.from(keccak256(RLP.encode(bufArrToArr(this.raw()))))
}

@@ -303,3 +288,3 @@ return this.cache.hash

return rlphash(this.raw())
return Buffer.from(keccak256(RLP.encode(bufArrToArr(this.raw()))))
}

@@ -316,3 +301,3 @@

const message = this._getMessageToSign()
return rlphash(message)
return Buffer.from(keccak256(RLP.encode(bufArrToArr(message))))
}

@@ -326,12 +311,6 @@

// 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') && this.s?.gt(N_DIV_2)) {
const msg = this._errorMsg(
'Invalid Signature: s-values greater than secp256k1n/2 are considered invalid'
)
throw new Error(msg)
}
const { v, r, s } = this
const { v, r, s } = this
this._validateHighS()
try {

@@ -341,5 +320,5 @@ return ecrecover(

v!,
bnToUnpaddedBuffer(r!),
bnToUnpaddedBuffer(s!),
this.supports(Capability.EIP155ReplayProtection) ? this.common.chainIdBN() : undefined
bigIntToUnpaddedBuffer(r!),
bigIntToUnpaddedBuffer(s!),
this.supports(Capability.EIP155ReplayProtection) ? this.common.chainId() : undefined
)

@@ -355,6 +334,5 @@ } catch (e: any) {

*/
protected _processSignature(v: number, r: Buffer, s: Buffer) {
const vBN = new BN(v)
protected _processSignature(v: bigint, r: Buffer, s: Buffer) {
if (this.supports(Capability.EIP155ReplayProtection)) {
vBN.iadd(this.common.chainIdBN().muln(2).addn(8))
v += this.common.chainId() * BigInt(2) + BigInt(8)
}

@@ -372,5 +350,5 @@

data: this.data,
v: vBN,
r: new BN(r),
s: new BN(s),
v,
r: bufferToBigInt(r),
s: bufferToBigInt(s),
},

@@ -386,11 +364,11 @@ opts

return {
nonce: bnToHex(this.nonce),
gasPrice: bnToHex(this.gasPrice),
gasLimit: bnToHex(this.gasLimit),
nonce: bigIntToHex(this.nonce),
gasPrice: bigIntToHex(this.gasPrice),
gasLimit: bigIntToHex(this.gasLimit),
to: this.to !== undefined ? this.to.toString() : undefined,
value: bnToHex(this.value),
value: bigIntToHex(this.value),
data: '0x' + this.data.toString('hex'),
v: this.v !== undefined ? bnToHex(this.v) : undefined,
r: this.r !== undefined ? bnToHex(this.r) : undefined,
s: this.s !== undefined ? bnToHex(this.s) : undefined,
v: this.v !== undefined ? bigIntToHex(this.v) : undefined,
r: this.r !== undefined ? bigIntToHex(this.r) : undefined,
s: this.s !== undefined ? bigIntToHex(this.s) : undefined,
}

@@ -402,3 +380,5 @@ }

*/
private _validateTxV(v?: BN, common?: Common): Common {
private _validateTxV(_v?: bigint, common?: Common): Common {
let chainIdBigInt
const v = _v !== undefined ? Number(_v) : undefined
// Check for valid v values in the scope of a signed legacy tx

@@ -408,3 +388,3 @@ if (v !== undefined) {

// v is 2. not matching the classic v=27 or v=28 case
if (v.ltn(37) && !v.eqn(27) && !v.eqn(28)) {
if (v < 37 && v !== 27 && v !== 28) {
throw new Error(

@@ -416,17 +396,14 @@ `Legacy txs need either v = 27/28 or v >= 37 (EIP-155 replay protection), got v = ${v}`

let chainIdBN
// No unsigned tx and EIP-155 activated and chain ID included
if (
v !== undefined &&
v !== 0 &&
(!common || common.gteHardfork('spuriousDragon')) &&
!v.eqn(27) &&
!v.eqn(28)
v !== 27 &&
v !== 28
) {
if (common) {
const chainIdDoubled = common.chainIdBN().muln(2)
const isValidEIP155V = v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36))
if (!isValidEIP155V) {
if (!meetsEIP155(BigInt(v), common.chainId())) {
throw new Error(
`Incompatible EIP155-based V ${v} and chain id ${common.chainIdBN()}. See the Common parameter of the Transaction constructor to set the chain id.`
`Incompatible EIP155-based V ${v} and chain id ${common.chainId()}. See the Common parameter of the Transaction constructor to set the chain id.`
)

@@ -437,3 +414,3 @@ }

let numSub
if (v.subn(35).isEven()) {
if ((v - 35) % 2 === 0) {
numSub = 35

@@ -444,38 +421,9 @@ } else {

// Use derived chain ID to create a proper Common
chainIdBN = v.subn(numSub).divn(2)
chainIdBigInt = BigInt(v - numSub) / BigInt(2)
}
}
return this._getCommon(common, chainIdBN)
return this._getCommon(common, chainIdBigInt)
}
/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
private _unsignedTxImplementsEIP155() {
return this.common.gteHardfork('spuriousDragon')
}
/**
* @deprecated if you have called this internal method please use `tx.supports(Capabilities.EIP155ReplayProtection)` instead
*/
private _signedTxImplementsEIP155() {
if (!this.isSigned()) {
const msg = this._errorMsg('This transaction is not signed')
throw new Error(msg)
}
const onEIP155BlockOrLater = this.common.gteHardfork('spuriousDragon')
// EIP155 spec:
// If block.number >= 2,675,000 and v = CHAIN_ID * 2 + 35 or v = CHAIN_ID * 2 + 36, then when computing the hash of a transaction for purposes of signing or recovering, instead of hashing only the first six elements (i.e. nonce, gasprice, startgas, to, value, data), hash nine elements, with v replaced by CHAIN_ID, r = 0 and s = 0.
const v = this.v!
const chainIdDoubled = this.common.chainIdBN().muln(2)
const vAndChainIdMeetEIP155Conditions =
v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36))
return vAndChainIdMeetEIP155Conditions && onEIP155BlockOrLater
}
/**
* Return a compact error string representation of the object

@@ -482,0 +430,0 @@ */

@@ -1,2 +0,2 @@

import { BN, toBuffer } from 'ethereumjs-util'
import { bufferToBigInt, toBuffer } from '@ethereumjs/util'
import {

@@ -10,3 +10,2 @@ TxOptions,

import { Transaction, AccessListEIP2930Transaction, FeeMarketEIP1559Transaction } from '.'
import Common from '@ethereumjs/common'

@@ -31,3 +30,3 @@ export default class TransactionFactory {

} else {
const txType = new BN(toBuffer(txData.type)).toNumber()
const txType = Number(bufferToBigInt(toBuffer(txData.type)))
if (txType === 0) {

@@ -95,26 +94,2 @@ return Transaction.fromTxData(<TxData>txData, txOptions)

}
/**
* This helper method allows one to retrieve the class which matches the transactionID
* 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 - This option is not used
*/
public static getTransactionClass(transactionID: number = 0, _common?: Common) {
const legacyTxn = transactionID == 0 || (transactionID >= 0x80 && transactionID <= 0xff)
if (legacyTxn) {
return Transaction
}
switch (transactionID) {
case 1:
return AccessListEIP2930Transaction
case 2:
return FeeMarketEIP1559Transaction
default:
throw new Error(`TypedTransaction with ID ${transactionID} unknown`)
}
}
}

@@ -1,2 +0,2 @@

import { BN, AddressLike, BNLike, BufferLike, PrefixedHexString } from 'ethereumjs-util'
import { AddressLike, BigIntLike, BufferLike, PrefixedHexString } from '@ethereumjs/util'
import Common from '@ethereumjs/common'

@@ -117,3 +117,3 @@ import { default as Transaction } from './legacyTransaction'

*/
nonce?: BNLike
nonce?: BigIntLike

@@ -123,3 +123,3 @@ /**

*/
gasPrice?: BNLike
gasPrice?: BigIntLike

@@ -129,3 +129,3 @@ /**

*/
gasLimit?: BNLike
gasLimit?: BigIntLike

@@ -140,3 +140,3 @@ /**

*/
value?: BNLike
value?: BigIntLike

@@ -151,3 +151,3 @@ /**

*/
v?: BNLike
v?: BigIntLike

@@ -157,3 +157,3 @@ /**

*/
r?: BNLike
r?: BigIntLike

@@ -163,3 +163,3 @@ /**

*/
s?: BNLike
s?: BigIntLike

@@ -170,3 +170,3 @@ /**

type?: BNLike
type?: BigIntLike
}

@@ -181,3 +181,3 @@

*/
chainId?: BNLike
chainId?: BigIntLike

@@ -202,7 +202,7 @@ /**

*/
maxPriorityFeePerGas?: BNLike
maxPriorityFeePerGas?: BigIntLike
/**
* The maximum total fee
*/
maxFeePerGas?: BNLike
maxFeePerGas?: BigIntLike
}

@@ -276,9 +276,1 @@

}
/**
* A const defining secp256k1n/2
*/
export const N_DIV_2 = new BN(
'7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0',
16
)
import Common from '@ethereumjs/common'
import { bufferToHex, setLengthLeft, toBuffer } from 'ethereumjs-util'
import { bufferToHex, setLengthLeft, toBuffer } from '@ethereumjs/util'
import { AccessList, AccessListBuffer, AccessListItem, isAccessList } from './types'
export function checkMaxInitCodeSize(common: Common, length: number) {
if (length > common.param('vm', 'maxInitCodeSize')) {
const maxInitCodeSize = common.param('vm', 'maxInitCodeSize')
if (maxInitCodeSize && BigInt(length) > maxInitCodeSize) {
throw new Error(

@@ -111,4 +112,4 @@ `the initcode size of this transaction is too large: it is ${length} while the max is ${common.param(

const addresses = accessList.length
return addresses * accessListAddressCost + slots * accessListStorageKeyCost
return addresses * Number(accessListAddressCost) + slots * Number(accessListStorageKeyCost)
}
}

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