Socket
Socket
Sign inDemoInstall

@ethereumjs/tx

Package Overview
Dependencies
44
Maintainers
6
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.0 to 3.2.1

69

CHANGELOG.md

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

## 3.2.1 - 2021-06-11
This release comes with significant library usability improvements by allowing a tx instantiation more independently from the `Common` library. This was reported and requested by Web3.js (thanks to @gregthegreek for giving some guidance on the discussion) and others, since they needed the possibility of a tx instantiation in unknown contexts where the chain or HF state is somewhat unclear.
So we've decided to do the following tweaks to the libray:
### New Rules for Internal Default HF Setting
Up to `v3.2.0` it was simply necessary/mandatory to pass in a `Common` instance for typed tx instantiation (otherwise the instantiation process would have thrown an error). For compatibility reasons the tx library was still on `istanbul` as the default HF and both `EIP-2930` (access lists) and `EIP-1559` (fee market) txs needed a higher (`berlin` respectively `london`) HF setting. After some reflection we have therefore decided to adopt our tx library tx type default HF setting and go with the following expanded 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."
This has been done in PR [#1292](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1292). This should be safe to do since there just are no txs of the specific type before this new default HF (`EIP-2930`: `istanbul` -> `berlin`, `EIP-1559`: `istanbul` -> `london`).
### More Intelligent Default Chain Instantiation
We tried to get more intelligent on the instantiation with a default chain if no `Common` is provided. On older versions of the library `mainnet` was the default fallback here. For typed txs the chain ID is also provided as a data parameter along instantiation. This chain ID parameter is now used for the internal `Common` and therefore the internal chain setting. Same for signed EIP-155 respecting legacy txs, there the chain ID is now extracted from the `v` parameter provided and initialized with the internal `Common` accordingly. For unsigned or non-EIP-1559 legacy txs the chain for `Common` still defaults back to `mainnet`.
Both these changes with the new default HF rules and the more intelligent chain ID instantiation now allows for an e.g. `EIP-155` tx instantiation without a Common (and generally for a safer non-Common tx instantiation) like this:
```typescript
import Common from '@ethereumjs/common'
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
const txData = {
"data": "0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x02625a00",
"maxPriorityFeePerGas": "0x01",
"maxFeePerGas": "0xff",
"nonce": "0x00",
"to": "0xcccccccccccccccccccccccccccccccccccccccc",
"value": "0x0186a0",
"v": "0x01",
"r": "0xafb6e247b1c490e284053c87ab5f6b59e219d51f743f7a4d83e400782bc7e4b9",
"s": "0x479a268e0e0acd4de3f1e28e4fac2a6b32a4195e8dfa9d19147abe8807aa6f64",
"chainId": "0x01",
"accessList": [],
"type": "0x02"
}
const tx = FeeMarketEIP1559Transaction.fromTxData(txData)
```
Note that depending on your usage context it might still be a good idea to instantiate with `Common` since you then have a deterministic state setup, explicitly know what rule set your tx is operating on, and are safe towards eventual future behavioral changes (e.g. on a default HF update along a major version tx library bump).
### Signing Txs with a Hardware Wallet
This is just a note on documentation. There has been some confusion around how to use the tx library for signing of a tx with a HW wallet device (e.g. a Ledger) - see Issue [#1228](https://github.com/ethereumjs/ethereumjs-monorepo/issues/1228) - especially around the usage of `tx.getMessageToSign()`. This is now better documented in the code. Dropping here the associated code on how to do for awareness, for some more context have a look into the associated issue:
```typescript
import { rlp } from 'ethereumjs-util'
import Common from '@ethereumjs/common'
import { Transaction } from '@ethereumjs/tx'
const common = new Common({ chain: 'goerli', hardfork: 'berlin'})
const tx = Transaction.fromTxData({}, { common })
const message = tx.getMessageToSign(false)
const serializedMessage = rlp.encode(message) // use this for the ledger input
```
### Other Changes
- EIP-1559 Validation (spec update): The `maxFeePerGas` and `maxPriorityFeePerGas` parameters are now limited in size to not exceed 256-bit to prevent chain spamming, PR [#1272](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1272)
- Code docs have been improved substantially, PR [#1283](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1283)
- Deprecation of `tx.transactionType`, use `tx.type` instead, PR [#1283](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1283)
- Deprecation of `tx.yParity`, `tx.senderR` and `tx.senderS`, use `v`, `r` and `s` instead, PR [#1283](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1283)
## 3.2.0 - 2021-05-26

@@ -11,0 +80,0 @@

56

dist.browser/baseTransaction.d.ts
/// <reference types="bn.js" />
/// <reference types="node" />
import Common from '@ethereumjs/common';
import { Address, BN } from 'ethereumjs-util';
import { TxData, TxOptions, JsonTx, AccessListEIP2930ValuesArray, AccessListEIP2930TxData, FeeMarketEIP1559ValuesArray, FeeMarketEIP1559TxData, TxValuesArray } from './types';
import { Address, BN, BNLike } from 'ethereumjs-util';
import { TxData, JsonTx, AccessListEIP2930ValuesArray, AccessListEIP2930TxData, FeeMarketEIP1559ValuesArray, FeeMarketEIP1559TxData, TxValuesArray } from './types';
/**

@@ -20,13 +20,33 @@ * This base class will likely be subject to further

readonly data: Buffer;
readonly common: Common;
readonly v?: BN;
readonly r?: BN;
readonly s?: BN;
constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, txOptions?: TxOptions);
readonly common: Common;
/**
* Returns the transaction type
* The default chain the tx falls back to if no Common
* is provided and if the chain can't be derived from
* a passed in chainId (only EIP-2718 typed txs) or
* EIP-155 signature (legacy txs).
*
* @hidden
*/
protected DEFAULT_CHAIN: string;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
protected DEFAULT_HARDFORK: string;
constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData);
/**
* Alias for `type`
*
* @deprecated Use `type` instead
*/
get transactionType(): number;
/**
* Alias for `transactionType`
* Returns the transaction type.
*
* Note: legacy txs will return tx type `0`.
*/

@@ -65,7 +85,2 @@ get type(): number;

abstract serialize(): Buffer;
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
*
* @param hashMessage - Return hashed message if set to true (default: true)
*/
abstract getMessageToSign(hashMessage: false): Buffer | Buffer[];

@@ -89,3 +104,9 @@ abstract getMessageToSign(hashMessage?: true): Buffer;

/**
* Signs a tx and returns a new signed tx object
* Signs a transaction.
*
* Note that the signed tx is returned as a new object,
* use as follows:
* ```javascript
* const signedTx = tx.sign(privateKey)
* ```
*/

@@ -98,5 +119,14 @@ sign(privateKey: Buffer): TransactionObject;

protected abstract _processSignature(v: number, r: Buffer, s: Buffer): TransactionObject;
/**
* Does chain ID checks on common and returns a common
* to be used on instantiation
* @hidden
*
* @param common - Common instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)
*/
protected _getCommon(common?: Common, chainId?: BNLike): Common;
protected _validateCannotExceedMaxInteger(values: {
[key: string]: BN | undefined;
}): void;
}, bits?: number): void;
}

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

var BaseTransaction = /** @class */ (function () {
function BaseTransaction(txData, txOptions) {
if (txOptions === void 0) { txOptions = {}; }
var _a, _b;
function BaseTransaction(txData) {
/**
* The default chain the tx falls back to if no Common
* is provided and if the chain can't be derived from
* a passed in chainId (only EIP-2718 typed txs) or
* EIP-155 signature (legacy txs).
*
* @hidden
*/
this.DEFAULT_CHAIN = 'mainnet';
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
this.DEFAULT_HARDFORK = 'istanbul';
var nonce = txData.nonce, gasLimit = txData.gasLimit, to = txData.to, value = txData.value, data = txData.data, v = txData.v, r = txData.r, s = txData.s, type = txData.type;

@@ -69,10 +83,11 @@ this._type = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(type)).toNumber();

});
this.common = (_b = (_a = txOptions.common) === null || _a === void 0 ? void 0 : _a.copy()) !== null && _b !== void 0 ? _b : new common_1.default({ chain: 'mainnet' });
}
Object.defineProperty(BaseTransaction.prototype, "transactionType", {
/**
* Returns the transaction type
* Alias for `type`
*
* @deprecated Use `type` instead
*/
get: function () {
return this._type;
return this.type;
},

@@ -84,6 +99,8 @@ enumerable: false,

/**
* Alias for `transactionType`
* Returns the transaction type.
*
* Note: legacy txs will return tx type `0`.
*/
get: function () {
return this.transactionType;
return this._type;
},

@@ -171,3 +188,9 @@ enumerable: false,

/**
* Signs a tx and returns a new signed tx object
* Signs a transaction.
*
* Note that the signed tx is returned as a new object,
* use as follows:
* ```javascript
* const signedTx = tx.sign(privateKey)
* ```
*/

@@ -182,10 +205,65 @@ BaseTransaction.prototype.sign = function (privateKey) {

};
BaseTransaction.prototype._validateCannotExceedMaxInteger = function (values) {
/**
* Does chain ID checks on common and returns a common
* to be used on instantiation
* @hidden
*
* @param common - Common instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)
*/
BaseTransaction.prototype._getCommon = function (common, chainId) {
var _a;
// Chain ID provided
if (chainId) {
var chainIdBN = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId));
if (common) {
if (!common.chainIdBN().eq(chainIdBN)) {
throw new Error('The chain ID does not match the chain ID of Common');
}
// Common provided, chain ID does match
// -> Return provided Common
return common.copy();
}
else {
if (common_1.default.isSupportedChainId(chainIdBN)) {
// No Common, chain ID supported by Common
// -> Instantiate Common with chain ID
return new common_1.default({ chain: chainIdBN, hardfork: this.DEFAULT_HARDFORK });
}
else {
// No Common, chain ID not supported by Common
// -> Instantiate custom Common derived from DEFAULT_CHAIN
return common_1.default.forCustomChain(this.DEFAULT_CHAIN, {
name: 'custom-chain',
networkId: chainIdBN,
chainId: chainIdBN,
}, this.DEFAULT_HARDFORK);
}
}
}
else {
// No chain ID provided
// -> 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 }));
}
};
BaseTransaction.prototype._validateCannotExceedMaxInteger = function (values, bits) {
var e_1, _a;
if (bits === void 0) { bits = 53; }
try {
for (var _b = __values(Object.entries(values)), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
if (value === null || value === void 0 ? void 0 : value.gt(ethereumjs_util_1.MAX_INTEGER)) {
throw new Error(key + " cannot exceed MAX_INTEGER, given " + value);
if (bits === 53) {
if (value === null || value === void 0 ? void 0 : value.gt(ethereumjs_util_1.MAX_INTEGER)) {
throw new Error(key + " cannot exceed MAX_INTEGER, given " + value);
}
}
else if (bits === 256) {
if (value === null || value === void 0 ? void 0 : value.gte(ethereumjs_util_1.TWO_POW256)) {
throw new Error(key + " must be less than 2^256, given " + value);
}
}
else {
throw new Error('unimplemented bits value');
}
}

@@ -192,0 +270,0 @@ }

/// <reference types="bn.js" />
/// <reference types="node" />
import Common from '@ethereumjs/common';
import { BN } from 'ethereumjs-util';
import { BaseTransaction } from './baseTransaction';
import { AccessList, AccessListBuffer, FeeMarketEIP1559TxData, FeeMarketEIP1559ValuesArray, JsonTx, TxOptions } from './types';
/**
* Typed transaction with a new gas fee market mechanism
*
* - TransactionType: 2
* - EIP: [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
*/
export default class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP1559Transaction> {

@@ -12,4 +19,14 @@ readonly chainId: BN;

readonly maxFeePerGas: BN;
readonly common: Common;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
protected DEFAULT_HARDFORK: string;
/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -19,2 +36,4 @@ get senderR(): BN | undefined;

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -24,4 +43,16 @@ get senderS(): BN | undefined;

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity(): BN | undefined;
/**
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/
static fromTxData(txData: FeeMarketEIP1559TxData, opts?: TxOptions): FeeMarketEIP1559Transaction;

@@ -31,3 +62,4 @@ /**

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*/

@@ -48,4 +80,4 @@ static fromSerializedTx(serialized: Buffer, opts?: TxOptions): FeeMarketEIP1559Transaction;

*
* The format is:
* chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*/

@@ -71,4 +103,7 @@ static fromValuesArray(values: FeeMarketEIP1559ValuesArray, opts?: TxOptions): FeeMarketEIP1559Transaction;

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-1559 transaction, in order.
*
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -78,8 +113,23 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-1559 transaction.
*
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/
serialize(): Buffer;
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: in contrast to the legacy tx the raw message format is already
* serialized and doesn't need to be RLP encoded any more.
*
* ```javascript
* const serializedMessage = tx.getMessageToSign(false) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

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

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -93,0 +146,0 @@ hash(): Buffer;

@@ -49,2 +49,8 @@ "use strict";

var TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex');
/**
* Typed transaction with a new gas fee market mechanism
*
* - TransactionType: 2
* - EIP: [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
*/
var FeeMarketEIP1559Transaction = /** @class */ (function (_super) {

@@ -62,5 +68,13 @@ __extends(FeeMarketEIP1559Transaction, _super);

var _a, _b;
var _this = this;
var _this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE })) || this;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
_this.DEFAULT_HARDFORK = 'london';
var chainId = txData.chainId, accessList = txData.accessList, maxFeePerGas = txData.maxFeePerGas, maxPriorityFeePerGas = txData.maxPriorityFeePerGas;
_this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE }), opts) || this;
_this.common = _this._getCommon(opts.common, chainId);
_this.chainId = _this.common.chainIdBN();
if (!_this.common.isActivatedEIP(1559)) {

@@ -75,3 +89,2 @@ throw new Error('EIP-1559 not enabled on Common');

util_1.AccessLists.verifyAccessList(_this.accessList);
_this.chainId = chainId ? new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId)) : _this.common.chainIdBN();
_this.maxFeePerGas = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(maxFeePerGas === '' ? '0x' : maxFeePerGas));

@@ -82,5 +95,5 @@ _this.maxPriorityFeePerGas = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(maxPriorityFeePerGas === '' ? '0x' : maxPriorityFeePerGas));

maxPriorityFeePerGas: _this.maxPriorityFeePerGas,
});
if (!_this.chainId.eq(_this.common.chainIdBN())) {
throw new Error('The chain ID does not match the chain ID of Common');
}, 256);
if (_this.maxFeePerGas.lt(_this.maxPriorityFeePerGas)) {
throw new Error('maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)');
}

@@ -102,2 +115,4 @@ if (_this.v && !_this.v.eqn(0) && !_this.v.eqn(1)) {

* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -113,2 +128,4 @@ get: function () {

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -124,2 +141,4 @@ get: function () {

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/

@@ -132,2 +151,12 @@ get: function () {

});
/**
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/
FeeMarketEIP1559Transaction.fromTxData = function (txData, opts) {

@@ -140,3 +169,4 @@ if (opts === void 0) { opts = {}; }

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*/

@@ -172,4 +202,4 @@ FeeMarketEIP1559Transaction.fromSerializedTx = function (serialized, opts) {

*
* The format is:
* chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*/

@@ -210,5 +240,3 @@ FeeMarketEIP1559Transaction.fromValuesArray = function (values, opts) {

FeeMarketEIP1559Transaction.prototype.getUpfrontCost = function (baseFee) {
if (!baseFee) {
baseFee = new ethereumjs_util_1.BN(0);
}
if (baseFee === void 0) { baseFee = new ethereumjs_util_1.BN(0); }
var inclusionFeePerGas = ethereumjs_util_1.BN.min(this.maxPriorityFeePerGas, this.maxFeePerGas.sub(baseFee));

@@ -219,4 +247,7 @@ var gasPrice = inclusionFeePerGas.add(baseFee);

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-1559 transaction, in order.
*
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -241,3 +272,10 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-1559 transaction.
*
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/

@@ -260,3 +298,6 @@ FeeMarketEIP1559Transaction.prototype.serialize = function () {

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -263,0 +304,0 @@ FeeMarketEIP1559Transaction.prototype.hash = function () {

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

@@ -17,4 +18,14 @@ import { BaseTransaction } from './baseTransaction';

readonly gasPrice: BN;
readonly common: Common;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
protected DEFAULT_HARDFORK: string;
/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -24,2 +35,4 @@ get senderR(): BN | undefined;

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -29,6 +42,15 @@ get senderS(): BN | undefined;

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity(): BN | undefined;
/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/

@@ -39,3 +61,4 @@ static fromTxData(txData: AccessListEIP2930TxData, opts?: TxOptions): AccessListEIP2930Transaction;

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*/

@@ -56,4 +79,4 @@ static fromSerializedTx(serialized: Buffer, opts?: TxOptions): AccessListEIP2930Transaction;

*
* The format is:
* chainId, nonce, gasPrice, gasLimit, to, value, data, access_list, yParity (v), senderR (r), senderS (s)
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*/

@@ -78,4 +101,7 @@ static fromValuesArray(values: AccessListEIP2930ValuesArray, opts?: TxOptions): AccessListEIP2930Transaction;

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-2930 transaction, in order.
*
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -85,8 +111,23 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-2930 transaction.
*
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/
serialize(): Buffer;
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: in contrast to the legacy tx the raw message format is already
* serialized and doesn't need to be RLP encoded any more.
*
* ```javascript
* const serializedMessage = tx.getMessageToSign(false) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

@@ -96,3 +137,6 @@ */

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -99,0 +143,0 @@ hash(): Buffer;

@@ -67,5 +67,13 @@ "use strict";

var _a, _b;
var _this = this;
var _this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE })) || this;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
_this.DEFAULT_HARDFORK = 'berlin';
var chainId = txData.chainId, accessList = txData.accessList, gasPrice = txData.gasPrice;
_this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE }), opts) || this;
_this.common = _this._getCommon(opts.common, chainId);
_this.chainId = _this.common.chainIdBN();
// EIP-2718 check is done in Common

@@ -81,8 +89,4 @@ if (!_this.common.isActivatedEIP(2930)) {

util_1.AccessLists.verifyAccessList(_this.accessList);
_this.chainId = chainId ? new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId)) : _this.common.chainIdBN();
_this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice === '' ? '0x' : gasPrice));
_this._validateCannotExceedMaxInteger({ gasPrice: _this.gasPrice });
if (!_this.chainId.eq(_this.common.chainIdBN())) {
throw new Error('The chain ID does not match the chain ID of Common');
}
if (_this.v && !_this.v.eqn(0) && !_this.v.eqn(1)) {

@@ -103,2 +107,4 @@ throw new Error('The y-parity of the transaction should either be 0 or 1');

* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -114,2 +120,4 @@ get: function () {

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -125,2 +133,4 @@ get: function () {

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/

@@ -134,3 +144,10 @@ get: function () {

/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/

@@ -144,3 +161,4 @@ AccessListEIP2930Transaction.fromTxData = function (txData, opts) {

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*/

@@ -176,4 +194,4 @@ AccessListEIP2930Transaction.fromSerializedTx = function (serialized, opts) {

*
* The format is:
* chainId, nonce, gasPrice, gasLimit, to, value, data, access_list, yParity (v), senderR (r), senderS (s)
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*/

@@ -216,4 +234,7 @@ AccessListEIP2930Transaction.fromValuesArray = function (values, opts) {

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-2930 transaction, in order.
*
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -237,3 +258,10 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-2930 transaction.
*
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/

@@ -245,4 +273,12 @@ AccessListEIP2930Transaction.prototype.serialize = function () {

/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: in contrast to the legacy tx the raw message format is already
* serialized and doesn't need to be RLP encoded any more.
*
* ```javascript
* const serializedMessage = tx.getMessageToSign(false) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

@@ -262,3 +298,6 @@ */

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -265,0 +304,0 @@ AccessListEIP2930Transaction.prototype.hash = function () {

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

import { BaseTransaction } from './baseTransaction';
import Common from '@ethereumjs/common';
/**

@@ -12,4 +13,10 @@ * An Ethereum non-typed (legacy) transaction

readonly gasPrice: BN;
readonly common: Common;
/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { nonce, gasPrice, gasLimit, to, value, data, v, r, s }
*
* Notes:
* - All parameters are optional and have some basic default values
*/

@@ -19,2 +26,4 @@ static fromTxData(txData: TxData, opts?: TxOptions): Transaction;

* Instantiate a transaction from the serialized tx.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*/

@@ -33,4 +42,3 @@ static fromSerializedTx(serialized: Buffer, opts?: TxOptions): Transaction;

*
* The format is:
* nonce, gasPrice, gasLimit, to, value, data, v, r, s
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*/

@@ -47,7 +55,19 @@ static fromValuesArray(values: TxValuesArray, opts?: TxOptions): Transaction;

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the legacy transaction, in order.
*
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*
* For an unsigned legacy tx this method returns the the empty Buffer values
* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
*/
raw(): TxValuesArray;
/**
* Returns the rlp encoding of the transaction.
* Returns the serialized encoding of the legacy transaction.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*
* For an unsigned legacy tx this method uses the empty Buffer values
* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
*/

@@ -58,4 +78,14 @@ serialize(): Buffer;

/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: the raw message message format for the legacy tx is not RLP encoded
* and you might need to do yourself with:
*
* ```javascript
* import { rlp } from 'ethereumjs-util'
* const message = tx.getMessageToSign(false)
* const serializedMessage = rlp.encode(message) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

@@ -70,3 +100,6 @@ */

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -87,3 +120,3 @@ hash(): Buffer;

/**
* Returns an object with the JSON representation of the transaction
* Returns an object with the JSON representation of the transaction.
*/

@@ -90,0 +123,0 @@ toJSON(): JsonTx;

@@ -62,6 +62,6 @@ "use strict";

var _a;
var _this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE }), opts) || this;
var _this = _super.call(this, __assign(__assign({}, txData), { type: TRANSACTION_TYPE })) || this;
_this.common = _this._validateTxV(_this.v, opts.common);
_this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(txData.gasPrice === '' ? '0x' : txData.gasPrice));
_this._validateCannotExceedMaxInteger({ gasPrice: _this.gasPrice });
_this._validateTxV(_this.v);
var freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;

@@ -74,3 +74,8 @@ if (freeze) {

/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { nonce, gasPrice, gasLimit, to, value, data, v, r, s }
*
* Notes:
* - All parameters are optional and have some basic default values
*/

@@ -83,2 +88,4 @@ Transaction.fromTxData = function (txData, opts) {

* Instantiate a transaction from the serialized tx.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*/

@@ -107,4 +114,3 @@ Transaction.fromSerializedTx = function (serialized, opts) {

*
* The format is:
* nonce, gasPrice, gasLimit, to, value, data, v, r, s
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*/

@@ -132,3 +138,9 @@ Transaction.fromValuesArray = function (values, opts) {

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the legacy transaction, in order.
*
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*
* For an unsigned legacy tx this method returns the the empty Buffer values
* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
*/

@@ -149,3 +161,9 @@ Transaction.prototype.raw = function () {

/**
* Returns the rlp encoding of the transaction.
* Returns the serialized encoding of the legacy transaction.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*
* For an unsigned legacy tx this method uses the empty Buffer values
* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
*/

@@ -191,3 +209,6 @@ Transaction.prototype.serialize = function () {

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -248,3 +269,3 @@ Transaction.prototype.hash = function () {

/**
* Returns an object with the JSON representation of the transaction
* Returns an object with the JSON representation of the transaction.
*/

@@ -267,19 +288,33 @@ Transaction.prototype.toJSON = function () {

*/
Transaction.prototype._validateTxV = function (v) {
if (v === undefined || v.eqn(0)) {
return;
Transaction.prototype._validateTxV = function (v, common) {
var chainIdBN;
// No unsigned tx and EIP-155 activated and chain ID included
if (v !== undefined &&
!v.eqn(0) &&
(!common || common.gteHardfork('spuriousDragon')) &&
!v.eqn(27) &&
!v.eqn(28)) {
if (common) {
var chainIdDoubled = common.chainIdBN().muln(2);
var isValidEIP155V = v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36));
if (!isValidEIP155V) {
throw new Error("Incompatible EIP155-based V " + v.toString() + " and chain id " + common
.chainIdBN()
.toString() + ". See the Common parameter of the Transaction constructor to set the chain id.");
}
}
else {
// Derive the original chain ID
var numSub = void 0;
if (v.subn(35).isEven()) {
numSub = 35;
}
else {
numSub = 36;
}
// Use derived chain ID to create a proper Common
chainIdBN = v.subn(numSub).divn(2);
}
}
if (!this.common.gteHardfork('spuriousDragon')) {
return;
}
if (v.eqn(27) || v.eqn(28)) {
return;
}
var chainIdDoubled = this.common.chainIdBN().muln(2);
var isValidEIP155V = v.eq(chainIdDoubled.addn(35)) || v.eq(chainIdDoubled.addn(36));
if (!isValidEIP155V) {
throw new Error("Incompatible EIP155-based V " + v.toString() + " and chain id " + this.common
.chainIdBN()
.toString() + ". See the Common parameter of the Transaction constructor to set the chain id.");
}
return this._getCommon(common, chainIdBN);
};

@@ -286,0 +321,0 @@ Transaction.prototype._signedTxImplementsEIP155 = function () {

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

@@ -36,5 +36,5 @@ private constructor();

* @param transactionID
* @param common
* @param common - This option is not used
*/
static getTransactionClass(transactionID?: number, common?: Common): typeof Transaction | typeof AccessListEIP2930Transaction | typeof FeeMarketEIP1559Transaction;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var ethereumjs_util_1 = require("ethereumjs-util");
var common_1 = __importDefault(require("@ethereumjs/common"));
var _1 = require(".");
var DEFAULT_COMMON = new common_1.default({ chain: 'mainnet' });
var TransactionFactory = /** @class */ (function () {

@@ -49,10 +44,4 @@ // It is not possible to instantiate a TransactionFactory object.

TransactionFactory.fromSerializedData = function (data, txOptions) {
var _a;
if (txOptions === void 0) { txOptions = {}; }
var common = (_a = txOptions.common) !== null && _a !== void 0 ? _a : DEFAULT_COMMON;
if (data[0] <= 0x7f) {
// It is an EIP-2718 Typed Transaction
if (!common.isActivatedEIP(2718)) {
throw new Error('Common support for TypedTransactions (EIP-2718) not activated');
}
// Determine the type.

@@ -70,5 +59,2 @@ var EIP = void 0;

}
if (!common.isActivatedEIP(EIP)) {
throw new Error("Cannot create TypedTransaction with ID " + data[0] + ": EIP " + EIP + " not activated");
}
if (EIP === 1559) {

@@ -113,12 +99,7 @@ return _1.FeeMarketEIP1559Transaction.fromSerializedTx(data, txOptions);

* @param transactionID
* @param common
* @param common - This option is not used
*/
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
TransactionFactory.getTransactionClass = function (transactionID, common) {
if (transactionID === void 0) { transactionID = 0; }
var usedCommon = common !== null && common !== void 0 ? common : DEFAULT_COMMON;
if (transactionID !== 0) {
if (!usedCommon.isActivatedEIP(2718)) {
throw new Error('Common support for TypedTransactions (EIP-2718) not activated');
}
}
var legacyTxn = transactionID == 0 || (transactionID >= 0x80 && transactionID <= 0xff);

@@ -125,0 +106,0 @@ if (legacyTxn) {

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

@@ -20,13 +20,33 @@ * This base class will likely be subject to further

readonly data: Buffer;
readonly common: Common;
readonly v?: BN;
readonly r?: BN;
readonly s?: BN;
constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData, txOptions?: TxOptions);
readonly common: Common;
/**
* Returns the transaction type
* The default chain the tx falls back to if no Common
* is provided and if the chain can't be derived from
* a passed in chainId (only EIP-2718 typed txs) or
* EIP-155 signature (legacy txs).
*
* @hidden
*/
protected DEFAULT_CHAIN: string;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
protected DEFAULT_HARDFORK: string;
constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData);
/**
* Alias for `type`
*
* @deprecated Use `type` instead
*/
get transactionType(): number;
/**
* Alias for `transactionType`
* Returns the transaction type.
*
* Note: legacy txs will return tx type `0`.
*/

@@ -65,7 +85,2 @@ get type(): number;

abstract serialize(): Buffer;
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
*
* @param hashMessage - Return hashed message if set to true (default: true)
*/
abstract getMessageToSign(hashMessage: false): Buffer | Buffer[];

@@ -89,3 +104,9 @@ abstract getMessageToSign(hashMessage?: true): Buffer;

/**
* Signs a tx and returns a new signed tx object
* Signs a transaction.
*
* Note that the signed tx is returned as a new object,
* use as follows:
* ```javascript
* const signedTx = tx.sign(privateKey)
* ```
*/

@@ -98,5 +119,14 @@ sign(privateKey: Buffer): TransactionObject;

protected abstract _processSignature(v: number, r: Buffer, s: Buffer): TransactionObject;
/**
* Does chain ID checks on common and returns a common
* to be used on instantiation
* @hidden
*
* @param common - Common instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)
*/
protected _getCommon(common?: Common, chainId?: BNLike): Common;
protected _validateCannotExceedMaxInteger(values: {
[key: string]: BN | undefined;
}): void;
}, bits?: number): void;
}

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

class BaseTransaction {
constructor(txData, txOptions = {}) {
var _a, _b;
constructor(txData) {
/**
* The default chain the tx falls back to if no Common
* is provided and if the chain can't be derived from
* a passed in chainId (only EIP-2718 typed txs) or
* EIP-155 signature (legacy txs).
*
* @hidden
*/
this.DEFAULT_CHAIN = 'mainnet';
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
this.DEFAULT_HARDFORK = 'istanbul';
const { nonce, gasLimit, to, value, data, v, r, s, type } = txData;

@@ -41,15 +56,18 @@ this._type = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(type)).toNumber();

});
this.common = (_b = (_a = txOptions.common) === null || _a === void 0 ? void 0 : _a.copy()) !== null && _b !== void 0 ? _b : new common_1.default({ chain: 'mainnet' });
}
/**
* Returns the transaction type
* Alias for `type`
*
* @deprecated Use `type` instead
*/
get transactionType() {
return this._type;
return this.type;
}
/**
* Alias for `transactionType`
* Returns the transaction type.
*
* Note: legacy txs will return tx type `0`.
*/
get type() {
return this.transactionType;
return this._type;
}

@@ -133,3 +151,9 @@ validate(stringError = false) {

/**
* Signs a tx and returns a new signed tx object
* Signs a transaction.
*
* Note that the signed tx is returned as a new object,
* use as follows:
* ```javascript
* const signedTx = tx.sign(privateKey)
* ```
*/

@@ -144,7 +168,61 @@ sign(privateKey) {

}
_validateCannotExceedMaxInteger(values) {
/**
* Does chain ID checks on common and returns a common
* to be used on instantiation
* @hidden
*
* @param common - Common instance from tx options
* @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx)
*/
_getCommon(common, chainId) {
var _a;
// Chain ID provided
if (chainId) {
const chainIdBN = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId));
if (common) {
if (!common.chainIdBN().eq(chainIdBN)) {
throw new Error('The chain ID does not match the chain ID of Common');
}
// Common provided, chain ID does match
// -> Return provided Common
return common.copy();
}
else {
if (common_1.default.isSupportedChainId(chainIdBN)) {
// No Common, chain ID supported by Common
// -> Instantiate Common with chain ID
return new common_1.default({ chain: chainIdBN, hardfork: this.DEFAULT_HARDFORK });
}
else {
// No Common, chain ID not supported by Common
// -> Instantiate custom Common derived from DEFAULT_CHAIN
return common_1.default.forCustomChain(this.DEFAULT_CHAIN, {
name: 'custom-chain',
networkId: chainIdBN,
chainId: chainIdBN,
}, this.DEFAULT_HARDFORK);
}
}
}
else {
// No chain ID provided
// -> 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 }));
}
}
_validateCannotExceedMaxInteger(values, bits = 53) {
for (const [key, value] of Object.entries(values)) {
if (value === null || value === void 0 ? void 0 : value.gt(ethereumjs_util_1.MAX_INTEGER)) {
throw new Error(`${key} cannot exceed MAX_INTEGER, given ${value}`);
if (bits === 53) {
if (value === null || value === void 0 ? void 0 : value.gt(ethereumjs_util_1.MAX_INTEGER)) {
throw new Error(`${key} cannot exceed MAX_INTEGER, given ${value}`);
}
}
else if (bits === 256) {
if (value === null || value === void 0 ? void 0 : value.gte(ethereumjs_util_1.TWO_POW256)) {
throw new Error(`${key} must be less than 2^256, given ${value}`);
}
}
else {
throw new Error('unimplemented bits value');
}
}

@@ -151,0 +229,0 @@ }

/// <reference types="bn.js" />
/// <reference types="node" />
import Common from '@ethereumjs/common';
import { BN } from 'ethereumjs-util';
import { BaseTransaction } from './baseTransaction';
import { AccessList, AccessListBuffer, FeeMarketEIP1559TxData, FeeMarketEIP1559ValuesArray, JsonTx, TxOptions } from './types';
/**
* Typed transaction with a new gas fee market mechanism
*
* - TransactionType: 2
* - EIP: [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
*/
export default class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP1559Transaction> {

@@ -12,4 +19,14 @@ readonly chainId: BN;

readonly maxFeePerGas: BN;
readonly common: Common;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
protected DEFAULT_HARDFORK: string;
/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -19,2 +36,4 @@ get senderR(): BN | undefined;

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -24,4 +43,16 @@ get senderS(): BN | undefined;

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity(): BN | undefined;
/**
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/
static fromTxData(txData: FeeMarketEIP1559TxData, opts?: TxOptions): FeeMarketEIP1559Transaction;

@@ -31,3 +62,4 @@ /**

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*/

@@ -48,4 +80,4 @@ static fromSerializedTx(serialized: Buffer, opts?: TxOptions): FeeMarketEIP1559Transaction;

*
* The format is:
* chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*/

@@ -71,4 +103,7 @@ static fromValuesArray(values: FeeMarketEIP1559ValuesArray, opts?: TxOptions): FeeMarketEIP1559Transaction;

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-1559 transaction, in order.
*
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -78,8 +113,23 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-1559 transaction.
*
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/
serialize(): Buffer;
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: in contrast to the legacy tx the raw message format is already
* serialized and doesn't need to be RLP encoded any more.
*
* ```javascript
* const serializedMessage = tx.getMessageToSign(false) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

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

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -93,0 +146,0 @@ hash(): Buffer;

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

const TRANSACTION_TYPE_BUFFER = Buffer.from(TRANSACTION_TYPE.toString(16).padStart(2, '0'), 'hex');
/**
* Typed transaction with a new gas fee market mechanism
*
* - TransactionType: 2
* - EIP: [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
*/
class FeeMarketEIP1559Transaction extends baseTransaction_1.BaseTransaction {

@@ -20,4 +26,13 @@ /**

var _a, _b;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }));
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
this.DEFAULT_HARDFORK = 'london';
const { chainId, accessList, maxFeePerGas, maxPriorityFeePerGas } = txData;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
this.common = this._getCommon(opts.common, chainId);
this.chainId = this.common.chainIdBN();
if (!this.common.isActivatedEIP(1559)) {

@@ -32,3 +47,2 @@ throw new Error('EIP-1559 not enabled on Common');

util_1.AccessLists.verifyAccessList(this.accessList);
this.chainId = chainId ? new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId)) : this.common.chainIdBN();
this.maxFeePerGas = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(maxFeePerGas === '' ? '0x' : maxFeePerGas));

@@ -39,5 +53,5 @@ this.maxPriorityFeePerGas = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(maxPriorityFeePerGas === '' ? '0x' : maxPriorityFeePerGas));

maxPriorityFeePerGas: this.maxPriorityFeePerGas,
});
if (!this.chainId.eq(this.common.chainIdBN())) {
throw new Error('The chain ID does not match the chain ID of Common');
}, 256);
if (this.maxFeePerGas.lt(this.maxPriorityFeePerGas)) {
throw new Error('maxFeePerGas cannot be less than maxPriorityFeePerGas (The total must be the larger of the two)');
}

@@ -57,2 +71,4 @@ if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {

* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -64,2 +80,4 @@ get senderR() {

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -71,2 +89,4 @@ get senderS() {

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/

@@ -76,2 +96,12 @@ get yParity() {

}
/**
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/
static fromTxData(txData, opts = {}) {

@@ -83,3 +113,4 @@ return new FeeMarketEIP1559Transaction(txData, opts);

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*/

@@ -113,4 +144,4 @@ static fromSerializedTx(serialized, opts = {}) {

*
* The format is:
* chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*/

@@ -149,6 +180,3 @@ static fromValuesArray(values, opts = {}) {

*/
getUpfrontCost(baseFee) {
if (!baseFee) {
baseFee = new ethereumjs_util_1.BN(0);
}
getUpfrontCost(baseFee = new ethereumjs_util_1.BN(0)) {
const inclusionFeePerGas = ethereumjs_util_1.BN.min(this.maxPriorityFeePerGas, this.maxFeePerGas.sub(baseFee));

@@ -159,4 +187,7 @@ const gasPrice = inclusionFeePerGas.add(baseFee);

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-1559 transaction, in order.
*
* Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -181,3 +212,10 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-1559 transaction.
*
* Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data,
* accessList, signatureYParity, signatureR, signatureS])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/

@@ -199,3 +237,6 @@ serialize() {

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -202,0 +243,0 @@ hash() {

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

@@ -17,4 +18,14 @@ import { BaseTransaction } from './baseTransaction';

readonly gasPrice: BN;
readonly common: Common;
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
protected DEFAULT_HARDFORK: string;
/**
* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -24,2 +35,4 @@ get senderR(): BN | undefined;

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -29,6 +42,15 @@ get senderS(): BN | undefined;

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/
get yParity(): BN | undefined;
/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/

@@ -39,3 +61,4 @@ static fromTxData(txData: AccessListEIP2930TxData, opts?: TxOptions): AccessListEIP2930Transaction;

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*/

@@ -56,4 +79,4 @@ static fromSerializedTx(serialized: Buffer, opts?: TxOptions): AccessListEIP2930Transaction;

*
* The format is:
* chainId, nonce, gasPrice, gasLimit, to, value, data, access_list, yParity (v), senderR (r), senderS (s)
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*/

@@ -78,4 +101,7 @@ static fromValuesArray(values: AccessListEIP2930ValuesArray, opts?: TxOptions): AccessListEIP2930Transaction;

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-2930 transaction, in order.
*
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -85,8 +111,23 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-2930 transaction.
*
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/
serialize(): Buffer;
/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: in contrast to the legacy tx the raw message format is already
* serialized and doesn't need to be RLP encoded any more.
*
* ```javascript
* const serializedMessage = tx.getMessageToSign(false) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

@@ -96,3 +137,6 @@ */

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -99,0 +143,0 @@ hash(): Buffer;

@@ -25,4 +25,13 @@ "use strict";

var _a, _b;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }));
/**
* The default HF if the tx type is active on that HF
* or the first greater HF where the tx is active.
*
* @hidden
*/
this.DEFAULT_HARDFORK = 'berlin';
const { chainId, accessList, gasPrice } = txData;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
this.common = this._getCommon(opts.common, chainId);
this.chainId = this.common.chainIdBN();
// EIP-2718 check is done in Common

@@ -38,8 +47,4 @@ if (!this.common.isActivatedEIP(2930)) {

util_1.AccessLists.verifyAccessList(this.accessList);
this.chainId = chainId ? new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(chainId)) : this.common.chainIdBN();
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(gasPrice === '' ? '0x' : gasPrice));
this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice });
if (!this.chainId.eq(this.common.chainIdBN())) {
throw new Error('The chain ID does not match the chain ID of Common');
}
if (this.v && !this.v.eqn(0) && !this.v.eqn(1)) {

@@ -58,2 +63,4 @@ throw new Error('The y-parity of the transaction should either be 0 or 1');

* EIP-2930 alias for `r`
*
* @deprecated use `r` instead
*/

@@ -65,2 +72,4 @@ get senderR() {

* EIP-2930 alias for `s`
*
* @deprecated use `s` instead
*/

@@ -72,2 +81,4 @@ get senderS() {

* EIP-2930 alias for `v`
*
* @deprecated use `v` instead
*/

@@ -78,3 +89,10 @@ get yParity() {

/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* v, r, s }
*
* Notes:
* - `chainId` will be set automatically if not provided
* - All parameters are optional and have some basic default values
*/

@@ -87,3 +105,4 @@ static fromTxData(txData, opts = {}) {

*
* Note: this means that the Buffer should start with 0x01.
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*/

@@ -117,4 +136,4 @@ static fromSerializedTx(serialized, opts = {}) {

*
* The format is:
* chainId, nonce, gasPrice, gasLimit, to, value, data, access_list, yParity (v), senderR (r), senderS (s)
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*/

@@ -156,4 +175,7 @@ static fromValuesArray(values, opts = {}) {

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the EIP-2930 transaction, in order.
*
* Format: `[chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)]`
*
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.

@@ -177,3 +199,10 @@ */

/**
* Returns the serialized encoding of the transaction.
* Returns the serialized encoding of the EIP-2930 transaction.
*
* Format: `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList,
* signatureYParity (v), signatureR (r), signatureS (s)])`
*
* Note that in contrast to the legacy tx serialization format this is not
* valid RLP any more due to the raw tx type preceeding and concatenated to
* the RLP encoding of the values.
*/

@@ -185,4 +214,12 @@ serialize() {

/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: in contrast to the legacy tx the raw message format is already
* serialized and doesn't need to be RLP encoded any more.
*
* ```javascript
* const serializedMessage = tx.getMessageToSign(false) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

@@ -201,3 +238,6 @@ */

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -204,0 +244,0 @@ hash() {

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

import { BaseTransaction } from './baseTransaction';
import Common from '@ethereumjs/common';
/**

@@ -12,4 +13,10 @@ * An Ethereum non-typed (legacy) transaction

readonly gasPrice: BN;
readonly common: Common;
/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { nonce, gasPrice, gasLimit, to, value, data, v, r, s }
*
* Notes:
* - All parameters are optional and have some basic default values
*/

@@ -19,2 +26,4 @@ static fromTxData(txData: TxData, opts?: TxOptions): Transaction;

* Instantiate a transaction from the serialized tx.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*/

@@ -33,4 +42,3 @@ static fromSerializedTx(serialized: Buffer, opts?: TxOptions): Transaction;

*
* The format is:
* nonce, gasPrice, gasLimit, to, value, data, v, r, s
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*/

@@ -47,7 +55,19 @@ static fromValuesArray(values: TxValuesArray, opts?: TxOptions): Transaction;

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the legacy transaction, in order.
*
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*
* For an unsigned legacy tx this method returns the the empty Buffer values
* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
*/
raw(): TxValuesArray;
/**
* Returns the rlp encoding of the transaction.
* Returns the serialized encoding of the legacy transaction.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*
* For an unsigned legacy tx this method uses the empty Buffer values
* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
*/

@@ -58,4 +78,14 @@ serialize(): Buffer;

/**
* Returns the serialized unsigned tx (hashed or raw), which is used to sign the transaction.
* Returns the serialized unsigned tx (hashed or raw), which can be used
* to sign the transaction (e.g. for sending to a hardware wallet).
*
* Note: the raw message message format for the legacy tx is not RLP encoded
* and you might need to do yourself with:
*
* ```javascript
* import { rlp } from 'ethereumjs-util'
* const message = tx.getMessageToSign(false)
* const serializedMessage = rlp.encode(message) // use this for the HW wallet input
* ```
*
* @param hashMessage - Return hashed message if set to true (default: true)

@@ -70,3 +100,6 @@ */

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -87,3 +120,3 @@ hash(): Buffer;

/**
* Returns an object with the JSON representation of the transaction
* Returns an object with the JSON representation of the transaction.
*/

@@ -90,0 +123,0 @@ toJSON(): JsonTx;

@@ -20,6 +20,6 @@ "use strict";

var _a;
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }), opts);
super(Object.assign(Object.assign({}, txData), { type: TRANSACTION_TYPE }));
this.common = this._validateTxV(this.v, opts.common);
this.gasPrice = new ethereumjs_util_1.BN(ethereumjs_util_1.toBuffer(txData.gasPrice === '' ? '0x' : txData.gasPrice));
this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice });
this._validateTxV(this.v);
const freeze = (_a = opts === null || opts === void 0 ? void 0 : opts.freeze) !== null && _a !== void 0 ? _a : true;

@@ -31,3 +31,8 @@ if (freeze) {

/**
* Instantiate a transaction from a data dictionary
* Instantiate a transaction from a data dictionary.
*
* Format: { nonce, gasPrice, gasLimit, to, value, data, v, r, s }
*
* Notes:
* - All parameters are optional and have some basic default values
*/

@@ -39,2 +44,4 @@ static fromTxData(txData, opts = {}) {

* Instantiate a transaction from the serialized tx.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*/

@@ -61,4 +68,3 @@ static fromSerializedTx(serialized, opts = {}) {

*
* The format is:
* nonce, gasPrice, gasLimit, to, value, data, v, r, s
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*/

@@ -85,3 +91,9 @@ static fromValuesArray(values, opts = {}) {

/**
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
* Returns a Buffer Array of the raw Buffers of the legacy transaction, in order.
*
* Format: `[nonce, gasPrice, gasLimit, to, value, data, v, r, s]`
*
* For an unsigned legacy tx this method returns the the empty Buffer values
* for the signature parameters `v`, `r` and `s`. For an EIP-155 compliant
* representation have a look at the `getMessageToSign()` method.
*/

@@ -102,3 +114,9 @@ raw() {

/**
* Returns the rlp encoding of the transaction.
* Returns the serialized encoding of the legacy transaction.
*
* Format: `rlp([nonce, gasPrice, gasLimit, to, value, data, v, r, s])`
*
* For an unsigned legacy tx this method uses the empty Buffer values
* for the signature parameters `v`, `r` and `s` for encoding. For an
* EIP-155 compliant representation use the `getMessageToSign()` method.
*/

@@ -143,3 +161,6 @@ serialize() {

/**
* Computes a sha3-256 hash of the serialized tx
* Computes a sha3-256 hash of the serialized tx.
*
* This method can only be used for signed txs (it throws otherwise).
* Use `getMessageToSign()` to get a tx hash for the purpose of signing.
*/

@@ -200,3 +221,3 @@ hash() {

/**
* Returns an object with the JSON representation of the transaction
* Returns an object with the JSON representation of the transaction.
*/

@@ -219,19 +240,33 @@ toJSON() {

*/
_validateTxV(v) {
if (v === undefined || v.eqn(0)) {
return;
_validateTxV(v, common) {
let chainIdBN;
// No unsigned tx and EIP-155 activated and chain ID included
if (v !== undefined &&
!v.eqn(0) &&
(!common || common.gteHardfork('spuriousDragon')) &&
!v.eqn(27) &&
!v.eqn(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.toString()} and chain id ${common
.chainIdBN()
.toString()}. See the Common parameter of the Transaction constructor to set the chain id.`);
}
}
else {
// Derive the original chain ID
let numSub;
if (v.subn(35).isEven()) {
numSub = 35;
}
else {
numSub = 36;
}
// Use derived chain ID to create a proper Common
chainIdBN = v.subn(numSub).divn(2);
}
}
if (!this.common.gteHardfork('spuriousDragon')) {
return;
}
if (v.eqn(27) || v.eqn(28)) {
return;
}
const chainIdDoubled = this.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.toString()} and chain id ${this.common
.chainIdBN()
.toString()}. See the Common parameter of the Transaction constructor to set the chain id.`);
}
return this._getCommon(common, chainIdBN);
}

@@ -238,0 +273,0 @@ _signedTxImplementsEIP155() {

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

@@ -36,5 +36,5 @@ private constructor();

* @param transactionID
* @param common
* @param common - This option is not used
*/
static getTransactionClass(transactionID?: number, common?: Common): typeof Transaction | typeof AccessListEIP2930Transaction | typeof FeeMarketEIP1559Transaction;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ethereumjs_util_1 = require("ethereumjs-util");
const common_1 = __importDefault(require("@ethereumjs/common"));
const _1 = require(".");
const DEFAULT_COMMON = new common_1.default({ chain: 'mainnet' });
class TransactionFactory {

@@ -47,9 +42,3 @@ // It is not possible to instantiate a TransactionFactory object.

static fromSerializedData(data, txOptions = {}) {
var _a;
const common = (_a = txOptions.common) !== null && _a !== void 0 ? _a : DEFAULT_COMMON;
if (data[0] <= 0x7f) {
// It is an EIP-2718 Typed Transaction
if (!common.isActivatedEIP(2718)) {
throw new Error('Common support for TypedTransactions (EIP-2718) not activated');
}
// Determine the type.

@@ -67,5 +56,2 @@ let EIP;

}
if (!common.isActivatedEIP(EIP)) {
throw new Error(`Cannot create TypedTransaction with ID ${data[0]}: EIP ${EIP} not activated`);
}
if (EIP === 1559) {

@@ -109,11 +95,6 @@ return _1.FeeMarketEIP1559Transaction.fromSerializedTx(data, txOptions);

* @param transactionID
* @param common
* @param common - This option is not used
*/
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
static getTransactionClass(transactionID = 0, common) {
const usedCommon = common !== null && common !== void 0 ? common : DEFAULT_COMMON;
if (transactionID !== 0) {
if (!usedCommon.isActivatedEIP(2718)) {
throw new Error('Common support for TypedTransactions (EIP-2718) not activated');
}
}
const legacyTxn = transactionID == 0 || (transactionID >= 0x80 && transactionID <= 0xff);

@@ -120,0 +101,0 @@ if (legacyTxn) {

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

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

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

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

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

Please note that for now you have to manually set the `hardfork` in `Common` to `berlin` 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.
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).

@@ -129,2 +129,3 @@ #### Gas Fee Market Transactions (EIP-1559)

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

@@ -202,6 +203,7 @@

The `Transaction` constructor receives a parameter of an [`@ethereumjs/common`](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common) object that lets you specify the chain and hardfork to be used. The chain defaults to `mainnet`.
The `Transaction` constructor receives a parameter of an [`@ethereumjs/common`](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/common) object that lets you specify the chain and hardfork to be used. If there is no `Common` provided the chain ID provided as a paramter on typed tx or the chain ID derived from the `v` value on signed EIP-155 conforming legacy txs will be taken (introduced in `v3.2.1`). In other cases the chain defaults to `mainnet`.
Base default HF (determined by `Common`): `istanbul`
Current default HF (determined by `Common`): `istanbul`
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."

@@ -208,0 +210,0 @@ ### Supported Hardforks

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc